1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2013 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
40 #include "gdb-demangle.h"
41 #include "expression.h"
42 #include "filenames.h" /* for DOSish file names */
45 #include "complaints.h"
47 #include "dwarf2expr.h"
48 #include "dwarf2loc.h"
49 #include "cp-support.h"
55 #include "typeprint.h"
58 #include "exceptions.h"
60 #include "completer.h"
65 #include "gdbcore.h" /* for gnutarget */
66 #include "gdb/gdb-index.h"
72 #include "gdb_string.h"
73 #include "gdb_assert.h"
74 #include <sys/types.h>
76 typedef struct symbol
*symbolp
;
79 /* When non-zero, print basic high level tracing messages.
80 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
81 static int dwarf2_read_debug
= 0;
83 /* When non-zero, dump DIEs after they are read in. */
84 static unsigned int dwarf2_die_debug
= 0;
86 /* When non-zero, cross-check physname against demangler. */
87 static int check_physname
= 0;
89 /* When non-zero, do not reject deprecated .gdb_index sections. */
90 static int use_deprecated_index_sections
= 0;
92 /* When set, the file that we're processing is known to have debugging
93 info for C++ namespaces. GCC 3.3.x did not produce this information,
94 but later versions do. */
96 static int processing_has_namespace_info
;
98 static const struct objfile_data
*dwarf2_objfile_data_key
;
100 struct dwarf2_section_info
105 /* True if we have tried to read this section. */
109 typedef struct dwarf2_section_info dwarf2_section_info_def
;
110 DEF_VEC_O (dwarf2_section_info_def
);
112 /* All offsets in the index are of this type. It must be
113 architecture-independent. */
114 typedef uint32_t offset_type
;
116 DEF_VEC_I (offset_type
);
118 /* Ensure only legit values are used. */
119 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
121 gdb_assert ((unsigned int) (value) <= 1); \
122 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
125 /* Ensure only legit values are used. */
126 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
128 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
129 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
130 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
133 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
134 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
136 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
137 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
140 /* A description of the mapped index. The file format is described in
141 a comment by the code that writes the index. */
144 /* Index data format version. */
147 /* The total length of the buffer. */
150 /* A pointer to the address table data. */
151 const gdb_byte
*address_table
;
153 /* Size of the address table data in bytes. */
154 offset_type address_table_size
;
156 /* The symbol table, implemented as a hash table. */
157 const offset_type
*symbol_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type symbol_table_slots
;
162 /* A pointer to the constant pool. */
163 const char *constant_pool
;
166 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
167 DEF_VEC_P (dwarf2_per_cu_ptr
);
169 /* Collection of data recorded per objfile.
170 This hangs off of dwarf2_objfile_data_key. */
172 struct dwarf2_per_objfile
174 struct dwarf2_section_info info
;
175 struct dwarf2_section_info abbrev
;
176 struct dwarf2_section_info line
;
177 struct dwarf2_section_info loc
;
178 struct dwarf2_section_info macinfo
;
179 struct dwarf2_section_info macro
;
180 struct dwarf2_section_info str
;
181 struct dwarf2_section_info ranges
;
182 struct dwarf2_section_info addr
;
183 struct dwarf2_section_info frame
;
184 struct dwarf2_section_info eh_frame
;
185 struct dwarf2_section_info gdb_index
;
187 VEC (dwarf2_section_info_def
) *types
;
190 struct objfile
*objfile
;
192 /* Table of all the compilation units. This is used to locate
193 the target compilation unit of a particular reference. */
194 struct dwarf2_per_cu_data
**all_comp_units
;
196 /* The number of compilation units in ALL_COMP_UNITS. */
199 /* The number of .debug_types-related CUs. */
202 /* The .debug_types-related CUs (TUs). */
203 struct signatured_type
**all_type_units
;
205 /* The number of entries in all_type_unit_groups. */
206 int n_type_unit_groups
;
208 /* Table of type unit groups.
209 This exists to make it easy to iterate over all CUs and TU groups. */
210 struct type_unit_group
**all_type_unit_groups
;
212 /* Table of struct type_unit_group objects.
213 The hash key is the DW_AT_stmt_list value. */
214 htab_t type_unit_groups
;
216 /* A table mapping .debug_types signatures to its signatured_type entry.
217 This is NULL if the .debug_types section hasn't been read in yet. */
218 htab_t signatured_types
;
220 /* Type unit statistics, to see how well the scaling improvements
224 int nr_uniq_abbrev_tables
;
226 int nr_symtab_sharers
;
227 int nr_stmt_less_type_units
;
230 /* A chain of compilation units that are currently read in, so that
231 they can be freed later. */
232 struct dwarf2_per_cu_data
*read_in_chain
;
234 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
235 This is NULL if the table hasn't been allocated yet. */
238 /* Non-zero if we've check for whether there is a DWP file. */
241 /* The DWP file if there is one, or NULL. */
242 struct dwp_file
*dwp_file
;
244 /* The shared '.dwz' file, if one exists. This is used when the
245 original data was compressed using 'dwz -m'. */
246 struct dwz_file
*dwz_file
;
248 /* A flag indicating wether this objfile has a section loaded at a
250 int has_section_at_zero
;
252 /* True if we are using the mapped index,
253 or we are faking it for OBJF_READNOW's sake. */
254 unsigned char using_index
;
256 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
257 struct mapped_index
*index_table
;
259 /* When using index_table, this keeps track of all quick_file_names entries.
260 TUs typically share line table entries with a CU, so we maintain a
261 separate table of all line table entries to support the sharing.
262 Note that while there can be way more TUs than CUs, we've already
263 sorted all the TUs into "type unit groups", grouped by their
264 DW_AT_stmt_list value. Therefore the only sharing done here is with a
265 CU and its associated TU group if there is one. */
266 htab_t quick_file_names_table
;
268 /* Set during partial symbol reading, to prevent queueing of full
270 int reading_partial_symbols
;
272 /* Table mapping type DIEs to their struct type *.
273 This is NULL if not allocated yet.
274 The mapping is done via (CU/TU signature + DIE offset) -> type. */
275 htab_t die_type_hash
;
277 /* The CUs we recently read. */
278 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
281 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
283 /* Default names of the debugging sections. */
285 /* Note that if the debugging section has been compressed, it might
286 have a name like .zdebug_info. */
288 static const struct dwarf2_debug_sections dwarf2_elf_names
=
290 { ".debug_info", ".zdebug_info" },
291 { ".debug_abbrev", ".zdebug_abbrev" },
292 { ".debug_line", ".zdebug_line" },
293 { ".debug_loc", ".zdebug_loc" },
294 { ".debug_macinfo", ".zdebug_macinfo" },
295 { ".debug_macro", ".zdebug_macro" },
296 { ".debug_str", ".zdebug_str" },
297 { ".debug_ranges", ".zdebug_ranges" },
298 { ".debug_types", ".zdebug_types" },
299 { ".debug_addr", ".zdebug_addr" },
300 { ".debug_frame", ".zdebug_frame" },
301 { ".eh_frame", NULL
},
302 { ".gdb_index", ".zgdb_index" },
306 /* List of DWO/DWP sections. */
308 static const struct dwop_section_names
310 struct dwarf2_section_names abbrev_dwo
;
311 struct dwarf2_section_names info_dwo
;
312 struct dwarf2_section_names line_dwo
;
313 struct dwarf2_section_names loc_dwo
;
314 struct dwarf2_section_names macinfo_dwo
;
315 struct dwarf2_section_names macro_dwo
;
316 struct dwarf2_section_names str_dwo
;
317 struct dwarf2_section_names str_offsets_dwo
;
318 struct dwarf2_section_names types_dwo
;
319 struct dwarf2_section_names cu_index
;
320 struct dwarf2_section_names tu_index
;
324 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
325 { ".debug_info.dwo", ".zdebug_info.dwo" },
326 { ".debug_line.dwo", ".zdebug_line.dwo" },
327 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
328 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
329 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
330 { ".debug_str.dwo", ".zdebug_str.dwo" },
331 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
332 { ".debug_types.dwo", ".zdebug_types.dwo" },
333 { ".debug_cu_index", ".zdebug_cu_index" },
334 { ".debug_tu_index", ".zdebug_tu_index" },
337 /* local data types */
339 /* The data in a compilation unit header, after target2host
340 translation, looks like this. */
341 struct comp_unit_head
345 unsigned char addr_size
;
346 unsigned char signed_addr_p
;
347 sect_offset abbrev_offset
;
349 /* Size of file offsets; either 4 or 8. */
350 unsigned int offset_size
;
352 /* Size of the length field; either 4 or 12. */
353 unsigned int initial_length_size
;
355 /* Offset to the first byte of this compilation unit header in the
356 .debug_info section, for resolving relative reference dies. */
359 /* Offset to first die in this cu from the start of the cu.
360 This will be the first byte following the compilation unit header. */
361 cu_offset first_die_offset
;
364 /* Type used for delaying computation of method physnames.
365 See comments for compute_delayed_physnames. */
366 struct delayed_method_info
368 /* The type to which the method is attached, i.e., its parent class. */
371 /* The index of the method in the type's function fieldlists. */
374 /* The index of the method in the fieldlist. */
377 /* The name of the DIE. */
380 /* The DIE associated with this method. */
381 struct die_info
*die
;
384 typedef struct delayed_method_info delayed_method_info
;
385 DEF_VEC_O (delayed_method_info
);
387 /* Internal state when decoding a particular compilation unit. */
390 /* The objfile containing this compilation unit. */
391 struct objfile
*objfile
;
393 /* The header of the compilation unit. */
394 struct comp_unit_head header
;
396 /* Base address of this compilation unit. */
397 CORE_ADDR base_address
;
399 /* Non-zero if base_address has been set. */
402 /* The language we are debugging. */
403 enum language language
;
404 const struct language_defn
*language_defn
;
406 const char *producer
;
408 /* The generic symbol table building routines have separate lists for
409 file scope symbols and all all other scopes (local scopes). So
410 we need to select the right one to pass to add_symbol_to_list().
411 We do it by keeping a pointer to the correct list in list_in_scope.
413 FIXME: The original dwarf code just treated the file scope as the
414 first local scope, and all other local scopes as nested local
415 scopes, and worked fine. Check to see if we really need to
416 distinguish these in buildsym.c. */
417 struct pending
**list_in_scope
;
419 /* The abbrev table for this CU.
420 Normally this points to the abbrev table in the objfile.
421 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
422 struct abbrev_table
*abbrev_table
;
424 /* Hash table holding all the loaded partial DIEs
425 with partial_die->offset.SECT_OFF as hash. */
428 /* Storage for things with the same lifetime as this read-in compilation
429 unit, including partial DIEs. */
430 struct obstack comp_unit_obstack
;
432 /* When multiple dwarf2_cu structures are living in memory, this field
433 chains them all together, so that they can be released efficiently.
434 We will probably also want a generation counter so that most-recently-used
435 compilation units are cached... */
436 struct dwarf2_per_cu_data
*read_in_chain
;
438 /* Backchain to our per_cu entry if the tree has been built. */
439 struct dwarf2_per_cu_data
*per_cu
;
441 /* How many compilation units ago was this CU last referenced? */
444 /* A hash table of DIE cu_offset for following references with
445 die_info->offset.sect_off as hash. */
448 /* Full DIEs if read in. */
449 struct die_info
*dies
;
451 /* A set of pointers to dwarf2_per_cu_data objects for compilation
452 units referenced by this one. Only set during full symbol processing;
453 partial symbol tables do not have dependencies. */
456 /* Header data from the line table, during full symbol processing. */
457 struct line_header
*line_header
;
459 /* A list of methods which need to have physnames computed
460 after all type information has been read. */
461 VEC (delayed_method_info
) *method_list
;
463 /* To be copied to symtab->call_site_htab. */
464 htab_t call_site_htab
;
466 /* Non-NULL if this CU came from a DWO file.
467 There is an invariant here that is important to remember:
468 Except for attributes copied from the top level DIE in the "main"
469 (or "stub") file in preparation for reading the DWO file
470 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
471 Either there isn't a DWO file (in which case this is NULL and the point
472 is moot), or there is and either we're not going to read it (in which
473 case this is NULL) or there is and we are reading it (in which case this
475 struct dwo_unit
*dwo_unit
;
477 /* The DW_AT_addr_base attribute if present, zero otherwise
478 (zero is a valid value though).
479 Note this value comes from the stub CU/TU's DIE. */
482 /* The DW_AT_ranges_base attribute if present, zero otherwise
483 (zero is a valid value though).
484 Note this value comes from the stub CU/TU's DIE.
485 Also note that the value is zero in the non-DWO case so this value can
486 be used without needing to know whether DWO files are in use or not.
487 N.B. This does not apply to DW_AT_ranges appearing in
488 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
489 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
490 DW_AT_ranges_base *would* have to be applied, and we'd have to care
491 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
492 ULONGEST ranges_base
;
494 /* Mark used when releasing cached dies. */
495 unsigned int mark
: 1;
497 /* This CU references .debug_loc. See the symtab->locations_valid field.
498 This test is imperfect as there may exist optimized debug code not using
499 any location list and still facing inlining issues if handled as
500 unoptimized code. For a future better test see GCC PR other/32998. */
501 unsigned int has_loclist
: 1;
503 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
504 if all the producer_is_* fields are valid. This information is cached
505 because profiling CU expansion showed excessive time spent in
506 producer_is_gxx_lt_4_6. */
507 unsigned int checked_producer
: 1;
508 unsigned int producer_is_gxx_lt_4_6
: 1;
509 unsigned int producer_is_gcc_lt_4_3
: 1;
510 unsigned int producer_is_icc
: 1;
513 /* Persistent data held for a compilation unit, even when not
514 processing it. We put a pointer to this structure in the
515 read_symtab_private field of the psymtab. */
517 struct dwarf2_per_cu_data
519 /* The start offset and length of this compilation unit.
520 NOTE: Unlike comp_unit_head.length, this length includes
522 If the DIE refers to a DWO file, this is always of the original die,
527 /* Flag indicating this compilation unit will be read in before
528 any of the current compilation units are processed. */
529 unsigned int queued
: 1;
531 /* This flag will be set when reading partial DIEs if we need to load
532 absolutely all DIEs for this compilation unit, instead of just the ones
533 we think are interesting. It gets set if we look for a DIE in the
534 hash table and don't find it. */
535 unsigned int load_all_dies
: 1;
537 /* Non-zero if this CU is from .debug_types. */
538 unsigned int is_debug_types
: 1;
540 /* Non-zero if this CU is from the .dwz file. */
541 unsigned int is_dwz
: 1;
543 /* The section this CU/TU lives in.
544 If the DIE refers to a DWO file, this is always the original die,
546 struct dwarf2_section_info
*info_or_types_section
;
548 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
549 of the CU cache it gets reset to NULL again. */
550 struct dwarf2_cu
*cu
;
552 /* The corresponding objfile.
553 Normally we can get the objfile from dwarf2_per_objfile.
554 However we can enter this file with just a "per_cu" handle. */
555 struct objfile
*objfile
;
557 /* When using partial symbol tables, the 'psymtab' field is active.
558 Otherwise the 'quick' field is active. */
561 /* The partial symbol table associated with this compilation unit,
562 or NULL for unread partial units. */
563 struct partial_symtab
*psymtab
;
565 /* Data needed by the "quick" functions. */
566 struct dwarf2_per_cu_quick_data
*quick
;
571 /* The CUs we import using DW_TAG_imported_unit. This is filled in
572 while reading psymtabs, used to compute the psymtab dependencies,
573 and then cleared. Then it is filled in again while reading full
574 symbols, and only deleted when the objfile is destroyed. */
575 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
577 /* Type units are grouped by their DW_AT_stmt_list entry so that they
578 can share them. If this is a TU, this points to the containing
580 struct type_unit_group
*type_unit_group
;
584 /* Entry in the signatured_types hash table. */
586 struct signatured_type
588 /* The "per_cu" object of this type.
589 N.B.: This is the first member so that it's easy to convert pointers
591 struct dwarf2_per_cu_data per_cu
;
593 /* The type's signature. */
596 /* Offset in the TU of the type's DIE, as read from the TU header.
597 If the definition lives in a DWO file, this value is unusable. */
598 cu_offset type_offset_in_tu
;
600 /* Offset in the section of the type's DIE.
601 If the definition lives in a DWO file, this is the offset in the
602 .debug_types.dwo section.
603 The value is zero until the actual value is known.
604 Zero is otherwise not a valid section offset. */
605 sect_offset type_offset_in_section
;
608 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
609 This includes type_unit_group and quick_file_names. */
611 struct stmt_list_hash
613 /* The DWO unit this table is from or NULL if there is none. */
614 struct dwo_unit
*dwo_unit
;
616 /* Offset in .debug_line or .debug_line.dwo. */
617 sect_offset line_offset
;
620 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
621 an object of this type. */
623 struct type_unit_group
625 /* dwarf2read.c's main "handle" on the symtab.
626 To simplify things we create an artificial CU that "includes" all the
627 type units using this stmt_list so that the rest of the code still has
628 a "per_cu" handle on the symtab.
629 This PER_CU is recognized by having no section. */
630 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
631 struct dwarf2_per_cu_data per_cu
;
635 /* The TUs that share this DW_AT_stmt_list entry.
636 This is added to while parsing type units to build partial symtabs,
637 and is deleted afterwards and not used again. */
638 VEC (dwarf2_per_cu_ptr
) *tus
;
640 /* When reading the line table in "quick" functions, we need a real TU.
641 Any will do, we know they all share the same DW_AT_stmt_list entry.
642 For simplicity's sake, we pick the first one. */
643 struct dwarf2_per_cu_data
*first_tu
;
646 /* The primary symtab.
647 Type units in a group needn't all be defined in the same source file,
648 so we create an essentially anonymous symtab as the primary symtab. */
649 struct symtab
*primary_symtab
;
651 /* The data used to construct the hash key. */
652 struct stmt_list_hash hash
;
654 /* The number of symtabs from the line header.
655 The value here must match line_header.num_file_names. */
656 unsigned int num_symtabs
;
658 /* The symbol tables for this TU (obtained from the files listed in
660 WARNING: The order of entries here must match the order of entries
661 in the line header. After the first TU using this type_unit_group, the
662 line header for the subsequent TUs is recreated from this. This is done
663 because we need to use the same symtabs for each TU using the same
664 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
665 there's no guarantee the line header doesn't have duplicate entries. */
666 struct symtab
**symtabs
;
669 /* These sections are what may appear in a DWO file. */
673 struct dwarf2_section_info abbrev
;
674 struct dwarf2_section_info line
;
675 struct dwarf2_section_info loc
;
676 struct dwarf2_section_info macinfo
;
677 struct dwarf2_section_info macro
;
678 struct dwarf2_section_info str
;
679 struct dwarf2_section_info str_offsets
;
680 /* In the case of a virtual DWO file, these two are unused. */
681 struct dwarf2_section_info info
;
682 VEC (dwarf2_section_info_def
) *types
;
685 /* Common bits of DWO CUs/TUs. */
689 /* Backlink to the containing struct dwo_file. */
690 struct dwo_file
*dwo_file
;
692 /* The "id" that distinguishes this CU/TU.
693 .debug_info calls this "dwo_id", .debug_types calls this "signature".
694 Since signatures came first, we stick with it for consistency. */
697 /* The section this CU/TU lives in, in the DWO file. */
698 struct dwarf2_section_info
*info_or_types_section
;
700 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
704 /* For types, offset in the type's DIE of the type defined by this TU. */
705 cu_offset type_offset_in_tu
;
708 /* Data for one DWO file.
709 This includes virtual DWO files that have been packaged into a
714 /* The DW_AT_GNU_dwo_name attribute. This is the hash key.
715 For virtual DWO files the name is constructed from the section offsets
716 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
717 from related CU+TUs. */
720 /* The bfd, when the file is open. Otherwise this is NULL.
721 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
724 /* Section info for this file. */
725 struct dwo_sections sections
;
727 /* Table of CUs in the file.
728 Each element is a struct dwo_unit. */
731 /* Table of TUs in the file.
732 Each element is a struct dwo_unit. */
736 /* These sections are what may appear in a DWP file. */
740 struct dwarf2_section_info str
;
741 struct dwarf2_section_info cu_index
;
742 struct dwarf2_section_info tu_index
;
743 /* The .debug_info.dwo, .debug_types.dwo, and other sections are referenced
744 by section number. We don't need to record them here. */
747 /* These sections are what may appear in a virtual DWO file. */
749 struct virtual_dwo_sections
751 struct dwarf2_section_info abbrev
;
752 struct dwarf2_section_info line
;
753 struct dwarf2_section_info loc
;
754 struct dwarf2_section_info macinfo
;
755 struct dwarf2_section_info macro
;
756 struct dwarf2_section_info str_offsets
;
757 /* Each DWP hash table entry records one CU or one TU.
758 That is recorded here, and copied to dwo_unit.info_or_types_section. */
759 struct dwarf2_section_info info_or_types
;
762 /* Contents of DWP hash tables. */
764 struct dwp_hash_table
766 uint32_t nr_units
, nr_slots
;
767 const gdb_byte
*hash_table
, *unit_table
, *section_pool
;
770 /* Data for one DWP file. */
774 /* Name of the file. */
777 /* The bfd, when the file is open. Otherwise this is NULL. */
780 /* Section info for this file. */
781 struct dwp_sections sections
;
783 /* Table of CUs in the file. */
784 const struct dwp_hash_table
*cus
;
786 /* Table of TUs in the file. */
787 const struct dwp_hash_table
*tus
;
789 /* Table of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
792 /* Table to map ELF section numbers to their sections. */
793 unsigned int num_sections
;
794 asection
**elf_sections
;
797 /* This represents a '.dwz' file. */
801 /* A dwz file can only contain a few sections. */
802 struct dwarf2_section_info abbrev
;
803 struct dwarf2_section_info info
;
804 struct dwarf2_section_info str
;
805 struct dwarf2_section_info line
;
806 struct dwarf2_section_info macro
;
807 struct dwarf2_section_info gdb_index
;
813 /* Struct used to pass misc. parameters to read_die_and_children, et
814 al. which are used for both .debug_info and .debug_types dies.
815 All parameters here are unchanging for the life of the call. This
816 struct exists to abstract away the constant parameters of die reading. */
818 struct die_reader_specs
820 /* die_section->asection->owner. */
823 /* The CU of the DIE we are parsing. */
824 struct dwarf2_cu
*cu
;
826 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
827 struct dwo_file
*dwo_file
;
829 /* The section the die comes from.
830 This is either .debug_info or .debug_types, or the .dwo variants. */
831 struct dwarf2_section_info
*die_section
;
833 /* die_section->buffer. */
836 /* The end of the buffer. */
837 const gdb_byte
*buffer_end
;
840 /* Type of function passed to init_cutu_and_read_dies, et.al. */
841 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
843 struct die_info
*comp_unit_die
,
847 /* The line number information for a compilation unit (found in the
848 .debug_line section) begins with a "statement program header",
849 which contains the following information. */
852 unsigned int total_length
;
853 unsigned short version
;
854 unsigned int header_length
;
855 unsigned char minimum_instruction_length
;
856 unsigned char maximum_ops_per_instruction
;
857 unsigned char default_is_stmt
;
859 unsigned char line_range
;
860 unsigned char opcode_base
;
862 /* standard_opcode_lengths[i] is the number of operands for the
863 standard opcode whose value is i. This means that
864 standard_opcode_lengths[0] is unused, and the last meaningful
865 element is standard_opcode_lengths[opcode_base - 1]. */
866 unsigned char *standard_opcode_lengths
;
868 /* The include_directories table. NOTE! These strings are not
869 allocated with xmalloc; instead, they are pointers into
870 debug_line_buffer. If you try to free them, `free' will get
872 unsigned int num_include_dirs
, include_dirs_size
;
875 /* The file_names table. NOTE! These strings are not allocated
876 with xmalloc; instead, they are pointers into debug_line_buffer.
877 Don't try to free them directly. */
878 unsigned int num_file_names
, file_names_size
;
882 unsigned int dir_index
;
883 unsigned int mod_time
;
885 int included_p
; /* Non-zero if referenced by the Line Number Program. */
886 struct symtab
*symtab
; /* The associated symbol table, if any. */
889 /* The start and end of the statement program following this
890 header. These point into dwarf2_per_objfile->line_buffer. */
891 gdb_byte
*statement_program_start
, *statement_program_end
;
894 /* When we construct a partial symbol table entry we only
895 need this much information. */
896 struct partial_die_info
898 /* Offset of this DIE. */
901 /* DWARF-2 tag for this DIE. */
902 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
904 /* Assorted flags describing the data found in this DIE. */
905 unsigned int has_children
: 1;
906 unsigned int is_external
: 1;
907 unsigned int is_declaration
: 1;
908 unsigned int has_type
: 1;
909 unsigned int has_specification
: 1;
910 unsigned int has_pc_info
: 1;
911 unsigned int may_be_inlined
: 1;
913 /* Flag set if the SCOPE field of this structure has been
915 unsigned int scope_set
: 1;
917 /* Flag set if the DIE has a byte_size attribute. */
918 unsigned int has_byte_size
: 1;
920 /* Flag set if any of the DIE's children are template arguments. */
921 unsigned int has_template_arguments
: 1;
923 /* Flag set if fixup_partial_die has been called on this die. */
924 unsigned int fixup_called
: 1;
926 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
927 unsigned int is_dwz
: 1;
929 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
930 unsigned int spec_is_dwz
: 1;
932 /* The name of this DIE. Normally the value of DW_AT_name, but
933 sometimes a default name for unnamed DIEs. */
936 /* The linkage name, if present. */
937 const char *linkage_name
;
939 /* The scope to prepend to our children. This is generally
940 allocated on the comp_unit_obstack, so will disappear
941 when this compilation unit leaves the cache. */
944 /* Some data associated with the partial DIE. The tag determines
945 which field is live. */
948 /* The location description associated with this DIE, if any. */
949 struct dwarf_block
*locdesc
;
950 /* The offset of an import, for DW_TAG_imported_unit. */
954 /* If HAS_PC_INFO, the PC range associated with this DIE. */
958 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
959 DW_AT_sibling, if any. */
960 /* NOTE: This member isn't strictly necessary, read_partial_die could
961 return DW_AT_sibling values to its caller load_partial_dies. */
964 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
965 DW_AT_specification (or DW_AT_abstract_origin or
967 sect_offset spec_offset
;
969 /* Pointers to this DIE's parent, first child, and next sibling,
971 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
974 /* This data structure holds the information of an abbrev. */
977 unsigned int number
; /* number identifying abbrev */
978 enum dwarf_tag tag
; /* dwarf tag */
979 unsigned short has_children
; /* boolean */
980 unsigned short num_attrs
; /* number of attributes */
981 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
982 struct abbrev_info
*next
; /* next in chain */
987 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
988 ENUM_BITFIELD(dwarf_form
) form
: 16;
991 /* Size of abbrev_table.abbrev_hash_table. */
992 #define ABBREV_HASH_SIZE 121
994 /* Top level data structure to contain an abbreviation table. */
998 /* Where the abbrev table came from.
999 This is used as a sanity check when the table is used. */
1002 /* Storage for the abbrev table. */
1003 struct obstack abbrev_obstack
;
1005 /* Hash table of abbrevs.
1006 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1007 It could be statically allocated, but the previous code didn't so we
1009 struct abbrev_info
**abbrevs
;
1012 /* Attributes have a name and a value. */
1015 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1016 ENUM_BITFIELD(dwarf_form
) form
: 15;
1018 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1019 field should be in u.str (existing only for DW_STRING) but it is kept
1020 here for better struct attribute alignment. */
1021 unsigned int string_is_canonical
: 1;
1026 struct dwarf_block
*blk
;
1030 struct signatured_type
*signatured_type
;
1035 /* This data structure holds a complete die structure. */
1038 /* DWARF-2 tag for this DIE. */
1039 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1041 /* Number of attributes */
1042 unsigned char num_attrs
;
1044 /* True if we're presently building the full type name for the
1045 type derived from this DIE. */
1046 unsigned char building_fullname
: 1;
1049 unsigned int abbrev
;
1051 /* Offset in .debug_info or .debug_types section. */
1054 /* The dies in a compilation unit form an n-ary tree. PARENT
1055 points to this die's parent; CHILD points to the first child of
1056 this node; and all the children of a given node are chained
1057 together via their SIBLING fields. */
1058 struct die_info
*child
; /* Its first child, if any. */
1059 struct die_info
*sibling
; /* Its next sibling, if any. */
1060 struct die_info
*parent
; /* Its parent, if any. */
1062 /* An array of attributes, with NUM_ATTRS elements. There may be
1063 zero, but it's not common and zero-sized arrays are not
1064 sufficiently portable C. */
1065 struct attribute attrs
[1];
1068 /* Get at parts of an attribute structure. */
1070 #define DW_STRING(attr) ((attr)->u.str)
1071 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1072 #define DW_UNSND(attr) ((attr)->u.unsnd)
1073 #define DW_BLOCK(attr) ((attr)->u.blk)
1074 #define DW_SND(attr) ((attr)->u.snd)
1075 #define DW_ADDR(attr) ((attr)->u.addr)
1076 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
1078 /* Blocks are a bunch of untyped bytes. */
1083 /* Valid only if SIZE is not zero. */
1087 #ifndef ATTR_ALLOC_CHUNK
1088 #define ATTR_ALLOC_CHUNK 4
1091 /* Allocate fields for structs, unions and enums in this size. */
1092 #ifndef DW_FIELD_ALLOC_CHUNK
1093 #define DW_FIELD_ALLOC_CHUNK 4
1096 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1097 but this would require a corresponding change in unpack_field_as_long
1099 static int bits_per_byte
= 8;
1101 /* The routines that read and process dies for a C struct or C++ class
1102 pass lists of data member fields and lists of member function fields
1103 in an instance of a field_info structure, as defined below. */
1106 /* List of data member and baseclasses fields. */
1109 struct nextfield
*next
;
1114 *fields
, *baseclasses
;
1116 /* Number of fields (including baseclasses). */
1119 /* Number of baseclasses. */
1122 /* Set if the accesibility of one of the fields is not public. */
1123 int non_public_fields
;
1125 /* Member function fields array, entries are allocated in the order they
1126 are encountered in the object file. */
1129 struct nextfnfield
*next
;
1130 struct fn_field fnfield
;
1134 /* Member function fieldlist array, contains name of possibly overloaded
1135 member function, number of overloaded member functions and a pointer
1136 to the head of the member function field chain. */
1141 struct nextfnfield
*head
;
1145 /* Number of entries in the fnfieldlists array. */
1148 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1149 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1150 struct typedef_field_list
1152 struct typedef_field field
;
1153 struct typedef_field_list
*next
;
1155 *typedef_field_list
;
1156 unsigned typedef_field_list_count
;
1159 /* One item on the queue of compilation units to read in full symbols
1161 struct dwarf2_queue_item
1163 struct dwarf2_per_cu_data
*per_cu
;
1164 enum language pretend_language
;
1165 struct dwarf2_queue_item
*next
;
1168 /* The current queue. */
1169 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1171 /* Loaded secondary compilation units are kept in memory until they
1172 have not been referenced for the processing of this many
1173 compilation units. Set this to zero to disable caching. Cache
1174 sizes of up to at least twenty will improve startup time for
1175 typical inter-CU-reference binaries, at an obvious memory cost. */
1176 static int dwarf2_max_cache_age
= 5;
1178 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1179 struct cmd_list_element
*c
, const char *value
)
1181 fprintf_filtered (file
, _("The upper bound on the age of cached "
1182 "dwarf2 compilation units is %s.\n"),
1187 /* Various complaints about symbol reading that don't abort the process. */
1190 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1192 complaint (&symfile_complaints
,
1193 _("statement list doesn't fit in .debug_line section"));
1197 dwarf2_debug_line_missing_file_complaint (void)
1199 complaint (&symfile_complaints
,
1200 _(".debug_line section has line data without a file"));
1204 dwarf2_debug_line_missing_end_sequence_complaint (void)
1206 complaint (&symfile_complaints
,
1207 _(".debug_line section has line "
1208 "program sequence without an end"));
1212 dwarf2_complex_location_expr_complaint (void)
1214 complaint (&symfile_complaints
, _("location expression too complex"));
1218 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1221 complaint (&symfile_complaints
,
1222 _("const value length mismatch for '%s', got %d, expected %d"),
1227 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1229 complaint (&symfile_complaints
,
1230 _("debug info runs off end of %s section"
1232 section
->asection
->name
,
1233 bfd_get_filename (section
->asection
->owner
));
1237 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1239 complaint (&symfile_complaints
,
1240 _("macro debug info contains a "
1241 "malformed macro definition:\n`%s'"),
1246 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1248 complaint (&symfile_complaints
,
1249 _("invalid attribute class or form for '%s' in '%s'"),
1253 /* local function prototypes */
1255 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1257 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1260 static void dwarf2_find_base_address (struct die_info
*die
,
1261 struct dwarf2_cu
*cu
);
1263 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1265 static void scan_partial_symbols (struct partial_die_info
*,
1266 CORE_ADDR
*, CORE_ADDR
*,
1267 int, struct dwarf2_cu
*);
1269 static void add_partial_symbol (struct partial_die_info
*,
1270 struct dwarf2_cu
*);
1272 static void add_partial_namespace (struct partial_die_info
*pdi
,
1273 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1274 int need_pc
, struct dwarf2_cu
*cu
);
1276 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1277 CORE_ADDR
*highpc
, int need_pc
,
1278 struct dwarf2_cu
*cu
);
1280 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1281 struct dwarf2_cu
*cu
);
1283 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1284 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1285 int need_pc
, struct dwarf2_cu
*cu
);
1287 static void dwarf2_psymtab_to_symtab (struct objfile
*,
1288 struct partial_symtab
*);
1290 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1292 static struct abbrev_info
*abbrev_table_lookup_abbrev
1293 (const struct abbrev_table
*, unsigned int);
1295 static struct abbrev_table
*abbrev_table_read_table
1296 (struct dwarf2_section_info
*, sect_offset
);
1298 static void abbrev_table_free (struct abbrev_table
*);
1300 static void abbrev_table_free_cleanup (void *);
1302 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1303 struct dwarf2_section_info
*);
1305 static void dwarf2_free_abbrev_table (void *);
1307 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1309 static struct partial_die_info
*load_partial_dies
1310 (const struct die_reader_specs
*, gdb_byte
*, int);
1312 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1313 struct partial_die_info
*,
1314 struct abbrev_info
*,
1318 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1319 struct dwarf2_cu
*);
1321 static void fixup_partial_die (struct partial_die_info
*,
1322 struct dwarf2_cu
*);
1324 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1325 struct attribute
*, struct attr_abbrev
*,
1328 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1330 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1332 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1334 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1336 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1338 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1341 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1343 static LONGEST read_checked_initial_length_and_offset
1344 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1345 unsigned int *, unsigned int *);
1347 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1350 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1352 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1355 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1357 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1359 static char *read_indirect_string (bfd
*, gdb_byte
*,
1360 const struct comp_unit_head
*,
1363 static char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1365 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1367 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1369 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1372 static char *read_str_index (const struct die_reader_specs
*reader
,
1373 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1375 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1377 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1378 struct dwarf2_cu
*);
1380 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1383 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1384 struct dwarf2_cu
*cu
);
1386 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1388 static struct die_info
*die_specification (struct die_info
*die
,
1389 struct dwarf2_cu
**);
1391 static void free_line_header (struct line_header
*lh
);
1393 static void add_file_name (struct line_header
*, char *, unsigned int,
1394 unsigned int, unsigned int);
1396 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1397 struct dwarf2_cu
*cu
);
1399 static void dwarf_decode_lines (struct line_header
*, const char *,
1400 struct dwarf2_cu
*, struct partial_symtab
*,
1403 static void dwarf2_start_subfile (char *, const char *, const char *);
1405 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1406 char *, char *, CORE_ADDR
);
1408 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1409 struct dwarf2_cu
*);
1411 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1412 struct dwarf2_cu
*, struct symbol
*);
1414 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1415 struct dwarf2_cu
*);
1417 static void dwarf2_const_value_attr (struct attribute
*attr
,
1420 struct obstack
*obstack
,
1421 struct dwarf2_cu
*cu
, LONGEST
*value
,
1423 struct dwarf2_locexpr_baton
**baton
);
1425 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1427 static int need_gnat_info (struct dwarf2_cu
*);
1429 static struct type
*die_descriptive_type (struct die_info
*,
1430 struct dwarf2_cu
*);
1432 static void set_descriptive_type (struct type
*, struct die_info
*,
1433 struct dwarf2_cu
*);
1435 static struct type
*die_containing_type (struct die_info
*,
1436 struct dwarf2_cu
*);
1438 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1439 struct dwarf2_cu
*);
1441 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1443 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1445 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1447 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1448 const char *suffix
, int physname
,
1449 struct dwarf2_cu
*cu
);
1451 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1453 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1455 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1457 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1459 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1461 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1462 struct dwarf2_cu
*, struct partial_symtab
*);
1464 static int dwarf2_get_pc_bounds (struct die_info
*,
1465 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1466 struct partial_symtab
*);
1468 static void get_scope_pc_bounds (struct die_info
*,
1469 CORE_ADDR
*, CORE_ADDR
*,
1470 struct dwarf2_cu
*);
1472 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1473 CORE_ADDR
, struct dwarf2_cu
*);
1475 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1476 struct dwarf2_cu
*);
1478 static void dwarf2_attach_fields_to_type (struct field_info
*,
1479 struct type
*, struct dwarf2_cu
*);
1481 static void dwarf2_add_member_fn (struct field_info
*,
1482 struct die_info
*, struct type
*,
1483 struct dwarf2_cu
*);
1485 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1487 struct dwarf2_cu
*);
1489 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1491 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1493 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1495 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1497 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1499 static struct type
*read_module_type (struct die_info
*die
,
1500 struct dwarf2_cu
*cu
);
1502 static const char *namespace_name (struct die_info
*die
,
1503 int *is_anonymous
, struct dwarf2_cu
*);
1505 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1507 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1509 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1510 struct dwarf2_cu
*);
1512 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1514 gdb_byte
**new_info_ptr
,
1515 struct die_info
*parent
);
1517 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1519 gdb_byte
**new_info_ptr
,
1520 struct die_info
*parent
);
1522 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1523 struct die_info
**, gdb_byte
*, int *, int);
1525 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1526 struct die_info
**, gdb_byte
*, int *);
1528 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1530 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1533 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1535 static const char *dwarf2_full_name (char *name
,
1536 struct die_info
*die
,
1537 struct dwarf2_cu
*cu
);
1539 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1540 struct dwarf2_cu
**);
1542 static const char *dwarf_tag_name (unsigned int);
1544 static const char *dwarf_attr_name (unsigned int);
1546 static const char *dwarf_form_name (unsigned int);
1548 static char *dwarf_bool_name (unsigned int);
1550 static const char *dwarf_type_encoding_name (unsigned int);
1552 static struct die_info
*sibling_die (struct die_info
*);
1554 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1556 static void dump_die_for_error (struct die_info
*);
1558 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1561 /*static*/ void dump_die (struct die_info
*, int max_level
);
1563 static void store_in_ref_table (struct die_info
*,
1564 struct dwarf2_cu
*);
1566 static int is_ref_attr (struct attribute
*);
1568 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1570 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1572 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1574 struct dwarf2_cu
**);
1576 static struct die_info
*follow_die_ref (struct die_info
*,
1578 struct dwarf2_cu
**);
1580 static struct die_info
*follow_die_sig (struct die_info
*,
1582 struct dwarf2_cu
**);
1584 static struct signatured_type
*lookup_signatured_type_at_offset
1585 (struct objfile
*objfile
,
1586 struct dwarf2_section_info
*section
, sect_offset offset
);
1588 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1590 static void read_signatured_type (struct signatured_type
*);
1592 static struct type_unit_group
*get_type_unit_group
1593 (struct dwarf2_cu
*, struct attribute
*);
1595 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1597 /* memory allocation interface */
1599 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1601 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1603 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1606 static int attr_form_is_block (struct attribute
*);
1608 static int attr_form_is_section_offset (struct attribute
*);
1610 static int attr_form_is_constant (struct attribute
*);
1612 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1613 struct dwarf2_loclist_baton
*baton
,
1614 struct attribute
*attr
);
1616 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1618 struct dwarf2_cu
*cu
);
1620 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1622 struct abbrev_info
*abbrev
);
1624 static void free_stack_comp_unit (void *);
1626 static hashval_t
partial_die_hash (const void *item
);
1628 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1630 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1631 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1633 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1634 struct dwarf2_per_cu_data
*per_cu
);
1636 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1637 struct die_info
*comp_unit_die
,
1638 enum language pretend_language
);
1640 static void free_heap_comp_unit (void *);
1642 static void free_cached_comp_units (void *);
1644 static void age_cached_comp_units (void);
1646 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1648 static struct type
*set_die_type (struct die_info
*, struct type
*,
1649 struct dwarf2_cu
*);
1651 static void create_all_comp_units (struct objfile
*);
1653 static int create_all_type_units (struct objfile
*);
1655 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1658 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1661 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1664 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1665 struct dwarf2_per_cu_data
*);
1667 static void dwarf2_mark (struct dwarf2_cu
*);
1669 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1671 static struct type
*get_die_type_at_offset (sect_offset
,
1672 struct dwarf2_per_cu_data
*per_cu
);
1674 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1676 static void dwarf2_release_queue (void *dummy
);
1678 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1679 enum language pretend_language
);
1681 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1682 struct dwarf2_per_cu_data
*per_cu
,
1683 enum language pretend_language
);
1685 static void process_queue (void);
1687 static void find_file_and_directory (struct die_info
*die
,
1688 struct dwarf2_cu
*cu
,
1689 char **name
, char **comp_dir
);
1691 static char *file_full_name (int file
, struct line_header
*lh
,
1692 const char *comp_dir
);
1694 static gdb_byte
*read_and_check_comp_unit_head
1695 (struct comp_unit_head
*header
,
1696 struct dwarf2_section_info
*section
,
1697 struct dwarf2_section_info
*abbrev_section
, gdb_byte
*info_ptr
,
1698 int is_debug_types_section
);
1700 static void init_cutu_and_read_dies
1701 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1702 int use_existing_cu
, int keep
,
1703 die_reader_func_ftype
*die_reader_func
, void *data
);
1705 static void init_cutu_and_read_dies_simple
1706 (struct dwarf2_per_cu_data
*this_cu
,
1707 die_reader_func_ftype
*die_reader_func
, void *data
);
1709 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1711 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1713 static struct dwo_unit
*lookup_dwo_comp_unit
1714 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1716 static struct dwo_unit
*lookup_dwo_type_unit
1717 (struct signatured_type
*, const char *, const char *);
1719 static void free_dwo_file_cleanup (void *);
1721 static void process_cu_includes (void);
1723 static void check_producer (struct dwarf2_cu
*cu
);
1727 /* Convert VALUE between big- and little-endian. */
1729 byte_swap (offset_type value
)
1733 result
= (value
& 0xff) << 24;
1734 result
|= (value
& 0xff00) << 8;
1735 result
|= (value
& 0xff0000) >> 8;
1736 result
|= (value
& 0xff000000) >> 24;
1740 #define MAYBE_SWAP(V) byte_swap (V)
1743 #define MAYBE_SWAP(V) (V)
1744 #endif /* WORDS_BIGENDIAN */
1746 /* The suffix for an index file. */
1747 #define INDEX_SUFFIX ".gdb-index"
1749 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1750 struct dwarf2_cu
*cu
);
1752 /* Try to locate the sections we need for DWARF 2 debugging
1753 information and return true if we have enough to do something.
1754 NAMES points to the dwarf2 section names, or is NULL if the standard
1755 ELF names are used. */
1758 dwarf2_has_info (struct objfile
*objfile
,
1759 const struct dwarf2_debug_sections
*names
)
1761 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1762 if (!dwarf2_per_objfile
)
1764 /* Initialize per-objfile state. */
1765 struct dwarf2_per_objfile
*data
1766 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1768 memset (data
, 0, sizeof (*data
));
1769 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1770 dwarf2_per_objfile
= data
;
1772 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1774 dwarf2_per_objfile
->objfile
= objfile
;
1776 return (dwarf2_per_objfile
->info
.asection
!= NULL
1777 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1780 /* When loading sections, we look either for uncompressed section or for
1781 compressed section names. */
1784 section_is_p (const char *section_name
,
1785 const struct dwarf2_section_names
*names
)
1787 if (names
->normal
!= NULL
1788 && strcmp (section_name
, names
->normal
) == 0)
1790 if (names
->compressed
!= NULL
1791 && strcmp (section_name
, names
->compressed
) == 0)
1796 /* This function is mapped across the sections and remembers the
1797 offset and size of each of the debugging sections we are interested
1801 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1803 const struct dwarf2_debug_sections
*names
;
1804 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1807 names
= &dwarf2_elf_names
;
1809 names
= (const struct dwarf2_debug_sections
*) vnames
;
1811 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1814 else if (section_is_p (sectp
->name
, &names
->info
))
1816 dwarf2_per_objfile
->info
.asection
= sectp
;
1817 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1819 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1821 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1822 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1824 else if (section_is_p (sectp
->name
, &names
->line
))
1826 dwarf2_per_objfile
->line
.asection
= sectp
;
1827 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1829 else if (section_is_p (sectp
->name
, &names
->loc
))
1831 dwarf2_per_objfile
->loc
.asection
= sectp
;
1832 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1834 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1836 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1837 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1839 else if (section_is_p (sectp
->name
, &names
->macro
))
1841 dwarf2_per_objfile
->macro
.asection
= sectp
;
1842 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1844 else if (section_is_p (sectp
->name
, &names
->str
))
1846 dwarf2_per_objfile
->str
.asection
= sectp
;
1847 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1849 else if (section_is_p (sectp
->name
, &names
->addr
))
1851 dwarf2_per_objfile
->addr
.asection
= sectp
;
1852 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1854 else if (section_is_p (sectp
->name
, &names
->frame
))
1856 dwarf2_per_objfile
->frame
.asection
= sectp
;
1857 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1859 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1861 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1862 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1864 else if (section_is_p (sectp
->name
, &names
->ranges
))
1866 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1867 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1869 else if (section_is_p (sectp
->name
, &names
->types
))
1871 struct dwarf2_section_info type_section
;
1873 memset (&type_section
, 0, sizeof (type_section
));
1874 type_section
.asection
= sectp
;
1875 type_section
.size
= bfd_get_section_size (sectp
);
1877 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1880 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1882 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1883 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1886 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1887 && bfd_section_vma (abfd
, sectp
) == 0)
1888 dwarf2_per_objfile
->has_section_at_zero
= 1;
1891 /* A helper function that decides whether a section is empty,
1895 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1897 return info
->asection
== NULL
|| info
->size
== 0;
1900 /* Read the contents of the section INFO.
1901 OBJFILE is the main object file, but not necessarily the file where
1902 the section comes from. E.g., for DWO files INFO->asection->owner
1903 is the bfd of the DWO file.
1904 If the section is compressed, uncompress it before returning. */
1907 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1909 asection
*sectp
= info
->asection
;
1911 gdb_byte
*buf
, *retbuf
;
1912 unsigned char header
[4];
1916 info
->buffer
= NULL
;
1919 if (dwarf2_section_empty_p (info
))
1922 abfd
= sectp
->owner
;
1924 /* If the section has relocations, we must read it ourselves.
1925 Otherwise we attach it to the BFD. */
1926 if ((sectp
->flags
& SEC_RELOC
) == 0)
1928 const gdb_byte
*bytes
= gdb_bfd_map_section (sectp
, &info
->size
);
1930 /* We have to cast away const here for historical reasons.
1931 Fixing dwarf2read to be const-correct would be quite nice. */
1932 info
->buffer
= (gdb_byte
*) bytes
;
1936 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1939 /* When debugging .o files, we may need to apply relocations; see
1940 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1941 We never compress sections in .o files, so we only need to
1942 try this when the section is not compressed. */
1943 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1946 info
->buffer
= retbuf
;
1950 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1951 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1952 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1953 bfd_get_filename (abfd
));
1956 /* A helper function that returns the size of a section in a safe way.
1957 If you are positive that the section has been read before using the
1958 size, then it is safe to refer to the dwarf2_section_info object's
1959 "size" field directly. In other cases, you must call this
1960 function, because for compressed sections the size field is not set
1961 correctly until the section has been read. */
1963 static bfd_size_type
1964 dwarf2_section_size (struct objfile
*objfile
,
1965 struct dwarf2_section_info
*info
)
1968 dwarf2_read_section (objfile
, info
);
1972 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1976 dwarf2_get_section_info (struct objfile
*objfile
,
1977 enum dwarf2_section_enum sect
,
1978 asection
**sectp
, gdb_byte
**bufp
,
1979 bfd_size_type
*sizep
)
1981 struct dwarf2_per_objfile
*data
1982 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1983 struct dwarf2_section_info
*info
;
1985 /* We may see an objfile without any DWARF, in which case we just
1996 case DWARF2_DEBUG_FRAME
:
1997 info
= &data
->frame
;
1999 case DWARF2_EH_FRAME
:
2000 info
= &data
->eh_frame
;
2003 gdb_assert_not_reached ("unexpected section");
2006 dwarf2_read_section (objfile
, info
);
2008 *sectp
= info
->asection
;
2009 *bufp
= info
->buffer
;
2010 *sizep
= info
->size
;
2013 /* A helper function to find the sections for a .dwz file. */
2016 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2018 struct dwz_file
*dwz_file
= arg
;
2020 /* Note that we only support the standard ELF names, because .dwz
2021 is ELF-only (at the time of writing). */
2022 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2024 dwz_file
->abbrev
.asection
= sectp
;
2025 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2027 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2029 dwz_file
->info
.asection
= sectp
;
2030 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2032 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2034 dwz_file
->str
.asection
= sectp
;
2035 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2037 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2039 dwz_file
->line
.asection
= sectp
;
2040 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2042 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2044 dwz_file
->macro
.asection
= sectp
;
2045 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2047 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2049 dwz_file
->gdb_index
.asection
= sectp
;
2050 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2054 /* Open the separate '.dwz' debug file, if needed. Error if the file
2057 static struct dwz_file
*
2058 dwarf2_get_dwz_file (void)
2060 bfd
*abfd
, *dwz_bfd
;
2063 struct cleanup
*cleanup
;
2064 const char *filename
;
2065 struct dwz_file
*result
;
2067 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2068 return dwarf2_per_objfile
->dwz_file
;
2070 abfd
= dwarf2_per_objfile
->objfile
->obfd
;
2071 section
= bfd_get_section_by_name (abfd
, ".gnu_debugaltlink");
2072 if (section
== NULL
)
2073 error (_("could not find '.gnu_debugaltlink' section"));
2074 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
2075 error (_("could not read '.gnu_debugaltlink' section: %s"),
2076 bfd_errmsg (bfd_get_error ()));
2077 cleanup
= make_cleanup (xfree
, data
);
2080 if (!IS_ABSOLUTE_PATH (filename
))
2082 char *abs
= gdb_realpath (dwarf2_per_objfile
->objfile
->name
);
2085 make_cleanup (xfree
, abs
);
2086 abs
= ldirname (abs
);
2087 make_cleanup (xfree
, abs
);
2089 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2090 make_cleanup (xfree
, rel
);
2094 /* The format is just a NUL-terminated file name, followed by the
2095 build-id. For now, though, we ignore the build-id. */
2096 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2097 if (dwz_bfd
== NULL
)
2098 error (_("could not read '%s': %s"), filename
,
2099 bfd_errmsg (bfd_get_error ()));
2101 if (!bfd_check_format (dwz_bfd
, bfd_object
))
2103 gdb_bfd_unref (dwz_bfd
);
2104 error (_("file '%s' was not usable: %s"), filename
,
2105 bfd_errmsg (bfd_get_error ()));
2108 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2110 result
->dwz_bfd
= dwz_bfd
;
2112 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2114 do_cleanups (cleanup
);
2116 dwarf2_per_objfile
->dwz_file
= result
;
2120 /* DWARF quick_symbols_functions support. */
2122 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2123 unique line tables, so we maintain a separate table of all .debug_line
2124 derived entries to support the sharing.
2125 All the quick functions need is the list of file names. We discard the
2126 line_header when we're done and don't need to record it here. */
2127 struct quick_file_names
2129 /* The data used to construct the hash key. */
2130 struct stmt_list_hash hash
;
2132 /* The number of entries in file_names, real_names. */
2133 unsigned int num_file_names
;
2135 /* The file names from the line table, after being run through
2137 const char **file_names
;
2139 /* The file names from the line table after being run through
2140 gdb_realpath. These are computed lazily. */
2141 const char **real_names
;
2144 /* When using the index (and thus not using psymtabs), each CU has an
2145 object of this type. This is used to hold information needed by
2146 the various "quick" methods. */
2147 struct dwarf2_per_cu_quick_data
2149 /* The file table. This can be NULL if there was no file table
2150 or it's currently not read in.
2151 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2152 struct quick_file_names
*file_names
;
2154 /* The corresponding symbol table. This is NULL if symbols for this
2155 CU have not yet been read. */
2156 struct symtab
*symtab
;
2158 /* A temporary mark bit used when iterating over all CUs in
2159 expand_symtabs_matching. */
2160 unsigned int mark
: 1;
2162 /* True if we've tried to read the file table and found there isn't one.
2163 There will be no point in trying to read it again next time. */
2164 unsigned int no_file_data
: 1;
2167 /* Utility hash function for a stmt_list_hash. */
2170 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2174 if (stmt_list_hash
->dwo_unit
!= NULL
)
2175 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2176 v
+= stmt_list_hash
->line_offset
.sect_off
;
2180 /* Utility equality function for a stmt_list_hash. */
2183 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2184 const struct stmt_list_hash
*rhs
)
2186 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2188 if (lhs
->dwo_unit
!= NULL
2189 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2192 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2195 /* Hash function for a quick_file_names. */
2198 hash_file_name_entry (const void *e
)
2200 const struct quick_file_names
*file_data
= e
;
2202 return hash_stmt_list_entry (&file_data
->hash
);
2205 /* Equality function for a quick_file_names. */
2208 eq_file_name_entry (const void *a
, const void *b
)
2210 const struct quick_file_names
*ea
= a
;
2211 const struct quick_file_names
*eb
= b
;
2213 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2216 /* Delete function for a quick_file_names. */
2219 delete_file_name_entry (void *e
)
2221 struct quick_file_names
*file_data
= e
;
2224 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2226 xfree ((void*) file_data
->file_names
[i
]);
2227 if (file_data
->real_names
)
2228 xfree ((void*) file_data
->real_names
[i
]);
2231 /* The space for the struct itself lives on objfile_obstack,
2232 so we don't free it here. */
2235 /* Create a quick_file_names hash table. */
2238 create_quick_file_names_table (unsigned int nr_initial_entries
)
2240 return htab_create_alloc (nr_initial_entries
,
2241 hash_file_name_entry
, eq_file_name_entry
,
2242 delete_file_name_entry
, xcalloc
, xfree
);
2245 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2246 have to be created afterwards. You should call age_cached_comp_units after
2247 processing PER_CU->CU. dw2_setup must have been already called. */
2250 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2252 if (per_cu
->is_debug_types
)
2253 load_full_type_unit (per_cu
);
2255 load_full_comp_unit (per_cu
, language_minimal
);
2257 gdb_assert (per_cu
->cu
!= NULL
);
2259 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2262 /* Read in the symbols for PER_CU. */
2265 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2267 struct cleanup
*back_to
;
2269 /* Skip type_unit_groups, reading the type units they contain
2270 is handled elsewhere. */
2271 if (IS_TYPE_UNIT_GROUP (per_cu
))
2274 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2276 if (dwarf2_per_objfile
->using_index
2277 ? per_cu
->v
.quick
->symtab
== NULL
2278 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2280 queue_comp_unit (per_cu
, language_minimal
);
2286 /* Age the cache, releasing compilation units that have not
2287 been used recently. */
2288 age_cached_comp_units ();
2290 do_cleanups (back_to
);
2293 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2294 the objfile from which this CU came. Returns the resulting symbol
2297 static struct symtab
*
2298 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2300 gdb_assert (dwarf2_per_objfile
->using_index
);
2301 if (!per_cu
->v
.quick
->symtab
)
2303 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2304 increment_reading_symtab ();
2305 dw2_do_instantiate_symtab (per_cu
);
2306 process_cu_includes ();
2307 do_cleanups (back_to
);
2309 return per_cu
->v
.quick
->symtab
;
2312 /* Return the CU given its index.
2314 This is intended for loops like:
2316 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2317 + dwarf2_per_objfile->n_type_units); ++i)
2319 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2325 static struct dwarf2_per_cu_data
*
2326 dw2_get_cu (int index
)
2328 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2330 index
-= dwarf2_per_objfile
->n_comp_units
;
2331 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2332 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2335 return dwarf2_per_objfile
->all_comp_units
[index
];
2338 /* Return the primary CU given its index.
2339 The difference between this function and dw2_get_cu is in the handling
2340 of type units (TUs). Here we return the type_unit_group object.
2342 This is intended for loops like:
2344 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2345 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2347 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2353 static struct dwarf2_per_cu_data
*
2354 dw2_get_primary_cu (int index
)
2356 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2358 index
-= dwarf2_per_objfile
->n_comp_units
;
2359 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2360 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2363 return dwarf2_per_objfile
->all_comp_units
[index
];
2366 /* A helper for create_cus_from_index that handles a given list of
2370 create_cus_from_index_list (struct objfile
*objfile
,
2371 const gdb_byte
*cu_list
, offset_type n_elements
,
2372 struct dwarf2_section_info
*section
,
2378 for (i
= 0; i
< n_elements
; i
+= 2)
2380 struct dwarf2_per_cu_data
*the_cu
;
2381 ULONGEST offset
, length
;
2383 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2384 offset
= extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2385 length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2388 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2389 struct dwarf2_per_cu_data
);
2390 the_cu
->offset
.sect_off
= offset
;
2391 the_cu
->length
= length
;
2392 the_cu
->objfile
= objfile
;
2393 the_cu
->info_or_types_section
= section
;
2394 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2395 struct dwarf2_per_cu_quick_data
);
2396 the_cu
->is_dwz
= is_dwz
;
2397 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2401 /* Read the CU list from the mapped index, and use it to create all
2402 the CU objects for this objfile. */
2405 create_cus_from_index (struct objfile
*objfile
,
2406 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2407 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2409 struct dwz_file
*dwz
;
2411 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2412 dwarf2_per_objfile
->all_comp_units
2413 = obstack_alloc (&objfile
->objfile_obstack
,
2414 dwarf2_per_objfile
->n_comp_units
2415 * sizeof (struct dwarf2_per_cu_data
*));
2417 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2418 &dwarf2_per_objfile
->info
, 0, 0);
2420 if (dwz_elements
== 0)
2423 dwz
= dwarf2_get_dwz_file ();
2424 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2425 cu_list_elements
/ 2);
2428 /* Create the signatured type hash table from the index. */
2431 create_signatured_type_table_from_index (struct objfile
*objfile
,
2432 struct dwarf2_section_info
*section
,
2433 const gdb_byte
*bytes
,
2434 offset_type elements
)
2437 htab_t sig_types_hash
;
2439 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2440 dwarf2_per_objfile
->all_type_units
2441 = obstack_alloc (&objfile
->objfile_obstack
,
2442 dwarf2_per_objfile
->n_type_units
2443 * sizeof (struct signatured_type
*));
2445 sig_types_hash
= allocate_signatured_type_table (objfile
);
2447 for (i
= 0; i
< elements
; i
+= 3)
2449 struct signatured_type
*sig_type
;
2450 ULONGEST offset
, type_offset_in_tu
, signature
;
2453 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2454 offset
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2455 type_offset_in_tu
= extract_unsigned_integer (bytes
+ 8, 8,
2457 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2460 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2461 struct signatured_type
);
2462 sig_type
->signature
= signature
;
2463 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2464 sig_type
->per_cu
.is_debug_types
= 1;
2465 sig_type
->per_cu
.info_or_types_section
= section
;
2466 sig_type
->per_cu
.offset
.sect_off
= offset
;
2467 sig_type
->per_cu
.objfile
= objfile
;
2468 sig_type
->per_cu
.v
.quick
2469 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2470 struct dwarf2_per_cu_quick_data
);
2472 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2475 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2478 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2481 /* Read the address map data from the mapped index, and use it to
2482 populate the objfile's psymtabs_addrmap. */
2485 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2487 const gdb_byte
*iter
, *end
;
2488 struct obstack temp_obstack
;
2489 struct addrmap
*mutable_map
;
2490 struct cleanup
*cleanup
;
2493 obstack_init (&temp_obstack
);
2494 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2495 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2497 iter
= index
->address_table
;
2498 end
= iter
+ index
->address_table_size
;
2500 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2504 ULONGEST hi
, lo
, cu_index
;
2505 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2507 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2509 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2512 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2513 dw2_get_cu (cu_index
));
2516 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2517 &objfile
->objfile_obstack
);
2518 do_cleanups (cleanup
);
2521 /* The hash function for strings in the mapped index. This is the same as
2522 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2523 implementation. This is necessary because the hash function is tied to the
2524 format of the mapped index file. The hash values do not have to match with
2527 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2530 mapped_index_string_hash (int index_version
, const void *p
)
2532 const unsigned char *str
= (const unsigned char *) p
;
2536 while ((c
= *str
++) != 0)
2538 if (index_version
>= 5)
2540 r
= r
* 67 + c
- 113;
2546 /* Find a slot in the mapped index INDEX for the object named NAME.
2547 If NAME is found, set *VEC_OUT to point to the CU vector in the
2548 constant pool and return 1. If NAME cannot be found, return 0. */
2551 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2552 offset_type
**vec_out
)
2554 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2556 offset_type slot
, step
;
2557 int (*cmp
) (const char *, const char *);
2559 if (current_language
->la_language
== language_cplus
2560 || current_language
->la_language
== language_java
2561 || current_language
->la_language
== language_fortran
)
2563 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2565 const char *paren
= strchr (name
, '(');
2571 dup
= xmalloc (paren
- name
+ 1);
2572 memcpy (dup
, name
, paren
- name
);
2573 dup
[paren
- name
] = 0;
2575 make_cleanup (xfree
, dup
);
2580 /* Index version 4 did not support case insensitive searches. But the
2581 indices for case insensitive languages are built in lowercase, therefore
2582 simulate our NAME being searched is also lowercased. */
2583 hash
= mapped_index_string_hash ((index
->version
== 4
2584 && case_sensitivity
== case_sensitive_off
2585 ? 5 : index
->version
),
2588 slot
= hash
& (index
->symbol_table_slots
- 1);
2589 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2590 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2594 /* Convert a slot number to an offset into the table. */
2595 offset_type i
= 2 * slot
;
2597 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2599 do_cleanups (back_to
);
2603 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2604 if (!cmp (name
, str
))
2606 *vec_out
= (offset_type
*) (index
->constant_pool
2607 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2608 do_cleanups (back_to
);
2612 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2616 /* A helper function that reads the .gdb_index from SECTION and fills
2617 in MAP. FILENAME is the name of the file containing the section;
2618 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2619 ok to use deprecated sections.
2621 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2622 out parameters that are filled in with information about the CU and
2623 TU lists in the section.
2625 Returns 1 if all went well, 0 otherwise. */
2628 read_index_from_section (struct objfile
*objfile
,
2629 const char *filename
,
2631 struct dwarf2_section_info
*section
,
2632 struct mapped_index
*map
,
2633 const gdb_byte
**cu_list
,
2634 offset_type
*cu_list_elements
,
2635 const gdb_byte
**types_list
,
2636 offset_type
*types_list_elements
)
2639 offset_type version
;
2640 offset_type
*metadata
;
2643 if (dwarf2_section_empty_p (section
))
2646 /* Older elfutils strip versions could keep the section in the main
2647 executable while splitting it for the separate debug info file. */
2648 if ((bfd_get_file_flags (section
->asection
) & SEC_HAS_CONTENTS
) == 0)
2651 dwarf2_read_section (objfile
, section
);
2653 addr
= section
->buffer
;
2654 /* Version check. */
2655 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2656 /* Versions earlier than 3 emitted every copy of a psymbol. This
2657 causes the index to behave very poorly for certain requests. Version 3
2658 contained incomplete addrmap. So, it seems better to just ignore such
2662 static int warning_printed
= 0;
2663 if (!warning_printed
)
2665 warning (_("Skipping obsolete .gdb_index section in %s."),
2667 warning_printed
= 1;
2671 /* Index version 4 uses a different hash function than index version
2674 Versions earlier than 6 did not emit psymbols for inlined
2675 functions. Using these files will cause GDB not to be able to
2676 set breakpoints on inlined functions by name, so we ignore these
2677 indices unless the user has done
2678 "set use-deprecated-index-sections on". */
2679 if (version
< 6 && !deprecated_ok
)
2681 static int warning_printed
= 0;
2682 if (!warning_printed
)
2685 Skipping deprecated .gdb_index section in %s.\n\
2686 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2687 to use the section anyway."),
2689 warning_printed
= 1;
2693 /* Indexes with higher version than the one supported by GDB may be no
2694 longer backward compatible. */
2698 map
->version
= version
;
2699 map
->total_size
= section
->size
;
2701 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2704 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2705 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2709 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2710 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2711 - MAYBE_SWAP (metadata
[i
]))
2715 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2716 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2717 - MAYBE_SWAP (metadata
[i
]));
2720 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2721 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2722 - MAYBE_SWAP (metadata
[i
]))
2723 / (2 * sizeof (offset_type
)));
2726 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2732 /* Read the index file. If everything went ok, initialize the "quick"
2733 elements of all the CUs and return 1. Otherwise, return 0. */
2736 dwarf2_read_index (struct objfile
*objfile
)
2738 struct mapped_index local_map
, *map
;
2739 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2740 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2742 if (!read_index_from_section (objfile
, objfile
->name
,
2743 use_deprecated_index_sections
,
2744 &dwarf2_per_objfile
->gdb_index
, &local_map
,
2745 &cu_list
, &cu_list_elements
,
2746 &types_list
, &types_list_elements
))
2749 /* Don't use the index if it's empty. */
2750 if (local_map
.symbol_table_slots
== 0)
2753 /* If there is a .dwz file, read it so we can get its CU list as
2755 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
2757 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
2758 struct mapped_index dwz_map
;
2759 const gdb_byte
*dwz_types_ignore
;
2760 offset_type dwz_types_elements_ignore
;
2762 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
2764 &dwz
->gdb_index
, &dwz_map
,
2765 &dwz_list
, &dwz_list_elements
,
2767 &dwz_types_elements_ignore
))
2769 warning (_("could not read '.gdb_index' section from %s; skipping"),
2770 bfd_get_filename (dwz
->dwz_bfd
));
2775 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
2778 if (types_list_elements
)
2780 struct dwarf2_section_info
*section
;
2782 /* We can only handle a single .debug_types when we have an
2784 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2787 section
= VEC_index (dwarf2_section_info_def
,
2788 dwarf2_per_objfile
->types
, 0);
2790 create_signatured_type_table_from_index (objfile
, section
, types_list
,
2791 types_list_elements
);
2794 create_addrmap_from_index (objfile
, &local_map
);
2796 map
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct mapped_index
));
2799 dwarf2_per_objfile
->index_table
= map
;
2800 dwarf2_per_objfile
->using_index
= 1;
2801 dwarf2_per_objfile
->quick_file_names_table
=
2802 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2807 /* A helper for the "quick" functions which sets the global
2808 dwarf2_per_objfile according to OBJFILE. */
2811 dw2_setup (struct objfile
*objfile
)
2813 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2814 gdb_assert (dwarf2_per_objfile
);
2817 /* Reader function for dw2_build_type_unit_groups. */
2820 dw2_build_type_unit_groups_reader (const struct die_reader_specs
*reader
,
2822 struct die_info
*type_unit_die
,
2826 struct dwarf2_cu
*cu
= reader
->cu
;
2827 struct attribute
*attr
;
2828 struct type_unit_group
*tu_group
;
2830 gdb_assert (data
== NULL
);
2835 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
2836 /* Call this for its side-effect of creating the associated
2837 struct type_unit_group if it doesn't already exist. */
2838 tu_group
= get_type_unit_group (cu
, attr
);
2841 /* Build dwarf2_per_objfile->type_unit_groups.
2842 This function may be called multiple times. */
2845 dw2_build_type_unit_groups (void)
2847 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
2848 build_type_unit_groups (dw2_build_type_unit_groups_reader
, NULL
);
2851 /* die_reader_func for dw2_get_file_names. */
2854 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2856 struct die_info
*comp_unit_die
,
2860 struct dwarf2_cu
*cu
= reader
->cu
;
2861 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2862 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2863 struct dwarf2_per_cu_data
*lh_cu
;
2864 struct line_header
*lh
;
2865 struct attribute
*attr
;
2867 char *name
, *comp_dir
;
2869 struct quick_file_names
*qfn
;
2870 unsigned int line_offset
;
2872 /* Our callers never want to match partial units -- instead they
2873 will match the enclosing full CU. */
2874 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2876 this_cu
->v
.quick
->no_file_data
= 1;
2880 /* If we're reading the line header for TUs, store it in the "per_cu"
2882 if (this_cu
->is_debug_types
)
2884 struct type_unit_group
*tu_group
= data
;
2886 gdb_assert (tu_group
!= NULL
);
2887 lh_cu
= &tu_group
->per_cu
;
2896 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2899 struct quick_file_names find_entry
;
2901 line_offset
= DW_UNSND (attr
);
2903 /* We may have already read in this line header (TU line header sharing).
2904 If we have we're done. */
2905 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2906 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2907 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2908 &find_entry
, INSERT
);
2911 lh_cu
->v
.quick
->file_names
= *slot
;
2915 lh
= dwarf_decode_line_header (line_offset
, cu
);
2919 lh_cu
->v
.quick
->no_file_data
= 1;
2923 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2924 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2925 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2926 gdb_assert (slot
!= NULL
);
2929 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2931 qfn
->num_file_names
= lh
->num_file_names
;
2932 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2933 lh
->num_file_names
* sizeof (char *));
2934 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2935 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2936 qfn
->real_names
= NULL
;
2938 free_line_header (lh
);
2940 lh_cu
->v
.quick
->file_names
= qfn
;
2943 /* A helper for the "quick" functions which attempts to read the line
2944 table for THIS_CU. */
2946 static struct quick_file_names
*
2947 dw2_get_file_names (struct objfile
*objfile
,
2948 struct dwarf2_per_cu_data
*this_cu
)
2950 /* For TUs this should only be called on the parent group. */
2951 if (this_cu
->is_debug_types
)
2952 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2954 if (this_cu
->v
.quick
->file_names
!= NULL
)
2955 return this_cu
->v
.quick
->file_names
;
2956 /* If we know there is no line data, no point in looking again. */
2957 if (this_cu
->v
.quick
->no_file_data
)
2960 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2961 in the stub for CUs, there's is no need to lookup the DWO file.
2962 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2964 if (this_cu
->is_debug_types
)
2966 struct type_unit_group
*tu_group
= this_cu
->s
.type_unit_group
;
2968 init_cutu_and_read_dies (tu_group
->t
.first_tu
, NULL
, 0, 0,
2969 dw2_get_file_names_reader
, tu_group
);
2972 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2974 if (this_cu
->v
.quick
->no_file_data
)
2976 return this_cu
->v
.quick
->file_names
;
2979 /* A helper for the "quick" functions which computes and caches the
2980 real path for a given file name from the line table. */
2983 dw2_get_real_path (struct objfile
*objfile
,
2984 struct quick_file_names
*qfn
, int index
)
2986 if (qfn
->real_names
== NULL
)
2987 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2988 qfn
->num_file_names
, sizeof (char *));
2990 if (qfn
->real_names
[index
] == NULL
)
2991 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2993 return qfn
->real_names
[index
];
2996 static struct symtab
*
2997 dw2_find_last_source_symtab (struct objfile
*objfile
)
3001 dw2_setup (objfile
);
3002 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3003 return dw2_instantiate_symtab (dw2_get_cu (index
));
3006 /* Traversal function for dw2_forget_cached_source_info. */
3009 dw2_free_cached_file_names (void **slot
, void *info
)
3011 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3013 if (file_data
->real_names
)
3017 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3019 xfree ((void*) file_data
->real_names
[i
]);
3020 file_data
->real_names
[i
] = NULL
;
3028 dw2_forget_cached_source_info (struct objfile
*objfile
)
3030 dw2_setup (objfile
);
3032 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3033 dw2_free_cached_file_names
, NULL
);
3036 /* Helper function for dw2_map_symtabs_matching_filename that expands
3037 the symtabs and calls the iterator. */
3040 dw2_map_expand_apply (struct objfile
*objfile
,
3041 struct dwarf2_per_cu_data
*per_cu
,
3043 const char *full_path
, const char *real_path
,
3044 int (*callback
) (struct symtab
*, void *),
3047 struct symtab
*last_made
= objfile
->symtabs
;
3049 /* Don't visit already-expanded CUs. */
3050 if (per_cu
->v
.quick
->symtab
)
3053 /* This may expand more than one symtab, and we want to iterate over
3055 dw2_instantiate_symtab (per_cu
);
3057 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
3058 objfile
->symtabs
, last_made
);
3061 /* Implementation of the map_symtabs_matching_filename method. */
3064 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3065 const char *full_path
, const char *real_path
,
3066 int (*callback
) (struct symtab
*, void *),
3070 const char *name_basename
= lbasename (name
);
3071 int is_abs
= IS_ABSOLUTE_PATH (name
);
3073 dw2_setup (objfile
);
3075 dw2_build_type_unit_groups ();
3077 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3078 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3081 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3082 struct quick_file_names
*file_data
;
3084 /* We only need to look at symtabs not already expanded. */
3085 if (per_cu
->v
.quick
->symtab
)
3088 file_data
= dw2_get_file_names (objfile
, per_cu
);
3089 if (file_data
== NULL
)
3092 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3094 const char *this_name
= file_data
->file_names
[j
];
3096 if (FILENAME_CMP (name
, this_name
) == 0
3097 || (!is_abs
&& compare_filenames_for_search (this_name
, name
)))
3099 if (dw2_map_expand_apply (objfile
, per_cu
,
3100 name
, full_path
, real_path
,
3105 /* Before we invoke realpath, which can get expensive when many
3106 files are involved, do a quick comparison of the basenames. */
3107 if (! basenames_may_differ
3108 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3111 if (full_path
!= NULL
)
3113 const char *this_real_name
= dw2_get_real_path (objfile
,
3116 if (this_real_name
!= NULL
3117 && (FILENAME_CMP (full_path
, this_real_name
) == 0
3119 && compare_filenames_for_search (this_real_name
,
3122 if (dw2_map_expand_apply (objfile
, per_cu
,
3123 name
, full_path
, real_path
,
3129 if (real_path
!= NULL
)
3131 const char *this_real_name
= dw2_get_real_path (objfile
,
3134 if (this_real_name
!= NULL
3135 && (FILENAME_CMP (real_path
, this_real_name
) == 0
3137 && compare_filenames_for_search (this_real_name
,
3140 if (dw2_map_expand_apply (objfile
, per_cu
,
3141 name
, full_path
, real_path
,
3152 /* Struct used to manage iterating over all CUs looking for a symbol. */
3154 struct dw2_symtab_iterator
3156 /* The internalized form of .gdb_index. */
3157 struct mapped_index
*index
;
3158 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3159 int want_specific_block
;
3160 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3161 Unused if !WANT_SPECIFIC_BLOCK. */
3163 /* The kind of symbol we're looking for. */
3165 /* The list of CUs from the index entry of the symbol,
3166 or NULL if not found. */
3168 /* The next element in VEC to look at. */
3170 /* The number of elements in VEC, or zero if there is no match. */
3174 /* Initialize the index symtab iterator ITER.
3175 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3176 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3179 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3180 struct mapped_index
*index
,
3181 int want_specific_block
,
3186 iter
->index
= index
;
3187 iter
->want_specific_block
= want_specific_block
;
3188 iter
->block_index
= block_index
;
3189 iter
->domain
= domain
;
3192 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3193 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3201 /* Return the next matching CU or NULL if there are no more. */
3203 static struct dwarf2_per_cu_data
*
3204 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3206 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3208 offset_type cu_index_and_attrs
=
3209 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3210 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3211 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
3212 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3213 /* This value is only valid for index versions >= 7. */
3214 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3215 gdb_index_symbol_kind symbol_kind
=
3216 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3217 /* Only check the symbol attributes if they're present.
3218 Indices prior to version 7 don't record them,
3219 and indices >= 7 may elide them for certain symbols
3220 (gold does this). */
3222 (iter
->index
->version
>= 7
3223 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3225 /* Skip if already read in. */
3226 if (per_cu
->v
.quick
->symtab
)
3230 && iter
->want_specific_block
3231 && want_static
!= is_static
)
3234 /* Only check the symbol's kind if it has one. */
3237 switch (iter
->domain
)
3240 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3241 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3242 /* Some types are also in VAR_DOMAIN. */
3243 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3247 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3251 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3266 static struct symtab
*
3267 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3268 const char *name
, domain_enum domain
)
3270 struct symtab
*stab_best
= NULL
;
3271 struct mapped_index
*index
;
3273 dw2_setup (objfile
);
3275 index
= dwarf2_per_objfile
->index_table
;
3277 /* index is NULL if OBJF_READNOW. */
3280 struct dw2_symtab_iterator iter
;
3281 struct dwarf2_per_cu_data
*per_cu
;
3283 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3285 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3287 struct symbol
*sym
= NULL
;
3288 struct symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3290 /* Some caution must be observed with overloaded functions
3291 and methods, since the index will not contain any overload
3292 information (but NAME might contain it). */
3295 struct blockvector
*bv
= BLOCKVECTOR (stab
);
3296 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3298 sym
= lookup_block_symbol (block
, name
, domain
);
3301 if (sym
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
3303 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
3309 /* Keep looking through other CUs. */
3317 dw2_print_stats (struct objfile
*objfile
)
3321 dw2_setup (objfile
);
3323 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3324 + dwarf2_per_objfile
->n_type_units
); ++i
)
3326 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3328 if (!per_cu
->v
.quick
->symtab
)
3331 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3335 dw2_dump (struct objfile
*objfile
)
3337 /* Nothing worth printing. */
3341 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
3342 struct section_offsets
*delta
)
3344 /* There's nothing to relocate here. */
3348 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3349 const char *func_name
)
3351 struct mapped_index
*index
;
3353 dw2_setup (objfile
);
3355 index
= dwarf2_per_objfile
->index_table
;
3357 /* index is NULL if OBJF_READNOW. */
3360 struct dw2_symtab_iterator iter
;
3361 struct dwarf2_per_cu_data
*per_cu
;
3363 /* Note: It doesn't matter what we pass for block_index here. */
3364 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3367 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3368 dw2_instantiate_symtab (per_cu
);
3373 dw2_expand_all_symtabs (struct objfile
*objfile
)
3377 dw2_setup (objfile
);
3379 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3380 + dwarf2_per_objfile
->n_type_units
); ++i
)
3382 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3384 dw2_instantiate_symtab (per_cu
);
3389 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3390 const char *filename
)
3394 dw2_setup (objfile
);
3396 /* We don't need to consider type units here.
3397 This is only called for examining code, e.g. expand_line_sal.
3398 There can be an order of magnitude (or more) more type units
3399 than comp units, and we avoid them if we can. */
3401 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3404 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3405 struct quick_file_names
*file_data
;
3407 /* We only need to look at symtabs not already expanded. */
3408 if (per_cu
->v
.quick
->symtab
)
3411 file_data
= dw2_get_file_names (objfile
, per_cu
);
3412 if (file_data
== NULL
)
3415 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3417 const char *this_name
= file_data
->file_names
[j
];
3418 if (FILENAME_CMP (this_name
, filename
) == 0)
3420 dw2_instantiate_symtab (per_cu
);
3427 /* A helper function for dw2_find_symbol_file that finds the primary
3428 file name for a given CU. This is a die_reader_func. */
3431 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3433 struct die_info
*comp_unit_die
,
3437 const char **result_ptr
= data
;
3438 struct dwarf2_cu
*cu
= reader
->cu
;
3439 struct attribute
*attr
;
3441 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3445 *result_ptr
= DW_STRING (attr
);
3449 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3451 struct dwarf2_per_cu_data
*per_cu
;
3453 const char *filename
;
3455 dw2_setup (objfile
);
3457 /* index_table is NULL if OBJF_READNOW. */
3458 if (!dwarf2_per_objfile
->index_table
)
3462 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3464 struct blockvector
*bv
= BLOCKVECTOR (s
);
3465 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3466 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3469 return SYMBOL_SYMTAB (sym
)->filename
;
3474 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3478 /* Note that this just looks at the very first one named NAME -- but
3479 actually we are looking for a function. find_main_filename
3480 should be rewritten so that it doesn't require a custom hook. It
3481 could just use the ordinary symbol tables. */
3482 /* vec[0] is the length, which must always be >0. */
3483 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3485 if (per_cu
->v
.quick
->symtab
!= NULL
)
3486 return per_cu
->v
.quick
->symtab
->filename
;
3488 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3489 dw2_get_primary_filename_reader
, &filename
);
3495 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3496 struct objfile
*objfile
, int global
,
3497 int (*callback
) (struct block
*,
3498 struct symbol
*, void *),
3499 void *data
, symbol_compare_ftype
*match
,
3500 symbol_compare_ftype
*ordered_compare
)
3502 /* Currently unimplemented; used for Ada. The function can be called if the
3503 current language is Ada for a non-Ada objfile using GNU index. As Ada
3504 does not look for non-Ada symbols this function should just return. */
3508 dw2_expand_symtabs_matching
3509 (struct objfile
*objfile
,
3510 int (*file_matcher
) (const char *, void *),
3511 int (*name_matcher
) (const char *, void *),
3512 enum search_domain kind
,
3517 struct mapped_index
*index
;
3519 dw2_setup (objfile
);
3521 /* index_table is NULL if OBJF_READNOW. */
3522 if (!dwarf2_per_objfile
->index_table
)
3524 index
= dwarf2_per_objfile
->index_table
;
3526 if (file_matcher
!= NULL
)
3528 struct cleanup
*cleanup
;
3529 htab_t visited_found
, visited_not_found
;
3531 dw2_build_type_unit_groups ();
3533 visited_found
= htab_create_alloc (10,
3534 htab_hash_pointer
, htab_eq_pointer
,
3535 NULL
, xcalloc
, xfree
);
3536 cleanup
= make_cleanup_htab_delete (visited_found
);
3537 visited_not_found
= htab_create_alloc (10,
3538 htab_hash_pointer
, htab_eq_pointer
,
3539 NULL
, xcalloc
, xfree
);
3540 make_cleanup_htab_delete (visited_not_found
);
3542 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3543 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3546 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3547 struct quick_file_names
*file_data
;
3550 per_cu
->v
.quick
->mark
= 0;
3552 /* We only need to look at symtabs not already expanded. */
3553 if (per_cu
->v
.quick
->symtab
)
3556 file_data
= dw2_get_file_names (objfile
, per_cu
);
3557 if (file_data
== NULL
)
3560 if (htab_find (visited_not_found
, file_data
) != NULL
)
3562 else if (htab_find (visited_found
, file_data
) != NULL
)
3564 per_cu
->v
.quick
->mark
= 1;
3568 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3570 if (file_matcher (file_data
->file_names
[j
], data
))
3572 per_cu
->v
.quick
->mark
= 1;
3577 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3579 : visited_not_found
,
3584 do_cleanups (cleanup
);
3587 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3589 offset_type idx
= 2 * iter
;
3591 offset_type
*vec
, vec_len
, vec_idx
;
3593 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3596 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3598 if (! (*name_matcher
) (name
, data
))
3601 /* The name was matched, now expand corresponding CUs that were
3603 vec
= (offset_type
*) (index
->constant_pool
3604 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3605 vec_len
= MAYBE_SWAP (vec
[0]);
3606 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3608 struct dwarf2_per_cu_data
*per_cu
;
3609 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3610 gdb_index_symbol_kind symbol_kind
=
3611 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3612 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3614 /* Don't crash on bad data. */
3615 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3616 + dwarf2_per_objfile
->n_type_units
))
3619 /* Only check the symbol's kind if it has one.
3620 Indices prior to version 7 don't record it. */
3621 if (index
->version
>= 7)
3625 case VARIABLES_DOMAIN
:
3626 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3629 case FUNCTIONS_DOMAIN
:
3630 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3634 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3642 per_cu
= dw2_get_cu (cu_index
);
3643 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3644 dw2_instantiate_symtab (per_cu
);
3649 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3652 static struct symtab
*
3653 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3657 if (BLOCKVECTOR (symtab
) != NULL
3658 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3661 if (symtab
->includes
== NULL
)
3664 for (i
= 0; symtab
->includes
[i
]; ++i
)
3666 struct symtab
*s
= symtab
->includes
[i
];
3668 s
= recursively_find_pc_sect_symtab (s
, pc
);
3676 static struct symtab
*
3677 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3678 struct minimal_symbol
*msymbol
,
3680 struct obj_section
*section
,
3683 struct dwarf2_per_cu_data
*data
;
3684 struct symtab
*result
;
3686 dw2_setup (objfile
);
3688 if (!objfile
->psymtabs_addrmap
)
3691 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3695 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3696 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3697 paddress (get_objfile_arch (objfile
), pc
));
3699 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3700 gdb_assert (result
!= NULL
);
3705 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3706 void *data
, int need_fullname
)
3709 struct cleanup
*cleanup
;
3710 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3711 NULL
, xcalloc
, xfree
);
3713 cleanup
= make_cleanup_htab_delete (visited
);
3714 dw2_setup (objfile
);
3716 dw2_build_type_unit_groups ();
3718 /* We can ignore file names coming from already-expanded CUs. */
3719 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3720 + dwarf2_per_objfile
->n_type_units
); ++i
)
3722 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3724 if (per_cu
->v
.quick
->symtab
)
3726 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3729 *slot
= per_cu
->v
.quick
->file_names
;
3733 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3734 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3737 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3738 struct quick_file_names
*file_data
;
3741 /* We only need to look at symtabs not already expanded. */
3742 if (per_cu
->v
.quick
->symtab
)
3745 file_data
= dw2_get_file_names (objfile
, per_cu
);
3746 if (file_data
== NULL
)
3749 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3752 /* Already visited. */
3757 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3759 const char *this_real_name
;
3762 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3764 this_real_name
= NULL
;
3765 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3769 do_cleanups (cleanup
);
3773 dw2_has_symbols (struct objfile
*objfile
)
3778 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3781 dw2_find_last_source_symtab
,
3782 dw2_forget_cached_source_info
,
3783 dw2_map_symtabs_matching_filename
,
3788 dw2_expand_symtabs_for_function
,
3789 dw2_expand_all_symtabs
,
3790 dw2_expand_symtabs_with_filename
,
3791 dw2_find_symbol_file
,
3792 dw2_map_matching_symbols
,
3793 dw2_expand_symtabs_matching
,
3794 dw2_find_pc_sect_symtab
,
3795 dw2_map_symbol_filenames
3798 /* Initialize for reading DWARF for this objfile. Return 0 if this
3799 file will use psymtabs, or 1 if using the GNU index. */
3802 dwarf2_initialize_objfile (struct objfile
*objfile
)
3804 /* If we're about to read full symbols, don't bother with the
3805 indices. In this case we also don't care if some other debug
3806 format is making psymtabs, because they are all about to be
3808 if ((objfile
->flags
& OBJF_READNOW
))
3812 dwarf2_per_objfile
->using_index
= 1;
3813 create_all_comp_units (objfile
);
3814 create_all_type_units (objfile
);
3815 dwarf2_per_objfile
->quick_file_names_table
=
3816 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3818 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3819 + dwarf2_per_objfile
->n_type_units
); ++i
)
3821 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3823 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3824 struct dwarf2_per_cu_quick_data
);
3827 /* Return 1 so that gdb sees the "quick" functions. However,
3828 these functions will be no-ops because we will have expanded
3833 if (dwarf2_read_index (objfile
))
3841 /* Build a partial symbol table. */
3844 dwarf2_build_psymtabs (struct objfile
*objfile
)
3846 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3848 init_psymbol_list (objfile
, 1024);
3851 dwarf2_build_psymtabs_hard (objfile
);
3854 /* Return the total length of the CU described by HEADER. */
3857 get_cu_length (const struct comp_unit_head
*header
)
3859 return header
->initial_length_size
+ header
->length
;
3862 /* Return TRUE if OFFSET is within CU_HEADER. */
3865 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3867 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3868 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3870 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3873 /* Find the base address of the compilation unit for range lists and
3874 location lists. It will normally be specified by DW_AT_low_pc.
3875 In DWARF-3 draft 4, the base address could be overridden by
3876 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3877 compilation units with discontinuous ranges. */
3880 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3882 struct attribute
*attr
;
3885 cu
->base_address
= 0;
3887 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3890 cu
->base_address
= DW_ADDR (attr
);
3895 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3898 cu
->base_address
= DW_ADDR (attr
);
3904 /* Read in the comp unit header information from the debug_info at info_ptr.
3905 NOTE: This leaves members offset, first_die_offset to be filled in
3909 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3910 gdb_byte
*info_ptr
, bfd
*abfd
)
3913 unsigned int bytes_read
;
3915 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3916 cu_header
->initial_length_size
= bytes_read
;
3917 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3918 info_ptr
+= bytes_read
;
3919 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3921 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3923 info_ptr
+= bytes_read
;
3924 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3926 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3927 if (signed_addr
< 0)
3928 internal_error (__FILE__
, __LINE__
,
3929 _("read_comp_unit_head: dwarf from non elf file"));
3930 cu_header
->signed_addr_p
= signed_addr
;
3935 /* Helper function that returns the proper abbrev section for
3938 static struct dwarf2_section_info
*
3939 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
3941 struct dwarf2_section_info
*abbrev
;
3943 if (this_cu
->is_dwz
)
3944 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
3946 abbrev
= &dwarf2_per_objfile
->abbrev
;
3951 /* Subroutine of read_and_check_comp_unit_head and
3952 read_and_check_type_unit_head to simplify them.
3953 Perform various error checking on the header. */
3956 error_check_comp_unit_head (struct comp_unit_head
*header
,
3957 struct dwarf2_section_info
*section
,
3958 struct dwarf2_section_info
*abbrev_section
)
3960 bfd
*abfd
= section
->asection
->owner
;
3961 const char *filename
= bfd_get_filename (abfd
);
3963 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3964 error (_("Dwarf Error: wrong version in compilation unit header "
3965 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3968 if (header
->abbrev_offset
.sect_off
3969 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
3970 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3971 "(offset 0x%lx + 6) [in module %s]"),
3972 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3975 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3976 avoid potential 32-bit overflow. */
3977 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3979 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3980 "(offset 0x%lx + 0) [in module %s]"),
3981 (long) header
->length
, (long) header
->offset
.sect_off
,
3985 /* Read in a CU/TU header and perform some basic error checking.
3986 The contents of the header are stored in HEADER.
3987 The result is a pointer to the start of the first DIE. */
3990 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3991 struct dwarf2_section_info
*section
,
3992 struct dwarf2_section_info
*abbrev_section
,
3994 int is_debug_types_section
)
3996 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3997 bfd
*abfd
= section
->asection
->owner
;
3999 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4001 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4003 /* If we're reading a type unit, skip over the signature and
4004 type_offset fields. */
4005 if (is_debug_types_section
)
4006 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
4008 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4010 error_check_comp_unit_head (header
, section
, abbrev_section
);
4015 /* Read in the types comp unit header information from .debug_types entry at
4016 types_ptr. The result is a pointer to one past the end of the header. */
4019 read_and_check_type_unit_head (struct comp_unit_head
*header
,
4020 struct dwarf2_section_info
*section
,
4021 struct dwarf2_section_info
*abbrev_section
,
4023 ULONGEST
*signature
,
4024 cu_offset
*type_offset_in_tu
)
4026 gdb_byte
*beg_of_comp_unit
= info_ptr
;
4027 bfd
*abfd
= section
->asection
->owner
;
4029 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4031 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4033 /* If we're reading a type unit, skip over the signature and
4034 type_offset fields. */
4035 if (signature
!= NULL
)
4036 *signature
= read_8_bytes (abfd
, info_ptr
);
4038 if (type_offset_in_tu
!= NULL
)
4039 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
4040 header
->offset_size
);
4041 info_ptr
+= header
->offset_size
;
4043 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4045 error_check_comp_unit_head (header
, section
, abbrev_section
);
4050 /* Fetch the abbreviation table offset from a comp or type unit header. */
4053 read_abbrev_offset (struct dwarf2_section_info
*section
,
4056 bfd
*abfd
= section
->asection
->owner
;
4058 unsigned int length
, initial_length_size
, offset_size
;
4059 sect_offset abbrev_offset
;
4061 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4062 info_ptr
= section
->buffer
+ offset
.sect_off
;
4063 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4064 offset_size
= initial_length_size
== 4 ? 4 : 8;
4065 info_ptr
+= initial_length_size
+ 2 /*version*/;
4066 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
4067 return abbrev_offset
;
4070 /* Allocate a new partial symtab for file named NAME and mark this new
4071 partial symtab as being an include of PST. */
4074 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
4075 struct objfile
*objfile
)
4077 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4079 subpst
->section_offsets
= pst
->section_offsets
;
4080 subpst
->textlow
= 0;
4081 subpst
->texthigh
= 0;
4083 subpst
->dependencies
= (struct partial_symtab
**)
4084 obstack_alloc (&objfile
->objfile_obstack
,
4085 sizeof (struct partial_symtab
*));
4086 subpst
->dependencies
[0] = pst
;
4087 subpst
->number_of_dependencies
= 1;
4089 subpst
->globals_offset
= 0;
4090 subpst
->n_global_syms
= 0;
4091 subpst
->statics_offset
= 0;
4092 subpst
->n_static_syms
= 0;
4093 subpst
->symtab
= NULL
;
4094 subpst
->read_symtab
= pst
->read_symtab
;
4097 /* No private part is necessary for include psymtabs. This property
4098 can be used to differentiate between such include psymtabs and
4099 the regular ones. */
4100 subpst
->read_symtab_private
= NULL
;
4103 /* Read the Line Number Program data and extract the list of files
4104 included by the source file represented by PST. Build an include
4105 partial symtab for each of these included files. */
4108 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4109 struct die_info
*die
,
4110 struct partial_symtab
*pst
)
4112 struct line_header
*lh
= NULL
;
4113 struct attribute
*attr
;
4115 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4117 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4119 return; /* No linetable, so no includes. */
4121 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4122 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
4124 free_line_header (lh
);
4128 hash_signatured_type (const void *item
)
4130 const struct signatured_type
*sig_type
= item
;
4132 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4133 return sig_type
->signature
;
4137 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4139 const struct signatured_type
*lhs
= item_lhs
;
4140 const struct signatured_type
*rhs
= item_rhs
;
4142 return lhs
->signature
== rhs
->signature
;
4145 /* Allocate a hash table for signatured types. */
4148 allocate_signatured_type_table (struct objfile
*objfile
)
4150 return htab_create_alloc_ex (41,
4151 hash_signatured_type
,
4154 &objfile
->objfile_obstack
,
4155 hashtab_obstack_allocate
,
4156 dummy_obstack_deallocate
);
4159 /* A helper function to add a signatured type CU to a table. */
4162 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4164 struct signatured_type
*sigt
= *slot
;
4165 struct signatured_type
***datap
= datum
;
4173 /* Create the hash table of all entries in the .debug_types section.
4174 DWO_FILE is a pointer to the DWO file for .debug_types.dwo,
4176 Note: This function processes DWO files only, not DWP files.
4177 The result is a pointer to the hash table or NULL if there are
4181 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4182 VEC (dwarf2_section_info_def
) *types
)
4184 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4185 htab_t types_htab
= NULL
;
4187 struct dwarf2_section_info
*section
;
4188 struct dwarf2_section_info
*abbrev_section
;
4190 if (VEC_empty (dwarf2_section_info_def
, types
))
4193 abbrev_section
= (dwo_file
!= NULL
4194 ? &dwo_file
->sections
.abbrev
4195 : &dwarf2_per_objfile
->abbrev
);
4197 if (dwarf2_read_debug
)
4198 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4199 dwo_file
? ".dwo" : "",
4200 bfd_get_filename (abbrev_section
->asection
->owner
));
4203 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4207 gdb_byte
*info_ptr
, *end_ptr
;
4208 struct dwarf2_section_info
*abbrev_section
;
4210 dwarf2_read_section (objfile
, section
);
4211 info_ptr
= section
->buffer
;
4213 if (info_ptr
== NULL
)
4216 /* We can't set abfd until now because the section may be empty or
4217 not present, in which case section->asection will be NULL. */
4218 abfd
= section
->asection
->owner
;
4221 abbrev_section
= &dwo_file
->sections
.abbrev
;
4223 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4225 if (types_htab
== NULL
)
4228 types_htab
= allocate_dwo_unit_table (objfile
);
4230 types_htab
= allocate_signatured_type_table (objfile
);
4233 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4234 because we don't need to read any dies: the signature is in the
4237 end_ptr
= info_ptr
+ section
->size
;
4238 while (info_ptr
< end_ptr
)
4241 cu_offset type_offset_in_tu
;
4243 struct signatured_type
*sig_type
;
4244 struct dwo_unit
*dwo_tu
;
4246 gdb_byte
*ptr
= info_ptr
;
4247 struct comp_unit_head header
;
4248 unsigned int length
;
4250 offset
.sect_off
= ptr
- section
->buffer
;
4252 /* We need to read the type's signature in order to build the hash
4253 table, but we don't need anything else just yet. */
4255 ptr
= read_and_check_type_unit_head (&header
, section
,
4256 abbrev_section
, ptr
,
4257 &signature
, &type_offset_in_tu
);
4259 length
= get_cu_length (&header
);
4261 /* Skip dummy type units. */
4262 if (ptr
>= info_ptr
+ length
4263 || peek_abbrev_code (abfd
, ptr
) == 0)
4272 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4274 dwo_tu
->dwo_file
= dwo_file
;
4275 dwo_tu
->signature
= signature
;
4276 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4277 dwo_tu
->info_or_types_section
= section
;
4278 dwo_tu
->offset
= offset
;
4279 dwo_tu
->length
= length
;
4283 /* N.B.: type_offset is not usable if this type uses a DWO file.
4284 The real type_offset is in the DWO file. */
4286 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4287 struct signatured_type
);
4288 sig_type
->signature
= signature
;
4289 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4290 sig_type
->per_cu
.objfile
= objfile
;
4291 sig_type
->per_cu
.is_debug_types
= 1;
4292 sig_type
->per_cu
.info_or_types_section
= section
;
4293 sig_type
->per_cu
.offset
= offset
;
4294 sig_type
->per_cu
.length
= length
;
4297 slot
= htab_find_slot (types_htab
,
4298 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4300 gdb_assert (slot
!= NULL
);
4303 sect_offset dup_offset
;
4307 const struct dwo_unit
*dup_tu
= *slot
;
4309 dup_offset
= dup_tu
->offset
;
4313 const struct signatured_type
*dup_tu
= *slot
;
4315 dup_offset
= dup_tu
->per_cu
.offset
;
4318 complaint (&symfile_complaints
,
4319 _("debug type entry at offset 0x%x is duplicate to the "
4320 "entry at offset 0x%x, signature 0x%s"),
4321 offset
.sect_off
, dup_offset
.sect_off
,
4322 phex (signature
, sizeof (signature
)));
4324 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4326 if (dwarf2_read_debug
)
4327 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
4329 phex (signature
, sizeof (signature
)));
4338 /* Create the hash table of all entries in the .debug_types section,
4339 and initialize all_type_units.
4340 The result is zero if there is an error (e.g. missing .debug_types section),
4341 otherwise non-zero. */
4344 create_all_type_units (struct objfile
*objfile
)
4347 struct signatured_type
**iter
;
4349 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4350 if (types_htab
== NULL
)
4352 dwarf2_per_objfile
->signatured_types
= NULL
;
4356 dwarf2_per_objfile
->signatured_types
= types_htab
;
4358 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4359 dwarf2_per_objfile
->all_type_units
4360 = obstack_alloc (&objfile
->objfile_obstack
,
4361 dwarf2_per_objfile
->n_type_units
4362 * sizeof (struct signatured_type
*));
4363 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4364 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4365 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4366 == dwarf2_per_objfile
->n_type_units
);
4371 /* Lookup a signature based type for DW_FORM_ref_sig8.
4372 Returns NULL if signature SIG is not present in the table. */
4374 static struct signatured_type
*
4375 lookup_signatured_type (ULONGEST sig
)
4377 struct signatured_type find_entry
, *entry
;
4379 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4381 complaint (&symfile_complaints
,
4382 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4386 find_entry
.signature
= sig
;
4387 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4391 /* Low level DIE reading support. */
4393 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4396 init_cu_die_reader (struct die_reader_specs
*reader
,
4397 struct dwarf2_cu
*cu
,
4398 struct dwarf2_section_info
*section
,
4399 struct dwo_file
*dwo_file
)
4401 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4402 reader
->abfd
= section
->asection
->owner
;
4404 reader
->dwo_file
= dwo_file
;
4405 reader
->die_section
= section
;
4406 reader
->buffer
= section
->buffer
;
4407 reader
->buffer_end
= section
->buffer
+ section
->size
;
4410 /* Initialize a CU (or TU) and read its DIEs.
4411 If the CU defers to a DWO file, read the DWO file as well.
4413 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4414 Otherwise the table specified in the comp unit header is read in and used.
4415 This is an optimization for when we already have the abbrev table.
4417 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4418 Otherwise, a new CU is allocated with xmalloc.
4420 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4421 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4423 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4424 linker) then DIE_READER_FUNC will not get called. */
4427 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4428 struct abbrev_table
*abbrev_table
,
4429 int use_existing_cu
, int keep
,
4430 die_reader_func_ftype
*die_reader_func
,
4433 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4434 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4435 bfd
*abfd
= section
->asection
->owner
;
4436 struct dwarf2_cu
*cu
;
4437 gdb_byte
*begin_info_ptr
, *info_ptr
;
4438 struct die_reader_specs reader
;
4439 struct die_info
*comp_unit_die
;
4441 struct attribute
*attr
;
4442 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4443 struct signatured_type
*sig_type
= NULL
;
4444 struct dwarf2_section_info
*abbrev_section
;
4445 /* Non-zero if CU currently points to a DWO file and we need to
4446 reread it. When this happens we need to reread the skeleton die
4447 before we can reread the DWO file. */
4448 int rereading_dwo_cu
= 0;
4450 if (dwarf2_die_debug
)
4451 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4452 this_cu
->is_debug_types
? "type" : "comp",
4453 this_cu
->offset
.sect_off
);
4455 if (use_existing_cu
)
4458 cleanups
= make_cleanup (null_cleanup
, NULL
);
4460 /* This is cheap if the section is already read in. */
4461 dwarf2_read_section (objfile
, section
);
4463 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4465 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
4467 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4471 /* If this CU is from a DWO file we need to start over, we need to
4472 refetch the attributes from the skeleton CU.
4473 This could be optimized by retrieving those attributes from when we
4474 were here the first time: the previous comp_unit_die was stored in
4475 comp_unit_obstack. But there's no data yet that we need this
4477 if (cu
->dwo_unit
!= NULL
)
4478 rereading_dwo_cu
= 1;
4482 /* If !use_existing_cu, this_cu->cu must be NULL. */
4483 gdb_assert (this_cu
->cu
== NULL
);
4485 cu
= xmalloc (sizeof (*cu
));
4486 init_one_comp_unit (cu
, this_cu
);
4488 /* If an error occurs while loading, release our storage. */
4489 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4492 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4494 /* We already have the header, there's no need to read it in again. */
4495 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4499 if (this_cu
->is_debug_types
)
4502 cu_offset type_offset_in_tu
;
4504 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4505 abbrev_section
, info_ptr
,
4507 &type_offset_in_tu
);
4509 /* Since per_cu is the first member of struct signatured_type,
4510 we can go from a pointer to one to a pointer to the other. */
4511 sig_type
= (struct signatured_type
*) this_cu
;
4512 gdb_assert (sig_type
->signature
== signature
);
4513 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4514 == type_offset_in_tu
.cu_off
);
4515 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4517 /* LENGTH has not been set yet for type units if we're
4518 using .gdb_index. */
4519 this_cu
->length
= get_cu_length (&cu
->header
);
4521 /* Establish the type offset that can be used to lookup the type. */
4522 sig_type
->type_offset_in_section
.sect_off
=
4523 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4527 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4531 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4532 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4536 /* Skip dummy compilation units. */
4537 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4538 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4540 do_cleanups (cleanups
);
4544 /* If we don't have them yet, read the abbrevs for this compilation unit.
4545 And if we need to read them now, make sure they're freed when we're
4546 done. Note that it's important that if the CU had an abbrev table
4547 on entry we don't free it when we're done: Somewhere up the call stack
4548 it may be in use. */
4549 if (abbrev_table
!= NULL
)
4551 gdb_assert (cu
->abbrev_table
== NULL
);
4552 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4553 == abbrev_table
->offset
.sect_off
);
4554 cu
->abbrev_table
= abbrev_table
;
4556 else if (cu
->abbrev_table
== NULL
)
4558 dwarf2_read_abbrevs (cu
, abbrev_section
);
4559 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4561 else if (rereading_dwo_cu
)
4563 dwarf2_free_abbrev_table (cu
);
4564 dwarf2_read_abbrevs (cu
, abbrev_section
);
4567 /* Read the top level CU/TU die. */
4568 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4569 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4571 /* If we have a DWO stub, process it and then read in the DWO file.
4572 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4573 a DWO CU, that this test will fail. */
4574 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4577 char *dwo_name
= DW_STRING (attr
);
4578 const char *comp_dir_string
;
4579 struct dwo_unit
*dwo_unit
;
4580 ULONGEST signature
; /* Or dwo_id. */
4581 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4582 int i
,num_extra_attrs
;
4583 struct dwarf2_section_info
*dwo_abbrev_section
;
4586 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4587 " has children (offset 0x%x) [in module %s]"),
4588 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4590 /* These attributes aren't processed until later:
4591 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4592 However, the attribute is found in the stub which we won't have later.
4593 In order to not impose this complication on the rest of the code,
4594 we read them here and copy them to the DWO CU/TU die. */
4596 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4599 if (! this_cu
->is_debug_types
)
4600 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4601 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4602 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4603 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4604 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4606 /* There should be a DW_AT_addr_base attribute here (if needed).
4607 We need the value before we can process DW_FORM_GNU_addr_index. */
4609 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4611 cu
->addr_base
= DW_UNSND (attr
);
4613 /* There should be a DW_AT_ranges_base attribute here (if needed).
4614 We need the value before we can process DW_AT_ranges. */
4615 cu
->ranges_base
= 0;
4616 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4618 cu
->ranges_base
= DW_UNSND (attr
);
4620 if (this_cu
->is_debug_types
)
4622 gdb_assert (sig_type
!= NULL
);
4623 signature
= sig_type
->signature
;
4627 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4629 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4631 signature
= DW_UNSND (attr
);
4634 /* We may need the comp_dir in order to find the DWO file. */
4635 comp_dir_string
= NULL
;
4637 comp_dir_string
= DW_STRING (comp_dir
);
4639 if (this_cu
->is_debug_types
)
4640 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4642 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4645 if (dwo_unit
== NULL
)
4647 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4648 " with ID %s [in module %s]"),
4649 this_cu
->offset
.sect_off
,
4650 phex (signature
, sizeof (signature
)),
4654 /* Set up for reading the DWO CU/TU. */
4655 cu
->dwo_unit
= dwo_unit
;
4656 section
= dwo_unit
->info_or_types_section
;
4657 dwarf2_read_section (objfile
, section
);
4658 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4659 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4660 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4662 if (this_cu
->is_debug_types
)
4665 cu_offset type_offset_in_tu
;
4667 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4671 &type_offset_in_tu
);
4672 gdb_assert (sig_type
->signature
== signature
);
4673 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4674 /* For DWOs coming from DWP files, we don't know the CU length
4675 nor the type's offset in the TU until now. */
4676 dwo_unit
->length
= get_cu_length (&cu
->header
);
4677 dwo_unit
->type_offset_in_tu
= type_offset_in_tu
;
4679 /* Establish the type offset that can be used to lookup the type.
4680 For DWO files, we don't know it until now. */
4681 sig_type
->type_offset_in_section
.sect_off
=
4682 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4686 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4689 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4690 /* For DWOs coming from DWP files, we don't know the CU length
4692 dwo_unit
->length
= get_cu_length (&cu
->header
);
4695 /* Discard the original CU's abbrev table, and read the DWO's. */
4696 if (abbrev_table
== NULL
)
4698 dwarf2_free_abbrev_table (cu
);
4699 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4703 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4704 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4707 /* Read in the die, but leave space to copy over the attributes
4708 from the stub. This has the benefit of simplifying the rest of
4709 the code - all the real work is done here. */
4710 num_extra_attrs
= ((stmt_list
!= NULL
)
4714 + (comp_dir
!= NULL
));
4715 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4716 &has_children
, num_extra_attrs
);
4718 /* Copy over the attributes from the stub to the DWO die. */
4719 i
= comp_unit_die
->num_attrs
;
4720 if (stmt_list
!= NULL
)
4721 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4723 comp_unit_die
->attrs
[i
++] = *low_pc
;
4724 if (high_pc
!= NULL
)
4725 comp_unit_die
->attrs
[i
++] = *high_pc
;
4727 comp_unit_die
->attrs
[i
++] = *ranges
;
4728 if (comp_dir
!= NULL
)
4729 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4730 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4732 /* Skip dummy compilation units. */
4733 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4734 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4736 do_cleanups (cleanups
);
4741 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4743 if (free_cu_cleanup
!= NULL
)
4747 /* We've successfully allocated this compilation unit. Let our
4748 caller clean it up when finished with it. */
4749 discard_cleanups (free_cu_cleanup
);
4751 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4752 So we have to manually free the abbrev table. */
4753 dwarf2_free_abbrev_table (cu
);
4755 /* Link this CU into read_in_chain. */
4756 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4757 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4760 do_cleanups (free_cu_cleanup
);
4763 do_cleanups (cleanups
);
4766 /* Read CU/TU THIS_CU in section SECTION,
4767 but do not follow DW_AT_GNU_dwo_name if present.
4768 DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed
4769 to have already done the lookup to find the DWO/DWP file).
4771 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4772 THIS_CU->is_debug_types, but nothing else.
4774 We fill in THIS_CU->length.
4776 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4777 linker) then DIE_READER_FUNC will not get called.
4779 THIS_CU->cu is always freed when done.
4780 This is done in order to not leave THIS_CU->cu in a state where we have
4781 to care whether it refers to the "main" CU or the DWO CU. */
4784 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4785 struct dwarf2_section_info
*abbrev_section
,
4786 struct dwo_file
*dwo_file
,
4787 die_reader_func_ftype
*die_reader_func
,
4790 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4791 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4792 bfd
*abfd
= section
->asection
->owner
;
4793 struct dwarf2_cu cu
;
4794 gdb_byte
*begin_info_ptr
, *info_ptr
;
4795 struct die_reader_specs reader
;
4796 struct cleanup
*cleanups
;
4797 struct die_info
*comp_unit_die
;
4800 if (dwarf2_die_debug
)
4801 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4802 this_cu
->is_debug_types
? "type" : "comp",
4803 this_cu
->offset
.sect_off
);
4805 gdb_assert (this_cu
->cu
== NULL
);
4807 /* This is cheap if the section is already read in. */
4808 dwarf2_read_section (objfile
, section
);
4810 init_one_comp_unit (&cu
, this_cu
);
4812 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4814 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4815 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4816 abbrev_section
, info_ptr
,
4817 this_cu
->is_debug_types
);
4819 this_cu
->length
= get_cu_length (&cu
.header
);
4821 /* Skip dummy compilation units. */
4822 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4823 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4825 do_cleanups (cleanups
);
4829 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4830 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4832 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4833 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4835 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4837 do_cleanups (cleanups
);
4840 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4841 does not lookup the specified DWO file.
4842 This cannot be used to read DWO files.
4844 THIS_CU->cu is always freed when done.
4845 This is done in order to not leave THIS_CU->cu in a state where we have
4846 to care whether it refers to the "main" CU or the DWO CU.
4847 We can revisit this if the data shows there's a performance issue. */
4850 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4851 die_reader_func_ftype
*die_reader_func
,
4854 init_cutu_and_read_dies_no_follow (this_cu
,
4855 get_abbrev_section_for_cu (this_cu
),
4857 die_reader_func
, data
);
4860 /* Create a psymtab named NAME and assign it to PER_CU.
4862 The caller must fill in the following details:
4863 dirname, textlow, texthigh. */
4865 static struct partial_symtab
*
4866 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4868 struct objfile
*objfile
= per_cu
->objfile
;
4869 struct partial_symtab
*pst
;
4871 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4873 objfile
->global_psymbols
.next
,
4874 objfile
->static_psymbols
.next
);
4876 pst
->psymtabs_addrmap_supported
= 1;
4878 /* This is the glue that links PST into GDB's symbol API. */
4879 pst
->read_symtab_private
= per_cu
;
4880 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4881 per_cu
->v
.psymtab
= pst
;
4886 /* die_reader_func for process_psymtab_comp_unit. */
4889 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4891 struct die_info
*comp_unit_die
,
4895 struct dwarf2_cu
*cu
= reader
->cu
;
4896 struct objfile
*objfile
= cu
->objfile
;
4897 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4898 struct attribute
*attr
;
4900 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4901 struct partial_symtab
*pst
;
4903 const char *filename
;
4904 int *want_partial_unit_ptr
= data
;
4906 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4907 && (want_partial_unit_ptr
== NULL
4908 || !*want_partial_unit_ptr
))
4911 gdb_assert (! per_cu
->is_debug_types
);
4913 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4915 cu
->list_in_scope
= &file_symbols
;
4917 /* Allocate a new partial symbol table structure. */
4918 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4919 if (attr
== NULL
|| !DW_STRING (attr
))
4922 filename
= DW_STRING (attr
);
4924 pst
= create_partial_symtab (per_cu
, filename
);
4926 /* This must be done before calling dwarf2_build_include_psymtabs. */
4927 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4929 pst
->dirname
= DW_STRING (attr
);
4931 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4933 dwarf2_find_base_address (comp_unit_die
, cu
);
4935 /* Possibly set the default values of LOWPC and HIGHPC from
4937 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4938 &best_highpc
, cu
, pst
);
4939 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4940 /* Store the contiguous range if it is not empty; it can be empty for
4941 CUs with no code. */
4942 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4943 best_lowpc
+ baseaddr
,
4944 best_highpc
+ baseaddr
- 1, pst
);
4946 /* Check if comp unit has_children.
4947 If so, read the rest of the partial symbols from this comp unit.
4948 If not, there's no more debug_info for this comp unit. */
4951 struct partial_die_info
*first_die
;
4952 CORE_ADDR lowpc
, highpc
;
4954 lowpc
= ((CORE_ADDR
) -1);
4955 highpc
= ((CORE_ADDR
) 0);
4957 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4959 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4962 /* If we didn't find a lowpc, set it to highpc to avoid
4963 complaints from `maint check'. */
4964 if (lowpc
== ((CORE_ADDR
) -1))
4967 /* If the compilation unit didn't have an explicit address range,
4968 then use the information extracted from its child dies. */
4972 best_highpc
= highpc
;
4975 pst
->textlow
= best_lowpc
+ baseaddr
;
4976 pst
->texthigh
= best_highpc
+ baseaddr
;
4978 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4979 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4980 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4981 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4982 sort_pst_symbols (objfile
, pst
);
4984 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
))
4987 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4988 struct dwarf2_per_cu_data
*iter
;
4990 /* Fill in 'dependencies' here; we fill in 'users' in a
4992 pst
->number_of_dependencies
= len
;
4993 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4994 len
* sizeof (struct symtab
*));
4996 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
4999 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5001 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
5004 /* Get the list of files included in the current compilation unit,
5005 and build a psymtab for each of them. */
5006 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
5008 if (dwarf2_read_debug
)
5010 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5012 fprintf_unfiltered (gdb_stdlog
,
5013 "Psymtab for %s unit @0x%x: %s - %s"
5014 ", %d global, %d static syms\n",
5015 per_cu
->is_debug_types
? "type" : "comp",
5016 per_cu
->offset
.sect_off
,
5017 paddress (gdbarch
, pst
->textlow
),
5018 paddress (gdbarch
, pst
->texthigh
),
5019 pst
->n_global_syms
, pst
->n_static_syms
);
5023 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5024 Process compilation unit THIS_CU for a psymtab. */
5027 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
5028 int want_partial_unit
)
5030 /* If this compilation unit was already read in, free the
5031 cached copy in order to read it in again. This is
5032 necessary because we skipped some symbols when we first
5033 read in the compilation unit (see load_partial_dies).
5034 This problem could be avoided, but the benefit is unclear. */
5035 if (this_cu
->cu
!= NULL
)
5036 free_one_cached_comp_unit (this_cu
);
5038 gdb_assert (! this_cu
->is_debug_types
);
5039 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
5040 process_psymtab_comp_unit_reader
,
5041 &want_partial_unit
);
5043 /* Age out any secondary CUs. */
5044 age_cached_comp_units ();
5048 hash_type_unit_group (const void *item
)
5050 const struct type_unit_group
*tu_group
= item
;
5052 return hash_stmt_list_entry (&tu_group
->hash
);
5056 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5058 const struct type_unit_group
*lhs
= item_lhs
;
5059 const struct type_unit_group
*rhs
= item_rhs
;
5061 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5064 /* Allocate a hash table for type unit groups. */
5067 allocate_type_unit_groups_table (void)
5069 return htab_create_alloc_ex (3,
5070 hash_type_unit_group
,
5073 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5074 hashtab_obstack_allocate
,
5075 dummy_obstack_deallocate
);
5078 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5079 partial symtabs. We combine several TUs per psymtab to not let the size
5080 of any one psymtab grow too big. */
5081 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5082 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5084 /* Helper routine for get_type_unit_group.
5085 Create the type_unit_group object used to hold one or more TUs. */
5087 static struct type_unit_group
*
5088 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5090 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5091 struct dwarf2_per_cu_data
*per_cu
;
5092 struct type_unit_group
*tu_group
;
5094 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5095 struct type_unit_group
);
5096 per_cu
= &tu_group
->per_cu
;
5097 per_cu
->objfile
= objfile
;
5098 per_cu
->is_debug_types
= 1;
5099 per_cu
->s
.type_unit_group
= tu_group
;
5101 if (dwarf2_per_objfile
->using_index
)
5103 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5104 struct dwarf2_per_cu_quick_data
);
5105 tu_group
->t
.first_tu
= cu
->per_cu
;
5109 unsigned int line_offset
= line_offset_struct
.sect_off
;
5110 struct partial_symtab
*pst
;
5113 /* Give the symtab a useful name for debug purposes. */
5114 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5115 name
= xstrprintf ("<type_units_%d>",
5116 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5118 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5120 pst
= create_partial_symtab (per_cu
, name
);
5126 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5127 tu_group
->hash
.line_offset
= line_offset_struct
;
5132 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5133 STMT_LIST is a DW_AT_stmt_list attribute. */
5135 static struct type_unit_group
*
5136 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
5138 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5139 struct type_unit_group
*tu_group
;
5141 unsigned int line_offset
;
5142 struct type_unit_group type_unit_group_for_lookup
;
5144 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5146 dwarf2_per_objfile
->type_unit_groups
=
5147 allocate_type_unit_groups_table ();
5150 /* Do we need to create a new group, or can we use an existing one? */
5154 line_offset
= DW_UNSND (stmt_list
);
5155 ++tu_stats
->nr_symtab_sharers
;
5159 /* Ugh, no stmt_list. Rare, but we have to handle it.
5160 We can do various things here like create one group per TU or
5161 spread them over multiple groups to split up the expansion work.
5162 To avoid worst case scenarios (too many groups or too large groups)
5163 we, umm, group them in bunches. */
5164 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5165 | (tu_stats
->nr_stmt_less_type_units
5166 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5167 ++tu_stats
->nr_stmt_less_type_units
;
5170 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5171 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5172 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5173 &type_unit_group_for_lookup
, INSERT
);
5177 gdb_assert (tu_group
!= NULL
);
5181 sect_offset line_offset_struct
;
5183 line_offset_struct
.sect_off
= line_offset
;
5184 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5186 ++tu_stats
->nr_symtabs
;
5192 /* Struct used to sort TUs by their abbreviation table offset. */
5194 struct tu_abbrev_offset
5196 struct signatured_type
*sig_type
;
5197 sect_offset abbrev_offset
;
5200 /* Helper routine for build_type_unit_groups, passed to qsort. */
5203 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
5205 const struct tu_abbrev_offset
* const *a
= ap
;
5206 const struct tu_abbrev_offset
* const *b
= bp
;
5207 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
5208 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
5210 return (aoff
> boff
) - (aoff
< boff
);
5213 /* A helper function to add a type_unit_group to a table. */
5216 add_type_unit_group_to_table (void **slot
, void *datum
)
5218 struct type_unit_group
*tu_group
= *slot
;
5219 struct type_unit_group
***datap
= datum
;
5227 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5228 each one passing FUNC,DATA.
5230 The efficiency is because we sort TUs by the abbrev table they use and
5231 only read each abbrev table once. In one program there are 200K TUs
5232 sharing 8K abbrev tables.
5234 The main purpose of this function is to support building the
5235 dwarf2_per_objfile->type_unit_groups table.
5236 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5237 can collapse the search space by grouping them by stmt_list.
5238 The savings can be significant, in the same program from above the 200K TUs
5239 share 8K stmt_list tables.
5241 FUNC is expected to call get_type_unit_group, which will create the
5242 struct type_unit_group if necessary and add it to
5243 dwarf2_per_objfile->type_unit_groups. */
5246 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
5248 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5249 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5250 struct cleanup
*cleanups
;
5251 struct abbrev_table
*abbrev_table
;
5252 sect_offset abbrev_offset
;
5253 struct tu_abbrev_offset
*sorted_by_abbrev
;
5254 struct type_unit_group
**iter
;
5257 /* It's up to the caller to not call us multiple times. */
5258 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
5260 if (dwarf2_per_objfile
->n_type_units
== 0)
5263 /* TUs typically share abbrev tables, and there can be way more TUs than
5264 abbrev tables. Sort by abbrev table to reduce the number of times we
5265 read each abbrev table in.
5266 Alternatives are to punt or to maintain a cache of abbrev tables.
5267 This is simpler and efficient enough for now.
5269 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5270 symtab to use). Typically TUs with the same abbrev offset have the same
5271 stmt_list value too so in practice this should work well.
5273 The basic algorithm here is:
5275 sort TUs by abbrev table
5276 for each TU with same abbrev table:
5277 read abbrev table if first user
5278 read TU top level DIE
5279 [IWBN if DWO skeletons had DW_AT_stmt_list]
5282 if (dwarf2_read_debug
)
5283 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5285 /* Sort in a separate table to maintain the order of all_type_units
5286 for .gdb_index: TU indices directly index all_type_units. */
5287 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5288 dwarf2_per_objfile
->n_type_units
);
5289 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5291 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5293 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5294 sorted_by_abbrev
[i
].abbrev_offset
=
5295 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
5296 sig_type
->per_cu
.offset
);
5298 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5299 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5300 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5302 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5303 called any number of times, so we don't reset tu_stats here. */
5305 abbrev_offset
.sect_off
= ~(unsigned) 0;
5306 abbrev_table
= NULL
;
5307 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5309 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5311 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5313 /* Switch to the next abbrev table if necessary. */
5314 if (abbrev_table
== NULL
5315 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5317 if (abbrev_table
!= NULL
)
5319 abbrev_table_free (abbrev_table
);
5320 /* Reset to NULL in case abbrev_table_read_table throws
5321 an error: abbrev_table_free_cleanup will get called. */
5322 abbrev_table
= NULL
;
5324 abbrev_offset
= tu
->abbrev_offset
;
5326 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5328 ++tu_stats
->nr_uniq_abbrev_tables
;
5331 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5335 /* Create a vector of pointers to primary type units to make it easy to
5336 iterate over them and CUs. See dw2_get_primary_cu. */
5337 dwarf2_per_objfile
->n_type_unit_groups
=
5338 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5339 dwarf2_per_objfile
->all_type_unit_groups
=
5340 obstack_alloc (&objfile
->objfile_obstack
,
5341 dwarf2_per_objfile
->n_type_unit_groups
5342 * sizeof (struct type_unit_group
*));
5343 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5344 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5345 add_type_unit_group_to_table
, &iter
);
5346 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5347 == dwarf2_per_objfile
->n_type_unit_groups
);
5349 do_cleanups (cleanups
);
5351 if (dwarf2_read_debug
)
5353 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5354 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5355 dwarf2_per_objfile
->n_type_units
);
5356 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5357 tu_stats
->nr_uniq_abbrev_tables
);
5358 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5359 tu_stats
->nr_symtabs
);
5360 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5361 tu_stats
->nr_symtab_sharers
);
5362 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5363 tu_stats
->nr_stmt_less_type_units
);
5367 /* Reader function for build_type_psymtabs. */
5370 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5372 struct die_info
*type_unit_die
,
5376 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5377 struct dwarf2_cu
*cu
= reader
->cu
;
5378 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5379 struct type_unit_group
*tu_group
;
5380 struct attribute
*attr
;
5381 struct partial_die_info
*first_die
;
5382 CORE_ADDR lowpc
, highpc
;
5383 struct partial_symtab
*pst
;
5385 gdb_assert (data
== NULL
);
5390 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5391 tu_group
= get_type_unit_group (cu
, attr
);
5393 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, per_cu
);
5395 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5396 cu
->list_in_scope
= &file_symbols
;
5397 pst
= create_partial_symtab (per_cu
, "");
5400 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5402 lowpc
= (CORE_ADDR
) -1;
5403 highpc
= (CORE_ADDR
) 0;
5404 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5406 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5407 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5408 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5409 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5410 sort_pst_symbols (objfile
, pst
);
5413 /* Traversal function for build_type_psymtabs. */
5416 build_type_psymtab_dependencies (void **slot
, void *info
)
5418 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5419 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5420 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5421 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5422 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5423 struct dwarf2_per_cu_data
*iter
;
5426 gdb_assert (len
> 0);
5428 pst
->number_of_dependencies
= len
;
5429 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5430 len
* sizeof (struct psymtab
*));
5432 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, i
, iter
);
5435 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5436 iter
->s
.type_unit_group
= tu_group
;
5439 VEC_free (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5444 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5445 Build partial symbol tables for the .debug_types comp-units. */
5448 build_type_psymtabs (struct objfile
*objfile
)
5450 if (! create_all_type_units (objfile
))
5453 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5455 /* Now that all TUs have been processed we can fill in the dependencies. */
5456 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5457 build_type_psymtab_dependencies
, NULL
);
5460 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5463 psymtabs_addrmap_cleanup (void *o
)
5465 struct objfile
*objfile
= o
;
5467 objfile
->psymtabs_addrmap
= NULL
;
5470 /* Compute the 'user' field for each psymtab in OBJFILE. */
5473 set_partial_user (struct objfile
*objfile
)
5477 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5479 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5480 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5486 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5488 /* Set the 'user' field only if it is not already set. */
5489 if (pst
->dependencies
[j
]->user
== NULL
)
5490 pst
->dependencies
[j
]->user
= pst
;
5495 /* Build the partial symbol table by doing a quick pass through the
5496 .debug_info and .debug_abbrev sections. */
5499 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5501 struct cleanup
*back_to
, *addrmap_cleanup
;
5502 struct obstack temp_obstack
;
5505 if (dwarf2_read_debug
)
5507 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5511 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5513 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5515 /* Any cached compilation units will be linked by the per-objfile
5516 read_in_chain. Make sure to free them when we're done. */
5517 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5519 build_type_psymtabs (objfile
);
5521 create_all_comp_units (objfile
);
5523 /* Create a temporary address map on a temporary obstack. We later
5524 copy this to the final obstack. */
5525 obstack_init (&temp_obstack
);
5526 make_cleanup_obstack_free (&temp_obstack
);
5527 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5528 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5530 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5532 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5534 process_psymtab_comp_unit (per_cu
, 0);
5537 set_partial_user (objfile
);
5539 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5540 &objfile
->objfile_obstack
);
5541 discard_cleanups (addrmap_cleanup
);
5543 do_cleanups (back_to
);
5545 if (dwarf2_read_debug
)
5546 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5550 /* die_reader_func for load_partial_comp_unit. */
5553 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5555 struct die_info
*comp_unit_die
,
5559 struct dwarf2_cu
*cu
= reader
->cu
;
5561 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5563 /* Check if comp unit has_children.
5564 If so, read the rest of the partial symbols from this comp unit.
5565 If not, there's no more debug_info for this comp unit. */
5567 load_partial_dies (reader
, info_ptr
, 0);
5570 /* Load the partial DIEs for a secondary CU into memory.
5571 This is also used when rereading a primary CU with load_all_dies. */
5574 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5576 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5577 load_partial_comp_unit_reader
, NULL
);
5581 read_comp_units_from_section (struct objfile
*objfile
,
5582 struct dwarf2_section_info
*section
,
5583 unsigned int is_dwz
,
5586 struct dwarf2_per_cu_data
***all_comp_units
)
5589 bfd
*abfd
= section
->asection
->owner
;
5591 dwarf2_read_section (objfile
, section
);
5593 info_ptr
= section
->buffer
;
5595 while (info_ptr
< section
->buffer
+ section
->size
)
5597 unsigned int length
, initial_length_size
;
5598 struct dwarf2_per_cu_data
*this_cu
;
5601 offset
.sect_off
= info_ptr
- section
->buffer
;
5603 /* Read just enough information to find out where the next
5604 compilation unit is. */
5605 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5607 /* Save the compilation unit for later lookup. */
5608 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5609 sizeof (struct dwarf2_per_cu_data
));
5610 memset (this_cu
, 0, sizeof (*this_cu
));
5611 this_cu
->offset
= offset
;
5612 this_cu
->length
= length
+ initial_length_size
;
5613 this_cu
->is_dwz
= is_dwz
;
5614 this_cu
->objfile
= objfile
;
5615 this_cu
->info_or_types_section
= section
;
5617 if (*n_comp_units
== *n_allocated
)
5620 *all_comp_units
= xrealloc (*all_comp_units
,
5622 * sizeof (struct dwarf2_per_cu_data
*));
5624 (*all_comp_units
)[*n_comp_units
] = this_cu
;
5627 info_ptr
= info_ptr
+ this_cu
->length
;
5631 /* Create a list of all compilation units in OBJFILE.
5632 This is only done for -readnow and building partial symtabs. */
5635 create_all_comp_units (struct objfile
*objfile
)
5639 struct dwarf2_per_cu_data
**all_comp_units
;
5643 all_comp_units
= xmalloc (n_allocated
5644 * sizeof (struct dwarf2_per_cu_data
*));
5646 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
5647 &n_allocated
, &n_comp_units
, &all_comp_units
);
5649 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
5651 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
5653 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
5654 &n_allocated
, &n_comp_units
,
5658 dwarf2_per_objfile
->all_comp_units
5659 = obstack_alloc (&objfile
->objfile_obstack
,
5660 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5661 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5662 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5663 xfree (all_comp_units
);
5664 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5667 /* Process all loaded DIEs for compilation unit CU, starting at
5668 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5669 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5670 DW_AT_ranges). If NEED_PC is set, then this function will set
5671 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5672 and record the covered ranges in the addrmap. */
5675 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5676 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5678 struct partial_die_info
*pdi
;
5680 /* Now, march along the PDI's, descending into ones which have
5681 interesting children but skipping the children of the other ones,
5682 until we reach the end of the compilation unit. */
5688 fixup_partial_die (pdi
, cu
);
5690 /* Anonymous namespaces or modules have no name but have interesting
5691 children, so we need to look at them. Ditto for anonymous
5694 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5695 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5696 || pdi
->tag
== DW_TAG_imported_unit
)
5700 case DW_TAG_subprogram
:
5701 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5703 case DW_TAG_constant
:
5704 case DW_TAG_variable
:
5705 case DW_TAG_typedef
:
5706 case DW_TAG_union_type
:
5707 if (!pdi
->is_declaration
)
5709 add_partial_symbol (pdi
, cu
);
5712 case DW_TAG_class_type
:
5713 case DW_TAG_interface_type
:
5714 case DW_TAG_structure_type
:
5715 if (!pdi
->is_declaration
)
5717 add_partial_symbol (pdi
, cu
);
5720 case DW_TAG_enumeration_type
:
5721 if (!pdi
->is_declaration
)
5722 add_partial_enumeration (pdi
, cu
);
5724 case DW_TAG_base_type
:
5725 case DW_TAG_subrange_type
:
5726 /* File scope base type definitions are added to the partial
5728 add_partial_symbol (pdi
, cu
);
5730 case DW_TAG_namespace
:
5731 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5734 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5736 case DW_TAG_imported_unit
:
5738 struct dwarf2_per_cu_data
*per_cu
;
5740 /* For now we don't handle imported units in type units. */
5741 if (cu
->per_cu
->is_debug_types
)
5743 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5744 " supported in type units [in module %s]"),
5748 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5752 /* Go read the partial unit, if needed. */
5753 if (per_cu
->v
.psymtab
== NULL
)
5754 process_psymtab_comp_unit (per_cu
, 1);
5756 VEC_safe_push (dwarf2_per_cu_ptr
,
5757 cu
->per_cu
->s
.imported_symtabs
, per_cu
);
5765 /* If the die has a sibling, skip to the sibling. */
5767 pdi
= pdi
->die_sibling
;
5771 /* Functions used to compute the fully scoped name of a partial DIE.
5773 Normally, this is simple. For C++, the parent DIE's fully scoped
5774 name is concatenated with "::" and the partial DIE's name. For
5775 Java, the same thing occurs except that "." is used instead of "::".
5776 Enumerators are an exception; they use the scope of their parent
5777 enumeration type, i.e. the name of the enumeration type is not
5778 prepended to the enumerator.
5780 There are two complexities. One is DW_AT_specification; in this
5781 case "parent" means the parent of the target of the specification,
5782 instead of the direct parent of the DIE. The other is compilers
5783 which do not emit DW_TAG_namespace; in this case we try to guess
5784 the fully qualified name of structure types from their members'
5785 linkage names. This must be done using the DIE's children rather
5786 than the children of any DW_AT_specification target. We only need
5787 to do this for structures at the top level, i.e. if the target of
5788 any DW_AT_specification (if any; otherwise the DIE itself) does not
5791 /* Compute the scope prefix associated with PDI's parent, in
5792 compilation unit CU. The result will be allocated on CU's
5793 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5794 field. NULL is returned if no prefix is necessary. */
5796 partial_die_parent_scope (struct partial_die_info
*pdi
,
5797 struct dwarf2_cu
*cu
)
5799 char *grandparent_scope
;
5800 struct partial_die_info
*parent
, *real_pdi
;
5802 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5803 then this means the parent of the specification DIE. */
5806 while (real_pdi
->has_specification
)
5807 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
5808 real_pdi
->spec_is_dwz
, cu
);
5810 parent
= real_pdi
->die_parent
;
5814 if (parent
->scope_set
)
5815 return parent
->scope
;
5817 fixup_partial_die (parent
, cu
);
5819 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5821 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5822 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5823 Work around this problem here. */
5824 if (cu
->language
== language_cplus
5825 && parent
->tag
== DW_TAG_namespace
5826 && strcmp (parent
->name
, "::") == 0
5827 && grandparent_scope
== NULL
)
5829 parent
->scope
= NULL
;
5830 parent
->scope_set
= 1;
5834 if (pdi
->tag
== DW_TAG_enumerator
)
5835 /* Enumerators should not get the name of the enumeration as a prefix. */
5836 parent
->scope
= grandparent_scope
;
5837 else if (parent
->tag
== DW_TAG_namespace
5838 || parent
->tag
== DW_TAG_module
5839 || parent
->tag
== DW_TAG_structure_type
5840 || parent
->tag
== DW_TAG_class_type
5841 || parent
->tag
== DW_TAG_interface_type
5842 || parent
->tag
== DW_TAG_union_type
5843 || parent
->tag
== DW_TAG_enumeration_type
)
5845 if (grandparent_scope
== NULL
)
5846 parent
->scope
= parent
->name
;
5848 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5850 parent
->name
, 0, cu
);
5854 /* FIXME drow/2004-04-01: What should we be doing with
5855 function-local names? For partial symbols, we should probably be
5857 complaint (&symfile_complaints
,
5858 _("unhandled containing DIE tag %d for DIE at %d"),
5859 parent
->tag
, pdi
->offset
.sect_off
);
5860 parent
->scope
= grandparent_scope
;
5863 parent
->scope_set
= 1;
5864 return parent
->scope
;
5867 /* Return the fully scoped name associated with PDI, from compilation unit
5868 CU. The result will be allocated with malloc. */
5871 partial_die_full_name (struct partial_die_info
*pdi
,
5872 struct dwarf2_cu
*cu
)
5876 /* If this is a template instantiation, we can not work out the
5877 template arguments from partial DIEs. So, unfortunately, we have
5878 to go through the full DIEs. At least any work we do building
5879 types here will be reused if full symbols are loaded later. */
5880 if (pdi
->has_template_arguments
)
5882 fixup_partial_die (pdi
, cu
);
5884 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5886 struct die_info
*die
;
5887 struct attribute attr
;
5888 struct dwarf2_cu
*ref_cu
= cu
;
5890 /* DW_FORM_ref_addr is using section offset. */
5892 attr
.form
= DW_FORM_ref_addr
;
5893 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5894 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5896 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5900 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5901 if (parent_scope
== NULL
)
5904 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5908 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5910 struct objfile
*objfile
= cu
->objfile
;
5912 char *actual_name
= NULL
;
5914 int built_actual_name
= 0;
5916 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5918 actual_name
= partial_die_full_name (pdi
, cu
);
5920 built_actual_name
= 1;
5922 if (actual_name
== NULL
)
5923 actual_name
= pdi
->name
;
5927 case DW_TAG_subprogram
:
5928 if (pdi
->is_external
|| cu
->language
== language_ada
)
5930 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5931 of the global scope. But in Ada, we want to be able to access
5932 nested procedures globally. So all Ada subprograms are stored
5933 in the global scope. */
5934 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5935 mst_text, objfile); */
5936 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5938 VAR_DOMAIN
, LOC_BLOCK
,
5939 &objfile
->global_psymbols
,
5940 0, pdi
->lowpc
+ baseaddr
,
5941 cu
->language
, objfile
);
5945 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5946 mst_file_text, objfile); */
5947 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5949 VAR_DOMAIN
, LOC_BLOCK
,
5950 &objfile
->static_psymbols
,
5951 0, pdi
->lowpc
+ baseaddr
,
5952 cu
->language
, objfile
);
5955 case DW_TAG_constant
:
5957 struct psymbol_allocation_list
*list
;
5959 if (pdi
->is_external
)
5960 list
= &objfile
->global_psymbols
;
5962 list
= &objfile
->static_psymbols
;
5963 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5964 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
5965 list
, 0, 0, cu
->language
, objfile
);
5968 case DW_TAG_variable
:
5970 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5974 && !dwarf2_per_objfile
->has_section_at_zero
)
5976 /* A global or static variable may also have been stripped
5977 out by the linker if unused, in which case its address
5978 will be nullified; do not add such variables into partial
5979 symbol table then. */
5981 else if (pdi
->is_external
)
5984 Don't enter into the minimal symbol tables as there is
5985 a minimal symbol table entry from the ELF symbols already.
5986 Enter into partial symbol table if it has a location
5987 descriptor or a type.
5988 If the location descriptor is missing, new_symbol will create
5989 a LOC_UNRESOLVED symbol, the address of the variable will then
5990 be determined from the minimal symbol table whenever the variable
5992 The address for the partial symbol table entry is not
5993 used by GDB, but it comes in handy for debugging partial symbol
5996 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5997 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5999 VAR_DOMAIN
, LOC_STATIC
,
6000 &objfile
->global_psymbols
,
6002 cu
->language
, objfile
);
6006 /* Static Variable. Skip symbols without location descriptors. */
6007 if (pdi
->d
.locdesc
== NULL
)
6009 if (built_actual_name
)
6010 xfree (actual_name
);
6013 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
6014 mst_file_data, objfile); */
6015 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6017 VAR_DOMAIN
, LOC_STATIC
,
6018 &objfile
->static_psymbols
,
6020 cu
->language
, objfile
);
6023 case DW_TAG_typedef
:
6024 case DW_TAG_base_type
:
6025 case DW_TAG_subrange_type
:
6026 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6028 VAR_DOMAIN
, LOC_TYPEDEF
,
6029 &objfile
->static_psymbols
,
6030 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6032 case DW_TAG_namespace
:
6033 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6035 VAR_DOMAIN
, LOC_TYPEDEF
,
6036 &objfile
->global_psymbols
,
6037 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6039 case DW_TAG_class_type
:
6040 case DW_TAG_interface_type
:
6041 case DW_TAG_structure_type
:
6042 case DW_TAG_union_type
:
6043 case DW_TAG_enumeration_type
:
6044 /* Skip external references. The DWARF standard says in the section
6045 about "Structure, Union, and Class Type Entries": "An incomplete
6046 structure, union or class type is represented by a structure,
6047 union or class entry that does not have a byte size attribute
6048 and that has a DW_AT_declaration attribute." */
6049 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
6051 if (built_actual_name
)
6052 xfree (actual_name
);
6056 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
6057 static vs. global. */
6058 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6060 STRUCT_DOMAIN
, LOC_TYPEDEF
,
6061 (cu
->language
== language_cplus
6062 || cu
->language
== language_java
)
6063 ? &objfile
->global_psymbols
6064 : &objfile
->static_psymbols
,
6065 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6068 case DW_TAG_enumerator
:
6069 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6071 VAR_DOMAIN
, LOC_CONST
,
6072 (cu
->language
== language_cplus
6073 || cu
->language
== language_java
)
6074 ? &objfile
->global_psymbols
6075 : &objfile
->static_psymbols
,
6076 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6082 if (built_actual_name
)
6083 xfree (actual_name
);
6086 /* Read a partial die corresponding to a namespace; also, add a symbol
6087 corresponding to that namespace to the symbol table. NAMESPACE is
6088 the name of the enclosing namespace. */
6091 add_partial_namespace (struct partial_die_info
*pdi
,
6092 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6093 int need_pc
, struct dwarf2_cu
*cu
)
6095 /* Add a symbol for the namespace. */
6097 add_partial_symbol (pdi
, cu
);
6099 /* Now scan partial symbols in that namespace. */
6101 if (pdi
->has_children
)
6102 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6105 /* Read a partial die corresponding to a Fortran module. */
6108 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
6109 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
6111 /* Now scan partial symbols in that module. */
6113 if (pdi
->has_children
)
6114 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6117 /* Read a partial die corresponding to a subprogram and create a partial
6118 symbol for that subprogram. When the CU language allows it, this
6119 routine also defines a partial symbol for each nested subprogram
6120 that this subprogram contains.
6122 DIE my also be a lexical block, in which case we simply search
6123 recursively for suprograms defined inside that lexical block.
6124 Again, this is only performed when the CU language allows this
6125 type of definitions. */
6128 add_partial_subprogram (struct partial_die_info
*pdi
,
6129 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6130 int need_pc
, struct dwarf2_cu
*cu
)
6132 if (pdi
->tag
== DW_TAG_subprogram
)
6134 if (pdi
->has_pc_info
)
6136 if (pdi
->lowpc
< *lowpc
)
6137 *lowpc
= pdi
->lowpc
;
6138 if (pdi
->highpc
> *highpc
)
6139 *highpc
= pdi
->highpc
;
6143 struct objfile
*objfile
= cu
->objfile
;
6145 baseaddr
= ANOFFSET (objfile
->section_offsets
,
6146 SECT_OFF_TEXT (objfile
));
6147 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6148 pdi
->lowpc
+ baseaddr
,
6149 pdi
->highpc
- 1 + baseaddr
,
6150 cu
->per_cu
->v
.psymtab
);
6154 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
6156 if (!pdi
->is_declaration
)
6157 /* Ignore subprogram DIEs that do not have a name, they are
6158 illegal. Do not emit a complaint at this point, we will
6159 do so when we convert this psymtab into a symtab. */
6161 add_partial_symbol (pdi
, cu
);
6165 if (! pdi
->has_children
)
6168 if (cu
->language
== language_ada
)
6170 pdi
= pdi
->die_child
;
6173 fixup_partial_die (pdi
, cu
);
6174 if (pdi
->tag
== DW_TAG_subprogram
6175 || pdi
->tag
== DW_TAG_lexical_block
)
6176 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6177 pdi
= pdi
->die_sibling
;
6182 /* Read a partial die corresponding to an enumeration type. */
6185 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
6186 struct dwarf2_cu
*cu
)
6188 struct partial_die_info
*pdi
;
6190 if (enum_pdi
->name
!= NULL
)
6191 add_partial_symbol (enum_pdi
, cu
);
6193 pdi
= enum_pdi
->die_child
;
6196 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
6197 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6199 add_partial_symbol (pdi
, cu
);
6200 pdi
= pdi
->die_sibling
;
6204 /* Return the initial uleb128 in the die at INFO_PTR. */
6207 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
6209 unsigned int bytes_read
;
6211 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6214 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6215 Return the corresponding abbrev, or NULL if the number is zero (indicating
6216 an empty DIE). In either case *BYTES_READ will be set to the length of
6217 the initial number. */
6219 static struct abbrev_info
*
6220 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
6221 struct dwarf2_cu
*cu
)
6223 bfd
*abfd
= cu
->objfile
->obfd
;
6224 unsigned int abbrev_number
;
6225 struct abbrev_info
*abbrev
;
6227 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
6229 if (abbrev_number
== 0)
6232 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
6235 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6236 abbrev_number
, bfd_get_filename (abfd
));
6242 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6243 Returns a pointer to the end of a series of DIEs, terminated by an empty
6244 DIE. Any children of the skipped DIEs will also be skipped. */
6247 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
6249 struct dwarf2_cu
*cu
= reader
->cu
;
6250 struct abbrev_info
*abbrev
;
6251 unsigned int bytes_read
;
6255 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6257 return info_ptr
+ bytes_read
;
6259 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
6263 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6264 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6265 abbrev corresponding to that skipped uleb128 should be passed in
6266 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6270 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
6271 struct abbrev_info
*abbrev
)
6273 unsigned int bytes_read
;
6274 struct attribute attr
;
6275 bfd
*abfd
= reader
->abfd
;
6276 struct dwarf2_cu
*cu
= reader
->cu
;
6277 gdb_byte
*buffer
= reader
->buffer
;
6278 const gdb_byte
*buffer_end
= reader
->buffer_end
;
6279 gdb_byte
*start_info_ptr
= info_ptr
;
6280 unsigned int form
, i
;
6282 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
6284 /* The only abbrev we care about is DW_AT_sibling. */
6285 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
6287 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
6288 if (attr
.form
== DW_FORM_ref_addr
)
6289 complaint (&symfile_complaints
,
6290 _("ignoring absolute DW_AT_sibling"));
6292 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
6295 /* If it isn't DW_AT_sibling, skip this attribute. */
6296 form
= abbrev
->attrs
[i
].form
;
6300 case DW_FORM_ref_addr
:
6301 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6302 and later it is offset sized. */
6303 if (cu
->header
.version
== 2)
6304 info_ptr
+= cu
->header
.addr_size
;
6306 info_ptr
+= cu
->header
.offset_size
;
6308 case DW_FORM_GNU_ref_alt
:
6309 info_ptr
+= cu
->header
.offset_size
;
6312 info_ptr
+= cu
->header
.addr_size
;
6319 case DW_FORM_flag_present
:
6331 case DW_FORM_ref_sig8
:
6334 case DW_FORM_string
:
6335 read_direct_string (abfd
, info_ptr
, &bytes_read
);
6336 info_ptr
+= bytes_read
;
6338 case DW_FORM_sec_offset
:
6340 case DW_FORM_GNU_strp_alt
:
6341 info_ptr
+= cu
->header
.offset_size
;
6343 case DW_FORM_exprloc
:
6345 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6346 info_ptr
+= bytes_read
;
6348 case DW_FORM_block1
:
6349 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
6351 case DW_FORM_block2
:
6352 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
6354 case DW_FORM_block4
:
6355 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
6359 case DW_FORM_ref_udata
:
6360 case DW_FORM_GNU_addr_index
:
6361 case DW_FORM_GNU_str_index
:
6362 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
6364 case DW_FORM_indirect
:
6365 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6366 info_ptr
+= bytes_read
;
6367 /* We need to continue parsing from here, so just go back to
6369 goto skip_attribute
;
6372 error (_("Dwarf Error: Cannot handle %s "
6373 "in DWARF reader [in module %s]"),
6374 dwarf_form_name (form
),
6375 bfd_get_filename (abfd
));
6379 if (abbrev
->has_children
)
6380 return skip_children (reader
, info_ptr
);
6385 /* Locate ORIG_PDI's sibling.
6386 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6389 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6390 struct partial_die_info
*orig_pdi
,
6393 /* Do we know the sibling already? */
6395 if (orig_pdi
->sibling
)
6396 return orig_pdi
->sibling
;
6398 /* Are there any children to deal with? */
6400 if (!orig_pdi
->has_children
)
6403 /* Skip the children the long way. */
6405 return skip_children (reader
, info_ptr
);
6408 /* Expand this partial symbol table into a full symbol table. */
6411 dwarf2_psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
6417 warning (_("bug: psymtab for %s is already read in."),
6424 printf_filtered (_("Reading in symbols for %s..."),
6426 gdb_flush (gdb_stdout
);
6429 /* Restore our global data. */
6430 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
6432 /* If this psymtab is constructed from a debug-only objfile, the
6433 has_section_at_zero flag will not necessarily be correct. We
6434 can get the correct value for this flag by looking at the data
6435 associated with the (presumably stripped) associated objfile. */
6436 if (objfile
->separate_debug_objfile_backlink
)
6438 struct dwarf2_per_objfile
*dpo_backlink
6439 = objfile_data (objfile
->separate_debug_objfile_backlink
,
6440 dwarf2_objfile_data_key
);
6442 dwarf2_per_objfile
->has_section_at_zero
6443 = dpo_backlink
->has_section_at_zero
;
6446 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6448 psymtab_to_symtab_1 (pst
);
6450 /* Finish up the debug error message. */
6452 printf_filtered (_("done.\n"));
6456 process_cu_includes ();
6459 /* Reading in full CUs. */
6461 /* Add PER_CU to the queue. */
6464 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6465 enum language pretend_language
)
6467 struct dwarf2_queue_item
*item
;
6470 item
= xmalloc (sizeof (*item
));
6471 item
->per_cu
= per_cu
;
6472 item
->pretend_language
= pretend_language
;
6475 if (dwarf2_queue
== NULL
)
6476 dwarf2_queue
= item
;
6478 dwarf2_queue_tail
->next
= item
;
6480 dwarf2_queue_tail
= item
;
6483 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6484 unit and add it to our queue.
6485 The result is non-zero if PER_CU was queued, otherwise the result is zero
6486 meaning either PER_CU is already queued or it is already loaded. */
6489 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6490 struct dwarf2_per_cu_data
*per_cu
,
6491 enum language pretend_language
)
6493 /* We may arrive here during partial symbol reading, if we need full
6494 DIEs to process an unusual case (e.g. template arguments). Do
6495 not queue PER_CU, just tell our caller to load its DIEs. */
6496 if (dwarf2_per_objfile
->reading_partial_symbols
)
6498 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6503 /* Mark the dependence relation so that we don't flush PER_CU
6505 dwarf2_add_dependence (this_cu
, per_cu
);
6507 /* If it's already on the queue, we have nothing to do. */
6511 /* If the compilation unit is already loaded, just mark it as
6513 if (per_cu
->cu
!= NULL
)
6515 per_cu
->cu
->last_used
= 0;
6519 /* Add it to the queue. */
6520 queue_comp_unit (per_cu
, pretend_language
);
6525 /* Process the queue. */
6528 process_queue (void)
6530 struct dwarf2_queue_item
*item
, *next_item
;
6532 if (dwarf2_read_debug
)
6534 fprintf_unfiltered (gdb_stdlog
,
6535 "Expanding one or more symtabs of objfile %s ...\n",
6536 dwarf2_per_objfile
->objfile
->name
);
6539 /* The queue starts out with one item, but following a DIE reference
6540 may load a new CU, adding it to the end of the queue. */
6541 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6543 if (dwarf2_per_objfile
->using_index
6544 ? !item
->per_cu
->v
.quick
->symtab
6545 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6547 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6549 if (dwarf2_read_debug
)
6551 fprintf_unfiltered (gdb_stdlog
,
6552 "Expanding symtab of %s at offset 0x%x\n",
6553 per_cu
->is_debug_types
? "TU" : "CU",
6554 per_cu
->offset
.sect_off
);
6557 if (per_cu
->is_debug_types
)
6558 process_full_type_unit (per_cu
, item
->pretend_language
);
6560 process_full_comp_unit (per_cu
, item
->pretend_language
);
6562 if (dwarf2_read_debug
)
6564 fprintf_unfiltered (gdb_stdlog
,
6565 "Done expanding %s at offset 0x%x\n",
6566 per_cu
->is_debug_types
? "TU" : "CU",
6567 per_cu
->offset
.sect_off
);
6571 item
->per_cu
->queued
= 0;
6572 next_item
= item
->next
;
6576 dwarf2_queue_tail
= NULL
;
6578 if (dwarf2_read_debug
)
6580 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6581 dwarf2_per_objfile
->objfile
->name
);
6585 /* Free all allocated queue entries. This function only releases anything if
6586 an error was thrown; if the queue was processed then it would have been
6587 freed as we went along. */
6590 dwarf2_release_queue (void *dummy
)
6592 struct dwarf2_queue_item
*item
, *last
;
6594 item
= dwarf2_queue
;
6597 /* Anything still marked queued is likely to be in an
6598 inconsistent state, so discard it. */
6599 if (item
->per_cu
->queued
)
6601 if (item
->per_cu
->cu
!= NULL
)
6602 free_one_cached_comp_unit (item
->per_cu
);
6603 item
->per_cu
->queued
= 0;
6611 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6614 /* Read in full symbols for PST, and anything it depends on. */
6617 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6619 struct dwarf2_per_cu_data
*per_cu
;
6625 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6626 if (!pst
->dependencies
[i
]->readin
6627 && pst
->dependencies
[i
]->user
== NULL
)
6629 /* Inform about additional files that need to be read in. */
6632 /* FIXME: i18n: Need to make this a single string. */
6633 fputs_filtered (" ", gdb_stdout
);
6635 fputs_filtered ("and ", gdb_stdout
);
6637 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6638 wrap_here (""); /* Flush output. */
6639 gdb_flush (gdb_stdout
);
6641 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6644 per_cu
= pst
->read_symtab_private
;
6648 /* It's an include file, no symbols to read for it.
6649 Everything is in the parent symtab. */
6654 dw2_do_instantiate_symtab (per_cu
);
6657 /* Trivial hash function for die_info: the hash value of a DIE
6658 is its offset in .debug_info for this objfile. */
6661 die_hash (const void *item
)
6663 const struct die_info
*die
= item
;
6665 return die
->offset
.sect_off
;
6668 /* Trivial comparison function for die_info structures: two DIEs
6669 are equal if they have the same offset. */
6672 die_eq (const void *item_lhs
, const void *item_rhs
)
6674 const struct die_info
*die_lhs
= item_lhs
;
6675 const struct die_info
*die_rhs
= item_rhs
;
6677 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6680 /* die_reader_func for load_full_comp_unit.
6681 This is identical to read_signatured_type_reader,
6682 but is kept separate for now. */
6685 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6687 struct die_info
*comp_unit_die
,
6691 struct dwarf2_cu
*cu
= reader
->cu
;
6692 enum language
*language_ptr
= data
;
6694 gdb_assert (cu
->die_hash
== NULL
);
6696 htab_create_alloc_ex (cu
->header
.length
/ 12,
6700 &cu
->comp_unit_obstack
,
6701 hashtab_obstack_allocate
,
6702 dummy_obstack_deallocate
);
6705 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6706 &info_ptr
, comp_unit_die
);
6707 cu
->dies
= comp_unit_die
;
6708 /* comp_unit_die is not stored in die_hash, no need. */
6710 /* We try not to read any attributes in this function, because not
6711 all CUs needed for references have been loaded yet, and symbol
6712 table processing isn't initialized. But we have to set the CU language,
6713 or we won't be able to build types correctly.
6714 Similarly, if we do not read the producer, we can not apply
6715 producer-specific interpretation. */
6716 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6719 /* Load the DIEs associated with PER_CU into memory. */
6722 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6723 enum language pretend_language
)
6725 gdb_assert (! this_cu
->is_debug_types
);
6727 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6728 load_full_comp_unit_reader
, &pretend_language
);
6731 /* Add a DIE to the delayed physname list. */
6734 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6735 const char *name
, struct die_info
*die
,
6736 struct dwarf2_cu
*cu
)
6738 struct delayed_method_info mi
;
6740 mi
.fnfield_index
= fnfield_index
;
6744 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6747 /* A cleanup for freeing the delayed method list. */
6750 free_delayed_list (void *ptr
)
6752 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6753 if (cu
->method_list
!= NULL
)
6755 VEC_free (delayed_method_info
, cu
->method_list
);
6756 cu
->method_list
= NULL
;
6760 /* Compute the physnames of any methods on the CU's method list.
6762 The computation of method physnames is delayed in order to avoid the
6763 (bad) condition that one of the method's formal parameters is of an as yet
6767 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6770 struct delayed_method_info
*mi
;
6771 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6773 const char *physname
;
6774 struct fn_fieldlist
*fn_flp
6775 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6776 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6777 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6781 /* Go objects should be embedded in a DW_TAG_module DIE,
6782 and it's not clear if/how imported objects will appear.
6783 To keep Go support simple until that's worked out,
6784 go back through what we've read and create something usable.
6785 We could do this while processing each DIE, and feels kinda cleaner,
6786 but that way is more invasive.
6787 This is to, for example, allow the user to type "p var" or "b main"
6788 without having to specify the package name, and allow lookups
6789 of module.object to work in contexts that use the expression
6793 fixup_go_packaging (struct dwarf2_cu
*cu
)
6795 char *package_name
= NULL
;
6796 struct pending
*list
;
6799 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6801 for (i
= 0; i
< list
->nsyms
; ++i
)
6803 struct symbol
*sym
= list
->symbol
[i
];
6805 if (SYMBOL_LANGUAGE (sym
) == language_go
6806 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6808 char *this_package_name
= go_symbol_package_name (sym
);
6810 if (this_package_name
== NULL
)
6812 if (package_name
== NULL
)
6813 package_name
= this_package_name
;
6816 if (strcmp (package_name
, this_package_name
) != 0)
6817 complaint (&symfile_complaints
,
6818 _("Symtab %s has objects from two different Go packages: %s and %s"),
6819 (SYMBOL_SYMTAB (sym
)
6820 ? SYMBOL_SYMTAB (sym
)->filename
6821 : cu
->objfile
->name
),
6822 this_package_name
, package_name
);
6823 xfree (this_package_name
);
6829 if (package_name
!= NULL
)
6831 struct objfile
*objfile
= cu
->objfile
;
6832 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6833 package_name
, objfile
);
6836 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6838 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6839 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6840 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
6841 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6842 e.g., "main" finds the "main" module and not C's main(). */
6843 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6844 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6845 SYMBOL_TYPE (sym
) = type
;
6847 add_symbol_to_list (sym
, &global_symbols
);
6849 xfree (package_name
);
6853 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6855 /* Return the symtab for PER_CU. This works properly regardless of
6856 whether we're using the index or psymtabs. */
6858 static struct symtab
*
6859 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6861 return (dwarf2_per_objfile
->using_index
6862 ? per_cu
->v
.quick
->symtab
6863 : per_cu
->v
.psymtab
->symtab
);
6866 /* A helper function for computing the list of all symbol tables
6867 included by PER_CU. */
6870 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6871 htab_t all_children
,
6872 struct dwarf2_per_cu_data
*per_cu
)
6876 struct dwarf2_per_cu_data
*iter
;
6878 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6881 /* This inclusion and its children have been processed. */
6886 /* Only add a CU if it has a symbol table. */
6887 if (get_symtab (per_cu
) != NULL
)
6888 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6891 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
, ix
, iter
);
6893 recursively_compute_inclusions (result
, all_children
, iter
);
6896 /* Compute the symtab 'includes' fields for the symtab related to
6900 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6902 gdb_assert (! per_cu
->is_debug_types
);
6904 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
))
6907 struct dwarf2_per_cu_data
*iter
;
6908 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6909 htab_t all_children
;
6910 struct symtab
*symtab
= get_symtab (per_cu
);
6912 /* If we don't have a symtab, we can just skip this case. */
6916 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6917 NULL
, xcalloc
, xfree
);
6920 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
,
6923 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6925 /* Now we have a transitive closure of all the included CUs, so
6926 we can convert it to a list of symtabs. */
6927 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6929 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6930 (len
+ 1) * sizeof (struct symtab
*));
6932 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6934 symtab
->includes
[ix
] = get_symtab (iter
);
6935 symtab
->includes
[len
] = NULL
;
6937 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6938 htab_delete (all_children
);
6942 /* Compute the 'includes' field for the symtabs of all the CUs we just
6946 process_cu_includes (void)
6949 struct dwarf2_per_cu_data
*iter
;
6952 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6956 if (! iter
->is_debug_types
)
6957 compute_symtab_includes (iter
);
6960 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6963 /* Generate full symbol information for PER_CU, whose DIEs have
6964 already been loaded into memory. */
6967 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6968 enum language pretend_language
)
6970 struct dwarf2_cu
*cu
= per_cu
->cu
;
6971 struct objfile
*objfile
= per_cu
->objfile
;
6972 CORE_ADDR lowpc
, highpc
;
6973 struct symtab
*symtab
;
6974 struct cleanup
*back_to
, *delayed_list_cleanup
;
6976 struct block
*static_block
;
6978 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6981 back_to
= make_cleanup (really_free_pendings
, NULL
);
6982 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6984 cu
->list_in_scope
= &file_symbols
;
6986 cu
->language
= pretend_language
;
6987 cu
->language_defn
= language_def (cu
->language
);
6989 /* Do line number decoding in read_file_scope () */
6990 process_die (cu
->dies
, cu
);
6992 /* For now fudge the Go package. */
6993 if (cu
->language
== language_go
)
6994 fixup_go_packaging (cu
);
6996 /* Now that we have processed all the DIEs in the CU, all the types
6997 should be complete, and it should now be safe to compute all of the
6999 compute_delayed_physnames (cu
);
7000 do_cleanups (delayed_list_cleanup
);
7002 /* Some compilers don't define a DW_AT_high_pc attribute for the
7003 compilation unit. If the DW_AT_high_pc is missing, synthesize
7004 it, by scanning the DIE's below the compilation unit. */
7005 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
7008 = end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0,
7009 per_cu
->s
.imported_symtabs
!= NULL
);
7011 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
7012 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
7013 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
7014 addrmap to help ensure it has an accurate map of pc values belonging to
7016 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
7018 symtab
= end_symtab_from_static_block (static_block
, objfile
,
7019 SECT_OFF_TEXT (objfile
), 0);
7023 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
7025 /* Set symtab language to language from DW_AT_language. If the
7026 compilation is from a C file generated by language preprocessors, do
7027 not set the language if it was already deduced by start_subfile. */
7028 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7029 symtab
->language
= cu
->language
;
7031 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
7032 produce DW_AT_location with location lists but it can be possibly
7033 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
7034 there were bugs in prologue debug info, fixed later in GCC-4.5
7035 by "unwind info for epilogues" patch (which is not directly related).
7037 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
7038 needed, it would be wrong due to missing DW_AT_producer there.
7040 Still one can confuse GDB by using non-standard GCC compilation
7041 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
7043 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
7044 symtab
->locations_valid
= 1;
7046 if (gcc_4_minor
>= 5)
7047 symtab
->epilogue_unwind_valid
= 1;
7049 symtab
->call_site_htab
= cu
->call_site_htab
;
7052 if (dwarf2_per_objfile
->using_index
)
7053 per_cu
->v
.quick
->symtab
= symtab
;
7056 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7057 pst
->symtab
= symtab
;
7061 /* Push it for inclusion processing later. */
7062 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
7064 do_cleanups (back_to
);
7067 /* Generate full symbol information for type unit PER_CU, whose DIEs have
7068 already been loaded into memory. */
7071 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
7072 enum language pretend_language
)
7074 struct dwarf2_cu
*cu
= per_cu
->cu
;
7075 struct objfile
*objfile
= per_cu
->objfile
;
7076 struct symtab
*symtab
;
7077 struct cleanup
*back_to
, *delayed_list_cleanup
;
7080 back_to
= make_cleanup (really_free_pendings
, NULL
);
7081 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
7083 cu
->list_in_scope
= &file_symbols
;
7085 cu
->language
= pretend_language
;
7086 cu
->language_defn
= language_def (cu
->language
);
7088 /* The symbol tables are set up in read_type_unit_scope. */
7089 process_die (cu
->dies
, cu
);
7091 /* For now fudge the Go package. */
7092 if (cu
->language
== language_go
)
7093 fixup_go_packaging (cu
);
7095 /* Now that we have processed all the DIEs in the CU, all the types
7096 should be complete, and it should now be safe to compute all of the
7098 compute_delayed_physnames (cu
);
7099 do_cleanups (delayed_list_cleanup
);
7101 /* TUs share symbol tables.
7102 If this is the first TU to use this symtab, complete the construction
7103 of it with end_expandable_symtab. Otherwise, complete the addition of
7104 this TU's symbols to the existing symtab. */
7105 if (per_cu
->s
.type_unit_group
->primary_symtab
== NULL
)
7107 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
7108 per_cu
->s
.type_unit_group
->primary_symtab
= symtab
;
7112 /* Set symtab language to language from DW_AT_language. If the
7113 compilation is from a C file generated by language preprocessors,
7114 do not set the language if it was already deduced by
7116 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7117 symtab
->language
= cu
->language
;
7122 augment_type_symtab (objfile
,
7123 per_cu
->s
.type_unit_group
->primary_symtab
);
7124 symtab
= per_cu
->s
.type_unit_group
->primary_symtab
;
7127 if (dwarf2_per_objfile
->using_index
)
7128 per_cu
->v
.quick
->symtab
= symtab
;
7131 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7132 pst
->symtab
= symtab
;
7136 do_cleanups (back_to
);
7139 /* Process an imported unit DIE. */
7142 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7144 struct attribute
*attr
;
7146 /* For now we don't handle imported units in type units. */
7147 if (cu
->per_cu
->is_debug_types
)
7149 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7150 " supported in type units [in module %s]"),
7154 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7157 struct dwarf2_per_cu_data
*per_cu
;
7158 struct symtab
*imported_symtab
;
7162 offset
= dwarf2_get_ref_die_offset (attr
);
7163 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
7164 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
7166 /* Queue the unit, if needed. */
7167 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
7168 load_full_comp_unit (per_cu
, cu
->language
);
7170 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
7175 /* Process a die and its children. */
7178 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7182 case DW_TAG_padding
:
7184 case DW_TAG_compile_unit
:
7185 case DW_TAG_partial_unit
:
7186 read_file_scope (die
, cu
);
7188 case DW_TAG_type_unit
:
7189 read_type_unit_scope (die
, cu
);
7191 case DW_TAG_subprogram
:
7192 case DW_TAG_inlined_subroutine
:
7193 read_func_scope (die
, cu
);
7195 case DW_TAG_lexical_block
:
7196 case DW_TAG_try_block
:
7197 case DW_TAG_catch_block
:
7198 read_lexical_block_scope (die
, cu
);
7200 case DW_TAG_GNU_call_site
:
7201 read_call_site_scope (die
, cu
);
7203 case DW_TAG_class_type
:
7204 case DW_TAG_interface_type
:
7205 case DW_TAG_structure_type
:
7206 case DW_TAG_union_type
:
7207 process_structure_scope (die
, cu
);
7209 case DW_TAG_enumeration_type
:
7210 process_enumeration_scope (die
, cu
);
7213 /* These dies have a type, but processing them does not create
7214 a symbol or recurse to process the children. Therefore we can
7215 read them on-demand through read_type_die. */
7216 case DW_TAG_subroutine_type
:
7217 case DW_TAG_set_type
:
7218 case DW_TAG_array_type
:
7219 case DW_TAG_pointer_type
:
7220 case DW_TAG_ptr_to_member_type
:
7221 case DW_TAG_reference_type
:
7222 case DW_TAG_string_type
:
7225 case DW_TAG_base_type
:
7226 case DW_TAG_subrange_type
:
7227 case DW_TAG_typedef
:
7228 /* Add a typedef symbol for the type definition, if it has a
7230 new_symbol (die
, read_type_die (die
, cu
), cu
);
7232 case DW_TAG_common_block
:
7233 read_common_block (die
, cu
);
7235 case DW_TAG_common_inclusion
:
7237 case DW_TAG_namespace
:
7238 processing_has_namespace_info
= 1;
7239 read_namespace (die
, cu
);
7242 processing_has_namespace_info
= 1;
7243 read_module (die
, cu
);
7245 case DW_TAG_imported_declaration
:
7246 case DW_TAG_imported_module
:
7247 processing_has_namespace_info
= 1;
7248 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
7249 || cu
->language
!= language_fortran
))
7250 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
7251 dwarf_tag_name (die
->tag
));
7252 read_import_statement (die
, cu
);
7255 case DW_TAG_imported_unit
:
7256 process_imported_unit_die (die
, cu
);
7260 new_symbol (die
, NULL
, cu
);
7265 /* A helper function for dwarf2_compute_name which determines whether DIE
7266 needs to have the name of the scope prepended to the name listed in the
7270 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7272 struct attribute
*attr
;
7276 case DW_TAG_namespace
:
7277 case DW_TAG_typedef
:
7278 case DW_TAG_class_type
:
7279 case DW_TAG_interface_type
:
7280 case DW_TAG_structure_type
:
7281 case DW_TAG_union_type
:
7282 case DW_TAG_enumeration_type
:
7283 case DW_TAG_enumerator
:
7284 case DW_TAG_subprogram
:
7288 case DW_TAG_variable
:
7289 case DW_TAG_constant
:
7290 /* We only need to prefix "globally" visible variables. These include
7291 any variable marked with DW_AT_external or any variable that
7292 lives in a namespace. [Variables in anonymous namespaces
7293 require prefixing, but they are not DW_AT_external.] */
7295 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
7297 struct dwarf2_cu
*spec_cu
= cu
;
7299 return die_needs_namespace (die_specification (die
, &spec_cu
),
7303 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7304 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
7305 && die
->parent
->tag
!= DW_TAG_module
)
7307 /* A variable in a lexical block of some kind does not need a
7308 namespace, even though in C++ such variables may be external
7309 and have a mangled name. */
7310 if (die
->parent
->tag
== DW_TAG_lexical_block
7311 || die
->parent
->tag
== DW_TAG_try_block
7312 || die
->parent
->tag
== DW_TAG_catch_block
7313 || die
->parent
->tag
== DW_TAG_subprogram
)
7322 /* Retrieve the last character from a mem_file. */
7325 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
7327 char *last_char_p
= (char *) object
;
7330 *last_char_p
= buffer
[length
- 1];
7333 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7334 compute the physname for the object, which include a method's:
7335 - formal parameters (C++/Java),
7336 - receiver type (Go),
7337 - return type (Java).
7339 The term "physname" is a bit confusing.
7340 For C++, for example, it is the demangled name.
7341 For Go, for example, it's the mangled name.
7343 For Ada, return the DIE's linkage name rather than the fully qualified
7344 name. PHYSNAME is ignored..
7346 The result is allocated on the objfile_obstack and canonicalized. */
7349 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
7352 struct objfile
*objfile
= cu
->objfile
;
7355 name
= dwarf2_name (die
, cu
);
7357 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7358 compute it by typename_concat inside GDB. */
7359 if (cu
->language
== language_ada
7360 || (cu
->language
== language_fortran
&& physname
))
7362 /* For Ada unit, we prefer the linkage name over the name, as
7363 the former contains the exported name, which the user expects
7364 to be able to reference. Ideally, we want the user to be able
7365 to reference this entity using either natural or linkage name,
7366 but we haven't started looking at this enhancement yet. */
7367 struct attribute
*attr
;
7369 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7371 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7372 if (attr
&& DW_STRING (attr
))
7373 return DW_STRING (attr
);
7376 /* These are the only languages we know how to qualify names in. */
7378 && (cu
->language
== language_cplus
|| cu
->language
== language_java
7379 || cu
->language
== language_fortran
))
7381 if (die_needs_namespace (die
, cu
))
7385 struct ui_file
*buf
;
7387 prefix
= determine_prefix (die
, cu
);
7388 buf
= mem_fileopen ();
7389 if (*prefix
!= '\0')
7391 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7394 fputs_unfiltered (prefixed_name
, buf
);
7395 xfree (prefixed_name
);
7398 fputs_unfiltered (name
, buf
);
7400 /* Template parameters may be specified in the DIE's DW_AT_name, or
7401 as children with DW_TAG_template_type_param or
7402 DW_TAG_value_type_param. If the latter, add them to the name
7403 here. If the name already has template parameters, then
7404 skip this step; some versions of GCC emit both, and
7405 it is more efficient to use the pre-computed name.
7407 Something to keep in mind about this process: it is very
7408 unlikely, or in some cases downright impossible, to produce
7409 something that will match the mangled name of a function.
7410 If the definition of the function has the same debug info,
7411 we should be able to match up with it anyway. But fallbacks
7412 using the minimal symbol, for instance to find a method
7413 implemented in a stripped copy of libstdc++, will not work.
7414 If we do not have debug info for the definition, we will have to
7415 match them up some other way.
7417 When we do name matching there is a related problem with function
7418 templates; two instantiated function templates are allowed to
7419 differ only by their return types, which we do not add here. */
7421 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7423 struct attribute
*attr
;
7424 struct die_info
*child
;
7427 die
->building_fullname
= 1;
7429 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7434 struct dwarf2_locexpr_baton
*baton
;
7437 if (child
->tag
!= DW_TAG_template_type_param
7438 && child
->tag
!= DW_TAG_template_value_param
)
7443 fputs_unfiltered ("<", buf
);
7447 fputs_unfiltered (", ", buf
);
7449 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7452 complaint (&symfile_complaints
,
7453 _("template parameter missing DW_AT_type"));
7454 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7457 type
= die_type (child
, cu
);
7459 if (child
->tag
== DW_TAG_template_type_param
)
7461 c_print_type (type
, "", buf
, -1, 0, &type_print_raw_options
);
7465 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7468 complaint (&symfile_complaints
,
7469 _("template parameter missing "
7470 "DW_AT_const_value"));
7471 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7475 dwarf2_const_value_attr (attr
, type
, name
,
7476 &cu
->comp_unit_obstack
, cu
,
7477 &value
, &bytes
, &baton
);
7479 if (TYPE_NOSIGN (type
))
7480 /* GDB prints characters as NUMBER 'CHAR'. If that's
7481 changed, this can use value_print instead. */
7482 c_printchar (value
, type
, buf
);
7485 struct value_print_options opts
;
7488 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7492 else if (bytes
!= NULL
)
7494 v
= allocate_value (type
);
7495 memcpy (value_contents_writeable (v
), bytes
,
7496 TYPE_LENGTH (type
));
7499 v
= value_from_longest (type
, value
);
7501 /* Specify decimal so that we do not depend on
7503 get_formatted_print_options (&opts
, 'd');
7505 value_print (v
, buf
, &opts
);
7511 die
->building_fullname
= 0;
7515 /* Close the argument list, with a space if necessary
7516 (nested templates). */
7517 char last_char
= '\0';
7518 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7519 if (last_char
== '>')
7520 fputs_unfiltered (" >", buf
);
7522 fputs_unfiltered (">", buf
);
7526 /* For Java and C++ methods, append formal parameter type
7527 information, if PHYSNAME. */
7529 if (physname
&& die
->tag
== DW_TAG_subprogram
7530 && (cu
->language
== language_cplus
7531 || cu
->language
== language_java
))
7533 struct type
*type
= read_type_die (die
, cu
);
7535 c_type_print_args (type
, buf
, 1, cu
->language
,
7536 &type_print_raw_options
);
7538 if (cu
->language
== language_java
)
7540 /* For java, we must append the return type to method
7542 if (die
->tag
== DW_TAG_subprogram
)
7543 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7544 0, 0, &type_print_raw_options
);
7546 else if (cu
->language
== language_cplus
)
7548 /* Assume that an artificial first parameter is
7549 "this", but do not crash if it is not. RealView
7550 marks unnamed (and thus unused) parameters as
7551 artificial; there is no way to differentiate
7553 if (TYPE_NFIELDS (type
) > 0
7554 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7555 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7556 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7558 fputs_unfiltered (" const", buf
);
7562 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7564 ui_file_delete (buf
);
7566 if (cu
->language
== language_cplus
)
7569 = dwarf2_canonicalize_name (name
, cu
,
7570 &objfile
->objfile_obstack
);
7581 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7582 If scope qualifiers are appropriate they will be added. The result
7583 will be allocated on the objfile_obstack, or NULL if the DIE does
7584 not have a name. NAME may either be from a previous call to
7585 dwarf2_name or NULL.
7587 The output string will be canonicalized (if C++/Java). */
7590 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7592 return dwarf2_compute_name (name
, die
, cu
, 0);
7595 /* Construct a physname for the given DIE in CU. NAME may either be
7596 from a previous call to dwarf2_name or NULL. The result will be
7597 allocated on the objfile_objstack or NULL if the DIE does not have a
7600 The output string will be canonicalized (if C++/Java). */
7603 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7605 struct objfile
*objfile
= cu
->objfile
;
7606 struct attribute
*attr
;
7607 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7608 struct cleanup
*back_to
;
7611 /* In this case dwarf2_compute_name is just a shortcut not building anything
7613 if (!die_needs_namespace (die
, cu
))
7614 return dwarf2_compute_name (name
, die
, cu
, 1);
7616 back_to
= make_cleanup (null_cleanup
, NULL
);
7618 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7620 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7622 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7624 if (attr
&& DW_STRING (attr
))
7628 mangled
= DW_STRING (attr
);
7630 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7631 type. It is easier for GDB users to search for such functions as
7632 `name(params)' than `long name(params)'. In such case the minimal
7633 symbol names do not match the full symbol names but for template
7634 functions there is never a need to look up their definition from their
7635 declaration so the only disadvantage remains the minimal symbol
7636 variant `long name(params)' does not have the proper inferior type.
7639 if (cu
->language
== language_go
)
7641 /* This is a lie, but we already lie to the caller new_symbol_full.
7642 new_symbol_full assumes we return the mangled name.
7643 This just undoes that lie until things are cleaned up. */
7648 demangled
= cplus_demangle (mangled
,
7649 (DMGL_PARAMS
| DMGL_ANSI
7650 | (cu
->language
== language_java
7651 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7656 make_cleanup (xfree
, demangled
);
7666 if (canon
== NULL
|| check_physname
)
7668 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7670 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7672 /* It may not mean a bug in GDB. The compiler could also
7673 compute DW_AT_linkage_name incorrectly. But in such case
7674 GDB would need to be bug-to-bug compatible. */
7676 complaint (&symfile_complaints
,
7677 _("Computed physname <%s> does not match demangled <%s> "
7678 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7679 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7681 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7682 is available here - over computed PHYSNAME. It is safer
7683 against both buggy GDB and buggy compilers. */
7697 retval
= obsavestring (retval
, strlen (retval
),
7698 &objfile
->objfile_obstack
);
7700 do_cleanups (back_to
);
7704 /* Read the import statement specified by the given die and record it. */
7707 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7709 struct objfile
*objfile
= cu
->objfile
;
7710 struct attribute
*import_attr
;
7711 struct die_info
*imported_die
, *child_die
;
7712 struct dwarf2_cu
*imported_cu
;
7713 const char *imported_name
;
7714 const char *imported_name_prefix
;
7715 const char *canonical_name
;
7716 const char *import_alias
;
7717 const char *imported_declaration
= NULL
;
7718 const char *import_prefix
;
7719 VEC (const_char_ptr
) *excludes
= NULL
;
7720 struct cleanup
*cleanups
;
7724 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7725 if (import_attr
== NULL
)
7727 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7728 dwarf_tag_name (die
->tag
));
7733 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7734 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7735 if (imported_name
== NULL
)
7737 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7739 The import in the following code:
7753 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7754 <52> DW_AT_decl_file : 1
7755 <53> DW_AT_decl_line : 6
7756 <54> DW_AT_import : <0x75>
7757 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7759 <5b> DW_AT_decl_file : 1
7760 <5c> DW_AT_decl_line : 2
7761 <5d> DW_AT_type : <0x6e>
7763 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7764 <76> DW_AT_byte_size : 4
7765 <77> DW_AT_encoding : 5 (signed)
7767 imports the wrong die ( 0x75 instead of 0x58 ).
7768 This case will be ignored until the gcc bug is fixed. */
7772 /* Figure out the local name after import. */
7773 import_alias
= dwarf2_name (die
, cu
);
7775 /* Figure out where the statement is being imported to. */
7776 import_prefix
= determine_prefix (die
, cu
);
7778 /* Figure out what the scope of the imported die is and prepend it
7779 to the name of the imported die. */
7780 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7782 if (imported_die
->tag
!= DW_TAG_namespace
7783 && imported_die
->tag
!= DW_TAG_module
)
7785 imported_declaration
= imported_name
;
7786 canonical_name
= imported_name_prefix
;
7788 else if (strlen (imported_name_prefix
) > 0)
7790 temp
= alloca (strlen (imported_name_prefix
)
7791 + 2 + strlen (imported_name
) + 1);
7792 strcpy (temp
, imported_name_prefix
);
7793 strcat (temp
, "::");
7794 strcat (temp
, imported_name
);
7795 canonical_name
= temp
;
7798 canonical_name
= imported_name
;
7800 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7802 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7803 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7804 child_die
= sibling_die (child_die
))
7806 /* DWARF-4: A Fortran use statement with a “rename list” may be
7807 represented by an imported module entry with an import attribute
7808 referring to the module and owned entries corresponding to those
7809 entities that are renamed as part of being imported. */
7811 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7813 complaint (&symfile_complaints
,
7814 _("child DW_TAG_imported_declaration expected "
7815 "- DIE at 0x%x [in module %s]"),
7816 child_die
->offset
.sect_off
, objfile
->name
);
7820 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7821 if (import_attr
== NULL
)
7823 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7824 dwarf_tag_name (child_die
->tag
));
7829 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7831 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7832 if (imported_name
== NULL
)
7834 complaint (&symfile_complaints
,
7835 _("child DW_TAG_imported_declaration has unknown "
7836 "imported name - DIE at 0x%x [in module %s]"),
7837 child_die
->offset
.sect_off
, objfile
->name
);
7841 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7843 process_die (child_die
, cu
);
7846 cp_add_using_directive (import_prefix
,
7849 imported_declaration
,
7851 &objfile
->objfile_obstack
);
7853 do_cleanups (cleanups
);
7856 /* Cleanup function for handle_DW_AT_stmt_list. */
7859 free_cu_line_header (void *arg
)
7861 struct dwarf2_cu
*cu
= arg
;
7863 free_line_header (cu
->line_header
);
7864 cu
->line_header
= NULL
;
7867 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
7868 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
7869 this, it was first present in GCC release 4.3.0. */
7872 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
7874 if (!cu
->checked_producer
)
7875 check_producer (cu
);
7877 return cu
->producer_is_gcc_lt_4_3
;
7881 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7882 char **name
, char **comp_dir
)
7884 struct attribute
*attr
;
7889 /* Find the filename. Do not use dwarf2_name here, since the filename
7890 is not a source language identifier. */
7891 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7894 *name
= DW_STRING (attr
);
7897 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7899 *comp_dir
= DW_STRING (attr
);
7900 else if (producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
7901 && IS_ABSOLUTE_PATH (*name
))
7903 *comp_dir
= ldirname (*name
);
7904 if (*comp_dir
!= NULL
)
7905 make_cleanup (xfree
, *comp_dir
);
7907 if (*comp_dir
!= NULL
)
7909 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7910 directory, get rid of it. */
7911 char *cp
= strchr (*comp_dir
, ':');
7913 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7918 *name
= "<unknown>";
7921 /* Handle DW_AT_stmt_list for a compilation unit.
7922 DIE is the DW_TAG_compile_unit die for CU.
7923 COMP_DIR is the compilation directory.
7924 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7927 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7928 const char *comp_dir
)
7930 struct attribute
*attr
;
7932 gdb_assert (! cu
->per_cu
->is_debug_types
);
7934 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7937 unsigned int line_offset
= DW_UNSND (attr
);
7938 struct line_header
*line_header
7939 = dwarf_decode_line_header (line_offset
, cu
);
7943 cu
->line_header
= line_header
;
7944 make_cleanup (free_cu_line_header
, cu
);
7945 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7950 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7953 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7955 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7956 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7957 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7958 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7959 struct attribute
*attr
;
7961 char *comp_dir
= NULL
;
7962 struct die_info
*child_die
;
7963 bfd
*abfd
= objfile
->obfd
;
7966 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7968 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7970 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7971 from finish_block. */
7972 if (lowpc
== ((CORE_ADDR
) -1))
7977 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7979 prepare_one_comp_unit (cu
, die
, cu
->language
);
7981 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7982 standardised yet. As a workaround for the language detection we fall
7983 back to the DW_AT_producer string. */
7984 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7985 cu
->language
= language_opencl
;
7987 /* Similar hack for Go. */
7988 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
7989 set_cu_language (DW_LANG_Go
, cu
);
7991 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
7993 /* Decode line number information if present. We do this before
7994 processing child DIEs, so that the line header table is available
7995 for DW_AT_decl_file. */
7996 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
7998 /* Process all dies in compilation unit. */
7999 if (die
->child
!= NULL
)
8001 child_die
= die
->child
;
8002 while (child_die
&& child_die
->tag
)
8004 process_die (child_die
, cu
);
8005 child_die
= sibling_die (child_die
);
8009 /* Decode macro information, if present. Dwarf 2 macro information
8010 refers to information in the line number info statement program
8011 header, so we can only read it if we've read the header
8013 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
8014 if (attr
&& cu
->line_header
)
8016 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
8017 complaint (&symfile_complaints
,
8018 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
8020 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
8024 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
8025 if (attr
&& cu
->line_header
)
8027 unsigned int macro_offset
= DW_UNSND (attr
);
8029 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
8033 do_cleanups (back_to
);
8036 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
8037 Create the set of symtabs used by this TU, or if this TU is sharing
8038 symtabs with another TU and the symtabs have already been created
8039 then restore those symtabs in the line header.
8040 We don't need the pc/line-number mapping for type units. */
8043 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
8045 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8046 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8047 struct type_unit_group
*tu_group
;
8049 struct line_header
*lh
;
8050 struct attribute
*attr
;
8051 unsigned int i
, line_offset
;
8053 gdb_assert (per_cu
->is_debug_types
);
8055 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
8057 /* If we're using .gdb_index (includes -readnow) then
8058 per_cu->s.type_unit_group may not have been set up yet. */
8059 if (per_cu
->s
.type_unit_group
== NULL
)
8060 per_cu
->s
.type_unit_group
= get_type_unit_group (cu
, attr
);
8061 tu_group
= per_cu
->s
.type_unit_group
;
8063 /* If we've already processed this stmt_list there's no real need to
8064 do it again, we could fake it and just recreate the part we need
8065 (file name,index -> symtab mapping). If data shows this optimization
8066 is useful we can do it then. */
8067 first_time
= tu_group
->primary_symtab
== NULL
;
8069 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
8074 line_offset
= DW_UNSND (attr
);
8075 lh
= dwarf_decode_line_header (line_offset
, cu
);
8080 dwarf2_start_symtab (cu
, "", NULL
, 0);
8083 gdb_assert (tu_group
->symtabs
== NULL
);
8086 /* Note: The primary symtab will get allocated at the end. */
8090 cu
->line_header
= lh
;
8091 make_cleanup (free_cu_line_header
, cu
);
8095 dwarf2_start_symtab (cu
, "", NULL
, 0);
8097 tu_group
->num_symtabs
= lh
->num_file_names
;
8098 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
8100 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8103 struct file_entry
*fe
= &lh
->file_names
[i
];
8106 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8107 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
8109 /* Note: We don't have to watch for the main subfile here, type units
8110 don't have DW_AT_name. */
8112 if (current_subfile
->symtab
== NULL
)
8114 /* NOTE: start_subfile will recognize when it's been passed
8115 a file it has already seen. So we can't assume there's a
8116 simple mapping from lh->file_names to subfiles,
8117 lh->file_names may contain dups. */
8118 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8122 fe
->symtab
= current_subfile
->symtab
;
8123 tu_group
->symtabs
[i
] = fe
->symtab
;
8130 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8132 struct file_entry
*fe
= &lh
->file_names
[i
];
8134 fe
->symtab
= tu_group
->symtabs
[i
];
8138 /* The main symtab is allocated last. Type units don't have DW_AT_name
8139 so they don't have a "real" (so to speak) symtab anyway.
8140 There is later code that will assign the main symtab to all symbols
8141 that don't have one. We need to handle the case of a symbol with a
8142 missing symtab (DW_AT_decl_file) anyway. */
8145 /* Process DW_TAG_type_unit.
8146 For TUs we want to skip the first top level sibling if it's not the
8147 actual type being defined by this TU. In this case the first top
8148 level sibling is there to provide context only. */
8151 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8153 struct die_info
*child_die
;
8155 prepare_one_comp_unit (cu
, die
, language_minimal
);
8157 /* Initialize (or reinitialize) the machinery for building symtabs.
8158 We do this before processing child DIEs, so that the line header table
8159 is available for DW_AT_decl_file. */
8160 setup_type_unit_groups (die
, cu
);
8162 if (die
->child
!= NULL
)
8164 child_die
= die
->child
;
8165 while (child_die
&& child_die
->tag
)
8167 process_die (child_die
, cu
);
8168 child_die
= sibling_die (child_die
);
8175 http://gcc.gnu.org/wiki/DebugFission
8176 http://gcc.gnu.org/wiki/DebugFissionDWP
8178 To simplify handling of both DWO files ("object" files with the DWARF info)
8179 and DWP files (a file with the DWOs packaged up into one file), we treat
8180 DWP files as having a collection of virtual DWO files. */
8183 hash_dwo_file (const void *item
)
8185 const struct dwo_file
*dwo_file
= item
;
8187 return htab_hash_string (dwo_file
->name
);
8191 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
8193 const struct dwo_file
*lhs
= item_lhs
;
8194 const struct dwo_file
*rhs
= item_rhs
;
8196 return strcmp (lhs
->name
, rhs
->name
) == 0;
8199 /* Allocate a hash table for DWO files. */
8202 allocate_dwo_file_hash_table (void)
8204 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8206 return htab_create_alloc_ex (41,
8210 &objfile
->objfile_obstack
,
8211 hashtab_obstack_allocate
,
8212 dummy_obstack_deallocate
);
8215 /* Lookup DWO file DWO_NAME. */
8218 lookup_dwo_file_slot (const char *dwo_name
)
8220 struct dwo_file find_entry
;
8223 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8224 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8226 memset (&find_entry
, 0, sizeof (find_entry
));
8227 find_entry
.name
= dwo_name
;
8228 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8234 hash_dwo_unit (const void *item
)
8236 const struct dwo_unit
*dwo_unit
= item
;
8238 /* This drops the top 32 bits of the id, but is ok for a hash. */
8239 return dwo_unit
->signature
;
8243 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
8245 const struct dwo_unit
*lhs
= item_lhs
;
8246 const struct dwo_unit
*rhs
= item_rhs
;
8248 /* The signature is assumed to be unique within the DWO file.
8249 So while object file CU dwo_id's always have the value zero,
8250 that's OK, assuming each object file DWO file has only one CU,
8251 and that's the rule for now. */
8252 return lhs
->signature
== rhs
->signature
;
8255 /* Allocate a hash table for DWO CUs,TUs.
8256 There is one of these tables for each of CUs,TUs for each DWO file. */
8259 allocate_dwo_unit_table (struct objfile
*objfile
)
8261 /* Start out with a pretty small number.
8262 Generally DWO files contain only one CU and maybe some TUs. */
8263 return htab_create_alloc_ex (3,
8267 &objfile
->objfile_obstack
,
8268 hashtab_obstack_allocate
,
8269 dummy_obstack_deallocate
);
8272 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
8274 struct create_dwo_info_table_data
8276 struct dwo_file
*dwo_file
;
8280 /* die_reader_func for create_dwo_debug_info_hash_table. */
8283 create_dwo_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
8285 struct die_info
*comp_unit_die
,
8289 struct dwarf2_cu
*cu
= reader
->cu
;
8290 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8291 sect_offset offset
= cu
->per_cu
->offset
;
8292 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
8293 struct create_dwo_info_table_data
*data
= datap
;
8294 struct dwo_file
*dwo_file
= data
->dwo_file
;
8295 htab_t cu_htab
= data
->cu_htab
;
8297 struct attribute
*attr
;
8298 struct dwo_unit
*dwo_unit
;
8300 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
8303 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8304 " its dwo_id [in module %s]"),
8305 offset
.sect_off
, dwo_file
->name
);
8309 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8310 dwo_unit
->dwo_file
= dwo_file
;
8311 dwo_unit
->signature
= DW_UNSND (attr
);
8312 dwo_unit
->info_or_types_section
= section
;
8313 dwo_unit
->offset
= offset
;
8314 dwo_unit
->length
= cu
->per_cu
->length
;
8316 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
8317 gdb_assert (slot
!= NULL
);
8320 const struct dwo_unit
*dup_dwo_unit
= *slot
;
8322 complaint (&symfile_complaints
,
8323 _("debug entry at offset 0x%x is duplicate to the entry at"
8324 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8325 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
8326 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
8332 if (dwarf2_read_debug
)
8333 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
8335 phex (dwo_unit
->signature
,
8336 sizeof (dwo_unit
->signature
)));
8339 /* Create a hash table to map DWO IDs to their CU entry in
8340 .debug_info.dwo in DWO_FILE.
8341 Note: This function processes DWO files only, not DWP files. */
8344 create_dwo_debug_info_hash_table (struct dwo_file
*dwo_file
)
8346 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8347 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
8350 gdb_byte
*info_ptr
, *end_ptr
;
8351 struct create_dwo_info_table_data create_dwo_info_table_data
;
8353 dwarf2_read_section (objfile
, section
);
8354 info_ptr
= section
->buffer
;
8356 if (info_ptr
== NULL
)
8359 /* We can't set abfd until now because the section may be empty or
8360 not present, in which case section->asection will be NULL. */
8361 abfd
= section
->asection
->owner
;
8363 if (dwarf2_read_debug
)
8364 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
8365 bfd_get_filename (abfd
));
8367 cu_htab
= allocate_dwo_unit_table (objfile
);
8369 create_dwo_info_table_data
.dwo_file
= dwo_file
;
8370 create_dwo_info_table_data
.cu_htab
= cu_htab
;
8372 end_ptr
= info_ptr
+ section
->size
;
8373 while (info_ptr
< end_ptr
)
8375 struct dwarf2_per_cu_data per_cu
;
8377 memset (&per_cu
, 0, sizeof (per_cu
));
8378 per_cu
.objfile
= objfile
;
8379 per_cu
.is_debug_types
= 0;
8380 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8381 per_cu
.info_or_types_section
= section
;
8383 init_cutu_and_read_dies_no_follow (&per_cu
,
8384 &dwo_file
->sections
.abbrev
,
8386 create_dwo_debug_info_hash_table_reader
,
8387 &create_dwo_info_table_data
);
8389 info_ptr
+= per_cu
.length
;
8395 /* DWP file .debug_{cu,tu}_index section format:
8396 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8398 Both index sections have the same format, and serve to map a 64-bit
8399 signature to a set of section numbers. Each section begins with a header,
8400 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8401 indexes, and a pool of 32-bit section numbers. The index sections will be
8402 aligned at 8-byte boundaries in the file.
8404 The index section header contains two unsigned 32-bit values (using the
8405 byte order of the application binary):
8407 N, the number of compilation units or type units in the index
8408 M, the number of slots in the hash table
8410 (We assume that N and M will not exceed 2^32 - 1.)
8412 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8414 The hash table begins at offset 8 in the section, and consists of an array
8415 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8416 order of the application binary). Unused slots in the hash table are 0.
8417 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8419 The parallel table begins immediately after the hash table
8420 (at offset 8 + 8 * M from the beginning of the section), and consists of an
8421 array of 32-bit indexes (using the byte order of the application binary),
8422 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8423 table contains a 32-bit index into the pool of section numbers. For unused
8424 hash table slots, the corresponding entry in the parallel table will be 0.
8426 Given a 64-bit compilation unit signature or a type signature S, an entry
8427 in the hash table is located as follows:
8429 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8430 the low-order k bits all set to 1.
8432 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8434 3) If the hash table entry at index H matches the signature, use that
8435 entry. If the hash table entry at index H is unused (all zeroes),
8436 terminate the search: the signature is not present in the table.
8438 4) Let H = (H + H') modulo M. Repeat at Step 3.
8440 Because M > N and H' and M are relatively prime, the search is guaranteed
8441 to stop at an unused slot or find the match.
8443 The pool of section numbers begins immediately following the hash table
8444 (at offset 8 + 12 * M from the beginning of the section). The pool of
8445 section numbers consists of an array of 32-bit words (using the byte order
8446 of the application binary). Each item in the array is indexed starting
8447 from 0. The hash table entry provides the index of the first section
8448 number in the set. Additional section numbers in the set follow, and the
8449 set is terminated by a 0 entry (section number 0 is not used in ELF).
8451 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8452 section must be the first entry in the set, and the .debug_abbrev.dwo must
8453 be the second entry. Other members of the set may follow in any order. */
8455 /* Create a hash table to map DWO IDs to their CU/TU entry in
8456 .debug_{info,types}.dwo in DWP_FILE.
8457 Returns NULL if there isn't one.
8458 Note: This function processes DWP files only, not DWO files. */
8460 static struct dwp_hash_table
*
8461 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
8463 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8464 bfd
*dbfd
= dwp_file
->dbfd
;
8465 char *index_ptr
, *index_end
;
8466 struct dwarf2_section_info
*index
;
8467 uint32_t version
, nr_units
, nr_slots
;
8468 struct dwp_hash_table
*htab
;
8471 index
= &dwp_file
->sections
.tu_index
;
8473 index
= &dwp_file
->sections
.cu_index
;
8475 if (dwarf2_section_empty_p (index
))
8477 dwarf2_read_section (objfile
, index
);
8479 index_ptr
= index
->buffer
;
8480 index_end
= index_ptr
+ index
->size
;
8482 version
= read_4_bytes (dbfd
, index_ptr
);
8483 index_ptr
+= 8; /* Skip the unused word. */
8484 nr_units
= read_4_bytes (dbfd
, index_ptr
);
8486 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
8491 error (_("Dwarf Error: unsupported DWP file version (%u)"
8493 version
, dwp_file
->name
);
8495 if (nr_slots
!= (nr_slots
& -nr_slots
))
8497 error (_("Dwarf Error: number of slots in DWP hash table (%u)"
8498 " is not power of 2 [in module %s]"),
8499 nr_slots
, dwp_file
->name
);
8502 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
8503 htab
->nr_units
= nr_units
;
8504 htab
->nr_slots
= nr_slots
;
8505 htab
->hash_table
= index_ptr
;
8506 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
8507 htab
->section_pool
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8512 /* Update SECTIONS with the data from SECTP.
8514 This function is like the other "locate" section routines that are
8515 passed to bfd_map_over_sections, but in this context the sections to
8516 read comes from the DWP hash table, not the full ELF section table.
8518 The result is non-zero for success, or zero if an error was found. */
8521 locate_virtual_dwo_sections (asection
*sectp
,
8522 struct virtual_dwo_sections
*sections
)
8524 const struct dwop_section_names
*names
= &dwop_section_names
;
8526 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8528 /* There can be only one. */
8529 if (sections
->abbrev
.asection
!= NULL
)
8531 sections
->abbrev
.asection
= sectp
;
8532 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8534 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
8535 || section_is_p (sectp
->name
, &names
->types_dwo
))
8537 /* There can be only one. */
8538 if (sections
->info_or_types
.asection
!= NULL
)
8540 sections
->info_or_types
.asection
= sectp
;
8541 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
8543 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8545 /* There can be only one. */
8546 if (sections
->line
.asection
!= NULL
)
8548 sections
->line
.asection
= sectp
;
8549 sections
->line
.size
= bfd_get_section_size (sectp
);
8551 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8553 /* There can be only one. */
8554 if (sections
->loc
.asection
!= NULL
)
8556 sections
->loc
.asection
= sectp
;
8557 sections
->loc
.size
= bfd_get_section_size (sectp
);
8559 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8561 /* There can be only one. */
8562 if (sections
->macinfo
.asection
!= NULL
)
8564 sections
->macinfo
.asection
= sectp
;
8565 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8567 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8569 /* There can be only one. */
8570 if (sections
->macro
.asection
!= NULL
)
8572 sections
->macro
.asection
= sectp
;
8573 sections
->macro
.size
= bfd_get_section_size (sectp
);
8575 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8577 /* There can be only one. */
8578 if (sections
->str_offsets
.asection
!= NULL
)
8580 sections
->str_offsets
.asection
= sectp
;
8581 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8585 /* No other kind of section is valid. */
8592 /* Create a dwo_unit object for the DWO with signature SIGNATURE.
8593 HTAB is the hash table from the DWP file.
8594 SECTION_INDEX is the index of the DWO in HTAB. */
8596 static struct dwo_unit
*
8597 create_dwo_in_dwp (struct dwp_file
*dwp_file
,
8598 const struct dwp_hash_table
*htab
,
8599 uint32_t section_index
,
8600 ULONGEST signature
, int is_debug_types
)
8602 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8603 bfd
*dbfd
= dwp_file
->dbfd
;
8604 const char *kind
= is_debug_types
? "TU" : "CU";
8605 struct dwo_file
*dwo_file
;
8606 struct dwo_unit
*dwo_unit
;
8607 struct virtual_dwo_sections sections
;
8608 void **dwo_file_slot
;
8609 char *virtual_dwo_name
;
8610 struct dwarf2_section_info
*cutu
;
8611 struct cleanup
*cleanups
;
8614 if (dwarf2_read_debug
)
8616 fprintf_unfiltered (gdb_stdlog
, "Reading %s %u/0x%s in DWP file: %s\n",
8618 section_index
, phex (signature
, sizeof (signature
)),
8622 /* Fetch the sections of this DWO.
8623 Put a limit on the number of sections we look for so that bad data
8624 doesn't cause us to loop forever. */
8626 #define MAX_NR_DWO_SECTIONS \
8627 (1 /* .debug_info or .debug_types */ \
8628 + 1 /* .debug_abbrev */ \
8629 + 1 /* .debug_line */ \
8630 + 1 /* .debug_loc */ \
8631 + 1 /* .debug_str_offsets */ \
8632 + 1 /* .debug_macro */ \
8633 + 1 /* .debug_macinfo */ \
8634 + 1 /* trailing zero */)
8636 memset (§ions
, 0, sizeof (sections
));
8637 cleanups
= make_cleanup (null_cleanup
, 0);
8639 for (i
= 0; i
< MAX_NR_DWO_SECTIONS
; ++i
)
8642 uint32_t section_nr
=
8645 + (section_index
+ i
) * sizeof (uint32_t));
8647 if (section_nr
== 0)
8649 if (section_nr
>= dwp_file
->num_sections
)
8651 error (_("Dwarf Error: bad DWP hash table, section number too large"
8656 sectp
= dwp_file
->elf_sections
[section_nr
];
8657 if (! locate_virtual_dwo_sections (sectp
, §ions
))
8659 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8666 || sections
.info_or_types
.asection
== NULL
8667 || sections
.abbrev
.asection
== NULL
)
8669 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8673 if (i
== MAX_NR_DWO_SECTIONS
)
8675 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8680 /* It's easier for the rest of the code if we fake a struct dwo_file and
8681 have dwo_unit "live" in that. At least for now.
8683 The DWP file can be made up of a random collection of CUs and TUs.
8684 However, for each CU + set of TUs that came from the same original DWO
8685 file, we want to combine them back into a virtual DWO file to save space
8686 (fewer struct dwo_file objects to allocated). Remember that for really
8687 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8690 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
8691 sections
.abbrev
.asection
? sections
.abbrev
.asection
->id
: 0,
8692 sections
.line
.asection
? sections
.line
.asection
->id
: 0,
8693 sections
.loc
.asection
? sections
.loc
.asection
->id
: 0,
8694 (sections
.str_offsets
.asection
8695 ? sections
.str_offsets
.asection
->id
8697 make_cleanup (xfree
, virtual_dwo_name
);
8698 /* Can we use an existing virtual DWO file? */
8699 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
);
8700 /* Create one if necessary. */
8701 if (*dwo_file_slot
== NULL
)
8703 if (dwarf2_read_debug
)
8705 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
8708 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8709 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8711 strlen (virtual_dwo_name
));
8712 dwo_file
->sections
.abbrev
= sections
.abbrev
;
8713 dwo_file
->sections
.line
= sections
.line
;
8714 dwo_file
->sections
.loc
= sections
.loc
;
8715 dwo_file
->sections
.macinfo
= sections
.macinfo
;
8716 dwo_file
->sections
.macro
= sections
.macro
;
8717 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
8718 /* The "str" section is global to the entire DWP file. */
8719 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
8720 /* The info or types section is assigned later to dwo_unit,
8721 there's no need to record it in dwo_file.
8722 Also, we can't simply record type sections in dwo_file because
8723 we record a pointer into the vector in dwo_unit. As we collect more
8724 types we'll grow the vector and eventually have to reallocate space
8725 for it, invalidating all the pointers into the current copy. */
8726 *dwo_file_slot
= dwo_file
;
8730 if (dwarf2_read_debug
)
8732 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
8735 dwo_file
= *dwo_file_slot
;
8737 do_cleanups (cleanups
);
8739 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8740 dwo_unit
->dwo_file
= dwo_file
;
8741 dwo_unit
->signature
= signature
;
8742 dwo_unit
->info_or_types_section
=
8743 obstack_alloc (&objfile
->objfile_obstack
,
8744 sizeof (struct dwarf2_section_info
));
8745 *dwo_unit
->info_or_types_section
= sections
.info_or_types
;
8746 /* offset, length, type_offset_in_tu are set later. */
8751 /* Lookup the DWO with SIGNATURE in DWP_FILE. */
8753 static struct dwo_unit
*
8754 lookup_dwo_in_dwp (struct dwp_file
*dwp_file
,
8755 const struct dwp_hash_table
*htab
,
8756 ULONGEST signature
, int is_debug_types
)
8758 bfd
*dbfd
= dwp_file
->dbfd
;
8759 uint32_t mask
= htab
->nr_slots
- 1;
8760 uint32_t hash
= signature
& mask
;
8761 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
8764 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8766 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
8767 find_dwo_cu
.signature
= signature
;
8768 slot
= htab_find_slot (dwp_file
->loaded_cutus
, &find_dwo_cu
, INSERT
);
8773 /* Use a for loop so that we don't loop forever on bad debug info. */
8774 for (i
= 0; i
< htab
->nr_slots
; ++i
)
8776 ULONGEST signature_in_table
;
8778 signature_in_table
=
8779 read_8_bytes (dbfd
, htab
->hash_table
+ hash
* sizeof (uint64_t));
8780 if (signature_in_table
== signature
)
8782 uint32_t section_index
=
8783 read_4_bytes (dbfd
, htab
->unit_table
+ hash
* sizeof (uint32_t));
8785 *slot
= create_dwo_in_dwp (dwp_file
, htab
, section_index
,
8786 signature
, is_debug_types
);
8789 if (signature_in_table
== 0)
8791 hash
= (hash
+ hash2
) & mask
;
8794 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
8799 /* Subroutine of open_dwop_file to simplify it.
8800 Open the file specified by FILE_NAME and hand it off to BFD for
8801 preliminary analysis. Return a newly initialized bfd *, which
8802 includes a canonicalized copy of FILE_NAME.
8803 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8804 In case of trouble, return NULL.
8805 NOTE: This function is derived from symfile_bfd_open. */
8808 try_open_dwop_file (const char *file_name
, int is_dwp
)
8812 char *absolute_name
;
8814 flags
= OPF_TRY_CWD_FIRST
;
8816 flags
|= OPF_SEARCH_IN_PATH
;
8817 desc
= openp (debug_file_directory
, flags
, file_name
,
8818 O_RDONLY
| O_BINARY
, &absolute_name
);
8822 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
8825 xfree (absolute_name
);
8828 xfree (absolute_name
);
8829 bfd_set_cacheable (sym_bfd
, 1);
8831 if (!bfd_check_format (sym_bfd
, bfd_object
))
8833 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
8840 /* Try to open DWO/DWP file FILE_NAME.
8841 COMP_DIR is the DW_AT_comp_dir attribute.
8842 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8843 The result is the bfd handle of the file.
8844 If there is a problem finding or opening the file, return NULL.
8845 Upon success, the canonicalized path of the file is stored in the bfd,
8846 same as symfile_bfd_open. */
8849 open_dwop_file (const char *file_name
, const char *comp_dir
, int is_dwp
)
8853 if (IS_ABSOLUTE_PATH (file_name
))
8854 return try_open_dwop_file (file_name
, is_dwp
);
8856 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8858 if (comp_dir
!= NULL
)
8860 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, file_name
, NULL
);
8862 /* NOTE: If comp_dir is a relative path, this will also try the
8863 search path, which seems useful. */
8864 abfd
= try_open_dwop_file (path_to_try
, is_dwp
);
8865 xfree (path_to_try
);
8870 /* That didn't work, try debug-file-directory, which, despite its name,
8871 is a list of paths. */
8873 if (*debug_file_directory
== '\0')
8876 return try_open_dwop_file (file_name
, is_dwp
);
8879 /* This function is mapped across the sections and remembers the offset and
8880 size of each of the DWO debugging sections we are interested in. */
8883 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
8885 struct dwo_sections
*dwo_sections
= dwo_sections_ptr
;
8886 const struct dwop_section_names
*names
= &dwop_section_names
;
8888 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8890 dwo_sections
->abbrev
.asection
= sectp
;
8891 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8893 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
8895 dwo_sections
->info
.asection
= sectp
;
8896 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
8898 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8900 dwo_sections
->line
.asection
= sectp
;
8901 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
8903 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8905 dwo_sections
->loc
.asection
= sectp
;
8906 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
8908 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8910 dwo_sections
->macinfo
.asection
= sectp
;
8911 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8913 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8915 dwo_sections
->macro
.asection
= sectp
;
8916 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
8918 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
8920 dwo_sections
->str
.asection
= sectp
;
8921 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
8923 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8925 dwo_sections
->str_offsets
.asection
= sectp
;
8926 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8928 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
8930 struct dwarf2_section_info type_section
;
8932 memset (&type_section
, 0, sizeof (type_section
));
8933 type_section
.asection
= sectp
;
8934 type_section
.size
= bfd_get_section_size (sectp
);
8935 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
8940 /* Initialize the use of the DWO file specified by DWO_NAME.
8941 The result is NULL if DWO_NAME can't be found. */
8943 static struct dwo_file
*
8944 open_and_init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8946 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8947 struct dwo_file
*dwo_file
;
8949 struct cleanup
*cleanups
;
8951 dbfd
= open_dwop_file (dwo_name
, comp_dir
, 0);
8954 if (dwarf2_read_debug
)
8955 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
8958 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8959 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8960 dwo_name
, strlen (dwo_name
));
8961 dwo_file
->dbfd
= dbfd
;
8963 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8965 bfd_map_over_sections (dbfd
, dwarf2_locate_dwo_sections
, &dwo_file
->sections
);
8967 dwo_file
->cus
= create_dwo_debug_info_hash_table (dwo_file
);
8969 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8970 dwo_file
->sections
.types
);
8972 discard_cleanups (cleanups
);
8974 if (dwarf2_read_debug
)
8975 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
8980 /* This function is mapped across the sections and remembers the offset and
8981 size of each of the DWP debugging sections we are interested in. */
8984 dwarf2_locate_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
8986 struct dwp_file
*dwp_file
= dwp_file_ptr
;
8987 const struct dwop_section_names
*names
= &dwop_section_names
;
8988 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
8990 /* Record the ELF section number for later lookup: this is what the
8991 .debug_cu_index,.debug_tu_index tables use. */
8992 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
8993 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
8995 /* Look for specific sections that we need. */
8996 if (section_is_p (sectp
->name
, &names
->str_dwo
))
8998 dwp_file
->sections
.str
.asection
= sectp
;
8999 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
9001 else if (section_is_p (sectp
->name
, &names
->cu_index
))
9003 dwp_file
->sections
.cu_index
.asection
= sectp
;
9004 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
9006 else if (section_is_p (sectp
->name
, &names
->tu_index
))
9008 dwp_file
->sections
.tu_index
.asection
= sectp
;
9009 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
9013 /* Hash function for dwp_file loaded CUs/TUs. */
9016 hash_dwp_loaded_cutus (const void *item
)
9018 const struct dwo_unit
*dwo_unit
= item
;
9020 /* This drops the top 32 bits of the signature, but is ok for a hash. */
9021 return dwo_unit
->signature
;
9024 /* Equality function for dwp_file loaded CUs/TUs. */
9027 eq_dwp_loaded_cutus (const void *a
, const void *b
)
9029 const struct dwo_unit
*dua
= a
;
9030 const struct dwo_unit
*dub
= b
;
9032 return dua
->signature
== dub
->signature
;
9035 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
9038 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
9040 return htab_create_alloc_ex (3,
9041 hash_dwp_loaded_cutus
,
9042 eq_dwp_loaded_cutus
,
9044 &objfile
->objfile_obstack
,
9045 hashtab_obstack_allocate
,
9046 dummy_obstack_deallocate
);
9049 /* Initialize the use of the DWP file for the current objfile.
9050 By convention the name of the DWP file is ${objfile}.dwp.
9051 The result is NULL if it can't be found. */
9053 static struct dwp_file
*
9054 open_and_init_dwp_file (const char *comp_dir
)
9056 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9057 struct dwp_file
*dwp_file
;
9060 struct cleanup
*cleanups
;
9062 dwp_name
= xstrprintf ("%s.dwp", dwarf2_per_objfile
->objfile
->name
);
9063 cleanups
= make_cleanup (xfree
, dwp_name
);
9065 dbfd
= open_dwop_file (dwp_name
, comp_dir
, 1);
9068 if (dwarf2_read_debug
)
9069 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
9070 do_cleanups (cleanups
);
9073 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
9074 dwp_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
9075 dwp_name
, strlen (dwp_name
));
9076 dwp_file
->dbfd
= dbfd
;
9077 do_cleanups (cleanups
);
9079 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwp_file
);
9081 /* +1: section 0 is unused */
9082 dwp_file
->num_sections
= bfd_count_sections (dbfd
) + 1;
9083 dwp_file
->elf_sections
=
9084 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
9085 dwp_file
->num_sections
, asection
*);
9087 bfd_map_over_sections (dbfd
, dwarf2_locate_dwp_sections
, dwp_file
);
9089 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
9091 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
9093 dwp_file
->loaded_cutus
= allocate_dwp_loaded_cutus_table (objfile
);
9095 discard_cleanups (cleanups
);
9097 if (dwarf2_read_debug
)
9099 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
9100 fprintf_unfiltered (gdb_stdlog
,
9101 " %u CUs, %u TUs\n",
9102 dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0,
9103 dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0);
9109 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9110 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9111 or in the DWP file for the objfile, referenced by THIS_UNIT.
9112 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9113 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9115 This is called, for example, when wanting to read a variable with a
9116 complex location. Therefore we don't want to do file i/o for every call.
9117 Therefore we don't want to look for a DWO file on every call.
9118 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9119 then we check if we've already seen DWO_NAME, and only THEN do we check
9122 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9123 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9125 static struct dwo_unit
*
9126 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
9127 const char *dwo_name
, const char *comp_dir
,
9128 ULONGEST signature
, int is_debug_types
)
9130 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9131 const char *kind
= is_debug_types
? "TU" : "CU";
9132 void **dwo_file_slot
;
9133 struct dwo_file
*dwo_file
;
9134 struct dwp_file
*dwp_file
;
9136 /* Have we already read SIGNATURE from a DWP file? */
9138 if (! dwarf2_per_objfile
->dwp_checked
)
9140 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file (comp_dir
);
9141 dwarf2_per_objfile
->dwp_checked
= 1;
9143 dwp_file
= dwarf2_per_objfile
->dwp_file
;
9145 if (dwp_file
!= NULL
)
9147 const struct dwp_hash_table
*dwp_htab
=
9148 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9150 if (dwp_htab
!= NULL
)
9152 struct dwo_unit
*dwo_cutu
=
9153 lookup_dwo_in_dwp (dwp_file
, dwp_htab
, signature
, is_debug_types
);
9155 if (dwo_cutu
!= NULL
)
9157 if (dwarf2_read_debug
)
9159 fprintf_unfiltered (gdb_stdlog
,
9160 "Virtual DWO %s %s found: @%s\n",
9161 kind
, hex_string (signature
),
9162 host_address_to_string (dwo_cutu
));
9169 /* Have we already seen DWO_NAME? */
9171 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
);
9172 if (*dwo_file_slot
== NULL
)
9174 /* Read in the file and build a table of the DWOs it contains. */
9175 *dwo_file_slot
= open_and_init_dwo_file (dwo_name
, comp_dir
);
9177 /* NOTE: This will be NULL if unable to open the file. */
9178 dwo_file
= *dwo_file_slot
;
9180 if (dwo_file
!= NULL
)
9182 htab_t htab
= is_debug_types
? dwo_file
->tus
: dwo_file
->cus
;
9186 struct dwo_unit find_dwo_cutu
, *dwo_cutu
;
9188 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
9189 find_dwo_cutu
.signature
= signature
;
9190 dwo_cutu
= htab_find (htab
, &find_dwo_cutu
);
9192 if (dwo_cutu
!= NULL
)
9194 if (dwarf2_read_debug
)
9196 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
9197 kind
, dwo_name
, hex_string (signature
),
9198 host_address_to_string (dwo_cutu
));
9205 /* We didn't find it. This could mean a dwo_id mismatch, or
9206 someone deleted the DWO/DWP file, or the search path isn't set up
9207 correctly to find the file. */
9209 if (dwarf2_read_debug
)
9211 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
9212 kind
, dwo_name
, hex_string (signature
));
9215 complaint (&symfile_complaints
,
9216 _("Could not find DWO CU referenced by CU at offset 0x%x"
9218 this_unit
->offset
.sect_off
, objfile
->name
);
9222 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9223 See lookup_dwo_cutu_unit for details. */
9225 static struct dwo_unit
*
9226 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9227 const char *dwo_name
, const char *comp_dir
,
9230 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
9233 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9234 See lookup_dwo_cutu_unit for details. */
9236 static struct dwo_unit
*
9237 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
9238 const char *dwo_name
, const char *comp_dir
)
9240 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
9243 /* Free all resources associated with DWO_FILE.
9244 Close the DWO file and munmap the sections.
9245 All memory should be on the objfile obstack. */
9248 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
9251 struct dwarf2_section_info
*section
;
9253 gdb_assert (dwo_file
->dbfd
!= objfile
->obfd
);
9254 gdb_bfd_unref (dwo_file
->dbfd
);
9256 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
9259 /* Wrapper for free_dwo_file for use in cleanups. */
9262 free_dwo_file_cleanup (void *arg
)
9264 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
9265 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9267 free_dwo_file (dwo_file
, objfile
);
9270 /* Traversal function for free_dwo_files. */
9273 free_dwo_file_from_slot (void **slot
, void *info
)
9275 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
9276 struct objfile
*objfile
= (struct objfile
*) info
;
9278 free_dwo_file (dwo_file
, objfile
);
9283 /* Free all resources associated with DWO_FILES. */
9286 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
9288 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
9291 /* Read in various DIEs. */
9293 /* qsort helper for inherit_abstract_dies. */
9296 unsigned_int_compar (const void *ap
, const void *bp
)
9298 unsigned int a
= *(unsigned int *) ap
;
9299 unsigned int b
= *(unsigned int *) bp
;
9301 return (a
> b
) - (b
> a
);
9304 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9305 Inherit only the children of the DW_AT_abstract_origin DIE not being
9306 already referenced by DW_AT_abstract_origin from the children of the
9310 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
9312 struct die_info
*child_die
;
9313 unsigned die_children_count
;
9314 /* CU offsets which were referenced by children of the current DIE. */
9315 sect_offset
*offsets
;
9316 sect_offset
*offsets_end
, *offsetp
;
9317 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9318 struct die_info
*origin_die
;
9319 /* Iterator of the ORIGIN_DIE children. */
9320 struct die_info
*origin_child_die
;
9321 struct cleanup
*cleanups
;
9322 struct attribute
*attr
;
9323 struct dwarf2_cu
*origin_cu
;
9324 struct pending
**origin_previous_list_in_scope
;
9326 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9330 /* Note that following die references may follow to a die in a
9334 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
9336 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9338 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
9339 origin_cu
->list_in_scope
= cu
->list_in_scope
;
9341 if (die
->tag
!= origin_die
->tag
9342 && !(die
->tag
== DW_TAG_inlined_subroutine
9343 && origin_die
->tag
== DW_TAG_subprogram
))
9344 complaint (&symfile_complaints
,
9345 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
9346 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
9348 child_die
= die
->child
;
9349 die_children_count
= 0;
9350 while (child_die
&& child_die
->tag
)
9352 child_die
= sibling_die (child_die
);
9353 die_children_count
++;
9355 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
9356 cleanups
= make_cleanup (xfree
, offsets
);
9358 offsets_end
= offsets
;
9359 child_die
= die
->child
;
9360 while (child_die
&& child_die
->tag
)
9362 /* For each CHILD_DIE, find the corresponding child of
9363 ORIGIN_DIE. If there is more than one layer of
9364 DW_AT_abstract_origin, follow them all; there shouldn't be,
9365 but GCC versions at least through 4.4 generate this (GCC PR
9367 struct die_info
*child_origin_die
= child_die
;
9368 struct dwarf2_cu
*child_origin_cu
= cu
;
9372 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
9376 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
9380 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9381 counterpart may exist. */
9382 if (child_origin_die
!= child_die
)
9384 if (child_die
->tag
!= child_origin_die
->tag
9385 && !(child_die
->tag
== DW_TAG_inlined_subroutine
9386 && child_origin_die
->tag
== DW_TAG_subprogram
))
9387 complaint (&symfile_complaints
,
9388 _("Child DIE 0x%x and its abstract origin 0x%x have "
9389 "different tags"), child_die
->offset
.sect_off
,
9390 child_origin_die
->offset
.sect_off
);
9391 if (child_origin_die
->parent
!= origin_die
)
9392 complaint (&symfile_complaints
,
9393 _("Child DIE 0x%x and its abstract origin 0x%x have "
9394 "different parents"), child_die
->offset
.sect_off
,
9395 child_origin_die
->offset
.sect_off
);
9397 *offsets_end
++ = child_origin_die
->offset
;
9399 child_die
= sibling_die (child_die
);
9401 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
9402 unsigned_int_compar
);
9403 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
9404 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
9405 complaint (&symfile_complaints
,
9406 _("Multiple children of DIE 0x%x refer "
9407 "to DIE 0x%x as their abstract origin"),
9408 die
->offset
.sect_off
, offsetp
->sect_off
);
9411 origin_child_die
= origin_die
->child
;
9412 while (origin_child_die
&& origin_child_die
->tag
)
9414 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9415 while (offsetp
< offsets_end
9416 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
9418 if (offsetp
>= offsets_end
9419 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
9421 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
9422 process_die (origin_child_die
, origin_cu
);
9424 origin_child_die
= sibling_die (origin_child_die
);
9426 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
9428 do_cleanups (cleanups
);
9432 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9434 struct objfile
*objfile
= cu
->objfile
;
9435 struct context_stack
*new;
9438 struct die_info
*child_die
;
9439 struct attribute
*attr
, *call_line
, *call_file
;
9442 struct block
*block
;
9443 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
9444 VEC (symbolp
) *template_args
= NULL
;
9445 struct template_symbol
*templ_func
= NULL
;
9449 /* If we do not have call site information, we can't show the
9450 caller of this inlined function. That's too confusing, so
9451 only use the scope for local variables. */
9452 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
9453 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
9454 if (call_line
== NULL
|| call_file
== NULL
)
9456 read_lexical_block_scope (die
, cu
);
9461 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9463 name
= dwarf2_name (die
, cu
);
9465 /* Ignore functions with missing or empty names. These are actually
9466 illegal according to the DWARF standard. */
9469 complaint (&symfile_complaints
,
9470 _("missing name for subprogram DIE at %d"),
9471 die
->offset
.sect_off
);
9475 /* Ignore functions with missing or invalid low and high pc attributes. */
9476 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9478 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9479 if (!attr
|| !DW_UNSND (attr
))
9480 complaint (&symfile_complaints
,
9481 _("cannot get low and high bounds "
9482 "for subprogram DIE at %d"),
9483 die
->offset
.sect_off
);
9490 /* If we have any template arguments, then we must allocate a
9491 different sort of symbol. */
9492 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
9494 if (child_die
->tag
== DW_TAG_template_type_param
9495 || child_die
->tag
== DW_TAG_template_value_param
)
9497 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
9498 struct template_symbol
);
9499 templ_func
->base
.is_cplus_template_function
= 1;
9504 new = push_context (0, lowpc
);
9505 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
9506 (struct symbol
*) templ_func
);
9508 /* If there is a location expression for DW_AT_frame_base, record
9510 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
9512 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
9513 expression is being recorded directly in the function's symbol
9514 and not in a separate frame-base object. I guess this hack is
9515 to avoid adding some sort of frame-base adjunct/annex to the
9516 function's symbol :-(. The problem with doing this is that it
9517 results in a function symbol with a location expression that
9518 has nothing to do with the location of the function, ouch! The
9519 relationship should be: a function's symbol has-a frame base; a
9520 frame-base has-a location expression. */
9521 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
9523 cu
->list_in_scope
= &local_symbols
;
9525 if (die
->child
!= NULL
)
9527 child_die
= die
->child
;
9528 while (child_die
&& child_die
->tag
)
9530 if (child_die
->tag
== DW_TAG_template_type_param
9531 || child_die
->tag
== DW_TAG_template_value_param
)
9533 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9536 VEC_safe_push (symbolp
, template_args
, arg
);
9539 process_die (child_die
, cu
);
9540 child_die
= sibling_die (child_die
);
9544 inherit_abstract_dies (die
, cu
);
9546 /* If we have a DW_AT_specification, we might need to import using
9547 directives from the context of the specification DIE. See the
9548 comment in determine_prefix. */
9549 if (cu
->language
== language_cplus
9550 && dwarf2_attr (die
, DW_AT_specification
, cu
))
9552 struct dwarf2_cu
*spec_cu
= cu
;
9553 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
9557 child_die
= spec_die
->child
;
9558 while (child_die
&& child_die
->tag
)
9560 if (child_die
->tag
== DW_TAG_imported_module
)
9561 process_die (child_die
, spec_cu
);
9562 child_die
= sibling_die (child_die
);
9565 /* In some cases, GCC generates specification DIEs that
9566 themselves contain DW_AT_specification attributes. */
9567 spec_die
= die_specification (spec_die
, &spec_cu
);
9571 new = pop_context ();
9572 /* Make a block for the local symbols within. */
9573 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
9574 lowpc
, highpc
, objfile
);
9576 /* For C++, set the block's scope. */
9577 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
9578 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
9579 determine_prefix (die
, cu
),
9580 processing_has_namespace_info
);
9582 /* If we have address ranges, record them. */
9583 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9585 /* Attach template arguments to function. */
9586 if (! VEC_empty (symbolp
, template_args
))
9588 gdb_assert (templ_func
!= NULL
);
9590 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
9591 templ_func
->template_arguments
9592 = obstack_alloc (&objfile
->objfile_obstack
,
9593 (templ_func
->n_template_arguments
9594 * sizeof (struct symbol
*)));
9595 memcpy (templ_func
->template_arguments
,
9596 VEC_address (symbolp
, template_args
),
9597 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
9598 VEC_free (symbolp
, template_args
);
9601 /* In C++, we can have functions nested inside functions (e.g., when
9602 a function declares a class that has methods). This means that
9603 when we finish processing a function scope, we may need to go
9604 back to building a containing block's symbol lists. */
9605 local_symbols
= new->locals
;
9606 using_directives
= new->using_directives
;
9608 /* If we've finished processing a top-level function, subsequent
9609 symbols go in the file symbol list. */
9610 if (outermost_context_p ())
9611 cu
->list_in_scope
= &file_symbols
;
9614 /* Process all the DIES contained within a lexical block scope. Start
9615 a new scope, process the dies, and then close the scope. */
9618 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9620 struct objfile
*objfile
= cu
->objfile
;
9621 struct context_stack
*new;
9622 CORE_ADDR lowpc
, highpc
;
9623 struct die_info
*child_die
;
9626 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9628 /* Ignore blocks with missing or invalid low and high pc attributes. */
9629 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
9630 as multiple lexical blocks? Handling children in a sane way would
9631 be nasty. Might be easier to properly extend generic blocks to
9633 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9638 push_context (0, lowpc
);
9639 if (die
->child
!= NULL
)
9641 child_die
= die
->child
;
9642 while (child_die
&& child_die
->tag
)
9644 process_die (child_die
, cu
);
9645 child_die
= sibling_die (child_die
);
9648 new = pop_context ();
9650 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
9653 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
9656 /* Note that recording ranges after traversing children, as we
9657 do here, means that recording a parent's ranges entails
9658 walking across all its children's ranges as they appear in
9659 the address map, which is quadratic behavior.
9661 It would be nicer to record the parent's ranges before
9662 traversing its children, simply overriding whatever you find
9663 there. But since we don't even decide whether to create a
9664 block until after we've traversed its children, that's hard
9666 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9668 local_symbols
= new->locals
;
9669 using_directives
= new->using_directives
;
9672 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
9675 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9677 struct objfile
*objfile
= cu
->objfile
;
9678 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9679 CORE_ADDR pc
, baseaddr
;
9680 struct attribute
*attr
;
9681 struct call_site
*call_site
, call_site_local
;
9684 struct die_info
*child_die
;
9686 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9688 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9691 complaint (&symfile_complaints
,
9692 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
9693 "DIE 0x%x [in module %s]"),
9694 die
->offset
.sect_off
, objfile
->name
);
9697 pc
= DW_ADDR (attr
) + baseaddr
;
9699 if (cu
->call_site_htab
== NULL
)
9700 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
9701 NULL
, &objfile
->objfile_obstack
,
9702 hashtab_obstack_allocate
, NULL
);
9703 call_site_local
.pc
= pc
;
9704 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
9707 complaint (&symfile_complaints
,
9708 _("Duplicate PC %s for DW_TAG_GNU_call_site "
9709 "DIE 0x%x [in module %s]"),
9710 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
9714 /* Count parameters at the caller. */
9717 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9718 child_die
= sibling_die (child_die
))
9720 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9722 complaint (&symfile_complaints
,
9723 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
9724 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9725 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
9732 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
9733 (sizeof (*call_site
)
9734 + (sizeof (*call_site
->parameter
)
9737 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
9740 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
9742 struct die_info
*func_die
;
9744 /* Skip also over DW_TAG_inlined_subroutine. */
9745 for (func_die
= die
->parent
;
9746 func_die
&& func_die
->tag
!= DW_TAG_subprogram
9747 && func_die
->tag
!= DW_TAG_subroutine_type
;
9748 func_die
= func_die
->parent
);
9750 /* DW_AT_GNU_all_call_sites is a superset
9751 of DW_AT_GNU_all_tail_call_sites. */
9753 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
9754 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
9756 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
9757 not complete. But keep CALL_SITE for look ups via call_site_htab,
9758 both the initial caller containing the real return address PC and
9759 the final callee containing the current PC of a chain of tail
9760 calls do not need to have the tail call list complete. But any
9761 function candidate for a virtual tail call frame searched via
9762 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
9763 determined unambiguously. */
9767 struct type
*func_type
= NULL
;
9770 func_type
= get_die_type (func_die
, cu
);
9771 if (func_type
!= NULL
)
9773 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
9775 /* Enlist this call site to the function. */
9776 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
9777 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
9780 complaint (&symfile_complaints
,
9781 _("Cannot find function owning DW_TAG_GNU_call_site "
9782 "DIE 0x%x [in module %s]"),
9783 die
->offset
.sect_off
, objfile
->name
);
9787 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
9789 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9790 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
9791 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
9792 /* Keep NULL DWARF_BLOCK. */;
9793 else if (attr_form_is_block (attr
))
9795 struct dwarf2_locexpr_baton
*dlbaton
;
9797 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
9798 dlbaton
->data
= DW_BLOCK (attr
)->data
;
9799 dlbaton
->size
= DW_BLOCK (attr
)->size
;
9800 dlbaton
->per_cu
= cu
->per_cu
;
9802 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
9804 else if (is_ref_attr (attr
))
9806 struct dwarf2_cu
*target_cu
= cu
;
9807 struct die_info
*target_die
;
9809 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
9810 gdb_assert (target_cu
->objfile
== objfile
);
9811 if (die_is_declaration (target_die
, target_cu
))
9813 const char *target_physname
;
9815 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
9816 if (target_physname
== NULL
)
9817 complaint (&symfile_complaints
,
9818 _("DW_AT_GNU_call_site_target target DIE has invalid "
9819 "physname, for referencing DIE 0x%x [in module %s]"),
9820 die
->offset
.sect_off
, objfile
->name
);
9822 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
9828 /* DW_AT_entry_pc should be preferred. */
9829 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
9830 complaint (&symfile_complaints
,
9831 _("DW_AT_GNU_call_site_target target DIE has invalid "
9832 "low pc, for referencing DIE 0x%x [in module %s]"),
9833 die
->offset
.sect_off
, objfile
->name
);
9835 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
9839 complaint (&symfile_complaints
,
9840 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
9841 "block nor reference, for DIE 0x%x [in module %s]"),
9842 die
->offset
.sect_off
, objfile
->name
);
9844 call_site
->per_cu
= cu
->per_cu
;
9846 for (child_die
= die
->child
;
9847 child_die
&& child_die
->tag
;
9848 child_die
= sibling_die (child_die
))
9850 struct call_site_parameter
*parameter
;
9851 struct attribute
*loc
, *origin
;
9853 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9855 /* Already printed the complaint above. */
9859 gdb_assert (call_site
->parameter_count
< nparams
);
9860 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
9862 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
9863 specifies DW_TAG_formal_parameter. Value of the data assumed for the
9864 register is contained in DW_AT_GNU_call_site_value. */
9866 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
9867 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
9868 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
9872 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
9873 offset
= dwarf2_get_ref_die_offset (origin
);
9874 if (!offset_in_cu_p (&cu
->header
, offset
))
9876 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
9877 binding can be done only inside one CU. Such referenced DIE
9878 therefore cannot be even moved to DW_TAG_partial_unit. */
9879 complaint (&symfile_complaints
,
9880 _("DW_AT_abstract_origin offset is not in CU for "
9881 "DW_TAG_GNU_call_site child DIE 0x%x "
9883 child_die
->offset
.sect_off
, objfile
->name
);
9886 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
9887 - cu
->header
.offset
.sect_off
);
9889 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
9891 complaint (&symfile_complaints
,
9892 _("No DW_FORM_block* DW_AT_location for "
9893 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9894 child_die
->offset
.sect_off
, objfile
->name
);
9899 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
9900 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
9901 if (parameter
->u
.dwarf_reg
!= -1)
9902 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
9903 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
9904 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
9905 ¶meter
->u
.fb_offset
))
9906 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
9909 complaint (&symfile_complaints
,
9910 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
9911 "for DW_FORM_block* DW_AT_location is supported for "
9912 "DW_TAG_GNU_call_site child DIE 0x%x "
9914 child_die
->offset
.sect_off
, objfile
->name
);
9919 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
9920 if (!attr_form_is_block (attr
))
9922 complaint (&symfile_complaints
,
9923 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9924 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9925 child_die
->offset
.sect_off
, objfile
->name
);
9928 parameter
->value
= DW_BLOCK (attr
)->data
;
9929 parameter
->value_size
= DW_BLOCK (attr
)->size
;
9931 /* Parameters are not pre-cleared by memset above. */
9932 parameter
->data_value
= NULL
;
9933 parameter
->data_value_size
= 0;
9934 call_site
->parameter_count
++;
9936 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
9939 if (!attr_form_is_block (attr
))
9940 complaint (&symfile_complaints
,
9941 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9942 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9943 child_die
->offset
.sect_off
, objfile
->name
);
9946 parameter
->data_value
= DW_BLOCK (attr
)->data
;
9947 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
9953 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9954 Return 1 if the attributes are present and valid, otherwise, return 0.
9955 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9958 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
9959 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
9960 struct partial_symtab
*ranges_pst
)
9962 struct objfile
*objfile
= cu
->objfile
;
9963 struct comp_unit_head
*cu_header
= &cu
->header
;
9964 bfd
*obfd
= objfile
->obfd
;
9965 unsigned int addr_size
= cu_header
->addr_size
;
9966 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9967 /* Base address selection entry. */
9978 found_base
= cu
->base_known
;
9979 base
= cu
->base_address
;
9981 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9982 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9984 complaint (&symfile_complaints
,
9985 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9989 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9991 /* Read in the largest possible address. */
9992 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
9993 if ((marker
& mask
) == mask
)
9995 /* If we found the largest possible address, then
9996 read the base address. */
9997 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9998 buffer
+= 2 * addr_size
;
9999 offset
+= 2 * addr_size
;
10005 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10009 CORE_ADDR range_beginning
, range_end
;
10011 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
10012 buffer
+= addr_size
;
10013 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
10014 buffer
+= addr_size
;
10015 offset
+= 2 * addr_size
;
10017 /* An end of list marker is a pair of zero addresses. */
10018 if (range_beginning
== 0 && range_end
== 0)
10019 /* Found the end of list entry. */
10022 /* Each base address selection entry is a pair of 2 values.
10023 The first is the largest possible address, the second is
10024 the base address. Check for a base address here. */
10025 if ((range_beginning
& mask
) == mask
)
10027 /* If we found the largest possible address, then
10028 read the base address. */
10029 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
10036 /* We have no valid base address for the ranges
10038 complaint (&symfile_complaints
,
10039 _("Invalid .debug_ranges data (no base address)"));
10043 if (range_beginning
> range_end
)
10045 /* Inverted range entries are invalid. */
10046 complaint (&symfile_complaints
,
10047 _("Invalid .debug_ranges data (inverted range)"));
10051 /* Empty range entries have no effect. */
10052 if (range_beginning
== range_end
)
10055 range_beginning
+= base
;
10058 /* A not-uncommon case of bad debug info.
10059 Don't pollute the addrmap with bad data. */
10060 if (range_beginning
+ baseaddr
== 0
10061 && !dwarf2_per_objfile
->has_section_at_zero
)
10063 complaint (&symfile_complaints
,
10064 _(".debug_ranges entry has start address of zero"
10065 " [in module %s]"), objfile
->name
);
10069 if (ranges_pst
!= NULL
)
10070 addrmap_set_empty (objfile
->psymtabs_addrmap
,
10071 range_beginning
+ baseaddr
,
10072 range_end
- 1 + baseaddr
,
10075 /* FIXME: This is recording everything as a low-high
10076 segment of consecutive addresses. We should have a
10077 data structure for discontiguous block ranges
10081 low
= range_beginning
;
10087 if (range_beginning
< low
)
10088 low
= range_beginning
;
10089 if (range_end
> high
)
10095 /* If the first entry is an end-of-list marker, the range
10096 describes an empty scope, i.e. no instructions. */
10102 *high_return
= high
;
10106 /* Get low and high pc attributes from a die. Return 1 if the attributes
10107 are present and valid, otherwise, return 0. Return -1 if the range is
10108 discontinuous, i.e. derived from DW_AT_ranges information. */
10111 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
10112 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
10113 struct partial_symtab
*pst
)
10115 struct attribute
*attr
;
10116 struct attribute
*attr_high
;
10118 CORE_ADDR high
= 0;
10121 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10124 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10127 low
= DW_ADDR (attr
);
10128 if (attr_high
->form
== DW_FORM_addr
10129 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10130 high
= DW_ADDR (attr_high
);
10132 high
= low
+ DW_UNSND (attr_high
);
10135 /* Found high w/o low attribute. */
10138 /* Found consecutive range of addresses. */
10143 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10146 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10147 We take advantage of the fact that DW_AT_ranges does not appear
10148 in DW_TAG_compile_unit of DWO files. */
10149 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
10150 unsigned int ranges_offset
= (DW_UNSND (attr
)
10151 + (need_ranges_base
10155 /* Value of the DW_AT_ranges attribute is the offset in the
10156 .debug_ranges section. */
10157 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
10159 /* Found discontinuous range of addresses. */
10164 /* read_partial_die has also the strict LOW < HIGH requirement. */
10168 /* When using the GNU linker, .gnu.linkonce. sections are used to
10169 eliminate duplicate copies of functions and vtables and such.
10170 The linker will arbitrarily choose one and discard the others.
10171 The AT_*_pc values for such functions refer to local labels in
10172 these sections. If the section from that file was discarded, the
10173 labels are not in the output, so the relocs get a value of 0.
10174 If this is a discarded function, mark the pc bounds as invalid,
10175 so that GDB will ignore it. */
10176 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10185 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
10186 its low and high PC addresses. Do nothing if these addresses could not
10187 be determined. Otherwise, set LOWPC to the low address if it is smaller,
10188 and HIGHPC to the high address if greater than HIGHPC. */
10191 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
10192 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10193 struct dwarf2_cu
*cu
)
10195 CORE_ADDR low
, high
;
10196 struct die_info
*child
= die
->child
;
10198 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
10200 *lowpc
= min (*lowpc
, low
);
10201 *highpc
= max (*highpc
, high
);
10204 /* If the language does not allow nested subprograms (either inside
10205 subprograms or lexical blocks), we're done. */
10206 if (cu
->language
!= language_ada
)
10209 /* Check all the children of the given DIE. If it contains nested
10210 subprograms, then check their pc bounds. Likewise, we need to
10211 check lexical blocks as well, as they may also contain subprogram
10213 while (child
&& child
->tag
)
10215 if (child
->tag
== DW_TAG_subprogram
10216 || child
->tag
== DW_TAG_lexical_block
)
10217 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
10218 child
= sibling_die (child
);
10222 /* Get the low and high pc's represented by the scope DIE, and store
10223 them in *LOWPC and *HIGHPC. If the correct values can't be
10224 determined, set *LOWPC to -1 and *HIGHPC to 0. */
10227 get_scope_pc_bounds (struct die_info
*die
,
10228 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10229 struct dwarf2_cu
*cu
)
10231 CORE_ADDR best_low
= (CORE_ADDR
) -1;
10232 CORE_ADDR best_high
= (CORE_ADDR
) 0;
10233 CORE_ADDR current_low
, current_high
;
10235 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
10237 best_low
= current_low
;
10238 best_high
= current_high
;
10242 struct die_info
*child
= die
->child
;
10244 while (child
&& child
->tag
)
10246 switch (child
->tag
) {
10247 case DW_TAG_subprogram
:
10248 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
10250 case DW_TAG_namespace
:
10251 case DW_TAG_module
:
10252 /* FIXME: carlton/2004-01-16: Should we do this for
10253 DW_TAG_class_type/DW_TAG_structure_type, too? I think
10254 that current GCC's always emit the DIEs corresponding
10255 to definitions of methods of classes as children of a
10256 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
10257 the DIEs giving the declarations, which could be
10258 anywhere). But I don't see any reason why the
10259 standards says that they have to be there. */
10260 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
10262 if (current_low
!= ((CORE_ADDR
) -1))
10264 best_low
= min (best_low
, current_low
);
10265 best_high
= max (best_high
, current_high
);
10273 child
= sibling_die (child
);
10278 *highpc
= best_high
;
10281 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
10285 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
10286 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
10288 struct objfile
*objfile
= cu
->objfile
;
10289 struct attribute
*attr
;
10290 struct attribute
*attr_high
;
10292 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10295 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10298 CORE_ADDR low
= DW_ADDR (attr
);
10300 if (attr_high
->form
== DW_FORM_addr
10301 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10302 high
= DW_ADDR (attr_high
);
10304 high
= low
+ DW_UNSND (attr_high
);
10306 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
10310 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10313 bfd
*obfd
= objfile
->obfd
;
10314 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10315 We take advantage of the fact that DW_AT_ranges does not appear
10316 in DW_TAG_compile_unit of DWO files. */
10317 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
10319 /* The value of the DW_AT_ranges attribute is the offset of the
10320 address range list in the .debug_ranges section. */
10321 unsigned long offset
= (DW_UNSND (attr
)
10322 + (need_ranges_base
? cu
->ranges_base
: 0));
10323 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
10325 /* For some target architectures, but not others, the
10326 read_address function sign-extends the addresses it returns.
10327 To recognize base address selection entries, we need a
10329 unsigned int addr_size
= cu
->header
.addr_size
;
10330 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
10332 /* The base address, to which the next pair is relative. Note
10333 that this 'base' is a DWARF concept: most entries in a range
10334 list are relative, to reduce the number of relocs against the
10335 debugging information. This is separate from this function's
10336 'baseaddr' argument, which GDB uses to relocate debugging
10337 information from a shared library based on the address at
10338 which the library was loaded. */
10339 CORE_ADDR base
= cu
->base_address
;
10340 int base_known
= cu
->base_known
;
10342 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
10343 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
10345 complaint (&symfile_complaints
,
10346 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
10353 unsigned int bytes_read
;
10354 CORE_ADDR start
, end
;
10356 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10357 buffer
+= bytes_read
;
10358 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10359 buffer
+= bytes_read
;
10361 /* Did we find the end of the range list? */
10362 if (start
== 0 && end
== 0)
10365 /* Did we find a base address selection entry? */
10366 else if ((start
& base_select_mask
) == base_select_mask
)
10372 /* We found an ordinary address range. */
10377 complaint (&symfile_complaints
,
10378 _("Invalid .debug_ranges data "
10379 "(no base address)"));
10385 /* Inverted range entries are invalid. */
10386 complaint (&symfile_complaints
,
10387 _("Invalid .debug_ranges data "
10388 "(inverted range)"));
10392 /* Empty range entries have no effect. */
10396 start
+= base
+ baseaddr
;
10397 end
+= base
+ baseaddr
;
10399 /* A not-uncommon case of bad debug info.
10400 Don't pollute the addrmap with bad data. */
10401 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10403 complaint (&symfile_complaints
,
10404 _(".debug_ranges entry has start address of zero"
10405 " [in module %s]"), objfile
->name
);
10409 record_block_range (block
, start
, end
- 1);
10415 /* Check whether the producer field indicates either of GCC < 4.6, or the
10416 Intel C/C++ compiler, and cache the result in CU. */
10419 check_producer (struct dwarf2_cu
*cu
)
10422 int major
, minor
, release
;
10424 if (cu
->producer
== NULL
)
10426 /* For unknown compilers expect their behavior is DWARF version
10429 GCC started to support .debug_types sections by -gdwarf-4 since
10430 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
10431 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
10432 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
10433 interpreted incorrectly by GDB now - GCC PR debug/48229. */
10435 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
10437 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
10439 cs
= &cu
->producer
[strlen ("GNU ")];
10440 while (*cs
&& !isdigit (*cs
))
10442 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
10444 /* Not recognized as GCC. */
10448 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
10449 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
10452 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
10453 cu
->producer_is_icc
= 1;
10456 /* For other non-GCC compilers, expect their behavior is DWARF version
10460 cu
->checked_producer
= 1;
10463 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
10464 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
10465 during 4.6.0 experimental. */
10468 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
10470 if (!cu
->checked_producer
)
10471 check_producer (cu
);
10473 return cu
->producer_is_gxx_lt_4_6
;
10476 /* Return the default accessibility type if it is not overriden by
10477 DW_AT_accessibility. */
10479 static enum dwarf_access_attribute
10480 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
10482 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
10484 /* The default DWARF 2 accessibility for members is public, the default
10485 accessibility for inheritance is private. */
10487 if (die
->tag
!= DW_TAG_inheritance
)
10488 return DW_ACCESS_public
;
10490 return DW_ACCESS_private
;
10494 /* DWARF 3+ defines the default accessibility a different way. The same
10495 rules apply now for DW_TAG_inheritance as for the members and it only
10496 depends on the container kind. */
10498 if (die
->parent
->tag
== DW_TAG_class_type
)
10499 return DW_ACCESS_private
;
10501 return DW_ACCESS_public
;
10505 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
10506 offset. If the attribute was not found return 0, otherwise return
10507 1. If it was found but could not properly be handled, set *OFFSET
10511 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
10514 struct attribute
*attr
;
10516 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
10521 /* Note that we do not check for a section offset first here.
10522 This is because DW_AT_data_member_location is new in DWARF 4,
10523 so if we see it, we can assume that a constant form is really
10524 a constant and not a section offset. */
10525 if (attr_form_is_constant (attr
))
10526 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
10527 else if (attr_form_is_section_offset (attr
))
10528 dwarf2_complex_location_expr_complaint ();
10529 else if (attr_form_is_block (attr
))
10530 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10532 dwarf2_complex_location_expr_complaint ();
10540 /* Add an aggregate field to the field list. */
10543 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
10544 struct dwarf2_cu
*cu
)
10546 struct objfile
*objfile
= cu
->objfile
;
10547 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10548 struct nextfield
*new_field
;
10549 struct attribute
*attr
;
10551 char *fieldname
= "";
10553 /* Allocate a new field list entry and link it in. */
10554 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
10555 make_cleanup (xfree
, new_field
);
10556 memset (new_field
, 0, sizeof (struct nextfield
));
10558 if (die
->tag
== DW_TAG_inheritance
)
10560 new_field
->next
= fip
->baseclasses
;
10561 fip
->baseclasses
= new_field
;
10565 new_field
->next
= fip
->fields
;
10566 fip
->fields
= new_field
;
10570 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10572 new_field
->accessibility
= DW_UNSND (attr
);
10574 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
10575 if (new_field
->accessibility
!= DW_ACCESS_public
)
10576 fip
->non_public_fields
= 1;
10578 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10580 new_field
->virtuality
= DW_UNSND (attr
);
10582 new_field
->virtuality
= DW_VIRTUALITY_none
;
10584 fp
= &new_field
->field
;
10586 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
10590 /* Data member other than a C++ static data member. */
10592 /* Get type of field. */
10593 fp
->type
= die_type (die
, cu
);
10595 SET_FIELD_BITPOS (*fp
, 0);
10597 /* Get bit size of field (zero if none). */
10598 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
10601 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
10605 FIELD_BITSIZE (*fp
) = 0;
10608 /* Get bit offset of field. */
10609 if (handle_data_member_location (die
, cu
, &offset
))
10610 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10611 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
10614 if (gdbarch_bits_big_endian (gdbarch
))
10616 /* For big endian bits, the DW_AT_bit_offset gives the
10617 additional bit offset from the MSB of the containing
10618 anonymous object to the MSB of the field. We don't
10619 have to do anything special since we don't need to
10620 know the size of the anonymous object. */
10621 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
10625 /* For little endian bits, compute the bit offset to the
10626 MSB of the anonymous object, subtract off the number of
10627 bits from the MSB of the field to the MSB of the
10628 object, and then subtract off the number of bits of
10629 the field itself. The result is the bit offset of
10630 the LSB of the field. */
10631 int anonymous_size
;
10632 int bit_offset
= DW_UNSND (attr
);
10634 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10637 /* The size of the anonymous object containing
10638 the bit field is explicit, so use the
10639 indicated size (in bytes). */
10640 anonymous_size
= DW_UNSND (attr
);
10644 /* The size of the anonymous object containing
10645 the bit field must be inferred from the type
10646 attribute of the data member containing the
10648 anonymous_size
= TYPE_LENGTH (fp
->type
);
10650 SET_FIELD_BITPOS (*fp
,
10651 (FIELD_BITPOS (*fp
)
10652 + anonymous_size
* bits_per_byte
10653 - bit_offset
- FIELD_BITSIZE (*fp
)));
10657 /* Get name of field. */
10658 fieldname
= dwarf2_name (die
, cu
);
10659 if (fieldname
== NULL
)
10662 /* The name is already allocated along with this objfile, so we don't
10663 need to duplicate it for the type. */
10664 fp
->name
= fieldname
;
10666 /* Change accessibility for artificial fields (e.g. virtual table
10667 pointer or virtual base class pointer) to private. */
10668 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
10670 FIELD_ARTIFICIAL (*fp
) = 1;
10671 new_field
->accessibility
= DW_ACCESS_private
;
10672 fip
->non_public_fields
= 1;
10675 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
10677 /* C++ static member. */
10679 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
10680 is a declaration, but all versions of G++ as of this writing
10681 (so through at least 3.2.1) incorrectly generate
10682 DW_TAG_variable tags. */
10684 const char *physname
;
10686 /* Get name of field. */
10687 fieldname
= dwarf2_name (die
, cu
);
10688 if (fieldname
== NULL
)
10691 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10693 /* Only create a symbol if this is an external value.
10694 new_symbol checks this and puts the value in the global symbol
10695 table, which we want. If it is not external, new_symbol
10696 will try to put the value in cu->list_in_scope which is wrong. */
10697 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
10699 /* A static const member, not much different than an enum as far as
10700 we're concerned, except that we can support more types. */
10701 new_symbol (die
, NULL
, cu
);
10704 /* Get physical name. */
10705 physname
= dwarf2_physname (fieldname
, die
, cu
);
10707 /* The name is already allocated along with this objfile, so we don't
10708 need to duplicate it for the type. */
10709 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
10710 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10711 FIELD_NAME (*fp
) = fieldname
;
10713 else if (die
->tag
== DW_TAG_inheritance
)
10717 /* C++ base class field. */
10718 if (handle_data_member_location (die
, cu
, &offset
))
10719 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10720 FIELD_BITSIZE (*fp
) = 0;
10721 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10722 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
10723 fip
->nbaseclasses
++;
10727 /* Add a typedef defined in the scope of the FIP's class. */
10730 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
10731 struct dwarf2_cu
*cu
)
10733 struct objfile
*objfile
= cu
->objfile
;
10734 struct typedef_field_list
*new_field
;
10735 struct attribute
*attr
;
10736 struct typedef_field
*fp
;
10737 char *fieldname
= "";
10739 /* Allocate a new field list entry and link it in. */
10740 new_field
= xzalloc (sizeof (*new_field
));
10741 make_cleanup (xfree
, new_field
);
10743 gdb_assert (die
->tag
== DW_TAG_typedef
);
10745 fp
= &new_field
->field
;
10747 /* Get name of field. */
10748 fp
->name
= dwarf2_name (die
, cu
);
10749 if (fp
->name
== NULL
)
10752 fp
->type
= read_type_die (die
, cu
);
10754 new_field
->next
= fip
->typedef_field_list
;
10755 fip
->typedef_field_list
= new_field
;
10756 fip
->typedef_field_list_count
++;
10759 /* Create the vector of fields, and attach it to the type. */
10762 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
10763 struct dwarf2_cu
*cu
)
10765 int nfields
= fip
->nfields
;
10767 /* Record the field count, allocate space for the array of fields,
10768 and create blank accessibility bitfields if necessary. */
10769 TYPE_NFIELDS (type
) = nfields
;
10770 TYPE_FIELDS (type
) = (struct field
*)
10771 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
10772 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
10774 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
10776 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10778 TYPE_FIELD_PRIVATE_BITS (type
) =
10779 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10780 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
10782 TYPE_FIELD_PROTECTED_BITS (type
) =
10783 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10784 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
10786 TYPE_FIELD_IGNORE_BITS (type
) =
10787 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10788 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
10791 /* If the type has baseclasses, allocate and clear a bit vector for
10792 TYPE_FIELD_VIRTUAL_BITS. */
10793 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
10795 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
10796 unsigned char *pointer
;
10798 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10799 pointer
= TYPE_ALLOC (type
, num_bytes
);
10800 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
10801 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
10802 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
10805 /* Copy the saved-up fields into the field vector. Start from the head of
10806 the list, adding to the tail of the field array, so that they end up in
10807 the same order in the array in which they were added to the list. */
10808 while (nfields
-- > 0)
10810 struct nextfield
*fieldp
;
10814 fieldp
= fip
->fields
;
10815 fip
->fields
= fieldp
->next
;
10819 fieldp
= fip
->baseclasses
;
10820 fip
->baseclasses
= fieldp
->next
;
10823 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
10824 switch (fieldp
->accessibility
)
10826 case DW_ACCESS_private
:
10827 if (cu
->language
!= language_ada
)
10828 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
10831 case DW_ACCESS_protected
:
10832 if (cu
->language
!= language_ada
)
10833 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
10836 case DW_ACCESS_public
:
10840 /* Unknown accessibility. Complain and treat it as public. */
10842 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
10843 fieldp
->accessibility
);
10847 if (nfields
< fip
->nbaseclasses
)
10849 switch (fieldp
->virtuality
)
10851 case DW_VIRTUALITY_virtual
:
10852 case DW_VIRTUALITY_pure_virtual
:
10853 if (cu
->language
== language_ada
)
10854 error (_("unexpected virtuality in component of Ada type"));
10855 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
10862 /* Return true if this member function is a constructor, false
10866 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
10868 const char *fieldname
;
10869 const char *typename
;
10872 if (die
->parent
== NULL
)
10875 if (die
->parent
->tag
!= DW_TAG_structure_type
10876 && die
->parent
->tag
!= DW_TAG_union_type
10877 && die
->parent
->tag
!= DW_TAG_class_type
)
10880 fieldname
= dwarf2_name (die
, cu
);
10881 typename
= dwarf2_name (die
->parent
, cu
);
10882 if (fieldname
== NULL
|| typename
== NULL
)
10885 len
= strlen (fieldname
);
10886 return (strncmp (fieldname
, typename
, len
) == 0
10887 && (typename
[len
] == '\0' || typename
[len
] == '<'));
10890 /* Add a member function to the proper fieldlist. */
10893 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
10894 struct type
*type
, struct dwarf2_cu
*cu
)
10896 struct objfile
*objfile
= cu
->objfile
;
10897 struct attribute
*attr
;
10898 struct fnfieldlist
*flp
;
10900 struct fn_field
*fnp
;
10902 struct nextfnfield
*new_fnfield
;
10903 struct type
*this_type
;
10904 enum dwarf_access_attribute accessibility
;
10906 if (cu
->language
== language_ada
)
10907 error (_("unexpected member function in Ada type"));
10909 /* Get name of member function. */
10910 fieldname
= dwarf2_name (die
, cu
);
10911 if (fieldname
== NULL
)
10914 /* Look up member function name in fieldlist. */
10915 for (i
= 0; i
< fip
->nfnfields
; i
++)
10917 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
10921 /* Create new list element if necessary. */
10922 if (i
< fip
->nfnfields
)
10923 flp
= &fip
->fnfieldlists
[i
];
10926 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10928 fip
->fnfieldlists
= (struct fnfieldlist
*)
10929 xrealloc (fip
->fnfieldlists
,
10930 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
10931 * sizeof (struct fnfieldlist
));
10932 if (fip
->nfnfields
== 0)
10933 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
10935 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
10936 flp
->name
= fieldname
;
10939 i
= fip
->nfnfields
++;
10942 /* Create a new member function field and chain it to the field list
10944 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
10945 make_cleanup (xfree
, new_fnfield
);
10946 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
10947 new_fnfield
->next
= flp
->head
;
10948 flp
->head
= new_fnfield
;
10951 /* Fill in the member function field info. */
10952 fnp
= &new_fnfield
->fnfield
;
10954 /* Delay processing of the physname until later. */
10955 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
10957 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
10962 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
10963 fnp
->physname
= physname
? physname
: "";
10966 fnp
->type
= alloc_type (objfile
);
10967 this_type
= read_type_die (die
, cu
);
10968 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
10970 int nparams
= TYPE_NFIELDS (this_type
);
10972 /* TYPE is the domain of this method, and THIS_TYPE is the type
10973 of the method itself (TYPE_CODE_METHOD). */
10974 smash_to_method_type (fnp
->type
, type
,
10975 TYPE_TARGET_TYPE (this_type
),
10976 TYPE_FIELDS (this_type
),
10977 TYPE_NFIELDS (this_type
),
10978 TYPE_VARARGS (this_type
));
10980 /* Handle static member functions.
10981 Dwarf2 has no clean way to discern C++ static and non-static
10982 member functions. G++ helps GDB by marking the first
10983 parameter for non-static member functions (which is the this
10984 pointer) as artificial. We obtain this information from
10985 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10986 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
10987 fnp
->voffset
= VOFFSET_STATIC
;
10990 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
10991 dwarf2_full_name (fieldname
, die
, cu
));
10993 /* Get fcontext from DW_AT_containing_type if present. */
10994 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10995 fnp
->fcontext
= die_containing_type (die
, cu
);
10997 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
10998 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
11000 /* Get accessibility. */
11001 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
11003 accessibility
= DW_UNSND (attr
);
11005 accessibility
= dwarf2_default_access_attribute (die
, cu
);
11006 switch (accessibility
)
11008 case DW_ACCESS_private
:
11009 fnp
->is_private
= 1;
11011 case DW_ACCESS_protected
:
11012 fnp
->is_protected
= 1;
11016 /* Check for artificial methods. */
11017 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
11018 if (attr
&& DW_UNSND (attr
) != 0)
11019 fnp
->is_artificial
= 1;
11021 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
11023 /* Get index in virtual function table if it is a virtual member
11024 function. For older versions of GCC, this is an offset in the
11025 appropriate virtual table, as specified by DW_AT_containing_type.
11026 For everyone else, it is an expression to be evaluated relative
11027 to the object address. */
11029 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
11032 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
11034 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
11036 /* Old-style GCC. */
11037 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
11039 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
11040 || (DW_BLOCK (attr
)->size
> 1
11041 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
11042 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
11044 struct dwarf_block blk
;
11047 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
11049 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
11050 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
11051 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
11052 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
11053 dwarf2_complex_location_expr_complaint ();
11055 fnp
->voffset
/= cu
->header
.addr_size
;
11059 dwarf2_complex_location_expr_complaint ();
11061 if (!fnp
->fcontext
)
11062 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
11064 else if (attr_form_is_section_offset (attr
))
11066 dwarf2_complex_location_expr_complaint ();
11070 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
11076 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
11077 if (attr
&& DW_UNSND (attr
))
11079 /* GCC does this, as of 2008-08-25; PR debug/37237. */
11080 complaint (&symfile_complaints
,
11081 _("Member function \"%s\" (offset %d) is virtual "
11082 "but the vtable offset is not specified"),
11083 fieldname
, die
->offset
.sect_off
);
11084 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11085 TYPE_CPLUS_DYNAMIC (type
) = 1;
11090 /* Create the vector of member function fields, and attach it to the type. */
11093 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
11094 struct dwarf2_cu
*cu
)
11096 struct fnfieldlist
*flp
;
11099 if (cu
->language
== language_ada
)
11100 error (_("unexpected member functions in Ada type"));
11102 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11103 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
11104 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
11106 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
11108 struct nextfnfield
*nfp
= flp
->head
;
11109 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
11112 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
11113 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
11114 fn_flp
->fn_fields
= (struct fn_field
*)
11115 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
11116 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
11117 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
11120 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
11123 /* Returns non-zero if NAME is the name of a vtable member in CU's
11124 language, zero otherwise. */
11126 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
11128 static const char vptr
[] = "_vptr";
11129 static const char vtable
[] = "vtable";
11131 /* Look for the C++ and Java forms of the vtable. */
11132 if ((cu
->language
== language_java
11133 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
11134 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
11135 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
11141 /* GCC outputs unnamed structures that are really pointers to member
11142 functions, with the ABI-specified layout. If TYPE describes
11143 such a structure, smash it into a member function type.
11145 GCC shouldn't do this; it should just output pointer to member DIEs.
11146 This is GCC PR debug/28767. */
11149 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
11151 struct type
*pfn_type
, *domain_type
, *new_type
;
11153 /* Check for a structure with no name and two children. */
11154 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
11157 /* Check for __pfn and __delta members. */
11158 if (TYPE_FIELD_NAME (type
, 0) == NULL
11159 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
11160 || TYPE_FIELD_NAME (type
, 1) == NULL
11161 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
11164 /* Find the type of the method. */
11165 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
11166 if (pfn_type
== NULL
11167 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
11168 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
11171 /* Look for the "this" argument. */
11172 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
11173 if (TYPE_NFIELDS (pfn_type
) == 0
11174 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
11175 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
11178 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
11179 new_type
= alloc_type (objfile
);
11180 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
11181 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
11182 TYPE_VARARGS (pfn_type
));
11183 smash_to_methodptr_type (type
, new_type
);
11186 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
11190 producer_is_icc (struct dwarf2_cu
*cu
)
11192 if (!cu
->checked_producer
)
11193 check_producer (cu
);
11195 return cu
->producer_is_icc
;
11198 /* Called when we find the DIE that starts a structure or union scope
11199 (definition) to create a type for the structure or union. Fill in
11200 the type's name and general properties; the members will not be
11201 processed until process_structure_type.
11203 NOTE: we need to call these functions regardless of whether or not the
11204 DIE has a DW_AT_name attribute, since it might be an anonymous
11205 structure or union. This gets the type entered into our set of
11206 user defined types.
11208 However, if the structure is incomplete (an opaque struct/union)
11209 then suppress creating a symbol table entry for it since gdb only
11210 wants to find the one with the complete definition. Note that if
11211 it is complete, we just call new_symbol, which does it's own
11212 checking about whether the struct/union is anonymous or not (and
11213 suppresses creating a symbol table entry itself). */
11215 static struct type
*
11216 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11218 struct objfile
*objfile
= cu
->objfile
;
11220 struct attribute
*attr
;
11223 /* If the definition of this type lives in .debug_types, read that type.
11224 Don't follow DW_AT_specification though, that will take us back up
11225 the chain and we want to go down. */
11226 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11229 struct dwarf2_cu
*type_cu
= cu
;
11230 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11232 /* We could just recurse on read_structure_type, but we need to call
11233 get_die_type to ensure only one type for this DIE is created.
11234 This is important, for example, because for c++ classes we need
11235 TYPE_NAME set which is only done by new_symbol. Blech. */
11236 type
= read_type_die (type_die
, type_cu
);
11238 /* TYPE_CU may not be the same as CU.
11239 Ensure TYPE is recorded in CU's type_hash table. */
11240 return set_die_type (die
, type
, cu
);
11243 type
= alloc_type (objfile
);
11244 INIT_CPLUS_SPECIFIC (type
);
11246 name
= dwarf2_name (die
, cu
);
11249 if (cu
->language
== language_cplus
11250 || cu
->language
== language_java
)
11252 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
11254 /* dwarf2_full_name might have already finished building the DIE's
11255 type. If so, there is no need to continue. */
11256 if (get_die_type (die
, cu
) != NULL
)
11257 return get_die_type (die
, cu
);
11259 TYPE_TAG_NAME (type
) = full_name
;
11260 if (die
->tag
== DW_TAG_structure_type
11261 || die
->tag
== DW_TAG_class_type
)
11262 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11266 /* The name is already allocated along with this objfile, so
11267 we don't need to duplicate it for the type. */
11268 TYPE_TAG_NAME (type
) = (char *) name
;
11269 if (die
->tag
== DW_TAG_class_type
)
11270 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11274 if (die
->tag
== DW_TAG_structure_type
)
11276 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
11278 else if (die
->tag
== DW_TAG_union_type
)
11280 TYPE_CODE (type
) = TYPE_CODE_UNION
;
11284 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
11287 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
11288 TYPE_DECLARED_CLASS (type
) = 1;
11290 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11293 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11297 TYPE_LENGTH (type
) = 0;
11300 if (producer_is_icc (cu
))
11302 /* ICC does not output the required DW_AT_declaration
11303 on incomplete types, but gives them a size of zero. */
11306 TYPE_STUB_SUPPORTED (type
) = 1;
11308 if (die_is_declaration (die
, cu
))
11309 TYPE_STUB (type
) = 1;
11310 else if (attr
== NULL
&& die
->child
== NULL
11311 && producer_is_realview (cu
->producer
))
11312 /* RealView does not output the required DW_AT_declaration
11313 on incomplete types. */
11314 TYPE_STUB (type
) = 1;
11316 /* We need to add the type field to the die immediately so we don't
11317 infinitely recurse when dealing with pointers to the structure
11318 type within the structure itself. */
11319 set_die_type (die
, type
, cu
);
11321 /* set_die_type should be already done. */
11322 set_descriptive_type (type
, die
, cu
);
11327 /* Finish creating a structure or union type, including filling in
11328 its members and creating a symbol for it. */
11331 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11333 struct objfile
*objfile
= cu
->objfile
;
11334 struct die_info
*child_die
= die
->child
;
11337 type
= get_die_type (die
, cu
);
11339 type
= read_structure_type (die
, cu
);
11341 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
11343 struct field_info fi
;
11344 struct die_info
*child_die
;
11345 VEC (symbolp
) *template_args
= NULL
;
11346 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
11348 memset (&fi
, 0, sizeof (struct field_info
));
11350 child_die
= die
->child
;
11352 while (child_die
&& child_die
->tag
)
11354 if (child_die
->tag
== DW_TAG_member
11355 || child_die
->tag
== DW_TAG_variable
)
11357 /* NOTE: carlton/2002-11-05: A C++ static data member
11358 should be a DW_TAG_member that is a declaration, but
11359 all versions of G++ as of this writing (so through at
11360 least 3.2.1) incorrectly generate DW_TAG_variable
11361 tags for them instead. */
11362 dwarf2_add_field (&fi
, child_die
, cu
);
11364 else if (child_die
->tag
== DW_TAG_subprogram
)
11366 /* C++ member function. */
11367 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
11369 else if (child_die
->tag
== DW_TAG_inheritance
)
11371 /* C++ base class field. */
11372 dwarf2_add_field (&fi
, child_die
, cu
);
11374 else if (child_die
->tag
== DW_TAG_typedef
)
11375 dwarf2_add_typedef (&fi
, child_die
, cu
);
11376 else if (child_die
->tag
== DW_TAG_template_type_param
11377 || child_die
->tag
== DW_TAG_template_value_param
)
11379 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11382 VEC_safe_push (symbolp
, template_args
, arg
);
11385 child_die
= sibling_die (child_die
);
11388 /* Attach template arguments to type. */
11389 if (! VEC_empty (symbolp
, template_args
))
11391 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11392 TYPE_N_TEMPLATE_ARGUMENTS (type
)
11393 = VEC_length (symbolp
, template_args
);
11394 TYPE_TEMPLATE_ARGUMENTS (type
)
11395 = obstack_alloc (&objfile
->objfile_obstack
,
11396 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11397 * sizeof (struct symbol
*)));
11398 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
11399 VEC_address (symbolp
, template_args
),
11400 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11401 * sizeof (struct symbol
*)));
11402 VEC_free (symbolp
, template_args
);
11405 /* Attach fields and member functions to the type. */
11407 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
11410 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
11412 /* Get the type which refers to the base class (possibly this
11413 class itself) which contains the vtable pointer for the current
11414 class from the DW_AT_containing_type attribute. This use of
11415 DW_AT_containing_type is a GNU extension. */
11417 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
11419 struct type
*t
= die_containing_type (die
, cu
);
11421 TYPE_VPTR_BASETYPE (type
) = t
;
11426 /* Our own class provides vtbl ptr. */
11427 for (i
= TYPE_NFIELDS (t
) - 1;
11428 i
>= TYPE_N_BASECLASSES (t
);
11431 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
11433 if (is_vtable_name (fieldname
, cu
))
11435 TYPE_VPTR_FIELDNO (type
) = i
;
11440 /* Complain if virtual function table field not found. */
11441 if (i
< TYPE_N_BASECLASSES (t
))
11442 complaint (&symfile_complaints
,
11443 _("virtual function table pointer "
11444 "not found when defining class '%s'"),
11445 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
11450 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
11453 else if (cu
->producer
11454 && strncmp (cu
->producer
,
11455 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
11457 /* The IBM XLC compiler does not provide direct indication
11458 of the containing type, but the vtable pointer is
11459 always named __vfp. */
11463 for (i
= TYPE_NFIELDS (type
) - 1;
11464 i
>= TYPE_N_BASECLASSES (type
);
11467 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
11469 TYPE_VPTR_FIELDNO (type
) = i
;
11470 TYPE_VPTR_BASETYPE (type
) = type
;
11477 /* Copy fi.typedef_field_list linked list elements content into the
11478 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
11479 if (fi
.typedef_field_list
)
11481 int i
= fi
.typedef_field_list_count
;
11483 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11484 TYPE_TYPEDEF_FIELD_ARRAY (type
)
11485 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
11486 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
11488 /* Reverse the list order to keep the debug info elements order. */
11491 struct typedef_field
*dest
, *src
;
11493 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
11494 src
= &fi
.typedef_field_list
->field
;
11495 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
11500 do_cleanups (back_to
);
11502 if (HAVE_CPLUS_STRUCT (type
))
11503 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
11506 quirk_gcc_member_function_pointer (type
, objfile
);
11508 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
11509 snapshots) has been known to create a die giving a declaration
11510 for a class that has, as a child, a die giving a definition for a
11511 nested class. So we have to process our children even if the
11512 current die is a declaration. Normally, of course, a declaration
11513 won't have any children at all. */
11515 while (child_die
!= NULL
&& child_die
->tag
)
11517 if (child_die
->tag
== DW_TAG_member
11518 || child_die
->tag
== DW_TAG_variable
11519 || child_die
->tag
== DW_TAG_inheritance
11520 || child_die
->tag
== DW_TAG_template_value_param
11521 || child_die
->tag
== DW_TAG_template_type_param
)
11526 process_die (child_die
, cu
);
11528 child_die
= sibling_die (child_die
);
11531 /* Do not consider external references. According to the DWARF standard,
11532 these DIEs are identified by the fact that they have no byte_size
11533 attribute, and a declaration attribute. */
11534 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
11535 || !die_is_declaration (die
, cu
))
11536 new_symbol (die
, type
, cu
);
11539 /* Given a DW_AT_enumeration_type die, set its type. We do not
11540 complete the type's fields yet, or create any symbols. */
11542 static struct type
*
11543 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11545 struct objfile
*objfile
= cu
->objfile
;
11547 struct attribute
*attr
;
11550 /* If the definition of this type lives in .debug_types, read that type.
11551 Don't follow DW_AT_specification though, that will take us back up
11552 the chain and we want to go down. */
11553 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11556 struct dwarf2_cu
*type_cu
= cu
;
11557 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11559 type
= read_type_die (type_die
, type_cu
);
11561 /* TYPE_CU may not be the same as CU.
11562 Ensure TYPE is recorded in CU's type_hash table. */
11563 return set_die_type (die
, type
, cu
);
11566 type
= alloc_type (objfile
);
11568 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
11569 name
= dwarf2_full_name (NULL
, die
, cu
);
11571 TYPE_TAG_NAME (type
) = (char *) name
;
11573 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11576 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11580 TYPE_LENGTH (type
) = 0;
11583 /* The enumeration DIE can be incomplete. In Ada, any type can be
11584 declared as private in the package spec, and then defined only
11585 inside the package body. Such types are known as Taft Amendment
11586 Types. When another package uses such a type, an incomplete DIE
11587 may be generated by the compiler. */
11588 if (die_is_declaration (die
, cu
))
11589 TYPE_STUB (type
) = 1;
11591 return set_die_type (die
, type
, cu
);
11594 /* Given a pointer to a die which begins an enumeration, process all
11595 the dies that define the members of the enumeration, and create the
11596 symbol for the enumeration type.
11598 NOTE: We reverse the order of the element list. */
11601 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11603 struct type
*this_type
;
11605 this_type
= get_die_type (die
, cu
);
11606 if (this_type
== NULL
)
11607 this_type
= read_enumeration_type (die
, cu
);
11609 if (die
->child
!= NULL
)
11611 struct die_info
*child_die
;
11612 struct symbol
*sym
;
11613 struct field
*fields
= NULL
;
11614 int num_fields
= 0;
11615 int unsigned_enum
= 1;
11620 child_die
= die
->child
;
11621 while (child_die
&& child_die
->tag
)
11623 if (child_die
->tag
!= DW_TAG_enumerator
)
11625 process_die (child_die
, cu
);
11629 name
= dwarf2_name (child_die
, cu
);
11632 sym
= new_symbol (child_die
, this_type
, cu
);
11633 if (SYMBOL_VALUE (sym
) < 0)
11638 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
11641 mask
|= SYMBOL_VALUE (sym
);
11643 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
11645 fields
= (struct field
*)
11647 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
11648 * sizeof (struct field
));
11651 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
11652 FIELD_TYPE (fields
[num_fields
]) = NULL
;
11653 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
11654 FIELD_BITSIZE (fields
[num_fields
]) = 0;
11660 child_die
= sibling_die (child_die
);
11665 TYPE_NFIELDS (this_type
) = num_fields
;
11666 TYPE_FIELDS (this_type
) = (struct field
*)
11667 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
11668 memcpy (TYPE_FIELDS (this_type
), fields
,
11669 sizeof (struct field
) * num_fields
);
11673 TYPE_UNSIGNED (this_type
) = 1;
11675 TYPE_FLAG_ENUM (this_type
) = 1;
11678 /* If we are reading an enum from a .debug_types unit, and the enum
11679 is a declaration, and the enum is not the signatured type in the
11680 unit, then we do not want to add a symbol for it. Adding a
11681 symbol would in some cases obscure the true definition of the
11682 enum, giving users an incomplete type when the definition is
11683 actually available. Note that we do not want to do this for all
11684 enums which are just declarations, because C++0x allows forward
11685 enum declarations. */
11686 if (cu
->per_cu
->is_debug_types
11687 && die_is_declaration (die
, cu
))
11689 struct signatured_type
*sig_type
;
11692 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
11693 cu
->per_cu
->info_or_types_section
,
11694 cu
->per_cu
->offset
);
11695 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
11696 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
11700 new_symbol (die
, this_type
, cu
);
11703 /* Extract all information from a DW_TAG_array_type DIE and put it in
11704 the DIE's type field. For now, this only handles one dimensional
11707 static struct type
*
11708 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11710 struct objfile
*objfile
= cu
->objfile
;
11711 struct die_info
*child_die
;
11713 struct type
*element_type
, *range_type
, *index_type
;
11714 struct type
**range_types
= NULL
;
11715 struct attribute
*attr
;
11717 struct cleanup
*back_to
;
11720 element_type
= die_type (die
, cu
);
11722 /* The die_type call above may have already set the type for this DIE. */
11723 type
= get_die_type (die
, cu
);
11727 /* Irix 6.2 native cc creates array types without children for
11728 arrays with unspecified length. */
11729 if (die
->child
== NULL
)
11731 index_type
= objfile_type (objfile
)->builtin_int
;
11732 range_type
= create_range_type (NULL
, index_type
, 0, -1);
11733 type
= create_array_type (NULL
, element_type
, range_type
);
11734 return set_die_type (die
, type
, cu
);
11737 back_to
= make_cleanup (null_cleanup
, NULL
);
11738 child_die
= die
->child
;
11739 while (child_die
&& child_die
->tag
)
11741 if (child_die
->tag
== DW_TAG_subrange_type
)
11743 struct type
*child_type
= read_type_die (child_die
, cu
);
11745 if (child_type
!= NULL
)
11747 /* The range type was succesfully read. Save it for the
11748 array type creation. */
11749 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
11751 range_types
= (struct type
**)
11752 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
11753 * sizeof (struct type
*));
11755 make_cleanup (free_current_contents
, &range_types
);
11757 range_types
[ndim
++] = child_type
;
11760 child_die
= sibling_die (child_die
);
11763 /* Dwarf2 dimensions are output from left to right, create the
11764 necessary array types in backwards order. */
11766 type
= element_type
;
11768 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
11773 type
= create_array_type (NULL
, type
, range_types
[i
++]);
11778 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
11781 /* Understand Dwarf2 support for vector types (like they occur on
11782 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
11783 array type. This is not part of the Dwarf2/3 standard yet, but a
11784 custom vendor extension. The main difference between a regular
11785 array and the vector variant is that vectors are passed by value
11787 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
11789 make_vector_type (type
);
11791 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
11792 implementation may choose to implement triple vectors using this
11794 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11797 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
11798 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11800 complaint (&symfile_complaints
,
11801 _("DW_AT_byte_size for array type smaller "
11802 "than the total size of elements"));
11805 name
= dwarf2_name (die
, cu
);
11807 TYPE_NAME (type
) = name
;
11809 /* Install the type in the die. */
11810 set_die_type (die
, type
, cu
);
11812 /* set_die_type should be already done. */
11813 set_descriptive_type (type
, die
, cu
);
11815 do_cleanups (back_to
);
11820 static enum dwarf_array_dim_ordering
11821 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
11823 struct attribute
*attr
;
11825 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
11827 if (attr
) return DW_SND (attr
);
11829 /* GNU F77 is a special case, as at 08/2004 array type info is the
11830 opposite order to the dwarf2 specification, but data is still
11831 laid out as per normal fortran.
11833 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
11834 version checking. */
11836 if (cu
->language
== language_fortran
11837 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
11839 return DW_ORD_row_major
;
11842 switch (cu
->language_defn
->la_array_ordering
)
11844 case array_column_major
:
11845 return DW_ORD_col_major
;
11846 case array_row_major
:
11848 return DW_ORD_row_major
;
11852 /* Extract all information from a DW_TAG_set_type DIE and put it in
11853 the DIE's type field. */
11855 static struct type
*
11856 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11858 struct type
*domain_type
, *set_type
;
11859 struct attribute
*attr
;
11861 domain_type
= die_type (die
, cu
);
11863 /* The die_type call above may have already set the type for this DIE. */
11864 set_type
= get_die_type (die
, cu
);
11868 set_type
= create_set_type (NULL
, domain_type
);
11870 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11872 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
11874 return set_die_type (die
, set_type
, cu
);
11877 /* A helper for read_common_block that creates a locexpr baton.
11878 SYM is the symbol which we are marking as computed.
11879 COMMON_DIE is the DIE for the common block.
11880 COMMON_LOC is the location expression attribute for the common
11882 MEMBER_LOC is the location expression attribute for the particular
11883 member of the common block that we are processing.
11884 CU is the CU from which the above come. */
11887 mark_common_block_symbol_computed (struct symbol
*sym
,
11888 struct die_info
*common_die
,
11889 struct attribute
*common_loc
,
11890 struct attribute
*member_loc
,
11891 struct dwarf2_cu
*cu
)
11893 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11894 struct dwarf2_locexpr_baton
*baton
;
11896 unsigned int cu_off
;
11897 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
11898 LONGEST offset
= 0;
11900 gdb_assert (common_loc
&& member_loc
);
11901 gdb_assert (attr_form_is_block (common_loc
));
11902 gdb_assert (attr_form_is_block (member_loc
)
11903 || attr_form_is_constant (member_loc
));
11905 baton
= obstack_alloc (&objfile
->objfile_obstack
,
11906 sizeof (struct dwarf2_locexpr_baton
));
11907 baton
->per_cu
= cu
->per_cu
;
11908 gdb_assert (baton
->per_cu
);
11910 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
11912 if (attr_form_is_constant (member_loc
))
11914 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
11915 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
11918 baton
->size
+= DW_BLOCK (member_loc
)->size
;
11920 ptr
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
11923 *ptr
++ = DW_OP_call4
;
11924 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
11925 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
11928 if (attr_form_is_constant (member_loc
))
11930 *ptr
++ = DW_OP_addr
;
11931 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
11932 ptr
+= cu
->header
.addr_size
;
11936 /* We have to copy the data here, because DW_OP_call4 will only
11937 use a DW_AT_location attribute. */
11938 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
11939 ptr
+= DW_BLOCK (member_loc
)->size
;
11942 *ptr
++ = DW_OP_plus
;
11943 gdb_assert (ptr
- baton
->data
== baton
->size
);
11945 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11946 SYMBOL_LOCATION_BATON (sym
) = baton
;
11947 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11950 /* Create appropriate locally-scoped variables for all the
11951 DW_TAG_common_block entries. Also create a struct common_block
11952 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
11953 is used to sepate the common blocks name namespace from regular
11957 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
11959 struct attribute
*attr
;
11961 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11964 /* Support the .debug_loc offsets. */
11965 if (attr_form_is_block (attr
))
11969 else if (attr_form_is_section_offset (attr
))
11971 dwarf2_complex_location_expr_complaint ();
11976 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11977 "common block member");
11982 if (die
->child
!= NULL
)
11984 struct objfile
*objfile
= cu
->objfile
;
11985 struct die_info
*child_die
;
11986 size_t n_entries
= 0, size
;
11987 struct common_block
*common_block
;
11988 struct symbol
*sym
;
11990 for (child_die
= die
->child
;
11991 child_die
&& child_die
->tag
;
11992 child_die
= sibling_die (child_die
))
11995 size
= (sizeof (struct common_block
)
11996 + (n_entries
- 1) * sizeof (struct symbol
*));
11997 common_block
= obstack_alloc (&objfile
->objfile_obstack
, size
);
11998 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
11999 common_block
->n_entries
= 0;
12001 for (child_die
= die
->child
;
12002 child_die
&& child_die
->tag
;
12003 child_die
= sibling_die (child_die
))
12005 /* Create the symbol in the DW_TAG_common_block block in the current
12007 sym
= new_symbol (child_die
, NULL
, cu
);
12010 struct attribute
*member_loc
;
12012 common_block
->contents
[common_block
->n_entries
++] = sym
;
12014 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
12018 /* GDB has handled this for a long time, but it is
12019 not specified by DWARF. It seems to have been
12020 emitted by gfortran at least as recently as:
12021 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
12022 complaint (&symfile_complaints
,
12023 _("Variable in common block has "
12024 "DW_AT_data_member_location "
12025 "- DIE at 0x%x [in module %s]"),
12026 child_die
->offset
.sect_off
, cu
->objfile
->name
);
12028 if (attr_form_is_section_offset (member_loc
))
12029 dwarf2_complex_location_expr_complaint ();
12030 else if (attr_form_is_constant (member_loc
)
12031 || attr_form_is_block (member_loc
))
12034 mark_common_block_symbol_computed (sym
, die
, attr
,
12038 dwarf2_complex_location_expr_complaint ();
12043 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
12044 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
12048 /* Create a type for a C++ namespace. */
12050 static struct type
*
12051 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12053 struct objfile
*objfile
= cu
->objfile
;
12054 const char *previous_prefix
, *name
;
12058 /* For extensions, reuse the type of the original namespace. */
12059 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
12061 struct die_info
*ext_die
;
12062 struct dwarf2_cu
*ext_cu
= cu
;
12064 ext_die
= dwarf2_extension (die
, &ext_cu
);
12065 type
= read_type_die (ext_die
, ext_cu
);
12067 /* EXT_CU may not be the same as CU.
12068 Ensure TYPE is recorded in CU's type_hash table. */
12069 return set_die_type (die
, type
, cu
);
12072 name
= namespace_name (die
, &is_anonymous
, cu
);
12074 /* Now build the name of the current namespace. */
12076 previous_prefix
= determine_prefix (die
, cu
);
12077 if (previous_prefix
[0] != '\0')
12078 name
= typename_concat (&objfile
->objfile_obstack
,
12079 previous_prefix
, name
, 0, cu
);
12081 /* Create the type. */
12082 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
12084 TYPE_NAME (type
) = (char *) name
;
12085 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
12087 return set_die_type (die
, type
, cu
);
12090 /* Read a C++ namespace. */
12093 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
12095 struct objfile
*objfile
= cu
->objfile
;
12098 /* Add a symbol associated to this if we haven't seen the namespace
12099 before. Also, add a using directive if it's an anonymous
12102 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
12106 type
= read_type_die (die
, cu
);
12107 new_symbol (die
, type
, cu
);
12109 namespace_name (die
, &is_anonymous
, cu
);
12112 const char *previous_prefix
= determine_prefix (die
, cu
);
12114 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
12115 NULL
, NULL
, &objfile
->objfile_obstack
);
12119 if (die
->child
!= NULL
)
12121 struct die_info
*child_die
= die
->child
;
12123 while (child_die
&& child_die
->tag
)
12125 process_die (child_die
, cu
);
12126 child_die
= sibling_die (child_die
);
12131 /* Read a Fortran module as type. This DIE can be only a declaration used for
12132 imported module. Still we need that type as local Fortran "use ... only"
12133 declaration imports depend on the created type in determine_prefix. */
12135 static struct type
*
12136 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12138 struct objfile
*objfile
= cu
->objfile
;
12142 module_name
= dwarf2_name (die
, cu
);
12144 complaint (&symfile_complaints
,
12145 _("DW_TAG_module has no name, offset 0x%x"),
12146 die
->offset
.sect_off
);
12147 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
12149 /* determine_prefix uses TYPE_TAG_NAME. */
12150 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
12152 return set_die_type (die
, type
, cu
);
12155 /* Read a Fortran module. */
12158 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
12160 struct die_info
*child_die
= die
->child
;
12162 while (child_die
&& child_die
->tag
)
12164 process_die (child_die
, cu
);
12165 child_die
= sibling_die (child_die
);
12169 /* Return the name of the namespace represented by DIE. Set
12170 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
12173 static const char *
12174 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
12176 struct die_info
*current_die
;
12177 const char *name
= NULL
;
12179 /* Loop through the extensions until we find a name. */
12181 for (current_die
= die
;
12182 current_die
!= NULL
;
12183 current_die
= dwarf2_extension (die
, &cu
))
12185 name
= dwarf2_name (current_die
, cu
);
12190 /* Is it an anonymous namespace? */
12192 *is_anonymous
= (name
== NULL
);
12194 name
= CP_ANONYMOUS_NAMESPACE_STR
;
12199 /* Extract all information from a DW_TAG_pointer_type DIE and add to
12200 the user defined type vector. */
12202 static struct type
*
12203 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12205 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
12206 struct comp_unit_head
*cu_header
= &cu
->header
;
12208 struct attribute
*attr_byte_size
;
12209 struct attribute
*attr_address_class
;
12210 int byte_size
, addr_class
;
12211 struct type
*target_type
;
12213 target_type
= die_type (die
, cu
);
12215 /* The die_type call above may have already set the type for this DIE. */
12216 type
= get_die_type (die
, cu
);
12220 type
= lookup_pointer_type (target_type
);
12222 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12223 if (attr_byte_size
)
12224 byte_size
= DW_UNSND (attr_byte_size
);
12226 byte_size
= cu_header
->addr_size
;
12228 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
12229 if (attr_address_class
)
12230 addr_class
= DW_UNSND (attr_address_class
);
12232 addr_class
= DW_ADDR_none
;
12234 /* If the pointer size or address class is different than the
12235 default, create a type variant marked as such and set the
12236 length accordingly. */
12237 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
12239 if (gdbarch_address_class_type_flags_p (gdbarch
))
12243 type_flags
= gdbarch_address_class_type_flags
12244 (gdbarch
, byte_size
, addr_class
);
12245 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
12247 type
= make_type_with_address_space (type
, type_flags
);
12249 else if (TYPE_LENGTH (type
) != byte_size
)
12251 complaint (&symfile_complaints
,
12252 _("invalid pointer size %d"), byte_size
);
12256 /* Should we also complain about unhandled address classes? */
12260 TYPE_LENGTH (type
) = byte_size
;
12261 return set_die_type (die
, type
, cu
);
12264 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
12265 the user defined type vector. */
12267 static struct type
*
12268 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12271 struct type
*to_type
;
12272 struct type
*domain
;
12274 to_type
= die_type (die
, cu
);
12275 domain
= die_containing_type (die
, cu
);
12277 /* The calls above may have already set the type for this DIE. */
12278 type
= get_die_type (die
, cu
);
12282 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
12283 type
= lookup_methodptr_type (to_type
);
12285 type
= lookup_memberptr_type (to_type
, domain
);
12287 return set_die_type (die
, type
, cu
);
12290 /* Extract all information from a DW_TAG_reference_type DIE and add to
12291 the user defined type vector. */
12293 static struct type
*
12294 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12296 struct comp_unit_head
*cu_header
= &cu
->header
;
12297 struct type
*type
, *target_type
;
12298 struct attribute
*attr
;
12300 target_type
= die_type (die
, cu
);
12302 /* The die_type call above may have already set the type for this DIE. */
12303 type
= get_die_type (die
, cu
);
12307 type
= lookup_reference_type (target_type
);
12308 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12311 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12315 TYPE_LENGTH (type
) = cu_header
->addr_size
;
12317 return set_die_type (die
, type
, cu
);
12320 static struct type
*
12321 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12323 struct type
*base_type
, *cv_type
;
12325 base_type
= die_type (die
, cu
);
12327 /* The die_type call above may have already set the type for this DIE. */
12328 cv_type
= get_die_type (die
, cu
);
12332 /* In case the const qualifier is applied to an array type, the element type
12333 is so qualified, not the array type (section 6.7.3 of C99). */
12334 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
12336 struct type
*el_type
, *inner_array
;
12338 base_type
= copy_type (base_type
);
12339 inner_array
= base_type
;
12341 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
12343 TYPE_TARGET_TYPE (inner_array
) =
12344 copy_type (TYPE_TARGET_TYPE (inner_array
));
12345 inner_array
= TYPE_TARGET_TYPE (inner_array
);
12348 el_type
= TYPE_TARGET_TYPE (inner_array
);
12349 TYPE_TARGET_TYPE (inner_array
) =
12350 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
12352 return set_die_type (die
, base_type
, cu
);
12355 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
12356 return set_die_type (die
, cv_type
, cu
);
12359 static struct type
*
12360 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12362 struct type
*base_type
, *cv_type
;
12364 base_type
= die_type (die
, cu
);
12366 /* The die_type call above may have already set the type for this DIE. */
12367 cv_type
= get_die_type (die
, cu
);
12371 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
12372 return set_die_type (die
, cv_type
, cu
);
12375 /* Extract all information from a DW_TAG_string_type DIE and add to
12376 the user defined type vector. It isn't really a user defined type,
12377 but it behaves like one, with other DIE's using an AT_user_def_type
12378 attribute to reference it. */
12380 static struct type
*
12381 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12383 struct objfile
*objfile
= cu
->objfile
;
12384 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12385 struct type
*type
, *range_type
, *index_type
, *char_type
;
12386 struct attribute
*attr
;
12387 unsigned int length
;
12389 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
12392 length
= DW_UNSND (attr
);
12396 /* Check for the DW_AT_byte_size attribute. */
12397 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12400 length
= DW_UNSND (attr
);
12408 index_type
= objfile_type (objfile
)->builtin_int
;
12409 range_type
= create_range_type (NULL
, index_type
, 1, length
);
12410 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
12411 type
= create_string_type (NULL
, char_type
, range_type
);
12413 return set_die_type (die
, type
, cu
);
12416 /* Handle DIES due to C code like:
12420 int (*funcp)(int a, long l);
12424 ('funcp' generates a DW_TAG_subroutine_type DIE). */
12426 static struct type
*
12427 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12429 struct objfile
*objfile
= cu
->objfile
;
12430 struct type
*type
; /* Type that this function returns. */
12431 struct type
*ftype
; /* Function that returns above type. */
12432 struct attribute
*attr
;
12434 type
= die_type (die
, cu
);
12436 /* The die_type call above may have already set the type for this DIE. */
12437 ftype
= get_die_type (die
, cu
);
12441 ftype
= lookup_function_type (type
);
12443 /* All functions in C++, Pascal and Java have prototypes. */
12444 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
12445 if ((attr
&& (DW_UNSND (attr
) != 0))
12446 || cu
->language
== language_cplus
12447 || cu
->language
== language_java
12448 || cu
->language
== language_pascal
)
12449 TYPE_PROTOTYPED (ftype
) = 1;
12450 else if (producer_is_realview (cu
->producer
))
12451 /* RealView does not emit DW_AT_prototyped. We can not
12452 distinguish prototyped and unprototyped functions; default to
12453 prototyped, since that is more common in modern code (and
12454 RealView warns about unprototyped functions). */
12455 TYPE_PROTOTYPED (ftype
) = 1;
12457 /* Store the calling convention in the type if it's available in
12458 the subroutine die. Otherwise set the calling convention to
12459 the default value DW_CC_normal. */
12460 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
12462 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
12463 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
12464 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
12466 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
12468 /* We need to add the subroutine type to the die immediately so
12469 we don't infinitely recurse when dealing with parameters
12470 declared as the same subroutine type. */
12471 set_die_type (die
, ftype
, cu
);
12473 if (die
->child
!= NULL
)
12475 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
12476 struct die_info
*child_die
;
12477 int nparams
, iparams
;
12479 /* Count the number of parameters.
12480 FIXME: GDB currently ignores vararg functions, but knows about
12481 vararg member functions. */
12483 child_die
= die
->child
;
12484 while (child_die
&& child_die
->tag
)
12486 if (child_die
->tag
== DW_TAG_formal_parameter
)
12488 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
12489 TYPE_VARARGS (ftype
) = 1;
12490 child_die
= sibling_die (child_die
);
12493 /* Allocate storage for parameters and fill them in. */
12494 TYPE_NFIELDS (ftype
) = nparams
;
12495 TYPE_FIELDS (ftype
) = (struct field
*)
12496 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
12498 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
12499 even if we error out during the parameters reading below. */
12500 for (iparams
= 0; iparams
< nparams
; iparams
++)
12501 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
12504 child_die
= die
->child
;
12505 while (child_die
&& child_die
->tag
)
12507 if (child_die
->tag
== DW_TAG_formal_parameter
)
12509 struct type
*arg_type
;
12511 /* DWARF version 2 has no clean way to discern C++
12512 static and non-static member functions. G++ helps
12513 GDB by marking the first parameter for non-static
12514 member functions (which is the this pointer) as
12515 artificial. We pass this information to
12516 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
12518 DWARF version 3 added DW_AT_object_pointer, which GCC
12519 4.5 does not yet generate. */
12520 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
12522 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
12525 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
12527 /* GCC/43521: In java, the formal parameter
12528 "this" is sometimes not marked with DW_AT_artificial. */
12529 if (cu
->language
== language_java
)
12531 const char *name
= dwarf2_name (child_die
, cu
);
12533 if (name
&& !strcmp (name
, "this"))
12534 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
12537 arg_type
= die_type (child_die
, cu
);
12539 /* RealView does not mark THIS as const, which the testsuite
12540 expects. GCC marks THIS as const in method definitions,
12541 but not in the class specifications (GCC PR 43053). */
12542 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
12543 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
12546 struct dwarf2_cu
*arg_cu
= cu
;
12547 const char *name
= dwarf2_name (child_die
, cu
);
12549 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
12552 /* If the compiler emits this, use it. */
12553 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
12556 else if (name
&& strcmp (name
, "this") == 0)
12557 /* Function definitions will have the argument names. */
12559 else if (name
== NULL
&& iparams
== 0)
12560 /* Declarations may not have the names, so like
12561 elsewhere in GDB, assume an artificial first
12562 argument is "this". */
12566 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
12570 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
12573 child_die
= sibling_die (child_die
);
12580 static struct type
*
12581 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
12583 struct objfile
*objfile
= cu
->objfile
;
12584 const char *name
= NULL
;
12585 struct type
*this_type
, *target_type
;
12587 name
= dwarf2_full_name (NULL
, die
, cu
);
12588 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
12589 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
12590 TYPE_NAME (this_type
) = (char *) name
;
12591 set_die_type (die
, this_type
, cu
);
12592 target_type
= die_type (die
, cu
);
12593 if (target_type
!= this_type
)
12594 TYPE_TARGET_TYPE (this_type
) = target_type
;
12597 /* Self-referential typedefs are, it seems, not allowed by the DWARF
12598 spec and cause infinite loops in GDB. */
12599 complaint (&symfile_complaints
,
12600 _("Self-referential DW_TAG_typedef "
12601 "- DIE at 0x%x [in module %s]"),
12602 die
->offset
.sect_off
, objfile
->name
);
12603 TYPE_TARGET_TYPE (this_type
) = NULL
;
12608 /* Find a representation of a given base type and install
12609 it in the TYPE field of the die. */
12611 static struct type
*
12612 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12614 struct objfile
*objfile
= cu
->objfile
;
12616 struct attribute
*attr
;
12617 int encoding
= 0, size
= 0;
12619 enum type_code code
= TYPE_CODE_INT
;
12620 int type_flags
= 0;
12621 struct type
*target_type
= NULL
;
12623 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
12626 encoding
= DW_UNSND (attr
);
12628 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12631 size
= DW_UNSND (attr
);
12633 name
= dwarf2_name (die
, cu
);
12636 complaint (&symfile_complaints
,
12637 _("DW_AT_name missing from DW_TAG_base_type"));
12642 case DW_ATE_address
:
12643 /* Turn DW_ATE_address into a void * pointer. */
12644 code
= TYPE_CODE_PTR
;
12645 type_flags
|= TYPE_FLAG_UNSIGNED
;
12646 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
12648 case DW_ATE_boolean
:
12649 code
= TYPE_CODE_BOOL
;
12650 type_flags
|= TYPE_FLAG_UNSIGNED
;
12652 case DW_ATE_complex_float
:
12653 code
= TYPE_CODE_COMPLEX
;
12654 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
12656 case DW_ATE_decimal_float
:
12657 code
= TYPE_CODE_DECFLOAT
;
12660 code
= TYPE_CODE_FLT
;
12662 case DW_ATE_signed
:
12664 case DW_ATE_unsigned
:
12665 type_flags
|= TYPE_FLAG_UNSIGNED
;
12666 if (cu
->language
== language_fortran
12668 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
12669 code
= TYPE_CODE_CHAR
;
12671 case DW_ATE_signed_char
:
12672 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12673 || cu
->language
== language_pascal
12674 || cu
->language
== language_fortran
)
12675 code
= TYPE_CODE_CHAR
;
12677 case DW_ATE_unsigned_char
:
12678 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12679 || cu
->language
== language_pascal
12680 || cu
->language
== language_fortran
)
12681 code
= TYPE_CODE_CHAR
;
12682 type_flags
|= TYPE_FLAG_UNSIGNED
;
12685 /* We just treat this as an integer and then recognize the
12686 type by name elsewhere. */
12690 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
12691 dwarf_type_encoding_name (encoding
));
12695 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
12696 TYPE_NAME (type
) = name
;
12697 TYPE_TARGET_TYPE (type
) = target_type
;
12699 if (name
&& strcmp (name
, "char") == 0)
12700 TYPE_NOSIGN (type
) = 1;
12702 return set_die_type (die
, type
, cu
);
12705 /* Read the given DW_AT_subrange DIE. */
12707 static struct type
*
12708 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12710 struct type
*base_type
;
12711 struct type
*range_type
;
12712 struct attribute
*attr
;
12714 int low_default_is_valid
;
12716 LONGEST negative_mask
;
12718 base_type
= die_type (die
, cu
);
12719 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
12720 check_typedef (base_type
);
12722 /* The die_type call above may have already set the type for this DIE. */
12723 range_type
= get_die_type (die
, cu
);
12727 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
12728 omitting DW_AT_lower_bound. */
12729 switch (cu
->language
)
12732 case language_cplus
:
12734 low_default_is_valid
= 1;
12736 case language_fortran
:
12738 low_default_is_valid
= 1;
12741 case language_java
:
12742 case language_objc
:
12744 low_default_is_valid
= (cu
->header
.version
>= 4);
12748 case language_pascal
:
12750 low_default_is_valid
= (cu
->header
.version
>= 4);
12754 low_default_is_valid
= 0;
12758 /* FIXME: For variable sized arrays either of these could be
12759 a variable rather than a constant value. We'll allow it,
12760 but we don't know how to handle it. */
12761 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
12763 low
= dwarf2_get_attr_constant_value (attr
, low
);
12764 else if (!low_default_is_valid
)
12765 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
12766 "- DIE at 0x%x [in module %s]"),
12767 die
->offset
.sect_off
, cu
->objfile
->name
);
12769 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
12772 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
12774 /* GCC encodes arrays with unspecified or dynamic length
12775 with a DW_FORM_block1 attribute or a reference attribute.
12776 FIXME: GDB does not yet know how to handle dynamic
12777 arrays properly, treat them as arrays with unspecified
12780 FIXME: jimb/2003-09-22: GDB does not really know
12781 how to handle arrays of unspecified length
12782 either; we just represent them as zero-length
12783 arrays. Choose an appropriate upper bound given
12784 the lower bound we've computed above. */
12788 high
= dwarf2_get_attr_constant_value (attr
, 1);
12792 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
12795 int count
= dwarf2_get_attr_constant_value (attr
, 1);
12796 high
= low
+ count
- 1;
12800 /* Unspecified array length. */
12805 /* Dwarf-2 specifications explicitly allows to create subrange types
12806 without specifying a base type.
12807 In that case, the base type must be set to the type of
12808 the lower bound, upper bound or count, in that order, if any of these
12809 three attributes references an object that has a type.
12810 If no base type is found, the Dwarf-2 specifications say that
12811 a signed integer type of size equal to the size of an address should
12813 For the following C code: `extern char gdb_int [];'
12814 GCC produces an empty range DIE.
12815 FIXME: muller/2010-05-28: Possible references to object for low bound,
12816 high bound or count are not yet handled by this code. */
12817 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
12819 struct objfile
*objfile
= cu
->objfile
;
12820 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12821 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
12822 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
12824 /* Test "int", "long int", and "long long int" objfile types,
12825 and select the first one having a size above or equal to the
12826 architecture address size. */
12827 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12828 base_type
= int_type
;
12831 int_type
= objfile_type (objfile
)->builtin_long
;
12832 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12833 base_type
= int_type
;
12836 int_type
= objfile_type (objfile
)->builtin_long_long
;
12837 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12838 base_type
= int_type
;
12844 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
12845 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
12846 low
|= negative_mask
;
12847 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
12848 high
|= negative_mask
;
12850 range_type
= create_range_type (NULL
, base_type
, low
, high
);
12852 /* Mark arrays with dynamic length at least as an array of unspecified
12853 length. GDB could check the boundary but before it gets implemented at
12854 least allow accessing the array elements. */
12855 if (attr
&& attr_form_is_block (attr
))
12856 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12858 /* Ada expects an empty array on no boundary attributes. */
12859 if (attr
== NULL
&& cu
->language
!= language_ada
)
12860 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12862 name
= dwarf2_name (die
, cu
);
12864 TYPE_NAME (range_type
) = name
;
12866 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12868 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
12870 set_die_type (die
, range_type
, cu
);
12872 /* set_die_type should be already done. */
12873 set_descriptive_type (range_type
, die
, cu
);
12878 static struct type
*
12879 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12883 /* For now, we only support the C meaning of an unspecified type: void. */
12885 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
12886 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
12888 return set_die_type (die
, type
, cu
);
12891 /* Read a single die and all its descendents. Set the die's sibling
12892 field to NULL; set other fields in the die correctly, and set all
12893 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
12894 location of the info_ptr after reading all of those dies. PARENT
12895 is the parent of the die in question. */
12897 static struct die_info
*
12898 read_die_and_children (const struct die_reader_specs
*reader
,
12899 gdb_byte
*info_ptr
,
12900 gdb_byte
**new_info_ptr
,
12901 struct die_info
*parent
)
12903 struct die_info
*die
;
12907 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
12910 *new_info_ptr
= cur_ptr
;
12913 store_in_ref_table (die
, reader
->cu
);
12916 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
12920 *new_info_ptr
= cur_ptr
;
12923 die
->sibling
= NULL
;
12924 die
->parent
= parent
;
12928 /* Read a die, all of its descendents, and all of its siblings; set
12929 all of the fields of all of the dies correctly. Arguments are as
12930 in read_die_and_children. */
12932 static struct die_info
*
12933 read_die_and_siblings (const struct die_reader_specs
*reader
,
12934 gdb_byte
*info_ptr
,
12935 gdb_byte
**new_info_ptr
,
12936 struct die_info
*parent
)
12938 struct die_info
*first_die
, *last_sibling
;
12941 cur_ptr
= info_ptr
;
12942 first_die
= last_sibling
= NULL
;
12946 struct die_info
*die
12947 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
12951 *new_info_ptr
= cur_ptr
;
12958 last_sibling
->sibling
= die
;
12960 last_sibling
= die
;
12964 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
12966 The caller is responsible for filling in the extra attributes
12967 and updating (*DIEP)->num_attrs.
12968 Set DIEP to point to a newly allocated die with its information,
12969 except for its child, sibling, and parent fields.
12970 Set HAS_CHILDREN to tell whether the die has children or not. */
12973 read_full_die_1 (const struct die_reader_specs
*reader
,
12974 struct die_info
**diep
, gdb_byte
*info_ptr
,
12975 int *has_children
, int num_extra_attrs
)
12977 unsigned int abbrev_number
, bytes_read
, i
;
12978 sect_offset offset
;
12979 struct abbrev_info
*abbrev
;
12980 struct die_info
*die
;
12981 struct dwarf2_cu
*cu
= reader
->cu
;
12982 bfd
*abfd
= reader
->abfd
;
12984 offset
.sect_off
= info_ptr
- reader
->buffer
;
12985 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12986 info_ptr
+= bytes_read
;
12987 if (!abbrev_number
)
12994 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
12996 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
12998 bfd_get_filename (abfd
));
13000 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
13001 die
->offset
= offset
;
13002 die
->tag
= abbrev
->tag
;
13003 die
->abbrev
= abbrev_number
;
13005 /* Make the result usable.
13006 The caller needs to update num_attrs after adding the extra
13008 die
->num_attrs
= abbrev
->num_attrs
;
13010 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
13011 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
13015 *has_children
= abbrev
->has_children
;
13019 /* Read a die and all its attributes.
13020 Set DIEP to point to a newly allocated die with its information,
13021 except for its child, sibling, and parent fields.
13022 Set HAS_CHILDREN to tell whether the die has children or not. */
13025 read_full_die (const struct die_reader_specs
*reader
,
13026 struct die_info
**diep
, gdb_byte
*info_ptr
,
13029 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
13032 /* Abbreviation tables.
13034 In DWARF version 2, the description of the debugging information is
13035 stored in a separate .debug_abbrev section. Before we read any
13036 dies from a section we read in all abbreviations and install them
13037 in a hash table. */
13039 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
13041 static struct abbrev_info
*
13042 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
13044 struct abbrev_info
*abbrev
;
13046 abbrev
= (struct abbrev_info
*)
13047 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
13048 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13052 /* Add an abbreviation to the table. */
13055 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
13056 unsigned int abbrev_number
,
13057 struct abbrev_info
*abbrev
)
13059 unsigned int hash_number
;
13061 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
13062 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
13063 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
13066 /* Look up an abbrev in the table.
13067 Returns NULL if the abbrev is not found. */
13069 static struct abbrev_info
*
13070 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
13071 unsigned int abbrev_number
)
13073 unsigned int hash_number
;
13074 struct abbrev_info
*abbrev
;
13076 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
13077 abbrev
= abbrev_table
->abbrevs
[hash_number
];
13081 if (abbrev
->number
== abbrev_number
)
13083 abbrev
= abbrev
->next
;
13088 /* Read in an abbrev table. */
13090 static struct abbrev_table
*
13091 abbrev_table_read_table (struct dwarf2_section_info
*section
,
13092 sect_offset offset
)
13094 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13095 bfd
*abfd
= section
->asection
->owner
;
13096 struct abbrev_table
*abbrev_table
;
13097 gdb_byte
*abbrev_ptr
;
13098 struct abbrev_info
*cur_abbrev
;
13099 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
13100 unsigned int abbrev_form
;
13101 struct attr_abbrev
*cur_attrs
;
13102 unsigned int allocated_attrs
;
13104 abbrev_table
= XMALLOC (struct abbrev_table
);
13105 abbrev_table
->offset
= offset
;
13106 obstack_init (&abbrev_table
->abbrev_obstack
);
13107 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13109 * sizeof (struct abbrev_info
*)));
13110 memset (abbrev_table
->abbrevs
, 0,
13111 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
13113 dwarf2_read_section (objfile
, section
);
13114 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
13115 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13116 abbrev_ptr
+= bytes_read
;
13118 allocated_attrs
= ATTR_ALLOC_CHUNK
;
13119 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
13121 /* Loop until we reach an abbrev number of 0. */
13122 while (abbrev_number
)
13124 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
13126 /* read in abbrev header */
13127 cur_abbrev
->number
= abbrev_number
;
13128 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13129 abbrev_ptr
+= bytes_read
;
13130 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
13133 /* now read in declarations */
13134 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13135 abbrev_ptr
+= bytes_read
;
13136 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13137 abbrev_ptr
+= bytes_read
;
13138 while (abbrev_name
)
13140 if (cur_abbrev
->num_attrs
== allocated_attrs
)
13142 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
13144 = xrealloc (cur_attrs
, (allocated_attrs
13145 * sizeof (struct attr_abbrev
)));
13148 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
13149 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
13150 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13151 abbrev_ptr
+= bytes_read
;
13152 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13153 abbrev_ptr
+= bytes_read
;
13156 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13157 (cur_abbrev
->num_attrs
13158 * sizeof (struct attr_abbrev
)));
13159 memcpy (cur_abbrev
->attrs
, cur_attrs
,
13160 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
13162 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
13164 /* Get next abbreviation.
13165 Under Irix6 the abbreviations for a compilation unit are not
13166 always properly terminated with an abbrev number of 0.
13167 Exit loop if we encounter an abbreviation which we have
13168 already read (which means we are about to read the abbreviations
13169 for the next compile unit) or if the end of the abbreviation
13170 table is reached. */
13171 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
13173 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13174 abbrev_ptr
+= bytes_read
;
13175 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
13180 return abbrev_table
;
13183 /* Free the resources held by ABBREV_TABLE. */
13186 abbrev_table_free (struct abbrev_table
*abbrev_table
)
13188 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
13189 xfree (abbrev_table
);
13192 /* Same as abbrev_table_free but as a cleanup.
13193 We pass in a pointer to the pointer to the table so that we can
13194 set the pointer to NULL when we're done. It also simplifies
13195 build_type_unit_groups. */
13198 abbrev_table_free_cleanup (void *table_ptr
)
13200 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
13202 if (*abbrev_table_ptr
!= NULL
)
13203 abbrev_table_free (*abbrev_table_ptr
);
13204 *abbrev_table_ptr
= NULL
;
13207 /* Read the abbrev table for CU from ABBREV_SECTION. */
13210 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
13211 struct dwarf2_section_info
*abbrev_section
)
13214 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
13217 /* Release the memory used by the abbrev table for a compilation unit. */
13220 dwarf2_free_abbrev_table (void *ptr_to_cu
)
13222 struct dwarf2_cu
*cu
= ptr_to_cu
;
13224 abbrev_table_free (cu
->abbrev_table
);
13225 /* Set this to NULL so that we SEGV if we try to read it later,
13226 and also because free_comp_unit verifies this is NULL. */
13227 cu
->abbrev_table
= NULL
;
13230 /* Returns nonzero if TAG represents a type that we might generate a partial
13234 is_type_tag_for_partial (int tag
)
13239 /* Some types that would be reasonable to generate partial symbols for,
13240 that we don't at present. */
13241 case DW_TAG_array_type
:
13242 case DW_TAG_file_type
:
13243 case DW_TAG_ptr_to_member_type
:
13244 case DW_TAG_set_type
:
13245 case DW_TAG_string_type
:
13246 case DW_TAG_subroutine_type
:
13248 case DW_TAG_base_type
:
13249 case DW_TAG_class_type
:
13250 case DW_TAG_interface_type
:
13251 case DW_TAG_enumeration_type
:
13252 case DW_TAG_structure_type
:
13253 case DW_TAG_subrange_type
:
13254 case DW_TAG_typedef
:
13255 case DW_TAG_union_type
:
13262 /* Load all DIEs that are interesting for partial symbols into memory. */
13264 static struct partial_die_info
*
13265 load_partial_dies (const struct die_reader_specs
*reader
,
13266 gdb_byte
*info_ptr
, int building_psymtab
)
13268 struct dwarf2_cu
*cu
= reader
->cu
;
13269 struct objfile
*objfile
= cu
->objfile
;
13270 struct partial_die_info
*part_die
;
13271 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
13272 struct abbrev_info
*abbrev
;
13273 unsigned int bytes_read
;
13274 unsigned int load_all
= 0;
13275 int nesting_level
= 1;
13280 gdb_assert (cu
->per_cu
!= NULL
);
13281 if (cu
->per_cu
->load_all_dies
)
13285 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13289 &cu
->comp_unit_obstack
,
13290 hashtab_obstack_allocate
,
13291 dummy_obstack_deallocate
);
13293 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13294 sizeof (struct partial_die_info
));
13298 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
13300 /* A NULL abbrev means the end of a series of children. */
13301 if (abbrev
== NULL
)
13303 if (--nesting_level
== 0)
13305 /* PART_DIE was probably the last thing allocated on the
13306 comp_unit_obstack, so we could call obstack_free
13307 here. We don't do that because the waste is small,
13308 and will be cleaned up when we're done with this
13309 compilation unit. This way, we're also more robust
13310 against other users of the comp_unit_obstack. */
13313 info_ptr
+= bytes_read
;
13314 last_die
= parent_die
;
13315 parent_die
= parent_die
->die_parent
;
13319 /* Check for template arguments. We never save these; if
13320 they're seen, we just mark the parent, and go on our way. */
13321 if (parent_die
!= NULL
13322 && cu
->language
== language_cplus
13323 && (abbrev
->tag
== DW_TAG_template_type_param
13324 || abbrev
->tag
== DW_TAG_template_value_param
))
13326 parent_die
->has_template_arguments
= 1;
13330 /* We don't need a partial DIE for the template argument. */
13331 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13336 /* We only recurse into c++ subprograms looking for template arguments.
13337 Skip their other children. */
13339 && cu
->language
== language_cplus
13340 && parent_die
!= NULL
13341 && parent_die
->tag
== DW_TAG_subprogram
)
13343 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13347 /* Check whether this DIE is interesting enough to save. Normally
13348 we would not be interested in members here, but there may be
13349 later variables referencing them via DW_AT_specification (for
13350 static members). */
13352 && !is_type_tag_for_partial (abbrev
->tag
)
13353 && abbrev
->tag
!= DW_TAG_constant
13354 && abbrev
->tag
!= DW_TAG_enumerator
13355 && abbrev
->tag
!= DW_TAG_subprogram
13356 && abbrev
->tag
!= DW_TAG_lexical_block
13357 && abbrev
->tag
!= DW_TAG_variable
13358 && abbrev
->tag
!= DW_TAG_namespace
13359 && abbrev
->tag
!= DW_TAG_module
13360 && abbrev
->tag
!= DW_TAG_member
13361 && abbrev
->tag
!= DW_TAG_imported_unit
)
13363 /* Otherwise we skip to the next sibling, if any. */
13364 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13368 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
13371 /* This two-pass algorithm for processing partial symbols has a
13372 high cost in cache pressure. Thus, handle some simple cases
13373 here which cover the majority of C partial symbols. DIEs
13374 which neither have specification tags in them, nor could have
13375 specification tags elsewhere pointing at them, can simply be
13376 processed and discarded.
13378 This segment is also optional; scan_partial_symbols and
13379 add_partial_symbol will handle these DIEs if we chain
13380 them in normally. When compilers which do not emit large
13381 quantities of duplicate debug information are more common,
13382 this code can probably be removed. */
13384 /* Any complete simple types at the top level (pretty much all
13385 of them, for a language without namespaces), can be processed
13387 if (parent_die
== NULL
13388 && part_die
->has_specification
== 0
13389 && part_die
->is_declaration
== 0
13390 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
13391 || part_die
->tag
== DW_TAG_base_type
13392 || part_die
->tag
== DW_TAG_subrange_type
))
13394 if (building_psymtab
&& part_die
->name
!= NULL
)
13395 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13396 VAR_DOMAIN
, LOC_TYPEDEF
,
13397 &objfile
->static_psymbols
,
13398 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13399 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13403 /* The exception for DW_TAG_typedef with has_children above is
13404 a workaround of GCC PR debug/47510. In the case of this complaint
13405 type_name_no_tag_or_error will error on such types later.
13407 GDB skipped children of DW_TAG_typedef by the shortcut above and then
13408 it could not find the child DIEs referenced later, this is checked
13409 above. In correct DWARF DW_TAG_typedef should have no children. */
13411 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
13412 complaint (&symfile_complaints
,
13413 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
13414 "- DIE at 0x%x [in module %s]"),
13415 part_die
->offset
.sect_off
, objfile
->name
);
13417 /* If we're at the second level, and we're an enumerator, and
13418 our parent has no specification (meaning possibly lives in a
13419 namespace elsewhere), then we can add the partial symbol now
13420 instead of queueing it. */
13421 if (part_die
->tag
== DW_TAG_enumerator
13422 && parent_die
!= NULL
13423 && parent_die
->die_parent
== NULL
13424 && parent_die
->tag
== DW_TAG_enumeration_type
13425 && parent_die
->has_specification
== 0)
13427 if (part_die
->name
== NULL
)
13428 complaint (&symfile_complaints
,
13429 _("malformed enumerator DIE ignored"));
13430 else if (building_psymtab
)
13431 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13432 VAR_DOMAIN
, LOC_CONST
,
13433 (cu
->language
== language_cplus
13434 || cu
->language
== language_java
)
13435 ? &objfile
->global_psymbols
13436 : &objfile
->static_psymbols
,
13437 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13439 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13443 /* We'll save this DIE so link it in. */
13444 part_die
->die_parent
= parent_die
;
13445 part_die
->die_sibling
= NULL
;
13446 part_die
->die_child
= NULL
;
13448 if (last_die
&& last_die
== parent_die
)
13449 last_die
->die_child
= part_die
;
13451 last_die
->die_sibling
= part_die
;
13453 last_die
= part_die
;
13455 if (first_die
== NULL
)
13456 first_die
= part_die
;
13458 /* Maybe add the DIE to the hash table. Not all DIEs that we
13459 find interesting need to be in the hash table, because we
13460 also have the parent/sibling/child chains; only those that we
13461 might refer to by offset later during partial symbol reading.
13463 For now this means things that might have be the target of a
13464 DW_AT_specification, DW_AT_abstract_origin, or
13465 DW_AT_extension. DW_AT_extension will refer only to
13466 namespaces; DW_AT_abstract_origin refers to functions (and
13467 many things under the function DIE, but we do not recurse
13468 into function DIEs during partial symbol reading) and
13469 possibly variables as well; DW_AT_specification refers to
13470 declarations. Declarations ought to have the DW_AT_declaration
13471 flag. It happens that GCC forgets to put it in sometimes, but
13472 only for functions, not for types.
13474 Adding more things than necessary to the hash table is harmless
13475 except for the performance cost. Adding too few will result in
13476 wasted time in find_partial_die, when we reread the compilation
13477 unit with load_all_dies set. */
13480 || abbrev
->tag
== DW_TAG_constant
13481 || abbrev
->tag
== DW_TAG_subprogram
13482 || abbrev
->tag
== DW_TAG_variable
13483 || abbrev
->tag
== DW_TAG_namespace
13484 || part_die
->is_declaration
)
13488 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
13489 part_die
->offset
.sect_off
, INSERT
);
13493 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13494 sizeof (struct partial_die_info
));
13496 /* For some DIEs we want to follow their children (if any). For C
13497 we have no reason to follow the children of structures; for other
13498 languages we have to, so that we can get at method physnames
13499 to infer fully qualified class names, for DW_AT_specification,
13500 and for C++ template arguments. For C++, we also look one level
13501 inside functions to find template arguments (if the name of the
13502 function does not already contain the template arguments).
13504 For Ada, we need to scan the children of subprograms and lexical
13505 blocks as well because Ada allows the definition of nested
13506 entities that could be interesting for the debugger, such as
13507 nested subprograms for instance. */
13508 if (last_die
->has_children
13510 || last_die
->tag
== DW_TAG_namespace
13511 || last_die
->tag
== DW_TAG_module
13512 || last_die
->tag
== DW_TAG_enumeration_type
13513 || (cu
->language
== language_cplus
13514 && last_die
->tag
== DW_TAG_subprogram
13515 && (last_die
->name
== NULL
13516 || strchr (last_die
->name
, '<') == NULL
))
13517 || (cu
->language
!= language_c
13518 && (last_die
->tag
== DW_TAG_class_type
13519 || last_die
->tag
== DW_TAG_interface_type
13520 || last_die
->tag
== DW_TAG_structure_type
13521 || last_die
->tag
== DW_TAG_union_type
))
13522 || (cu
->language
== language_ada
13523 && (last_die
->tag
== DW_TAG_subprogram
13524 || last_die
->tag
== DW_TAG_lexical_block
))))
13527 parent_die
= last_die
;
13531 /* Otherwise we skip to the next sibling, if any. */
13532 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
13534 /* Back to the top, do it again. */
13538 /* Read a minimal amount of information into the minimal die structure. */
13541 read_partial_die (const struct die_reader_specs
*reader
,
13542 struct partial_die_info
*part_die
,
13543 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
13544 gdb_byte
*info_ptr
)
13546 struct dwarf2_cu
*cu
= reader
->cu
;
13547 struct objfile
*objfile
= cu
->objfile
;
13548 gdb_byte
*buffer
= reader
->buffer
;
13550 struct attribute attr
;
13551 int has_low_pc_attr
= 0;
13552 int has_high_pc_attr
= 0;
13553 int high_pc_relative
= 0;
13555 memset (part_die
, 0, sizeof (struct partial_die_info
));
13557 part_die
->offset
.sect_off
= info_ptr
- buffer
;
13559 info_ptr
+= abbrev_len
;
13561 if (abbrev
== NULL
)
13564 part_die
->tag
= abbrev
->tag
;
13565 part_die
->has_children
= abbrev
->has_children
;
13567 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
13569 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
13571 /* Store the data if it is of an attribute we want to keep in a
13572 partial symbol table. */
13576 switch (part_die
->tag
)
13578 case DW_TAG_compile_unit
:
13579 case DW_TAG_partial_unit
:
13580 case DW_TAG_type_unit
:
13581 /* Compilation units have a DW_AT_name that is a filename, not
13582 a source language identifier. */
13583 case DW_TAG_enumeration_type
:
13584 case DW_TAG_enumerator
:
13585 /* These tags always have simple identifiers already; no need
13586 to canonicalize them. */
13587 part_die
->name
= DW_STRING (&attr
);
13591 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
13592 &objfile
->objfile_obstack
);
13596 case DW_AT_linkage_name
:
13597 case DW_AT_MIPS_linkage_name
:
13598 /* Note that both forms of linkage name might appear. We
13599 assume they will be the same, and we only store the last
13601 if (cu
->language
== language_ada
)
13602 part_die
->name
= DW_STRING (&attr
);
13603 part_die
->linkage_name
= DW_STRING (&attr
);
13606 has_low_pc_attr
= 1;
13607 part_die
->lowpc
= DW_ADDR (&attr
);
13609 case DW_AT_high_pc
:
13610 has_high_pc_attr
= 1;
13611 if (attr
.form
== DW_FORM_addr
13612 || attr
.form
== DW_FORM_GNU_addr_index
)
13613 part_die
->highpc
= DW_ADDR (&attr
);
13616 high_pc_relative
= 1;
13617 part_die
->highpc
= DW_UNSND (&attr
);
13620 case DW_AT_location
:
13621 /* Support the .debug_loc offsets. */
13622 if (attr_form_is_block (&attr
))
13624 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
13626 else if (attr_form_is_section_offset (&attr
))
13628 dwarf2_complex_location_expr_complaint ();
13632 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13633 "partial symbol information");
13636 case DW_AT_external
:
13637 part_die
->is_external
= DW_UNSND (&attr
);
13639 case DW_AT_declaration
:
13640 part_die
->is_declaration
= DW_UNSND (&attr
);
13643 part_die
->has_type
= 1;
13645 case DW_AT_abstract_origin
:
13646 case DW_AT_specification
:
13647 case DW_AT_extension
:
13648 part_die
->has_specification
= 1;
13649 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
13650 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13651 || cu
->per_cu
->is_dwz
);
13653 case DW_AT_sibling
:
13654 /* Ignore absolute siblings, they might point outside of
13655 the current compile unit. */
13656 if (attr
.form
== DW_FORM_ref_addr
)
13657 complaint (&symfile_complaints
,
13658 _("ignoring absolute DW_AT_sibling"));
13660 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
13662 case DW_AT_byte_size
:
13663 part_die
->has_byte_size
= 1;
13665 case DW_AT_calling_convention
:
13666 /* DWARF doesn't provide a way to identify a program's source-level
13667 entry point. DW_AT_calling_convention attributes are only meant
13668 to describe functions' calling conventions.
13670 However, because it's a necessary piece of information in
13671 Fortran, and because DW_CC_program is the only piece of debugging
13672 information whose definition refers to a 'main program' at all,
13673 several compilers have begun marking Fortran main programs with
13674 DW_CC_program --- even when those functions use the standard
13675 calling conventions.
13677 So until DWARF specifies a way to provide this information and
13678 compilers pick up the new representation, we'll support this
13680 if (DW_UNSND (&attr
) == DW_CC_program
13681 && cu
->language
== language_fortran
)
13683 set_main_name (part_die
->name
);
13685 /* As this DIE has a static linkage the name would be difficult
13686 to look up later. */
13687 language_of_main
= language_fortran
;
13691 if (DW_UNSND (&attr
) == DW_INL_inlined
13692 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
13693 part_die
->may_be_inlined
= 1;
13697 if (part_die
->tag
== DW_TAG_imported_unit
)
13699 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
13700 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13701 || cu
->per_cu
->is_dwz
);
13710 if (high_pc_relative
)
13711 part_die
->highpc
+= part_die
->lowpc
;
13713 if (has_low_pc_attr
&& has_high_pc_attr
)
13715 /* When using the GNU linker, .gnu.linkonce. sections are used to
13716 eliminate duplicate copies of functions and vtables and such.
13717 The linker will arbitrarily choose one and discard the others.
13718 The AT_*_pc values for such functions refer to local labels in
13719 these sections. If the section from that file was discarded, the
13720 labels are not in the output, so the relocs get a value of 0.
13721 If this is a discarded function, mark the pc bounds as invalid,
13722 so that GDB will ignore it. */
13723 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13725 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13727 complaint (&symfile_complaints
,
13728 _("DW_AT_low_pc %s is zero "
13729 "for DIE at 0x%x [in module %s]"),
13730 paddress (gdbarch
, part_die
->lowpc
),
13731 part_die
->offset
.sect_off
, objfile
->name
);
13733 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
13734 else if (part_die
->lowpc
>= part_die
->highpc
)
13736 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13738 complaint (&symfile_complaints
,
13739 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
13740 "for DIE at 0x%x [in module %s]"),
13741 paddress (gdbarch
, part_die
->lowpc
),
13742 paddress (gdbarch
, part_die
->highpc
),
13743 part_die
->offset
.sect_off
, objfile
->name
);
13746 part_die
->has_pc_info
= 1;
13752 /* Find a cached partial DIE at OFFSET in CU. */
13754 static struct partial_die_info
*
13755 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
13757 struct partial_die_info
*lookup_die
= NULL
;
13758 struct partial_die_info part_die
;
13760 part_die
.offset
= offset
;
13761 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
13767 /* Find a partial DIE at OFFSET, which may or may not be in CU,
13768 except in the case of .debug_types DIEs which do not reference
13769 outside their CU (they do however referencing other types via
13770 DW_FORM_ref_sig8). */
13772 static struct partial_die_info
*
13773 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
13775 struct objfile
*objfile
= cu
->objfile
;
13776 struct dwarf2_per_cu_data
*per_cu
= NULL
;
13777 struct partial_die_info
*pd
= NULL
;
13779 if (offset_in_dwz
== cu
->per_cu
->is_dwz
13780 && offset_in_cu_p (&cu
->header
, offset
))
13782 pd
= find_partial_die_in_comp_unit (offset
, cu
);
13785 /* We missed recording what we needed.
13786 Load all dies and try again. */
13787 per_cu
= cu
->per_cu
;
13791 /* TUs don't reference other CUs/TUs (except via type signatures). */
13792 if (cu
->per_cu
->is_debug_types
)
13794 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
13795 " external reference to offset 0x%lx [in module %s].\n"),
13796 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
13797 bfd_get_filename (objfile
->obfd
));
13799 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
13802 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
13803 load_partial_comp_unit (per_cu
);
13805 per_cu
->cu
->last_used
= 0;
13806 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13809 /* If we didn't find it, and not all dies have been loaded,
13810 load them all and try again. */
13812 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
13814 per_cu
->load_all_dies
= 1;
13816 /* This is nasty. When we reread the DIEs, somewhere up the call chain
13817 THIS_CU->cu may already be in use. So we can't just free it and
13818 replace its DIEs with the ones we read in. Instead, we leave those
13819 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
13820 and clobber THIS_CU->cu->partial_dies with the hash table for the new
13822 load_partial_comp_unit (per_cu
);
13824 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13828 internal_error (__FILE__
, __LINE__
,
13829 _("could not find partial DIE 0x%x "
13830 "in cache [from module %s]\n"),
13831 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
13835 /* See if we can figure out if the class lives in a namespace. We do
13836 this by looking for a member function; its demangled name will
13837 contain namespace info, if there is any. */
13840 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
13841 struct dwarf2_cu
*cu
)
13843 /* NOTE: carlton/2003-10-07: Getting the info this way changes
13844 what template types look like, because the demangler
13845 frequently doesn't give the same name as the debug info. We
13846 could fix this by only using the demangled name to get the
13847 prefix (but see comment in read_structure_type). */
13849 struct partial_die_info
*real_pdi
;
13850 struct partial_die_info
*child_pdi
;
13852 /* If this DIE (this DIE's specification, if any) has a parent, then
13853 we should not do this. We'll prepend the parent's fully qualified
13854 name when we create the partial symbol. */
13856 real_pdi
= struct_pdi
;
13857 while (real_pdi
->has_specification
)
13858 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
13859 real_pdi
->spec_is_dwz
, cu
);
13861 if (real_pdi
->die_parent
!= NULL
)
13864 for (child_pdi
= struct_pdi
->die_child
;
13866 child_pdi
= child_pdi
->die_sibling
)
13868 if (child_pdi
->tag
== DW_TAG_subprogram
13869 && child_pdi
->linkage_name
!= NULL
)
13871 char *actual_class_name
13872 = language_class_name_from_physname (cu
->language_defn
,
13873 child_pdi
->linkage_name
);
13874 if (actual_class_name
!= NULL
)
13877 = obsavestring (actual_class_name
,
13878 strlen (actual_class_name
),
13879 &cu
->objfile
->objfile_obstack
);
13880 xfree (actual_class_name
);
13887 /* Adjust PART_DIE before generating a symbol for it. This function
13888 may set the is_external flag or change the DIE's name. */
13891 fixup_partial_die (struct partial_die_info
*part_die
,
13892 struct dwarf2_cu
*cu
)
13894 /* Once we've fixed up a die, there's no point in doing so again.
13895 This also avoids a memory leak if we were to call
13896 guess_partial_die_structure_name multiple times. */
13897 if (part_die
->fixup_called
)
13900 /* If we found a reference attribute and the DIE has no name, try
13901 to find a name in the referred to DIE. */
13903 if (part_die
->name
== NULL
&& part_die
->has_specification
)
13905 struct partial_die_info
*spec_die
;
13907 spec_die
= find_partial_die (part_die
->spec_offset
,
13908 part_die
->spec_is_dwz
, cu
);
13910 fixup_partial_die (spec_die
, cu
);
13912 if (spec_die
->name
)
13914 part_die
->name
= spec_die
->name
;
13916 /* Copy DW_AT_external attribute if it is set. */
13917 if (spec_die
->is_external
)
13918 part_die
->is_external
= spec_die
->is_external
;
13922 /* Set default names for some unnamed DIEs. */
13924 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
13925 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
13927 /* If there is no parent die to provide a namespace, and there are
13928 children, see if we can determine the namespace from their linkage
13930 if (cu
->language
== language_cplus
13931 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
13932 && part_die
->die_parent
== NULL
13933 && part_die
->has_children
13934 && (part_die
->tag
== DW_TAG_class_type
13935 || part_die
->tag
== DW_TAG_structure_type
13936 || part_die
->tag
== DW_TAG_union_type
))
13937 guess_partial_die_structure_name (part_die
, cu
);
13939 /* GCC might emit a nameless struct or union that has a linkage
13940 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13941 if (part_die
->name
== NULL
13942 && (part_die
->tag
== DW_TAG_class_type
13943 || part_die
->tag
== DW_TAG_interface_type
13944 || part_die
->tag
== DW_TAG_structure_type
13945 || part_die
->tag
== DW_TAG_union_type
)
13946 && part_die
->linkage_name
!= NULL
)
13950 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
13955 /* Strip any leading namespaces/classes, keep only the base name.
13956 DW_AT_name for named DIEs does not contain the prefixes. */
13957 base
= strrchr (demangled
, ':');
13958 if (base
&& base
> demangled
&& base
[-1] == ':')
13963 part_die
->name
= obsavestring (base
, strlen (base
),
13964 &cu
->objfile
->objfile_obstack
);
13969 part_die
->fixup_called
= 1;
13972 /* Read an attribute value described by an attribute form. */
13975 read_attribute_value (const struct die_reader_specs
*reader
,
13976 struct attribute
*attr
, unsigned form
,
13977 gdb_byte
*info_ptr
)
13979 struct dwarf2_cu
*cu
= reader
->cu
;
13980 bfd
*abfd
= reader
->abfd
;
13981 struct comp_unit_head
*cu_header
= &cu
->header
;
13982 unsigned int bytes_read
;
13983 struct dwarf_block
*blk
;
13988 case DW_FORM_ref_addr
:
13989 if (cu
->header
.version
== 2)
13990 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13992 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
13993 &cu
->header
, &bytes_read
);
13994 info_ptr
+= bytes_read
;
13996 case DW_FORM_GNU_ref_alt
:
13997 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13998 info_ptr
+= bytes_read
;
14001 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
14002 info_ptr
+= bytes_read
;
14004 case DW_FORM_block2
:
14005 blk
= dwarf_alloc_block (cu
);
14006 blk
->size
= read_2_bytes (abfd
, info_ptr
);
14008 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14009 info_ptr
+= blk
->size
;
14010 DW_BLOCK (attr
) = blk
;
14012 case DW_FORM_block4
:
14013 blk
= dwarf_alloc_block (cu
);
14014 blk
->size
= read_4_bytes (abfd
, info_ptr
);
14016 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14017 info_ptr
+= blk
->size
;
14018 DW_BLOCK (attr
) = blk
;
14020 case DW_FORM_data2
:
14021 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
14024 case DW_FORM_data4
:
14025 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
14028 case DW_FORM_data8
:
14029 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
14032 case DW_FORM_sec_offset
:
14033 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
14034 info_ptr
+= bytes_read
;
14036 case DW_FORM_string
:
14037 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
14038 DW_STRING_IS_CANONICAL (attr
) = 0;
14039 info_ptr
+= bytes_read
;
14042 if (!cu
->per_cu
->is_dwz
)
14044 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
14046 DW_STRING_IS_CANONICAL (attr
) = 0;
14047 info_ptr
+= bytes_read
;
14051 case DW_FORM_GNU_strp_alt
:
14053 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14054 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
14057 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
14058 DW_STRING_IS_CANONICAL (attr
) = 0;
14059 info_ptr
+= bytes_read
;
14062 case DW_FORM_exprloc
:
14063 case DW_FORM_block
:
14064 blk
= dwarf_alloc_block (cu
);
14065 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14066 info_ptr
+= bytes_read
;
14067 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14068 info_ptr
+= blk
->size
;
14069 DW_BLOCK (attr
) = blk
;
14071 case DW_FORM_block1
:
14072 blk
= dwarf_alloc_block (cu
);
14073 blk
->size
= read_1_byte (abfd
, info_ptr
);
14075 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14076 info_ptr
+= blk
->size
;
14077 DW_BLOCK (attr
) = blk
;
14079 case DW_FORM_data1
:
14080 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
14084 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
14087 case DW_FORM_flag_present
:
14088 DW_UNSND (attr
) = 1;
14090 case DW_FORM_sdata
:
14091 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
14092 info_ptr
+= bytes_read
;
14094 case DW_FORM_udata
:
14095 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14096 info_ptr
+= bytes_read
;
14099 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14100 + read_1_byte (abfd
, info_ptr
));
14104 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14105 + read_2_bytes (abfd
, info_ptr
));
14109 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14110 + read_4_bytes (abfd
, info_ptr
));
14114 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14115 + read_8_bytes (abfd
, info_ptr
));
14118 case DW_FORM_ref_sig8
:
14119 /* Convert the signature to something we can record in DW_UNSND
14121 NOTE: This is NULL if the type wasn't found. */
14122 DW_SIGNATURED_TYPE (attr
) =
14123 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
14126 case DW_FORM_ref_udata
:
14127 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14128 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
14129 info_ptr
+= bytes_read
;
14131 case DW_FORM_indirect
:
14132 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14133 info_ptr
+= bytes_read
;
14134 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
14136 case DW_FORM_GNU_addr_index
:
14137 if (reader
->dwo_file
== NULL
)
14139 /* For now flag a hard error.
14140 Later we can turn this into a complaint. */
14141 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14142 dwarf_form_name (form
),
14143 bfd_get_filename (abfd
));
14145 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
14146 info_ptr
+= bytes_read
;
14148 case DW_FORM_GNU_str_index
:
14149 if (reader
->dwo_file
== NULL
)
14151 /* For now flag a hard error.
14152 Later we can turn this into a complaint if warranted. */
14153 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14154 dwarf_form_name (form
),
14155 bfd_get_filename (abfd
));
14158 ULONGEST str_index
=
14159 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14161 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
14162 DW_STRING_IS_CANONICAL (attr
) = 0;
14163 info_ptr
+= bytes_read
;
14167 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
14168 dwarf_form_name (form
),
14169 bfd_get_filename (abfd
));
14173 if (cu
->per_cu
->is_dwz
&& is_ref_attr (attr
))
14174 attr
->form
= DW_FORM_GNU_ref_alt
;
14176 /* We have seen instances where the compiler tried to emit a byte
14177 size attribute of -1 which ended up being encoded as an unsigned
14178 0xffffffff. Although 0xffffffff is technically a valid size value,
14179 an object of this size seems pretty unlikely so we can relatively
14180 safely treat these cases as if the size attribute was invalid and
14181 treat them as zero by default. */
14182 if (attr
->name
== DW_AT_byte_size
14183 && form
== DW_FORM_data4
14184 && DW_UNSND (attr
) >= 0xffffffff)
14187 (&symfile_complaints
,
14188 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
14189 hex_string (DW_UNSND (attr
)));
14190 DW_UNSND (attr
) = 0;
14196 /* Read an attribute described by an abbreviated attribute. */
14199 read_attribute (const struct die_reader_specs
*reader
,
14200 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
14201 gdb_byte
*info_ptr
)
14203 attr
->name
= abbrev
->name
;
14204 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
14207 /* Read dwarf information from a buffer. */
14209 static unsigned int
14210 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
14212 return bfd_get_8 (abfd
, buf
);
14216 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
14218 return bfd_get_signed_8 (abfd
, buf
);
14221 static unsigned int
14222 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14224 return bfd_get_16 (abfd
, buf
);
14228 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14230 return bfd_get_signed_16 (abfd
, buf
);
14233 static unsigned int
14234 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14236 return bfd_get_32 (abfd
, buf
);
14240 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14242 return bfd_get_signed_32 (abfd
, buf
);
14246 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14248 return bfd_get_64 (abfd
, buf
);
14252 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
14253 unsigned int *bytes_read
)
14255 struct comp_unit_head
*cu_header
= &cu
->header
;
14256 CORE_ADDR retval
= 0;
14258 if (cu_header
->signed_addr_p
)
14260 switch (cu_header
->addr_size
)
14263 retval
= bfd_get_signed_16 (abfd
, buf
);
14266 retval
= bfd_get_signed_32 (abfd
, buf
);
14269 retval
= bfd_get_signed_64 (abfd
, buf
);
14272 internal_error (__FILE__
, __LINE__
,
14273 _("read_address: bad switch, signed [in module %s]"),
14274 bfd_get_filename (abfd
));
14279 switch (cu_header
->addr_size
)
14282 retval
= bfd_get_16 (abfd
, buf
);
14285 retval
= bfd_get_32 (abfd
, buf
);
14288 retval
= bfd_get_64 (abfd
, buf
);
14291 internal_error (__FILE__
, __LINE__
,
14292 _("read_address: bad switch, "
14293 "unsigned [in module %s]"),
14294 bfd_get_filename (abfd
));
14298 *bytes_read
= cu_header
->addr_size
;
14302 /* Read the initial length from a section. The (draft) DWARF 3
14303 specification allows the initial length to take up either 4 bytes
14304 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
14305 bytes describe the length and all offsets will be 8 bytes in length
14308 An older, non-standard 64-bit format is also handled by this
14309 function. The older format in question stores the initial length
14310 as an 8-byte quantity without an escape value. Lengths greater
14311 than 2^32 aren't very common which means that the initial 4 bytes
14312 is almost always zero. Since a length value of zero doesn't make
14313 sense for the 32-bit format, this initial zero can be considered to
14314 be an escape value which indicates the presence of the older 64-bit
14315 format. As written, the code can't detect (old format) lengths
14316 greater than 4GB. If it becomes necessary to handle lengths
14317 somewhat larger than 4GB, we could allow other small values (such
14318 as the non-sensical values of 1, 2, and 3) to also be used as
14319 escape values indicating the presence of the old format.
14321 The value returned via bytes_read should be used to increment the
14322 relevant pointer after calling read_initial_length().
14324 [ Note: read_initial_length() and read_offset() are based on the
14325 document entitled "DWARF Debugging Information Format", revision
14326 3, draft 8, dated November 19, 2001. This document was obtained
14329 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
14331 This document is only a draft and is subject to change. (So beware.)
14333 Details regarding the older, non-standard 64-bit format were
14334 determined empirically by examining 64-bit ELF files produced by
14335 the SGI toolchain on an IRIX 6.5 machine.
14337 - Kevin, July 16, 2002
14341 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
14343 LONGEST length
= bfd_get_32 (abfd
, buf
);
14345 if (length
== 0xffffffff)
14347 length
= bfd_get_64 (abfd
, buf
+ 4);
14350 else if (length
== 0)
14352 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
14353 length
= bfd_get_64 (abfd
, buf
);
14364 /* Cover function for read_initial_length.
14365 Returns the length of the object at BUF, and stores the size of the
14366 initial length in *BYTES_READ and stores the size that offsets will be in
14368 If the initial length size is not equivalent to that specified in
14369 CU_HEADER then issue a complaint.
14370 This is useful when reading non-comp-unit headers. */
14373 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
14374 const struct comp_unit_head
*cu_header
,
14375 unsigned int *bytes_read
,
14376 unsigned int *offset_size
)
14378 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
14380 gdb_assert (cu_header
->initial_length_size
== 4
14381 || cu_header
->initial_length_size
== 8
14382 || cu_header
->initial_length_size
== 12);
14384 if (cu_header
->initial_length_size
!= *bytes_read
)
14385 complaint (&symfile_complaints
,
14386 _("intermixed 32-bit and 64-bit DWARF sections"));
14388 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
14392 /* Read an offset from the data stream. The size of the offset is
14393 given by cu_header->offset_size. */
14396 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
14397 unsigned int *bytes_read
)
14399 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
14401 *bytes_read
= cu_header
->offset_size
;
14405 /* Read an offset from the data stream. */
14408 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
14410 LONGEST retval
= 0;
14412 switch (offset_size
)
14415 retval
= bfd_get_32 (abfd
, buf
);
14418 retval
= bfd_get_64 (abfd
, buf
);
14421 internal_error (__FILE__
, __LINE__
,
14422 _("read_offset_1: bad switch [in module %s]"),
14423 bfd_get_filename (abfd
));
14430 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
14432 /* If the size of a host char is 8 bits, we can return a pointer
14433 to the buffer, otherwise we have to copy the data to a buffer
14434 allocated on the temporary obstack. */
14435 gdb_assert (HOST_CHAR_BIT
== 8);
14440 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14442 /* If the size of a host char is 8 bits, we can return a pointer
14443 to the string, otherwise we have to copy the string to a buffer
14444 allocated on the temporary obstack. */
14445 gdb_assert (HOST_CHAR_BIT
== 8);
14448 *bytes_read_ptr
= 1;
14451 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
14452 return (char *) buf
;
14456 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
14458 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
14459 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
14460 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
14461 bfd_get_filename (abfd
));
14462 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
14463 error (_("DW_FORM_strp pointing outside of "
14464 ".debug_str section [in module %s]"),
14465 bfd_get_filename (abfd
));
14466 gdb_assert (HOST_CHAR_BIT
== 8);
14467 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
14469 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
14472 /* Read a string at offset STR_OFFSET in the .debug_str section from
14473 the .dwz file DWZ. Throw an error if the offset is too large. If
14474 the string consists of a single NUL byte, return NULL; otherwise
14475 return a pointer to the string. */
14478 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
14480 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
14482 if (dwz
->str
.buffer
== NULL
)
14483 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
14484 "section [in module %s]"),
14485 bfd_get_filename (dwz
->dwz_bfd
));
14486 if (str_offset
>= dwz
->str
.size
)
14487 error (_("DW_FORM_GNU_strp_alt pointing outside of "
14488 ".debug_str section [in module %s]"),
14489 bfd_get_filename (dwz
->dwz_bfd
));
14490 gdb_assert (HOST_CHAR_BIT
== 8);
14491 if (dwz
->str
.buffer
[str_offset
] == '\0')
14493 return (char *) (dwz
->str
.buffer
+ str_offset
);
14497 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
14498 const struct comp_unit_head
*cu_header
,
14499 unsigned int *bytes_read_ptr
)
14501 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
14503 return read_indirect_string_at_offset (abfd
, str_offset
);
14507 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14510 unsigned int num_read
;
14512 unsigned char byte
;
14520 byte
= bfd_get_8 (abfd
, buf
);
14523 result
|= ((ULONGEST
) (byte
& 127) << shift
);
14524 if ((byte
& 128) == 0)
14530 *bytes_read_ptr
= num_read
;
14535 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14538 int i
, shift
, num_read
;
14539 unsigned char byte
;
14547 byte
= bfd_get_8 (abfd
, buf
);
14550 result
|= ((LONGEST
) (byte
& 127) << shift
);
14552 if ((byte
& 128) == 0)
14557 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
14558 result
|= -(((LONGEST
) 1) << shift
);
14559 *bytes_read_ptr
= num_read
;
14563 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
14564 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
14565 ADDR_SIZE is the size of addresses from the CU header. */
14568 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
14570 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14571 bfd
*abfd
= objfile
->obfd
;
14572 const gdb_byte
*info_ptr
;
14574 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
14575 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
14576 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
14578 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
14579 error (_("DW_FORM_addr_index pointing outside of "
14580 ".debug_addr section [in module %s]"),
14582 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
14583 + addr_base
+ addr_index
* addr_size
);
14584 if (addr_size
== 4)
14585 return bfd_get_32 (abfd
, info_ptr
);
14587 return bfd_get_64 (abfd
, info_ptr
);
14590 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
14593 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
14595 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
14598 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
14601 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
14602 unsigned int *bytes_read
)
14604 bfd
*abfd
= cu
->objfile
->obfd
;
14605 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
14607 return read_addr_index (cu
, addr_index
);
14610 /* Data structure to pass results from dwarf2_read_addr_index_reader
14611 back to dwarf2_read_addr_index. */
14613 struct dwarf2_read_addr_index_data
14615 ULONGEST addr_base
;
14619 /* die_reader_func for dwarf2_read_addr_index. */
14622 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
14623 gdb_byte
*info_ptr
,
14624 struct die_info
*comp_unit_die
,
14628 struct dwarf2_cu
*cu
= reader
->cu
;
14629 struct dwarf2_read_addr_index_data
*aidata
=
14630 (struct dwarf2_read_addr_index_data
*) data
;
14632 aidata
->addr_base
= cu
->addr_base
;
14633 aidata
->addr_size
= cu
->header
.addr_size
;
14636 /* Given an index in .debug_addr, fetch the value.
14637 NOTE: This can be called during dwarf expression evaluation,
14638 long after the debug information has been read, and thus per_cu->cu
14639 may no longer exist. */
14642 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
14643 unsigned int addr_index
)
14645 struct objfile
*objfile
= per_cu
->objfile
;
14646 struct dwarf2_cu
*cu
= per_cu
->cu
;
14647 ULONGEST addr_base
;
14650 /* This is intended to be called from outside this file. */
14651 dw2_setup (objfile
);
14653 /* We need addr_base and addr_size.
14654 If we don't have PER_CU->cu, we have to get it.
14655 Nasty, but the alternative is storing the needed info in PER_CU,
14656 which at this point doesn't seem justified: it's not clear how frequently
14657 it would get used and it would increase the size of every PER_CU.
14658 Entry points like dwarf2_per_cu_addr_size do a similar thing
14659 so we're not in uncharted territory here.
14660 Alas we need to be a bit more complicated as addr_base is contained
14663 We don't need to read the entire CU(/TU).
14664 We just need the header and top level die.
14666 IWBN to use the aging mechanism to let us lazily later discard the CU.
14667 For now we skip this optimization. */
14671 addr_base
= cu
->addr_base
;
14672 addr_size
= cu
->header
.addr_size
;
14676 struct dwarf2_read_addr_index_data aidata
;
14678 /* Note: We can't use init_cutu_and_read_dies_simple here,
14679 we need addr_base. */
14680 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
14681 dwarf2_read_addr_index_reader
, &aidata
);
14682 addr_base
= aidata
.addr_base
;
14683 addr_size
= aidata
.addr_size
;
14686 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
14689 /* Given a DW_AT_str_index, fetch the string. */
14692 read_str_index (const struct die_reader_specs
*reader
,
14693 struct dwarf2_cu
*cu
, ULONGEST str_index
)
14695 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14696 const char *dwo_name
= objfile
->name
;
14697 bfd
*abfd
= objfile
->obfd
;
14698 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
14699 gdb_byte
*info_ptr
;
14700 ULONGEST str_offset
;
14702 dwarf2_read_section (objfile
, §ions
->str
);
14703 dwarf2_read_section (objfile
, §ions
->str_offsets
);
14704 if (sections
->str
.buffer
== NULL
)
14705 error (_("DW_FORM_str_index used without .debug_str.dwo section"
14706 " in CU at offset 0x%lx [in module %s]"),
14707 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14708 if (sections
->str_offsets
.buffer
== NULL
)
14709 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
14710 " in CU at offset 0x%lx [in module %s]"),
14711 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14712 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
14713 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
14714 " section in CU at offset 0x%lx [in module %s]"),
14715 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14716 info_ptr
= (sections
->str_offsets
.buffer
14717 + str_index
* cu
->header
.offset_size
);
14718 if (cu
->header
.offset_size
== 4)
14719 str_offset
= bfd_get_32 (abfd
, info_ptr
);
14721 str_offset
= bfd_get_64 (abfd
, info_ptr
);
14722 if (str_offset
>= sections
->str
.size
)
14723 error (_("Offset from DW_FORM_str_index pointing outside of"
14724 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
14725 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14726 return (char *) (sections
->str
.buffer
+ str_offset
);
14729 /* Return the length of an LEB128 number in BUF. */
14732 leb128_size (const gdb_byte
*buf
)
14734 const gdb_byte
*begin
= buf
;
14740 if ((byte
& 128) == 0)
14741 return buf
- begin
;
14746 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
14753 cu
->language
= language_c
;
14755 case DW_LANG_C_plus_plus
:
14756 cu
->language
= language_cplus
;
14759 cu
->language
= language_d
;
14761 case DW_LANG_Fortran77
:
14762 case DW_LANG_Fortran90
:
14763 case DW_LANG_Fortran95
:
14764 cu
->language
= language_fortran
;
14767 cu
->language
= language_go
;
14769 case DW_LANG_Mips_Assembler
:
14770 cu
->language
= language_asm
;
14773 cu
->language
= language_java
;
14775 case DW_LANG_Ada83
:
14776 case DW_LANG_Ada95
:
14777 cu
->language
= language_ada
;
14779 case DW_LANG_Modula2
:
14780 cu
->language
= language_m2
;
14782 case DW_LANG_Pascal83
:
14783 cu
->language
= language_pascal
;
14786 cu
->language
= language_objc
;
14788 case DW_LANG_Cobol74
:
14789 case DW_LANG_Cobol85
:
14791 cu
->language
= language_minimal
;
14794 cu
->language_defn
= language_def (cu
->language
);
14797 /* Return the named attribute or NULL if not there. */
14799 static struct attribute
*
14800 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
14805 struct attribute
*spec
= NULL
;
14807 for (i
= 0; i
< die
->num_attrs
; ++i
)
14809 if (die
->attrs
[i
].name
== name
)
14810 return &die
->attrs
[i
];
14811 if (die
->attrs
[i
].name
== DW_AT_specification
14812 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
14813 spec
= &die
->attrs
[i
];
14819 die
= follow_die_ref (die
, spec
, &cu
);
14825 /* Return the named attribute or NULL if not there,
14826 but do not follow DW_AT_specification, etc.
14827 This is for use in contexts where we're reading .debug_types dies.
14828 Following DW_AT_specification, DW_AT_abstract_origin will take us
14829 back up the chain, and we want to go down. */
14831 static struct attribute
*
14832 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
14836 for (i
= 0; i
< die
->num_attrs
; ++i
)
14837 if (die
->attrs
[i
].name
== name
)
14838 return &die
->attrs
[i
];
14843 /* Return non-zero iff the attribute NAME is defined for the given DIE,
14844 and holds a non-zero value. This function should only be used for
14845 DW_FORM_flag or DW_FORM_flag_present attributes. */
14848 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
14850 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
14852 return (attr
&& DW_UNSND (attr
));
14856 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
14858 /* A DIE is a declaration if it has a DW_AT_declaration attribute
14859 which value is non-zero. However, we have to be careful with
14860 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
14861 (via dwarf2_flag_true_p) follows this attribute. So we may
14862 end up accidently finding a declaration attribute that belongs
14863 to a different DIE referenced by the specification attribute,
14864 even though the given DIE does not have a declaration attribute. */
14865 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
14866 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
14869 /* Return the die giving the specification for DIE, if there is
14870 one. *SPEC_CU is the CU containing DIE on input, and the CU
14871 containing the return value on output. If there is no
14872 specification, but there is an abstract origin, that is
14875 static struct die_info
*
14876 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
14878 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
14881 if (spec_attr
== NULL
)
14882 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
14884 if (spec_attr
== NULL
)
14887 return follow_die_ref (die
, spec_attr
, spec_cu
);
14890 /* Free the line_header structure *LH, and any arrays and strings it
14892 NOTE: This is also used as a "cleanup" function. */
14895 free_line_header (struct line_header
*lh
)
14897 if (lh
->standard_opcode_lengths
)
14898 xfree (lh
->standard_opcode_lengths
);
14900 /* Remember that all the lh->file_names[i].name pointers are
14901 pointers into debug_line_buffer, and don't need to be freed. */
14902 if (lh
->file_names
)
14903 xfree (lh
->file_names
);
14905 /* Similarly for the include directory names. */
14906 if (lh
->include_dirs
)
14907 xfree (lh
->include_dirs
);
14912 /* Add an entry to LH's include directory table. */
14915 add_include_dir (struct line_header
*lh
, char *include_dir
)
14917 /* Grow the array if necessary. */
14918 if (lh
->include_dirs_size
== 0)
14920 lh
->include_dirs_size
= 1; /* for testing */
14921 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
14922 * sizeof (*lh
->include_dirs
));
14924 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
14926 lh
->include_dirs_size
*= 2;
14927 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
14928 (lh
->include_dirs_size
14929 * sizeof (*lh
->include_dirs
)));
14932 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
14935 /* Add an entry to LH's file name table. */
14938 add_file_name (struct line_header
*lh
,
14940 unsigned int dir_index
,
14941 unsigned int mod_time
,
14942 unsigned int length
)
14944 struct file_entry
*fe
;
14946 /* Grow the array if necessary. */
14947 if (lh
->file_names_size
== 0)
14949 lh
->file_names_size
= 1; /* for testing */
14950 lh
->file_names
= xmalloc (lh
->file_names_size
14951 * sizeof (*lh
->file_names
));
14953 else if (lh
->num_file_names
>= lh
->file_names_size
)
14955 lh
->file_names_size
*= 2;
14956 lh
->file_names
= xrealloc (lh
->file_names
,
14957 (lh
->file_names_size
14958 * sizeof (*lh
->file_names
)));
14961 fe
= &lh
->file_names
[lh
->num_file_names
++];
14963 fe
->dir_index
= dir_index
;
14964 fe
->mod_time
= mod_time
;
14965 fe
->length
= length
;
14966 fe
->included_p
= 0;
14970 /* A convenience function to find the proper .debug_line section for a
14973 static struct dwarf2_section_info
*
14974 get_debug_line_section (struct dwarf2_cu
*cu
)
14976 struct dwarf2_section_info
*section
;
14978 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
14980 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14981 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
14982 else if (cu
->per_cu
->is_dwz
)
14984 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14986 section
= &dwz
->line
;
14989 section
= &dwarf2_per_objfile
->line
;
14994 /* Read the statement program header starting at OFFSET in
14995 .debug_line, or .debug_line.dwo. Return a pointer
14996 to a struct line_header, allocated using xmalloc.
14998 NOTE: the strings in the include directory and file name tables of
14999 the returned object point into the dwarf line section buffer,
15000 and must not be freed. */
15002 static struct line_header
*
15003 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
15005 struct cleanup
*back_to
;
15006 struct line_header
*lh
;
15007 gdb_byte
*line_ptr
;
15008 unsigned int bytes_read
, offset_size
;
15010 char *cur_dir
, *cur_file
;
15011 struct dwarf2_section_info
*section
;
15014 section
= get_debug_line_section (cu
);
15015 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
15016 if (section
->buffer
== NULL
)
15018 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
15019 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
15021 complaint (&symfile_complaints
, _("missing .debug_line section"));
15025 /* We can't do this until we know the section is non-empty.
15026 Only then do we know we have such a section. */
15027 abfd
= section
->asection
->owner
;
15029 /* Make sure that at least there's room for the total_length field.
15030 That could be 12 bytes long, but we're just going to fudge that. */
15031 if (offset
+ 4 >= section
->size
)
15033 dwarf2_statement_list_fits_in_line_number_section_complaint ();
15037 lh
= xmalloc (sizeof (*lh
));
15038 memset (lh
, 0, sizeof (*lh
));
15039 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
15042 line_ptr
= section
->buffer
+ offset
;
15044 /* Read in the header. */
15046 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
15047 &bytes_read
, &offset_size
);
15048 line_ptr
+= bytes_read
;
15049 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
15051 dwarf2_statement_list_fits_in_line_number_section_complaint ();
15054 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
15055 lh
->version
= read_2_bytes (abfd
, line_ptr
);
15057 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
15058 line_ptr
+= offset_size
;
15059 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
15061 if (lh
->version
>= 4)
15063 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
15067 lh
->maximum_ops_per_instruction
= 1;
15069 if (lh
->maximum_ops_per_instruction
== 0)
15071 lh
->maximum_ops_per_instruction
= 1;
15072 complaint (&symfile_complaints
,
15073 _("invalid maximum_ops_per_instruction "
15074 "in `.debug_line' section"));
15077 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
15079 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
15081 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
15083 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
15085 lh
->standard_opcode_lengths
15086 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
15088 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
15089 for (i
= 1; i
< lh
->opcode_base
; ++i
)
15091 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
15095 /* Read directory table. */
15096 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
15098 line_ptr
+= bytes_read
;
15099 add_include_dir (lh
, cur_dir
);
15101 line_ptr
+= bytes_read
;
15103 /* Read file name table. */
15104 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
15106 unsigned int dir_index
, mod_time
, length
;
15108 line_ptr
+= bytes_read
;
15109 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15110 line_ptr
+= bytes_read
;
15111 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15112 line_ptr
+= bytes_read
;
15113 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15114 line_ptr
+= bytes_read
;
15116 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15118 line_ptr
+= bytes_read
;
15119 lh
->statement_program_start
= line_ptr
;
15121 if (line_ptr
> (section
->buffer
+ section
->size
))
15122 complaint (&symfile_complaints
,
15123 _("line number info header doesn't "
15124 "fit in `.debug_line' section"));
15126 discard_cleanups (back_to
);
15130 /* Subroutine of dwarf_decode_lines to simplify it.
15131 Return the file name of the psymtab for included file FILE_INDEX
15132 in line header LH of PST.
15133 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15134 If space for the result is malloc'd, it will be freed by a cleanup.
15135 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
15138 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
15139 const struct partial_symtab
*pst
,
15140 const char *comp_dir
)
15142 const struct file_entry fe
= lh
->file_names
[file_index
];
15143 char *include_name
= fe
.name
;
15144 char *include_name_to_compare
= include_name
;
15145 char *dir_name
= NULL
;
15146 const char *pst_filename
;
15147 char *copied_name
= NULL
;
15151 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
15153 if (!IS_ABSOLUTE_PATH (include_name
)
15154 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
15156 /* Avoid creating a duplicate psymtab for PST.
15157 We do this by comparing INCLUDE_NAME and PST_FILENAME.
15158 Before we do the comparison, however, we need to account
15159 for DIR_NAME and COMP_DIR.
15160 First prepend dir_name (if non-NULL). If we still don't
15161 have an absolute path prepend comp_dir (if non-NULL).
15162 However, the directory we record in the include-file's
15163 psymtab does not contain COMP_DIR (to match the
15164 corresponding symtab(s)).
15169 bash$ gcc -g ./hello.c
15170 include_name = "hello.c"
15172 DW_AT_comp_dir = comp_dir = "/tmp"
15173 DW_AT_name = "./hello.c" */
15175 if (dir_name
!= NULL
)
15177 include_name
= concat (dir_name
, SLASH_STRING
,
15178 include_name
, (char *)NULL
);
15179 include_name_to_compare
= include_name
;
15180 make_cleanup (xfree
, include_name
);
15182 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
15184 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
15185 include_name
, (char *)NULL
);
15189 pst_filename
= pst
->filename
;
15190 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
15192 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
15193 pst_filename
, (char *)NULL
);
15194 pst_filename
= copied_name
;
15197 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
15199 if (include_name_to_compare
!= include_name
)
15200 xfree (include_name_to_compare
);
15201 if (copied_name
!= NULL
)
15202 xfree (copied_name
);
15206 return include_name
;
15209 /* Ignore this record_line request. */
15212 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15217 /* Subroutine of dwarf_decode_lines to simplify it.
15218 Process the line number information in LH. */
15221 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
15222 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
15224 gdb_byte
*line_ptr
, *extended_end
;
15225 gdb_byte
*line_end
;
15226 unsigned int bytes_read
, extended_len
;
15227 unsigned char op_code
, extended_op
, adj_opcode
;
15228 CORE_ADDR baseaddr
;
15229 struct objfile
*objfile
= cu
->objfile
;
15230 bfd
*abfd
= objfile
->obfd
;
15231 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15232 const int decode_for_pst_p
= (pst
!= NULL
);
15233 struct subfile
*last_subfile
= NULL
;
15234 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15237 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15239 line_ptr
= lh
->statement_program_start
;
15240 line_end
= lh
->statement_program_end
;
15242 /* Read the statement sequences until there's nothing left. */
15243 while (line_ptr
< line_end
)
15245 /* state machine registers */
15246 CORE_ADDR address
= 0;
15247 unsigned int file
= 1;
15248 unsigned int line
= 1;
15249 unsigned int column
= 0;
15250 int is_stmt
= lh
->default_is_stmt
;
15251 int basic_block
= 0;
15252 int end_sequence
= 0;
15254 unsigned char op_index
= 0;
15256 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
15258 /* Start a subfile for the current file of the state machine. */
15259 /* lh->include_dirs and lh->file_names are 0-based, but the
15260 directory and file name numbers in the statement program
15262 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15266 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15268 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15271 /* Decode the table. */
15272 while (!end_sequence
)
15274 op_code
= read_1_byte (abfd
, line_ptr
);
15276 if (line_ptr
> line_end
)
15278 dwarf2_debug_line_missing_end_sequence_complaint ();
15282 if (op_code
>= lh
->opcode_base
)
15284 /* Special operand. */
15285 adj_opcode
= op_code
- lh
->opcode_base
;
15286 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
15287 / lh
->maximum_ops_per_instruction
)
15288 * lh
->minimum_instruction_length
);
15289 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
15290 % lh
->maximum_ops_per_instruction
);
15291 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
15292 if (lh
->num_file_names
< file
|| file
== 0)
15293 dwarf2_debug_line_missing_file_complaint ();
15294 /* For now we ignore lines not starting on an
15295 instruction boundary. */
15296 else if (op_index
== 0)
15298 lh
->file_names
[file
- 1].included_p
= 1;
15299 if (!decode_for_pst_p
&& is_stmt
)
15301 if (last_subfile
!= current_subfile
)
15303 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15305 (*p_record_line
) (last_subfile
, 0, addr
);
15306 last_subfile
= current_subfile
;
15308 /* Append row to matrix using current values. */
15309 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15310 (*p_record_line
) (current_subfile
, line
, addr
);
15315 else switch (op_code
)
15317 case DW_LNS_extended_op
:
15318 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
15320 line_ptr
+= bytes_read
;
15321 extended_end
= line_ptr
+ extended_len
;
15322 extended_op
= read_1_byte (abfd
, line_ptr
);
15324 switch (extended_op
)
15326 case DW_LNE_end_sequence
:
15327 p_record_line
= record_line
;
15330 case DW_LNE_set_address
:
15331 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
15333 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15335 /* This line table is for a function which has been
15336 GCd by the linker. Ignore it. PR gdb/12528 */
15339 = line_ptr
- get_debug_line_section (cu
)->buffer
;
15341 complaint (&symfile_complaints
,
15342 _(".debug_line address at offset 0x%lx is 0 "
15344 line_offset
, objfile
->name
);
15345 p_record_line
= noop_record_line
;
15349 line_ptr
+= bytes_read
;
15350 address
+= baseaddr
;
15352 case DW_LNE_define_file
:
15355 unsigned int dir_index
, mod_time
, length
;
15357 cur_file
= read_direct_string (abfd
, line_ptr
,
15359 line_ptr
+= bytes_read
;
15361 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15362 line_ptr
+= bytes_read
;
15364 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15365 line_ptr
+= bytes_read
;
15367 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15368 line_ptr
+= bytes_read
;
15369 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15372 case DW_LNE_set_discriminator
:
15373 /* The discriminator is not interesting to the debugger;
15375 line_ptr
= extended_end
;
15378 complaint (&symfile_complaints
,
15379 _("mangled .debug_line section"));
15382 /* Make sure that we parsed the extended op correctly. If e.g.
15383 we expected a different address size than the producer used,
15384 we may have read the wrong number of bytes. */
15385 if (line_ptr
!= extended_end
)
15387 complaint (&symfile_complaints
,
15388 _("mangled .debug_line section"));
15393 if (lh
->num_file_names
< file
|| file
== 0)
15394 dwarf2_debug_line_missing_file_complaint ();
15397 lh
->file_names
[file
- 1].included_p
= 1;
15398 if (!decode_for_pst_p
&& is_stmt
)
15400 if (last_subfile
!= current_subfile
)
15402 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15404 (*p_record_line
) (last_subfile
, 0, addr
);
15405 last_subfile
= current_subfile
;
15407 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15408 (*p_record_line
) (current_subfile
, line
, addr
);
15413 case DW_LNS_advance_pc
:
15416 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15418 address
+= (((op_index
+ adjust
)
15419 / lh
->maximum_ops_per_instruction
)
15420 * lh
->minimum_instruction_length
);
15421 op_index
= ((op_index
+ adjust
)
15422 % lh
->maximum_ops_per_instruction
);
15423 line_ptr
+= bytes_read
;
15426 case DW_LNS_advance_line
:
15427 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
15428 line_ptr
+= bytes_read
;
15430 case DW_LNS_set_file
:
15432 /* The arrays lh->include_dirs and lh->file_names are
15433 0-based, but the directory and file name numbers in
15434 the statement program are 1-based. */
15435 struct file_entry
*fe
;
15438 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15439 line_ptr
+= bytes_read
;
15440 if (lh
->num_file_names
< file
|| file
== 0)
15441 dwarf2_debug_line_missing_file_complaint ();
15444 fe
= &lh
->file_names
[file
- 1];
15446 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15447 if (!decode_for_pst_p
)
15449 last_subfile
= current_subfile
;
15450 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15455 case DW_LNS_set_column
:
15456 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15457 line_ptr
+= bytes_read
;
15459 case DW_LNS_negate_stmt
:
15460 is_stmt
= (!is_stmt
);
15462 case DW_LNS_set_basic_block
:
15465 /* Add to the address register of the state machine the
15466 address increment value corresponding to special opcode
15467 255. I.e., this value is scaled by the minimum
15468 instruction length since special opcode 255 would have
15469 scaled the increment. */
15470 case DW_LNS_const_add_pc
:
15472 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
15474 address
+= (((op_index
+ adjust
)
15475 / lh
->maximum_ops_per_instruction
)
15476 * lh
->minimum_instruction_length
);
15477 op_index
= ((op_index
+ adjust
)
15478 % lh
->maximum_ops_per_instruction
);
15481 case DW_LNS_fixed_advance_pc
:
15482 address
+= read_2_bytes (abfd
, line_ptr
);
15488 /* Unknown standard opcode, ignore it. */
15491 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
15493 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15494 line_ptr
+= bytes_read
;
15499 if (lh
->num_file_names
< file
|| file
== 0)
15500 dwarf2_debug_line_missing_file_complaint ();
15503 lh
->file_names
[file
- 1].included_p
= 1;
15504 if (!decode_for_pst_p
)
15506 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15507 (*p_record_line
) (current_subfile
, 0, addr
);
15513 /* Decode the Line Number Program (LNP) for the given line_header
15514 structure and CU. The actual information extracted and the type
15515 of structures created from the LNP depends on the value of PST.
15517 1. If PST is NULL, then this procedure uses the data from the program
15518 to create all necessary symbol tables, and their linetables.
15520 2. If PST is not NULL, this procedure reads the program to determine
15521 the list of files included by the unit represented by PST, and
15522 builds all the associated partial symbol tables.
15524 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15525 It is used for relative paths in the line table.
15526 NOTE: When processing partial symtabs (pst != NULL),
15527 comp_dir == pst->dirname.
15529 NOTE: It is important that psymtabs have the same file name (via strcmp)
15530 as the corresponding symtab. Since COMP_DIR is not used in the name of the
15531 symtab we don't use it in the name of the psymtabs we create.
15532 E.g. expand_line_sal requires this when finding psymtabs to expand.
15533 A good testcase for this is mb-inline.exp. */
15536 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
15537 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
15538 int want_line_info
)
15540 struct objfile
*objfile
= cu
->objfile
;
15541 const int decode_for_pst_p
= (pst
!= NULL
);
15542 struct subfile
*first_subfile
= current_subfile
;
15544 if (want_line_info
)
15545 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
15547 if (decode_for_pst_p
)
15551 /* Now that we're done scanning the Line Header Program, we can
15552 create the psymtab of each included file. */
15553 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
15554 if (lh
->file_names
[file_index
].included_p
== 1)
15556 char *include_name
=
15557 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
15558 if (include_name
!= NULL
)
15559 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
15564 /* Make sure a symtab is created for every file, even files
15565 which contain only variables (i.e. no code with associated
15569 for (i
= 0; i
< lh
->num_file_names
; i
++)
15572 struct file_entry
*fe
;
15574 fe
= &lh
->file_names
[i
];
15576 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15577 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15579 /* Skip the main file; we don't need it, and it must be
15580 allocated last, so that it will show up before the
15581 non-primary symtabs in the objfile's symtab list. */
15582 if (current_subfile
== first_subfile
)
15585 if (current_subfile
->symtab
== NULL
)
15586 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
15588 fe
->symtab
= current_subfile
->symtab
;
15593 /* Start a subfile for DWARF. FILENAME is the name of the file and
15594 DIRNAME the name of the source directory which contains FILENAME
15595 or NULL if not known. COMP_DIR is the compilation directory for the
15596 linetable's compilation unit or NULL if not known.
15597 This routine tries to keep line numbers from identical absolute and
15598 relative file names in a common subfile.
15600 Using the `list' example from the GDB testsuite, which resides in
15601 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
15602 of /srcdir/list0.c yields the following debugging information for list0.c:
15604 DW_AT_name: /srcdir/list0.c
15605 DW_AT_comp_dir: /compdir
15606 files.files[0].name: list0.h
15607 files.files[0].dir: /srcdir
15608 files.files[1].name: list0.c
15609 files.files[1].dir: /srcdir
15611 The line number information for list0.c has to end up in a single
15612 subfile, so that `break /srcdir/list0.c:1' works as expected.
15613 start_subfile will ensure that this happens provided that we pass the
15614 concatenation of files.files[1].dir and files.files[1].name as the
15618 dwarf2_start_subfile (char *filename
, const char *dirname
,
15619 const char *comp_dir
)
15623 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
15624 `start_symtab' will always pass the contents of DW_AT_comp_dir as
15625 second argument to start_subfile. To be consistent, we do the
15626 same here. In order not to lose the line information directory,
15627 we concatenate it to the filename when it makes sense.
15628 Note that the Dwarf3 standard says (speaking of filenames in line
15629 information): ``The directory index is ignored for file names
15630 that represent full path names''. Thus ignoring dirname in the
15631 `else' branch below isn't an issue. */
15633 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
15634 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
15636 fullname
= filename
;
15638 start_subfile (fullname
, comp_dir
);
15640 if (fullname
!= filename
)
15644 /* Start a symtab for DWARF.
15645 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
15648 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
15649 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
15651 start_symtab (name
, comp_dir
, low_pc
);
15652 record_debugformat ("DWARF 2");
15653 record_producer (cu
->producer
);
15655 /* We assume that we're processing GCC output. */
15656 processing_gcc_compilation
= 2;
15658 processing_has_namespace_info
= 0;
15662 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
15663 struct dwarf2_cu
*cu
)
15665 struct objfile
*objfile
= cu
->objfile
;
15666 struct comp_unit_head
*cu_header
= &cu
->header
;
15668 /* NOTE drow/2003-01-30: There used to be a comment and some special
15669 code here to turn a symbol with DW_AT_external and a
15670 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
15671 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
15672 with some versions of binutils) where shared libraries could have
15673 relocations against symbols in their debug information - the
15674 minimal symbol would have the right address, but the debug info
15675 would not. It's no longer necessary, because we will explicitly
15676 apply relocations when we read in the debug information now. */
15678 /* A DW_AT_location attribute with no contents indicates that a
15679 variable has been optimized away. */
15680 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
15682 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15686 /* Handle one degenerate form of location expression specially, to
15687 preserve GDB's previous behavior when section offsets are
15688 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
15689 then mark this symbol as LOC_STATIC. */
15691 if (attr_form_is_block (attr
)
15692 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
15693 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
15694 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
15695 && (DW_BLOCK (attr
)->size
15696 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
15698 unsigned int dummy
;
15700 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
15701 SYMBOL_VALUE_ADDRESS (sym
) =
15702 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
15704 SYMBOL_VALUE_ADDRESS (sym
) =
15705 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
15706 SYMBOL_CLASS (sym
) = LOC_STATIC
;
15707 fixup_symbol_section (sym
, objfile
);
15708 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
15709 SYMBOL_SECTION (sym
));
15713 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
15714 expression evaluator, and use LOC_COMPUTED only when necessary
15715 (i.e. when the value of a register or memory location is
15716 referenced, or a thread-local block, etc.). Then again, it might
15717 not be worthwhile. I'm assuming that it isn't unless performance
15718 or memory numbers show me otherwise. */
15720 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
15721 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15723 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
15724 cu
->has_loclist
= 1;
15727 /* Given a pointer to a DWARF information entry, figure out if we need
15728 to make a symbol table entry for it, and if so, create a new entry
15729 and return a pointer to it.
15730 If TYPE is NULL, determine symbol type from the die, otherwise
15731 used the passed type.
15732 If SPACE is not NULL, use it to hold the new symbol. If it is
15733 NULL, allocate a new symbol on the objfile's obstack. */
15735 static struct symbol
*
15736 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
15737 struct symbol
*space
)
15739 struct objfile
*objfile
= cu
->objfile
;
15740 struct symbol
*sym
= NULL
;
15742 struct attribute
*attr
= NULL
;
15743 struct attribute
*attr2
= NULL
;
15744 CORE_ADDR baseaddr
;
15745 struct pending
**list_to_add
= NULL
;
15747 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
15749 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15751 name
= dwarf2_name (die
, cu
);
15754 const char *linkagename
;
15755 int suppress_add
= 0;
15760 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
15761 OBJSTAT (objfile
, n_syms
++);
15763 /* Cache this symbol's name and the name's demangled form (if any). */
15764 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
15765 linkagename
= dwarf2_physname (name
, die
, cu
);
15766 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
15768 /* Fortran does not have mangling standard and the mangling does differ
15769 between gfortran, iFort etc. */
15770 if (cu
->language
== language_fortran
15771 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
15772 symbol_set_demangled_name (&(sym
->ginfo
),
15773 (char *) dwarf2_full_name (name
, die
, cu
),
15776 /* Default assumptions.
15777 Use the passed type or decode it from the die. */
15778 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15779 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15781 SYMBOL_TYPE (sym
) = type
;
15783 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
15784 attr
= dwarf2_attr (die
,
15785 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
15789 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
15792 attr
= dwarf2_attr (die
,
15793 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
15797 int file_index
= DW_UNSND (attr
);
15799 if (cu
->line_header
== NULL
15800 || file_index
> cu
->line_header
->num_file_names
)
15801 complaint (&symfile_complaints
,
15802 _("file index out of range"));
15803 else if (file_index
> 0)
15805 struct file_entry
*fe
;
15807 fe
= &cu
->line_header
->file_names
[file_index
- 1];
15808 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
15815 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15818 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
15820 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
15821 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
15822 SYMBOL_CLASS (sym
) = LOC_LABEL
;
15823 add_symbol_to_list (sym
, cu
->list_in_scope
);
15825 case DW_TAG_subprogram
:
15826 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15828 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15829 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15830 if ((attr2
&& (DW_UNSND (attr2
) != 0))
15831 || cu
->language
== language_ada
)
15833 /* Subprograms marked external are stored as a global symbol.
15834 Ada subprograms, whether marked external or not, are always
15835 stored as a global symbol, because we want to be able to
15836 access them globally. For instance, we want to be able
15837 to break on a nested subprogram without having to
15838 specify the context. */
15839 list_to_add
= &global_symbols
;
15843 list_to_add
= cu
->list_in_scope
;
15846 case DW_TAG_inlined_subroutine
:
15847 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15849 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15850 SYMBOL_INLINED (sym
) = 1;
15851 list_to_add
= cu
->list_in_scope
;
15853 case DW_TAG_template_value_param
:
15855 /* Fall through. */
15856 case DW_TAG_constant
:
15857 case DW_TAG_variable
:
15858 case DW_TAG_member
:
15859 /* Compilation with minimal debug info may result in
15860 variables with missing type entries. Change the
15861 misleading `void' type to something sensible. */
15862 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
15864 = objfile_type (objfile
)->nodebug_data_symbol
;
15866 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15867 /* In the case of DW_TAG_member, we should only be called for
15868 static const members. */
15869 if (die
->tag
== DW_TAG_member
)
15871 /* dwarf2_add_field uses die_is_declaration,
15872 so we do the same. */
15873 gdb_assert (die_is_declaration (die
, cu
));
15878 dwarf2_const_value (attr
, sym
, cu
);
15879 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15882 if (attr2
&& (DW_UNSND (attr2
) != 0))
15883 list_to_add
= &global_symbols
;
15885 list_to_add
= cu
->list_in_scope
;
15889 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15892 var_decode_location (attr
, sym
, cu
);
15893 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15895 /* Fortran explicitly imports any global symbols to the local
15896 scope by DW_TAG_common_block. */
15897 if (cu
->language
== language_fortran
&& die
->parent
15898 && die
->parent
->tag
== DW_TAG_common_block
)
15901 if (SYMBOL_CLASS (sym
) == LOC_STATIC
15902 && SYMBOL_VALUE_ADDRESS (sym
) == 0
15903 && !dwarf2_per_objfile
->has_section_at_zero
)
15905 /* When a static variable is eliminated by the linker,
15906 the corresponding debug information is not stripped
15907 out, but the variable address is set to null;
15908 do not add such variables into symbol table. */
15910 else if (attr2
&& (DW_UNSND (attr2
) != 0))
15912 /* Workaround gfortran PR debug/40040 - it uses
15913 DW_AT_location for variables in -fPIC libraries which may
15914 get overriden by other libraries/executable and get
15915 a different address. Resolve it by the minimal symbol
15916 which may come from inferior's executable using copy
15917 relocation. Make this workaround only for gfortran as for
15918 other compilers GDB cannot guess the minimal symbol
15919 Fortran mangling kind. */
15920 if (cu
->language
== language_fortran
&& die
->parent
15921 && die
->parent
->tag
== DW_TAG_module
15923 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
15924 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15926 /* A variable with DW_AT_external is never static,
15927 but it may be block-scoped. */
15928 list_to_add
= (cu
->list_in_scope
== &file_symbols
15929 ? &global_symbols
: cu
->list_in_scope
);
15932 list_to_add
= cu
->list_in_scope
;
15936 /* We do not know the address of this symbol.
15937 If it is an external symbol and we have type information
15938 for it, enter the symbol as a LOC_UNRESOLVED symbol.
15939 The address of the variable will then be determined from
15940 the minimal symbol table whenever the variable is
15942 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15944 /* Fortran explicitly imports any global symbols to the local
15945 scope by DW_TAG_common_block. */
15946 if (cu
->language
== language_fortran
&& die
->parent
15947 && die
->parent
->tag
== DW_TAG_common_block
)
15949 /* SYMBOL_CLASS doesn't matter here because
15950 read_common_block is going to reset it. */
15952 list_to_add
= cu
->list_in_scope
;
15954 else if (attr2
&& (DW_UNSND (attr2
) != 0)
15955 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
15957 /* A variable with DW_AT_external is never static, but it
15958 may be block-scoped. */
15959 list_to_add
= (cu
->list_in_scope
== &file_symbols
15960 ? &global_symbols
: cu
->list_in_scope
);
15962 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15964 else if (!die_is_declaration (die
, cu
))
15966 /* Use the default LOC_OPTIMIZED_OUT class. */
15967 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
15969 list_to_add
= cu
->list_in_scope
;
15973 case DW_TAG_formal_parameter
:
15974 /* If we are inside a function, mark this as an argument. If
15975 not, we might be looking at an argument to an inlined function
15976 when we do not have enough information to show inlined frames;
15977 pretend it's a local variable in that case so that the user can
15979 if (context_stack_depth
> 0
15980 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
15981 SYMBOL_IS_ARGUMENT (sym
) = 1;
15982 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15985 var_decode_location (attr
, sym
, cu
);
15987 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15990 dwarf2_const_value (attr
, sym
, cu
);
15993 list_to_add
= cu
->list_in_scope
;
15995 case DW_TAG_unspecified_parameters
:
15996 /* From varargs functions; gdb doesn't seem to have any
15997 interest in this information, so just ignore it for now.
16000 case DW_TAG_template_type_param
:
16002 /* Fall through. */
16003 case DW_TAG_class_type
:
16004 case DW_TAG_interface_type
:
16005 case DW_TAG_structure_type
:
16006 case DW_TAG_union_type
:
16007 case DW_TAG_set_type
:
16008 case DW_TAG_enumeration_type
:
16009 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
16010 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
16013 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
16014 really ever be static objects: otherwise, if you try
16015 to, say, break of a class's method and you're in a file
16016 which doesn't mention that class, it won't work unless
16017 the check for all static symbols in lookup_symbol_aux
16018 saves you. See the OtherFileClass tests in
16019 gdb.c++/namespace.exp. */
16023 list_to_add
= (cu
->list_in_scope
== &file_symbols
16024 && (cu
->language
== language_cplus
16025 || cu
->language
== language_java
)
16026 ? &global_symbols
: cu
->list_in_scope
);
16028 /* The semantics of C++ state that "struct foo {
16029 ... }" also defines a typedef for "foo". A Java
16030 class declaration also defines a typedef for the
16032 if (cu
->language
== language_cplus
16033 || cu
->language
== language_java
16034 || cu
->language
== language_ada
)
16036 /* The symbol's name is already allocated along
16037 with this objfile, so we don't need to
16038 duplicate it for the type. */
16039 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
16040 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
16045 case DW_TAG_typedef
:
16046 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
16047 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
16048 list_to_add
= cu
->list_in_scope
;
16050 case DW_TAG_base_type
:
16051 case DW_TAG_subrange_type
:
16052 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
16053 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
16054 list_to_add
= cu
->list_in_scope
;
16056 case DW_TAG_enumerator
:
16057 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
16060 dwarf2_const_value (attr
, sym
, cu
);
16063 /* NOTE: carlton/2003-11-10: See comment above in the
16064 DW_TAG_class_type, etc. block. */
16066 list_to_add
= (cu
->list_in_scope
== &file_symbols
16067 && (cu
->language
== language_cplus
16068 || cu
->language
== language_java
)
16069 ? &global_symbols
: cu
->list_in_scope
);
16072 case DW_TAG_namespace
:
16073 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
16074 list_to_add
= &global_symbols
;
16076 case DW_TAG_common_block
:
16077 SYMBOL_CLASS (sym
) = LOC_STATIC
;
16078 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
16079 add_symbol_to_list (sym
, cu
->list_in_scope
);
16082 /* Not a tag we recognize. Hopefully we aren't processing
16083 trash data, but since we must specifically ignore things
16084 we don't recognize, there is nothing else we should do at
16086 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
16087 dwarf_tag_name (die
->tag
));
16093 sym
->hash_next
= objfile
->template_symbols
;
16094 objfile
->template_symbols
= sym
;
16095 list_to_add
= NULL
;
16098 if (list_to_add
!= NULL
)
16099 add_symbol_to_list (sym
, list_to_add
);
16101 /* For the benefit of old versions of GCC, check for anonymous
16102 namespaces based on the demangled name. */
16103 if (!processing_has_namespace_info
16104 && cu
->language
== language_cplus
)
16105 cp_scan_for_anonymous_namespaces (sym
, objfile
);
16110 /* A wrapper for new_symbol_full that always allocates a new symbol. */
16112 static struct symbol
*
16113 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16115 return new_symbol_full (die
, type
, cu
, NULL
);
16118 /* Given an attr with a DW_FORM_dataN value in host byte order,
16119 zero-extend it as appropriate for the symbol's type. The DWARF
16120 standard (v4) is not entirely clear about the meaning of using
16121 DW_FORM_dataN for a constant with a signed type, where the type is
16122 wider than the data. The conclusion of a discussion on the DWARF
16123 list was that this is unspecified. We choose to always zero-extend
16124 because that is the interpretation long in use by GCC. */
16127 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
16128 const char *name
, struct obstack
*obstack
,
16129 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
16131 struct objfile
*objfile
= cu
->objfile
;
16132 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
16133 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
16134 LONGEST l
= DW_UNSND (attr
);
16136 if (bits
< sizeof (*value
) * 8)
16138 l
&= ((LONGEST
) 1 << bits
) - 1;
16141 else if (bits
== sizeof (*value
) * 8)
16145 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
16146 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
16153 /* Read a constant value from an attribute. Either set *VALUE, or if
16154 the value does not fit in *VALUE, set *BYTES - either already
16155 allocated on the objfile obstack, or newly allocated on OBSTACK,
16156 or, set *BATON, if we translated the constant to a location
16160 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
16161 const char *name
, struct obstack
*obstack
,
16162 struct dwarf2_cu
*cu
,
16163 LONGEST
*value
, gdb_byte
**bytes
,
16164 struct dwarf2_locexpr_baton
**baton
)
16166 struct objfile
*objfile
= cu
->objfile
;
16167 struct comp_unit_head
*cu_header
= &cu
->header
;
16168 struct dwarf_block
*blk
;
16169 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
16170 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
16176 switch (attr
->form
)
16179 case DW_FORM_GNU_addr_index
:
16183 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
16184 dwarf2_const_value_length_mismatch_complaint (name
,
16185 cu_header
->addr_size
,
16186 TYPE_LENGTH (type
));
16187 /* Symbols of this form are reasonably rare, so we just
16188 piggyback on the existing location code rather than writing
16189 a new implementation of symbol_computed_ops. */
16190 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
16191 sizeof (struct dwarf2_locexpr_baton
));
16192 (*baton
)->per_cu
= cu
->per_cu
;
16193 gdb_assert ((*baton
)->per_cu
);
16195 (*baton
)->size
= 2 + cu_header
->addr_size
;
16196 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
16197 (*baton
)->data
= data
;
16199 data
[0] = DW_OP_addr
;
16200 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
16201 byte_order
, DW_ADDR (attr
));
16202 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
16205 case DW_FORM_string
:
16207 case DW_FORM_GNU_str_index
:
16208 case DW_FORM_GNU_strp_alt
:
16209 /* DW_STRING is already allocated on the objfile obstack, point
16211 *bytes
= (gdb_byte
*) DW_STRING (attr
);
16213 case DW_FORM_block1
:
16214 case DW_FORM_block2
:
16215 case DW_FORM_block4
:
16216 case DW_FORM_block
:
16217 case DW_FORM_exprloc
:
16218 blk
= DW_BLOCK (attr
);
16219 if (TYPE_LENGTH (type
) != blk
->size
)
16220 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
16221 TYPE_LENGTH (type
));
16222 *bytes
= blk
->data
;
16225 /* The DW_AT_const_value attributes are supposed to carry the
16226 symbol's value "represented as it would be on the target
16227 architecture." By the time we get here, it's already been
16228 converted to host endianness, so we just need to sign- or
16229 zero-extend it as appropriate. */
16230 case DW_FORM_data1
:
16231 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16232 obstack
, cu
, value
, 8);
16234 case DW_FORM_data2
:
16235 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16236 obstack
, cu
, value
, 16);
16238 case DW_FORM_data4
:
16239 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16240 obstack
, cu
, value
, 32);
16242 case DW_FORM_data8
:
16243 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16244 obstack
, cu
, value
, 64);
16247 case DW_FORM_sdata
:
16248 *value
= DW_SND (attr
);
16251 case DW_FORM_udata
:
16252 *value
= DW_UNSND (attr
);
16256 complaint (&symfile_complaints
,
16257 _("unsupported const value attribute form: '%s'"),
16258 dwarf_form_name (attr
->form
));
16265 /* Copy constant value from an attribute to a symbol. */
16268 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
16269 struct dwarf2_cu
*cu
)
16271 struct objfile
*objfile
= cu
->objfile
;
16272 struct comp_unit_head
*cu_header
= &cu
->header
;
16275 struct dwarf2_locexpr_baton
*baton
;
16277 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
16278 SYMBOL_PRINT_NAME (sym
),
16279 &objfile
->objfile_obstack
, cu
,
16280 &value
, &bytes
, &baton
);
16284 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16285 SYMBOL_LOCATION_BATON (sym
) = baton
;
16286 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
16288 else if (bytes
!= NULL
)
16290 SYMBOL_VALUE_BYTES (sym
) = bytes
;
16291 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
16295 SYMBOL_VALUE (sym
) = value
;
16296 SYMBOL_CLASS (sym
) = LOC_CONST
;
16300 /* Return the type of the die in question using its DW_AT_type attribute. */
16302 static struct type
*
16303 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16305 struct attribute
*type_attr
;
16307 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16310 /* A missing DW_AT_type represents a void type. */
16311 return objfile_type (cu
->objfile
)->builtin_void
;
16314 return lookup_die_type (die
, type_attr
, cu
);
16317 /* True iff CU's producer generates GNAT Ada auxiliary information
16318 that allows to find parallel types through that information instead
16319 of having to do expensive parallel lookups by type name. */
16322 need_gnat_info (struct dwarf2_cu
*cu
)
16324 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
16325 of GNAT produces this auxiliary information, without any indication
16326 that it is produced. Part of enhancing the FSF version of GNAT
16327 to produce that information will be to put in place an indicator
16328 that we can use in order to determine whether the descriptive type
16329 info is available or not. One suggestion that has been made is
16330 to use a new attribute, attached to the CU die. For now, assume
16331 that the descriptive type info is not available. */
16335 /* Return the auxiliary type of the die in question using its
16336 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
16337 attribute is not present. */
16339 static struct type
*
16340 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16342 struct attribute
*type_attr
;
16344 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
16348 return lookup_die_type (die
, type_attr
, cu
);
16351 /* If DIE has a descriptive_type attribute, then set the TYPE's
16352 descriptive type accordingly. */
16355 set_descriptive_type (struct type
*type
, struct die_info
*die
,
16356 struct dwarf2_cu
*cu
)
16358 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
16360 if (descriptive_type
)
16362 ALLOCATE_GNAT_AUX_TYPE (type
);
16363 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
16367 /* Return the containing type of the die in question using its
16368 DW_AT_containing_type attribute. */
16370 static struct type
*
16371 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16373 struct attribute
*type_attr
;
16375 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
16377 error (_("Dwarf Error: Problem turning containing type into gdb type "
16378 "[in module %s]"), cu
->objfile
->name
);
16380 return lookup_die_type (die
, type_attr
, cu
);
16383 /* Look up the type of DIE in CU using its type attribute ATTR.
16384 If there is no type substitute an error marker. */
16386 static struct type
*
16387 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
16388 struct dwarf2_cu
*cu
)
16390 struct objfile
*objfile
= cu
->objfile
;
16391 struct type
*this_type
;
16393 /* First see if we have it cached. */
16395 if (attr
->form
== DW_FORM_GNU_ref_alt
)
16397 struct dwarf2_per_cu_data
*per_cu
;
16398 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16400 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
16401 this_type
= get_die_type_at_offset (offset
, per_cu
);
16403 else if (is_ref_attr (attr
))
16405 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16407 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
16409 else if (attr
->form
== DW_FORM_ref_sig8
)
16411 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16413 /* sig_type will be NULL if the signatured type is missing from
16415 if (sig_type
== NULL
)
16416 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16417 "at 0x%x [in module %s]"),
16418 die
->offset
.sect_off
, objfile
->name
);
16420 gdb_assert (sig_type
->per_cu
.is_debug_types
);
16421 /* If we haven't filled in type_offset_in_section yet, then we
16422 haven't read the type in yet. */
16424 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
16427 get_die_type_at_offset (sig_type
->type_offset_in_section
,
16428 &sig_type
->per_cu
);
16433 dump_die_for_error (die
);
16434 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
16435 dwarf_attr_name (attr
->name
), objfile
->name
);
16438 /* If not cached we need to read it in. */
16440 if (this_type
== NULL
)
16442 struct die_info
*type_die
;
16443 struct dwarf2_cu
*type_cu
= cu
;
16445 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
16446 /* If we found the type now, it's probably because the type came
16447 from an inter-CU reference and the type's CU got expanded before
16449 this_type
= get_die_type (type_die
, type_cu
);
16450 if (this_type
== NULL
)
16451 this_type
= read_type_die_1 (type_die
, type_cu
);
16454 /* If we still don't have a type use an error marker. */
16456 if (this_type
== NULL
)
16458 char *message
, *saved
;
16460 /* read_type_die already issued a complaint. */
16461 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
16463 cu
->header
.offset
.sect_off
,
16464 die
->offset
.sect_off
);
16465 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
16466 message
, strlen (message
));
16469 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
16475 /* Return the type in DIE, CU.
16476 Returns NULL for invalid types.
16478 This first does a lookup in the appropriate type_hash table,
16479 and only reads the die in if necessary.
16481 NOTE: This can be called when reading in partial or full symbols. */
16483 static struct type
*
16484 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
16486 struct type
*this_type
;
16488 this_type
= get_die_type (die
, cu
);
16492 return read_type_die_1 (die
, cu
);
16495 /* Read the type in DIE, CU.
16496 Returns NULL for invalid types. */
16498 static struct type
*
16499 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
16501 struct type
*this_type
= NULL
;
16505 case DW_TAG_class_type
:
16506 case DW_TAG_interface_type
:
16507 case DW_TAG_structure_type
:
16508 case DW_TAG_union_type
:
16509 this_type
= read_structure_type (die
, cu
);
16511 case DW_TAG_enumeration_type
:
16512 this_type
= read_enumeration_type (die
, cu
);
16514 case DW_TAG_subprogram
:
16515 case DW_TAG_subroutine_type
:
16516 case DW_TAG_inlined_subroutine
:
16517 this_type
= read_subroutine_type (die
, cu
);
16519 case DW_TAG_array_type
:
16520 this_type
= read_array_type (die
, cu
);
16522 case DW_TAG_set_type
:
16523 this_type
= read_set_type (die
, cu
);
16525 case DW_TAG_pointer_type
:
16526 this_type
= read_tag_pointer_type (die
, cu
);
16528 case DW_TAG_ptr_to_member_type
:
16529 this_type
= read_tag_ptr_to_member_type (die
, cu
);
16531 case DW_TAG_reference_type
:
16532 this_type
= read_tag_reference_type (die
, cu
);
16534 case DW_TAG_const_type
:
16535 this_type
= read_tag_const_type (die
, cu
);
16537 case DW_TAG_volatile_type
:
16538 this_type
= read_tag_volatile_type (die
, cu
);
16540 case DW_TAG_string_type
:
16541 this_type
= read_tag_string_type (die
, cu
);
16543 case DW_TAG_typedef
:
16544 this_type
= read_typedef (die
, cu
);
16546 case DW_TAG_subrange_type
:
16547 this_type
= read_subrange_type (die
, cu
);
16549 case DW_TAG_base_type
:
16550 this_type
= read_base_type (die
, cu
);
16552 case DW_TAG_unspecified_type
:
16553 this_type
= read_unspecified_type (die
, cu
);
16555 case DW_TAG_namespace
:
16556 this_type
= read_namespace_type (die
, cu
);
16558 case DW_TAG_module
:
16559 this_type
= read_module_type (die
, cu
);
16562 complaint (&symfile_complaints
,
16563 _("unexpected tag in read_type_die: '%s'"),
16564 dwarf_tag_name (die
->tag
));
16571 /* See if we can figure out if the class lives in a namespace. We do
16572 this by looking for a member function; its demangled name will
16573 contain namespace info, if there is any.
16574 Return the computed name or NULL.
16575 Space for the result is allocated on the objfile's obstack.
16576 This is the full-die version of guess_partial_die_structure_name.
16577 In this case we know DIE has no useful parent. */
16580 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16582 struct die_info
*spec_die
;
16583 struct dwarf2_cu
*spec_cu
;
16584 struct die_info
*child
;
16587 spec_die
= die_specification (die
, &spec_cu
);
16588 if (spec_die
!= NULL
)
16594 for (child
= die
->child
;
16596 child
= child
->sibling
)
16598 if (child
->tag
== DW_TAG_subprogram
)
16600 struct attribute
*attr
;
16602 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
16604 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
16608 = language_class_name_from_physname (cu
->language_defn
,
16612 if (actual_name
!= NULL
)
16614 char *die_name
= dwarf2_name (die
, cu
);
16616 if (die_name
!= NULL
16617 && strcmp (die_name
, actual_name
) != 0)
16619 /* Strip off the class name from the full name.
16620 We want the prefix. */
16621 int die_name_len
= strlen (die_name
);
16622 int actual_name_len
= strlen (actual_name
);
16624 /* Test for '::' as a sanity check. */
16625 if (actual_name_len
> die_name_len
+ 2
16626 && actual_name
[actual_name_len
16627 - die_name_len
- 1] == ':')
16629 obsavestring (actual_name
,
16630 actual_name_len
- die_name_len
- 2,
16631 &cu
->objfile
->objfile_obstack
);
16634 xfree (actual_name
);
16643 /* GCC might emit a nameless typedef that has a linkage name. Determine the
16644 prefix part in such case. See
16645 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16648 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16650 struct attribute
*attr
;
16653 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
16654 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
16657 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16658 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
16661 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16663 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16664 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16667 /* dwarf2_name had to be already called. */
16668 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
16670 /* Strip the base name, keep any leading namespaces/classes. */
16671 base
= strrchr (DW_STRING (attr
), ':');
16672 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
16675 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
16676 &cu
->objfile
->objfile_obstack
);
16679 /* Return the name of the namespace/class that DIE is defined within,
16680 or "" if we can't tell. The caller should not xfree the result.
16682 For example, if we're within the method foo() in the following
16692 then determine_prefix on foo's die will return "N::C". */
16694 static const char *
16695 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16697 struct die_info
*parent
, *spec_die
;
16698 struct dwarf2_cu
*spec_cu
;
16699 struct type
*parent_type
;
16702 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
16703 && cu
->language
!= language_fortran
)
16706 retval
= anonymous_struct_prefix (die
, cu
);
16710 /* We have to be careful in the presence of DW_AT_specification.
16711 For example, with GCC 3.4, given the code
16715 // Definition of N::foo.
16719 then we'll have a tree of DIEs like this:
16721 1: DW_TAG_compile_unit
16722 2: DW_TAG_namespace // N
16723 3: DW_TAG_subprogram // declaration of N::foo
16724 4: DW_TAG_subprogram // definition of N::foo
16725 DW_AT_specification // refers to die #3
16727 Thus, when processing die #4, we have to pretend that we're in
16728 the context of its DW_AT_specification, namely the contex of die
16731 spec_die
= die_specification (die
, &spec_cu
);
16732 if (spec_die
== NULL
)
16733 parent
= die
->parent
;
16736 parent
= spec_die
->parent
;
16740 if (parent
== NULL
)
16742 else if (parent
->building_fullname
)
16745 const char *parent_name
;
16747 /* It has been seen on RealView 2.2 built binaries,
16748 DW_TAG_template_type_param types actually _defined_ as
16749 children of the parent class:
16752 template class <class Enum> Class{};
16753 Class<enum E> class_e;
16755 1: DW_TAG_class_type (Class)
16756 2: DW_TAG_enumeration_type (E)
16757 3: DW_TAG_enumerator (enum1:0)
16758 3: DW_TAG_enumerator (enum2:1)
16760 2: DW_TAG_template_type_param
16761 DW_AT_type DW_FORM_ref_udata (E)
16763 Besides being broken debug info, it can put GDB into an
16764 infinite loop. Consider:
16766 When we're building the full name for Class<E>, we'll start
16767 at Class, and go look over its template type parameters,
16768 finding E. We'll then try to build the full name of E, and
16769 reach here. We're now trying to build the full name of E,
16770 and look over the parent DIE for containing scope. In the
16771 broken case, if we followed the parent DIE of E, we'd again
16772 find Class, and once again go look at its template type
16773 arguments, etc., etc. Simply don't consider such parent die
16774 as source-level parent of this die (it can't be, the language
16775 doesn't allow it), and break the loop here. */
16776 name
= dwarf2_name (die
, cu
);
16777 parent_name
= dwarf2_name (parent
, cu
);
16778 complaint (&symfile_complaints
,
16779 _("template param type '%s' defined within parent '%s'"),
16780 name
? name
: "<unknown>",
16781 parent_name
? parent_name
: "<unknown>");
16785 switch (parent
->tag
)
16787 case DW_TAG_namespace
:
16788 parent_type
= read_type_die (parent
, cu
);
16789 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
16790 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
16791 Work around this problem here. */
16792 if (cu
->language
== language_cplus
16793 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
16795 /* We give a name to even anonymous namespaces. */
16796 return TYPE_TAG_NAME (parent_type
);
16797 case DW_TAG_class_type
:
16798 case DW_TAG_interface_type
:
16799 case DW_TAG_structure_type
:
16800 case DW_TAG_union_type
:
16801 case DW_TAG_module
:
16802 parent_type
= read_type_die (parent
, cu
);
16803 if (TYPE_TAG_NAME (parent_type
) != NULL
)
16804 return TYPE_TAG_NAME (parent_type
);
16806 /* An anonymous structure is only allowed non-static data
16807 members; no typedefs, no member functions, et cetera.
16808 So it does not need a prefix. */
16810 case DW_TAG_compile_unit
:
16811 case DW_TAG_partial_unit
:
16812 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
16813 if (cu
->language
== language_cplus
16814 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16815 && die
->child
!= NULL
16816 && (die
->tag
== DW_TAG_class_type
16817 || die
->tag
== DW_TAG_structure_type
16818 || die
->tag
== DW_TAG_union_type
))
16820 char *name
= guess_full_die_structure_name (die
, cu
);
16826 return determine_prefix (parent
, cu
);
16830 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
16831 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
16832 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
16833 an obconcat, otherwise allocate storage for the result. The CU argument is
16834 used to determine the language and hence, the appropriate separator. */
16836 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
16839 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
16840 int physname
, struct dwarf2_cu
*cu
)
16842 const char *lead
= "";
16845 if (suffix
== NULL
|| suffix
[0] == '\0'
16846 || prefix
== NULL
|| prefix
[0] == '\0')
16848 else if (cu
->language
== language_java
)
16850 else if (cu
->language
== language_fortran
&& physname
)
16852 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
16853 DW_AT_MIPS_linkage_name is preferred and used instead. */
16861 if (prefix
== NULL
)
16863 if (suffix
== NULL
)
16869 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
16871 strcpy (retval
, lead
);
16872 strcat (retval
, prefix
);
16873 strcat (retval
, sep
);
16874 strcat (retval
, suffix
);
16879 /* We have an obstack. */
16880 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
16884 /* Return sibling of die, NULL if no sibling. */
16886 static struct die_info
*
16887 sibling_die (struct die_info
*die
)
16889 return die
->sibling
;
16892 /* Get name of a die, return NULL if not found. */
16895 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
16896 struct obstack
*obstack
)
16898 if (name
&& cu
->language
== language_cplus
)
16900 char *canon_name
= cp_canonicalize_string (name
);
16902 if (canon_name
!= NULL
)
16904 if (strcmp (canon_name
, name
) != 0)
16905 name
= obsavestring (canon_name
, strlen (canon_name
),
16907 xfree (canon_name
);
16914 /* Get name of a die, return NULL if not found. */
16917 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16919 struct attribute
*attr
;
16921 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16922 if ((!attr
|| !DW_STRING (attr
))
16923 && die
->tag
!= DW_TAG_class_type
16924 && die
->tag
!= DW_TAG_interface_type
16925 && die
->tag
!= DW_TAG_structure_type
16926 && die
->tag
!= DW_TAG_union_type
)
16931 case DW_TAG_compile_unit
:
16932 case DW_TAG_partial_unit
:
16933 /* Compilation units have a DW_AT_name that is a filename, not
16934 a source language identifier. */
16935 case DW_TAG_enumeration_type
:
16936 case DW_TAG_enumerator
:
16937 /* These tags always have simple identifiers already; no need
16938 to canonicalize them. */
16939 return DW_STRING (attr
);
16941 case DW_TAG_subprogram
:
16942 /* Java constructors will all be named "<init>", so return
16943 the class name when we see this special case. */
16944 if (cu
->language
== language_java
16945 && DW_STRING (attr
) != NULL
16946 && strcmp (DW_STRING (attr
), "<init>") == 0)
16948 struct dwarf2_cu
*spec_cu
= cu
;
16949 struct die_info
*spec_die
;
16951 /* GCJ will output '<init>' for Java constructor names.
16952 For this special case, return the name of the parent class. */
16954 /* GCJ may output suprogram DIEs with AT_specification set.
16955 If so, use the name of the specified DIE. */
16956 spec_die
= die_specification (die
, &spec_cu
);
16957 if (spec_die
!= NULL
)
16958 return dwarf2_name (spec_die
, spec_cu
);
16963 if (die
->tag
== DW_TAG_class_type
)
16964 return dwarf2_name (die
, cu
);
16966 while (die
->tag
!= DW_TAG_compile_unit
16967 && die
->tag
!= DW_TAG_partial_unit
);
16971 case DW_TAG_class_type
:
16972 case DW_TAG_interface_type
:
16973 case DW_TAG_structure_type
:
16974 case DW_TAG_union_type
:
16975 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
16976 structures or unions. These were of the form "._%d" in GCC 4.1,
16977 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
16978 and GCC 4.4. We work around this problem by ignoring these. */
16979 if (attr
&& DW_STRING (attr
)
16980 && (strncmp (DW_STRING (attr
), "._", 2) == 0
16981 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
16984 /* GCC might emit a nameless typedef that has a linkage name. See
16985 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16986 if (!attr
|| DW_STRING (attr
) == NULL
)
16988 char *demangled
= NULL
;
16990 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16992 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16994 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16997 /* Avoid demangling DW_STRING (attr) the second time on a second
16998 call for the same DIE. */
16999 if (!DW_STRING_IS_CANONICAL (attr
))
17000 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
17006 /* FIXME: we already did this for the partial symbol... */
17007 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
17008 &cu
->objfile
->objfile_obstack
);
17009 DW_STRING_IS_CANONICAL (attr
) = 1;
17012 /* Strip any leading namespaces/classes, keep only the base name.
17013 DW_AT_name for named DIEs does not contain the prefixes. */
17014 base
= strrchr (DW_STRING (attr
), ':');
17015 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
17018 return DW_STRING (attr
);
17027 if (!DW_STRING_IS_CANONICAL (attr
))
17030 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
17031 &cu
->objfile
->objfile_obstack
);
17032 DW_STRING_IS_CANONICAL (attr
) = 1;
17034 return DW_STRING (attr
);
17037 /* Return the die that this die in an extension of, or NULL if there
17038 is none. *EXT_CU is the CU containing DIE on input, and the CU
17039 containing the return value on output. */
17041 static struct die_info
*
17042 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
17044 struct attribute
*attr
;
17046 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
17050 return follow_die_ref (die
, attr
, ext_cu
);
17053 /* Convert a DIE tag into its string name. */
17055 static const char *
17056 dwarf_tag_name (unsigned tag
)
17058 const char *name
= get_DW_TAG_name (tag
);
17061 return "DW_TAG_<unknown>";
17066 /* Convert a DWARF attribute code into its string name. */
17068 static const char *
17069 dwarf_attr_name (unsigned attr
)
17073 #ifdef MIPS /* collides with DW_AT_HP_block_index */
17074 if (attr
== DW_AT_MIPS_fde
)
17075 return "DW_AT_MIPS_fde";
17077 if (attr
== DW_AT_HP_block_index
)
17078 return "DW_AT_HP_block_index";
17081 name
= get_DW_AT_name (attr
);
17084 return "DW_AT_<unknown>";
17089 /* Convert a DWARF value form code into its string name. */
17091 static const char *
17092 dwarf_form_name (unsigned form
)
17094 const char *name
= get_DW_FORM_name (form
);
17097 return "DW_FORM_<unknown>";
17103 dwarf_bool_name (unsigned mybool
)
17111 /* Convert a DWARF type code into its string name. */
17113 static const char *
17114 dwarf_type_encoding_name (unsigned enc
)
17116 const char *name
= get_DW_ATE_name (enc
);
17119 return "DW_ATE_<unknown>";
17125 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
17129 print_spaces (indent
, f
);
17130 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
17131 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
17133 if (die
->parent
!= NULL
)
17135 print_spaces (indent
, f
);
17136 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
17137 die
->parent
->offset
.sect_off
);
17140 print_spaces (indent
, f
);
17141 fprintf_unfiltered (f
, " has children: %s\n",
17142 dwarf_bool_name (die
->child
!= NULL
));
17144 print_spaces (indent
, f
);
17145 fprintf_unfiltered (f
, " attributes:\n");
17147 for (i
= 0; i
< die
->num_attrs
; ++i
)
17149 print_spaces (indent
, f
);
17150 fprintf_unfiltered (f
, " %s (%s) ",
17151 dwarf_attr_name (die
->attrs
[i
].name
),
17152 dwarf_form_name (die
->attrs
[i
].form
));
17154 switch (die
->attrs
[i
].form
)
17157 case DW_FORM_GNU_addr_index
:
17158 fprintf_unfiltered (f
, "address: ");
17159 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
17161 case DW_FORM_block2
:
17162 case DW_FORM_block4
:
17163 case DW_FORM_block
:
17164 case DW_FORM_block1
:
17165 fprintf_unfiltered (f
, "block: size %s",
17166 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17168 case DW_FORM_exprloc
:
17169 fprintf_unfiltered (f
, "expression: size %s",
17170 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17172 case DW_FORM_ref_addr
:
17173 fprintf_unfiltered (f
, "ref address: ");
17174 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17176 case DW_FORM_GNU_ref_alt
:
17177 fprintf_unfiltered (f
, "alt ref address: ");
17178 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17184 case DW_FORM_ref_udata
:
17185 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
17186 (long) (DW_UNSND (&die
->attrs
[i
])));
17188 case DW_FORM_data1
:
17189 case DW_FORM_data2
:
17190 case DW_FORM_data4
:
17191 case DW_FORM_data8
:
17192 case DW_FORM_udata
:
17193 case DW_FORM_sdata
:
17194 fprintf_unfiltered (f
, "constant: %s",
17195 pulongest (DW_UNSND (&die
->attrs
[i
])));
17197 case DW_FORM_sec_offset
:
17198 fprintf_unfiltered (f
, "section offset: %s",
17199 pulongest (DW_UNSND (&die
->attrs
[i
])));
17201 case DW_FORM_ref_sig8
:
17202 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
17203 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
17204 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
17206 fprintf_unfiltered (f
, "signatured type, offset: unknown");
17208 case DW_FORM_string
:
17210 case DW_FORM_GNU_str_index
:
17211 case DW_FORM_GNU_strp_alt
:
17212 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
17213 DW_STRING (&die
->attrs
[i
])
17214 ? DW_STRING (&die
->attrs
[i
]) : "",
17215 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
17218 if (DW_UNSND (&die
->attrs
[i
]))
17219 fprintf_unfiltered (f
, "flag: TRUE");
17221 fprintf_unfiltered (f
, "flag: FALSE");
17223 case DW_FORM_flag_present
:
17224 fprintf_unfiltered (f
, "flag: TRUE");
17226 case DW_FORM_indirect
:
17227 /* The reader will have reduced the indirect form to
17228 the "base form" so this form should not occur. */
17229 fprintf_unfiltered (f
,
17230 "unexpected attribute form: DW_FORM_indirect");
17233 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
17234 die
->attrs
[i
].form
);
17237 fprintf_unfiltered (f
, "\n");
17242 dump_die_for_error (struct die_info
*die
)
17244 dump_die_shallow (gdb_stderr
, 0, die
);
17248 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
17250 int indent
= level
* 4;
17252 gdb_assert (die
!= NULL
);
17254 if (level
>= max_level
)
17257 dump_die_shallow (f
, indent
, die
);
17259 if (die
->child
!= NULL
)
17261 print_spaces (indent
, f
);
17262 fprintf_unfiltered (f
, " Children:");
17263 if (level
+ 1 < max_level
)
17265 fprintf_unfiltered (f
, "\n");
17266 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
17270 fprintf_unfiltered (f
,
17271 " [not printed, max nesting level reached]\n");
17275 if (die
->sibling
!= NULL
&& level
> 0)
17277 dump_die_1 (f
, level
, max_level
, die
->sibling
);
17281 /* This is called from the pdie macro in gdbinit.in.
17282 It's not static so gcc will keep a copy callable from gdb. */
17285 dump_die (struct die_info
*die
, int max_level
)
17287 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
17291 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
17295 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
17301 /* DW_ADDR is always stored already as sect_offset; despite for the forms
17302 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
17305 is_ref_attr (struct attribute
*attr
)
17307 switch (attr
->form
)
17309 case DW_FORM_ref_addr
:
17314 case DW_FORM_ref_udata
:
17315 case DW_FORM_GNU_ref_alt
:
17322 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
17326 dwarf2_get_ref_die_offset (struct attribute
*attr
)
17328 sect_offset retval
= { DW_UNSND (attr
) };
17330 if (is_ref_attr (attr
))
17333 retval
.sect_off
= 0;
17334 complaint (&symfile_complaints
,
17335 _("unsupported die ref attribute form: '%s'"),
17336 dwarf_form_name (attr
->form
));
17340 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
17341 * the value held by the attribute is not constant. */
17344 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
17346 if (attr
->form
== DW_FORM_sdata
)
17347 return DW_SND (attr
);
17348 else if (attr
->form
== DW_FORM_udata
17349 || attr
->form
== DW_FORM_data1
17350 || attr
->form
== DW_FORM_data2
17351 || attr
->form
== DW_FORM_data4
17352 || attr
->form
== DW_FORM_data8
)
17353 return DW_UNSND (attr
);
17356 complaint (&symfile_complaints
,
17357 _("Attribute value is not a constant (%s)"),
17358 dwarf_form_name (attr
->form
));
17359 return default_value
;
17363 /* Follow reference or signature attribute ATTR of SRC_DIE.
17364 On entry *REF_CU is the CU of SRC_DIE.
17365 On exit *REF_CU is the CU of the result. */
17367 static struct die_info
*
17368 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
17369 struct dwarf2_cu
**ref_cu
)
17371 struct die_info
*die
;
17373 if (is_ref_attr (attr
))
17374 die
= follow_die_ref (src_die
, attr
, ref_cu
);
17375 else if (attr
->form
== DW_FORM_ref_sig8
)
17376 die
= follow_die_sig (src_die
, attr
, ref_cu
);
17379 dump_die_for_error (src_die
);
17380 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
17381 (*ref_cu
)->objfile
->name
);
17387 /* Follow reference OFFSET.
17388 On entry *REF_CU is the CU of the source die referencing OFFSET.
17389 On exit *REF_CU is the CU of the result.
17390 Returns NULL if OFFSET is invalid. */
17392 static struct die_info
*
17393 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
17394 struct dwarf2_cu
**ref_cu
)
17396 struct die_info temp_die
;
17397 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
17399 gdb_assert (cu
->per_cu
!= NULL
);
17403 if (cu
->per_cu
->is_debug_types
)
17405 /* .debug_types CUs cannot reference anything outside their CU.
17406 If they need to, they have to reference a signatured type via
17407 DW_FORM_ref_sig8. */
17408 if (! offset_in_cu_p (&cu
->header
, offset
))
17411 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
17412 || ! offset_in_cu_p (&cu
->header
, offset
))
17414 struct dwarf2_per_cu_data
*per_cu
;
17416 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
17419 /* If necessary, add it to the queue and load its DIEs. */
17420 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
17421 load_full_comp_unit (per_cu
, cu
->language
);
17423 target_cu
= per_cu
->cu
;
17425 else if (cu
->dies
== NULL
)
17427 /* We're loading full DIEs during partial symbol reading. */
17428 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
17429 load_full_comp_unit (cu
->per_cu
, language_minimal
);
17432 *ref_cu
= target_cu
;
17433 temp_die
.offset
= offset
;
17434 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
17437 /* Follow reference attribute ATTR of SRC_DIE.
17438 On entry *REF_CU is the CU of SRC_DIE.
17439 On exit *REF_CU is the CU of the result. */
17441 static struct die_info
*
17442 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
17443 struct dwarf2_cu
**ref_cu
)
17445 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17446 struct dwarf2_cu
*cu
= *ref_cu
;
17447 struct die_info
*die
;
17449 die
= follow_die_offset (offset
,
17450 (attr
->form
== DW_FORM_GNU_ref_alt
17451 || cu
->per_cu
->is_dwz
),
17454 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
17455 "at 0x%x [in module %s]"),
17456 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
17461 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
17462 Returned value is intended for DW_OP_call*. Returned
17463 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
17465 struct dwarf2_locexpr_baton
17466 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
17467 struct dwarf2_per_cu_data
*per_cu
,
17468 CORE_ADDR (*get_frame_pc
) (void *baton
),
17471 struct dwarf2_cu
*cu
;
17472 struct die_info
*die
;
17473 struct attribute
*attr
;
17474 struct dwarf2_locexpr_baton retval
;
17476 dw2_setup (per_cu
->objfile
);
17478 if (per_cu
->cu
== NULL
)
17482 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
17484 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
17485 offset
.sect_off
, per_cu
->objfile
->name
);
17487 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17490 /* DWARF: "If there is no such attribute, then there is no effect.".
17491 DATA is ignored if SIZE is 0. */
17493 retval
.data
= NULL
;
17496 else if (attr_form_is_section_offset (attr
))
17498 struct dwarf2_loclist_baton loclist_baton
;
17499 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
17502 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
17504 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
17506 retval
.size
= size
;
17510 if (!attr_form_is_block (attr
))
17511 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
17512 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
17513 offset
.sect_off
, per_cu
->objfile
->name
);
17515 retval
.data
= DW_BLOCK (attr
)->data
;
17516 retval
.size
= DW_BLOCK (attr
)->size
;
17518 retval
.per_cu
= cu
->per_cu
;
17520 age_cached_comp_units ();
17525 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
17528 struct dwarf2_locexpr_baton
17529 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
17530 struct dwarf2_per_cu_data
*per_cu
,
17531 CORE_ADDR (*get_frame_pc
) (void *baton
),
17534 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
17536 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
17539 /* Return the type of the DIE at DIE_OFFSET in the CU named by
17543 dwarf2_get_die_type (cu_offset die_offset
,
17544 struct dwarf2_per_cu_data
*per_cu
)
17546 sect_offset die_offset_sect
;
17548 dw2_setup (per_cu
->objfile
);
17550 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
17551 return get_die_type_at_offset (die_offset_sect
, per_cu
);
17554 /* Follow the signature attribute ATTR in SRC_DIE.
17555 On entry *REF_CU is the CU of SRC_DIE.
17556 On exit *REF_CU is the CU of the result. */
17558 static struct die_info
*
17559 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
17560 struct dwarf2_cu
**ref_cu
)
17562 struct objfile
*objfile
= (*ref_cu
)->objfile
;
17563 struct die_info temp_die
;
17564 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
17565 struct dwarf2_cu
*sig_cu
;
17566 struct die_info
*die
;
17568 /* sig_type will be NULL if the signatured type is missing from
17570 if (sig_type
== NULL
)
17571 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
17572 "at 0x%x [in module %s]"),
17573 src_die
->offset
.sect_off
, objfile
->name
);
17575 /* If necessary, add it to the queue and load its DIEs. */
17577 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
17578 read_signatured_type (sig_type
);
17580 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
17582 sig_cu
= sig_type
->per_cu
.cu
;
17583 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
17584 temp_die
.offset
= sig_type
->type_offset_in_section
;
17585 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
17586 temp_die
.offset
.sect_off
);
17593 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
17594 "from DIE at 0x%x [in module %s]"),
17595 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
17598 /* Given an offset of a signatured type, return its signatured_type. */
17600 static struct signatured_type
*
17601 lookup_signatured_type_at_offset (struct objfile
*objfile
,
17602 struct dwarf2_section_info
*section
,
17603 sect_offset offset
)
17605 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
17606 unsigned int length
, initial_length_size
;
17607 unsigned int sig_offset
;
17608 struct signatured_type find_entry
, *sig_type
;
17610 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
17611 sig_offset
= (initial_length_size
17613 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
17614 + 1 /*address_size*/);
17615 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
17616 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
17618 /* This is only used to lookup previously recorded types.
17619 If we didn't find it, it's our bug. */
17620 gdb_assert (sig_type
!= NULL
);
17621 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
17626 /* Load the DIEs associated with type unit PER_CU into memory. */
17629 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
17631 struct signatured_type
*sig_type
;
17633 /* Caller is responsible for ensuring type_unit_groups don't get here. */
17634 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
17636 /* We have the per_cu, but we need the signatured_type.
17637 Fortunately this is an easy translation. */
17638 gdb_assert (per_cu
->is_debug_types
);
17639 sig_type
= (struct signatured_type
*) per_cu
;
17641 gdb_assert (per_cu
->cu
== NULL
);
17643 read_signatured_type (sig_type
);
17645 gdb_assert (per_cu
->cu
!= NULL
);
17648 /* die_reader_func for read_signatured_type.
17649 This is identical to load_full_comp_unit_reader,
17650 but is kept separate for now. */
17653 read_signatured_type_reader (const struct die_reader_specs
*reader
,
17654 gdb_byte
*info_ptr
,
17655 struct die_info
*comp_unit_die
,
17659 struct dwarf2_cu
*cu
= reader
->cu
;
17661 gdb_assert (cu
->die_hash
== NULL
);
17663 htab_create_alloc_ex (cu
->header
.length
/ 12,
17667 &cu
->comp_unit_obstack
,
17668 hashtab_obstack_allocate
,
17669 dummy_obstack_deallocate
);
17672 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
17673 &info_ptr
, comp_unit_die
);
17674 cu
->dies
= comp_unit_die
;
17675 /* comp_unit_die is not stored in die_hash, no need. */
17677 /* We try not to read any attributes in this function, because not
17678 all CUs needed for references have been loaded yet, and symbol
17679 table processing isn't initialized. But we have to set the CU language,
17680 or we won't be able to build types correctly.
17681 Similarly, if we do not read the producer, we can not apply
17682 producer-specific interpretation. */
17683 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
17686 /* Read in a signatured type and build its CU and DIEs.
17687 If the type is a stub for the real type in a DWO file,
17688 read in the real type from the DWO file as well. */
17691 read_signatured_type (struct signatured_type
*sig_type
)
17693 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
17695 gdb_assert (per_cu
->is_debug_types
);
17696 gdb_assert (per_cu
->cu
== NULL
);
17698 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
17699 read_signatured_type_reader
, NULL
);
17702 /* Decode simple location descriptions.
17703 Given a pointer to a dwarf block that defines a location, compute
17704 the location and return the value.
17706 NOTE drow/2003-11-18: This function is called in two situations
17707 now: for the address of static or global variables (partial symbols
17708 only) and for offsets into structures which are expected to be
17709 (more or less) constant. The partial symbol case should go away,
17710 and only the constant case should remain. That will let this
17711 function complain more accurately. A few special modes are allowed
17712 without complaint for global variables (for instance, global
17713 register values and thread-local values).
17715 A location description containing no operations indicates that the
17716 object is optimized out. The return value is 0 for that case.
17717 FIXME drow/2003-11-16: No callers check for this case any more; soon all
17718 callers will only want a very basic result and this can become a
17721 Note that stack[0] is unused except as a default error return. */
17724 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
17726 struct objfile
*objfile
= cu
->objfile
;
17728 size_t size
= blk
->size
;
17729 gdb_byte
*data
= blk
->data
;
17730 CORE_ADDR stack
[64];
17732 unsigned int bytes_read
, unsnd
;
17738 stack
[++stacki
] = 0;
17777 stack
[++stacki
] = op
- DW_OP_lit0
;
17812 stack
[++stacki
] = op
- DW_OP_reg0
;
17814 dwarf2_complex_location_expr_complaint ();
17818 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
17820 stack
[++stacki
] = unsnd
;
17822 dwarf2_complex_location_expr_complaint ();
17826 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
17831 case DW_OP_const1u
:
17832 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
17836 case DW_OP_const1s
:
17837 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
17841 case DW_OP_const2u
:
17842 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
17846 case DW_OP_const2s
:
17847 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
17851 case DW_OP_const4u
:
17852 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
17856 case DW_OP_const4s
:
17857 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
17861 case DW_OP_const8u
:
17862 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
17867 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
17873 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
17878 stack
[stacki
+ 1] = stack
[stacki
];
17883 stack
[stacki
- 1] += stack
[stacki
];
17887 case DW_OP_plus_uconst
:
17888 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
17894 stack
[stacki
- 1] -= stack
[stacki
];
17899 /* If we're not the last op, then we definitely can't encode
17900 this using GDB's address_class enum. This is valid for partial
17901 global symbols, although the variable's address will be bogus
17904 dwarf2_complex_location_expr_complaint ();
17907 case DW_OP_GNU_push_tls_address
:
17908 /* The top of the stack has the offset from the beginning
17909 of the thread control block at which the variable is located. */
17910 /* Nothing should follow this operator, so the top of stack would
17912 /* This is valid for partial global symbols, but the variable's
17913 address will be bogus in the psymtab. Make it always at least
17914 non-zero to not look as a variable garbage collected by linker
17915 which have DW_OP_addr 0. */
17917 dwarf2_complex_location_expr_complaint ();
17921 case DW_OP_GNU_uninit
:
17924 case DW_OP_GNU_addr_index
:
17925 case DW_OP_GNU_const_index
:
17926 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
17933 const char *name
= get_DW_OP_name (op
);
17936 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
17939 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
17943 return (stack
[stacki
]);
17946 /* Enforce maximum stack depth of SIZE-1 to avoid writing
17947 outside of the allocated space. Also enforce minimum>0. */
17948 if (stacki
>= ARRAY_SIZE (stack
) - 1)
17950 complaint (&symfile_complaints
,
17951 _("location description stack overflow"));
17957 complaint (&symfile_complaints
,
17958 _("location description stack underflow"));
17962 return (stack
[stacki
]);
17965 /* memory allocation interface */
17967 static struct dwarf_block
*
17968 dwarf_alloc_block (struct dwarf2_cu
*cu
)
17970 struct dwarf_block
*blk
;
17972 blk
= (struct dwarf_block
*)
17973 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
17977 static struct die_info
*
17978 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
17980 struct die_info
*die
;
17981 size_t size
= sizeof (struct die_info
);
17984 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
17986 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
17987 memset (die
, 0, sizeof (struct die_info
));
17992 /* Macro support. */
17994 /* Return the full name of file number I in *LH's file name table.
17995 Use COMP_DIR as the name of the current directory of the
17996 compilation. The result is allocated using xmalloc; the caller is
17997 responsible for freeing it. */
17999 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
18001 /* Is the file number a valid index into the line header's file name
18002 table? Remember that file numbers start with one, not zero. */
18003 if (1 <= file
&& file
<= lh
->num_file_names
)
18005 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
18007 if (IS_ABSOLUTE_PATH (fe
->name
))
18008 return xstrdup (fe
->name
);
18016 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18022 dir_len
= strlen (dir
);
18023 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
18024 strcpy (full_name
, dir
);
18025 full_name
[dir_len
] = '/';
18026 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
18030 return xstrdup (fe
->name
);
18035 /* The compiler produced a bogus file number. We can at least
18036 record the macro definitions made in the file, even if we
18037 won't be able to find the file by name. */
18038 char fake_name
[80];
18040 xsnprintf (fake_name
, sizeof (fake_name
),
18041 "<bad macro file number %d>", file
);
18043 complaint (&symfile_complaints
,
18044 _("bad file number in macro information (%d)"),
18047 return xstrdup (fake_name
);
18052 static struct macro_source_file
*
18053 macro_start_file (int file
, int line
,
18054 struct macro_source_file
*current_file
,
18055 const char *comp_dir
,
18056 struct line_header
*lh
, struct objfile
*objfile
)
18058 /* The full name of this source file. */
18059 char *full_name
= file_full_name (file
, lh
, comp_dir
);
18061 /* We don't create a macro table for this compilation unit
18062 at all until we actually get a filename. */
18063 if (! pending_macros
)
18064 pending_macros
= new_macro_table (&objfile
->per_bfd
->storage_obstack
,
18065 objfile
->per_bfd
->macro_cache
);
18067 if (! current_file
)
18069 /* If we have no current file, then this must be the start_file
18070 directive for the compilation unit's main source file. */
18071 current_file
= macro_set_main (pending_macros
, full_name
);
18072 macro_define_special (pending_macros
);
18075 current_file
= macro_include (current_file
, line
, full_name
);
18079 return current_file
;
18083 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
18084 followed by a null byte. */
18086 copy_string (const char *buf
, int len
)
18088 char *s
= xmalloc (len
+ 1);
18090 memcpy (s
, buf
, len
);
18096 static const char *
18097 consume_improper_spaces (const char *p
, const char *body
)
18101 complaint (&symfile_complaints
,
18102 _("macro definition contains spaces "
18103 "in formal argument list:\n`%s'"),
18115 parse_macro_definition (struct macro_source_file
*file
, int line
,
18120 /* The body string takes one of two forms. For object-like macro
18121 definitions, it should be:
18123 <macro name> " " <definition>
18125 For function-like macro definitions, it should be:
18127 <macro name> "() " <definition>
18129 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
18131 Spaces may appear only where explicitly indicated, and in the
18134 The Dwarf 2 spec says that an object-like macro's name is always
18135 followed by a space, but versions of GCC around March 2002 omit
18136 the space when the macro's definition is the empty string.
18138 The Dwarf 2 spec says that there should be no spaces between the
18139 formal arguments in a function-like macro's formal argument list,
18140 but versions of GCC around March 2002 include spaces after the
18144 /* Find the extent of the macro name. The macro name is terminated
18145 by either a space or null character (for an object-like macro) or
18146 an opening paren (for a function-like macro). */
18147 for (p
= body
; *p
; p
++)
18148 if (*p
== ' ' || *p
== '(')
18151 if (*p
== ' ' || *p
== '\0')
18153 /* It's an object-like macro. */
18154 int name_len
= p
- body
;
18155 char *name
= copy_string (body
, name_len
);
18156 const char *replacement
;
18159 replacement
= body
+ name_len
+ 1;
18162 dwarf2_macro_malformed_definition_complaint (body
);
18163 replacement
= body
+ name_len
;
18166 macro_define_object (file
, line
, name
, replacement
);
18170 else if (*p
== '(')
18172 /* It's a function-like macro. */
18173 char *name
= copy_string (body
, p
- body
);
18176 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
18180 p
= consume_improper_spaces (p
, body
);
18182 /* Parse the formal argument list. */
18183 while (*p
&& *p
!= ')')
18185 /* Find the extent of the current argument name. */
18186 const char *arg_start
= p
;
18188 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
18191 if (! *p
|| p
== arg_start
)
18192 dwarf2_macro_malformed_definition_complaint (body
);
18195 /* Make sure argv has room for the new argument. */
18196 if (argc
>= argv_size
)
18199 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
18202 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
18205 p
= consume_improper_spaces (p
, body
);
18207 /* Consume the comma, if present. */
18212 p
= consume_improper_spaces (p
, body
);
18221 /* Perfectly formed definition, no complaints. */
18222 macro_define_function (file
, line
, name
,
18223 argc
, (const char **) argv
,
18225 else if (*p
== '\0')
18227 /* Complain, but do define it. */
18228 dwarf2_macro_malformed_definition_complaint (body
);
18229 macro_define_function (file
, line
, name
,
18230 argc
, (const char **) argv
,
18234 /* Just complain. */
18235 dwarf2_macro_malformed_definition_complaint (body
);
18238 /* Just complain. */
18239 dwarf2_macro_malformed_definition_complaint (body
);
18245 for (i
= 0; i
< argc
; i
++)
18251 dwarf2_macro_malformed_definition_complaint (body
);
18254 /* Skip some bytes from BYTES according to the form given in FORM.
18255 Returns the new pointer. */
18258 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
18259 enum dwarf_form form
,
18260 unsigned int offset_size
,
18261 struct dwarf2_section_info
*section
)
18263 unsigned int bytes_read
;
18267 case DW_FORM_data1
:
18272 case DW_FORM_data2
:
18276 case DW_FORM_data4
:
18280 case DW_FORM_data8
:
18284 case DW_FORM_string
:
18285 read_direct_string (abfd
, bytes
, &bytes_read
);
18286 bytes
+= bytes_read
;
18289 case DW_FORM_sec_offset
:
18291 case DW_FORM_GNU_strp_alt
:
18292 bytes
+= offset_size
;
18295 case DW_FORM_block
:
18296 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
18297 bytes
+= bytes_read
;
18300 case DW_FORM_block1
:
18301 bytes
+= 1 + read_1_byte (abfd
, bytes
);
18303 case DW_FORM_block2
:
18304 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
18306 case DW_FORM_block4
:
18307 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
18310 case DW_FORM_sdata
:
18311 case DW_FORM_udata
:
18312 case DW_FORM_GNU_addr_index
:
18313 case DW_FORM_GNU_str_index
:
18314 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
18317 dwarf2_section_buffer_overflow_complaint (section
);
18325 complaint (&symfile_complaints
,
18326 _("invalid form 0x%x in `%s'"),
18328 section
->asection
->name
);
18336 /* A helper for dwarf_decode_macros that handles skipping an unknown
18337 opcode. Returns an updated pointer to the macro data buffer; or,
18338 on error, issues a complaint and returns NULL. */
18341 skip_unknown_opcode (unsigned int opcode
,
18342 gdb_byte
**opcode_definitions
,
18343 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18345 unsigned int offset_size
,
18346 struct dwarf2_section_info
*section
)
18348 unsigned int bytes_read
, i
;
18352 if (opcode_definitions
[opcode
] == NULL
)
18354 complaint (&symfile_complaints
,
18355 _("unrecognized DW_MACFINO opcode 0x%x"),
18360 defn
= opcode_definitions
[opcode
];
18361 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
18362 defn
+= bytes_read
;
18364 for (i
= 0; i
< arg
; ++i
)
18366 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
18368 if (mac_ptr
== NULL
)
18370 /* skip_form_bytes already issued the complaint. */
18378 /* A helper function which parses the header of a macro section.
18379 If the macro section is the extended (for now called "GNU") type,
18380 then this updates *OFFSET_SIZE. Returns a pointer to just after
18381 the header, or issues a complaint and returns NULL on error. */
18384 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
18387 unsigned int *offset_size
,
18388 int section_is_gnu
)
18390 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
18392 if (section_is_gnu
)
18394 unsigned int version
, flags
;
18396 version
= read_2_bytes (abfd
, mac_ptr
);
18399 complaint (&symfile_complaints
,
18400 _("unrecognized version `%d' in .debug_macro section"),
18406 flags
= read_1_byte (abfd
, mac_ptr
);
18408 *offset_size
= (flags
& 1) ? 8 : 4;
18410 if ((flags
& 2) != 0)
18411 /* We don't need the line table offset. */
18412 mac_ptr
+= *offset_size
;
18414 /* Vendor opcode descriptions. */
18415 if ((flags
& 4) != 0)
18417 unsigned int i
, count
;
18419 count
= read_1_byte (abfd
, mac_ptr
);
18421 for (i
= 0; i
< count
; ++i
)
18423 unsigned int opcode
, bytes_read
;
18426 opcode
= read_1_byte (abfd
, mac_ptr
);
18428 opcode_definitions
[opcode
] = mac_ptr
;
18429 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18430 mac_ptr
+= bytes_read
;
18439 /* A helper for dwarf_decode_macros that handles the GNU extensions,
18440 including DW_MACRO_GNU_transparent_include. */
18443 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18444 struct macro_source_file
*current_file
,
18445 struct line_header
*lh
, char *comp_dir
,
18446 struct dwarf2_section_info
*section
,
18447 int section_is_gnu
, int section_is_dwz
,
18448 unsigned int offset_size
,
18449 struct objfile
*objfile
,
18450 htab_t include_hash
)
18452 enum dwarf_macro_record_type macinfo_type
;
18453 int at_commandline
;
18454 gdb_byte
*opcode_definitions
[256];
18456 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18457 &offset_size
, section_is_gnu
);
18458 if (mac_ptr
== NULL
)
18460 /* We already issued a complaint. */
18464 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
18465 GDB is still reading the definitions from command line. First
18466 DW_MACINFO_start_file will need to be ignored as it was already executed
18467 to create CURRENT_FILE for the main source holding also the command line
18468 definitions. On first met DW_MACINFO_start_file this flag is reset to
18469 normally execute all the remaining DW_MACINFO_start_file macinfos. */
18471 at_commandline
= 1;
18475 /* Do we at least have room for a macinfo type byte? */
18476 if (mac_ptr
>= mac_end
)
18478 dwarf2_section_buffer_overflow_complaint (section
);
18482 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18485 /* Note that we rely on the fact that the corresponding GNU and
18486 DWARF constants are the same. */
18487 switch (macinfo_type
)
18489 /* A zero macinfo type indicates the end of the macro
18494 case DW_MACRO_GNU_define
:
18495 case DW_MACRO_GNU_undef
:
18496 case DW_MACRO_GNU_define_indirect
:
18497 case DW_MACRO_GNU_undef_indirect
:
18498 case DW_MACRO_GNU_define_indirect_alt
:
18499 case DW_MACRO_GNU_undef_indirect_alt
:
18501 unsigned int bytes_read
;
18506 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18507 mac_ptr
+= bytes_read
;
18509 if (macinfo_type
== DW_MACRO_GNU_define
18510 || macinfo_type
== DW_MACRO_GNU_undef
)
18512 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18513 mac_ptr
+= bytes_read
;
18517 LONGEST str_offset
;
18519 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18520 mac_ptr
+= offset_size
;
18522 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
18523 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
18526 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18528 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
18531 body
= read_indirect_string_at_offset (abfd
, str_offset
);
18534 is_define
= (macinfo_type
== DW_MACRO_GNU_define
18535 || macinfo_type
== DW_MACRO_GNU_define_indirect
18536 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
18537 if (! current_file
)
18539 /* DWARF violation as no main source is present. */
18540 complaint (&symfile_complaints
,
18541 _("debug info with no main source gives macro %s "
18543 is_define
? _("definition") : _("undefinition"),
18547 if ((line
== 0 && !at_commandline
)
18548 || (line
!= 0 && at_commandline
))
18549 complaint (&symfile_complaints
,
18550 _("debug info gives %s macro %s with %s line %d: %s"),
18551 at_commandline
? _("command-line") : _("in-file"),
18552 is_define
? _("definition") : _("undefinition"),
18553 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
18556 parse_macro_definition (current_file
, line
, body
);
18559 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
18560 || macinfo_type
== DW_MACRO_GNU_undef_indirect
18561 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
18562 macro_undef (current_file
, line
, body
);
18567 case DW_MACRO_GNU_start_file
:
18569 unsigned int bytes_read
;
18572 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18573 mac_ptr
+= bytes_read
;
18574 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18575 mac_ptr
+= bytes_read
;
18577 if ((line
== 0 && !at_commandline
)
18578 || (line
!= 0 && at_commandline
))
18579 complaint (&symfile_complaints
,
18580 _("debug info gives source %d included "
18581 "from %s at %s line %d"),
18582 file
, at_commandline
? _("command-line") : _("file"),
18583 line
== 0 ? _("zero") : _("non-zero"), line
);
18585 if (at_commandline
)
18587 /* This DW_MACRO_GNU_start_file was executed in the
18589 at_commandline
= 0;
18592 current_file
= macro_start_file (file
, line
,
18593 current_file
, comp_dir
,
18598 case DW_MACRO_GNU_end_file
:
18599 if (! current_file
)
18600 complaint (&symfile_complaints
,
18601 _("macro debug info has an unmatched "
18602 "`close_file' directive"));
18605 current_file
= current_file
->included_by
;
18606 if (! current_file
)
18608 enum dwarf_macro_record_type next_type
;
18610 /* GCC circa March 2002 doesn't produce the zero
18611 type byte marking the end of the compilation
18612 unit. Complain if it's not there, but exit no
18615 /* Do we at least have room for a macinfo type byte? */
18616 if (mac_ptr
>= mac_end
)
18618 dwarf2_section_buffer_overflow_complaint (section
);
18622 /* We don't increment mac_ptr here, so this is just
18624 next_type
= read_1_byte (abfd
, mac_ptr
);
18625 if (next_type
!= 0)
18626 complaint (&symfile_complaints
,
18627 _("no terminating 0-type entry for "
18628 "macros in `.debug_macinfo' section"));
18635 case DW_MACRO_GNU_transparent_include
:
18636 case DW_MACRO_GNU_transparent_include_alt
:
18640 bfd
*include_bfd
= abfd
;
18641 struct dwarf2_section_info
*include_section
= section
;
18642 struct dwarf2_section_info alt_section
;
18643 gdb_byte
*include_mac_end
= mac_end
;
18644 int is_dwz
= section_is_dwz
;
18645 gdb_byte
*new_mac_ptr
;
18647 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18648 mac_ptr
+= offset_size
;
18650 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
18652 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18654 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
18657 include_bfd
= dwz
->macro
.asection
->owner
;
18658 include_section
= &dwz
->macro
;
18659 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
18663 new_mac_ptr
= include_section
->buffer
+ offset
;
18664 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
18668 /* This has actually happened; see
18669 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
18670 complaint (&symfile_complaints
,
18671 _("recursive DW_MACRO_GNU_transparent_include in "
18672 ".debug_macro section"));
18676 *slot
= new_mac_ptr
;
18678 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
18679 include_mac_end
, current_file
,
18681 section
, section_is_gnu
, is_dwz
,
18682 offset_size
, objfile
, include_hash
);
18684 htab_remove_elt (include_hash
, new_mac_ptr
);
18689 case DW_MACINFO_vendor_ext
:
18690 if (!section_is_gnu
)
18692 unsigned int bytes_read
;
18695 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18696 mac_ptr
+= bytes_read
;
18697 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18698 mac_ptr
+= bytes_read
;
18700 /* We don't recognize any vendor extensions. */
18706 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18707 mac_ptr
, mac_end
, abfd
, offset_size
,
18709 if (mac_ptr
== NULL
)
18713 } while (macinfo_type
!= 0);
18717 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
18718 char *comp_dir
, int section_is_gnu
)
18720 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18721 struct line_header
*lh
= cu
->line_header
;
18723 gdb_byte
*mac_ptr
, *mac_end
;
18724 struct macro_source_file
*current_file
= 0;
18725 enum dwarf_macro_record_type macinfo_type
;
18726 unsigned int offset_size
= cu
->header
.offset_size
;
18727 gdb_byte
*opcode_definitions
[256];
18728 struct cleanup
*cleanup
;
18729 htab_t include_hash
;
18731 struct dwarf2_section_info
*section
;
18732 const char *section_name
;
18734 if (cu
->dwo_unit
!= NULL
)
18736 if (section_is_gnu
)
18738 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
18739 section_name
= ".debug_macro.dwo";
18743 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
18744 section_name
= ".debug_macinfo.dwo";
18749 if (section_is_gnu
)
18751 section
= &dwarf2_per_objfile
->macro
;
18752 section_name
= ".debug_macro";
18756 section
= &dwarf2_per_objfile
->macinfo
;
18757 section_name
= ".debug_macinfo";
18761 dwarf2_read_section (objfile
, section
);
18762 if (section
->buffer
== NULL
)
18764 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
18767 abfd
= section
->asection
->owner
;
18769 /* First pass: Find the name of the base filename.
18770 This filename is needed in order to process all macros whose definition
18771 (or undefinition) comes from the command line. These macros are defined
18772 before the first DW_MACINFO_start_file entry, and yet still need to be
18773 associated to the base file.
18775 To determine the base file name, we scan the macro definitions until we
18776 reach the first DW_MACINFO_start_file entry. We then initialize
18777 CURRENT_FILE accordingly so that any macro definition found before the
18778 first DW_MACINFO_start_file can still be associated to the base file. */
18780 mac_ptr
= section
->buffer
+ offset
;
18781 mac_end
= section
->buffer
+ section
->size
;
18783 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18784 &offset_size
, section_is_gnu
);
18785 if (mac_ptr
== NULL
)
18787 /* We already issued a complaint. */
18793 /* Do we at least have room for a macinfo type byte? */
18794 if (mac_ptr
>= mac_end
)
18796 /* Complaint is printed during the second pass as GDB will probably
18797 stop the first pass earlier upon finding
18798 DW_MACINFO_start_file. */
18802 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18805 /* Note that we rely on the fact that the corresponding GNU and
18806 DWARF constants are the same. */
18807 switch (macinfo_type
)
18809 /* A zero macinfo type indicates the end of the macro
18814 case DW_MACRO_GNU_define
:
18815 case DW_MACRO_GNU_undef
:
18816 /* Only skip the data by MAC_PTR. */
18818 unsigned int bytes_read
;
18820 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18821 mac_ptr
+= bytes_read
;
18822 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18823 mac_ptr
+= bytes_read
;
18827 case DW_MACRO_GNU_start_file
:
18829 unsigned int bytes_read
;
18832 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18833 mac_ptr
+= bytes_read
;
18834 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18835 mac_ptr
+= bytes_read
;
18837 current_file
= macro_start_file (file
, line
, current_file
,
18838 comp_dir
, lh
, objfile
);
18842 case DW_MACRO_GNU_end_file
:
18843 /* No data to skip by MAC_PTR. */
18846 case DW_MACRO_GNU_define_indirect
:
18847 case DW_MACRO_GNU_undef_indirect
:
18848 case DW_MACRO_GNU_define_indirect_alt
:
18849 case DW_MACRO_GNU_undef_indirect_alt
:
18851 unsigned int bytes_read
;
18853 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18854 mac_ptr
+= bytes_read
;
18855 mac_ptr
+= offset_size
;
18859 case DW_MACRO_GNU_transparent_include
:
18860 case DW_MACRO_GNU_transparent_include_alt
:
18861 /* Note that, according to the spec, a transparent include
18862 chain cannot call DW_MACRO_GNU_start_file. So, we can just
18863 skip this opcode. */
18864 mac_ptr
+= offset_size
;
18867 case DW_MACINFO_vendor_ext
:
18868 /* Only skip the data by MAC_PTR. */
18869 if (!section_is_gnu
)
18871 unsigned int bytes_read
;
18873 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18874 mac_ptr
+= bytes_read
;
18875 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18876 mac_ptr
+= bytes_read
;
18881 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18882 mac_ptr
, mac_end
, abfd
, offset_size
,
18884 if (mac_ptr
== NULL
)
18888 } while (macinfo_type
!= 0 && current_file
== NULL
);
18890 /* Second pass: Process all entries.
18892 Use the AT_COMMAND_LINE flag to determine whether we are still processing
18893 command-line macro definitions/undefinitions. This flag is unset when we
18894 reach the first DW_MACINFO_start_file entry. */
18896 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
18897 NULL
, xcalloc
, xfree
);
18898 cleanup
= make_cleanup_htab_delete (include_hash
);
18899 mac_ptr
= section
->buffer
+ offset
;
18900 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
18902 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
18903 current_file
, lh
, comp_dir
, section
,
18905 offset_size
, objfile
, include_hash
);
18906 do_cleanups (cleanup
);
18909 /* Check if the attribute's form is a DW_FORM_block*
18910 if so return true else false. */
18913 attr_form_is_block (struct attribute
*attr
)
18915 return (attr
== NULL
? 0 :
18916 attr
->form
== DW_FORM_block1
18917 || attr
->form
== DW_FORM_block2
18918 || attr
->form
== DW_FORM_block4
18919 || attr
->form
== DW_FORM_block
18920 || attr
->form
== DW_FORM_exprloc
);
18923 /* Return non-zero if ATTR's value is a section offset --- classes
18924 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
18925 You may use DW_UNSND (attr) to retrieve such offsets.
18927 Section 7.5.4, "Attribute Encodings", explains that no attribute
18928 may have a value that belongs to more than one of these classes; it
18929 would be ambiguous if we did, because we use the same forms for all
18933 attr_form_is_section_offset (struct attribute
*attr
)
18935 return (attr
->form
== DW_FORM_data4
18936 || attr
->form
== DW_FORM_data8
18937 || attr
->form
== DW_FORM_sec_offset
);
18940 /* Return non-zero if ATTR's value falls in the 'constant' class, or
18941 zero otherwise. When this function returns true, you can apply
18942 dwarf2_get_attr_constant_value to it.
18944 However, note that for some attributes you must check
18945 attr_form_is_section_offset before using this test. DW_FORM_data4
18946 and DW_FORM_data8 are members of both the constant class, and of
18947 the classes that contain offsets into other debug sections
18948 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
18949 that, if an attribute's can be either a constant or one of the
18950 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
18951 taken as section offsets, not constants. */
18954 attr_form_is_constant (struct attribute
*attr
)
18956 switch (attr
->form
)
18958 case DW_FORM_sdata
:
18959 case DW_FORM_udata
:
18960 case DW_FORM_data1
:
18961 case DW_FORM_data2
:
18962 case DW_FORM_data4
:
18963 case DW_FORM_data8
:
18970 /* Return the .debug_loc section to use for CU.
18971 For DWO files use .debug_loc.dwo. */
18973 static struct dwarf2_section_info
*
18974 cu_debug_loc_section (struct dwarf2_cu
*cu
)
18977 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
18978 return &dwarf2_per_objfile
->loc
;
18981 /* A helper function that fills in a dwarf2_loclist_baton. */
18984 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
18985 struct dwarf2_loclist_baton
*baton
,
18986 struct attribute
*attr
)
18988 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18990 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
18992 baton
->per_cu
= cu
->per_cu
;
18993 gdb_assert (baton
->per_cu
);
18994 /* We don't know how long the location list is, but make sure we
18995 don't run off the edge of the section. */
18996 baton
->size
= section
->size
- DW_UNSND (attr
);
18997 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
18998 baton
->base_address
= cu
->base_address
;
18999 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
19003 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
19004 struct dwarf2_cu
*cu
)
19006 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19007 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19009 if (attr_form_is_section_offset (attr
)
19010 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
19011 the section. If so, fall through to the complaint in the
19013 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
19015 struct dwarf2_loclist_baton
*baton
;
19017 baton
= obstack_alloc (&objfile
->objfile_obstack
,
19018 sizeof (struct dwarf2_loclist_baton
));
19020 fill_in_loclist_baton (cu
, baton
, attr
);
19022 if (cu
->base_known
== 0)
19023 complaint (&symfile_complaints
,
19024 _("Location list used without "
19025 "specifying the CU base address."));
19027 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
19028 SYMBOL_LOCATION_BATON (sym
) = baton
;
19032 struct dwarf2_locexpr_baton
*baton
;
19034 baton
= obstack_alloc (&objfile
->objfile_obstack
,
19035 sizeof (struct dwarf2_locexpr_baton
));
19036 baton
->per_cu
= cu
->per_cu
;
19037 gdb_assert (baton
->per_cu
);
19039 if (attr_form_is_block (attr
))
19041 /* Note that we're just copying the block's data pointer
19042 here, not the actual data. We're still pointing into the
19043 info_buffer for SYM's objfile; right now we never release
19044 that buffer, but when we do clean up properly this may
19046 baton
->size
= DW_BLOCK (attr
)->size
;
19047 baton
->data
= DW_BLOCK (attr
)->data
;
19051 dwarf2_invalid_attrib_class_complaint ("location description",
19052 SYMBOL_NATURAL_NAME (sym
));
19056 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
19057 SYMBOL_LOCATION_BATON (sym
) = baton
;
19061 /* Return the OBJFILE associated with the compilation unit CU. If CU
19062 came from a separate debuginfo file, then the master objfile is
19066 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
19068 struct objfile
*objfile
= per_cu
->objfile
;
19070 /* Return the master objfile, so that we can report and look up the
19071 correct file containing this variable. */
19072 if (objfile
->separate_debug_objfile_backlink
)
19073 objfile
= objfile
->separate_debug_objfile_backlink
;
19078 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
19079 (CU_HEADERP is unused in such case) or prepare a temporary copy at
19080 CU_HEADERP first. */
19082 static const struct comp_unit_head
*
19083 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
19084 struct dwarf2_per_cu_data
*per_cu
)
19086 gdb_byte
*info_ptr
;
19089 return &per_cu
->cu
->header
;
19091 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
19093 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
19094 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
19099 /* Return the address size given in the compilation unit header for CU. */
19102 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
19104 struct comp_unit_head cu_header_local
;
19105 const struct comp_unit_head
*cu_headerp
;
19107 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19109 return cu_headerp
->addr_size
;
19112 /* Return the offset size given in the compilation unit header for CU. */
19115 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
19117 struct comp_unit_head cu_header_local
;
19118 const struct comp_unit_head
*cu_headerp
;
19120 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19122 return cu_headerp
->offset_size
;
19125 /* See its dwarf2loc.h declaration. */
19128 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
19130 struct comp_unit_head cu_header_local
;
19131 const struct comp_unit_head
*cu_headerp
;
19133 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19135 if (cu_headerp
->version
== 2)
19136 return cu_headerp
->addr_size
;
19138 return cu_headerp
->offset_size
;
19141 /* Return the text offset of the CU. The returned offset comes from
19142 this CU's objfile. If this objfile came from a separate debuginfo
19143 file, then the offset may be different from the corresponding
19144 offset in the parent objfile. */
19147 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
19149 struct objfile
*objfile
= per_cu
->objfile
;
19151 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19154 /* Locate the .debug_info compilation unit from CU's objfile which contains
19155 the DIE at OFFSET. Raises an error on failure. */
19157 static struct dwarf2_per_cu_data
*
19158 dwarf2_find_containing_comp_unit (sect_offset offset
,
19159 unsigned int offset_in_dwz
,
19160 struct objfile
*objfile
)
19162 struct dwarf2_per_cu_data
*this_cu
;
19164 const sect_offset
*cu_off
;
19167 high
= dwarf2_per_objfile
->n_comp_units
- 1;
19170 struct dwarf2_per_cu_data
*mid_cu
;
19171 int mid
= low
+ (high
- low
) / 2;
19173 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
19174 cu_off
= &mid_cu
->offset
;
19175 if (mid_cu
->is_dwz
> offset_in_dwz
19176 || (mid_cu
->is_dwz
== offset_in_dwz
19177 && cu_off
->sect_off
>= offset
.sect_off
))
19182 gdb_assert (low
== high
);
19183 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19184 cu_off
= &this_cu
->offset
;
19185 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
19187 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
19188 error (_("Dwarf Error: could not find partial DIE containing "
19189 "offset 0x%lx [in module %s]"),
19190 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
19192 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
19193 <= offset
.sect_off
);
19194 return dwarf2_per_objfile
->all_comp_units
[low
-1];
19198 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19199 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
19200 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
19201 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
19202 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
19207 /* Initialize dwarf2_cu CU, owned by PER_CU. */
19210 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
19212 memset (cu
, 0, sizeof (*cu
));
19214 cu
->per_cu
= per_cu
;
19215 cu
->objfile
= per_cu
->objfile
;
19216 obstack_init (&cu
->comp_unit_obstack
);
19219 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
19222 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
19223 enum language pretend_language
)
19225 struct attribute
*attr
;
19227 /* Set the language we're debugging. */
19228 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
19230 set_cu_language (DW_UNSND (attr
), cu
);
19233 cu
->language
= pretend_language
;
19234 cu
->language_defn
= language_def (cu
->language
);
19237 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
19239 cu
->producer
= DW_STRING (attr
);
19242 /* Release one cached compilation unit, CU. We unlink it from the tree
19243 of compilation units, but we don't remove it from the read_in_chain;
19244 the caller is responsible for that.
19245 NOTE: DATA is a void * because this function is also used as a
19246 cleanup routine. */
19249 free_heap_comp_unit (void *data
)
19251 struct dwarf2_cu
*cu
= data
;
19253 gdb_assert (cu
->per_cu
!= NULL
);
19254 cu
->per_cu
->cu
= NULL
;
19257 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19262 /* This cleanup function is passed the address of a dwarf2_cu on the stack
19263 when we're finished with it. We can't free the pointer itself, but be
19264 sure to unlink it from the cache. Also release any associated storage. */
19267 free_stack_comp_unit (void *data
)
19269 struct dwarf2_cu
*cu
= data
;
19271 gdb_assert (cu
->per_cu
!= NULL
);
19272 cu
->per_cu
->cu
= NULL
;
19275 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19276 cu
->partial_dies
= NULL
;
19279 /* Free all cached compilation units. */
19282 free_cached_comp_units (void *data
)
19284 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19286 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19287 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19288 while (per_cu
!= NULL
)
19290 struct dwarf2_per_cu_data
*next_cu
;
19292 next_cu
= per_cu
->cu
->read_in_chain
;
19294 free_heap_comp_unit (per_cu
->cu
);
19295 *last_chain
= next_cu
;
19301 /* Increase the age counter on each cached compilation unit, and free
19302 any that are too old. */
19305 age_cached_comp_units (void)
19307 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19309 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
19310 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19311 while (per_cu
!= NULL
)
19313 per_cu
->cu
->last_used
++;
19314 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
19315 dwarf2_mark (per_cu
->cu
);
19316 per_cu
= per_cu
->cu
->read_in_chain
;
19319 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19320 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19321 while (per_cu
!= NULL
)
19323 struct dwarf2_per_cu_data
*next_cu
;
19325 next_cu
= per_cu
->cu
->read_in_chain
;
19327 if (!per_cu
->cu
->mark
)
19329 free_heap_comp_unit (per_cu
->cu
);
19330 *last_chain
= next_cu
;
19333 last_chain
= &per_cu
->cu
->read_in_chain
;
19339 /* Remove a single compilation unit from the cache. */
19342 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
19344 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19346 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19347 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19348 while (per_cu
!= NULL
)
19350 struct dwarf2_per_cu_data
*next_cu
;
19352 next_cu
= per_cu
->cu
->read_in_chain
;
19354 if (per_cu
== target_per_cu
)
19356 free_heap_comp_unit (per_cu
->cu
);
19358 *last_chain
= next_cu
;
19362 last_chain
= &per_cu
->cu
->read_in_chain
;
19368 /* Release all extra memory associated with OBJFILE. */
19371 dwarf2_free_objfile (struct objfile
*objfile
)
19373 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19375 if (dwarf2_per_objfile
== NULL
)
19378 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
19379 free_cached_comp_units (NULL
);
19381 if (dwarf2_per_objfile
->quick_file_names_table
)
19382 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
19384 /* Everything else should be on the objfile obstack. */
19387 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
19388 We store these in a hash table separate from the DIEs, and preserve them
19389 when the DIEs are flushed out of cache.
19391 The CU "per_cu" pointer is needed because offset alone is not enough to
19392 uniquely identify the type. A file may have multiple .debug_types sections,
19393 or the type may come from a DWO file. We have to use something in
19394 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
19395 routine, get_die_type_at_offset, from outside this file, and thus won't
19396 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
19399 struct dwarf2_per_cu_offset_and_type
19401 const struct dwarf2_per_cu_data
*per_cu
;
19402 sect_offset offset
;
19406 /* Hash function for a dwarf2_per_cu_offset_and_type. */
19409 per_cu_offset_and_type_hash (const void *item
)
19411 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
19413 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
19416 /* Equality function for a dwarf2_per_cu_offset_and_type. */
19419 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
19421 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
19422 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
19424 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
19425 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
19428 /* Set the type associated with DIE to TYPE. Save it in CU's hash
19429 table if necessary. For convenience, return TYPE.
19431 The DIEs reading must have careful ordering to:
19432 * Not cause infite loops trying to read in DIEs as a prerequisite for
19433 reading current DIE.
19434 * Not trying to dereference contents of still incompletely read in types
19435 while reading in other DIEs.
19436 * Enable referencing still incompletely read in types just by a pointer to
19437 the type without accessing its fields.
19439 Therefore caller should follow these rules:
19440 * Try to fetch any prerequisite types we may need to build this DIE type
19441 before building the type and calling set_die_type.
19442 * After building type call set_die_type for current DIE as soon as
19443 possible before fetching more types to complete the current type.
19444 * Make the type as complete as possible before fetching more types. */
19446 static struct type
*
19447 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19449 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
19450 struct objfile
*objfile
= cu
->objfile
;
19452 /* For Ada types, make sure that the gnat-specific data is always
19453 initialized (if not already set). There are a few types where
19454 we should not be doing so, because the type-specific area is
19455 already used to hold some other piece of info (eg: TYPE_CODE_FLT
19456 where the type-specific area is used to store the floatformat).
19457 But this is not a problem, because the gnat-specific information
19458 is actually not needed for these types. */
19459 if (need_gnat_info (cu
)
19460 && TYPE_CODE (type
) != TYPE_CODE_FUNC
19461 && TYPE_CODE (type
) != TYPE_CODE_FLT
19462 && !HAVE_GNAT_AUX_INFO (type
))
19463 INIT_GNAT_SPECIFIC (type
);
19465 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19467 dwarf2_per_objfile
->die_type_hash
=
19468 htab_create_alloc_ex (127,
19469 per_cu_offset_and_type_hash
,
19470 per_cu_offset_and_type_eq
,
19472 &objfile
->objfile_obstack
,
19473 hashtab_obstack_allocate
,
19474 dummy_obstack_deallocate
);
19477 ofs
.per_cu
= cu
->per_cu
;
19478 ofs
.offset
= die
->offset
;
19480 slot
= (struct dwarf2_per_cu_offset_and_type
**)
19481 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
19483 complaint (&symfile_complaints
,
19484 _("A problem internal to GDB: DIE 0x%x has type already set"),
19485 die
->offset
.sect_off
);
19486 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
19491 /* Look up the type for the die at OFFSET in the appropriate type_hash
19492 table, or return NULL if the die does not have a saved type. */
19494 static struct type
*
19495 get_die_type_at_offset (sect_offset offset
,
19496 struct dwarf2_per_cu_data
*per_cu
)
19498 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
19500 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19503 ofs
.per_cu
= per_cu
;
19504 ofs
.offset
= offset
;
19505 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
19512 /* Look up the type for DIE in the appropriate type_hash table,
19513 or return NULL if DIE does not have a saved type. */
19515 static struct type
*
19516 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19518 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
19521 /* Add a dependence relationship from CU to REF_PER_CU. */
19524 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
19525 struct dwarf2_per_cu_data
*ref_per_cu
)
19529 if (cu
->dependencies
== NULL
)
19531 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
19532 NULL
, &cu
->comp_unit_obstack
,
19533 hashtab_obstack_allocate
,
19534 dummy_obstack_deallocate
);
19536 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
19538 *slot
= ref_per_cu
;
19541 /* Subroutine of dwarf2_mark to pass to htab_traverse.
19542 Set the mark field in every compilation unit in the
19543 cache that we must keep because we are keeping CU. */
19546 dwarf2_mark_helper (void **slot
, void *data
)
19548 struct dwarf2_per_cu_data
*per_cu
;
19550 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
19552 /* cu->dependencies references may not yet have been ever read if QUIT aborts
19553 reading of the chain. As such dependencies remain valid it is not much
19554 useful to track and undo them during QUIT cleanups. */
19555 if (per_cu
->cu
== NULL
)
19558 if (per_cu
->cu
->mark
)
19560 per_cu
->cu
->mark
= 1;
19562 if (per_cu
->cu
->dependencies
!= NULL
)
19563 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19568 /* Set the mark field in CU and in every other compilation unit in the
19569 cache that we must keep because we are keeping CU. */
19572 dwarf2_mark (struct dwarf2_cu
*cu
)
19577 if (cu
->dependencies
!= NULL
)
19578 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19582 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
19586 per_cu
->cu
->mark
= 0;
19587 per_cu
= per_cu
->cu
->read_in_chain
;
19591 /* Trivial hash function for partial_die_info: the hash value of a DIE
19592 is its offset in .debug_info for this objfile. */
19595 partial_die_hash (const void *item
)
19597 const struct partial_die_info
*part_die
= item
;
19599 return part_die
->offset
.sect_off
;
19602 /* Trivial comparison function for partial_die_info structures: two DIEs
19603 are equal if they have the same offset. */
19606 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
19608 const struct partial_die_info
*part_die_lhs
= item_lhs
;
19609 const struct partial_die_info
*part_die_rhs
= item_rhs
;
19611 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
19614 static struct cmd_list_element
*set_dwarf2_cmdlist
;
19615 static struct cmd_list_element
*show_dwarf2_cmdlist
;
19618 set_dwarf2_cmd (char *args
, int from_tty
)
19620 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
19624 show_dwarf2_cmd (char *args
, int from_tty
)
19626 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
19629 /* Free data associated with OBJFILE, if necessary. */
19632 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
19634 struct dwarf2_per_objfile
*data
= d
;
19637 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
19638 VEC_free (dwarf2_per_cu_ptr
,
19639 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
19641 VEC_free (dwarf2_section_info_def
, data
->types
);
19643 if (data
->dwo_files
)
19644 free_dwo_files (data
->dwo_files
, objfile
);
19646 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
19647 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
19651 /* The "save gdb-index" command. */
19653 /* The contents of the hash table we create when building the string
19655 struct strtab_entry
19657 offset_type offset
;
19661 /* Hash function for a strtab_entry.
19663 Function is used only during write_hash_table so no index format backward
19664 compatibility is needed. */
19667 hash_strtab_entry (const void *e
)
19669 const struct strtab_entry
*entry
= e
;
19670 return mapped_index_string_hash (INT_MAX
, entry
->str
);
19673 /* Equality function for a strtab_entry. */
19676 eq_strtab_entry (const void *a
, const void *b
)
19678 const struct strtab_entry
*ea
= a
;
19679 const struct strtab_entry
*eb
= b
;
19680 return !strcmp (ea
->str
, eb
->str
);
19683 /* Create a strtab_entry hash table. */
19686 create_strtab (void)
19688 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
19689 xfree
, xcalloc
, xfree
);
19692 /* Add a string to the constant pool. Return the string's offset in
19696 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
19699 struct strtab_entry entry
;
19700 struct strtab_entry
*result
;
19703 slot
= htab_find_slot (table
, &entry
, INSERT
);
19708 result
= XNEW (struct strtab_entry
);
19709 result
->offset
= obstack_object_size (cpool
);
19711 obstack_grow_str0 (cpool
, str
);
19714 return result
->offset
;
19717 /* An entry in the symbol table. */
19718 struct symtab_index_entry
19720 /* The name of the symbol. */
19722 /* The offset of the name in the constant pool. */
19723 offset_type index_offset
;
19724 /* A sorted vector of the indices of all the CUs that hold an object
19726 VEC (offset_type
) *cu_indices
;
19729 /* The symbol table. This is a power-of-2-sized hash table. */
19730 struct mapped_symtab
19732 offset_type n_elements
;
19734 struct symtab_index_entry
**data
;
19737 /* Hash function for a symtab_index_entry. */
19740 hash_symtab_entry (const void *e
)
19742 const struct symtab_index_entry
*entry
= e
;
19743 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
19744 sizeof (offset_type
) * VEC_length (offset_type
,
19745 entry
->cu_indices
),
19749 /* Equality function for a symtab_index_entry. */
19752 eq_symtab_entry (const void *a
, const void *b
)
19754 const struct symtab_index_entry
*ea
= a
;
19755 const struct symtab_index_entry
*eb
= b
;
19756 int len
= VEC_length (offset_type
, ea
->cu_indices
);
19757 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
19759 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
19760 VEC_address (offset_type
, eb
->cu_indices
),
19761 sizeof (offset_type
) * len
);
19764 /* Destroy a symtab_index_entry. */
19767 delete_symtab_entry (void *p
)
19769 struct symtab_index_entry
*entry
= p
;
19770 VEC_free (offset_type
, entry
->cu_indices
);
19774 /* Create a hash table holding symtab_index_entry objects. */
19777 create_symbol_hash_table (void)
19779 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
19780 delete_symtab_entry
, xcalloc
, xfree
);
19783 /* Create a new mapped symtab object. */
19785 static struct mapped_symtab
*
19786 create_mapped_symtab (void)
19788 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
19789 symtab
->n_elements
= 0;
19790 symtab
->size
= 1024;
19791 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19795 /* Destroy a mapped_symtab. */
19798 cleanup_mapped_symtab (void *p
)
19800 struct mapped_symtab
*symtab
= p
;
19801 /* The contents of the array are freed when the other hash table is
19803 xfree (symtab
->data
);
19807 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
19810 Function is used only during write_hash_table so no index format backward
19811 compatibility is needed. */
19813 static struct symtab_index_entry
**
19814 find_slot (struct mapped_symtab
*symtab
, const char *name
)
19816 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
19818 index
= hash
& (symtab
->size
- 1);
19819 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
19823 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
19824 return &symtab
->data
[index
];
19825 index
= (index
+ step
) & (symtab
->size
- 1);
19829 /* Expand SYMTAB's hash table. */
19832 hash_expand (struct mapped_symtab
*symtab
)
19834 offset_type old_size
= symtab
->size
;
19836 struct symtab_index_entry
**old_entries
= symtab
->data
;
19839 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19841 for (i
= 0; i
< old_size
; ++i
)
19843 if (old_entries
[i
])
19845 struct symtab_index_entry
**slot
= find_slot (symtab
,
19846 old_entries
[i
]->name
);
19847 *slot
= old_entries
[i
];
19851 xfree (old_entries
);
19854 /* Add an entry to SYMTAB. NAME is the name of the symbol.
19855 CU_INDEX is the index of the CU in which the symbol appears.
19856 IS_STATIC is one if the symbol is static, otherwise zero (global). */
19859 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
19860 int is_static
, gdb_index_symbol_kind kind
,
19861 offset_type cu_index
)
19863 struct symtab_index_entry
**slot
;
19864 offset_type cu_index_and_attrs
;
19866 ++symtab
->n_elements
;
19867 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
19868 hash_expand (symtab
);
19870 slot
= find_slot (symtab
, name
);
19873 *slot
= XNEW (struct symtab_index_entry
);
19874 (*slot
)->name
= name
;
19875 /* index_offset is set later. */
19876 (*slot
)->cu_indices
= NULL
;
19879 cu_index_and_attrs
= 0;
19880 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
19881 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
19882 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
19884 /* We don't want to record an index value twice as we want to avoid the
19886 We process all global symbols and then all static symbols
19887 (which would allow us to avoid the duplication by only having to check
19888 the last entry pushed), but a symbol could have multiple kinds in one CU.
19889 To keep things simple we don't worry about the duplication here and
19890 sort and uniqufy the list after we've processed all symbols. */
19891 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
19894 /* qsort helper routine for uniquify_cu_indices. */
19897 offset_type_compare (const void *ap
, const void *bp
)
19899 offset_type a
= *(offset_type
*) ap
;
19900 offset_type b
= *(offset_type
*) bp
;
19902 return (a
> b
) - (b
> a
);
19905 /* Sort and remove duplicates of all symbols' cu_indices lists. */
19908 uniquify_cu_indices (struct mapped_symtab
*symtab
)
19912 for (i
= 0; i
< symtab
->size
; ++i
)
19914 struct symtab_index_entry
*entry
= symtab
->data
[i
];
19917 && entry
->cu_indices
!= NULL
)
19919 unsigned int next_to_insert
, next_to_check
;
19920 offset_type last_value
;
19922 qsort (VEC_address (offset_type
, entry
->cu_indices
),
19923 VEC_length (offset_type
, entry
->cu_indices
),
19924 sizeof (offset_type
), offset_type_compare
);
19926 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
19927 next_to_insert
= 1;
19928 for (next_to_check
= 1;
19929 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
19932 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
19935 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
19937 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
19942 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
19947 /* Add a vector of indices to the constant pool. */
19950 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
19951 struct symtab_index_entry
*entry
)
19955 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
19958 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
19959 offset_type val
= MAYBE_SWAP (len
);
19964 entry
->index_offset
= obstack_object_size (cpool
);
19966 obstack_grow (cpool
, &val
, sizeof (val
));
19968 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
19971 val
= MAYBE_SWAP (iter
);
19972 obstack_grow (cpool
, &val
, sizeof (val
));
19977 struct symtab_index_entry
*old_entry
= *slot
;
19978 entry
->index_offset
= old_entry
->index_offset
;
19981 return entry
->index_offset
;
19984 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
19985 constant pool entries going into the obstack CPOOL. */
19988 write_hash_table (struct mapped_symtab
*symtab
,
19989 struct obstack
*output
, struct obstack
*cpool
)
19992 htab_t symbol_hash_table
;
19995 symbol_hash_table
= create_symbol_hash_table ();
19996 str_table
= create_strtab ();
19998 /* We add all the index vectors to the constant pool first, to
19999 ensure alignment is ok. */
20000 for (i
= 0; i
< symtab
->size
; ++i
)
20002 if (symtab
->data
[i
])
20003 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
20006 /* Now write out the hash table. */
20007 for (i
= 0; i
< symtab
->size
; ++i
)
20009 offset_type str_off
, vec_off
;
20011 if (symtab
->data
[i
])
20013 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
20014 vec_off
= symtab
->data
[i
]->index_offset
;
20018 /* While 0 is a valid constant pool index, it is not valid
20019 to have 0 for both offsets. */
20024 str_off
= MAYBE_SWAP (str_off
);
20025 vec_off
= MAYBE_SWAP (vec_off
);
20027 obstack_grow (output
, &str_off
, sizeof (str_off
));
20028 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
20031 htab_delete (str_table
);
20032 htab_delete (symbol_hash_table
);
20035 /* Struct to map psymtab to CU index in the index file. */
20036 struct psymtab_cu_index_map
20038 struct partial_symtab
*psymtab
;
20039 unsigned int cu_index
;
20043 hash_psymtab_cu_index (const void *item
)
20045 const struct psymtab_cu_index_map
*map
= item
;
20047 return htab_hash_pointer (map
->psymtab
);
20051 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
20053 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
20054 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
20056 return lhs
->psymtab
== rhs
->psymtab
;
20059 /* Helper struct for building the address table. */
20060 struct addrmap_index_data
20062 struct objfile
*objfile
;
20063 struct obstack
*addr_obstack
;
20064 htab_t cu_index_htab
;
20066 /* Non-zero if the previous_* fields are valid.
20067 We can't write an entry until we see the next entry (since it is only then
20068 that we know the end of the entry). */
20069 int previous_valid
;
20070 /* Index of the CU in the table of all CUs in the index file. */
20071 unsigned int previous_cu_index
;
20072 /* Start address of the CU. */
20073 CORE_ADDR previous_cu_start
;
20076 /* Write an address entry to OBSTACK. */
20079 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
20080 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
20082 offset_type cu_index_to_write
;
20084 CORE_ADDR baseaddr
;
20086 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20088 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
20089 obstack_grow (obstack
, addr
, 8);
20090 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
20091 obstack_grow (obstack
, addr
, 8);
20092 cu_index_to_write
= MAYBE_SWAP (cu_index
);
20093 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
20096 /* Worker function for traversing an addrmap to build the address table. */
20099 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
20101 struct addrmap_index_data
*data
= datap
;
20102 struct partial_symtab
*pst
= obj
;
20104 if (data
->previous_valid
)
20105 add_address_entry (data
->objfile
, data
->addr_obstack
,
20106 data
->previous_cu_start
, start_addr
,
20107 data
->previous_cu_index
);
20109 data
->previous_cu_start
= start_addr
;
20112 struct psymtab_cu_index_map find_map
, *map
;
20113 find_map
.psymtab
= pst
;
20114 map
= htab_find (data
->cu_index_htab
, &find_map
);
20115 gdb_assert (map
!= NULL
);
20116 data
->previous_cu_index
= map
->cu_index
;
20117 data
->previous_valid
= 1;
20120 data
->previous_valid
= 0;
20125 /* Write OBJFILE's address map to OBSTACK.
20126 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
20127 in the index file. */
20130 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
20131 htab_t cu_index_htab
)
20133 struct addrmap_index_data addrmap_index_data
;
20135 /* When writing the address table, we have to cope with the fact that
20136 the addrmap iterator only provides the start of a region; we have to
20137 wait until the next invocation to get the start of the next region. */
20139 addrmap_index_data
.objfile
= objfile
;
20140 addrmap_index_data
.addr_obstack
= obstack
;
20141 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
20142 addrmap_index_data
.previous_valid
= 0;
20144 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
20145 &addrmap_index_data
);
20147 /* It's highly unlikely the last entry (end address = 0xff...ff)
20148 is valid, but we should still handle it.
20149 The end address is recorded as the start of the next region, but that
20150 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
20152 if (addrmap_index_data
.previous_valid
)
20153 add_address_entry (objfile
, obstack
,
20154 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
20155 addrmap_index_data
.previous_cu_index
);
20158 /* Return the symbol kind of PSYM. */
20160 static gdb_index_symbol_kind
20161 symbol_kind (struct partial_symbol
*psym
)
20163 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
20164 enum address_class aclass
= PSYMBOL_CLASS (psym
);
20172 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
20174 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20176 case LOC_CONST_BYTES
:
20177 case LOC_OPTIMIZED_OUT
:
20179 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20181 /* Note: It's currently impossible to recognize psyms as enum values
20182 short of reading the type info. For now punt. */
20183 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20185 /* There are other LOC_FOO values that one might want to classify
20186 as variables, but dwarf2read.c doesn't currently use them. */
20187 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20189 case STRUCT_DOMAIN
:
20190 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20192 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20196 /* Add a list of partial symbols to SYMTAB. */
20199 write_psymbols (struct mapped_symtab
*symtab
,
20201 struct partial_symbol
**psymp
,
20203 offset_type cu_index
,
20206 for (; count
-- > 0; ++psymp
)
20208 struct partial_symbol
*psym
= *psymp
;
20211 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
20212 error (_("Ada is not currently supported by the index"));
20214 /* Only add a given psymbol once. */
20215 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
20218 gdb_index_symbol_kind kind
= symbol_kind (psym
);
20221 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
20222 is_static
, kind
, cu_index
);
20227 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
20228 exception if there is an error. */
20231 write_obstack (FILE *file
, struct obstack
*obstack
)
20233 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
20235 != obstack_object_size (obstack
))
20236 error (_("couldn't data write to file"));
20239 /* Unlink a file if the argument is not NULL. */
20242 unlink_if_set (void *p
)
20244 char **filename
= p
;
20246 unlink (*filename
);
20249 /* A helper struct used when iterating over debug_types. */
20250 struct signatured_type_index_data
20252 struct objfile
*objfile
;
20253 struct mapped_symtab
*symtab
;
20254 struct obstack
*types_list
;
20259 /* A helper function that writes a single signatured_type to an
20263 write_one_signatured_type (void **slot
, void *d
)
20265 struct signatured_type_index_data
*info
= d
;
20266 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
20267 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
20268 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20271 write_psymbols (info
->symtab
,
20273 info
->objfile
->global_psymbols
.list
20274 + psymtab
->globals_offset
,
20275 psymtab
->n_global_syms
, info
->cu_index
,
20277 write_psymbols (info
->symtab
,
20279 info
->objfile
->static_psymbols
.list
20280 + psymtab
->statics_offset
,
20281 psymtab
->n_static_syms
, info
->cu_index
,
20284 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20285 entry
->per_cu
.offset
.sect_off
);
20286 obstack_grow (info
->types_list
, val
, 8);
20287 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20288 entry
->type_offset_in_tu
.cu_off
);
20289 obstack_grow (info
->types_list
, val
, 8);
20290 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
20291 obstack_grow (info
->types_list
, val
, 8);
20298 /* Recurse into all "included" dependencies and write their symbols as
20299 if they appeared in this psymtab. */
20302 recursively_write_psymbols (struct objfile
*objfile
,
20303 struct partial_symtab
*psymtab
,
20304 struct mapped_symtab
*symtab
,
20306 offset_type cu_index
)
20310 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
20311 if (psymtab
->dependencies
[i
]->user
!= NULL
)
20312 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
20313 symtab
, psyms_seen
, cu_index
);
20315 write_psymbols (symtab
,
20317 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
20318 psymtab
->n_global_syms
, cu_index
,
20320 write_psymbols (symtab
,
20322 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
20323 psymtab
->n_static_syms
, cu_index
,
20327 /* Create an index file for OBJFILE in the directory DIR. */
20330 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
20332 struct cleanup
*cleanup
;
20333 char *filename
, *cleanup_filename
;
20334 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
20335 struct obstack cu_list
, types_cu_list
;
20338 struct mapped_symtab
*symtab
;
20339 offset_type val
, size_of_contents
, total_len
;
20342 htab_t cu_index_htab
;
20343 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
20345 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
20348 if (dwarf2_per_objfile
->using_index
)
20349 error (_("Cannot use an index to create the index"));
20351 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
20352 error (_("Cannot make an index when the file has multiple .debug_types sections"));
20354 if (stat (objfile
->name
, &st
) < 0)
20355 perror_with_name (objfile
->name
);
20357 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
20358 INDEX_SUFFIX
, (char *) NULL
);
20359 cleanup
= make_cleanup (xfree
, filename
);
20361 out_file
= fopen (filename
, "wb");
20363 error (_("Can't open `%s' for writing"), filename
);
20365 cleanup_filename
= filename
;
20366 make_cleanup (unlink_if_set
, &cleanup_filename
);
20368 symtab
= create_mapped_symtab ();
20369 make_cleanup (cleanup_mapped_symtab
, symtab
);
20371 obstack_init (&addr_obstack
);
20372 make_cleanup_obstack_free (&addr_obstack
);
20374 obstack_init (&cu_list
);
20375 make_cleanup_obstack_free (&cu_list
);
20377 obstack_init (&types_cu_list
);
20378 make_cleanup_obstack_free (&types_cu_list
);
20380 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
20381 NULL
, xcalloc
, xfree
);
20382 make_cleanup_htab_delete (psyms_seen
);
20384 /* While we're scanning CU's create a table that maps a psymtab pointer
20385 (which is what addrmap records) to its index (which is what is recorded
20386 in the index file). This will later be needed to write the address
20388 cu_index_htab
= htab_create_alloc (100,
20389 hash_psymtab_cu_index
,
20390 eq_psymtab_cu_index
,
20391 NULL
, xcalloc
, xfree
);
20392 make_cleanup_htab_delete (cu_index_htab
);
20393 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
20394 xmalloc (sizeof (struct psymtab_cu_index_map
)
20395 * dwarf2_per_objfile
->n_comp_units
);
20396 make_cleanup (xfree
, psymtab_cu_index_map
);
20398 /* The CU list is already sorted, so we don't need to do additional
20399 work here. Also, the debug_types entries do not appear in
20400 all_comp_units, but only in their own hash table. */
20401 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
20403 struct dwarf2_per_cu_data
*per_cu
20404 = dwarf2_per_objfile
->all_comp_units
[i
];
20405 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20407 struct psymtab_cu_index_map
*map
;
20410 if (psymtab
->user
== NULL
)
20411 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
20413 map
= &psymtab_cu_index_map
[i
];
20414 map
->psymtab
= psymtab
;
20416 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
20417 gdb_assert (slot
!= NULL
);
20418 gdb_assert (*slot
== NULL
);
20421 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20422 per_cu
->offset
.sect_off
);
20423 obstack_grow (&cu_list
, val
, 8);
20424 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
20425 obstack_grow (&cu_list
, val
, 8);
20428 /* Dump the address map. */
20429 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
20431 /* Write out the .debug_type entries, if any. */
20432 if (dwarf2_per_objfile
->signatured_types
)
20434 struct signatured_type_index_data sig_data
;
20436 sig_data
.objfile
= objfile
;
20437 sig_data
.symtab
= symtab
;
20438 sig_data
.types_list
= &types_cu_list
;
20439 sig_data
.psyms_seen
= psyms_seen
;
20440 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
20441 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
20442 write_one_signatured_type
, &sig_data
);
20445 /* Now that we've processed all symbols we can shrink their cu_indices
20447 uniquify_cu_indices (symtab
);
20449 obstack_init (&constant_pool
);
20450 make_cleanup_obstack_free (&constant_pool
);
20451 obstack_init (&symtab_obstack
);
20452 make_cleanup_obstack_free (&symtab_obstack
);
20453 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
20455 obstack_init (&contents
);
20456 make_cleanup_obstack_free (&contents
);
20457 size_of_contents
= 6 * sizeof (offset_type
);
20458 total_len
= size_of_contents
;
20460 /* The version number. */
20461 val
= MAYBE_SWAP (7);
20462 obstack_grow (&contents
, &val
, sizeof (val
));
20464 /* The offset of the CU list from the start of the file. */
20465 val
= MAYBE_SWAP (total_len
);
20466 obstack_grow (&contents
, &val
, sizeof (val
));
20467 total_len
+= obstack_object_size (&cu_list
);
20469 /* The offset of the types CU list from the start of the file. */
20470 val
= MAYBE_SWAP (total_len
);
20471 obstack_grow (&contents
, &val
, sizeof (val
));
20472 total_len
+= obstack_object_size (&types_cu_list
);
20474 /* The offset of the address table from the start of the file. */
20475 val
= MAYBE_SWAP (total_len
);
20476 obstack_grow (&contents
, &val
, sizeof (val
));
20477 total_len
+= obstack_object_size (&addr_obstack
);
20479 /* The offset of the symbol table from the start of the file. */
20480 val
= MAYBE_SWAP (total_len
);
20481 obstack_grow (&contents
, &val
, sizeof (val
));
20482 total_len
+= obstack_object_size (&symtab_obstack
);
20484 /* The offset of the constant pool from the start of the file. */
20485 val
= MAYBE_SWAP (total_len
);
20486 obstack_grow (&contents
, &val
, sizeof (val
));
20487 total_len
+= obstack_object_size (&constant_pool
);
20489 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
20491 write_obstack (out_file
, &contents
);
20492 write_obstack (out_file
, &cu_list
);
20493 write_obstack (out_file
, &types_cu_list
);
20494 write_obstack (out_file
, &addr_obstack
);
20495 write_obstack (out_file
, &symtab_obstack
);
20496 write_obstack (out_file
, &constant_pool
);
20500 /* We want to keep the file, so we set cleanup_filename to NULL
20501 here. See unlink_if_set. */
20502 cleanup_filename
= NULL
;
20504 do_cleanups (cleanup
);
20507 /* Implementation of the `save gdb-index' command.
20509 Note that the file format used by this command is documented in the
20510 GDB manual. Any changes here must be documented there. */
20513 save_gdb_index_command (char *arg
, int from_tty
)
20515 struct objfile
*objfile
;
20518 error (_("usage: save gdb-index DIRECTORY"));
20520 ALL_OBJFILES (objfile
)
20524 /* If the objfile does not correspond to an actual file, skip it. */
20525 if (stat (objfile
->name
, &st
) < 0)
20528 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
20529 if (dwarf2_per_objfile
)
20531 volatile struct gdb_exception except
;
20533 TRY_CATCH (except
, RETURN_MASK_ERROR
)
20535 write_psymtabs_to_index (objfile
, arg
);
20537 if (except
.reason
< 0)
20538 exception_fprintf (gdb_stderr
, except
,
20539 _("Error while writing index for `%s': "),
20547 int dwarf2_always_disassemble
;
20550 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
20551 struct cmd_list_element
*c
, const char *value
)
20553 fprintf_filtered (file
,
20554 _("Whether to always disassemble "
20555 "DWARF expressions is %s.\n"),
20560 show_check_physname (struct ui_file
*file
, int from_tty
,
20561 struct cmd_list_element
*c
, const char *value
)
20563 fprintf_filtered (file
,
20564 _("Whether to check \"physname\" is %s.\n"),
20568 void _initialize_dwarf2_read (void);
20571 _initialize_dwarf2_read (void)
20573 struct cmd_list_element
*c
;
20575 dwarf2_objfile_data_key
20576 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
20578 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
20579 Set DWARF 2 specific variables.\n\
20580 Configure DWARF 2 variables such as the cache size"),
20581 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
20582 0/*allow-unknown*/, &maintenance_set_cmdlist
);
20584 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
20585 Show DWARF 2 specific variables\n\
20586 Show DWARF 2 variables such as the cache size"),
20587 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
20588 0/*allow-unknown*/, &maintenance_show_cmdlist
);
20590 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
20591 &dwarf2_max_cache_age
, _("\
20592 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
20593 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
20594 A higher limit means that cached compilation units will be stored\n\
20595 in memory longer, and more total memory will be used. Zero disables\n\
20596 caching, which can slow down startup."),
20598 show_dwarf2_max_cache_age
,
20599 &set_dwarf2_cmdlist
,
20600 &show_dwarf2_cmdlist
);
20602 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
20603 &dwarf2_always_disassemble
, _("\
20604 Set whether `info address' always disassembles DWARF expressions."), _("\
20605 Show whether `info address' always disassembles DWARF expressions."), _("\
20606 When enabled, DWARF expressions are always printed in an assembly-like\n\
20607 syntax. When disabled, expressions will be printed in a more\n\
20608 conversational style, when possible."),
20610 show_dwarf2_always_disassemble
,
20611 &set_dwarf2_cmdlist
,
20612 &show_dwarf2_cmdlist
);
20614 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
20615 Set debugging of the dwarf2 reader."), _("\
20616 Show debugging of the dwarf2 reader."), _("\
20617 When enabled, debugging messages are printed during dwarf2 reading\n\
20618 and symtab expansion."),
20621 &setdebuglist
, &showdebuglist
);
20623 add_setshow_zuinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
20624 Set debugging of the dwarf2 DIE reader."), _("\
20625 Show debugging of the dwarf2 DIE reader."), _("\
20626 When enabled (non-zero), DIEs are dumped after they are read in.\n\
20627 The value is the maximum depth to print."),
20630 &setdebuglist
, &showdebuglist
);
20632 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
20633 Set cross-checking of \"physname\" code against demangler."), _("\
20634 Show cross-checking of \"physname\" code against demangler."), _("\
20635 When enabled, GDB's internal \"physname\" code is checked against\n\
20637 NULL
, show_check_physname
,
20638 &setdebuglist
, &showdebuglist
);
20640 add_setshow_boolean_cmd ("use-deprecated-index-sections",
20641 no_class
, &use_deprecated_index_sections
, _("\
20642 Set whether to use deprecated gdb_index sections."), _("\
20643 Show whether to use deprecated gdb_index sections."), _("\
20644 When enabled, deprecated .gdb_index sections are used anyway.\n\
20645 Normally they are ignored either because of a missing feature or\n\
20646 performance issue.\n\
20647 Warning: This option must be enabled before gdb reads the file."),
20650 &setlist
, &showlist
);
20652 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
20654 Save a gdb-index file.\n\
20655 Usage: save gdb-index DIRECTORY"),
20657 set_cmd_completer (c
, filename_completer
);