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 can share line table entries with CUs or other TUs, and there can be
261 a lot more TUs than unique line tables, so we maintain a separate table
262 of all line table entries to support the sharing. */
263 htab_t quick_file_names_table
;
265 /* Set during partial symbol reading, to prevent queueing of full
267 int reading_partial_symbols
;
269 /* Table mapping type DIEs to their struct type *.
270 This is NULL if not allocated yet.
271 The mapping is done via (CU/TU signature + DIE offset) -> type. */
272 htab_t die_type_hash
;
274 /* The CUs we recently read. */
275 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
278 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
280 /* Default names of the debugging sections. */
282 /* Note that if the debugging section has been compressed, it might
283 have a name like .zdebug_info. */
285 static const struct dwarf2_debug_sections dwarf2_elf_names
=
287 { ".debug_info", ".zdebug_info" },
288 { ".debug_abbrev", ".zdebug_abbrev" },
289 { ".debug_line", ".zdebug_line" },
290 { ".debug_loc", ".zdebug_loc" },
291 { ".debug_macinfo", ".zdebug_macinfo" },
292 { ".debug_macro", ".zdebug_macro" },
293 { ".debug_str", ".zdebug_str" },
294 { ".debug_ranges", ".zdebug_ranges" },
295 { ".debug_types", ".zdebug_types" },
296 { ".debug_addr", ".zdebug_addr" },
297 { ".debug_frame", ".zdebug_frame" },
298 { ".eh_frame", NULL
},
299 { ".gdb_index", ".zgdb_index" },
303 /* List of DWO/DWP sections. */
305 static const struct dwop_section_names
307 struct dwarf2_section_names abbrev_dwo
;
308 struct dwarf2_section_names info_dwo
;
309 struct dwarf2_section_names line_dwo
;
310 struct dwarf2_section_names loc_dwo
;
311 struct dwarf2_section_names macinfo_dwo
;
312 struct dwarf2_section_names macro_dwo
;
313 struct dwarf2_section_names str_dwo
;
314 struct dwarf2_section_names str_offsets_dwo
;
315 struct dwarf2_section_names types_dwo
;
316 struct dwarf2_section_names cu_index
;
317 struct dwarf2_section_names tu_index
;
321 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
322 { ".debug_info.dwo", ".zdebug_info.dwo" },
323 { ".debug_line.dwo", ".zdebug_line.dwo" },
324 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
325 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
326 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
327 { ".debug_str.dwo", ".zdebug_str.dwo" },
328 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
329 { ".debug_types.dwo", ".zdebug_types.dwo" },
330 { ".debug_cu_index", ".zdebug_cu_index" },
331 { ".debug_tu_index", ".zdebug_tu_index" },
334 /* local data types */
336 /* The data in a compilation unit header, after target2host
337 translation, looks like this. */
338 struct comp_unit_head
342 unsigned char addr_size
;
343 unsigned char signed_addr_p
;
344 sect_offset abbrev_offset
;
346 /* Size of file offsets; either 4 or 8. */
347 unsigned int offset_size
;
349 /* Size of the length field; either 4 or 12. */
350 unsigned int initial_length_size
;
352 /* Offset to the first byte of this compilation unit header in the
353 .debug_info section, for resolving relative reference dies. */
356 /* Offset to first die in this cu from the start of the cu.
357 This will be the first byte following the compilation unit header. */
358 cu_offset first_die_offset
;
361 /* Type used for delaying computation of method physnames.
362 See comments for compute_delayed_physnames. */
363 struct delayed_method_info
365 /* The type to which the method is attached, i.e., its parent class. */
368 /* The index of the method in the type's function fieldlists. */
371 /* The index of the method in the fieldlist. */
374 /* The name of the DIE. */
377 /* The DIE associated with this method. */
378 struct die_info
*die
;
381 typedef struct delayed_method_info delayed_method_info
;
382 DEF_VEC_O (delayed_method_info
);
384 /* Internal state when decoding a particular compilation unit. */
387 /* The objfile containing this compilation unit. */
388 struct objfile
*objfile
;
390 /* The header of the compilation unit. */
391 struct comp_unit_head header
;
393 /* Base address of this compilation unit. */
394 CORE_ADDR base_address
;
396 /* Non-zero if base_address has been set. */
399 /* The language we are debugging. */
400 enum language language
;
401 const struct language_defn
*language_defn
;
403 const char *producer
;
405 /* The generic symbol table building routines have separate lists for
406 file scope symbols and all all other scopes (local scopes). So
407 we need to select the right one to pass to add_symbol_to_list().
408 We do it by keeping a pointer to the correct list in list_in_scope.
410 FIXME: The original dwarf code just treated the file scope as the
411 first local scope, and all other local scopes as nested local
412 scopes, and worked fine. Check to see if we really need to
413 distinguish these in buildsym.c. */
414 struct pending
**list_in_scope
;
416 /* The abbrev table for this CU.
417 Normally this points to the abbrev table in the objfile.
418 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
419 struct abbrev_table
*abbrev_table
;
421 /* Hash table holding all the loaded partial DIEs
422 with partial_die->offset.SECT_OFF as hash. */
425 /* Storage for things with the same lifetime as this read-in compilation
426 unit, including partial DIEs. */
427 struct obstack comp_unit_obstack
;
429 /* When multiple dwarf2_cu structures are living in memory, this field
430 chains them all together, so that they can be released efficiently.
431 We will probably also want a generation counter so that most-recently-used
432 compilation units are cached... */
433 struct dwarf2_per_cu_data
*read_in_chain
;
435 /* Backchain to our per_cu entry if the tree has been built. */
436 struct dwarf2_per_cu_data
*per_cu
;
438 /* How many compilation units ago was this CU last referenced? */
441 /* A hash table of DIE cu_offset for following references with
442 die_info->offset.sect_off as hash. */
445 /* Full DIEs if read in. */
446 struct die_info
*dies
;
448 /* A set of pointers to dwarf2_per_cu_data objects for compilation
449 units referenced by this one. Only set during full symbol processing;
450 partial symbol tables do not have dependencies. */
453 /* Header data from the line table, during full symbol processing. */
454 struct line_header
*line_header
;
456 /* A list of methods which need to have physnames computed
457 after all type information has been read. */
458 VEC (delayed_method_info
) *method_list
;
460 /* To be copied to symtab->call_site_htab. */
461 htab_t call_site_htab
;
463 /* Non-NULL if this CU came from a DWO file.
464 There is an invariant here that is important to remember:
465 Except for attributes copied from the top level DIE in the "main"
466 (or "stub") file in preparation for reading the DWO file
467 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
468 Either there isn't a DWO file (in which case this is NULL and the point
469 is moot), or there is and either we're not going to read it (in which
470 case this is NULL) or there is and we are reading it (in which case this
472 struct dwo_unit
*dwo_unit
;
474 /* The DW_AT_addr_base attribute if present, zero otherwise
475 (zero is a valid value though).
476 Note this value comes from the stub CU/TU's DIE. */
479 /* The DW_AT_ranges_base attribute if present, zero otherwise
480 (zero is a valid value though).
481 Note this value comes from the stub CU/TU's DIE.
482 Also note that the value is zero in the non-DWO case so this value can
483 be used without needing to know whether DWO files are in use or not. */
484 ULONGEST ranges_base
;
486 /* Mark used when releasing cached dies. */
487 unsigned int mark
: 1;
489 /* This CU references .debug_loc. See the symtab->locations_valid field.
490 This test is imperfect as there may exist optimized debug code not using
491 any location list and still facing inlining issues if handled as
492 unoptimized code. For a future better test see GCC PR other/32998. */
493 unsigned int has_loclist
: 1;
495 /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc.
496 CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC
497 are valid. This information is cached because profiling CU expansion
498 showed excessive time spent in producer_is_gxx_lt_4_6. */
499 unsigned int checked_producer
: 1;
500 unsigned int producer_is_gxx_lt_4_6
: 1;
501 unsigned int producer_is_icc
: 1;
504 /* Persistent data held for a compilation unit, even when not
505 processing it. We put a pointer to this structure in the
506 read_symtab_private field of the psymtab. */
508 struct dwarf2_per_cu_data
510 /* The start offset and length of this compilation unit.
511 NOTE: Unlike comp_unit_head.length, this length includes
513 If the DIE refers to a DWO file, this is always of the original die,
518 /* Flag indicating this compilation unit will be read in before
519 any of the current compilation units are processed. */
520 unsigned int queued
: 1;
522 /* This flag will be set when reading partial DIEs if we need to load
523 absolutely all DIEs for this compilation unit, instead of just the ones
524 we think are interesting. It gets set if we look for a DIE in the
525 hash table and don't find it. */
526 unsigned int load_all_dies
: 1;
528 /* Non-zero if this CU is from .debug_types. */
529 unsigned int is_debug_types
: 1;
531 /* Non-zero if this CU is from the .dwz file. */
532 unsigned int is_dwz
: 1;
534 /* The section this CU/TU lives in.
535 If the DIE refers to a DWO file, this is always the original die,
537 struct dwarf2_section_info
*info_or_types_section
;
539 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
540 of the CU cache it gets reset to NULL again. */
541 struct dwarf2_cu
*cu
;
543 /* The corresponding objfile.
544 Normally we can get the objfile from dwarf2_per_objfile.
545 However we can enter this file with just a "per_cu" handle. */
546 struct objfile
*objfile
;
548 /* When using partial symbol tables, the 'psymtab' field is active.
549 Otherwise the 'quick' field is active. */
552 /* The partial symbol table associated with this compilation unit,
553 or NULL for unread partial units. */
554 struct partial_symtab
*psymtab
;
556 /* Data needed by the "quick" functions. */
557 struct dwarf2_per_cu_quick_data
*quick
;
562 /* The CUs we import using DW_TAG_imported_unit. This is filled in
563 while reading psymtabs, used to compute the psymtab dependencies,
564 and then cleared. Then it is filled in again while reading full
565 symbols, and only deleted when the objfile is destroyed. */
566 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
568 /* Type units are grouped by their DW_AT_stmt_list entry so that they
569 can share them. If this is a TU, this points to the containing
571 struct type_unit_group
*type_unit_group
;
575 /* Entry in the signatured_types hash table. */
577 struct signatured_type
579 /* The "per_cu" object of this type.
580 N.B.: This is the first member so that it's easy to convert pointers
582 struct dwarf2_per_cu_data per_cu
;
584 /* The type's signature. */
587 /* Offset in the TU of the type's DIE, as read from the TU header.
588 If the definition lives in a DWO file, this value is unusable. */
589 cu_offset type_offset_in_tu
;
591 /* Offset in the section of the type's DIE.
592 If the definition lives in a DWO file, this is the offset in the
593 .debug_types.dwo section.
594 The value is zero until the actual value is known.
595 Zero is otherwise not a valid section offset. */
596 sect_offset type_offset_in_section
;
599 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
600 This includes type_unit_group and quick_file_names. */
602 struct stmt_list_hash
604 /* The DWO unit this table is from or NULL if there is none. */
605 struct dwo_unit
*dwo_unit
;
607 /* Offset in .debug_line or .debug_line.dwo. */
608 sect_offset line_offset
;
611 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
612 an object of this type. */
614 struct type_unit_group
616 /* dwarf2read.c's main "handle" on the symtab.
617 To simplify things we create an artificial CU that "includes" all the
618 type units using this stmt_list so that the rest of the code still has
619 a "per_cu" handle on the symtab.
620 This PER_CU is recognized by having no section. */
621 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
622 struct dwarf2_per_cu_data per_cu
;
626 /* The TUs that share this DW_AT_stmt_list entry.
627 This is added to while parsing type units to build partial symtabs,
628 and is deleted afterwards and not used again. */
629 VEC (dwarf2_per_cu_ptr
) *tus
;
631 /* When reading the line table in "quick" functions, we need a real TU.
632 Any will do, we know they all share the same DW_AT_stmt_list entry.
633 For simplicity's sake, we pick the first one. */
634 struct dwarf2_per_cu_data
*first_tu
;
637 /* The primary symtab.
638 Type units in a group needn't all be defined in the same source file,
639 so we create an essentially anonymous symtab as the primary symtab. */
640 struct symtab
*primary_symtab
;
642 /* The data used to construct the hash key. */
643 struct stmt_list_hash hash
;
645 /* The number of symtabs from the line header.
646 The value here must match line_header.num_file_names. */
647 unsigned int num_symtabs
;
649 /* The symbol tables for this TU (obtained from the files listed in
651 WARNING: The order of entries here must match the order of entries
652 in the line header. After the first TU using this type_unit_group, the
653 line header for the subsequent TUs is recreated from this. This is done
654 because we need to use the same symtabs for each TU using the same
655 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
656 there's no guarantee the line header doesn't have duplicate entries. */
657 struct symtab
**symtabs
;
660 /* These sections are what may appear in a DWO file. */
664 struct dwarf2_section_info abbrev
;
665 struct dwarf2_section_info line
;
666 struct dwarf2_section_info loc
;
667 struct dwarf2_section_info macinfo
;
668 struct dwarf2_section_info macro
;
669 struct dwarf2_section_info str
;
670 struct dwarf2_section_info str_offsets
;
671 /* In the case of a virtual DWO file, these two are unused. */
672 struct dwarf2_section_info info
;
673 VEC (dwarf2_section_info_def
) *types
;
676 /* Common bits of DWO CUs/TUs. */
680 /* Backlink to the containing struct dwo_file. */
681 struct dwo_file
*dwo_file
;
683 /* The "id" that distinguishes this CU/TU.
684 .debug_info calls this "dwo_id", .debug_types calls this "signature".
685 Since signatures came first, we stick with it for consistency. */
688 /* The section this CU/TU lives in, in the DWO file. */
689 struct dwarf2_section_info
*info_or_types_section
;
691 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
695 /* For types, offset in the type's DIE of the type defined by this TU. */
696 cu_offset type_offset_in_tu
;
699 /* Data for one DWO file.
700 This includes virtual DWO files that have been packaged into a
705 /* The DW_AT_GNU_dwo_name attribute. This is the hash key.
706 For virtual DWO files the name is constructed from the section offsets
707 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
708 from related CU+TUs. */
711 /* The bfd, when the file is open. Otherwise this is NULL.
712 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
715 /* Section info for this file. */
716 struct dwo_sections sections
;
718 /* Table of CUs in the file.
719 Each element is a struct dwo_unit. */
722 /* Table of TUs in the file.
723 Each element is a struct dwo_unit. */
727 /* These sections are what may appear in a DWP file. */
731 struct dwarf2_section_info str
;
732 struct dwarf2_section_info cu_index
;
733 struct dwarf2_section_info tu_index
;
734 /* The .debug_info.dwo, .debug_types.dwo, and other sections are referenced
735 by section number. We don't need to record them here. */
738 /* These sections are what may appear in a virtual DWO file. */
740 struct virtual_dwo_sections
742 struct dwarf2_section_info abbrev
;
743 struct dwarf2_section_info line
;
744 struct dwarf2_section_info loc
;
745 struct dwarf2_section_info macinfo
;
746 struct dwarf2_section_info macro
;
747 struct dwarf2_section_info str_offsets
;
748 /* Each DWP hash table entry records one CU or one TU.
749 That is recorded here, and copied to dwo_unit.info_or_types_section. */
750 struct dwarf2_section_info info_or_types
;
753 /* Contents of DWP hash tables. */
755 struct dwp_hash_table
757 uint32_t nr_units
, nr_slots
;
758 const gdb_byte
*hash_table
, *unit_table
, *section_pool
;
761 /* Data for one DWP file. */
765 /* Name of the file. */
768 /* The bfd, when the file is open. Otherwise this is NULL. */
771 /* Section info for this file. */
772 struct dwp_sections sections
;
774 /* Table of CUs in the file. */
775 const struct dwp_hash_table
*cus
;
777 /* Table of TUs in the file. */
778 const struct dwp_hash_table
*tus
;
780 /* Table of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
783 /* Table to map ELF section numbers to their sections. */
784 unsigned int num_sections
;
785 asection
**elf_sections
;
788 /* This represents a '.dwz' file. */
792 /* A dwz file can only contain a few sections. */
793 struct dwarf2_section_info abbrev
;
794 struct dwarf2_section_info info
;
795 struct dwarf2_section_info str
;
796 struct dwarf2_section_info line
;
797 struct dwarf2_section_info macro
;
798 struct dwarf2_section_info gdb_index
;
804 /* Struct used to pass misc. parameters to read_die_and_children, et
805 al. which are used for both .debug_info and .debug_types dies.
806 All parameters here are unchanging for the life of the call. This
807 struct exists to abstract away the constant parameters of die reading. */
809 struct die_reader_specs
811 /* die_section->asection->owner. */
814 /* The CU of the DIE we are parsing. */
815 struct dwarf2_cu
*cu
;
817 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
818 struct dwo_file
*dwo_file
;
820 /* The section the die comes from.
821 This is either .debug_info or .debug_types, or the .dwo variants. */
822 struct dwarf2_section_info
*die_section
;
824 /* die_section->buffer. */
827 /* The end of the buffer. */
828 const gdb_byte
*buffer_end
;
831 /* Type of function passed to init_cutu_and_read_dies, et.al. */
832 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
834 struct die_info
*comp_unit_die
,
838 /* The line number information for a compilation unit (found in the
839 .debug_line section) begins with a "statement program header",
840 which contains the following information. */
843 unsigned int total_length
;
844 unsigned short version
;
845 unsigned int header_length
;
846 unsigned char minimum_instruction_length
;
847 unsigned char maximum_ops_per_instruction
;
848 unsigned char default_is_stmt
;
850 unsigned char line_range
;
851 unsigned char opcode_base
;
853 /* standard_opcode_lengths[i] is the number of operands for the
854 standard opcode whose value is i. This means that
855 standard_opcode_lengths[0] is unused, and the last meaningful
856 element is standard_opcode_lengths[opcode_base - 1]. */
857 unsigned char *standard_opcode_lengths
;
859 /* The include_directories table. NOTE! These strings are not
860 allocated with xmalloc; instead, they are pointers into
861 debug_line_buffer. If you try to free them, `free' will get
863 unsigned int num_include_dirs
, include_dirs_size
;
866 /* The file_names table. NOTE! These strings are not allocated
867 with xmalloc; instead, they are pointers into debug_line_buffer.
868 Don't try to free them directly. */
869 unsigned int num_file_names
, file_names_size
;
873 unsigned int dir_index
;
874 unsigned int mod_time
;
876 int included_p
; /* Non-zero if referenced by the Line Number Program. */
877 struct symtab
*symtab
; /* The associated symbol table, if any. */
880 /* The start and end of the statement program following this
881 header. These point into dwarf2_per_objfile->line_buffer. */
882 gdb_byte
*statement_program_start
, *statement_program_end
;
885 /* When we construct a partial symbol table entry we only
886 need this much information. */
887 struct partial_die_info
889 /* Offset of this DIE. */
892 /* DWARF-2 tag for this DIE. */
893 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
895 /* Assorted flags describing the data found in this DIE. */
896 unsigned int has_children
: 1;
897 unsigned int is_external
: 1;
898 unsigned int is_declaration
: 1;
899 unsigned int has_type
: 1;
900 unsigned int has_specification
: 1;
901 unsigned int has_pc_info
: 1;
902 unsigned int may_be_inlined
: 1;
904 /* Flag set if the SCOPE field of this structure has been
906 unsigned int scope_set
: 1;
908 /* Flag set if the DIE has a byte_size attribute. */
909 unsigned int has_byte_size
: 1;
911 /* Flag set if any of the DIE's children are template arguments. */
912 unsigned int has_template_arguments
: 1;
914 /* Flag set if fixup_partial_die has been called on this die. */
915 unsigned int fixup_called
: 1;
917 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
918 unsigned int is_dwz
: 1;
920 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
921 unsigned int spec_is_dwz
: 1;
923 /* The name of this DIE. Normally the value of DW_AT_name, but
924 sometimes a default name for unnamed DIEs. */
927 /* The linkage name, if present. */
928 const char *linkage_name
;
930 /* The scope to prepend to our children. This is generally
931 allocated on the comp_unit_obstack, so will disappear
932 when this compilation unit leaves the cache. */
935 /* Some data associated with the partial DIE. The tag determines
936 which field is live. */
939 /* The location description associated with this DIE, if any. */
940 struct dwarf_block
*locdesc
;
941 /* The offset of an import, for DW_TAG_imported_unit. */
945 /* If HAS_PC_INFO, the PC range associated with this DIE. */
949 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
950 DW_AT_sibling, if any. */
951 /* NOTE: This member isn't strictly necessary, read_partial_die could
952 return DW_AT_sibling values to its caller load_partial_dies. */
955 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
956 DW_AT_specification (or DW_AT_abstract_origin or
958 sect_offset spec_offset
;
960 /* Pointers to this DIE's parent, first child, and next sibling,
962 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
965 /* This data structure holds the information of an abbrev. */
968 unsigned int number
; /* number identifying abbrev */
969 enum dwarf_tag tag
; /* dwarf tag */
970 unsigned short has_children
; /* boolean */
971 unsigned short num_attrs
; /* number of attributes */
972 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
973 struct abbrev_info
*next
; /* next in chain */
978 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
979 ENUM_BITFIELD(dwarf_form
) form
: 16;
982 /* Size of abbrev_table.abbrev_hash_table. */
983 #define ABBREV_HASH_SIZE 121
985 /* Top level data structure to contain an abbreviation table. */
989 /* Where the abbrev table came from.
990 This is used as a sanity check when the table is used. */
993 /* Storage for the abbrev table. */
994 struct obstack abbrev_obstack
;
996 /* Hash table of abbrevs.
997 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
998 It could be statically allocated, but the previous code didn't so we
1000 struct abbrev_info
**abbrevs
;
1003 /* Attributes have a name and a value. */
1006 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1007 ENUM_BITFIELD(dwarf_form
) form
: 15;
1009 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1010 field should be in u.str (existing only for DW_STRING) but it is kept
1011 here for better struct attribute alignment. */
1012 unsigned int string_is_canonical
: 1;
1017 struct dwarf_block
*blk
;
1021 struct signatured_type
*signatured_type
;
1026 /* This data structure holds a complete die structure. */
1029 /* DWARF-2 tag for this DIE. */
1030 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1032 /* Number of attributes */
1033 unsigned char num_attrs
;
1035 /* True if we're presently building the full type name for the
1036 type derived from this DIE. */
1037 unsigned char building_fullname
: 1;
1040 unsigned int abbrev
;
1042 /* Offset in .debug_info or .debug_types section. */
1045 /* The dies in a compilation unit form an n-ary tree. PARENT
1046 points to this die's parent; CHILD points to the first child of
1047 this node; and all the children of a given node are chained
1048 together via their SIBLING fields. */
1049 struct die_info
*child
; /* Its first child, if any. */
1050 struct die_info
*sibling
; /* Its next sibling, if any. */
1051 struct die_info
*parent
; /* Its parent, if any. */
1053 /* An array of attributes, with NUM_ATTRS elements. There may be
1054 zero, but it's not common and zero-sized arrays are not
1055 sufficiently portable C. */
1056 struct attribute attrs
[1];
1059 /* Get at parts of an attribute structure. */
1061 #define DW_STRING(attr) ((attr)->u.str)
1062 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1063 #define DW_UNSND(attr) ((attr)->u.unsnd)
1064 #define DW_BLOCK(attr) ((attr)->u.blk)
1065 #define DW_SND(attr) ((attr)->u.snd)
1066 #define DW_ADDR(attr) ((attr)->u.addr)
1067 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
1069 /* Blocks are a bunch of untyped bytes. */
1074 /* Valid only if SIZE is not zero. */
1078 #ifndef ATTR_ALLOC_CHUNK
1079 #define ATTR_ALLOC_CHUNK 4
1082 /* Allocate fields for structs, unions and enums in this size. */
1083 #ifndef DW_FIELD_ALLOC_CHUNK
1084 #define DW_FIELD_ALLOC_CHUNK 4
1087 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1088 but this would require a corresponding change in unpack_field_as_long
1090 static int bits_per_byte
= 8;
1092 /* The routines that read and process dies for a C struct or C++ class
1093 pass lists of data member fields and lists of member function fields
1094 in an instance of a field_info structure, as defined below. */
1097 /* List of data member and baseclasses fields. */
1100 struct nextfield
*next
;
1105 *fields
, *baseclasses
;
1107 /* Number of fields (including baseclasses). */
1110 /* Number of baseclasses. */
1113 /* Set if the accesibility of one of the fields is not public. */
1114 int non_public_fields
;
1116 /* Member function fields array, entries are allocated in the order they
1117 are encountered in the object file. */
1120 struct nextfnfield
*next
;
1121 struct fn_field fnfield
;
1125 /* Member function fieldlist array, contains name of possibly overloaded
1126 member function, number of overloaded member functions and a pointer
1127 to the head of the member function field chain. */
1132 struct nextfnfield
*head
;
1136 /* Number of entries in the fnfieldlists array. */
1139 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1140 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1141 struct typedef_field_list
1143 struct typedef_field field
;
1144 struct typedef_field_list
*next
;
1146 *typedef_field_list
;
1147 unsigned typedef_field_list_count
;
1150 /* One item on the queue of compilation units to read in full symbols
1152 struct dwarf2_queue_item
1154 struct dwarf2_per_cu_data
*per_cu
;
1155 enum language pretend_language
;
1156 struct dwarf2_queue_item
*next
;
1159 /* The current queue. */
1160 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1162 /* Loaded secondary compilation units are kept in memory until they
1163 have not been referenced for the processing of this many
1164 compilation units. Set this to zero to disable caching. Cache
1165 sizes of up to at least twenty will improve startup time for
1166 typical inter-CU-reference binaries, at an obvious memory cost. */
1167 static int dwarf2_max_cache_age
= 5;
1169 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1170 struct cmd_list_element
*c
, const char *value
)
1172 fprintf_filtered (file
, _("The upper bound on the age of cached "
1173 "dwarf2 compilation units is %s.\n"),
1178 /* Various complaints about symbol reading that don't abort the process. */
1181 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1183 complaint (&symfile_complaints
,
1184 _("statement list doesn't fit in .debug_line section"));
1188 dwarf2_debug_line_missing_file_complaint (void)
1190 complaint (&symfile_complaints
,
1191 _(".debug_line section has line data without a file"));
1195 dwarf2_debug_line_missing_end_sequence_complaint (void)
1197 complaint (&symfile_complaints
,
1198 _(".debug_line section has line "
1199 "program sequence without an end"));
1203 dwarf2_complex_location_expr_complaint (void)
1205 complaint (&symfile_complaints
, _("location expression too complex"));
1209 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1212 complaint (&symfile_complaints
,
1213 _("const value length mismatch for '%s', got %d, expected %d"),
1218 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1220 complaint (&symfile_complaints
,
1221 _("debug info runs off end of %s section"
1223 section
->asection
->name
,
1224 bfd_get_filename (section
->asection
->owner
));
1228 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1230 complaint (&symfile_complaints
,
1231 _("macro debug info contains a "
1232 "malformed macro definition:\n`%s'"),
1237 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1239 complaint (&symfile_complaints
,
1240 _("invalid attribute class or form for '%s' in '%s'"),
1244 /* local function prototypes */
1246 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1248 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1251 static void dwarf2_find_base_address (struct die_info
*die
,
1252 struct dwarf2_cu
*cu
);
1254 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1256 static void scan_partial_symbols (struct partial_die_info
*,
1257 CORE_ADDR
*, CORE_ADDR
*,
1258 int, struct dwarf2_cu
*);
1260 static void add_partial_symbol (struct partial_die_info
*,
1261 struct dwarf2_cu
*);
1263 static void add_partial_namespace (struct partial_die_info
*pdi
,
1264 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1265 int need_pc
, struct dwarf2_cu
*cu
);
1267 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1268 CORE_ADDR
*highpc
, int need_pc
,
1269 struct dwarf2_cu
*cu
);
1271 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1272 struct dwarf2_cu
*cu
);
1274 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1275 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1276 int need_pc
, struct dwarf2_cu
*cu
);
1278 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1280 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1282 static struct abbrev_info
*abbrev_table_lookup_abbrev
1283 (const struct abbrev_table
*, unsigned int);
1285 static struct abbrev_table
*abbrev_table_read_table
1286 (struct dwarf2_section_info
*, sect_offset
);
1288 static void abbrev_table_free (struct abbrev_table
*);
1290 static void abbrev_table_free_cleanup (void *);
1292 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1293 struct dwarf2_section_info
*);
1295 static void dwarf2_free_abbrev_table (void *);
1297 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1299 static struct partial_die_info
*load_partial_dies
1300 (const struct die_reader_specs
*, gdb_byte
*, int);
1302 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1303 struct partial_die_info
*,
1304 struct abbrev_info
*,
1308 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1309 struct dwarf2_cu
*);
1311 static void fixup_partial_die (struct partial_die_info
*,
1312 struct dwarf2_cu
*);
1314 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1315 struct attribute
*, struct attr_abbrev
*,
1318 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1320 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1322 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1324 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1326 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1328 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1331 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1333 static LONGEST read_checked_initial_length_and_offset
1334 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1335 unsigned int *, unsigned int *);
1337 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1340 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1342 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1345 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1347 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1349 static char *read_indirect_string (bfd
*, gdb_byte
*,
1350 const struct comp_unit_head
*,
1353 static char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1355 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1357 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1359 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1362 static char *read_str_index (const struct die_reader_specs
*reader
,
1363 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1365 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1367 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1368 struct dwarf2_cu
*);
1370 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1373 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1374 struct dwarf2_cu
*cu
);
1376 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1378 static struct die_info
*die_specification (struct die_info
*die
,
1379 struct dwarf2_cu
**);
1381 static void free_line_header (struct line_header
*lh
);
1383 static void add_file_name (struct line_header
*, char *, unsigned int,
1384 unsigned int, unsigned int);
1386 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1387 struct dwarf2_cu
*cu
);
1389 static void dwarf_decode_lines (struct line_header
*, const char *,
1390 struct dwarf2_cu
*, struct partial_symtab
*,
1393 static void dwarf2_start_subfile (char *, const char *, const char *);
1395 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1396 char *, char *, CORE_ADDR
);
1398 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1399 struct dwarf2_cu
*);
1401 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1402 struct dwarf2_cu
*, struct symbol
*);
1404 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1405 struct dwarf2_cu
*);
1407 static void dwarf2_const_value_attr (struct attribute
*attr
,
1410 struct obstack
*obstack
,
1411 struct dwarf2_cu
*cu
, LONGEST
*value
,
1413 struct dwarf2_locexpr_baton
**baton
);
1415 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1417 static int need_gnat_info (struct dwarf2_cu
*);
1419 static struct type
*die_descriptive_type (struct die_info
*,
1420 struct dwarf2_cu
*);
1422 static void set_descriptive_type (struct type
*, struct die_info
*,
1423 struct dwarf2_cu
*);
1425 static struct type
*die_containing_type (struct die_info
*,
1426 struct dwarf2_cu
*);
1428 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1429 struct dwarf2_cu
*);
1431 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1433 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1435 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1437 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1438 const char *suffix
, int physname
,
1439 struct dwarf2_cu
*cu
);
1441 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1443 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1445 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1447 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1449 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1451 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1452 struct dwarf2_cu
*, struct partial_symtab
*);
1454 static int dwarf2_get_pc_bounds (struct die_info
*,
1455 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1456 struct partial_symtab
*);
1458 static void get_scope_pc_bounds (struct die_info
*,
1459 CORE_ADDR
*, CORE_ADDR
*,
1460 struct dwarf2_cu
*);
1462 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1463 CORE_ADDR
, struct dwarf2_cu
*);
1465 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1466 struct dwarf2_cu
*);
1468 static void dwarf2_attach_fields_to_type (struct field_info
*,
1469 struct type
*, struct dwarf2_cu
*);
1471 static void dwarf2_add_member_fn (struct field_info
*,
1472 struct die_info
*, struct type
*,
1473 struct dwarf2_cu
*);
1475 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1477 struct dwarf2_cu
*);
1479 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1481 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1483 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1485 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1487 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1489 static struct type
*read_module_type (struct die_info
*die
,
1490 struct dwarf2_cu
*cu
);
1492 static const char *namespace_name (struct die_info
*die
,
1493 int *is_anonymous
, struct dwarf2_cu
*);
1495 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1497 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1499 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1500 struct dwarf2_cu
*);
1502 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1504 gdb_byte
**new_info_ptr
,
1505 struct die_info
*parent
);
1507 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1509 gdb_byte
**new_info_ptr
,
1510 struct die_info
*parent
);
1512 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1513 struct die_info
**, gdb_byte
*, int *, int);
1515 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1516 struct die_info
**, gdb_byte
*, int *);
1518 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1520 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1523 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1525 static const char *dwarf2_full_name (char *name
,
1526 struct die_info
*die
,
1527 struct dwarf2_cu
*cu
);
1529 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1530 struct dwarf2_cu
**);
1532 static const char *dwarf_tag_name (unsigned int);
1534 static const char *dwarf_attr_name (unsigned int);
1536 static const char *dwarf_form_name (unsigned int);
1538 static char *dwarf_bool_name (unsigned int);
1540 static const char *dwarf_type_encoding_name (unsigned int);
1542 static struct die_info
*sibling_die (struct die_info
*);
1544 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1546 static void dump_die_for_error (struct die_info
*);
1548 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1551 /*static*/ void dump_die (struct die_info
*, int max_level
);
1553 static void store_in_ref_table (struct die_info
*,
1554 struct dwarf2_cu
*);
1556 static int is_ref_attr (struct attribute
*);
1558 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1560 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1562 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1564 struct dwarf2_cu
**);
1566 static struct die_info
*follow_die_ref (struct die_info
*,
1568 struct dwarf2_cu
**);
1570 static struct die_info
*follow_die_sig (struct die_info
*,
1572 struct dwarf2_cu
**);
1574 static struct signatured_type
*lookup_signatured_type_at_offset
1575 (struct objfile
*objfile
,
1576 struct dwarf2_section_info
*section
, sect_offset offset
);
1578 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1580 static void read_signatured_type (struct signatured_type
*);
1582 static struct type_unit_group
*get_type_unit_group
1583 (struct dwarf2_cu
*, struct attribute
*);
1585 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1587 /* memory allocation interface */
1589 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1591 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1593 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1596 static int attr_form_is_block (struct attribute
*);
1598 static int attr_form_is_section_offset (struct attribute
*);
1600 static int attr_form_is_constant (struct attribute
*);
1602 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1603 struct dwarf2_loclist_baton
*baton
,
1604 struct attribute
*attr
);
1606 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1608 struct dwarf2_cu
*cu
);
1610 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1612 struct abbrev_info
*abbrev
);
1614 static void free_stack_comp_unit (void *);
1616 static hashval_t
partial_die_hash (const void *item
);
1618 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1620 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1621 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1623 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1624 struct dwarf2_per_cu_data
*per_cu
);
1626 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1627 struct die_info
*comp_unit_die
,
1628 enum language pretend_language
);
1630 static void free_heap_comp_unit (void *);
1632 static void free_cached_comp_units (void *);
1634 static void age_cached_comp_units (void);
1636 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1638 static struct type
*set_die_type (struct die_info
*, struct type
*,
1639 struct dwarf2_cu
*);
1641 static void create_all_comp_units (struct objfile
*);
1643 static int create_all_type_units (struct objfile
*);
1645 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1648 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1651 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1654 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1655 struct dwarf2_per_cu_data
*);
1657 static void dwarf2_mark (struct dwarf2_cu
*);
1659 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1661 static struct type
*get_die_type_at_offset (sect_offset
,
1662 struct dwarf2_per_cu_data
*per_cu
);
1664 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1666 static void dwarf2_release_queue (void *dummy
);
1668 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1669 enum language pretend_language
);
1671 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1672 struct dwarf2_per_cu_data
*per_cu
,
1673 enum language pretend_language
);
1675 static void process_queue (void);
1677 static void find_file_and_directory (struct die_info
*die
,
1678 struct dwarf2_cu
*cu
,
1679 char **name
, char **comp_dir
);
1681 static char *file_full_name (int file
, struct line_header
*lh
,
1682 const char *comp_dir
);
1684 static gdb_byte
*read_and_check_comp_unit_head
1685 (struct comp_unit_head
*header
,
1686 struct dwarf2_section_info
*section
,
1687 struct dwarf2_section_info
*abbrev_section
, gdb_byte
*info_ptr
,
1688 int is_debug_types_section
);
1690 static void init_cutu_and_read_dies
1691 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1692 int use_existing_cu
, int keep
,
1693 die_reader_func_ftype
*die_reader_func
, void *data
);
1695 static void init_cutu_and_read_dies_simple
1696 (struct dwarf2_per_cu_data
*this_cu
,
1697 die_reader_func_ftype
*die_reader_func
, void *data
);
1699 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1701 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1703 static struct dwo_unit
*lookup_dwo_comp_unit
1704 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1706 static struct dwo_unit
*lookup_dwo_type_unit
1707 (struct signatured_type
*, const char *, const char *);
1709 static void free_dwo_file_cleanup (void *);
1711 static void process_cu_includes (void);
1715 /* Convert VALUE between big- and little-endian. */
1717 byte_swap (offset_type value
)
1721 result
= (value
& 0xff) << 24;
1722 result
|= (value
& 0xff00) << 8;
1723 result
|= (value
& 0xff0000) >> 8;
1724 result
|= (value
& 0xff000000) >> 24;
1728 #define MAYBE_SWAP(V) byte_swap (V)
1731 #define MAYBE_SWAP(V) (V)
1732 #endif /* WORDS_BIGENDIAN */
1734 /* The suffix for an index file. */
1735 #define INDEX_SUFFIX ".gdb-index"
1737 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1738 struct dwarf2_cu
*cu
);
1740 /* Try to locate the sections we need for DWARF 2 debugging
1741 information and return true if we have enough to do something.
1742 NAMES points to the dwarf2 section names, or is NULL if the standard
1743 ELF names are used. */
1746 dwarf2_has_info (struct objfile
*objfile
,
1747 const struct dwarf2_debug_sections
*names
)
1749 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1750 if (!dwarf2_per_objfile
)
1752 /* Initialize per-objfile state. */
1753 struct dwarf2_per_objfile
*data
1754 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1756 memset (data
, 0, sizeof (*data
));
1757 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1758 dwarf2_per_objfile
= data
;
1760 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1762 dwarf2_per_objfile
->objfile
= objfile
;
1764 return (dwarf2_per_objfile
->info
.asection
!= NULL
1765 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1768 /* When loading sections, we look either for uncompressed section or for
1769 compressed section names. */
1772 section_is_p (const char *section_name
,
1773 const struct dwarf2_section_names
*names
)
1775 if (names
->normal
!= NULL
1776 && strcmp (section_name
, names
->normal
) == 0)
1778 if (names
->compressed
!= NULL
1779 && strcmp (section_name
, names
->compressed
) == 0)
1784 /* This function is mapped across the sections and remembers the
1785 offset and size of each of the debugging sections we are interested
1789 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1791 const struct dwarf2_debug_sections
*names
;
1792 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1795 names
= &dwarf2_elf_names
;
1797 names
= (const struct dwarf2_debug_sections
*) vnames
;
1799 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1802 else if (section_is_p (sectp
->name
, &names
->info
))
1804 dwarf2_per_objfile
->info
.asection
= sectp
;
1805 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1807 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1809 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1810 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1812 else if (section_is_p (sectp
->name
, &names
->line
))
1814 dwarf2_per_objfile
->line
.asection
= sectp
;
1815 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1817 else if (section_is_p (sectp
->name
, &names
->loc
))
1819 dwarf2_per_objfile
->loc
.asection
= sectp
;
1820 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1822 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1824 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1825 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1827 else if (section_is_p (sectp
->name
, &names
->macro
))
1829 dwarf2_per_objfile
->macro
.asection
= sectp
;
1830 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1832 else if (section_is_p (sectp
->name
, &names
->str
))
1834 dwarf2_per_objfile
->str
.asection
= sectp
;
1835 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1837 else if (section_is_p (sectp
->name
, &names
->addr
))
1839 dwarf2_per_objfile
->addr
.asection
= sectp
;
1840 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1842 else if (section_is_p (sectp
->name
, &names
->frame
))
1844 dwarf2_per_objfile
->frame
.asection
= sectp
;
1845 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1847 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1849 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1850 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1852 else if (section_is_p (sectp
->name
, &names
->ranges
))
1854 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1855 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1857 else if (section_is_p (sectp
->name
, &names
->types
))
1859 struct dwarf2_section_info type_section
;
1861 memset (&type_section
, 0, sizeof (type_section
));
1862 type_section
.asection
= sectp
;
1863 type_section
.size
= bfd_get_section_size (sectp
);
1865 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1868 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1870 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1871 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1874 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1875 && bfd_section_vma (abfd
, sectp
) == 0)
1876 dwarf2_per_objfile
->has_section_at_zero
= 1;
1879 /* A helper function that decides whether a section is empty,
1883 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1885 return info
->asection
== NULL
|| info
->size
== 0;
1888 /* Read the contents of the section INFO.
1889 OBJFILE is the main object file, but not necessarily the file where
1890 the section comes from. E.g., for DWO files INFO->asection->owner
1891 is the bfd of the DWO file.
1892 If the section is compressed, uncompress it before returning. */
1895 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1897 asection
*sectp
= info
->asection
;
1899 gdb_byte
*buf
, *retbuf
;
1900 unsigned char header
[4];
1904 info
->buffer
= NULL
;
1907 if (dwarf2_section_empty_p (info
))
1910 abfd
= sectp
->owner
;
1912 /* If the section has relocations, we must read it ourselves.
1913 Otherwise we attach it to the BFD. */
1914 if ((sectp
->flags
& SEC_RELOC
) == 0)
1916 const gdb_byte
*bytes
= gdb_bfd_map_section (sectp
, &info
->size
);
1918 /* We have to cast away const here for historical reasons.
1919 Fixing dwarf2read to be const-correct would be quite nice. */
1920 info
->buffer
= (gdb_byte
*) bytes
;
1924 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1927 /* When debugging .o files, we may need to apply relocations; see
1928 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1929 We never compress sections in .o files, so we only need to
1930 try this when the section is not compressed. */
1931 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1934 info
->buffer
= retbuf
;
1938 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1939 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1940 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1941 bfd_get_filename (abfd
));
1944 /* A helper function that returns the size of a section in a safe way.
1945 If you are positive that the section has been read before using the
1946 size, then it is safe to refer to the dwarf2_section_info object's
1947 "size" field directly. In other cases, you must call this
1948 function, because for compressed sections the size field is not set
1949 correctly until the section has been read. */
1951 static bfd_size_type
1952 dwarf2_section_size (struct objfile
*objfile
,
1953 struct dwarf2_section_info
*info
)
1956 dwarf2_read_section (objfile
, info
);
1960 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1964 dwarf2_get_section_info (struct objfile
*objfile
,
1965 enum dwarf2_section_enum sect
,
1966 asection
**sectp
, gdb_byte
**bufp
,
1967 bfd_size_type
*sizep
)
1969 struct dwarf2_per_objfile
*data
1970 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1971 struct dwarf2_section_info
*info
;
1973 /* We may see an objfile without any DWARF, in which case we just
1984 case DWARF2_DEBUG_FRAME
:
1985 info
= &data
->frame
;
1987 case DWARF2_EH_FRAME
:
1988 info
= &data
->eh_frame
;
1991 gdb_assert_not_reached ("unexpected section");
1994 dwarf2_read_section (objfile
, info
);
1996 *sectp
= info
->asection
;
1997 *bufp
= info
->buffer
;
1998 *sizep
= info
->size
;
2001 /* A helper function to find the sections for a .dwz file. */
2004 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2006 struct dwz_file
*dwz_file
= arg
;
2008 /* Note that we only support the standard ELF names, because .dwz
2009 is ELF-only (at the time of writing). */
2010 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2012 dwz_file
->abbrev
.asection
= sectp
;
2013 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2015 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2017 dwz_file
->info
.asection
= sectp
;
2018 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2020 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2022 dwz_file
->str
.asection
= sectp
;
2023 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2025 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2027 dwz_file
->line
.asection
= sectp
;
2028 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2030 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2032 dwz_file
->macro
.asection
= sectp
;
2033 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2035 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2037 dwz_file
->gdb_index
.asection
= sectp
;
2038 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2042 /* Open the separate '.dwz' debug file, if needed. Error if the file
2045 static struct dwz_file
*
2046 dwarf2_get_dwz_file (void)
2048 bfd
*abfd
, *dwz_bfd
;
2051 struct cleanup
*cleanup
;
2052 const char *filename
;
2053 struct dwz_file
*result
;
2055 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2056 return dwarf2_per_objfile
->dwz_file
;
2058 abfd
= dwarf2_per_objfile
->objfile
->obfd
;
2059 section
= bfd_get_section_by_name (abfd
, ".gnu_debugaltlink");
2060 if (section
== NULL
)
2061 error (_("could not find '.gnu_debugaltlink' section"));
2062 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
2063 error (_("could not read '.gnu_debugaltlink' section: %s"),
2064 bfd_errmsg (bfd_get_error ()));
2065 cleanup
= make_cleanup (xfree
, data
);
2068 if (!IS_ABSOLUTE_PATH (filename
))
2070 char *abs
= gdb_realpath (dwarf2_per_objfile
->objfile
->name
);
2073 make_cleanup (xfree
, abs
);
2074 abs
= ldirname (abs
);
2075 make_cleanup (xfree
, abs
);
2077 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2078 make_cleanup (xfree
, rel
);
2082 /* The format is just a NUL-terminated file name, followed by the
2083 build-id. For now, though, we ignore the build-id. */
2084 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2085 if (dwz_bfd
== NULL
)
2086 error (_("could not read '%s': %s"), filename
,
2087 bfd_errmsg (bfd_get_error ()));
2089 if (!bfd_check_format (dwz_bfd
, bfd_object
))
2091 gdb_bfd_unref (dwz_bfd
);
2092 error (_("file '%s' was not usable: %s"), filename
,
2093 bfd_errmsg (bfd_get_error ()));
2096 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2098 result
->dwz_bfd
= dwz_bfd
;
2100 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2102 do_cleanups (cleanup
);
2107 /* DWARF quick_symbols_functions support. */
2109 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2110 unique line tables, so we maintain a separate table of all .debug_line
2111 derived entries to support the sharing.
2112 All the quick functions need is the list of file names. We discard the
2113 line_header when we're done and don't need to record it here. */
2114 struct quick_file_names
2116 /* The data used to construct the hash key. */
2117 struct stmt_list_hash hash
;
2119 /* The number of entries in file_names, real_names. */
2120 unsigned int num_file_names
;
2122 /* The file names from the line table, after being run through
2124 const char **file_names
;
2126 /* The file names from the line table after being run through
2127 gdb_realpath. These are computed lazily. */
2128 const char **real_names
;
2131 /* When using the index (and thus not using psymtabs), each CU has an
2132 object of this type. This is used to hold information needed by
2133 the various "quick" methods. */
2134 struct dwarf2_per_cu_quick_data
2136 /* The file table. This can be NULL if there was no file table
2137 or it's currently not read in.
2138 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2139 struct quick_file_names
*file_names
;
2141 /* The corresponding symbol table. This is NULL if symbols for this
2142 CU have not yet been read. */
2143 struct symtab
*symtab
;
2145 /* A temporary mark bit used when iterating over all CUs in
2146 expand_symtabs_matching. */
2147 unsigned int mark
: 1;
2149 /* True if we've tried to read the file table and found there isn't one.
2150 There will be no point in trying to read it again next time. */
2151 unsigned int no_file_data
: 1;
2154 /* Utility hash function for a stmt_list_hash. */
2157 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2161 if (stmt_list_hash
->dwo_unit
!= NULL
)
2162 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2163 v
+= stmt_list_hash
->line_offset
.sect_off
;
2167 /* Utility equality function for a stmt_list_hash. */
2170 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2171 const struct stmt_list_hash
*rhs
)
2173 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2175 if (lhs
->dwo_unit
!= NULL
2176 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2179 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2182 /* Hash function for a quick_file_names. */
2185 hash_file_name_entry (const void *e
)
2187 const struct quick_file_names
*file_data
= e
;
2189 return hash_stmt_list_entry (&file_data
->hash
);
2192 /* Equality function for a quick_file_names. */
2195 eq_file_name_entry (const void *a
, const void *b
)
2197 const struct quick_file_names
*ea
= a
;
2198 const struct quick_file_names
*eb
= b
;
2200 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2203 /* Delete function for a quick_file_names. */
2206 delete_file_name_entry (void *e
)
2208 struct quick_file_names
*file_data
= e
;
2211 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2213 xfree ((void*) file_data
->file_names
[i
]);
2214 if (file_data
->real_names
)
2215 xfree ((void*) file_data
->real_names
[i
]);
2218 /* The space for the struct itself lives on objfile_obstack,
2219 so we don't free it here. */
2222 /* Create a quick_file_names hash table. */
2225 create_quick_file_names_table (unsigned int nr_initial_entries
)
2227 return htab_create_alloc (nr_initial_entries
,
2228 hash_file_name_entry
, eq_file_name_entry
,
2229 delete_file_name_entry
, xcalloc
, xfree
);
2232 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2233 have to be created afterwards. You should call age_cached_comp_units after
2234 processing PER_CU->CU. dw2_setup must have been already called. */
2237 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2239 if (per_cu
->is_debug_types
)
2240 load_full_type_unit (per_cu
);
2242 load_full_comp_unit (per_cu
, language_minimal
);
2244 gdb_assert (per_cu
->cu
!= NULL
);
2246 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2249 /* Read in the symbols for PER_CU. */
2252 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2254 struct cleanup
*back_to
;
2256 /* Skip type_unit_groups, reading the type units they contain
2257 is handled elsewhere. */
2258 if (IS_TYPE_UNIT_GROUP (per_cu
))
2261 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2263 if (dwarf2_per_objfile
->using_index
2264 ? per_cu
->v
.quick
->symtab
== NULL
2265 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2267 queue_comp_unit (per_cu
, language_minimal
);
2273 /* Age the cache, releasing compilation units that have not
2274 been used recently. */
2275 age_cached_comp_units ();
2277 do_cleanups (back_to
);
2280 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2281 the objfile from which this CU came. Returns the resulting symbol
2284 static struct symtab
*
2285 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2287 gdb_assert (dwarf2_per_objfile
->using_index
);
2288 if (!per_cu
->v
.quick
->symtab
)
2290 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2291 increment_reading_symtab ();
2292 dw2_do_instantiate_symtab (per_cu
);
2293 process_cu_includes ();
2294 do_cleanups (back_to
);
2296 return per_cu
->v
.quick
->symtab
;
2299 /* Return the CU given its index.
2301 This is intended for loops like:
2303 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2304 + dwarf2_per_objfile->n_type_units); ++i)
2306 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2312 static struct dwarf2_per_cu_data
*
2313 dw2_get_cu (int index
)
2315 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2317 index
-= dwarf2_per_objfile
->n_comp_units
;
2318 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2319 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2322 return dwarf2_per_objfile
->all_comp_units
[index
];
2325 /* Return the primary CU given its index.
2326 The difference between this function and dw2_get_cu is in the handling
2327 of type units (TUs). Here we return the type_unit_group object.
2329 This is intended for loops like:
2331 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2332 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2334 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2340 static struct dwarf2_per_cu_data
*
2341 dw2_get_primary_cu (int index
)
2343 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2345 index
-= dwarf2_per_objfile
->n_comp_units
;
2346 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2347 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2350 return dwarf2_per_objfile
->all_comp_units
[index
];
2353 /* A helper function that knows how to read a 64-bit value in a way
2354 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2358 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2360 if (sizeof (ULONGEST
) < 8)
2364 /* Ignore the upper 4 bytes if they are all zero. */
2365 for (i
= 0; i
< 4; ++i
)
2366 if (bytes
[i
+ 4] != 0)
2369 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2372 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2376 /* A helper for create_cus_from_index that handles a given list of
2380 create_cus_from_index_list (struct objfile
*objfile
,
2381 const gdb_byte
*cu_list
, offset_type n_elements
,
2382 struct dwarf2_section_info
*section
,
2388 for (i
= 0; i
< n_elements
; i
+= 2)
2390 struct dwarf2_per_cu_data
*the_cu
;
2391 ULONGEST offset
, length
;
2393 if (!extract_cu_value (cu_list
, &offset
)
2394 || !extract_cu_value (cu_list
+ 8, &length
))
2398 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2399 struct dwarf2_per_cu_data
);
2400 the_cu
->offset
.sect_off
= offset
;
2401 the_cu
->length
= length
;
2402 the_cu
->objfile
= objfile
;
2403 the_cu
->info_or_types_section
= section
;
2404 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2405 struct dwarf2_per_cu_quick_data
);
2406 the_cu
->is_dwz
= is_dwz
;
2407 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2413 /* Read the CU list from the mapped index, and use it to create all
2414 the CU objects for this objfile. Return 0 if something went wrong,
2415 1 if everything went ok. */
2418 create_cus_from_index (struct objfile
*objfile
,
2419 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2420 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2422 struct dwz_file
*dwz
;
2424 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2425 dwarf2_per_objfile
->all_comp_units
2426 = obstack_alloc (&objfile
->objfile_obstack
,
2427 dwarf2_per_objfile
->n_comp_units
2428 * sizeof (struct dwarf2_per_cu_data
*));
2430 if (!create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2431 &dwarf2_per_objfile
->info
, 0, 0))
2434 if (dwz_elements
== 0)
2437 dwz
= dwarf2_get_dwz_file ();
2438 return create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
,
2439 &dwz
->info
, 1, cu_list_elements
/ 2);
2442 /* Create the signatured type hash table from the index. */
2445 create_signatured_type_table_from_index (struct objfile
*objfile
,
2446 struct dwarf2_section_info
*section
,
2447 const gdb_byte
*bytes
,
2448 offset_type elements
)
2451 htab_t sig_types_hash
;
2453 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2454 dwarf2_per_objfile
->all_type_units
2455 = obstack_alloc (&objfile
->objfile_obstack
,
2456 dwarf2_per_objfile
->n_type_units
2457 * sizeof (struct signatured_type
*));
2459 sig_types_hash
= allocate_signatured_type_table (objfile
);
2461 for (i
= 0; i
< elements
; i
+= 3)
2463 struct signatured_type
*sig_type
;
2464 ULONGEST offset
, type_offset_in_tu
, signature
;
2467 if (!extract_cu_value (bytes
, &offset
)
2468 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2470 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2473 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2474 struct signatured_type
);
2475 sig_type
->signature
= signature
;
2476 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2477 sig_type
->per_cu
.is_debug_types
= 1;
2478 sig_type
->per_cu
.info_or_types_section
= section
;
2479 sig_type
->per_cu
.offset
.sect_off
= offset
;
2480 sig_type
->per_cu
.objfile
= objfile
;
2481 sig_type
->per_cu
.v
.quick
2482 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2483 struct dwarf2_per_cu_quick_data
);
2485 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2488 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2491 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2496 /* Read the address map data from the mapped index, and use it to
2497 populate the objfile's psymtabs_addrmap. */
2500 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2502 const gdb_byte
*iter
, *end
;
2503 struct obstack temp_obstack
;
2504 struct addrmap
*mutable_map
;
2505 struct cleanup
*cleanup
;
2508 obstack_init (&temp_obstack
);
2509 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2510 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2512 iter
= index
->address_table
;
2513 end
= iter
+ index
->address_table_size
;
2515 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2519 ULONGEST hi
, lo
, cu_index
;
2520 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2522 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2524 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2527 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2528 dw2_get_cu (cu_index
));
2531 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2532 &objfile
->objfile_obstack
);
2533 do_cleanups (cleanup
);
2536 /* The hash function for strings in the mapped index. This is the same as
2537 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2538 implementation. This is necessary because the hash function is tied to the
2539 format of the mapped index file. The hash values do not have to match with
2542 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2545 mapped_index_string_hash (int index_version
, const void *p
)
2547 const unsigned char *str
= (const unsigned char *) p
;
2551 while ((c
= *str
++) != 0)
2553 if (index_version
>= 5)
2555 r
= r
* 67 + c
- 113;
2561 /* Find a slot in the mapped index INDEX for the object named NAME.
2562 If NAME is found, set *VEC_OUT to point to the CU vector in the
2563 constant pool and return 1. If NAME cannot be found, return 0. */
2566 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2567 offset_type
**vec_out
)
2569 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2571 offset_type slot
, step
;
2572 int (*cmp
) (const char *, const char *);
2574 if (current_language
->la_language
== language_cplus
2575 || current_language
->la_language
== language_java
2576 || current_language
->la_language
== language_fortran
)
2578 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2580 const char *paren
= strchr (name
, '(');
2586 dup
= xmalloc (paren
- name
+ 1);
2587 memcpy (dup
, name
, paren
- name
);
2588 dup
[paren
- name
] = 0;
2590 make_cleanup (xfree
, dup
);
2595 /* Index version 4 did not support case insensitive searches. But the
2596 indices for case insensitive languages are built in lowercase, therefore
2597 simulate our NAME being searched is also lowercased. */
2598 hash
= mapped_index_string_hash ((index
->version
== 4
2599 && case_sensitivity
== case_sensitive_off
2600 ? 5 : index
->version
),
2603 slot
= hash
& (index
->symbol_table_slots
- 1);
2604 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2605 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2609 /* Convert a slot number to an offset into the table. */
2610 offset_type i
= 2 * slot
;
2612 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2614 do_cleanups (back_to
);
2618 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2619 if (!cmp (name
, str
))
2621 *vec_out
= (offset_type
*) (index
->constant_pool
2622 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2623 do_cleanups (back_to
);
2627 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2631 /* A helper function that reads the .gdb_index from SECTION and fills
2632 in MAP. FILENAME is the name of the file containing the section;
2633 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2634 ok to use deprecated sections.
2636 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2637 out parameters that are filled in with information about the CU and
2638 TU lists in the section.
2640 Returns 1 if all went well, 0 otherwise. */
2643 read_index_from_section (struct objfile
*objfile
,
2644 const char *filename
,
2646 struct dwarf2_section_info
*section
,
2647 struct mapped_index
*map
,
2648 const gdb_byte
**cu_list
,
2649 offset_type
*cu_list_elements
,
2650 const gdb_byte
**types_list
,
2651 offset_type
*types_list_elements
)
2654 offset_type version
;
2655 offset_type
*metadata
;
2658 if (dwarf2_section_empty_p (section
))
2661 /* Older elfutils strip versions could keep the section in the main
2662 executable while splitting it for the separate debug info file. */
2663 if ((bfd_get_file_flags (section
->asection
) & SEC_HAS_CONTENTS
) == 0)
2666 dwarf2_read_section (objfile
, section
);
2668 addr
= section
->buffer
;
2669 /* Version check. */
2670 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2671 /* Versions earlier than 3 emitted every copy of a psymbol. This
2672 causes the index to behave very poorly for certain requests. Version 3
2673 contained incomplete addrmap. So, it seems better to just ignore such
2677 static int warning_printed
= 0;
2678 if (!warning_printed
)
2680 warning (_("Skipping obsolete .gdb_index section in %s."),
2682 warning_printed
= 1;
2686 /* Index version 4 uses a different hash function than index version
2689 Versions earlier than 6 did not emit psymbols for inlined
2690 functions. Using these files will cause GDB not to be able to
2691 set breakpoints on inlined functions by name, so we ignore these
2692 indices unless the user has done
2693 "set use-deprecated-index-sections on". */
2694 if (version
< 6 && !deprecated_ok
)
2696 static int warning_printed
= 0;
2697 if (!warning_printed
)
2700 Skipping deprecated .gdb_index section in %s.\n\
2701 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2702 to use the section anyway."),
2704 warning_printed
= 1;
2708 /* Indexes with higher version than the one supported by GDB may be no
2709 longer backward compatible. */
2713 map
->version
= version
;
2714 map
->total_size
= section
->size
;
2716 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2719 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2720 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2724 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2725 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2726 - MAYBE_SWAP (metadata
[i
]))
2730 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2731 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2732 - MAYBE_SWAP (metadata
[i
]));
2735 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2736 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2737 - MAYBE_SWAP (metadata
[i
]))
2738 / (2 * sizeof (offset_type
)));
2741 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2747 /* Read the index file. If everything went ok, initialize the "quick"
2748 elements of all the CUs and return 1. Otherwise, return 0. */
2751 dwarf2_read_index (struct objfile
*objfile
)
2753 struct mapped_index local_map
, *map
;
2754 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2755 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2757 if (!read_index_from_section (objfile
, objfile
->name
,
2758 use_deprecated_index_sections
,
2759 &dwarf2_per_objfile
->gdb_index
, &local_map
,
2760 &cu_list
, &cu_list_elements
,
2761 &types_list
, &types_list_elements
))
2764 /* Don't use the index if it's empty. */
2765 if (local_map
.symbol_table_slots
== 0)
2768 /* If there is a .dwz file, read it so we can get its CU list as
2770 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
2772 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
2773 struct mapped_index dwz_map
;
2774 const gdb_byte
*dwz_types_ignore
;
2775 offset_type dwz_types_elements_ignore
;
2777 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
2779 &dwz
->gdb_index
, &dwz_map
,
2780 &dwz_list
, &dwz_list_elements
,
2782 &dwz_types_elements_ignore
))
2784 warning (_("could not read '.gdb_index' section from %s; skipping"),
2785 bfd_get_filename (dwz
->dwz_bfd
));
2790 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
,
2791 dwz_list
, dwz_list_elements
))
2794 if (types_list_elements
)
2796 struct dwarf2_section_info
*section
;
2798 /* We can only handle a single .debug_types when we have an
2800 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2803 section
= VEC_index (dwarf2_section_info_def
,
2804 dwarf2_per_objfile
->types
, 0);
2806 if (!create_signatured_type_table_from_index (objfile
, section
,
2808 types_list_elements
))
2812 create_addrmap_from_index (objfile
, &local_map
);
2814 map
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct mapped_index
));
2817 dwarf2_per_objfile
->index_table
= map
;
2818 dwarf2_per_objfile
->using_index
= 1;
2819 dwarf2_per_objfile
->quick_file_names_table
=
2820 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2825 /* A helper for the "quick" functions which sets the global
2826 dwarf2_per_objfile according to OBJFILE. */
2829 dw2_setup (struct objfile
*objfile
)
2831 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2832 gdb_assert (dwarf2_per_objfile
);
2835 /* Reader function for dw2_build_type_unit_groups. */
2838 dw2_build_type_unit_groups_reader (const struct die_reader_specs
*reader
,
2840 struct die_info
*type_unit_die
,
2844 struct dwarf2_cu
*cu
= reader
->cu
;
2845 struct attribute
*attr
;
2846 struct type_unit_group
*tu_group
;
2848 gdb_assert (data
== NULL
);
2853 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
2854 /* Call this for its side-effect of creating the associated
2855 struct type_unit_group if it doesn't already exist. */
2856 tu_group
= get_type_unit_group (cu
, attr
);
2859 /* Build dwarf2_per_objfile->type_unit_groups.
2860 This function may be called multiple times. */
2863 dw2_build_type_unit_groups (void)
2865 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
2866 build_type_unit_groups (dw2_build_type_unit_groups_reader
, NULL
);
2869 /* die_reader_func for dw2_get_file_names. */
2872 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2874 struct die_info
*comp_unit_die
,
2878 struct dwarf2_cu
*cu
= reader
->cu
;
2879 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2880 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2881 struct dwarf2_per_cu_data
*lh_cu
;
2882 struct line_header
*lh
;
2883 struct attribute
*attr
;
2885 char *name
, *comp_dir
;
2887 struct quick_file_names
*qfn
;
2888 unsigned int line_offset
;
2890 /* Our callers never want to match partial units -- instead they
2891 will match the enclosing full CU. */
2892 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2894 this_cu
->v
.quick
->no_file_data
= 1;
2898 /* If we're reading the line header for TUs, store it in the "per_cu"
2900 if (this_cu
->is_debug_types
)
2902 struct type_unit_group
*tu_group
= data
;
2904 gdb_assert (tu_group
!= NULL
);
2905 lh_cu
= &tu_group
->per_cu
;
2914 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2917 struct quick_file_names find_entry
;
2919 line_offset
= DW_UNSND (attr
);
2921 /* We may have already read in this line header (TU line header sharing).
2922 If we have we're done. */
2923 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2924 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2925 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2926 &find_entry
, INSERT
);
2929 lh_cu
->v
.quick
->file_names
= *slot
;
2933 lh
= dwarf_decode_line_header (line_offset
, cu
);
2937 lh_cu
->v
.quick
->no_file_data
= 1;
2941 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2942 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2943 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2944 gdb_assert (slot
!= NULL
);
2947 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2949 qfn
->num_file_names
= lh
->num_file_names
;
2950 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2951 lh
->num_file_names
* sizeof (char *));
2952 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2953 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2954 qfn
->real_names
= NULL
;
2956 free_line_header (lh
);
2958 lh_cu
->v
.quick
->file_names
= qfn
;
2961 /* A helper for the "quick" functions which attempts to read the line
2962 table for THIS_CU. */
2964 static struct quick_file_names
*
2965 dw2_get_file_names (struct objfile
*objfile
,
2966 struct dwarf2_per_cu_data
*this_cu
)
2968 /* For TUs this should only be called on the parent group. */
2969 if (this_cu
->is_debug_types
)
2970 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2972 if (this_cu
->v
.quick
->file_names
!= NULL
)
2973 return this_cu
->v
.quick
->file_names
;
2974 /* If we know there is no line data, no point in looking again. */
2975 if (this_cu
->v
.quick
->no_file_data
)
2978 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2979 in the stub for CUs, there's is no need to lookup the DWO file.
2980 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2982 if (this_cu
->is_debug_types
)
2984 struct type_unit_group
*tu_group
= this_cu
->s
.type_unit_group
;
2986 init_cutu_and_read_dies (tu_group
->t
.first_tu
, NULL
, 0, 0,
2987 dw2_get_file_names_reader
, tu_group
);
2990 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2992 if (this_cu
->v
.quick
->no_file_data
)
2994 return this_cu
->v
.quick
->file_names
;
2997 /* A helper for the "quick" functions which computes and caches the
2998 real path for a given file name from the line table. */
3001 dw2_get_real_path (struct objfile
*objfile
,
3002 struct quick_file_names
*qfn
, int index
)
3004 if (qfn
->real_names
== NULL
)
3005 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3006 qfn
->num_file_names
, sizeof (char *));
3008 if (qfn
->real_names
[index
] == NULL
)
3009 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
3011 return qfn
->real_names
[index
];
3014 static struct symtab
*
3015 dw2_find_last_source_symtab (struct objfile
*objfile
)
3019 dw2_setup (objfile
);
3020 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3021 return dw2_instantiate_symtab (dw2_get_cu (index
));
3024 /* Traversal function for dw2_forget_cached_source_info. */
3027 dw2_free_cached_file_names (void **slot
, void *info
)
3029 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3031 if (file_data
->real_names
)
3035 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3037 xfree ((void*) file_data
->real_names
[i
]);
3038 file_data
->real_names
[i
] = NULL
;
3046 dw2_forget_cached_source_info (struct objfile
*objfile
)
3048 dw2_setup (objfile
);
3050 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3051 dw2_free_cached_file_names
, NULL
);
3054 /* Helper function for dw2_map_symtabs_matching_filename that expands
3055 the symtabs and calls the iterator. */
3058 dw2_map_expand_apply (struct objfile
*objfile
,
3059 struct dwarf2_per_cu_data
*per_cu
,
3061 const char *full_path
, const char *real_path
,
3062 int (*callback
) (struct symtab
*, void *),
3065 struct symtab
*last_made
= objfile
->symtabs
;
3067 /* Don't visit already-expanded CUs. */
3068 if (per_cu
->v
.quick
->symtab
)
3071 /* This may expand more than one symtab, and we want to iterate over
3073 dw2_instantiate_symtab (per_cu
);
3075 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
3076 objfile
->symtabs
, last_made
);
3079 /* Implementation of the map_symtabs_matching_filename method. */
3082 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3083 const char *full_path
, const char *real_path
,
3084 int (*callback
) (struct symtab
*, void *),
3088 const char *name_basename
= lbasename (name
);
3089 int name_len
= strlen (name
);
3090 int is_abs
= IS_ABSOLUTE_PATH (name
);
3092 dw2_setup (objfile
);
3094 dw2_build_type_unit_groups ();
3096 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3097 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3100 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3101 struct quick_file_names
*file_data
;
3103 /* We only need to look at symtabs not already expanded. */
3104 if (per_cu
->v
.quick
->symtab
)
3107 file_data
= dw2_get_file_names (objfile
, per_cu
);
3108 if (file_data
== NULL
)
3111 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3113 const char *this_name
= file_data
->file_names
[j
];
3115 if (FILENAME_CMP (name
, this_name
) == 0
3116 || (!is_abs
&& compare_filenames_for_search (this_name
,
3119 if (dw2_map_expand_apply (objfile
, per_cu
,
3120 name
, full_path
, real_path
,
3125 /* Before we invoke realpath, which can get expensive when many
3126 files are involved, do a quick comparison of the basenames. */
3127 if (! basenames_may_differ
3128 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3131 if (full_path
!= NULL
)
3133 const char *this_real_name
= dw2_get_real_path (objfile
,
3136 if (this_real_name
!= NULL
3137 && (FILENAME_CMP (full_path
, this_real_name
) == 0
3139 && compare_filenames_for_search (this_real_name
,
3142 if (dw2_map_expand_apply (objfile
, per_cu
,
3143 name
, full_path
, real_path
,
3149 if (real_path
!= NULL
)
3151 const char *this_real_name
= dw2_get_real_path (objfile
,
3154 if (this_real_name
!= NULL
3155 && (FILENAME_CMP (real_path
, this_real_name
) == 0
3157 && compare_filenames_for_search (this_real_name
,
3160 if (dw2_map_expand_apply (objfile
, per_cu
,
3161 name
, full_path
, real_path
,
3172 static struct symtab
*
3173 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3174 const char *name
, domain_enum domain
)
3176 /* We do all the work in the pre_expand_symtabs_matching hook
3181 /* A helper function that expands all symtabs that hold an object
3182 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
3183 symbols in block BLOCK_KIND. */
3186 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
3187 int want_specific_block
,
3188 enum block_enum block_kind
,
3189 const char *name
, domain_enum domain
)
3191 struct mapped_index
*index
;
3193 dw2_setup (objfile
);
3195 index
= dwarf2_per_objfile
->index_table
;
3197 /* index_table is NULL if OBJF_READNOW. */
3202 if (find_slot_in_mapped_hash (index
, name
, &vec
))
3204 offset_type i
, len
= MAYBE_SWAP (*vec
);
3205 for (i
= 0; i
< len
; ++i
)
3207 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
3208 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3209 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
3210 int want_static
= block_kind
!= GLOBAL_BLOCK
;
3211 /* This value is only valid for index versions >= 7. */
3212 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3213 gdb_index_symbol_kind symbol_kind
=
3214 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3215 /* Only check the symbol attributes if they're present.
3216 Indices prior to version 7 don't record them,
3217 and indices >= 7 may elide them for certain symbols
3218 (gold does this). */
3220 (index
->version
>= 7
3221 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3224 && want_specific_block
3225 && want_static
!= is_static
)
3228 /* Only check the symbol's kind if it has one. */
3234 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3235 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3236 /* Some types are also in VAR_DOMAIN. */
3237 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3241 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3245 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3253 dw2_instantiate_symtab (per_cu
);
3260 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
3261 enum block_enum block_kind
, const char *name
,
3264 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
3268 dw2_print_stats (struct objfile
*objfile
)
3272 dw2_setup (objfile
);
3274 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3275 + dwarf2_per_objfile
->n_type_units
); ++i
)
3277 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3279 if (!per_cu
->v
.quick
->symtab
)
3282 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3286 dw2_dump (struct objfile
*objfile
)
3288 /* Nothing worth printing. */
3292 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
3293 struct section_offsets
*delta
)
3295 /* There's nothing to relocate here. */
3299 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3300 const char *func_name
)
3302 /* Note: It doesn't matter what we pass for block_kind here. */
3303 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
3308 dw2_expand_all_symtabs (struct objfile
*objfile
)
3312 dw2_setup (objfile
);
3314 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3315 + dwarf2_per_objfile
->n_type_units
); ++i
)
3317 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3319 dw2_instantiate_symtab (per_cu
);
3324 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3325 const char *filename
)
3329 dw2_setup (objfile
);
3331 /* We don't need to consider type units here.
3332 This is only called for examining code, e.g. expand_line_sal.
3333 There can be an order of magnitude (or more) more type units
3334 than comp units, and we avoid them if we can. */
3336 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3339 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3340 struct quick_file_names
*file_data
;
3342 /* We only need to look at symtabs not already expanded. */
3343 if (per_cu
->v
.quick
->symtab
)
3346 file_data
= dw2_get_file_names (objfile
, per_cu
);
3347 if (file_data
== NULL
)
3350 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3352 const char *this_name
= file_data
->file_names
[j
];
3353 if (FILENAME_CMP (this_name
, filename
) == 0)
3355 dw2_instantiate_symtab (per_cu
);
3362 /* A helper function for dw2_find_symbol_file that finds the primary
3363 file name for a given CU. This is a die_reader_func. */
3366 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3368 struct die_info
*comp_unit_die
,
3372 const char **result_ptr
= data
;
3373 struct dwarf2_cu
*cu
= reader
->cu
;
3374 struct attribute
*attr
;
3376 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3380 *result_ptr
= DW_STRING (attr
);
3384 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3386 struct dwarf2_per_cu_data
*per_cu
;
3388 struct quick_file_names
*file_data
;
3389 const char *filename
;
3391 dw2_setup (objfile
);
3393 /* index_table is NULL if OBJF_READNOW. */
3394 if (!dwarf2_per_objfile
->index_table
)
3398 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3400 struct blockvector
*bv
= BLOCKVECTOR (s
);
3401 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3402 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3405 return sym
->symtab
->filename
;
3410 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3414 /* Note that this just looks at the very first one named NAME -- but
3415 actually we are looking for a function. find_main_filename
3416 should be rewritten so that it doesn't require a custom hook. It
3417 could just use the ordinary symbol tables. */
3418 /* vec[0] is the length, which must always be >0. */
3419 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3421 if (per_cu
->v
.quick
->symtab
!= NULL
)
3422 return per_cu
->v
.quick
->symtab
->filename
;
3424 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3425 dw2_get_primary_filename_reader
, &filename
);
3431 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3432 struct objfile
*objfile
, int global
,
3433 int (*callback
) (struct block
*,
3434 struct symbol
*, void *),
3435 void *data
, symbol_compare_ftype
*match
,
3436 symbol_compare_ftype
*ordered_compare
)
3438 /* Currently unimplemented; used for Ada. The function can be called if the
3439 current language is Ada for a non-Ada objfile using GNU index. As Ada
3440 does not look for non-Ada symbols this function should just return. */
3444 dw2_expand_symtabs_matching
3445 (struct objfile
*objfile
,
3446 int (*file_matcher
) (const char *, void *),
3447 int (*name_matcher
) (const char *, void *),
3448 enum search_domain kind
,
3453 struct mapped_index
*index
;
3455 dw2_setup (objfile
);
3457 /* index_table is NULL if OBJF_READNOW. */
3458 if (!dwarf2_per_objfile
->index_table
)
3460 index
= dwarf2_per_objfile
->index_table
;
3462 if (file_matcher
!= NULL
)
3464 struct cleanup
*cleanup
;
3465 htab_t visited_found
, visited_not_found
;
3467 dw2_build_type_unit_groups ();
3469 visited_found
= htab_create_alloc (10,
3470 htab_hash_pointer
, htab_eq_pointer
,
3471 NULL
, xcalloc
, xfree
);
3472 cleanup
= make_cleanup_htab_delete (visited_found
);
3473 visited_not_found
= htab_create_alloc (10,
3474 htab_hash_pointer
, htab_eq_pointer
,
3475 NULL
, xcalloc
, xfree
);
3476 make_cleanup_htab_delete (visited_not_found
);
3478 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3479 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3482 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3483 struct quick_file_names
*file_data
;
3486 per_cu
->v
.quick
->mark
= 0;
3488 /* We only need to look at symtabs not already expanded. */
3489 if (per_cu
->v
.quick
->symtab
)
3492 file_data
= dw2_get_file_names (objfile
, per_cu
);
3493 if (file_data
== NULL
)
3496 if (htab_find (visited_not_found
, file_data
) != NULL
)
3498 else if (htab_find (visited_found
, file_data
) != NULL
)
3500 per_cu
->v
.quick
->mark
= 1;
3504 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3506 if (file_matcher (file_data
->file_names
[j
], data
))
3508 per_cu
->v
.quick
->mark
= 1;
3513 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3515 : visited_not_found
,
3520 do_cleanups (cleanup
);
3523 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3525 offset_type idx
= 2 * iter
;
3527 offset_type
*vec
, vec_len
, vec_idx
;
3529 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3532 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3534 if (! (*name_matcher
) (name
, data
))
3537 /* The name was matched, now expand corresponding CUs that were
3539 vec
= (offset_type
*) (index
->constant_pool
3540 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3541 vec_len
= MAYBE_SWAP (vec
[0]);
3542 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3544 struct dwarf2_per_cu_data
*per_cu
;
3545 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3546 gdb_index_symbol_kind symbol_kind
=
3547 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3548 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3550 /* Don't crash on bad data. */
3551 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3552 + dwarf2_per_objfile
->n_type_units
))
3555 /* Only check the symbol's kind if it has one.
3556 Indices prior to version 7 don't record it. */
3557 if (index
->version
>= 7)
3561 case VARIABLES_DOMAIN
:
3562 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3565 case FUNCTIONS_DOMAIN
:
3566 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3570 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3578 per_cu
= dw2_get_cu (cu_index
);
3579 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3580 dw2_instantiate_symtab (per_cu
);
3585 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3588 static struct symtab
*
3589 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3593 if (BLOCKVECTOR (symtab
) != NULL
3594 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3597 if (symtab
->includes
== NULL
)
3600 for (i
= 0; symtab
->includes
[i
]; ++i
)
3602 struct symtab
*s
= symtab
->includes
[i
];
3604 s
= recursively_find_pc_sect_symtab (s
, pc
);
3612 static struct symtab
*
3613 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3614 struct minimal_symbol
*msymbol
,
3616 struct obj_section
*section
,
3619 struct dwarf2_per_cu_data
*data
;
3620 struct symtab
*result
;
3622 dw2_setup (objfile
);
3624 if (!objfile
->psymtabs_addrmap
)
3627 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3631 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3632 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3633 paddress (get_objfile_arch (objfile
), pc
));
3635 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3636 gdb_assert (result
!= NULL
);
3641 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3642 void *data
, int need_fullname
)
3645 struct cleanup
*cleanup
;
3646 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3647 NULL
, xcalloc
, xfree
);
3649 cleanup
= make_cleanup_htab_delete (visited
);
3650 dw2_setup (objfile
);
3652 dw2_build_type_unit_groups ();
3654 /* We can ignore file names coming from already-expanded CUs. */
3655 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3656 + dwarf2_per_objfile
->n_type_units
); ++i
)
3658 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3660 if (per_cu
->v
.quick
->symtab
)
3662 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3665 *slot
= per_cu
->v
.quick
->file_names
;
3669 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3670 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3673 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3674 struct quick_file_names
*file_data
;
3677 /* We only need to look at symtabs not already expanded. */
3678 if (per_cu
->v
.quick
->symtab
)
3681 file_data
= dw2_get_file_names (objfile
, per_cu
);
3682 if (file_data
== NULL
)
3685 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3688 /* Already visited. */
3693 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3695 const char *this_real_name
;
3698 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3700 this_real_name
= NULL
;
3701 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3705 do_cleanups (cleanup
);
3709 dw2_has_symbols (struct objfile
*objfile
)
3714 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3717 dw2_find_last_source_symtab
,
3718 dw2_forget_cached_source_info
,
3719 dw2_map_symtabs_matching_filename
,
3721 dw2_pre_expand_symtabs_matching
,
3725 dw2_expand_symtabs_for_function
,
3726 dw2_expand_all_symtabs
,
3727 dw2_expand_symtabs_with_filename
,
3728 dw2_find_symbol_file
,
3729 dw2_map_matching_symbols
,
3730 dw2_expand_symtabs_matching
,
3731 dw2_find_pc_sect_symtab
,
3732 dw2_map_symbol_filenames
3735 /* Initialize for reading DWARF for this objfile. Return 0 if this
3736 file will use psymtabs, or 1 if using the GNU index. */
3739 dwarf2_initialize_objfile (struct objfile
*objfile
)
3741 /* If we're about to read full symbols, don't bother with the
3742 indices. In this case we also don't care if some other debug
3743 format is making psymtabs, because they are all about to be
3745 if ((objfile
->flags
& OBJF_READNOW
))
3749 dwarf2_per_objfile
->using_index
= 1;
3750 create_all_comp_units (objfile
);
3751 create_all_type_units (objfile
);
3752 dwarf2_per_objfile
->quick_file_names_table
=
3753 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3755 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3756 + dwarf2_per_objfile
->n_type_units
); ++i
)
3758 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3760 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3761 struct dwarf2_per_cu_quick_data
);
3764 /* Return 1 so that gdb sees the "quick" functions. However,
3765 these functions will be no-ops because we will have expanded
3770 if (dwarf2_read_index (objfile
))
3778 /* Build a partial symbol table. */
3781 dwarf2_build_psymtabs (struct objfile
*objfile
)
3783 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3785 init_psymbol_list (objfile
, 1024);
3788 dwarf2_build_psymtabs_hard (objfile
);
3791 /* Return the total length of the CU described by HEADER. */
3794 get_cu_length (const struct comp_unit_head
*header
)
3796 return header
->initial_length_size
+ header
->length
;
3799 /* Return TRUE if OFFSET is within CU_HEADER. */
3802 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3804 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3805 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3807 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3810 /* Find the base address of the compilation unit for range lists and
3811 location lists. It will normally be specified by DW_AT_low_pc.
3812 In DWARF-3 draft 4, the base address could be overridden by
3813 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3814 compilation units with discontinuous ranges. */
3817 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3819 struct attribute
*attr
;
3822 cu
->base_address
= 0;
3824 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3827 cu
->base_address
= DW_ADDR (attr
);
3832 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3835 cu
->base_address
= DW_ADDR (attr
);
3841 /* Read in the comp unit header information from the debug_info at info_ptr.
3842 NOTE: This leaves members offset, first_die_offset to be filled in
3846 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3847 gdb_byte
*info_ptr
, bfd
*abfd
)
3850 unsigned int bytes_read
;
3852 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3853 cu_header
->initial_length_size
= bytes_read
;
3854 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3855 info_ptr
+= bytes_read
;
3856 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3858 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3860 info_ptr
+= bytes_read
;
3861 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3863 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3864 if (signed_addr
< 0)
3865 internal_error (__FILE__
, __LINE__
,
3866 _("read_comp_unit_head: dwarf from non elf file"));
3867 cu_header
->signed_addr_p
= signed_addr
;
3872 /* Helper function that returns the proper abbrev section for
3875 static struct dwarf2_section_info
*
3876 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
3878 struct dwarf2_section_info
*abbrev
;
3880 if (this_cu
->is_dwz
)
3881 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
3883 abbrev
= &dwarf2_per_objfile
->abbrev
;
3888 /* Subroutine of read_and_check_comp_unit_head and
3889 read_and_check_type_unit_head to simplify them.
3890 Perform various error checking on the header. */
3893 error_check_comp_unit_head (struct comp_unit_head
*header
,
3894 struct dwarf2_section_info
*section
,
3895 struct dwarf2_section_info
*abbrev_section
)
3897 bfd
*abfd
= section
->asection
->owner
;
3898 const char *filename
= bfd_get_filename (abfd
);
3900 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3901 error (_("Dwarf Error: wrong version in compilation unit header "
3902 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3905 if (header
->abbrev_offset
.sect_off
3906 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
3907 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3908 "(offset 0x%lx + 6) [in module %s]"),
3909 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3912 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3913 avoid potential 32-bit overflow. */
3914 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3916 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3917 "(offset 0x%lx + 0) [in module %s]"),
3918 (long) header
->length
, (long) header
->offset
.sect_off
,
3922 /* Read in a CU/TU header and perform some basic error checking.
3923 The contents of the header are stored in HEADER.
3924 The result is a pointer to the start of the first DIE. */
3927 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3928 struct dwarf2_section_info
*section
,
3929 struct dwarf2_section_info
*abbrev_section
,
3931 int is_debug_types_section
)
3933 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3934 bfd
*abfd
= section
->asection
->owner
;
3936 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3938 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3940 /* If we're reading a type unit, skip over the signature and
3941 type_offset fields. */
3942 if (is_debug_types_section
)
3943 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3945 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3947 error_check_comp_unit_head (header
, section
, abbrev_section
);
3952 /* Read in the types comp unit header information from .debug_types entry at
3953 types_ptr. The result is a pointer to one past the end of the header. */
3956 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3957 struct dwarf2_section_info
*section
,
3958 struct dwarf2_section_info
*abbrev_section
,
3960 ULONGEST
*signature
,
3961 cu_offset
*type_offset_in_tu
)
3963 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3964 bfd
*abfd
= section
->asection
->owner
;
3966 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3968 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3970 /* If we're reading a type unit, skip over the signature and
3971 type_offset fields. */
3972 if (signature
!= NULL
)
3973 *signature
= read_8_bytes (abfd
, info_ptr
);
3975 if (type_offset_in_tu
!= NULL
)
3976 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3977 header
->offset_size
);
3978 info_ptr
+= header
->offset_size
;
3980 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3982 error_check_comp_unit_head (header
, section
, abbrev_section
);
3987 /* Fetch the abbreviation table offset from a comp or type unit header. */
3990 read_abbrev_offset (struct dwarf2_section_info
*section
,
3993 bfd
*abfd
= section
->asection
->owner
;
3995 unsigned int length
, initial_length_size
, offset_size
;
3996 sect_offset abbrev_offset
;
3998 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3999 info_ptr
= section
->buffer
+ offset
.sect_off
;
4000 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4001 offset_size
= initial_length_size
== 4 ? 4 : 8;
4002 info_ptr
+= initial_length_size
+ 2 /*version*/;
4003 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
4004 return abbrev_offset
;
4007 /* Allocate a new partial symtab for file named NAME and mark this new
4008 partial symtab as being an include of PST. */
4011 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
4012 struct objfile
*objfile
)
4014 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4016 subpst
->section_offsets
= pst
->section_offsets
;
4017 subpst
->textlow
= 0;
4018 subpst
->texthigh
= 0;
4020 subpst
->dependencies
= (struct partial_symtab
**)
4021 obstack_alloc (&objfile
->objfile_obstack
,
4022 sizeof (struct partial_symtab
*));
4023 subpst
->dependencies
[0] = pst
;
4024 subpst
->number_of_dependencies
= 1;
4026 subpst
->globals_offset
= 0;
4027 subpst
->n_global_syms
= 0;
4028 subpst
->statics_offset
= 0;
4029 subpst
->n_static_syms
= 0;
4030 subpst
->symtab
= NULL
;
4031 subpst
->read_symtab
= pst
->read_symtab
;
4034 /* No private part is necessary for include psymtabs. This property
4035 can be used to differentiate between such include psymtabs and
4036 the regular ones. */
4037 subpst
->read_symtab_private
= NULL
;
4040 /* Read the Line Number Program data and extract the list of files
4041 included by the source file represented by PST. Build an include
4042 partial symtab for each of these included files. */
4045 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4046 struct die_info
*die
,
4047 struct partial_symtab
*pst
)
4049 struct line_header
*lh
= NULL
;
4050 struct attribute
*attr
;
4052 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4054 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4056 return; /* No linetable, so no includes. */
4058 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4059 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
4061 free_line_header (lh
);
4065 hash_signatured_type (const void *item
)
4067 const struct signatured_type
*sig_type
= item
;
4069 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4070 return sig_type
->signature
;
4074 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4076 const struct signatured_type
*lhs
= item_lhs
;
4077 const struct signatured_type
*rhs
= item_rhs
;
4079 return lhs
->signature
== rhs
->signature
;
4082 /* Allocate a hash table for signatured types. */
4085 allocate_signatured_type_table (struct objfile
*objfile
)
4087 return htab_create_alloc_ex (41,
4088 hash_signatured_type
,
4091 &objfile
->objfile_obstack
,
4092 hashtab_obstack_allocate
,
4093 dummy_obstack_deallocate
);
4096 /* A helper function to add a signatured type CU to a table. */
4099 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4101 struct signatured_type
*sigt
= *slot
;
4102 struct signatured_type
***datap
= datum
;
4110 /* Create the hash table of all entries in the .debug_types section.
4111 DWO_FILE is a pointer to the DWO file for .debug_types.dwo,
4113 Note: This function processes DWO files only, not DWP files.
4114 The result is a pointer to the hash table or NULL if there are
4118 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4119 VEC (dwarf2_section_info_def
) *types
)
4121 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4122 htab_t types_htab
= NULL
;
4124 struct dwarf2_section_info
*section
;
4125 struct dwarf2_section_info
*abbrev_section
;
4127 if (VEC_empty (dwarf2_section_info_def
, types
))
4130 abbrev_section
= (dwo_file
!= NULL
4131 ? &dwo_file
->sections
.abbrev
4132 : &dwarf2_per_objfile
->abbrev
);
4134 if (dwarf2_read_debug
)
4135 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4136 dwo_file
? ".dwo" : "",
4137 bfd_get_filename (abbrev_section
->asection
->owner
));
4140 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4144 gdb_byte
*info_ptr
, *end_ptr
;
4145 struct dwarf2_section_info
*abbrev_section
;
4147 dwarf2_read_section (objfile
, section
);
4148 info_ptr
= section
->buffer
;
4150 if (info_ptr
== NULL
)
4153 /* We can't set abfd until now because the section may be empty or
4154 not present, in which case section->asection will be NULL. */
4155 abfd
= section
->asection
->owner
;
4158 abbrev_section
= &dwo_file
->sections
.abbrev
;
4160 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4162 if (types_htab
== NULL
)
4165 types_htab
= allocate_dwo_unit_table (objfile
);
4167 types_htab
= allocate_signatured_type_table (objfile
);
4170 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4171 because we don't need to read any dies: the signature is in the
4174 end_ptr
= info_ptr
+ section
->size
;
4175 while (info_ptr
< end_ptr
)
4178 cu_offset type_offset_in_tu
;
4180 struct signatured_type
*sig_type
;
4181 struct dwo_unit
*dwo_tu
;
4183 gdb_byte
*ptr
= info_ptr
;
4184 struct comp_unit_head header
;
4185 unsigned int length
;
4187 offset
.sect_off
= ptr
- section
->buffer
;
4189 /* We need to read the type's signature in order to build the hash
4190 table, but we don't need anything else just yet. */
4192 ptr
= read_and_check_type_unit_head (&header
, section
,
4193 abbrev_section
, ptr
,
4194 &signature
, &type_offset_in_tu
);
4196 length
= get_cu_length (&header
);
4198 /* Skip dummy type units. */
4199 if (ptr
>= info_ptr
+ length
4200 || peek_abbrev_code (abfd
, ptr
) == 0)
4209 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4211 dwo_tu
->dwo_file
= dwo_file
;
4212 dwo_tu
->signature
= signature
;
4213 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4214 dwo_tu
->info_or_types_section
= section
;
4215 dwo_tu
->offset
= offset
;
4216 dwo_tu
->length
= length
;
4220 /* N.B.: type_offset is not usable if this type uses a DWO file.
4221 The real type_offset is in the DWO file. */
4223 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4224 struct signatured_type
);
4225 sig_type
->signature
= signature
;
4226 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4227 sig_type
->per_cu
.objfile
= objfile
;
4228 sig_type
->per_cu
.is_debug_types
= 1;
4229 sig_type
->per_cu
.info_or_types_section
= section
;
4230 sig_type
->per_cu
.offset
= offset
;
4231 sig_type
->per_cu
.length
= length
;
4234 slot
= htab_find_slot (types_htab
,
4235 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4237 gdb_assert (slot
!= NULL
);
4240 sect_offset dup_offset
;
4244 const struct dwo_unit
*dup_tu
= *slot
;
4246 dup_offset
= dup_tu
->offset
;
4250 const struct signatured_type
*dup_tu
= *slot
;
4252 dup_offset
= dup_tu
->per_cu
.offset
;
4255 complaint (&symfile_complaints
,
4256 _("debug type entry at offset 0x%x is duplicate to the "
4257 "entry at offset 0x%x, signature 0x%s"),
4258 offset
.sect_off
, dup_offset
.sect_off
,
4259 phex (signature
, sizeof (signature
)));
4261 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4263 if (dwarf2_read_debug
)
4264 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
4266 phex (signature
, sizeof (signature
)));
4275 /* Create the hash table of all entries in the .debug_types section,
4276 and initialize all_type_units.
4277 The result is zero if there is an error (e.g. missing .debug_types section),
4278 otherwise non-zero. */
4281 create_all_type_units (struct objfile
*objfile
)
4284 struct signatured_type
**iter
;
4286 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4287 if (types_htab
== NULL
)
4289 dwarf2_per_objfile
->signatured_types
= NULL
;
4293 dwarf2_per_objfile
->signatured_types
= types_htab
;
4295 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4296 dwarf2_per_objfile
->all_type_units
4297 = obstack_alloc (&objfile
->objfile_obstack
,
4298 dwarf2_per_objfile
->n_type_units
4299 * sizeof (struct signatured_type
*));
4300 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4301 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4302 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4303 == dwarf2_per_objfile
->n_type_units
);
4308 /* Lookup a signature based type for DW_FORM_ref_sig8.
4309 Returns NULL if signature SIG is not present in the table. */
4311 static struct signatured_type
*
4312 lookup_signatured_type (ULONGEST sig
)
4314 struct signatured_type find_entry
, *entry
;
4316 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4318 complaint (&symfile_complaints
,
4319 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4323 find_entry
.signature
= sig
;
4324 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4328 /* Low level DIE reading support. */
4330 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4333 init_cu_die_reader (struct die_reader_specs
*reader
,
4334 struct dwarf2_cu
*cu
,
4335 struct dwarf2_section_info
*section
,
4336 struct dwo_file
*dwo_file
)
4338 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4339 reader
->abfd
= section
->asection
->owner
;
4341 reader
->dwo_file
= dwo_file
;
4342 reader
->die_section
= section
;
4343 reader
->buffer
= section
->buffer
;
4344 reader
->buffer_end
= section
->buffer
+ section
->size
;
4347 /* Initialize a CU (or TU) and read its DIEs.
4348 If the CU defers to a DWO file, read the DWO file as well.
4350 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4351 Otherwise the table specified in the comp unit header is read in and used.
4352 This is an optimization for when we already have the abbrev table.
4354 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4355 Otherwise, a new CU is allocated with xmalloc.
4357 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4358 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4360 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4361 linker) then DIE_READER_FUNC will not get called. */
4364 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4365 struct abbrev_table
*abbrev_table
,
4366 int use_existing_cu
, int keep
,
4367 die_reader_func_ftype
*die_reader_func
,
4370 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4371 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4372 bfd
*abfd
= section
->asection
->owner
;
4373 struct dwarf2_cu
*cu
;
4374 gdb_byte
*begin_info_ptr
, *info_ptr
;
4375 struct die_reader_specs reader
;
4376 struct die_info
*comp_unit_die
;
4378 struct attribute
*attr
;
4379 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4380 struct signatured_type
*sig_type
= NULL
;
4381 struct dwarf2_section_info
*abbrev_section
;
4382 /* Non-zero if CU currently points to a DWO file and we need to
4383 reread it. When this happens we need to reread the skeleton die
4384 before we can reread the DWO file. */
4385 int rereading_dwo_cu
= 0;
4387 if (dwarf2_die_debug
)
4388 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4389 this_cu
->is_debug_types
? "type" : "comp",
4390 this_cu
->offset
.sect_off
);
4392 if (use_existing_cu
)
4395 cleanups
= make_cleanup (null_cleanup
, NULL
);
4397 /* This is cheap if the section is already read in. */
4398 dwarf2_read_section (objfile
, section
);
4400 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4402 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
4404 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4408 /* If this CU is from a DWO file we need to start over, we need to
4409 refetch the attributes from the skeleton CU.
4410 This could be optimized by retrieving those attributes from when we
4411 were here the first time: the previous comp_unit_die was stored in
4412 comp_unit_obstack. But there's no data yet that we need this
4414 if (cu
->dwo_unit
!= NULL
)
4415 rereading_dwo_cu
= 1;
4419 /* If !use_existing_cu, this_cu->cu must be NULL. */
4420 gdb_assert (this_cu
->cu
== NULL
);
4422 cu
= xmalloc (sizeof (*cu
));
4423 init_one_comp_unit (cu
, this_cu
);
4425 /* If an error occurs while loading, release our storage. */
4426 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4429 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4431 /* We already have the header, there's no need to read it in again. */
4432 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4436 if (this_cu
->is_debug_types
)
4439 cu_offset type_offset_in_tu
;
4441 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4442 abbrev_section
, info_ptr
,
4444 &type_offset_in_tu
);
4446 /* Since per_cu is the first member of struct signatured_type,
4447 we can go from a pointer to one to a pointer to the other. */
4448 sig_type
= (struct signatured_type
*) this_cu
;
4449 gdb_assert (sig_type
->signature
== signature
);
4450 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4451 == type_offset_in_tu
.cu_off
);
4452 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4454 /* LENGTH has not been set yet for type units if we're
4455 using .gdb_index. */
4456 this_cu
->length
= get_cu_length (&cu
->header
);
4458 /* Establish the type offset that can be used to lookup the type. */
4459 sig_type
->type_offset_in_section
.sect_off
=
4460 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4464 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4468 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4469 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4473 /* Skip dummy compilation units. */
4474 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4475 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4477 do_cleanups (cleanups
);
4481 /* If we don't have them yet, read the abbrevs for this compilation unit.
4482 And if we need to read them now, make sure they're freed when we're
4483 done. Note that it's important that if the CU had an abbrev table
4484 on entry we don't free it when we're done: Somewhere up the call stack
4485 it may be in use. */
4486 if (abbrev_table
!= NULL
)
4488 gdb_assert (cu
->abbrev_table
== NULL
);
4489 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4490 == abbrev_table
->offset
.sect_off
);
4491 cu
->abbrev_table
= abbrev_table
;
4493 else if (cu
->abbrev_table
== NULL
)
4495 dwarf2_read_abbrevs (cu
, abbrev_section
);
4496 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4498 else if (rereading_dwo_cu
)
4500 dwarf2_free_abbrev_table (cu
);
4501 dwarf2_read_abbrevs (cu
, abbrev_section
);
4504 /* Read the top level CU/TU die. */
4505 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4506 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4508 /* If we have a DWO stub, process it and then read in the DWO file.
4509 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4510 a DWO CU, that this test will fail. */
4511 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4514 char *dwo_name
= DW_STRING (attr
);
4515 const char *comp_dir_string
;
4516 struct dwo_unit
*dwo_unit
;
4517 ULONGEST signature
; /* Or dwo_id. */
4518 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4519 int i
,num_extra_attrs
;
4520 struct dwarf2_section_info
*dwo_abbrev_section
;
4523 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4524 " has children (offset 0x%x) [in module %s]"),
4525 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4527 /* These attributes aren't processed until later:
4528 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4529 However, the attribute is found in the stub which we won't have later.
4530 In order to not impose this complication on the rest of the code,
4531 we read them here and copy them to the DWO CU/TU die. */
4533 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4536 if (! this_cu
->is_debug_types
)
4537 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4538 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4539 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4540 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4541 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4543 /* There should be a DW_AT_addr_base attribute here (if needed).
4544 We need the value before we can process DW_FORM_GNU_addr_index. */
4546 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4548 cu
->addr_base
= DW_UNSND (attr
);
4550 /* There should be a DW_AT_ranges_base attribute here (if needed).
4551 We need the value before we can process DW_AT_ranges. */
4552 cu
->ranges_base
= 0;
4553 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4555 cu
->ranges_base
= DW_UNSND (attr
);
4557 if (this_cu
->is_debug_types
)
4559 gdb_assert (sig_type
!= NULL
);
4560 signature
= sig_type
->signature
;
4564 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4566 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4568 signature
= DW_UNSND (attr
);
4571 /* We may need the comp_dir in order to find the DWO file. */
4572 comp_dir_string
= NULL
;
4574 comp_dir_string
= DW_STRING (comp_dir
);
4576 if (this_cu
->is_debug_types
)
4577 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4579 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4582 if (dwo_unit
== NULL
)
4584 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4585 " with ID %s [in module %s]"),
4586 this_cu
->offset
.sect_off
,
4587 phex (signature
, sizeof (signature
)),
4591 /* Set up for reading the DWO CU/TU. */
4592 cu
->dwo_unit
= dwo_unit
;
4593 section
= dwo_unit
->info_or_types_section
;
4594 dwarf2_read_section (objfile
, section
);
4595 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4596 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4597 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4599 if (this_cu
->is_debug_types
)
4602 cu_offset type_offset_in_tu
;
4604 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4608 &type_offset_in_tu
);
4609 gdb_assert (sig_type
->signature
== signature
);
4610 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4611 /* For DWOs coming from DWP files, we don't know the CU length
4612 nor the type's offset in the TU until now. */
4613 dwo_unit
->length
= get_cu_length (&cu
->header
);
4614 dwo_unit
->type_offset_in_tu
= type_offset_in_tu
;
4616 /* Establish the type offset that can be used to lookup the type.
4617 For DWO files, we don't know it until now. */
4618 sig_type
->type_offset_in_section
.sect_off
=
4619 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4623 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4626 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4627 /* For DWOs coming from DWP files, we don't know the CU length
4629 dwo_unit
->length
= get_cu_length (&cu
->header
);
4632 /* Discard the original CU's abbrev table, and read the DWO's. */
4633 if (abbrev_table
== NULL
)
4635 dwarf2_free_abbrev_table (cu
);
4636 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4640 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4641 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4644 /* Read in the die, but leave space to copy over the attributes
4645 from the stub. This has the benefit of simplifying the rest of
4646 the code - all the real work is done here. */
4647 num_extra_attrs
= ((stmt_list
!= NULL
)
4651 + (comp_dir
!= NULL
));
4652 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4653 &has_children
, num_extra_attrs
);
4655 /* Copy over the attributes from the stub to the DWO die. */
4656 i
= comp_unit_die
->num_attrs
;
4657 if (stmt_list
!= NULL
)
4658 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4660 comp_unit_die
->attrs
[i
++] = *low_pc
;
4661 if (high_pc
!= NULL
)
4662 comp_unit_die
->attrs
[i
++] = *high_pc
;
4664 comp_unit_die
->attrs
[i
++] = *ranges
;
4665 if (comp_dir
!= NULL
)
4666 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4667 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4669 /* Skip dummy compilation units. */
4670 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4671 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4673 do_cleanups (cleanups
);
4678 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4680 if (free_cu_cleanup
!= NULL
)
4684 /* We've successfully allocated this compilation unit. Let our
4685 caller clean it up when finished with it. */
4686 discard_cleanups (free_cu_cleanup
);
4688 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4689 So we have to manually free the abbrev table. */
4690 dwarf2_free_abbrev_table (cu
);
4692 /* Link this CU into read_in_chain. */
4693 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4694 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4697 do_cleanups (free_cu_cleanup
);
4700 do_cleanups (cleanups
);
4703 /* Read CU/TU THIS_CU in section SECTION,
4704 but do not follow DW_AT_GNU_dwo_name if present.
4705 DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed
4706 to have already done the lookup to find the DWO/DWP file).
4708 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4709 THIS_CU->is_debug_types, but nothing else.
4711 We fill in THIS_CU->length.
4713 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4714 linker) then DIE_READER_FUNC will not get called.
4716 THIS_CU->cu is always freed when done.
4717 This is done in order to not leave THIS_CU->cu in a state where we have
4718 to care whether it refers to the "main" CU or the DWO CU. */
4721 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4722 struct dwarf2_section_info
*abbrev_section
,
4723 struct dwo_file
*dwo_file
,
4724 die_reader_func_ftype
*die_reader_func
,
4727 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4728 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4729 bfd
*abfd
= section
->asection
->owner
;
4730 struct dwarf2_cu cu
;
4731 gdb_byte
*begin_info_ptr
, *info_ptr
;
4732 struct die_reader_specs reader
;
4733 struct cleanup
*cleanups
;
4734 struct die_info
*comp_unit_die
;
4737 if (dwarf2_die_debug
)
4738 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4739 this_cu
->is_debug_types
? "type" : "comp",
4740 this_cu
->offset
.sect_off
);
4742 gdb_assert (this_cu
->cu
== NULL
);
4744 /* This is cheap if the section is already read in. */
4745 dwarf2_read_section (objfile
, section
);
4747 init_one_comp_unit (&cu
, this_cu
);
4749 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4751 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4752 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4753 abbrev_section
, info_ptr
,
4754 this_cu
->is_debug_types
);
4756 this_cu
->length
= get_cu_length (&cu
.header
);
4758 /* Skip dummy compilation units. */
4759 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4760 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4762 do_cleanups (cleanups
);
4766 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4767 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4769 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4770 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4772 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4774 do_cleanups (cleanups
);
4777 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4778 does not lookup the specified DWO file.
4779 This cannot be used to read DWO files.
4781 THIS_CU->cu is always freed when done.
4782 This is done in order to not leave THIS_CU->cu in a state where we have
4783 to care whether it refers to the "main" CU or the DWO CU.
4784 We can revisit this if the data shows there's a performance issue. */
4787 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4788 die_reader_func_ftype
*die_reader_func
,
4791 init_cutu_and_read_dies_no_follow (this_cu
,
4792 get_abbrev_section_for_cu (this_cu
),
4794 die_reader_func
, data
);
4797 /* Create a psymtab named NAME and assign it to PER_CU.
4799 The caller must fill in the following details:
4800 dirname, textlow, texthigh. */
4802 static struct partial_symtab
*
4803 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4805 struct objfile
*objfile
= per_cu
->objfile
;
4806 struct partial_symtab
*pst
;
4808 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4810 objfile
->global_psymbols
.next
,
4811 objfile
->static_psymbols
.next
);
4813 pst
->psymtabs_addrmap_supported
= 1;
4815 /* This is the glue that links PST into GDB's symbol API. */
4816 pst
->read_symtab_private
= per_cu
;
4817 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4818 per_cu
->v
.psymtab
= pst
;
4823 /* die_reader_func for process_psymtab_comp_unit. */
4826 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4828 struct die_info
*comp_unit_die
,
4832 struct dwarf2_cu
*cu
= reader
->cu
;
4833 struct objfile
*objfile
= cu
->objfile
;
4834 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4835 struct attribute
*attr
;
4837 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4838 struct partial_symtab
*pst
;
4840 const char *filename
;
4841 int *want_partial_unit_ptr
= data
;
4843 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4844 && (want_partial_unit_ptr
== NULL
4845 || !*want_partial_unit_ptr
))
4848 gdb_assert (! per_cu
->is_debug_types
);
4850 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4852 cu
->list_in_scope
= &file_symbols
;
4854 /* Allocate a new partial symbol table structure. */
4855 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4856 if (attr
== NULL
|| !DW_STRING (attr
))
4859 filename
= DW_STRING (attr
);
4861 pst
= create_partial_symtab (per_cu
, filename
);
4863 /* This must be done before calling dwarf2_build_include_psymtabs. */
4864 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4866 pst
->dirname
= DW_STRING (attr
);
4868 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4870 dwarf2_find_base_address (comp_unit_die
, cu
);
4872 /* Possibly set the default values of LOWPC and HIGHPC from
4874 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4875 &best_highpc
, cu
, pst
);
4876 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4877 /* Store the contiguous range if it is not empty; it can be empty for
4878 CUs with no code. */
4879 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4880 best_lowpc
+ baseaddr
,
4881 best_highpc
+ baseaddr
- 1, pst
);
4883 /* Check if comp unit has_children.
4884 If so, read the rest of the partial symbols from this comp unit.
4885 If not, there's no more debug_info for this comp unit. */
4888 struct partial_die_info
*first_die
;
4889 CORE_ADDR lowpc
, highpc
;
4891 lowpc
= ((CORE_ADDR
) -1);
4892 highpc
= ((CORE_ADDR
) 0);
4894 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4896 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4899 /* If we didn't find a lowpc, set it to highpc to avoid
4900 complaints from `maint check'. */
4901 if (lowpc
== ((CORE_ADDR
) -1))
4904 /* If the compilation unit didn't have an explicit address range,
4905 then use the information extracted from its child dies. */
4909 best_highpc
= highpc
;
4912 pst
->textlow
= best_lowpc
+ baseaddr
;
4913 pst
->texthigh
= best_highpc
+ baseaddr
;
4915 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4916 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4917 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4918 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4919 sort_pst_symbols (pst
);
4921 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
))
4924 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4925 struct dwarf2_per_cu_data
*iter
;
4927 /* Fill in 'dependencies' here; we fill in 'users' in a
4929 pst
->number_of_dependencies
= len
;
4930 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4931 len
* sizeof (struct symtab
*));
4933 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
4936 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4938 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4941 /* Get the list of files included in the current compilation unit,
4942 and build a psymtab for each of them. */
4943 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4945 if (dwarf2_read_debug
)
4947 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4949 fprintf_unfiltered (gdb_stdlog
,
4950 "Psymtab for %s unit @0x%x: %s - %s"
4951 ", %d global, %d static syms\n",
4952 per_cu
->is_debug_types
? "type" : "comp",
4953 per_cu
->offset
.sect_off
,
4954 paddress (gdbarch
, pst
->textlow
),
4955 paddress (gdbarch
, pst
->texthigh
),
4956 pst
->n_global_syms
, pst
->n_static_syms
);
4960 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4961 Process compilation unit THIS_CU for a psymtab. */
4964 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4965 int want_partial_unit
)
4967 /* If this compilation unit was already read in, free the
4968 cached copy in order to read it in again. This is
4969 necessary because we skipped some symbols when we first
4970 read in the compilation unit (see load_partial_dies).
4971 This problem could be avoided, but the benefit is unclear. */
4972 if (this_cu
->cu
!= NULL
)
4973 free_one_cached_comp_unit (this_cu
);
4975 gdb_assert (! this_cu
->is_debug_types
);
4976 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
4977 process_psymtab_comp_unit_reader
,
4978 &want_partial_unit
);
4980 /* Age out any secondary CUs. */
4981 age_cached_comp_units ();
4985 hash_type_unit_group (const void *item
)
4987 const struct type_unit_group
*tu_group
= item
;
4989 return hash_stmt_list_entry (&tu_group
->hash
);
4993 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
4995 const struct type_unit_group
*lhs
= item_lhs
;
4996 const struct type_unit_group
*rhs
= item_rhs
;
4998 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5001 /* Allocate a hash table for type unit groups. */
5004 allocate_type_unit_groups_table (void)
5006 return htab_create_alloc_ex (3,
5007 hash_type_unit_group
,
5010 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5011 hashtab_obstack_allocate
,
5012 dummy_obstack_deallocate
);
5015 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5016 partial symtabs. We combine several TUs per psymtab to not let the size
5017 of any one psymtab grow too big. */
5018 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5019 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5021 /* Helper routine for get_type_unit_group.
5022 Create the type_unit_group object used to hold one or more TUs. */
5024 static struct type_unit_group
*
5025 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5027 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5028 struct dwarf2_per_cu_data
*per_cu
;
5029 struct type_unit_group
*tu_group
;
5031 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5032 struct type_unit_group
);
5033 per_cu
= &tu_group
->per_cu
;
5034 per_cu
->objfile
= objfile
;
5035 per_cu
->is_debug_types
= 1;
5036 per_cu
->s
.type_unit_group
= tu_group
;
5038 if (dwarf2_per_objfile
->using_index
)
5040 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5041 struct dwarf2_per_cu_quick_data
);
5042 tu_group
->t
.first_tu
= cu
->per_cu
;
5046 unsigned int line_offset
= line_offset_struct
.sect_off
;
5047 struct partial_symtab
*pst
;
5050 /* Give the symtab a useful name for debug purposes. */
5051 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5052 name
= xstrprintf ("<type_units_%d>",
5053 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5055 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5057 pst
= create_partial_symtab (per_cu
, name
);
5063 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5064 tu_group
->hash
.line_offset
= line_offset_struct
;
5069 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5070 STMT_LIST is a DW_AT_stmt_list attribute. */
5072 static struct type_unit_group
*
5073 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
5075 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5076 struct type_unit_group
*tu_group
;
5078 unsigned int line_offset
;
5079 struct type_unit_group type_unit_group_for_lookup
;
5081 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5083 dwarf2_per_objfile
->type_unit_groups
=
5084 allocate_type_unit_groups_table ();
5087 /* Do we need to create a new group, or can we use an existing one? */
5091 line_offset
= DW_UNSND (stmt_list
);
5092 ++tu_stats
->nr_symtab_sharers
;
5096 /* Ugh, no stmt_list. Rare, but we have to handle it.
5097 We can do various things here like create one group per TU or
5098 spread them over multiple groups to split up the expansion work.
5099 To avoid worst case scenarios (too many groups or too large groups)
5100 we, umm, group them in bunches. */
5101 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5102 | (tu_stats
->nr_stmt_less_type_units
5103 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5104 ++tu_stats
->nr_stmt_less_type_units
;
5107 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5108 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5109 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5110 &type_unit_group_for_lookup
, INSERT
);
5114 gdb_assert (tu_group
!= NULL
);
5118 sect_offset line_offset_struct
;
5120 line_offset_struct
.sect_off
= line_offset
;
5121 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5123 ++tu_stats
->nr_symtabs
;
5129 /* Struct used to sort TUs by their abbreviation table offset. */
5131 struct tu_abbrev_offset
5133 struct signatured_type
*sig_type
;
5134 sect_offset abbrev_offset
;
5137 /* Helper routine for build_type_unit_groups, passed to qsort. */
5140 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
5142 const struct tu_abbrev_offset
* const *a
= ap
;
5143 const struct tu_abbrev_offset
* const *b
= bp
;
5144 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
5145 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
5147 return (aoff
> boff
) - (aoff
< boff
);
5150 /* A helper function to add a type_unit_group to a table. */
5153 add_type_unit_group_to_table (void **slot
, void *datum
)
5155 struct type_unit_group
*tu_group
= *slot
;
5156 struct type_unit_group
***datap
= datum
;
5164 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5165 each one passing FUNC,DATA.
5167 The efficiency is because we sort TUs by the abbrev table they use and
5168 only read each abbrev table once. In one program there are 200K TUs
5169 sharing 8K abbrev tables.
5171 The main purpose of this function is to support building the
5172 dwarf2_per_objfile->type_unit_groups table.
5173 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5174 can collapse the search space by grouping them by stmt_list.
5175 The savings can be significant, in the same program from above the 200K TUs
5176 share 8K stmt_list tables.
5178 FUNC is expected to call get_type_unit_group, which will create the
5179 struct type_unit_group if necessary and add it to
5180 dwarf2_per_objfile->type_unit_groups. */
5183 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
5185 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5186 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5187 struct cleanup
*cleanups
;
5188 struct abbrev_table
*abbrev_table
;
5189 sect_offset abbrev_offset
;
5190 struct tu_abbrev_offset
*sorted_by_abbrev
;
5191 struct type_unit_group
**iter
;
5194 /* It's up to the caller to not call us multiple times. */
5195 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
5197 if (dwarf2_per_objfile
->n_type_units
== 0)
5200 /* TUs typically share abbrev tables, and there can be way more TUs than
5201 abbrev tables. Sort by abbrev table to reduce the number of times we
5202 read each abbrev table in.
5203 Alternatives are to punt or to maintain a cache of abbrev tables.
5204 This is simpler and efficient enough for now.
5206 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5207 symtab to use). Typically TUs with the same abbrev offset have the same
5208 stmt_list value too so in practice this should work well.
5210 The basic algorithm here is:
5212 sort TUs by abbrev table
5213 for each TU with same abbrev table:
5214 read abbrev table if first user
5215 read TU top level DIE
5216 [IWBN if DWO skeletons had DW_AT_stmt_list]
5219 if (dwarf2_read_debug
)
5220 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5222 /* Sort in a separate table to maintain the order of all_type_units
5223 for .gdb_index: TU indices directly index all_type_units. */
5224 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5225 dwarf2_per_objfile
->n_type_units
);
5226 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5228 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5230 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5231 sorted_by_abbrev
[i
].abbrev_offset
=
5232 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
5233 sig_type
->per_cu
.offset
);
5235 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5236 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5237 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5239 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5240 called any number of times, so we don't reset tu_stats here. */
5242 abbrev_offset
.sect_off
= ~(unsigned) 0;
5243 abbrev_table
= NULL
;
5244 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5246 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5248 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5250 /* Switch to the next abbrev table if necessary. */
5251 if (abbrev_table
== NULL
5252 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5254 if (abbrev_table
!= NULL
)
5256 abbrev_table_free (abbrev_table
);
5257 /* Reset to NULL in case abbrev_table_read_table throws
5258 an error: abbrev_table_free_cleanup will get called. */
5259 abbrev_table
= NULL
;
5261 abbrev_offset
= tu
->abbrev_offset
;
5263 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5265 ++tu_stats
->nr_uniq_abbrev_tables
;
5268 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5272 /* Create a vector of pointers to primary type units to make it easy to
5273 iterate over them and CUs. See dw2_get_primary_cu. */
5274 dwarf2_per_objfile
->n_type_unit_groups
=
5275 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5276 dwarf2_per_objfile
->all_type_unit_groups
=
5277 obstack_alloc (&objfile
->objfile_obstack
,
5278 dwarf2_per_objfile
->n_type_unit_groups
5279 * sizeof (struct type_unit_group
*));
5280 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5281 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5282 add_type_unit_group_to_table
, &iter
);
5283 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5284 == dwarf2_per_objfile
->n_type_unit_groups
);
5286 do_cleanups (cleanups
);
5288 if (dwarf2_read_debug
)
5290 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5291 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5292 dwarf2_per_objfile
->n_type_units
);
5293 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5294 tu_stats
->nr_uniq_abbrev_tables
);
5295 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5296 tu_stats
->nr_symtabs
);
5297 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5298 tu_stats
->nr_symtab_sharers
);
5299 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5300 tu_stats
->nr_stmt_less_type_units
);
5304 /* Reader function for build_type_psymtabs. */
5307 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5309 struct die_info
*type_unit_die
,
5313 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5314 struct dwarf2_cu
*cu
= reader
->cu
;
5315 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5316 struct type_unit_group
*tu_group
;
5317 struct attribute
*attr
;
5318 struct partial_die_info
*first_die
;
5319 CORE_ADDR lowpc
, highpc
;
5320 struct partial_symtab
*pst
;
5322 gdb_assert (data
== NULL
);
5327 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5328 tu_group
= get_type_unit_group (cu
, attr
);
5330 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, per_cu
);
5332 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5333 cu
->list_in_scope
= &file_symbols
;
5334 pst
= create_partial_symtab (per_cu
, "");
5337 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5339 lowpc
= (CORE_ADDR
) -1;
5340 highpc
= (CORE_ADDR
) 0;
5341 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5343 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5344 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5345 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5346 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5347 sort_pst_symbols (pst
);
5350 /* Traversal function for build_type_psymtabs. */
5353 build_type_psymtab_dependencies (void **slot
, void *info
)
5355 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5356 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5357 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5358 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5359 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5360 struct dwarf2_per_cu_data
*iter
;
5363 gdb_assert (len
> 0);
5365 pst
->number_of_dependencies
= len
;
5366 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5367 len
* sizeof (struct psymtab
*));
5369 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, i
, iter
);
5372 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5373 iter
->s
.type_unit_group
= tu_group
;
5376 VEC_free (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5381 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5382 Build partial symbol tables for the .debug_types comp-units. */
5385 build_type_psymtabs (struct objfile
*objfile
)
5387 if (! create_all_type_units (objfile
))
5390 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5392 /* Now that all TUs have been processed we can fill in the dependencies. */
5393 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5394 build_type_psymtab_dependencies
, NULL
);
5397 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5400 psymtabs_addrmap_cleanup (void *o
)
5402 struct objfile
*objfile
= o
;
5404 objfile
->psymtabs_addrmap
= NULL
;
5407 /* Compute the 'user' field for each psymtab in OBJFILE. */
5410 set_partial_user (struct objfile
*objfile
)
5414 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5416 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5417 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5423 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5425 /* Set the 'user' field only if it is not already set. */
5426 if (pst
->dependencies
[j
]->user
== NULL
)
5427 pst
->dependencies
[j
]->user
= pst
;
5432 /* Build the partial symbol table by doing a quick pass through the
5433 .debug_info and .debug_abbrev sections. */
5436 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5438 struct cleanup
*back_to
, *addrmap_cleanup
;
5439 struct obstack temp_obstack
;
5442 if (dwarf2_read_debug
)
5444 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5448 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5450 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5452 /* Any cached compilation units will be linked by the per-objfile
5453 read_in_chain. Make sure to free them when we're done. */
5454 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5456 build_type_psymtabs (objfile
);
5458 create_all_comp_units (objfile
);
5460 /* Create a temporary address map on a temporary obstack. We later
5461 copy this to the final obstack. */
5462 obstack_init (&temp_obstack
);
5463 make_cleanup_obstack_free (&temp_obstack
);
5464 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5465 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5467 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5469 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5471 process_psymtab_comp_unit (per_cu
, 0);
5474 set_partial_user (objfile
);
5476 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5477 &objfile
->objfile_obstack
);
5478 discard_cleanups (addrmap_cleanup
);
5480 do_cleanups (back_to
);
5482 if (dwarf2_read_debug
)
5483 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5487 /* die_reader_func for load_partial_comp_unit. */
5490 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5492 struct die_info
*comp_unit_die
,
5496 struct dwarf2_cu
*cu
= reader
->cu
;
5498 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5500 /* Check if comp unit has_children.
5501 If so, read the rest of the partial symbols from this comp unit.
5502 If not, there's no more debug_info for this comp unit. */
5504 load_partial_dies (reader
, info_ptr
, 0);
5507 /* Load the partial DIEs for a secondary CU into memory.
5508 This is also used when rereading a primary CU with load_all_dies. */
5511 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5513 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5514 load_partial_comp_unit_reader
, NULL
);
5518 read_comp_units_from_section (struct objfile
*objfile
,
5519 struct dwarf2_section_info
*section
,
5520 unsigned int is_dwz
,
5523 struct dwarf2_per_cu_data
***all_comp_units
)
5526 bfd
*abfd
= section
->asection
->owner
;
5528 dwarf2_read_section (objfile
, section
);
5530 info_ptr
= section
->buffer
;
5532 while (info_ptr
< section
->buffer
+ section
->size
)
5534 unsigned int length
, initial_length_size
;
5535 struct dwarf2_per_cu_data
*this_cu
;
5538 offset
.sect_off
= info_ptr
- section
->buffer
;
5540 /* Read just enough information to find out where the next
5541 compilation unit is. */
5542 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5544 /* Save the compilation unit for later lookup. */
5545 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5546 sizeof (struct dwarf2_per_cu_data
));
5547 memset (this_cu
, 0, sizeof (*this_cu
));
5548 this_cu
->offset
= offset
;
5549 this_cu
->length
= length
+ initial_length_size
;
5550 this_cu
->is_dwz
= is_dwz
;
5551 this_cu
->objfile
= objfile
;
5552 this_cu
->info_or_types_section
= section
;
5554 if (*n_comp_units
== *n_allocated
)
5557 *all_comp_units
= xrealloc (*all_comp_units
,
5559 * sizeof (struct dwarf2_per_cu_data
*));
5561 (*all_comp_units
)[*n_comp_units
] = this_cu
;
5564 info_ptr
= info_ptr
+ this_cu
->length
;
5568 /* Create a list of all compilation units in OBJFILE.
5569 This is only done for -readnow and building partial symtabs. */
5572 create_all_comp_units (struct objfile
*objfile
)
5576 struct dwarf2_per_cu_data
**all_comp_units
;
5580 all_comp_units
= xmalloc (n_allocated
5581 * sizeof (struct dwarf2_per_cu_data
*));
5583 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
5584 &n_allocated
, &n_comp_units
, &all_comp_units
);
5586 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
5588 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
5590 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
5591 &n_allocated
, &n_comp_units
,
5595 dwarf2_per_objfile
->all_comp_units
5596 = obstack_alloc (&objfile
->objfile_obstack
,
5597 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5598 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5599 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5600 xfree (all_comp_units
);
5601 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5604 /* Process all loaded DIEs for compilation unit CU, starting at
5605 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5606 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5607 DW_AT_ranges). If NEED_PC is set, then this function will set
5608 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5609 and record the covered ranges in the addrmap. */
5612 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5613 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5615 struct partial_die_info
*pdi
;
5617 /* Now, march along the PDI's, descending into ones which have
5618 interesting children but skipping the children of the other ones,
5619 until we reach the end of the compilation unit. */
5625 fixup_partial_die (pdi
, cu
);
5627 /* Anonymous namespaces or modules have no name but have interesting
5628 children, so we need to look at them. Ditto for anonymous
5631 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5632 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5633 || pdi
->tag
== DW_TAG_imported_unit
)
5637 case DW_TAG_subprogram
:
5638 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5640 case DW_TAG_constant
:
5641 case DW_TAG_variable
:
5642 case DW_TAG_typedef
:
5643 case DW_TAG_union_type
:
5644 if (!pdi
->is_declaration
)
5646 add_partial_symbol (pdi
, cu
);
5649 case DW_TAG_class_type
:
5650 case DW_TAG_interface_type
:
5651 case DW_TAG_structure_type
:
5652 if (!pdi
->is_declaration
)
5654 add_partial_symbol (pdi
, cu
);
5657 case DW_TAG_enumeration_type
:
5658 if (!pdi
->is_declaration
)
5659 add_partial_enumeration (pdi
, cu
);
5661 case DW_TAG_base_type
:
5662 case DW_TAG_subrange_type
:
5663 /* File scope base type definitions are added to the partial
5665 add_partial_symbol (pdi
, cu
);
5667 case DW_TAG_namespace
:
5668 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5671 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5673 case DW_TAG_imported_unit
:
5675 struct dwarf2_per_cu_data
*per_cu
;
5677 /* For now we don't handle imported units in type units. */
5678 if (cu
->per_cu
->is_debug_types
)
5680 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5681 " supported in type units [in module %s]"),
5685 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5689 /* Go read the partial unit, if needed. */
5690 if (per_cu
->v
.psymtab
== NULL
)
5691 process_psymtab_comp_unit (per_cu
, 1);
5693 VEC_safe_push (dwarf2_per_cu_ptr
,
5694 cu
->per_cu
->s
.imported_symtabs
, per_cu
);
5702 /* If the die has a sibling, skip to the sibling. */
5704 pdi
= pdi
->die_sibling
;
5708 /* Functions used to compute the fully scoped name of a partial DIE.
5710 Normally, this is simple. For C++, the parent DIE's fully scoped
5711 name is concatenated with "::" and the partial DIE's name. For
5712 Java, the same thing occurs except that "." is used instead of "::".
5713 Enumerators are an exception; they use the scope of their parent
5714 enumeration type, i.e. the name of the enumeration type is not
5715 prepended to the enumerator.
5717 There are two complexities. One is DW_AT_specification; in this
5718 case "parent" means the parent of the target of the specification,
5719 instead of the direct parent of the DIE. The other is compilers
5720 which do not emit DW_TAG_namespace; in this case we try to guess
5721 the fully qualified name of structure types from their members'
5722 linkage names. This must be done using the DIE's children rather
5723 than the children of any DW_AT_specification target. We only need
5724 to do this for structures at the top level, i.e. if the target of
5725 any DW_AT_specification (if any; otherwise the DIE itself) does not
5728 /* Compute the scope prefix associated with PDI's parent, in
5729 compilation unit CU. The result will be allocated on CU's
5730 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5731 field. NULL is returned if no prefix is necessary. */
5733 partial_die_parent_scope (struct partial_die_info
*pdi
,
5734 struct dwarf2_cu
*cu
)
5736 char *grandparent_scope
;
5737 struct partial_die_info
*parent
, *real_pdi
;
5739 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5740 then this means the parent of the specification DIE. */
5743 while (real_pdi
->has_specification
)
5744 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
5745 real_pdi
->spec_is_dwz
, cu
);
5747 parent
= real_pdi
->die_parent
;
5751 if (parent
->scope_set
)
5752 return parent
->scope
;
5754 fixup_partial_die (parent
, cu
);
5756 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5758 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5759 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5760 Work around this problem here. */
5761 if (cu
->language
== language_cplus
5762 && parent
->tag
== DW_TAG_namespace
5763 && strcmp (parent
->name
, "::") == 0
5764 && grandparent_scope
== NULL
)
5766 parent
->scope
= NULL
;
5767 parent
->scope_set
= 1;
5771 if (pdi
->tag
== DW_TAG_enumerator
)
5772 /* Enumerators should not get the name of the enumeration as a prefix. */
5773 parent
->scope
= grandparent_scope
;
5774 else if (parent
->tag
== DW_TAG_namespace
5775 || parent
->tag
== DW_TAG_module
5776 || parent
->tag
== DW_TAG_structure_type
5777 || parent
->tag
== DW_TAG_class_type
5778 || parent
->tag
== DW_TAG_interface_type
5779 || parent
->tag
== DW_TAG_union_type
5780 || parent
->tag
== DW_TAG_enumeration_type
)
5782 if (grandparent_scope
== NULL
)
5783 parent
->scope
= parent
->name
;
5785 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5787 parent
->name
, 0, cu
);
5791 /* FIXME drow/2004-04-01: What should we be doing with
5792 function-local names? For partial symbols, we should probably be
5794 complaint (&symfile_complaints
,
5795 _("unhandled containing DIE tag %d for DIE at %d"),
5796 parent
->tag
, pdi
->offset
.sect_off
);
5797 parent
->scope
= grandparent_scope
;
5800 parent
->scope_set
= 1;
5801 return parent
->scope
;
5804 /* Return the fully scoped name associated with PDI, from compilation unit
5805 CU. The result will be allocated with malloc. */
5808 partial_die_full_name (struct partial_die_info
*pdi
,
5809 struct dwarf2_cu
*cu
)
5813 /* If this is a template instantiation, we can not work out the
5814 template arguments from partial DIEs. So, unfortunately, we have
5815 to go through the full DIEs. At least any work we do building
5816 types here will be reused if full symbols are loaded later. */
5817 if (pdi
->has_template_arguments
)
5819 fixup_partial_die (pdi
, cu
);
5821 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5823 struct die_info
*die
;
5824 struct attribute attr
;
5825 struct dwarf2_cu
*ref_cu
= cu
;
5827 /* DW_FORM_ref_addr is using section offset. */
5829 attr
.form
= DW_FORM_ref_addr
;
5830 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5831 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5833 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5837 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5838 if (parent_scope
== NULL
)
5841 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5845 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5847 struct objfile
*objfile
= cu
->objfile
;
5849 char *actual_name
= NULL
;
5851 int built_actual_name
= 0;
5853 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5855 actual_name
= partial_die_full_name (pdi
, cu
);
5857 built_actual_name
= 1;
5859 if (actual_name
== NULL
)
5860 actual_name
= pdi
->name
;
5864 case DW_TAG_subprogram
:
5865 if (pdi
->is_external
|| cu
->language
== language_ada
)
5867 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5868 of the global scope. But in Ada, we want to be able to access
5869 nested procedures globally. So all Ada subprograms are stored
5870 in the global scope. */
5871 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5872 mst_text, objfile); */
5873 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5875 VAR_DOMAIN
, LOC_BLOCK
,
5876 &objfile
->global_psymbols
,
5877 0, pdi
->lowpc
+ baseaddr
,
5878 cu
->language
, objfile
);
5882 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5883 mst_file_text, objfile); */
5884 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5886 VAR_DOMAIN
, LOC_BLOCK
,
5887 &objfile
->static_psymbols
,
5888 0, pdi
->lowpc
+ baseaddr
,
5889 cu
->language
, objfile
);
5892 case DW_TAG_constant
:
5894 struct psymbol_allocation_list
*list
;
5896 if (pdi
->is_external
)
5897 list
= &objfile
->global_psymbols
;
5899 list
= &objfile
->static_psymbols
;
5900 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5901 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
5902 list
, 0, 0, cu
->language
, objfile
);
5905 case DW_TAG_variable
:
5907 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5911 && !dwarf2_per_objfile
->has_section_at_zero
)
5913 /* A global or static variable may also have been stripped
5914 out by the linker if unused, in which case its address
5915 will be nullified; do not add such variables into partial
5916 symbol table then. */
5918 else if (pdi
->is_external
)
5921 Don't enter into the minimal symbol tables as there is
5922 a minimal symbol table entry from the ELF symbols already.
5923 Enter into partial symbol table if it has a location
5924 descriptor or a type.
5925 If the location descriptor is missing, new_symbol will create
5926 a LOC_UNRESOLVED symbol, the address of the variable will then
5927 be determined from the minimal symbol table whenever the variable
5929 The address for the partial symbol table entry is not
5930 used by GDB, but it comes in handy for debugging partial symbol
5933 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5934 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5936 VAR_DOMAIN
, LOC_STATIC
,
5937 &objfile
->global_psymbols
,
5939 cu
->language
, objfile
);
5943 /* Static Variable. Skip symbols without location descriptors. */
5944 if (pdi
->d
.locdesc
== NULL
)
5946 if (built_actual_name
)
5947 xfree (actual_name
);
5950 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
5951 mst_file_data, objfile); */
5952 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5954 VAR_DOMAIN
, LOC_STATIC
,
5955 &objfile
->static_psymbols
,
5957 cu
->language
, objfile
);
5960 case DW_TAG_typedef
:
5961 case DW_TAG_base_type
:
5962 case DW_TAG_subrange_type
:
5963 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5965 VAR_DOMAIN
, LOC_TYPEDEF
,
5966 &objfile
->static_psymbols
,
5967 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5969 case DW_TAG_namespace
:
5970 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5972 VAR_DOMAIN
, LOC_TYPEDEF
,
5973 &objfile
->global_psymbols
,
5974 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5976 case DW_TAG_class_type
:
5977 case DW_TAG_interface_type
:
5978 case DW_TAG_structure_type
:
5979 case DW_TAG_union_type
:
5980 case DW_TAG_enumeration_type
:
5981 /* Skip external references. The DWARF standard says in the section
5982 about "Structure, Union, and Class Type Entries": "An incomplete
5983 structure, union or class type is represented by a structure,
5984 union or class entry that does not have a byte size attribute
5985 and that has a DW_AT_declaration attribute." */
5986 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
5988 if (built_actual_name
)
5989 xfree (actual_name
);
5993 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5994 static vs. global. */
5995 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5997 STRUCT_DOMAIN
, LOC_TYPEDEF
,
5998 (cu
->language
== language_cplus
5999 || cu
->language
== language_java
)
6000 ? &objfile
->global_psymbols
6001 : &objfile
->static_psymbols
,
6002 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6005 case DW_TAG_enumerator
:
6006 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6008 VAR_DOMAIN
, LOC_CONST
,
6009 (cu
->language
== language_cplus
6010 || cu
->language
== language_java
)
6011 ? &objfile
->global_psymbols
6012 : &objfile
->static_psymbols
,
6013 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6019 if (built_actual_name
)
6020 xfree (actual_name
);
6023 /* Read a partial die corresponding to a namespace; also, add a symbol
6024 corresponding to that namespace to the symbol table. NAMESPACE is
6025 the name of the enclosing namespace. */
6028 add_partial_namespace (struct partial_die_info
*pdi
,
6029 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6030 int need_pc
, struct dwarf2_cu
*cu
)
6032 /* Add a symbol for the namespace. */
6034 add_partial_symbol (pdi
, cu
);
6036 /* Now scan partial symbols in that namespace. */
6038 if (pdi
->has_children
)
6039 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6042 /* Read a partial die corresponding to a Fortran module. */
6045 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
6046 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
6048 /* Now scan partial symbols in that module. */
6050 if (pdi
->has_children
)
6051 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6054 /* Read a partial die corresponding to a subprogram and create a partial
6055 symbol for that subprogram. When the CU language allows it, this
6056 routine also defines a partial symbol for each nested subprogram
6057 that this subprogram contains.
6059 DIE my also be a lexical block, in which case we simply search
6060 recursively for suprograms defined inside that lexical block.
6061 Again, this is only performed when the CU language allows this
6062 type of definitions. */
6065 add_partial_subprogram (struct partial_die_info
*pdi
,
6066 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6067 int need_pc
, struct dwarf2_cu
*cu
)
6069 if (pdi
->tag
== DW_TAG_subprogram
)
6071 if (pdi
->has_pc_info
)
6073 if (pdi
->lowpc
< *lowpc
)
6074 *lowpc
= pdi
->lowpc
;
6075 if (pdi
->highpc
> *highpc
)
6076 *highpc
= pdi
->highpc
;
6080 struct objfile
*objfile
= cu
->objfile
;
6082 baseaddr
= ANOFFSET (objfile
->section_offsets
,
6083 SECT_OFF_TEXT (objfile
));
6084 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6085 pdi
->lowpc
+ baseaddr
,
6086 pdi
->highpc
- 1 + baseaddr
,
6087 cu
->per_cu
->v
.psymtab
);
6091 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
6093 if (!pdi
->is_declaration
)
6094 /* Ignore subprogram DIEs that do not have a name, they are
6095 illegal. Do not emit a complaint at this point, we will
6096 do so when we convert this psymtab into a symtab. */
6098 add_partial_symbol (pdi
, cu
);
6102 if (! pdi
->has_children
)
6105 if (cu
->language
== language_ada
)
6107 pdi
= pdi
->die_child
;
6110 fixup_partial_die (pdi
, cu
);
6111 if (pdi
->tag
== DW_TAG_subprogram
6112 || pdi
->tag
== DW_TAG_lexical_block
)
6113 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6114 pdi
= pdi
->die_sibling
;
6119 /* Read a partial die corresponding to an enumeration type. */
6122 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
6123 struct dwarf2_cu
*cu
)
6125 struct partial_die_info
*pdi
;
6127 if (enum_pdi
->name
!= NULL
)
6128 add_partial_symbol (enum_pdi
, cu
);
6130 pdi
= enum_pdi
->die_child
;
6133 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
6134 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6136 add_partial_symbol (pdi
, cu
);
6137 pdi
= pdi
->die_sibling
;
6141 /* Return the initial uleb128 in the die at INFO_PTR. */
6144 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
6146 unsigned int bytes_read
;
6148 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6151 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6152 Return the corresponding abbrev, or NULL if the number is zero (indicating
6153 an empty DIE). In either case *BYTES_READ will be set to the length of
6154 the initial number. */
6156 static struct abbrev_info
*
6157 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
6158 struct dwarf2_cu
*cu
)
6160 bfd
*abfd
= cu
->objfile
->obfd
;
6161 unsigned int abbrev_number
;
6162 struct abbrev_info
*abbrev
;
6164 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
6166 if (abbrev_number
== 0)
6169 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
6172 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6173 abbrev_number
, bfd_get_filename (abfd
));
6179 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6180 Returns a pointer to the end of a series of DIEs, terminated by an empty
6181 DIE. Any children of the skipped DIEs will also be skipped. */
6184 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
6186 struct dwarf2_cu
*cu
= reader
->cu
;
6187 struct abbrev_info
*abbrev
;
6188 unsigned int bytes_read
;
6192 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6194 return info_ptr
+ bytes_read
;
6196 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
6200 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6201 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6202 abbrev corresponding to that skipped uleb128 should be passed in
6203 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6207 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
6208 struct abbrev_info
*abbrev
)
6210 unsigned int bytes_read
;
6211 struct attribute attr
;
6212 bfd
*abfd
= reader
->abfd
;
6213 struct dwarf2_cu
*cu
= reader
->cu
;
6214 gdb_byte
*buffer
= reader
->buffer
;
6215 const gdb_byte
*buffer_end
= reader
->buffer_end
;
6216 gdb_byte
*start_info_ptr
= info_ptr
;
6217 unsigned int form
, i
;
6219 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
6221 /* The only abbrev we care about is DW_AT_sibling. */
6222 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
6224 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
6225 if (attr
.form
== DW_FORM_ref_addr
)
6226 complaint (&symfile_complaints
,
6227 _("ignoring absolute DW_AT_sibling"));
6229 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
6232 /* If it isn't DW_AT_sibling, skip this attribute. */
6233 form
= abbrev
->attrs
[i
].form
;
6237 case DW_FORM_ref_addr
:
6238 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6239 and later it is offset sized. */
6240 if (cu
->header
.version
== 2)
6241 info_ptr
+= cu
->header
.addr_size
;
6243 info_ptr
+= cu
->header
.offset_size
;
6245 case DW_FORM_GNU_ref_alt
:
6246 info_ptr
+= cu
->header
.offset_size
;
6249 info_ptr
+= cu
->header
.addr_size
;
6256 case DW_FORM_flag_present
:
6268 case DW_FORM_ref_sig8
:
6271 case DW_FORM_string
:
6272 read_direct_string (abfd
, info_ptr
, &bytes_read
);
6273 info_ptr
+= bytes_read
;
6275 case DW_FORM_sec_offset
:
6277 case DW_FORM_GNU_strp_alt
:
6278 info_ptr
+= cu
->header
.offset_size
;
6280 case DW_FORM_exprloc
:
6282 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6283 info_ptr
+= bytes_read
;
6285 case DW_FORM_block1
:
6286 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
6288 case DW_FORM_block2
:
6289 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
6291 case DW_FORM_block4
:
6292 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
6296 case DW_FORM_ref_udata
:
6297 case DW_FORM_GNU_addr_index
:
6298 case DW_FORM_GNU_str_index
:
6299 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
6301 case DW_FORM_indirect
:
6302 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6303 info_ptr
+= bytes_read
;
6304 /* We need to continue parsing from here, so just go back to
6306 goto skip_attribute
;
6309 error (_("Dwarf Error: Cannot handle %s "
6310 "in DWARF reader [in module %s]"),
6311 dwarf_form_name (form
),
6312 bfd_get_filename (abfd
));
6316 if (abbrev
->has_children
)
6317 return skip_children (reader
, info_ptr
);
6322 /* Locate ORIG_PDI's sibling.
6323 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6326 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6327 struct partial_die_info
*orig_pdi
,
6330 /* Do we know the sibling already? */
6332 if (orig_pdi
->sibling
)
6333 return orig_pdi
->sibling
;
6335 /* Are there any children to deal with? */
6337 if (!orig_pdi
->has_children
)
6340 /* Skip the children the long way. */
6342 return skip_children (reader
, info_ptr
);
6345 /* Expand this partial symbol table into a full symbol table. */
6348 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
6354 warning (_("bug: psymtab for %s is already read in."),
6361 printf_filtered (_("Reading in symbols for %s..."),
6363 gdb_flush (gdb_stdout
);
6366 /* Restore our global data. */
6367 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
6368 dwarf2_objfile_data_key
);
6370 /* If this psymtab is constructed from a debug-only objfile, the
6371 has_section_at_zero flag will not necessarily be correct. We
6372 can get the correct value for this flag by looking at the data
6373 associated with the (presumably stripped) associated objfile. */
6374 if (pst
->objfile
->separate_debug_objfile_backlink
)
6376 struct dwarf2_per_objfile
*dpo_backlink
6377 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
6378 dwarf2_objfile_data_key
);
6380 dwarf2_per_objfile
->has_section_at_zero
6381 = dpo_backlink
->has_section_at_zero
;
6384 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6386 psymtab_to_symtab_1 (pst
);
6388 /* Finish up the debug error message. */
6390 printf_filtered (_("done.\n"));
6394 process_cu_includes ();
6397 /* Reading in full CUs. */
6399 /* Add PER_CU to the queue. */
6402 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6403 enum language pretend_language
)
6405 struct dwarf2_queue_item
*item
;
6408 item
= xmalloc (sizeof (*item
));
6409 item
->per_cu
= per_cu
;
6410 item
->pretend_language
= pretend_language
;
6413 if (dwarf2_queue
== NULL
)
6414 dwarf2_queue
= item
;
6416 dwarf2_queue_tail
->next
= item
;
6418 dwarf2_queue_tail
= item
;
6421 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6422 unit and add it to our queue.
6423 The result is non-zero if PER_CU was queued, otherwise the result is zero
6424 meaning either PER_CU is already queued or it is already loaded. */
6427 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6428 struct dwarf2_per_cu_data
*per_cu
,
6429 enum language pretend_language
)
6431 /* We may arrive here during partial symbol reading, if we need full
6432 DIEs to process an unusual case (e.g. template arguments). Do
6433 not queue PER_CU, just tell our caller to load its DIEs. */
6434 if (dwarf2_per_objfile
->reading_partial_symbols
)
6436 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6441 /* Mark the dependence relation so that we don't flush PER_CU
6443 dwarf2_add_dependence (this_cu
, per_cu
);
6445 /* If it's already on the queue, we have nothing to do. */
6449 /* If the compilation unit is already loaded, just mark it as
6451 if (per_cu
->cu
!= NULL
)
6453 per_cu
->cu
->last_used
= 0;
6457 /* Add it to the queue. */
6458 queue_comp_unit (per_cu
, pretend_language
);
6463 /* Process the queue. */
6466 process_queue (void)
6468 struct dwarf2_queue_item
*item
, *next_item
;
6470 if (dwarf2_read_debug
)
6472 fprintf_unfiltered (gdb_stdlog
,
6473 "Expanding one or more symtabs of objfile %s ...\n",
6474 dwarf2_per_objfile
->objfile
->name
);
6477 /* The queue starts out with one item, but following a DIE reference
6478 may load a new CU, adding it to the end of the queue. */
6479 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6481 if (dwarf2_per_objfile
->using_index
6482 ? !item
->per_cu
->v
.quick
->symtab
6483 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6485 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6487 if (dwarf2_read_debug
)
6489 fprintf_unfiltered (gdb_stdlog
,
6490 "Expanding symtab of %s at offset 0x%x\n",
6491 per_cu
->is_debug_types
? "TU" : "CU",
6492 per_cu
->offset
.sect_off
);
6495 if (per_cu
->is_debug_types
)
6496 process_full_type_unit (per_cu
, item
->pretend_language
);
6498 process_full_comp_unit (per_cu
, item
->pretend_language
);
6500 if (dwarf2_read_debug
)
6502 fprintf_unfiltered (gdb_stdlog
,
6503 "Done expanding %s at offset 0x%x\n",
6504 per_cu
->is_debug_types
? "TU" : "CU",
6505 per_cu
->offset
.sect_off
);
6509 item
->per_cu
->queued
= 0;
6510 next_item
= item
->next
;
6514 dwarf2_queue_tail
= NULL
;
6516 if (dwarf2_read_debug
)
6518 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6519 dwarf2_per_objfile
->objfile
->name
);
6523 /* Free all allocated queue entries. This function only releases anything if
6524 an error was thrown; if the queue was processed then it would have been
6525 freed as we went along. */
6528 dwarf2_release_queue (void *dummy
)
6530 struct dwarf2_queue_item
*item
, *last
;
6532 item
= dwarf2_queue
;
6535 /* Anything still marked queued is likely to be in an
6536 inconsistent state, so discard it. */
6537 if (item
->per_cu
->queued
)
6539 if (item
->per_cu
->cu
!= NULL
)
6540 free_one_cached_comp_unit (item
->per_cu
);
6541 item
->per_cu
->queued
= 0;
6549 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6552 /* Read in full symbols for PST, and anything it depends on. */
6555 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6557 struct dwarf2_per_cu_data
*per_cu
;
6563 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6564 if (!pst
->dependencies
[i
]->readin
6565 && pst
->dependencies
[i
]->user
== NULL
)
6567 /* Inform about additional files that need to be read in. */
6570 /* FIXME: i18n: Need to make this a single string. */
6571 fputs_filtered (" ", gdb_stdout
);
6573 fputs_filtered ("and ", gdb_stdout
);
6575 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6576 wrap_here (""); /* Flush output. */
6577 gdb_flush (gdb_stdout
);
6579 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6582 per_cu
= pst
->read_symtab_private
;
6586 /* It's an include file, no symbols to read for it.
6587 Everything is in the parent symtab. */
6592 dw2_do_instantiate_symtab (per_cu
);
6595 /* Trivial hash function for die_info: the hash value of a DIE
6596 is its offset in .debug_info for this objfile. */
6599 die_hash (const void *item
)
6601 const struct die_info
*die
= item
;
6603 return die
->offset
.sect_off
;
6606 /* Trivial comparison function for die_info structures: two DIEs
6607 are equal if they have the same offset. */
6610 die_eq (const void *item_lhs
, const void *item_rhs
)
6612 const struct die_info
*die_lhs
= item_lhs
;
6613 const struct die_info
*die_rhs
= item_rhs
;
6615 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6618 /* die_reader_func for load_full_comp_unit.
6619 This is identical to read_signatured_type_reader,
6620 but is kept separate for now. */
6623 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6625 struct die_info
*comp_unit_die
,
6629 struct dwarf2_cu
*cu
= reader
->cu
;
6630 enum language
*language_ptr
= data
;
6632 gdb_assert (cu
->die_hash
== NULL
);
6634 htab_create_alloc_ex (cu
->header
.length
/ 12,
6638 &cu
->comp_unit_obstack
,
6639 hashtab_obstack_allocate
,
6640 dummy_obstack_deallocate
);
6643 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6644 &info_ptr
, comp_unit_die
);
6645 cu
->dies
= comp_unit_die
;
6646 /* comp_unit_die is not stored in die_hash, no need. */
6648 /* We try not to read any attributes in this function, because not
6649 all CUs needed for references have been loaded yet, and symbol
6650 table processing isn't initialized. But we have to set the CU language,
6651 or we won't be able to build types correctly.
6652 Similarly, if we do not read the producer, we can not apply
6653 producer-specific interpretation. */
6654 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6657 /* Load the DIEs associated with PER_CU into memory. */
6660 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6661 enum language pretend_language
)
6663 gdb_assert (! this_cu
->is_debug_types
);
6665 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6666 load_full_comp_unit_reader
, &pretend_language
);
6669 /* Add a DIE to the delayed physname list. */
6672 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6673 const char *name
, struct die_info
*die
,
6674 struct dwarf2_cu
*cu
)
6676 struct delayed_method_info mi
;
6678 mi
.fnfield_index
= fnfield_index
;
6682 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6685 /* A cleanup for freeing the delayed method list. */
6688 free_delayed_list (void *ptr
)
6690 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6691 if (cu
->method_list
!= NULL
)
6693 VEC_free (delayed_method_info
, cu
->method_list
);
6694 cu
->method_list
= NULL
;
6698 /* Compute the physnames of any methods on the CU's method list.
6700 The computation of method physnames is delayed in order to avoid the
6701 (bad) condition that one of the method's formal parameters is of an as yet
6705 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6708 struct delayed_method_info
*mi
;
6709 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6711 const char *physname
;
6712 struct fn_fieldlist
*fn_flp
6713 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6714 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6715 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6719 /* Go objects should be embedded in a DW_TAG_module DIE,
6720 and it's not clear if/how imported objects will appear.
6721 To keep Go support simple until that's worked out,
6722 go back through what we've read and create something usable.
6723 We could do this while processing each DIE, and feels kinda cleaner,
6724 but that way is more invasive.
6725 This is to, for example, allow the user to type "p var" or "b main"
6726 without having to specify the package name, and allow lookups
6727 of module.object to work in contexts that use the expression
6731 fixup_go_packaging (struct dwarf2_cu
*cu
)
6733 char *package_name
= NULL
;
6734 struct pending
*list
;
6737 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6739 for (i
= 0; i
< list
->nsyms
; ++i
)
6741 struct symbol
*sym
= list
->symbol
[i
];
6743 if (SYMBOL_LANGUAGE (sym
) == language_go
6744 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6746 char *this_package_name
= go_symbol_package_name (sym
);
6748 if (this_package_name
== NULL
)
6750 if (package_name
== NULL
)
6751 package_name
= this_package_name
;
6754 if (strcmp (package_name
, this_package_name
) != 0)
6755 complaint (&symfile_complaints
,
6756 _("Symtab %s has objects from two different Go packages: %s and %s"),
6757 (sym
->symtab
&& sym
->symtab
->filename
6758 ? sym
->symtab
->filename
6759 : cu
->objfile
->name
),
6760 this_package_name
, package_name
);
6761 xfree (this_package_name
);
6767 if (package_name
!= NULL
)
6769 struct objfile
*objfile
= cu
->objfile
;
6770 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6771 package_name
, objfile
);
6774 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6776 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6777 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6778 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
6779 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6780 e.g., "main" finds the "main" module and not C's main(). */
6781 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6782 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6783 SYMBOL_TYPE (sym
) = type
;
6785 add_symbol_to_list (sym
, &global_symbols
);
6787 xfree (package_name
);
6791 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6793 /* Return the symtab for PER_CU. This works properly regardless of
6794 whether we're using the index or psymtabs. */
6796 static struct symtab
*
6797 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6799 return (dwarf2_per_objfile
->using_index
6800 ? per_cu
->v
.quick
->symtab
6801 : per_cu
->v
.psymtab
->symtab
);
6804 /* A helper function for computing the list of all symbol tables
6805 included by PER_CU. */
6808 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6809 htab_t all_children
,
6810 struct dwarf2_per_cu_data
*per_cu
)
6814 struct dwarf2_per_cu_data
*iter
;
6816 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6819 /* This inclusion and its children have been processed. */
6824 /* Only add a CU if it has a symbol table. */
6825 if (get_symtab (per_cu
) != NULL
)
6826 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6829 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
, ix
, iter
);
6831 recursively_compute_inclusions (result
, all_children
, iter
);
6834 /* Compute the symtab 'includes' fields for the symtab related to
6838 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6840 gdb_assert (! per_cu
->is_debug_types
);
6842 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
))
6845 struct dwarf2_per_cu_data
*iter
;
6846 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6847 htab_t all_children
;
6848 struct symtab
*symtab
= get_symtab (per_cu
);
6850 /* If we don't have a symtab, we can just skip this case. */
6854 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6855 NULL
, xcalloc
, xfree
);
6858 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
,
6861 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6863 /* Now we have a transitive closure of all the included CUs, so
6864 we can convert it to a list of symtabs. */
6865 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6867 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6868 (len
+ 1) * sizeof (struct symtab
*));
6870 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6872 symtab
->includes
[ix
] = get_symtab (iter
);
6873 symtab
->includes
[len
] = NULL
;
6875 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6876 htab_delete (all_children
);
6880 /* Compute the 'includes' field for the symtabs of all the CUs we just
6884 process_cu_includes (void)
6887 struct dwarf2_per_cu_data
*iter
;
6890 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6894 if (! iter
->is_debug_types
)
6895 compute_symtab_includes (iter
);
6898 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6901 /* Generate full symbol information for PER_CU, whose DIEs have
6902 already been loaded into memory. */
6905 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6906 enum language pretend_language
)
6908 struct dwarf2_cu
*cu
= per_cu
->cu
;
6909 struct objfile
*objfile
= per_cu
->objfile
;
6910 CORE_ADDR lowpc
, highpc
;
6911 struct symtab
*symtab
;
6912 struct cleanup
*back_to
, *delayed_list_cleanup
;
6914 struct block
*static_block
;
6916 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6919 back_to
= make_cleanup (really_free_pendings
, NULL
);
6920 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6922 cu
->list_in_scope
= &file_symbols
;
6924 cu
->language
= pretend_language
;
6925 cu
->language_defn
= language_def (cu
->language
);
6927 /* Do line number decoding in read_file_scope () */
6928 process_die (cu
->dies
, cu
);
6930 /* For now fudge the Go package. */
6931 if (cu
->language
== language_go
)
6932 fixup_go_packaging (cu
);
6934 /* Now that we have processed all the DIEs in the CU, all the types
6935 should be complete, and it should now be safe to compute all of the
6937 compute_delayed_physnames (cu
);
6938 do_cleanups (delayed_list_cleanup
);
6940 /* Some compilers don't define a DW_AT_high_pc attribute for the
6941 compilation unit. If the DW_AT_high_pc is missing, synthesize
6942 it, by scanning the DIE's below the compilation unit. */
6943 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6946 = end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0,
6947 per_cu
->s
.imported_symtabs
!= NULL
);
6949 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6950 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6951 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6952 addrmap to help ensure it has an accurate map of pc values belonging to
6954 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
6956 symtab
= end_symtab_from_static_block (static_block
, objfile
,
6957 SECT_OFF_TEXT (objfile
), 0);
6961 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6963 /* Set symtab language to language from DW_AT_language. If the
6964 compilation is from a C file generated by language preprocessors, do
6965 not set the language if it was already deduced by start_subfile. */
6966 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6967 symtab
->language
= cu
->language
;
6969 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6970 produce DW_AT_location with location lists but it can be possibly
6971 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6972 there were bugs in prologue debug info, fixed later in GCC-4.5
6973 by "unwind info for epilogues" patch (which is not directly related).
6975 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6976 needed, it would be wrong due to missing DW_AT_producer there.
6978 Still one can confuse GDB by using non-standard GCC compilation
6979 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6981 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6982 symtab
->locations_valid
= 1;
6984 if (gcc_4_minor
>= 5)
6985 symtab
->epilogue_unwind_valid
= 1;
6987 symtab
->call_site_htab
= cu
->call_site_htab
;
6990 if (dwarf2_per_objfile
->using_index
)
6991 per_cu
->v
.quick
->symtab
= symtab
;
6994 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6995 pst
->symtab
= symtab
;
6999 /* Push it for inclusion processing later. */
7000 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
7002 do_cleanups (back_to
);
7005 /* Generate full symbol information for type unit PER_CU, whose DIEs have
7006 already been loaded into memory. */
7009 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
7010 enum language pretend_language
)
7012 struct dwarf2_cu
*cu
= per_cu
->cu
;
7013 struct objfile
*objfile
= per_cu
->objfile
;
7014 struct symtab
*symtab
;
7015 struct cleanup
*back_to
, *delayed_list_cleanup
;
7018 back_to
= make_cleanup (really_free_pendings
, NULL
);
7019 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
7021 cu
->list_in_scope
= &file_symbols
;
7023 cu
->language
= pretend_language
;
7024 cu
->language_defn
= language_def (cu
->language
);
7026 /* The symbol tables are set up in read_type_unit_scope. */
7027 process_die (cu
->dies
, cu
);
7029 /* For now fudge the Go package. */
7030 if (cu
->language
== language_go
)
7031 fixup_go_packaging (cu
);
7033 /* Now that we have processed all the DIEs in the CU, all the types
7034 should be complete, and it should now be safe to compute all of the
7036 compute_delayed_physnames (cu
);
7037 do_cleanups (delayed_list_cleanup
);
7039 /* TUs share symbol tables.
7040 If this is the first TU to use this symtab, complete the construction
7041 of it with end_expandable_symtab. Otherwise, complete the addition of
7042 this TU's symbols to the existing symtab. */
7043 if (per_cu
->s
.type_unit_group
->primary_symtab
== NULL
)
7045 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
7046 per_cu
->s
.type_unit_group
->primary_symtab
= symtab
;
7050 /* Set symtab language to language from DW_AT_language. If the
7051 compilation is from a C file generated by language preprocessors,
7052 do not set the language if it was already deduced by
7054 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7055 symtab
->language
= cu
->language
;
7060 augment_type_symtab (objfile
,
7061 per_cu
->s
.type_unit_group
->primary_symtab
);
7062 symtab
= per_cu
->s
.type_unit_group
->primary_symtab
;
7065 if (dwarf2_per_objfile
->using_index
)
7066 per_cu
->v
.quick
->symtab
= symtab
;
7069 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7070 pst
->symtab
= symtab
;
7074 do_cleanups (back_to
);
7077 /* Process an imported unit DIE. */
7080 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7082 struct attribute
*attr
;
7084 /* For now we don't handle imported units in type units. */
7085 if (cu
->per_cu
->is_debug_types
)
7087 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7088 " supported in type units [in module %s]"),
7092 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7095 struct dwarf2_per_cu_data
*per_cu
;
7096 struct symtab
*imported_symtab
;
7100 offset
= dwarf2_get_ref_die_offset (attr
);
7101 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
7102 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
7104 /* Queue the unit, if needed. */
7105 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
7106 load_full_comp_unit (per_cu
, cu
->language
);
7108 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
7113 /* Process a die and its children. */
7116 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7120 case DW_TAG_padding
:
7122 case DW_TAG_compile_unit
:
7123 case DW_TAG_partial_unit
:
7124 read_file_scope (die
, cu
);
7126 case DW_TAG_type_unit
:
7127 read_type_unit_scope (die
, cu
);
7129 case DW_TAG_subprogram
:
7130 case DW_TAG_inlined_subroutine
:
7131 read_func_scope (die
, cu
);
7133 case DW_TAG_lexical_block
:
7134 case DW_TAG_try_block
:
7135 case DW_TAG_catch_block
:
7136 read_lexical_block_scope (die
, cu
);
7138 case DW_TAG_GNU_call_site
:
7139 read_call_site_scope (die
, cu
);
7141 case DW_TAG_class_type
:
7142 case DW_TAG_interface_type
:
7143 case DW_TAG_structure_type
:
7144 case DW_TAG_union_type
:
7145 process_structure_scope (die
, cu
);
7147 case DW_TAG_enumeration_type
:
7148 process_enumeration_scope (die
, cu
);
7151 /* These dies have a type, but processing them does not create
7152 a symbol or recurse to process the children. Therefore we can
7153 read them on-demand through read_type_die. */
7154 case DW_TAG_subroutine_type
:
7155 case DW_TAG_set_type
:
7156 case DW_TAG_array_type
:
7157 case DW_TAG_pointer_type
:
7158 case DW_TAG_ptr_to_member_type
:
7159 case DW_TAG_reference_type
:
7160 case DW_TAG_string_type
:
7163 case DW_TAG_base_type
:
7164 case DW_TAG_subrange_type
:
7165 case DW_TAG_typedef
:
7166 /* Add a typedef symbol for the type definition, if it has a
7168 new_symbol (die
, read_type_die (die
, cu
), cu
);
7170 case DW_TAG_common_block
:
7171 read_common_block (die
, cu
);
7173 case DW_TAG_common_inclusion
:
7175 case DW_TAG_namespace
:
7176 processing_has_namespace_info
= 1;
7177 read_namespace (die
, cu
);
7180 processing_has_namespace_info
= 1;
7181 read_module (die
, cu
);
7183 case DW_TAG_imported_declaration
:
7184 case DW_TAG_imported_module
:
7185 processing_has_namespace_info
= 1;
7186 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
7187 || cu
->language
!= language_fortran
))
7188 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
7189 dwarf_tag_name (die
->tag
));
7190 read_import_statement (die
, cu
);
7193 case DW_TAG_imported_unit
:
7194 process_imported_unit_die (die
, cu
);
7198 new_symbol (die
, NULL
, cu
);
7203 /* A helper function for dwarf2_compute_name which determines whether DIE
7204 needs to have the name of the scope prepended to the name listed in the
7208 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7210 struct attribute
*attr
;
7214 case DW_TAG_namespace
:
7215 case DW_TAG_typedef
:
7216 case DW_TAG_class_type
:
7217 case DW_TAG_interface_type
:
7218 case DW_TAG_structure_type
:
7219 case DW_TAG_union_type
:
7220 case DW_TAG_enumeration_type
:
7221 case DW_TAG_enumerator
:
7222 case DW_TAG_subprogram
:
7226 case DW_TAG_variable
:
7227 case DW_TAG_constant
:
7228 /* We only need to prefix "globally" visible variables. These include
7229 any variable marked with DW_AT_external or any variable that
7230 lives in a namespace. [Variables in anonymous namespaces
7231 require prefixing, but they are not DW_AT_external.] */
7233 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
7235 struct dwarf2_cu
*spec_cu
= cu
;
7237 return die_needs_namespace (die_specification (die
, &spec_cu
),
7241 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7242 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
7243 && die
->parent
->tag
!= DW_TAG_module
)
7245 /* A variable in a lexical block of some kind does not need a
7246 namespace, even though in C++ such variables may be external
7247 and have a mangled name. */
7248 if (die
->parent
->tag
== DW_TAG_lexical_block
7249 || die
->parent
->tag
== DW_TAG_try_block
7250 || die
->parent
->tag
== DW_TAG_catch_block
7251 || die
->parent
->tag
== DW_TAG_subprogram
)
7260 /* Retrieve the last character from a mem_file. */
7263 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
7265 char *last_char_p
= (char *) object
;
7268 *last_char_p
= buffer
[length
- 1];
7271 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7272 compute the physname for the object, which include a method's:
7273 - formal parameters (C++/Java),
7274 - receiver type (Go),
7275 - return type (Java).
7277 The term "physname" is a bit confusing.
7278 For C++, for example, it is the demangled name.
7279 For Go, for example, it's the mangled name.
7281 For Ada, return the DIE's linkage name rather than the fully qualified
7282 name. PHYSNAME is ignored..
7284 The result is allocated on the objfile_obstack and canonicalized. */
7287 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
7290 struct objfile
*objfile
= cu
->objfile
;
7293 name
= dwarf2_name (die
, cu
);
7295 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7296 compute it by typename_concat inside GDB. */
7297 if (cu
->language
== language_ada
7298 || (cu
->language
== language_fortran
&& physname
))
7300 /* For Ada unit, we prefer the linkage name over the name, as
7301 the former contains the exported name, which the user expects
7302 to be able to reference. Ideally, we want the user to be able
7303 to reference this entity using either natural or linkage name,
7304 but we haven't started looking at this enhancement yet. */
7305 struct attribute
*attr
;
7307 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7309 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7310 if (attr
&& DW_STRING (attr
))
7311 return DW_STRING (attr
);
7314 /* These are the only languages we know how to qualify names in. */
7316 && (cu
->language
== language_cplus
|| cu
->language
== language_java
7317 || cu
->language
== language_fortran
))
7319 if (die_needs_namespace (die
, cu
))
7323 struct ui_file
*buf
;
7325 prefix
= determine_prefix (die
, cu
);
7326 buf
= mem_fileopen ();
7327 if (*prefix
!= '\0')
7329 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7332 fputs_unfiltered (prefixed_name
, buf
);
7333 xfree (prefixed_name
);
7336 fputs_unfiltered (name
, buf
);
7338 /* Template parameters may be specified in the DIE's DW_AT_name, or
7339 as children with DW_TAG_template_type_param or
7340 DW_TAG_value_type_param. If the latter, add them to the name
7341 here. If the name already has template parameters, then
7342 skip this step; some versions of GCC emit both, and
7343 it is more efficient to use the pre-computed name.
7345 Something to keep in mind about this process: it is very
7346 unlikely, or in some cases downright impossible, to produce
7347 something that will match the mangled name of a function.
7348 If the definition of the function has the same debug info,
7349 we should be able to match up with it anyway. But fallbacks
7350 using the minimal symbol, for instance to find a method
7351 implemented in a stripped copy of libstdc++, will not work.
7352 If we do not have debug info for the definition, we will have to
7353 match them up some other way.
7355 When we do name matching there is a related problem with function
7356 templates; two instantiated function templates are allowed to
7357 differ only by their return types, which we do not add here. */
7359 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7361 struct attribute
*attr
;
7362 struct die_info
*child
;
7365 die
->building_fullname
= 1;
7367 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7372 struct dwarf2_locexpr_baton
*baton
;
7375 if (child
->tag
!= DW_TAG_template_type_param
7376 && child
->tag
!= DW_TAG_template_value_param
)
7381 fputs_unfiltered ("<", buf
);
7385 fputs_unfiltered (", ", buf
);
7387 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7390 complaint (&symfile_complaints
,
7391 _("template parameter missing DW_AT_type"));
7392 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7395 type
= die_type (child
, cu
);
7397 if (child
->tag
== DW_TAG_template_type_param
)
7399 c_print_type (type
, "", buf
, -1, 0, &type_print_raw_options
);
7403 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7406 complaint (&symfile_complaints
,
7407 _("template parameter missing "
7408 "DW_AT_const_value"));
7409 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7413 dwarf2_const_value_attr (attr
, type
, name
,
7414 &cu
->comp_unit_obstack
, cu
,
7415 &value
, &bytes
, &baton
);
7417 if (TYPE_NOSIGN (type
))
7418 /* GDB prints characters as NUMBER 'CHAR'. If that's
7419 changed, this can use value_print instead. */
7420 c_printchar (value
, type
, buf
);
7423 struct value_print_options opts
;
7426 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7430 else if (bytes
!= NULL
)
7432 v
= allocate_value (type
);
7433 memcpy (value_contents_writeable (v
), bytes
,
7434 TYPE_LENGTH (type
));
7437 v
= value_from_longest (type
, value
);
7439 /* Specify decimal so that we do not depend on
7441 get_formatted_print_options (&opts
, 'd');
7443 value_print (v
, buf
, &opts
);
7449 die
->building_fullname
= 0;
7453 /* Close the argument list, with a space if necessary
7454 (nested templates). */
7455 char last_char
= '\0';
7456 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7457 if (last_char
== '>')
7458 fputs_unfiltered (" >", buf
);
7460 fputs_unfiltered (">", buf
);
7464 /* For Java and C++ methods, append formal parameter type
7465 information, if PHYSNAME. */
7467 if (physname
&& die
->tag
== DW_TAG_subprogram
7468 && (cu
->language
== language_cplus
7469 || cu
->language
== language_java
))
7471 struct type
*type
= read_type_die (die
, cu
);
7473 c_type_print_args (type
, buf
, 1, cu
->language
,
7474 &type_print_raw_options
);
7476 if (cu
->language
== language_java
)
7478 /* For java, we must append the return type to method
7480 if (die
->tag
== DW_TAG_subprogram
)
7481 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7482 0, 0, &type_print_raw_options
);
7484 else if (cu
->language
== language_cplus
)
7486 /* Assume that an artificial first parameter is
7487 "this", but do not crash if it is not. RealView
7488 marks unnamed (and thus unused) parameters as
7489 artificial; there is no way to differentiate
7491 if (TYPE_NFIELDS (type
) > 0
7492 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7493 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7494 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7496 fputs_unfiltered (" const", buf
);
7500 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7502 ui_file_delete (buf
);
7504 if (cu
->language
== language_cplus
)
7507 = dwarf2_canonicalize_name (name
, cu
,
7508 &objfile
->objfile_obstack
);
7519 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7520 If scope qualifiers are appropriate they will be added. The result
7521 will be allocated on the objfile_obstack, or NULL if the DIE does
7522 not have a name. NAME may either be from a previous call to
7523 dwarf2_name or NULL.
7525 The output string will be canonicalized (if C++/Java). */
7528 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7530 return dwarf2_compute_name (name
, die
, cu
, 0);
7533 /* Construct a physname for the given DIE in CU. NAME may either be
7534 from a previous call to dwarf2_name or NULL. The result will be
7535 allocated on the objfile_objstack or NULL if the DIE does not have a
7538 The output string will be canonicalized (if C++/Java). */
7541 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7543 struct objfile
*objfile
= cu
->objfile
;
7544 struct attribute
*attr
;
7545 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7546 struct cleanup
*back_to
;
7549 /* In this case dwarf2_compute_name is just a shortcut not building anything
7551 if (!die_needs_namespace (die
, cu
))
7552 return dwarf2_compute_name (name
, die
, cu
, 1);
7554 back_to
= make_cleanup (null_cleanup
, NULL
);
7556 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7558 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7560 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7562 if (attr
&& DW_STRING (attr
))
7566 mangled
= DW_STRING (attr
);
7568 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7569 type. It is easier for GDB users to search for such functions as
7570 `name(params)' than `long name(params)'. In such case the minimal
7571 symbol names do not match the full symbol names but for template
7572 functions there is never a need to look up their definition from their
7573 declaration so the only disadvantage remains the minimal symbol
7574 variant `long name(params)' does not have the proper inferior type.
7577 if (cu
->language
== language_go
)
7579 /* This is a lie, but we already lie to the caller new_symbol_full.
7580 new_symbol_full assumes we return the mangled name.
7581 This just undoes that lie until things are cleaned up. */
7586 demangled
= cplus_demangle (mangled
,
7587 (DMGL_PARAMS
| DMGL_ANSI
7588 | (cu
->language
== language_java
7589 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7594 make_cleanup (xfree
, demangled
);
7604 if (canon
== NULL
|| check_physname
)
7606 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7608 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7610 /* It may not mean a bug in GDB. The compiler could also
7611 compute DW_AT_linkage_name incorrectly. But in such case
7612 GDB would need to be bug-to-bug compatible. */
7614 complaint (&symfile_complaints
,
7615 _("Computed physname <%s> does not match demangled <%s> "
7616 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7617 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7619 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7620 is available here - over computed PHYSNAME. It is safer
7621 against both buggy GDB and buggy compilers. */
7635 retval
= obsavestring (retval
, strlen (retval
),
7636 &objfile
->objfile_obstack
);
7638 do_cleanups (back_to
);
7642 /* Read the import statement specified by the given die and record it. */
7645 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7647 struct objfile
*objfile
= cu
->objfile
;
7648 struct attribute
*import_attr
;
7649 struct die_info
*imported_die
, *child_die
;
7650 struct dwarf2_cu
*imported_cu
;
7651 const char *imported_name
;
7652 const char *imported_name_prefix
;
7653 const char *canonical_name
;
7654 const char *import_alias
;
7655 const char *imported_declaration
= NULL
;
7656 const char *import_prefix
;
7657 VEC (const_char_ptr
) *excludes
= NULL
;
7658 struct cleanup
*cleanups
;
7662 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7663 if (import_attr
== NULL
)
7665 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7666 dwarf_tag_name (die
->tag
));
7671 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7672 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7673 if (imported_name
== NULL
)
7675 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7677 The import in the following code:
7691 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7692 <52> DW_AT_decl_file : 1
7693 <53> DW_AT_decl_line : 6
7694 <54> DW_AT_import : <0x75>
7695 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7697 <5b> DW_AT_decl_file : 1
7698 <5c> DW_AT_decl_line : 2
7699 <5d> DW_AT_type : <0x6e>
7701 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7702 <76> DW_AT_byte_size : 4
7703 <77> DW_AT_encoding : 5 (signed)
7705 imports the wrong die ( 0x75 instead of 0x58 ).
7706 This case will be ignored until the gcc bug is fixed. */
7710 /* Figure out the local name after import. */
7711 import_alias
= dwarf2_name (die
, cu
);
7713 /* Figure out where the statement is being imported to. */
7714 import_prefix
= determine_prefix (die
, cu
);
7716 /* Figure out what the scope of the imported die is and prepend it
7717 to the name of the imported die. */
7718 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7720 if (imported_die
->tag
!= DW_TAG_namespace
7721 && imported_die
->tag
!= DW_TAG_module
)
7723 imported_declaration
= imported_name
;
7724 canonical_name
= imported_name_prefix
;
7726 else if (strlen (imported_name_prefix
) > 0)
7728 temp
= alloca (strlen (imported_name_prefix
)
7729 + 2 + strlen (imported_name
) + 1);
7730 strcpy (temp
, imported_name_prefix
);
7731 strcat (temp
, "::");
7732 strcat (temp
, imported_name
);
7733 canonical_name
= temp
;
7736 canonical_name
= imported_name
;
7738 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7740 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7741 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7742 child_die
= sibling_die (child_die
))
7744 /* DWARF-4: A Fortran use statement with a “rename list” may be
7745 represented by an imported module entry with an import attribute
7746 referring to the module and owned entries corresponding to those
7747 entities that are renamed as part of being imported. */
7749 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7751 complaint (&symfile_complaints
,
7752 _("child DW_TAG_imported_declaration expected "
7753 "- DIE at 0x%x [in module %s]"),
7754 child_die
->offset
.sect_off
, objfile
->name
);
7758 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7759 if (import_attr
== NULL
)
7761 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7762 dwarf_tag_name (child_die
->tag
));
7767 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7769 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7770 if (imported_name
== NULL
)
7772 complaint (&symfile_complaints
,
7773 _("child DW_TAG_imported_declaration has unknown "
7774 "imported name - DIE at 0x%x [in module %s]"),
7775 child_die
->offset
.sect_off
, objfile
->name
);
7779 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7781 process_die (child_die
, cu
);
7784 cp_add_using_directive (import_prefix
,
7787 imported_declaration
,
7789 &objfile
->objfile_obstack
);
7791 do_cleanups (cleanups
);
7794 /* Cleanup function for handle_DW_AT_stmt_list. */
7797 free_cu_line_header (void *arg
)
7799 struct dwarf2_cu
*cu
= arg
;
7801 free_line_header (cu
->line_header
);
7802 cu
->line_header
= NULL
;
7806 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7807 char **name
, char **comp_dir
)
7809 struct attribute
*attr
;
7814 /* Find the filename. Do not use dwarf2_name here, since the filename
7815 is not a source language identifier. */
7816 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7819 *name
= DW_STRING (attr
);
7822 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7824 *comp_dir
= DW_STRING (attr
);
7825 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
7827 *comp_dir
= ldirname (*name
);
7828 if (*comp_dir
!= NULL
)
7829 make_cleanup (xfree
, *comp_dir
);
7831 if (*comp_dir
!= NULL
)
7833 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7834 directory, get rid of it. */
7835 char *cp
= strchr (*comp_dir
, ':');
7837 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7842 *name
= "<unknown>";
7845 /* Handle DW_AT_stmt_list for a compilation unit.
7846 DIE is the DW_TAG_compile_unit die for CU.
7847 COMP_DIR is the compilation directory.
7848 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7851 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7852 const char *comp_dir
)
7854 struct attribute
*attr
;
7856 gdb_assert (! cu
->per_cu
->is_debug_types
);
7858 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7861 unsigned int line_offset
= DW_UNSND (attr
);
7862 struct line_header
*line_header
7863 = dwarf_decode_line_header (line_offset
, cu
);
7867 cu
->line_header
= line_header
;
7868 make_cleanup (free_cu_line_header
, cu
);
7869 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7874 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7877 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7879 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7880 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7881 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7882 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7883 struct attribute
*attr
;
7885 char *comp_dir
= NULL
;
7886 struct die_info
*child_die
;
7887 bfd
*abfd
= objfile
->obfd
;
7890 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7892 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7894 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7895 from finish_block. */
7896 if (lowpc
== ((CORE_ADDR
) -1))
7901 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7903 prepare_one_comp_unit (cu
, die
, cu
->language
);
7905 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7906 standardised yet. As a workaround for the language detection we fall
7907 back to the DW_AT_producer string. */
7908 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7909 cu
->language
= language_opencl
;
7911 /* Similar hack for Go. */
7912 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
7913 set_cu_language (DW_LANG_Go
, cu
);
7915 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
7917 /* Decode line number information if present. We do this before
7918 processing child DIEs, so that the line header table is available
7919 for DW_AT_decl_file. */
7920 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
7922 /* Process all dies in compilation unit. */
7923 if (die
->child
!= NULL
)
7925 child_die
= die
->child
;
7926 while (child_die
&& child_die
->tag
)
7928 process_die (child_die
, cu
);
7929 child_die
= sibling_die (child_die
);
7933 /* Decode macro information, if present. Dwarf 2 macro information
7934 refers to information in the line number info statement program
7935 header, so we can only read it if we've read the header
7937 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
7938 if (attr
&& cu
->line_header
)
7940 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
7941 complaint (&symfile_complaints
,
7942 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
7944 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
7948 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
7949 if (attr
&& cu
->line_header
)
7951 unsigned int macro_offset
= DW_UNSND (attr
);
7953 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
7957 do_cleanups (back_to
);
7960 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
7961 Create the set of symtabs used by this TU, or if this TU is sharing
7962 symtabs with another TU and the symtabs have already been created
7963 then restore those symtabs in the line header.
7964 We don't need the pc/line-number mapping for type units. */
7967 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
7969 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7970 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7971 struct type_unit_group
*tu_group
;
7973 struct line_header
*lh
;
7974 struct attribute
*attr
;
7975 unsigned int i
, line_offset
;
7977 gdb_assert (per_cu
->is_debug_types
);
7979 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7981 /* If we're using .gdb_index (includes -readnow) then
7982 per_cu->s.type_unit_group may not have been set up yet. */
7983 if (per_cu
->s
.type_unit_group
== NULL
)
7984 per_cu
->s
.type_unit_group
= get_type_unit_group (cu
, attr
);
7985 tu_group
= per_cu
->s
.type_unit_group
;
7987 /* If we've already processed this stmt_list there's no real need to
7988 do it again, we could fake it and just recreate the part we need
7989 (file name,index -> symtab mapping). If data shows this optimization
7990 is useful we can do it then. */
7991 first_time
= tu_group
->primary_symtab
== NULL
;
7993 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7998 line_offset
= DW_UNSND (attr
);
7999 lh
= dwarf_decode_line_header (line_offset
, cu
);
8004 dwarf2_start_symtab (cu
, "", NULL
, 0);
8007 gdb_assert (tu_group
->symtabs
== NULL
);
8010 /* Note: The primary symtab will get allocated at the end. */
8014 cu
->line_header
= lh
;
8015 make_cleanup (free_cu_line_header
, cu
);
8019 dwarf2_start_symtab (cu
, "", NULL
, 0);
8021 tu_group
->num_symtabs
= lh
->num_file_names
;
8022 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
8024 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8027 struct file_entry
*fe
= &lh
->file_names
[i
];
8030 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8031 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
8033 /* Note: We don't have to watch for the main subfile here, type units
8034 don't have DW_AT_name. */
8036 if (current_subfile
->symtab
== NULL
)
8038 /* NOTE: start_subfile will recognize when it's been passed
8039 a file it has already seen. So we can't assume there's a
8040 simple mapping from lh->file_names to subfiles,
8041 lh->file_names may contain dups. */
8042 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8046 fe
->symtab
= current_subfile
->symtab
;
8047 tu_group
->symtabs
[i
] = fe
->symtab
;
8054 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8056 struct file_entry
*fe
= &lh
->file_names
[i
];
8058 fe
->symtab
= tu_group
->symtabs
[i
];
8062 /* The main symtab is allocated last. Type units don't have DW_AT_name
8063 so they don't have a "real" (so to speak) symtab anyway.
8064 There is later code that will assign the main symtab to all symbols
8065 that don't have one. We need to handle the case of a symbol with a
8066 missing symtab (DW_AT_decl_file) anyway. */
8069 /* Process DW_TAG_type_unit.
8070 For TUs we want to skip the first top level sibling if it's not the
8071 actual type being defined by this TU. In this case the first top
8072 level sibling is there to provide context only. */
8075 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8077 struct die_info
*child_die
;
8079 prepare_one_comp_unit (cu
, die
, language_minimal
);
8081 /* Initialize (or reinitialize) the machinery for building symtabs.
8082 We do this before processing child DIEs, so that the line header table
8083 is available for DW_AT_decl_file. */
8084 setup_type_unit_groups (die
, cu
);
8086 if (die
->child
!= NULL
)
8088 child_die
= die
->child
;
8089 while (child_die
&& child_die
->tag
)
8091 process_die (child_die
, cu
);
8092 child_die
= sibling_die (child_die
);
8099 http://gcc.gnu.org/wiki/DebugFission
8100 http://gcc.gnu.org/wiki/DebugFissionDWP
8102 To simplify handling of both DWO files ("object" files with the DWARF info)
8103 and DWP files (a file with the DWOs packaged up into one file), we treat
8104 DWP files as having a collection of virtual DWO files. */
8107 hash_dwo_file (const void *item
)
8109 const struct dwo_file
*dwo_file
= item
;
8111 return htab_hash_string (dwo_file
->name
);
8115 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
8117 const struct dwo_file
*lhs
= item_lhs
;
8118 const struct dwo_file
*rhs
= item_rhs
;
8120 return strcmp (lhs
->name
, rhs
->name
) == 0;
8123 /* Allocate a hash table for DWO files. */
8126 allocate_dwo_file_hash_table (void)
8128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8130 return htab_create_alloc_ex (41,
8134 &objfile
->objfile_obstack
,
8135 hashtab_obstack_allocate
,
8136 dummy_obstack_deallocate
);
8139 /* Lookup DWO file DWO_NAME. */
8142 lookup_dwo_file_slot (const char *dwo_name
)
8144 struct dwo_file find_entry
;
8147 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8148 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8150 memset (&find_entry
, 0, sizeof (find_entry
));
8151 find_entry
.name
= dwo_name
;
8152 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8158 hash_dwo_unit (const void *item
)
8160 const struct dwo_unit
*dwo_unit
= item
;
8162 /* This drops the top 32 bits of the id, but is ok for a hash. */
8163 return dwo_unit
->signature
;
8167 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
8169 const struct dwo_unit
*lhs
= item_lhs
;
8170 const struct dwo_unit
*rhs
= item_rhs
;
8172 /* The signature is assumed to be unique within the DWO file.
8173 So while object file CU dwo_id's always have the value zero,
8174 that's OK, assuming each object file DWO file has only one CU,
8175 and that's the rule for now. */
8176 return lhs
->signature
== rhs
->signature
;
8179 /* Allocate a hash table for DWO CUs,TUs.
8180 There is one of these tables for each of CUs,TUs for each DWO file. */
8183 allocate_dwo_unit_table (struct objfile
*objfile
)
8185 /* Start out with a pretty small number.
8186 Generally DWO files contain only one CU and maybe some TUs. */
8187 return htab_create_alloc_ex (3,
8191 &objfile
->objfile_obstack
,
8192 hashtab_obstack_allocate
,
8193 dummy_obstack_deallocate
);
8196 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
8198 struct create_dwo_info_table_data
8200 struct dwo_file
*dwo_file
;
8204 /* die_reader_func for create_dwo_debug_info_hash_table. */
8207 create_dwo_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
8209 struct die_info
*comp_unit_die
,
8213 struct dwarf2_cu
*cu
= reader
->cu
;
8214 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8215 sect_offset offset
= cu
->per_cu
->offset
;
8216 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
8217 struct create_dwo_info_table_data
*data
= datap
;
8218 struct dwo_file
*dwo_file
= data
->dwo_file
;
8219 htab_t cu_htab
= data
->cu_htab
;
8221 struct attribute
*attr
;
8222 struct dwo_unit
*dwo_unit
;
8224 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
8227 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8228 " its dwo_id [in module %s]"),
8229 offset
.sect_off
, dwo_file
->name
);
8233 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8234 dwo_unit
->dwo_file
= dwo_file
;
8235 dwo_unit
->signature
= DW_UNSND (attr
);
8236 dwo_unit
->info_or_types_section
= section
;
8237 dwo_unit
->offset
= offset
;
8238 dwo_unit
->length
= cu
->per_cu
->length
;
8240 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
8241 gdb_assert (slot
!= NULL
);
8244 const struct dwo_unit
*dup_dwo_unit
= *slot
;
8246 complaint (&symfile_complaints
,
8247 _("debug entry at offset 0x%x is duplicate to the entry at"
8248 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8249 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
8250 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
8256 if (dwarf2_read_debug
)
8257 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
8259 phex (dwo_unit
->signature
,
8260 sizeof (dwo_unit
->signature
)));
8263 /* Create a hash table to map DWO IDs to their CU entry in
8264 .debug_info.dwo in DWO_FILE.
8265 Note: This function processes DWO files only, not DWP files. */
8268 create_dwo_debug_info_hash_table (struct dwo_file
*dwo_file
)
8270 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8271 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
8274 gdb_byte
*info_ptr
, *end_ptr
;
8275 struct create_dwo_info_table_data create_dwo_info_table_data
;
8277 dwarf2_read_section (objfile
, section
);
8278 info_ptr
= section
->buffer
;
8280 if (info_ptr
== NULL
)
8283 /* We can't set abfd until now because the section may be empty or
8284 not present, in which case section->asection will be NULL. */
8285 abfd
= section
->asection
->owner
;
8287 if (dwarf2_read_debug
)
8288 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
8289 bfd_get_filename (abfd
));
8291 cu_htab
= allocate_dwo_unit_table (objfile
);
8293 create_dwo_info_table_data
.dwo_file
= dwo_file
;
8294 create_dwo_info_table_data
.cu_htab
= cu_htab
;
8296 end_ptr
= info_ptr
+ section
->size
;
8297 while (info_ptr
< end_ptr
)
8299 struct dwarf2_per_cu_data per_cu
;
8301 memset (&per_cu
, 0, sizeof (per_cu
));
8302 per_cu
.objfile
= objfile
;
8303 per_cu
.is_debug_types
= 0;
8304 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8305 per_cu
.info_or_types_section
= section
;
8307 init_cutu_and_read_dies_no_follow (&per_cu
,
8308 &dwo_file
->sections
.abbrev
,
8310 create_dwo_debug_info_hash_table_reader
,
8311 &create_dwo_info_table_data
);
8313 info_ptr
+= per_cu
.length
;
8319 /* DWP file .debug_{cu,tu}_index section format:
8320 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8322 Both index sections have the same format, and serve to map a 64-bit
8323 signature to a set of section numbers. Each section begins with a header,
8324 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8325 indexes, and a pool of 32-bit section numbers. The index sections will be
8326 aligned at 8-byte boundaries in the file.
8328 The index section header contains two unsigned 32-bit values (using the
8329 byte order of the application binary):
8331 N, the number of compilation units or type units in the index
8332 M, the number of slots in the hash table
8334 (We assume that N and M will not exceed 2^32 - 1.)
8336 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8338 The hash table begins at offset 8 in the section, and consists of an array
8339 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8340 order of the application binary). Unused slots in the hash table are 0.
8341 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8343 The parallel table begins immediately after the hash table
8344 (at offset 8 + 8 * M from the beginning of the section), and consists of an
8345 array of 32-bit indexes (using the byte order of the application binary),
8346 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8347 table contains a 32-bit index into the pool of section numbers. For unused
8348 hash table slots, the corresponding entry in the parallel table will be 0.
8350 Given a 64-bit compilation unit signature or a type signature S, an entry
8351 in the hash table is located as follows:
8353 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8354 the low-order k bits all set to 1.
8356 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8358 3) If the hash table entry at index H matches the signature, use that
8359 entry. If the hash table entry at index H is unused (all zeroes),
8360 terminate the search: the signature is not present in the table.
8362 4) Let H = (H + H') modulo M. Repeat at Step 3.
8364 Because M > N and H' and M are relatively prime, the search is guaranteed
8365 to stop at an unused slot or find the match.
8367 The pool of section numbers begins immediately following the hash table
8368 (at offset 8 + 12 * M from the beginning of the section). The pool of
8369 section numbers consists of an array of 32-bit words (using the byte order
8370 of the application binary). Each item in the array is indexed starting
8371 from 0. The hash table entry provides the index of the first section
8372 number in the set. Additional section numbers in the set follow, and the
8373 set is terminated by a 0 entry (section number 0 is not used in ELF).
8375 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8376 section must be the first entry in the set, and the .debug_abbrev.dwo must
8377 be the second entry. Other members of the set may follow in any order. */
8379 /* Create a hash table to map DWO IDs to their CU/TU entry in
8380 .debug_{info,types}.dwo in DWP_FILE.
8381 Returns NULL if there isn't one.
8382 Note: This function processes DWP files only, not DWO files. */
8384 static struct dwp_hash_table
*
8385 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
8387 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8388 bfd
*dbfd
= dwp_file
->dbfd
;
8389 char *index_ptr
, *index_end
;
8390 struct dwarf2_section_info
*index
;
8391 uint32_t version
, nr_units
, nr_slots
;
8392 struct dwp_hash_table
*htab
;
8395 index
= &dwp_file
->sections
.tu_index
;
8397 index
= &dwp_file
->sections
.cu_index
;
8399 if (dwarf2_section_empty_p (index
))
8401 dwarf2_read_section (objfile
, index
);
8403 index_ptr
= index
->buffer
;
8404 index_end
= index_ptr
+ index
->size
;
8406 version
= read_4_bytes (dbfd
, index_ptr
);
8407 index_ptr
+= 8; /* Skip the unused word. */
8408 nr_units
= read_4_bytes (dbfd
, index_ptr
);
8410 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
8415 error (_("Dwarf Error: unsupported DWP file version (%u)"
8417 version
, dwp_file
->name
);
8419 if (nr_slots
!= (nr_slots
& -nr_slots
))
8421 error (_("Dwarf Error: number of slots in DWP hash table (%u)"
8422 " is not power of 2 [in module %s]"),
8423 nr_slots
, dwp_file
->name
);
8426 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
8427 htab
->nr_units
= nr_units
;
8428 htab
->nr_slots
= nr_slots
;
8429 htab
->hash_table
= index_ptr
;
8430 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
8431 htab
->section_pool
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8436 /* Update SECTIONS with the data from SECTP.
8438 This function is like the other "locate" section routines that are
8439 passed to bfd_map_over_sections, but in this context the sections to
8440 read comes from the DWP hash table, not the full ELF section table.
8442 The result is non-zero for success, or zero if an error was found. */
8445 locate_virtual_dwo_sections (asection
*sectp
,
8446 struct virtual_dwo_sections
*sections
)
8448 const struct dwop_section_names
*names
= &dwop_section_names
;
8450 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8452 /* There can be only one. */
8453 if (sections
->abbrev
.asection
!= NULL
)
8455 sections
->abbrev
.asection
= sectp
;
8456 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8458 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
8459 || section_is_p (sectp
->name
, &names
->types_dwo
))
8461 /* There can be only one. */
8462 if (sections
->info_or_types
.asection
!= NULL
)
8464 sections
->info_or_types
.asection
= sectp
;
8465 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
8467 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8469 /* There can be only one. */
8470 if (sections
->line
.asection
!= NULL
)
8472 sections
->line
.asection
= sectp
;
8473 sections
->line
.size
= bfd_get_section_size (sectp
);
8475 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8477 /* There can be only one. */
8478 if (sections
->loc
.asection
!= NULL
)
8480 sections
->loc
.asection
= sectp
;
8481 sections
->loc
.size
= bfd_get_section_size (sectp
);
8483 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8485 /* There can be only one. */
8486 if (sections
->macinfo
.asection
!= NULL
)
8488 sections
->macinfo
.asection
= sectp
;
8489 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8491 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8493 /* There can be only one. */
8494 if (sections
->macro
.asection
!= NULL
)
8496 sections
->macro
.asection
= sectp
;
8497 sections
->macro
.size
= bfd_get_section_size (sectp
);
8499 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8501 /* There can be only one. */
8502 if (sections
->str_offsets
.asection
!= NULL
)
8504 sections
->str_offsets
.asection
= sectp
;
8505 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8509 /* No other kind of section is valid. */
8516 /* Create a dwo_unit object for the DWO with signature SIGNATURE.
8517 HTAB is the hash table from the DWP file.
8518 SECTION_INDEX is the index of the DWO in HTAB. */
8520 static struct dwo_unit
*
8521 create_dwo_in_dwp (struct dwp_file
*dwp_file
,
8522 const struct dwp_hash_table
*htab
,
8523 uint32_t section_index
,
8524 ULONGEST signature
, int is_debug_types
)
8526 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8527 bfd
*dbfd
= dwp_file
->dbfd
;
8528 const char *kind
= is_debug_types
? "TU" : "CU";
8529 struct dwo_file
*dwo_file
;
8530 struct dwo_unit
*dwo_unit
;
8531 struct virtual_dwo_sections sections
;
8532 void **dwo_file_slot
;
8533 char *virtual_dwo_name
;
8534 struct dwarf2_section_info
*cutu
;
8535 struct cleanup
*cleanups
;
8538 if (dwarf2_read_debug
)
8540 fprintf_unfiltered (gdb_stdlog
, "Reading %s %u/0x%s in DWP file: %s\n",
8542 section_index
, phex (signature
, sizeof (signature
)),
8546 /* Fetch the sections of this DWO.
8547 Put a limit on the number of sections we look for so that bad data
8548 doesn't cause us to loop forever. */
8550 #define MAX_NR_DWO_SECTIONS \
8551 (1 /* .debug_info or .debug_types */ \
8552 + 1 /* .debug_abbrev */ \
8553 + 1 /* .debug_line */ \
8554 + 1 /* .debug_loc */ \
8555 + 1 /* .debug_str_offsets */ \
8556 + 1 /* .debug_macro */ \
8557 + 1 /* .debug_macinfo */ \
8558 + 1 /* trailing zero */)
8560 memset (§ions
, 0, sizeof (sections
));
8561 cleanups
= make_cleanup (null_cleanup
, 0);
8563 for (i
= 0; i
< MAX_NR_DWO_SECTIONS
; ++i
)
8566 uint32_t section_nr
=
8569 + (section_index
+ i
) * sizeof (uint32_t));
8571 if (section_nr
== 0)
8573 if (section_nr
>= dwp_file
->num_sections
)
8575 error (_("Dwarf Error: bad DWP hash table, section number too large"
8580 sectp
= dwp_file
->elf_sections
[section_nr
];
8581 if (! locate_virtual_dwo_sections (sectp
, §ions
))
8583 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8590 || sections
.info_or_types
.asection
== NULL
8591 || sections
.abbrev
.asection
== NULL
)
8593 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8597 if (i
== MAX_NR_DWO_SECTIONS
)
8599 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8604 /* It's easier for the rest of the code if we fake a struct dwo_file and
8605 have dwo_unit "live" in that. At least for now.
8607 The DWP file can be made up of a random collection of CUs and TUs.
8608 However, for each CU + set of TUs that came from the same original
8609 DWO file, we want combine them back into a virtual DWO file to save space
8610 (fewer struct dwo_file objects to allocated). Remember that for really
8611 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8613 xasprintf (&virtual_dwo_name
, "virtual-dwo/%d-%d-%d-%d",
8614 sections
.abbrev
.asection
? sections
.abbrev
.asection
->id
: 0,
8615 sections
.line
.asection
? sections
.line
.asection
->id
: 0,
8616 sections
.loc
.asection
? sections
.loc
.asection
->id
: 0,
8617 (sections
.str_offsets
.asection
8618 ? sections
.str_offsets
.asection
->id
8620 make_cleanup (xfree
, virtual_dwo_name
);
8621 /* Can we use an existing virtual DWO file? */
8622 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
);
8623 /* Create one if necessary. */
8624 if (*dwo_file_slot
== NULL
)
8626 if (dwarf2_read_debug
)
8628 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
8631 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8632 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8634 strlen (virtual_dwo_name
));
8635 dwo_file
->sections
.abbrev
= sections
.abbrev
;
8636 dwo_file
->sections
.line
= sections
.line
;
8637 dwo_file
->sections
.loc
= sections
.loc
;
8638 dwo_file
->sections
.macinfo
= sections
.macinfo
;
8639 dwo_file
->sections
.macro
= sections
.macro
;
8640 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
8641 /* The "str" section is global to the entire DWP file. */
8642 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
8643 /* The info or types section is assigned later to dwo_unit,
8644 there's no need to record it in dwo_file.
8645 Also, we can't simply record type sections in dwo_file because
8646 we record a pointer into the vector in dwo_unit. As we collect more
8647 types we'll grow the vector and eventually have to reallocate space
8648 for it, invalidating all the pointers into the current copy. */
8649 *dwo_file_slot
= dwo_file
;
8653 if (dwarf2_read_debug
)
8655 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
8658 dwo_file
= *dwo_file_slot
;
8660 do_cleanups (cleanups
);
8662 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8663 dwo_unit
->dwo_file
= dwo_file
;
8664 dwo_unit
->signature
= signature
;
8665 dwo_unit
->info_or_types_section
=
8666 obstack_alloc (&objfile
->objfile_obstack
,
8667 sizeof (struct dwarf2_section_info
));
8668 *dwo_unit
->info_or_types_section
= sections
.info_or_types
;
8669 /* offset, length, type_offset_in_tu are set later. */
8674 /* Lookup the DWO with SIGNATURE in DWP_FILE. */
8676 static struct dwo_unit
*
8677 lookup_dwo_in_dwp (struct dwp_file
*dwp_file
,
8678 const struct dwp_hash_table
*htab
,
8679 ULONGEST signature
, int is_debug_types
)
8681 bfd
*dbfd
= dwp_file
->dbfd
;
8682 uint32_t mask
= htab
->nr_slots
- 1;
8683 uint32_t hash
= signature
& mask
;
8684 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
8687 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8689 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
8690 find_dwo_cu
.signature
= signature
;
8691 slot
= htab_find_slot (dwp_file
->loaded_cutus
, &find_dwo_cu
, INSERT
);
8696 /* Use a for loop so that we don't loop forever on bad debug info. */
8697 for (i
= 0; i
< htab
->nr_slots
; ++i
)
8699 ULONGEST signature_in_table
;
8701 signature_in_table
=
8702 read_8_bytes (dbfd
, htab
->hash_table
+ hash
* sizeof (uint64_t));
8703 if (signature_in_table
== signature
)
8705 uint32_t section_index
=
8706 read_4_bytes (dbfd
, htab
->unit_table
+ hash
* sizeof (uint32_t));
8708 *slot
= create_dwo_in_dwp (dwp_file
, htab
, section_index
,
8709 signature
, is_debug_types
);
8712 if (signature_in_table
== 0)
8714 hash
= (hash
+ hash2
) & mask
;
8717 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
8722 /* Subroutine of open_dwop_file to simplify it.
8723 Open the file specified by FILE_NAME and hand it off to BFD for
8724 preliminary analysis. Return a newly initialized bfd *, which
8725 includes a canonicalized copy of FILE_NAME.
8726 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8727 In case of trouble, return NULL.
8728 NOTE: This function is derived from symfile_bfd_open. */
8731 try_open_dwop_file (const char *file_name
, int is_dwp
)
8735 char *absolute_name
;
8737 flags
= OPF_TRY_CWD_FIRST
;
8739 flags
|= OPF_SEARCH_IN_PATH
;
8740 desc
= openp (debug_file_directory
, flags
, file_name
,
8741 O_RDONLY
| O_BINARY
, &absolute_name
);
8745 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
8748 xfree (absolute_name
);
8751 xfree (absolute_name
);
8752 bfd_set_cacheable (sym_bfd
, 1);
8754 if (!bfd_check_format (sym_bfd
, bfd_object
))
8756 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
8763 /* Try to open DWO/DWP file FILE_NAME.
8764 COMP_DIR is the DW_AT_comp_dir attribute.
8765 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8766 The result is the bfd handle of the file.
8767 If there is a problem finding or opening the file, return NULL.
8768 Upon success, the canonicalized path of the file is stored in the bfd,
8769 same as symfile_bfd_open. */
8772 open_dwop_file (const char *file_name
, const char *comp_dir
, int is_dwp
)
8776 if (IS_ABSOLUTE_PATH (file_name
))
8777 return try_open_dwop_file (file_name
, is_dwp
);
8779 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8781 if (comp_dir
!= NULL
)
8783 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, file_name
, NULL
);
8785 /* NOTE: If comp_dir is a relative path, this will also try the
8786 search path, which seems useful. */
8787 abfd
= try_open_dwop_file (path_to_try
, is_dwp
);
8788 xfree (path_to_try
);
8793 /* That didn't work, try debug-file-directory, which, despite its name,
8794 is a list of paths. */
8796 if (*debug_file_directory
== '\0')
8799 return try_open_dwop_file (file_name
, is_dwp
);
8802 /* This function is mapped across the sections and remembers the offset and
8803 size of each of the DWO debugging sections we are interested in. */
8806 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
8808 struct dwo_sections
*dwo_sections
= dwo_sections_ptr
;
8809 const struct dwop_section_names
*names
= &dwop_section_names
;
8811 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8813 dwo_sections
->abbrev
.asection
= sectp
;
8814 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8816 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
8818 dwo_sections
->info
.asection
= sectp
;
8819 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
8821 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8823 dwo_sections
->line
.asection
= sectp
;
8824 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
8826 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8828 dwo_sections
->loc
.asection
= sectp
;
8829 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
8831 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8833 dwo_sections
->macinfo
.asection
= sectp
;
8834 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8836 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8838 dwo_sections
->macro
.asection
= sectp
;
8839 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
8841 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
8843 dwo_sections
->str
.asection
= sectp
;
8844 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
8846 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8848 dwo_sections
->str_offsets
.asection
= sectp
;
8849 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8851 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
8853 struct dwarf2_section_info type_section
;
8855 memset (&type_section
, 0, sizeof (type_section
));
8856 type_section
.asection
= sectp
;
8857 type_section
.size
= bfd_get_section_size (sectp
);
8858 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
8863 /* Initialize the use of the DWO file specified by DWO_NAME.
8864 The result is NULL if DWO_NAME can't be found. */
8866 static struct dwo_file
*
8867 open_and_init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8869 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8870 struct dwo_file
*dwo_file
;
8872 struct cleanup
*cleanups
;
8874 dbfd
= open_dwop_file (dwo_name
, comp_dir
, 0);
8877 if (dwarf2_read_debug
)
8878 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
8881 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8882 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8883 dwo_name
, strlen (dwo_name
));
8884 dwo_file
->dbfd
= dbfd
;
8886 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8888 bfd_map_over_sections (dbfd
, dwarf2_locate_dwo_sections
, &dwo_file
->sections
);
8890 dwo_file
->cus
= create_dwo_debug_info_hash_table (dwo_file
);
8892 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8893 dwo_file
->sections
.types
);
8895 discard_cleanups (cleanups
);
8897 if (dwarf2_read_debug
)
8898 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
8903 /* This function is mapped across the sections and remembers the offset and
8904 size of each of the DWP debugging sections we are interested in. */
8907 dwarf2_locate_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
8909 struct dwp_file
*dwp_file
= dwp_file_ptr
;
8910 const struct dwop_section_names
*names
= &dwop_section_names
;
8911 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
8913 /* Record the ELF section number for later lookup: this is what the
8914 .debug_cu_index,.debug_tu_index tables use. */
8915 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
8916 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
8918 /* Look for specific sections that we need. */
8919 if (section_is_p (sectp
->name
, &names
->str_dwo
))
8921 dwp_file
->sections
.str
.asection
= sectp
;
8922 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
8924 else if (section_is_p (sectp
->name
, &names
->cu_index
))
8926 dwp_file
->sections
.cu_index
.asection
= sectp
;
8927 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
8929 else if (section_is_p (sectp
->name
, &names
->tu_index
))
8931 dwp_file
->sections
.tu_index
.asection
= sectp
;
8932 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
8936 /* Hash function for dwp_file loaded CUs/TUs. */
8939 hash_dwp_loaded_cutus (const void *item
)
8941 const struct dwo_unit
*dwo_unit
= item
;
8943 /* This drops the top 32 bits of the signature, but is ok for a hash. */
8944 return dwo_unit
->signature
;
8947 /* Equality function for dwp_file loaded CUs/TUs. */
8950 eq_dwp_loaded_cutus (const void *a
, const void *b
)
8952 const struct dwo_unit
*dua
= a
;
8953 const struct dwo_unit
*dub
= b
;
8955 return dua
->signature
== dub
->signature
;
8958 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
8961 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
8963 return htab_create_alloc_ex (3,
8964 hash_dwp_loaded_cutus
,
8965 eq_dwp_loaded_cutus
,
8967 &objfile
->objfile_obstack
,
8968 hashtab_obstack_allocate
,
8969 dummy_obstack_deallocate
);
8972 /* Initialize the use of the DWP file for the current objfile.
8973 By convention the name of the DWP file is ${objfile}.dwp.
8974 The result is NULL if it can't be found. */
8976 static struct dwp_file
*
8977 open_and_init_dwp_file (const char *comp_dir
)
8979 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8980 struct dwp_file
*dwp_file
;
8983 struct cleanup
*cleanups
;
8985 xasprintf (&dwp_name
, "%s.dwp", dwarf2_per_objfile
->objfile
->name
);
8986 cleanups
= make_cleanup (xfree
, dwp_name
);
8988 dbfd
= open_dwop_file (dwp_name
, comp_dir
, 1);
8991 if (dwarf2_read_debug
)
8992 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
8993 do_cleanups (cleanups
);
8996 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
8997 dwp_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8998 dwp_name
, strlen (dwp_name
));
8999 dwp_file
->dbfd
= dbfd
;
9000 do_cleanups (cleanups
);
9002 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwp_file
);
9004 /* +1: section 0 is unused */
9005 dwp_file
->num_sections
= bfd_count_sections (dbfd
) + 1;
9006 dwp_file
->elf_sections
=
9007 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
9008 dwp_file
->num_sections
, asection
*);
9010 bfd_map_over_sections (dbfd
, dwarf2_locate_dwp_sections
, dwp_file
);
9012 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
9014 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
9016 dwp_file
->loaded_cutus
= allocate_dwp_loaded_cutus_table (objfile
);
9018 discard_cleanups (cleanups
);
9020 if (dwarf2_read_debug
)
9022 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
9023 fprintf_unfiltered (gdb_stdlog
,
9024 " %u CUs, %u TUs\n",
9025 dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0,
9026 dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0);
9032 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9033 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9034 or in the DWP file for the objfile, referenced by THIS_UNIT.
9035 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9036 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9038 This is called, for example, when wanting to read a variable with a
9039 complex location. Therefore we don't want to do file i/o for every call.
9040 Therefore we don't want to look for a DWO file on every call.
9041 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9042 then we check if we've already seen DWO_NAME, and only THEN do we check
9045 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9046 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9048 static struct dwo_unit
*
9049 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
9050 const char *dwo_name
, const char *comp_dir
,
9051 ULONGEST signature
, int is_debug_types
)
9053 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9054 const char *kind
= is_debug_types
? "TU" : "CU";
9055 void **dwo_file_slot
;
9056 struct dwo_file
*dwo_file
;
9057 struct dwp_file
*dwp_file
;
9059 /* Have we already read SIGNATURE from a DWP file? */
9061 if (! dwarf2_per_objfile
->dwp_checked
)
9063 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file (comp_dir
);
9064 dwarf2_per_objfile
->dwp_checked
= 1;
9066 dwp_file
= dwarf2_per_objfile
->dwp_file
;
9068 if (dwp_file
!= NULL
)
9070 const struct dwp_hash_table
*dwp_htab
=
9071 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9073 if (dwp_htab
!= NULL
)
9075 struct dwo_unit
*dwo_cutu
=
9076 lookup_dwo_in_dwp (dwp_file
, dwp_htab
, signature
, is_debug_types
);
9078 if (dwo_cutu
!= NULL
)
9080 if (dwarf2_read_debug
)
9082 fprintf_unfiltered (gdb_stdlog
,
9083 "Virtual DWO %s %s found: @%s\n",
9084 kind
, hex_string (signature
),
9085 host_address_to_string (dwo_cutu
));
9092 /* Have we already seen DWO_NAME? */
9094 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
);
9095 if (*dwo_file_slot
== NULL
)
9097 /* Read in the file and build a table of the DWOs it contains. */
9098 *dwo_file_slot
= open_and_init_dwo_file (dwo_name
, comp_dir
);
9100 /* NOTE: This will be NULL if unable to open the file. */
9101 dwo_file
= *dwo_file_slot
;
9103 if (dwo_file
!= NULL
)
9105 htab_t htab
= is_debug_types
? dwo_file
->tus
: dwo_file
->cus
;
9109 struct dwo_unit find_dwo_cutu
, *dwo_cutu
;
9111 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
9112 find_dwo_cutu
.signature
= signature
;
9113 dwo_cutu
= htab_find (htab
, &find_dwo_cutu
);
9115 if (dwo_cutu
!= NULL
)
9117 if (dwarf2_read_debug
)
9119 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
9120 kind
, dwo_name
, hex_string (signature
),
9121 host_address_to_string (dwo_cutu
));
9128 /* We didn't find it. This could mean a dwo_id mismatch, or
9129 someone deleted the DWO/DWP file, or the search path isn't set up
9130 correctly to find the file. */
9132 if (dwarf2_read_debug
)
9134 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
9135 kind
, dwo_name
, hex_string (signature
));
9138 complaint (&symfile_complaints
,
9139 _("Could not find DWO CU referenced by CU at offset 0x%x"
9141 this_unit
->offset
.sect_off
, objfile
->name
);
9145 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9146 See lookup_dwo_cutu_unit for details. */
9148 static struct dwo_unit
*
9149 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9150 const char *dwo_name
, const char *comp_dir
,
9153 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
9156 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9157 See lookup_dwo_cutu_unit for details. */
9159 static struct dwo_unit
*
9160 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
9161 const char *dwo_name
, const char *comp_dir
)
9163 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
9166 /* Free all resources associated with DWO_FILE.
9167 Close the DWO file and munmap the sections.
9168 All memory should be on the objfile obstack. */
9171 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
9174 struct dwarf2_section_info
*section
;
9176 gdb_assert (dwo_file
->dbfd
!= objfile
->obfd
);
9177 gdb_bfd_unref (dwo_file
->dbfd
);
9179 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
9182 /* Wrapper for free_dwo_file for use in cleanups. */
9185 free_dwo_file_cleanup (void *arg
)
9187 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
9188 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9190 free_dwo_file (dwo_file
, objfile
);
9193 /* Traversal function for free_dwo_files. */
9196 free_dwo_file_from_slot (void **slot
, void *info
)
9198 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
9199 struct objfile
*objfile
= (struct objfile
*) info
;
9201 free_dwo_file (dwo_file
, objfile
);
9206 /* Free all resources associated with DWO_FILES. */
9209 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
9211 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
9214 /* Read in various DIEs. */
9216 /* qsort helper for inherit_abstract_dies. */
9219 unsigned_int_compar (const void *ap
, const void *bp
)
9221 unsigned int a
= *(unsigned int *) ap
;
9222 unsigned int b
= *(unsigned int *) bp
;
9224 return (a
> b
) - (b
> a
);
9227 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9228 Inherit only the children of the DW_AT_abstract_origin DIE not being
9229 already referenced by DW_AT_abstract_origin from the children of the
9233 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
9235 struct die_info
*child_die
;
9236 unsigned die_children_count
;
9237 /* CU offsets which were referenced by children of the current DIE. */
9238 sect_offset
*offsets
;
9239 sect_offset
*offsets_end
, *offsetp
;
9240 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9241 struct die_info
*origin_die
;
9242 /* Iterator of the ORIGIN_DIE children. */
9243 struct die_info
*origin_child_die
;
9244 struct cleanup
*cleanups
;
9245 struct attribute
*attr
;
9246 struct dwarf2_cu
*origin_cu
;
9247 struct pending
**origin_previous_list_in_scope
;
9249 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9253 /* Note that following die references may follow to a die in a
9257 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
9259 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9261 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
9262 origin_cu
->list_in_scope
= cu
->list_in_scope
;
9264 if (die
->tag
!= origin_die
->tag
9265 && !(die
->tag
== DW_TAG_inlined_subroutine
9266 && origin_die
->tag
== DW_TAG_subprogram
))
9267 complaint (&symfile_complaints
,
9268 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
9269 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
9271 child_die
= die
->child
;
9272 die_children_count
= 0;
9273 while (child_die
&& child_die
->tag
)
9275 child_die
= sibling_die (child_die
);
9276 die_children_count
++;
9278 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
9279 cleanups
= make_cleanup (xfree
, offsets
);
9281 offsets_end
= offsets
;
9282 child_die
= die
->child
;
9283 while (child_die
&& child_die
->tag
)
9285 /* For each CHILD_DIE, find the corresponding child of
9286 ORIGIN_DIE. If there is more than one layer of
9287 DW_AT_abstract_origin, follow them all; there shouldn't be,
9288 but GCC versions at least through 4.4 generate this (GCC PR
9290 struct die_info
*child_origin_die
= child_die
;
9291 struct dwarf2_cu
*child_origin_cu
= cu
;
9295 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
9299 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
9303 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9304 counterpart may exist. */
9305 if (child_origin_die
!= child_die
)
9307 if (child_die
->tag
!= child_origin_die
->tag
9308 && !(child_die
->tag
== DW_TAG_inlined_subroutine
9309 && child_origin_die
->tag
== DW_TAG_subprogram
))
9310 complaint (&symfile_complaints
,
9311 _("Child DIE 0x%x and its abstract origin 0x%x have "
9312 "different tags"), child_die
->offset
.sect_off
,
9313 child_origin_die
->offset
.sect_off
);
9314 if (child_origin_die
->parent
!= origin_die
)
9315 complaint (&symfile_complaints
,
9316 _("Child DIE 0x%x and its abstract origin 0x%x have "
9317 "different parents"), child_die
->offset
.sect_off
,
9318 child_origin_die
->offset
.sect_off
);
9320 *offsets_end
++ = child_origin_die
->offset
;
9322 child_die
= sibling_die (child_die
);
9324 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
9325 unsigned_int_compar
);
9326 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
9327 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
9328 complaint (&symfile_complaints
,
9329 _("Multiple children of DIE 0x%x refer "
9330 "to DIE 0x%x as their abstract origin"),
9331 die
->offset
.sect_off
, offsetp
->sect_off
);
9334 origin_child_die
= origin_die
->child
;
9335 while (origin_child_die
&& origin_child_die
->tag
)
9337 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9338 while (offsetp
< offsets_end
9339 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
9341 if (offsetp
>= offsets_end
9342 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
9344 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
9345 process_die (origin_child_die
, origin_cu
);
9347 origin_child_die
= sibling_die (origin_child_die
);
9349 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
9351 do_cleanups (cleanups
);
9355 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9357 struct objfile
*objfile
= cu
->objfile
;
9358 struct context_stack
*new;
9361 struct die_info
*child_die
;
9362 struct attribute
*attr
, *call_line
, *call_file
;
9365 struct block
*block
;
9366 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
9367 VEC (symbolp
) *template_args
= NULL
;
9368 struct template_symbol
*templ_func
= NULL
;
9372 /* If we do not have call site information, we can't show the
9373 caller of this inlined function. That's too confusing, so
9374 only use the scope for local variables. */
9375 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
9376 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
9377 if (call_line
== NULL
|| call_file
== NULL
)
9379 read_lexical_block_scope (die
, cu
);
9384 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9386 name
= dwarf2_name (die
, cu
);
9388 /* Ignore functions with missing or empty names. These are actually
9389 illegal according to the DWARF standard. */
9392 complaint (&symfile_complaints
,
9393 _("missing name for subprogram DIE at %d"),
9394 die
->offset
.sect_off
);
9398 /* Ignore functions with missing or invalid low and high pc attributes. */
9399 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9401 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9402 if (!attr
|| !DW_UNSND (attr
))
9403 complaint (&symfile_complaints
,
9404 _("cannot get low and high bounds "
9405 "for subprogram DIE at %d"),
9406 die
->offset
.sect_off
);
9413 /* If we have any template arguments, then we must allocate a
9414 different sort of symbol. */
9415 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
9417 if (child_die
->tag
== DW_TAG_template_type_param
9418 || child_die
->tag
== DW_TAG_template_value_param
)
9420 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
9421 struct template_symbol
);
9422 templ_func
->base
.is_cplus_template_function
= 1;
9427 new = push_context (0, lowpc
);
9428 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
9429 (struct symbol
*) templ_func
);
9431 /* If there is a location expression for DW_AT_frame_base, record
9433 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
9435 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
9436 expression is being recorded directly in the function's symbol
9437 and not in a separate frame-base object. I guess this hack is
9438 to avoid adding some sort of frame-base adjunct/annex to the
9439 function's symbol :-(. The problem with doing this is that it
9440 results in a function symbol with a location expression that
9441 has nothing to do with the location of the function, ouch! The
9442 relationship should be: a function's symbol has-a frame base; a
9443 frame-base has-a location expression. */
9444 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
9446 cu
->list_in_scope
= &local_symbols
;
9448 if (die
->child
!= NULL
)
9450 child_die
= die
->child
;
9451 while (child_die
&& child_die
->tag
)
9453 if (child_die
->tag
== DW_TAG_template_type_param
9454 || child_die
->tag
== DW_TAG_template_value_param
)
9456 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9459 VEC_safe_push (symbolp
, template_args
, arg
);
9462 process_die (child_die
, cu
);
9463 child_die
= sibling_die (child_die
);
9467 inherit_abstract_dies (die
, cu
);
9469 /* If we have a DW_AT_specification, we might need to import using
9470 directives from the context of the specification DIE. See the
9471 comment in determine_prefix. */
9472 if (cu
->language
== language_cplus
9473 && dwarf2_attr (die
, DW_AT_specification
, cu
))
9475 struct dwarf2_cu
*spec_cu
= cu
;
9476 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
9480 child_die
= spec_die
->child
;
9481 while (child_die
&& child_die
->tag
)
9483 if (child_die
->tag
== DW_TAG_imported_module
)
9484 process_die (child_die
, spec_cu
);
9485 child_die
= sibling_die (child_die
);
9488 /* In some cases, GCC generates specification DIEs that
9489 themselves contain DW_AT_specification attributes. */
9490 spec_die
= die_specification (spec_die
, &spec_cu
);
9494 new = pop_context ();
9495 /* Make a block for the local symbols within. */
9496 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
9497 lowpc
, highpc
, objfile
);
9499 /* For C++, set the block's scope. */
9500 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
9501 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
9502 determine_prefix (die
, cu
),
9503 processing_has_namespace_info
);
9505 /* If we have address ranges, record them. */
9506 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9508 /* Attach template arguments to function. */
9509 if (! VEC_empty (symbolp
, template_args
))
9511 gdb_assert (templ_func
!= NULL
);
9513 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
9514 templ_func
->template_arguments
9515 = obstack_alloc (&objfile
->objfile_obstack
,
9516 (templ_func
->n_template_arguments
9517 * sizeof (struct symbol
*)));
9518 memcpy (templ_func
->template_arguments
,
9519 VEC_address (symbolp
, template_args
),
9520 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
9521 VEC_free (symbolp
, template_args
);
9524 /* In C++, we can have functions nested inside functions (e.g., when
9525 a function declares a class that has methods). This means that
9526 when we finish processing a function scope, we may need to go
9527 back to building a containing block's symbol lists. */
9528 local_symbols
= new->locals
;
9529 using_directives
= new->using_directives
;
9531 /* If we've finished processing a top-level function, subsequent
9532 symbols go in the file symbol list. */
9533 if (outermost_context_p ())
9534 cu
->list_in_scope
= &file_symbols
;
9537 /* Process all the DIES contained within a lexical block scope. Start
9538 a new scope, process the dies, and then close the scope. */
9541 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9543 struct objfile
*objfile
= cu
->objfile
;
9544 struct context_stack
*new;
9545 CORE_ADDR lowpc
, highpc
;
9546 struct die_info
*child_die
;
9549 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9551 /* Ignore blocks with missing or invalid low and high pc attributes. */
9552 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
9553 as multiple lexical blocks? Handling children in a sane way would
9554 be nasty. Might be easier to properly extend generic blocks to
9556 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9561 push_context (0, lowpc
);
9562 if (die
->child
!= NULL
)
9564 child_die
= die
->child
;
9565 while (child_die
&& child_die
->tag
)
9567 process_die (child_die
, cu
);
9568 child_die
= sibling_die (child_die
);
9571 new = pop_context ();
9573 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
9576 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
9579 /* Note that recording ranges after traversing children, as we
9580 do here, means that recording a parent's ranges entails
9581 walking across all its children's ranges as they appear in
9582 the address map, which is quadratic behavior.
9584 It would be nicer to record the parent's ranges before
9585 traversing its children, simply overriding whatever you find
9586 there. But since we don't even decide whether to create a
9587 block until after we've traversed its children, that's hard
9589 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9591 local_symbols
= new->locals
;
9592 using_directives
= new->using_directives
;
9595 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
9598 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9600 struct objfile
*objfile
= cu
->objfile
;
9601 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9602 CORE_ADDR pc
, baseaddr
;
9603 struct attribute
*attr
;
9604 struct call_site
*call_site
, call_site_local
;
9607 struct die_info
*child_die
;
9609 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9611 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9614 complaint (&symfile_complaints
,
9615 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
9616 "DIE 0x%x [in module %s]"),
9617 die
->offset
.sect_off
, objfile
->name
);
9620 pc
= DW_ADDR (attr
) + baseaddr
;
9622 if (cu
->call_site_htab
== NULL
)
9623 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
9624 NULL
, &objfile
->objfile_obstack
,
9625 hashtab_obstack_allocate
, NULL
);
9626 call_site_local
.pc
= pc
;
9627 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
9630 complaint (&symfile_complaints
,
9631 _("Duplicate PC %s for DW_TAG_GNU_call_site "
9632 "DIE 0x%x [in module %s]"),
9633 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
9637 /* Count parameters at the caller. */
9640 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9641 child_die
= sibling_die (child_die
))
9643 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9645 complaint (&symfile_complaints
,
9646 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
9647 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9648 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
9655 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
9656 (sizeof (*call_site
)
9657 + (sizeof (*call_site
->parameter
)
9660 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
9663 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
9665 struct die_info
*func_die
;
9667 /* Skip also over DW_TAG_inlined_subroutine. */
9668 for (func_die
= die
->parent
;
9669 func_die
&& func_die
->tag
!= DW_TAG_subprogram
9670 && func_die
->tag
!= DW_TAG_subroutine_type
;
9671 func_die
= func_die
->parent
);
9673 /* DW_AT_GNU_all_call_sites is a superset
9674 of DW_AT_GNU_all_tail_call_sites. */
9676 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
9677 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
9679 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
9680 not complete. But keep CALL_SITE for look ups via call_site_htab,
9681 both the initial caller containing the real return address PC and
9682 the final callee containing the current PC of a chain of tail
9683 calls do not need to have the tail call list complete. But any
9684 function candidate for a virtual tail call frame searched via
9685 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
9686 determined unambiguously. */
9690 struct type
*func_type
= NULL
;
9693 func_type
= get_die_type (func_die
, cu
);
9694 if (func_type
!= NULL
)
9696 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
9698 /* Enlist this call site to the function. */
9699 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
9700 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
9703 complaint (&symfile_complaints
,
9704 _("Cannot find function owning DW_TAG_GNU_call_site "
9705 "DIE 0x%x [in module %s]"),
9706 die
->offset
.sect_off
, objfile
->name
);
9710 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
9712 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9713 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
9714 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
9715 /* Keep NULL DWARF_BLOCK. */;
9716 else if (attr_form_is_block (attr
))
9718 struct dwarf2_locexpr_baton
*dlbaton
;
9720 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
9721 dlbaton
->data
= DW_BLOCK (attr
)->data
;
9722 dlbaton
->size
= DW_BLOCK (attr
)->size
;
9723 dlbaton
->per_cu
= cu
->per_cu
;
9725 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
9727 else if (is_ref_attr (attr
))
9729 struct dwarf2_cu
*target_cu
= cu
;
9730 struct die_info
*target_die
;
9732 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
9733 gdb_assert (target_cu
->objfile
== objfile
);
9734 if (die_is_declaration (target_die
, target_cu
))
9736 const char *target_physname
;
9738 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
9739 if (target_physname
== NULL
)
9740 complaint (&symfile_complaints
,
9741 _("DW_AT_GNU_call_site_target target DIE has invalid "
9742 "physname, for referencing DIE 0x%x [in module %s]"),
9743 die
->offset
.sect_off
, objfile
->name
);
9745 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
9751 /* DW_AT_entry_pc should be preferred. */
9752 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
9753 complaint (&symfile_complaints
,
9754 _("DW_AT_GNU_call_site_target target DIE has invalid "
9755 "low pc, for referencing DIE 0x%x [in module %s]"),
9756 die
->offset
.sect_off
, objfile
->name
);
9758 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
9762 complaint (&symfile_complaints
,
9763 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
9764 "block nor reference, for DIE 0x%x [in module %s]"),
9765 die
->offset
.sect_off
, objfile
->name
);
9767 call_site
->per_cu
= cu
->per_cu
;
9769 for (child_die
= die
->child
;
9770 child_die
&& child_die
->tag
;
9771 child_die
= sibling_die (child_die
))
9773 struct call_site_parameter
*parameter
;
9774 struct attribute
*loc
, *origin
;
9776 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9778 /* Already printed the complaint above. */
9782 gdb_assert (call_site
->parameter_count
< nparams
);
9783 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
9785 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
9786 specifies DW_TAG_formal_parameter. Value of the data assumed for the
9787 register is contained in DW_AT_GNU_call_site_value. */
9789 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
9790 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
9791 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
9795 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
9796 offset
= dwarf2_get_ref_die_offset (origin
);
9797 if (!offset_in_cu_p (&cu
->header
, offset
))
9799 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
9800 binding can be done only inside one CU. Such referenced DIE
9801 therefore cannot be even moved to DW_TAG_partial_unit. */
9802 complaint (&symfile_complaints
,
9803 _("DW_AT_abstract_origin offset is not in CU for "
9804 "DW_TAG_GNU_call_site child DIE 0x%x "
9806 child_die
->offset
.sect_off
, objfile
->name
);
9809 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
9810 - cu
->header
.offset
.sect_off
);
9812 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
9814 complaint (&symfile_complaints
,
9815 _("No DW_FORM_block* DW_AT_location for "
9816 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9817 child_die
->offset
.sect_off
, objfile
->name
);
9822 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
9823 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
9824 if (parameter
->u
.dwarf_reg
!= -1)
9825 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
9826 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
9827 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
9828 ¶meter
->u
.fb_offset
))
9829 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
9832 complaint (&symfile_complaints
,
9833 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
9834 "for DW_FORM_block* DW_AT_location is supported for "
9835 "DW_TAG_GNU_call_site child DIE 0x%x "
9837 child_die
->offset
.sect_off
, objfile
->name
);
9842 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
9843 if (!attr_form_is_block (attr
))
9845 complaint (&symfile_complaints
,
9846 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9847 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9848 child_die
->offset
.sect_off
, objfile
->name
);
9851 parameter
->value
= DW_BLOCK (attr
)->data
;
9852 parameter
->value_size
= DW_BLOCK (attr
)->size
;
9854 /* Parameters are not pre-cleared by memset above. */
9855 parameter
->data_value
= NULL
;
9856 parameter
->data_value_size
= 0;
9857 call_site
->parameter_count
++;
9859 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
9862 if (!attr_form_is_block (attr
))
9863 complaint (&symfile_complaints
,
9864 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9865 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9866 child_die
->offset
.sect_off
, objfile
->name
);
9869 parameter
->data_value
= DW_BLOCK (attr
)->data
;
9870 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
9876 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9877 Return 1 if the attributes are present and valid, otherwise, return 0.
9878 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9881 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
9882 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
9883 struct partial_symtab
*ranges_pst
)
9885 struct objfile
*objfile
= cu
->objfile
;
9886 struct comp_unit_head
*cu_header
= &cu
->header
;
9887 bfd
*obfd
= objfile
->obfd
;
9888 unsigned int addr_size
= cu_header
->addr_size
;
9889 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9890 /* Base address selection entry. */
9901 found_base
= cu
->base_known
;
9902 base
= cu
->base_address
;
9904 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9905 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9907 complaint (&symfile_complaints
,
9908 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9912 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9914 /* Read in the largest possible address. */
9915 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
9916 if ((marker
& mask
) == mask
)
9918 /* If we found the largest possible address, then
9919 read the base address. */
9920 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9921 buffer
+= 2 * addr_size
;
9922 offset
+= 2 * addr_size
;
9928 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9932 CORE_ADDR range_beginning
, range_end
;
9934 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
9935 buffer
+= addr_size
;
9936 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
9937 buffer
+= addr_size
;
9938 offset
+= 2 * addr_size
;
9940 /* An end of list marker is a pair of zero addresses. */
9941 if (range_beginning
== 0 && range_end
== 0)
9942 /* Found the end of list entry. */
9945 /* Each base address selection entry is a pair of 2 values.
9946 The first is the largest possible address, the second is
9947 the base address. Check for a base address here. */
9948 if ((range_beginning
& mask
) == mask
)
9950 /* If we found the largest possible address, then
9951 read the base address. */
9952 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9959 /* We have no valid base address for the ranges
9961 complaint (&symfile_complaints
,
9962 _("Invalid .debug_ranges data (no base address)"));
9966 if (range_beginning
> range_end
)
9968 /* Inverted range entries are invalid. */
9969 complaint (&symfile_complaints
,
9970 _("Invalid .debug_ranges data (inverted range)"));
9974 /* Empty range entries have no effect. */
9975 if (range_beginning
== range_end
)
9978 range_beginning
+= base
;
9981 /* A not-uncommon case of bad debug info.
9982 Don't pollute the addrmap with bad data. */
9983 if (range_beginning
+ baseaddr
== 0
9984 && !dwarf2_per_objfile
->has_section_at_zero
)
9986 complaint (&symfile_complaints
,
9987 _(".debug_ranges entry has start address of zero"
9988 " [in module %s]"), objfile
->name
);
9992 if (ranges_pst
!= NULL
)
9993 addrmap_set_empty (objfile
->psymtabs_addrmap
,
9994 range_beginning
+ baseaddr
,
9995 range_end
- 1 + baseaddr
,
9998 /* FIXME: This is recording everything as a low-high
9999 segment of consecutive addresses. We should have a
10000 data structure for discontiguous block ranges
10004 low
= range_beginning
;
10010 if (range_beginning
< low
)
10011 low
= range_beginning
;
10012 if (range_end
> high
)
10018 /* If the first entry is an end-of-list marker, the range
10019 describes an empty scope, i.e. no instructions. */
10025 *high_return
= high
;
10029 /* Get low and high pc attributes from a die. Return 1 if the attributes
10030 are present and valid, otherwise, return 0. Return -1 if the range is
10031 discontinuous, i.e. derived from DW_AT_ranges information. */
10034 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
10035 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
10036 struct partial_symtab
*pst
)
10038 struct attribute
*attr
;
10039 struct attribute
*attr_high
;
10041 CORE_ADDR high
= 0;
10044 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10047 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10050 low
= DW_ADDR (attr
);
10051 if (attr_high
->form
== DW_FORM_addr
10052 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10053 high
= DW_ADDR (attr_high
);
10055 high
= low
+ DW_UNSND (attr_high
);
10058 /* Found high w/o low attribute. */
10061 /* Found consecutive range of addresses. */
10066 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10069 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
10071 /* Value of the DW_AT_ranges attribute is the offset in the
10072 .debug_ranges section. */
10073 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
10075 /* Found discontinuous range of addresses. */
10080 /* read_partial_die has also the strict LOW < HIGH requirement. */
10084 /* When using the GNU linker, .gnu.linkonce. sections are used to
10085 eliminate duplicate copies of functions and vtables and such.
10086 The linker will arbitrarily choose one and discard the others.
10087 The AT_*_pc values for such functions refer to local labels in
10088 these sections. If the section from that file was discarded, the
10089 labels are not in the output, so the relocs get a value of 0.
10090 If this is a discarded function, mark the pc bounds as invalid,
10091 so that GDB will ignore it. */
10092 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10101 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
10102 its low and high PC addresses. Do nothing if these addresses could not
10103 be determined. Otherwise, set LOWPC to the low address if it is smaller,
10104 and HIGHPC to the high address if greater than HIGHPC. */
10107 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
10108 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10109 struct dwarf2_cu
*cu
)
10111 CORE_ADDR low
, high
;
10112 struct die_info
*child
= die
->child
;
10114 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
10116 *lowpc
= min (*lowpc
, low
);
10117 *highpc
= max (*highpc
, high
);
10120 /* If the language does not allow nested subprograms (either inside
10121 subprograms or lexical blocks), we're done. */
10122 if (cu
->language
!= language_ada
)
10125 /* Check all the children of the given DIE. If it contains nested
10126 subprograms, then check their pc bounds. Likewise, we need to
10127 check lexical blocks as well, as they may also contain subprogram
10129 while (child
&& child
->tag
)
10131 if (child
->tag
== DW_TAG_subprogram
10132 || child
->tag
== DW_TAG_lexical_block
)
10133 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
10134 child
= sibling_die (child
);
10138 /* Get the low and high pc's represented by the scope DIE, and store
10139 them in *LOWPC and *HIGHPC. If the correct values can't be
10140 determined, set *LOWPC to -1 and *HIGHPC to 0. */
10143 get_scope_pc_bounds (struct die_info
*die
,
10144 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10145 struct dwarf2_cu
*cu
)
10147 CORE_ADDR best_low
= (CORE_ADDR
) -1;
10148 CORE_ADDR best_high
= (CORE_ADDR
) 0;
10149 CORE_ADDR current_low
, current_high
;
10151 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
10153 best_low
= current_low
;
10154 best_high
= current_high
;
10158 struct die_info
*child
= die
->child
;
10160 while (child
&& child
->tag
)
10162 switch (child
->tag
) {
10163 case DW_TAG_subprogram
:
10164 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
10166 case DW_TAG_namespace
:
10167 case DW_TAG_module
:
10168 /* FIXME: carlton/2004-01-16: Should we do this for
10169 DW_TAG_class_type/DW_TAG_structure_type, too? I think
10170 that current GCC's always emit the DIEs corresponding
10171 to definitions of methods of classes as children of a
10172 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
10173 the DIEs giving the declarations, which could be
10174 anywhere). But I don't see any reason why the
10175 standards says that they have to be there. */
10176 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
10178 if (current_low
!= ((CORE_ADDR
) -1))
10180 best_low
= min (best_low
, current_low
);
10181 best_high
= max (best_high
, current_high
);
10189 child
= sibling_die (child
);
10194 *highpc
= best_high
;
10197 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
10201 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
10202 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
10204 struct objfile
*objfile
= cu
->objfile
;
10205 struct attribute
*attr
;
10206 struct attribute
*attr_high
;
10208 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10211 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10214 CORE_ADDR low
= DW_ADDR (attr
);
10216 if (attr_high
->form
== DW_FORM_addr
10217 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10218 high
= DW_ADDR (attr_high
);
10220 high
= low
+ DW_UNSND (attr_high
);
10222 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
10226 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10229 bfd
*obfd
= objfile
->obfd
;
10231 /* The value of the DW_AT_ranges attribute is the offset of the
10232 address range list in the .debug_ranges section. */
10233 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
10234 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
10236 /* For some target architectures, but not others, the
10237 read_address function sign-extends the addresses it returns.
10238 To recognize base address selection entries, we need a
10240 unsigned int addr_size
= cu
->header
.addr_size
;
10241 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
10243 /* The base address, to which the next pair is relative. Note
10244 that this 'base' is a DWARF concept: most entries in a range
10245 list are relative, to reduce the number of relocs against the
10246 debugging information. This is separate from this function's
10247 'baseaddr' argument, which GDB uses to relocate debugging
10248 information from a shared library based on the address at
10249 which the library was loaded. */
10250 CORE_ADDR base
= cu
->base_address
;
10251 int base_known
= cu
->base_known
;
10253 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
10254 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
10256 complaint (&symfile_complaints
,
10257 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
10264 unsigned int bytes_read
;
10265 CORE_ADDR start
, end
;
10267 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10268 buffer
+= bytes_read
;
10269 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10270 buffer
+= bytes_read
;
10272 /* Did we find the end of the range list? */
10273 if (start
== 0 && end
== 0)
10276 /* Did we find a base address selection entry? */
10277 else if ((start
& base_select_mask
) == base_select_mask
)
10283 /* We found an ordinary address range. */
10288 complaint (&symfile_complaints
,
10289 _("Invalid .debug_ranges data "
10290 "(no base address)"));
10296 /* Inverted range entries are invalid. */
10297 complaint (&symfile_complaints
,
10298 _("Invalid .debug_ranges data "
10299 "(inverted range)"));
10303 /* Empty range entries have no effect. */
10307 start
+= base
+ baseaddr
;
10308 end
+= base
+ baseaddr
;
10310 /* A not-uncommon case of bad debug info.
10311 Don't pollute the addrmap with bad data. */
10312 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10314 complaint (&symfile_complaints
,
10315 _(".debug_ranges entry has start address of zero"
10316 " [in module %s]"), objfile
->name
);
10320 record_block_range (block
, start
, end
- 1);
10326 /* Check whether the producer field indicates either of GCC < 4.6, or the
10327 Intel C/C++ compiler, and cache the result in CU. */
10330 check_producer (struct dwarf2_cu
*cu
)
10333 int major
, minor
, release
;
10335 if (cu
->producer
== NULL
)
10337 /* For unknown compilers expect their behavior is DWARF version
10340 GCC started to support .debug_types sections by -gdwarf-4 since
10341 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
10342 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
10343 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
10344 interpreted incorrectly by GDB now - GCC PR debug/48229. */
10346 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
10348 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
10350 cs
= &cu
->producer
[strlen ("GNU ")];
10351 while (*cs
&& !isdigit (*cs
))
10353 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
10355 /* Not recognized as GCC. */
10358 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
10360 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
10361 cu
->producer_is_icc
= 1;
10364 /* For other non-GCC compilers, expect their behavior is DWARF version
10368 cu
->checked_producer
= 1;
10371 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
10372 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
10373 during 4.6.0 experimental. */
10376 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
10378 if (!cu
->checked_producer
)
10379 check_producer (cu
);
10381 return cu
->producer_is_gxx_lt_4_6
;
10384 /* Return the default accessibility type if it is not overriden by
10385 DW_AT_accessibility. */
10387 static enum dwarf_access_attribute
10388 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
10390 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
10392 /* The default DWARF 2 accessibility for members is public, the default
10393 accessibility for inheritance is private. */
10395 if (die
->tag
!= DW_TAG_inheritance
)
10396 return DW_ACCESS_public
;
10398 return DW_ACCESS_private
;
10402 /* DWARF 3+ defines the default accessibility a different way. The same
10403 rules apply now for DW_TAG_inheritance as for the members and it only
10404 depends on the container kind. */
10406 if (die
->parent
->tag
== DW_TAG_class_type
)
10407 return DW_ACCESS_private
;
10409 return DW_ACCESS_public
;
10413 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
10414 offset. If the attribute was not found return 0, otherwise return
10415 1. If it was found but could not properly be handled, set *OFFSET
10419 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
10422 struct attribute
*attr
;
10424 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
10429 /* Note that we do not check for a section offset first here.
10430 This is because DW_AT_data_member_location is new in DWARF 4,
10431 so if we see it, we can assume that a constant form is really
10432 a constant and not a section offset. */
10433 if (attr_form_is_constant (attr
))
10434 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
10435 else if (attr_form_is_section_offset (attr
))
10436 dwarf2_complex_location_expr_complaint ();
10437 else if (attr_form_is_block (attr
))
10438 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10440 dwarf2_complex_location_expr_complaint ();
10448 /* Add an aggregate field to the field list. */
10451 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
10452 struct dwarf2_cu
*cu
)
10454 struct objfile
*objfile
= cu
->objfile
;
10455 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10456 struct nextfield
*new_field
;
10457 struct attribute
*attr
;
10459 char *fieldname
= "";
10461 /* Allocate a new field list entry and link it in. */
10462 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
10463 make_cleanup (xfree
, new_field
);
10464 memset (new_field
, 0, sizeof (struct nextfield
));
10466 if (die
->tag
== DW_TAG_inheritance
)
10468 new_field
->next
= fip
->baseclasses
;
10469 fip
->baseclasses
= new_field
;
10473 new_field
->next
= fip
->fields
;
10474 fip
->fields
= new_field
;
10478 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10480 new_field
->accessibility
= DW_UNSND (attr
);
10482 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
10483 if (new_field
->accessibility
!= DW_ACCESS_public
)
10484 fip
->non_public_fields
= 1;
10486 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10488 new_field
->virtuality
= DW_UNSND (attr
);
10490 new_field
->virtuality
= DW_VIRTUALITY_none
;
10492 fp
= &new_field
->field
;
10494 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
10498 /* Data member other than a C++ static data member. */
10500 /* Get type of field. */
10501 fp
->type
= die_type (die
, cu
);
10503 SET_FIELD_BITPOS (*fp
, 0);
10505 /* Get bit size of field (zero if none). */
10506 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
10509 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
10513 FIELD_BITSIZE (*fp
) = 0;
10516 /* Get bit offset of field. */
10517 if (handle_data_member_location (die
, cu
, &offset
))
10518 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10519 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
10522 if (gdbarch_bits_big_endian (gdbarch
))
10524 /* For big endian bits, the DW_AT_bit_offset gives the
10525 additional bit offset from the MSB of the containing
10526 anonymous object to the MSB of the field. We don't
10527 have to do anything special since we don't need to
10528 know the size of the anonymous object. */
10529 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
10533 /* For little endian bits, compute the bit offset to the
10534 MSB of the anonymous object, subtract off the number of
10535 bits from the MSB of the field to the MSB of the
10536 object, and then subtract off the number of bits of
10537 the field itself. The result is the bit offset of
10538 the LSB of the field. */
10539 int anonymous_size
;
10540 int bit_offset
= DW_UNSND (attr
);
10542 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10545 /* The size of the anonymous object containing
10546 the bit field is explicit, so use the
10547 indicated size (in bytes). */
10548 anonymous_size
= DW_UNSND (attr
);
10552 /* The size of the anonymous object containing
10553 the bit field must be inferred from the type
10554 attribute of the data member containing the
10556 anonymous_size
= TYPE_LENGTH (fp
->type
);
10558 SET_FIELD_BITPOS (*fp
,
10559 (FIELD_BITPOS (*fp
)
10560 + anonymous_size
* bits_per_byte
10561 - bit_offset
- FIELD_BITSIZE (*fp
)));
10565 /* Get name of field. */
10566 fieldname
= dwarf2_name (die
, cu
);
10567 if (fieldname
== NULL
)
10570 /* The name is already allocated along with this objfile, so we don't
10571 need to duplicate it for the type. */
10572 fp
->name
= fieldname
;
10574 /* Change accessibility for artificial fields (e.g. virtual table
10575 pointer or virtual base class pointer) to private. */
10576 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
10578 FIELD_ARTIFICIAL (*fp
) = 1;
10579 new_field
->accessibility
= DW_ACCESS_private
;
10580 fip
->non_public_fields
= 1;
10583 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
10585 /* C++ static member. */
10587 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
10588 is a declaration, but all versions of G++ as of this writing
10589 (so through at least 3.2.1) incorrectly generate
10590 DW_TAG_variable tags. */
10592 const char *physname
;
10594 /* Get name of field. */
10595 fieldname
= dwarf2_name (die
, cu
);
10596 if (fieldname
== NULL
)
10599 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10601 /* Only create a symbol if this is an external value.
10602 new_symbol checks this and puts the value in the global symbol
10603 table, which we want. If it is not external, new_symbol
10604 will try to put the value in cu->list_in_scope which is wrong. */
10605 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
10607 /* A static const member, not much different than an enum as far as
10608 we're concerned, except that we can support more types. */
10609 new_symbol (die
, NULL
, cu
);
10612 /* Get physical name. */
10613 physname
= dwarf2_physname (fieldname
, die
, cu
);
10615 /* The name is already allocated along with this objfile, so we don't
10616 need to duplicate it for the type. */
10617 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
10618 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10619 FIELD_NAME (*fp
) = fieldname
;
10621 else if (die
->tag
== DW_TAG_inheritance
)
10625 /* C++ base class field. */
10626 if (handle_data_member_location (die
, cu
, &offset
))
10627 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10628 FIELD_BITSIZE (*fp
) = 0;
10629 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10630 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
10631 fip
->nbaseclasses
++;
10635 /* Add a typedef defined in the scope of the FIP's class. */
10638 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
10639 struct dwarf2_cu
*cu
)
10641 struct objfile
*objfile
= cu
->objfile
;
10642 struct typedef_field_list
*new_field
;
10643 struct attribute
*attr
;
10644 struct typedef_field
*fp
;
10645 char *fieldname
= "";
10647 /* Allocate a new field list entry and link it in. */
10648 new_field
= xzalloc (sizeof (*new_field
));
10649 make_cleanup (xfree
, new_field
);
10651 gdb_assert (die
->tag
== DW_TAG_typedef
);
10653 fp
= &new_field
->field
;
10655 /* Get name of field. */
10656 fp
->name
= dwarf2_name (die
, cu
);
10657 if (fp
->name
== NULL
)
10660 fp
->type
= read_type_die (die
, cu
);
10662 new_field
->next
= fip
->typedef_field_list
;
10663 fip
->typedef_field_list
= new_field
;
10664 fip
->typedef_field_list_count
++;
10667 /* Create the vector of fields, and attach it to the type. */
10670 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
10671 struct dwarf2_cu
*cu
)
10673 int nfields
= fip
->nfields
;
10675 /* Record the field count, allocate space for the array of fields,
10676 and create blank accessibility bitfields if necessary. */
10677 TYPE_NFIELDS (type
) = nfields
;
10678 TYPE_FIELDS (type
) = (struct field
*)
10679 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
10680 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
10682 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
10684 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10686 TYPE_FIELD_PRIVATE_BITS (type
) =
10687 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10688 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
10690 TYPE_FIELD_PROTECTED_BITS (type
) =
10691 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10692 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
10694 TYPE_FIELD_IGNORE_BITS (type
) =
10695 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10696 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
10699 /* If the type has baseclasses, allocate and clear a bit vector for
10700 TYPE_FIELD_VIRTUAL_BITS. */
10701 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
10703 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
10704 unsigned char *pointer
;
10706 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10707 pointer
= TYPE_ALLOC (type
, num_bytes
);
10708 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
10709 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
10710 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
10713 /* Copy the saved-up fields into the field vector. Start from the head of
10714 the list, adding to the tail of the field array, so that they end up in
10715 the same order in the array in which they were added to the list. */
10716 while (nfields
-- > 0)
10718 struct nextfield
*fieldp
;
10722 fieldp
= fip
->fields
;
10723 fip
->fields
= fieldp
->next
;
10727 fieldp
= fip
->baseclasses
;
10728 fip
->baseclasses
= fieldp
->next
;
10731 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
10732 switch (fieldp
->accessibility
)
10734 case DW_ACCESS_private
:
10735 if (cu
->language
!= language_ada
)
10736 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
10739 case DW_ACCESS_protected
:
10740 if (cu
->language
!= language_ada
)
10741 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
10744 case DW_ACCESS_public
:
10748 /* Unknown accessibility. Complain and treat it as public. */
10750 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
10751 fieldp
->accessibility
);
10755 if (nfields
< fip
->nbaseclasses
)
10757 switch (fieldp
->virtuality
)
10759 case DW_VIRTUALITY_virtual
:
10760 case DW_VIRTUALITY_pure_virtual
:
10761 if (cu
->language
== language_ada
)
10762 error (_("unexpected virtuality in component of Ada type"));
10763 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
10770 /* Add a member function to the proper fieldlist. */
10773 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
10774 struct type
*type
, struct dwarf2_cu
*cu
)
10776 struct objfile
*objfile
= cu
->objfile
;
10777 struct attribute
*attr
;
10778 struct fnfieldlist
*flp
;
10780 struct fn_field
*fnp
;
10782 struct nextfnfield
*new_fnfield
;
10783 struct type
*this_type
;
10784 enum dwarf_access_attribute accessibility
;
10786 if (cu
->language
== language_ada
)
10787 error (_("unexpected member function in Ada type"));
10789 /* Get name of member function. */
10790 fieldname
= dwarf2_name (die
, cu
);
10791 if (fieldname
== NULL
)
10794 /* Look up member function name in fieldlist. */
10795 for (i
= 0; i
< fip
->nfnfields
; i
++)
10797 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
10801 /* Create new list element if necessary. */
10802 if (i
< fip
->nfnfields
)
10803 flp
= &fip
->fnfieldlists
[i
];
10806 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10808 fip
->fnfieldlists
= (struct fnfieldlist
*)
10809 xrealloc (fip
->fnfieldlists
,
10810 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
10811 * sizeof (struct fnfieldlist
));
10812 if (fip
->nfnfields
== 0)
10813 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
10815 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
10816 flp
->name
= fieldname
;
10819 i
= fip
->nfnfields
++;
10822 /* Create a new member function field and chain it to the field list
10824 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
10825 make_cleanup (xfree
, new_fnfield
);
10826 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
10827 new_fnfield
->next
= flp
->head
;
10828 flp
->head
= new_fnfield
;
10831 /* Fill in the member function field info. */
10832 fnp
= &new_fnfield
->fnfield
;
10834 /* Delay processing of the physname until later. */
10835 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
10837 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
10842 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
10843 fnp
->physname
= physname
? physname
: "";
10846 fnp
->type
= alloc_type (objfile
);
10847 this_type
= read_type_die (die
, cu
);
10848 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
10850 int nparams
= TYPE_NFIELDS (this_type
);
10852 /* TYPE is the domain of this method, and THIS_TYPE is the type
10853 of the method itself (TYPE_CODE_METHOD). */
10854 smash_to_method_type (fnp
->type
, type
,
10855 TYPE_TARGET_TYPE (this_type
),
10856 TYPE_FIELDS (this_type
),
10857 TYPE_NFIELDS (this_type
),
10858 TYPE_VARARGS (this_type
));
10860 /* Handle static member functions.
10861 Dwarf2 has no clean way to discern C++ static and non-static
10862 member functions. G++ helps GDB by marking the first
10863 parameter for non-static member functions (which is the this
10864 pointer) as artificial. We obtain this information from
10865 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10866 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
10867 fnp
->voffset
= VOFFSET_STATIC
;
10870 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
10871 dwarf2_full_name (fieldname
, die
, cu
));
10873 /* Get fcontext from DW_AT_containing_type if present. */
10874 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10875 fnp
->fcontext
= die_containing_type (die
, cu
);
10877 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
10878 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
10880 /* Get accessibility. */
10881 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10883 accessibility
= DW_UNSND (attr
);
10885 accessibility
= dwarf2_default_access_attribute (die
, cu
);
10886 switch (accessibility
)
10888 case DW_ACCESS_private
:
10889 fnp
->is_private
= 1;
10891 case DW_ACCESS_protected
:
10892 fnp
->is_protected
= 1;
10896 /* Check for artificial methods. */
10897 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
10898 if (attr
&& DW_UNSND (attr
) != 0)
10899 fnp
->is_artificial
= 1;
10901 /* Get index in virtual function table if it is a virtual member
10902 function. For older versions of GCC, this is an offset in the
10903 appropriate virtual table, as specified by DW_AT_containing_type.
10904 For everyone else, it is an expression to be evaluated relative
10905 to the object address. */
10907 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
10910 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
10912 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
10914 /* Old-style GCC. */
10915 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
10917 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10918 || (DW_BLOCK (attr
)->size
> 1
10919 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
10920 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
10922 struct dwarf_block blk
;
10925 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10927 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
10928 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
10929 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10930 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
10931 dwarf2_complex_location_expr_complaint ();
10933 fnp
->voffset
/= cu
->header
.addr_size
;
10937 dwarf2_complex_location_expr_complaint ();
10939 if (!fnp
->fcontext
)
10940 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
10942 else if (attr_form_is_section_offset (attr
))
10944 dwarf2_complex_location_expr_complaint ();
10948 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
10954 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10955 if (attr
&& DW_UNSND (attr
))
10957 /* GCC does this, as of 2008-08-25; PR debug/37237. */
10958 complaint (&symfile_complaints
,
10959 _("Member function \"%s\" (offset %d) is virtual "
10960 "but the vtable offset is not specified"),
10961 fieldname
, die
->offset
.sect_off
);
10962 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10963 TYPE_CPLUS_DYNAMIC (type
) = 1;
10968 /* Create the vector of member function fields, and attach it to the type. */
10971 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
10972 struct dwarf2_cu
*cu
)
10974 struct fnfieldlist
*flp
;
10977 if (cu
->language
== language_ada
)
10978 error (_("unexpected member functions in Ada type"));
10980 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10981 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
10982 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
10984 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
10986 struct nextfnfield
*nfp
= flp
->head
;
10987 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
10990 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
10991 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
10992 fn_flp
->fn_fields
= (struct fn_field
*)
10993 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
10994 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
10995 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
10998 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
11001 /* Returns non-zero if NAME is the name of a vtable member in CU's
11002 language, zero otherwise. */
11004 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
11006 static const char vptr
[] = "_vptr";
11007 static const char vtable
[] = "vtable";
11009 /* Look for the C++ and Java forms of the vtable. */
11010 if ((cu
->language
== language_java
11011 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
11012 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
11013 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
11019 /* GCC outputs unnamed structures that are really pointers to member
11020 functions, with the ABI-specified layout. If TYPE describes
11021 such a structure, smash it into a member function type.
11023 GCC shouldn't do this; it should just output pointer to member DIEs.
11024 This is GCC PR debug/28767. */
11027 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
11029 struct type
*pfn_type
, *domain_type
, *new_type
;
11031 /* Check for a structure with no name and two children. */
11032 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
11035 /* Check for __pfn and __delta members. */
11036 if (TYPE_FIELD_NAME (type
, 0) == NULL
11037 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
11038 || TYPE_FIELD_NAME (type
, 1) == NULL
11039 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
11042 /* Find the type of the method. */
11043 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
11044 if (pfn_type
== NULL
11045 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
11046 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
11049 /* Look for the "this" argument. */
11050 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
11051 if (TYPE_NFIELDS (pfn_type
) == 0
11052 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
11053 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
11056 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
11057 new_type
= alloc_type (objfile
);
11058 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
11059 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
11060 TYPE_VARARGS (pfn_type
));
11061 smash_to_methodptr_type (type
, new_type
);
11064 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
11068 producer_is_icc (struct dwarf2_cu
*cu
)
11070 if (!cu
->checked_producer
)
11071 check_producer (cu
);
11073 return cu
->producer_is_icc
;
11076 /* Called when we find the DIE that starts a structure or union scope
11077 (definition) to create a type for the structure or union. Fill in
11078 the type's name and general properties; the members will not be
11079 processed until process_structure_type.
11081 NOTE: we need to call these functions regardless of whether or not the
11082 DIE has a DW_AT_name attribute, since it might be an anonymous
11083 structure or union. This gets the type entered into our set of
11084 user defined types.
11086 However, if the structure is incomplete (an opaque struct/union)
11087 then suppress creating a symbol table entry for it since gdb only
11088 wants to find the one with the complete definition. Note that if
11089 it is complete, we just call new_symbol, which does it's own
11090 checking about whether the struct/union is anonymous or not (and
11091 suppresses creating a symbol table entry itself). */
11093 static struct type
*
11094 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11096 struct objfile
*objfile
= cu
->objfile
;
11098 struct attribute
*attr
;
11101 /* If the definition of this type lives in .debug_types, read that type.
11102 Don't follow DW_AT_specification though, that will take us back up
11103 the chain and we want to go down. */
11104 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11107 struct dwarf2_cu
*type_cu
= cu
;
11108 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11110 /* We could just recurse on read_structure_type, but we need to call
11111 get_die_type to ensure only one type for this DIE is created.
11112 This is important, for example, because for c++ classes we need
11113 TYPE_NAME set which is only done by new_symbol. Blech. */
11114 type
= read_type_die (type_die
, type_cu
);
11116 /* TYPE_CU may not be the same as CU.
11117 Ensure TYPE is recorded in CU's type_hash table. */
11118 return set_die_type (die
, type
, cu
);
11121 type
= alloc_type (objfile
);
11122 INIT_CPLUS_SPECIFIC (type
);
11124 name
= dwarf2_name (die
, cu
);
11127 if (cu
->language
== language_cplus
11128 || cu
->language
== language_java
)
11130 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
11132 /* dwarf2_full_name might have already finished building the DIE's
11133 type. If so, there is no need to continue. */
11134 if (get_die_type (die
, cu
) != NULL
)
11135 return get_die_type (die
, cu
);
11137 TYPE_TAG_NAME (type
) = full_name
;
11138 if (die
->tag
== DW_TAG_structure_type
11139 || die
->tag
== DW_TAG_class_type
)
11140 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11144 /* The name is already allocated along with this objfile, so
11145 we don't need to duplicate it for the type. */
11146 TYPE_TAG_NAME (type
) = (char *) name
;
11147 if (die
->tag
== DW_TAG_class_type
)
11148 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11152 if (die
->tag
== DW_TAG_structure_type
)
11154 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
11156 else if (die
->tag
== DW_TAG_union_type
)
11158 TYPE_CODE (type
) = TYPE_CODE_UNION
;
11162 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
11165 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
11166 TYPE_DECLARED_CLASS (type
) = 1;
11168 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11171 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11175 TYPE_LENGTH (type
) = 0;
11178 if (producer_is_icc (cu
))
11180 /* ICC does not output the required DW_AT_declaration
11181 on incomplete types, but gives them a size of zero. */
11184 TYPE_STUB_SUPPORTED (type
) = 1;
11186 if (die_is_declaration (die
, cu
))
11187 TYPE_STUB (type
) = 1;
11188 else if (attr
== NULL
&& die
->child
== NULL
11189 && producer_is_realview (cu
->producer
))
11190 /* RealView does not output the required DW_AT_declaration
11191 on incomplete types. */
11192 TYPE_STUB (type
) = 1;
11194 /* We need to add the type field to the die immediately so we don't
11195 infinitely recurse when dealing with pointers to the structure
11196 type within the structure itself. */
11197 set_die_type (die
, type
, cu
);
11199 /* set_die_type should be already done. */
11200 set_descriptive_type (type
, die
, cu
);
11205 /* Finish creating a structure or union type, including filling in
11206 its members and creating a symbol for it. */
11209 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11211 struct objfile
*objfile
= cu
->objfile
;
11212 struct die_info
*child_die
= die
->child
;
11215 type
= get_die_type (die
, cu
);
11217 type
= read_structure_type (die
, cu
);
11219 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
11221 struct field_info fi
;
11222 struct die_info
*child_die
;
11223 VEC (symbolp
) *template_args
= NULL
;
11224 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
11226 memset (&fi
, 0, sizeof (struct field_info
));
11228 child_die
= die
->child
;
11230 while (child_die
&& child_die
->tag
)
11232 if (child_die
->tag
== DW_TAG_member
11233 || child_die
->tag
== DW_TAG_variable
)
11235 /* NOTE: carlton/2002-11-05: A C++ static data member
11236 should be a DW_TAG_member that is a declaration, but
11237 all versions of G++ as of this writing (so through at
11238 least 3.2.1) incorrectly generate DW_TAG_variable
11239 tags for them instead. */
11240 dwarf2_add_field (&fi
, child_die
, cu
);
11242 else if (child_die
->tag
== DW_TAG_subprogram
)
11244 /* C++ member function. */
11245 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
11247 else if (child_die
->tag
== DW_TAG_inheritance
)
11249 /* C++ base class field. */
11250 dwarf2_add_field (&fi
, child_die
, cu
);
11252 else if (child_die
->tag
== DW_TAG_typedef
)
11253 dwarf2_add_typedef (&fi
, child_die
, cu
);
11254 else if (child_die
->tag
== DW_TAG_template_type_param
11255 || child_die
->tag
== DW_TAG_template_value_param
)
11257 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11260 VEC_safe_push (symbolp
, template_args
, arg
);
11263 child_die
= sibling_die (child_die
);
11266 /* Attach template arguments to type. */
11267 if (! VEC_empty (symbolp
, template_args
))
11269 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11270 TYPE_N_TEMPLATE_ARGUMENTS (type
)
11271 = VEC_length (symbolp
, template_args
);
11272 TYPE_TEMPLATE_ARGUMENTS (type
)
11273 = obstack_alloc (&objfile
->objfile_obstack
,
11274 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11275 * sizeof (struct symbol
*)));
11276 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
11277 VEC_address (symbolp
, template_args
),
11278 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11279 * sizeof (struct symbol
*)));
11280 VEC_free (symbolp
, template_args
);
11283 /* Attach fields and member functions to the type. */
11285 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
11288 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
11290 /* Get the type which refers to the base class (possibly this
11291 class itself) which contains the vtable pointer for the current
11292 class from the DW_AT_containing_type attribute. This use of
11293 DW_AT_containing_type is a GNU extension. */
11295 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
11297 struct type
*t
= die_containing_type (die
, cu
);
11299 TYPE_VPTR_BASETYPE (type
) = t
;
11304 /* Our own class provides vtbl ptr. */
11305 for (i
= TYPE_NFIELDS (t
) - 1;
11306 i
>= TYPE_N_BASECLASSES (t
);
11309 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
11311 if (is_vtable_name (fieldname
, cu
))
11313 TYPE_VPTR_FIELDNO (type
) = i
;
11318 /* Complain if virtual function table field not found. */
11319 if (i
< TYPE_N_BASECLASSES (t
))
11320 complaint (&symfile_complaints
,
11321 _("virtual function table pointer "
11322 "not found when defining class '%s'"),
11323 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
11328 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
11331 else if (cu
->producer
11332 && strncmp (cu
->producer
,
11333 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
11335 /* The IBM XLC compiler does not provide direct indication
11336 of the containing type, but the vtable pointer is
11337 always named __vfp. */
11341 for (i
= TYPE_NFIELDS (type
) - 1;
11342 i
>= TYPE_N_BASECLASSES (type
);
11345 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
11347 TYPE_VPTR_FIELDNO (type
) = i
;
11348 TYPE_VPTR_BASETYPE (type
) = type
;
11355 /* Copy fi.typedef_field_list linked list elements content into the
11356 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
11357 if (fi
.typedef_field_list
)
11359 int i
= fi
.typedef_field_list_count
;
11361 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11362 TYPE_TYPEDEF_FIELD_ARRAY (type
)
11363 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
11364 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
11366 /* Reverse the list order to keep the debug info elements order. */
11369 struct typedef_field
*dest
, *src
;
11371 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
11372 src
= &fi
.typedef_field_list
->field
;
11373 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
11378 do_cleanups (back_to
);
11380 if (HAVE_CPLUS_STRUCT (type
))
11381 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
11384 quirk_gcc_member_function_pointer (type
, objfile
);
11386 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
11387 snapshots) has been known to create a die giving a declaration
11388 for a class that has, as a child, a die giving a definition for a
11389 nested class. So we have to process our children even if the
11390 current die is a declaration. Normally, of course, a declaration
11391 won't have any children at all. */
11393 while (child_die
!= NULL
&& child_die
->tag
)
11395 if (child_die
->tag
== DW_TAG_member
11396 || child_die
->tag
== DW_TAG_variable
11397 || child_die
->tag
== DW_TAG_inheritance
11398 || child_die
->tag
== DW_TAG_template_value_param
11399 || child_die
->tag
== DW_TAG_template_type_param
)
11404 process_die (child_die
, cu
);
11406 child_die
= sibling_die (child_die
);
11409 /* Do not consider external references. According to the DWARF standard,
11410 these DIEs are identified by the fact that they have no byte_size
11411 attribute, and a declaration attribute. */
11412 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
11413 || !die_is_declaration (die
, cu
))
11414 new_symbol (die
, type
, cu
);
11417 /* Given a DW_AT_enumeration_type die, set its type. We do not
11418 complete the type's fields yet, or create any symbols. */
11420 static struct type
*
11421 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11423 struct objfile
*objfile
= cu
->objfile
;
11425 struct attribute
*attr
;
11428 /* If the definition of this type lives in .debug_types, read that type.
11429 Don't follow DW_AT_specification though, that will take us back up
11430 the chain and we want to go down. */
11431 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11434 struct dwarf2_cu
*type_cu
= cu
;
11435 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11437 type
= read_type_die (type_die
, type_cu
);
11439 /* TYPE_CU may not be the same as CU.
11440 Ensure TYPE is recorded in CU's type_hash table. */
11441 return set_die_type (die
, type
, cu
);
11444 type
= alloc_type (objfile
);
11446 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
11447 name
= dwarf2_full_name (NULL
, die
, cu
);
11449 TYPE_TAG_NAME (type
) = (char *) name
;
11451 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11454 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11458 TYPE_LENGTH (type
) = 0;
11461 /* The enumeration DIE can be incomplete. In Ada, any type can be
11462 declared as private in the package spec, and then defined only
11463 inside the package body. Such types are known as Taft Amendment
11464 Types. When another package uses such a type, an incomplete DIE
11465 may be generated by the compiler. */
11466 if (die_is_declaration (die
, cu
))
11467 TYPE_STUB (type
) = 1;
11469 return set_die_type (die
, type
, cu
);
11472 /* Given a pointer to a die which begins an enumeration, process all
11473 the dies that define the members of the enumeration, and create the
11474 symbol for the enumeration type.
11476 NOTE: We reverse the order of the element list. */
11479 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11481 struct type
*this_type
;
11483 this_type
= get_die_type (die
, cu
);
11484 if (this_type
== NULL
)
11485 this_type
= read_enumeration_type (die
, cu
);
11487 if (die
->child
!= NULL
)
11489 struct die_info
*child_die
;
11490 struct symbol
*sym
;
11491 struct field
*fields
= NULL
;
11492 int num_fields
= 0;
11493 int unsigned_enum
= 1;
11498 child_die
= die
->child
;
11499 while (child_die
&& child_die
->tag
)
11501 if (child_die
->tag
!= DW_TAG_enumerator
)
11503 process_die (child_die
, cu
);
11507 name
= dwarf2_name (child_die
, cu
);
11510 sym
= new_symbol (child_die
, this_type
, cu
);
11511 if (SYMBOL_VALUE (sym
) < 0)
11516 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
11519 mask
|= SYMBOL_VALUE (sym
);
11521 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
11523 fields
= (struct field
*)
11525 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
11526 * sizeof (struct field
));
11529 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
11530 FIELD_TYPE (fields
[num_fields
]) = NULL
;
11531 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
11532 FIELD_BITSIZE (fields
[num_fields
]) = 0;
11538 child_die
= sibling_die (child_die
);
11543 TYPE_NFIELDS (this_type
) = num_fields
;
11544 TYPE_FIELDS (this_type
) = (struct field
*)
11545 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
11546 memcpy (TYPE_FIELDS (this_type
), fields
,
11547 sizeof (struct field
) * num_fields
);
11551 TYPE_UNSIGNED (this_type
) = 1;
11553 TYPE_FLAG_ENUM (this_type
) = 1;
11556 /* If we are reading an enum from a .debug_types unit, and the enum
11557 is a declaration, and the enum is not the signatured type in the
11558 unit, then we do not want to add a symbol for it. Adding a
11559 symbol would in some cases obscure the true definition of the
11560 enum, giving users an incomplete type when the definition is
11561 actually available. Note that we do not want to do this for all
11562 enums which are just declarations, because C++0x allows forward
11563 enum declarations. */
11564 if (cu
->per_cu
->is_debug_types
11565 && die_is_declaration (die
, cu
))
11567 struct signatured_type
*sig_type
;
11570 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
11571 cu
->per_cu
->info_or_types_section
,
11572 cu
->per_cu
->offset
);
11573 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
11574 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
11578 new_symbol (die
, this_type
, cu
);
11581 /* Extract all information from a DW_TAG_array_type DIE and put it in
11582 the DIE's type field. For now, this only handles one dimensional
11585 static struct type
*
11586 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11588 struct objfile
*objfile
= cu
->objfile
;
11589 struct die_info
*child_die
;
11591 struct type
*element_type
, *range_type
, *index_type
;
11592 struct type
**range_types
= NULL
;
11593 struct attribute
*attr
;
11595 struct cleanup
*back_to
;
11598 element_type
= die_type (die
, cu
);
11600 /* The die_type call above may have already set the type for this DIE. */
11601 type
= get_die_type (die
, cu
);
11605 /* Irix 6.2 native cc creates array types without children for
11606 arrays with unspecified length. */
11607 if (die
->child
== NULL
)
11609 index_type
= objfile_type (objfile
)->builtin_int
;
11610 range_type
= create_range_type (NULL
, index_type
, 0, -1);
11611 type
= create_array_type (NULL
, element_type
, range_type
);
11612 return set_die_type (die
, type
, cu
);
11615 back_to
= make_cleanup (null_cleanup
, NULL
);
11616 child_die
= die
->child
;
11617 while (child_die
&& child_die
->tag
)
11619 if (child_die
->tag
== DW_TAG_subrange_type
)
11621 struct type
*child_type
= read_type_die (child_die
, cu
);
11623 if (child_type
!= NULL
)
11625 /* The range type was succesfully read. Save it for the
11626 array type creation. */
11627 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
11629 range_types
= (struct type
**)
11630 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
11631 * sizeof (struct type
*));
11633 make_cleanup (free_current_contents
, &range_types
);
11635 range_types
[ndim
++] = child_type
;
11638 child_die
= sibling_die (child_die
);
11641 /* Dwarf2 dimensions are output from left to right, create the
11642 necessary array types in backwards order. */
11644 type
= element_type
;
11646 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
11651 type
= create_array_type (NULL
, type
, range_types
[i
++]);
11656 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
11659 /* Understand Dwarf2 support for vector types (like they occur on
11660 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
11661 array type. This is not part of the Dwarf2/3 standard yet, but a
11662 custom vendor extension. The main difference between a regular
11663 array and the vector variant is that vectors are passed by value
11665 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
11667 make_vector_type (type
);
11669 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
11670 implementation may choose to implement triple vectors using this
11672 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11675 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
11676 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11678 complaint (&symfile_complaints
,
11679 _("DW_AT_byte_size for array type smaller "
11680 "than the total size of elements"));
11683 name
= dwarf2_name (die
, cu
);
11685 TYPE_NAME (type
) = name
;
11687 /* Install the type in the die. */
11688 set_die_type (die
, type
, cu
);
11690 /* set_die_type should be already done. */
11691 set_descriptive_type (type
, die
, cu
);
11693 do_cleanups (back_to
);
11698 static enum dwarf_array_dim_ordering
11699 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
11701 struct attribute
*attr
;
11703 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
11705 if (attr
) return DW_SND (attr
);
11707 /* GNU F77 is a special case, as at 08/2004 array type info is the
11708 opposite order to the dwarf2 specification, but data is still
11709 laid out as per normal fortran.
11711 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
11712 version checking. */
11714 if (cu
->language
== language_fortran
11715 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
11717 return DW_ORD_row_major
;
11720 switch (cu
->language_defn
->la_array_ordering
)
11722 case array_column_major
:
11723 return DW_ORD_col_major
;
11724 case array_row_major
:
11726 return DW_ORD_row_major
;
11730 /* Extract all information from a DW_TAG_set_type DIE and put it in
11731 the DIE's type field. */
11733 static struct type
*
11734 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11736 struct type
*domain_type
, *set_type
;
11737 struct attribute
*attr
;
11739 domain_type
= die_type (die
, cu
);
11741 /* The die_type call above may have already set the type for this DIE. */
11742 set_type
= get_die_type (die
, cu
);
11746 set_type
= create_set_type (NULL
, domain_type
);
11748 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11750 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
11752 return set_die_type (die
, set_type
, cu
);
11755 /* A helper for read_common_block that creates a locexpr baton.
11756 SYM is the symbol which we are marking as computed.
11757 COMMON_DIE is the DIE for the common block.
11758 COMMON_LOC is the location expression attribute for the common
11760 MEMBER_LOC is the location expression attribute for the particular
11761 member of the common block that we are processing.
11762 CU is the CU from which the above come. */
11765 mark_common_block_symbol_computed (struct symbol
*sym
,
11766 struct die_info
*common_die
,
11767 struct attribute
*common_loc
,
11768 struct attribute
*member_loc
,
11769 struct dwarf2_cu
*cu
)
11771 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11772 struct dwarf2_locexpr_baton
*baton
;
11774 unsigned int cu_off
;
11775 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
11776 LONGEST offset
= 0;
11778 gdb_assert (common_loc
&& member_loc
);
11779 gdb_assert (attr_form_is_block (common_loc
));
11780 gdb_assert (attr_form_is_block (member_loc
)
11781 || attr_form_is_constant (member_loc
));
11783 baton
= obstack_alloc (&objfile
->objfile_obstack
,
11784 sizeof (struct dwarf2_locexpr_baton
));
11785 baton
->per_cu
= cu
->per_cu
;
11786 gdb_assert (baton
->per_cu
);
11788 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
11790 if (attr_form_is_constant (member_loc
))
11792 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
11793 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
11796 baton
->size
+= DW_BLOCK (member_loc
)->size
;
11798 ptr
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
11801 *ptr
++ = DW_OP_call4
;
11802 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
11803 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
11806 if (attr_form_is_constant (member_loc
))
11808 *ptr
++ = DW_OP_addr
;
11809 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
11810 ptr
+= cu
->header
.addr_size
;
11814 /* We have to copy the data here, because DW_OP_call4 will only
11815 use a DW_AT_location attribute. */
11816 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
11817 ptr
+= DW_BLOCK (member_loc
)->size
;
11820 *ptr
++ = DW_OP_plus
;
11821 gdb_assert (ptr
- baton
->data
== baton
->size
);
11823 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11824 SYMBOL_LOCATION_BATON (sym
) = baton
;
11825 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11828 /* Create appropriate locally-scoped variables for all the
11829 DW_TAG_common_block entries. Also create a struct common_block
11830 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
11831 is used to sepate the common blocks name namespace from regular
11835 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
11837 struct attribute
*attr
;
11839 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11842 /* Support the .debug_loc offsets. */
11843 if (attr_form_is_block (attr
))
11847 else if (attr_form_is_section_offset (attr
))
11849 dwarf2_complex_location_expr_complaint ();
11854 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11855 "common block member");
11860 if (die
->child
!= NULL
)
11862 struct objfile
*objfile
= cu
->objfile
;
11863 struct die_info
*child_die
;
11864 size_t n_entries
= 0, size
;
11865 struct common_block
*common_block
;
11866 struct symbol
*sym
;
11868 for (child_die
= die
->child
;
11869 child_die
&& child_die
->tag
;
11870 child_die
= sibling_die (child_die
))
11873 size
= (sizeof (struct common_block
)
11874 + (n_entries
- 1) * sizeof (struct symbol
*));
11875 common_block
= obstack_alloc (&objfile
->objfile_obstack
, size
);
11876 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
11877 common_block
->n_entries
= 0;
11879 for (child_die
= die
->child
;
11880 child_die
&& child_die
->tag
;
11881 child_die
= sibling_die (child_die
))
11883 /* Create the symbol in the DW_TAG_common_block block in the current
11885 sym
= new_symbol (child_die
, NULL
, cu
);
11888 struct attribute
*member_loc
;
11890 common_block
->contents
[common_block
->n_entries
++] = sym
;
11892 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
11896 /* GDB has handled this for a long time, but it is
11897 not specified by DWARF. It seems to have been
11898 emitted by gfortran at least as recently as:
11899 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
11900 complaint (&symfile_complaints
,
11901 _("Variable in common block has "
11902 "DW_AT_data_member_location "
11903 "- DIE at 0x%x [in module %s]"),
11904 child_die
->offset
.sect_off
, cu
->objfile
->name
);
11906 if (attr_form_is_section_offset (member_loc
))
11907 dwarf2_complex_location_expr_complaint ();
11908 else if (attr_form_is_constant (member_loc
)
11909 || attr_form_is_block (member_loc
))
11912 mark_common_block_symbol_computed (sym
, die
, attr
,
11916 dwarf2_complex_location_expr_complaint ();
11921 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
11922 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
11926 /* Create a type for a C++ namespace. */
11928 static struct type
*
11929 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11931 struct objfile
*objfile
= cu
->objfile
;
11932 const char *previous_prefix
, *name
;
11936 /* For extensions, reuse the type of the original namespace. */
11937 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
11939 struct die_info
*ext_die
;
11940 struct dwarf2_cu
*ext_cu
= cu
;
11942 ext_die
= dwarf2_extension (die
, &ext_cu
);
11943 type
= read_type_die (ext_die
, ext_cu
);
11945 /* EXT_CU may not be the same as CU.
11946 Ensure TYPE is recorded in CU's type_hash table. */
11947 return set_die_type (die
, type
, cu
);
11950 name
= namespace_name (die
, &is_anonymous
, cu
);
11952 /* Now build the name of the current namespace. */
11954 previous_prefix
= determine_prefix (die
, cu
);
11955 if (previous_prefix
[0] != '\0')
11956 name
= typename_concat (&objfile
->objfile_obstack
,
11957 previous_prefix
, name
, 0, cu
);
11959 /* Create the type. */
11960 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
11962 TYPE_NAME (type
) = (char *) name
;
11963 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
11965 return set_die_type (die
, type
, cu
);
11968 /* Read a C++ namespace. */
11971 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
11973 struct objfile
*objfile
= cu
->objfile
;
11976 /* Add a symbol associated to this if we haven't seen the namespace
11977 before. Also, add a using directive if it's an anonymous
11980 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
11984 type
= read_type_die (die
, cu
);
11985 new_symbol (die
, type
, cu
);
11987 namespace_name (die
, &is_anonymous
, cu
);
11990 const char *previous_prefix
= determine_prefix (die
, cu
);
11992 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
11993 NULL
, NULL
, &objfile
->objfile_obstack
);
11997 if (die
->child
!= NULL
)
11999 struct die_info
*child_die
= die
->child
;
12001 while (child_die
&& child_die
->tag
)
12003 process_die (child_die
, cu
);
12004 child_die
= sibling_die (child_die
);
12009 /* Read a Fortran module as type. This DIE can be only a declaration used for
12010 imported module. Still we need that type as local Fortran "use ... only"
12011 declaration imports depend on the created type in determine_prefix. */
12013 static struct type
*
12014 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12016 struct objfile
*objfile
= cu
->objfile
;
12020 module_name
= dwarf2_name (die
, cu
);
12022 complaint (&symfile_complaints
,
12023 _("DW_TAG_module has no name, offset 0x%x"),
12024 die
->offset
.sect_off
);
12025 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
12027 /* determine_prefix uses TYPE_TAG_NAME. */
12028 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
12030 return set_die_type (die
, type
, cu
);
12033 /* Read a Fortran module. */
12036 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
12038 struct die_info
*child_die
= die
->child
;
12040 while (child_die
&& child_die
->tag
)
12042 process_die (child_die
, cu
);
12043 child_die
= sibling_die (child_die
);
12047 /* Return the name of the namespace represented by DIE. Set
12048 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
12051 static const char *
12052 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
12054 struct die_info
*current_die
;
12055 const char *name
= NULL
;
12057 /* Loop through the extensions until we find a name. */
12059 for (current_die
= die
;
12060 current_die
!= NULL
;
12061 current_die
= dwarf2_extension (die
, &cu
))
12063 name
= dwarf2_name (current_die
, cu
);
12068 /* Is it an anonymous namespace? */
12070 *is_anonymous
= (name
== NULL
);
12072 name
= CP_ANONYMOUS_NAMESPACE_STR
;
12077 /* Extract all information from a DW_TAG_pointer_type DIE and add to
12078 the user defined type vector. */
12080 static struct type
*
12081 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12083 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
12084 struct comp_unit_head
*cu_header
= &cu
->header
;
12086 struct attribute
*attr_byte_size
;
12087 struct attribute
*attr_address_class
;
12088 int byte_size
, addr_class
;
12089 struct type
*target_type
;
12091 target_type
= die_type (die
, cu
);
12093 /* The die_type call above may have already set the type for this DIE. */
12094 type
= get_die_type (die
, cu
);
12098 type
= lookup_pointer_type (target_type
);
12100 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12101 if (attr_byte_size
)
12102 byte_size
= DW_UNSND (attr_byte_size
);
12104 byte_size
= cu_header
->addr_size
;
12106 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
12107 if (attr_address_class
)
12108 addr_class
= DW_UNSND (attr_address_class
);
12110 addr_class
= DW_ADDR_none
;
12112 /* If the pointer size or address class is different than the
12113 default, create a type variant marked as such and set the
12114 length accordingly. */
12115 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
12117 if (gdbarch_address_class_type_flags_p (gdbarch
))
12121 type_flags
= gdbarch_address_class_type_flags
12122 (gdbarch
, byte_size
, addr_class
);
12123 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
12125 type
= make_type_with_address_space (type
, type_flags
);
12127 else if (TYPE_LENGTH (type
) != byte_size
)
12129 complaint (&symfile_complaints
,
12130 _("invalid pointer size %d"), byte_size
);
12134 /* Should we also complain about unhandled address classes? */
12138 TYPE_LENGTH (type
) = byte_size
;
12139 return set_die_type (die
, type
, cu
);
12142 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
12143 the user defined type vector. */
12145 static struct type
*
12146 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12149 struct type
*to_type
;
12150 struct type
*domain
;
12152 to_type
= die_type (die
, cu
);
12153 domain
= die_containing_type (die
, cu
);
12155 /* The calls above may have already set the type for this DIE. */
12156 type
= get_die_type (die
, cu
);
12160 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
12161 type
= lookup_methodptr_type (to_type
);
12163 type
= lookup_memberptr_type (to_type
, domain
);
12165 return set_die_type (die
, type
, cu
);
12168 /* Extract all information from a DW_TAG_reference_type DIE and add to
12169 the user defined type vector. */
12171 static struct type
*
12172 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12174 struct comp_unit_head
*cu_header
= &cu
->header
;
12175 struct type
*type
, *target_type
;
12176 struct attribute
*attr
;
12178 target_type
= die_type (die
, cu
);
12180 /* The die_type call above may have already set the type for this DIE. */
12181 type
= get_die_type (die
, cu
);
12185 type
= lookup_reference_type (target_type
);
12186 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12189 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12193 TYPE_LENGTH (type
) = cu_header
->addr_size
;
12195 return set_die_type (die
, type
, cu
);
12198 static struct type
*
12199 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12201 struct type
*base_type
, *cv_type
;
12203 base_type
= die_type (die
, cu
);
12205 /* The die_type call above may have already set the type for this DIE. */
12206 cv_type
= get_die_type (die
, cu
);
12210 /* In case the const qualifier is applied to an array type, the element type
12211 is so qualified, not the array type (section 6.7.3 of C99). */
12212 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
12214 struct type
*el_type
, *inner_array
;
12216 base_type
= copy_type (base_type
);
12217 inner_array
= base_type
;
12219 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
12221 TYPE_TARGET_TYPE (inner_array
) =
12222 copy_type (TYPE_TARGET_TYPE (inner_array
));
12223 inner_array
= TYPE_TARGET_TYPE (inner_array
);
12226 el_type
= TYPE_TARGET_TYPE (inner_array
);
12227 TYPE_TARGET_TYPE (inner_array
) =
12228 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
12230 return set_die_type (die
, base_type
, cu
);
12233 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
12234 return set_die_type (die
, cv_type
, cu
);
12237 static struct type
*
12238 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12240 struct type
*base_type
, *cv_type
;
12242 base_type
= die_type (die
, cu
);
12244 /* The die_type call above may have already set the type for this DIE. */
12245 cv_type
= get_die_type (die
, cu
);
12249 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
12250 return set_die_type (die
, cv_type
, cu
);
12253 /* Extract all information from a DW_TAG_string_type DIE and add to
12254 the user defined type vector. It isn't really a user defined type,
12255 but it behaves like one, with other DIE's using an AT_user_def_type
12256 attribute to reference it. */
12258 static struct type
*
12259 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12261 struct objfile
*objfile
= cu
->objfile
;
12262 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12263 struct type
*type
, *range_type
, *index_type
, *char_type
;
12264 struct attribute
*attr
;
12265 unsigned int length
;
12267 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
12270 length
= DW_UNSND (attr
);
12274 /* Check for the DW_AT_byte_size attribute. */
12275 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12278 length
= DW_UNSND (attr
);
12286 index_type
= objfile_type (objfile
)->builtin_int
;
12287 range_type
= create_range_type (NULL
, index_type
, 1, length
);
12288 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
12289 type
= create_string_type (NULL
, char_type
, range_type
);
12291 return set_die_type (die
, type
, cu
);
12294 /* Handle DIES due to C code like:
12298 int (*funcp)(int a, long l);
12302 ('funcp' generates a DW_TAG_subroutine_type DIE). */
12304 static struct type
*
12305 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12307 struct objfile
*objfile
= cu
->objfile
;
12308 struct type
*type
; /* Type that this function returns. */
12309 struct type
*ftype
; /* Function that returns above type. */
12310 struct attribute
*attr
;
12312 type
= die_type (die
, cu
);
12314 /* The die_type call above may have already set the type for this DIE. */
12315 ftype
= get_die_type (die
, cu
);
12319 ftype
= lookup_function_type (type
);
12321 /* All functions in C++, Pascal and Java have prototypes. */
12322 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
12323 if ((attr
&& (DW_UNSND (attr
) != 0))
12324 || cu
->language
== language_cplus
12325 || cu
->language
== language_java
12326 || cu
->language
== language_pascal
)
12327 TYPE_PROTOTYPED (ftype
) = 1;
12328 else if (producer_is_realview (cu
->producer
))
12329 /* RealView does not emit DW_AT_prototyped. We can not
12330 distinguish prototyped and unprototyped functions; default to
12331 prototyped, since that is more common in modern code (and
12332 RealView warns about unprototyped functions). */
12333 TYPE_PROTOTYPED (ftype
) = 1;
12335 /* Store the calling convention in the type if it's available in
12336 the subroutine die. Otherwise set the calling convention to
12337 the default value DW_CC_normal. */
12338 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
12340 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
12341 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
12342 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
12344 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
12346 /* We need to add the subroutine type to the die immediately so
12347 we don't infinitely recurse when dealing with parameters
12348 declared as the same subroutine type. */
12349 set_die_type (die
, ftype
, cu
);
12351 if (die
->child
!= NULL
)
12353 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
12354 struct die_info
*child_die
;
12355 int nparams
, iparams
;
12357 /* Count the number of parameters.
12358 FIXME: GDB currently ignores vararg functions, but knows about
12359 vararg member functions. */
12361 child_die
= die
->child
;
12362 while (child_die
&& child_die
->tag
)
12364 if (child_die
->tag
== DW_TAG_formal_parameter
)
12366 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
12367 TYPE_VARARGS (ftype
) = 1;
12368 child_die
= sibling_die (child_die
);
12371 /* Allocate storage for parameters and fill them in. */
12372 TYPE_NFIELDS (ftype
) = nparams
;
12373 TYPE_FIELDS (ftype
) = (struct field
*)
12374 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
12376 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
12377 even if we error out during the parameters reading below. */
12378 for (iparams
= 0; iparams
< nparams
; iparams
++)
12379 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
12382 child_die
= die
->child
;
12383 while (child_die
&& child_die
->tag
)
12385 if (child_die
->tag
== DW_TAG_formal_parameter
)
12387 struct type
*arg_type
;
12389 /* DWARF version 2 has no clean way to discern C++
12390 static and non-static member functions. G++ helps
12391 GDB by marking the first parameter for non-static
12392 member functions (which is the this pointer) as
12393 artificial. We pass this information to
12394 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
12396 DWARF version 3 added DW_AT_object_pointer, which GCC
12397 4.5 does not yet generate. */
12398 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
12400 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
12403 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
12405 /* GCC/43521: In java, the formal parameter
12406 "this" is sometimes not marked with DW_AT_artificial. */
12407 if (cu
->language
== language_java
)
12409 const char *name
= dwarf2_name (child_die
, cu
);
12411 if (name
&& !strcmp (name
, "this"))
12412 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
12415 arg_type
= die_type (child_die
, cu
);
12417 /* RealView does not mark THIS as const, which the testsuite
12418 expects. GCC marks THIS as const in method definitions,
12419 but not in the class specifications (GCC PR 43053). */
12420 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
12421 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
12424 struct dwarf2_cu
*arg_cu
= cu
;
12425 const char *name
= dwarf2_name (child_die
, cu
);
12427 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
12430 /* If the compiler emits this, use it. */
12431 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
12434 else if (name
&& strcmp (name
, "this") == 0)
12435 /* Function definitions will have the argument names. */
12437 else if (name
== NULL
&& iparams
== 0)
12438 /* Declarations may not have the names, so like
12439 elsewhere in GDB, assume an artificial first
12440 argument is "this". */
12444 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
12448 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
12451 child_die
= sibling_die (child_die
);
12458 static struct type
*
12459 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
12461 struct objfile
*objfile
= cu
->objfile
;
12462 const char *name
= NULL
;
12463 struct type
*this_type
, *target_type
;
12465 name
= dwarf2_full_name (NULL
, die
, cu
);
12466 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
12467 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
12468 TYPE_NAME (this_type
) = (char *) name
;
12469 set_die_type (die
, this_type
, cu
);
12470 target_type
= die_type (die
, cu
);
12471 if (target_type
!= this_type
)
12472 TYPE_TARGET_TYPE (this_type
) = target_type
;
12475 /* Self-referential typedefs are, it seems, not allowed by the DWARF
12476 spec and cause infinite loops in GDB. */
12477 complaint (&symfile_complaints
,
12478 _("Self-referential DW_TAG_typedef "
12479 "- DIE at 0x%x [in module %s]"),
12480 die
->offset
.sect_off
, objfile
->name
);
12481 TYPE_TARGET_TYPE (this_type
) = NULL
;
12486 /* Find a representation of a given base type and install
12487 it in the TYPE field of the die. */
12489 static struct type
*
12490 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12492 struct objfile
*objfile
= cu
->objfile
;
12494 struct attribute
*attr
;
12495 int encoding
= 0, size
= 0;
12497 enum type_code code
= TYPE_CODE_INT
;
12498 int type_flags
= 0;
12499 struct type
*target_type
= NULL
;
12501 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
12504 encoding
= DW_UNSND (attr
);
12506 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12509 size
= DW_UNSND (attr
);
12511 name
= dwarf2_name (die
, cu
);
12514 complaint (&symfile_complaints
,
12515 _("DW_AT_name missing from DW_TAG_base_type"));
12520 case DW_ATE_address
:
12521 /* Turn DW_ATE_address into a void * pointer. */
12522 code
= TYPE_CODE_PTR
;
12523 type_flags
|= TYPE_FLAG_UNSIGNED
;
12524 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
12526 case DW_ATE_boolean
:
12527 code
= TYPE_CODE_BOOL
;
12528 type_flags
|= TYPE_FLAG_UNSIGNED
;
12530 case DW_ATE_complex_float
:
12531 code
= TYPE_CODE_COMPLEX
;
12532 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
12534 case DW_ATE_decimal_float
:
12535 code
= TYPE_CODE_DECFLOAT
;
12538 code
= TYPE_CODE_FLT
;
12540 case DW_ATE_signed
:
12542 case DW_ATE_unsigned
:
12543 type_flags
|= TYPE_FLAG_UNSIGNED
;
12544 if (cu
->language
== language_fortran
12546 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
12547 code
= TYPE_CODE_CHAR
;
12549 case DW_ATE_signed_char
:
12550 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12551 || cu
->language
== language_pascal
12552 || cu
->language
== language_fortran
)
12553 code
= TYPE_CODE_CHAR
;
12555 case DW_ATE_unsigned_char
:
12556 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12557 || cu
->language
== language_pascal
12558 || cu
->language
== language_fortran
)
12559 code
= TYPE_CODE_CHAR
;
12560 type_flags
|= TYPE_FLAG_UNSIGNED
;
12563 /* We just treat this as an integer and then recognize the
12564 type by name elsewhere. */
12568 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
12569 dwarf_type_encoding_name (encoding
));
12573 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
12574 TYPE_NAME (type
) = name
;
12575 TYPE_TARGET_TYPE (type
) = target_type
;
12577 if (name
&& strcmp (name
, "char") == 0)
12578 TYPE_NOSIGN (type
) = 1;
12580 return set_die_type (die
, type
, cu
);
12583 /* Read the given DW_AT_subrange DIE. */
12585 static struct type
*
12586 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12588 struct type
*base_type
;
12589 struct type
*range_type
;
12590 struct attribute
*attr
;
12592 int low_default_is_valid
;
12594 LONGEST negative_mask
;
12596 base_type
= die_type (die
, cu
);
12597 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
12598 check_typedef (base_type
);
12600 /* The die_type call above may have already set the type for this DIE. */
12601 range_type
= get_die_type (die
, cu
);
12605 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
12606 omitting DW_AT_lower_bound. */
12607 switch (cu
->language
)
12610 case language_cplus
:
12612 low_default_is_valid
= 1;
12614 case language_fortran
:
12616 low_default_is_valid
= 1;
12619 case language_java
:
12620 case language_objc
:
12622 low_default_is_valid
= (cu
->header
.version
>= 4);
12626 case language_pascal
:
12628 low_default_is_valid
= (cu
->header
.version
>= 4);
12632 low_default_is_valid
= 0;
12636 /* FIXME: For variable sized arrays either of these could be
12637 a variable rather than a constant value. We'll allow it,
12638 but we don't know how to handle it. */
12639 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
12641 low
= dwarf2_get_attr_constant_value (attr
, low
);
12642 else if (!low_default_is_valid
)
12643 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
12644 "- DIE at 0x%x [in module %s]"),
12645 die
->offset
.sect_off
, cu
->objfile
->name
);
12647 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
12650 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
12652 /* GCC encodes arrays with unspecified or dynamic length
12653 with a DW_FORM_block1 attribute or a reference attribute.
12654 FIXME: GDB does not yet know how to handle dynamic
12655 arrays properly, treat them as arrays with unspecified
12658 FIXME: jimb/2003-09-22: GDB does not really know
12659 how to handle arrays of unspecified length
12660 either; we just represent them as zero-length
12661 arrays. Choose an appropriate upper bound given
12662 the lower bound we've computed above. */
12666 high
= dwarf2_get_attr_constant_value (attr
, 1);
12670 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
12673 int count
= dwarf2_get_attr_constant_value (attr
, 1);
12674 high
= low
+ count
- 1;
12678 /* Unspecified array length. */
12683 /* Dwarf-2 specifications explicitly allows to create subrange types
12684 without specifying a base type.
12685 In that case, the base type must be set to the type of
12686 the lower bound, upper bound or count, in that order, if any of these
12687 three attributes references an object that has a type.
12688 If no base type is found, the Dwarf-2 specifications say that
12689 a signed integer type of size equal to the size of an address should
12691 For the following C code: `extern char gdb_int [];'
12692 GCC produces an empty range DIE.
12693 FIXME: muller/2010-05-28: Possible references to object for low bound,
12694 high bound or count are not yet handled by this code. */
12695 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
12697 struct objfile
*objfile
= cu
->objfile
;
12698 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12699 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
12700 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
12702 /* Test "int", "long int", and "long long int" objfile types,
12703 and select the first one having a size above or equal to the
12704 architecture address size. */
12705 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12706 base_type
= int_type
;
12709 int_type
= objfile_type (objfile
)->builtin_long
;
12710 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12711 base_type
= int_type
;
12714 int_type
= objfile_type (objfile
)->builtin_long_long
;
12715 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12716 base_type
= int_type
;
12722 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
12723 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
12724 low
|= negative_mask
;
12725 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
12726 high
|= negative_mask
;
12728 range_type
= create_range_type (NULL
, base_type
, low
, high
);
12730 /* Mark arrays with dynamic length at least as an array of unspecified
12731 length. GDB could check the boundary but before it gets implemented at
12732 least allow accessing the array elements. */
12733 if (attr
&& attr_form_is_block (attr
))
12734 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12736 /* Ada expects an empty array on no boundary attributes. */
12737 if (attr
== NULL
&& cu
->language
!= language_ada
)
12738 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12740 name
= dwarf2_name (die
, cu
);
12742 TYPE_NAME (range_type
) = name
;
12744 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12746 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
12748 set_die_type (die
, range_type
, cu
);
12750 /* set_die_type should be already done. */
12751 set_descriptive_type (range_type
, die
, cu
);
12756 static struct type
*
12757 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12761 /* For now, we only support the C meaning of an unspecified type: void. */
12763 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
12764 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
12766 return set_die_type (die
, type
, cu
);
12769 /* Read a single die and all its descendents. Set the die's sibling
12770 field to NULL; set other fields in the die correctly, and set all
12771 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
12772 location of the info_ptr after reading all of those dies. PARENT
12773 is the parent of the die in question. */
12775 static struct die_info
*
12776 read_die_and_children (const struct die_reader_specs
*reader
,
12777 gdb_byte
*info_ptr
,
12778 gdb_byte
**new_info_ptr
,
12779 struct die_info
*parent
)
12781 struct die_info
*die
;
12785 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
12788 *new_info_ptr
= cur_ptr
;
12791 store_in_ref_table (die
, reader
->cu
);
12794 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
12798 *new_info_ptr
= cur_ptr
;
12801 die
->sibling
= NULL
;
12802 die
->parent
= parent
;
12806 /* Read a die, all of its descendents, and all of its siblings; set
12807 all of the fields of all of the dies correctly. Arguments are as
12808 in read_die_and_children. */
12810 static struct die_info
*
12811 read_die_and_siblings (const struct die_reader_specs
*reader
,
12812 gdb_byte
*info_ptr
,
12813 gdb_byte
**new_info_ptr
,
12814 struct die_info
*parent
)
12816 struct die_info
*first_die
, *last_sibling
;
12819 cur_ptr
= info_ptr
;
12820 first_die
= last_sibling
= NULL
;
12824 struct die_info
*die
12825 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
12829 *new_info_ptr
= cur_ptr
;
12836 last_sibling
->sibling
= die
;
12838 last_sibling
= die
;
12842 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
12844 The caller is responsible for filling in the extra attributes
12845 and updating (*DIEP)->num_attrs.
12846 Set DIEP to point to a newly allocated die with its information,
12847 except for its child, sibling, and parent fields.
12848 Set HAS_CHILDREN to tell whether the die has children or not. */
12851 read_full_die_1 (const struct die_reader_specs
*reader
,
12852 struct die_info
**diep
, gdb_byte
*info_ptr
,
12853 int *has_children
, int num_extra_attrs
)
12855 unsigned int abbrev_number
, bytes_read
, i
;
12856 sect_offset offset
;
12857 struct abbrev_info
*abbrev
;
12858 struct die_info
*die
;
12859 struct dwarf2_cu
*cu
= reader
->cu
;
12860 bfd
*abfd
= reader
->abfd
;
12862 offset
.sect_off
= info_ptr
- reader
->buffer
;
12863 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12864 info_ptr
+= bytes_read
;
12865 if (!abbrev_number
)
12872 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
12874 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
12876 bfd_get_filename (abfd
));
12878 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
12879 die
->offset
= offset
;
12880 die
->tag
= abbrev
->tag
;
12881 die
->abbrev
= abbrev_number
;
12883 /* Make the result usable.
12884 The caller needs to update num_attrs after adding the extra
12886 die
->num_attrs
= abbrev
->num_attrs
;
12888 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12889 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
12893 *has_children
= abbrev
->has_children
;
12897 /* Read a die and all its attributes.
12898 Set DIEP to point to a newly allocated die with its information,
12899 except for its child, sibling, and parent fields.
12900 Set HAS_CHILDREN to tell whether the die has children or not. */
12903 read_full_die (const struct die_reader_specs
*reader
,
12904 struct die_info
**diep
, gdb_byte
*info_ptr
,
12907 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
12910 /* Abbreviation tables.
12912 In DWARF version 2, the description of the debugging information is
12913 stored in a separate .debug_abbrev section. Before we read any
12914 dies from a section we read in all abbreviations and install them
12915 in a hash table. */
12917 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
12919 static struct abbrev_info
*
12920 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
12922 struct abbrev_info
*abbrev
;
12924 abbrev
= (struct abbrev_info
*)
12925 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
12926 memset (abbrev
, 0, sizeof (struct abbrev_info
));
12930 /* Add an abbreviation to the table. */
12933 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
12934 unsigned int abbrev_number
,
12935 struct abbrev_info
*abbrev
)
12937 unsigned int hash_number
;
12939 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
12940 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
12941 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
12944 /* Look up an abbrev in the table.
12945 Returns NULL if the abbrev is not found. */
12947 static struct abbrev_info
*
12948 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
12949 unsigned int abbrev_number
)
12951 unsigned int hash_number
;
12952 struct abbrev_info
*abbrev
;
12954 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
12955 abbrev
= abbrev_table
->abbrevs
[hash_number
];
12959 if (abbrev
->number
== abbrev_number
)
12961 abbrev
= abbrev
->next
;
12966 /* Read in an abbrev table. */
12968 static struct abbrev_table
*
12969 abbrev_table_read_table (struct dwarf2_section_info
*section
,
12970 sect_offset offset
)
12972 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12973 bfd
*abfd
= section
->asection
->owner
;
12974 struct abbrev_table
*abbrev_table
;
12975 gdb_byte
*abbrev_ptr
;
12976 struct abbrev_info
*cur_abbrev
;
12977 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
12978 unsigned int abbrev_form
;
12979 struct attr_abbrev
*cur_attrs
;
12980 unsigned int allocated_attrs
;
12982 abbrev_table
= XMALLOC (struct abbrev_table
);
12983 abbrev_table
->offset
= offset
;
12984 obstack_init (&abbrev_table
->abbrev_obstack
);
12985 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12987 * sizeof (struct abbrev_info
*)));
12988 memset (abbrev_table
->abbrevs
, 0,
12989 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
12991 dwarf2_read_section (objfile
, section
);
12992 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
12993 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12994 abbrev_ptr
+= bytes_read
;
12996 allocated_attrs
= ATTR_ALLOC_CHUNK
;
12997 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
12999 /* Loop until we reach an abbrev number of 0. */
13000 while (abbrev_number
)
13002 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
13004 /* read in abbrev header */
13005 cur_abbrev
->number
= abbrev_number
;
13006 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13007 abbrev_ptr
+= bytes_read
;
13008 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
13011 /* now read in declarations */
13012 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13013 abbrev_ptr
+= bytes_read
;
13014 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13015 abbrev_ptr
+= bytes_read
;
13016 while (abbrev_name
)
13018 if (cur_abbrev
->num_attrs
== allocated_attrs
)
13020 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
13022 = xrealloc (cur_attrs
, (allocated_attrs
13023 * sizeof (struct attr_abbrev
)));
13026 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
13027 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
13028 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13029 abbrev_ptr
+= bytes_read
;
13030 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13031 abbrev_ptr
+= bytes_read
;
13034 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13035 (cur_abbrev
->num_attrs
13036 * sizeof (struct attr_abbrev
)));
13037 memcpy (cur_abbrev
->attrs
, cur_attrs
,
13038 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
13040 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
13042 /* Get next abbreviation.
13043 Under Irix6 the abbreviations for a compilation unit are not
13044 always properly terminated with an abbrev number of 0.
13045 Exit loop if we encounter an abbreviation which we have
13046 already read (which means we are about to read the abbreviations
13047 for the next compile unit) or if the end of the abbreviation
13048 table is reached. */
13049 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
13051 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13052 abbrev_ptr
+= bytes_read
;
13053 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
13058 return abbrev_table
;
13061 /* Free the resources held by ABBREV_TABLE. */
13064 abbrev_table_free (struct abbrev_table
*abbrev_table
)
13066 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
13067 xfree (abbrev_table
);
13070 /* Same as abbrev_table_free but as a cleanup.
13071 We pass in a pointer to the pointer to the table so that we can
13072 set the pointer to NULL when we're done. It also simplifies
13073 build_type_unit_groups. */
13076 abbrev_table_free_cleanup (void *table_ptr
)
13078 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
13080 if (*abbrev_table_ptr
!= NULL
)
13081 abbrev_table_free (*abbrev_table_ptr
);
13082 *abbrev_table_ptr
= NULL
;
13085 /* Read the abbrev table for CU from ABBREV_SECTION. */
13088 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
13089 struct dwarf2_section_info
*abbrev_section
)
13092 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
13095 /* Release the memory used by the abbrev table for a compilation unit. */
13098 dwarf2_free_abbrev_table (void *ptr_to_cu
)
13100 struct dwarf2_cu
*cu
= ptr_to_cu
;
13102 abbrev_table_free (cu
->abbrev_table
);
13103 /* Set this to NULL so that we SEGV if we try to read it later,
13104 and also because free_comp_unit verifies this is NULL. */
13105 cu
->abbrev_table
= NULL
;
13108 /* Returns nonzero if TAG represents a type that we might generate a partial
13112 is_type_tag_for_partial (int tag
)
13117 /* Some types that would be reasonable to generate partial symbols for,
13118 that we don't at present. */
13119 case DW_TAG_array_type
:
13120 case DW_TAG_file_type
:
13121 case DW_TAG_ptr_to_member_type
:
13122 case DW_TAG_set_type
:
13123 case DW_TAG_string_type
:
13124 case DW_TAG_subroutine_type
:
13126 case DW_TAG_base_type
:
13127 case DW_TAG_class_type
:
13128 case DW_TAG_interface_type
:
13129 case DW_TAG_enumeration_type
:
13130 case DW_TAG_structure_type
:
13131 case DW_TAG_subrange_type
:
13132 case DW_TAG_typedef
:
13133 case DW_TAG_union_type
:
13140 /* Load all DIEs that are interesting for partial symbols into memory. */
13142 static struct partial_die_info
*
13143 load_partial_dies (const struct die_reader_specs
*reader
,
13144 gdb_byte
*info_ptr
, int building_psymtab
)
13146 struct dwarf2_cu
*cu
= reader
->cu
;
13147 struct objfile
*objfile
= cu
->objfile
;
13148 struct partial_die_info
*part_die
;
13149 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
13150 struct abbrev_info
*abbrev
;
13151 unsigned int bytes_read
;
13152 unsigned int load_all
= 0;
13153 int nesting_level
= 1;
13158 gdb_assert (cu
->per_cu
!= NULL
);
13159 if (cu
->per_cu
->load_all_dies
)
13163 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13167 &cu
->comp_unit_obstack
,
13168 hashtab_obstack_allocate
,
13169 dummy_obstack_deallocate
);
13171 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13172 sizeof (struct partial_die_info
));
13176 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
13178 /* A NULL abbrev means the end of a series of children. */
13179 if (abbrev
== NULL
)
13181 if (--nesting_level
== 0)
13183 /* PART_DIE was probably the last thing allocated on the
13184 comp_unit_obstack, so we could call obstack_free
13185 here. We don't do that because the waste is small,
13186 and will be cleaned up when we're done with this
13187 compilation unit. This way, we're also more robust
13188 against other users of the comp_unit_obstack. */
13191 info_ptr
+= bytes_read
;
13192 last_die
= parent_die
;
13193 parent_die
= parent_die
->die_parent
;
13197 /* Check for template arguments. We never save these; if
13198 they're seen, we just mark the parent, and go on our way. */
13199 if (parent_die
!= NULL
13200 && cu
->language
== language_cplus
13201 && (abbrev
->tag
== DW_TAG_template_type_param
13202 || abbrev
->tag
== DW_TAG_template_value_param
))
13204 parent_die
->has_template_arguments
= 1;
13208 /* We don't need a partial DIE for the template argument. */
13209 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13214 /* We only recurse into c++ subprograms looking for template arguments.
13215 Skip their other children. */
13217 && cu
->language
== language_cplus
13218 && parent_die
!= NULL
13219 && parent_die
->tag
== DW_TAG_subprogram
)
13221 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13225 /* Check whether this DIE is interesting enough to save. Normally
13226 we would not be interested in members here, but there may be
13227 later variables referencing them via DW_AT_specification (for
13228 static members). */
13230 && !is_type_tag_for_partial (abbrev
->tag
)
13231 && abbrev
->tag
!= DW_TAG_constant
13232 && abbrev
->tag
!= DW_TAG_enumerator
13233 && abbrev
->tag
!= DW_TAG_subprogram
13234 && abbrev
->tag
!= DW_TAG_lexical_block
13235 && abbrev
->tag
!= DW_TAG_variable
13236 && abbrev
->tag
!= DW_TAG_namespace
13237 && abbrev
->tag
!= DW_TAG_module
13238 && abbrev
->tag
!= DW_TAG_member
13239 && abbrev
->tag
!= DW_TAG_imported_unit
)
13241 /* Otherwise we skip to the next sibling, if any. */
13242 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13246 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
13249 /* This two-pass algorithm for processing partial symbols has a
13250 high cost in cache pressure. Thus, handle some simple cases
13251 here which cover the majority of C partial symbols. DIEs
13252 which neither have specification tags in them, nor could have
13253 specification tags elsewhere pointing at them, can simply be
13254 processed and discarded.
13256 This segment is also optional; scan_partial_symbols and
13257 add_partial_symbol will handle these DIEs if we chain
13258 them in normally. When compilers which do not emit large
13259 quantities of duplicate debug information are more common,
13260 this code can probably be removed. */
13262 /* Any complete simple types at the top level (pretty much all
13263 of them, for a language without namespaces), can be processed
13265 if (parent_die
== NULL
13266 && part_die
->has_specification
== 0
13267 && part_die
->is_declaration
== 0
13268 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
13269 || part_die
->tag
== DW_TAG_base_type
13270 || part_die
->tag
== DW_TAG_subrange_type
))
13272 if (building_psymtab
&& part_die
->name
!= NULL
)
13273 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13274 VAR_DOMAIN
, LOC_TYPEDEF
,
13275 &objfile
->static_psymbols
,
13276 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13277 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13281 /* The exception for DW_TAG_typedef with has_children above is
13282 a workaround of GCC PR debug/47510. In the case of this complaint
13283 type_name_no_tag_or_error will error on such types later.
13285 GDB skipped children of DW_TAG_typedef by the shortcut above and then
13286 it could not find the child DIEs referenced later, this is checked
13287 above. In correct DWARF DW_TAG_typedef should have no children. */
13289 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
13290 complaint (&symfile_complaints
,
13291 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
13292 "- DIE at 0x%x [in module %s]"),
13293 part_die
->offset
.sect_off
, objfile
->name
);
13295 /* If we're at the second level, and we're an enumerator, and
13296 our parent has no specification (meaning possibly lives in a
13297 namespace elsewhere), then we can add the partial symbol now
13298 instead of queueing it. */
13299 if (part_die
->tag
== DW_TAG_enumerator
13300 && parent_die
!= NULL
13301 && parent_die
->die_parent
== NULL
13302 && parent_die
->tag
== DW_TAG_enumeration_type
13303 && parent_die
->has_specification
== 0)
13305 if (part_die
->name
== NULL
)
13306 complaint (&symfile_complaints
,
13307 _("malformed enumerator DIE ignored"));
13308 else if (building_psymtab
)
13309 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13310 VAR_DOMAIN
, LOC_CONST
,
13311 (cu
->language
== language_cplus
13312 || cu
->language
== language_java
)
13313 ? &objfile
->global_psymbols
13314 : &objfile
->static_psymbols
,
13315 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13317 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13321 /* We'll save this DIE so link it in. */
13322 part_die
->die_parent
= parent_die
;
13323 part_die
->die_sibling
= NULL
;
13324 part_die
->die_child
= NULL
;
13326 if (last_die
&& last_die
== parent_die
)
13327 last_die
->die_child
= part_die
;
13329 last_die
->die_sibling
= part_die
;
13331 last_die
= part_die
;
13333 if (first_die
== NULL
)
13334 first_die
= part_die
;
13336 /* Maybe add the DIE to the hash table. Not all DIEs that we
13337 find interesting need to be in the hash table, because we
13338 also have the parent/sibling/child chains; only those that we
13339 might refer to by offset later during partial symbol reading.
13341 For now this means things that might have be the target of a
13342 DW_AT_specification, DW_AT_abstract_origin, or
13343 DW_AT_extension. DW_AT_extension will refer only to
13344 namespaces; DW_AT_abstract_origin refers to functions (and
13345 many things under the function DIE, but we do not recurse
13346 into function DIEs during partial symbol reading) and
13347 possibly variables as well; DW_AT_specification refers to
13348 declarations. Declarations ought to have the DW_AT_declaration
13349 flag. It happens that GCC forgets to put it in sometimes, but
13350 only for functions, not for types.
13352 Adding more things than necessary to the hash table is harmless
13353 except for the performance cost. Adding too few will result in
13354 wasted time in find_partial_die, when we reread the compilation
13355 unit with load_all_dies set. */
13358 || abbrev
->tag
== DW_TAG_constant
13359 || abbrev
->tag
== DW_TAG_subprogram
13360 || abbrev
->tag
== DW_TAG_variable
13361 || abbrev
->tag
== DW_TAG_namespace
13362 || part_die
->is_declaration
)
13366 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
13367 part_die
->offset
.sect_off
, INSERT
);
13371 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13372 sizeof (struct partial_die_info
));
13374 /* For some DIEs we want to follow their children (if any). For C
13375 we have no reason to follow the children of structures; for other
13376 languages we have to, so that we can get at method physnames
13377 to infer fully qualified class names, for DW_AT_specification,
13378 and for C++ template arguments. For C++, we also look one level
13379 inside functions to find template arguments (if the name of the
13380 function does not already contain the template arguments).
13382 For Ada, we need to scan the children of subprograms and lexical
13383 blocks as well because Ada allows the definition of nested
13384 entities that could be interesting for the debugger, such as
13385 nested subprograms for instance. */
13386 if (last_die
->has_children
13388 || last_die
->tag
== DW_TAG_namespace
13389 || last_die
->tag
== DW_TAG_module
13390 || last_die
->tag
== DW_TAG_enumeration_type
13391 || (cu
->language
== language_cplus
13392 && last_die
->tag
== DW_TAG_subprogram
13393 && (last_die
->name
== NULL
13394 || strchr (last_die
->name
, '<') == NULL
))
13395 || (cu
->language
!= language_c
13396 && (last_die
->tag
== DW_TAG_class_type
13397 || last_die
->tag
== DW_TAG_interface_type
13398 || last_die
->tag
== DW_TAG_structure_type
13399 || last_die
->tag
== DW_TAG_union_type
))
13400 || (cu
->language
== language_ada
13401 && (last_die
->tag
== DW_TAG_subprogram
13402 || last_die
->tag
== DW_TAG_lexical_block
))))
13405 parent_die
= last_die
;
13409 /* Otherwise we skip to the next sibling, if any. */
13410 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
13412 /* Back to the top, do it again. */
13416 /* Read a minimal amount of information into the minimal die structure. */
13419 read_partial_die (const struct die_reader_specs
*reader
,
13420 struct partial_die_info
*part_die
,
13421 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
13422 gdb_byte
*info_ptr
)
13424 struct dwarf2_cu
*cu
= reader
->cu
;
13425 struct objfile
*objfile
= cu
->objfile
;
13426 gdb_byte
*buffer
= reader
->buffer
;
13428 struct attribute attr
;
13429 int has_low_pc_attr
= 0;
13430 int has_high_pc_attr
= 0;
13431 int high_pc_relative
= 0;
13433 memset (part_die
, 0, sizeof (struct partial_die_info
));
13435 part_die
->offset
.sect_off
= info_ptr
- buffer
;
13437 info_ptr
+= abbrev_len
;
13439 if (abbrev
== NULL
)
13442 part_die
->tag
= abbrev
->tag
;
13443 part_die
->has_children
= abbrev
->has_children
;
13445 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
13447 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
13449 /* Store the data if it is of an attribute we want to keep in a
13450 partial symbol table. */
13454 switch (part_die
->tag
)
13456 case DW_TAG_compile_unit
:
13457 case DW_TAG_partial_unit
:
13458 case DW_TAG_type_unit
:
13459 /* Compilation units have a DW_AT_name that is a filename, not
13460 a source language identifier. */
13461 case DW_TAG_enumeration_type
:
13462 case DW_TAG_enumerator
:
13463 /* These tags always have simple identifiers already; no need
13464 to canonicalize them. */
13465 part_die
->name
= DW_STRING (&attr
);
13469 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
13470 &objfile
->objfile_obstack
);
13474 case DW_AT_linkage_name
:
13475 case DW_AT_MIPS_linkage_name
:
13476 /* Note that both forms of linkage name might appear. We
13477 assume they will be the same, and we only store the last
13479 if (cu
->language
== language_ada
)
13480 part_die
->name
= DW_STRING (&attr
);
13481 part_die
->linkage_name
= DW_STRING (&attr
);
13484 has_low_pc_attr
= 1;
13485 part_die
->lowpc
= DW_ADDR (&attr
);
13487 case DW_AT_high_pc
:
13488 has_high_pc_attr
= 1;
13489 if (attr
.form
== DW_FORM_addr
13490 || attr
.form
== DW_FORM_GNU_addr_index
)
13491 part_die
->highpc
= DW_ADDR (&attr
);
13494 high_pc_relative
= 1;
13495 part_die
->highpc
= DW_UNSND (&attr
);
13498 case DW_AT_location
:
13499 /* Support the .debug_loc offsets. */
13500 if (attr_form_is_block (&attr
))
13502 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
13504 else if (attr_form_is_section_offset (&attr
))
13506 dwarf2_complex_location_expr_complaint ();
13510 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13511 "partial symbol information");
13514 case DW_AT_external
:
13515 part_die
->is_external
= DW_UNSND (&attr
);
13517 case DW_AT_declaration
:
13518 part_die
->is_declaration
= DW_UNSND (&attr
);
13521 part_die
->has_type
= 1;
13523 case DW_AT_abstract_origin
:
13524 case DW_AT_specification
:
13525 case DW_AT_extension
:
13526 part_die
->has_specification
= 1;
13527 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
13528 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13529 || cu
->per_cu
->is_dwz
);
13531 case DW_AT_sibling
:
13532 /* Ignore absolute siblings, they might point outside of
13533 the current compile unit. */
13534 if (attr
.form
== DW_FORM_ref_addr
)
13535 complaint (&symfile_complaints
,
13536 _("ignoring absolute DW_AT_sibling"));
13538 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
13540 case DW_AT_byte_size
:
13541 part_die
->has_byte_size
= 1;
13543 case DW_AT_calling_convention
:
13544 /* DWARF doesn't provide a way to identify a program's source-level
13545 entry point. DW_AT_calling_convention attributes are only meant
13546 to describe functions' calling conventions.
13548 However, because it's a necessary piece of information in
13549 Fortran, and because DW_CC_program is the only piece of debugging
13550 information whose definition refers to a 'main program' at all,
13551 several compilers have begun marking Fortran main programs with
13552 DW_CC_program --- even when those functions use the standard
13553 calling conventions.
13555 So until DWARF specifies a way to provide this information and
13556 compilers pick up the new representation, we'll support this
13558 if (DW_UNSND (&attr
) == DW_CC_program
13559 && cu
->language
== language_fortran
)
13561 set_main_name (part_die
->name
);
13563 /* As this DIE has a static linkage the name would be difficult
13564 to look up later. */
13565 language_of_main
= language_fortran
;
13569 if (DW_UNSND (&attr
) == DW_INL_inlined
13570 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
13571 part_die
->may_be_inlined
= 1;
13575 if (part_die
->tag
== DW_TAG_imported_unit
)
13577 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
13578 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13579 || cu
->per_cu
->is_dwz
);
13588 if (high_pc_relative
)
13589 part_die
->highpc
+= part_die
->lowpc
;
13591 if (has_low_pc_attr
&& has_high_pc_attr
)
13593 /* When using the GNU linker, .gnu.linkonce. sections are used to
13594 eliminate duplicate copies of functions and vtables and such.
13595 The linker will arbitrarily choose one and discard the others.
13596 The AT_*_pc values for such functions refer to local labels in
13597 these sections. If the section from that file was discarded, the
13598 labels are not in the output, so the relocs get a value of 0.
13599 If this is a discarded function, mark the pc bounds as invalid,
13600 so that GDB will ignore it. */
13601 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13603 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13605 complaint (&symfile_complaints
,
13606 _("DW_AT_low_pc %s is zero "
13607 "for DIE at 0x%x [in module %s]"),
13608 paddress (gdbarch
, part_die
->lowpc
),
13609 part_die
->offset
.sect_off
, objfile
->name
);
13611 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
13612 else if (part_die
->lowpc
>= part_die
->highpc
)
13614 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13616 complaint (&symfile_complaints
,
13617 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
13618 "for DIE at 0x%x [in module %s]"),
13619 paddress (gdbarch
, part_die
->lowpc
),
13620 paddress (gdbarch
, part_die
->highpc
),
13621 part_die
->offset
.sect_off
, objfile
->name
);
13624 part_die
->has_pc_info
= 1;
13630 /* Find a cached partial DIE at OFFSET in CU. */
13632 static struct partial_die_info
*
13633 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
13635 struct partial_die_info
*lookup_die
= NULL
;
13636 struct partial_die_info part_die
;
13638 part_die
.offset
= offset
;
13639 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
13645 /* Find a partial DIE at OFFSET, which may or may not be in CU,
13646 except in the case of .debug_types DIEs which do not reference
13647 outside their CU (they do however referencing other types via
13648 DW_FORM_ref_sig8). */
13650 static struct partial_die_info
*
13651 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
13653 struct objfile
*objfile
= cu
->objfile
;
13654 struct dwarf2_per_cu_data
*per_cu
= NULL
;
13655 struct partial_die_info
*pd
= NULL
;
13657 if (offset_in_dwz
== cu
->per_cu
->is_dwz
13658 && offset_in_cu_p (&cu
->header
, offset
))
13660 pd
= find_partial_die_in_comp_unit (offset
, cu
);
13663 /* We missed recording what we needed.
13664 Load all dies and try again. */
13665 per_cu
= cu
->per_cu
;
13669 /* TUs don't reference other CUs/TUs (except via type signatures). */
13670 if (cu
->per_cu
->is_debug_types
)
13672 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
13673 " external reference to offset 0x%lx [in module %s].\n"),
13674 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
13675 bfd_get_filename (objfile
->obfd
));
13677 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
13680 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
13681 load_partial_comp_unit (per_cu
);
13683 per_cu
->cu
->last_used
= 0;
13684 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13687 /* If we didn't find it, and not all dies have been loaded,
13688 load them all and try again. */
13690 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
13692 per_cu
->load_all_dies
= 1;
13694 /* This is nasty. When we reread the DIEs, somewhere up the call chain
13695 THIS_CU->cu may already be in use. So we can't just free it and
13696 replace its DIEs with the ones we read in. Instead, we leave those
13697 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
13698 and clobber THIS_CU->cu->partial_dies with the hash table for the new
13700 load_partial_comp_unit (per_cu
);
13702 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13706 internal_error (__FILE__
, __LINE__
,
13707 _("could not find partial DIE 0x%x "
13708 "in cache [from module %s]\n"),
13709 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
13713 /* See if we can figure out if the class lives in a namespace. We do
13714 this by looking for a member function; its demangled name will
13715 contain namespace info, if there is any. */
13718 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
13719 struct dwarf2_cu
*cu
)
13721 /* NOTE: carlton/2003-10-07: Getting the info this way changes
13722 what template types look like, because the demangler
13723 frequently doesn't give the same name as the debug info. We
13724 could fix this by only using the demangled name to get the
13725 prefix (but see comment in read_structure_type). */
13727 struct partial_die_info
*real_pdi
;
13728 struct partial_die_info
*child_pdi
;
13730 /* If this DIE (this DIE's specification, if any) has a parent, then
13731 we should not do this. We'll prepend the parent's fully qualified
13732 name when we create the partial symbol. */
13734 real_pdi
= struct_pdi
;
13735 while (real_pdi
->has_specification
)
13736 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
13737 real_pdi
->spec_is_dwz
, cu
);
13739 if (real_pdi
->die_parent
!= NULL
)
13742 for (child_pdi
= struct_pdi
->die_child
;
13744 child_pdi
= child_pdi
->die_sibling
)
13746 if (child_pdi
->tag
== DW_TAG_subprogram
13747 && child_pdi
->linkage_name
!= NULL
)
13749 char *actual_class_name
13750 = language_class_name_from_physname (cu
->language_defn
,
13751 child_pdi
->linkage_name
);
13752 if (actual_class_name
!= NULL
)
13755 = obsavestring (actual_class_name
,
13756 strlen (actual_class_name
),
13757 &cu
->objfile
->objfile_obstack
);
13758 xfree (actual_class_name
);
13765 /* Adjust PART_DIE before generating a symbol for it. This function
13766 may set the is_external flag or change the DIE's name. */
13769 fixup_partial_die (struct partial_die_info
*part_die
,
13770 struct dwarf2_cu
*cu
)
13772 /* Once we've fixed up a die, there's no point in doing so again.
13773 This also avoids a memory leak if we were to call
13774 guess_partial_die_structure_name multiple times. */
13775 if (part_die
->fixup_called
)
13778 /* If we found a reference attribute and the DIE has no name, try
13779 to find a name in the referred to DIE. */
13781 if (part_die
->name
== NULL
&& part_die
->has_specification
)
13783 struct partial_die_info
*spec_die
;
13785 spec_die
= find_partial_die (part_die
->spec_offset
,
13786 part_die
->spec_is_dwz
, cu
);
13788 fixup_partial_die (spec_die
, cu
);
13790 if (spec_die
->name
)
13792 part_die
->name
= spec_die
->name
;
13794 /* Copy DW_AT_external attribute if it is set. */
13795 if (spec_die
->is_external
)
13796 part_die
->is_external
= spec_die
->is_external
;
13800 /* Set default names for some unnamed DIEs. */
13802 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
13803 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
13805 /* If there is no parent die to provide a namespace, and there are
13806 children, see if we can determine the namespace from their linkage
13808 if (cu
->language
== language_cplus
13809 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
13810 && part_die
->die_parent
== NULL
13811 && part_die
->has_children
13812 && (part_die
->tag
== DW_TAG_class_type
13813 || part_die
->tag
== DW_TAG_structure_type
13814 || part_die
->tag
== DW_TAG_union_type
))
13815 guess_partial_die_structure_name (part_die
, cu
);
13817 /* GCC might emit a nameless struct or union that has a linkage
13818 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13819 if (part_die
->name
== NULL
13820 && (part_die
->tag
== DW_TAG_class_type
13821 || part_die
->tag
== DW_TAG_interface_type
13822 || part_die
->tag
== DW_TAG_structure_type
13823 || part_die
->tag
== DW_TAG_union_type
)
13824 && part_die
->linkage_name
!= NULL
)
13828 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
13833 /* Strip any leading namespaces/classes, keep only the base name.
13834 DW_AT_name for named DIEs does not contain the prefixes. */
13835 base
= strrchr (demangled
, ':');
13836 if (base
&& base
> demangled
&& base
[-1] == ':')
13841 part_die
->name
= obsavestring (base
, strlen (base
),
13842 &cu
->objfile
->objfile_obstack
);
13847 part_die
->fixup_called
= 1;
13850 /* Read an attribute value described by an attribute form. */
13853 read_attribute_value (const struct die_reader_specs
*reader
,
13854 struct attribute
*attr
, unsigned form
,
13855 gdb_byte
*info_ptr
)
13857 struct dwarf2_cu
*cu
= reader
->cu
;
13858 bfd
*abfd
= reader
->abfd
;
13859 struct comp_unit_head
*cu_header
= &cu
->header
;
13860 unsigned int bytes_read
;
13861 struct dwarf_block
*blk
;
13866 case DW_FORM_ref_addr
:
13867 if (cu
->header
.version
== 2)
13868 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13870 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
13871 &cu
->header
, &bytes_read
);
13872 info_ptr
+= bytes_read
;
13874 case DW_FORM_GNU_ref_alt
:
13875 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13876 info_ptr
+= bytes_read
;
13879 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13880 info_ptr
+= bytes_read
;
13882 case DW_FORM_block2
:
13883 blk
= dwarf_alloc_block (cu
);
13884 blk
->size
= read_2_bytes (abfd
, info_ptr
);
13886 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13887 info_ptr
+= blk
->size
;
13888 DW_BLOCK (attr
) = blk
;
13890 case DW_FORM_block4
:
13891 blk
= dwarf_alloc_block (cu
);
13892 blk
->size
= read_4_bytes (abfd
, info_ptr
);
13894 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13895 info_ptr
+= blk
->size
;
13896 DW_BLOCK (attr
) = blk
;
13898 case DW_FORM_data2
:
13899 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
13902 case DW_FORM_data4
:
13903 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
13906 case DW_FORM_data8
:
13907 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
13910 case DW_FORM_sec_offset
:
13911 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13912 info_ptr
+= bytes_read
;
13914 case DW_FORM_string
:
13915 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
13916 DW_STRING_IS_CANONICAL (attr
) = 0;
13917 info_ptr
+= bytes_read
;
13920 if (!cu
->per_cu
->is_dwz
)
13922 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
13924 DW_STRING_IS_CANONICAL (attr
) = 0;
13925 info_ptr
+= bytes_read
;
13929 case DW_FORM_GNU_strp_alt
:
13931 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
13932 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
13935 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
13936 DW_STRING_IS_CANONICAL (attr
) = 0;
13937 info_ptr
+= bytes_read
;
13940 case DW_FORM_exprloc
:
13941 case DW_FORM_block
:
13942 blk
= dwarf_alloc_block (cu
);
13943 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13944 info_ptr
+= bytes_read
;
13945 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13946 info_ptr
+= blk
->size
;
13947 DW_BLOCK (attr
) = blk
;
13949 case DW_FORM_block1
:
13950 blk
= dwarf_alloc_block (cu
);
13951 blk
->size
= read_1_byte (abfd
, info_ptr
);
13953 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13954 info_ptr
+= blk
->size
;
13955 DW_BLOCK (attr
) = blk
;
13957 case DW_FORM_data1
:
13958 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
13962 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
13965 case DW_FORM_flag_present
:
13966 DW_UNSND (attr
) = 1;
13968 case DW_FORM_sdata
:
13969 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
13970 info_ptr
+= bytes_read
;
13972 case DW_FORM_udata
:
13973 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13974 info_ptr
+= bytes_read
;
13977 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13978 + read_1_byte (abfd
, info_ptr
));
13982 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13983 + read_2_bytes (abfd
, info_ptr
));
13987 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13988 + read_4_bytes (abfd
, info_ptr
));
13992 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13993 + read_8_bytes (abfd
, info_ptr
));
13996 case DW_FORM_ref_sig8
:
13997 /* Convert the signature to something we can record in DW_UNSND
13999 NOTE: This is NULL if the type wasn't found. */
14000 DW_SIGNATURED_TYPE (attr
) =
14001 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
14004 case DW_FORM_ref_udata
:
14005 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14006 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
14007 info_ptr
+= bytes_read
;
14009 case DW_FORM_indirect
:
14010 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14011 info_ptr
+= bytes_read
;
14012 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
14014 case DW_FORM_GNU_addr_index
:
14015 if (reader
->dwo_file
== NULL
)
14017 /* For now flag a hard error.
14018 Later we can turn this into a complaint. */
14019 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14020 dwarf_form_name (form
),
14021 bfd_get_filename (abfd
));
14023 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
14024 info_ptr
+= bytes_read
;
14026 case DW_FORM_GNU_str_index
:
14027 if (reader
->dwo_file
== NULL
)
14029 /* For now flag a hard error.
14030 Later we can turn this into a complaint if warranted. */
14031 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14032 dwarf_form_name (form
),
14033 bfd_get_filename (abfd
));
14036 ULONGEST str_index
=
14037 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14039 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
14040 DW_STRING_IS_CANONICAL (attr
) = 0;
14041 info_ptr
+= bytes_read
;
14045 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
14046 dwarf_form_name (form
),
14047 bfd_get_filename (abfd
));
14051 if (cu
->per_cu
->is_dwz
&& is_ref_attr (attr
))
14052 attr
->form
= DW_FORM_GNU_ref_alt
;
14054 /* We have seen instances where the compiler tried to emit a byte
14055 size attribute of -1 which ended up being encoded as an unsigned
14056 0xffffffff. Although 0xffffffff is technically a valid size value,
14057 an object of this size seems pretty unlikely so we can relatively
14058 safely treat these cases as if the size attribute was invalid and
14059 treat them as zero by default. */
14060 if (attr
->name
== DW_AT_byte_size
14061 && form
== DW_FORM_data4
14062 && DW_UNSND (attr
) >= 0xffffffff)
14065 (&symfile_complaints
,
14066 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
14067 hex_string (DW_UNSND (attr
)));
14068 DW_UNSND (attr
) = 0;
14074 /* Read an attribute described by an abbreviated attribute. */
14077 read_attribute (const struct die_reader_specs
*reader
,
14078 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
14079 gdb_byte
*info_ptr
)
14081 attr
->name
= abbrev
->name
;
14082 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
14085 /* Read dwarf information from a buffer. */
14087 static unsigned int
14088 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
14090 return bfd_get_8 (abfd
, buf
);
14094 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
14096 return bfd_get_signed_8 (abfd
, buf
);
14099 static unsigned int
14100 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14102 return bfd_get_16 (abfd
, buf
);
14106 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14108 return bfd_get_signed_16 (abfd
, buf
);
14111 static unsigned int
14112 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14114 return bfd_get_32 (abfd
, buf
);
14118 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14120 return bfd_get_signed_32 (abfd
, buf
);
14124 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14126 return bfd_get_64 (abfd
, buf
);
14130 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
14131 unsigned int *bytes_read
)
14133 struct comp_unit_head
*cu_header
= &cu
->header
;
14134 CORE_ADDR retval
= 0;
14136 if (cu_header
->signed_addr_p
)
14138 switch (cu_header
->addr_size
)
14141 retval
= bfd_get_signed_16 (abfd
, buf
);
14144 retval
= bfd_get_signed_32 (abfd
, buf
);
14147 retval
= bfd_get_signed_64 (abfd
, buf
);
14150 internal_error (__FILE__
, __LINE__
,
14151 _("read_address: bad switch, signed [in module %s]"),
14152 bfd_get_filename (abfd
));
14157 switch (cu_header
->addr_size
)
14160 retval
= bfd_get_16 (abfd
, buf
);
14163 retval
= bfd_get_32 (abfd
, buf
);
14166 retval
= bfd_get_64 (abfd
, buf
);
14169 internal_error (__FILE__
, __LINE__
,
14170 _("read_address: bad switch, "
14171 "unsigned [in module %s]"),
14172 bfd_get_filename (abfd
));
14176 *bytes_read
= cu_header
->addr_size
;
14180 /* Read the initial length from a section. The (draft) DWARF 3
14181 specification allows the initial length to take up either 4 bytes
14182 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
14183 bytes describe the length and all offsets will be 8 bytes in length
14186 An older, non-standard 64-bit format is also handled by this
14187 function. The older format in question stores the initial length
14188 as an 8-byte quantity without an escape value. Lengths greater
14189 than 2^32 aren't very common which means that the initial 4 bytes
14190 is almost always zero. Since a length value of zero doesn't make
14191 sense for the 32-bit format, this initial zero can be considered to
14192 be an escape value which indicates the presence of the older 64-bit
14193 format. As written, the code can't detect (old format) lengths
14194 greater than 4GB. If it becomes necessary to handle lengths
14195 somewhat larger than 4GB, we could allow other small values (such
14196 as the non-sensical values of 1, 2, and 3) to also be used as
14197 escape values indicating the presence of the old format.
14199 The value returned via bytes_read should be used to increment the
14200 relevant pointer after calling read_initial_length().
14202 [ Note: read_initial_length() and read_offset() are based on the
14203 document entitled "DWARF Debugging Information Format", revision
14204 3, draft 8, dated November 19, 2001. This document was obtained
14207 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
14209 This document is only a draft and is subject to change. (So beware.)
14211 Details regarding the older, non-standard 64-bit format were
14212 determined empirically by examining 64-bit ELF files produced by
14213 the SGI toolchain on an IRIX 6.5 machine.
14215 - Kevin, July 16, 2002
14219 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
14221 LONGEST length
= bfd_get_32 (abfd
, buf
);
14223 if (length
== 0xffffffff)
14225 length
= bfd_get_64 (abfd
, buf
+ 4);
14228 else if (length
== 0)
14230 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
14231 length
= bfd_get_64 (abfd
, buf
);
14242 /* Cover function for read_initial_length.
14243 Returns the length of the object at BUF, and stores the size of the
14244 initial length in *BYTES_READ and stores the size that offsets will be in
14246 If the initial length size is not equivalent to that specified in
14247 CU_HEADER then issue a complaint.
14248 This is useful when reading non-comp-unit headers. */
14251 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
14252 const struct comp_unit_head
*cu_header
,
14253 unsigned int *bytes_read
,
14254 unsigned int *offset_size
)
14256 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
14258 gdb_assert (cu_header
->initial_length_size
== 4
14259 || cu_header
->initial_length_size
== 8
14260 || cu_header
->initial_length_size
== 12);
14262 if (cu_header
->initial_length_size
!= *bytes_read
)
14263 complaint (&symfile_complaints
,
14264 _("intermixed 32-bit and 64-bit DWARF sections"));
14266 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
14270 /* Read an offset from the data stream. The size of the offset is
14271 given by cu_header->offset_size. */
14274 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
14275 unsigned int *bytes_read
)
14277 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
14279 *bytes_read
= cu_header
->offset_size
;
14283 /* Read an offset from the data stream. */
14286 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
14288 LONGEST retval
= 0;
14290 switch (offset_size
)
14293 retval
= bfd_get_32 (abfd
, buf
);
14296 retval
= bfd_get_64 (abfd
, buf
);
14299 internal_error (__FILE__
, __LINE__
,
14300 _("read_offset_1: bad switch [in module %s]"),
14301 bfd_get_filename (abfd
));
14308 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
14310 /* If the size of a host char is 8 bits, we can return a pointer
14311 to the buffer, otherwise we have to copy the data to a buffer
14312 allocated on the temporary obstack. */
14313 gdb_assert (HOST_CHAR_BIT
== 8);
14318 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14320 /* If the size of a host char is 8 bits, we can return a pointer
14321 to the string, otherwise we have to copy the string to a buffer
14322 allocated on the temporary obstack. */
14323 gdb_assert (HOST_CHAR_BIT
== 8);
14326 *bytes_read_ptr
= 1;
14329 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
14330 return (char *) buf
;
14334 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
14336 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
14337 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
14338 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
14339 bfd_get_filename (abfd
));
14340 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
14341 error (_("DW_FORM_strp pointing outside of "
14342 ".debug_str section [in module %s]"),
14343 bfd_get_filename (abfd
));
14344 gdb_assert (HOST_CHAR_BIT
== 8);
14345 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
14347 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
14350 /* Read a string at offset STR_OFFSET in the .debug_str section from
14351 the .dwz file DWZ. Throw an error if the offset is too large. If
14352 the string consists of a single NUL byte, return NULL; otherwise
14353 return a pointer to the string. */
14356 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
14358 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
14360 if (dwz
->str
.buffer
== NULL
)
14361 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
14362 "section [in module %s]"),
14363 bfd_get_filename (dwz
->dwz_bfd
));
14364 if (str_offset
>= dwz
->str
.size
)
14365 error (_("DW_FORM_GNU_strp_alt pointing outside of "
14366 ".debug_str section [in module %s]"),
14367 bfd_get_filename (dwz
->dwz_bfd
));
14368 gdb_assert (HOST_CHAR_BIT
== 8);
14369 if (dwz
->str
.buffer
[str_offset
] == '\0')
14371 return (char *) (dwz
->str
.buffer
+ str_offset
);
14375 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
14376 const struct comp_unit_head
*cu_header
,
14377 unsigned int *bytes_read_ptr
)
14379 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
14381 return read_indirect_string_at_offset (abfd
, str_offset
);
14385 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14388 unsigned int num_read
;
14390 unsigned char byte
;
14398 byte
= bfd_get_8 (abfd
, buf
);
14401 result
|= ((ULONGEST
) (byte
& 127) << shift
);
14402 if ((byte
& 128) == 0)
14408 *bytes_read_ptr
= num_read
;
14413 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14416 int i
, shift
, num_read
;
14417 unsigned char byte
;
14425 byte
= bfd_get_8 (abfd
, buf
);
14428 result
|= ((LONGEST
) (byte
& 127) << shift
);
14430 if ((byte
& 128) == 0)
14435 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
14436 result
|= -(((LONGEST
) 1) << shift
);
14437 *bytes_read_ptr
= num_read
;
14441 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
14442 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
14443 ADDR_SIZE is the size of addresses from the CU header. */
14446 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
14448 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14449 bfd
*abfd
= objfile
->obfd
;
14450 const gdb_byte
*info_ptr
;
14452 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
14453 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
14454 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
14456 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
14457 error (_("DW_FORM_addr_index pointing outside of "
14458 ".debug_addr section [in module %s]"),
14460 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
14461 + addr_base
+ addr_index
* addr_size
);
14462 if (addr_size
== 4)
14463 return bfd_get_32 (abfd
, info_ptr
);
14465 return bfd_get_64 (abfd
, info_ptr
);
14468 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
14471 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
14473 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
14476 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
14479 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
14480 unsigned int *bytes_read
)
14482 bfd
*abfd
= cu
->objfile
->obfd
;
14483 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
14485 return read_addr_index (cu
, addr_index
);
14488 /* Data structure to pass results from dwarf2_read_addr_index_reader
14489 back to dwarf2_read_addr_index. */
14491 struct dwarf2_read_addr_index_data
14493 ULONGEST addr_base
;
14497 /* die_reader_func for dwarf2_read_addr_index. */
14500 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
14501 gdb_byte
*info_ptr
,
14502 struct die_info
*comp_unit_die
,
14506 struct dwarf2_cu
*cu
= reader
->cu
;
14507 struct dwarf2_read_addr_index_data
*aidata
=
14508 (struct dwarf2_read_addr_index_data
*) data
;
14510 aidata
->addr_base
= cu
->addr_base
;
14511 aidata
->addr_size
= cu
->header
.addr_size
;
14514 /* Given an index in .debug_addr, fetch the value.
14515 NOTE: This can be called during dwarf expression evaluation,
14516 long after the debug information has been read, and thus per_cu->cu
14517 may no longer exist. */
14520 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
14521 unsigned int addr_index
)
14523 struct objfile
*objfile
= per_cu
->objfile
;
14524 struct dwarf2_cu
*cu
= per_cu
->cu
;
14525 ULONGEST addr_base
;
14528 /* This is intended to be called from outside this file. */
14529 dw2_setup (objfile
);
14531 /* We need addr_base and addr_size.
14532 If we don't have PER_CU->cu, we have to get it.
14533 Nasty, but the alternative is storing the needed info in PER_CU,
14534 which at this point doesn't seem justified: it's not clear how frequently
14535 it would get used and it would increase the size of every PER_CU.
14536 Entry points like dwarf2_per_cu_addr_size do a similar thing
14537 so we're not in uncharted territory here.
14538 Alas we need to be a bit more complicated as addr_base is contained
14541 We don't need to read the entire CU(/TU).
14542 We just need the header and top level die.
14544 IWBN to use the aging mechanism to let us lazily later discard the CU.
14545 For now we skip this optimization. */
14549 addr_base
= cu
->addr_base
;
14550 addr_size
= cu
->header
.addr_size
;
14554 struct dwarf2_read_addr_index_data aidata
;
14556 /* Note: We can't use init_cutu_and_read_dies_simple here,
14557 we need addr_base. */
14558 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
14559 dwarf2_read_addr_index_reader
, &aidata
);
14560 addr_base
= aidata
.addr_base
;
14561 addr_size
= aidata
.addr_size
;
14564 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
14567 /* Given a DW_AT_str_index, fetch the string. */
14570 read_str_index (const struct die_reader_specs
*reader
,
14571 struct dwarf2_cu
*cu
, ULONGEST str_index
)
14573 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14574 const char *dwo_name
= objfile
->name
;
14575 bfd
*abfd
= objfile
->obfd
;
14576 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
14577 gdb_byte
*info_ptr
;
14578 ULONGEST str_offset
;
14580 dwarf2_read_section (objfile
, §ions
->str
);
14581 dwarf2_read_section (objfile
, §ions
->str_offsets
);
14582 if (sections
->str
.buffer
== NULL
)
14583 error (_("DW_FORM_str_index used without .debug_str.dwo section"
14584 " in CU at offset 0x%lx [in module %s]"),
14585 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14586 if (sections
->str_offsets
.buffer
== NULL
)
14587 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
14588 " in CU at offset 0x%lx [in module %s]"),
14589 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14590 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
14591 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
14592 " section in CU at offset 0x%lx [in module %s]"),
14593 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14594 info_ptr
= (sections
->str_offsets
.buffer
14595 + str_index
* cu
->header
.offset_size
);
14596 if (cu
->header
.offset_size
== 4)
14597 str_offset
= bfd_get_32 (abfd
, info_ptr
);
14599 str_offset
= bfd_get_64 (abfd
, info_ptr
);
14600 if (str_offset
>= sections
->str
.size
)
14601 error (_("Offset from DW_FORM_str_index pointing outside of"
14602 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
14603 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14604 return (char *) (sections
->str
.buffer
+ str_offset
);
14607 /* Return the length of an LEB128 number in BUF. */
14610 leb128_size (const gdb_byte
*buf
)
14612 const gdb_byte
*begin
= buf
;
14618 if ((byte
& 128) == 0)
14619 return buf
- begin
;
14624 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
14631 cu
->language
= language_c
;
14633 case DW_LANG_C_plus_plus
:
14634 cu
->language
= language_cplus
;
14637 cu
->language
= language_d
;
14639 case DW_LANG_Fortran77
:
14640 case DW_LANG_Fortran90
:
14641 case DW_LANG_Fortran95
:
14642 cu
->language
= language_fortran
;
14645 cu
->language
= language_go
;
14647 case DW_LANG_Mips_Assembler
:
14648 cu
->language
= language_asm
;
14651 cu
->language
= language_java
;
14653 case DW_LANG_Ada83
:
14654 case DW_LANG_Ada95
:
14655 cu
->language
= language_ada
;
14657 case DW_LANG_Modula2
:
14658 cu
->language
= language_m2
;
14660 case DW_LANG_Pascal83
:
14661 cu
->language
= language_pascal
;
14664 cu
->language
= language_objc
;
14666 case DW_LANG_Cobol74
:
14667 case DW_LANG_Cobol85
:
14669 cu
->language
= language_minimal
;
14672 cu
->language_defn
= language_def (cu
->language
);
14675 /* Return the named attribute or NULL if not there. */
14677 static struct attribute
*
14678 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
14683 struct attribute
*spec
= NULL
;
14685 for (i
= 0; i
< die
->num_attrs
; ++i
)
14687 if (die
->attrs
[i
].name
== name
)
14688 return &die
->attrs
[i
];
14689 if (die
->attrs
[i
].name
== DW_AT_specification
14690 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
14691 spec
= &die
->attrs
[i
];
14697 die
= follow_die_ref (die
, spec
, &cu
);
14703 /* Return the named attribute or NULL if not there,
14704 but do not follow DW_AT_specification, etc.
14705 This is for use in contexts where we're reading .debug_types dies.
14706 Following DW_AT_specification, DW_AT_abstract_origin will take us
14707 back up the chain, and we want to go down. */
14709 static struct attribute
*
14710 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
14714 for (i
= 0; i
< die
->num_attrs
; ++i
)
14715 if (die
->attrs
[i
].name
== name
)
14716 return &die
->attrs
[i
];
14721 /* Return non-zero iff the attribute NAME is defined for the given DIE,
14722 and holds a non-zero value. This function should only be used for
14723 DW_FORM_flag or DW_FORM_flag_present attributes. */
14726 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
14728 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
14730 return (attr
&& DW_UNSND (attr
));
14734 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
14736 /* A DIE is a declaration if it has a DW_AT_declaration attribute
14737 which value is non-zero. However, we have to be careful with
14738 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
14739 (via dwarf2_flag_true_p) follows this attribute. So we may
14740 end up accidently finding a declaration attribute that belongs
14741 to a different DIE referenced by the specification attribute,
14742 even though the given DIE does not have a declaration attribute. */
14743 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
14744 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
14747 /* Return the die giving the specification for DIE, if there is
14748 one. *SPEC_CU is the CU containing DIE on input, and the CU
14749 containing the return value on output. If there is no
14750 specification, but there is an abstract origin, that is
14753 static struct die_info
*
14754 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
14756 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
14759 if (spec_attr
== NULL
)
14760 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
14762 if (spec_attr
== NULL
)
14765 return follow_die_ref (die
, spec_attr
, spec_cu
);
14768 /* Free the line_header structure *LH, and any arrays and strings it
14770 NOTE: This is also used as a "cleanup" function. */
14773 free_line_header (struct line_header
*lh
)
14775 if (lh
->standard_opcode_lengths
)
14776 xfree (lh
->standard_opcode_lengths
);
14778 /* Remember that all the lh->file_names[i].name pointers are
14779 pointers into debug_line_buffer, and don't need to be freed. */
14780 if (lh
->file_names
)
14781 xfree (lh
->file_names
);
14783 /* Similarly for the include directory names. */
14784 if (lh
->include_dirs
)
14785 xfree (lh
->include_dirs
);
14790 /* Add an entry to LH's include directory table. */
14793 add_include_dir (struct line_header
*lh
, char *include_dir
)
14795 /* Grow the array if necessary. */
14796 if (lh
->include_dirs_size
== 0)
14798 lh
->include_dirs_size
= 1; /* for testing */
14799 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
14800 * sizeof (*lh
->include_dirs
));
14802 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
14804 lh
->include_dirs_size
*= 2;
14805 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
14806 (lh
->include_dirs_size
14807 * sizeof (*lh
->include_dirs
)));
14810 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
14813 /* Add an entry to LH's file name table. */
14816 add_file_name (struct line_header
*lh
,
14818 unsigned int dir_index
,
14819 unsigned int mod_time
,
14820 unsigned int length
)
14822 struct file_entry
*fe
;
14824 /* Grow the array if necessary. */
14825 if (lh
->file_names_size
== 0)
14827 lh
->file_names_size
= 1; /* for testing */
14828 lh
->file_names
= xmalloc (lh
->file_names_size
14829 * sizeof (*lh
->file_names
));
14831 else if (lh
->num_file_names
>= lh
->file_names_size
)
14833 lh
->file_names_size
*= 2;
14834 lh
->file_names
= xrealloc (lh
->file_names
,
14835 (lh
->file_names_size
14836 * sizeof (*lh
->file_names
)));
14839 fe
= &lh
->file_names
[lh
->num_file_names
++];
14841 fe
->dir_index
= dir_index
;
14842 fe
->mod_time
= mod_time
;
14843 fe
->length
= length
;
14844 fe
->included_p
= 0;
14848 /* A convenience function to find the proper .debug_line section for a
14851 static struct dwarf2_section_info
*
14852 get_debug_line_section (struct dwarf2_cu
*cu
)
14854 struct dwarf2_section_info
*section
;
14856 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
14858 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14859 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
14860 else if (cu
->per_cu
->is_dwz
)
14862 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14864 section
= &dwz
->line
;
14867 section
= &dwarf2_per_objfile
->line
;
14872 /* Read the statement program header starting at OFFSET in
14873 .debug_line, or .debug_line.dwo. Return a pointer
14874 to a struct line_header, allocated using xmalloc.
14876 NOTE: the strings in the include directory and file name tables of
14877 the returned object point into the dwarf line section buffer,
14878 and must not be freed. */
14880 static struct line_header
*
14881 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
14883 struct cleanup
*back_to
;
14884 struct line_header
*lh
;
14885 gdb_byte
*line_ptr
;
14886 unsigned int bytes_read
, offset_size
;
14888 char *cur_dir
, *cur_file
;
14889 struct dwarf2_section_info
*section
;
14892 section
= get_debug_line_section (cu
);
14893 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
14894 if (section
->buffer
== NULL
)
14896 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14897 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
14899 complaint (&symfile_complaints
, _("missing .debug_line section"));
14903 /* We can't do this until we know the section is non-empty.
14904 Only then do we know we have such a section. */
14905 abfd
= section
->asection
->owner
;
14907 /* Make sure that at least there's room for the total_length field.
14908 That could be 12 bytes long, but we're just going to fudge that. */
14909 if (offset
+ 4 >= section
->size
)
14911 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14915 lh
= xmalloc (sizeof (*lh
));
14916 memset (lh
, 0, sizeof (*lh
));
14917 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
14920 line_ptr
= section
->buffer
+ offset
;
14922 /* Read in the header. */
14924 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
14925 &bytes_read
, &offset_size
);
14926 line_ptr
+= bytes_read
;
14927 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
14929 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14932 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
14933 lh
->version
= read_2_bytes (abfd
, line_ptr
);
14935 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
14936 line_ptr
+= offset_size
;
14937 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
14939 if (lh
->version
>= 4)
14941 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
14945 lh
->maximum_ops_per_instruction
= 1;
14947 if (lh
->maximum_ops_per_instruction
== 0)
14949 lh
->maximum_ops_per_instruction
= 1;
14950 complaint (&symfile_complaints
,
14951 _("invalid maximum_ops_per_instruction "
14952 "in `.debug_line' section"));
14955 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
14957 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
14959 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
14961 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
14963 lh
->standard_opcode_lengths
14964 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
14966 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
14967 for (i
= 1; i
< lh
->opcode_base
; ++i
)
14969 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
14973 /* Read directory table. */
14974 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
14976 line_ptr
+= bytes_read
;
14977 add_include_dir (lh
, cur_dir
);
14979 line_ptr
+= bytes_read
;
14981 /* Read file name table. */
14982 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
14984 unsigned int dir_index
, mod_time
, length
;
14986 line_ptr
+= bytes_read
;
14987 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14988 line_ptr
+= bytes_read
;
14989 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14990 line_ptr
+= bytes_read
;
14991 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14992 line_ptr
+= bytes_read
;
14994 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
14996 line_ptr
+= bytes_read
;
14997 lh
->statement_program_start
= line_ptr
;
14999 if (line_ptr
> (section
->buffer
+ section
->size
))
15000 complaint (&symfile_complaints
,
15001 _("line number info header doesn't "
15002 "fit in `.debug_line' section"));
15004 discard_cleanups (back_to
);
15008 /* Subroutine of dwarf_decode_lines to simplify it.
15009 Return the file name of the psymtab for included file FILE_INDEX
15010 in line header LH of PST.
15011 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15012 If space for the result is malloc'd, it will be freed by a cleanup.
15013 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
15016 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
15017 const struct partial_symtab
*pst
,
15018 const char *comp_dir
)
15020 const struct file_entry fe
= lh
->file_names
[file_index
];
15021 char *include_name
= fe
.name
;
15022 char *include_name_to_compare
= include_name
;
15023 char *dir_name
= NULL
;
15024 const char *pst_filename
;
15025 char *copied_name
= NULL
;
15029 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
15031 if (!IS_ABSOLUTE_PATH (include_name
)
15032 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
15034 /* Avoid creating a duplicate psymtab for PST.
15035 We do this by comparing INCLUDE_NAME and PST_FILENAME.
15036 Before we do the comparison, however, we need to account
15037 for DIR_NAME and COMP_DIR.
15038 First prepend dir_name (if non-NULL). If we still don't
15039 have an absolute path prepend comp_dir (if non-NULL).
15040 However, the directory we record in the include-file's
15041 psymtab does not contain COMP_DIR (to match the
15042 corresponding symtab(s)).
15047 bash$ gcc -g ./hello.c
15048 include_name = "hello.c"
15050 DW_AT_comp_dir = comp_dir = "/tmp"
15051 DW_AT_name = "./hello.c" */
15053 if (dir_name
!= NULL
)
15055 include_name
= concat (dir_name
, SLASH_STRING
,
15056 include_name
, (char *)NULL
);
15057 include_name_to_compare
= include_name
;
15058 make_cleanup (xfree
, include_name
);
15060 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
15062 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
15063 include_name
, (char *)NULL
);
15067 pst_filename
= pst
->filename
;
15068 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
15070 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
15071 pst_filename
, (char *)NULL
);
15072 pst_filename
= copied_name
;
15075 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
15077 if (include_name_to_compare
!= include_name
)
15078 xfree (include_name_to_compare
);
15079 if (copied_name
!= NULL
)
15080 xfree (copied_name
);
15084 return include_name
;
15087 /* Ignore this record_line request. */
15090 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15095 /* Subroutine of dwarf_decode_lines to simplify it.
15096 Process the line number information in LH. */
15099 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
15100 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
15102 gdb_byte
*line_ptr
, *extended_end
;
15103 gdb_byte
*line_end
;
15104 unsigned int bytes_read
, extended_len
;
15105 unsigned char op_code
, extended_op
, adj_opcode
;
15106 CORE_ADDR baseaddr
;
15107 struct objfile
*objfile
= cu
->objfile
;
15108 bfd
*abfd
= objfile
->obfd
;
15109 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15110 const int decode_for_pst_p
= (pst
!= NULL
);
15111 struct subfile
*last_subfile
= NULL
;
15112 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15115 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15117 line_ptr
= lh
->statement_program_start
;
15118 line_end
= lh
->statement_program_end
;
15120 /* Read the statement sequences until there's nothing left. */
15121 while (line_ptr
< line_end
)
15123 /* state machine registers */
15124 CORE_ADDR address
= 0;
15125 unsigned int file
= 1;
15126 unsigned int line
= 1;
15127 unsigned int column
= 0;
15128 int is_stmt
= lh
->default_is_stmt
;
15129 int basic_block
= 0;
15130 int end_sequence
= 0;
15132 unsigned char op_index
= 0;
15134 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
15136 /* Start a subfile for the current file of the state machine. */
15137 /* lh->include_dirs and lh->file_names are 0-based, but the
15138 directory and file name numbers in the statement program
15140 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15144 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15146 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15149 /* Decode the table. */
15150 while (!end_sequence
)
15152 op_code
= read_1_byte (abfd
, line_ptr
);
15154 if (line_ptr
> line_end
)
15156 dwarf2_debug_line_missing_end_sequence_complaint ();
15160 if (op_code
>= lh
->opcode_base
)
15162 /* Special operand. */
15163 adj_opcode
= op_code
- lh
->opcode_base
;
15164 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
15165 / lh
->maximum_ops_per_instruction
)
15166 * lh
->minimum_instruction_length
);
15167 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
15168 % lh
->maximum_ops_per_instruction
);
15169 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
15170 if (lh
->num_file_names
< file
|| file
== 0)
15171 dwarf2_debug_line_missing_file_complaint ();
15172 /* For now we ignore lines not starting on an
15173 instruction boundary. */
15174 else if (op_index
== 0)
15176 lh
->file_names
[file
- 1].included_p
= 1;
15177 if (!decode_for_pst_p
&& is_stmt
)
15179 if (last_subfile
!= current_subfile
)
15181 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15183 (*p_record_line
) (last_subfile
, 0, addr
);
15184 last_subfile
= current_subfile
;
15186 /* Append row to matrix using current values. */
15187 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15188 (*p_record_line
) (current_subfile
, line
, addr
);
15193 else switch (op_code
)
15195 case DW_LNS_extended_op
:
15196 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
15198 line_ptr
+= bytes_read
;
15199 extended_end
= line_ptr
+ extended_len
;
15200 extended_op
= read_1_byte (abfd
, line_ptr
);
15202 switch (extended_op
)
15204 case DW_LNE_end_sequence
:
15205 p_record_line
= record_line
;
15208 case DW_LNE_set_address
:
15209 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
15211 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15213 /* This line table is for a function which has been
15214 GCd by the linker. Ignore it. PR gdb/12528 */
15217 = line_ptr
- get_debug_line_section (cu
)->buffer
;
15219 complaint (&symfile_complaints
,
15220 _(".debug_line address at offset 0x%lx is 0 "
15222 line_offset
, objfile
->name
);
15223 p_record_line
= noop_record_line
;
15227 line_ptr
+= bytes_read
;
15228 address
+= baseaddr
;
15230 case DW_LNE_define_file
:
15233 unsigned int dir_index
, mod_time
, length
;
15235 cur_file
= read_direct_string (abfd
, line_ptr
,
15237 line_ptr
+= bytes_read
;
15239 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15240 line_ptr
+= bytes_read
;
15242 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15243 line_ptr
+= bytes_read
;
15245 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15246 line_ptr
+= bytes_read
;
15247 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15250 case DW_LNE_set_discriminator
:
15251 /* The discriminator is not interesting to the debugger;
15253 line_ptr
= extended_end
;
15256 complaint (&symfile_complaints
,
15257 _("mangled .debug_line section"));
15260 /* Make sure that we parsed the extended op correctly. If e.g.
15261 we expected a different address size than the producer used,
15262 we may have read the wrong number of bytes. */
15263 if (line_ptr
!= extended_end
)
15265 complaint (&symfile_complaints
,
15266 _("mangled .debug_line section"));
15271 if (lh
->num_file_names
< file
|| file
== 0)
15272 dwarf2_debug_line_missing_file_complaint ();
15275 lh
->file_names
[file
- 1].included_p
= 1;
15276 if (!decode_for_pst_p
&& is_stmt
)
15278 if (last_subfile
!= current_subfile
)
15280 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15282 (*p_record_line
) (last_subfile
, 0, addr
);
15283 last_subfile
= current_subfile
;
15285 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15286 (*p_record_line
) (current_subfile
, line
, addr
);
15291 case DW_LNS_advance_pc
:
15294 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15296 address
+= (((op_index
+ adjust
)
15297 / lh
->maximum_ops_per_instruction
)
15298 * lh
->minimum_instruction_length
);
15299 op_index
= ((op_index
+ adjust
)
15300 % lh
->maximum_ops_per_instruction
);
15301 line_ptr
+= bytes_read
;
15304 case DW_LNS_advance_line
:
15305 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
15306 line_ptr
+= bytes_read
;
15308 case DW_LNS_set_file
:
15310 /* The arrays lh->include_dirs and lh->file_names are
15311 0-based, but the directory and file name numbers in
15312 the statement program are 1-based. */
15313 struct file_entry
*fe
;
15316 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15317 line_ptr
+= bytes_read
;
15318 if (lh
->num_file_names
< file
|| file
== 0)
15319 dwarf2_debug_line_missing_file_complaint ();
15322 fe
= &lh
->file_names
[file
- 1];
15324 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15325 if (!decode_for_pst_p
)
15327 last_subfile
= current_subfile
;
15328 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15333 case DW_LNS_set_column
:
15334 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15335 line_ptr
+= bytes_read
;
15337 case DW_LNS_negate_stmt
:
15338 is_stmt
= (!is_stmt
);
15340 case DW_LNS_set_basic_block
:
15343 /* Add to the address register of the state machine the
15344 address increment value corresponding to special opcode
15345 255. I.e., this value is scaled by the minimum
15346 instruction length since special opcode 255 would have
15347 scaled the increment. */
15348 case DW_LNS_const_add_pc
:
15350 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
15352 address
+= (((op_index
+ adjust
)
15353 / lh
->maximum_ops_per_instruction
)
15354 * lh
->minimum_instruction_length
);
15355 op_index
= ((op_index
+ adjust
)
15356 % lh
->maximum_ops_per_instruction
);
15359 case DW_LNS_fixed_advance_pc
:
15360 address
+= read_2_bytes (abfd
, line_ptr
);
15366 /* Unknown standard opcode, ignore it. */
15369 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
15371 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15372 line_ptr
+= bytes_read
;
15377 if (lh
->num_file_names
< file
|| file
== 0)
15378 dwarf2_debug_line_missing_file_complaint ();
15381 lh
->file_names
[file
- 1].included_p
= 1;
15382 if (!decode_for_pst_p
)
15384 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15385 (*p_record_line
) (current_subfile
, 0, addr
);
15391 /* Decode the Line Number Program (LNP) for the given line_header
15392 structure and CU. The actual information extracted and the type
15393 of structures created from the LNP depends on the value of PST.
15395 1. If PST is NULL, then this procedure uses the data from the program
15396 to create all necessary symbol tables, and their linetables.
15398 2. If PST is not NULL, this procedure reads the program to determine
15399 the list of files included by the unit represented by PST, and
15400 builds all the associated partial symbol tables.
15402 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15403 It is used for relative paths in the line table.
15404 NOTE: When processing partial symtabs (pst != NULL),
15405 comp_dir == pst->dirname.
15407 NOTE: It is important that psymtabs have the same file name (via strcmp)
15408 as the corresponding symtab. Since COMP_DIR is not used in the name of the
15409 symtab we don't use it in the name of the psymtabs we create.
15410 E.g. expand_line_sal requires this when finding psymtabs to expand.
15411 A good testcase for this is mb-inline.exp. */
15414 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
15415 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
15416 int want_line_info
)
15418 struct objfile
*objfile
= cu
->objfile
;
15419 const int decode_for_pst_p
= (pst
!= NULL
);
15420 struct subfile
*first_subfile
= current_subfile
;
15422 if (want_line_info
)
15423 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
15425 if (decode_for_pst_p
)
15429 /* Now that we're done scanning the Line Header Program, we can
15430 create the psymtab of each included file. */
15431 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
15432 if (lh
->file_names
[file_index
].included_p
== 1)
15434 char *include_name
=
15435 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
15436 if (include_name
!= NULL
)
15437 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
15442 /* Make sure a symtab is created for every file, even files
15443 which contain only variables (i.e. no code with associated
15447 for (i
= 0; i
< lh
->num_file_names
; i
++)
15450 struct file_entry
*fe
;
15452 fe
= &lh
->file_names
[i
];
15454 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15455 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15457 /* Skip the main file; we don't need it, and it must be
15458 allocated last, so that it will show up before the
15459 non-primary symtabs in the objfile's symtab list. */
15460 if (current_subfile
== first_subfile
)
15463 if (current_subfile
->symtab
== NULL
)
15464 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
15466 fe
->symtab
= current_subfile
->symtab
;
15471 /* Start a subfile for DWARF. FILENAME is the name of the file and
15472 DIRNAME the name of the source directory which contains FILENAME
15473 or NULL if not known. COMP_DIR is the compilation directory for the
15474 linetable's compilation unit or NULL if not known.
15475 This routine tries to keep line numbers from identical absolute and
15476 relative file names in a common subfile.
15478 Using the `list' example from the GDB testsuite, which resides in
15479 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
15480 of /srcdir/list0.c yields the following debugging information for list0.c:
15482 DW_AT_name: /srcdir/list0.c
15483 DW_AT_comp_dir: /compdir
15484 files.files[0].name: list0.h
15485 files.files[0].dir: /srcdir
15486 files.files[1].name: list0.c
15487 files.files[1].dir: /srcdir
15489 The line number information for list0.c has to end up in a single
15490 subfile, so that `break /srcdir/list0.c:1' works as expected.
15491 start_subfile will ensure that this happens provided that we pass the
15492 concatenation of files.files[1].dir and files.files[1].name as the
15496 dwarf2_start_subfile (char *filename
, const char *dirname
,
15497 const char *comp_dir
)
15501 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
15502 `start_symtab' will always pass the contents of DW_AT_comp_dir as
15503 second argument to start_subfile. To be consistent, we do the
15504 same here. In order not to lose the line information directory,
15505 we concatenate it to the filename when it makes sense.
15506 Note that the Dwarf3 standard says (speaking of filenames in line
15507 information): ``The directory index is ignored for file names
15508 that represent full path names''. Thus ignoring dirname in the
15509 `else' branch below isn't an issue. */
15511 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
15512 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
15514 fullname
= filename
;
15516 start_subfile (fullname
, comp_dir
);
15518 if (fullname
!= filename
)
15522 /* Start a symtab for DWARF.
15523 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
15526 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
15527 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
15529 start_symtab (name
, comp_dir
, low_pc
);
15530 record_debugformat ("DWARF 2");
15531 record_producer (cu
->producer
);
15533 /* We assume that we're processing GCC output. */
15534 processing_gcc_compilation
= 2;
15536 processing_has_namespace_info
= 0;
15540 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
15541 struct dwarf2_cu
*cu
)
15543 struct objfile
*objfile
= cu
->objfile
;
15544 struct comp_unit_head
*cu_header
= &cu
->header
;
15546 /* NOTE drow/2003-01-30: There used to be a comment and some special
15547 code here to turn a symbol with DW_AT_external and a
15548 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
15549 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
15550 with some versions of binutils) where shared libraries could have
15551 relocations against symbols in their debug information - the
15552 minimal symbol would have the right address, but the debug info
15553 would not. It's no longer necessary, because we will explicitly
15554 apply relocations when we read in the debug information now. */
15556 /* A DW_AT_location attribute with no contents indicates that a
15557 variable has been optimized away. */
15558 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
15560 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15564 /* Handle one degenerate form of location expression specially, to
15565 preserve GDB's previous behavior when section offsets are
15566 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
15567 then mark this symbol as LOC_STATIC. */
15569 if (attr_form_is_block (attr
)
15570 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
15571 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
15572 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
15573 && (DW_BLOCK (attr
)->size
15574 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
15576 unsigned int dummy
;
15578 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
15579 SYMBOL_VALUE_ADDRESS (sym
) =
15580 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
15582 SYMBOL_VALUE_ADDRESS (sym
) =
15583 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
15584 SYMBOL_CLASS (sym
) = LOC_STATIC
;
15585 fixup_symbol_section (sym
, objfile
);
15586 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
15587 SYMBOL_SECTION (sym
));
15591 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
15592 expression evaluator, and use LOC_COMPUTED only when necessary
15593 (i.e. when the value of a register or memory location is
15594 referenced, or a thread-local block, etc.). Then again, it might
15595 not be worthwhile. I'm assuming that it isn't unless performance
15596 or memory numbers show me otherwise. */
15598 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
15599 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15601 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
15602 cu
->has_loclist
= 1;
15605 /* Given a pointer to a DWARF information entry, figure out if we need
15606 to make a symbol table entry for it, and if so, create a new entry
15607 and return a pointer to it.
15608 If TYPE is NULL, determine symbol type from the die, otherwise
15609 used the passed type.
15610 If SPACE is not NULL, use it to hold the new symbol. If it is
15611 NULL, allocate a new symbol on the objfile's obstack. */
15613 static struct symbol
*
15614 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
15615 struct symbol
*space
)
15617 struct objfile
*objfile
= cu
->objfile
;
15618 struct symbol
*sym
= NULL
;
15620 struct attribute
*attr
= NULL
;
15621 struct attribute
*attr2
= NULL
;
15622 CORE_ADDR baseaddr
;
15623 struct pending
**list_to_add
= NULL
;
15625 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
15627 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15629 name
= dwarf2_name (die
, cu
);
15632 const char *linkagename
;
15633 int suppress_add
= 0;
15638 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
15639 OBJSTAT (objfile
, n_syms
++);
15641 /* Cache this symbol's name and the name's demangled form (if any). */
15642 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
15643 linkagename
= dwarf2_physname (name
, die
, cu
);
15644 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
15646 /* Fortran does not have mangling standard and the mangling does differ
15647 between gfortran, iFort etc. */
15648 if (cu
->language
== language_fortran
15649 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
15650 symbol_set_demangled_name (&(sym
->ginfo
),
15651 (char *) dwarf2_full_name (name
, die
, cu
),
15654 /* Default assumptions.
15655 Use the passed type or decode it from the die. */
15656 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15657 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15659 SYMBOL_TYPE (sym
) = type
;
15661 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
15662 attr
= dwarf2_attr (die
,
15663 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
15667 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
15670 attr
= dwarf2_attr (die
,
15671 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
15675 int file_index
= DW_UNSND (attr
);
15677 if (cu
->line_header
== NULL
15678 || file_index
> cu
->line_header
->num_file_names
)
15679 complaint (&symfile_complaints
,
15680 _("file index out of range"));
15681 else if (file_index
> 0)
15683 struct file_entry
*fe
;
15685 fe
= &cu
->line_header
->file_names
[file_index
- 1];
15686 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
15693 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15696 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
15698 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
15699 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
15700 SYMBOL_CLASS (sym
) = LOC_LABEL
;
15701 add_symbol_to_list (sym
, cu
->list_in_scope
);
15703 case DW_TAG_subprogram
:
15704 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15706 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15707 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15708 if ((attr2
&& (DW_UNSND (attr2
) != 0))
15709 || cu
->language
== language_ada
)
15711 /* Subprograms marked external are stored as a global symbol.
15712 Ada subprograms, whether marked external or not, are always
15713 stored as a global symbol, because we want to be able to
15714 access them globally. For instance, we want to be able
15715 to break on a nested subprogram without having to
15716 specify the context. */
15717 list_to_add
= &global_symbols
;
15721 list_to_add
= cu
->list_in_scope
;
15724 case DW_TAG_inlined_subroutine
:
15725 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15727 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15728 SYMBOL_INLINED (sym
) = 1;
15729 list_to_add
= cu
->list_in_scope
;
15731 case DW_TAG_template_value_param
:
15733 /* Fall through. */
15734 case DW_TAG_constant
:
15735 case DW_TAG_variable
:
15736 case DW_TAG_member
:
15737 /* Compilation with minimal debug info may result in
15738 variables with missing type entries. Change the
15739 misleading `void' type to something sensible. */
15740 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
15742 = objfile_type (objfile
)->nodebug_data_symbol
;
15744 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15745 /* In the case of DW_TAG_member, we should only be called for
15746 static const members. */
15747 if (die
->tag
== DW_TAG_member
)
15749 /* dwarf2_add_field uses die_is_declaration,
15750 so we do the same. */
15751 gdb_assert (die_is_declaration (die
, cu
));
15756 dwarf2_const_value (attr
, sym
, cu
);
15757 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15760 if (attr2
&& (DW_UNSND (attr2
) != 0))
15761 list_to_add
= &global_symbols
;
15763 list_to_add
= cu
->list_in_scope
;
15767 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15770 var_decode_location (attr
, sym
, cu
);
15771 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15773 /* Fortran explicitly imports any global symbols to the local
15774 scope by DW_TAG_common_block. */
15775 if (cu
->language
== language_fortran
&& die
->parent
15776 && die
->parent
->tag
== DW_TAG_common_block
)
15779 if (SYMBOL_CLASS (sym
) == LOC_STATIC
15780 && SYMBOL_VALUE_ADDRESS (sym
) == 0
15781 && !dwarf2_per_objfile
->has_section_at_zero
)
15783 /* When a static variable is eliminated by the linker,
15784 the corresponding debug information is not stripped
15785 out, but the variable address is set to null;
15786 do not add such variables into symbol table. */
15788 else if (attr2
&& (DW_UNSND (attr2
) != 0))
15790 /* Workaround gfortran PR debug/40040 - it uses
15791 DW_AT_location for variables in -fPIC libraries which may
15792 get overriden by other libraries/executable and get
15793 a different address. Resolve it by the minimal symbol
15794 which may come from inferior's executable using copy
15795 relocation. Make this workaround only for gfortran as for
15796 other compilers GDB cannot guess the minimal symbol
15797 Fortran mangling kind. */
15798 if (cu
->language
== language_fortran
&& die
->parent
15799 && die
->parent
->tag
== DW_TAG_module
15801 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
15802 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15804 /* A variable with DW_AT_external is never static,
15805 but it may be block-scoped. */
15806 list_to_add
= (cu
->list_in_scope
== &file_symbols
15807 ? &global_symbols
: cu
->list_in_scope
);
15810 list_to_add
= cu
->list_in_scope
;
15814 /* We do not know the address of this symbol.
15815 If it is an external symbol and we have type information
15816 for it, enter the symbol as a LOC_UNRESOLVED symbol.
15817 The address of the variable will then be determined from
15818 the minimal symbol table whenever the variable is
15820 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15822 /* Fortran explicitly imports any global symbols to the local
15823 scope by DW_TAG_common_block. */
15824 if (cu
->language
== language_fortran
&& die
->parent
15825 && die
->parent
->tag
== DW_TAG_common_block
)
15827 /* SYMBOL_CLASS doesn't matter here because
15828 read_common_block is going to reset it. */
15830 list_to_add
= cu
->list_in_scope
;
15832 else if (attr2
&& (DW_UNSND (attr2
) != 0)
15833 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
15835 /* A variable with DW_AT_external is never static, but it
15836 may be block-scoped. */
15837 list_to_add
= (cu
->list_in_scope
== &file_symbols
15838 ? &global_symbols
: cu
->list_in_scope
);
15840 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15842 else if (!die_is_declaration (die
, cu
))
15844 /* Use the default LOC_OPTIMIZED_OUT class. */
15845 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
15847 list_to_add
= cu
->list_in_scope
;
15851 case DW_TAG_formal_parameter
:
15852 /* If we are inside a function, mark this as an argument. If
15853 not, we might be looking at an argument to an inlined function
15854 when we do not have enough information to show inlined frames;
15855 pretend it's a local variable in that case so that the user can
15857 if (context_stack_depth
> 0
15858 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
15859 SYMBOL_IS_ARGUMENT (sym
) = 1;
15860 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15863 var_decode_location (attr
, sym
, cu
);
15865 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15868 dwarf2_const_value (attr
, sym
, cu
);
15871 list_to_add
= cu
->list_in_scope
;
15873 case DW_TAG_unspecified_parameters
:
15874 /* From varargs functions; gdb doesn't seem to have any
15875 interest in this information, so just ignore it for now.
15878 case DW_TAG_template_type_param
:
15880 /* Fall through. */
15881 case DW_TAG_class_type
:
15882 case DW_TAG_interface_type
:
15883 case DW_TAG_structure_type
:
15884 case DW_TAG_union_type
:
15885 case DW_TAG_set_type
:
15886 case DW_TAG_enumeration_type
:
15887 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15888 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
15891 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
15892 really ever be static objects: otherwise, if you try
15893 to, say, break of a class's method and you're in a file
15894 which doesn't mention that class, it won't work unless
15895 the check for all static symbols in lookup_symbol_aux
15896 saves you. See the OtherFileClass tests in
15897 gdb.c++/namespace.exp. */
15901 list_to_add
= (cu
->list_in_scope
== &file_symbols
15902 && (cu
->language
== language_cplus
15903 || cu
->language
== language_java
)
15904 ? &global_symbols
: cu
->list_in_scope
);
15906 /* The semantics of C++ state that "struct foo {
15907 ... }" also defines a typedef for "foo". A Java
15908 class declaration also defines a typedef for the
15910 if (cu
->language
== language_cplus
15911 || cu
->language
== language_java
15912 || cu
->language
== language_ada
)
15914 /* The symbol's name is already allocated along
15915 with this objfile, so we don't need to
15916 duplicate it for the type. */
15917 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
15918 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
15923 case DW_TAG_typedef
:
15924 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15925 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15926 list_to_add
= cu
->list_in_scope
;
15928 case DW_TAG_base_type
:
15929 case DW_TAG_subrange_type
:
15930 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15931 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15932 list_to_add
= cu
->list_in_scope
;
15934 case DW_TAG_enumerator
:
15935 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15938 dwarf2_const_value (attr
, sym
, cu
);
15941 /* NOTE: carlton/2003-11-10: See comment above in the
15942 DW_TAG_class_type, etc. block. */
15944 list_to_add
= (cu
->list_in_scope
== &file_symbols
15945 && (cu
->language
== language_cplus
15946 || cu
->language
== language_java
)
15947 ? &global_symbols
: cu
->list_in_scope
);
15950 case DW_TAG_namespace
:
15951 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15952 list_to_add
= &global_symbols
;
15954 case DW_TAG_common_block
:
15955 SYMBOL_CLASS (sym
) = LOC_STATIC
;
15956 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
15957 add_symbol_to_list (sym
, cu
->list_in_scope
);
15960 /* Not a tag we recognize. Hopefully we aren't processing
15961 trash data, but since we must specifically ignore things
15962 we don't recognize, there is nothing else we should do at
15964 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
15965 dwarf_tag_name (die
->tag
));
15971 sym
->hash_next
= objfile
->template_symbols
;
15972 objfile
->template_symbols
= sym
;
15973 list_to_add
= NULL
;
15976 if (list_to_add
!= NULL
)
15977 add_symbol_to_list (sym
, list_to_add
);
15979 /* For the benefit of old versions of GCC, check for anonymous
15980 namespaces based on the demangled name. */
15981 if (!processing_has_namespace_info
15982 && cu
->language
== language_cplus
)
15983 cp_scan_for_anonymous_namespaces (sym
, objfile
);
15988 /* A wrapper for new_symbol_full that always allocates a new symbol. */
15990 static struct symbol
*
15991 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15993 return new_symbol_full (die
, type
, cu
, NULL
);
15996 /* Given an attr with a DW_FORM_dataN value in host byte order,
15997 zero-extend it as appropriate for the symbol's type. The DWARF
15998 standard (v4) is not entirely clear about the meaning of using
15999 DW_FORM_dataN for a constant with a signed type, where the type is
16000 wider than the data. The conclusion of a discussion on the DWARF
16001 list was that this is unspecified. We choose to always zero-extend
16002 because that is the interpretation long in use by GCC. */
16005 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
16006 const char *name
, struct obstack
*obstack
,
16007 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
16009 struct objfile
*objfile
= cu
->objfile
;
16010 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
16011 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
16012 LONGEST l
= DW_UNSND (attr
);
16014 if (bits
< sizeof (*value
) * 8)
16016 l
&= ((LONGEST
) 1 << bits
) - 1;
16019 else if (bits
== sizeof (*value
) * 8)
16023 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
16024 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
16031 /* Read a constant value from an attribute. Either set *VALUE, or if
16032 the value does not fit in *VALUE, set *BYTES - either already
16033 allocated on the objfile obstack, or newly allocated on OBSTACK,
16034 or, set *BATON, if we translated the constant to a location
16038 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
16039 const char *name
, struct obstack
*obstack
,
16040 struct dwarf2_cu
*cu
,
16041 LONGEST
*value
, gdb_byte
**bytes
,
16042 struct dwarf2_locexpr_baton
**baton
)
16044 struct objfile
*objfile
= cu
->objfile
;
16045 struct comp_unit_head
*cu_header
= &cu
->header
;
16046 struct dwarf_block
*blk
;
16047 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
16048 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
16054 switch (attr
->form
)
16057 case DW_FORM_GNU_addr_index
:
16061 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
16062 dwarf2_const_value_length_mismatch_complaint (name
,
16063 cu_header
->addr_size
,
16064 TYPE_LENGTH (type
));
16065 /* Symbols of this form are reasonably rare, so we just
16066 piggyback on the existing location code rather than writing
16067 a new implementation of symbol_computed_ops. */
16068 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
16069 sizeof (struct dwarf2_locexpr_baton
));
16070 (*baton
)->per_cu
= cu
->per_cu
;
16071 gdb_assert ((*baton
)->per_cu
);
16073 (*baton
)->size
= 2 + cu_header
->addr_size
;
16074 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
16075 (*baton
)->data
= data
;
16077 data
[0] = DW_OP_addr
;
16078 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
16079 byte_order
, DW_ADDR (attr
));
16080 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
16083 case DW_FORM_string
:
16085 case DW_FORM_GNU_str_index
:
16086 case DW_FORM_GNU_strp_alt
:
16087 /* DW_STRING is already allocated on the objfile obstack, point
16089 *bytes
= (gdb_byte
*) DW_STRING (attr
);
16091 case DW_FORM_block1
:
16092 case DW_FORM_block2
:
16093 case DW_FORM_block4
:
16094 case DW_FORM_block
:
16095 case DW_FORM_exprloc
:
16096 blk
= DW_BLOCK (attr
);
16097 if (TYPE_LENGTH (type
) != blk
->size
)
16098 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
16099 TYPE_LENGTH (type
));
16100 *bytes
= blk
->data
;
16103 /* The DW_AT_const_value attributes are supposed to carry the
16104 symbol's value "represented as it would be on the target
16105 architecture." By the time we get here, it's already been
16106 converted to host endianness, so we just need to sign- or
16107 zero-extend it as appropriate. */
16108 case DW_FORM_data1
:
16109 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16110 obstack
, cu
, value
, 8);
16112 case DW_FORM_data2
:
16113 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16114 obstack
, cu
, value
, 16);
16116 case DW_FORM_data4
:
16117 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16118 obstack
, cu
, value
, 32);
16120 case DW_FORM_data8
:
16121 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16122 obstack
, cu
, value
, 64);
16125 case DW_FORM_sdata
:
16126 *value
= DW_SND (attr
);
16129 case DW_FORM_udata
:
16130 *value
= DW_UNSND (attr
);
16134 complaint (&symfile_complaints
,
16135 _("unsupported const value attribute form: '%s'"),
16136 dwarf_form_name (attr
->form
));
16143 /* Copy constant value from an attribute to a symbol. */
16146 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
16147 struct dwarf2_cu
*cu
)
16149 struct objfile
*objfile
= cu
->objfile
;
16150 struct comp_unit_head
*cu_header
= &cu
->header
;
16153 struct dwarf2_locexpr_baton
*baton
;
16155 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
16156 SYMBOL_PRINT_NAME (sym
),
16157 &objfile
->objfile_obstack
, cu
,
16158 &value
, &bytes
, &baton
);
16162 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16163 SYMBOL_LOCATION_BATON (sym
) = baton
;
16164 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
16166 else if (bytes
!= NULL
)
16168 SYMBOL_VALUE_BYTES (sym
) = bytes
;
16169 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
16173 SYMBOL_VALUE (sym
) = value
;
16174 SYMBOL_CLASS (sym
) = LOC_CONST
;
16178 /* Return the type of the die in question using its DW_AT_type attribute. */
16180 static struct type
*
16181 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16183 struct attribute
*type_attr
;
16185 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16188 /* A missing DW_AT_type represents a void type. */
16189 return objfile_type (cu
->objfile
)->builtin_void
;
16192 return lookup_die_type (die
, type_attr
, cu
);
16195 /* True iff CU's producer generates GNAT Ada auxiliary information
16196 that allows to find parallel types through that information instead
16197 of having to do expensive parallel lookups by type name. */
16200 need_gnat_info (struct dwarf2_cu
*cu
)
16202 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
16203 of GNAT produces this auxiliary information, without any indication
16204 that it is produced. Part of enhancing the FSF version of GNAT
16205 to produce that information will be to put in place an indicator
16206 that we can use in order to determine whether the descriptive type
16207 info is available or not. One suggestion that has been made is
16208 to use a new attribute, attached to the CU die. For now, assume
16209 that the descriptive type info is not available. */
16213 /* Return the auxiliary type of the die in question using its
16214 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
16215 attribute is not present. */
16217 static struct type
*
16218 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16220 struct attribute
*type_attr
;
16222 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
16226 return lookup_die_type (die
, type_attr
, cu
);
16229 /* If DIE has a descriptive_type attribute, then set the TYPE's
16230 descriptive type accordingly. */
16233 set_descriptive_type (struct type
*type
, struct die_info
*die
,
16234 struct dwarf2_cu
*cu
)
16236 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
16238 if (descriptive_type
)
16240 ALLOCATE_GNAT_AUX_TYPE (type
);
16241 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
16245 /* Return the containing type of the die in question using its
16246 DW_AT_containing_type attribute. */
16248 static struct type
*
16249 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16251 struct attribute
*type_attr
;
16253 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
16255 error (_("Dwarf Error: Problem turning containing type into gdb type "
16256 "[in module %s]"), cu
->objfile
->name
);
16258 return lookup_die_type (die
, type_attr
, cu
);
16261 /* Look up the type of DIE in CU using its type attribute ATTR.
16262 If there is no type substitute an error marker. */
16264 static struct type
*
16265 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
16266 struct dwarf2_cu
*cu
)
16268 struct objfile
*objfile
= cu
->objfile
;
16269 struct type
*this_type
;
16271 /* First see if we have it cached. */
16273 if (attr
->form
== DW_FORM_GNU_ref_alt
)
16275 struct dwarf2_per_cu_data
*per_cu
;
16276 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16278 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
16279 this_type
= get_die_type_at_offset (offset
, per_cu
);
16281 else if (is_ref_attr (attr
))
16283 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16285 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
16287 else if (attr
->form
== DW_FORM_ref_sig8
)
16289 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16291 /* sig_type will be NULL if the signatured type is missing from
16293 if (sig_type
== NULL
)
16294 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16295 "at 0x%x [in module %s]"),
16296 die
->offset
.sect_off
, objfile
->name
);
16298 gdb_assert (sig_type
->per_cu
.is_debug_types
);
16299 /* If we haven't filled in type_offset_in_section yet, then we
16300 haven't read the type in yet. */
16302 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
16305 get_die_type_at_offset (sig_type
->type_offset_in_section
,
16306 &sig_type
->per_cu
);
16311 dump_die_for_error (die
);
16312 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
16313 dwarf_attr_name (attr
->name
), objfile
->name
);
16316 /* If not cached we need to read it in. */
16318 if (this_type
== NULL
)
16320 struct die_info
*type_die
;
16321 struct dwarf2_cu
*type_cu
= cu
;
16323 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
16324 /* If we found the type now, it's probably because the type came
16325 from an inter-CU reference and the type's CU got expanded before
16327 this_type
= get_die_type (type_die
, type_cu
);
16328 if (this_type
== NULL
)
16329 this_type
= read_type_die_1 (type_die
, type_cu
);
16332 /* If we still don't have a type use an error marker. */
16334 if (this_type
== NULL
)
16336 char *message
, *saved
;
16338 /* read_type_die already issued a complaint. */
16339 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
16341 cu
->header
.offset
.sect_off
,
16342 die
->offset
.sect_off
);
16343 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
16344 message
, strlen (message
));
16347 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
16353 /* Return the type in DIE, CU.
16354 Returns NULL for invalid types.
16356 This first does a lookup in the appropriate type_hash table,
16357 and only reads the die in if necessary.
16359 NOTE: This can be called when reading in partial or full symbols. */
16361 static struct type
*
16362 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
16364 struct type
*this_type
;
16366 this_type
= get_die_type (die
, cu
);
16370 return read_type_die_1 (die
, cu
);
16373 /* Read the type in DIE, CU.
16374 Returns NULL for invalid types. */
16376 static struct type
*
16377 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
16379 struct type
*this_type
= NULL
;
16383 case DW_TAG_class_type
:
16384 case DW_TAG_interface_type
:
16385 case DW_TAG_structure_type
:
16386 case DW_TAG_union_type
:
16387 this_type
= read_structure_type (die
, cu
);
16389 case DW_TAG_enumeration_type
:
16390 this_type
= read_enumeration_type (die
, cu
);
16392 case DW_TAG_subprogram
:
16393 case DW_TAG_subroutine_type
:
16394 case DW_TAG_inlined_subroutine
:
16395 this_type
= read_subroutine_type (die
, cu
);
16397 case DW_TAG_array_type
:
16398 this_type
= read_array_type (die
, cu
);
16400 case DW_TAG_set_type
:
16401 this_type
= read_set_type (die
, cu
);
16403 case DW_TAG_pointer_type
:
16404 this_type
= read_tag_pointer_type (die
, cu
);
16406 case DW_TAG_ptr_to_member_type
:
16407 this_type
= read_tag_ptr_to_member_type (die
, cu
);
16409 case DW_TAG_reference_type
:
16410 this_type
= read_tag_reference_type (die
, cu
);
16412 case DW_TAG_const_type
:
16413 this_type
= read_tag_const_type (die
, cu
);
16415 case DW_TAG_volatile_type
:
16416 this_type
= read_tag_volatile_type (die
, cu
);
16418 case DW_TAG_string_type
:
16419 this_type
= read_tag_string_type (die
, cu
);
16421 case DW_TAG_typedef
:
16422 this_type
= read_typedef (die
, cu
);
16424 case DW_TAG_subrange_type
:
16425 this_type
= read_subrange_type (die
, cu
);
16427 case DW_TAG_base_type
:
16428 this_type
= read_base_type (die
, cu
);
16430 case DW_TAG_unspecified_type
:
16431 this_type
= read_unspecified_type (die
, cu
);
16433 case DW_TAG_namespace
:
16434 this_type
= read_namespace_type (die
, cu
);
16436 case DW_TAG_module
:
16437 this_type
= read_module_type (die
, cu
);
16440 complaint (&symfile_complaints
,
16441 _("unexpected tag in read_type_die: '%s'"),
16442 dwarf_tag_name (die
->tag
));
16449 /* See if we can figure out if the class lives in a namespace. We do
16450 this by looking for a member function; its demangled name will
16451 contain namespace info, if there is any.
16452 Return the computed name or NULL.
16453 Space for the result is allocated on the objfile's obstack.
16454 This is the full-die version of guess_partial_die_structure_name.
16455 In this case we know DIE has no useful parent. */
16458 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16460 struct die_info
*spec_die
;
16461 struct dwarf2_cu
*spec_cu
;
16462 struct die_info
*child
;
16465 spec_die
= die_specification (die
, &spec_cu
);
16466 if (spec_die
!= NULL
)
16472 for (child
= die
->child
;
16474 child
= child
->sibling
)
16476 if (child
->tag
== DW_TAG_subprogram
)
16478 struct attribute
*attr
;
16480 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
16482 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
16486 = language_class_name_from_physname (cu
->language_defn
,
16490 if (actual_name
!= NULL
)
16492 char *die_name
= dwarf2_name (die
, cu
);
16494 if (die_name
!= NULL
16495 && strcmp (die_name
, actual_name
) != 0)
16497 /* Strip off the class name from the full name.
16498 We want the prefix. */
16499 int die_name_len
= strlen (die_name
);
16500 int actual_name_len
= strlen (actual_name
);
16502 /* Test for '::' as a sanity check. */
16503 if (actual_name_len
> die_name_len
+ 2
16504 && actual_name
[actual_name_len
16505 - die_name_len
- 1] == ':')
16507 obsavestring (actual_name
,
16508 actual_name_len
- die_name_len
- 2,
16509 &cu
->objfile
->objfile_obstack
);
16512 xfree (actual_name
);
16521 /* GCC might emit a nameless typedef that has a linkage name. Determine the
16522 prefix part in such case. See
16523 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16526 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16528 struct attribute
*attr
;
16531 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
16532 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
16535 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16536 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
16539 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16541 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16542 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16545 /* dwarf2_name had to be already called. */
16546 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
16548 /* Strip the base name, keep any leading namespaces/classes. */
16549 base
= strrchr (DW_STRING (attr
), ':');
16550 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
16553 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
16554 &cu
->objfile
->objfile_obstack
);
16557 /* Return the name of the namespace/class that DIE is defined within,
16558 or "" if we can't tell. The caller should not xfree the result.
16560 For example, if we're within the method foo() in the following
16570 then determine_prefix on foo's die will return "N::C". */
16572 static const char *
16573 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16575 struct die_info
*parent
, *spec_die
;
16576 struct dwarf2_cu
*spec_cu
;
16577 struct type
*parent_type
;
16580 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
16581 && cu
->language
!= language_fortran
)
16584 retval
= anonymous_struct_prefix (die
, cu
);
16588 /* We have to be careful in the presence of DW_AT_specification.
16589 For example, with GCC 3.4, given the code
16593 // Definition of N::foo.
16597 then we'll have a tree of DIEs like this:
16599 1: DW_TAG_compile_unit
16600 2: DW_TAG_namespace // N
16601 3: DW_TAG_subprogram // declaration of N::foo
16602 4: DW_TAG_subprogram // definition of N::foo
16603 DW_AT_specification // refers to die #3
16605 Thus, when processing die #4, we have to pretend that we're in
16606 the context of its DW_AT_specification, namely the contex of die
16609 spec_die
= die_specification (die
, &spec_cu
);
16610 if (spec_die
== NULL
)
16611 parent
= die
->parent
;
16614 parent
= spec_die
->parent
;
16618 if (parent
== NULL
)
16620 else if (parent
->building_fullname
)
16623 const char *parent_name
;
16625 /* It has been seen on RealView 2.2 built binaries,
16626 DW_TAG_template_type_param types actually _defined_ as
16627 children of the parent class:
16630 template class <class Enum> Class{};
16631 Class<enum E> class_e;
16633 1: DW_TAG_class_type (Class)
16634 2: DW_TAG_enumeration_type (E)
16635 3: DW_TAG_enumerator (enum1:0)
16636 3: DW_TAG_enumerator (enum2:1)
16638 2: DW_TAG_template_type_param
16639 DW_AT_type DW_FORM_ref_udata (E)
16641 Besides being broken debug info, it can put GDB into an
16642 infinite loop. Consider:
16644 When we're building the full name for Class<E>, we'll start
16645 at Class, and go look over its template type parameters,
16646 finding E. We'll then try to build the full name of E, and
16647 reach here. We're now trying to build the full name of E,
16648 and look over the parent DIE for containing scope. In the
16649 broken case, if we followed the parent DIE of E, we'd again
16650 find Class, and once again go look at its template type
16651 arguments, etc., etc. Simply don't consider such parent die
16652 as source-level parent of this die (it can't be, the language
16653 doesn't allow it), and break the loop here. */
16654 name
= dwarf2_name (die
, cu
);
16655 parent_name
= dwarf2_name (parent
, cu
);
16656 complaint (&symfile_complaints
,
16657 _("template param type '%s' defined within parent '%s'"),
16658 name
? name
: "<unknown>",
16659 parent_name
? parent_name
: "<unknown>");
16663 switch (parent
->tag
)
16665 case DW_TAG_namespace
:
16666 parent_type
= read_type_die (parent
, cu
);
16667 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
16668 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
16669 Work around this problem here. */
16670 if (cu
->language
== language_cplus
16671 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
16673 /* We give a name to even anonymous namespaces. */
16674 return TYPE_TAG_NAME (parent_type
);
16675 case DW_TAG_class_type
:
16676 case DW_TAG_interface_type
:
16677 case DW_TAG_structure_type
:
16678 case DW_TAG_union_type
:
16679 case DW_TAG_module
:
16680 parent_type
= read_type_die (parent
, cu
);
16681 if (TYPE_TAG_NAME (parent_type
) != NULL
)
16682 return TYPE_TAG_NAME (parent_type
);
16684 /* An anonymous structure is only allowed non-static data
16685 members; no typedefs, no member functions, et cetera.
16686 So it does not need a prefix. */
16688 case DW_TAG_compile_unit
:
16689 case DW_TAG_partial_unit
:
16690 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
16691 if (cu
->language
== language_cplus
16692 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16693 && die
->child
!= NULL
16694 && (die
->tag
== DW_TAG_class_type
16695 || die
->tag
== DW_TAG_structure_type
16696 || die
->tag
== DW_TAG_union_type
))
16698 char *name
= guess_full_die_structure_name (die
, cu
);
16704 return determine_prefix (parent
, cu
);
16708 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
16709 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
16710 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
16711 an obconcat, otherwise allocate storage for the result. The CU argument is
16712 used to determine the language and hence, the appropriate separator. */
16714 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
16717 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
16718 int physname
, struct dwarf2_cu
*cu
)
16720 const char *lead
= "";
16723 if (suffix
== NULL
|| suffix
[0] == '\0'
16724 || prefix
== NULL
|| prefix
[0] == '\0')
16726 else if (cu
->language
== language_java
)
16728 else if (cu
->language
== language_fortran
&& physname
)
16730 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
16731 DW_AT_MIPS_linkage_name is preferred and used instead. */
16739 if (prefix
== NULL
)
16741 if (suffix
== NULL
)
16747 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
16749 strcpy (retval
, lead
);
16750 strcat (retval
, prefix
);
16751 strcat (retval
, sep
);
16752 strcat (retval
, suffix
);
16757 /* We have an obstack. */
16758 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
16762 /* Return sibling of die, NULL if no sibling. */
16764 static struct die_info
*
16765 sibling_die (struct die_info
*die
)
16767 return die
->sibling
;
16770 /* Get name of a die, return NULL if not found. */
16773 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
16774 struct obstack
*obstack
)
16776 if (name
&& cu
->language
== language_cplus
)
16778 char *canon_name
= cp_canonicalize_string (name
);
16780 if (canon_name
!= NULL
)
16782 if (strcmp (canon_name
, name
) != 0)
16783 name
= obsavestring (canon_name
, strlen (canon_name
),
16785 xfree (canon_name
);
16792 /* Get name of a die, return NULL if not found. */
16795 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16797 struct attribute
*attr
;
16799 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16800 if ((!attr
|| !DW_STRING (attr
))
16801 && die
->tag
!= DW_TAG_class_type
16802 && die
->tag
!= DW_TAG_interface_type
16803 && die
->tag
!= DW_TAG_structure_type
16804 && die
->tag
!= DW_TAG_union_type
)
16809 case DW_TAG_compile_unit
:
16810 case DW_TAG_partial_unit
:
16811 /* Compilation units have a DW_AT_name that is a filename, not
16812 a source language identifier. */
16813 case DW_TAG_enumeration_type
:
16814 case DW_TAG_enumerator
:
16815 /* These tags always have simple identifiers already; no need
16816 to canonicalize them. */
16817 return DW_STRING (attr
);
16819 case DW_TAG_subprogram
:
16820 /* Java constructors will all be named "<init>", so return
16821 the class name when we see this special case. */
16822 if (cu
->language
== language_java
16823 && DW_STRING (attr
) != NULL
16824 && strcmp (DW_STRING (attr
), "<init>") == 0)
16826 struct dwarf2_cu
*spec_cu
= cu
;
16827 struct die_info
*spec_die
;
16829 /* GCJ will output '<init>' for Java constructor names.
16830 For this special case, return the name of the parent class. */
16832 /* GCJ may output suprogram DIEs with AT_specification set.
16833 If so, use the name of the specified DIE. */
16834 spec_die
= die_specification (die
, &spec_cu
);
16835 if (spec_die
!= NULL
)
16836 return dwarf2_name (spec_die
, spec_cu
);
16841 if (die
->tag
== DW_TAG_class_type
)
16842 return dwarf2_name (die
, cu
);
16844 while (die
->tag
!= DW_TAG_compile_unit
16845 && die
->tag
!= DW_TAG_partial_unit
);
16849 case DW_TAG_class_type
:
16850 case DW_TAG_interface_type
:
16851 case DW_TAG_structure_type
:
16852 case DW_TAG_union_type
:
16853 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
16854 structures or unions. These were of the form "._%d" in GCC 4.1,
16855 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
16856 and GCC 4.4. We work around this problem by ignoring these. */
16857 if (attr
&& DW_STRING (attr
)
16858 && (strncmp (DW_STRING (attr
), "._", 2) == 0
16859 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
16862 /* GCC might emit a nameless typedef that has a linkage name. See
16863 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16864 if (!attr
|| DW_STRING (attr
) == NULL
)
16866 char *demangled
= NULL
;
16868 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16870 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16872 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16875 /* Avoid demangling DW_STRING (attr) the second time on a second
16876 call for the same DIE. */
16877 if (!DW_STRING_IS_CANONICAL (attr
))
16878 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
16884 /* FIXME: we already did this for the partial symbol... */
16885 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
16886 &cu
->objfile
->objfile_obstack
);
16887 DW_STRING_IS_CANONICAL (attr
) = 1;
16890 /* Strip any leading namespaces/classes, keep only the base name.
16891 DW_AT_name for named DIEs does not contain the prefixes. */
16892 base
= strrchr (DW_STRING (attr
), ':');
16893 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
16896 return DW_STRING (attr
);
16905 if (!DW_STRING_IS_CANONICAL (attr
))
16908 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
16909 &cu
->objfile
->objfile_obstack
);
16910 DW_STRING_IS_CANONICAL (attr
) = 1;
16912 return DW_STRING (attr
);
16915 /* Return the die that this die in an extension of, or NULL if there
16916 is none. *EXT_CU is the CU containing DIE on input, and the CU
16917 containing the return value on output. */
16919 static struct die_info
*
16920 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
16922 struct attribute
*attr
;
16924 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
16928 return follow_die_ref (die
, attr
, ext_cu
);
16931 /* Convert a DIE tag into its string name. */
16933 static const char *
16934 dwarf_tag_name (unsigned tag
)
16936 const char *name
= get_DW_TAG_name (tag
);
16939 return "DW_TAG_<unknown>";
16944 /* Convert a DWARF attribute code into its string name. */
16946 static const char *
16947 dwarf_attr_name (unsigned attr
)
16951 #ifdef MIPS /* collides with DW_AT_HP_block_index */
16952 if (attr
== DW_AT_MIPS_fde
)
16953 return "DW_AT_MIPS_fde";
16955 if (attr
== DW_AT_HP_block_index
)
16956 return "DW_AT_HP_block_index";
16959 name
= get_DW_AT_name (attr
);
16962 return "DW_AT_<unknown>";
16967 /* Convert a DWARF value form code into its string name. */
16969 static const char *
16970 dwarf_form_name (unsigned form
)
16972 const char *name
= get_DW_FORM_name (form
);
16975 return "DW_FORM_<unknown>";
16981 dwarf_bool_name (unsigned mybool
)
16989 /* Convert a DWARF type code into its string name. */
16991 static const char *
16992 dwarf_type_encoding_name (unsigned enc
)
16994 const char *name
= get_DW_ATE_name (enc
);
16997 return "DW_ATE_<unknown>";
17003 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
17007 print_spaces (indent
, f
);
17008 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
17009 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
17011 if (die
->parent
!= NULL
)
17013 print_spaces (indent
, f
);
17014 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
17015 die
->parent
->offset
.sect_off
);
17018 print_spaces (indent
, f
);
17019 fprintf_unfiltered (f
, " has children: %s\n",
17020 dwarf_bool_name (die
->child
!= NULL
));
17022 print_spaces (indent
, f
);
17023 fprintf_unfiltered (f
, " attributes:\n");
17025 for (i
= 0; i
< die
->num_attrs
; ++i
)
17027 print_spaces (indent
, f
);
17028 fprintf_unfiltered (f
, " %s (%s) ",
17029 dwarf_attr_name (die
->attrs
[i
].name
),
17030 dwarf_form_name (die
->attrs
[i
].form
));
17032 switch (die
->attrs
[i
].form
)
17035 case DW_FORM_GNU_addr_index
:
17036 fprintf_unfiltered (f
, "address: ");
17037 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
17039 case DW_FORM_block2
:
17040 case DW_FORM_block4
:
17041 case DW_FORM_block
:
17042 case DW_FORM_block1
:
17043 fprintf_unfiltered (f
, "block: size %s",
17044 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17046 case DW_FORM_exprloc
:
17047 fprintf_unfiltered (f
, "expression: size %s",
17048 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17050 case DW_FORM_ref_addr
:
17051 fprintf_unfiltered (f
, "ref address: ");
17052 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17054 case DW_FORM_GNU_ref_alt
:
17055 fprintf_unfiltered (f
, "alt ref address: ");
17056 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17062 case DW_FORM_ref_udata
:
17063 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
17064 (long) (DW_UNSND (&die
->attrs
[i
])));
17066 case DW_FORM_data1
:
17067 case DW_FORM_data2
:
17068 case DW_FORM_data4
:
17069 case DW_FORM_data8
:
17070 case DW_FORM_udata
:
17071 case DW_FORM_sdata
:
17072 fprintf_unfiltered (f
, "constant: %s",
17073 pulongest (DW_UNSND (&die
->attrs
[i
])));
17075 case DW_FORM_sec_offset
:
17076 fprintf_unfiltered (f
, "section offset: %s",
17077 pulongest (DW_UNSND (&die
->attrs
[i
])));
17079 case DW_FORM_ref_sig8
:
17080 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
17081 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
17082 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
17084 fprintf_unfiltered (f
, "signatured type, offset: unknown");
17086 case DW_FORM_string
:
17088 case DW_FORM_GNU_str_index
:
17089 case DW_FORM_GNU_strp_alt
:
17090 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
17091 DW_STRING (&die
->attrs
[i
])
17092 ? DW_STRING (&die
->attrs
[i
]) : "",
17093 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
17096 if (DW_UNSND (&die
->attrs
[i
]))
17097 fprintf_unfiltered (f
, "flag: TRUE");
17099 fprintf_unfiltered (f
, "flag: FALSE");
17101 case DW_FORM_flag_present
:
17102 fprintf_unfiltered (f
, "flag: TRUE");
17104 case DW_FORM_indirect
:
17105 /* The reader will have reduced the indirect form to
17106 the "base form" so this form should not occur. */
17107 fprintf_unfiltered (f
,
17108 "unexpected attribute form: DW_FORM_indirect");
17111 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
17112 die
->attrs
[i
].form
);
17115 fprintf_unfiltered (f
, "\n");
17120 dump_die_for_error (struct die_info
*die
)
17122 dump_die_shallow (gdb_stderr
, 0, die
);
17126 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
17128 int indent
= level
* 4;
17130 gdb_assert (die
!= NULL
);
17132 if (level
>= max_level
)
17135 dump_die_shallow (f
, indent
, die
);
17137 if (die
->child
!= NULL
)
17139 print_spaces (indent
, f
);
17140 fprintf_unfiltered (f
, " Children:");
17141 if (level
+ 1 < max_level
)
17143 fprintf_unfiltered (f
, "\n");
17144 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
17148 fprintf_unfiltered (f
,
17149 " [not printed, max nesting level reached]\n");
17153 if (die
->sibling
!= NULL
&& level
> 0)
17155 dump_die_1 (f
, level
, max_level
, die
->sibling
);
17159 /* This is called from the pdie macro in gdbinit.in.
17160 It's not static so gcc will keep a copy callable from gdb. */
17163 dump_die (struct die_info
*die
, int max_level
)
17165 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
17169 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
17173 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
17179 /* DW_ADDR is always stored already as sect_offset; despite for the forms
17180 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
17183 is_ref_attr (struct attribute
*attr
)
17185 switch (attr
->form
)
17187 case DW_FORM_ref_addr
:
17192 case DW_FORM_ref_udata
:
17193 case DW_FORM_GNU_ref_alt
:
17200 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
17204 dwarf2_get_ref_die_offset (struct attribute
*attr
)
17206 sect_offset retval
= { DW_UNSND (attr
) };
17208 if (is_ref_attr (attr
))
17211 retval
.sect_off
= 0;
17212 complaint (&symfile_complaints
,
17213 _("unsupported die ref attribute form: '%s'"),
17214 dwarf_form_name (attr
->form
));
17218 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
17219 * the value held by the attribute is not constant. */
17222 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
17224 if (attr
->form
== DW_FORM_sdata
)
17225 return DW_SND (attr
);
17226 else if (attr
->form
== DW_FORM_udata
17227 || attr
->form
== DW_FORM_data1
17228 || attr
->form
== DW_FORM_data2
17229 || attr
->form
== DW_FORM_data4
17230 || attr
->form
== DW_FORM_data8
)
17231 return DW_UNSND (attr
);
17234 complaint (&symfile_complaints
,
17235 _("Attribute value is not a constant (%s)"),
17236 dwarf_form_name (attr
->form
));
17237 return default_value
;
17241 /* Follow reference or signature attribute ATTR of SRC_DIE.
17242 On entry *REF_CU is the CU of SRC_DIE.
17243 On exit *REF_CU is the CU of the result. */
17245 static struct die_info
*
17246 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
17247 struct dwarf2_cu
**ref_cu
)
17249 struct die_info
*die
;
17251 if (is_ref_attr (attr
))
17252 die
= follow_die_ref (src_die
, attr
, ref_cu
);
17253 else if (attr
->form
== DW_FORM_ref_sig8
)
17254 die
= follow_die_sig (src_die
, attr
, ref_cu
);
17257 dump_die_for_error (src_die
);
17258 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
17259 (*ref_cu
)->objfile
->name
);
17265 /* Follow reference OFFSET.
17266 On entry *REF_CU is the CU of the source die referencing OFFSET.
17267 On exit *REF_CU is the CU of the result.
17268 Returns NULL if OFFSET is invalid. */
17270 static struct die_info
*
17271 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
17272 struct dwarf2_cu
**ref_cu
)
17274 struct die_info temp_die
;
17275 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
17277 gdb_assert (cu
->per_cu
!= NULL
);
17281 if (cu
->per_cu
->is_debug_types
)
17283 /* .debug_types CUs cannot reference anything outside their CU.
17284 If they need to, they have to reference a signatured type via
17285 DW_FORM_ref_sig8. */
17286 if (! offset_in_cu_p (&cu
->header
, offset
))
17289 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
17290 || ! offset_in_cu_p (&cu
->header
, offset
))
17292 struct dwarf2_per_cu_data
*per_cu
;
17294 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
17297 /* If necessary, add it to the queue and load its DIEs. */
17298 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
17299 load_full_comp_unit (per_cu
, cu
->language
);
17301 target_cu
= per_cu
->cu
;
17303 else if (cu
->dies
== NULL
)
17305 /* We're loading full DIEs during partial symbol reading. */
17306 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
17307 load_full_comp_unit (cu
->per_cu
, language_minimal
);
17310 *ref_cu
= target_cu
;
17311 temp_die
.offset
= offset
;
17312 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
17315 /* Follow reference attribute ATTR of SRC_DIE.
17316 On entry *REF_CU is the CU of SRC_DIE.
17317 On exit *REF_CU is the CU of the result. */
17319 static struct die_info
*
17320 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
17321 struct dwarf2_cu
**ref_cu
)
17323 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17324 struct dwarf2_cu
*cu
= *ref_cu
;
17325 struct die_info
*die
;
17327 die
= follow_die_offset (offset
,
17328 (attr
->form
== DW_FORM_GNU_ref_alt
17329 || cu
->per_cu
->is_dwz
),
17332 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
17333 "at 0x%x [in module %s]"),
17334 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
17339 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
17340 Returned value is intended for DW_OP_call*. Returned
17341 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
17343 struct dwarf2_locexpr_baton
17344 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
17345 struct dwarf2_per_cu_data
*per_cu
,
17346 CORE_ADDR (*get_frame_pc
) (void *baton
),
17349 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
17350 struct dwarf2_cu
*cu
;
17351 struct die_info
*die
;
17352 struct attribute
*attr
;
17353 struct dwarf2_locexpr_baton retval
;
17355 dw2_setup (per_cu
->objfile
);
17357 if (per_cu
->cu
== NULL
)
17361 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
17363 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
17364 offset
.sect_off
, per_cu
->objfile
->name
);
17366 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17369 /* DWARF: "If there is no such attribute, then there is no effect.".
17370 DATA is ignored if SIZE is 0. */
17372 retval
.data
= NULL
;
17375 else if (attr_form_is_section_offset (attr
))
17377 struct dwarf2_loclist_baton loclist_baton
;
17378 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
17381 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
17383 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
17385 retval
.size
= size
;
17389 if (!attr_form_is_block (attr
))
17390 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
17391 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
17392 offset
.sect_off
, per_cu
->objfile
->name
);
17394 retval
.data
= DW_BLOCK (attr
)->data
;
17395 retval
.size
= DW_BLOCK (attr
)->size
;
17397 retval
.per_cu
= cu
->per_cu
;
17399 age_cached_comp_units ();
17404 /* Return the type of the DIE at DIE_OFFSET in the CU named by
17408 dwarf2_get_die_type (cu_offset die_offset
,
17409 struct dwarf2_per_cu_data
*per_cu
)
17411 sect_offset die_offset_sect
;
17413 dw2_setup (per_cu
->objfile
);
17415 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
17416 return get_die_type_at_offset (die_offset_sect
, per_cu
);
17419 /* Follow the signature attribute ATTR in SRC_DIE.
17420 On entry *REF_CU is the CU of SRC_DIE.
17421 On exit *REF_CU is the CU of the result. */
17423 static struct die_info
*
17424 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
17425 struct dwarf2_cu
**ref_cu
)
17427 struct objfile
*objfile
= (*ref_cu
)->objfile
;
17428 struct die_info temp_die
;
17429 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
17430 struct dwarf2_cu
*sig_cu
;
17431 struct die_info
*die
;
17433 /* sig_type will be NULL if the signatured type is missing from
17435 if (sig_type
== NULL
)
17436 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
17437 "at 0x%x [in module %s]"),
17438 src_die
->offset
.sect_off
, objfile
->name
);
17440 /* If necessary, add it to the queue and load its DIEs. */
17442 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
17443 read_signatured_type (sig_type
);
17445 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
17447 sig_cu
= sig_type
->per_cu
.cu
;
17448 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
17449 temp_die
.offset
= sig_type
->type_offset_in_section
;
17450 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
17451 temp_die
.offset
.sect_off
);
17458 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
17459 "from DIE at 0x%x [in module %s]"),
17460 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
17463 /* Given an offset of a signatured type, return its signatured_type. */
17465 static struct signatured_type
*
17466 lookup_signatured_type_at_offset (struct objfile
*objfile
,
17467 struct dwarf2_section_info
*section
,
17468 sect_offset offset
)
17470 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
17471 unsigned int length
, initial_length_size
;
17472 unsigned int sig_offset
;
17473 struct signatured_type find_entry
, *sig_type
;
17475 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
17476 sig_offset
= (initial_length_size
17478 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
17479 + 1 /*address_size*/);
17480 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
17481 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
17483 /* This is only used to lookup previously recorded types.
17484 If we didn't find it, it's our bug. */
17485 gdb_assert (sig_type
!= NULL
);
17486 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
17491 /* Load the DIEs associated with type unit PER_CU into memory. */
17494 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
17496 struct signatured_type
*sig_type
;
17498 /* Caller is responsible for ensuring type_unit_groups don't get here. */
17499 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
17501 /* We have the per_cu, but we need the signatured_type.
17502 Fortunately this is an easy translation. */
17503 gdb_assert (per_cu
->is_debug_types
);
17504 sig_type
= (struct signatured_type
*) per_cu
;
17506 gdb_assert (per_cu
->cu
== NULL
);
17508 read_signatured_type (sig_type
);
17510 gdb_assert (per_cu
->cu
!= NULL
);
17513 /* die_reader_func for read_signatured_type.
17514 This is identical to load_full_comp_unit_reader,
17515 but is kept separate for now. */
17518 read_signatured_type_reader (const struct die_reader_specs
*reader
,
17519 gdb_byte
*info_ptr
,
17520 struct die_info
*comp_unit_die
,
17524 struct dwarf2_cu
*cu
= reader
->cu
;
17526 gdb_assert (cu
->die_hash
== NULL
);
17528 htab_create_alloc_ex (cu
->header
.length
/ 12,
17532 &cu
->comp_unit_obstack
,
17533 hashtab_obstack_allocate
,
17534 dummy_obstack_deallocate
);
17537 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
17538 &info_ptr
, comp_unit_die
);
17539 cu
->dies
= comp_unit_die
;
17540 /* comp_unit_die is not stored in die_hash, no need. */
17542 /* We try not to read any attributes in this function, because not
17543 all CUs needed for references have been loaded yet, and symbol
17544 table processing isn't initialized. But we have to set the CU language,
17545 or we won't be able to build types correctly.
17546 Similarly, if we do not read the producer, we can not apply
17547 producer-specific interpretation. */
17548 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
17551 /* Read in a signatured type and build its CU and DIEs.
17552 If the type is a stub for the real type in a DWO file,
17553 read in the real type from the DWO file as well. */
17556 read_signatured_type (struct signatured_type
*sig_type
)
17558 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
17560 gdb_assert (per_cu
->is_debug_types
);
17561 gdb_assert (per_cu
->cu
== NULL
);
17563 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
17564 read_signatured_type_reader
, NULL
);
17567 /* Decode simple location descriptions.
17568 Given a pointer to a dwarf block that defines a location, compute
17569 the location and return the value.
17571 NOTE drow/2003-11-18: This function is called in two situations
17572 now: for the address of static or global variables (partial symbols
17573 only) and for offsets into structures which are expected to be
17574 (more or less) constant. The partial symbol case should go away,
17575 and only the constant case should remain. That will let this
17576 function complain more accurately. A few special modes are allowed
17577 without complaint for global variables (for instance, global
17578 register values and thread-local values).
17580 A location description containing no operations indicates that the
17581 object is optimized out. The return value is 0 for that case.
17582 FIXME drow/2003-11-16: No callers check for this case any more; soon all
17583 callers will only want a very basic result and this can become a
17586 Note that stack[0] is unused except as a default error return. */
17589 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
17591 struct objfile
*objfile
= cu
->objfile
;
17593 size_t size
= blk
->size
;
17594 gdb_byte
*data
= blk
->data
;
17595 CORE_ADDR stack
[64];
17597 unsigned int bytes_read
, unsnd
;
17603 stack
[++stacki
] = 0;
17642 stack
[++stacki
] = op
- DW_OP_lit0
;
17677 stack
[++stacki
] = op
- DW_OP_reg0
;
17679 dwarf2_complex_location_expr_complaint ();
17683 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
17685 stack
[++stacki
] = unsnd
;
17687 dwarf2_complex_location_expr_complaint ();
17691 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
17696 case DW_OP_const1u
:
17697 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
17701 case DW_OP_const1s
:
17702 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
17706 case DW_OP_const2u
:
17707 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
17711 case DW_OP_const2s
:
17712 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
17716 case DW_OP_const4u
:
17717 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
17721 case DW_OP_const4s
:
17722 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
17726 case DW_OP_const8u
:
17727 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
17732 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
17738 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
17743 stack
[stacki
+ 1] = stack
[stacki
];
17748 stack
[stacki
- 1] += stack
[stacki
];
17752 case DW_OP_plus_uconst
:
17753 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
17759 stack
[stacki
- 1] -= stack
[stacki
];
17764 /* If we're not the last op, then we definitely can't encode
17765 this using GDB's address_class enum. This is valid for partial
17766 global symbols, although the variable's address will be bogus
17769 dwarf2_complex_location_expr_complaint ();
17772 case DW_OP_GNU_push_tls_address
:
17773 /* The top of the stack has the offset from the beginning
17774 of the thread control block at which the variable is located. */
17775 /* Nothing should follow this operator, so the top of stack would
17777 /* This is valid for partial global symbols, but the variable's
17778 address will be bogus in the psymtab. Make it always at least
17779 non-zero to not look as a variable garbage collected by linker
17780 which have DW_OP_addr 0. */
17782 dwarf2_complex_location_expr_complaint ();
17786 case DW_OP_GNU_uninit
:
17789 case DW_OP_GNU_addr_index
:
17790 case DW_OP_GNU_const_index
:
17791 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
17798 const char *name
= get_DW_OP_name (op
);
17801 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
17804 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
17808 return (stack
[stacki
]);
17811 /* Enforce maximum stack depth of SIZE-1 to avoid writing
17812 outside of the allocated space. Also enforce minimum>0. */
17813 if (stacki
>= ARRAY_SIZE (stack
) - 1)
17815 complaint (&symfile_complaints
,
17816 _("location description stack overflow"));
17822 complaint (&symfile_complaints
,
17823 _("location description stack underflow"));
17827 return (stack
[stacki
]);
17830 /* memory allocation interface */
17832 static struct dwarf_block
*
17833 dwarf_alloc_block (struct dwarf2_cu
*cu
)
17835 struct dwarf_block
*blk
;
17837 blk
= (struct dwarf_block
*)
17838 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
17842 static struct die_info
*
17843 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
17845 struct die_info
*die
;
17846 size_t size
= sizeof (struct die_info
);
17849 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
17851 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
17852 memset (die
, 0, sizeof (struct die_info
));
17857 /* Macro support. */
17859 /* Return the full name of file number I in *LH's file name table.
17860 Use COMP_DIR as the name of the current directory of the
17861 compilation. The result is allocated using xmalloc; the caller is
17862 responsible for freeing it. */
17864 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
17866 /* Is the file number a valid index into the line header's file name
17867 table? Remember that file numbers start with one, not zero. */
17868 if (1 <= file
&& file
<= lh
->num_file_names
)
17870 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
17872 if (IS_ABSOLUTE_PATH (fe
->name
))
17873 return xstrdup (fe
->name
);
17881 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
17887 dir_len
= strlen (dir
);
17888 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
17889 strcpy (full_name
, dir
);
17890 full_name
[dir_len
] = '/';
17891 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
17895 return xstrdup (fe
->name
);
17900 /* The compiler produced a bogus file number. We can at least
17901 record the macro definitions made in the file, even if we
17902 won't be able to find the file by name. */
17903 char fake_name
[80];
17905 sprintf (fake_name
, "<bad macro file number %d>", file
);
17907 complaint (&symfile_complaints
,
17908 _("bad file number in macro information (%d)"),
17911 return xstrdup (fake_name
);
17916 static struct macro_source_file
*
17917 macro_start_file (int file
, int line
,
17918 struct macro_source_file
*current_file
,
17919 const char *comp_dir
,
17920 struct line_header
*lh
, struct objfile
*objfile
)
17922 /* The full name of this source file. */
17923 char *full_name
= file_full_name (file
, lh
, comp_dir
);
17925 /* We don't create a macro table for this compilation unit
17926 at all until we actually get a filename. */
17927 if (! pending_macros
)
17928 pending_macros
= new_macro_table (&objfile
->per_bfd
->storage_obstack
,
17929 objfile
->per_bfd
->macro_cache
);
17931 if (! current_file
)
17933 /* If we have no current file, then this must be the start_file
17934 directive for the compilation unit's main source file. */
17935 current_file
= macro_set_main (pending_macros
, full_name
);
17936 macro_define_special (pending_macros
);
17939 current_file
= macro_include (current_file
, line
, full_name
);
17943 return current_file
;
17947 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
17948 followed by a null byte. */
17950 copy_string (const char *buf
, int len
)
17952 char *s
= xmalloc (len
+ 1);
17954 memcpy (s
, buf
, len
);
17960 static const char *
17961 consume_improper_spaces (const char *p
, const char *body
)
17965 complaint (&symfile_complaints
,
17966 _("macro definition contains spaces "
17967 "in formal argument list:\n`%s'"),
17979 parse_macro_definition (struct macro_source_file
*file
, int line
,
17984 /* The body string takes one of two forms. For object-like macro
17985 definitions, it should be:
17987 <macro name> " " <definition>
17989 For function-like macro definitions, it should be:
17991 <macro name> "() " <definition>
17993 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
17995 Spaces may appear only where explicitly indicated, and in the
17998 The Dwarf 2 spec says that an object-like macro's name is always
17999 followed by a space, but versions of GCC around March 2002 omit
18000 the space when the macro's definition is the empty string.
18002 The Dwarf 2 spec says that there should be no spaces between the
18003 formal arguments in a function-like macro's formal argument list,
18004 but versions of GCC around March 2002 include spaces after the
18008 /* Find the extent of the macro name. The macro name is terminated
18009 by either a space or null character (for an object-like macro) or
18010 an opening paren (for a function-like macro). */
18011 for (p
= body
; *p
; p
++)
18012 if (*p
== ' ' || *p
== '(')
18015 if (*p
== ' ' || *p
== '\0')
18017 /* It's an object-like macro. */
18018 int name_len
= p
- body
;
18019 char *name
= copy_string (body
, name_len
);
18020 const char *replacement
;
18023 replacement
= body
+ name_len
+ 1;
18026 dwarf2_macro_malformed_definition_complaint (body
);
18027 replacement
= body
+ name_len
;
18030 macro_define_object (file
, line
, name
, replacement
);
18034 else if (*p
== '(')
18036 /* It's a function-like macro. */
18037 char *name
= copy_string (body
, p
- body
);
18040 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
18044 p
= consume_improper_spaces (p
, body
);
18046 /* Parse the formal argument list. */
18047 while (*p
&& *p
!= ')')
18049 /* Find the extent of the current argument name. */
18050 const char *arg_start
= p
;
18052 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
18055 if (! *p
|| p
== arg_start
)
18056 dwarf2_macro_malformed_definition_complaint (body
);
18059 /* Make sure argv has room for the new argument. */
18060 if (argc
>= argv_size
)
18063 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
18066 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
18069 p
= consume_improper_spaces (p
, body
);
18071 /* Consume the comma, if present. */
18076 p
= consume_improper_spaces (p
, body
);
18085 /* Perfectly formed definition, no complaints. */
18086 macro_define_function (file
, line
, name
,
18087 argc
, (const char **) argv
,
18089 else if (*p
== '\0')
18091 /* Complain, but do define it. */
18092 dwarf2_macro_malformed_definition_complaint (body
);
18093 macro_define_function (file
, line
, name
,
18094 argc
, (const char **) argv
,
18098 /* Just complain. */
18099 dwarf2_macro_malformed_definition_complaint (body
);
18102 /* Just complain. */
18103 dwarf2_macro_malformed_definition_complaint (body
);
18109 for (i
= 0; i
< argc
; i
++)
18115 dwarf2_macro_malformed_definition_complaint (body
);
18118 /* Skip some bytes from BYTES according to the form given in FORM.
18119 Returns the new pointer. */
18122 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
18123 enum dwarf_form form
,
18124 unsigned int offset_size
,
18125 struct dwarf2_section_info
*section
)
18127 unsigned int bytes_read
;
18131 case DW_FORM_data1
:
18136 case DW_FORM_data2
:
18140 case DW_FORM_data4
:
18144 case DW_FORM_data8
:
18148 case DW_FORM_string
:
18149 read_direct_string (abfd
, bytes
, &bytes_read
);
18150 bytes
+= bytes_read
;
18153 case DW_FORM_sec_offset
:
18155 case DW_FORM_GNU_strp_alt
:
18156 bytes
+= offset_size
;
18159 case DW_FORM_block
:
18160 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
18161 bytes
+= bytes_read
;
18164 case DW_FORM_block1
:
18165 bytes
+= 1 + read_1_byte (abfd
, bytes
);
18167 case DW_FORM_block2
:
18168 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
18170 case DW_FORM_block4
:
18171 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
18174 case DW_FORM_sdata
:
18175 case DW_FORM_udata
:
18176 case DW_FORM_GNU_addr_index
:
18177 case DW_FORM_GNU_str_index
:
18178 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
18181 dwarf2_section_buffer_overflow_complaint (section
);
18189 complaint (&symfile_complaints
,
18190 _("invalid form 0x%x in `%s'"),
18192 section
->asection
->name
);
18200 /* A helper for dwarf_decode_macros that handles skipping an unknown
18201 opcode. Returns an updated pointer to the macro data buffer; or,
18202 on error, issues a complaint and returns NULL. */
18205 skip_unknown_opcode (unsigned int opcode
,
18206 gdb_byte
**opcode_definitions
,
18207 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18209 unsigned int offset_size
,
18210 struct dwarf2_section_info
*section
)
18212 unsigned int bytes_read
, i
;
18216 if (opcode_definitions
[opcode
] == NULL
)
18218 complaint (&symfile_complaints
,
18219 _("unrecognized DW_MACFINO opcode 0x%x"),
18224 defn
= opcode_definitions
[opcode
];
18225 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
18226 defn
+= bytes_read
;
18228 for (i
= 0; i
< arg
; ++i
)
18230 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
18232 if (mac_ptr
== NULL
)
18234 /* skip_form_bytes already issued the complaint. */
18242 /* A helper function which parses the header of a macro section.
18243 If the macro section is the extended (for now called "GNU") type,
18244 then this updates *OFFSET_SIZE. Returns a pointer to just after
18245 the header, or issues a complaint and returns NULL on error. */
18248 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
18251 unsigned int *offset_size
,
18252 int section_is_gnu
)
18254 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
18256 if (section_is_gnu
)
18258 unsigned int version
, flags
;
18260 version
= read_2_bytes (abfd
, mac_ptr
);
18263 complaint (&symfile_complaints
,
18264 _("unrecognized version `%d' in .debug_macro section"),
18270 flags
= read_1_byte (abfd
, mac_ptr
);
18272 *offset_size
= (flags
& 1) ? 8 : 4;
18274 if ((flags
& 2) != 0)
18275 /* We don't need the line table offset. */
18276 mac_ptr
+= *offset_size
;
18278 /* Vendor opcode descriptions. */
18279 if ((flags
& 4) != 0)
18281 unsigned int i
, count
;
18283 count
= read_1_byte (abfd
, mac_ptr
);
18285 for (i
= 0; i
< count
; ++i
)
18287 unsigned int opcode
, bytes_read
;
18290 opcode
= read_1_byte (abfd
, mac_ptr
);
18292 opcode_definitions
[opcode
] = mac_ptr
;
18293 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18294 mac_ptr
+= bytes_read
;
18303 /* A helper for dwarf_decode_macros that handles the GNU extensions,
18304 including DW_MACRO_GNU_transparent_include. */
18307 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18308 struct macro_source_file
*current_file
,
18309 struct line_header
*lh
, char *comp_dir
,
18310 struct dwarf2_section_info
*section
,
18311 int section_is_gnu
, int section_is_dwz
,
18312 unsigned int offset_size
,
18313 struct objfile
*objfile
,
18314 htab_t include_hash
)
18316 enum dwarf_macro_record_type macinfo_type
;
18317 int at_commandline
;
18318 gdb_byte
*opcode_definitions
[256];
18320 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18321 &offset_size
, section_is_gnu
);
18322 if (mac_ptr
== NULL
)
18324 /* We already issued a complaint. */
18328 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
18329 GDB is still reading the definitions from command line. First
18330 DW_MACINFO_start_file will need to be ignored as it was already executed
18331 to create CURRENT_FILE for the main source holding also the command line
18332 definitions. On first met DW_MACINFO_start_file this flag is reset to
18333 normally execute all the remaining DW_MACINFO_start_file macinfos. */
18335 at_commandline
= 1;
18339 /* Do we at least have room for a macinfo type byte? */
18340 if (mac_ptr
>= mac_end
)
18342 dwarf2_section_buffer_overflow_complaint (section
);
18346 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18349 /* Note that we rely on the fact that the corresponding GNU and
18350 DWARF constants are the same. */
18351 switch (macinfo_type
)
18353 /* A zero macinfo type indicates the end of the macro
18358 case DW_MACRO_GNU_define
:
18359 case DW_MACRO_GNU_undef
:
18360 case DW_MACRO_GNU_define_indirect
:
18361 case DW_MACRO_GNU_undef_indirect
:
18362 case DW_MACRO_GNU_define_indirect_alt
:
18363 case DW_MACRO_GNU_undef_indirect_alt
:
18365 unsigned int bytes_read
;
18370 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18371 mac_ptr
+= bytes_read
;
18373 if (macinfo_type
== DW_MACRO_GNU_define
18374 || macinfo_type
== DW_MACRO_GNU_undef
)
18376 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18377 mac_ptr
+= bytes_read
;
18381 LONGEST str_offset
;
18383 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18384 mac_ptr
+= offset_size
;
18386 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
18387 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
18390 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18392 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
18395 body
= read_indirect_string_at_offset (abfd
, str_offset
);
18398 is_define
= (macinfo_type
== DW_MACRO_GNU_define
18399 || macinfo_type
== DW_MACRO_GNU_define_indirect
18400 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
18401 if (! current_file
)
18403 /* DWARF violation as no main source is present. */
18404 complaint (&symfile_complaints
,
18405 _("debug info with no main source gives macro %s "
18407 is_define
? _("definition") : _("undefinition"),
18411 if ((line
== 0 && !at_commandline
)
18412 || (line
!= 0 && at_commandline
))
18413 complaint (&symfile_complaints
,
18414 _("debug info gives %s macro %s with %s line %d: %s"),
18415 at_commandline
? _("command-line") : _("in-file"),
18416 is_define
? _("definition") : _("undefinition"),
18417 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
18420 parse_macro_definition (current_file
, line
, body
);
18423 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
18424 || macinfo_type
== DW_MACRO_GNU_undef_indirect
18425 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
18426 macro_undef (current_file
, line
, body
);
18431 case DW_MACRO_GNU_start_file
:
18433 unsigned int bytes_read
;
18436 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18437 mac_ptr
+= bytes_read
;
18438 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18439 mac_ptr
+= bytes_read
;
18441 if ((line
== 0 && !at_commandline
)
18442 || (line
!= 0 && at_commandline
))
18443 complaint (&symfile_complaints
,
18444 _("debug info gives source %d included "
18445 "from %s at %s line %d"),
18446 file
, at_commandline
? _("command-line") : _("file"),
18447 line
== 0 ? _("zero") : _("non-zero"), line
);
18449 if (at_commandline
)
18451 /* This DW_MACRO_GNU_start_file was executed in the
18453 at_commandline
= 0;
18456 current_file
= macro_start_file (file
, line
,
18457 current_file
, comp_dir
,
18462 case DW_MACRO_GNU_end_file
:
18463 if (! current_file
)
18464 complaint (&symfile_complaints
,
18465 _("macro debug info has an unmatched "
18466 "`close_file' directive"));
18469 current_file
= current_file
->included_by
;
18470 if (! current_file
)
18472 enum dwarf_macro_record_type next_type
;
18474 /* GCC circa March 2002 doesn't produce the zero
18475 type byte marking the end of the compilation
18476 unit. Complain if it's not there, but exit no
18479 /* Do we at least have room for a macinfo type byte? */
18480 if (mac_ptr
>= mac_end
)
18482 dwarf2_section_buffer_overflow_complaint (section
);
18486 /* We don't increment mac_ptr here, so this is just
18488 next_type
= read_1_byte (abfd
, mac_ptr
);
18489 if (next_type
!= 0)
18490 complaint (&symfile_complaints
,
18491 _("no terminating 0-type entry for "
18492 "macros in `.debug_macinfo' section"));
18499 case DW_MACRO_GNU_transparent_include
:
18500 case DW_MACRO_GNU_transparent_include_alt
:
18504 bfd
*include_bfd
= abfd
;
18505 struct dwarf2_section_info
*include_section
= section
;
18506 struct dwarf2_section_info alt_section
;
18507 gdb_byte
*include_mac_end
= mac_end
;
18508 int is_dwz
= section_is_dwz
;
18509 gdb_byte
*new_mac_ptr
;
18511 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18512 mac_ptr
+= offset_size
;
18514 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
18516 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18518 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
18521 include_bfd
= dwz
->macro
.asection
->owner
;
18522 include_section
= &dwz
->macro
;
18523 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
18527 new_mac_ptr
= include_section
->buffer
+ offset
;
18528 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
18532 /* This has actually happened; see
18533 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
18534 complaint (&symfile_complaints
,
18535 _("recursive DW_MACRO_GNU_transparent_include in "
18536 ".debug_macro section"));
18540 *slot
= new_mac_ptr
;
18542 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
18543 include_mac_end
, current_file
,
18545 section
, section_is_gnu
, is_dwz
,
18546 offset_size
, objfile
, include_hash
);
18548 htab_remove_elt (include_hash
, new_mac_ptr
);
18553 case DW_MACINFO_vendor_ext
:
18554 if (!section_is_gnu
)
18556 unsigned int bytes_read
;
18559 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18560 mac_ptr
+= bytes_read
;
18561 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18562 mac_ptr
+= bytes_read
;
18564 /* We don't recognize any vendor extensions. */
18570 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18571 mac_ptr
, mac_end
, abfd
, offset_size
,
18573 if (mac_ptr
== NULL
)
18577 } while (macinfo_type
!= 0);
18581 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
18582 char *comp_dir
, int section_is_gnu
)
18584 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18585 struct line_header
*lh
= cu
->line_header
;
18587 gdb_byte
*mac_ptr
, *mac_end
;
18588 struct macro_source_file
*current_file
= 0;
18589 enum dwarf_macro_record_type macinfo_type
;
18590 unsigned int offset_size
= cu
->header
.offset_size
;
18591 gdb_byte
*opcode_definitions
[256];
18592 struct cleanup
*cleanup
;
18593 htab_t include_hash
;
18595 struct dwarf2_section_info
*section
;
18596 const char *section_name
;
18598 if (cu
->dwo_unit
!= NULL
)
18600 if (section_is_gnu
)
18602 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
18603 section_name
= ".debug_macro.dwo";
18607 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
18608 section_name
= ".debug_macinfo.dwo";
18613 if (section_is_gnu
)
18615 section
= &dwarf2_per_objfile
->macro
;
18616 section_name
= ".debug_macro";
18620 section
= &dwarf2_per_objfile
->macinfo
;
18621 section_name
= ".debug_macinfo";
18625 dwarf2_read_section (objfile
, section
);
18626 if (section
->buffer
== NULL
)
18628 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
18631 abfd
= section
->asection
->owner
;
18633 /* First pass: Find the name of the base filename.
18634 This filename is needed in order to process all macros whose definition
18635 (or undefinition) comes from the command line. These macros are defined
18636 before the first DW_MACINFO_start_file entry, and yet still need to be
18637 associated to the base file.
18639 To determine the base file name, we scan the macro definitions until we
18640 reach the first DW_MACINFO_start_file entry. We then initialize
18641 CURRENT_FILE accordingly so that any macro definition found before the
18642 first DW_MACINFO_start_file can still be associated to the base file. */
18644 mac_ptr
= section
->buffer
+ offset
;
18645 mac_end
= section
->buffer
+ section
->size
;
18647 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18648 &offset_size
, section_is_gnu
);
18649 if (mac_ptr
== NULL
)
18651 /* We already issued a complaint. */
18657 /* Do we at least have room for a macinfo type byte? */
18658 if (mac_ptr
>= mac_end
)
18660 /* Complaint is printed during the second pass as GDB will probably
18661 stop the first pass earlier upon finding
18662 DW_MACINFO_start_file. */
18666 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18669 /* Note that we rely on the fact that the corresponding GNU and
18670 DWARF constants are the same. */
18671 switch (macinfo_type
)
18673 /* A zero macinfo type indicates the end of the macro
18678 case DW_MACRO_GNU_define
:
18679 case DW_MACRO_GNU_undef
:
18680 /* Only skip the data by MAC_PTR. */
18682 unsigned int bytes_read
;
18684 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18685 mac_ptr
+= bytes_read
;
18686 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18687 mac_ptr
+= bytes_read
;
18691 case DW_MACRO_GNU_start_file
:
18693 unsigned int bytes_read
;
18696 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18697 mac_ptr
+= bytes_read
;
18698 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18699 mac_ptr
+= bytes_read
;
18701 current_file
= macro_start_file (file
, line
, current_file
,
18702 comp_dir
, lh
, objfile
);
18706 case DW_MACRO_GNU_end_file
:
18707 /* No data to skip by MAC_PTR. */
18710 case DW_MACRO_GNU_define_indirect
:
18711 case DW_MACRO_GNU_undef_indirect
:
18712 case DW_MACRO_GNU_define_indirect_alt
:
18713 case DW_MACRO_GNU_undef_indirect_alt
:
18715 unsigned int bytes_read
;
18717 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18718 mac_ptr
+= bytes_read
;
18719 mac_ptr
+= offset_size
;
18723 case DW_MACRO_GNU_transparent_include
:
18724 case DW_MACRO_GNU_transparent_include_alt
:
18725 /* Note that, according to the spec, a transparent include
18726 chain cannot call DW_MACRO_GNU_start_file. So, we can just
18727 skip this opcode. */
18728 mac_ptr
+= offset_size
;
18731 case DW_MACINFO_vendor_ext
:
18732 /* Only skip the data by MAC_PTR. */
18733 if (!section_is_gnu
)
18735 unsigned int bytes_read
;
18737 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18738 mac_ptr
+= bytes_read
;
18739 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18740 mac_ptr
+= bytes_read
;
18745 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18746 mac_ptr
, mac_end
, abfd
, offset_size
,
18748 if (mac_ptr
== NULL
)
18752 } while (macinfo_type
!= 0 && current_file
== NULL
);
18754 /* Second pass: Process all entries.
18756 Use the AT_COMMAND_LINE flag to determine whether we are still processing
18757 command-line macro definitions/undefinitions. This flag is unset when we
18758 reach the first DW_MACINFO_start_file entry. */
18760 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
18761 NULL
, xcalloc
, xfree
);
18762 cleanup
= make_cleanup_htab_delete (include_hash
);
18763 mac_ptr
= section
->buffer
+ offset
;
18764 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
18766 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
18767 current_file
, lh
, comp_dir
, section
,
18769 offset_size
, objfile
, include_hash
);
18770 do_cleanups (cleanup
);
18773 /* Check if the attribute's form is a DW_FORM_block*
18774 if so return true else false. */
18777 attr_form_is_block (struct attribute
*attr
)
18779 return (attr
== NULL
? 0 :
18780 attr
->form
== DW_FORM_block1
18781 || attr
->form
== DW_FORM_block2
18782 || attr
->form
== DW_FORM_block4
18783 || attr
->form
== DW_FORM_block
18784 || attr
->form
== DW_FORM_exprloc
);
18787 /* Return non-zero if ATTR's value is a section offset --- classes
18788 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
18789 You may use DW_UNSND (attr) to retrieve such offsets.
18791 Section 7.5.4, "Attribute Encodings", explains that no attribute
18792 may have a value that belongs to more than one of these classes; it
18793 would be ambiguous if we did, because we use the same forms for all
18797 attr_form_is_section_offset (struct attribute
*attr
)
18799 return (attr
->form
== DW_FORM_data4
18800 || attr
->form
== DW_FORM_data8
18801 || attr
->form
== DW_FORM_sec_offset
);
18804 /* Return non-zero if ATTR's value falls in the 'constant' class, or
18805 zero otherwise. When this function returns true, you can apply
18806 dwarf2_get_attr_constant_value to it.
18808 However, note that for some attributes you must check
18809 attr_form_is_section_offset before using this test. DW_FORM_data4
18810 and DW_FORM_data8 are members of both the constant class, and of
18811 the classes that contain offsets into other debug sections
18812 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
18813 that, if an attribute's can be either a constant or one of the
18814 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
18815 taken as section offsets, not constants. */
18818 attr_form_is_constant (struct attribute
*attr
)
18820 switch (attr
->form
)
18822 case DW_FORM_sdata
:
18823 case DW_FORM_udata
:
18824 case DW_FORM_data1
:
18825 case DW_FORM_data2
:
18826 case DW_FORM_data4
:
18827 case DW_FORM_data8
:
18834 /* Return the .debug_loc section to use for CU.
18835 For DWO files use .debug_loc.dwo. */
18837 static struct dwarf2_section_info
*
18838 cu_debug_loc_section (struct dwarf2_cu
*cu
)
18841 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
18842 return &dwarf2_per_objfile
->loc
;
18845 /* A helper function that fills in a dwarf2_loclist_baton. */
18848 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
18849 struct dwarf2_loclist_baton
*baton
,
18850 struct attribute
*attr
)
18852 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18854 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
18856 baton
->per_cu
= cu
->per_cu
;
18857 gdb_assert (baton
->per_cu
);
18858 /* We don't know how long the location list is, but make sure we
18859 don't run off the edge of the section. */
18860 baton
->size
= section
->size
- DW_UNSND (attr
);
18861 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
18862 baton
->base_address
= cu
->base_address
;
18863 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
18867 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
18868 struct dwarf2_cu
*cu
)
18870 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18871 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18873 if (attr_form_is_section_offset (attr
)
18874 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
18875 the section. If so, fall through to the complaint in the
18877 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
18879 struct dwarf2_loclist_baton
*baton
;
18881 baton
= obstack_alloc (&objfile
->objfile_obstack
,
18882 sizeof (struct dwarf2_loclist_baton
));
18884 fill_in_loclist_baton (cu
, baton
, attr
);
18886 if (cu
->base_known
== 0)
18887 complaint (&symfile_complaints
,
18888 _("Location list used without "
18889 "specifying the CU base address."));
18891 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
18892 SYMBOL_LOCATION_BATON (sym
) = baton
;
18896 struct dwarf2_locexpr_baton
*baton
;
18898 baton
= obstack_alloc (&objfile
->objfile_obstack
,
18899 sizeof (struct dwarf2_locexpr_baton
));
18900 baton
->per_cu
= cu
->per_cu
;
18901 gdb_assert (baton
->per_cu
);
18903 if (attr_form_is_block (attr
))
18905 /* Note that we're just copying the block's data pointer
18906 here, not the actual data. We're still pointing into the
18907 info_buffer for SYM's objfile; right now we never release
18908 that buffer, but when we do clean up properly this may
18910 baton
->size
= DW_BLOCK (attr
)->size
;
18911 baton
->data
= DW_BLOCK (attr
)->data
;
18915 dwarf2_invalid_attrib_class_complaint ("location description",
18916 SYMBOL_NATURAL_NAME (sym
));
18920 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
18921 SYMBOL_LOCATION_BATON (sym
) = baton
;
18925 /* Return the OBJFILE associated with the compilation unit CU. If CU
18926 came from a separate debuginfo file, then the master objfile is
18930 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
18932 struct objfile
*objfile
= per_cu
->objfile
;
18934 /* Return the master objfile, so that we can report and look up the
18935 correct file containing this variable. */
18936 if (objfile
->separate_debug_objfile_backlink
)
18937 objfile
= objfile
->separate_debug_objfile_backlink
;
18942 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
18943 (CU_HEADERP is unused in such case) or prepare a temporary copy at
18944 CU_HEADERP first. */
18946 static const struct comp_unit_head
*
18947 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
18948 struct dwarf2_per_cu_data
*per_cu
)
18950 gdb_byte
*info_ptr
;
18953 return &per_cu
->cu
->header
;
18955 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
18957 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
18958 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
18963 /* Return the address size given in the compilation unit header for CU. */
18966 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
18968 struct comp_unit_head cu_header_local
;
18969 const struct comp_unit_head
*cu_headerp
;
18971 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18973 return cu_headerp
->addr_size
;
18976 /* Return the offset size given in the compilation unit header for CU. */
18979 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
18981 struct comp_unit_head cu_header_local
;
18982 const struct comp_unit_head
*cu_headerp
;
18984 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18986 return cu_headerp
->offset_size
;
18989 /* See its dwarf2loc.h declaration. */
18992 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
18994 struct comp_unit_head cu_header_local
;
18995 const struct comp_unit_head
*cu_headerp
;
18997 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18999 if (cu_headerp
->version
== 2)
19000 return cu_headerp
->addr_size
;
19002 return cu_headerp
->offset_size
;
19005 /* Return the text offset of the CU. The returned offset comes from
19006 this CU's objfile. If this objfile came from a separate debuginfo
19007 file, then the offset may be different from the corresponding
19008 offset in the parent objfile. */
19011 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
19013 struct objfile
*objfile
= per_cu
->objfile
;
19015 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19018 /* Locate the .debug_info compilation unit from CU's objfile which contains
19019 the DIE at OFFSET. Raises an error on failure. */
19021 static struct dwarf2_per_cu_data
*
19022 dwarf2_find_containing_comp_unit (sect_offset offset
,
19023 unsigned int offset_in_dwz
,
19024 struct objfile
*objfile
)
19026 struct dwarf2_per_cu_data
*this_cu
;
19028 const sect_offset
*cu_off
;
19031 high
= dwarf2_per_objfile
->n_comp_units
- 1;
19034 struct dwarf2_per_cu_data
*mid_cu
;
19035 int mid
= low
+ (high
- low
) / 2;
19037 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
19038 cu_off
= &mid_cu
->offset
;
19039 if (mid_cu
->is_dwz
> offset_in_dwz
19040 || (mid_cu
->is_dwz
== offset_in_dwz
19041 && cu_off
->sect_off
>= offset
.sect_off
))
19046 gdb_assert (low
== high
);
19047 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19048 cu_off
= &this_cu
->offset
;
19049 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
19051 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
19052 error (_("Dwarf Error: could not find partial DIE containing "
19053 "offset 0x%lx [in module %s]"),
19054 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
19056 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
19057 <= offset
.sect_off
);
19058 return dwarf2_per_objfile
->all_comp_units
[low
-1];
19062 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19063 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
19064 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
19065 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
19066 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
19071 /* Initialize dwarf2_cu CU, owned by PER_CU. */
19074 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
19076 memset (cu
, 0, sizeof (*cu
));
19078 cu
->per_cu
= per_cu
;
19079 cu
->objfile
= per_cu
->objfile
;
19080 obstack_init (&cu
->comp_unit_obstack
);
19083 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
19086 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
19087 enum language pretend_language
)
19089 struct attribute
*attr
;
19091 /* Set the language we're debugging. */
19092 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
19094 set_cu_language (DW_UNSND (attr
), cu
);
19097 cu
->language
= pretend_language
;
19098 cu
->language_defn
= language_def (cu
->language
);
19101 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
19103 cu
->producer
= DW_STRING (attr
);
19106 /* Release one cached compilation unit, CU. We unlink it from the tree
19107 of compilation units, but we don't remove it from the read_in_chain;
19108 the caller is responsible for that.
19109 NOTE: DATA is a void * because this function is also used as a
19110 cleanup routine. */
19113 free_heap_comp_unit (void *data
)
19115 struct dwarf2_cu
*cu
= data
;
19117 gdb_assert (cu
->per_cu
!= NULL
);
19118 cu
->per_cu
->cu
= NULL
;
19121 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19126 /* This cleanup function is passed the address of a dwarf2_cu on the stack
19127 when we're finished with it. We can't free the pointer itself, but be
19128 sure to unlink it from the cache. Also release any associated storage. */
19131 free_stack_comp_unit (void *data
)
19133 struct dwarf2_cu
*cu
= data
;
19135 gdb_assert (cu
->per_cu
!= NULL
);
19136 cu
->per_cu
->cu
= NULL
;
19139 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19140 cu
->partial_dies
= NULL
;
19143 /* Free all cached compilation units. */
19146 free_cached_comp_units (void *data
)
19148 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19150 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19151 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19152 while (per_cu
!= NULL
)
19154 struct dwarf2_per_cu_data
*next_cu
;
19156 next_cu
= per_cu
->cu
->read_in_chain
;
19158 free_heap_comp_unit (per_cu
->cu
);
19159 *last_chain
= next_cu
;
19165 /* Increase the age counter on each cached compilation unit, and free
19166 any that are too old. */
19169 age_cached_comp_units (void)
19171 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19173 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
19174 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19175 while (per_cu
!= NULL
)
19177 per_cu
->cu
->last_used
++;
19178 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
19179 dwarf2_mark (per_cu
->cu
);
19180 per_cu
= per_cu
->cu
->read_in_chain
;
19183 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19184 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19185 while (per_cu
!= NULL
)
19187 struct dwarf2_per_cu_data
*next_cu
;
19189 next_cu
= per_cu
->cu
->read_in_chain
;
19191 if (!per_cu
->cu
->mark
)
19193 free_heap_comp_unit (per_cu
->cu
);
19194 *last_chain
= next_cu
;
19197 last_chain
= &per_cu
->cu
->read_in_chain
;
19203 /* Remove a single compilation unit from the cache. */
19206 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
19208 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19210 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19211 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19212 while (per_cu
!= NULL
)
19214 struct dwarf2_per_cu_data
*next_cu
;
19216 next_cu
= per_cu
->cu
->read_in_chain
;
19218 if (per_cu
== target_per_cu
)
19220 free_heap_comp_unit (per_cu
->cu
);
19222 *last_chain
= next_cu
;
19226 last_chain
= &per_cu
->cu
->read_in_chain
;
19232 /* Release all extra memory associated with OBJFILE. */
19235 dwarf2_free_objfile (struct objfile
*objfile
)
19237 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19239 if (dwarf2_per_objfile
== NULL
)
19242 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
19243 free_cached_comp_units (NULL
);
19245 if (dwarf2_per_objfile
->quick_file_names_table
)
19246 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
19248 /* Everything else should be on the objfile obstack. */
19251 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
19252 We store these in a hash table separate from the DIEs, and preserve them
19253 when the DIEs are flushed out of cache.
19255 The CU "per_cu" pointer is needed because offset alone is not enough to
19256 uniquely identify the type. A file may have multiple .debug_types sections,
19257 or the type may come from a DWO file. We have to use something in
19258 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
19259 routine, get_die_type_at_offset, from outside this file, and thus won't
19260 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
19263 struct dwarf2_per_cu_offset_and_type
19265 const struct dwarf2_per_cu_data
*per_cu
;
19266 sect_offset offset
;
19270 /* Hash function for a dwarf2_per_cu_offset_and_type. */
19273 per_cu_offset_and_type_hash (const void *item
)
19275 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
19277 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
19280 /* Equality function for a dwarf2_per_cu_offset_and_type. */
19283 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
19285 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
19286 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
19288 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
19289 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
19292 /* Set the type associated with DIE to TYPE. Save it in CU's hash
19293 table if necessary. For convenience, return TYPE.
19295 The DIEs reading must have careful ordering to:
19296 * Not cause infite loops trying to read in DIEs as a prerequisite for
19297 reading current DIE.
19298 * Not trying to dereference contents of still incompletely read in types
19299 while reading in other DIEs.
19300 * Enable referencing still incompletely read in types just by a pointer to
19301 the type without accessing its fields.
19303 Therefore caller should follow these rules:
19304 * Try to fetch any prerequisite types we may need to build this DIE type
19305 before building the type and calling set_die_type.
19306 * After building type call set_die_type for current DIE as soon as
19307 possible before fetching more types to complete the current type.
19308 * Make the type as complete as possible before fetching more types. */
19310 static struct type
*
19311 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19313 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
19314 struct objfile
*objfile
= cu
->objfile
;
19316 /* For Ada types, make sure that the gnat-specific data is always
19317 initialized (if not already set). There are a few types where
19318 we should not be doing so, because the type-specific area is
19319 already used to hold some other piece of info (eg: TYPE_CODE_FLT
19320 where the type-specific area is used to store the floatformat).
19321 But this is not a problem, because the gnat-specific information
19322 is actually not needed for these types. */
19323 if (need_gnat_info (cu
)
19324 && TYPE_CODE (type
) != TYPE_CODE_FUNC
19325 && TYPE_CODE (type
) != TYPE_CODE_FLT
19326 && !HAVE_GNAT_AUX_INFO (type
))
19327 INIT_GNAT_SPECIFIC (type
);
19329 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19331 dwarf2_per_objfile
->die_type_hash
=
19332 htab_create_alloc_ex (127,
19333 per_cu_offset_and_type_hash
,
19334 per_cu_offset_and_type_eq
,
19336 &objfile
->objfile_obstack
,
19337 hashtab_obstack_allocate
,
19338 dummy_obstack_deallocate
);
19341 ofs
.per_cu
= cu
->per_cu
;
19342 ofs
.offset
= die
->offset
;
19344 slot
= (struct dwarf2_per_cu_offset_and_type
**)
19345 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
19347 complaint (&symfile_complaints
,
19348 _("A problem internal to GDB: DIE 0x%x has type already set"),
19349 die
->offset
.sect_off
);
19350 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
19355 /* Look up the type for the die at OFFSET in the appropriate type_hash
19356 table, or return NULL if the die does not have a saved type. */
19358 static struct type
*
19359 get_die_type_at_offset (sect_offset offset
,
19360 struct dwarf2_per_cu_data
*per_cu
)
19362 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
19364 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19367 ofs
.per_cu
= per_cu
;
19368 ofs
.offset
= offset
;
19369 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
19376 /* Look up the type for DIE in the appropriate type_hash table,
19377 or return NULL if DIE does not have a saved type. */
19379 static struct type
*
19380 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19382 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
19385 /* Add a dependence relationship from CU to REF_PER_CU. */
19388 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
19389 struct dwarf2_per_cu_data
*ref_per_cu
)
19393 if (cu
->dependencies
== NULL
)
19395 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
19396 NULL
, &cu
->comp_unit_obstack
,
19397 hashtab_obstack_allocate
,
19398 dummy_obstack_deallocate
);
19400 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
19402 *slot
= ref_per_cu
;
19405 /* Subroutine of dwarf2_mark to pass to htab_traverse.
19406 Set the mark field in every compilation unit in the
19407 cache that we must keep because we are keeping CU. */
19410 dwarf2_mark_helper (void **slot
, void *data
)
19412 struct dwarf2_per_cu_data
*per_cu
;
19414 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
19416 /* cu->dependencies references may not yet have been ever read if QUIT aborts
19417 reading of the chain. As such dependencies remain valid it is not much
19418 useful to track and undo them during QUIT cleanups. */
19419 if (per_cu
->cu
== NULL
)
19422 if (per_cu
->cu
->mark
)
19424 per_cu
->cu
->mark
= 1;
19426 if (per_cu
->cu
->dependencies
!= NULL
)
19427 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19432 /* Set the mark field in CU and in every other compilation unit in the
19433 cache that we must keep because we are keeping CU. */
19436 dwarf2_mark (struct dwarf2_cu
*cu
)
19441 if (cu
->dependencies
!= NULL
)
19442 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19446 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
19450 per_cu
->cu
->mark
= 0;
19451 per_cu
= per_cu
->cu
->read_in_chain
;
19455 /* Trivial hash function for partial_die_info: the hash value of a DIE
19456 is its offset in .debug_info for this objfile. */
19459 partial_die_hash (const void *item
)
19461 const struct partial_die_info
*part_die
= item
;
19463 return part_die
->offset
.sect_off
;
19466 /* Trivial comparison function for partial_die_info structures: two DIEs
19467 are equal if they have the same offset. */
19470 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
19472 const struct partial_die_info
*part_die_lhs
= item_lhs
;
19473 const struct partial_die_info
*part_die_rhs
= item_rhs
;
19475 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
19478 static struct cmd_list_element
*set_dwarf2_cmdlist
;
19479 static struct cmd_list_element
*show_dwarf2_cmdlist
;
19482 set_dwarf2_cmd (char *args
, int from_tty
)
19484 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
19488 show_dwarf2_cmd (char *args
, int from_tty
)
19490 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
19493 /* Free data associated with OBJFILE, if necessary. */
19496 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
19498 struct dwarf2_per_objfile
*data
= d
;
19501 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
19502 VEC_free (dwarf2_per_cu_ptr
,
19503 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
19505 VEC_free (dwarf2_section_info_def
, data
->types
);
19507 if (data
->dwo_files
)
19508 free_dwo_files (data
->dwo_files
, objfile
);
19510 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
19511 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
19515 /* The "save gdb-index" command. */
19517 /* The contents of the hash table we create when building the string
19519 struct strtab_entry
19521 offset_type offset
;
19525 /* Hash function for a strtab_entry.
19527 Function is used only during write_hash_table so no index format backward
19528 compatibility is needed. */
19531 hash_strtab_entry (const void *e
)
19533 const struct strtab_entry
*entry
= e
;
19534 return mapped_index_string_hash (INT_MAX
, entry
->str
);
19537 /* Equality function for a strtab_entry. */
19540 eq_strtab_entry (const void *a
, const void *b
)
19542 const struct strtab_entry
*ea
= a
;
19543 const struct strtab_entry
*eb
= b
;
19544 return !strcmp (ea
->str
, eb
->str
);
19547 /* Create a strtab_entry hash table. */
19550 create_strtab (void)
19552 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
19553 xfree
, xcalloc
, xfree
);
19556 /* Add a string to the constant pool. Return the string's offset in
19560 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
19563 struct strtab_entry entry
;
19564 struct strtab_entry
*result
;
19567 slot
= htab_find_slot (table
, &entry
, INSERT
);
19572 result
= XNEW (struct strtab_entry
);
19573 result
->offset
= obstack_object_size (cpool
);
19575 obstack_grow_str0 (cpool
, str
);
19578 return result
->offset
;
19581 /* An entry in the symbol table. */
19582 struct symtab_index_entry
19584 /* The name of the symbol. */
19586 /* The offset of the name in the constant pool. */
19587 offset_type index_offset
;
19588 /* A sorted vector of the indices of all the CUs that hold an object
19590 VEC (offset_type
) *cu_indices
;
19593 /* The symbol table. This is a power-of-2-sized hash table. */
19594 struct mapped_symtab
19596 offset_type n_elements
;
19598 struct symtab_index_entry
**data
;
19601 /* Hash function for a symtab_index_entry. */
19604 hash_symtab_entry (const void *e
)
19606 const struct symtab_index_entry
*entry
= e
;
19607 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
19608 sizeof (offset_type
) * VEC_length (offset_type
,
19609 entry
->cu_indices
),
19613 /* Equality function for a symtab_index_entry. */
19616 eq_symtab_entry (const void *a
, const void *b
)
19618 const struct symtab_index_entry
*ea
= a
;
19619 const struct symtab_index_entry
*eb
= b
;
19620 int len
= VEC_length (offset_type
, ea
->cu_indices
);
19621 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
19623 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
19624 VEC_address (offset_type
, eb
->cu_indices
),
19625 sizeof (offset_type
) * len
);
19628 /* Destroy a symtab_index_entry. */
19631 delete_symtab_entry (void *p
)
19633 struct symtab_index_entry
*entry
= p
;
19634 VEC_free (offset_type
, entry
->cu_indices
);
19638 /* Create a hash table holding symtab_index_entry objects. */
19641 create_symbol_hash_table (void)
19643 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
19644 delete_symtab_entry
, xcalloc
, xfree
);
19647 /* Create a new mapped symtab object. */
19649 static struct mapped_symtab
*
19650 create_mapped_symtab (void)
19652 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
19653 symtab
->n_elements
= 0;
19654 symtab
->size
= 1024;
19655 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19659 /* Destroy a mapped_symtab. */
19662 cleanup_mapped_symtab (void *p
)
19664 struct mapped_symtab
*symtab
= p
;
19665 /* The contents of the array are freed when the other hash table is
19667 xfree (symtab
->data
);
19671 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
19674 Function is used only during write_hash_table so no index format backward
19675 compatibility is needed. */
19677 static struct symtab_index_entry
**
19678 find_slot (struct mapped_symtab
*symtab
, const char *name
)
19680 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
19682 index
= hash
& (symtab
->size
- 1);
19683 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
19687 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
19688 return &symtab
->data
[index
];
19689 index
= (index
+ step
) & (symtab
->size
- 1);
19693 /* Expand SYMTAB's hash table. */
19696 hash_expand (struct mapped_symtab
*symtab
)
19698 offset_type old_size
= symtab
->size
;
19700 struct symtab_index_entry
**old_entries
= symtab
->data
;
19703 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19705 for (i
= 0; i
< old_size
; ++i
)
19707 if (old_entries
[i
])
19709 struct symtab_index_entry
**slot
= find_slot (symtab
,
19710 old_entries
[i
]->name
);
19711 *slot
= old_entries
[i
];
19715 xfree (old_entries
);
19718 /* Add an entry to SYMTAB. NAME is the name of the symbol.
19719 CU_INDEX is the index of the CU in which the symbol appears.
19720 IS_STATIC is one if the symbol is static, otherwise zero (global). */
19723 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
19724 int is_static
, gdb_index_symbol_kind kind
,
19725 offset_type cu_index
)
19727 struct symtab_index_entry
**slot
;
19728 offset_type cu_index_and_attrs
;
19730 ++symtab
->n_elements
;
19731 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
19732 hash_expand (symtab
);
19734 slot
= find_slot (symtab
, name
);
19737 *slot
= XNEW (struct symtab_index_entry
);
19738 (*slot
)->name
= name
;
19739 /* index_offset is set later. */
19740 (*slot
)->cu_indices
= NULL
;
19743 cu_index_and_attrs
= 0;
19744 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
19745 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
19746 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
19748 /* We don't want to record an index value twice as we want to avoid the
19750 We process all global symbols and then all static symbols
19751 (which would allow us to avoid the duplication by only having to check
19752 the last entry pushed), but a symbol could have multiple kinds in one CU.
19753 To keep things simple we don't worry about the duplication here and
19754 sort and uniqufy the list after we've processed all symbols. */
19755 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
19758 /* qsort helper routine for uniquify_cu_indices. */
19761 offset_type_compare (const void *ap
, const void *bp
)
19763 offset_type a
= *(offset_type
*) ap
;
19764 offset_type b
= *(offset_type
*) bp
;
19766 return (a
> b
) - (b
> a
);
19769 /* Sort and remove duplicates of all symbols' cu_indices lists. */
19772 uniquify_cu_indices (struct mapped_symtab
*symtab
)
19776 for (i
= 0; i
< symtab
->size
; ++i
)
19778 struct symtab_index_entry
*entry
= symtab
->data
[i
];
19781 && entry
->cu_indices
!= NULL
)
19783 unsigned int next_to_insert
, next_to_check
;
19784 offset_type last_value
;
19786 qsort (VEC_address (offset_type
, entry
->cu_indices
),
19787 VEC_length (offset_type
, entry
->cu_indices
),
19788 sizeof (offset_type
), offset_type_compare
);
19790 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
19791 next_to_insert
= 1;
19792 for (next_to_check
= 1;
19793 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
19796 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
19799 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
19801 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
19806 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
19811 /* Add a vector of indices to the constant pool. */
19814 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
19815 struct symtab_index_entry
*entry
)
19819 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
19822 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
19823 offset_type val
= MAYBE_SWAP (len
);
19828 entry
->index_offset
= obstack_object_size (cpool
);
19830 obstack_grow (cpool
, &val
, sizeof (val
));
19832 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
19835 val
= MAYBE_SWAP (iter
);
19836 obstack_grow (cpool
, &val
, sizeof (val
));
19841 struct symtab_index_entry
*old_entry
= *slot
;
19842 entry
->index_offset
= old_entry
->index_offset
;
19845 return entry
->index_offset
;
19848 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
19849 constant pool entries going into the obstack CPOOL. */
19852 write_hash_table (struct mapped_symtab
*symtab
,
19853 struct obstack
*output
, struct obstack
*cpool
)
19856 htab_t symbol_hash_table
;
19859 symbol_hash_table
= create_symbol_hash_table ();
19860 str_table
= create_strtab ();
19862 /* We add all the index vectors to the constant pool first, to
19863 ensure alignment is ok. */
19864 for (i
= 0; i
< symtab
->size
; ++i
)
19866 if (symtab
->data
[i
])
19867 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
19870 /* Now write out the hash table. */
19871 for (i
= 0; i
< symtab
->size
; ++i
)
19873 offset_type str_off
, vec_off
;
19875 if (symtab
->data
[i
])
19877 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
19878 vec_off
= symtab
->data
[i
]->index_offset
;
19882 /* While 0 is a valid constant pool index, it is not valid
19883 to have 0 for both offsets. */
19888 str_off
= MAYBE_SWAP (str_off
);
19889 vec_off
= MAYBE_SWAP (vec_off
);
19891 obstack_grow (output
, &str_off
, sizeof (str_off
));
19892 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
19895 htab_delete (str_table
);
19896 htab_delete (symbol_hash_table
);
19899 /* Struct to map psymtab to CU index in the index file. */
19900 struct psymtab_cu_index_map
19902 struct partial_symtab
*psymtab
;
19903 unsigned int cu_index
;
19907 hash_psymtab_cu_index (const void *item
)
19909 const struct psymtab_cu_index_map
*map
= item
;
19911 return htab_hash_pointer (map
->psymtab
);
19915 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
19917 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
19918 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
19920 return lhs
->psymtab
== rhs
->psymtab
;
19923 /* Helper struct for building the address table. */
19924 struct addrmap_index_data
19926 struct objfile
*objfile
;
19927 struct obstack
*addr_obstack
;
19928 htab_t cu_index_htab
;
19930 /* Non-zero if the previous_* fields are valid.
19931 We can't write an entry until we see the next entry (since it is only then
19932 that we know the end of the entry). */
19933 int previous_valid
;
19934 /* Index of the CU in the table of all CUs in the index file. */
19935 unsigned int previous_cu_index
;
19936 /* Start address of the CU. */
19937 CORE_ADDR previous_cu_start
;
19940 /* Write an address entry to OBSTACK. */
19943 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
19944 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
19946 offset_type cu_index_to_write
;
19948 CORE_ADDR baseaddr
;
19950 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19952 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
19953 obstack_grow (obstack
, addr
, 8);
19954 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
19955 obstack_grow (obstack
, addr
, 8);
19956 cu_index_to_write
= MAYBE_SWAP (cu_index
);
19957 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
19960 /* Worker function for traversing an addrmap to build the address table. */
19963 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
19965 struct addrmap_index_data
*data
= datap
;
19966 struct partial_symtab
*pst
= obj
;
19968 if (data
->previous_valid
)
19969 add_address_entry (data
->objfile
, data
->addr_obstack
,
19970 data
->previous_cu_start
, start_addr
,
19971 data
->previous_cu_index
);
19973 data
->previous_cu_start
= start_addr
;
19976 struct psymtab_cu_index_map find_map
, *map
;
19977 find_map
.psymtab
= pst
;
19978 map
= htab_find (data
->cu_index_htab
, &find_map
);
19979 gdb_assert (map
!= NULL
);
19980 data
->previous_cu_index
= map
->cu_index
;
19981 data
->previous_valid
= 1;
19984 data
->previous_valid
= 0;
19989 /* Write OBJFILE's address map to OBSTACK.
19990 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
19991 in the index file. */
19994 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
19995 htab_t cu_index_htab
)
19997 struct addrmap_index_data addrmap_index_data
;
19999 /* When writing the address table, we have to cope with the fact that
20000 the addrmap iterator only provides the start of a region; we have to
20001 wait until the next invocation to get the start of the next region. */
20003 addrmap_index_data
.objfile
= objfile
;
20004 addrmap_index_data
.addr_obstack
= obstack
;
20005 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
20006 addrmap_index_data
.previous_valid
= 0;
20008 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
20009 &addrmap_index_data
);
20011 /* It's highly unlikely the last entry (end address = 0xff...ff)
20012 is valid, but we should still handle it.
20013 The end address is recorded as the start of the next region, but that
20014 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
20016 if (addrmap_index_data
.previous_valid
)
20017 add_address_entry (objfile
, obstack
,
20018 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
20019 addrmap_index_data
.previous_cu_index
);
20022 /* Return the symbol kind of PSYM. */
20024 static gdb_index_symbol_kind
20025 symbol_kind (struct partial_symbol
*psym
)
20027 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
20028 enum address_class aclass
= PSYMBOL_CLASS (psym
);
20036 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
20038 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20040 case LOC_CONST_BYTES
:
20041 case LOC_OPTIMIZED_OUT
:
20043 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20045 /* Note: It's currently impossible to recognize psyms as enum values
20046 short of reading the type info. For now punt. */
20047 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20049 /* There are other LOC_FOO values that one might want to classify
20050 as variables, but dwarf2read.c doesn't currently use them. */
20051 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20053 case STRUCT_DOMAIN
:
20054 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20056 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20060 /* Add a list of partial symbols to SYMTAB. */
20063 write_psymbols (struct mapped_symtab
*symtab
,
20065 struct partial_symbol
**psymp
,
20067 offset_type cu_index
,
20070 for (; count
-- > 0; ++psymp
)
20072 struct partial_symbol
*psym
= *psymp
;
20075 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
20076 error (_("Ada is not currently supported by the index"));
20078 /* Only add a given psymbol once. */
20079 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
20082 gdb_index_symbol_kind kind
= symbol_kind (psym
);
20085 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
20086 is_static
, kind
, cu_index
);
20091 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
20092 exception if there is an error. */
20095 write_obstack (FILE *file
, struct obstack
*obstack
)
20097 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
20099 != obstack_object_size (obstack
))
20100 error (_("couldn't data write to file"));
20103 /* Unlink a file if the argument is not NULL. */
20106 unlink_if_set (void *p
)
20108 char **filename
= p
;
20110 unlink (*filename
);
20113 /* A helper struct used when iterating over debug_types. */
20114 struct signatured_type_index_data
20116 struct objfile
*objfile
;
20117 struct mapped_symtab
*symtab
;
20118 struct obstack
*types_list
;
20123 /* A helper function that writes a single signatured_type to an
20127 write_one_signatured_type (void **slot
, void *d
)
20129 struct signatured_type_index_data
*info
= d
;
20130 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
20131 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
20132 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20135 write_psymbols (info
->symtab
,
20137 info
->objfile
->global_psymbols
.list
20138 + psymtab
->globals_offset
,
20139 psymtab
->n_global_syms
, info
->cu_index
,
20141 write_psymbols (info
->symtab
,
20143 info
->objfile
->static_psymbols
.list
20144 + psymtab
->statics_offset
,
20145 psymtab
->n_static_syms
, info
->cu_index
,
20148 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20149 entry
->per_cu
.offset
.sect_off
);
20150 obstack_grow (info
->types_list
, val
, 8);
20151 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20152 entry
->type_offset_in_tu
.cu_off
);
20153 obstack_grow (info
->types_list
, val
, 8);
20154 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
20155 obstack_grow (info
->types_list
, val
, 8);
20162 /* Recurse into all "included" dependencies and write their symbols as
20163 if they appeared in this psymtab. */
20166 recursively_write_psymbols (struct objfile
*objfile
,
20167 struct partial_symtab
*psymtab
,
20168 struct mapped_symtab
*symtab
,
20170 offset_type cu_index
)
20174 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
20175 if (psymtab
->dependencies
[i
]->user
!= NULL
)
20176 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
20177 symtab
, psyms_seen
, cu_index
);
20179 write_psymbols (symtab
,
20181 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
20182 psymtab
->n_global_syms
, cu_index
,
20184 write_psymbols (symtab
,
20186 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
20187 psymtab
->n_static_syms
, cu_index
,
20191 /* Create an index file for OBJFILE in the directory DIR. */
20194 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
20196 struct cleanup
*cleanup
;
20197 char *filename
, *cleanup_filename
;
20198 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
20199 struct obstack cu_list
, types_cu_list
;
20202 struct mapped_symtab
*symtab
;
20203 offset_type val
, size_of_contents
, total_len
;
20206 htab_t cu_index_htab
;
20207 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
20209 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
20212 if (dwarf2_per_objfile
->using_index
)
20213 error (_("Cannot use an index to create the index"));
20215 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
20216 error (_("Cannot make an index when the file has multiple .debug_types sections"));
20218 if (stat (objfile
->name
, &st
) < 0)
20219 perror_with_name (objfile
->name
);
20221 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
20222 INDEX_SUFFIX
, (char *) NULL
);
20223 cleanup
= make_cleanup (xfree
, filename
);
20225 out_file
= fopen (filename
, "wb");
20227 error (_("Can't open `%s' for writing"), filename
);
20229 cleanup_filename
= filename
;
20230 make_cleanup (unlink_if_set
, &cleanup_filename
);
20232 symtab
= create_mapped_symtab ();
20233 make_cleanup (cleanup_mapped_symtab
, symtab
);
20235 obstack_init (&addr_obstack
);
20236 make_cleanup_obstack_free (&addr_obstack
);
20238 obstack_init (&cu_list
);
20239 make_cleanup_obstack_free (&cu_list
);
20241 obstack_init (&types_cu_list
);
20242 make_cleanup_obstack_free (&types_cu_list
);
20244 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
20245 NULL
, xcalloc
, xfree
);
20246 make_cleanup_htab_delete (psyms_seen
);
20248 /* While we're scanning CU's create a table that maps a psymtab pointer
20249 (which is what addrmap records) to its index (which is what is recorded
20250 in the index file). This will later be needed to write the address
20252 cu_index_htab
= htab_create_alloc (100,
20253 hash_psymtab_cu_index
,
20254 eq_psymtab_cu_index
,
20255 NULL
, xcalloc
, xfree
);
20256 make_cleanup_htab_delete (cu_index_htab
);
20257 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
20258 xmalloc (sizeof (struct psymtab_cu_index_map
)
20259 * dwarf2_per_objfile
->n_comp_units
);
20260 make_cleanup (xfree
, psymtab_cu_index_map
);
20262 /* The CU list is already sorted, so we don't need to do additional
20263 work here. Also, the debug_types entries do not appear in
20264 all_comp_units, but only in their own hash table. */
20265 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
20267 struct dwarf2_per_cu_data
*per_cu
20268 = dwarf2_per_objfile
->all_comp_units
[i
];
20269 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20271 struct psymtab_cu_index_map
*map
;
20274 if (psymtab
->user
== NULL
)
20275 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
20277 map
= &psymtab_cu_index_map
[i
];
20278 map
->psymtab
= psymtab
;
20280 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
20281 gdb_assert (slot
!= NULL
);
20282 gdb_assert (*slot
== NULL
);
20285 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20286 per_cu
->offset
.sect_off
);
20287 obstack_grow (&cu_list
, val
, 8);
20288 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
20289 obstack_grow (&cu_list
, val
, 8);
20292 /* Dump the address map. */
20293 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
20295 /* Write out the .debug_type entries, if any. */
20296 if (dwarf2_per_objfile
->signatured_types
)
20298 struct signatured_type_index_data sig_data
;
20300 sig_data
.objfile
= objfile
;
20301 sig_data
.symtab
= symtab
;
20302 sig_data
.types_list
= &types_cu_list
;
20303 sig_data
.psyms_seen
= psyms_seen
;
20304 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
20305 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
20306 write_one_signatured_type
, &sig_data
);
20309 /* Now that we've processed all symbols we can shrink their cu_indices
20311 uniquify_cu_indices (symtab
);
20313 obstack_init (&constant_pool
);
20314 make_cleanup_obstack_free (&constant_pool
);
20315 obstack_init (&symtab_obstack
);
20316 make_cleanup_obstack_free (&symtab_obstack
);
20317 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
20319 obstack_init (&contents
);
20320 make_cleanup_obstack_free (&contents
);
20321 size_of_contents
= 6 * sizeof (offset_type
);
20322 total_len
= size_of_contents
;
20324 /* The version number. */
20325 val
= MAYBE_SWAP (7);
20326 obstack_grow (&contents
, &val
, sizeof (val
));
20328 /* The offset of the CU list from the start of the file. */
20329 val
= MAYBE_SWAP (total_len
);
20330 obstack_grow (&contents
, &val
, sizeof (val
));
20331 total_len
+= obstack_object_size (&cu_list
);
20333 /* The offset of the types CU list from the start of the file. */
20334 val
= MAYBE_SWAP (total_len
);
20335 obstack_grow (&contents
, &val
, sizeof (val
));
20336 total_len
+= obstack_object_size (&types_cu_list
);
20338 /* The offset of the address table from the start of the file. */
20339 val
= MAYBE_SWAP (total_len
);
20340 obstack_grow (&contents
, &val
, sizeof (val
));
20341 total_len
+= obstack_object_size (&addr_obstack
);
20343 /* The offset of the symbol table from the start of the file. */
20344 val
= MAYBE_SWAP (total_len
);
20345 obstack_grow (&contents
, &val
, sizeof (val
));
20346 total_len
+= obstack_object_size (&symtab_obstack
);
20348 /* The offset of the constant pool from the start of the file. */
20349 val
= MAYBE_SWAP (total_len
);
20350 obstack_grow (&contents
, &val
, sizeof (val
));
20351 total_len
+= obstack_object_size (&constant_pool
);
20353 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
20355 write_obstack (out_file
, &contents
);
20356 write_obstack (out_file
, &cu_list
);
20357 write_obstack (out_file
, &types_cu_list
);
20358 write_obstack (out_file
, &addr_obstack
);
20359 write_obstack (out_file
, &symtab_obstack
);
20360 write_obstack (out_file
, &constant_pool
);
20364 /* We want to keep the file, so we set cleanup_filename to NULL
20365 here. See unlink_if_set. */
20366 cleanup_filename
= NULL
;
20368 do_cleanups (cleanup
);
20371 /* Implementation of the `save gdb-index' command.
20373 Note that the file format used by this command is documented in the
20374 GDB manual. Any changes here must be documented there. */
20377 save_gdb_index_command (char *arg
, int from_tty
)
20379 struct objfile
*objfile
;
20382 error (_("usage: save gdb-index DIRECTORY"));
20384 ALL_OBJFILES (objfile
)
20388 /* If the objfile does not correspond to an actual file, skip it. */
20389 if (stat (objfile
->name
, &st
) < 0)
20392 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
20393 if (dwarf2_per_objfile
)
20395 volatile struct gdb_exception except
;
20397 TRY_CATCH (except
, RETURN_MASK_ERROR
)
20399 write_psymtabs_to_index (objfile
, arg
);
20401 if (except
.reason
< 0)
20402 exception_fprintf (gdb_stderr
, except
,
20403 _("Error while writing index for `%s': "),
20411 int dwarf2_always_disassemble
;
20414 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
20415 struct cmd_list_element
*c
, const char *value
)
20417 fprintf_filtered (file
,
20418 _("Whether to always disassemble "
20419 "DWARF expressions is %s.\n"),
20424 show_check_physname (struct ui_file
*file
, int from_tty
,
20425 struct cmd_list_element
*c
, const char *value
)
20427 fprintf_filtered (file
,
20428 _("Whether to check \"physname\" is %s.\n"),
20432 void _initialize_dwarf2_read (void);
20435 _initialize_dwarf2_read (void)
20437 struct cmd_list_element
*c
;
20439 dwarf2_objfile_data_key
20440 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
20442 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
20443 Set DWARF 2 specific variables.\n\
20444 Configure DWARF 2 variables such as the cache size"),
20445 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
20446 0/*allow-unknown*/, &maintenance_set_cmdlist
);
20448 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
20449 Show DWARF 2 specific variables\n\
20450 Show DWARF 2 variables such as the cache size"),
20451 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
20452 0/*allow-unknown*/, &maintenance_show_cmdlist
);
20454 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
20455 &dwarf2_max_cache_age
, _("\
20456 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
20457 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
20458 A higher limit means that cached compilation units will be stored\n\
20459 in memory longer, and more total memory will be used. Zero disables\n\
20460 caching, which can slow down startup."),
20462 show_dwarf2_max_cache_age
,
20463 &set_dwarf2_cmdlist
,
20464 &show_dwarf2_cmdlist
);
20466 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
20467 &dwarf2_always_disassemble
, _("\
20468 Set whether `info address' always disassembles DWARF expressions."), _("\
20469 Show whether `info address' always disassembles DWARF expressions."), _("\
20470 When enabled, DWARF expressions are always printed in an assembly-like\n\
20471 syntax. When disabled, expressions will be printed in a more\n\
20472 conversational style, when possible."),
20474 show_dwarf2_always_disassemble
,
20475 &set_dwarf2_cmdlist
,
20476 &show_dwarf2_cmdlist
);
20478 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
20479 Set debugging of the dwarf2 reader."), _("\
20480 Show debugging of the dwarf2 reader."), _("\
20481 When enabled, debugging messages are printed during dwarf2 reading\n\
20482 and symtab expansion."),
20485 &setdebuglist
, &showdebuglist
);
20487 add_setshow_zuinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
20488 Set debugging of the dwarf2 DIE reader."), _("\
20489 Show debugging of the dwarf2 DIE reader."), _("\
20490 When enabled (non-zero), DIEs are dumped after they are read in.\n\
20491 The value is the maximum depth to print."),
20494 &setdebuglist
, &showdebuglist
);
20496 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
20497 Set cross-checking of \"physname\" code against demangler."), _("\
20498 Show cross-checking of \"physname\" code against demangler."), _("\
20499 When enabled, GDB's internal \"physname\" code is checked against\n\
20501 NULL
, show_check_physname
,
20502 &setdebuglist
, &showdebuglist
);
20504 add_setshow_boolean_cmd ("use-deprecated-index-sections",
20505 no_class
, &use_deprecated_index_sections
, _("\
20506 Set whether to use deprecated gdb_index sections."), _("\
20507 Show whether to use deprecated gdb_index sections."), _("\
20508 When enabled, deprecated .gdb_index sections are used anyway.\n\
20509 Normally they are ignored either because of a missing feature or\n\
20510 performance issue.\n\
20511 Warning: This option must be enabled before gdb reads the file."),
20514 &setlist
, &showlist
);
20516 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
20518 Save a gdb-index file.\n\
20519 Usage: save gdb-index DIRECTORY"),
20521 set_cmd_completer (c
, filename_completer
);