1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
40 #include "gdb-demangle.h"
41 #include "expression.h"
42 #include "filenames.h" /* for DOSish file names */
45 #include "complaints.h"
47 #include "dwarf2expr.h"
48 #include "dwarf2loc.h"
49 #include "cp-support.h"
55 #include "typeprint.h"
58 #include "exceptions.h"
60 #include "completer.h"
65 #include "gdbcore.h" /* for gnutarget */
66 #include "gdb/gdb-index.h"
72 #include "gdb_string.h"
73 #include "gdb_assert.h"
74 #include <sys/types.h>
76 typedef struct symbol
*symbolp
;
79 /* When non-zero, print basic high level tracing messages.
80 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
81 static int dwarf2_read_debug
= 0;
83 /* When non-zero, dump DIEs after they are read in. */
84 static unsigned int dwarf2_die_debug
= 0;
86 /* When non-zero, cross-check physname against demangler. */
87 static int check_physname
= 0;
89 /* When non-zero, do not reject deprecated .gdb_index sections. */
90 static int use_deprecated_index_sections
= 0;
92 /* When set, the file that we're processing is known to have debugging
93 info for C++ namespaces. GCC 3.3.x did not produce this information,
94 but later versions do. */
96 static int processing_has_namespace_info
;
98 static const struct objfile_data
*dwarf2_objfile_data_key
;
100 struct dwarf2_section_info
105 /* True if we have tried to read this section. */
109 typedef struct dwarf2_section_info dwarf2_section_info_def
;
110 DEF_VEC_O (dwarf2_section_info_def
);
112 /* All offsets in the index are of this type. It must be
113 architecture-independent. */
114 typedef uint32_t offset_type
;
116 DEF_VEC_I (offset_type
);
118 /* Ensure only legit values are used. */
119 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
121 gdb_assert ((unsigned int) (value) <= 1); \
122 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
125 /* Ensure only legit values are used. */
126 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
128 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
129 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
130 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
133 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
134 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
136 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
137 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
140 /* A description of the mapped index. The file format is described in
141 a comment by the code that writes the index. */
144 /* Index data format version. */
147 /* The total length of the buffer. */
150 /* A pointer to the address table data. */
151 const gdb_byte
*address_table
;
153 /* Size of the address table data in bytes. */
154 offset_type address_table_size
;
156 /* The symbol table, implemented as a hash table. */
157 const offset_type
*symbol_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type symbol_table_slots
;
162 /* A pointer to the constant pool. */
163 const char *constant_pool
;
166 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
167 DEF_VEC_P (dwarf2_per_cu_ptr
);
169 /* Collection of data recorded per objfile.
170 This hangs off of dwarf2_objfile_data_key. */
172 struct dwarf2_per_objfile
174 struct dwarf2_section_info info
;
175 struct dwarf2_section_info abbrev
;
176 struct dwarf2_section_info line
;
177 struct dwarf2_section_info loc
;
178 struct dwarf2_section_info macinfo
;
179 struct dwarf2_section_info macro
;
180 struct dwarf2_section_info str
;
181 struct dwarf2_section_info ranges
;
182 struct dwarf2_section_info addr
;
183 struct dwarf2_section_info frame
;
184 struct dwarf2_section_info eh_frame
;
185 struct dwarf2_section_info gdb_index
;
187 VEC (dwarf2_section_info_def
) *types
;
190 struct objfile
*objfile
;
192 /* Table of all the compilation units. This is used to locate
193 the target compilation unit of a particular reference. */
194 struct dwarf2_per_cu_data
**all_comp_units
;
196 /* The number of compilation units in ALL_COMP_UNITS. */
199 /* The number of .debug_types-related CUs. */
202 /* The .debug_types-related CUs (TUs). */
203 struct signatured_type
**all_type_units
;
205 /* The number of entries in all_type_unit_groups. */
206 int n_type_unit_groups
;
208 /* Table of type unit groups.
209 This exists to make it easy to iterate over all CUs and TU groups. */
210 struct type_unit_group
**all_type_unit_groups
;
212 /* Table of struct type_unit_group objects.
213 The hash key is the DW_AT_stmt_list value. */
214 htab_t type_unit_groups
;
216 /* A table mapping .debug_types signatures to its signatured_type entry.
217 This is NULL if the .debug_types section hasn't been read in yet. */
218 htab_t signatured_types
;
220 /* Type unit statistics, to see how well the scaling improvements
224 int nr_uniq_abbrev_tables
;
226 int nr_symtab_sharers
;
227 int nr_stmt_less_type_units
;
230 /* A chain of compilation units that are currently read in, so that
231 they can be freed later. */
232 struct dwarf2_per_cu_data
*read_in_chain
;
234 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
235 This is NULL if the table hasn't been allocated yet. */
238 /* Non-zero if we've check for whether there is a DWP file. */
241 /* The DWP file if there is one, or NULL. */
242 struct dwp_file
*dwp_file
;
244 /* The shared '.dwz' file, if one exists. This is used when the
245 original data was compressed using 'dwz -m'. */
246 struct dwz_file
*dwz_file
;
248 /* A flag indicating wether this objfile has a section loaded at a
250 int has_section_at_zero
;
252 /* True if we are using the mapped index,
253 or we are faking it for OBJF_READNOW's sake. */
254 unsigned char using_index
;
256 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
257 struct mapped_index
*index_table
;
259 /* When using index_table, this keeps track of all quick_file_names entries.
260 TUs typically share line table entries with a CU, so we maintain a
261 separate table of all line table entries to support the sharing.
262 Note that while there can be way more TUs than CUs, we've already
263 sorted all the TUs into "type unit groups", grouped by their
264 DW_AT_stmt_list value. Therefore the only sharing done here is with a
265 CU and its associated TU group if there is one. */
266 htab_t quick_file_names_table
;
268 /* Set during partial symbol reading, to prevent queueing of full
270 int reading_partial_symbols
;
272 /* Table mapping type DIEs to their struct type *.
273 This is NULL if not allocated yet.
274 The mapping is done via (CU/TU signature + DIE offset) -> type. */
275 htab_t die_type_hash
;
277 /* The CUs we recently read. */
278 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
281 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
283 /* Default names of the debugging sections. */
285 /* Note that if the debugging section has been compressed, it might
286 have a name like .zdebug_info. */
288 static const struct dwarf2_debug_sections dwarf2_elf_names
=
290 { ".debug_info", ".zdebug_info" },
291 { ".debug_abbrev", ".zdebug_abbrev" },
292 { ".debug_line", ".zdebug_line" },
293 { ".debug_loc", ".zdebug_loc" },
294 { ".debug_macinfo", ".zdebug_macinfo" },
295 { ".debug_macro", ".zdebug_macro" },
296 { ".debug_str", ".zdebug_str" },
297 { ".debug_ranges", ".zdebug_ranges" },
298 { ".debug_types", ".zdebug_types" },
299 { ".debug_addr", ".zdebug_addr" },
300 { ".debug_frame", ".zdebug_frame" },
301 { ".eh_frame", NULL
},
302 { ".gdb_index", ".zgdb_index" },
306 /* List of DWO/DWP sections. */
308 static const struct dwop_section_names
310 struct dwarf2_section_names abbrev_dwo
;
311 struct dwarf2_section_names info_dwo
;
312 struct dwarf2_section_names line_dwo
;
313 struct dwarf2_section_names loc_dwo
;
314 struct dwarf2_section_names macinfo_dwo
;
315 struct dwarf2_section_names macro_dwo
;
316 struct dwarf2_section_names str_dwo
;
317 struct dwarf2_section_names str_offsets_dwo
;
318 struct dwarf2_section_names types_dwo
;
319 struct dwarf2_section_names cu_index
;
320 struct dwarf2_section_names tu_index
;
324 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
325 { ".debug_info.dwo", ".zdebug_info.dwo" },
326 { ".debug_line.dwo", ".zdebug_line.dwo" },
327 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
328 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
329 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
330 { ".debug_str.dwo", ".zdebug_str.dwo" },
331 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
332 { ".debug_types.dwo", ".zdebug_types.dwo" },
333 { ".debug_cu_index", ".zdebug_cu_index" },
334 { ".debug_tu_index", ".zdebug_tu_index" },
337 /* local data types */
339 /* The data in a compilation unit header, after target2host
340 translation, looks like this. */
341 struct comp_unit_head
345 unsigned char addr_size
;
346 unsigned char signed_addr_p
;
347 sect_offset abbrev_offset
;
349 /* Size of file offsets; either 4 or 8. */
350 unsigned int offset_size
;
352 /* Size of the length field; either 4 or 12. */
353 unsigned int initial_length_size
;
355 /* Offset to the first byte of this compilation unit header in the
356 .debug_info section, for resolving relative reference dies. */
359 /* Offset to first die in this cu from the start of the cu.
360 This will be the first byte following the compilation unit header. */
361 cu_offset first_die_offset
;
364 /* Type used for delaying computation of method physnames.
365 See comments for compute_delayed_physnames. */
366 struct delayed_method_info
368 /* The type to which the method is attached, i.e., its parent class. */
371 /* The index of the method in the type's function fieldlists. */
374 /* The index of the method in the fieldlist. */
377 /* The name of the DIE. */
380 /* The DIE associated with this method. */
381 struct die_info
*die
;
384 typedef struct delayed_method_info delayed_method_info
;
385 DEF_VEC_O (delayed_method_info
);
387 /* Internal state when decoding a particular compilation unit. */
390 /* The objfile containing this compilation unit. */
391 struct objfile
*objfile
;
393 /* The header of the compilation unit. */
394 struct comp_unit_head header
;
396 /* Base address of this compilation unit. */
397 CORE_ADDR base_address
;
399 /* Non-zero if base_address has been set. */
402 /* The language we are debugging. */
403 enum language language
;
404 const struct language_defn
*language_defn
;
406 const char *producer
;
408 /* The generic symbol table building routines have separate lists for
409 file scope symbols and all all other scopes (local scopes). So
410 we need to select the right one to pass to add_symbol_to_list().
411 We do it by keeping a pointer to the correct list in list_in_scope.
413 FIXME: The original dwarf code just treated the file scope as the
414 first local scope, and all other local scopes as nested local
415 scopes, and worked fine. Check to see if we really need to
416 distinguish these in buildsym.c. */
417 struct pending
**list_in_scope
;
419 /* The abbrev table for this CU.
420 Normally this points to the abbrev table in the objfile.
421 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
422 struct abbrev_table
*abbrev_table
;
424 /* Hash table holding all the loaded partial DIEs
425 with partial_die->offset.SECT_OFF as hash. */
428 /* Storage for things with the same lifetime as this read-in compilation
429 unit, including partial DIEs. */
430 struct obstack comp_unit_obstack
;
432 /* When multiple dwarf2_cu structures are living in memory, this field
433 chains them all together, so that they can be released efficiently.
434 We will probably also want a generation counter so that most-recently-used
435 compilation units are cached... */
436 struct dwarf2_per_cu_data
*read_in_chain
;
438 /* Backchain to our per_cu entry if the tree has been built. */
439 struct dwarf2_per_cu_data
*per_cu
;
441 /* How many compilation units ago was this CU last referenced? */
444 /* A hash table of DIE cu_offset for following references with
445 die_info->offset.sect_off as hash. */
448 /* Full DIEs if read in. */
449 struct die_info
*dies
;
451 /* A set of pointers to dwarf2_per_cu_data objects for compilation
452 units referenced by this one. Only set during full symbol processing;
453 partial symbol tables do not have dependencies. */
456 /* Header data from the line table, during full symbol processing. */
457 struct line_header
*line_header
;
459 /* A list of methods which need to have physnames computed
460 after all type information has been read. */
461 VEC (delayed_method_info
) *method_list
;
463 /* To be copied to symtab->call_site_htab. */
464 htab_t call_site_htab
;
466 /* Non-NULL if this CU came from a DWO file.
467 There is an invariant here that is important to remember:
468 Except for attributes copied from the top level DIE in the "main"
469 (or "stub") file in preparation for reading the DWO file
470 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
471 Either there isn't a DWO file (in which case this is NULL and the point
472 is moot), or there is and either we're not going to read it (in which
473 case this is NULL) or there is and we are reading it (in which case this
475 struct dwo_unit
*dwo_unit
;
477 /* The DW_AT_addr_base attribute if present, zero otherwise
478 (zero is a valid value though).
479 Note this value comes from the stub CU/TU's DIE. */
482 /* The DW_AT_ranges_base attribute if present, zero otherwise
483 (zero is a valid value though).
484 Note this value comes from the stub CU/TU's DIE.
485 Also note that the value is zero in the non-DWO case so this value can
486 be used without needing to know whether DWO files are in use or not.
487 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 partial_symtab
*);
1289 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1291 static struct abbrev_info
*abbrev_table_lookup_abbrev
1292 (const struct abbrev_table
*, unsigned int);
1294 static struct abbrev_table
*abbrev_table_read_table
1295 (struct dwarf2_section_info
*, sect_offset
);
1297 static void abbrev_table_free (struct abbrev_table
*);
1299 static void abbrev_table_free_cleanup (void *);
1301 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1302 struct dwarf2_section_info
*);
1304 static void dwarf2_free_abbrev_table (void *);
1306 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1308 static struct partial_die_info
*load_partial_dies
1309 (const struct die_reader_specs
*, gdb_byte
*, int);
1311 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1312 struct partial_die_info
*,
1313 struct abbrev_info
*,
1317 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1318 struct dwarf2_cu
*);
1320 static void fixup_partial_die (struct partial_die_info
*,
1321 struct dwarf2_cu
*);
1323 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1324 struct attribute
*, struct attr_abbrev
*,
1327 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1329 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1331 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1333 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1335 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1337 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1340 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1342 static LONGEST read_checked_initial_length_and_offset
1343 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1344 unsigned int *, unsigned int *);
1346 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1349 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1351 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1354 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1356 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1358 static char *read_indirect_string (bfd
*, gdb_byte
*,
1359 const struct comp_unit_head
*,
1362 static char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1364 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1366 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1368 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1371 static char *read_str_index (const struct die_reader_specs
*reader
,
1372 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1374 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1376 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1377 struct dwarf2_cu
*);
1379 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1382 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1383 struct dwarf2_cu
*cu
);
1385 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1387 static struct die_info
*die_specification (struct die_info
*die
,
1388 struct dwarf2_cu
**);
1390 static void free_line_header (struct line_header
*lh
);
1392 static void add_file_name (struct line_header
*, char *, unsigned int,
1393 unsigned int, unsigned int);
1395 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1396 struct dwarf2_cu
*cu
);
1398 static void dwarf_decode_lines (struct line_header
*, const char *,
1399 struct dwarf2_cu
*, struct partial_symtab
*,
1402 static void dwarf2_start_subfile (char *, const char *, const char *);
1404 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1405 char *, char *, CORE_ADDR
);
1407 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1408 struct dwarf2_cu
*);
1410 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1411 struct dwarf2_cu
*, struct symbol
*);
1413 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1414 struct dwarf2_cu
*);
1416 static void dwarf2_const_value_attr (struct attribute
*attr
,
1419 struct obstack
*obstack
,
1420 struct dwarf2_cu
*cu
, LONGEST
*value
,
1422 struct dwarf2_locexpr_baton
**baton
);
1424 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1426 static int need_gnat_info (struct dwarf2_cu
*);
1428 static struct type
*die_descriptive_type (struct die_info
*,
1429 struct dwarf2_cu
*);
1431 static void set_descriptive_type (struct type
*, struct die_info
*,
1432 struct dwarf2_cu
*);
1434 static struct type
*die_containing_type (struct die_info
*,
1435 struct dwarf2_cu
*);
1437 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1438 struct dwarf2_cu
*);
1440 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1442 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1444 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1446 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1447 const char *suffix
, int physname
,
1448 struct dwarf2_cu
*cu
);
1450 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1452 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1454 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1456 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1458 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1460 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1461 struct dwarf2_cu
*, struct partial_symtab
*);
1463 static int dwarf2_get_pc_bounds (struct die_info
*,
1464 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1465 struct partial_symtab
*);
1467 static void get_scope_pc_bounds (struct die_info
*,
1468 CORE_ADDR
*, CORE_ADDR
*,
1469 struct dwarf2_cu
*);
1471 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1472 CORE_ADDR
, struct dwarf2_cu
*);
1474 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1475 struct dwarf2_cu
*);
1477 static void dwarf2_attach_fields_to_type (struct field_info
*,
1478 struct type
*, struct dwarf2_cu
*);
1480 static void dwarf2_add_member_fn (struct field_info
*,
1481 struct die_info
*, struct type
*,
1482 struct dwarf2_cu
*);
1484 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1486 struct dwarf2_cu
*);
1488 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1490 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1492 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1494 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1496 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1498 static struct type
*read_module_type (struct die_info
*die
,
1499 struct dwarf2_cu
*cu
);
1501 static const char *namespace_name (struct die_info
*die
,
1502 int *is_anonymous
, struct dwarf2_cu
*);
1504 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1506 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1508 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1509 struct dwarf2_cu
*);
1511 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1513 gdb_byte
**new_info_ptr
,
1514 struct die_info
*parent
);
1516 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1518 gdb_byte
**new_info_ptr
,
1519 struct die_info
*parent
);
1521 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1522 struct die_info
**, gdb_byte
*, int *, int);
1524 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1525 struct die_info
**, gdb_byte
*, int *);
1527 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1529 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1532 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1534 static const char *dwarf2_full_name (char *name
,
1535 struct die_info
*die
,
1536 struct dwarf2_cu
*cu
);
1538 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1539 struct dwarf2_cu
**);
1541 static const char *dwarf_tag_name (unsigned int);
1543 static const char *dwarf_attr_name (unsigned int);
1545 static const char *dwarf_form_name (unsigned int);
1547 static char *dwarf_bool_name (unsigned int);
1549 static const char *dwarf_type_encoding_name (unsigned int);
1551 static struct die_info
*sibling_die (struct die_info
*);
1553 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1555 static void dump_die_for_error (struct die_info
*);
1557 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1560 /*static*/ void dump_die (struct die_info
*, int max_level
);
1562 static void store_in_ref_table (struct die_info
*,
1563 struct dwarf2_cu
*);
1565 static int is_ref_attr (struct attribute
*);
1567 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1569 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1571 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1573 struct dwarf2_cu
**);
1575 static struct die_info
*follow_die_ref (struct die_info
*,
1577 struct dwarf2_cu
**);
1579 static struct die_info
*follow_die_sig (struct die_info
*,
1581 struct dwarf2_cu
**);
1583 static struct signatured_type
*lookup_signatured_type_at_offset
1584 (struct objfile
*objfile
,
1585 struct dwarf2_section_info
*section
, sect_offset offset
);
1587 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1589 static void read_signatured_type (struct signatured_type
*);
1591 static struct type_unit_group
*get_type_unit_group
1592 (struct dwarf2_cu
*, struct attribute
*);
1594 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1596 /* memory allocation interface */
1598 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1600 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1602 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1605 static int attr_form_is_block (struct attribute
*);
1607 static int attr_form_is_section_offset (struct attribute
*);
1609 static int attr_form_is_constant (struct attribute
*);
1611 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1612 struct dwarf2_loclist_baton
*baton
,
1613 struct attribute
*attr
);
1615 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1617 struct dwarf2_cu
*cu
);
1619 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1621 struct abbrev_info
*abbrev
);
1623 static void free_stack_comp_unit (void *);
1625 static hashval_t
partial_die_hash (const void *item
);
1627 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1629 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1630 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1632 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1633 struct dwarf2_per_cu_data
*per_cu
);
1635 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1636 struct die_info
*comp_unit_die
,
1637 enum language pretend_language
);
1639 static void free_heap_comp_unit (void *);
1641 static void free_cached_comp_units (void *);
1643 static void age_cached_comp_units (void);
1645 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1647 static struct type
*set_die_type (struct die_info
*, struct type
*,
1648 struct dwarf2_cu
*);
1650 static void create_all_comp_units (struct objfile
*);
1652 static int create_all_type_units (struct objfile
*);
1654 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1657 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1660 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1663 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1664 struct dwarf2_per_cu_data
*);
1666 static void dwarf2_mark (struct dwarf2_cu
*);
1668 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1670 static struct type
*get_die_type_at_offset (sect_offset
,
1671 struct dwarf2_per_cu_data
*per_cu
);
1673 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1675 static void dwarf2_release_queue (void *dummy
);
1677 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1678 enum language pretend_language
);
1680 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1681 struct dwarf2_per_cu_data
*per_cu
,
1682 enum language pretend_language
);
1684 static void process_queue (void);
1686 static void find_file_and_directory (struct die_info
*die
,
1687 struct dwarf2_cu
*cu
,
1688 char **name
, char **comp_dir
);
1690 static char *file_full_name (int file
, struct line_header
*lh
,
1691 const char *comp_dir
);
1693 static gdb_byte
*read_and_check_comp_unit_head
1694 (struct comp_unit_head
*header
,
1695 struct dwarf2_section_info
*section
,
1696 struct dwarf2_section_info
*abbrev_section
, gdb_byte
*info_ptr
,
1697 int is_debug_types_section
);
1699 static void init_cutu_and_read_dies
1700 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1701 int use_existing_cu
, int keep
,
1702 die_reader_func_ftype
*die_reader_func
, void *data
);
1704 static void init_cutu_and_read_dies_simple
1705 (struct dwarf2_per_cu_data
*this_cu
,
1706 die_reader_func_ftype
*die_reader_func
, void *data
);
1708 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1710 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1712 static struct dwo_unit
*lookup_dwo_comp_unit
1713 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1715 static struct dwo_unit
*lookup_dwo_type_unit
1716 (struct signatured_type
*, const char *, const char *);
1718 static void free_dwo_file_cleanup (void *);
1720 static void process_cu_includes (void);
1722 static void check_producer (struct dwarf2_cu
*cu
);
1726 /* Convert VALUE between big- and little-endian. */
1728 byte_swap (offset_type value
)
1732 result
= (value
& 0xff) << 24;
1733 result
|= (value
& 0xff00) << 8;
1734 result
|= (value
& 0xff0000) >> 8;
1735 result
|= (value
& 0xff000000) >> 24;
1739 #define MAYBE_SWAP(V) byte_swap (V)
1742 #define MAYBE_SWAP(V) (V)
1743 #endif /* WORDS_BIGENDIAN */
1745 /* The suffix for an index file. */
1746 #define INDEX_SUFFIX ".gdb-index"
1748 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1749 struct dwarf2_cu
*cu
);
1751 /* Try to locate the sections we need for DWARF 2 debugging
1752 information and return true if we have enough to do something.
1753 NAMES points to the dwarf2 section names, or is NULL if the standard
1754 ELF names are used. */
1757 dwarf2_has_info (struct objfile
*objfile
,
1758 const struct dwarf2_debug_sections
*names
)
1760 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1761 if (!dwarf2_per_objfile
)
1763 /* Initialize per-objfile state. */
1764 struct dwarf2_per_objfile
*data
1765 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1767 memset (data
, 0, sizeof (*data
));
1768 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1769 dwarf2_per_objfile
= data
;
1771 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1773 dwarf2_per_objfile
->objfile
= objfile
;
1775 return (dwarf2_per_objfile
->info
.asection
!= NULL
1776 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1779 /* When loading sections, we look either for uncompressed section or for
1780 compressed section names. */
1783 section_is_p (const char *section_name
,
1784 const struct dwarf2_section_names
*names
)
1786 if (names
->normal
!= NULL
1787 && strcmp (section_name
, names
->normal
) == 0)
1789 if (names
->compressed
!= NULL
1790 && strcmp (section_name
, names
->compressed
) == 0)
1795 /* This function is mapped across the sections and remembers the
1796 offset and size of each of the debugging sections we are interested
1800 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1802 const struct dwarf2_debug_sections
*names
;
1803 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1806 names
= &dwarf2_elf_names
;
1808 names
= (const struct dwarf2_debug_sections
*) vnames
;
1810 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1813 else if (section_is_p (sectp
->name
, &names
->info
))
1815 dwarf2_per_objfile
->info
.asection
= sectp
;
1816 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1818 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1820 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1821 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1823 else if (section_is_p (sectp
->name
, &names
->line
))
1825 dwarf2_per_objfile
->line
.asection
= sectp
;
1826 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1828 else if (section_is_p (sectp
->name
, &names
->loc
))
1830 dwarf2_per_objfile
->loc
.asection
= sectp
;
1831 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1833 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1835 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1836 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1838 else if (section_is_p (sectp
->name
, &names
->macro
))
1840 dwarf2_per_objfile
->macro
.asection
= sectp
;
1841 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1843 else if (section_is_p (sectp
->name
, &names
->str
))
1845 dwarf2_per_objfile
->str
.asection
= sectp
;
1846 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1848 else if (section_is_p (sectp
->name
, &names
->addr
))
1850 dwarf2_per_objfile
->addr
.asection
= sectp
;
1851 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1853 else if (section_is_p (sectp
->name
, &names
->frame
))
1855 dwarf2_per_objfile
->frame
.asection
= sectp
;
1856 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1858 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1860 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1861 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1863 else if (section_is_p (sectp
->name
, &names
->ranges
))
1865 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1866 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1868 else if (section_is_p (sectp
->name
, &names
->types
))
1870 struct dwarf2_section_info type_section
;
1872 memset (&type_section
, 0, sizeof (type_section
));
1873 type_section
.asection
= sectp
;
1874 type_section
.size
= bfd_get_section_size (sectp
);
1876 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1879 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1881 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1882 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1885 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1886 && bfd_section_vma (abfd
, sectp
) == 0)
1887 dwarf2_per_objfile
->has_section_at_zero
= 1;
1890 /* A helper function that decides whether a section is empty,
1894 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1896 return info
->asection
== NULL
|| info
->size
== 0;
1899 /* Read the contents of the section INFO.
1900 OBJFILE is the main object file, but not necessarily the file where
1901 the section comes from. E.g., for DWO files INFO->asection->owner
1902 is the bfd of the DWO file.
1903 If the section is compressed, uncompress it before returning. */
1906 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1908 asection
*sectp
= info
->asection
;
1910 gdb_byte
*buf
, *retbuf
;
1911 unsigned char header
[4];
1915 info
->buffer
= NULL
;
1918 if (dwarf2_section_empty_p (info
))
1921 abfd
= sectp
->owner
;
1923 /* If the section has relocations, we must read it ourselves.
1924 Otherwise we attach it to the BFD. */
1925 if ((sectp
->flags
& SEC_RELOC
) == 0)
1927 const gdb_byte
*bytes
= gdb_bfd_map_section (sectp
, &info
->size
);
1929 /* We have to cast away const here for historical reasons.
1930 Fixing dwarf2read to be const-correct would be quite nice. */
1931 info
->buffer
= (gdb_byte
*) bytes
;
1935 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1938 /* When debugging .o files, we may need to apply relocations; see
1939 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1940 We never compress sections in .o files, so we only need to
1941 try this when the section is not compressed. */
1942 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1945 info
->buffer
= retbuf
;
1949 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1950 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1951 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1952 bfd_get_filename (abfd
));
1955 /* A helper function that returns the size of a section in a safe way.
1956 If you are positive that the section has been read before using the
1957 size, then it is safe to refer to the dwarf2_section_info object's
1958 "size" field directly. In other cases, you must call this
1959 function, because for compressed sections the size field is not set
1960 correctly until the section has been read. */
1962 static bfd_size_type
1963 dwarf2_section_size (struct objfile
*objfile
,
1964 struct dwarf2_section_info
*info
)
1967 dwarf2_read_section (objfile
, info
);
1971 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1975 dwarf2_get_section_info (struct objfile
*objfile
,
1976 enum dwarf2_section_enum sect
,
1977 asection
**sectp
, gdb_byte
**bufp
,
1978 bfd_size_type
*sizep
)
1980 struct dwarf2_per_objfile
*data
1981 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1982 struct dwarf2_section_info
*info
;
1984 /* We may see an objfile without any DWARF, in which case we just
1995 case DWARF2_DEBUG_FRAME
:
1996 info
= &data
->frame
;
1998 case DWARF2_EH_FRAME
:
1999 info
= &data
->eh_frame
;
2002 gdb_assert_not_reached ("unexpected section");
2005 dwarf2_read_section (objfile
, info
);
2007 *sectp
= info
->asection
;
2008 *bufp
= info
->buffer
;
2009 *sizep
= info
->size
;
2012 /* A helper function to find the sections for a .dwz file. */
2015 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2017 struct dwz_file
*dwz_file
= arg
;
2019 /* Note that we only support the standard ELF names, because .dwz
2020 is ELF-only (at the time of writing). */
2021 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2023 dwz_file
->abbrev
.asection
= sectp
;
2024 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2026 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2028 dwz_file
->info
.asection
= sectp
;
2029 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2031 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2033 dwz_file
->str
.asection
= sectp
;
2034 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2036 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2038 dwz_file
->line
.asection
= sectp
;
2039 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2041 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2043 dwz_file
->macro
.asection
= sectp
;
2044 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2046 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2048 dwz_file
->gdb_index
.asection
= sectp
;
2049 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2053 /* Open the separate '.dwz' debug file, if needed. Error if the file
2056 static struct dwz_file
*
2057 dwarf2_get_dwz_file (void)
2059 bfd
*abfd
, *dwz_bfd
;
2062 struct cleanup
*cleanup
;
2063 const char *filename
;
2064 struct dwz_file
*result
;
2066 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2067 return dwarf2_per_objfile
->dwz_file
;
2069 abfd
= dwarf2_per_objfile
->objfile
->obfd
;
2070 section
= bfd_get_section_by_name (abfd
, ".gnu_debugaltlink");
2071 if (section
== NULL
)
2072 error (_("could not find '.gnu_debugaltlink' section"));
2073 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
2074 error (_("could not read '.gnu_debugaltlink' section: %s"),
2075 bfd_errmsg (bfd_get_error ()));
2076 cleanup
= make_cleanup (xfree
, data
);
2079 if (!IS_ABSOLUTE_PATH (filename
))
2081 char *abs
= gdb_realpath (dwarf2_per_objfile
->objfile
->name
);
2084 make_cleanup (xfree
, abs
);
2085 abs
= ldirname (abs
);
2086 make_cleanup (xfree
, abs
);
2088 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2089 make_cleanup (xfree
, rel
);
2093 /* The format is just a NUL-terminated file name, followed by the
2094 build-id. For now, though, we ignore the build-id. */
2095 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2096 if (dwz_bfd
== NULL
)
2097 error (_("could not read '%s': %s"), filename
,
2098 bfd_errmsg (bfd_get_error ()));
2100 if (!bfd_check_format (dwz_bfd
, bfd_object
))
2102 gdb_bfd_unref (dwz_bfd
);
2103 error (_("file '%s' was not usable: %s"), filename
,
2104 bfd_errmsg (bfd_get_error ()));
2107 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2109 result
->dwz_bfd
= dwz_bfd
;
2111 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2113 do_cleanups (cleanup
);
2118 /* DWARF quick_symbols_functions support. */
2120 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2121 unique line tables, so we maintain a separate table of all .debug_line
2122 derived entries to support the sharing.
2123 All the quick functions need is the list of file names. We discard the
2124 line_header when we're done and don't need to record it here. */
2125 struct quick_file_names
2127 /* The data used to construct the hash key. */
2128 struct stmt_list_hash hash
;
2130 /* The number of entries in file_names, real_names. */
2131 unsigned int num_file_names
;
2133 /* The file names from the line table, after being run through
2135 const char **file_names
;
2137 /* The file names from the line table after being run through
2138 gdb_realpath. These are computed lazily. */
2139 const char **real_names
;
2142 /* When using the index (and thus not using psymtabs), each CU has an
2143 object of this type. This is used to hold information needed by
2144 the various "quick" methods. */
2145 struct dwarf2_per_cu_quick_data
2147 /* The file table. This can be NULL if there was no file table
2148 or it's currently not read in.
2149 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2150 struct quick_file_names
*file_names
;
2152 /* The corresponding symbol table. This is NULL if symbols for this
2153 CU have not yet been read. */
2154 struct symtab
*symtab
;
2156 /* A temporary mark bit used when iterating over all CUs in
2157 expand_symtabs_matching. */
2158 unsigned int mark
: 1;
2160 /* True if we've tried to read the file table and found there isn't one.
2161 There will be no point in trying to read it again next time. */
2162 unsigned int no_file_data
: 1;
2165 /* Utility hash function for a stmt_list_hash. */
2168 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2172 if (stmt_list_hash
->dwo_unit
!= NULL
)
2173 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2174 v
+= stmt_list_hash
->line_offset
.sect_off
;
2178 /* Utility equality function for a stmt_list_hash. */
2181 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2182 const struct stmt_list_hash
*rhs
)
2184 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2186 if (lhs
->dwo_unit
!= NULL
2187 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2190 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2193 /* Hash function for a quick_file_names. */
2196 hash_file_name_entry (const void *e
)
2198 const struct quick_file_names
*file_data
= e
;
2200 return hash_stmt_list_entry (&file_data
->hash
);
2203 /* Equality function for a quick_file_names. */
2206 eq_file_name_entry (const void *a
, const void *b
)
2208 const struct quick_file_names
*ea
= a
;
2209 const struct quick_file_names
*eb
= b
;
2211 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2214 /* Delete function for a quick_file_names. */
2217 delete_file_name_entry (void *e
)
2219 struct quick_file_names
*file_data
= e
;
2222 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2224 xfree ((void*) file_data
->file_names
[i
]);
2225 if (file_data
->real_names
)
2226 xfree ((void*) file_data
->real_names
[i
]);
2229 /* The space for the struct itself lives on objfile_obstack,
2230 so we don't free it here. */
2233 /* Create a quick_file_names hash table. */
2236 create_quick_file_names_table (unsigned int nr_initial_entries
)
2238 return htab_create_alloc (nr_initial_entries
,
2239 hash_file_name_entry
, eq_file_name_entry
,
2240 delete_file_name_entry
, xcalloc
, xfree
);
2243 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2244 have to be created afterwards. You should call age_cached_comp_units after
2245 processing PER_CU->CU. dw2_setup must have been already called. */
2248 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2250 if (per_cu
->is_debug_types
)
2251 load_full_type_unit (per_cu
);
2253 load_full_comp_unit (per_cu
, language_minimal
);
2255 gdb_assert (per_cu
->cu
!= NULL
);
2257 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2260 /* Read in the symbols for PER_CU. */
2263 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2265 struct cleanup
*back_to
;
2267 /* Skip type_unit_groups, reading the type units they contain
2268 is handled elsewhere. */
2269 if (IS_TYPE_UNIT_GROUP (per_cu
))
2272 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2274 if (dwarf2_per_objfile
->using_index
2275 ? per_cu
->v
.quick
->symtab
== NULL
2276 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2278 queue_comp_unit (per_cu
, language_minimal
);
2284 /* Age the cache, releasing compilation units that have not
2285 been used recently. */
2286 age_cached_comp_units ();
2288 do_cleanups (back_to
);
2291 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2292 the objfile from which this CU came. Returns the resulting symbol
2295 static struct symtab
*
2296 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2298 gdb_assert (dwarf2_per_objfile
->using_index
);
2299 if (!per_cu
->v
.quick
->symtab
)
2301 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2302 increment_reading_symtab ();
2303 dw2_do_instantiate_symtab (per_cu
);
2304 process_cu_includes ();
2305 do_cleanups (back_to
);
2307 return per_cu
->v
.quick
->symtab
;
2310 /* Return the CU given its index.
2312 This is intended for loops like:
2314 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2315 + dwarf2_per_objfile->n_type_units); ++i)
2317 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2323 static struct dwarf2_per_cu_data
*
2324 dw2_get_cu (int index
)
2326 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2328 index
-= dwarf2_per_objfile
->n_comp_units
;
2329 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2330 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2333 return dwarf2_per_objfile
->all_comp_units
[index
];
2336 /* Return the primary CU given its index.
2337 The difference between this function and dw2_get_cu is in the handling
2338 of type units (TUs). Here we return the type_unit_group object.
2340 This is intended for loops like:
2342 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2343 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2345 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2351 static struct dwarf2_per_cu_data
*
2352 dw2_get_primary_cu (int index
)
2354 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2356 index
-= dwarf2_per_objfile
->n_comp_units
;
2357 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2358 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2361 return dwarf2_per_objfile
->all_comp_units
[index
];
2364 /* A helper for create_cus_from_index that handles a given list of
2368 create_cus_from_index_list (struct objfile
*objfile
,
2369 const gdb_byte
*cu_list
, offset_type n_elements
,
2370 struct dwarf2_section_info
*section
,
2376 for (i
= 0; i
< n_elements
; i
+= 2)
2378 struct dwarf2_per_cu_data
*the_cu
;
2379 ULONGEST offset
, length
;
2381 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2382 offset
= extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2383 length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2386 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2387 struct dwarf2_per_cu_data
);
2388 the_cu
->offset
.sect_off
= offset
;
2389 the_cu
->length
= length
;
2390 the_cu
->objfile
= objfile
;
2391 the_cu
->info_or_types_section
= section
;
2392 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2393 struct dwarf2_per_cu_quick_data
);
2394 the_cu
->is_dwz
= is_dwz
;
2395 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2399 /* Read the CU list from the mapped index, and use it to create all
2400 the CU objects for this objfile. */
2403 create_cus_from_index (struct objfile
*objfile
,
2404 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2405 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2407 struct dwz_file
*dwz
;
2409 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2410 dwarf2_per_objfile
->all_comp_units
2411 = obstack_alloc (&objfile
->objfile_obstack
,
2412 dwarf2_per_objfile
->n_comp_units
2413 * sizeof (struct dwarf2_per_cu_data
*));
2415 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2416 &dwarf2_per_objfile
->info
, 0, 0);
2418 if (dwz_elements
== 0)
2421 dwz
= dwarf2_get_dwz_file ();
2422 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2423 cu_list_elements
/ 2);
2426 /* Create the signatured type hash table from the index. */
2429 create_signatured_type_table_from_index (struct objfile
*objfile
,
2430 struct dwarf2_section_info
*section
,
2431 const gdb_byte
*bytes
,
2432 offset_type elements
)
2435 htab_t sig_types_hash
;
2437 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2438 dwarf2_per_objfile
->all_type_units
2439 = obstack_alloc (&objfile
->objfile_obstack
,
2440 dwarf2_per_objfile
->n_type_units
2441 * sizeof (struct signatured_type
*));
2443 sig_types_hash
= allocate_signatured_type_table (objfile
);
2445 for (i
= 0; i
< elements
; i
+= 3)
2447 struct signatured_type
*sig_type
;
2448 ULONGEST offset
, type_offset_in_tu
, signature
;
2451 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2452 offset
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2453 type_offset_in_tu
= extract_unsigned_integer (bytes
+ 8, 8,
2455 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2458 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2459 struct signatured_type
);
2460 sig_type
->signature
= signature
;
2461 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2462 sig_type
->per_cu
.is_debug_types
= 1;
2463 sig_type
->per_cu
.info_or_types_section
= section
;
2464 sig_type
->per_cu
.offset
.sect_off
= offset
;
2465 sig_type
->per_cu
.objfile
= objfile
;
2466 sig_type
->per_cu
.v
.quick
2467 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2468 struct dwarf2_per_cu_quick_data
);
2470 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2473 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2476 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2479 /* Read the address map data from the mapped index, and use it to
2480 populate the objfile's psymtabs_addrmap. */
2483 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2485 const gdb_byte
*iter
, *end
;
2486 struct obstack temp_obstack
;
2487 struct addrmap
*mutable_map
;
2488 struct cleanup
*cleanup
;
2491 obstack_init (&temp_obstack
);
2492 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2493 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2495 iter
= index
->address_table
;
2496 end
= iter
+ index
->address_table_size
;
2498 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2502 ULONGEST hi
, lo
, cu_index
;
2503 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2505 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2507 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2510 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2511 dw2_get_cu (cu_index
));
2514 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2515 &objfile
->objfile_obstack
);
2516 do_cleanups (cleanup
);
2519 /* The hash function for strings in the mapped index. This is the same as
2520 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2521 implementation. This is necessary because the hash function is tied to the
2522 format of the mapped index file. The hash values do not have to match with
2525 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2528 mapped_index_string_hash (int index_version
, const void *p
)
2530 const unsigned char *str
= (const unsigned char *) p
;
2534 while ((c
= *str
++) != 0)
2536 if (index_version
>= 5)
2538 r
= r
* 67 + c
- 113;
2544 /* Find a slot in the mapped index INDEX for the object named NAME.
2545 If NAME is found, set *VEC_OUT to point to the CU vector in the
2546 constant pool and return 1. If NAME cannot be found, return 0. */
2549 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2550 offset_type
**vec_out
)
2552 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2554 offset_type slot
, step
;
2555 int (*cmp
) (const char *, const char *);
2557 if (current_language
->la_language
== language_cplus
2558 || current_language
->la_language
== language_java
2559 || current_language
->la_language
== language_fortran
)
2561 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2563 const char *paren
= strchr (name
, '(');
2569 dup
= xmalloc (paren
- name
+ 1);
2570 memcpy (dup
, name
, paren
- name
);
2571 dup
[paren
- name
] = 0;
2573 make_cleanup (xfree
, dup
);
2578 /* Index version 4 did not support case insensitive searches. But the
2579 indices for case insensitive languages are built in lowercase, therefore
2580 simulate our NAME being searched is also lowercased. */
2581 hash
= mapped_index_string_hash ((index
->version
== 4
2582 && case_sensitivity
== case_sensitive_off
2583 ? 5 : index
->version
),
2586 slot
= hash
& (index
->symbol_table_slots
- 1);
2587 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2588 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2592 /* Convert a slot number to an offset into the table. */
2593 offset_type i
= 2 * slot
;
2595 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2597 do_cleanups (back_to
);
2601 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2602 if (!cmp (name
, str
))
2604 *vec_out
= (offset_type
*) (index
->constant_pool
2605 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2606 do_cleanups (back_to
);
2610 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2614 /* A helper function that reads the .gdb_index from SECTION and fills
2615 in MAP. FILENAME is the name of the file containing the section;
2616 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2617 ok to use deprecated sections.
2619 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2620 out parameters that are filled in with information about the CU and
2621 TU lists in the section.
2623 Returns 1 if all went well, 0 otherwise. */
2626 read_index_from_section (struct objfile
*objfile
,
2627 const char *filename
,
2629 struct dwarf2_section_info
*section
,
2630 struct mapped_index
*map
,
2631 const gdb_byte
**cu_list
,
2632 offset_type
*cu_list_elements
,
2633 const gdb_byte
**types_list
,
2634 offset_type
*types_list_elements
)
2637 offset_type version
;
2638 offset_type
*metadata
;
2641 if (dwarf2_section_empty_p (section
))
2644 /* Older elfutils strip versions could keep the section in the main
2645 executable while splitting it for the separate debug info file. */
2646 if ((bfd_get_file_flags (section
->asection
) & SEC_HAS_CONTENTS
) == 0)
2649 dwarf2_read_section (objfile
, section
);
2651 addr
= section
->buffer
;
2652 /* Version check. */
2653 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2654 /* Versions earlier than 3 emitted every copy of a psymbol. This
2655 causes the index to behave very poorly for certain requests. Version 3
2656 contained incomplete addrmap. So, it seems better to just ignore such
2660 static int warning_printed
= 0;
2661 if (!warning_printed
)
2663 warning (_("Skipping obsolete .gdb_index section in %s."),
2665 warning_printed
= 1;
2669 /* Index version 4 uses a different hash function than index version
2672 Versions earlier than 6 did not emit psymbols for inlined
2673 functions. Using these files will cause GDB not to be able to
2674 set breakpoints on inlined functions by name, so we ignore these
2675 indices unless the user has done
2676 "set use-deprecated-index-sections on". */
2677 if (version
< 6 && !deprecated_ok
)
2679 static int warning_printed
= 0;
2680 if (!warning_printed
)
2683 Skipping deprecated .gdb_index section in %s.\n\
2684 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2685 to use the section anyway."),
2687 warning_printed
= 1;
2691 /* Indexes with higher version than the one supported by GDB may be no
2692 longer backward compatible. */
2696 map
->version
= version
;
2697 map
->total_size
= section
->size
;
2699 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2702 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2703 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2707 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2708 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2709 - MAYBE_SWAP (metadata
[i
]))
2713 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2714 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2715 - MAYBE_SWAP (metadata
[i
]));
2718 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2719 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2720 - MAYBE_SWAP (metadata
[i
]))
2721 / (2 * sizeof (offset_type
)));
2724 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2730 /* Read the index file. If everything went ok, initialize the "quick"
2731 elements of all the CUs and return 1. Otherwise, return 0. */
2734 dwarf2_read_index (struct objfile
*objfile
)
2736 struct mapped_index local_map
, *map
;
2737 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2738 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2740 if (!read_index_from_section (objfile
, objfile
->name
,
2741 use_deprecated_index_sections
,
2742 &dwarf2_per_objfile
->gdb_index
, &local_map
,
2743 &cu_list
, &cu_list_elements
,
2744 &types_list
, &types_list_elements
))
2747 /* Don't use the index if it's empty. */
2748 if (local_map
.symbol_table_slots
== 0)
2751 /* If there is a .dwz file, read it so we can get its CU list as
2753 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
2755 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
2756 struct mapped_index dwz_map
;
2757 const gdb_byte
*dwz_types_ignore
;
2758 offset_type dwz_types_elements_ignore
;
2760 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
2762 &dwz
->gdb_index
, &dwz_map
,
2763 &dwz_list
, &dwz_list_elements
,
2765 &dwz_types_elements_ignore
))
2767 warning (_("could not read '.gdb_index' section from %s; skipping"),
2768 bfd_get_filename (dwz
->dwz_bfd
));
2773 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
2776 if (types_list_elements
)
2778 struct dwarf2_section_info
*section
;
2780 /* We can only handle a single .debug_types when we have an
2782 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2785 section
= VEC_index (dwarf2_section_info_def
,
2786 dwarf2_per_objfile
->types
, 0);
2788 create_signatured_type_table_from_index (objfile
, section
, types_list
,
2789 types_list_elements
);
2792 create_addrmap_from_index (objfile
, &local_map
);
2794 map
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct mapped_index
));
2797 dwarf2_per_objfile
->index_table
= map
;
2798 dwarf2_per_objfile
->using_index
= 1;
2799 dwarf2_per_objfile
->quick_file_names_table
=
2800 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2805 /* A helper for the "quick" functions which sets the global
2806 dwarf2_per_objfile according to OBJFILE. */
2809 dw2_setup (struct objfile
*objfile
)
2811 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2812 gdb_assert (dwarf2_per_objfile
);
2815 /* Reader function for dw2_build_type_unit_groups. */
2818 dw2_build_type_unit_groups_reader (const struct die_reader_specs
*reader
,
2820 struct die_info
*type_unit_die
,
2824 struct dwarf2_cu
*cu
= reader
->cu
;
2825 struct attribute
*attr
;
2826 struct type_unit_group
*tu_group
;
2828 gdb_assert (data
== NULL
);
2833 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
2834 /* Call this for its side-effect of creating the associated
2835 struct type_unit_group if it doesn't already exist. */
2836 tu_group
= get_type_unit_group (cu
, attr
);
2839 /* Build dwarf2_per_objfile->type_unit_groups.
2840 This function may be called multiple times. */
2843 dw2_build_type_unit_groups (void)
2845 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
2846 build_type_unit_groups (dw2_build_type_unit_groups_reader
, NULL
);
2849 /* die_reader_func for dw2_get_file_names. */
2852 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2854 struct die_info
*comp_unit_die
,
2858 struct dwarf2_cu
*cu
= reader
->cu
;
2859 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2860 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2861 struct dwarf2_per_cu_data
*lh_cu
;
2862 struct line_header
*lh
;
2863 struct attribute
*attr
;
2865 char *name
, *comp_dir
;
2867 struct quick_file_names
*qfn
;
2868 unsigned int line_offset
;
2870 /* Our callers never want to match partial units -- instead they
2871 will match the enclosing full CU. */
2872 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2874 this_cu
->v
.quick
->no_file_data
= 1;
2878 /* If we're reading the line header for TUs, store it in the "per_cu"
2880 if (this_cu
->is_debug_types
)
2882 struct type_unit_group
*tu_group
= data
;
2884 gdb_assert (tu_group
!= NULL
);
2885 lh_cu
= &tu_group
->per_cu
;
2894 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2897 struct quick_file_names find_entry
;
2899 line_offset
= DW_UNSND (attr
);
2901 /* We may have already read in this line header (TU line header sharing).
2902 If we have we're done. */
2903 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2904 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2905 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2906 &find_entry
, INSERT
);
2909 lh_cu
->v
.quick
->file_names
= *slot
;
2913 lh
= dwarf_decode_line_header (line_offset
, cu
);
2917 lh_cu
->v
.quick
->no_file_data
= 1;
2921 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2922 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2923 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2924 gdb_assert (slot
!= NULL
);
2927 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2929 qfn
->num_file_names
= lh
->num_file_names
;
2930 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2931 lh
->num_file_names
* sizeof (char *));
2932 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2933 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2934 qfn
->real_names
= NULL
;
2936 free_line_header (lh
);
2938 lh_cu
->v
.quick
->file_names
= qfn
;
2941 /* A helper for the "quick" functions which attempts to read the line
2942 table for THIS_CU. */
2944 static struct quick_file_names
*
2945 dw2_get_file_names (struct objfile
*objfile
,
2946 struct dwarf2_per_cu_data
*this_cu
)
2948 /* For TUs this should only be called on the parent group. */
2949 if (this_cu
->is_debug_types
)
2950 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2952 if (this_cu
->v
.quick
->file_names
!= NULL
)
2953 return this_cu
->v
.quick
->file_names
;
2954 /* If we know there is no line data, no point in looking again. */
2955 if (this_cu
->v
.quick
->no_file_data
)
2958 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2959 in the stub for CUs, there's is no need to lookup the DWO file.
2960 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2962 if (this_cu
->is_debug_types
)
2964 struct type_unit_group
*tu_group
= this_cu
->s
.type_unit_group
;
2966 init_cutu_and_read_dies (tu_group
->t
.first_tu
, NULL
, 0, 0,
2967 dw2_get_file_names_reader
, tu_group
);
2970 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2972 if (this_cu
->v
.quick
->no_file_data
)
2974 return this_cu
->v
.quick
->file_names
;
2977 /* A helper for the "quick" functions which computes and caches the
2978 real path for a given file name from the line table. */
2981 dw2_get_real_path (struct objfile
*objfile
,
2982 struct quick_file_names
*qfn
, int index
)
2984 if (qfn
->real_names
== NULL
)
2985 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2986 qfn
->num_file_names
, sizeof (char *));
2988 if (qfn
->real_names
[index
] == NULL
)
2989 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2991 return qfn
->real_names
[index
];
2994 static struct symtab
*
2995 dw2_find_last_source_symtab (struct objfile
*objfile
)
2999 dw2_setup (objfile
);
3000 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3001 return dw2_instantiate_symtab (dw2_get_cu (index
));
3004 /* Traversal function for dw2_forget_cached_source_info. */
3007 dw2_free_cached_file_names (void **slot
, void *info
)
3009 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3011 if (file_data
->real_names
)
3015 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3017 xfree ((void*) file_data
->real_names
[i
]);
3018 file_data
->real_names
[i
] = NULL
;
3026 dw2_forget_cached_source_info (struct objfile
*objfile
)
3028 dw2_setup (objfile
);
3030 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3031 dw2_free_cached_file_names
, NULL
);
3034 /* Helper function for dw2_map_symtabs_matching_filename that expands
3035 the symtabs and calls the iterator. */
3038 dw2_map_expand_apply (struct objfile
*objfile
,
3039 struct dwarf2_per_cu_data
*per_cu
,
3041 const char *full_path
, const char *real_path
,
3042 int (*callback
) (struct symtab
*, void *),
3045 struct symtab
*last_made
= objfile
->symtabs
;
3047 /* Don't visit already-expanded CUs. */
3048 if (per_cu
->v
.quick
->symtab
)
3051 /* This may expand more than one symtab, and we want to iterate over
3053 dw2_instantiate_symtab (per_cu
);
3055 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
3056 objfile
->symtabs
, last_made
);
3059 /* Implementation of the map_symtabs_matching_filename method. */
3062 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3063 const char *full_path
, const char *real_path
,
3064 int (*callback
) (struct symtab
*, void *),
3068 const char *name_basename
= lbasename (name
);
3069 int name_len
= strlen (name
);
3070 int is_abs
= IS_ABSOLUTE_PATH (name
);
3072 dw2_setup (objfile
);
3074 dw2_build_type_unit_groups ();
3076 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3077 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3080 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3081 struct quick_file_names
*file_data
;
3083 /* We only need to look at symtabs not already expanded. */
3084 if (per_cu
->v
.quick
->symtab
)
3087 file_data
= dw2_get_file_names (objfile
, per_cu
);
3088 if (file_data
== NULL
)
3091 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3093 const char *this_name
= file_data
->file_names
[j
];
3095 if (FILENAME_CMP (name
, this_name
) == 0
3096 || (!is_abs
&& compare_filenames_for_search (this_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 static struct symtab
*
3153 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3154 const char *name
, domain_enum domain
)
3156 /* We do all the work in the pre_expand_symtabs_matching hook
3161 /* A helper function that expands all symtabs that hold an object
3162 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
3163 symbols in block BLOCK_KIND. */
3166 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
3167 int want_specific_block
,
3168 enum block_enum block_kind
,
3169 const char *name
, domain_enum domain
)
3171 struct mapped_index
*index
;
3173 dw2_setup (objfile
);
3175 index
= dwarf2_per_objfile
->index_table
;
3177 /* index_table is NULL if OBJF_READNOW. */
3182 if (find_slot_in_mapped_hash (index
, name
, &vec
))
3184 offset_type i
, len
= MAYBE_SWAP (*vec
);
3185 for (i
= 0; i
< len
; ++i
)
3187 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
3188 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3189 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
3190 int want_static
= block_kind
!= GLOBAL_BLOCK
;
3191 /* This value is only valid for index versions >= 7. */
3192 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3193 gdb_index_symbol_kind symbol_kind
=
3194 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3195 /* Only check the symbol attributes if they're present.
3196 Indices prior to version 7 don't record them,
3197 and indices >= 7 may elide them for certain symbols
3198 (gold does this). */
3200 (index
->version
>= 7
3201 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3204 && want_specific_block
3205 && want_static
!= is_static
)
3208 /* Only check the symbol's kind if it has one. */
3214 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3215 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3216 /* Some types are also in VAR_DOMAIN. */
3217 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3221 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3225 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3233 dw2_instantiate_symtab (per_cu
);
3240 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
3241 enum block_enum block_kind
, const char *name
,
3244 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
3248 dw2_print_stats (struct objfile
*objfile
)
3252 dw2_setup (objfile
);
3254 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3255 + dwarf2_per_objfile
->n_type_units
); ++i
)
3257 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3259 if (!per_cu
->v
.quick
->symtab
)
3262 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3266 dw2_dump (struct objfile
*objfile
)
3268 /* Nothing worth printing. */
3272 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
3273 struct section_offsets
*delta
)
3275 /* There's nothing to relocate here. */
3279 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3280 const char *func_name
)
3282 /* Note: It doesn't matter what we pass for block_kind here. */
3283 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
3288 dw2_expand_all_symtabs (struct objfile
*objfile
)
3292 dw2_setup (objfile
);
3294 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3295 + dwarf2_per_objfile
->n_type_units
); ++i
)
3297 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3299 dw2_instantiate_symtab (per_cu
);
3304 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3305 const char *filename
)
3309 dw2_setup (objfile
);
3311 /* We don't need to consider type units here.
3312 This is only called for examining code, e.g. expand_line_sal.
3313 There can be an order of magnitude (or more) more type units
3314 than comp units, and we avoid them if we can. */
3316 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3319 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3320 struct quick_file_names
*file_data
;
3322 /* We only need to look at symtabs not already expanded. */
3323 if (per_cu
->v
.quick
->symtab
)
3326 file_data
= dw2_get_file_names (objfile
, per_cu
);
3327 if (file_data
== NULL
)
3330 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3332 const char *this_name
= file_data
->file_names
[j
];
3333 if (FILENAME_CMP (this_name
, filename
) == 0)
3335 dw2_instantiate_symtab (per_cu
);
3342 /* A helper function for dw2_find_symbol_file that finds the primary
3343 file name for a given CU. This is a die_reader_func. */
3346 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3348 struct die_info
*comp_unit_die
,
3352 const char **result_ptr
= data
;
3353 struct dwarf2_cu
*cu
= reader
->cu
;
3354 struct attribute
*attr
;
3356 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3360 *result_ptr
= DW_STRING (attr
);
3364 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3366 struct dwarf2_per_cu_data
*per_cu
;
3368 const char *filename
;
3370 dw2_setup (objfile
);
3372 /* index_table is NULL if OBJF_READNOW. */
3373 if (!dwarf2_per_objfile
->index_table
)
3377 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3379 struct blockvector
*bv
= BLOCKVECTOR (s
);
3380 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3381 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3384 return SYMBOL_SYMTAB (sym
)->filename
;
3389 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3393 /* Note that this just looks at the very first one named NAME -- but
3394 actually we are looking for a function. find_main_filename
3395 should be rewritten so that it doesn't require a custom hook. It
3396 could just use the ordinary symbol tables. */
3397 /* vec[0] is the length, which must always be >0. */
3398 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3400 if (per_cu
->v
.quick
->symtab
!= NULL
)
3401 return per_cu
->v
.quick
->symtab
->filename
;
3403 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3404 dw2_get_primary_filename_reader
, &filename
);
3410 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3411 struct objfile
*objfile
, int global
,
3412 int (*callback
) (struct block
*,
3413 struct symbol
*, void *),
3414 void *data
, symbol_compare_ftype
*match
,
3415 symbol_compare_ftype
*ordered_compare
)
3417 /* Currently unimplemented; used for Ada. The function can be called if the
3418 current language is Ada for a non-Ada objfile using GNU index. As Ada
3419 does not look for non-Ada symbols this function should just return. */
3423 dw2_expand_symtabs_matching
3424 (struct objfile
*objfile
,
3425 int (*file_matcher
) (const char *, void *),
3426 int (*name_matcher
) (const char *, void *),
3427 enum search_domain kind
,
3432 struct mapped_index
*index
;
3434 dw2_setup (objfile
);
3436 /* index_table is NULL if OBJF_READNOW. */
3437 if (!dwarf2_per_objfile
->index_table
)
3439 index
= dwarf2_per_objfile
->index_table
;
3441 if (file_matcher
!= NULL
)
3443 struct cleanup
*cleanup
;
3444 htab_t visited_found
, visited_not_found
;
3446 dw2_build_type_unit_groups ();
3448 visited_found
= htab_create_alloc (10,
3449 htab_hash_pointer
, htab_eq_pointer
,
3450 NULL
, xcalloc
, xfree
);
3451 cleanup
= make_cleanup_htab_delete (visited_found
);
3452 visited_not_found
= htab_create_alloc (10,
3453 htab_hash_pointer
, htab_eq_pointer
,
3454 NULL
, xcalloc
, xfree
);
3455 make_cleanup_htab_delete (visited_not_found
);
3457 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3458 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3461 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3462 struct quick_file_names
*file_data
;
3465 per_cu
->v
.quick
->mark
= 0;
3467 /* We only need to look at symtabs not already expanded. */
3468 if (per_cu
->v
.quick
->symtab
)
3471 file_data
= dw2_get_file_names (objfile
, per_cu
);
3472 if (file_data
== NULL
)
3475 if (htab_find (visited_not_found
, file_data
) != NULL
)
3477 else if (htab_find (visited_found
, file_data
) != NULL
)
3479 per_cu
->v
.quick
->mark
= 1;
3483 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3485 if (file_matcher (file_data
->file_names
[j
], data
))
3487 per_cu
->v
.quick
->mark
= 1;
3492 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3494 : visited_not_found
,
3499 do_cleanups (cleanup
);
3502 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3504 offset_type idx
= 2 * iter
;
3506 offset_type
*vec
, vec_len
, vec_idx
;
3508 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3511 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3513 if (! (*name_matcher
) (name
, data
))
3516 /* The name was matched, now expand corresponding CUs that were
3518 vec
= (offset_type
*) (index
->constant_pool
3519 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3520 vec_len
= MAYBE_SWAP (vec
[0]);
3521 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3523 struct dwarf2_per_cu_data
*per_cu
;
3524 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3525 gdb_index_symbol_kind symbol_kind
=
3526 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3527 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3529 /* Don't crash on bad data. */
3530 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3531 + dwarf2_per_objfile
->n_type_units
))
3534 /* Only check the symbol's kind if it has one.
3535 Indices prior to version 7 don't record it. */
3536 if (index
->version
>= 7)
3540 case VARIABLES_DOMAIN
:
3541 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3544 case FUNCTIONS_DOMAIN
:
3545 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3549 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3557 per_cu
= dw2_get_cu (cu_index
);
3558 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3559 dw2_instantiate_symtab (per_cu
);
3564 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3567 static struct symtab
*
3568 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3572 if (BLOCKVECTOR (symtab
) != NULL
3573 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3576 if (symtab
->includes
== NULL
)
3579 for (i
= 0; symtab
->includes
[i
]; ++i
)
3581 struct symtab
*s
= symtab
->includes
[i
];
3583 s
= recursively_find_pc_sect_symtab (s
, pc
);
3591 static struct symtab
*
3592 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3593 struct minimal_symbol
*msymbol
,
3595 struct obj_section
*section
,
3598 struct dwarf2_per_cu_data
*data
;
3599 struct symtab
*result
;
3601 dw2_setup (objfile
);
3603 if (!objfile
->psymtabs_addrmap
)
3606 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3610 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3611 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3612 paddress (get_objfile_arch (objfile
), pc
));
3614 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3615 gdb_assert (result
!= NULL
);
3620 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3621 void *data
, int need_fullname
)
3624 struct cleanup
*cleanup
;
3625 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3626 NULL
, xcalloc
, xfree
);
3628 cleanup
= make_cleanup_htab_delete (visited
);
3629 dw2_setup (objfile
);
3631 dw2_build_type_unit_groups ();
3633 /* We can ignore file names coming from already-expanded CUs. */
3634 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3635 + dwarf2_per_objfile
->n_type_units
); ++i
)
3637 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3639 if (per_cu
->v
.quick
->symtab
)
3641 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3644 *slot
= per_cu
->v
.quick
->file_names
;
3648 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3649 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3652 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3653 struct quick_file_names
*file_data
;
3656 /* We only need to look at symtabs not already expanded. */
3657 if (per_cu
->v
.quick
->symtab
)
3660 file_data
= dw2_get_file_names (objfile
, per_cu
);
3661 if (file_data
== NULL
)
3664 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3667 /* Already visited. */
3672 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3674 const char *this_real_name
;
3677 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3679 this_real_name
= NULL
;
3680 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3684 do_cleanups (cleanup
);
3688 dw2_has_symbols (struct objfile
*objfile
)
3693 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3696 dw2_find_last_source_symtab
,
3697 dw2_forget_cached_source_info
,
3698 dw2_map_symtabs_matching_filename
,
3700 dw2_pre_expand_symtabs_matching
,
3704 dw2_expand_symtabs_for_function
,
3705 dw2_expand_all_symtabs
,
3706 dw2_expand_symtabs_with_filename
,
3707 dw2_find_symbol_file
,
3708 dw2_map_matching_symbols
,
3709 dw2_expand_symtabs_matching
,
3710 dw2_find_pc_sect_symtab
,
3711 dw2_map_symbol_filenames
3714 /* Initialize for reading DWARF for this objfile. Return 0 if this
3715 file will use psymtabs, or 1 if using the GNU index. */
3718 dwarf2_initialize_objfile (struct objfile
*objfile
)
3720 /* If we're about to read full symbols, don't bother with the
3721 indices. In this case we also don't care if some other debug
3722 format is making psymtabs, because they are all about to be
3724 if ((objfile
->flags
& OBJF_READNOW
))
3728 dwarf2_per_objfile
->using_index
= 1;
3729 create_all_comp_units (objfile
);
3730 create_all_type_units (objfile
);
3731 dwarf2_per_objfile
->quick_file_names_table
=
3732 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3734 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3735 + dwarf2_per_objfile
->n_type_units
); ++i
)
3737 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3739 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3740 struct dwarf2_per_cu_quick_data
);
3743 /* Return 1 so that gdb sees the "quick" functions. However,
3744 these functions will be no-ops because we will have expanded
3749 if (dwarf2_read_index (objfile
))
3757 /* Build a partial symbol table. */
3760 dwarf2_build_psymtabs (struct objfile
*objfile
)
3762 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3764 init_psymbol_list (objfile
, 1024);
3767 dwarf2_build_psymtabs_hard (objfile
);
3770 /* Return the total length of the CU described by HEADER. */
3773 get_cu_length (const struct comp_unit_head
*header
)
3775 return header
->initial_length_size
+ header
->length
;
3778 /* Return TRUE if OFFSET is within CU_HEADER. */
3781 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3783 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3784 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3786 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3789 /* Find the base address of the compilation unit for range lists and
3790 location lists. It will normally be specified by DW_AT_low_pc.
3791 In DWARF-3 draft 4, the base address could be overridden by
3792 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3793 compilation units with discontinuous ranges. */
3796 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3798 struct attribute
*attr
;
3801 cu
->base_address
= 0;
3803 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3806 cu
->base_address
= DW_ADDR (attr
);
3811 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3814 cu
->base_address
= DW_ADDR (attr
);
3820 /* Read in the comp unit header information from the debug_info at info_ptr.
3821 NOTE: This leaves members offset, first_die_offset to be filled in
3825 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3826 gdb_byte
*info_ptr
, bfd
*abfd
)
3829 unsigned int bytes_read
;
3831 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3832 cu_header
->initial_length_size
= bytes_read
;
3833 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3834 info_ptr
+= bytes_read
;
3835 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3837 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3839 info_ptr
+= bytes_read
;
3840 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3842 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3843 if (signed_addr
< 0)
3844 internal_error (__FILE__
, __LINE__
,
3845 _("read_comp_unit_head: dwarf from non elf file"));
3846 cu_header
->signed_addr_p
= signed_addr
;
3851 /* Helper function that returns the proper abbrev section for
3854 static struct dwarf2_section_info
*
3855 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
3857 struct dwarf2_section_info
*abbrev
;
3859 if (this_cu
->is_dwz
)
3860 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
3862 abbrev
= &dwarf2_per_objfile
->abbrev
;
3867 /* Subroutine of read_and_check_comp_unit_head and
3868 read_and_check_type_unit_head to simplify them.
3869 Perform various error checking on the header. */
3872 error_check_comp_unit_head (struct comp_unit_head
*header
,
3873 struct dwarf2_section_info
*section
,
3874 struct dwarf2_section_info
*abbrev_section
)
3876 bfd
*abfd
= section
->asection
->owner
;
3877 const char *filename
= bfd_get_filename (abfd
);
3879 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3880 error (_("Dwarf Error: wrong version in compilation unit header "
3881 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3884 if (header
->abbrev_offset
.sect_off
3885 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
3886 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3887 "(offset 0x%lx + 6) [in module %s]"),
3888 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3891 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3892 avoid potential 32-bit overflow. */
3893 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3895 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3896 "(offset 0x%lx + 0) [in module %s]"),
3897 (long) header
->length
, (long) header
->offset
.sect_off
,
3901 /* Read in a CU/TU header and perform some basic error checking.
3902 The contents of the header are stored in HEADER.
3903 The result is a pointer to the start of the first DIE. */
3906 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3907 struct dwarf2_section_info
*section
,
3908 struct dwarf2_section_info
*abbrev_section
,
3910 int is_debug_types_section
)
3912 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3913 bfd
*abfd
= section
->asection
->owner
;
3915 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3917 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3919 /* If we're reading a type unit, skip over the signature and
3920 type_offset fields. */
3921 if (is_debug_types_section
)
3922 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3924 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3926 error_check_comp_unit_head (header
, section
, abbrev_section
);
3931 /* Read in the types comp unit header information from .debug_types entry at
3932 types_ptr. The result is a pointer to one past the end of the header. */
3935 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3936 struct dwarf2_section_info
*section
,
3937 struct dwarf2_section_info
*abbrev_section
,
3939 ULONGEST
*signature
,
3940 cu_offset
*type_offset_in_tu
)
3942 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3943 bfd
*abfd
= section
->asection
->owner
;
3945 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3947 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3949 /* If we're reading a type unit, skip over the signature and
3950 type_offset fields. */
3951 if (signature
!= NULL
)
3952 *signature
= read_8_bytes (abfd
, info_ptr
);
3954 if (type_offset_in_tu
!= NULL
)
3955 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3956 header
->offset_size
);
3957 info_ptr
+= header
->offset_size
;
3959 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3961 error_check_comp_unit_head (header
, section
, abbrev_section
);
3966 /* Fetch the abbreviation table offset from a comp or type unit header. */
3969 read_abbrev_offset (struct dwarf2_section_info
*section
,
3972 bfd
*abfd
= section
->asection
->owner
;
3974 unsigned int length
, initial_length_size
, offset_size
;
3975 sect_offset abbrev_offset
;
3977 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3978 info_ptr
= section
->buffer
+ offset
.sect_off
;
3979 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
3980 offset_size
= initial_length_size
== 4 ? 4 : 8;
3981 info_ptr
+= initial_length_size
+ 2 /*version*/;
3982 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
3983 return abbrev_offset
;
3986 /* Allocate a new partial symtab for file named NAME and mark this new
3987 partial symtab as being an include of PST. */
3990 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3991 struct objfile
*objfile
)
3993 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3995 subpst
->section_offsets
= pst
->section_offsets
;
3996 subpst
->textlow
= 0;
3997 subpst
->texthigh
= 0;
3999 subpst
->dependencies
= (struct partial_symtab
**)
4000 obstack_alloc (&objfile
->objfile_obstack
,
4001 sizeof (struct partial_symtab
*));
4002 subpst
->dependencies
[0] = pst
;
4003 subpst
->number_of_dependencies
= 1;
4005 subpst
->globals_offset
= 0;
4006 subpst
->n_global_syms
= 0;
4007 subpst
->statics_offset
= 0;
4008 subpst
->n_static_syms
= 0;
4009 subpst
->symtab
= NULL
;
4010 subpst
->read_symtab
= pst
->read_symtab
;
4013 /* No private part is necessary for include psymtabs. This property
4014 can be used to differentiate between such include psymtabs and
4015 the regular ones. */
4016 subpst
->read_symtab_private
= NULL
;
4019 /* Read the Line Number Program data and extract the list of files
4020 included by the source file represented by PST. Build an include
4021 partial symtab for each of these included files. */
4024 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4025 struct die_info
*die
,
4026 struct partial_symtab
*pst
)
4028 struct line_header
*lh
= NULL
;
4029 struct attribute
*attr
;
4031 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4033 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4035 return; /* No linetable, so no includes. */
4037 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4038 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
4040 free_line_header (lh
);
4044 hash_signatured_type (const void *item
)
4046 const struct signatured_type
*sig_type
= item
;
4048 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4049 return sig_type
->signature
;
4053 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4055 const struct signatured_type
*lhs
= item_lhs
;
4056 const struct signatured_type
*rhs
= item_rhs
;
4058 return lhs
->signature
== rhs
->signature
;
4061 /* Allocate a hash table for signatured types. */
4064 allocate_signatured_type_table (struct objfile
*objfile
)
4066 return htab_create_alloc_ex (41,
4067 hash_signatured_type
,
4070 &objfile
->objfile_obstack
,
4071 hashtab_obstack_allocate
,
4072 dummy_obstack_deallocate
);
4075 /* A helper function to add a signatured type CU to a table. */
4078 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4080 struct signatured_type
*sigt
= *slot
;
4081 struct signatured_type
***datap
= datum
;
4089 /* Create the hash table of all entries in the .debug_types section.
4090 DWO_FILE is a pointer to the DWO file for .debug_types.dwo,
4092 Note: This function processes DWO files only, not DWP files.
4093 The result is a pointer to the hash table or NULL if there are
4097 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4098 VEC (dwarf2_section_info_def
) *types
)
4100 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4101 htab_t types_htab
= NULL
;
4103 struct dwarf2_section_info
*section
;
4104 struct dwarf2_section_info
*abbrev_section
;
4106 if (VEC_empty (dwarf2_section_info_def
, types
))
4109 abbrev_section
= (dwo_file
!= NULL
4110 ? &dwo_file
->sections
.abbrev
4111 : &dwarf2_per_objfile
->abbrev
);
4113 if (dwarf2_read_debug
)
4114 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4115 dwo_file
? ".dwo" : "",
4116 bfd_get_filename (abbrev_section
->asection
->owner
));
4119 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4123 gdb_byte
*info_ptr
, *end_ptr
;
4124 struct dwarf2_section_info
*abbrev_section
;
4126 dwarf2_read_section (objfile
, section
);
4127 info_ptr
= section
->buffer
;
4129 if (info_ptr
== NULL
)
4132 /* We can't set abfd until now because the section may be empty or
4133 not present, in which case section->asection will be NULL. */
4134 abfd
= section
->asection
->owner
;
4137 abbrev_section
= &dwo_file
->sections
.abbrev
;
4139 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4141 if (types_htab
== NULL
)
4144 types_htab
= allocate_dwo_unit_table (objfile
);
4146 types_htab
= allocate_signatured_type_table (objfile
);
4149 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4150 because we don't need to read any dies: the signature is in the
4153 end_ptr
= info_ptr
+ section
->size
;
4154 while (info_ptr
< end_ptr
)
4157 cu_offset type_offset_in_tu
;
4159 struct signatured_type
*sig_type
;
4160 struct dwo_unit
*dwo_tu
;
4162 gdb_byte
*ptr
= info_ptr
;
4163 struct comp_unit_head header
;
4164 unsigned int length
;
4166 offset
.sect_off
= ptr
- section
->buffer
;
4168 /* We need to read the type's signature in order to build the hash
4169 table, but we don't need anything else just yet. */
4171 ptr
= read_and_check_type_unit_head (&header
, section
,
4172 abbrev_section
, ptr
,
4173 &signature
, &type_offset_in_tu
);
4175 length
= get_cu_length (&header
);
4177 /* Skip dummy type units. */
4178 if (ptr
>= info_ptr
+ length
4179 || peek_abbrev_code (abfd
, ptr
) == 0)
4188 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4190 dwo_tu
->dwo_file
= dwo_file
;
4191 dwo_tu
->signature
= signature
;
4192 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4193 dwo_tu
->info_or_types_section
= section
;
4194 dwo_tu
->offset
= offset
;
4195 dwo_tu
->length
= length
;
4199 /* N.B.: type_offset is not usable if this type uses a DWO file.
4200 The real type_offset is in the DWO file. */
4202 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4203 struct signatured_type
);
4204 sig_type
->signature
= signature
;
4205 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4206 sig_type
->per_cu
.objfile
= objfile
;
4207 sig_type
->per_cu
.is_debug_types
= 1;
4208 sig_type
->per_cu
.info_or_types_section
= section
;
4209 sig_type
->per_cu
.offset
= offset
;
4210 sig_type
->per_cu
.length
= length
;
4213 slot
= htab_find_slot (types_htab
,
4214 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4216 gdb_assert (slot
!= NULL
);
4219 sect_offset dup_offset
;
4223 const struct dwo_unit
*dup_tu
= *slot
;
4225 dup_offset
= dup_tu
->offset
;
4229 const struct signatured_type
*dup_tu
= *slot
;
4231 dup_offset
= dup_tu
->per_cu
.offset
;
4234 complaint (&symfile_complaints
,
4235 _("debug type entry at offset 0x%x is duplicate to the "
4236 "entry at offset 0x%x, signature 0x%s"),
4237 offset
.sect_off
, dup_offset
.sect_off
,
4238 phex (signature
, sizeof (signature
)));
4240 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4242 if (dwarf2_read_debug
)
4243 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
4245 phex (signature
, sizeof (signature
)));
4254 /* Create the hash table of all entries in the .debug_types section,
4255 and initialize all_type_units.
4256 The result is zero if there is an error (e.g. missing .debug_types section),
4257 otherwise non-zero. */
4260 create_all_type_units (struct objfile
*objfile
)
4263 struct signatured_type
**iter
;
4265 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4266 if (types_htab
== NULL
)
4268 dwarf2_per_objfile
->signatured_types
= NULL
;
4272 dwarf2_per_objfile
->signatured_types
= types_htab
;
4274 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4275 dwarf2_per_objfile
->all_type_units
4276 = obstack_alloc (&objfile
->objfile_obstack
,
4277 dwarf2_per_objfile
->n_type_units
4278 * sizeof (struct signatured_type
*));
4279 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4280 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4281 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4282 == dwarf2_per_objfile
->n_type_units
);
4287 /* Lookup a signature based type for DW_FORM_ref_sig8.
4288 Returns NULL if signature SIG is not present in the table. */
4290 static struct signatured_type
*
4291 lookup_signatured_type (ULONGEST sig
)
4293 struct signatured_type find_entry
, *entry
;
4295 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4297 complaint (&symfile_complaints
,
4298 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4302 find_entry
.signature
= sig
;
4303 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4307 /* Low level DIE reading support. */
4309 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4312 init_cu_die_reader (struct die_reader_specs
*reader
,
4313 struct dwarf2_cu
*cu
,
4314 struct dwarf2_section_info
*section
,
4315 struct dwo_file
*dwo_file
)
4317 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4318 reader
->abfd
= section
->asection
->owner
;
4320 reader
->dwo_file
= dwo_file
;
4321 reader
->die_section
= section
;
4322 reader
->buffer
= section
->buffer
;
4323 reader
->buffer_end
= section
->buffer
+ section
->size
;
4326 /* Initialize a CU (or TU) and read its DIEs.
4327 If the CU defers to a DWO file, read the DWO file as well.
4329 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4330 Otherwise the table specified in the comp unit header is read in and used.
4331 This is an optimization for when we already have the abbrev table.
4333 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4334 Otherwise, a new CU is allocated with xmalloc.
4336 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4337 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4339 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4340 linker) then DIE_READER_FUNC will not get called. */
4343 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4344 struct abbrev_table
*abbrev_table
,
4345 int use_existing_cu
, int keep
,
4346 die_reader_func_ftype
*die_reader_func
,
4349 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4350 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4351 bfd
*abfd
= section
->asection
->owner
;
4352 struct dwarf2_cu
*cu
;
4353 gdb_byte
*begin_info_ptr
, *info_ptr
;
4354 struct die_reader_specs reader
;
4355 struct die_info
*comp_unit_die
;
4357 struct attribute
*attr
;
4358 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4359 struct signatured_type
*sig_type
= NULL
;
4360 struct dwarf2_section_info
*abbrev_section
;
4361 /* Non-zero if CU currently points to a DWO file and we need to
4362 reread it. When this happens we need to reread the skeleton die
4363 before we can reread the DWO file. */
4364 int rereading_dwo_cu
= 0;
4366 if (dwarf2_die_debug
)
4367 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4368 this_cu
->is_debug_types
? "type" : "comp",
4369 this_cu
->offset
.sect_off
);
4371 if (use_existing_cu
)
4374 cleanups
= make_cleanup (null_cleanup
, NULL
);
4376 /* This is cheap if the section is already read in. */
4377 dwarf2_read_section (objfile
, section
);
4379 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4381 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
4383 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4387 /* If this CU is from a DWO file we need to start over, we need to
4388 refetch the attributes from the skeleton CU.
4389 This could be optimized by retrieving those attributes from when we
4390 were here the first time: the previous comp_unit_die was stored in
4391 comp_unit_obstack. But there's no data yet that we need this
4393 if (cu
->dwo_unit
!= NULL
)
4394 rereading_dwo_cu
= 1;
4398 /* If !use_existing_cu, this_cu->cu must be NULL. */
4399 gdb_assert (this_cu
->cu
== NULL
);
4401 cu
= xmalloc (sizeof (*cu
));
4402 init_one_comp_unit (cu
, this_cu
);
4404 /* If an error occurs while loading, release our storage. */
4405 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4408 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4410 /* We already have the header, there's no need to read it in again. */
4411 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4415 if (this_cu
->is_debug_types
)
4418 cu_offset type_offset_in_tu
;
4420 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4421 abbrev_section
, info_ptr
,
4423 &type_offset_in_tu
);
4425 /* Since per_cu is the first member of struct signatured_type,
4426 we can go from a pointer to one to a pointer to the other. */
4427 sig_type
= (struct signatured_type
*) this_cu
;
4428 gdb_assert (sig_type
->signature
== signature
);
4429 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4430 == type_offset_in_tu
.cu_off
);
4431 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4433 /* LENGTH has not been set yet for type units if we're
4434 using .gdb_index. */
4435 this_cu
->length
= get_cu_length (&cu
->header
);
4437 /* Establish the type offset that can be used to lookup the type. */
4438 sig_type
->type_offset_in_section
.sect_off
=
4439 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4443 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4447 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4448 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4452 /* Skip dummy compilation units. */
4453 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4454 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4456 do_cleanups (cleanups
);
4460 /* If we don't have them yet, read the abbrevs for this compilation unit.
4461 And if we need to read them now, make sure they're freed when we're
4462 done. Note that it's important that if the CU had an abbrev table
4463 on entry we don't free it when we're done: Somewhere up the call stack
4464 it may be in use. */
4465 if (abbrev_table
!= NULL
)
4467 gdb_assert (cu
->abbrev_table
== NULL
);
4468 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4469 == abbrev_table
->offset
.sect_off
);
4470 cu
->abbrev_table
= abbrev_table
;
4472 else if (cu
->abbrev_table
== NULL
)
4474 dwarf2_read_abbrevs (cu
, abbrev_section
);
4475 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4477 else if (rereading_dwo_cu
)
4479 dwarf2_free_abbrev_table (cu
);
4480 dwarf2_read_abbrevs (cu
, abbrev_section
);
4483 /* Read the top level CU/TU die. */
4484 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4485 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4487 /* If we have a DWO stub, process it and then read in the DWO file.
4488 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4489 a DWO CU, that this test will fail. */
4490 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4493 char *dwo_name
= DW_STRING (attr
);
4494 const char *comp_dir_string
;
4495 struct dwo_unit
*dwo_unit
;
4496 ULONGEST signature
; /* Or dwo_id. */
4497 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4498 int i
,num_extra_attrs
;
4499 struct dwarf2_section_info
*dwo_abbrev_section
;
4502 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4503 " has children (offset 0x%x) [in module %s]"),
4504 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4506 /* These attributes aren't processed until later:
4507 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4508 However, the attribute is found in the stub which we won't have later.
4509 In order to not impose this complication on the rest of the code,
4510 we read them here and copy them to the DWO CU/TU die. */
4512 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4515 if (! this_cu
->is_debug_types
)
4516 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4517 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4518 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4519 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4520 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4522 /* There should be a DW_AT_addr_base attribute here (if needed).
4523 We need the value before we can process DW_FORM_GNU_addr_index. */
4525 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4527 cu
->addr_base
= DW_UNSND (attr
);
4529 /* There should be a DW_AT_ranges_base attribute here (if needed).
4530 We need the value before we can process DW_AT_ranges. */
4531 cu
->ranges_base
= 0;
4532 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4534 cu
->ranges_base
= DW_UNSND (attr
);
4536 if (this_cu
->is_debug_types
)
4538 gdb_assert (sig_type
!= NULL
);
4539 signature
= sig_type
->signature
;
4543 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4545 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4547 signature
= DW_UNSND (attr
);
4550 /* We may need the comp_dir in order to find the DWO file. */
4551 comp_dir_string
= NULL
;
4553 comp_dir_string
= DW_STRING (comp_dir
);
4555 if (this_cu
->is_debug_types
)
4556 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4558 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4561 if (dwo_unit
== NULL
)
4563 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4564 " with ID %s [in module %s]"),
4565 this_cu
->offset
.sect_off
,
4566 phex (signature
, sizeof (signature
)),
4570 /* Set up for reading the DWO CU/TU. */
4571 cu
->dwo_unit
= dwo_unit
;
4572 section
= dwo_unit
->info_or_types_section
;
4573 dwarf2_read_section (objfile
, section
);
4574 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4575 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4576 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4578 if (this_cu
->is_debug_types
)
4581 cu_offset type_offset_in_tu
;
4583 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4587 &type_offset_in_tu
);
4588 gdb_assert (sig_type
->signature
== signature
);
4589 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4590 /* For DWOs coming from DWP files, we don't know the CU length
4591 nor the type's offset in the TU until now. */
4592 dwo_unit
->length
= get_cu_length (&cu
->header
);
4593 dwo_unit
->type_offset_in_tu
= type_offset_in_tu
;
4595 /* Establish the type offset that can be used to lookup the type.
4596 For DWO files, we don't know it until now. */
4597 sig_type
->type_offset_in_section
.sect_off
=
4598 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4602 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4605 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4606 /* For DWOs coming from DWP files, we don't know the CU length
4608 dwo_unit
->length
= get_cu_length (&cu
->header
);
4611 /* Discard the original CU's abbrev table, and read the DWO's. */
4612 if (abbrev_table
== NULL
)
4614 dwarf2_free_abbrev_table (cu
);
4615 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4619 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4620 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4623 /* Read in the die, but leave space to copy over the attributes
4624 from the stub. This has the benefit of simplifying the rest of
4625 the code - all the real work is done here. */
4626 num_extra_attrs
= ((stmt_list
!= NULL
)
4630 + (comp_dir
!= NULL
));
4631 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4632 &has_children
, num_extra_attrs
);
4634 /* Copy over the attributes from the stub to the DWO die. */
4635 i
= comp_unit_die
->num_attrs
;
4636 if (stmt_list
!= NULL
)
4637 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4639 comp_unit_die
->attrs
[i
++] = *low_pc
;
4640 if (high_pc
!= NULL
)
4641 comp_unit_die
->attrs
[i
++] = *high_pc
;
4643 comp_unit_die
->attrs
[i
++] = *ranges
;
4644 if (comp_dir
!= NULL
)
4645 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4646 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4648 /* Skip dummy compilation units. */
4649 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4650 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4652 do_cleanups (cleanups
);
4657 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4659 if (free_cu_cleanup
!= NULL
)
4663 /* We've successfully allocated this compilation unit. Let our
4664 caller clean it up when finished with it. */
4665 discard_cleanups (free_cu_cleanup
);
4667 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4668 So we have to manually free the abbrev table. */
4669 dwarf2_free_abbrev_table (cu
);
4671 /* Link this CU into read_in_chain. */
4672 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4673 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4676 do_cleanups (free_cu_cleanup
);
4679 do_cleanups (cleanups
);
4682 /* Read CU/TU THIS_CU in section SECTION,
4683 but do not follow DW_AT_GNU_dwo_name if present.
4684 DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed
4685 to have already done the lookup to find the DWO/DWP file).
4687 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4688 THIS_CU->is_debug_types, but nothing else.
4690 We fill in THIS_CU->length.
4692 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4693 linker) then DIE_READER_FUNC will not get called.
4695 THIS_CU->cu is always freed when done.
4696 This is done in order to not leave THIS_CU->cu in a state where we have
4697 to care whether it refers to the "main" CU or the DWO CU. */
4700 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4701 struct dwarf2_section_info
*abbrev_section
,
4702 struct dwo_file
*dwo_file
,
4703 die_reader_func_ftype
*die_reader_func
,
4706 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4707 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4708 bfd
*abfd
= section
->asection
->owner
;
4709 struct dwarf2_cu cu
;
4710 gdb_byte
*begin_info_ptr
, *info_ptr
;
4711 struct die_reader_specs reader
;
4712 struct cleanup
*cleanups
;
4713 struct die_info
*comp_unit_die
;
4716 if (dwarf2_die_debug
)
4717 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4718 this_cu
->is_debug_types
? "type" : "comp",
4719 this_cu
->offset
.sect_off
);
4721 gdb_assert (this_cu
->cu
== NULL
);
4723 /* This is cheap if the section is already read in. */
4724 dwarf2_read_section (objfile
, section
);
4726 init_one_comp_unit (&cu
, this_cu
);
4728 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4730 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4731 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4732 abbrev_section
, info_ptr
,
4733 this_cu
->is_debug_types
);
4735 this_cu
->length
= get_cu_length (&cu
.header
);
4737 /* Skip dummy compilation units. */
4738 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4739 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4741 do_cleanups (cleanups
);
4745 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4746 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4748 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4749 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4751 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4753 do_cleanups (cleanups
);
4756 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4757 does not lookup the specified DWO file.
4758 This cannot be used to read DWO files.
4760 THIS_CU->cu is always freed when done.
4761 This is done in order to not leave THIS_CU->cu in a state where we have
4762 to care whether it refers to the "main" CU or the DWO CU.
4763 We can revisit this if the data shows there's a performance issue. */
4766 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4767 die_reader_func_ftype
*die_reader_func
,
4770 init_cutu_and_read_dies_no_follow (this_cu
,
4771 get_abbrev_section_for_cu (this_cu
),
4773 die_reader_func
, data
);
4776 /* Create a psymtab named NAME and assign it to PER_CU.
4778 The caller must fill in the following details:
4779 dirname, textlow, texthigh. */
4781 static struct partial_symtab
*
4782 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4784 struct objfile
*objfile
= per_cu
->objfile
;
4785 struct partial_symtab
*pst
;
4787 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4789 objfile
->global_psymbols
.next
,
4790 objfile
->static_psymbols
.next
);
4792 pst
->psymtabs_addrmap_supported
= 1;
4794 /* This is the glue that links PST into GDB's symbol API. */
4795 pst
->read_symtab_private
= per_cu
;
4796 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4797 per_cu
->v
.psymtab
= pst
;
4802 /* die_reader_func for process_psymtab_comp_unit. */
4805 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4807 struct die_info
*comp_unit_die
,
4811 struct dwarf2_cu
*cu
= reader
->cu
;
4812 struct objfile
*objfile
= cu
->objfile
;
4813 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4814 struct attribute
*attr
;
4816 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4817 struct partial_symtab
*pst
;
4819 const char *filename
;
4820 int *want_partial_unit_ptr
= data
;
4822 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4823 && (want_partial_unit_ptr
== NULL
4824 || !*want_partial_unit_ptr
))
4827 gdb_assert (! per_cu
->is_debug_types
);
4829 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4831 cu
->list_in_scope
= &file_symbols
;
4833 /* Allocate a new partial symbol table structure. */
4834 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4835 if (attr
== NULL
|| !DW_STRING (attr
))
4838 filename
= DW_STRING (attr
);
4840 pst
= create_partial_symtab (per_cu
, filename
);
4842 /* This must be done before calling dwarf2_build_include_psymtabs. */
4843 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4845 pst
->dirname
= DW_STRING (attr
);
4847 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4849 dwarf2_find_base_address (comp_unit_die
, cu
);
4851 /* Possibly set the default values of LOWPC and HIGHPC from
4853 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4854 &best_highpc
, cu
, pst
);
4855 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4856 /* Store the contiguous range if it is not empty; it can be empty for
4857 CUs with no code. */
4858 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4859 best_lowpc
+ baseaddr
,
4860 best_highpc
+ baseaddr
- 1, pst
);
4862 /* Check if comp unit has_children.
4863 If so, read the rest of the partial symbols from this comp unit.
4864 If not, there's no more debug_info for this comp unit. */
4867 struct partial_die_info
*first_die
;
4868 CORE_ADDR lowpc
, highpc
;
4870 lowpc
= ((CORE_ADDR
) -1);
4871 highpc
= ((CORE_ADDR
) 0);
4873 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4875 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4878 /* If we didn't find a lowpc, set it to highpc to avoid
4879 complaints from `maint check'. */
4880 if (lowpc
== ((CORE_ADDR
) -1))
4883 /* If the compilation unit didn't have an explicit address range,
4884 then use the information extracted from its child dies. */
4888 best_highpc
= highpc
;
4891 pst
->textlow
= best_lowpc
+ baseaddr
;
4892 pst
->texthigh
= best_highpc
+ baseaddr
;
4894 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4895 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4896 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4897 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4898 sort_pst_symbols (pst
);
4900 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
))
4903 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4904 struct dwarf2_per_cu_data
*iter
;
4906 /* Fill in 'dependencies' here; we fill in 'users' in a
4908 pst
->number_of_dependencies
= len
;
4909 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4910 len
* sizeof (struct symtab
*));
4912 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
4915 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4917 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4920 /* Get the list of files included in the current compilation unit,
4921 and build a psymtab for each of them. */
4922 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4924 if (dwarf2_read_debug
)
4926 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4928 fprintf_unfiltered (gdb_stdlog
,
4929 "Psymtab for %s unit @0x%x: %s - %s"
4930 ", %d global, %d static syms\n",
4931 per_cu
->is_debug_types
? "type" : "comp",
4932 per_cu
->offset
.sect_off
,
4933 paddress (gdbarch
, pst
->textlow
),
4934 paddress (gdbarch
, pst
->texthigh
),
4935 pst
->n_global_syms
, pst
->n_static_syms
);
4939 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4940 Process compilation unit THIS_CU for a psymtab. */
4943 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4944 int want_partial_unit
)
4946 /* If this compilation unit was already read in, free the
4947 cached copy in order to read it in again. This is
4948 necessary because we skipped some symbols when we first
4949 read in the compilation unit (see load_partial_dies).
4950 This problem could be avoided, but the benefit is unclear. */
4951 if (this_cu
->cu
!= NULL
)
4952 free_one_cached_comp_unit (this_cu
);
4954 gdb_assert (! this_cu
->is_debug_types
);
4955 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
4956 process_psymtab_comp_unit_reader
,
4957 &want_partial_unit
);
4959 /* Age out any secondary CUs. */
4960 age_cached_comp_units ();
4964 hash_type_unit_group (const void *item
)
4966 const struct type_unit_group
*tu_group
= item
;
4968 return hash_stmt_list_entry (&tu_group
->hash
);
4972 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
4974 const struct type_unit_group
*lhs
= item_lhs
;
4975 const struct type_unit_group
*rhs
= item_rhs
;
4977 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
4980 /* Allocate a hash table for type unit groups. */
4983 allocate_type_unit_groups_table (void)
4985 return htab_create_alloc_ex (3,
4986 hash_type_unit_group
,
4989 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
4990 hashtab_obstack_allocate
,
4991 dummy_obstack_deallocate
);
4994 /* Type units that don't have DW_AT_stmt_list are grouped into their own
4995 partial symtabs. We combine several TUs per psymtab to not let the size
4996 of any one psymtab grow too big. */
4997 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
4998 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5000 /* Helper routine for get_type_unit_group.
5001 Create the type_unit_group object used to hold one or more TUs. */
5003 static struct type_unit_group
*
5004 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5006 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5007 struct dwarf2_per_cu_data
*per_cu
;
5008 struct type_unit_group
*tu_group
;
5010 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5011 struct type_unit_group
);
5012 per_cu
= &tu_group
->per_cu
;
5013 per_cu
->objfile
= objfile
;
5014 per_cu
->is_debug_types
= 1;
5015 per_cu
->s
.type_unit_group
= tu_group
;
5017 if (dwarf2_per_objfile
->using_index
)
5019 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5020 struct dwarf2_per_cu_quick_data
);
5021 tu_group
->t
.first_tu
= cu
->per_cu
;
5025 unsigned int line_offset
= line_offset_struct
.sect_off
;
5026 struct partial_symtab
*pst
;
5029 /* Give the symtab a useful name for debug purposes. */
5030 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5031 name
= xstrprintf ("<type_units_%d>",
5032 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5034 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5036 pst
= create_partial_symtab (per_cu
, name
);
5042 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5043 tu_group
->hash
.line_offset
= line_offset_struct
;
5048 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5049 STMT_LIST is a DW_AT_stmt_list attribute. */
5051 static struct type_unit_group
*
5052 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
5054 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5055 struct type_unit_group
*tu_group
;
5057 unsigned int line_offset
;
5058 struct type_unit_group type_unit_group_for_lookup
;
5060 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5062 dwarf2_per_objfile
->type_unit_groups
=
5063 allocate_type_unit_groups_table ();
5066 /* Do we need to create a new group, or can we use an existing one? */
5070 line_offset
= DW_UNSND (stmt_list
);
5071 ++tu_stats
->nr_symtab_sharers
;
5075 /* Ugh, no stmt_list. Rare, but we have to handle it.
5076 We can do various things here like create one group per TU or
5077 spread them over multiple groups to split up the expansion work.
5078 To avoid worst case scenarios (too many groups or too large groups)
5079 we, umm, group them in bunches. */
5080 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5081 | (tu_stats
->nr_stmt_less_type_units
5082 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5083 ++tu_stats
->nr_stmt_less_type_units
;
5086 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5087 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5088 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5089 &type_unit_group_for_lookup
, INSERT
);
5093 gdb_assert (tu_group
!= NULL
);
5097 sect_offset line_offset_struct
;
5099 line_offset_struct
.sect_off
= line_offset
;
5100 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5102 ++tu_stats
->nr_symtabs
;
5108 /* Struct used to sort TUs by their abbreviation table offset. */
5110 struct tu_abbrev_offset
5112 struct signatured_type
*sig_type
;
5113 sect_offset abbrev_offset
;
5116 /* Helper routine for build_type_unit_groups, passed to qsort. */
5119 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
5121 const struct tu_abbrev_offset
* const *a
= ap
;
5122 const struct tu_abbrev_offset
* const *b
= bp
;
5123 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
5124 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
5126 return (aoff
> boff
) - (aoff
< boff
);
5129 /* A helper function to add a type_unit_group to a table. */
5132 add_type_unit_group_to_table (void **slot
, void *datum
)
5134 struct type_unit_group
*tu_group
= *slot
;
5135 struct type_unit_group
***datap
= datum
;
5143 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5144 each one passing FUNC,DATA.
5146 The efficiency is because we sort TUs by the abbrev table they use and
5147 only read each abbrev table once. In one program there are 200K TUs
5148 sharing 8K abbrev tables.
5150 The main purpose of this function is to support building the
5151 dwarf2_per_objfile->type_unit_groups table.
5152 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5153 can collapse the search space by grouping them by stmt_list.
5154 The savings can be significant, in the same program from above the 200K TUs
5155 share 8K stmt_list tables.
5157 FUNC is expected to call get_type_unit_group, which will create the
5158 struct type_unit_group if necessary and add it to
5159 dwarf2_per_objfile->type_unit_groups. */
5162 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
5164 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5165 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5166 struct cleanup
*cleanups
;
5167 struct abbrev_table
*abbrev_table
;
5168 sect_offset abbrev_offset
;
5169 struct tu_abbrev_offset
*sorted_by_abbrev
;
5170 struct type_unit_group
**iter
;
5173 /* It's up to the caller to not call us multiple times. */
5174 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
5176 if (dwarf2_per_objfile
->n_type_units
== 0)
5179 /* TUs typically share abbrev tables, and there can be way more TUs than
5180 abbrev tables. Sort by abbrev table to reduce the number of times we
5181 read each abbrev table in.
5182 Alternatives are to punt or to maintain a cache of abbrev tables.
5183 This is simpler and efficient enough for now.
5185 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5186 symtab to use). Typically TUs with the same abbrev offset have the same
5187 stmt_list value too so in practice this should work well.
5189 The basic algorithm here is:
5191 sort TUs by abbrev table
5192 for each TU with same abbrev table:
5193 read abbrev table if first user
5194 read TU top level DIE
5195 [IWBN if DWO skeletons had DW_AT_stmt_list]
5198 if (dwarf2_read_debug
)
5199 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5201 /* Sort in a separate table to maintain the order of all_type_units
5202 for .gdb_index: TU indices directly index all_type_units. */
5203 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5204 dwarf2_per_objfile
->n_type_units
);
5205 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5207 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5209 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5210 sorted_by_abbrev
[i
].abbrev_offset
=
5211 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
5212 sig_type
->per_cu
.offset
);
5214 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5215 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5216 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5218 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5219 called any number of times, so we don't reset tu_stats here. */
5221 abbrev_offset
.sect_off
= ~(unsigned) 0;
5222 abbrev_table
= NULL
;
5223 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5225 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5227 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5229 /* Switch to the next abbrev table if necessary. */
5230 if (abbrev_table
== NULL
5231 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5233 if (abbrev_table
!= NULL
)
5235 abbrev_table_free (abbrev_table
);
5236 /* Reset to NULL in case abbrev_table_read_table throws
5237 an error: abbrev_table_free_cleanup will get called. */
5238 abbrev_table
= NULL
;
5240 abbrev_offset
= tu
->abbrev_offset
;
5242 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5244 ++tu_stats
->nr_uniq_abbrev_tables
;
5247 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5251 /* Create a vector of pointers to primary type units to make it easy to
5252 iterate over them and CUs. See dw2_get_primary_cu. */
5253 dwarf2_per_objfile
->n_type_unit_groups
=
5254 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5255 dwarf2_per_objfile
->all_type_unit_groups
=
5256 obstack_alloc (&objfile
->objfile_obstack
,
5257 dwarf2_per_objfile
->n_type_unit_groups
5258 * sizeof (struct type_unit_group
*));
5259 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5260 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5261 add_type_unit_group_to_table
, &iter
);
5262 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5263 == dwarf2_per_objfile
->n_type_unit_groups
);
5265 do_cleanups (cleanups
);
5267 if (dwarf2_read_debug
)
5269 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5270 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5271 dwarf2_per_objfile
->n_type_units
);
5272 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5273 tu_stats
->nr_uniq_abbrev_tables
);
5274 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5275 tu_stats
->nr_symtabs
);
5276 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5277 tu_stats
->nr_symtab_sharers
);
5278 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5279 tu_stats
->nr_stmt_less_type_units
);
5283 /* Reader function for build_type_psymtabs. */
5286 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5288 struct die_info
*type_unit_die
,
5292 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5293 struct dwarf2_cu
*cu
= reader
->cu
;
5294 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5295 struct type_unit_group
*tu_group
;
5296 struct attribute
*attr
;
5297 struct partial_die_info
*first_die
;
5298 CORE_ADDR lowpc
, highpc
;
5299 struct partial_symtab
*pst
;
5301 gdb_assert (data
== NULL
);
5306 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5307 tu_group
= get_type_unit_group (cu
, attr
);
5309 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, per_cu
);
5311 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5312 cu
->list_in_scope
= &file_symbols
;
5313 pst
= create_partial_symtab (per_cu
, "");
5316 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5318 lowpc
= (CORE_ADDR
) -1;
5319 highpc
= (CORE_ADDR
) 0;
5320 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5322 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5323 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5324 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5325 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5326 sort_pst_symbols (pst
);
5329 /* Traversal function for build_type_psymtabs. */
5332 build_type_psymtab_dependencies (void **slot
, void *info
)
5334 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5335 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5336 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5337 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5338 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5339 struct dwarf2_per_cu_data
*iter
;
5342 gdb_assert (len
> 0);
5344 pst
->number_of_dependencies
= len
;
5345 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5346 len
* sizeof (struct psymtab
*));
5348 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, i
, iter
);
5351 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5352 iter
->s
.type_unit_group
= tu_group
;
5355 VEC_free (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5360 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5361 Build partial symbol tables for the .debug_types comp-units. */
5364 build_type_psymtabs (struct objfile
*objfile
)
5366 if (! create_all_type_units (objfile
))
5369 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5371 /* Now that all TUs have been processed we can fill in the dependencies. */
5372 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5373 build_type_psymtab_dependencies
, NULL
);
5376 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5379 psymtabs_addrmap_cleanup (void *o
)
5381 struct objfile
*objfile
= o
;
5383 objfile
->psymtabs_addrmap
= NULL
;
5386 /* Compute the 'user' field for each psymtab in OBJFILE. */
5389 set_partial_user (struct objfile
*objfile
)
5393 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5395 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5396 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5402 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5404 /* Set the 'user' field only if it is not already set. */
5405 if (pst
->dependencies
[j
]->user
== NULL
)
5406 pst
->dependencies
[j
]->user
= pst
;
5411 /* Build the partial symbol table by doing a quick pass through the
5412 .debug_info and .debug_abbrev sections. */
5415 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5417 struct cleanup
*back_to
, *addrmap_cleanup
;
5418 struct obstack temp_obstack
;
5421 if (dwarf2_read_debug
)
5423 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5427 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5429 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5431 /* Any cached compilation units will be linked by the per-objfile
5432 read_in_chain. Make sure to free them when we're done. */
5433 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5435 build_type_psymtabs (objfile
);
5437 create_all_comp_units (objfile
);
5439 /* Create a temporary address map on a temporary obstack. We later
5440 copy this to the final obstack. */
5441 obstack_init (&temp_obstack
);
5442 make_cleanup_obstack_free (&temp_obstack
);
5443 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5444 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5446 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5448 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5450 process_psymtab_comp_unit (per_cu
, 0);
5453 set_partial_user (objfile
);
5455 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5456 &objfile
->objfile_obstack
);
5457 discard_cleanups (addrmap_cleanup
);
5459 do_cleanups (back_to
);
5461 if (dwarf2_read_debug
)
5462 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5466 /* die_reader_func for load_partial_comp_unit. */
5469 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5471 struct die_info
*comp_unit_die
,
5475 struct dwarf2_cu
*cu
= reader
->cu
;
5477 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5479 /* Check if comp unit has_children.
5480 If so, read the rest of the partial symbols from this comp unit.
5481 If not, there's no more debug_info for this comp unit. */
5483 load_partial_dies (reader
, info_ptr
, 0);
5486 /* Load the partial DIEs for a secondary CU into memory.
5487 This is also used when rereading a primary CU with load_all_dies. */
5490 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5492 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5493 load_partial_comp_unit_reader
, NULL
);
5497 read_comp_units_from_section (struct objfile
*objfile
,
5498 struct dwarf2_section_info
*section
,
5499 unsigned int is_dwz
,
5502 struct dwarf2_per_cu_data
***all_comp_units
)
5505 bfd
*abfd
= section
->asection
->owner
;
5507 dwarf2_read_section (objfile
, section
);
5509 info_ptr
= section
->buffer
;
5511 while (info_ptr
< section
->buffer
+ section
->size
)
5513 unsigned int length
, initial_length_size
;
5514 struct dwarf2_per_cu_data
*this_cu
;
5517 offset
.sect_off
= info_ptr
- section
->buffer
;
5519 /* Read just enough information to find out where the next
5520 compilation unit is. */
5521 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5523 /* Save the compilation unit for later lookup. */
5524 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5525 sizeof (struct dwarf2_per_cu_data
));
5526 memset (this_cu
, 0, sizeof (*this_cu
));
5527 this_cu
->offset
= offset
;
5528 this_cu
->length
= length
+ initial_length_size
;
5529 this_cu
->is_dwz
= is_dwz
;
5530 this_cu
->objfile
= objfile
;
5531 this_cu
->info_or_types_section
= section
;
5533 if (*n_comp_units
== *n_allocated
)
5536 *all_comp_units
= xrealloc (*all_comp_units
,
5538 * sizeof (struct dwarf2_per_cu_data
*));
5540 (*all_comp_units
)[*n_comp_units
] = this_cu
;
5543 info_ptr
= info_ptr
+ this_cu
->length
;
5547 /* Create a list of all compilation units in OBJFILE.
5548 This is only done for -readnow and building partial symtabs. */
5551 create_all_comp_units (struct objfile
*objfile
)
5555 struct dwarf2_per_cu_data
**all_comp_units
;
5559 all_comp_units
= xmalloc (n_allocated
5560 * sizeof (struct dwarf2_per_cu_data
*));
5562 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
5563 &n_allocated
, &n_comp_units
, &all_comp_units
);
5565 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
5567 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
5569 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
5570 &n_allocated
, &n_comp_units
,
5574 dwarf2_per_objfile
->all_comp_units
5575 = obstack_alloc (&objfile
->objfile_obstack
,
5576 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5577 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5578 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5579 xfree (all_comp_units
);
5580 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5583 /* Process all loaded DIEs for compilation unit CU, starting at
5584 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5585 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5586 DW_AT_ranges). If NEED_PC is set, then this function will set
5587 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5588 and record the covered ranges in the addrmap. */
5591 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5592 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5594 struct partial_die_info
*pdi
;
5596 /* Now, march along the PDI's, descending into ones which have
5597 interesting children but skipping the children of the other ones,
5598 until we reach the end of the compilation unit. */
5604 fixup_partial_die (pdi
, cu
);
5606 /* Anonymous namespaces or modules have no name but have interesting
5607 children, so we need to look at them. Ditto for anonymous
5610 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5611 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5612 || pdi
->tag
== DW_TAG_imported_unit
)
5616 case DW_TAG_subprogram
:
5617 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5619 case DW_TAG_constant
:
5620 case DW_TAG_variable
:
5621 case DW_TAG_typedef
:
5622 case DW_TAG_union_type
:
5623 if (!pdi
->is_declaration
)
5625 add_partial_symbol (pdi
, cu
);
5628 case DW_TAG_class_type
:
5629 case DW_TAG_interface_type
:
5630 case DW_TAG_structure_type
:
5631 if (!pdi
->is_declaration
)
5633 add_partial_symbol (pdi
, cu
);
5636 case DW_TAG_enumeration_type
:
5637 if (!pdi
->is_declaration
)
5638 add_partial_enumeration (pdi
, cu
);
5640 case DW_TAG_base_type
:
5641 case DW_TAG_subrange_type
:
5642 /* File scope base type definitions are added to the partial
5644 add_partial_symbol (pdi
, cu
);
5646 case DW_TAG_namespace
:
5647 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5650 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5652 case DW_TAG_imported_unit
:
5654 struct dwarf2_per_cu_data
*per_cu
;
5656 /* For now we don't handle imported units in type units. */
5657 if (cu
->per_cu
->is_debug_types
)
5659 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5660 " supported in type units [in module %s]"),
5664 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5668 /* Go read the partial unit, if needed. */
5669 if (per_cu
->v
.psymtab
== NULL
)
5670 process_psymtab_comp_unit (per_cu
, 1);
5672 VEC_safe_push (dwarf2_per_cu_ptr
,
5673 cu
->per_cu
->s
.imported_symtabs
, per_cu
);
5681 /* If the die has a sibling, skip to the sibling. */
5683 pdi
= pdi
->die_sibling
;
5687 /* Functions used to compute the fully scoped name of a partial DIE.
5689 Normally, this is simple. For C++, the parent DIE's fully scoped
5690 name is concatenated with "::" and the partial DIE's name. For
5691 Java, the same thing occurs except that "." is used instead of "::".
5692 Enumerators are an exception; they use the scope of their parent
5693 enumeration type, i.e. the name of the enumeration type is not
5694 prepended to the enumerator.
5696 There are two complexities. One is DW_AT_specification; in this
5697 case "parent" means the parent of the target of the specification,
5698 instead of the direct parent of the DIE. The other is compilers
5699 which do not emit DW_TAG_namespace; in this case we try to guess
5700 the fully qualified name of structure types from their members'
5701 linkage names. This must be done using the DIE's children rather
5702 than the children of any DW_AT_specification target. We only need
5703 to do this for structures at the top level, i.e. if the target of
5704 any DW_AT_specification (if any; otherwise the DIE itself) does not
5707 /* Compute the scope prefix associated with PDI's parent, in
5708 compilation unit CU. The result will be allocated on CU's
5709 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5710 field. NULL is returned if no prefix is necessary. */
5712 partial_die_parent_scope (struct partial_die_info
*pdi
,
5713 struct dwarf2_cu
*cu
)
5715 char *grandparent_scope
;
5716 struct partial_die_info
*parent
, *real_pdi
;
5718 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5719 then this means the parent of the specification DIE. */
5722 while (real_pdi
->has_specification
)
5723 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
5724 real_pdi
->spec_is_dwz
, cu
);
5726 parent
= real_pdi
->die_parent
;
5730 if (parent
->scope_set
)
5731 return parent
->scope
;
5733 fixup_partial_die (parent
, cu
);
5735 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5737 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5738 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5739 Work around this problem here. */
5740 if (cu
->language
== language_cplus
5741 && parent
->tag
== DW_TAG_namespace
5742 && strcmp (parent
->name
, "::") == 0
5743 && grandparent_scope
== NULL
)
5745 parent
->scope
= NULL
;
5746 parent
->scope_set
= 1;
5750 if (pdi
->tag
== DW_TAG_enumerator
)
5751 /* Enumerators should not get the name of the enumeration as a prefix. */
5752 parent
->scope
= grandparent_scope
;
5753 else if (parent
->tag
== DW_TAG_namespace
5754 || parent
->tag
== DW_TAG_module
5755 || parent
->tag
== DW_TAG_structure_type
5756 || parent
->tag
== DW_TAG_class_type
5757 || parent
->tag
== DW_TAG_interface_type
5758 || parent
->tag
== DW_TAG_union_type
5759 || parent
->tag
== DW_TAG_enumeration_type
)
5761 if (grandparent_scope
== NULL
)
5762 parent
->scope
= parent
->name
;
5764 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5766 parent
->name
, 0, cu
);
5770 /* FIXME drow/2004-04-01: What should we be doing with
5771 function-local names? For partial symbols, we should probably be
5773 complaint (&symfile_complaints
,
5774 _("unhandled containing DIE tag %d for DIE at %d"),
5775 parent
->tag
, pdi
->offset
.sect_off
);
5776 parent
->scope
= grandparent_scope
;
5779 parent
->scope_set
= 1;
5780 return parent
->scope
;
5783 /* Return the fully scoped name associated with PDI, from compilation unit
5784 CU. The result will be allocated with malloc. */
5787 partial_die_full_name (struct partial_die_info
*pdi
,
5788 struct dwarf2_cu
*cu
)
5792 /* If this is a template instantiation, we can not work out the
5793 template arguments from partial DIEs. So, unfortunately, we have
5794 to go through the full DIEs. At least any work we do building
5795 types here will be reused if full symbols are loaded later. */
5796 if (pdi
->has_template_arguments
)
5798 fixup_partial_die (pdi
, cu
);
5800 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5802 struct die_info
*die
;
5803 struct attribute attr
;
5804 struct dwarf2_cu
*ref_cu
= cu
;
5806 /* DW_FORM_ref_addr is using section offset. */
5808 attr
.form
= DW_FORM_ref_addr
;
5809 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5810 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5812 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5816 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5817 if (parent_scope
== NULL
)
5820 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5824 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5826 struct objfile
*objfile
= cu
->objfile
;
5828 char *actual_name
= NULL
;
5830 int built_actual_name
= 0;
5832 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5834 actual_name
= partial_die_full_name (pdi
, cu
);
5836 built_actual_name
= 1;
5838 if (actual_name
== NULL
)
5839 actual_name
= pdi
->name
;
5843 case DW_TAG_subprogram
:
5844 if (pdi
->is_external
|| cu
->language
== language_ada
)
5846 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5847 of the global scope. But in Ada, we want to be able to access
5848 nested procedures globally. So all Ada subprograms are stored
5849 in the global scope. */
5850 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5851 mst_text, objfile); */
5852 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5854 VAR_DOMAIN
, LOC_BLOCK
,
5855 &objfile
->global_psymbols
,
5856 0, pdi
->lowpc
+ baseaddr
,
5857 cu
->language
, objfile
);
5861 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5862 mst_file_text, objfile); */
5863 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5865 VAR_DOMAIN
, LOC_BLOCK
,
5866 &objfile
->static_psymbols
,
5867 0, pdi
->lowpc
+ baseaddr
,
5868 cu
->language
, objfile
);
5871 case DW_TAG_constant
:
5873 struct psymbol_allocation_list
*list
;
5875 if (pdi
->is_external
)
5876 list
= &objfile
->global_psymbols
;
5878 list
= &objfile
->static_psymbols
;
5879 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5880 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
5881 list
, 0, 0, cu
->language
, objfile
);
5884 case DW_TAG_variable
:
5886 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5890 && !dwarf2_per_objfile
->has_section_at_zero
)
5892 /* A global or static variable may also have been stripped
5893 out by the linker if unused, in which case its address
5894 will be nullified; do not add such variables into partial
5895 symbol table then. */
5897 else if (pdi
->is_external
)
5900 Don't enter into the minimal symbol tables as there is
5901 a minimal symbol table entry from the ELF symbols already.
5902 Enter into partial symbol table if it has a location
5903 descriptor or a type.
5904 If the location descriptor is missing, new_symbol will create
5905 a LOC_UNRESOLVED symbol, the address of the variable will then
5906 be determined from the minimal symbol table whenever the variable
5908 The address for the partial symbol table entry is not
5909 used by GDB, but it comes in handy for debugging partial symbol
5912 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5913 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5915 VAR_DOMAIN
, LOC_STATIC
,
5916 &objfile
->global_psymbols
,
5918 cu
->language
, objfile
);
5922 /* Static Variable. Skip symbols without location descriptors. */
5923 if (pdi
->d
.locdesc
== NULL
)
5925 if (built_actual_name
)
5926 xfree (actual_name
);
5929 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
5930 mst_file_data, objfile); */
5931 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5933 VAR_DOMAIN
, LOC_STATIC
,
5934 &objfile
->static_psymbols
,
5936 cu
->language
, objfile
);
5939 case DW_TAG_typedef
:
5940 case DW_TAG_base_type
:
5941 case DW_TAG_subrange_type
:
5942 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5944 VAR_DOMAIN
, LOC_TYPEDEF
,
5945 &objfile
->static_psymbols
,
5946 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5948 case DW_TAG_namespace
:
5949 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5951 VAR_DOMAIN
, LOC_TYPEDEF
,
5952 &objfile
->global_psymbols
,
5953 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5955 case DW_TAG_class_type
:
5956 case DW_TAG_interface_type
:
5957 case DW_TAG_structure_type
:
5958 case DW_TAG_union_type
:
5959 case DW_TAG_enumeration_type
:
5960 /* Skip external references. The DWARF standard says in the section
5961 about "Structure, Union, and Class Type Entries": "An incomplete
5962 structure, union or class type is represented by a structure,
5963 union or class entry that does not have a byte size attribute
5964 and that has a DW_AT_declaration attribute." */
5965 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
5967 if (built_actual_name
)
5968 xfree (actual_name
);
5972 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5973 static vs. global. */
5974 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5976 STRUCT_DOMAIN
, LOC_TYPEDEF
,
5977 (cu
->language
== language_cplus
5978 || cu
->language
== language_java
)
5979 ? &objfile
->global_psymbols
5980 : &objfile
->static_psymbols
,
5981 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5984 case DW_TAG_enumerator
:
5985 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5987 VAR_DOMAIN
, LOC_CONST
,
5988 (cu
->language
== language_cplus
5989 || cu
->language
== language_java
)
5990 ? &objfile
->global_psymbols
5991 : &objfile
->static_psymbols
,
5992 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5998 if (built_actual_name
)
5999 xfree (actual_name
);
6002 /* Read a partial die corresponding to a namespace; also, add a symbol
6003 corresponding to that namespace to the symbol table. NAMESPACE is
6004 the name of the enclosing namespace. */
6007 add_partial_namespace (struct partial_die_info
*pdi
,
6008 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6009 int need_pc
, struct dwarf2_cu
*cu
)
6011 /* Add a symbol for the namespace. */
6013 add_partial_symbol (pdi
, cu
);
6015 /* Now scan partial symbols in that namespace. */
6017 if (pdi
->has_children
)
6018 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6021 /* Read a partial die corresponding to a Fortran module. */
6024 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
6025 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
6027 /* Now scan partial symbols in that module. */
6029 if (pdi
->has_children
)
6030 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6033 /* Read a partial die corresponding to a subprogram and create a partial
6034 symbol for that subprogram. When the CU language allows it, this
6035 routine also defines a partial symbol for each nested subprogram
6036 that this subprogram contains.
6038 DIE my also be a lexical block, in which case we simply search
6039 recursively for suprograms defined inside that lexical block.
6040 Again, this is only performed when the CU language allows this
6041 type of definitions. */
6044 add_partial_subprogram (struct partial_die_info
*pdi
,
6045 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6046 int need_pc
, struct dwarf2_cu
*cu
)
6048 if (pdi
->tag
== DW_TAG_subprogram
)
6050 if (pdi
->has_pc_info
)
6052 if (pdi
->lowpc
< *lowpc
)
6053 *lowpc
= pdi
->lowpc
;
6054 if (pdi
->highpc
> *highpc
)
6055 *highpc
= pdi
->highpc
;
6059 struct objfile
*objfile
= cu
->objfile
;
6061 baseaddr
= ANOFFSET (objfile
->section_offsets
,
6062 SECT_OFF_TEXT (objfile
));
6063 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6064 pdi
->lowpc
+ baseaddr
,
6065 pdi
->highpc
- 1 + baseaddr
,
6066 cu
->per_cu
->v
.psymtab
);
6070 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
6072 if (!pdi
->is_declaration
)
6073 /* Ignore subprogram DIEs that do not have a name, they are
6074 illegal. Do not emit a complaint at this point, we will
6075 do so when we convert this psymtab into a symtab. */
6077 add_partial_symbol (pdi
, cu
);
6081 if (! pdi
->has_children
)
6084 if (cu
->language
== language_ada
)
6086 pdi
= pdi
->die_child
;
6089 fixup_partial_die (pdi
, cu
);
6090 if (pdi
->tag
== DW_TAG_subprogram
6091 || pdi
->tag
== DW_TAG_lexical_block
)
6092 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6093 pdi
= pdi
->die_sibling
;
6098 /* Read a partial die corresponding to an enumeration type. */
6101 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
6102 struct dwarf2_cu
*cu
)
6104 struct partial_die_info
*pdi
;
6106 if (enum_pdi
->name
!= NULL
)
6107 add_partial_symbol (enum_pdi
, cu
);
6109 pdi
= enum_pdi
->die_child
;
6112 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
6113 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6115 add_partial_symbol (pdi
, cu
);
6116 pdi
= pdi
->die_sibling
;
6120 /* Return the initial uleb128 in the die at INFO_PTR. */
6123 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
6125 unsigned int bytes_read
;
6127 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6130 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6131 Return the corresponding abbrev, or NULL if the number is zero (indicating
6132 an empty DIE). In either case *BYTES_READ will be set to the length of
6133 the initial number. */
6135 static struct abbrev_info
*
6136 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
6137 struct dwarf2_cu
*cu
)
6139 bfd
*abfd
= cu
->objfile
->obfd
;
6140 unsigned int abbrev_number
;
6141 struct abbrev_info
*abbrev
;
6143 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
6145 if (abbrev_number
== 0)
6148 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
6151 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6152 abbrev_number
, bfd_get_filename (abfd
));
6158 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6159 Returns a pointer to the end of a series of DIEs, terminated by an empty
6160 DIE. Any children of the skipped DIEs will also be skipped. */
6163 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
6165 struct dwarf2_cu
*cu
= reader
->cu
;
6166 struct abbrev_info
*abbrev
;
6167 unsigned int bytes_read
;
6171 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6173 return info_ptr
+ bytes_read
;
6175 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
6179 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6180 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6181 abbrev corresponding to that skipped uleb128 should be passed in
6182 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6186 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
6187 struct abbrev_info
*abbrev
)
6189 unsigned int bytes_read
;
6190 struct attribute attr
;
6191 bfd
*abfd
= reader
->abfd
;
6192 struct dwarf2_cu
*cu
= reader
->cu
;
6193 gdb_byte
*buffer
= reader
->buffer
;
6194 const gdb_byte
*buffer_end
= reader
->buffer_end
;
6195 gdb_byte
*start_info_ptr
= info_ptr
;
6196 unsigned int form
, i
;
6198 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
6200 /* The only abbrev we care about is DW_AT_sibling. */
6201 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
6203 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
6204 if (attr
.form
== DW_FORM_ref_addr
)
6205 complaint (&symfile_complaints
,
6206 _("ignoring absolute DW_AT_sibling"));
6208 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
6211 /* If it isn't DW_AT_sibling, skip this attribute. */
6212 form
= abbrev
->attrs
[i
].form
;
6216 case DW_FORM_ref_addr
:
6217 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6218 and later it is offset sized. */
6219 if (cu
->header
.version
== 2)
6220 info_ptr
+= cu
->header
.addr_size
;
6222 info_ptr
+= cu
->header
.offset_size
;
6224 case DW_FORM_GNU_ref_alt
:
6225 info_ptr
+= cu
->header
.offset_size
;
6228 info_ptr
+= cu
->header
.addr_size
;
6235 case DW_FORM_flag_present
:
6247 case DW_FORM_ref_sig8
:
6250 case DW_FORM_string
:
6251 read_direct_string (abfd
, info_ptr
, &bytes_read
);
6252 info_ptr
+= bytes_read
;
6254 case DW_FORM_sec_offset
:
6256 case DW_FORM_GNU_strp_alt
:
6257 info_ptr
+= cu
->header
.offset_size
;
6259 case DW_FORM_exprloc
:
6261 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6262 info_ptr
+= bytes_read
;
6264 case DW_FORM_block1
:
6265 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
6267 case DW_FORM_block2
:
6268 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
6270 case DW_FORM_block4
:
6271 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
6275 case DW_FORM_ref_udata
:
6276 case DW_FORM_GNU_addr_index
:
6277 case DW_FORM_GNU_str_index
:
6278 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
6280 case DW_FORM_indirect
:
6281 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6282 info_ptr
+= bytes_read
;
6283 /* We need to continue parsing from here, so just go back to
6285 goto skip_attribute
;
6288 error (_("Dwarf Error: Cannot handle %s "
6289 "in DWARF reader [in module %s]"),
6290 dwarf_form_name (form
),
6291 bfd_get_filename (abfd
));
6295 if (abbrev
->has_children
)
6296 return skip_children (reader
, info_ptr
);
6301 /* Locate ORIG_PDI's sibling.
6302 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6305 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6306 struct partial_die_info
*orig_pdi
,
6309 /* Do we know the sibling already? */
6311 if (orig_pdi
->sibling
)
6312 return orig_pdi
->sibling
;
6314 /* Are there any children to deal with? */
6316 if (!orig_pdi
->has_children
)
6319 /* Skip the children the long way. */
6321 return skip_children (reader
, info_ptr
);
6324 /* Expand this partial symbol table into a full symbol table. */
6327 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
6333 warning (_("bug: psymtab for %s is already read in."),
6340 printf_filtered (_("Reading in symbols for %s..."),
6342 gdb_flush (gdb_stdout
);
6345 /* Restore our global data. */
6346 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
6347 dwarf2_objfile_data_key
);
6349 /* If this psymtab is constructed from a debug-only objfile, the
6350 has_section_at_zero flag will not necessarily be correct. We
6351 can get the correct value for this flag by looking at the data
6352 associated with the (presumably stripped) associated objfile. */
6353 if (pst
->objfile
->separate_debug_objfile_backlink
)
6355 struct dwarf2_per_objfile
*dpo_backlink
6356 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
6357 dwarf2_objfile_data_key
);
6359 dwarf2_per_objfile
->has_section_at_zero
6360 = dpo_backlink
->has_section_at_zero
;
6363 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6365 psymtab_to_symtab_1 (pst
);
6367 /* Finish up the debug error message. */
6369 printf_filtered (_("done.\n"));
6373 process_cu_includes ();
6376 /* Reading in full CUs. */
6378 /* Add PER_CU to the queue. */
6381 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6382 enum language pretend_language
)
6384 struct dwarf2_queue_item
*item
;
6387 item
= xmalloc (sizeof (*item
));
6388 item
->per_cu
= per_cu
;
6389 item
->pretend_language
= pretend_language
;
6392 if (dwarf2_queue
== NULL
)
6393 dwarf2_queue
= item
;
6395 dwarf2_queue_tail
->next
= item
;
6397 dwarf2_queue_tail
= item
;
6400 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6401 unit and add it to our queue.
6402 The result is non-zero if PER_CU was queued, otherwise the result is zero
6403 meaning either PER_CU is already queued or it is already loaded. */
6406 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6407 struct dwarf2_per_cu_data
*per_cu
,
6408 enum language pretend_language
)
6410 /* We may arrive here during partial symbol reading, if we need full
6411 DIEs to process an unusual case (e.g. template arguments). Do
6412 not queue PER_CU, just tell our caller to load its DIEs. */
6413 if (dwarf2_per_objfile
->reading_partial_symbols
)
6415 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6420 /* Mark the dependence relation so that we don't flush PER_CU
6422 dwarf2_add_dependence (this_cu
, per_cu
);
6424 /* If it's already on the queue, we have nothing to do. */
6428 /* If the compilation unit is already loaded, just mark it as
6430 if (per_cu
->cu
!= NULL
)
6432 per_cu
->cu
->last_used
= 0;
6436 /* Add it to the queue. */
6437 queue_comp_unit (per_cu
, pretend_language
);
6442 /* Process the queue. */
6445 process_queue (void)
6447 struct dwarf2_queue_item
*item
, *next_item
;
6449 if (dwarf2_read_debug
)
6451 fprintf_unfiltered (gdb_stdlog
,
6452 "Expanding one or more symtabs of objfile %s ...\n",
6453 dwarf2_per_objfile
->objfile
->name
);
6456 /* The queue starts out with one item, but following a DIE reference
6457 may load a new CU, adding it to the end of the queue. */
6458 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6460 if (dwarf2_per_objfile
->using_index
6461 ? !item
->per_cu
->v
.quick
->symtab
6462 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6464 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6466 if (dwarf2_read_debug
)
6468 fprintf_unfiltered (gdb_stdlog
,
6469 "Expanding symtab of %s at offset 0x%x\n",
6470 per_cu
->is_debug_types
? "TU" : "CU",
6471 per_cu
->offset
.sect_off
);
6474 if (per_cu
->is_debug_types
)
6475 process_full_type_unit (per_cu
, item
->pretend_language
);
6477 process_full_comp_unit (per_cu
, item
->pretend_language
);
6479 if (dwarf2_read_debug
)
6481 fprintf_unfiltered (gdb_stdlog
,
6482 "Done expanding %s at offset 0x%x\n",
6483 per_cu
->is_debug_types
? "TU" : "CU",
6484 per_cu
->offset
.sect_off
);
6488 item
->per_cu
->queued
= 0;
6489 next_item
= item
->next
;
6493 dwarf2_queue_tail
= NULL
;
6495 if (dwarf2_read_debug
)
6497 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6498 dwarf2_per_objfile
->objfile
->name
);
6502 /* Free all allocated queue entries. This function only releases anything if
6503 an error was thrown; if the queue was processed then it would have been
6504 freed as we went along. */
6507 dwarf2_release_queue (void *dummy
)
6509 struct dwarf2_queue_item
*item
, *last
;
6511 item
= dwarf2_queue
;
6514 /* Anything still marked queued is likely to be in an
6515 inconsistent state, so discard it. */
6516 if (item
->per_cu
->queued
)
6518 if (item
->per_cu
->cu
!= NULL
)
6519 free_one_cached_comp_unit (item
->per_cu
);
6520 item
->per_cu
->queued
= 0;
6528 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6531 /* Read in full symbols for PST, and anything it depends on. */
6534 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6536 struct dwarf2_per_cu_data
*per_cu
;
6542 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6543 if (!pst
->dependencies
[i
]->readin
6544 && pst
->dependencies
[i
]->user
== NULL
)
6546 /* Inform about additional files that need to be read in. */
6549 /* FIXME: i18n: Need to make this a single string. */
6550 fputs_filtered (" ", gdb_stdout
);
6552 fputs_filtered ("and ", gdb_stdout
);
6554 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6555 wrap_here (""); /* Flush output. */
6556 gdb_flush (gdb_stdout
);
6558 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6561 per_cu
= pst
->read_symtab_private
;
6565 /* It's an include file, no symbols to read for it.
6566 Everything is in the parent symtab. */
6571 dw2_do_instantiate_symtab (per_cu
);
6574 /* Trivial hash function for die_info: the hash value of a DIE
6575 is its offset in .debug_info for this objfile. */
6578 die_hash (const void *item
)
6580 const struct die_info
*die
= item
;
6582 return die
->offset
.sect_off
;
6585 /* Trivial comparison function for die_info structures: two DIEs
6586 are equal if they have the same offset. */
6589 die_eq (const void *item_lhs
, const void *item_rhs
)
6591 const struct die_info
*die_lhs
= item_lhs
;
6592 const struct die_info
*die_rhs
= item_rhs
;
6594 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6597 /* die_reader_func for load_full_comp_unit.
6598 This is identical to read_signatured_type_reader,
6599 but is kept separate for now. */
6602 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6604 struct die_info
*comp_unit_die
,
6608 struct dwarf2_cu
*cu
= reader
->cu
;
6609 enum language
*language_ptr
= data
;
6611 gdb_assert (cu
->die_hash
== NULL
);
6613 htab_create_alloc_ex (cu
->header
.length
/ 12,
6617 &cu
->comp_unit_obstack
,
6618 hashtab_obstack_allocate
,
6619 dummy_obstack_deallocate
);
6622 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6623 &info_ptr
, comp_unit_die
);
6624 cu
->dies
= comp_unit_die
;
6625 /* comp_unit_die is not stored in die_hash, no need. */
6627 /* We try not to read any attributes in this function, because not
6628 all CUs needed for references have been loaded yet, and symbol
6629 table processing isn't initialized. But we have to set the CU language,
6630 or we won't be able to build types correctly.
6631 Similarly, if we do not read the producer, we can not apply
6632 producer-specific interpretation. */
6633 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6636 /* Load the DIEs associated with PER_CU into memory. */
6639 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6640 enum language pretend_language
)
6642 gdb_assert (! this_cu
->is_debug_types
);
6644 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6645 load_full_comp_unit_reader
, &pretend_language
);
6648 /* Add a DIE to the delayed physname list. */
6651 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6652 const char *name
, struct die_info
*die
,
6653 struct dwarf2_cu
*cu
)
6655 struct delayed_method_info mi
;
6657 mi
.fnfield_index
= fnfield_index
;
6661 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6664 /* A cleanup for freeing the delayed method list. */
6667 free_delayed_list (void *ptr
)
6669 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6670 if (cu
->method_list
!= NULL
)
6672 VEC_free (delayed_method_info
, cu
->method_list
);
6673 cu
->method_list
= NULL
;
6677 /* Compute the physnames of any methods on the CU's method list.
6679 The computation of method physnames is delayed in order to avoid the
6680 (bad) condition that one of the method's formal parameters is of an as yet
6684 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6687 struct delayed_method_info
*mi
;
6688 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6690 const char *physname
;
6691 struct fn_fieldlist
*fn_flp
6692 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6693 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6694 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6698 /* Go objects should be embedded in a DW_TAG_module DIE,
6699 and it's not clear if/how imported objects will appear.
6700 To keep Go support simple until that's worked out,
6701 go back through what we've read and create something usable.
6702 We could do this while processing each DIE, and feels kinda cleaner,
6703 but that way is more invasive.
6704 This is to, for example, allow the user to type "p var" or "b main"
6705 without having to specify the package name, and allow lookups
6706 of module.object to work in contexts that use the expression
6710 fixup_go_packaging (struct dwarf2_cu
*cu
)
6712 char *package_name
= NULL
;
6713 struct pending
*list
;
6716 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6718 for (i
= 0; i
< list
->nsyms
; ++i
)
6720 struct symbol
*sym
= list
->symbol
[i
];
6722 if (SYMBOL_LANGUAGE (sym
) == language_go
6723 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6725 char *this_package_name
= go_symbol_package_name (sym
);
6727 if (this_package_name
== NULL
)
6729 if (package_name
== NULL
)
6730 package_name
= this_package_name
;
6733 if (strcmp (package_name
, this_package_name
) != 0)
6734 complaint (&symfile_complaints
,
6735 _("Symtab %s has objects from two different Go packages: %s and %s"),
6736 (SYMBOL_SYMTAB (sym
)
6737 && SYMBOL_SYMTAB (sym
)->filename
6738 ? SYMBOL_SYMTAB (sym
)->filename
6739 : cu
->objfile
->name
),
6740 this_package_name
, package_name
);
6741 xfree (this_package_name
);
6747 if (package_name
!= NULL
)
6749 struct objfile
*objfile
= cu
->objfile
;
6750 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6751 package_name
, objfile
);
6754 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6756 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6757 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6758 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
6759 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6760 e.g., "main" finds the "main" module and not C's main(). */
6761 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6762 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6763 SYMBOL_TYPE (sym
) = type
;
6765 add_symbol_to_list (sym
, &global_symbols
);
6767 xfree (package_name
);
6771 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6773 /* Return the symtab for PER_CU. This works properly regardless of
6774 whether we're using the index or psymtabs. */
6776 static struct symtab
*
6777 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6779 return (dwarf2_per_objfile
->using_index
6780 ? per_cu
->v
.quick
->symtab
6781 : per_cu
->v
.psymtab
->symtab
);
6784 /* A helper function for computing the list of all symbol tables
6785 included by PER_CU. */
6788 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6789 htab_t all_children
,
6790 struct dwarf2_per_cu_data
*per_cu
)
6794 struct dwarf2_per_cu_data
*iter
;
6796 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6799 /* This inclusion and its children have been processed. */
6804 /* Only add a CU if it has a symbol table. */
6805 if (get_symtab (per_cu
) != NULL
)
6806 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6809 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
, ix
, iter
);
6811 recursively_compute_inclusions (result
, all_children
, iter
);
6814 /* Compute the symtab 'includes' fields for the symtab related to
6818 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6820 gdb_assert (! per_cu
->is_debug_types
);
6822 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
))
6825 struct dwarf2_per_cu_data
*iter
;
6826 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6827 htab_t all_children
;
6828 struct symtab
*symtab
= get_symtab (per_cu
);
6830 /* If we don't have a symtab, we can just skip this case. */
6834 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6835 NULL
, xcalloc
, xfree
);
6838 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
,
6841 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6843 /* Now we have a transitive closure of all the included CUs, so
6844 we can convert it to a list of symtabs. */
6845 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6847 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6848 (len
+ 1) * sizeof (struct symtab
*));
6850 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6852 symtab
->includes
[ix
] = get_symtab (iter
);
6853 symtab
->includes
[len
] = NULL
;
6855 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6856 htab_delete (all_children
);
6860 /* Compute the 'includes' field for the symtabs of all the CUs we just
6864 process_cu_includes (void)
6867 struct dwarf2_per_cu_data
*iter
;
6870 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6874 if (! iter
->is_debug_types
)
6875 compute_symtab_includes (iter
);
6878 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6881 /* Generate full symbol information for PER_CU, whose DIEs have
6882 already been loaded into memory. */
6885 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6886 enum language pretend_language
)
6888 struct dwarf2_cu
*cu
= per_cu
->cu
;
6889 struct objfile
*objfile
= per_cu
->objfile
;
6890 CORE_ADDR lowpc
, highpc
;
6891 struct symtab
*symtab
;
6892 struct cleanup
*back_to
, *delayed_list_cleanup
;
6894 struct block
*static_block
;
6896 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6899 back_to
= make_cleanup (really_free_pendings
, NULL
);
6900 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6902 cu
->list_in_scope
= &file_symbols
;
6904 cu
->language
= pretend_language
;
6905 cu
->language_defn
= language_def (cu
->language
);
6907 /* Do line number decoding in read_file_scope () */
6908 process_die (cu
->dies
, cu
);
6910 /* For now fudge the Go package. */
6911 if (cu
->language
== language_go
)
6912 fixup_go_packaging (cu
);
6914 /* Now that we have processed all the DIEs in the CU, all the types
6915 should be complete, and it should now be safe to compute all of the
6917 compute_delayed_physnames (cu
);
6918 do_cleanups (delayed_list_cleanup
);
6920 /* Some compilers don't define a DW_AT_high_pc attribute for the
6921 compilation unit. If the DW_AT_high_pc is missing, synthesize
6922 it, by scanning the DIE's below the compilation unit. */
6923 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6926 = end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0,
6927 per_cu
->s
.imported_symtabs
!= NULL
);
6929 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6930 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6931 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6932 addrmap to help ensure it has an accurate map of pc values belonging to
6934 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
6936 symtab
= end_symtab_from_static_block (static_block
, objfile
,
6937 SECT_OFF_TEXT (objfile
), 0);
6941 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6943 /* Set symtab language to language from DW_AT_language. If the
6944 compilation is from a C file generated by language preprocessors, do
6945 not set the language if it was already deduced by start_subfile. */
6946 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6947 symtab
->language
= cu
->language
;
6949 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6950 produce DW_AT_location with location lists but it can be possibly
6951 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6952 there were bugs in prologue debug info, fixed later in GCC-4.5
6953 by "unwind info for epilogues" patch (which is not directly related).
6955 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6956 needed, it would be wrong due to missing DW_AT_producer there.
6958 Still one can confuse GDB by using non-standard GCC compilation
6959 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6961 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6962 symtab
->locations_valid
= 1;
6964 if (gcc_4_minor
>= 5)
6965 symtab
->epilogue_unwind_valid
= 1;
6967 symtab
->call_site_htab
= cu
->call_site_htab
;
6970 if (dwarf2_per_objfile
->using_index
)
6971 per_cu
->v
.quick
->symtab
= symtab
;
6974 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6975 pst
->symtab
= symtab
;
6979 /* Push it for inclusion processing later. */
6980 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
6982 do_cleanups (back_to
);
6985 /* Generate full symbol information for type unit PER_CU, whose DIEs have
6986 already been loaded into memory. */
6989 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
6990 enum language pretend_language
)
6992 struct dwarf2_cu
*cu
= per_cu
->cu
;
6993 struct objfile
*objfile
= per_cu
->objfile
;
6994 struct symtab
*symtab
;
6995 struct cleanup
*back_to
, *delayed_list_cleanup
;
6998 back_to
= make_cleanup (really_free_pendings
, NULL
);
6999 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
7001 cu
->list_in_scope
= &file_symbols
;
7003 cu
->language
= pretend_language
;
7004 cu
->language_defn
= language_def (cu
->language
);
7006 /* The symbol tables are set up in read_type_unit_scope. */
7007 process_die (cu
->dies
, cu
);
7009 /* For now fudge the Go package. */
7010 if (cu
->language
== language_go
)
7011 fixup_go_packaging (cu
);
7013 /* Now that we have processed all the DIEs in the CU, all the types
7014 should be complete, and it should now be safe to compute all of the
7016 compute_delayed_physnames (cu
);
7017 do_cleanups (delayed_list_cleanup
);
7019 /* TUs share symbol tables.
7020 If this is the first TU to use this symtab, complete the construction
7021 of it with end_expandable_symtab. Otherwise, complete the addition of
7022 this TU's symbols to the existing symtab. */
7023 if (per_cu
->s
.type_unit_group
->primary_symtab
== NULL
)
7025 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
7026 per_cu
->s
.type_unit_group
->primary_symtab
= symtab
;
7030 /* Set symtab language to language from DW_AT_language. If the
7031 compilation is from a C file generated by language preprocessors,
7032 do not set the language if it was already deduced by
7034 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7035 symtab
->language
= cu
->language
;
7040 augment_type_symtab (objfile
,
7041 per_cu
->s
.type_unit_group
->primary_symtab
);
7042 symtab
= per_cu
->s
.type_unit_group
->primary_symtab
;
7045 if (dwarf2_per_objfile
->using_index
)
7046 per_cu
->v
.quick
->symtab
= symtab
;
7049 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7050 pst
->symtab
= symtab
;
7054 do_cleanups (back_to
);
7057 /* Process an imported unit DIE. */
7060 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7062 struct attribute
*attr
;
7064 /* For now we don't handle imported units in type units. */
7065 if (cu
->per_cu
->is_debug_types
)
7067 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7068 " supported in type units [in module %s]"),
7072 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7075 struct dwarf2_per_cu_data
*per_cu
;
7076 struct symtab
*imported_symtab
;
7080 offset
= dwarf2_get_ref_die_offset (attr
);
7081 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
7082 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
7084 /* Queue the unit, if needed. */
7085 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
7086 load_full_comp_unit (per_cu
, cu
->language
);
7088 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
7093 /* Process a die and its children. */
7096 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7100 case DW_TAG_padding
:
7102 case DW_TAG_compile_unit
:
7103 case DW_TAG_partial_unit
:
7104 read_file_scope (die
, cu
);
7106 case DW_TAG_type_unit
:
7107 read_type_unit_scope (die
, cu
);
7109 case DW_TAG_subprogram
:
7110 case DW_TAG_inlined_subroutine
:
7111 read_func_scope (die
, cu
);
7113 case DW_TAG_lexical_block
:
7114 case DW_TAG_try_block
:
7115 case DW_TAG_catch_block
:
7116 read_lexical_block_scope (die
, cu
);
7118 case DW_TAG_GNU_call_site
:
7119 read_call_site_scope (die
, cu
);
7121 case DW_TAG_class_type
:
7122 case DW_TAG_interface_type
:
7123 case DW_TAG_structure_type
:
7124 case DW_TAG_union_type
:
7125 process_structure_scope (die
, cu
);
7127 case DW_TAG_enumeration_type
:
7128 process_enumeration_scope (die
, cu
);
7131 /* These dies have a type, but processing them does not create
7132 a symbol or recurse to process the children. Therefore we can
7133 read them on-demand through read_type_die. */
7134 case DW_TAG_subroutine_type
:
7135 case DW_TAG_set_type
:
7136 case DW_TAG_array_type
:
7137 case DW_TAG_pointer_type
:
7138 case DW_TAG_ptr_to_member_type
:
7139 case DW_TAG_reference_type
:
7140 case DW_TAG_string_type
:
7143 case DW_TAG_base_type
:
7144 case DW_TAG_subrange_type
:
7145 case DW_TAG_typedef
:
7146 /* Add a typedef symbol for the type definition, if it has a
7148 new_symbol (die
, read_type_die (die
, cu
), cu
);
7150 case DW_TAG_common_block
:
7151 read_common_block (die
, cu
);
7153 case DW_TAG_common_inclusion
:
7155 case DW_TAG_namespace
:
7156 processing_has_namespace_info
= 1;
7157 read_namespace (die
, cu
);
7160 processing_has_namespace_info
= 1;
7161 read_module (die
, cu
);
7163 case DW_TAG_imported_declaration
:
7164 case DW_TAG_imported_module
:
7165 processing_has_namespace_info
= 1;
7166 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
7167 || cu
->language
!= language_fortran
))
7168 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
7169 dwarf_tag_name (die
->tag
));
7170 read_import_statement (die
, cu
);
7173 case DW_TAG_imported_unit
:
7174 process_imported_unit_die (die
, cu
);
7178 new_symbol (die
, NULL
, cu
);
7183 /* A helper function for dwarf2_compute_name which determines whether DIE
7184 needs to have the name of the scope prepended to the name listed in the
7188 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7190 struct attribute
*attr
;
7194 case DW_TAG_namespace
:
7195 case DW_TAG_typedef
:
7196 case DW_TAG_class_type
:
7197 case DW_TAG_interface_type
:
7198 case DW_TAG_structure_type
:
7199 case DW_TAG_union_type
:
7200 case DW_TAG_enumeration_type
:
7201 case DW_TAG_enumerator
:
7202 case DW_TAG_subprogram
:
7206 case DW_TAG_variable
:
7207 case DW_TAG_constant
:
7208 /* We only need to prefix "globally" visible variables. These include
7209 any variable marked with DW_AT_external or any variable that
7210 lives in a namespace. [Variables in anonymous namespaces
7211 require prefixing, but they are not DW_AT_external.] */
7213 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
7215 struct dwarf2_cu
*spec_cu
= cu
;
7217 return die_needs_namespace (die_specification (die
, &spec_cu
),
7221 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7222 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
7223 && die
->parent
->tag
!= DW_TAG_module
)
7225 /* A variable in a lexical block of some kind does not need a
7226 namespace, even though in C++ such variables may be external
7227 and have a mangled name. */
7228 if (die
->parent
->tag
== DW_TAG_lexical_block
7229 || die
->parent
->tag
== DW_TAG_try_block
7230 || die
->parent
->tag
== DW_TAG_catch_block
7231 || die
->parent
->tag
== DW_TAG_subprogram
)
7240 /* Retrieve the last character from a mem_file. */
7243 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
7245 char *last_char_p
= (char *) object
;
7248 *last_char_p
= buffer
[length
- 1];
7251 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7252 compute the physname for the object, which include a method's:
7253 - formal parameters (C++/Java),
7254 - receiver type (Go),
7255 - return type (Java).
7257 The term "physname" is a bit confusing.
7258 For C++, for example, it is the demangled name.
7259 For Go, for example, it's the mangled name.
7261 For Ada, return the DIE's linkage name rather than the fully qualified
7262 name. PHYSNAME is ignored..
7264 The result is allocated on the objfile_obstack and canonicalized. */
7267 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
7270 struct objfile
*objfile
= cu
->objfile
;
7273 name
= dwarf2_name (die
, cu
);
7275 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7276 compute it by typename_concat inside GDB. */
7277 if (cu
->language
== language_ada
7278 || (cu
->language
== language_fortran
&& physname
))
7280 /* For Ada unit, we prefer the linkage name over the name, as
7281 the former contains the exported name, which the user expects
7282 to be able to reference. Ideally, we want the user to be able
7283 to reference this entity using either natural or linkage name,
7284 but we haven't started looking at this enhancement yet. */
7285 struct attribute
*attr
;
7287 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7289 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7290 if (attr
&& DW_STRING (attr
))
7291 return DW_STRING (attr
);
7294 /* These are the only languages we know how to qualify names in. */
7296 && (cu
->language
== language_cplus
|| cu
->language
== language_java
7297 || cu
->language
== language_fortran
))
7299 if (die_needs_namespace (die
, cu
))
7303 struct ui_file
*buf
;
7305 prefix
= determine_prefix (die
, cu
);
7306 buf
= mem_fileopen ();
7307 if (*prefix
!= '\0')
7309 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7312 fputs_unfiltered (prefixed_name
, buf
);
7313 xfree (prefixed_name
);
7316 fputs_unfiltered (name
, buf
);
7318 /* Template parameters may be specified in the DIE's DW_AT_name, or
7319 as children with DW_TAG_template_type_param or
7320 DW_TAG_value_type_param. If the latter, add them to the name
7321 here. If the name already has template parameters, then
7322 skip this step; some versions of GCC emit both, and
7323 it is more efficient to use the pre-computed name.
7325 Something to keep in mind about this process: it is very
7326 unlikely, or in some cases downright impossible, to produce
7327 something that will match the mangled name of a function.
7328 If the definition of the function has the same debug info,
7329 we should be able to match up with it anyway. But fallbacks
7330 using the minimal symbol, for instance to find a method
7331 implemented in a stripped copy of libstdc++, will not work.
7332 If we do not have debug info for the definition, we will have to
7333 match them up some other way.
7335 When we do name matching there is a related problem with function
7336 templates; two instantiated function templates are allowed to
7337 differ only by their return types, which we do not add here. */
7339 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7341 struct attribute
*attr
;
7342 struct die_info
*child
;
7345 die
->building_fullname
= 1;
7347 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7352 struct dwarf2_locexpr_baton
*baton
;
7355 if (child
->tag
!= DW_TAG_template_type_param
7356 && child
->tag
!= DW_TAG_template_value_param
)
7361 fputs_unfiltered ("<", buf
);
7365 fputs_unfiltered (", ", buf
);
7367 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7370 complaint (&symfile_complaints
,
7371 _("template parameter missing DW_AT_type"));
7372 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7375 type
= die_type (child
, cu
);
7377 if (child
->tag
== DW_TAG_template_type_param
)
7379 c_print_type (type
, "", buf
, -1, 0, &type_print_raw_options
);
7383 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7386 complaint (&symfile_complaints
,
7387 _("template parameter missing "
7388 "DW_AT_const_value"));
7389 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7393 dwarf2_const_value_attr (attr
, type
, name
,
7394 &cu
->comp_unit_obstack
, cu
,
7395 &value
, &bytes
, &baton
);
7397 if (TYPE_NOSIGN (type
))
7398 /* GDB prints characters as NUMBER 'CHAR'. If that's
7399 changed, this can use value_print instead. */
7400 c_printchar (value
, type
, buf
);
7403 struct value_print_options opts
;
7406 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7410 else if (bytes
!= NULL
)
7412 v
= allocate_value (type
);
7413 memcpy (value_contents_writeable (v
), bytes
,
7414 TYPE_LENGTH (type
));
7417 v
= value_from_longest (type
, value
);
7419 /* Specify decimal so that we do not depend on
7421 get_formatted_print_options (&opts
, 'd');
7423 value_print (v
, buf
, &opts
);
7429 die
->building_fullname
= 0;
7433 /* Close the argument list, with a space if necessary
7434 (nested templates). */
7435 char last_char
= '\0';
7436 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7437 if (last_char
== '>')
7438 fputs_unfiltered (" >", buf
);
7440 fputs_unfiltered (">", buf
);
7444 /* For Java and C++ methods, append formal parameter type
7445 information, if PHYSNAME. */
7447 if (physname
&& die
->tag
== DW_TAG_subprogram
7448 && (cu
->language
== language_cplus
7449 || cu
->language
== language_java
))
7451 struct type
*type
= read_type_die (die
, cu
);
7453 c_type_print_args (type
, buf
, 1, cu
->language
,
7454 &type_print_raw_options
);
7456 if (cu
->language
== language_java
)
7458 /* For java, we must append the return type to method
7460 if (die
->tag
== DW_TAG_subprogram
)
7461 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7462 0, 0, &type_print_raw_options
);
7464 else if (cu
->language
== language_cplus
)
7466 /* Assume that an artificial first parameter is
7467 "this", but do not crash if it is not. RealView
7468 marks unnamed (and thus unused) parameters as
7469 artificial; there is no way to differentiate
7471 if (TYPE_NFIELDS (type
) > 0
7472 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7473 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7474 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7476 fputs_unfiltered (" const", buf
);
7480 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7482 ui_file_delete (buf
);
7484 if (cu
->language
== language_cplus
)
7487 = dwarf2_canonicalize_name (name
, cu
,
7488 &objfile
->objfile_obstack
);
7499 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7500 If scope qualifiers are appropriate they will be added. The result
7501 will be allocated on the objfile_obstack, or NULL if the DIE does
7502 not have a name. NAME may either be from a previous call to
7503 dwarf2_name or NULL.
7505 The output string will be canonicalized (if C++/Java). */
7508 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7510 return dwarf2_compute_name (name
, die
, cu
, 0);
7513 /* Construct a physname for the given DIE in CU. NAME may either be
7514 from a previous call to dwarf2_name or NULL. The result will be
7515 allocated on the objfile_objstack or NULL if the DIE does not have a
7518 The output string will be canonicalized (if C++/Java). */
7521 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7523 struct objfile
*objfile
= cu
->objfile
;
7524 struct attribute
*attr
;
7525 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7526 struct cleanup
*back_to
;
7529 /* In this case dwarf2_compute_name is just a shortcut not building anything
7531 if (!die_needs_namespace (die
, cu
))
7532 return dwarf2_compute_name (name
, die
, cu
, 1);
7534 back_to
= make_cleanup (null_cleanup
, NULL
);
7536 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7538 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7540 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7542 if (attr
&& DW_STRING (attr
))
7546 mangled
= DW_STRING (attr
);
7548 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7549 type. It is easier for GDB users to search for such functions as
7550 `name(params)' than `long name(params)'. In such case the minimal
7551 symbol names do not match the full symbol names but for template
7552 functions there is never a need to look up their definition from their
7553 declaration so the only disadvantage remains the minimal symbol
7554 variant `long name(params)' does not have the proper inferior type.
7557 if (cu
->language
== language_go
)
7559 /* This is a lie, but we already lie to the caller new_symbol_full.
7560 new_symbol_full assumes we return the mangled name.
7561 This just undoes that lie until things are cleaned up. */
7566 demangled
= cplus_demangle (mangled
,
7567 (DMGL_PARAMS
| DMGL_ANSI
7568 | (cu
->language
== language_java
7569 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7574 make_cleanup (xfree
, demangled
);
7584 if (canon
== NULL
|| check_physname
)
7586 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7588 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7590 /* It may not mean a bug in GDB. The compiler could also
7591 compute DW_AT_linkage_name incorrectly. But in such case
7592 GDB would need to be bug-to-bug compatible. */
7594 complaint (&symfile_complaints
,
7595 _("Computed physname <%s> does not match demangled <%s> "
7596 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7597 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7599 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7600 is available here - over computed PHYSNAME. It is safer
7601 against both buggy GDB and buggy compilers. */
7615 retval
= obsavestring (retval
, strlen (retval
),
7616 &objfile
->objfile_obstack
);
7618 do_cleanups (back_to
);
7622 /* Read the import statement specified by the given die and record it. */
7625 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7627 struct objfile
*objfile
= cu
->objfile
;
7628 struct attribute
*import_attr
;
7629 struct die_info
*imported_die
, *child_die
;
7630 struct dwarf2_cu
*imported_cu
;
7631 const char *imported_name
;
7632 const char *imported_name_prefix
;
7633 const char *canonical_name
;
7634 const char *import_alias
;
7635 const char *imported_declaration
= NULL
;
7636 const char *import_prefix
;
7637 VEC (const_char_ptr
) *excludes
= NULL
;
7638 struct cleanup
*cleanups
;
7642 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7643 if (import_attr
== NULL
)
7645 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7646 dwarf_tag_name (die
->tag
));
7651 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7652 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7653 if (imported_name
== NULL
)
7655 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7657 The import in the following code:
7671 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7672 <52> DW_AT_decl_file : 1
7673 <53> DW_AT_decl_line : 6
7674 <54> DW_AT_import : <0x75>
7675 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7677 <5b> DW_AT_decl_file : 1
7678 <5c> DW_AT_decl_line : 2
7679 <5d> DW_AT_type : <0x6e>
7681 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7682 <76> DW_AT_byte_size : 4
7683 <77> DW_AT_encoding : 5 (signed)
7685 imports the wrong die ( 0x75 instead of 0x58 ).
7686 This case will be ignored until the gcc bug is fixed. */
7690 /* Figure out the local name after import. */
7691 import_alias
= dwarf2_name (die
, cu
);
7693 /* Figure out where the statement is being imported to. */
7694 import_prefix
= determine_prefix (die
, cu
);
7696 /* Figure out what the scope of the imported die is and prepend it
7697 to the name of the imported die. */
7698 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7700 if (imported_die
->tag
!= DW_TAG_namespace
7701 && imported_die
->tag
!= DW_TAG_module
)
7703 imported_declaration
= imported_name
;
7704 canonical_name
= imported_name_prefix
;
7706 else if (strlen (imported_name_prefix
) > 0)
7708 temp
= alloca (strlen (imported_name_prefix
)
7709 + 2 + strlen (imported_name
) + 1);
7710 strcpy (temp
, imported_name_prefix
);
7711 strcat (temp
, "::");
7712 strcat (temp
, imported_name
);
7713 canonical_name
= temp
;
7716 canonical_name
= imported_name
;
7718 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7720 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7721 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7722 child_die
= sibling_die (child_die
))
7724 /* DWARF-4: A Fortran use statement with a “rename list” may be
7725 represented by an imported module entry with an import attribute
7726 referring to the module and owned entries corresponding to those
7727 entities that are renamed as part of being imported. */
7729 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7731 complaint (&symfile_complaints
,
7732 _("child DW_TAG_imported_declaration expected "
7733 "- DIE at 0x%x [in module %s]"),
7734 child_die
->offset
.sect_off
, objfile
->name
);
7738 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7739 if (import_attr
== NULL
)
7741 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7742 dwarf_tag_name (child_die
->tag
));
7747 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7749 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7750 if (imported_name
== NULL
)
7752 complaint (&symfile_complaints
,
7753 _("child DW_TAG_imported_declaration has unknown "
7754 "imported name - DIE at 0x%x [in module %s]"),
7755 child_die
->offset
.sect_off
, objfile
->name
);
7759 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7761 process_die (child_die
, cu
);
7764 cp_add_using_directive (import_prefix
,
7767 imported_declaration
,
7769 &objfile
->objfile_obstack
);
7771 do_cleanups (cleanups
);
7774 /* Cleanup function for handle_DW_AT_stmt_list. */
7777 free_cu_line_header (void *arg
)
7779 struct dwarf2_cu
*cu
= arg
;
7781 free_line_header (cu
->line_header
);
7782 cu
->line_header
= NULL
;
7785 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
7786 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
7787 this, it was first present in GCC release 4.3.0. */
7790 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
7792 if (!cu
->checked_producer
)
7793 check_producer (cu
);
7795 return cu
->producer_is_gcc_lt_4_3
;
7799 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7800 char **name
, char **comp_dir
)
7802 struct attribute
*attr
;
7807 /* Find the filename. Do not use dwarf2_name here, since the filename
7808 is not a source language identifier. */
7809 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7812 *name
= DW_STRING (attr
);
7815 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7817 *comp_dir
= DW_STRING (attr
);
7818 else if (producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
7819 && IS_ABSOLUTE_PATH (*name
))
7821 *comp_dir
= ldirname (*name
);
7822 if (*comp_dir
!= NULL
)
7823 make_cleanup (xfree
, *comp_dir
);
7825 if (*comp_dir
!= NULL
)
7827 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7828 directory, get rid of it. */
7829 char *cp
= strchr (*comp_dir
, ':');
7831 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7836 *name
= "<unknown>";
7839 /* Handle DW_AT_stmt_list for a compilation unit.
7840 DIE is the DW_TAG_compile_unit die for CU.
7841 COMP_DIR is the compilation directory.
7842 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7845 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7846 const char *comp_dir
)
7848 struct attribute
*attr
;
7850 gdb_assert (! cu
->per_cu
->is_debug_types
);
7852 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7855 unsigned int line_offset
= DW_UNSND (attr
);
7856 struct line_header
*line_header
7857 = dwarf_decode_line_header (line_offset
, cu
);
7861 cu
->line_header
= line_header
;
7862 make_cleanup (free_cu_line_header
, cu
);
7863 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7868 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7871 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7873 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7874 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7875 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7876 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7877 struct attribute
*attr
;
7879 char *comp_dir
= NULL
;
7880 struct die_info
*child_die
;
7881 bfd
*abfd
= objfile
->obfd
;
7884 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7886 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7888 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7889 from finish_block. */
7890 if (lowpc
== ((CORE_ADDR
) -1))
7895 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7897 prepare_one_comp_unit (cu
, die
, cu
->language
);
7899 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7900 standardised yet. As a workaround for the language detection we fall
7901 back to the DW_AT_producer string. */
7902 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7903 cu
->language
= language_opencl
;
7905 /* Similar hack for Go. */
7906 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
7907 set_cu_language (DW_LANG_Go
, cu
);
7909 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
7911 /* Decode line number information if present. We do this before
7912 processing child DIEs, so that the line header table is available
7913 for DW_AT_decl_file. */
7914 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
7916 /* Process all dies in compilation unit. */
7917 if (die
->child
!= NULL
)
7919 child_die
= die
->child
;
7920 while (child_die
&& child_die
->tag
)
7922 process_die (child_die
, cu
);
7923 child_die
= sibling_die (child_die
);
7927 /* Decode macro information, if present. Dwarf 2 macro information
7928 refers to information in the line number info statement program
7929 header, so we can only read it if we've read the header
7931 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
7932 if (attr
&& cu
->line_header
)
7934 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
7935 complaint (&symfile_complaints
,
7936 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
7938 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
7942 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
7943 if (attr
&& cu
->line_header
)
7945 unsigned int macro_offset
= DW_UNSND (attr
);
7947 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
7951 do_cleanups (back_to
);
7954 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
7955 Create the set of symtabs used by this TU, or if this TU is sharing
7956 symtabs with another TU and the symtabs have already been created
7957 then restore those symtabs in the line header.
7958 We don't need the pc/line-number mapping for type units. */
7961 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
7963 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7964 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7965 struct type_unit_group
*tu_group
;
7967 struct line_header
*lh
;
7968 struct attribute
*attr
;
7969 unsigned int i
, line_offset
;
7971 gdb_assert (per_cu
->is_debug_types
);
7973 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7975 /* If we're using .gdb_index (includes -readnow) then
7976 per_cu->s.type_unit_group may not have been set up yet. */
7977 if (per_cu
->s
.type_unit_group
== NULL
)
7978 per_cu
->s
.type_unit_group
= get_type_unit_group (cu
, attr
);
7979 tu_group
= per_cu
->s
.type_unit_group
;
7981 /* If we've already processed this stmt_list there's no real need to
7982 do it again, we could fake it and just recreate the part we need
7983 (file name,index -> symtab mapping). If data shows this optimization
7984 is useful we can do it then. */
7985 first_time
= tu_group
->primary_symtab
== NULL
;
7987 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7992 line_offset
= DW_UNSND (attr
);
7993 lh
= dwarf_decode_line_header (line_offset
, cu
);
7998 dwarf2_start_symtab (cu
, "", NULL
, 0);
8001 gdb_assert (tu_group
->symtabs
== NULL
);
8004 /* Note: The primary symtab will get allocated at the end. */
8008 cu
->line_header
= lh
;
8009 make_cleanup (free_cu_line_header
, cu
);
8013 dwarf2_start_symtab (cu
, "", NULL
, 0);
8015 tu_group
->num_symtabs
= lh
->num_file_names
;
8016 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
8018 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8021 struct file_entry
*fe
= &lh
->file_names
[i
];
8024 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8025 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
8027 /* Note: We don't have to watch for the main subfile here, type units
8028 don't have DW_AT_name. */
8030 if (current_subfile
->symtab
== NULL
)
8032 /* NOTE: start_subfile will recognize when it's been passed
8033 a file it has already seen. So we can't assume there's a
8034 simple mapping from lh->file_names to subfiles,
8035 lh->file_names may contain dups. */
8036 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8040 fe
->symtab
= current_subfile
->symtab
;
8041 tu_group
->symtabs
[i
] = fe
->symtab
;
8048 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8050 struct file_entry
*fe
= &lh
->file_names
[i
];
8052 fe
->symtab
= tu_group
->symtabs
[i
];
8056 /* The main symtab is allocated last. Type units don't have DW_AT_name
8057 so they don't have a "real" (so to speak) symtab anyway.
8058 There is later code that will assign the main symtab to all symbols
8059 that don't have one. We need to handle the case of a symbol with a
8060 missing symtab (DW_AT_decl_file) anyway. */
8063 /* Process DW_TAG_type_unit.
8064 For TUs we want to skip the first top level sibling if it's not the
8065 actual type being defined by this TU. In this case the first top
8066 level sibling is there to provide context only. */
8069 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8071 struct die_info
*child_die
;
8073 prepare_one_comp_unit (cu
, die
, language_minimal
);
8075 /* Initialize (or reinitialize) the machinery for building symtabs.
8076 We do this before processing child DIEs, so that the line header table
8077 is available for DW_AT_decl_file. */
8078 setup_type_unit_groups (die
, cu
);
8080 if (die
->child
!= NULL
)
8082 child_die
= die
->child
;
8083 while (child_die
&& child_die
->tag
)
8085 process_die (child_die
, cu
);
8086 child_die
= sibling_die (child_die
);
8093 http://gcc.gnu.org/wiki/DebugFission
8094 http://gcc.gnu.org/wiki/DebugFissionDWP
8096 To simplify handling of both DWO files ("object" files with the DWARF info)
8097 and DWP files (a file with the DWOs packaged up into one file), we treat
8098 DWP files as having a collection of virtual DWO files. */
8101 hash_dwo_file (const void *item
)
8103 const struct dwo_file
*dwo_file
= item
;
8105 return htab_hash_string (dwo_file
->name
);
8109 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
8111 const struct dwo_file
*lhs
= item_lhs
;
8112 const struct dwo_file
*rhs
= item_rhs
;
8114 return strcmp (lhs
->name
, rhs
->name
) == 0;
8117 /* Allocate a hash table for DWO files. */
8120 allocate_dwo_file_hash_table (void)
8122 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8124 return htab_create_alloc_ex (41,
8128 &objfile
->objfile_obstack
,
8129 hashtab_obstack_allocate
,
8130 dummy_obstack_deallocate
);
8133 /* Lookup DWO file DWO_NAME. */
8136 lookup_dwo_file_slot (const char *dwo_name
)
8138 struct dwo_file find_entry
;
8141 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8142 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8144 memset (&find_entry
, 0, sizeof (find_entry
));
8145 find_entry
.name
= dwo_name
;
8146 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8152 hash_dwo_unit (const void *item
)
8154 const struct dwo_unit
*dwo_unit
= item
;
8156 /* This drops the top 32 bits of the id, but is ok for a hash. */
8157 return dwo_unit
->signature
;
8161 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
8163 const struct dwo_unit
*lhs
= item_lhs
;
8164 const struct dwo_unit
*rhs
= item_rhs
;
8166 /* The signature is assumed to be unique within the DWO file.
8167 So while object file CU dwo_id's always have the value zero,
8168 that's OK, assuming each object file DWO file has only one CU,
8169 and that's the rule for now. */
8170 return lhs
->signature
== rhs
->signature
;
8173 /* Allocate a hash table for DWO CUs,TUs.
8174 There is one of these tables for each of CUs,TUs for each DWO file. */
8177 allocate_dwo_unit_table (struct objfile
*objfile
)
8179 /* Start out with a pretty small number.
8180 Generally DWO files contain only one CU and maybe some TUs. */
8181 return htab_create_alloc_ex (3,
8185 &objfile
->objfile_obstack
,
8186 hashtab_obstack_allocate
,
8187 dummy_obstack_deallocate
);
8190 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
8192 struct create_dwo_info_table_data
8194 struct dwo_file
*dwo_file
;
8198 /* die_reader_func for create_dwo_debug_info_hash_table. */
8201 create_dwo_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
8203 struct die_info
*comp_unit_die
,
8207 struct dwarf2_cu
*cu
= reader
->cu
;
8208 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8209 sect_offset offset
= cu
->per_cu
->offset
;
8210 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
8211 struct create_dwo_info_table_data
*data
= datap
;
8212 struct dwo_file
*dwo_file
= data
->dwo_file
;
8213 htab_t cu_htab
= data
->cu_htab
;
8215 struct attribute
*attr
;
8216 struct dwo_unit
*dwo_unit
;
8218 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
8221 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8222 " its dwo_id [in module %s]"),
8223 offset
.sect_off
, dwo_file
->name
);
8227 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8228 dwo_unit
->dwo_file
= dwo_file
;
8229 dwo_unit
->signature
= DW_UNSND (attr
);
8230 dwo_unit
->info_or_types_section
= section
;
8231 dwo_unit
->offset
= offset
;
8232 dwo_unit
->length
= cu
->per_cu
->length
;
8234 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
8235 gdb_assert (slot
!= NULL
);
8238 const struct dwo_unit
*dup_dwo_unit
= *slot
;
8240 complaint (&symfile_complaints
,
8241 _("debug entry at offset 0x%x is duplicate to the entry at"
8242 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8243 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
8244 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
8250 if (dwarf2_read_debug
)
8251 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
8253 phex (dwo_unit
->signature
,
8254 sizeof (dwo_unit
->signature
)));
8257 /* Create a hash table to map DWO IDs to their CU entry in
8258 .debug_info.dwo in DWO_FILE.
8259 Note: This function processes DWO files only, not DWP files. */
8262 create_dwo_debug_info_hash_table (struct dwo_file
*dwo_file
)
8264 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8265 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
8268 gdb_byte
*info_ptr
, *end_ptr
;
8269 struct create_dwo_info_table_data create_dwo_info_table_data
;
8271 dwarf2_read_section (objfile
, section
);
8272 info_ptr
= section
->buffer
;
8274 if (info_ptr
== NULL
)
8277 /* We can't set abfd until now because the section may be empty or
8278 not present, in which case section->asection will be NULL. */
8279 abfd
= section
->asection
->owner
;
8281 if (dwarf2_read_debug
)
8282 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
8283 bfd_get_filename (abfd
));
8285 cu_htab
= allocate_dwo_unit_table (objfile
);
8287 create_dwo_info_table_data
.dwo_file
= dwo_file
;
8288 create_dwo_info_table_data
.cu_htab
= cu_htab
;
8290 end_ptr
= info_ptr
+ section
->size
;
8291 while (info_ptr
< end_ptr
)
8293 struct dwarf2_per_cu_data per_cu
;
8295 memset (&per_cu
, 0, sizeof (per_cu
));
8296 per_cu
.objfile
= objfile
;
8297 per_cu
.is_debug_types
= 0;
8298 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8299 per_cu
.info_or_types_section
= section
;
8301 init_cutu_and_read_dies_no_follow (&per_cu
,
8302 &dwo_file
->sections
.abbrev
,
8304 create_dwo_debug_info_hash_table_reader
,
8305 &create_dwo_info_table_data
);
8307 info_ptr
+= per_cu
.length
;
8313 /* DWP file .debug_{cu,tu}_index section format:
8314 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8316 Both index sections have the same format, and serve to map a 64-bit
8317 signature to a set of section numbers. Each section begins with a header,
8318 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8319 indexes, and a pool of 32-bit section numbers. The index sections will be
8320 aligned at 8-byte boundaries in the file.
8322 The index section header contains two unsigned 32-bit values (using the
8323 byte order of the application binary):
8325 N, the number of compilation units or type units in the index
8326 M, the number of slots in the hash table
8328 (We assume that N and M will not exceed 2^32 - 1.)
8330 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8332 The hash table begins at offset 8 in the section, and consists of an array
8333 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8334 order of the application binary). Unused slots in the hash table are 0.
8335 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8337 The parallel table begins immediately after the hash table
8338 (at offset 8 + 8 * M from the beginning of the section), and consists of an
8339 array of 32-bit indexes (using the byte order of the application binary),
8340 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8341 table contains a 32-bit index into the pool of section numbers. For unused
8342 hash table slots, the corresponding entry in the parallel table will be 0.
8344 Given a 64-bit compilation unit signature or a type signature S, an entry
8345 in the hash table is located as follows:
8347 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8348 the low-order k bits all set to 1.
8350 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8352 3) If the hash table entry at index H matches the signature, use that
8353 entry. If the hash table entry at index H is unused (all zeroes),
8354 terminate the search: the signature is not present in the table.
8356 4) Let H = (H + H') modulo M. Repeat at Step 3.
8358 Because M > N and H' and M are relatively prime, the search is guaranteed
8359 to stop at an unused slot or find the match.
8361 The pool of section numbers begins immediately following the hash table
8362 (at offset 8 + 12 * M from the beginning of the section). The pool of
8363 section numbers consists of an array of 32-bit words (using the byte order
8364 of the application binary). Each item in the array is indexed starting
8365 from 0. The hash table entry provides the index of the first section
8366 number in the set. Additional section numbers in the set follow, and the
8367 set is terminated by a 0 entry (section number 0 is not used in ELF).
8369 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8370 section must be the first entry in the set, and the .debug_abbrev.dwo must
8371 be the second entry. Other members of the set may follow in any order. */
8373 /* Create a hash table to map DWO IDs to their CU/TU entry in
8374 .debug_{info,types}.dwo in DWP_FILE.
8375 Returns NULL if there isn't one.
8376 Note: This function processes DWP files only, not DWO files. */
8378 static struct dwp_hash_table
*
8379 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
8381 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8382 bfd
*dbfd
= dwp_file
->dbfd
;
8383 char *index_ptr
, *index_end
;
8384 struct dwarf2_section_info
*index
;
8385 uint32_t version
, nr_units
, nr_slots
;
8386 struct dwp_hash_table
*htab
;
8389 index
= &dwp_file
->sections
.tu_index
;
8391 index
= &dwp_file
->sections
.cu_index
;
8393 if (dwarf2_section_empty_p (index
))
8395 dwarf2_read_section (objfile
, index
);
8397 index_ptr
= index
->buffer
;
8398 index_end
= index_ptr
+ index
->size
;
8400 version
= read_4_bytes (dbfd
, index_ptr
);
8401 index_ptr
+= 8; /* Skip the unused word. */
8402 nr_units
= read_4_bytes (dbfd
, index_ptr
);
8404 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
8409 error (_("Dwarf Error: unsupported DWP file version (%u)"
8411 version
, dwp_file
->name
);
8413 if (nr_slots
!= (nr_slots
& -nr_slots
))
8415 error (_("Dwarf Error: number of slots in DWP hash table (%u)"
8416 " is not power of 2 [in module %s]"),
8417 nr_slots
, dwp_file
->name
);
8420 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
8421 htab
->nr_units
= nr_units
;
8422 htab
->nr_slots
= nr_slots
;
8423 htab
->hash_table
= index_ptr
;
8424 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
8425 htab
->section_pool
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8430 /* Update SECTIONS with the data from SECTP.
8432 This function is like the other "locate" section routines that are
8433 passed to bfd_map_over_sections, but in this context the sections to
8434 read comes from the DWP hash table, not the full ELF section table.
8436 The result is non-zero for success, or zero if an error was found. */
8439 locate_virtual_dwo_sections (asection
*sectp
,
8440 struct virtual_dwo_sections
*sections
)
8442 const struct dwop_section_names
*names
= &dwop_section_names
;
8444 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8446 /* There can be only one. */
8447 if (sections
->abbrev
.asection
!= NULL
)
8449 sections
->abbrev
.asection
= sectp
;
8450 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8452 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
8453 || section_is_p (sectp
->name
, &names
->types_dwo
))
8455 /* There can be only one. */
8456 if (sections
->info_or_types
.asection
!= NULL
)
8458 sections
->info_or_types
.asection
= sectp
;
8459 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
8461 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8463 /* There can be only one. */
8464 if (sections
->line
.asection
!= NULL
)
8466 sections
->line
.asection
= sectp
;
8467 sections
->line
.size
= bfd_get_section_size (sectp
);
8469 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8471 /* There can be only one. */
8472 if (sections
->loc
.asection
!= NULL
)
8474 sections
->loc
.asection
= sectp
;
8475 sections
->loc
.size
= bfd_get_section_size (sectp
);
8477 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8479 /* There can be only one. */
8480 if (sections
->macinfo
.asection
!= NULL
)
8482 sections
->macinfo
.asection
= sectp
;
8483 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8485 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8487 /* There can be only one. */
8488 if (sections
->macro
.asection
!= NULL
)
8490 sections
->macro
.asection
= sectp
;
8491 sections
->macro
.size
= bfd_get_section_size (sectp
);
8493 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8495 /* There can be only one. */
8496 if (sections
->str_offsets
.asection
!= NULL
)
8498 sections
->str_offsets
.asection
= sectp
;
8499 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8503 /* No other kind of section is valid. */
8510 /* Create a dwo_unit object for the DWO with signature SIGNATURE.
8511 HTAB is the hash table from the DWP file.
8512 SECTION_INDEX is the index of the DWO in HTAB. */
8514 static struct dwo_unit
*
8515 create_dwo_in_dwp (struct dwp_file
*dwp_file
,
8516 const struct dwp_hash_table
*htab
,
8517 uint32_t section_index
,
8518 ULONGEST signature
, int is_debug_types
)
8520 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8521 bfd
*dbfd
= dwp_file
->dbfd
;
8522 const char *kind
= is_debug_types
? "TU" : "CU";
8523 struct dwo_file
*dwo_file
;
8524 struct dwo_unit
*dwo_unit
;
8525 struct virtual_dwo_sections sections
;
8526 void **dwo_file_slot
;
8527 char *virtual_dwo_name
;
8528 struct dwarf2_section_info
*cutu
;
8529 struct cleanup
*cleanups
;
8532 if (dwarf2_read_debug
)
8534 fprintf_unfiltered (gdb_stdlog
, "Reading %s %u/0x%s in DWP file: %s\n",
8536 section_index
, phex (signature
, sizeof (signature
)),
8540 /* Fetch the sections of this DWO.
8541 Put a limit on the number of sections we look for so that bad data
8542 doesn't cause us to loop forever. */
8544 #define MAX_NR_DWO_SECTIONS \
8545 (1 /* .debug_info or .debug_types */ \
8546 + 1 /* .debug_abbrev */ \
8547 + 1 /* .debug_line */ \
8548 + 1 /* .debug_loc */ \
8549 + 1 /* .debug_str_offsets */ \
8550 + 1 /* .debug_macro */ \
8551 + 1 /* .debug_macinfo */ \
8552 + 1 /* trailing zero */)
8554 memset (§ions
, 0, sizeof (sections
));
8555 cleanups
= make_cleanup (null_cleanup
, 0);
8557 for (i
= 0; i
< MAX_NR_DWO_SECTIONS
; ++i
)
8560 uint32_t section_nr
=
8563 + (section_index
+ i
) * sizeof (uint32_t));
8565 if (section_nr
== 0)
8567 if (section_nr
>= dwp_file
->num_sections
)
8569 error (_("Dwarf Error: bad DWP hash table, section number too large"
8574 sectp
= dwp_file
->elf_sections
[section_nr
];
8575 if (! locate_virtual_dwo_sections (sectp
, §ions
))
8577 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8584 || sections
.info_or_types
.asection
== NULL
8585 || sections
.abbrev
.asection
== NULL
)
8587 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8591 if (i
== MAX_NR_DWO_SECTIONS
)
8593 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8598 /* It's easier for the rest of the code if we fake a struct dwo_file and
8599 have dwo_unit "live" in that. At least for now.
8601 The DWP file can be made up of a random collection of CUs and TUs.
8602 However, for each CU + set of TUs that came from the same original DWO
8603 file, we want to combine them back into a virtual DWO file to save space
8604 (fewer struct dwo_file objects to allocated). Remember that for really
8605 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8608 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
8609 sections
.abbrev
.asection
? sections
.abbrev
.asection
->id
: 0,
8610 sections
.line
.asection
? sections
.line
.asection
->id
: 0,
8611 sections
.loc
.asection
? sections
.loc
.asection
->id
: 0,
8612 (sections
.str_offsets
.asection
8613 ? sections
.str_offsets
.asection
->id
8615 make_cleanup (xfree
, virtual_dwo_name
);
8616 /* Can we use an existing virtual DWO file? */
8617 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
);
8618 /* Create one if necessary. */
8619 if (*dwo_file_slot
== NULL
)
8621 if (dwarf2_read_debug
)
8623 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
8626 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8627 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8629 strlen (virtual_dwo_name
));
8630 dwo_file
->sections
.abbrev
= sections
.abbrev
;
8631 dwo_file
->sections
.line
= sections
.line
;
8632 dwo_file
->sections
.loc
= sections
.loc
;
8633 dwo_file
->sections
.macinfo
= sections
.macinfo
;
8634 dwo_file
->sections
.macro
= sections
.macro
;
8635 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
8636 /* The "str" section is global to the entire DWP file. */
8637 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
8638 /* The info or types section is assigned later to dwo_unit,
8639 there's no need to record it in dwo_file.
8640 Also, we can't simply record type sections in dwo_file because
8641 we record a pointer into the vector in dwo_unit. As we collect more
8642 types we'll grow the vector and eventually have to reallocate space
8643 for it, invalidating all the pointers into the current copy. */
8644 *dwo_file_slot
= dwo_file
;
8648 if (dwarf2_read_debug
)
8650 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
8653 dwo_file
= *dwo_file_slot
;
8655 do_cleanups (cleanups
);
8657 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8658 dwo_unit
->dwo_file
= dwo_file
;
8659 dwo_unit
->signature
= signature
;
8660 dwo_unit
->info_or_types_section
=
8661 obstack_alloc (&objfile
->objfile_obstack
,
8662 sizeof (struct dwarf2_section_info
));
8663 *dwo_unit
->info_or_types_section
= sections
.info_or_types
;
8664 /* offset, length, type_offset_in_tu are set later. */
8669 /* Lookup the DWO with SIGNATURE in DWP_FILE. */
8671 static struct dwo_unit
*
8672 lookup_dwo_in_dwp (struct dwp_file
*dwp_file
,
8673 const struct dwp_hash_table
*htab
,
8674 ULONGEST signature
, int is_debug_types
)
8676 bfd
*dbfd
= dwp_file
->dbfd
;
8677 uint32_t mask
= htab
->nr_slots
- 1;
8678 uint32_t hash
= signature
& mask
;
8679 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
8682 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8684 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
8685 find_dwo_cu
.signature
= signature
;
8686 slot
= htab_find_slot (dwp_file
->loaded_cutus
, &find_dwo_cu
, INSERT
);
8691 /* Use a for loop so that we don't loop forever on bad debug info. */
8692 for (i
= 0; i
< htab
->nr_slots
; ++i
)
8694 ULONGEST signature_in_table
;
8696 signature_in_table
=
8697 read_8_bytes (dbfd
, htab
->hash_table
+ hash
* sizeof (uint64_t));
8698 if (signature_in_table
== signature
)
8700 uint32_t section_index
=
8701 read_4_bytes (dbfd
, htab
->unit_table
+ hash
* sizeof (uint32_t));
8703 *slot
= create_dwo_in_dwp (dwp_file
, htab
, section_index
,
8704 signature
, is_debug_types
);
8707 if (signature_in_table
== 0)
8709 hash
= (hash
+ hash2
) & mask
;
8712 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
8717 /* Subroutine of open_dwop_file to simplify it.
8718 Open the file specified by FILE_NAME and hand it off to BFD for
8719 preliminary analysis. Return a newly initialized bfd *, which
8720 includes a canonicalized copy of FILE_NAME.
8721 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8722 In case of trouble, return NULL.
8723 NOTE: This function is derived from symfile_bfd_open. */
8726 try_open_dwop_file (const char *file_name
, int is_dwp
)
8730 char *absolute_name
;
8732 flags
= OPF_TRY_CWD_FIRST
;
8734 flags
|= OPF_SEARCH_IN_PATH
;
8735 desc
= openp (debug_file_directory
, flags
, file_name
,
8736 O_RDONLY
| O_BINARY
, &absolute_name
);
8740 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
8743 xfree (absolute_name
);
8746 xfree (absolute_name
);
8747 bfd_set_cacheable (sym_bfd
, 1);
8749 if (!bfd_check_format (sym_bfd
, bfd_object
))
8751 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
8758 /* Try to open DWO/DWP file FILE_NAME.
8759 COMP_DIR is the DW_AT_comp_dir attribute.
8760 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8761 The result is the bfd handle of the file.
8762 If there is a problem finding or opening the file, return NULL.
8763 Upon success, the canonicalized path of the file is stored in the bfd,
8764 same as symfile_bfd_open. */
8767 open_dwop_file (const char *file_name
, const char *comp_dir
, int is_dwp
)
8771 if (IS_ABSOLUTE_PATH (file_name
))
8772 return try_open_dwop_file (file_name
, is_dwp
);
8774 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8776 if (comp_dir
!= NULL
)
8778 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, file_name
, NULL
);
8780 /* NOTE: If comp_dir is a relative path, this will also try the
8781 search path, which seems useful. */
8782 abfd
= try_open_dwop_file (path_to_try
, is_dwp
);
8783 xfree (path_to_try
);
8788 /* That didn't work, try debug-file-directory, which, despite its name,
8789 is a list of paths. */
8791 if (*debug_file_directory
== '\0')
8794 return try_open_dwop_file (file_name
, is_dwp
);
8797 /* This function is mapped across the sections and remembers the offset and
8798 size of each of the DWO debugging sections we are interested in. */
8801 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
8803 struct dwo_sections
*dwo_sections
= dwo_sections_ptr
;
8804 const struct dwop_section_names
*names
= &dwop_section_names
;
8806 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8808 dwo_sections
->abbrev
.asection
= sectp
;
8809 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8811 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
8813 dwo_sections
->info
.asection
= sectp
;
8814 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
8816 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8818 dwo_sections
->line
.asection
= sectp
;
8819 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
8821 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8823 dwo_sections
->loc
.asection
= sectp
;
8824 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
8826 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8828 dwo_sections
->macinfo
.asection
= sectp
;
8829 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8831 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8833 dwo_sections
->macro
.asection
= sectp
;
8834 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
8836 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
8838 dwo_sections
->str
.asection
= sectp
;
8839 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
8841 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8843 dwo_sections
->str_offsets
.asection
= sectp
;
8844 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8846 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
8848 struct dwarf2_section_info type_section
;
8850 memset (&type_section
, 0, sizeof (type_section
));
8851 type_section
.asection
= sectp
;
8852 type_section
.size
= bfd_get_section_size (sectp
);
8853 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
8858 /* Initialize the use of the DWO file specified by DWO_NAME.
8859 The result is NULL if DWO_NAME can't be found. */
8861 static struct dwo_file
*
8862 open_and_init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8864 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8865 struct dwo_file
*dwo_file
;
8867 struct cleanup
*cleanups
;
8869 dbfd
= open_dwop_file (dwo_name
, comp_dir
, 0);
8872 if (dwarf2_read_debug
)
8873 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
8876 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8877 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8878 dwo_name
, strlen (dwo_name
));
8879 dwo_file
->dbfd
= dbfd
;
8881 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8883 bfd_map_over_sections (dbfd
, dwarf2_locate_dwo_sections
, &dwo_file
->sections
);
8885 dwo_file
->cus
= create_dwo_debug_info_hash_table (dwo_file
);
8887 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8888 dwo_file
->sections
.types
);
8890 discard_cleanups (cleanups
);
8892 if (dwarf2_read_debug
)
8893 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
8898 /* This function is mapped across the sections and remembers the offset and
8899 size of each of the DWP debugging sections we are interested in. */
8902 dwarf2_locate_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
8904 struct dwp_file
*dwp_file
= dwp_file_ptr
;
8905 const struct dwop_section_names
*names
= &dwop_section_names
;
8906 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
8908 /* Record the ELF section number for later lookup: this is what the
8909 .debug_cu_index,.debug_tu_index tables use. */
8910 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
8911 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
8913 /* Look for specific sections that we need. */
8914 if (section_is_p (sectp
->name
, &names
->str_dwo
))
8916 dwp_file
->sections
.str
.asection
= sectp
;
8917 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
8919 else if (section_is_p (sectp
->name
, &names
->cu_index
))
8921 dwp_file
->sections
.cu_index
.asection
= sectp
;
8922 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
8924 else if (section_is_p (sectp
->name
, &names
->tu_index
))
8926 dwp_file
->sections
.tu_index
.asection
= sectp
;
8927 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
8931 /* Hash function for dwp_file loaded CUs/TUs. */
8934 hash_dwp_loaded_cutus (const void *item
)
8936 const struct dwo_unit
*dwo_unit
= item
;
8938 /* This drops the top 32 bits of the signature, but is ok for a hash. */
8939 return dwo_unit
->signature
;
8942 /* Equality function for dwp_file loaded CUs/TUs. */
8945 eq_dwp_loaded_cutus (const void *a
, const void *b
)
8947 const struct dwo_unit
*dua
= a
;
8948 const struct dwo_unit
*dub
= b
;
8950 return dua
->signature
== dub
->signature
;
8953 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
8956 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
8958 return htab_create_alloc_ex (3,
8959 hash_dwp_loaded_cutus
,
8960 eq_dwp_loaded_cutus
,
8962 &objfile
->objfile_obstack
,
8963 hashtab_obstack_allocate
,
8964 dummy_obstack_deallocate
);
8967 /* Initialize the use of the DWP file for the current objfile.
8968 By convention the name of the DWP file is ${objfile}.dwp.
8969 The result is NULL if it can't be found. */
8971 static struct dwp_file
*
8972 open_and_init_dwp_file (const char *comp_dir
)
8974 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8975 struct dwp_file
*dwp_file
;
8978 struct cleanup
*cleanups
;
8980 dwp_name
= xstrprintf ("%s.dwp", dwarf2_per_objfile
->objfile
->name
);
8981 cleanups
= make_cleanup (xfree
, dwp_name
);
8983 dbfd
= open_dwop_file (dwp_name
, comp_dir
, 1);
8986 if (dwarf2_read_debug
)
8987 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
8988 do_cleanups (cleanups
);
8991 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
8992 dwp_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8993 dwp_name
, strlen (dwp_name
));
8994 dwp_file
->dbfd
= dbfd
;
8995 do_cleanups (cleanups
);
8997 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwp_file
);
8999 /* +1: section 0 is unused */
9000 dwp_file
->num_sections
= bfd_count_sections (dbfd
) + 1;
9001 dwp_file
->elf_sections
=
9002 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
9003 dwp_file
->num_sections
, asection
*);
9005 bfd_map_over_sections (dbfd
, dwarf2_locate_dwp_sections
, dwp_file
);
9007 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
9009 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
9011 dwp_file
->loaded_cutus
= allocate_dwp_loaded_cutus_table (objfile
);
9013 discard_cleanups (cleanups
);
9015 if (dwarf2_read_debug
)
9017 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
9018 fprintf_unfiltered (gdb_stdlog
,
9019 " %u CUs, %u TUs\n",
9020 dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0,
9021 dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0);
9027 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9028 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9029 or in the DWP file for the objfile, referenced by THIS_UNIT.
9030 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9031 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9033 This is called, for example, when wanting to read a variable with a
9034 complex location. Therefore we don't want to do file i/o for every call.
9035 Therefore we don't want to look for a DWO file on every call.
9036 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9037 then we check if we've already seen DWO_NAME, and only THEN do we check
9040 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9041 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9043 static struct dwo_unit
*
9044 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
9045 const char *dwo_name
, const char *comp_dir
,
9046 ULONGEST signature
, int is_debug_types
)
9048 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9049 const char *kind
= is_debug_types
? "TU" : "CU";
9050 void **dwo_file_slot
;
9051 struct dwo_file
*dwo_file
;
9052 struct dwp_file
*dwp_file
;
9054 /* Have we already read SIGNATURE from a DWP file? */
9056 if (! dwarf2_per_objfile
->dwp_checked
)
9058 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file (comp_dir
);
9059 dwarf2_per_objfile
->dwp_checked
= 1;
9061 dwp_file
= dwarf2_per_objfile
->dwp_file
;
9063 if (dwp_file
!= NULL
)
9065 const struct dwp_hash_table
*dwp_htab
=
9066 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9068 if (dwp_htab
!= NULL
)
9070 struct dwo_unit
*dwo_cutu
=
9071 lookup_dwo_in_dwp (dwp_file
, dwp_htab
, signature
, is_debug_types
);
9073 if (dwo_cutu
!= NULL
)
9075 if (dwarf2_read_debug
)
9077 fprintf_unfiltered (gdb_stdlog
,
9078 "Virtual DWO %s %s found: @%s\n",
9079 kind
, hex_string (signature
),
9080 host_address_to_string (dwo_cutu
));
9087 /* Have we already seen DWO_NAME? */
9089 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
);
9090 if (*dwo_file_slot
== NULL
)
9092 /* Read in the file and build a table of the DWOs it contains. */
9093 *dwo_file_slot
= open_and_init_dwo_file (dwo_name
, comp_dir
);
9095 /* NOTE: This will be NULL if unable to open the file. */
9096 dwo_file
= *dwo_file_slot
;
9098 if (dwo_file
!= NULL
)
9100 htab_t htab
= is_debug_types
? dwo_file
->tus
: dwo_file
->cus
;
9104 struct dwo_unit find_dwo_cutu
, *dwo_cutu
;
9106 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
9107 find_dwo_cutu
.signature
= signature
;
9108 dwo_cutu
= htab_find (htab
, &find_dwo_cutu
);
9110 if (dwo_cutu
!= NULL
)
9112 if (dwarf2_read_debug
)
9114 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
9115 kind
, dwo_name
, hex_string (signature
),
9116 host_address_to_string (dwo_cutu
));
9123 /* We didn't find it. This could mean a dwo_id mismatch, or
9124 someone deleted the DWO/DWP file, or the search path isn't set up
9125 correctly to find the file. */
9127 if (dwarf2_read_debug
)
9129 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
9130 kind
, dwo_name
, hex_string (signature
));
9133 complaint (&symfile_complaints
,
9134 _("Could not find DWO CU referenced by CU at offset 0x%x"
9136 this_unit
->offset
.sect_off
, objfile
->name
);
9140 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9141 See lookup_dwo_cutu_unit for details. */
9143 static struct dwo_unit
*
9144 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9145 const char *dwo_name
, const char *comp_dir
,
9148 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
9151 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9152 See lookup_dwo_cutu_unit for details. */
9154 static struct dwo_unit
*
9155 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
9156 const char *dwo_name
, const char *comp_dir
)
9158 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
9161 /* Free all resources associated with DWO_FILE.
9162 Close the DWO file and munmap the sections.
9163 All memory should be on the objfile obstack. */
9166 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
9169 struct dwarf2_section_info
*section
;
9171 gdb_assert (dwo_file
->dbfd
!= objfile
->obfd
);
9172 gdb_bfd_unref (dwo_file
->dbfd
);
9174 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
9177 /* Wrapper for free_dwo_file for use in cleanups. */
9180 free_dwo_file_cleanup (void *arg
)
9182 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
9183 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9185 free_dwo_file (dwo_file
, objfile
);
9188 /* Traversal function for free_dwo_files. */
9191 free_dwo_file_from_slot (void **slot
, void *info
)
9193 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
9194 struct objfile
*objfile
= (struct objfile
*) info
;
9196 free_dwo_file (dwo_file
, objfile
);
9201 /* Free all resources associated with DWO_FILES. */
9204 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
9206 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
9209 /* Read in various DIEs. */
9211 /* qsort helper for inherit_abstract_dies. */
9214 unsigned_int_compar (const void *ap
, const void *bp
)
9216 unsigned int a
= *(unsigned int *) ap
;
9217 unsigned int b
= *(unsigned int *) bp
;
9219 return (a
> b
) - (b
> a
);
9222 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9223 Inherit only the children of the DW_AT_abstract_origin DIE not being
9224 already referenced by DW_AT_abstract_origin from the children of the
9228 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
9230 struct die_info
*child_die
;
9231 unsigned die_children_count
;
9232 /* CU offsets which were referenced by children of the current DIE. */
9233 sect_offset
*offsets
;
9234 sect_offset
*offsets_end
, *offsetp
;
9235 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9236 struct die_info
*origin_die
;
9237 /* Iterator of the ORIGIN_DIE children. */
9238 struct die_info
*origin_child_die
;
9239 struct cleanup
*cleanups
;
9240 struct attribute
*attr
;
9241 struct dwarf2_cu
*origin_cu
;
9242 struct pending
**origin_previous_list_in_scope
;
9244 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9248 /* Note that following die references may follow to a die in a
9252 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
9254 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9256 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
9257 origin_cu
->list_in_scope
= cu
->list_in_scope
;
9259 if (die
->tag
!= origin_die
->tag
9260 && !(die
->tag
== DW_TAG_inlined_subroutine
9261 && origin_die
->tag
== DW_TAG_subprogram
))
9262 complaint (&symfile_complaints
,
9263 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
9264 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
9266 child_die
= die
->child
;
9267 die_children_count
= 0;
9268 while (child_die
&& child_die
->tag
)
9270 child_die
= sibling_die (child_die
);
9271 die_children_count
++;
9273 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
9274 cleanups
= make_cleanup (xfree
, offsets
);
9276 offsets_end
= offsets
;
9277 child_die
= die
->child
;
9278 while (child_die
&& child_die
->tag
)
9280 /* For each CHILD_DIE, find the corresponding child of
9281 ORIGIN_DIE. If there is more than one layer of
9282 DW_AT_abstract_origin, follow them all; there shouldn't be,
9283 but GCC versions at least through 4.4 generate this (GCC PR
9285 struct die_info
*child_origin_die
= child_die
;
9286 struct dwarf2_cu
*child_origin_cu
= cu
;
9290 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
9294 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
9298 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9299 counterpart may exist. */
9300 if (child_origin_die
!= child_die
)
9302 if (child_die
->tag
!= child_origin_die
->tag
9303 && !(child_die
->tag
== DW_TAG_inlined_subroutine
9304 && child_origin_die
->tag
== DW_TAG_subprogram
))
9305 complaint (&symfile_complaints
,
9306 _("Child DIE 0x%x and its abstract origin 0x%x have "
9307 "different tags"), child_die
->offset
.sect_off
,
9308 child_origin_die
->offset
.sect_off
);
9309 if (child_origin_die
->parent
!= origin_die
)
9310 complaint (&symfile_complaints
,
9311 _("Child DIE 0x%x and its abstract origin 0x%x have "
9312 "different parents"), child_die
->offset
.sect_off
,
9313 child_origin_die
->offset
.sect_off
);
9315 *offsets_end
++ = child_origin_die
->offset
;
9317 child_die
= sibling_die (child_die
);
9319 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
9320 unsigned_int_compar
);
9321 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
9322 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
9323 complaint (&symfile_complaints
,
9324 _("Multiple children of DIE 0x%x refer "
9325 "to DIE 0x%x as their abstract origin"),
9326 die
->offset
.sect_off
, offsetp
->sect_off
);
9329 origin_child_die
= origin_die
->child
;
9330 while (origin_child_die
&& origin_child_die
->tag
)
9332 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9333 while (offsetp
< offsets_end
9334 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
9336 if (offsetp
>= offsets_end
9337 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
9339 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
9340 process_die (origin_child_die
, origin_cu
);
9342 origin_child_die
= sibling_die (origin_child_die
);
9344 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
9346 do_cleanups (cleanups
);
9350 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9352 struct objfile
*objfile
= cu
->objfile
;
9353 struct context_stack
*new;
9356 struct die_info
*child_die
;
9357 struct attribute
*attr
, *call_line
, *call_file
;
9360 struct block
*block
;
9361 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
9362 VEC (symbolp
) *template_args
= NULL
;
9363 struct template_symbol
*templ_func
= NULL
;
9367 /* If we do not have call site information, we can't show the
9368 caller of this inlined function. That's too confusing, so
9369 only use the scope for local variables. */
9370 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
9371 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
9372 if (call_line
== NULL
|| call_file
== NULL
)
9374 read_lexical_block_scope (die
, cu
);
9379 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9381 name
= dwarf2_name (die
, cu
);
9383 /* Ignore functions with missing or empty names. These are actually
9384 illegal according to the DWARF standard. */
9387 complaint (&symfile_complaints
,
9388 _("missing name for subprogram DIE at %d"),
9389 die
->offset
.sect_off
);
9393 /* Ignore functions with missing or invalid low and high pc attributes. */
9394 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9396 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9397 if (!attr
|| !DW_UNSND (attr
))
9398 complaint (&symfile_complaints
,
9399 _("cannot get low and high bounds "
9400 "for subprogram DIE at %d"),
9401 die
->offset
.sect_off
);
9408 /* If we have any template arguments, then we must allocate a
9409 different sort of symbol. */
9410 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
9412 if (child_die
->tag
== DW_TAG_template_type_param
9413 || child_die
->tag
== DW_TAG_template_value_param
)
9415 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
9416 struct template_symbol
);
9417 templ_func
->base
.is_cplus_template_function
= 1;
9422 new = push_context (0, lowpc
);
9423 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
9424 (struct symbol
*) templ_func
);
9426 /* If there is a location expression for DW_AT_frame_base, record
9428 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
9430 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
9431 expression is being recorded directly in the function's symbol
9432 and not in a separate frame-base object. I guess this hack is
9433 to avoid adding some sort of frame-base adjunct/annex to the
9434 function's symbol :-(. The problem with doing this is that it
9435 results in a function symbol with a location expression that
9436 has nothing to do with the location of the function, ouch! The
9437 relationship should be: a function's symbol has-a frame base; a
9438 frame-base has-a location expression. */
9439 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
9441 cu
->list_in_scope
= &local_symbols
;
9443 if (die
->child
!= NULL
)
9445 child_die
= die
->child
;
9446 while (child_die
&& child_die
->tag
)
9448 if (child_die
->tag
== DW_TAG_template_type_param
9449 || child_die
->tag
== DW_TAG_template_value_param
)
9451 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9454 VEC_safe_push (symbolp
, template_args
, arg
);
9457 process_die (child_die
, cu
);
9458 child_die
= sibling_die (child_die
);
9462 inherit_abstract_dies (die
, cu
);
9464 /* If we have a DW_AT_specification, we might need to import using
9465 directives from the context of the specification DIE. See the
9466 comment in determine_prefix. */
9467 if (cu
->language
== language_cplus
9468 && dwarf2_attr (die
, DW_AT_specification
, cu
))
9470 struct dwarf2_cu
*spec_cu
= cu
;
9471 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
9475 child_die
= spec_die
->child
;
9476 while (child_die
&& child_die
->tag
)
9478 if (child_die
->tag
== DW_TAG_imported_module
)
9479 process_die (child_die
, spec_cu
);
9480 child_die
= sibling_die (child_die
);
9483 /* In some cases, GCC generates specification DIEs that
9484 themselves contain DW_AT_specification attributes. */
9485 spec_die
= die_specification (spec_die
, &spec_cu
);
9489 new = pop_context ();
9490 /* Make a block for the local symbols within. */
9491 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
9492 lowpc
, highpc
, objfile
);
9494 /* For C++, set the block's scope. */
9495 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
9496 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
9497 determine_prefix (die
, cu
),
9498 processing_has_namespace_info
);
9500 /* If we have address ranges, record them. */
9501 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9503 /* Attach template arguments to function. */
9504 if (! VEC_empty (symbolp
, template_args
))
9506 gdb_assert (templ_func
!= NULL
);
9508 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
9509 templ_func
->template_arguments
9510 = obstack_alloc (&objfile
->objfile_obstack
,
9511 (templ_func
->n_template_arguments
9512 * sizeof (struct symbol
*)));
9513 memcpy (templ_func
->template_arguments
,
9514 VEC_address (symbolp
, template_args
),
9515 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
9516 VEC_free (symbolp
, template_args
);
9519 /* In C++, we can have functions nested inside functions (e.g., when
9520 a function declares a class that has methods). This means that
9521 when we finish processing a function scope, we may need to go
9522 back to building a containing block's symbol lists. */
9523 local_symbols
= new->locals
;
9524 using_directives
= new->using_directives
;
9526 /* If we've finished processing a top-level function, subsequent
9527 symbols go in the file symbol list. */
9528 if (outermost_context_p ())
9529 cu
->list_in_scope
= &file_symbols
;
9532 /* Process all the DIES contained within a lexical block scope. Start
9533 a new scope, process the dies, and then close the scope. */
9536 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9538 struct objfile
*objfile
= cu
->objfile
;
9539 struct context_stack
*new;
9540 CORE_ADDR lowpc
, highpc
;
9541 struct die_info
*child_die
;
9544 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9546 /* Ignore blocks with missing or invalid low and high pc attributes. */
9547 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
9548 as multiple lexical blocks? Handling children in a sane way would
9549 be nasty. Might be easier to properly extend generic blocks to
9551 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9556 push_context (0, lowpc
);
9557 if (die
->child
!= NULL
)
9559 child_die
= die
->child
;
9560 while (child_die
&& child_die
->tag
)
9562 process_die (child_die
, cu
);
9563 child_die
= sibling_die (child_die
);
9566 new = pop_context ();
9568 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
9571 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
9574 /* Note that recording ranges after traversing children, as we
9575 do here, means that recording a parent's ranges entails
9576 walking across all its children's ranges as they appear in
9577 the address map, which is quadratic behavior.
9579 It would be nicer to record the parent's ranges before
9580 traversing its children, simply overriding whatever you find
9581 there. But since we don't even decide whether to create a
9582 block until after we've traversed its children, that's hard
9584 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9586 local_symbols
= new->locals
;
9587 using_directives
= new->using_directives
;
9590 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
9593 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9595 struct objfile
*objfile
= cu
->objfile
;
9596 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9597 CORE_ADDR pc
, baseaddr
;
9598 struct attribute
*attr
;
9599 struct call_site
*call_site
, call_site_local
;
9602 struct die_info
*child_die
;
9604 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9606 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9609 complaint (&symfile_complaints
,
9610 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
9611 "DIE 0x%x [in module %s]"),
9612 die
->offset
.sect_off
, objfile
->name
);
9615 pc
= DW_ADDR (attr
) + baseaddr
;
9617 if (cu
->call_site_htab
== NULL
)
9618 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
9619 NULL
, &objfile
->objfile_obstack
,
9620 hashtab_obstack_allocate
, NULL
);
9621 call_site_local
.pc
= pc
;
9622 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
9625 complaint (&symfile_complaints
,
9626 _("Duplicate PC %s for DW_TAG_GNU_call_site "
9627 "DIE 0x%x [in module %s]"),
9628 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
9632 /* Count parameters at the caller. */
9635 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9636 child_die
= sibling_die (child_die
))
9638 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9640 complaint (&symfile_complaints
,
9641 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
9642 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9643 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
9650 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
9651 (sizeof (*call_site
)
9652 + (sizeof (*call_site
->parameter
)
9655 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
9658 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
9660 struct die_info
*func_die
;
9662 /* Skip also over DW_TAG_inlined_subroutine. */
9663 for (func_die
= die
->parent
;
9664 func_die
&& func_die
->tag
!= DW_TAG_subprogram
9665 && func_die
->tag
!= DW_TAG_subroutine_type
;
9666 func_die
= func_die
->parent
);
9668 /* DW_AT_GNU_all_call_sites is a superset
9669 of DW_AT_GNU_all_tail_call_sites. */
9671 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
9672 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
9674 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
9675 not complete. But keep CALL_SITE for look ups via call_site_htab,
9676 both the initial caller containing the real return address PC and
9677 the final callee containing the current PC of a chain of tail
9678 calls do not need to have the tail call list complete. But any
9679 function candidate for a virtual tail call frame searched via
9680 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
9681 determined unambiguously. */
9685 struct type
*func_type
= NULL
;
9688 func_type
= get_die_type (func_die
, cu
);
9689 if (func_type
!= NULL
)
9691 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
9693 /* Enlist this call site to the function. */
9694 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
9695 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
9698 complaint (&symfile_complaints
,
9699 _("Cannot find function owning DW_TAG_GNU_call_site "
9700 "DIE 0x%x [in module %s]"),
9701 die
->offset
.sect_off
, objfile
->name
);
9705 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
9707 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9708 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
9709 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
9710 /* Keep NULL DWARF_BLOCK. */;
9711 else if (attr_form_is_block (attr
))
9713 struct dwarf2_locexpr_baton
*dlbaton
;
9715 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
9716 dlbaton
->data
= DW_BLOCK (attr
)->data
;
9717 dlbaton
->size
= DW_BLOCK (attr
)->size
;
9718 dlbaton
->per_cu
= cu
->per_cu
;
9720 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
9722 else if (is_ref_attr (attr
))
9724 struct dwarf2_cu
*target_cu
= cu
;
9725 struct die_info
*target_die
;
9727 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
9728 gdb_assert (target_cu
->objfile
== objfile
);
9729 if (die_is_declaration (target_die
, target_cu
))
9731 const char *target_physname
;
9733 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
9734 if (target_physname
== NULL
)
9735 complaint (&symfile_complaints
,
9736 _("DW_AT_GNU_call_site_target target DIE has invalid "
9737 "physname, for referencing DIE 0x%x [in module %s]"),
9738 die
->offset
.sect_off
, objfile
->name
);
9740 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
9746 /* DW_AT_entry_pc should be preferred. */
9747 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
9748 complaint (&symfile_complaints
,
9749 _("DW_AT_GNU_call_site_target target DIE has invalid "
9750 "low pc, for referencing DIE 0x%x [in module %s]"),
9751 die
->offset
.sect_off
, objfile
->name
);
9753 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
9757 complaint (&symfile_complaints
,
9758 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
9759 "block nor reference, for DIE 0x%x [in module %s]"),
9760 die
->offset
.sect_off
, objfile
->name
);
9762 call_site
->per_cu
= cu
->per_cu
;
9764 for (child_die
= die
->child
;
9765 child_die
&& child_die
->tag
;
9766 child_die
= sibling_die (child_die
))
9768 struct call_site_parameter
*parameter
;
9769 struct attribute
*loc
, *origin
;
9771 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9773 /* Already printed the complaint above. */
9777 gdb_assert (call_site
->parameter_count
< nparams
);
9778 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
9780 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
9781 specifies DW_TAG_formal_parameter. Value of the data assumed for the
9782 register is contained in DW_AT_GNU_call_site_value. */
9784 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
9785 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
9786 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
9790 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
9791 offset
= dwarf2_get_ref_die_offset (origin
);
9792 if (!offset_in_cu_p (&cu
->header
, offset
))
9794 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
9795 binding can be done only inside one CU. Such referenced DIE
9796 therefore cannot be even moved to DW_TAG_partial_unit. */
9797 complaint (&symfile_complaints
,
9798 _("DW_AT_abstract_origin offset is not in CU for "
9799 "DW_TAG_GNU_call_site child DIE 0x%x "
9801 child_die
->offset
.sect_off
, objfile
->name
);
9804 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
9805 - cu
->header
.offset
.sect_off
);
9807 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
9809 complaint (&symfile_complaints
,
9810 _("No DW_FORM_block* DW_AT_location for "
9811 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9812 child_die
->offset
.sect_off
, objfile
->name
);
9817 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
9818 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
9819 if (parameter
->u
.dwarf_reg
!= -1)
9820 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
9821 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
9822 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
9823 ¶meter
->u
.fb_offset
))
9824 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
9827 complaint (&symfile_complaints
,
9828 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
9829 "for DW_FORM_block* DW_AT_location is supported for "
9830 "DW_TAG_GNU_call_site child DIE 0x%x "
9832 child_die
->offset
.sect_off
, objfile
->name
);
9837 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
9838 if (!attr_form_is_block (attr
))
9840 complaint (&symfile_complaints
,
9841 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9842 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9843 child_die
->offset
.sect_off
, objfile
->name
);
9846 parameter
->value
= DW_BLOCK (attr
)->data
;
9847 parameter
->value_size
= DW_BLOCK (attr
)->size
;
9849 /* Parameters are not pre-cleared by memset above. */
9850 parameter
->data_value
= NULL
;
9851 parameter
->data_value_size
= 0;
9852 call_site
->parameter_count
++;
9854 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
9857 if (!attr_form_is_block (attr
))
9858 complaint (&symfile_complaints
,
9859 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9860 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9861 child_die
->offset
.sect_off
, objfile
->name
);
9864 parameter
->data_value
= DW_BLOCK (attr
)->data
;
9865 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
9871 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9872 Return 1 if the attributes are present and valid, otherwise, return 0.
9873 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9876 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
9877 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
9878 struct partial_symtab
*ranges_pst
)
9880 struct objfile
*objfile
= cu
->objfile
;
9881 struct comp_unit_head
*cu_header
= &cu
->header
;
9882 bfd
*obfd
= objfile
->obfd
;
9883 unsigned int addr_size
= cu_header
->addr_size
;
9884 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9885 /* Base address selection entry. */
9896 found_base
= cu
->base_known
;
9897 base
= cu
->base_address
;
9899 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9900 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9902 complaint (&symfile_complaints
,
9903 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9907 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9909 /* Read in the largest possible address. */
9910 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
9911 if ((marker
& mask
) == mask
)
9913 /* If we found the largest possible address, then
9914 read the base address. */
9915 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9916 buffer
+= 2 * addr_size
;
9917 offset
+= 2 * addr_size
;
9923 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9927 CORE_ADDR range_beginning
, range_end
;
9929 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
9930 buffer
+= addr_size
;
9931 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
9932 buffer
+= addr_size
;
9933 offset
+= 2 * addr_size
;
9935 /* An end of list marker is a pair of zero addresses. */
9936 if (range_beginning
== 0 && range_end
== 0)
9937 /* Found the end of list entry. */
9940 /* Each base address selection entry is a pair of 2 values.
9941 The first is the largest possible address, the second is
9942 the base address. Check for a base address here. */
9943 if ((range_beginning
& mask
) == mask
)
9945 /* If we found the largest possible address, then
9946 read the base address. */
9947 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9954 /* We have no valid base address for the ranges
9956 complaint (&symfile_complaints
,
9957 _("Invalid .debug_ranges data (no base address)"));
9961 if (range_beginning
> range_end
)
9963 /* Inverted range entries are invalid. */
9964 complaint (&symfile_complaints
,
9965 _("Invalid .debug_ranges data (inverted range)"));
9969 /* Empty range entries have no effect. */
9970 if (range_beginning
== range_end
)
9973 range_beginning
+= base
;
9976 /* A not-uncommon case of bad debug info.
9977 Don't pollute the addrmap with bad data. */
9978 if (range_beginning
+ baseaddr
== 0
9979 && !dwarf2_per_objfile
->has_section_at_zero
)
9981 complaint (&symfile_complaints
,
9982 _(".debug_ranges entry has start address of zero"
9983 " [in module %s]"), objfile
->name
);
9987 if (ranges_pst
!= NULL
)
9988 addrmap_set_empty (objfile
->psymtabs_addrmap
,
9989 range_beginning
+ baseaddr
,
9990 range_end
- 1 + baseaddr
,
9993 /* FIXME: This is recording everything as a low-high
9994 segment of consecutive addresses. We should have a
9995 data structure for discontiguous block ranges
9999 low
= range_beginning
;
10005 if (range_beginning
< low
)
10006 low
= range_beginning
;
10007 if (range_end
> high
)
10013 /* If the first entry is an end-of-list marker, the range
10014 describes an empty scope, i.e. no instructions. */
10020 *high_return
= high
;
10024 /* Get low and high pc attributes from a die. Return 1 if the attributes
10025 are present and valid, otherwise, return 0. Return -1 if the range is
10026 discontinuous, i.e. derived from DW_AT_ranges information. */
10029 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
10030 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
10031 struct partial_symtab
*pst
)
10033 struct attribute
*attr
;
10034 struct attribute
*attr_high
;
10036 CORE_ADDR high
= 0;
10039 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10042 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10045 low
= DW_ADDR (attr
);
10046 if (attr_high
->form
== DW_FORM_addr
10047 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10048 high
= DW_ADDR (attr_high
);
10050 high
= low
+ DW_UNSND (attr_high
);
10053 /* Found high w/o low attribute. */
10056 /* Found consecutive range of addresses. */
10061 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10064 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10065 We take advantage of the fact that DW_AT_ranges does not appear
10066 in DW_TAG_compile_unit of DWO files. */
10067 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
10068 unsigned int ranges_offset
= (DW_UNSND (attr
)
10069 + (need_ranges_base
10073 /* Value of the DW_AT_ranges attribute is the offset in the
10074 .debug_ranges section. */
10075 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
10077 /* Found discontinuous range of addresses. */
10082 /* read_partial_die has also the strict LOW < HIGH requirement. */
10086 /* When using the GNU linker, .gnu.linkonce. sections are used to
10087 eliminate duplicate copies of functions and vtables and such.
10088 The linker will arbitrarily choose one and discard the others.
10089 The AT_*_pc values for such functions refer to local labels in
10090 these sections. If the section from that file was discarded, the
10091 labels are not in the output, so the relocs get a value of 0.
10092 If this is a discarded function, mark the pc bounds as invalid,
10093 so that GDB will ignore it. */
10094 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10103 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
10104 its low and high PC addresses. Do nothing if these addresses could not
10105 be determined. Otherwise, set LOWPC to the low address if it is smaller,
10106 and HIGHPC to the high address if greater than HIGHPC. */
10109 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
10110 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10111 struct dwarf2_cu
*cu
)
10113 CORE_ADDR low
, high
;
10114 struct die_info
*child
= die
->child
;
10116 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
10118 *lowpc
= min (*lowpc
, low
);
10119 *highpc
= max (*highpc
, high
);
10122 /* If the language does not allow nested subprograms (either inside
10123 subprograms or lexical blocks), we're done. */
10124 if (cu
->language
!= language_ada
)
10127 /* Check all the children of the given DIE. If it contains nested
10128 subprograms, then check their pc bounds. Likewise, we need to
10129 check lexical blocks as well, as they may also contain subprogram
10131 while (child
&& child
->tag
)
10133 if (child
->tag
== DW_TAG_subprogram
10134 || child
->tag
== DW_TAG_lexical_block
)
10135 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
10136 child
= sibling_die (child
);
10140 /* Get the low and high pc's represented by the scope DIE, and store
10141 them in *LOWPC and *HIGHPC. If the correct values can't be
10142 determined, set *LOWPC to -1 and *HIGHPC to 0. */
10145 get_scope_pc_bounds (struct die_info
*die
,
10146 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10147 struct dwarf2_cu
*cu
)
10149 CORE_ADDR best_low
= (CORE_ADDR
) -1;
10150 CORE_ADDR best_high
= (CORE_ADDR
) 0;
10151 CORE_ADDR current_low
, current_high
;
10153 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
10155 best_low
= current_low
;
10156 best_high
= current_high
;
10160 struct die_info
*child
= die
->child
;
10162 while (child
&& child
->tag
)
10164 switch (child
->tag
) {
10165 case DW_TAG_subprogram
:
10166 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
10168 case DW_TAG_namespace
:
10169 case DW_TAG_module
:
10170 /* FIXME: carlton/2004-01-16: Should we do this for
10171 DW_TAG_class_type/DW_TAG_structure_type, too? I think
10172 that current GCC's always emit the DIEs corresponding
10173 to definitions of methods of classes as children of a
10174 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
10175 the DIEs giving the declarations, which could be
10176 anywhere). But I don't see any reason why the
10177 standards says that they have to be there. */
10178 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
10180 if (current_low
!= ((CORE_ADDR
) -1))
10182 best_low
= min (best_low
, current_low
);
10183 best_high
= max (best_high
, current_high
);
10191 child
= sibling_die (child
);
10196 *highpc
= best_high
;
10199 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
10203 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
10204 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
10206 struct objfile
*objfile
= cu
->objfile
;
10207 struct attribute
*attr
;
10208 struct attribute
*attr_high
;
10210 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10213 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10216 CORE_ADDR low
= DW_ADDR (attr
);
10218 if (attr_high
->form
== DW_FORM_addr
10219 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10220 high
= DW_ADDR (attr_high
);
10222 high
= low
+ DW_UNSND (attr_high
);
10224 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
10228 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10231 bfd
*obfd
= objfile
->obfd
;
10232 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10233 We take advantage of the fact that DW_AT_ranges does not appear
10234 in DW_TAG_compile_unit of DWO files. */
10235 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
10237 /* The value of the DW_AT_ranges attribute is the offset of the
10238 address range list in the .debug_ranges section. */
10239 unsigned long offset
= (DW_UNSND (attr
)
10240 + (need_ranges_base
? cu
->ranges_base
: 0));
10241 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
10243 /* For some target architectures, but not others, the
10244 read_address function sign-extends the addresses it returns.
10245 To recognize base address selection entries, we need a
10247 unsigned int addr_size
= cu
->header
.addr_size
;
10248 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
10250 /* The base address, to which the next pair is relative. Note
10251 that this 'base' is a DWARF concept: most entries in a range
10252 list are relative, to reduce the number of relocs against the
10253 debugging information. This is separate from this function's
10254 'baseaddr' argument, which GDB uses to relocate debugging
10255 information from a shared library based on the address at
10256 which the library was loaded. */
10257 CORE_ADDR base
= cu
->base_address
;
10258 int base_known
= cu
->base_known
;
10260 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
10261 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
10263 complaint (&symfile_complaints
,
10264 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
10271 unsigned int bytes_read
;
10272 CORE_ADDR start
, end
;
10274 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10275 buffer
+= bytes_read
;
10276 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10277 buffer
+= bytes_read
;
10279 /* Did we find the end of the range list? */
10280 if (start
== 0 && end
== 0)
10283 /* Did we find a base address selection entry? */
10284 else if ((start
& base_select_mask
) == base_select_mask
)
10290 /* We found an ordinary address range. */
10295 complaint (&symfile_complaints
,
10296 _("Invalid .debug_ranges data "
10297 "(no base address)"));
10303 /* Inverted range entries are invalid. */
10304 complaint (&symfile_complaints
,
10305 _("Invalid .debug_ranges data "
10306 "(inverted range)"));
10310 /* Empty range entries have no effect. */
10314 start
+= base
+ baseaddr
;
10315 end
+= base
+ baseaddr
;
10317 /* A not-uncommon case of bad debug info.
10318 Don't pollute the addrmap with bad data. */
10319 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10321 complaint (&symfile_complaints
,
10322 _(".debug_ranges entry has start address of zero"
10323 " [in module %s]"), objfile
->name
);
10327 record_block_range (block
, start
, end
- 1);
10333 /* Check whether the producer field indicates either of GCC < 4.6, or the
10334 Intel C/C++ compiler, and cache the result in CU. */
10337 check_producer (struct dwarf2_cu
*cu
)
10340 int major
, minor
, release
;
10342 if (cu
->producer
== NULL
)
10344 /* For unknown compilers expect their behavior is DWARF version
10347 GCC started to support .debug_types sections by -gdwarf-4 since
10348 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
10349 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
10350 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
10351 interpreted incorrectly by GDB now - GCC PR debug/48229. */
10353 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
10355 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
10357 cs
= &cu
->producer
[strlen ("GNU ")];
10358 while (*cs
&& !isdigit (*cs
))
10360 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
10362 /* Not recognized as GCC. */
10366 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
10367 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
10370 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
10371 cu
->producer_is_icc
= 1;
10374 /* For other non-GCC compilers, expect their behavior is DWARF version
10378 cu
->checked_producer
= 1;
10381 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
10382 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
10383 during 4.6.0 experimental. */
10386 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
10388 if (!cu
->checked_producer
)
10389 check_producer (cu
);
10391 return cu
->producer_is_gxx_lt_4_6
;
10394 /* Return the default accessibility type if it is not overriden by
10395 DW_AT_accessibility. */
10397 static enum dwarf_access_attribute
10398 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
10400 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
10402 /* The default DWARF 2 accessibility for members is public, the default
10403 accessibility for inheritance is private. */
10405 if (die
->tag
!= DW_TAG_inheritance
)
10406 return DW_ACCESS_public
;
10408 return DW_ACCESS_private
;
10412 /* DWARF 3+ defines the default accessibility a different way. The same
10413 rules apply now for DW_TAG_inheritance as for the members and it only
10414 depends on the container kind. */
10416 if (die
->parent
->tag
== DW_TAG_class_type
)
10417 return DW_ACCESS_private
;
10419 return DW_ACCESS_public
;
10423 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
10424 offset. If the attribute was not found return 0, otherwise return
10425 1. If it was found but could not properly be handled, set *OFFSET
10429 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
10432 struct attribute
*attr
;
10434 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
10439 /* Note that we do not check for a section offset first here.
10440 This is because DW_AT_data_member_location is new in DWARF 4,
10441 so if we see it, we can assume that a constant form is really
10442 a constant and not a section offset. */
10443 if (attr_form_is_constant (attr
))
10444 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
10445 else if (attr_form_is_section_offset (attr
))
10446 dwarf2_complex_location_expr_complaint ();
10447 else if (attr_form_is_block (attr
))
10448 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10450 dwarf2_complex_location_expr_complaint ();
10458 /* Add an aggregate field to the field list. */
10461 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
10462 struct dwarf2_cu
*cu
)
10464 struct objfile
*objfile
= cu
->objfile
;
10465 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10466 struct nextfield
*new_field
;
10467 struct attribute
*attr
;
10469 char *fieldname
= "";
10471 /* Allocate a new field list entry and link it in. */
10472 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
10473 make_cleanup (xfree
, new_field
);
10474 memset (new_field
, 0, sizeof (struct nextfield
));
10476 if (die
->tag
== DW_TAG_inheritance
)
10478 new_field
->next
= fip
->baseclasses
;
10479 fip
->baseclasses
= new_field
;
10483 new_field
->next
= fip
->fields
;
10484 fip
->fields
= new_field
;
10488 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10490 new_field
->accessibility
= DW_UNSND (attr
);
10492 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
10493 if (new_field
->accessibility
!= DW_ACCESS_public
)
10494 fip
->non_public_fields
= 1;
10496 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10498 new_field
->virtuality
= DW_UNSND (attr
);
10500 new_field
->virtuality
= DW_VIRTUALITY_none
;
10502 fp
= &new_field
->field
;
10504 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
10508 /* Data member other than a C++ static data member. */
10510 /* Get type of field. */
10511 fp
->type
= die_type (die
, cu
);
10513 SET_FIELD_BITPOS (*fp
, 0);
10515 /* Get bit size of field (zero if none). */
10516 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
10519 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
10523 FIELD_BITSIZE (*fp
) = 0;
10526 /* Get bit offset of field. */
10527 if (handle_data_member_location (die
, cu
, &offset
))
10528 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10529 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
10532 if (gdbarch_bits_big_endian (gdbarch
))
10534 /* For big endian bits, the DW_AT_bit_offset gives the
10535 additional bit offset from the MSB of the containing
10536 anonymous object to the MSB of the field. We don't
10537 have to do anything special since we don't need to
10538 know the size of the anonymous object. */
10539 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
10543 /* For little endian bits, compute the bit offset to the
10544 MSB of the anonymous object, subtract off the number of
10545 bits from the MSB of the field to the MSB of the
10546 object, and then subtract off the number of bits of
10547 the field itself. The result is the bit offset of
10548 the LSB of the field. */
10549 int anonymous_size
;
10550 int bit_offset
= DW_UNSND (attr
);
10552 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10555 /* The size of the anonymous object containing
10556 the bit field is explicit, so use the
10557 indicated size (in bytes). */
10558 anonymous_size
= DW_UNSND (attr
);
10562 /* The size of the anonymous object containing
10563 the bit field must be inferred from the type
10564 attribute of the data member containing the
10566 anonymous_size
= TYPE_LENGTH (fp
->type
);
10568 SET_FIELD_BITPOS (*fp
,
10569 (FIELD_BITPOS (*fp
)
10570 + anonymous_size
* bits_per_byte
10571 - bit_offset
- FIELD_BITSIZE (*fp
)));
10575 /* Get name of field. */
10576 fieldname
= dwarf2_name (die
, cu
);
10577 if (fieldname
== NULL
)
10580 /* The name is already allocated along with this objfile, so we don't
10581 need to duplicate it for the type. */
10582 fp
->name
= fieldname
;
10584 /* Change accessibility for artificial fields (e.g. virtual table
10585 pointer or virtual base class pointer) to private. */
10586 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
10588 FIELD_ARTIFICIAL (*fp
) = 1;
10589 new_field
->accessibility
= DW_ACCESS_private
;
10590 fip
->non_public_fields
= 1;
10593 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
10595 /* C++ static member. */
10597 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
10598 is a declaration, but all versions of G++ as of this writing
10599 (so through at least 3.2.1) incorrectly generate
10600 DW_TAG_variable tags. */
10602 const char *physname
;
10604 /* Get name of field. */
10605 fieldname
= dwarf2_name (die
, cu
);
10606 if (fieldname
== NULL
)
10609 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10611 /* Only create a symbol if this is an external value.
10612 new_symbol checks this and puts the value in the global symbol
10613 table, which we want. If it is not external, new_symbol
10614 will try to put the value in cu->list_in_scope which is wrong. */
10615 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
10617 /* A static const member, not much different than an enum as far as
10618 we're concerned, except that we can support more types. */
10619 new_symbol (die
, NULL
, cu
);
10622 /* Get physical name. */
10623 physname
= dwarf2_physname (fieldname
, die
, cu
);
10625 /* The name is already allocated along with this objfile, so we don't
10626 need to duplicate it for the type. */
10627 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
10628 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10629 FIELD_NAME (*fp
) = fieldname
;
10631 else if (die
->tag
== DW_TAG_inheritance
)
10635 /* C++ base class field. */
10636 if (handle_data_member_location (die
, cu
, &offset
))
10637 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10638 FIELD_BITSIZE (*fp
) = 0;
10639 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10640 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
10641 fip
->nbaseclasses
++;
10645 /* Add a typedef defined in the scope of the FIP's class. */
10648 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
10649 struct dwarf2_cu
*cu
)
10651 struct objfile
*objfile
= cu
->objfile
;
10652 struct typedef_field_list
*new_field
;
10653 struct attribute
*attr
;
10654 struct typedef_field
*fp
;
10655 char *fieldname
= "";
10657 /* Allocate a new field list entry and link it in. */
10658 new_field
= xzalloc (sizeof (*new_field
));
10659 make_cleanup (xfree
, new_field
);
10661 gdb_assert (die
->tag
== DW_TAG_typedef
);
10663 fp
= &new_field
->field
;
10665 /* Get name of field. */
10666 fp
->name
= dwarf2_name (die
, cu
);
10667 if (fp
->name
== NULL
)
10670 fp
->type
= read_type_die (die
, cu
);
10672 new_field
->next
= fip
->typedef_field_list
;
10673 fip
->typedef_field_list
= new_field
;
10674 fip
->typedef_field_list_count
++;
10677 /* Create the vector of fields, and attach it to the type. */
10680 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
10681 struct dwarf2_cu
*cu
)
10683 int nfields
= fip
->nfields
;
10685 /* Record the field count, allocate space for the array of fields,
10686 and create blank accessibility bitfields if necessary. */
10687 TYPE_NFIELDS (type
) = nfields
;
10688 TYPE_FIELDS (type
) = (struct field
*)
10689 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
10690 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
10692 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
10694 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10696 TYPE_FIELD_PRIVATE_BITS (type
) =
10697 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10698 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
10700 TYPE_FIELD_PROTECTED_BITS (type
) =
10701 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10702 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
10704 TYPE_FIELD_IGNORE_BITS (type
) =
10705 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10706 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
10709 /* If the type has baseclasses, allocate and clear a bit vector for
10710 TYPE_FIELD_VIRTUAL_BITS. */
10711 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
10713 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
10714 unsigned char *pointer
;
10716 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10717 pointer
= TYPE_ALLOC (type
, num_bytes
);
10718 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
10719 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
10720 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
10723 /* Copy the saved-up fields into the field vector. Start from the head of
10724 the list, adding to the tail of the field array, so that they end up in
10725 the same order in the array in which they were added to the list. */
10726 while (nfields
-- > 0)
10728 struct nextfield
*fieldp
;
10732 fieldp
= fip
->fields
;
10733 fip
->fields
= fieldp
->next
;
10737 fieldp
= fip
->baseclasses
;
10738 fip
->baseclasses
= fieldp
->next
;
10741 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
10742 switch (fieldp
->accessibility
)
10744 case DW_ACCESS_private
:
10745 if (cu
->language
!= language_ada
)
10746 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
10749 case DW_ACCESS_protected
:
10750 if (cu
->language
!= language_ada
)
10751 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
10754 case DW_ACCESS_public
:
10758 /* Unknown accessibility. Complain and treat it as public. */
10760 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
10761 fieldp
->accessibility
);
10765 if (nfields
< fip
->nbaseclasses
)
10767 switch (fieldp
->virtuality
)
10769 case DW_VIRTUALITY_virtual
:
10770 case DW_VIRTUALITY_pure_virtual
:
10771 if (cu
->language
== language_ada
)
10772 error (_("unexpected virtuality in component of Ada type"));
10773 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
10780 /* Add a member function to the proper fieldlist. */
10783 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
10784 struct type
*type
, struct dwarf2_cu
*cu
)
10786 struct objfile
*objfile
= cu
->objfile
;
10787 struct attribute
*attr
;
10788 struct fnfieldlist
*flp
;
10790 struct fn_field
*fnp
;
10792 struct nextfnfield
*new_fnfield
;
10793 struct type
*this_type
;
10794 enum dwarf_access_attribute accessibility
;
10796 if (cu
->language
== language_ada
)
10797 error (_("unexpected member function in Ada type"));
10799 /* Get name of member function. */
10800 fieldname
= dwarf2_name (die
, cu
);
10801 if (fieldname
== NULL
)
10804 /* Look up member function name in fieldlist. */
10805 for (i
= 0; i
< fip
->nfnfields
; i
++)
10807 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
10811 /* Create new list element if necessary. */
10812 if (i
< fip
->nfnfields
)
10813 flp
= &fip
->fnfieldlists
[i
];
10816 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10818 fip
->fnfieldlists
= (struct fnfieldlist
*)
10819 xrealloc (fip
->fnfieldlists
,
10820 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
10821 * sizeof (struct fnfieldlist
));
10822 if (fip
->nfnfields
== 0)
10823 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
10825 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
10826 flp
->name
= fieldname
;
10829 i
= fip
->nfnfields
++;
10832 /* Create a new member function field and chain it to the field list
10834 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
10835 make_cleanup (xfree
, new_fnfield
);
10836 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
10837 new_fnfield
->next
= flp
->head
;
10838 flp
->head
= new_fnfield
;
10841 /* Fill in the member function field info. */
10842 fnp
= &new_fnfield
->fnfield
;
10844 /* Delay processing of the physname until later. */
10845 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
10847 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
10852 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
10853 fnp
->physname
= physname
? physname
: "";
10856 fnp
->type
= alloc_type (objfile
);
10857 this_type
= read_type_die (die
, cu
);
10858 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
10860 int nparams
= TYPE_NFIELDS (this_type
);
10862 /* TYPE is the domain of this method, and THIS_TYPE is the type
10863 of the method itself (TYPE_CODE_METHOD). */
10864 smash_to_method_type (fnp
->type
, type
,
10865 TYPE_TARGET_TYPE (this_type
),
10866 TYPE_FIELDS (this_type
),
10867 TYPE_NFIELDS (this_type
),
10868 TYPE_VARARGS (this_type
));
10870 /* Handle static member functions.
10871 Dwarf2 has no clean way to discern C++ static and non-static
10872 member functions. G++ helps GDB by marking the first
10873 parameter for non-static member functions (which is the this
10874 pointer) as artificial. We obtain this information from
10875 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10876 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
10877 fnp
->voffset
= VOFFSET_STATIC
;
10880 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
10881 dwarf2_full_name (fieldname
, die
, cu
));
10883 /* Get fcontext from DW_AT_containing_type if present. */
10884 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10885 fnp
->fcontext
= die_containing_type (die
, cu
);
10887 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
10888 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
10890 /* Get accessibility. */
10891 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10893 accessibility
= DW_UNSND (attr
);
10895 accessibility
= dwarf2_default_access_attribute (die
, cu
);
10896 switch (accessibility
)
10898 case DW_ACCESS_private
:
10899 fnp
->is_private
= 1;
10901 case DW_ACCESS_protected
:
10902 fnp
->is_protected
= 1;
10906 /* Check for artificial methods. */
10907 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
10908 if (attr
&& DW_UNSND (attr
) != 0)
10909 fnp
->is_artificial
= 1;
10911 /* Get index in virtual function table if it is a virtual member
10912 function. For older versions of GCC, this is an offset in the
10913 appropriate virtual table, as specified by DW_AT_containing_type.
10914 For everyone else, it is an expression to be evaluated relative
10915 to the object address. */
10917 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
10920 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
10922 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
10924 /* Old-style GCC. */
10925 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
10927 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10928 || (DW_BLOCK (attr
)->size
> 1
10929 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
10930 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
10932 struct dwarf_block blk
;
10935 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10937 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
10938 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
10939 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10940 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
10941 dwarf2_complex_location_expr_complaint ();
10943 fnp
->voffset
/= cu
->header
.addr_size
;
10947 dwarf2_complex_location_expr_complaint ();
10949 if (!fnp
->fcontext
)
10950 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
10952 else if (attr_form_is_section_offset (attr
))
10954 dwarf2_complex_location_expr_complaint ();
10958 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
10964 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10965 if (attr
&& DW_UNSND (attr
))
10967 /* GCC does this, as of 2008-08-25; PR debug/37237. */
10968 complaint (&symfile_complaints
,
10969 _("Member function \"%s\" (offset %d) is virtual "
10970 "but the vtable offset is not specified"),
10971 fieldname
, die
->offset
.sect_off
);
10972 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10973 TYPE_CPLUS_DYNAMIC (type
) = 1;
10978 /* Create the vector of member function fields, and attach it to the type. */
10981 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
10982 struct dwarf2_cu
*cu
)
10984 struct fnfieldlist
*flp
;
10987 if (cu
->language
== language_ada
)
10988 error (_("unexpected member functions in Ada type"));
10990 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10991 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
10992 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
10994 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
10996 struct nextfnfield
*nfp
= flp
->head
;
10997 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
11000 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
11001 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
11002 fn_flp
->fn_fields
= (struct fn_field
*)
11003 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
11004 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
11005 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
11008 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
11011 /* Returns non-zero if NAME is the name of a vtable member in CU's
11012 language, zero otherwise. */
11014 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
11016 static const char vptr
[] = "_vptr";
11017 static const char vtable
[] = "vtable";
11019 /* Look for the C++ and Java forms of the vtable. */
11020 if ((cu
->language
== language_java
11021 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
11022 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
11023 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
11029 /* GCC outputs unnamed structures that are really pointers to member
11030 functions, with the ABI-specified layout. If TYPE describes
11031 such a structure, smash it into a member function type.
11033 GCC shouldn't do this; it should just output pointer to member DIEs.
11034 This is GCC PR debug/28767. */
11037 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
11039 struct type
*pfn_type
, *domain_type
, *new_type
;
11041 /* Check for a structure with no name and two children. */
11042 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
11045 /* Check for __pfn and __delta members. */
11046 if (TYPE_FIELD_NAME (type
, 0) == NULL
11047 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
11048 || TYPE_FIELD_NAME (type
, 1) == NULL
11049 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
11052 /* Find the type of the method. */
11053 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
11054 if (pfn_type
== NULL
11055 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
11056 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
11059 /* Look for the "this" argument. */
11060 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
11061 if (TYPE_NFIELDS (pfn_type
) == 0
11062 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
11063 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
11066 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
11067 new_type
= alloc_type (objfile
);
11068 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
11069 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
11070 TYPE_VARARGS (pfn_type
));
11071 smash_to_methodptr_type (type
, new_type
);
11074 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
11078 producer_is_icc (struct dwarf2_cu
*cu
)
11080 if (!cu
->checked_producer
)
11081 check_producer (cu
);
11083 return cu
->producer_is_icc
;
11086 /* Called when we find the DIE that starts a structure or union scope
11087 (definition) to create a type for the structure or union. Fill in
11088 the type's name and general properties; the members will not be
11089 processed until process_structure_type.
11091 NOTE: we need to call these functions regardless of whether or not the
11092 DIE has a DW_AT_name attribute, since it might be an anonymous
11093 structure or union. This gets the type entered into our set of
11094 user defined types.
11096 However, if the structure is incomplete (an opaque struct/union)
11097 then suppress creating a symbol table entry for it since gdb only
11098 wants to find the one with the complete definition. Note that if
11099 it is complete, we just call new_symbol, which does it's own
11100 checking about whether the struct/union is anonymous or not (and
11101 suppresses creating a symbol table entry itself). */
11103 static struct type
*
11104 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11106 struct objfile
*objfile
= cu
->objfile
;
11108 struct attribute
*attr
;
11111 /* If the definition of this type lives in .debug_types, read that type.
11112 Don't follow DW_AT_specification though, that will take us back up
11113 the chain and we want to go down. */
11114 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11117 struct dwarf2_cu
*type_cu
= cu
;
11118 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11120 /* We could just recurse on read_structure_type, but we need to call
11121 get_die_type to ensure only one type for this DIE is created.
11122 This is important, for example, because for c++ classes we need
11123 TYPE_NAME set which is only done by new_symbol. Blech. */
11124 type
= read_type_die (type_die
, type_cu
);
11126 /* TYPE_CU may not be the same as CU.
11127 Ensure TYPE is recorded in CU's type_hash table. */
11128 return set_die_type (die
, type
, cu
);
11131 type
= alloc_type (objfile
);
11132 INIT_CPLUS_SPECIFIC (type
);
11134 name
= dwarf2_name (die
, cu
);
11137 if (cu
->language
== language_cplus
11138 || cu
->language
== language_java
)
11140 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
11142 /* dwarf2_full_name might have already finished building the DIE's
11143 type. If so, there is no need to continue. */
11144 if (get_die_type (die
, cu
) != NULL
)
11145 return get_die_type (die
, cu
);
11147 TYPE_TAG_NAME (type
) = full_name
;
11148 if (die
->tag
== DW_TAG_structure_type
11149 || die
->tag
== DW_TAG_class_type
)
11150 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11154 /* The name is already allocated along with this objfile, so
11155 we don't need to duplicate it for the type. */
11156 TYPE_TAG_NAME (type
) = (char *) name
;
11157 if (die
->tag
== DW_TAG_class_type
)
11158 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11162 if (die
->tag
== DW_TAG_structure_type
)
11164 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
11166 else if (die
->tag
== DW_TAG_union_type
)
11168 TYPE_CODE (type
) = TYPE_CODE_UNION
;
11172 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
11175 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
11176 TYPE_DECLARED_CLASS (type
) = 1;
11178 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11181 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11185 TYPE_LENGTH (type
) = 0;
11188 if (producer_is_icc (cu
))
11190 /* ICC does not output the required DW_AT_declaration
11191 on incomplete types, but gives them a size of zero. */
11194 TYPE_STUB_SUPPORTED (type
) = 1;
11196 if (die_is_declaration (die
, cu
))
11197 TYPE_STUB (type
) = 1;
11198 else if (attr
== NULL
&& die
->child
== NULL
11199 && producer_is_realview (cu
->producer
))
11200 /* RealView does not output the required DW_AT_declaration
11201 on incomplete types. */
11202 TYPE_STUB (type
) = 1;
11204 /* We need to add the type field to the die immediately so we don't
11205 infinitely recurse when dealing with pointers to the structure
11206 type within the structure itself. */
11207 set_die_type (die
, type
, cu
);
11209 /* set_die_type should be already done. */
11210 set_descriptive_type (type
, die
, cu
);
11215 /* Finish creating a structure or union type, including filling in
11216 its members and creating a symbol for it. */
11219 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11221 struct objfile
*objfile
= cu
->objfile
;
11222 struct die_info
*child_die
= die
->child
;
11225 type
= get_die_type (die
, cu
);
11227 type
= read_structure_type (die
, cu
);
11229 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
11231 struct field_info fi
;
11232 struct die_info
*child_die
;
11233 VEC (symbolp
) *template_args
= NULL
;
11234 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
11236 memset (&fi
, 0, sizeof (struct field_info
));
11238 child_die
= die
->child
;
11240 while (child_die
&& child_die
->tag
)
11242 if (child_die
->tag
== DW_TAG_member
11243 || child_die
->tag
== DW_TAG_variable
)
11245 /* NOTE: carlton/2002-11-05: A C++ static data member
11246 should be a DW_TAG_member that is a declaration, but
11247 all versions of G++ as of this writing (so through at
11248 least 3.2.1) incorrectly generate DW_TAG_variable
11249 tags for them instead. */
11250 dwarf2_add_field (&fi
, child_die
, cu
);
11252 else if (child_die
->tag
== DW_TAG_subprogram
)
11254 /* C++ member function. */
11255 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
11257 else if (child_die
->tag
== DW_TAG_inheritance
)
11259 /* C++ base class field. */
11260 dwarf2_add_field (&fi
, child_die
, cu
);
11262 else if (child_die
->tag
== DW_TAG_typedef
)
11263 dwarf2_add_typedef (&fi
, child_die
, cu
);
11264 else if (child_die
->tag
== DW_TAG_template_type_param
11265 || child_die
->tag
== DW_TAG_template_value_param
)
11267 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11270 VEC_safe_push (symbolp
, template_args
, arg
);
11273 child_die
= sibling_die (child_die
);
11276 /* Attach template arguments to type. */
11277 if (! VEC_empty (symbolp
, template_args
))
11279 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11280 TYPE_N_TEMPLATE_ARGUMENTS (type
)
11281 = VEC_length (symbolp
, template_args
);
11282 TYPE_TEMPLATE_ARGUMENTS (type
)
11283 = obstack_alloc (&objfile
->objfile_obstack
,
11284 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11285 * sizeof (struct symbol
*)));
11286 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
11287 VEC_address (symbolp
, template_args
),
11288 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11289 * sizeof (struct symbol
*)));
11290 VEC_free (symbolp
, template_args
);
11293 /* Attach fields and member functions to the type. */
11295 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
11298 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
11300 /* Get the type which refers to the base class (possibly this
11301 class itself) which contains the vtable pointer for the current
11302 class from the DW_AT_containing_type attribute. This use of
11303 DW_AT_containing_type is a GNU extension. */
11305 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
11307 struct type
*t
= die_containing_type (die
, cu
);
11309 TYPE_VPTR_BASETYPE (type
) = t
;
11314 /* Our own class provides vtbl ptr. */
11315 for (i
= TYPE_NFIELDS (t
) - 1;
11316 i
>= TYPE_N_BASECLASSES (t
);
11319 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
11321 if (is_vtable_name (fieldname
, cu
))
11323 TYPE_VPTR_FIELDNO (type
) = i
;
11328 /* Complain if virtual function table field not found. */
11329 if (i
< TYPE_N_BASECLASSES (t
))
11330 complaint (&symfile_complaints
,
11331 _("virtual function table pointer "
11332 "not found when defining class '%s'"),
11333 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
11338 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
11341 else if (cu
->producer
11342 && strncmp (cu
->producer
,
11343 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
11345 /* The IBM XLC compiler does not provide direct indication
11346 of the containing type, but the vtable pointer is
11347 always named __vfp. */
11351 for (i
= TYPE_NFIELDS (type
) - 1;
11352 i
>= TYPE_N_BASECLASSES (type
);
11355 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
11357 TYPE_VPTR_FIELDNO (type
) = i
;
11358 TYPE_VPTR_BASETYPE (type
) = type
;
11365 /* Copy fi.typedef_field_list linked list elements content into the
11366 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
11367 if (fi
.typedef_field_list
)
11369 int i
= fi
.typedef_field_list_count
;
11371 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11372 TYPE_TYPEDEF_FIELD_ARRAY (type
)
11373 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
11374 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
11376 /* Reverse the list order to keep the debug info elements order. */
11379 struct typedef_field
*dest
, *src
;
11381 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
11382 src
= &fi
.typedef_field_list
->field
;
11383 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
11388 do_cleanups (back_to
);
11390 if (HAVE_CPLUS_STRUCT (type
))
11391 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
11394 quirk_gcc_member_function_pointer (type
, objfile
);
11396 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
11397 snapshots) has been known to create a die giving a declaration
11398 for a class that has, as a child, a die giving a definition for a
11399 nested class. So we have to process our children even if the
11400 current die is a declaration. Normally, of course, a declaration
11401 won't have any children at all. */
11403 while (child_die
!= NULL
&& child_die
->tag
)
11405 if (child_die
->tag
== DW_TAG_member
11406 || child_die
->tag
== DW_TAG_variable
11407 || child_die
->tag
== DW_TAG_inheritance
11408 || child_die
->tag
== DW_TAG_template_value_param
11409 || child_die
->tag
== DW_TAG_template_type_param
)
11414 process_die (child_die
, cu
);
11416 child_die
= sibling_die (child_die
);
11419 /* Do not consider external references. According to the DWARF standard,
11420 these DIEs are identified by the fact that they have no byte_size
11421 attribute, and a declaration attribute. */
11422 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
11423 || !die_is_declaration (die
, cu
))
11424 new_symbol (die
, type
, cu
);
11427 /* Given a DW_AT_enumeration_type die, set its type. We do not
11428 complete the type's fields yet, or create any symbols. */
11430 static struct type
*
11431 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11433 struct objfile
*objfile
= cu
->objfile
;
11435 struct attribute
*attr
;
11438 /* If the definition of this type lives in .debug_types, read that type.
11439 Don't follow DW_AT_specification though, that will take us back up
11440 the chain and we want to go down. */
11441 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11444 struct dwarf2_cu
*type_cu
= cu
;
11445 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11447 type
= read_type_die (type_die
, type_cu
);
11449 /* TYPE_CU may not be the same as CU.
11450 Ensure TYPE is recorded in CU's type_hash table. */
11451 return set_die_type (die
, type
, cu
);
11454 type
= alloc_type (objfile
);
11456 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
11457 name
= dwarf2_full_name (NULL
, die
, cu
);
11459 TYPE_TAG_NAME (type
) = (char *) name
;
11461 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11464 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11468 TYPE_LENGTH (type
) = 0;
11471 /* The enumeration DIE can be incomplete. In Ada, any type can be
11472 declared as private in the package spec, and then defined only
11473 inside the package body. Such types are known as Taft Amendment
11474 Types. When another package uses such a type, an incomplete DIE
11475 may be generated by the compiler. */
11476 if (die_is_declaration (die
, cu
))
11477 TYPE_STUB (type
) = 1;
11479 return set_die_type (die
, type
, cu
);
11482 /* Given a pointer to a die which begins an enumeration, process all
11483 the dies that define the members of the enumeration, and create the
11484 symbol for the enumeration type.
11486 NOTE: We reverse the order of the element list. */
11489 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11491 struct type
*this_type
;
11493 this_type
= get_die_type (die
, cu
);
11494 if (this_type
== NULL
)
11495 this_type
= read_enumeration_type (die
, cu
);
11497 if (die
->child
!= NULL
)
11499 struct die_info
*child_die
;
11500 struct symbol
*sym
;
11501 struct field
*fields
= NULL
;
11502 int num_fields
= 0;
11503 int unsigned_enum
= 1;
11508 child_die
= die
->child
;
11509 while (child_die
&& child_die
->tag
)
11511 if (child_die
->tag
!= DW_TAG_enumerator
)
11513 process_die (child_die
, cu
);
11517 name
= dwarf2_name (child_die
, cu
);
11520 sym
= new_symbol (child_die
, this_type
, cu
);
11521 if (SYMBOL_VALUE (sym
) < 0)
11526 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
11529 mask
|= SYMBOL_VALUE (sym
);
11531 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
11533 fields
= (struct field
*)
11535 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
11536 * sizeof (struct field
));
11539 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
11540 FIELD_TYPE (fields
[num_fields
]) = NULL
;
11541 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
11542 FIELD_BITSIZE (fields
[num_fields
]) = 0;
11548 child_die
= sibling_die (child_die
);
11553 TYPE_NFIELDS (this_type
) = num_fields
;
11554 TYPE_FIELDS (this_type
) = (struct field
*)
11555 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
11556 memcpy (TYPE_FIELDS (this_type
), fields
,
11557 sizeof (struct field
) * num_fields
);
11561 TYPE_UNSIGNED (this_type
) = 1;
11563 TYPE_FLAG_ENUM (this_type
) = 1;
11566 /* If we are reading an enum from a .debug_types unit, and the enum
11567 is a declaration, and the enum is not the signatured type in the
11568 unit, then we do not want to add a symbol for it. Adding a
11569 symbol would in some cases obscure the true definition of the
11570 enum, giving users an incomplete type when the definition is
11571 actually available. Note that we do not want to do this for all
11572 enums which are just declarations, because C++0x allows forward
11573 enum declarations. */
11574 if (cu
->per_cu
->is_debug_types
11575 && die_is_declaration (die
, cu
))
11577 struct signatured_type
*sig_type
;
11580 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
11581 cu
->per_cu
->info_or_types_section
,
11582 cu
->per_cu
->offset
);
11583 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
11584 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
11588 new_symbol (die
, this_type
, cu
);
11591 /* Extract all information from a DW_TAG_array_type DIE and put it in
11592 the DIE's type field. For now, this only handles one dimensional
11595 static struct type
*
11596 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11598 struct objfile
*objfile
= cu
->objfile
;
11599 struct die_info
*child_die
;
11601 struct type
*element_type
, *range_type
, *index_type
;
11602 struct type
**range_types
= NULL
;
11603 struct attribute
*attr
;
11605 struct cleanup
*back_to
;
11608 element_type
= die_type (die
, cu
);
11610 /* The die_type call above may have already set the type for this DIE. */
11611 type
= get_die_type (die
, cu
);
11615 /* Irix 6.2 native cc creates array types without children for
11616 arrays with unspecified length. */
11617 if (die
->child
== NULL
)
11619 index_type
= objfile_type (objfile
)->builtin_int
;
11620 range_type
= create_range_type (NULL
, index_type
, 0, -1);
11621 type
= create_array_type (NULL
, element_type
, range_type
);
11622 return set_die_type (die
, type
, cu
);
11625 back_to
= make_cleanup (null_cleanup
, NULL
);
11626 child_die
= die
->child
;
11627 while (child_die
&& child_die
->tag
)
11629 if (child_die
->tag
== DW_TAG_subrange_type
)
11631 struct type
*child_type
= read_type_die (child_die
, cu
);
11633 if (child_type
!= NULL
)
11635 /* The range type was succesfully read. Save it for the
11636 array type creation. */
11637 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
11639 range_types
= (struct type
**)
11640 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
11641 * sizeof (struct type
*));
11643 make_cleanup (free_current_contents
, &range_types
);
11645 range_types
[ndim
++] = child_type
;
11648 child_die
= sibling_die (child_die
);
11651 /* Dwarf2 dimensions are output from left to right, create the
11652 necessary array types in backwards order. */
11654 type
= element_type
;
11656 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
11661 type
= create_array_type (NULL
, type
, range_types
[i
++]);
11666 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
11669 /* Understand Dwarf2 support for vector types (like they occur on
11670 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
11671 array type. This is not part of the Dwarf2/3 standard yet, but a
11672 custom vendor extension. The main difference between a regular
11673 array and the vector variant is that vectors are passed by value
11675 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
11677 make_vector_type (type
);
11679 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
11680 implementation may choose to implement triple vectors using this
11682 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11685 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
11686 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11688 complaint (&symfile_complaints
,
11689 _("DW_AT_byte_size for array type smaller "
11690 "than the total size of elements"));
11693 name
= dwarf2_name (die
, cu
);
11695 TYPE_NAME (type
) = name
;
11697 /* Install the type in the die. */
11698 set_die_type (die
, type
, cu
);
11700 /* set_die_type should be already done. */
11701 set_descriptive_type (type
, die
, cu
);
11703 do_cleanups (back_to
);
11708 static enum dwarf_array_dim_ordering
11709 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
11711 struct attribute
*attr
;
11713 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
11715 if (attr
) return DW_SND (attr
);
11717 /* GNU F77 is a special case, as at 08/2004 array type info is the
11718 opposite order to the dwarf2 specification, but data is still
11719 laid out as per normal fortran.
11721 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
11722 version checking. */
11724 if (cu
->language
== language_fortran
11725 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
11727 return DW_ORD_row_major
;
11730 switch (cu
->language_defn
->la_array_ordering
)
11732 case array_column_major
:
11733 return DW_ORD_col_major
;
11734 case array_row_major
:
11736 return DW_ORD_row_major
;
11740 /* Extract all information from a DW_TAG_set_type DIE and put it in
11741 the DIE's type field. */
11743 static struct type
*
11744 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11746 struct type
*domain_type
, *set_type
;
11747 struct attribute
*attr
;
11749 domain_type
= die_type (die
, cu
);
11751 /* The die_type call above may have already set the type for this DIE. */
11752 set_type
= get_die_type (die
, cu
);
11756 set_type
= create_set_type (NULL
, domain_type
);
11758 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11760 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
11762 return set_die_type (die
, set_type
, cu
);
11765 /* A helper for read_common_block that creates a locexpr baton.
11766 SYM is the symbol which we are marking as computed.
11767 COMMON_DIE is the DIE for the common block.
11768 COMMON_LOC is the location expression attribute for the common
11770 MEMBER_LOC is the location expression attribute for the particular
11771 member of the common block that we are processing.
11772 CU is the CU from which the above come. */
11775 mark_common_block_symbol_computed (struct symbol
*sym
,
11776 struct die_info
*common_die
,
11777 struct attribute
*common_loc
,
11778 struct attribute
*member_loc
,
11779 struct dwarf2_cu
*cu
)
11781 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11782 struct dwarf2_locexpr_baton
*baton
;
11784 unsigned int cu_off
;
11785 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
11786 LONGEST offset
= 0;
11788 gdb_assert (common_loc
&& member_loc
);
11789 gdb_assert (attr_form_is_block (common_loc
));
11790 gdb_assert (attr_form_is_block (member_loc
)
11791 || attr_form_is_constant (member_loc
));
11793 baton
= obstack_alloc (&objfile
->objfile_obstack
,
11794 sizeof (struct dwarf2_locexpr_baton
));
11795 baton
->per_cu
= cu
->per_cu
;
11796 gdb_assert (baton
->per_cu
);
11798 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
11800 if (attr_form_is_constant (member_loc
))
11802 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
11803 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
11806 baton
->size
+= DW_BLOCK (member_loc
)->size
;
11808 ptr
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
11811 *ptr
++ = DW_OP_call4
;
11812 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
11813 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
11816 if (attr_form_is_constant (member_loc
))
11818 *ptr
++ = DW_OP_addr
;
11819 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
11820 ptr
+= cu
->header
.addr_size
;
11824 /* We have to copy the data here, because DW_OP_call4 will only
11825 use a DW_AT_location attribute. */
11826 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
11827 ptr
+= DW_BLOCK (member_loc
)->size
;
11830 *ptr
++ = DW_OP_plus
;
11831 gdb_assert (ptr
- baton
->data
== baton
->size
);
11833 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11834 SYMBOL_LOCATION_BATON (sym
) = baton
;
11835 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11838 /* Create appropriate locally-scoped variables for all the
11839 DW_TAG_common_block entries. Also create a struct common_block
11840 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
11841 is used to sepate the common blocks name namespace from regular
11845 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
11847 struct attribute
*attr
;
11849 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11852 /* Support the .debug_loc offsets. */
11853 if (attr_form_is_block (attr
))
11857 else if (attr_form_is_section_offset (attr
))
11859 dwarf2_complex_location_expr_complaint ();
11864 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11865 "common block member");
11870 if (die
->child
!= NULL
)
11872 struct objfile
*objfile
= cu
->objfile
;
11873 struct die_info
*child_die
;
11874 size_t n_entries
= 0, size
;
11875 struct common_block
*common_block
;
11876 struct symbol
*sym
;
11878 for (child_die
= die
->child
;
11879 child_die
&& child_die
->tag
;
11880 child_die
= sibling_die (child_die
))
11883 size
= (sizeof (struct common_block
)
11884 + (n_entries
- 1) * sizeof (struct symbol
*));
11885 common_block
= obstack_alloc (&objfile
->objfile_obstack
, size
);
11886 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
11887 common_block
->n_entries
= 0;
11889 for (child_die
= die
->child
;
11890 child_die
&& child_die
->tag
;
11891 child_die
= sibling_die (child_die
))
11893 /* Create the symbol in the DW_TAG_common_block block in the current
11895 sym
= new_symbol (child_die
, NULL
, cu
);
11898 struct attribute
*member_loc
;
11900 common_block
->contents
[common_block
->n_entries
++] = sym
;
11902 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
11906 /* GDB has handled this for a long time, but it is
11907 not specified by DWARF. It seems to have been
11908 emitted by gfortran at least as recently as:
11909 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
11910 complaint (&symfile_complaints
,
11911 _("Variable in common block has "
11912 "DW_AT_data_member_location "
11913 "- DIE at 0x%x [in module %s]"),
11914 child_die
->offset
.sect_off
, cu
->objfile
->name
);
11916 if (attr_form_is_section_offset (member_loc
))
11917 dwarf2_complex_location_expr_complaint ();
11918 else if (attr_form_is_constant (member_loc
)
11919 || attr_form_is_block (member_loc
))
11922 mark_common_block_symbol_computed (sym
, die
, attr
,
11926 dwarf2_complex_location_expr_complaint ();
11931 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
11932 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
11936 /* Create a type for a C++ namespace. */
11938 static struct type
*
11939 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11941 struct objfile
*objfile
= cu
->objfile
;
11942 const char *previous_prefix
, *name
;
11946 /* For extensions, reuse the type of the original namespace. */
11947 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
11949 struct die_info
*ext_die
;
11950 struct dwarf2_cu
*ext_cu
= cu
;
11952 ext_die
= dwarf2_extension (die
, &ext_cu
);
11953 type
= read_type_die (ext_die
, ext_cu
);
11955 /* EXT_CU may not be the same as CU.
11956 Ensure TYPE is recorded in CU's type_hash table. */
11957 return set_die_type (die
, type
, cu
);
11960 name
= namespace_name (die
, &is_anonymous
, cu
);
11962 /* Now build the name of the current namespace. */
11964 previous_prefix
= determine_prefix (die
, cu
);
11965 if (previous_prefix
[0] != '\0')
11966 name
= typename_concat (&objfile
->objfile_obstack
,
11967 previous_prefix
, name
, 0, cu
);
11969 /* Create the type. */
11970 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
11972 TYPE_NAME (type
) = (char *) name
;
11973 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
11975 return set_die_type (die
, type
, cu
);
11978 /* Read a C++ namespace. */
11981 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
11983 struct objfile
*objfile
= cu
->objfile
;
11986 /* Add a symbol associated to this if we haven't seen the namespace
11987 before. Also, add a using directive if it's an anonymous
11990 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
11994 type
= read_type_die (die
, cu
);
11995 new_symbol (die
, type
, cu
);
11997 namespace_name (die
, &is_anonymous
, cu
);
12000 const char *previous_prefix
= determine_prefix (die
, cu
);
12002 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
12003 NULL
, NULL
, &objfile
->objfile_obstack
);
12007 if (die
->child
!= NULL
)
12009 struct die_info
*child_die
= die
->child
;
12011 while (child_die
&& child_die
->tag
)
12013 process_die (child_die
, cu
);
12014 child_die
= sibling_die (child_die
);
12019 /* Read a Fortran module as type. This DIE can be only a declaration used for
12020 imported module. Still we need that type as local Fortran "use ... only"
12021 declaration imports depend on the created type in determine_prefix. */
12023 static struct type
*
12024 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12026 struct objfile
*objfile
= cu
->objfile
;
12030 module_name
= dwarf2_name (die
, cu
);
12032 complaint (&symfile_complaints
,
12033 _("DW_TAG_module has no name, offset 0x%x"),
12034 die
->offset
.sect_off
);
12035 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
12037 /* determine_prefix uses TYPE_TAG_NAME. */
12038 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
12040 return set_die_type (die
, type
, cu
);
12043 /* Read a Fortran module. */
12046 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
12048 struct die_info
*child_die
= die
->child
;
12050 while (child_die
&& child_die
->tag
)
12052 process_die (child_die
, cu
);
12053 child_die
= sibling_die (child_die
);
12057 /* Return the name of the namespace represented by DIE. Set
12058 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
12061 static const char *
12062 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
12064 struct die_info
*current_die
;
12065 const char *name
= NULL
;
12067 /* Loop through the extensions until we find a name. */
12069 for (current_die
= die
;
12070 current_die
!= NULL
;
12071 current_die
= dwarf2_extension (die
, &cu
))
12073 name
= dwarf2_name (current_die
, cu
);
12078 /* Is it an anonymous namespace? */
12080 *is_anonymous
= (name
== NULL
);
12082 name
= CP_ANONYMOUS_NAMESPACE_STR
;
12087 /* Extract all information from a DW_TAG_pointer_type DIE and add to
12088 the user defined type vector. */
12090 static struct type
*
12091 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12093 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
12094 struct comp_unit_head
*cu_header
= &cu
->header
;
12096 struct attribute
*attr_byte_size
;
12097 struct attribute
*attr_address_class
;
12098 int byte_size
, addr_class
;
12099 struct type
*target_type
;
12101 target_type
= die_type (die
, cu
);
12103 /* The die_type call above may have already set the type for this DIE. */
12104 type
= get_die_type (die
, cu
);
12108 type
= lookup_pointer_type (target_type
);
12110 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12111 if (attr_byte_size
)
12112 byte_size
= DW_UNSND (attr_byte_size
);
12114 byte_size
= cu_header
->addr_size
;
12116 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
12117 if (attr_address_class
)
12118 addr_class
= DW_UNSND (attr_address_class
);
12120 addr_class
= DW_ADDR_none
;
12122 /* If the pointer size or address class is different than the
12123 default, create a type variant marked as such and set the
12124 length accordingly. */
12125 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
12127 if (gdbarch_address_class_type_flags_p (gdbarch
))
12131 type_flags
= gdbarch_address_class_type_flags
12132 (gdbarch
, byte_size
, addr_class
);
12133 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
12135 type
= make_type_with_address_space (type
, type_flags
);
12137 else if (TYPE_LENGTH (type
) != byte_size
)
12139 complaint (&symfile_complaints
,
12140 _("invalid pointer size %d"), byte_size
);
12144 /* Should we also complain about unhandled address classes? */
12148 TYPE_LENGTH (type
) = byte_size
;
12149 return set_die_type (die
, type
, cu
);
12152 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
12153 the user defined type vector. */
12155 static struct type
*
12156 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12159 struct type
*to_type
;
12160 struct type
*domain
;
12162 to_type
= die_type (die
, cu
);
12163 domain
= die_containing_type (die
, cu
);
12165 /* The calls above may have already set the type for this DIE. */
12166 type
= get_die_type (die
, cu
);
12170 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
12171 type
= lookup_methodptr_type (to_type
);
12173 type
= lookup_memberptr_type (to_type
, domain
);
12175 return set_die_type (die
, type
, cu
);
12178 /* Extract all information from a DW_TAG_reference_type DIE and add to
12179 the user defined type vector. */
12181 static struct type
*
12182 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12184 struct comp_unit_head
*cu_header
= &cu
->header
;
12185 struct type
*type
, *target_type
;
12186 struct attribute
*attr
;
12188 target_type
= die_type (die
, cu
);
12190 /* The die_type call above may have already set the type for this DIE. */
12191 type
= get_die_type (die
, cu
);
12195 type
= lookup_reference_type (target_type
);
12196 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12199 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12203 TYPE_LENGTH (type
) = cu_header
->addr_size
;
12205 return set_die_type (die
, type
, cu
);
12208 static struct type
*
12209 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12211 struct type
*base_type
, *cv_type
;
12213 base_type
= die_type (die
, cu
);
12215 /* The die_type call above may have already set the type for this DIE. */
12216 cv_type
= get_die_type (die
, cu
);
12220 /* In case the const qualifier is applied to an array type, the element type
12221 is so qualified, not the array type (section 6.7.3 of C99). */
12222 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
12224 struct type
*el_type
, *inner_array
;
12226 base_type
= copy_type (base_type
);
12227 inner_array
= base_type
;
12229 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
12231 TYPE_TARGET_TYPE (inner_array
) =
12232 copy_type (TYPE_TARGET_TYPE (inner_array
));
12233 inner_array
= TYPE_TARGET_TYPE (inner_array
);
12236 el_type
= TYPE_TARGET_TYPE (inner_array
);
12237 TYPE_TARGET_TYPE (inner_array
) =
12238 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
12240 return set_die_type (die
, base_type
, cu
);
12243 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
12244 return set_die_type (die
, cv_type
, cu
);
12247 static struct type
*
12248 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12250 struct type
*base_type
, *cv_type
;
12252 base_type
= die_type (die
, cu
);
12254 /* The die_type call above may have already set the type for this DIE. */
12255 cv_type
= get_die_type (die
, cu
);
12259 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
12260 return set_die_type (die
, cv_type
, cu
);
12263 /* Extract all information from a DW_TAG_string_type DIE and add to
12264 the user defined type vector. It isn't really a user defined type,
12265 but it behaves like one, with other DIE's using an AT_user_def_type
12266 attribute to reference it. */
12268 static struct type
*
12269 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12271 struct objfile
*objfile
= cu
->objfile
;
12272 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12273 struct type
*type
, *range_type
, *index_type
, *char_type
;
12274 struct attribute
*attr
;
12275 unsigned int length
;
12277 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
12280 length
= DW_UNSND (attr
);
12284 /* Check for the DW_AT_byte_size attribute. */
12285 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12288 length
= DW_UNSND (attr
);
12296 index_type
= objfile_type (objfile
)->builtin_int
;
12297 range_type
= create_range_type (NULL
, index_type
, 1, length
);
12298 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
12299 type
= create_string_type (NULL
, char_type
, range_type
);
12301 return set_die_type (die
, type
, cu
);
12304 /* Handle DIES due to C code like:
12308 int (*funcp)(int a, long l);
12312 ('funcp' generates a DW_TAG_subroutine_type DIE). */
12314 static struct type
*
12315 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12317 struct objfile
*objfile
= cu
->objfile
;
12318 struct type
*type
; /* Type that this function returns. */
12319 struct type
*ftype
; /* Function that returns above type. */
12320 struct attribute
*attr
;
12322 type
= die_type (die
, cu
);
12324 /* The die_type call above may have already set the type for this DIE. */
12325 ftype
= get_die_type (die
, cu
);
12329 ftype
= lookup_function_type (type
);
12331 /* All functions in C++, Pascal and Java have prototypes. */
12332 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
12333 if ((attr
&& (DW_UNSND (attr
) != 0))
12334 || cu
->language
== language_cplus
12335 || cu
->language
== language_java
12336 || cu
->language
== language_pascal
)
12337 TYPE_PROTOTYPED (ftype
) = 1;
12338 else if (producer_is_realview (cu
->producer
))
12339 /* RealView does not emit DW_AT_prototyped. We can not
12340 distinguish prototyped and unprototyped functions; default to
12341 prototyped, since that is more common in modern code (and
12342 RealView warns about unprototyped functions). */
12343 TYPE_PROTOTYPED (ftype
) = 1;
12345 /* Store the calling convention in the type if it's available in
12346 the subroutine die. Otherwise set the calling convention to
12347 the default value DW_CC_normal. */
12348 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
12350 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
12351 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
12352 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
12354 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
12356 /* We need to add the subroutine type to the die immediately so
12357 we don't infinitely recurse when dealing with parameters
12358 declared as the same subroutine type. */
12359 set_die_type (die
, ftype
, cu
);
12361 if (die
->child
!= NULL
)
12363 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
12364 struct die_info
*child_die
;
12365 int nparams
, iparams
;
12367 /* Count the number of parameters.
12368 FIXME: GDB currently ignores vararg functions, but knows about
12369 vararg member functions. */
12371 child_die
= die
->child
;
12372 while (child_die
&& child_die
->tag
)
12374 if (child_die
->tag
== DW_TAG_formal_parameter
)
12376 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
12377 TYPE_VARARGS (ftype
) = 1;
12378 child_die
= sibling_die (child_die
);
12381 /* Allocate storage for parameters and fill them in. */
12382 TYPE_NFIELDS (ftype
) = nparams
;
12383 TYPE_FIELDS (ftype
) = (struct field
*)
12384 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
12386 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
12387 even if we error out during the parameters reading below. */
12388 for (iparams
= 0; iparams
< nparams
; iparams
++)
12389 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
12392 child_die
= die
->child
;
12393 while (child_die
&& child_die
->tag
)
12395 if (child_die
->tag
== DW_TAG_formal_parameter
)
12397 struct type
*arg_type
;
12399 /* DWARF version 2 has no clean way to discern C++
12400 static and non-static member functions. G++ helps
12401 GDB by marking the first parameter for non-static
12402 member functions (which is the this pointer) as
12403 artificial. We pass this information to
12404 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
12406 DWARF version 3 added DW_AT_object_pointer, which GCC
12407 4.5 does not yet generate. */
12408 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
12410 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
12413 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
12415 /* GCC/43521: In java, the formal parameter
12416 "this" is sometimes not marked with DW_AT_artificial. */
12417 if (cu
->language
== language_java
)
12419 const char *name
= dwarf2_name (child_die
, cu
);
12421 if (name
&& !strcmp (name
, "this"))
12422 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
12425 arg_type
= die_type (child_die
, cu
);
12427 /* RealView does not mark THIS as const, which the testsuite
12428 expects. GCC marks THIS as const in method definitions,
12429 but not in the class specifications (GCC PR 43053). */
12430 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
12431 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
12434 struct dwarf2_cu
*arg_cu
= cu
;
12435 const char *name
= dwarf2_name (child_die
, cu
);
12437 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
12440 /* If the compiler emits this, use it. */
12441 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
12444 else if (name
&& strcmp (name
, "this") == 0)
12445 /* Function definitions will have the argument names. */
12447 else if (name
== NULL
&& iparams
== 0)
12448 /* Declarations may not have the names, so like
12449 elsewhere in GDB, assume an artificial first
12450 argument is "this". */
12454 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
12458 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
12461 child_die
= sibling_die (child_die
);
12468 static struct type
*
12469 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
12471 struct objfile
*objfile
= cu
->objfile
;
12472 const char *name
= NULL
;
12473 struct type
*this_type
, *target_type
;
12475 name
= dwarf2_full_name (NULL
, die
, cu
);
12476 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
12477 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
12478 TYPE_NAME (this_type
) = (char *) name
;
12479 set_die_type (die
, this_type
, cu
);
12480 target_type
= die_type (die
, cu
);
12481 if (target_type
!= this_type
)
12482 TYPE_TARGET_TYPE (this_type
) = target_type
;
12485 /* Self-referential typedefs are, it seems, not allowed by the DWARF
12486 spec and cause infinite loops in GDB. */
12487 complaint (&symfile_complaints
,
12488 _("Self-referential DW_TAG_typedef "
12489 "- DIE at 0x%x [in module %s]"),
12490 die
->offset
.sect_off
, objfile
->name
);
12491 TYPE_TARGET_TYPE (this_type
) = NULL
;
12496 /* Find a representation of a given base type and install
12497 it in the TYPE field of the die. */
12499 static struct type
*
12500 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12502 struct objfile
*objfile
= cu
->objfile
;
12504 struct attribute
*attr
;
12505 int encoding
= 0, size
= 0;
12507 enum type_code code
= TYPE_CODE_INT
;
12508 int type_flags
= 0;
12509 struct type
*target_type
= NULL
;
12511 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
12514 encoding
= DW_UNSND (attr
);
12516 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12519 size
= DW_UNSND (attr
);
12521 name
= dwarf2_name (die
, cu
);
12524 complaint (&symfile_complaints
,
12525 _("DW_AT_name missing from DW_TAG_base_type"));
12530 case DW_ATE_address
:
12531 /* Turn DW_ATE_address into a void * pointer. */
12532 code
= TYPE_CODE_PTR
;
12533 type_flags
|= TYPE_FLAG_UNSIGNED
;
12534 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
12536 case DW_ATE_boolean
:
12537 code
= TYPE_CODE_BOOL
;
12538 type_flags
|= TYPE_FLAG_UNSIGNED
;
12540 case DW_ATE_complex_float
:
12541 code
= TYPE_CODE_COMPLEX
;
12542 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
12544 case DW_ATE_decimal_float
:
12545 code
= TYPE_CODE_DECFLOAT
;
12548 code
= TYPE_CODE_FLT
;
12550 case DW_ATE_signed
:
12552 case DW_ATE_unsigned
:
12553 type_flags
|= TYPE_FLAG_UNSIGNED
;
12554 if (cu
->language
== language_fortran
12556 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
12557 code
= TYPE_CODE_CHAR
;
12559 case DW_ATE_signed_char
:
12560 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12561 || cu
->language
== language_pascal
12562 || cu
->language
== language_fortran
)
12563 code
= TYPE_CODE_CHAR
;
12565 case DW_ATE_unsigned_char
:
12566 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12567 || cu
->language
== language_pascal
12568 || cu
->language
== language_fortran
)
12569 code
= TYPE_CODE_CHAR
;
12570 type_flags
|= TYPE_FLAG_UNSIGNED
;
12573 /* We just treat this as an integer and then recognize the
12574 type by name elsewhere. */
12578 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
12579 dwarf_type_encoding_name (encoding
));
12583 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
12584 TYPE_NAME (type
) = name
;
12585 TYPE_TARGET_TYPE (type
) = target_type
;
12587 if (name
&& strcmp (name
, "char") == 0)
12588 TYPE_NOSIGN (type
) = 1;
12590 return set_die_type (die
, type
, cu
);
12593 /* Read the given DW_AT_subrange DIE. */
12595 static struct type
*
12596 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12598 struct type
*base_type
;
12599 struct type
*range_type
;
12600 struct attribute
*attr
;
12602 int low_default_is_valid
;
12604 LONGEST negative_mask
;
12606 base_type
= die_type (die
, cu
);
12607 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
12608 check_typedef (base_type
);
12610 /* The die_type call above may have already set the type for this DIE. */
12611 range_type
= get_die_type (die
, cu
);
12615 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
12616 omitting DW_AT_lower_bound. */
12617 switch (cu
->language
)
12620 case language_cplus
:
12622 low_default_is_valid
= 1;
12624 case language_fortran
:
12626 low_default_is_valid
= 1;
12629 case language_java
:
12630 case language_objc
:
12632 low_default_is_valid
= (cu
->header
.version
>= 4);
12636 case language_pascal
:
12638 low_default_is_valid
= (cu
->header
.version
>= 4);
12642 low_default_is_valid
= 0;
12646 /* FIXME: For variable sized arrays either of these could be
12647 a variable rather than a constant value. We'll allow it,
12648 but we don't know how to handle it. */
12649 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
12651 low
= dwarf2_get_attr_constant_value (attr
, low
);
12652 else if (!low_default_is_valid
)
12653 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
12654 "- DIE at 0x%x [in module %s]"),
12655 die
->offset
.sect_off
, cu
->objfile
->name
);
12657 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
12660 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
12662 /* GCC encodes arrays with unspecified or dynamic length
12663 with a DW_FORM_block1 attribute or a reference attribute.
12664 FIXME: GDB does not yet know how to handle dynamic
12665 arrays properly, treat them as arrays with unspecified
12668 FIXME: jimb/2003-09-22: GDB does not really know
12669 how to handle arrays of unspecified length
12670 either; we just represent them as zero-length
12671 arrays. Choose an appropriate upper bound given
12672 the lower bound we've computed above. */
12676 high
= dwarf2_get_attr_constant_value (attr
, 1);
12680 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
12683 int count
= dwarf2_get_attr_constant_value (attr
, 1);
12684 high
= low
+ count
- 1;
12688 /* Unspecified array length. */
12693 /* Dwarf-2 specifications explicitly allows to create subrange types
12694 without specifying a base type.
12695 In that case, the base type must be set to the type of
12696 the lower bound, upper bound or count, in that order, if any of these
12697 three attributes references an object that has a type.
12698 If no base type is found, the Dwarf-2 specifications say that
12699 a signed integer type of size equal to the size of an address should
12701 For the following C code: `extern char gdb_int [];'
12702 GCC produces an empty range DIE.
12703 FIXME: muller/2010-05-28: Possible references to object for low bound,
12704 high bound or count are not yet handled by this code. */
12705 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
12707 struct objfile
*objfile
= cu
->objfile
;
12708 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12709 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
12710 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
12712 /* Test "int", "long int", and "long long int" objfile types,
12713 and select the first one having a size above or equal to the
12714 architecture address size. */
12715 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12716 base_type
= int_type
;
12719 int_type
= objfile_type (objfile
)->builtin_long
;
12720 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12721 base_type
= int_type
;
12724 int_type
= objfile_type (objfile
)->builtin_long_long
;
12725 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12726 base_type
= int_type
;
12732 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
12733 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
12734 low
|= negative_mask
;
12735 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
12736 high
|= negative_mask
;
12738 range_type
= create_range_type (NULL
, base_type
, low
, high
);
12740 /* Mark arrays with dynamic length at least as an array of unspecified
12741 length. GDB could check the boundary but before it gets implemented at
12742 least allow accessing the array elements. */
12743 if (attr
&& attr_form_is_block (attr
))
12744 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12746 /* Ada expects an empty array on no boundary attributes. */
12747 if (attr
== NULL
&& cu
->language
!= language_ada
)
12748 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12750 name
= dwarf2_name (die
, cu
);
12752 TYPE_NAME (range_type
) = name
;
12754 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12756 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
12758 set_die_type (die
, range_type
, cu
);
12760 /* set_die_type should be already done. */
12761 set_descriptive_type (range_type
, die
, cu
);
12766 static struct type
*
12767 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12771 /* For now, we only support the C meaning of an unspecified type: void. */
12773 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
12774 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
12776 return set_die_type (die
, type
, cu
);
12779 /* Read a single die and all its descendents. Set the die's sibling
12780 field to NULL; set other fields in the die correctly, and set all
12781 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
12782 location of the info_ptr after reading all of those dies. PARENT
12783 is the parent of the die in question. */
12785 static struct die_info
*
12786 read_die_and_children (const struct die_reader_specs
*reader
,
12787 gdb_byte
*info_ptr
,
12788 gdb_byte
**new_info_ptr
,
12789 struct die_info
*parent
)
12791 struct die_info
*die
;
12795 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
12798 *new_info_ptr
= cur_ptr
;
12801 store_in_ref_table (die
, reader
->cu
);
12804 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
12808 *new_info_ptr
= cur_ptr
;
12811 die
->sibling
= NULL
;
12812 die
->parent
= parent
;
12816 /* Read a die, all of its descendents, and all of its siblings; set
12817 all of the fields of all of the dies correctly. Arguments are as
12818 in read_die_and_children. */
12820 static struct die_info
*
12821 read_die_and_siblings (const struct die_reader_specs
*reader
,
12822 gdb_byte
*info_ptr
,
12823 gdb_byte
**new_info_ptr
,
12824 struct die_info
*parent
)
12826 struct die_info
*first_die
, *last_sibling
;
12829 cur_ptr
= info_ptr
;
12830 first_die
= last_sibling
= NULL
;
12834 struct die_info
*die
12835 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
12839 *new_info_ptr
= cur_ptr
;
12846 last_sibling
->sibling
= die
;
12848 last_sibling
= die
;
12852 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
12854 The caller is responsible for filling in the extra attributes
12855 and updating (*DIEP)->num_attrs.
12856 Set DIEP to point to a newly allocated die with its information,
12857 except for its child, sibling, and parent fields.
12858 Set HAS_CHILDREN to tell whether the die has children or not. */
12861 read_full_die_1 (const struct die_reader_specs
*reader
,
12862 struct die_info
**diep
, gdb_byte
*info_ptr
,
12863 int *has_children
, int num_extra_attrs
)
12865 unsigned int abbrev_number
, bytes_read
, i
;
12866 sect_offset offset
;
12867 struct abbrev_info
*abbrev
;
12868 struct die_info
*die
;
12869 struct dwarf2_cu
*cu
= reader
->cu
;
12870 bfd
*abfd
= reader
->abfd
;
12872 offset
.sect_off
= info_ptr
- reader
->buffer
;
12873 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12874 info_ptr
+= bytes_read
;
12875 if (!abbrev_number
)
12882 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
12884 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
12886 bfd_get_filename (abfd
));
12888 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
12889 die
->offset
= offset
;
12890 die
->tag
= abbrev
->tag
;
12891 die
->abbrev
= abbrev_number
;
12893 /* Make the result usable.
12894 The caller needs to update num_attrs after adding the extra
12896 die
->num_attrs
= abbrev
->num_attrs
;
12898 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12899 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
12903 *has_children
= abbrev
->has_children
;
12907 /* Read a die and all its attributes.
12908 Set DIEP to point to a newly allocated die with its information,
12909 except for its child, sibling, and parent fields.
12910 Set HAS_CHILDREN to tell whether the die has children or not. */
12913 read_full_die (const struct die_reader_specs
*reader
,
12914 struct die_info
**diep
, gdb_byte
*info_ptr
,
12917 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
12920 /* Abbreviation tables.
12922 In DWARF version 2, the description of the debugging information is
12923 stored in a separate .debug_abbrev section. Before we read any
12924 dies from a section we read in all abbreviations and install them
12925 in a hash table. */
12927 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
12929 static struct abbrev_info
*
12930 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
12932 struct abbrev_info
*abbrev
;
12934 abbrev
= (struct abbrev_info
*)
12935 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
12936 memset (abbrev
, 0, sizeof (struct abbrev_info
));
12940 /* Add an abbreviation to the table. */
12943 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
12944 unsigned int abbrev_number
,
12945 struct abbrev_info
*abbrev
)
12947 unsigned int hash_number
;
12949 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
12950 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
12951 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
12954 /* Look up an abbrev in the table.
12955 Returns NULL if the abbrev is not found. */
12957 static struct abbrev_info
*
12958 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
12959 unsigned int abbrev_number
)
12961 unsigned int hash_number
;
12962 struct abbrev_info
*abbrev
;
12964 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
12965 abbrev
= abbrev_table
->abbrevs
[hash_number
];
12969 if (abbrev
->number
== abbrev_number
)
12971 abbrev
= abbrev
->next
;
12976 /* Read in an abbrev table. */
12978 static struct abbrev_table
*
12979 abbrev_table_read_table (struct dwarf2_section_info
*section
,
12980 sect_offset offset
)
12982 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12983 bfd
*abfd
= section
->asection
->owner
;
12984 struct abbrev_table
*abbrev_table
;
12985 gdb_byte
*abbrev_ptr
;
12986 struct abbrev_info
*cur_abbrev
;
12987 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
12988 unsigned int abbrev_form
;
12989 struct attr_abbrev
*cur_attrs
;
12990 unsigned int allocated_attrs
;
12992 abbrev_table
= XMALLOC (struct abbrev_table
);
12993 abbrev_table
->offset
= offset
;
12994 obstack_init (&abbrev_table
->abbrev_obstack
);
12995 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12997 * sizeof (struct abbrev_info
*)));
12998 memset (abbrev_table
->abbrevs
, 0,
12999 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
13001 dwarf2_read_section (objfile
, section
);
13002 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
13003 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13004 abbrev_ptr
+= bytes_read
;
13006 allocated_attrs
= ATTR_ALLOC_CHUNK
;
13007 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
13009 /* Loop until we reach an abbrev number of 0. */
13010 while (abbrev_number
)
13012 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
13014 /* read in abbrev header */
13015 cur_abbrev
->number
= abbrev_number
;
13016 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13017 abbrev_ptr
+= bytes_read
;
13018 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
13021 /* now read in declarations */
13022 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13023 abbrev_ptr
+= bytes_read
;
13024 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13025 abbrev_ptr
+= bytes_read
;
13026 while (abbrev_name
)
13028 if (cur_abbrev
->num_attrs
== allocated_attrs
)
13030 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
13032 = xrealloc (cur_attrs
, (allocated_attrs
13033 * sizeof (struct attr_abbrev
)));
13036 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
13037 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
13038 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13039 abbrev_ptr
+= bytes_read
;
13040 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13041 abbrev_ptr
+= bytes_read
;
13044 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13045 (cur_abbrev
->num_attrs
13046 * sizeof (struct attr_abbrev
)));
13047 memcpy (cur_abbrev
->attrs
, cur_attrs
,
13048 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
13050 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
13052 /* Get next abbreviation.
13053 Under Irix6 the abbreviations for a compilation unit are not
13054 always properly terminated with an abbrev number of 0.
13055 Exit loop if we encounter an abbreviation which we have
13056 already read (which means we are about to read the abbreviations
13057 for the next compile unit) or if the end of the abbreviation
13058 table is reached. */
13059 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
13061 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13062 abbrev_ptr
+= bytes_read
;
13063 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
13068 return abbrev_table
;
13071 /* Free the resources held by ABBREV_TABLE. */
13074 abbrev_table_free (struct abbrev_table
*abbrev_table
)
13076 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
13077 xfree (abbrev_table
);
13080 /* Same as abbrev_table_free but as a cleanup.
13081 We pass in a pointer to the pointer to the table so that we can
13082 set the pointer to NULL when we're done. It also simplifies
13083 build_type_unit_groups. */
13086 abbrev_table_free_cleanup (void *table_ptr
)
13088 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
13090 if (*abbrev_table_ptr
!= NULL
)
13091 abbrev_table_free (*abbrev_table_ptr
);
13092 *abbrev_table_ptr
= NULL
;
13095 /* Read the abbrev table for CU from ABBREV_SECTION. */
13098 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
13099 struct dwarf2_section_info
*abbrev_section
)
13102 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
13105 /* Release the memory used by the abbrev table for a compilation unit. */
13108 dwarf2_free_abbrev_table (void *ptr_to_cu
)
13110 struct dwarf2_cu
*cu
= ptr_to_cu
;
13112 abbrev_table_free (cu
->abbrev_table
);
13113 /* Set this to NULL so that we SEGV if we try to read it later,
13114 and also because free_comp_unit verifies this is NULL. */
13115 cu
->abbrev_table
= NULL
;
13118 /* Returns nonzero if TAG represents a type that we might generate a partial
13122 is_type_tag_for_partial (int tag
)
13127 /* Some types that would be reasonable to generate partial symbols for,
13128 that we don't at present. */
13129 case DW_TAG_array_type
:
13130 case DW_TAG_file_type
:
13131 case DW_TAG_ptr_to_member_type
:
13132 case DW_TAG_set_type
:
13133 case DW_TAG_string_type
:
13134 case DW_TAG_subroutine_type
:
13136 case DW_TAG_base_type
:
13137 case DW_TAG_class_type
:
13138 case DW_TAG_interface_type
:
13139 case DW_TAG_enumeration_type
:
13140 case DW_TAG_structure_type
:
13141 case DW_TAG_subrange_type
:
13142 case DW_TAG_typedef
:
13143 case DW_TAG_union_type
:
13150 /* Load all DIEs that are interesting for partial symbols into memory. */
13152 static struct partial_die_info
*
13153 load_partial_dies (const struct die_reader_specs
*reader
,
13154 gdb_byte
*info_ptr
, int building_psymtab
)
13156 struct dwarf2_cu
*cu
= reader
->cu
;
13157 struct objfile
*objfile
= cu
->objfile
;
13158 struct partial_die_info
*part_die
;
13159 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
13160 struct abbrev_info
*abbrev
;
13161 unsigned int bytes_read
;
13162 unsigned int load_all
= 0;
13163 int nesting_level
= 1;
13168 gdb_assert (cu
->per_cu
!= NULL
);
13169 if (cu
->per_cu
->load_all_dies
)
13173 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13177 &cu
->comp_unit_obstack
,
13178 hashtab_obstack_allocate
,
13179 dummy_obstack_deallocate
);
13181 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13182 sizeof (struct partial_die_info
));
13186 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
13188 /* A NULL abbrev means the end of a series of children. */
13189 if (abbrev
== NULL
)
13191 if (--nesting_level
== 0)
13193 /* PART_DIE was probably the last thing allocated on the
13194 comp_unit_obstack, so we could call obstack_free
13195 here. We don't do that because the waste is small,
13196 and will be cleaned up when we're done with this
13197 compilation unit. This way, we're also more robust
13198 against other users of the comp_unit_obstack. */
13201 info_ptr
+= bytes_read
;
13202 last_die
= parent_die
;
13203 parent_die
= parent_die
->die_parent
;
13207 /* Check for template arguments. We never save these; if
13208 they're seen, we just mark the parent, and go on our way. */
13209 if (parent_die
!= NULL
13210 && cu
->language
== language_cplus
13211 && (abbrev
->tag
== DW_TAG_template_type_param
13212 || abbrev
->tag
== DW_TAG_template_value_param
))
13214 parent_die
->has_template_arguments
= 1;
13218 /* We don't need a partial DIE for the template argument. */
13219 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13224 /* We only recurse into c++ subprograms looking for template arguments.
13225 Skip their other children. */
13227 && cu
->language
== language_cplus
13228 && parent_die
!= NULL
13229 && parent_die
->tag
== DW_TAG_subprogram
)
13231 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13235 /* Check whether this DIE is interesting enough to save. Normally
13236 we would not be interested in members here, but there may be
13237 later variables referencing them via DW_AT_specification (for
13238 static members). */
13240 && !is_type_tag_for_partial (abbrev
->tag
)
13241 && abbrev
->tag
!= DW_TAG_constant
13242 && abbrev
->tag
!= DW_TAG_enumerator
13243 && abbrev
->tag
!= DW_TAG_subprogram
13244 && abbrev
->tag
!= DW_TAG_lexical_block
13245 && abbrev
->tag
!= DW_TAG_variable
13246 && abbrev
->tag
!= DW_TAG_namespace
13247 && abbrev
->tag
!= DW_TAG_module
13248 && abbrev
->tag
!= DW_TAG_member
13249 && abbrev
->tag
!= DW_TAG_imported_unit
)
13251 /* Otherwise we skip to the next sibling, if any. */
13252 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13256 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
13259 /* This two-pass algorithm for processing partial symbols has a
13260 high cost in cache pressure. Thus, handle some simple cases
13261 here which cover the majority of C partial symbols. DIEs
13262 which neither have specification tags in them, nor could have
13263 specification tags elsewhere pointing at them, can simply be
13264 processed and discarded.
13266 This segment is also optional; scan_partial_symbols and
13267 add_partial_symbol will handle these DIEs if we chain
13268 them in normally. When compilers which do not emit large
13269 quantities of duplicate debug information are more common,
13270 this code can probably be removed. */
13272 /* Any complete simple types at the top level (pretty much all
13273 of them, for a language without namespaces), can be processed
13275 if (parent_die
== NULL
13276 && part_die
->has_specification
== 0
13277 && part_die
->is_declaration
== 0
13278 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
13279 || part_die
->tag
== DW_TAG_base_type
13280 || part_die
->tag
== DW_TAG_subrange_type
))
13282 if (building_psymtab
&& part_die
->name
!= NULL
)
13283 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13284 VAR_DOMAIN
, LOC_TYPEDEF
,
13285 &objfile
->static_psymbols
,
13286 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13287 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13291 /* The exception for DW_TAG_typedef with has_children above is
13292 a workaround of GCC PR debug/47510. In the case of this complaint
13293 type_name_no_tag_or_error will error on such types later.
13295 GDB skipped children of DW_TAG_typedef by the shortcut above and then
13296 it could not find the child DIEs referenced later, this is checked
13297 above. In correct DWARF DW_TAG_typedef should have no children. */
13299 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
13300 complaint (&symfile_complaints
,
13301 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
13302 "- DIE at 0x%x [in module %s]"),
13303 part_die
->offset
.sect_off
, objfile
->name
);
13305 /* If we're at the second level, and we're an enumerator, and
13306 our parent has no specification (meaning possibly lives in a
13307 namespace elsewhere), then we can add the partial symbol now
13308 instead of queueing it. */
13309 if (part_die
->tag
== DW_TAG_enumerator
13310 && parent_die
!= NULL
13311 && parent_die
->die_parent
== NULL
13312 && parent_die
->tag
== DW_TAG_enumeration_type
13313 && parent_die
->has_specification
== 0)
13315 if (part_die
->name
== NULL
)
13316 complaint (&symfile_complaints
,
13317 _("malformed enumerator DIE ignored"));
13318 else if (building_psymtab
)
13319 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13320 VAR_DOMAIN
, LOC_CONST
,
13321 (cu
->language
== language_cplus
13322 || cu
->language
== language_java
)
13323 ? &objfile
->global_psymbols
13324 : &objfile
->static_psymbols
,
13325 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13327 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13331 /* We'll save this DIE so link it in. */
13332 part_die
->die_parent
= parent_die
;
13333 part_die
->die_sibling
= NULL
;
13334 part_die
->die_child
= NULL
;
13336 if (last_die
&& last_die
== parent_die
)
13337 last_die
->die_child
= part_die
;
13339 last_die
->die_sibling
= part_die
;
13341 last_die
= part_die
;
13343 if (first_die
== NULL
)
13344 first_die
= part_die
;
13346 /* Maybe add the DIE to the hash table. Not all DIEs that we
13347 find interesting need to be in the hash table, because we
13348 also have the parent/sibling/child chains; only those that we
13349 might refer to by offset later during partial symbol reading.
13351 For now this means things that might have be the target of a
13352 DW_AT_specification, DW_AT_abstract_origin, or
13353 DW_AT_extension. DW_AT_extension will refer only to
13354 namespaces; DW_AT_abstract_origin refers to functions (and
13355 many things under the function DIE, but we do not recurse
13356 into function DIEs during partial symbol reading) and
13357 possibly variables as well; DW_AT_specification refers to
13358 declarations. Declarations ought to have the DW_AT_declaration
13359 flag. It happens that GCC forgets to put it in sometimes, but
13360 only for functions, not for types.
13362 Adding more things than necessary to the hash table is harmless
13363 except for the performance cost. Adding too few will result in
13364 wasted time in find_partial_die, when we reread the compilation
13365 unit with load_all_dies set. */
13368 || abbrev
->tag
== DW_TAG_constant
13369 || abbrev
->tag
== DW_TAG_subprogram
13370 || abbrev
->tag
== DW_TAG_variable
13371 || abbrev
->tag
== DW_TAG_namespace
13372 || part_die
->is_declaration
)
13376 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
13377 part_die
->offset
.sect_off
, INSERT
);
13381 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13382 sizeof (struct partial_die_info
));
13384 /* For some DIEs we want to follow their children (if any). For C
13385 we have no reason to follow the children of structures; for other
13386 languages we have to, so that we can get at method physnames
13387 to infer fully qualified class names, for DW_AT_specification,
13388 and for C++ template arguments. For C++, we also look one level
13389 inside functions to find template arguments (if the name of the
13390 function does not already contain the template arguments).
13392 For Ada, we need to scan the children of subprograms and lexical
13393 blocks as well because Ada allows the definition of nested
13394 entities that could be interesting for the debugger, such as
13395 nested subprograms for instance. */
13396 if (last_die
->has_children
13398 || last_die
->tag
== DW_TAG_namespace
13399 || last_die
->tag
== DW_TAG_module
13400 || last_die
->tag
== DW_TAG_enumeration_type
13401 || (cu
->language
== language_cplus
13402 && last_die
->tag
== DW_TAG_subprogram
13403 && (last_die
->name
== NULL
13404 || strchr (last_die
->name
, '<') == NULL
))
13405 || (cu
->language
!= language_c
13406 && (last_die
->tag
== DW_TAG_class_type
13407 || last_die
->tag
== DW_TAG_interface_type
13408 || last_die
->tag
== DW_TAG_structure_type
13409 || last_die
->tag
== DW_TAG_union_type
))
13410 || (cu
->language
== language_ada
13411 && (last_die
->tag
== DW_TAG_subprogram
13412 || last_die
->tag
== DW_TAG_lexical_block
))))
13415 parent_die
= last_die
;
13419 /* Otherwise we skip to the next sibling, if any. */
13420 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
13422 /* Back to the top, do it again. */
13426 /* Read a minimal amount of information into the minimal die structure. */
13429 read_partial_die (const struct die_reader_specs
*reader
,
13430 struct partial_die_info
*part_die
,
13431 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
13432 gdb_byte
*info_ptr
)
13434 struct dwarf2_cu
*cu
= reader
->cu
;
13435 struct objfile
*objfile
= cu
->objfile
;
13436 gdb_byte
*buffer
= reader
->buffer
;
13438 struct attribute attr
;
13439 int has_low_pc_attr
= 0;
13440 int has_high_pc_attr
= 0;
13441 int high_pc_relative
= 0;
13443 memset (part_die
, 0, sizeof (struct partial_die_info
));
13445 part_die
->offset
.sect_off
= info_ptr
- buffer
;
13447 info_ptr
+= abbrev_len
;
13449 if (abbrev
== NULL
)
13452 part_die
->tag
= abbrev
->tag
;
13453 part_die
->has_children
= abbrev
->has_children
;
13455 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
13457 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
13459 /* Store the data if it is of an attribute we want to keep in a
13460 partial symbol table. */
13464 switch (part_die
->tag
)
13466 case DW_TAG_compile_unit
:
13467 case DW_TAG_partial_unit
:
13468 case DW_TAG_type_unit
:
13469 /* Compilation units have a DW_AT_name that is a filename, not
13470 a source language identifier. */
13471 case DW_TAG_enumeration_type
:
13472 case DW_TAG_enumerator
:
13473 /* These tags always have simple identifiers already; no need
13474 to canonicalize them. */
13475 part_die
->name
= DW_STRING (&attr
);
13479 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
13480 &objfile
->objfile_obstack
);
13484 case DW_AT_linkage_name
:
13485 case DW_AT_MIPS_linkage_name
:
13486 /* Note that both forms of linkage name might appear. We
13487 assume they will be the same, and we only store the last
13489 if (cu
->language
== language_ada
)
13490 part_die
->name
= DW_STRING (&attr
);
13491 part_die
->linkage_name
= DW_STRING (&attr
);
13494 has_low_pc_attr
= 1;
13495 part_die
->lowpc
= DW_ADDR (&attr
);
13497 case DW_AT_high_pc
:
13498 has_high_pc_attr
= 1;
13499 if (attr
.form
== DW_FORM_addr
13500 || attr
.form
== DW_FORM_GNU_addr_index
)
13501 part_die
->highpc
= DW_ADDR (&attr
);
13504 high_pc_relative
= 1;
13505 part_die
->highpc
= DW_UNSND (&attr
);
13508 case DW_AT_location
:
13509 /* Support the .debug_loc offsets. */
13510 if (attr_form_is_block (&attr
))
13512 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
13514 else if (attr_form_is_section_offset (&attr
))
13516 dwarf2_complex_location_expr_complaint ();
13520 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13521 "partial symbol information");
13524 case DW_AT_external
:
13525 part_die
->is_external
= DW_UNSND (&attr
);
13527 case DW_AT_declaration
:
13528 part_die
->is_declaration
= DW_UNSND (&attr
);
13531 part_die
->has_type
= 1;
13533 case DW_AT_abstract_origin
:
13534 case DW_AT_specification
:
13535 case DW_AT_extension
:
13536 part_die
->has_specification
= 1;
13537 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
13538 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13539 || cu
->per_cu
->is_dwz
);
13541 case DW_AT_sibling
:
13542 /* Ignore absolute siblings, they might point outside of
13543 the current compile unit. */
13544 if (attr
.form
== DW_FORM_ref_addr
)
13545 complaint (&symfile_complaints
,
13546 _("ignoring absolute DW_AT_sibling"));
13548 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
13550 case DW_AT_byte_size
:
13551 part_die
->has_byte_size
= 1;
13553 case DW_AT_calling_convention
:
13554 /* DWARF doesn't provide a way to identify a program's source-level
13555 entry point. DW_AT_calling_convention attributes are only meant
13556 to describe functions' calling conventions.
13558 However, because it's a necessary piece of information in
13559 Fortran, and because DW_CC_program is the only piece of debugging
13560 information whose definition refers to a 'main program' at all,
13561 several compilers have begun marking Fortran main programs with
13562 DW_CC_program --- even when those functions use the standard
13563 calling conventions.
13565 So until DWARF specifies a way to provide this information and
13566 compilers pick up the new representation, we'll support this
13568 if (DW_UNSND (&attr
) == DW_CC_program
13569 && cu
->language
== language_fortran
)
13571 set_main_name (part_die
->name
);
13573 /* As this DIE has a static linkage the name would be difficult
13574 to look up later. */
13575 language_of_main
= language_fortran
;
13579 if (DW_UNSND (&attr
) == DW_INL_inlined
13580 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
13581 part_die
->may_be_inlined
= 1;
13585 if (part_die
->tag
== DW_TAG_imported_unit
)
13587 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
13588 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13589 || cu
->per_cu
->is_dwz
);
13598 if (high_pc_relative
)
13599 part_die
->highpc
+= part_die
->lowpc
;
13601 if (has_low_pc_attr
&& has_high_pc_attr
)
13603 /* When using the GNU linker, .gnu.linkonce. sections are used to
13604 eliminate duplicate copies of functions and vtables and such.
13605 The linker will arbitrarily choose one and discard the others.
13606 The AT_*_pc values for such functions refer to local labels in
13607 these sections. If the section from that file was discarded, the
13608 labels are not in the output, so the relocs get a value of 0.
13609 If this is a discarded function, mark the pc bounds as invalid,
13610 so that GDB will ignore it. */
13611 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13613 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13615 complaint (&symfile_complaints
,
13616 _("DW_AT_low_pc %s is zero "
13617 "for DIE at 0x%x [in module %s]"),
13618 paddress (gdbarch
, part_die
->lowpc
),
13619 part_die
->offset
.sect_off
, objfile
->name
);
13621 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
13622 else if (part_die
->lowpc
>= part_die
->highpc
)
13624 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13626 complaint (&symfile_complaints
,
13627 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
13628 "for DIE at 0x%x [in module %s]"),
13629 paddress (gdbarch
, part_die
->lowpc
),
13630 paddress (gdbarch
, part_die
->highpc
),
13631 part_die
->offset
.sect_off
, objfile
->name
);
13634 part_die
->has_pc_info
= 1;
13640 /* Find a cached partial DIE at OFFSET in CU. */
13642 static struct partial_die_info
*
13643 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
13645 struct partial_die_info
*lookup_die
= NULL
;
13646 struct partial_die_info part_die
;
13648 part_die
.offset
= offset
;
13649 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
13655 /* Find a partial DIE at OFFSET, which may or may not be in CU,
13656 except in the case of .debug_types DIEs which do not reference
13657 outside their CU (they do however referencing other types via
13658 DW_FORM_ref_sig8). */
13660 static struct partial_die_info
*
13661 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
13663 struct objfile
*objfile
= cu
->objfile
;
13664 struct dwarf2_per_cu_data
*per_cu
= NULL
;
13665 struct partial_die_info
*pd
= NULL
;
13667 if (offset_in_dwz
== cu
->per_cu
->is_dwz
13668 && offset_in_cu_p (&cu
->header
, offset
))
13670 pd
= find_partial_die_in_comp_unit (offset
, cu
);
13673 /* We missed recording what we needed.
13674 Load all dies and try again. */
13675 per_cu
= cu
->per_cu
;
13679 /* TUs don't reference other CUs/TUs (except via type signatures). */
13680 if (cu
->per_cu
->is_debug_types
)
13682 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
13683 " external reference to offset 0x%lx [in module %s].\n"),
13684 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
13685 bfd_get_filename (objfile
->obfd
));
13687 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
13690 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
13691 load_partial_comp_unit (per_cu
);
13693 per_cu
->cu
->last_used
= 0;
13694 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13697 /* If we didn't find it, and not all dies have been loaded,
13698 load them all and try again. */
13700 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
13702 per_cu
->load_all_dies
= 1;
13704 /* This is nasty. When we reread the DIEs, somewhere up the call chain
13705 THIS_CU->cu may already be in use. So we can't just free it and
13706 replace its DIEs with the ones we read in. Instead, we leave those
13707 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
13708 and clobber THIS_CU->cu->partial_dies with the hash table for the new
13710 load_partial_comp_unit (per_cu
);
13712 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13716 internal_error (__FILE__
, __LINE__
,
13717 _("could not find partial DIE 0x%x "
13718 "in cache [from module %s]\n"),
13719 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
13723 /* See if we can figure out if the class lives in a namespace. We do
13724 this by looking for a member function; its demangled name will
13725 contain namespace info, if there is any. */
13728 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
13729 struct dwarf2_cu
*cu
)
13731 /* NOTE: carlton/2003-10-07: Getting the info this way changes
13732 what template types look like, because the demangler
13733 frequently doesn't give the same name as the debug info. We
13734 could fix this by only using the demangled name to get the
13735 prefix (but see comment in read_structure_type). */
13737 struct partial_die_info
*real_pdi
;
13738 struct partial_die_info
*child_pdi
;
13740 /* If this DIE (this DIE's specification, if any) has a parent, then
13741 we should not do this. We'll prepend the parent's fully qualified
13742 name when we create the partial symbol. */
13744 real_pdi
= struct_pdi
;
13745 while (real_pdi
->has_specification
)
13746 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
13747 real_pdi
->spec_is_dwz
, cu
);
13749 if (real_pdi
->die_parent
!= NULL
)
13752 for (child_pdi
= struct_pdi
->die_child
;
13754 child_pdi
= child_pdi
->die_sibling
)
13756 if (child_pdi
->tag
== DW_TAG_subprogram
13757 && child_pdi
->linkage_name
!= NULL
)
13759 char *actual_class_name
13760 = language_class_name_from_physname (cu
->language_defn
,
13761 child_pdi
->linkage_name
);
13762 if (actual_class_name
!= NULL
)
13765 = obsavestring (actual_class_name
,
13766 strlen (actual_class_name
),
13767 &cu
->objfile
->objfile_obstack
);
13768 xfree (actual_class_name
);
13775 /* Adjust PART_DIE before generating a symbol for it. This function
13776 may set the is_external flag or change the DIE's name. */
13779 fixup_partial_die (struct partial_die_info
*part_die
,
13780 struct dwarf2_cu
*cu
)
13782 /* Once we've fixed up a die, there's no point in doing so again.
13783 This also avoids a memory leak if we were to call
13784 guess_partial_die_structure_name multiple times. */
13785 if (part_die
->fixup_called
)
13788 /* If we found a reference attribute and the DIE has no name, try
13789 to find a name in the referred to DIE. */
13791 if (part_die
->name
== NULL
&& part_die
->has_specification
)
13793 struct partial_die_info
*spec_die
;
13795 spec_die
= find_partial_die (part_die
->spec_offset
,
13796 part_die
->spec_is_dwz
, cu
);
13798 fixup_partial_die (spec_die
, cu
);
13800 if (spec_die
->name
)
13802 part_die
->name
= spec_die
->name
;
13804 /* Copy DW_AT_external attribute if it is set. */
13805 if (spec_die
->is_external
)
13806 part_die
->is_external
= spec_die
->is_external
;
13810 /* Set default names for some unnamed DIEs. */
13812 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
13813 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
13815 /* If there is no parent die to provide a namespace, and there are
13816 children, see if we can determine the namespace from their linkage
13818 if (cu
->language
== language_cplus
13819 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
13820 && part_die
->die_parent
== NULL
13821 && part_die
->has_children
13822 && (part_die
->tag
== DW_TAG_class_type
13823 || part_die
->tag
== DW_TAG_structure_type
13824 || part_die
->tag
== DW_TAG_union_type
))
13825 guess_partial_die_structure_name (part_die
, cu
);
13827 /* GCC might emit a nameless struct or union that has a linkage
13828 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13829 if (part_die
->name
== NULL
13830 && (part_die
->tag
== DW_TAG_class_type
13831 || part_die
->tag
== DW_TAG_interface_type
13832 || part_die
->tag
== DW_TAG_structure_type
13833 || part_die
->tag
== DW_TAG_union_type
)
13834 && part_die
->linkage_name
!= NULL
)
13838 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
13843 /* Strip any leading namespaces/classes, keep only the base name.
13844 DW_AT_name for named DIEs does not contain the prefixes. */
13845 base
= strrchr (demangled
, ':');
13846 if (base
&& base
> demangled
&& base
[-1] == ':')
13851 part_die
->name
= obsavestring (base
, strlen (base
),
13852 &cu
->objfile
->objfile_obstack
);
13857 part_die
->fixup_called
= 1;
13860 /* Read an attribute value described by an attribute form. */
13863 read_attribute_value (const struct die_reader_specs
*reader
,
13864 struct attribute
*attr
, unsigned form
,
13865 gdb_byte
*info_ptr
)
13867 struct dwarf2_cu
*cu
= reader
->cu
;
13868 bfd
*abfd
= reader
->abfd
;
13869 struct comp_unit_head
*cu_header
= &cu
->header
;
13870 unsigned int bytes_read
;
13871 struct dwarf_block
*blk
;
13876 case DW_FORM_ref_addr
:
13877 if (cu
->header
.version
== 2)
13878 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13880 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
13881 &cu
->header
, &bytes_read
);
13882 info_ptr
+= bytes_read
;
13884 case DW_FORM_GNU_ref_alt
:
13885 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13886 info_ptr
+= bytes_read
;
13889 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13890 info_ptr
+= bytes_read
;
13892 case DW_FORM_block2
:
13893 blk
= dwarf_alloc_block (cu
);
13894 blk
->size
= read_2_bytes (abfd
, info_ptr
);
13896 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13897 info_ptr
+= blk
->size
;
13898 DW_BLOCK (attr
) = blk
;
13900 case DW_FORM_block4
:
13901 blk
= dwarf_alloc_block (cu
);
13902 blk
->size
= read_4_bytes (abfd
, info_ptr
);
13904 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13905 info_ptr
+= blk
->size
;
13906 DW_BLOCK (attr
) = blk
;
13908 case DW_FORM_data2
:
13909 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
13912 case DW_FORM_data4
:
13913 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
13916 case DW_FORM_data8
:
13917 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
13920 case DW_FORM_sec_offset
:
13921 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13922 info_ptr
+= bytes_read
;
13924 case DW_FORM_string
:
13925 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
13926 DW_STRING_IS_CANONICAL (attr
) = 0;
13927 info_ptr
+= bytes_read
;
13930 if (!cu
->per_cu
->is_dwz
)
13932 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
13934 DW_STRING_IS_CANONICAL (attr
) = 0;
13935 info_ptr
+= bytes_read
;
13939 case DW_FORM_GNU_strp_alt
:
13941 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
13942 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
13945 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
13946 DW_STRING_IS_CANONICAL (attr
) = 0;
13947 info_ptr
+= bytes_read
;
13950 case DW_FORM_exprloc
:
13951 case DW_FORM_block
:
13952 blk
= dwarf_alloc_block (cu
);
13953 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13954 info_ptr
+= bytes_read
;
13955 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13956 info_ptr
+= blk
->size
;
13957 DW_BLOCK (attr
) = blk
;
13959 case DW_FORM_block1
:
13960 blk
= dwarf_alloc_block (cu
);
13961 blk
->size
= read_1_byte (abfd
, info_ptr
);
13963 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13964 info_ptr
+= blk
->size
;
13965 DW_BLOCK (attr
) = blk
;
13967 case DW_FORM_data1
:
13968 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
13972 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
13975 case DW_FORM_flag_present
:
13976 DW_UNSND (attr
) = 1;
13978 case DW_FORM_sdata
:
13979 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
13980 info_ptr
+= bytes_read
;
13982 case DW_FORM_udata
:
13983 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13984 info_ptr
+= bytes_read
;
13987 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13988 + read_1_byte (abfd
, info_ptr
));
13992 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13993 + read_2_bytes (abfd
, info_ptr
));
13997 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13998 + read_4_bytes (abfd
, info_ptr
));
14002 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14003 + read_8_bytes (abfd
, info_ptr
));
14006 case DW_FORM_ref_sig8
:
14007 /* Convert the signature to something we can record in DW_UNSND
14009 NOTE: This is NULL if the type wasn't found. */
14010 DW_SIGNATURED_TYPE (attr
) =
14011 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
14014 case DW_FORM_ref_udata
:
14015 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14016 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
14017 info_ptr
+= bytes_read
;
14019 case DW_FORM_indirect
:
14020 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14021 info_ptr
+= bytes_read
;
14022 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
14024 case DW_FORM_GNU_addr_index
:
14025 if (reader
->dwo_file
== NULL
)
14027 /* For now flag a hard error.
14028 Later we can turn this into a complaint. */
14029 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14030 dwarf_form_name (form
),
14031 bfd_get_filename (abfd
));
14033 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
14034 info_ptr
+= bytes_read
;
14036 case DW_FORM_GNU_str_index
:
14037 if (reader
->dwo_file
== NULL
)
14039 /* For now flag a hard error.
14040 Later we can turn this into a complaint if warranted. */
14041 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14042 dwarf_form_name (form
),
14043 bfd_get_filename (abfd
));
14046 ULONGEST str_index
=
14047 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14049 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
14050 DW_STRING_IS_CANONICAL (attr
) = 0;
14051 info_ptr
+= bytes_read
;
14055 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
14056 dwarf_form_name (form
),
14057 bfd_get_filename (abfd
));
14061 if (cu
->per_cu
->is_dwz
&& is_ref_attr (attr
))
14062 attr
->form
= DW_FORM_GNU_ref_alt
;
14064 /* We have seen instances where the compiler tried to emit a byte
14065 size attribute of -1 which ended up being encoded as an unsigned
14066 0xffffffff. Although 0xffffffff is technically a valid size value,
14067 an object of this size seems pretty unlikely so we can relatively
14068 safely treat these cases as if the size attribute was invalid and
14069 treat them as zero by default. */
14070 if (attr
->name
== DW_AT_byte_size
14071 && form
== DW_FORM_data4
14072 && DW_UNSND (attr
) >= 0xffffffff)
14075 (&symfile_complaints
,
14076 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
14077 hex_string (DW_UNSND (attr
)));
14078 DW_UNSND (attr
) = 0;
14084 /* Read an attribute described by an abbreviated attribute. */
14087 read_attribute (const struct die_reader_specs
*reader
,
14088 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
14089 gdb_byte
*info_ptr
)
14091 attr
->name
= abbrev
->name
;
14092 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
14095 /* Read dwarf information from a buffer. */
14097 static unsigned int
14098 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
14100 return bfd_get_8 (abfd
, buf
);
14104 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
14106 return bfd_get_signed_8 (abfd
, buf
);
14109 static unsigned int
14110 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14112 return bfd_get_16 (abfd
, buf
);
14116 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14118 return bfd_get_signed_16 (abfd
, buf
);
14121 static unsigned int
14122 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14124 return bfd_get_32 (abfd
, buf
);
14128 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14130 return bfd_get_signed_32 (abfd
, buf
);
14134 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14136 return bfd_get_64 (abfd
, buf
);
14140 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
14141 unsigned int *bytes_read
)
14143 struct comp_unit_head
*cu_header
= &cu
->header
;
14144 CORE_ADDR retval
= 0;
14146 if (cu_header
->signed_addr_p
)
14148 switch (cu_header
->addr_size
)
14151 retval
= bfd_get_signed_16 (abfd
, buf
);
14154 retval
= bfd_get_signed_32 (abfd
, buf
);
14157 retval
= bfd_get_signed_64 (abfd
, buf
);
14160 internal_error (__FILE__
, __LINE__
,
14161 _("read_address: bad switch, signed [in module %s]"),
14162 bfd_get_filename (abfd
));
14167 switch (cu_header
->addr_size
)
14170 retval
= bfd_get_16 (abfd
, buf
);
14173 retval
= bfd_get_32 (abfd
, buf
);
14176 retval
= bfd_get_64 (abfd
, buf
);
14179 internal_error (__FILE__
, __LINE__
,
14180 _("read_address: bad switch, "
14181 "unsigned [in module %s]"),
14182 bfd_get_filename (abfd
));
14186 *bytes_read
= cu_header
->addr_size
;
14190 /* Read the initial length from a section. The (draft) DWARF 3
14191 specification allows the initial length to take up either 4 bytes
14192 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
14193 bytes describe the length and all offsets will be 8 bytes in length
14196 An older, non-standard 64-bit format is also handled by this
14197 function. The older format in question stores the initial length
14198 as an 8-byte quantity without an escape value. Lengths greater
14199 than 2^32 aren't very common which means that the initial 4 bytes
14200 is almost always zero. Since a length value of zero doesn't make
14201 sense for the 32-bit format, this initial zero can be considered to
14202 be an escape value which indicates the presence of the older 64-bit
14203 format. As written, the code can't detect (old format) lengths
14204 greater than 4GB. If it becomes necessary to handle lengths
14205 somewhat larger than 4GB, we could allow other small values (such
14206 as the non-sensical values of 1, 2, and 3) to also be used as
14207 escape values indicating the presence of the old format.
14209 The value returned via bytes_read should be used to increment the
14210 relevant pointer after calling read_initial_length().
14212 [ Note: read_initial_length() and read_offset() are based on the
14213 document entitled "DWARF Debugging Information Format", revision
14214 3, draft 8, dated November 19, 2001. This document was obtained
14217 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
14219 This document is only a draft and is subject to change. (So beware.)
14221 Details regarding the older, non-standard 64-bit format were
14222 determined empirically by examining 64-bit ELF files produced by
14223 the SGI toolchain on an IRIX 6.5 machine.
14225 - Kevin, July 16, 2002
14229 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
14231 LONGEST length
= bfd_get_32 (abfd
, buf
);
14233 if (length
== 0xffffffff)
14235 length
= bfd_get_64 (abfd
, buf
+ 4);
14238 else if (length
== 0)
14240 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
14241 length
= bfd_get_64 (abfd
, buf
);
14252 /* Cover function for read_initial_length.
14253 Returns the length of the object at BUF, and stores the size of the
14254 initial length in *BYTES_READ and stores the size that offsets will be in
14256 If the initial length size is not equivalent to that specified in
14257 CU_HEADER then issue a complaint.
14258 This is useful when reading non-comp-unit headers. */
14261 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
14262 const struct comp_unit_head
*cu_header
,
14263 unsigned int *bytes_read
,
14264 unsigned int *offset_size
)
14266 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
14268 gdb_assert (cu_header
->initial_length_size
== 4
14269 || cu_header
->initial_length_size
== 8
14270 || cu_header
->initial_length_size
== 12);
14272 if (cu_header
->initial_length_size
!= *bytes_read
)
14273 complaint (&symfile_complaints
,
14274 _("intermixed 32-bit and 64-bit DWARF sections"));
14276 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
14280 /* Read an offset from the data stream. The size of the offset is
14281 given by cu_header->offset_size. */
14284 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
14285 unsigned int *bytes_read
)
14287 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
14289 *bytes_read
= cu_header
->offset_size
;
14293 /* Read an offset from the data stream. */
14296 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
14298 LONGEST retval
= 0;
14300 switch (offset_size
)
14303 retval
= bfd_get_32 (abfd
, buf
);
14306 retval
= bfd_get_64 (abfd
, buf
);
14309 internal_error (__FILE__
, __LINE__
,
14310 _("read_offset_1: bad switch [in module %s]"),
14311 bfd_get_filename (abfd
));
14318 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
14320 /* If the size of a host char is 8 bits, we can return a pointer
14321 to the buffer, otherwise we have to copy the data to a buffer
14322 allocated on the temporary obstack. */
14323 gdb_assert (HOST_CHAR_BIT
== 8);
14328 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14330 /* If the size of a host char is 8 bits, we can return a pointer
14331 to the string, otherwise we have to copy the string to a buffer
14332 allocated on the temporary obstack. */
14333 gdb_assert (HOST_CHAR_BIT
== 8);
14336 *bytes_read_ptr
= 1;
14339 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
14340 return (char *) buf
;
14344 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
14346 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
14347 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
14348 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
14349 bfd_get_filename (abfd
));
14350 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
14351 error (_("DW_FORM_strp pointing outside of "
14352 ".debug_str section [in module %s]"),
14353 bfd_get_filename (abfd
));
14354 gdb_assert (HOST_CHAR_BIT
== 8);
14355 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
14357 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
14360 /* Read a string at offset STR_OFFSET in the .debug_str section from
14361 the .dwz file DWZ. Throw an error if the offset is too large. If
14362 the string consists of a single NUL byte, return NULL; otherwise
14363 return a pointer to the string. */
14366 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
14368 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
14370 if (dwz
->str
.buffer
== NULL
)
14371 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
14372 "section [in module %s]"),
14373 bfd_get_filename (dwz
->dwz_bfd
));
14374 if (str_offset
>= dwz
->str
.size
)
14375 error (_("DW_FORM_GNU_strp_alt pointing outside of "
14376 ".debug_str section [in module %s]"),
14377 bfd_get_filename (dwz
->dwz_bfd
));
14378 gdb_assert (HOST_CHAR_BIT
== 8);
14379 if (dwz
->str
.buffer
[str_offset
] == '\0')
14381 return (char *) (dwz
->str
.buffer
+ str_offset
);
14385 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
14386 const struct comp_unit_head
*cu_header
,
14387 unsigned int *bytes_read_ptr
)
14389 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
14391 return read_indirect_string_at_offset (abfd
, str_offset
);
14395 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14398 unsigned int num_read
;
14400 unsigned char byte
;
14408 byte
= bfd_get_8 (abfd
, buf
);
14411 result
|= ((ULONGEST
) (byte
& 127) << shift
);
14412 if ((byte
& 128) == 0)
14418 *bytes_read_ptr
= num_read
;
14423 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14426 int i
, shift
, num_read
;
14427 unsigned char byte
;
14435 byte
= bfd_get_8 (abfd
, buf
);
14438 result
|= ((LONGEST
) (byte
& 127) << shift
);
14440 if ((byte
& 128) == 0)
14445 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
14446 result
|= -(((LONGEST
) 1) << shift
);
14447 *bytes_read_ptr
= num_read
;
14451 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
14452 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
14453 ADDR_SIZE is the size of addresses from the CU header. */
14456 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
14458 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14459 bfd
*abfd
= objfile
->obfd
;
14460 const gdb_byte
*info_ptr
;
14462 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
14463 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
14464 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
14466 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
14467 error (_("DW_FORM_addr_index pointing outside of "
14468 ".debug_addr section [in module %s]"),
14470 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
14471 + addr_base
+ addr_index
* addr_size
);
14472 if (addr_size
== 4)
14473 return bfd_get_32 (abfd
, info_ptr
);
14475 return bfd_get_64 (abfd
, info_ptr
);
14478 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
14481 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
14483 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
14486 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
14489 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
14490 unsigned int *bytes_read
)
14492 bfd
*abfd
= cu
->objfile
->obfd
;
14493 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
14495 return read_addr_index (cu
, addr_index
);
14498 /* Data structure to pass results from dwarf2_read_addr_index_reader
14499 back to dwarf2_read_addr_index. */
14501 struct dwarf2_read_addr_index_data
14503 ULONGEST addr_base
;
14507 /* die_reader_func for dwarf2_read_addr_index. */
14510 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
14511 gdb_byte
*info_ptr
,
14512 struct die_info
*comp_unit_die
,
14516 struct dwarf2_cu
*cu
= reader
->cu
;
14517 struct dwarf2_read_addr_index_data
*aidata
=
14518 (struct dwarf2_read_addr_index_data
*) data
;
14520 aidata
->addr_base
= cu
->addr_base
;
14521 aidata
->addr_size
= cu
->header
.addr_size
;
14524 /* Given an index in .debug_addr, fetch the value.
14525 NOTE: This can be called during dwarf expression evaluation,
14526 long after the debug information has been read, and thus per_cu->cu
14527 may no longer exist. */
14530 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
14531 unsigned int addr_index
)
14533 struct objfile
*objfile
= per_cu
->objfile
;
14534 struct dwarf2_cu
*cu
= per_cu
->cu
;
14535 ULONGEST addr_base
;
14538 /* This is intended to be called from outside this file. */
14539 dw2_setup (objfile
);
14541 /* We need addr_base and addr_size.
14542 If we don't have PER_CU->cu, we have to get it.
14543 Nasty, but the alternative is storing the needed info in PER_CU,
14544 which at this point doesn't seem justified: it's not clear how frequently
14545 it would get used and it would increase the size of every PER_CU.
14546 Entry points like dwarf2_per_cu_addr_size do a similar thing
14547 so we're not in uncharted territory here.
14548 Alas we need to be a bit more complicated as addr_base is contained
14551 We don't need to read the entire CU(/TU).
14552 We just need the header and top level die.
14554 IWBN to use the aging mechanism to let us lazily later discard the CU.
14555 For now we skip this optimization. */
14559 addr_base
= cu
->addr_base
;
14560 addr_size
= cu
->header
.addr_size
;
14564 struct dwarf2_read_addr_index_data aidata
;
14566 /* Note: We can't use init_cutu_and_read_dies_simple here,
14567 we need addr_base. */
14568 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
14569 dwarf2_read_addr_index_reader
, &aidata
);
14570 addr_base
= aidata
.addr_base
;
14571 addr_size
= aidata
.addr_size
;
14574 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
14577 /* Given a DW_AT_str_index, fetch the string. */
14580 read_str_index (const struct die_reader_specs
*reader
,
14581 struct dwarf2_cu
*cu
, ULONGEST str_index
)
14583 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14584 const char *dwo_name
= objfile
->name
;
14585 bfd
*abfd
= objfile
->obfd
;
14586 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
14587 gdb_byte
*info_ptr
;
14588 ULONGEST str_offset
;
14590 dwarf2_read_section (objfile
, §ions
->str
);
14591 dwarf2_read_section (objfile
, §ions
->str_offsets
);
14592 if (sections
->str
.buffer
== NULL
)
14593 error (_("DW_FORM_str_index used without .debug_str.dwo section"
14594 " in CU at offset 0x%lx [in module %s]"),
14595 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14596 if (sections
->str_offsets
.buffer
== NULL
)
14597 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
14598 " in CU at offset 0x%lx [in module %s]"),
14599 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14600 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
14601 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
14602 " section in CU at offset 0x%lx [in module %s]"),
14603 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14604 info_ptr
= (sections
->str_offsets
.buffer
14605 + str_index
* cu
->header
.offset_size
);
14606 if (cu
->header
.offset_size
== 4)
14607 str_offset
= bfd_get_32 (abfd
, info_ptr
);
14609 str_offset
= bfd_get_64 (abfd
, info_ptr
);
14610 if (str_offset
>= sections
->str
.size
)
14611 error (_("Offset from DW_FORM_str_index pointing outside of"
14612 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
14613 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14614 return (char *) (sections
->str
.buffer
+ str_offset
);
14617 /* Return the length of an LEB128 number in BUF. */
14620 leb128_size (const gdb_byte
*buf
)
14622 const gdb_byte
*begin
= buf
;
14628 if ((byte
& 128) == 0)
14629 return buf
- begin
;
14634 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
14641 cu
->language
= language_c
;
14643 case DW_LANG_C_plus_plus
:
14644 cu
->language
= language_cplus
;
14647 cu
->language
= language_d
;
14649 case DW_LANG_Fortran77
:
14650 case DW_LANG_Fortran90
:
14651 case DW_LANG_Fortran95
:
14652 cu
->language
= language_fortran
;
14655 cu
->language
= language_go
;
14657 case DW_LANG_Mips_Assembler
:
14658 cu
->language
= language_asm
;
14661 cu
->language
= language_java
;
14663 case DW_LANG_Ada83
:
14664 case DW_LANG_Ada95
:
14665 cu
->language
= language_ada
;
14667 case DW_LANG_Modula2
:
14668 cu
->language
= language_m2
;
14670 case DW_LANG_Pascal83
:
14671 cu
->language
= language_pascal
;
14674 cu
->language
= language_objc
;
14676 case DW_LANG_Cobol74
:
14677 case DW_LANG_Cobol85
:
14679 cu
->language
= language_minimal
;
14682 cu
->language_defn
= language_def (cu
->language
);
14685 /* Return the named attribute or NULL if not there. */
14687 static struct attribute
*
14688 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
14693 struct attribute
*spec
= NULL
;
14695 for (i
= 0; i
< die
->num_attrs
; ++i
)
14697 if (die
->attrs
[i
].name
== name
)
14698 return &die
->attrs
[i
];
14699 if (die
->attrs
[i
].name
== DW_AT_specification
14700 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
14701 spec
= &die
->attrs
[i
];
14707 die
= follow_die_ref (die
, spec
, &cu
);
14713 /* Return the named attribute or NULL if not there,
14714 but do not follow DW_AT_specification, etc.
14715 This is for use in contexts where we're reading .debug_types dies.
14716 Following DW_AT_specification, DW_AT_abstract_origin will take us
14717 back up the chain, and we want to go down. */
14719 static struct attribute
*
14720 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
14724 for (i
= 0; i
< die
->num_attrs
; ++i
)
14725 if (die
->attrs
[i
].name
== name
)
14726 return &die
->attrs
[i
];
14731 /* Return non-zero iff the attribute NAME is defined for the given DIE,
14732 and holds a non-zero value. This function should only be used for
14733 DW_FORM_flag or DW_FORM_flag_present attributes. */
14736 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
14738 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
14740 return (attr
&& DW_UNSND (attr
));
14744 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
14746 /* A DIE is a declaration if it has a DW_AT_declaration attribute
14747 which value is non-zero. However, we have to be careful with
14748 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
14749 (via dwarf2_flag_true_p) follows this attribute. So we may
14750 end up accidently finding a declaration attribute that belongs
14751 to a different DIE referenced by the specification attribute,
14752 even though the given DIE does not have a declaration attribute. */
14753 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
14754 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
14757 /* Return the die giving the specification for DIE, if there is
14758 one. *SPEC_CU is the CU containing DIE on input, and the CU
14759 containing the return value on output. If there is no
14760 specification, but there is an abstract origin, that is
14763 static struct die_info
*
14764 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
14766 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
14769 if (spec_attr
== NULL
)
14770 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
14772 if (spec_attr
== NULL
)
14775 return follow_die_ref (die
, spec_attr
, spec_cu
);
14778 /* Free the line_header structure *LH, and any arrays and strings it
14780 NOTE: This is also used as a "cleanup" function. */
14783 free_line_header (struct line_header
*lh
)
14785 if (lh
->standard_opcode_lengths
)
14786 xfree (lh
->standard_opcode_lengths
);
14788 /* Remember that all the lh->file_names[i].name pointers are
14789 pointers into debug_line_buffer, and don't need to be freed. */
14790 if (lh
->file_names
)
14791 xfree (lh
->file_names
);
14793 /* Similarly for the include directory names. */
14794 if (lh
->include_dirs
)
14795 xfree (lh
->include_dirs
);
14800 /* Add an entry to LH's include directory table. */
14803 add_include_dir (struct line_header
*lh
, char *include_dir
)
14805 /* Grow the array if necessary. */
14806 if (lh
->include_dirs_size
== 0)
14808 lh
->include_dirs_size
= 1; /* for testing */
14809 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
14810 * sizeof (*lh
->include_dirs
));
14812 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
14814 lh
->include_dirs_size
*= 2;
14815 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
14816 (lh
->include_dirs_size
14817 * sizeof (*lh
->include_dirs
)));
14820 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
14823 /* Add an entry to LH's file name table. */
14826 add_file_name (struct line_header
*lh
,
14828 unsigned int dir_index
,
14829 unsigned int mod_time
,
14830 unsigned int length
)
14832 struct file_entry
*fe
;
14834 /* Grow the array if necessary. */
14835 if (lh
->file_names_size
== 0)
14837 lh
->file_names_size
= 1; /* for testing */
14838 lh
->file_names
= xmalloc (lh
->file_names_size
14839 * sizeof (*lh
->file_names
));
14841 else if (lh
->num_file_names
>= lh
->file_names_size
)
14843 lh
->file_names_size
*= 2;
14844 lh
->file_names
= xrealloc (lh
->file_names
,
14845 (lh
->file_names_size
14846 * sizeof (*lh
->file_names
)));
14849 fe
= &lh
->file_names
[lh
->num_file_names
++];
14851 fe
->dir_index
= dir_index
;
14852 fe
->mod_time
= mod_time
;
14853 fe
->length
= length
;
14854 fe
->included_p
= 0;
14858 /* A convenience function to find the proper .debug_line section for a
14861 static struct dwarf2_section_info
*
14862 get_debug_line_section (struct dwarf2_cu
*cu
)
14864 struct dwarf2_section_info
*section
;
14866 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
14868 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14869 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
14870 else if (cu
->per_cu
->is_dwz
)
14872 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14874 section
= &dwz
->line
;
14877 section
= &dwarf2_per_objfile
->line
;
14882 /* Read the statement program header starting at OFFSET in
14883 .debug_line, or .debug_line.dwo. Return a pointer
14884 to a struct line_header, allocated using xmalloc.
14886 NOTE: the strings in the include directory and file name tables of
14887 the returned object point into the dwarf line section buffer,
14888 and must not be freed. */
14890 static struct line_header
*
14891 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
14893 struct cleanup
*back_to
;
14894 struct line_header
*lh
;
14895 gdb_byte
*line_ptr
;
14896 unsigned int bytes_read
, offset_size
;
14898 char *cur_dir
, *cur_file
;
14899 struct dwarf2_section_info
*section
;
14902 section
= get_debug_line_section (cu
);
14903 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
14904 if (section
->buffer
== NULL
)
14906 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14907 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
14909 complaint (&symfile_complaints
, _("missing .debug_line section"));
14913 /* We can't do this until we know the section is non-empty.
14914 Only then do we know we have such a section. */
14915 abfd
= section
->asection
->owner
;
14917 /* Make sure that at least there's room for the total_length field.
14918 That could be 12 bytes long, but we're just going to fudge that. */
14919 if (offset
+ 4 >= section
->size
)
14921 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14925 lh
= xmalloc (sizeof (*lh
));
14926 memset (lh
, 0, sizeof (*lh
));
14927 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
14930 line_ptr
= section
->buffer
+ offset
;
14932 /* Read in the header. */
14934 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
14935 &bytes_read
, &offset_size
);
14936 line_ptr
+= bytes_read
;
14937 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
14939 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14942 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
14943 lh
->version
= read_2_bytes (abfd
, line_ptr
);
14945 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
14946 line_ptr
+= offset_size
;
14947 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
14949 if (lh
->version
>= 4)
14951 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
14955 lh
->maximum_ops_per_instruction
= 1;
14957 if (lh
->maximum_ops_per_instruction
== 0)
14959 lh
->maximum_ops_per_instruction
= 1;
14960 complaint (&symfile_complaints
,
14961 _("invalid maximum_ops_per_instruction "
14962 "in `.debug_line' section"));
14965 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
14967 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
14969 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
14971 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
14973 lh
->standard_opcode_lengths
14974 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
14976 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
14977 for (i
= 1; i
< lh
->opcode_base
; ++i
)
14979 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
14983 /* Read directory table. */
14984 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
14986 line_ptr
+= bytes_read
;
14987 add_include_dir (lh
, cur_dir
);
14989 line_ptr
+= bytes_read
;
14991 /* Read file name table. */
14992 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
14994 unsigned int dir_index
, mod_time
, length
;
14996 line_ptr
+= bytes_read
;
14997 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14998 line_ptr
+= bytes_read
;
14999 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15000 line_ptr
+= bytes_read
;
15001 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15002 line_ptr
+= bytes_read
;
15004 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15006 line_ptr
+= bytes_read
;
15007 lh
->statement_program_start
= line_ptr
;
15009 if (line_ptr
> (section
->buffer
+ section
->size
))
15010 complaint (&symfile_complaints
,
15011 _("line number info header doesn't "
15012 "fit in `.debug_line' section"));
15014 discard_cleanups (back_to
);
15018 /* Subroutine of dwarf_decode_lines to simplify it.
15019 Return the file name of the psymtab for included file FILE_INDEX
15020 in line header LH of PST.
15021 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15022 If space for the result is malloc'd, it will be freed by a cleanup.
15023 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
15026 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
15027 const struct partial_symtab
*pst
,
15028 const char *comp_dir
)
15030 const struct file_entry fe
= lh
->file_names
[file_index
];
15031 char *include_name
= fe
.name
;
15032 char *include_name_to_compare
= include_name
;
15033 char *dir_name
= NULL
;
15034 const char *pst_filename
;
15035 char *copied_name
= NULL
;
15039 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
15041 if (!IS_ABSOLUTE_PATH (include_name
)
15042 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
15044 /* Avoid creating a duplicate psymtab for PST.
15045 We do this by comparing INCLUDE_NAME and PST_FILENAME.
15046 Before we do the comparison, however, we need to account
15047 for DIR_NAME and COMP_DIR.
15048 First prepend dir_name (if non-NULL). If we still don't
15049 have an absolute path prepend comp_dir (if non-NULL).
15050 However, the directory we record in the include-file's
15051 psymtab does not contain COMP_DIR (to match the
15052 corresponding symtab(s)).
15057 bash$ gcc -g ./hello.c
15058 include_name = "hello.c"
15060 DW_AT_comp_dir = comp_dir = "/tmp"
15061 DW_AT_name = "./hello.c" */
15063 if (dir_name
!= NULL
)
15065 include_name
= concat (dir_name
, SLASH_STRING
,
15066 include_name
, (char *)NULL
);
15067 include_name_to_compare
= include_name
;
15068 make_cleanup (xfree
, include_name
);
15070 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
15072 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
15073 include_name
, (char *)NULL
);
15077 pst_filename
= pst
->filename
;
15078 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
15080 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
15081 pst_filename
, (char *)NULL
);
15082 pst_filename
= copied_name
;
15085 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
15087 if (include_name_to_compare
!= include_name
)
15088 xfree (include_name_to_compare
);
15089 if (copied_name
!= NULL
)
15090 xfree (copied_name
);
15094 return include_name
;
15097 /* Ignore this record_line request. */
15100 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15105 /* Subroutine of dwarf_decode_lines to simplify it.
15106 Process the line number information in LH. */
15109 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
15110 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
15112 gdb_byte
*line_ptr
, *extended_end
;
15113 gdb_byte
*line_end
;
15114 unsigned int bytes_read
, extended_len
;
15115 unsigned char op_code
, extended_op
, adj_opcode
;
15116 CORE_ADDR baseaddr
;
15117 struct objfile
*objfile
= cu
->objfile
;
15118 bfd
*abfd
= objfile
->obfd
;
15119 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15120 const int decode_for_pst_p
= (pst
!= NULL
);
15121 struct subfile
*last_subfile
= NULL
;
15122 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15125 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15127 line_ptr
= lh
->statement_program_start
;
15128 line_end
= lh
->statement_program_end
;
15130 /* Read the statement sequences until there's nothing left. */
15131 while (line_ptr
< line_end
)
15133 /* state machine registers */
15134 CORE_ADDR address
= 0;
15135 unsigned int file
= 1;
15136 unsigned int line
= 1;
15137 unsigned int column
= 0;
15138 int is_stmt
= lh
->default_is_stmt
;
15139 int basic_block
= 0;
15140 int end_sequence
= 0;
15142 unsigned char op_index
= 0;
15144 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
15146 /* Start a subfile for the current file of the state machine. */
15147 /* lh->include_dirs and lh->file_names are 0-based, but the
15148 directory and file name numbers in the statement program
15150 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15154 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15156 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15159 /* Decode the table. */
15160 while (!end_sequence
)
15162 op_code
= read_1_byte (abfd
, line_ptr
);
15164 if (line_ptr
> line_end
)
15166 dwarf2_debug_line_missing_end_sequence_complaint ();
15170 if (op_code
>= lh
->opcode_base
)
15172 /* Special operand. */
15173 adj_opcode
= op_code
- lh
->opcode_base
;
15174 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
15175 / lh
->maximum_ops_per_instruction
)
15176 * lh
->minimum_instruction_length
);
15177 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
15178 % lh
->maximum_ops_per_instruction
);
15179 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
15180 if (lh
->num_file_names
< file
|| file
== 0)
15181 dwarf2_debug_line_missing_file_complaint ();
15182 /* For now we ignore lines not starting on an
15183 instruction boundary. */
15184 else if (op_index
== 0)
15186 lh
->file_names
[file
- 1].included_p
= 1;
15187 if (!decode_for_pst_p
&& is_stmt
)
15189 if (last_subfile
!= current_subfile
)
15191 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15193 (*p_record_line
) (last_subfile
, 0, addr
);
15194 last_subfile
= current_subfile
;
15196 /* Append row to matrix using current values. */
15197 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15198 (*p_record_line
) (current_subfile
, line
, addr
);
15203 else switch (op_code
)
15205 case DW_LNS_extended_op
:
15206 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
15208 line_ptr
+= bytes_read
;
15209 extended_end
= line_ptr
+ extended_len
;
15210 extended_op
= read_1_byte (abfd
, line_ptr
);
15212 switch (extended_op
)
15214 case DW_LNE_end_sequence
:
15215 p_record_line
= record_line
;
15218 case DW_LNE_set_address
:
15219 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
15221 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15223 /* This line table is for a function which has been
15224 GCd by the linker. Ignore it. PR gdb/12528 */
15227 = line_ptr
- get_debug_line_section (cu
)->buffer
;
15229 complaint (&symfile_complaints
,
15230 _(".debug_line address at offset 0x%lx is 0 "
15232 line_offset
, objfile
->name
);
15233 p_record_line
= noop_record_line
;
15237 line_ptr
+= bytes_read
;
15238 address
+= baseaddr
;
15240 case DW_LNE_define_file
:
15243 unsigned int dir_index
, mod_time
, length
;
15245 cur_file
= read_direct_string (abfd
, line_ptr
,
15247 line_ptr
+= bytes_read
;
15249 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15250 line_ptr
+= bytes_read
;
15252 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15253 line_ptr
+= bytes_read
;
15255 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15256 line_ptr
+= bytes_read
;
15257 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15260 case DW_LNE_set_discriminator
:
15261 /* The discriminator is not interesting to the debugger;
15263 line_ptr
= extended_end
;
15266 complaint (&symfile_complaints
,
15267 _("mangled .debug_line section"));
15270 /* Make sure that we parsed the extended op correctly. If e.g.
15271 we expected a different address size than the producer used,
15272 we may have read the wrong number of bytes. */
15273 if (line_ptr
!= extended_end
)
15275 complaint (&symfile_complaints
,
15276 _("mangled .debug_line section"));
15281 if (lh
->num_file_names
< file
|| file
== 0)
15282 dwarf2_debug_line_missing_file_complaint ();
15285 lh
->file_names
[file
- 1].included_p
= 1;
15286 if (!decode_for_pst_p
&& is_stmt
)
15288 if (last_subfile
!= current_subfile
)
15290 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15292 (*p_record_line
) (last_subfile
, 0, addr
);
15293 last_subfile
= current_subfile
;
15295 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15296 (*p_record_line
) (current_subfile
, line
, addr
);
15301 case DW_LNS_advance_pc
:
15304 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15306 address
+= (((op_index
+ adjust
)
15307 / lh
->maximum_ops_per_instruction
)
15308 * lh
->minimum_instruction_length
);
15309 op_index
= ((op_index
+ adjust
)
15310 % lh
->maximum_ops_per_instruction
);
15311 line_ptr
+= bytes_read
;
15314 case DW_LNS_advance_line
:
15315 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
15316 line_ptr
+= bytes_read
;
15318 case DW_LNS_set_file
:
15320 /* The arrays lh->include_dirs and lh->file_names are
15321 0-based, but the directory and file name numbers in
15322 the statement program are 1-based. */
15323 struct file_entry
*fe
;
15326 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15327 line_ptr
+= bytes_read
;
15328 if (lh
->num_file_names
< file
|| file
== 0)
15329 dwarf2_debug_line_missing_file_complaint ();
15332 fe
= &lh
->file_names
[file
- 1];
15334 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15335 if (!decode_for_pst_p
)
15337 last_subfile
= current_subfile
;
15338 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15343 case DW_LNS_set_column
:
15344 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15345 line_ptr
+= bytes_read
;
15347 case DW_LNS_negate_stmt
:
15348 is_stmt
= (!is_stmt
);
15350 case DW_LNS_set_basic_block
:
15353 /* Add to the address register of the state machine the
15354 address increment value corresponding to special opcode
15355 255. I.e., this value is scaled by the minimum
15356 instruction length since special opcode 255 would have
15357 scaled the increment. */
15358 case DW_LNS_const_add_pc
:
15360 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
15362 address
+= (((op_index
+ adjust
)
15363 / lh
->maximum_ops_per_instruction
)
15364 * lh
->minimum_instruction_length
);
15365 op_index
= ((op_index
+ adjust
)
15366 % lh
->maximum_ops_per_instruction
);
15369 case DW_LNS_fixed_advance_pc
:
15370 address
+= read_2_bytes (abfd
, line_ptr
);
15376 /* Unknown standard opcode, ignore it. */
15379 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
15381 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15382 line_ptr
+= bytes_read
;
15387 if (lh
->num_file_names
< file
|| file
== 0)
15388 dwarf2_debug_line_missing_file_complaint ();
15391 lh
->file_names
[file
- 1].included_p
= 1;
15392 if (!decode_for_pst_p
)
15394 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15395 (*p_record_line
) (current_subfile
, 0, addr
);
15401 /* Decode the Line Number Program (LNP) for the given line_header
15402 structure and CU. The actual information extracted and the type
15403 of structures created from the LNP depends on the value of PST.
15405 1. If PST is NULL, then this procedure uses the data from the program
15406 to create all necessary symbol tables, and their linetables.
15408 2. If PST is not NULL, this procedure reads the program to determine
15409 the list of files included by the unit represented by PST, and
15410 builds all the associated partial symbol tables.
15412 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15413 It is used for relative paths in the line table.
15414 NOTE: When processing partial symtabs (pst != NULL),
15415 comp_dir == pst->dirname.
15417 NOTE: It is important that psymtabs have the same file name (via strcmp)
15418 as the corresponding symtab. Since COMP_DIR is not used in the name of the
15419 symtab we don't use it in the name of the psymtabs we create.
15420 E.g. expand_line_sal requires this when finding psymtabs to expand.
15421 A good testcase for this is mb-inline.exp. */
15424 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
15425 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
15426 int want_line_info
)
15428 struct objfile
*objfile
= cu
->objfile
;
15429 const int decode_for_pst_p
= (pst
!= NULL
);
15430 struct subfile
*first_subfile
= current_subfile
;
15432 if (want_line_info
)
15433 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
15435 if (decode_for_pst_p
)
15439 /* Now that we're done scanning the Line Header Program, we can
15440 create the psymtab of each included file. */
15441 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
15442 if (lh
->file_names
[file_index
].included_p
== 1)
15444 char *include_name
=
15445 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
15446 if (include_name
!= NULL
)
15447 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
15452 /* Make sure a symtab is created for every file, even files
15453 which contain only variables (i.e. no code with associated
15457 for (i
= 0; i
< lh
->num_file_names
; i
++)
15460 struct file_entry
*fe
;
15462 fe
= &lh
->file_names
[i
];
15464 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15465 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15467 /* Skip the main file; we don't need it, and it must be
15468 allocated last, so that it will show up before the
15469 non-primary symtabs in the objfile's symtab list. */
15470 if (current_subfile
== first_subfile
)
15473 if (current_subfile
->symtab
== NULL
)
15474 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
15476 fe
->symtab
= current_subfile
->symtab
;
15481 /* Start a subfile for DWARF. FILENAME is the name of the file and
15482 DIRNAME the name of the source directory which contains FILENAME
15483 or NULL if not known. COMP_DIR is the compilation directory for the
15484 linetable's compilation unit or NULL if not known.
15485 This routine tries to keep line numbers from identical absolute and
15486 relative file names in a common subfile.
15488 Using the `list' example from the GDB testsuite, which resides in
15489 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
15490 of /srcdir/list0.c yields the following debugging information for list0.c:
15492 DW_AT_name: /srcdir/list0.c
15493 DW_AT_comp_dir: /compdir
15494 files.files[0].name: list0.h
15495 files.files[0].dir: /srcdir
15496 files.files[1].name: list0.c
15497 files.files[1].dir: /srcdir
15499 The line number information for list0.c has to end up in a single
15500 subfile, so that `break /srcdir/list0.c:1' works as expected.
15501 start_subfile will ensure that this happens provided that we pass the
15502 concatenation of files.files[1].dir and files.files[1].name as the
15506 dwarf2_start_subfile (char *filename
, const char *dirname
,
15507 const char *comp_dir
)
15511 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
15512 `start_symtab' will always pass the contents of DW_AT_comp_dir as
15513 second argument to start_subfile. To be consistent, we do the
15514 same here. In order not to lose the line information directory,
15515 we concatenate it to the filename when it makes sense.
15516 Note that the Dwarf3 standard says (speaking of filenames in line
15517 information): ``The directory index is ignored for file names
15518 that represent full path names''. Thus ignoring dirname in the
15519 `else' branch below isn't an issue. */
15521 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
15522 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
15524 fullname
= filename
;
15526 start_subfile (fullname
, comp_dir
);
15528 if (fullname
!= filename
)
15532 /* Start a symtab for DWARF.
15533 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
15536 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
15537 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
15539 start_symtab (name
, comp_dir
, low_pc
);
15540 record_debugformat ("DWARF 2");
15541 record_producer (cu
->producer
);
15543 /* We assume that we're processing GCC output. */
15544 processing_gcc_compilation
= 2;
15546 processing_has_namespace_info
= 0;
15550 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
15551 struct dwarf2_cu
*cu
)
15553 struct objfile
*objfile
= cu
->objfile
;
15554 struct comp_unit_head
*cu_header
= &cu
->header
;
15556 /* NOTE drow/2003-01-30: There used to be a comment and some special
15557 code here to turn a symbol with DW_AT_external and a
15558 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
15559 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
15560 with some versions of binutils) where shared libraries could have
15561 relocations against symbols in their debug information - the
15562 minimal symbol would have the right address, but the debug info
15563 would not. It's no longer necessary, because we will explicitly
15564 apply relocations when we read in the debug information now. */
15566 /* A DW_AT_location attribute with no contents indicates that a
15567 variable has been optimized away. */
15568 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
15570 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15574 /* Handle one degenerate form of location expression specially, to
15575 preserve GDB's previous behavior when section offsets are
15576 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
15577 then mark this symbol as LOC_STATIC. */
15579 if (attr_form_is_block (attr
)
15580 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
15581 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
15582 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
15583 && (DW_BLOCK (attr
)->size
15584 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
15586 unsigned int dummy
;
15588 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
15589 SYMBOL_VALUE_ADDRESS (sym
) =
15590 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
15592 SYMBOL_VALUE_ADDRESS (sym
) =
15593 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
15594 SYMBOL_CLASS (sym
) = LOC_STATIC
;
15595 fixup_symbol_section (sym
, objfile
);
15596 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
15597 SYMBOL_SECTION (sym
));
15601 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
15602 expression evaluator, and use LOC_COMPUTED only when necessary
15603 (i.e. when the value of a register or memory location is
15604 referenced, or a thread-local block, etc.). Then again, it might
15605 not be worthwhile. I'm assuming that it isn't unless performance
15606 or memory numbers show me otherwise. */
15608 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
15609 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15611 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
15612 cu
->has_loclist
= 1;
15615 /* Given a pointer to a DWARF information entry, figure out if we need
15616 to make a symbol table entry for it, and if so, create a new entry
15617 and return a pointer to it.
15618 If TYPE is NULL, determine symbol type from the die, otherwise
15619 used the passed type.
15620 If SPACE is not NULL, use it to hold the new symbol. If it is
15621 NULL, allocate a new symbol on the objfile's obstack. */
15623 static struct symbol
*
15624 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
15625 struct symbol
*space
)
15627 struct objfile
*objfile
= cu
->objfile
;
15628 struct symbol
*sym
= NULL
;
15630 struct attribute
*attr
= NULL
;
15631 struct attribute
*attr2
= NULL
;
15632 CORE_ADDR baseaddr
;
15633 struct pending
**list_to_add
= NULL
;
15635 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
15637 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15639 name
= dwarf2_name (die
, cu
);
15642 const char *linkagename
;
15643 int suppress_add
= 0;
15648 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
15649 OBJSTAT (objfile
, n_syms
++);
15651 /* Cache this symbol's name and the name's demangled form (if any). */
15652 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
15653 linkagename
= dwarf2_physname (name
, die
, cu
);
15654 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
15656 /* Fortran does not have mangling standard and the mangling does differ
15657 between gfortran, iFort etc. */
15658 if (cu
->language
== language_fortran
15659 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
15660 symbol_set_demangled_name (&(sym
->ginfo
),
15661 (char *) dwarf2_full_name (name
, die
, cu
),
15664 /* Default assumptions.
15665 Use the passed type or decode it from the die. */
15666 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15667 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15669 SYMBOL_TYPE (sym
) = type
;
15671 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
15672 attr
= dwarf2_attr (die
,
15673 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
15677 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
15680 attr
= dwarf2_attr (die
,
15681 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
15685 int file_index
= DW_UNSND (attr
);
15687 if (cu
->line_header
== NULL
15688 || file_index
> cu
->line_header
->num_file_names
)
15689 complaint (&symfile_complaints
,
15690 _("file index out of range"));
15691 else if (file_index
> 0)
15693 struct file_entry
*fe
;
15695 fe
= &cu
->line_header
->file_names
[file_index
- 1];
15696 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
15703 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15706 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
15708 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
15709 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
15710 SYMBOL_CLASS (sym
) = LOC_LABEL
;
15711 add_symbol_to_list (sym
, cu
->list_in_scope
);
15713 case DW_TAG_subprogram
:
15714 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15716 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15717 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15718 if ((attr2
&& (DW_UNSND (attr2
) != 0))
15719 || cu
->language
== language_ada
)
15721 /* Subprograms marked external are stored as a global symbol.
15722 Ada subprograms, whether marked external or not, are always
15723 stored as a global symbol, because we want to be able to
15724 access them globally. For instance, we want to be able
15725 to break on a nested subprogram without having to
15726 specify the context. */
15727 list_to_add
= &global_symbols
;
15731 list_to_add
= cu
->list_in_scope
;
15734 case DW_TAG_inlined_subroutine
:
15735 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15737 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15738 SYMBOL_INLINED (sym
) = 1;
15739 list_to_add
= cu
->list_in_scope
;
15741 case DW_TAG_template_value_param
:
15743 /* Fall through. */
15744 case DW_TAG_constant
:
15745 case DW_TAG_variable
:
15746 case DW_TAG_member
:
15747 /* Compilation with minimal debug info may result in
15748 variables with missing type entries. Change the
15749 misleading `void' type to something sensible. */
15750 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
15752 = objfile_type (objfile
)->nodebug_data_symbol
;
15754 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15755 /* In the case of DW_TAG_member, we should only be called for
15756 static const members. */
15757 if (die
->tag
== DW_TAG_member
)
15759 /* dwarf2_add_field uses die_is_declaration,
15760 so we do the same. */
15761 gdb_assert (die_is_declaration (die
, cu
));
15766 dwarf2_const_value (attr
, sym
, cu
);
15767 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15770 if (attr2
&& (DW_UNSND (attr2
) != 0))
15771 list_to_add
= &global_symbols
;
15773 list_to_add
= cu
->list_in_scope
;
15777 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15780 var_decode_location (attr
, sym
, cu
);
15781 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15783 /* Fortran explicitly imports any global symbols to the local
15784 scope by DW_TAG_common_block. */
15785 if (cu
->language
== language_fortran
&& die
->parent
15786 && die
->parent
->tag
== DW_TAG_common_block
)
15789 if (SYMBOL_CLASS (sym
) == LOC_STATIC
15790 && SYMBOL_VALUE_ADDRESS (sym
) == 0
15791 && !dwarf2_per_objfile
->has_section_at_zero
)
15793 /* When a static variable is eliminated by the linker,
15794 the corresponding debug information is not stripped
15795 out, but the variable address is set to null;
15796 do not add such variables into symbol table. */
15798 else if (attr2
&& (DW_UNSND (attr2
) != 0))
15800 /* Workaround gfortran PR debug/40040 - it uses
15801 DW_AT_location for variables in -fPIC libraries which may
15802 get overriden by other libraries/executable and get
15803 a different address. Resolve it by the minimal symbol
15804 which may come from inferior's executable using copy
15805 relocation. Make this workaround only for gfortran as for
15806 other compilers GDB cannot guess the minimal symbol
15807 Fortran mangling kind. */
15808 if (cu
->language
== language_fortran
&& die
->parent
15809 && die
->parent
->tag
== DW_TAG_module
15811 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
15812 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15814 /* A variable with DW_AT_external is never static,
15815 but it may be block-scoped. */
15816 list_to_add
= (cu
->list_in_scope
== &file_symbols
15817 ? &global_symbols
: cu
->list_in_scope
);
15820 list_to_add
= cu
->list_in_scope
;
15824 /* We do not know the address of this symbol.
15825 If it is an external symbol and we have type information
15826 for it, enter the symbol as a LOC_UNRESOLVED symbol.
15827 The address of the variable will then be determined from
15828 the minimal symbol table whenever the variable is
15830 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15832 /* Fortran explicitly imports any global symbols to the local
15833 scope by DW_TAG_common_block. */
15834 if (cu
->language
== language_fortran
&& die
->parent
15835 && die
->parent
->tag
== DW_TAG_common_block
)
15837 /* SYMBOL_CLASS doesn't matter here because
15838 read_common_block is going to reset it. */
15840 list_to_add
= cu
->list_in_scope
;
15842 else if (attr2
&& (DW_UNSND (attr2
) != 0)
15843 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
15845 /* A variable with DW_AT_external is never static, but it
15846 may be block-scoped. */
15847 list_to_add
= (cu
->list_in_scope
== &file_symbols
15848 ? &global_symbols
: cu
->list_in_scope
);
15850 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15852 else if (!die_is_declaration (die
, cu
))
15854 /* Use the default LOC_OPTIMIZED_OUT class. */
15855 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
15857 list_to_add
= cu
->list_in_scope
;
15861 case DW_TAG_formal_parameter
:
15862 /* If we are inside a function, mark this as an argument. If
15863 not, we might be looking at an argument to an inlined function
15864 when we do not have enough information to show inlined frames;
15865 pretend it's a local variable in that case so that the user can
15867 if (context_stack_depth
> 0
15868 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
15869 SYMBOL_IS_ARGUMENT (sym
) = 1;
15870 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15873 var_decode_location (attr
, sym
, cu
);
15875 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15878 dwarf2_const_value (attr
, sym
, cu
);
15881 list_to_add
= cu
->list_in_scope
;
15883 case DW_TAG_unspecified_parameters
:
15884 /* From varargs functions; gdb doesn't seem to have any
15885 interest in this information, so just ignore it for now.
15888 case DW_TAG_template_type_param
:
15890 /* Fall through. */
15891 case DW_TAG_class_type
:
15892 case DW_TAG_interface_type
:
15893 case DW_TAG_structure_type
:
15894 case DW_TAG_union_type
:
15895 case DW_TAG_set_type
:
15896 case DW_TAG_enumeration_type
:
15897 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15898 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
15901 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
15902 really ever be static objects: otherwise, if you try
15903 to, say, break of a class's method and you're in a file
15904 which doesn't mention that class, it won't work unless
15905 the check for all static symbols in lookup_symbol_aux
15906 saves you. See the OtherFileClass tests in
15907 gdb.c++/namespace.exp. */
15911 list_to_add
= (cu
->list_in_scope
== &file_symbols
15912 && (cu
->language
== language_cplus
15913 || cu
->language
== language_java
)
15914 ? &global_symbols
: cu
->list_in_scope
);
15916 /* The semantics of C++ state that "struct foo {
15917 ... }" also defines a typedef for "foo". A Java
15918 class declaration also defines a typedef for the
15920 if (cu
->language
== language_cplus
15921 || cu
->language
== language_java
15922 || cu
->language
== language_ada
)
15924 /* The symbol's name is already allocated along
15925 with this objfile, so we don't need to
15926 duplicate it for the type. */
15927 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
15928 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
15933 case DW_TAG_typedef
:
15934 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15935 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15936 list_to_add
= cu
->list_in_scope
;
15938 case DW_TAG_base_type
:
15939 case DW_TAG_subrange_type
:
15940 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15941 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15942 list_to_add
= cu
->list_in_scope
;
15944 case DW_TAG_enumerator
:
15945 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15948 dwarf2_const_value (attr
, sym
, cu
);
15951 /* NOTE: carlton/2003-11-10: See comment above in the
15952 DW_TAG_class_type, etc. block. */
15954 list_to_add
= (cu
->list_in_scope
== &file_symbols
15955 && (cu
->language
== language_cplus
15956 || cu
->language
== language_java
)
15957 ? &global_symbols
: cu
->list_in_scope
);
15960 case DW_TAG_namespace
:
15961 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15962 list_to_add
= &global_symbols
;
15964 case DW_TAG_common_block
:
15965 SYMBOL_CLASS (sym
) = LOC_STATIC
;
15966 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
15967 add_symbol_to_list (sym
, cu
->list_in_scope
);
15970 /* Not a tag we recognize. Hopefully we aren't processing
15971 trash data, but since we must specifically ignore things
15972 we don't recognize, there is nothing else we should do at
15974 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
15975 dwarf_tag_name (die
->tag
));
15981 sym
->hash_next
= objfile
->template_symbols
;
15982 objfile
->template_symbols
= sym
;
15983 list_to_add
= NULL
;
15986 if (list_to_add
!= NULL
)
15987 add_symbol_to_list (sym
, list_to_add
);
15989 /* For the benefit of old versions of GCC, check for anonymous
15990 namespaces based on the demangled name. */
15991 if (!processing_has_namespace_info
15992 && cu
->language
== language_cplus
)
15993 cp_scan_for_anonymous_namespaces (sym
, objfile
);
15998 /* A wrapper for new_symbol_full that always allocates a new symbol. */
16000 static struct symbol
*
16001 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16003 return new_symbol_full (die
, type
, cu
, NULL
);
16006 /* Given an attr with a DW_FORM_dataN value in host byte order,
16007 zero-extend it as appropriate for the symbol's type. The DWARF
16008 standard (v4) is not entirely clear about the meaning of using
16009 DW_FORM_dataN for a constant with a signed type, where the type is
16010 wider than the data. The conclusion of a discussion on the DWARF
16011 list was that this is unspecified. We choose to always zero-extend
16012 because that is the interpretation long in use by GCC. */
16015 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
16016 const char *name
, struct obstack
*obstack
,
16017 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
16019 struct objfile
*objfile
= cu
->objfile
;
16020 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
16021 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
16022 LONGEST l
= DW_UNSND (attr
);
16024 if (bits
< sizeof (*value
) * 8)
16026 l
&= ((LONGEST
) 1 << bits
) - 1;
16029 else if (bits
== sizeof (*value
) * 8)
16033 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
16034 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
16041 /* Read a constant value from an attribute. Either set *VALUE, or if
16042 the value does not fit in *VALUE, set *BYTES - either already
16043 allocated on the objfile obstack, or newly allocated on OBSTACK,
16044 or, set *BATON, if we translated the constant to a location
16048 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
16049 const char *name
, struct obstack
*obstack
,
16050 struct dwarf2_cu
*cu
,
16051 LONGEST
*value
, gdb_byte
**bytes
,
16052 struct dwarf2_locexpr_baton
**baton
)
16054 struct objfile
*objfile
= cu
->objfile
;
16055 struct comp_unit_head
*cu_header
= &cu
->header
;
16056 struct dwarf_block
*blk
;
16057 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
16058 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
16064 switch (attr
->form
)
16067 case DW_FORM_GNU_addr_index
:
16071 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
16072 dwarf2_const_value_length_mismatch_complaint (name
,
16073 cu_header
->addr_size
,
16074 TYPE_LENGTH (type
));
16075 /* Symbols of this form are reasonably rare, so we just
16076 piggyback on the existing location code rather than writing
16077 a new implementation of symbol_computed_ops. */
16078 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
16079 sizeof (struct dwarf2_locexpr_baton
));
16080 (*baton
)->per_cu
= cu
->per_cu
;
16081 gdb_assert ((*baton
)->per_cu
);
16083 (*baton
)->size
= 2 + cu_header
->addr_size
;
16084 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
16085 (*baton
)->data
= data
;
16087 data
[0] = DW_OP_addr
;
16088 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
16089 byte_order
, DW_ADDR (attr
));
16090 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
16093 case DW_FORM_string
:
16095 case DW_FORM_GNU_str_index
:
16096 case DW_FORM_GNU_strp_alt
:
16097 /* DW_STRING is already allocated on the objfile obstack, point
16099 *bytes
= (gdb_byte
*) DW_STRING (attr
);
16101 case DW_FORM_block1
:
16102 case DW_FORM_block2
:
16103 case DW_FORM_block4
:
16104 case DW_FORM_block
:
16105 case DW_FORM_exprloc
:
16106 blk
= DW_BLOCK (attr
);
16107 if (TYPE_LENGTH (type
) != blk
->size
)
16108 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
16109 TYPE_LENGTH (type
));
16110 *bytes
= blk
->data
;
16113 /* The DW_AT_const_value attributes are supposed to carry the
16114 symbol's value "represented as it would be on the target
16115 architecture." By the time we get here, it's already been
16116 converted to host endianness, so we just need to sign- or
16117 zero-extend it as appropriate. */
16118 case DW_FORM_data1
:
16119 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16120 obstack
, cu
, value
, 8);
16122 case DW_FORM_data2
:
16123 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16124 obstack
, cu
, value
, 16);
16126 case DW_FORM_data4
:
16127 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16128 obstack
, cu
, value
, 32);
16130 case DW_FORM_data8
:
16131 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16132 obstack
, cu
, value
, 64);
16135 case DW_FORM_sdata
:
16136 *value
= DW_SND (attr
);
16139 case DW_FORM_udata
:
16140 *value
= DW_UNSND (attr
);
16144 complaint (&symfile_complaints
,
16145 _("unsupported const value attribute form: '%s'"),
16146 dwarf_form_name (attr
->form
));
16153 /* Copy constant value from an attribute to a symbol. */
16156 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
16157 struct dwarf2_cu
*cu
)
16159 struct objfile
*objfile
= cu
->objfile
;
16160 struct comp_unit_head
*cu_header
= &cu
->header
;
16163 struct dwarf2_locexpr_baton
*baton
;
16165 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
16166 SYMBOL_PRINT_NAME (sym
),
16167 &objfile
->objfile_obstack
, cu
,
16168 &value
, &bytes
, &baton
);
16172 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16173 SYMBOL_LOCATION_BATON (sym
) = baton
;
16174 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
16176 else if (bytes
!= NULL
)
16178 SYMBOL_VALUE_BYTES (sym
) = bytes
;
16179 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
16183 SYMBOL_VALUE (sym
) = value
;
16184 SYMBOL_CLASS (sym
) = LOC_CONST
;
16188 /* Return the type of the die in question using its DW_AT_type attribute. */
16190 static struct type
*
16191 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16193 struct attribute
*type_attr
;
16195 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16198 /* A missing DW_AT_type represents a void type. */
16199 return objfile_type (cu
->objfile
)->builtin_void
;
16202 return lookup_die_type (die
, type_attr
, cu
);
16205 /* True iff CU's producer generates GNAT Ada auxiliary information
16206 that allows to find parallel types through that information instead
16207 of having to do expensive parallel lookups by type name. */
16210 need_gnat_info (struct dwarf2_cu
*cu
)
16212 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
16213 of GNAT produces this auxiliary information, without any indication
16214 that it is produced. Part of enhancing the FSF version of GNAT
16215 to produce that information will be to put in place an indicator
16216 that we can use in order to determine whether the descriptive type
16217 info is available or not. One suggestion that has been made is
16218 to use a new attribute, attached to the CU die. For now, assume
16219 that the descriptive type info is not available. */
16223 /* Return the auxiliary type of the die in question using its
16224 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
16225 attribute is not present. */
16227 static struct type
*
16228 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16230 struct attribute
*type_attr
;
16232 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
16236 return lookup_die_type (die
, type_attr
, cu
);
16239 /* If DIE has a descriptive_type attribute, then set the TYPE's
16240 descriptive type accordingly. */
16243 set_descriptive_type (struct type
*type
, struct die_info
*die
,
16244 struct dwarf2_cu
*cu
)
16246 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
16248 if (descriptive_type
)
16250 ALLOCATE_GNAT_AUX_TYPE (type
);
16251 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
16255 /* Return the containing type of the die in question using its
16256 DW_AT_containing_type attribute. */
16258 static struct type
*
16259 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16261 struct attribute
*type_attr
;
16263 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
16265 error (_("Dwarf Error: Problem turning containing type into gdb type "
16266 "[in module %s]"), cu
->objfile
->name
);
16268 return lookup_die_type (die
, type_attr
, cu
);
16271 /* Look up the type of DIE in CU using its type attribute ATTR.
16272 If there is no type substitute an error marker. */
16274 static struct type
*
16275 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
16276 struct dwarf2_cu
*cu
)
16278 struct objfile
*objfile
= cu
->objfile
;
16279 struct type
*this_type
;
16281 /* First see if we have it cached. */
16283 if (attr
->form
== DW_FORM_GNU_ref_alt
)
16285 struct dwarf2_per_cu_data
*per_cu
;
16286 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16288 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
16289 this_type
= get_die_type_at_offset (offset
, per_cu
);
16291 else if (is_ref_attr (attr
))
16293 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16295 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
16297 else if (attr
->form
== DW_FORM_ref_sig8
)
16299 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16301 /* sig_type will be NULL if the signatured type is missing from
16303 if (sig_type
== NULL
)
16304 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16305 "at 0x%x [in module %s]"),
16306 die
->offset
.sect_off
, objfile
->name
);
16308 gdb_assert (sig_type
->per_cu
.is_debug_types
);
16309 /* If we haven't filled in type_offset_in_section yet, then we
16310 haven't read the type in yet. */
16312 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
16315 get_die_type_at_offset (sig_type
->type_offset_in_section
,
16316 &sig_type
->per_cu
);
16321 dump_die_for_error (die
);
16322 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
16323 dwarf_attr_name (attr
->name
), objfile
->name
);
16326 /* If not cached we need to read it in. */
16328 if (this_type
== NULL
)
16330 struct die_info
*type_die
;
16331 struct dwarf2_cu
*type_cu
= cu
;
16333 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
16334 /* If we found the type now, it's probably because the type came
16335 from an inter-CU reference and the type's CU got expanded before
16337 this_type
= get_die_type (type_die
, type_cu
);
16338 if (this_type
== NULL
)
16339 this_type
= read_type_die_1 (type_die
, type_cu
);
16342 /* If we still don't have a type use an error marker. */
16344 if (this_type
== NULL
)
16346 char *message
, *saved
;
16348 /* read_type_die already issued a complaint. */
16349 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
16351 cu
->header
.offset
.sect_off
,
16352 die
->offset
.sect_off
);
16353 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
16354 message
, strlen (message
));
16357 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
16363 /* Return the type in DIE, CU.
16364 Returns NULL for invalid types.
16366 This first does a lookup in the appropriate type_hash table,
16367 and only reads the die in if necessary.
16369 NOTE: This can be called when reading in partial or full symbols. */
16371 static struct type
*
16372 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
16374 struct type
*this_type
;
16376 this_type
= get_die_type (die
, cu
);
16380 return read_type_die_1 (die
, cu
);
16383 /* Read the type in DIE, CU.
16384 Returns NULL for invalid types. */
16386 static struct type
*
16387 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
16389 struct type
*this_type
= NULL
;
16393 case DW_TAG_class_type
:
16394 case DW_TAG_interface_type
:
16395 case DW_TAG_structure_type
:
16396 case DW_TAG_union_type
:
16397 this_type
= read_structure_type (die
, cu
);
16399 case DW_TAG_enumeration_type
:
16400 this_type
= read_enumeration_type (die
, cu
);
16402 case DW_TAG_subprogram
:
16403 case DW_TAG_subroutine_type
:
16404 case DW_TAG_inlined_subroutine
:
16405 this_type
= read_subroutine_type (die
, cu
);
16407 case DW_TAG_array_type
:
16408 this_type
= read_array_type (die
, cu
);
16410 case DW_TAG_set_type
:
16411 this_type
= read_set_type (die
, cu
);
16413 case DW_TAG_pointer_type
:
16414 this_type
= read_tag_pointer_type (die
, cu
);
16416 case DW_TAG_ptr_to_member_type
:
16417 this_type
= read_tag_ptr_to_member_type (die
, cu
);
16419 case DW_TAG_reference_type
:
16420 this_type
= read_tag_reference_type (die
, cu
);
16422 case DW_TAG_const_type
:
16423 this_type
= read_tag_const_type (die
, cu
);
16425 case DW_TAG_volatile_type
:
16426 this_type
= read_tag_volatile_type (die
, cu
);
16428 case DW_TAG_string_type
:
16429 this_type
= read_tag_string_type (die
, cu
);
16431 case DW_TAG_typedef
:
16432 this_type
= read_typedef (die
, cu
);
16434 case DW_TAG_subrange_type
:
16435 this_type
= read_subrange_type (die
, cu
);
16437 case DW_TAG_base_type
:
16438 this_type
= read_base_type (die
, cu
);
16440 case DW_TAG_unspecified_type
:
16441 this_type
= read_unspecified_type (die
, cu
);
16443 case DW_TAG_namespace
:
16444 this_type
= read_namespace_type (die
, cu
);
16446 case DW_TAG_module
:
16447 this_type
= read_module_type (die
, cu
);
16450 complaint (&symfile_complaints
,
16451 _("unexpected tag in read_type_die: '%s'"),
16452 dwarf_tag_name (die
->tag
));
16459 /* See if we can figure out if the class lives in a namespace. We do
16460 this by looking for a member function; its demangled name will
16461 contain namespace info, if there is any.
16462 Return the computed name or NULL.
16463 Space for the result is allocated on the objfile's obstack.
16464 This is the full-die version of guess_partial_die_structure_name.
16465 In this case we know DIE has no useful parent. */
16468 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16470 struct die_info
*spec_die
;
16471 struct dwarf2_cu
*spec_cu
;
16472 struct die_info
*child
;
16475 spec_die
= die_specification (die
, &spec_cu
);
16476 if (spec_die
!= NULL
)
16482 for (child
= die
->child
;
16484 child
= child
->sibling
)
16486 if (child
->tag
== DW_TAG_subprogram
)
16488 struct attribute
*attr
;
16490 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
16492 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
16496 = language_class_name_from_physname (cu
->language_defn
,
16500 if (actual_name
!= NULL
)
16502 char *die_name
= dwarf2_name (die
, cu
);
16504 if (die_name
!= NULL
16505 && strcmp (die_name
, actual_name
) != 0)
16507 /* Strip off the class name from the full name.
16508 We want the prefix. */
16509 int die_name_len
= strlen (die_name
);
16510 int actual_name_len
= strlen (actual_name
);
16512 /* Test for '::' as a sanity check. */
16513 if (actual_name_len
> die_name_len
+ 2
16514 && actual_name
[actual_name_len
16515 - die_name_len
- 1] == ':')
16517 obsavestring (actual_name
,
16518 actual_name_len
- die_name_len
- 2,
16519 &cu
->objfile
->objfile_obstack
);
16522 xfree (actual_name
);
16531 /* GCC might emit a nameless typedef that has a linkage name. Determine the
16532 prefix part in such case. See
16533 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16536 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16538 struct attribute
*attr
;
16541 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
16542 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
16545 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16546 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
16549 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16551 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16552 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16555 /* dwarf2_name had to be already called. */
16556 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
16558 /* Strip the base name, keep any leading namespaces/classes. */
16559 base
= strrchr (DW_STRING (attr
), ':');
16560 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
16563 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
16564 &cu
->objfile
->objfile_obstack
);
16567 /* Return the name of the namespace/class that DIE is defined within,
16568 or "" if we can't tell. The caller should not xfree the result.
16570 For example, if we're within the method foo() in the following
16580 then determine_prefix on foo's die will return "N::C". */
16582 static const char *
16583 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16585 struct die_info
*parent
, *spec_die
;
16586 struct dwarf2_cu
*spec_cu
;
16587 struct type
*parent_type
;
16590 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
16591 && cu
->language
!= language_fortran
)
16594 retval
= anonymous_struct_prefix (die
, cu
);
16598 /* We have to be careful in the presence of DW_AT_specification.
16599 For example, with GCC 3.4, given the code
16603 // Definition of N::foo.
16607 then we'll have a tree of DIEs like this:
16609 1: DW_TAG_compile_unit
16610 2: DW_TAG_namespace // N
16611 3: DW_TAG_subprogram // declaration of N::foo
16612 4: DW_TAG_subprogram // definition of N::foo
16613 DW_AT_specification // refers to die #3
16615 Thus, when processing die #4, we have to pretend that we're in
16616 the context of its DW_AT_specification, namely the contex of die
16619 spec_die
= die_specification (die
, &spec_cu
);
16620 if (spec_die
== NULL
)
16621 parent
= die
->parent
;
16624 parent
= spec_die
->parent
;
16628 if (parent
== NULL
)
16630 else if (parent
->building_fullname
)
16633 const char *parent_name
;
16635 /* It has been seen on RealView 2.2 built binaries,
16636 DW_TAG_template_type_param types actually _defined_ as
16637 children of the parent class:
16640 template class <class Enum> Class{};
16641 Class<enum E> class_e;
16643 1: DW_TAG_class_type (Class)
16644 2: DW_TAG_enumeration_type (E)
16645 3: DW_TAG_enumerator (enum1:0)
16646 3: DW_TAG_enumerator (enum2:1)
16648 2: DW_TAG_template_type_param
16649 DW_AT_type DW_FORM_ref_udata (E)
16651 Besides being broken debug info, it can put GDB into an
16652 infinite loop. Consider:
16654 When we're building the full name for Class<E>, we'll start
16655 at Class, and go look over its template type parameters,
16656 finding E. We'll then try to build the full name of E, and
16657 reach here. We're now trying to build the full name of E,
16658 and look over the parent DIE for containing scope. In the
16659 broken case, if we followed the parent DIE of E, we'd again
16660 find Class, and once again go look at its template type
16661 arguments, etc., etc. Simply don't consider such parent die
16662 as source-level parent of this die (it can't be, the language
16663 doesn't allow it), and break the loop here. */
16664 name
= dwarf2_name (die
, cu
);
16665 parent_name
= dwarf2_name (parent
, cu
);
16666 complaint (&symfile_complaints
,
16667 _("template param type '%s' defined within parent '%s'"),
16668 name
? name
: "<unknown>",
16669 parent_name
? parent_name
: "<unknown>");
16673 switch (parent
->tag
)
16675 case DW_TAG_namespace
:
16676 parent_type
= read_type_die (parent
, cu
);
16677 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
16678 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
16679 Work around this problem here. */
16680 if (cu
->language
== language_cplus
16681 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
16683 /* We give a name to even anonymous namespaces. */
16684 return TYPE_TAG_NAME (parent_type
);
16685 case DW_TAG_class_type
:
16686 case DW_TAG_interface_type
:
16687 case DW_TAG_structure_type
:
16688 case DW_TAG_union_type
:
16689 case DW_TAG_module
:
16690 parent_type
= read_type_die (parent
, cu
);
16691 if (TYPE_TAG_NAME (parent_type
) != NULL
)
16692 return TYPE_TAG_NAME (parent_type
);
16694 /* An anonymous structure is only allowed non-static data
16695 members; no typedefs, no member functions, et cetera.
16696 So it does not need a prefix. */
16698 case DW_TAG_compile_unit
:
16699 case DW_TAG_partial_unit
:
16700 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
16701 if (cu
->language
== language_cplus
16702 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16703 && die
->child
!= NULL
16704 && (die
->tag
== DW_TAG_class_type
16705 || die
->tag
== DW_TAG_structure_type
16706 || die
->tag
== DW_TAG_union_type
))
16708 char *name
= guess_full_die_structure_name (die
, cu
);
16714 return determine_prefix (parent
, cu
);
16718 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
16719 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
16720 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
16721 an obconcat, otherwise allocate storage for the result. The CU argument is
16722 used to determine the language and hence, the appropriate separator. */
16724 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
16727 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
16728 int physname
, struct dwarf2_cu
*cu
)
16730 const char *lead
= "";
16733 if (suffix
== NULL
|| suffix
[0] == '\0'
16734 || prefix
== NULL
|| prefix
[0] == '\0')
16736 else if (cu
->language
== language_java
)
16738 else if (cu
->language
== language_fortran
&& physname
)
16740 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
16741 DW_AT_MIPS_linkage_name is preferred and used instead. */
16749 if (prefix
== NULL
)
16751 if (suffix
== NULL
)
16757 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
16759 strcpy (retval
, lead
);
16760 strcat (retval
, prefix
);
16761 strcat (retval
, sep
);
16762 strcat (retval
, suffix
);
16767 /* We have an obstack. */
16768 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
16772 /* Return sibling of die, NULL if no sibling. */
16774 static struct die_info
*
16775 sibling_die (struct die_info
*die
)
16777 return die
->sibling
;
16780 /* Get name of a die, return NULL if not found. */
16783 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
16784 struct obstack
*obstack
)
16786 if (name
&& cu
->language
== language_cplus
)
16788 char *canon_name
= cp_canonicalize_string (name
);
16790 if (canon_name
!= NULL
)
16792 if (strcmp (canon_name
, name
) != 0)
16793 name
= obsavestring (canon_name
, strlen (canon_name
),
16795 xfree (canon_name
);
16802 /* Get name of a die, return NULL if not found. */
16805 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16807 struct attribute
*attr
;
16809 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16810 if ((!attr
|| !DW_STRING (attr
))
16811 && die
->tag
!= DW_TAG_class_type
16812 && die
->tag
!= DW_TAG_interface_type
16813 && die
->tag
!= DW_TAG_structure_type
16814 && die
->tag
!= DW_TAG_union_type
)
16819 case DW_TAG_compile_unit
:
16820 case DW_TAG_partial_unit
:
16821 /* Compilation units have a DW_AT_name that is a filename, not
16822 a source language identifier. */
16823 case DW_TAG_enumeration_type
:
16824 case DW_TAG_enumerator
:
16825 /* These tags always have simple identifiers already; no need
16826 to canonicalize them. */
16827 return DW_STRING (attr
);
16829 case DW_TAG_subprogram
:
16830 /* Java constructors will all be named "<init>", so return
16831 the class name when we see this special case. */
16832 if (cu
->language
== language_java
16833 && DW_STRING (attr
) != NULL
16834 && strcmp (DW_STRING (attr
), "<init>") == 0)
16836 struct dwarf2_cu
*spec_cu
= cu
;
16837 struct die_info
*spec_die
;
16839 /* GCJ will output '<init>' for Java constructor names.
16840 For this special case, return the name of the parent class. */
16842 /* GCJ may output suprogram DIEs with AT_specification set.
16843 If so, use the name of the specified DIE. */
16844 spec_die
= die_specification (die
, &spec_cu
);
16845 if (spec_die
!= NULL
)
16846 return dwarf2_name (spec_die
, spec_cu
);
16851 if (die
->tag
== DW_TAG_class_type
)
16852 return dwarf2_name (die
, cu
);
16854 while (die
->tag
!= DW_TAG_compile_unit
16855 && die
->tag
!= DW_TAG_partial_unit
);
16859 case DW_TAG_class_type
:
16860 case DW_TAG_interface_type
:
16861 case DW_TAG_structure_type
:
16862 case DW_TAG_union_type
:
16863 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
16864 structures or unions. These were of the form "._%d" in GCC 4.1,
16865 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
16866 and GCC 4.4. We work around this problem by ignoring these. */
16867 if (attr
&& DW_STRING (attr
)
16868 && (strncmp (DW_STRING (attr
), "._", 2) == 0
16869 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
16872 /* GCC might emit a nameless typedef that has a linkage name. See
16873 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16874 if (!attr
|| DW_STRING (attr
) == NULL
)
16876 char *demangled
= NULL
;
16878 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16880 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16882 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16885 /* Avoid demangling DW_STRING (attr) the second time on a second
16886 call for the same DIE. */
16887 if (!DW_STRING_IS_CANONICAL (attr
))
16888 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
16894 /* FIXME: we already did this for the partial symbol... */
16895 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
16896 &cu
->objfile
->objfile_obstack
);
16897 DW_STRING_IS_CANONICAL (attr
) = 1;
16900 /* Strip any leading namespaces/classes, keep only the base name.
16901 DW_AT_name for named DIEs does not contain the prefixes. */
16902 base
= strrchr (DW_STRING (attr
), ':');
16903 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
16906 return DW_STRING (attr
);
16915 if (!DW_STRING_IS_CANONICAL (attr
))
16918 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
16919 &cu
->objfile
->objfile_obstack
);
16920 DW_STRING_IS_CANONICAL (attr
) = 1;
16922 return DW_STRING (attr
);
16925 /* Return the die that this die in an extension of, or NULL if there
16926 is none. *EXT_CU is the CU containing DIE on input, and the CU
16927 containing the return value on output. */
16929 static struct die_info
*
16930 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
16932 struct attribute
*attr
;
16934 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
16938 return follow_die_ref (die
, attr
, ext_cu
);
16941 /* Convert a DIE tag into its string name. */
16943 static const char *
16944 dwarf_tag_name (unsigned tag
)
16946 const char *name
= get_DW_TAG_name (tag
);
16949 return "DW_TAG_<unknown>";
16954 /* Convert a DWARF attribute code into its string name. */
16956 static const char *
16957 dwarf_attr_name (unsigned attr
)
16961 #ifdef MIPS /* collides with DW_AT_HP_block_index */
16962 if (attr
== DW_AT_MIPS_fde
)
16963 return "DW_AT_MIPS_fde";
16965 if (attr
== DW_AT_HP_block_index
)
16966 return "DW_AT_HP_block_index";
16969 name
= get_DW_AT_name (attr
);
16972 return "DW_AT_<unknown>";
16977 /* Convert a DWARF value form code into its string name. */
16979 static const char *
16980 dwarf_form_name (unsigned form
)
16982 const char *name
= get_DW_FORM_name (form
);
16985 return "DW_FORM_<unknown>";
16991 dwarf_bool_name (unsigned mybool
)
16999 /* Convert a DWARF type code into its string name. */
17001 static const char *
17002 dwarf_type_encoding_name (unsigned enc
)
17004 const char *name
= get_DW_ATE_name (enc
);
17007 return "DW_ATE_<unknown>";
17013 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
17017 print_spaces (indent
, f
);
17018 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
17019 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
17021 if (die
->parent
!= NULL
)
17023 print_spaces (indent
, f
);
17024 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
17025 die
->parent
->offset
.sect_off
);
17028 print_spaces (indent
, f
);
17029 fprintf_unfiltered (f
, " has children: %s\n",
17030 dwarf_bool_name (die
->child
!= NULL
));
17032 print_spaces (indent
, f
);
17033 fprintf_unfiltered (f
, " attributes:\n");
17035 for (i
= 0; i
< die
->num_attrs
; ++i
)
17037 print_spaces (indent
, f
);
17038 fprintf_unfiltered (f
, " %s (%s) ",
17039 dwarf_attr_name (die
->attrs
[i
].name
),
17040 dwarf_form_name (die
->attrs
[i
].form
));
17042 switch (die
->attrs
[i
].form
)
17045 case DW_FORM_GNU_addr_index
:
17046 fprintf_unfiltered (f
, "address: ");
17047 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
17049 case DW_FORM_block2
:
17050 case DW_FORM_block4
:
17051 case DW_FORM_block
:
17052 case DW_FORM_block1
:
17053 fprintf_unfiltered (f
, "block: size %s",
17054 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17056 case DW_FORM_exprloc
:
17057 fprintf_unfiltered (f
, "expression: size %s",
17058 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17060 case DW_FORM_ref_addr
:
17061 fprintf_unfiltered (f
, "ref address: ");
17062 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17064 case DW_FORM_GNU_ref_alt
:
17065 fprintf_unfiltered (f
, "alt ref address: ");
17066 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17072 case DW_FORM_ref_udata
:
17073 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
17074 (long) (DW_UNSND (&die
->attrs
[i
])));
17076 case DW_FORM_data1
:
17077 case DW_FORM_data2
:
17078 case DW_FORM_data4
:
17079 case DW_FORM_data8
:
17080 case DW_FORM_udata
:
17081 case DW_FORM_sdata
:
17082 fprintf_unfiltered (f
, "constant: %s",
17083 pulongest (DW_UNSND (&die
->attrs
[i
])));
17085 case DW_FORM_sec_offset
:
17086 fprintf_unfiltered (f
, "section offset: %s",
17087 pulongest (DW_UNSND (&die
->attrs
[i
])));
17089 case DW_FORM_ref_sig8
:
17090 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
17091 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
17092 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
17094 fprintf_unfiltered (f
, "signatured type, offset: unknown");
17096 case DW_FORM_string
:
17098 case DW_FORM_GNU_str_index
:
17099 case DW_FORM_GNU_strp_alt
:
17100 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
17101 DW_STRING (&die
->attrs
[i
])
17102 ? DW_STRING (&die
->attrs
[i
]) : "",
17103 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
17106 if (DW_UNSND (&die
->attrs
[i
]))
17107 fprintf_unfiltered (f
, "flag: TRUE");
17109 fprintf_unfiltered (f
, "flag: FALSE");
17111 case DW_FORM_flag_present
:
17112 fprintf_unfiltered (f
, "flag: TRUE");
17114 case DW_FORM_indirect
:
17115 /* The reader will have reduced the indirect form to
17116 the "base form" so this form should not occur. */
17117 fprintf_unfiltered (f
,
17118 "unexpected attribute form: DW_FORM_indirect");
17121 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
17122 die
->attrs
[i
].form
);
17125 fprintf_unfiltered (f
, "\n");
17130 dump_die_for_error (struct die_info
*die
)
17132 dump_die_shallow (gdb_stderr
, 0, die
);
17136 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
17138 int indent
= level
* 4;
17140 gdb_assert (die
!= NULL
);
17142 if (level
>= max_level
)
17145 dump_die_shallow (f
, indent
, die
);
17147 if (die
->child
!= NULL
)
17149 print_spaces (indent
, f
);
17150 fprintf_unfiltered (f
, " Children:");
17151 if (level
+ 1 < max_level
)
17153 fprintf_unfiltered (f
, "\n");
17154 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
17158 fprintf_unfiltered (f
,
17159 " [not printed, max nesting level reached]\n");
17163 if (die
->sibling
!= NULL
&& level
> 0)
17165 dump_die_1 (f
, level
, max_level
, die
->sibling
);
17169 /* This is called from the pdie macro in gdbinit.in.
17170 It's not static so gcc will keep a copy callable from gdb. */
17173 dump_die (struct die_info
*die
, int max_level
)
17175 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
17179 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
17183 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
17189 /* DW_ADDR is always stored already as sect_offset; despite for the forms
17190 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
17193 is_ref_attr (struct attribute
*attr
)
17195 switch (attr
->form
)
17197 case DW_FORM_ref_addr
:
17202 case DW_FORM_ref_udata
:
17203 case DW_FORM_GNU_ref_alt
:
17210 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
17214 dwarf2_get_ref_die_offset (struct attribute
*attr
)
17216 sect_offset retval
= { DW_UNSND (attr
) };
17218 if (is_ref_attr (attr
))
17221 retval
.sect_off
= 0;
17222 complaint (&symfile_complaints
,
17223 _("unsupported die ref attribute form: '%s'"),
17224 dwarf_form_name (attr
->form
));
17228 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
17229 * the value held by the attribute is not constant. */
17232 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
17234 if (attr
->form
== DW_FORM_sdata
)
17235 return DW_SND (attr
);
17236 else if (attr
->form
== DW_FORM_udata
17237 || attr
->form
== DW_FORM_data1
17238 || attr
->form
== DW_FORM_data2
17239 || attr
->form
== DW_FORM_data4
17240 || attr
->form
== DW_FORM_data8
)
17241 return DW_UNSND (attr
);
17244 complaint (&symfile_complaints
,
17245 _("Attribute value is not a constant (%s)"),
17246 dwarf_form_name (attr
->form
));
17247 return default_value
;
17251 /* Follow reference or signature attribute ATTR of SRC_DIE.
17252 On entry *REF_CU is the CU of SRC_DIE.
17253 On exit *REF_CU is the CU of the result. */
17255 static struct die_info
*
17256 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
17257 struct dwarf2_cu
**ref_cu
)
17259 struct die_info
*die
;
17261 if (is_ref_attr (attr
))
17262 die
= follow_die_ref (src_die
, attr
, ref_cu
);
17263 else if (attr
->form
== DW_FORM_ref_sig8
)
17264 die
= follow_die_sig (src_die
, attr
, ref_cu
);
17267 dump_die_for_error (src_die
);
17268 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
17269 (*ref_cu
)->objfile
->name
);
17275 /* Follow reference OFFSET.
17276 On entry *REF_CU is the CU of the source die referencing OFFSET.
17277 On exit *REF_CU is the CU of the result.
17278 Returns NULL if OFFSET is invalid. */
17280 static struct die_info
*
17281 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
17282 struct dwarf2_cu
**ref_cu
)
17284 struct die_info temp_die
;
17285 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
17287 gdb_assert (cu
->per_cu
!= NULL
);
17291 if (cu
->per_cu
->is_debug_types
)
17293 /* .debug_types CUs cannot reference anything outside their CU.
17294 If they need to, they have to reference a signatured type via
17295 DW_FORM_ref_sig8. */
17296 if (! offset_in_cu_p (&cu
->header
, offset
))
17299 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
17300 || ! offset_in_cu_p (&cu
->header
, offset
))
17302 struct dwarf2_per_cu_data
*per_cu
;
17304 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
17307 /* If necessary, add it to the queue and load its DIEs. */
17308 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
17309 load_full_comp_unit (per_cu
, cu
->language
);
17311 target_cu
= per_cu
->cu
;
17313 else if (cu
->dies
== NULL
)
17315 /* We're loading full DIEs during partial symbol reading. */
17316 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
17317 load_full_comp_unit (cu
->per_cu
, language_minimal
);
17320 *ref_cu
= target_cu
;
17321 temp_die
.offset
= offset
;
17322 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
17325 /* Follow reference attribute ATTR of SRC_DIE.
17326 On entry *REF_CU is the CU of SRC_DIE.
17327 On exit *REF_CU is the CU of the result. */
17329 static struct die_info
*
17330 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
17331 struct dwarf2_cu
**ref_cu
)
17333 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17334 struct dwarf2_cu
*cu
= *ref_cu
;
17335 struct die_info
*die
;
17337 die
= follow_die_offset (offset
,
17338 (attr
->form
== DW_FORM_GNU_ref_alt
17339 || cu
->per_cu
->is_dwz
),
17342 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
17343 "at 0x%x [in module %s]"),
17344 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
17349 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
17350 Returned value is intended for DW_OP_call*. Returned
17351 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
17353 struct dwarf2_locexpr_baton
17354 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
17355 struct dwarf2_per_cu_data
*per_cu
,
17356 CORE_ADDR (*get_frame_pc
) (void *baton
),
17359 struct dwarf2_cu
*cu
;
17360 struct die_info
*die
;
17361 struct attribute
*attr
;
17362 struct dwarf2_locexpr_baton retval
;
17364 dw2_setup (per_cu
->objfile
);
17366 if (per_cu
->cu
== NULL
)
17370 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
17372 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
17373 offset
.sect_off
, per_cu
->objfile
->name
);
17375 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17378 /* DWARF: "If there is no such attribute, then there is no effect.".
17379 DATA is ignored if SIZE is 0. */
17381 retval
.data
= NULL
;
17384 else if (attr_form_is_section_offset (attr
))
17386 struct dwarf2_loclist_baton loclist_baton
;
17387 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
17390 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
17392 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
17394 retval
.size
= size
;
17398 if (!attr_form_is_block (attr
))
17399 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
17400 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
17401 offset
.sect_off
, per_cu
->objfile
->name
);
17403 retval
.data
= DW_BLOCK (attr
)->data
;
17404 retval
.size
= DW_BLOCK (attr
)->size
;
17406 retval
.per_cu
= cu
->per_cu
;
17408 age_cached_comp_units ();
17413 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
17416 struct dwarf2_locexpr_baton
17417 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
17418 struct dwarf2_per_cu_data
*per_cu
,
17419 CORE_ADDR (*get_frame_pc
) (void *baton
),
17422 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
17424 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
17427 /* Return the type of the DIE at DIE_OFFSET in the CU named by
17431 dwarf2_get_die_type (cu_offset die_offset
,
17432 struct dwarf2_per_cu_data
*per_cu
)
17434 sect_offset die_offset_sect
;
17436 dw2_setup (per_cu
->objfile
);
17438 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
17439 return get_die_type_at_offset (die_offset_sect
, per_cu
);
17442 /* Follow the signature attribute ATTR in SRC_DIE.
17443 On entry *REF_CU is the CU of SRC_DIE.
17444 On exit *REF_CU is the CU of the result. */
17446 static struct die_info
*
17447 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
17448 struct dwarf2_cu
**ref_cu
)
17450 struct objfile
*objfile
= (*ref_cu
)->objfile
;
17451 struct die_info temp_die
;
17452 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
17453 struct dwarf2_cu
*sig_cu
;
17454 struct die_info
*die
;
17456 /* sig_type will be NULL if the signatured type is missing from
17458 if (sig_type
== NULL
)
17459 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
17460 "at 0x%x [in module %s]"),
17461 src_die
->offset
.sect_off
, objfile
->name
);
17463 /* If necessary, add it to the queue and load its DIEs. */
17465 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
17466 read_signatured_type (sig_type
);
17468 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
17470 sig_cu
= sig_type
->per_cu
.cu
;
17471 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
17472 temp_die
.offset
= sig_type
->type_offset_in_section
;
17473 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
17474 temp_die
.offset
.sect_off
);
17481 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
17482 "from DIE at 0x%x [in module %s]"),
17483 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
17486 /* Given an offset of a signatured type, return its signatured_type. */
17488 static struct signatured_type
*
17489 lookup_signatured_type_at_offset (struct objfile
*objfile
,
17490 struct dwarf2_section_info
*section
,
17491 sect_offset offset
)
17493 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
17494 unsigned int length
, initial_length_size
;
17495 unsigned int sig_offset
;
17496 struct signatured_type find_entry
, *sig_type
;
17498 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
17499 sig_offset
= (initial_length_size
17501 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
17502 + 1 /*address_size*/);
17503 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
17504 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
17506 /* This is only used to lookup previously recorded types.
17507 If we didn't find it, it's our bug. */
17508 gdb_assert (sig_type
!= NULL
);
17509 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
17514 /* Load the DIEs associated with type unit PER_CU into memory. */
17517 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
17519 struct signatured_type
*sig_type
;
17521 /* Caller is responsible for ensuring type_unit_groups don't get here. */
17522 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
17524 /* We have the per_cu, but we need the signatured_type.
17525 Fortunately this is an easy translation. */
17526 gdb_assert (per_cu
->is_debug_types
);
17527 sig_type
= (struct signatured_type
*) per_cu
;
17529 gdb_assert (per_cu
->cu
== NULL
);
17531 read_signatured_type (sig_type
);
17533 gdb_assert (per_cu
->cu
!= NULL
);
17536 /* die_reader_func for read_signatured_type.
17537 This is identical to load_full_comp_unit_reader,
17538 but is kept separate for now. */
17541 read_signatured_type_reader (const struct die_reader_specs
*reader
,
17542 gdb_byte
*info_ptr
,
17543 struct die_info
*comp_unit_die
,
17547 struct dwarf2_cu
*cu
= reader
->cu
;
17549 gdb_assert (cu
->die_hash
== NULL
);
17551 htab_create_alloc_ex (cu
->header
.length
/ 12,
17555 &cu
->comp_unit_obstack
,
17556 hashtab_obstack_allocate
,
17557 dummy_obstack_deallocate
);
17560 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
17561 &info_ptr
, comp_unit_die
);
17562 cu
->dies
= comp_unit_die
;
17563 /* comp_unit_die is not stored in die_hash, no need. */
17565 /* We try not to read any attributes in this function, because not
17566 all CUs needed for references have been loaded yet, and symbol
17567 table processing isn't initialized. But we have to set the CU language,
17568 or we won't be able to build types correctly.
17569 Similarly, if we do not read the producer, we can not apply
17570 producer-specific interpretation. */
17571 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
17574 /* Read in a signatured type and build its CU and DIEs.
17575 If the type is a stub for the real type in a DWO file,
17576 read in the real type from the DWO file as well. */
17579 read_signatured_type (struct signatured_type
*sig_type
)
17581 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
17583 gdb_assert (per_cu
->is_debug_types
);
17584 gdb_assert (per_cu
->cu
== NULL
);
17586 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
17587 read_signatured_type_reader
, NULL
);
17590 /* Decode simple location descriptions.
17591 Given a pointer to a dwarf block that defines a location, compute
17592 the location and return the value.
17594 NOTE drow/2003-11-18: This function is called in two situations
17595 now: for the address of static or global variables (partial symbols
17596 only) and for offsets into structures which are expected to be
17597 (more or less) constant. The partial symbol case should go away,
17598 and only the constant case should remain. That will let this
17599 function complain more accurately. A few special modes are allowed
17600 without complaint for global variables (for instance, global
17601 register values and thread-local values).
17603 A location description containing no operations indicates that the
17604 object is optimized out. The return value is 0 for that case.
17605 FIXME drow/2003-11-16: No callers check for this case any more; soon all
17606 callers will only want a very basic result and this can become a
17609 Note that stack[0] is unused except as a default error return. */
17612 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
17614 struct objfile
*objfile
= cu
->objfile
;
17616 size_t size
= blk
->size
;
17617 gdb_byte
*data
= blk
->data
;
17618 CORE_ADDR stack
[64];
17620 unsigned int bytes_read
, unsnd
;
17626 stack
[++stacki
] = 0;
17665 stack
[++stacki
] = op
- DW_OP_lit0
;
17700 stack
[++stacki
] = op
- DW_OP_reg0
;
17702 dwarf2_complex_location_expr_complaint ();
17706 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
17708 stack
[++stacki
] = unsnd
;
17710 dwarf2_complex_location_expr_complaint ();
17714 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
17719 case DW_OP_const1u
:
17720 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
17724 case DW_OP_const1s
:
17725 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
17729 case DW_OP_const2u
:
17730 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
17734 case DW_OP_const2s
:
17735 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
17739 case DW_OP_const4u
:
17740 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
17744 case DW_OP_const4s
:
17745 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
17749 case DW_OP_const8u
:
17750 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
17755 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
17761 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
17766 stack
[stacki
+ 1] = stack
[stacki
];
17771 stack
[stacki
- 1] += stack
[stacki
];
17775 case DW_OP_plus_uconst
:
17776 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
17782 stack
[stacki
- 1] -= stack
[stacki
];
17787 /* If we're not the last op, then we definitely can't encode
17788 this using GDB's address_class enum. This is valid for partial
17789 global symbols, although the variable's address will be bogus
17792 dwarf2_complex_location_expr_complaint ();
17795 case DW_OP_GNU_push_tls_address
:
17796 /* The top of the stack has the offset from the beginning
17797 of the thread control block at which the variable is located. */
17798 /* Nothing should follow this operator, so the top of stack would
17800 /* This is valid for partial global symbols, but the variable's
17801 address will be bogus in the psymtab. Make it always at least
17802 non-zero to not look as a variable garbage collected by linker
17803 which have DW_OP_addr 0. */
17805 dwarf2_complex_location_expr_complaint ();
17809 case DW_OP_GNU_uninit
:
17812 case DW_OP_GNU_addr_index
:
17813 case DW_OP_GNU_const_index
:
17814 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
17821 const char *name
= get_DW_OP_name (op
);
17824 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
17827 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
17831 return (stack
[stacki
]);
17834 /* Enforce maximum stack depth of SIZE-1 to avoid writing
17835 outside of the allocated space. Also enforce minimum>0. */
17836 if (stacki
>= ARRAY_SIZE (stack
) - 1)
17838 complaint (&symfile_complaints
,
17839 _("location description stack overflow"));
17845 complaint (&symfile_complaints
,
17846 _("location description stack underflow"));
17850 return (stack
[stacki
]);
17853 /* memory allocation interface */
17855 static struct dwarf_block
*
17856 dwarf_alloc_block (struct dwarf2_cu
*cu
)
17858 struct dwarf_block
*blk
;
17860 blk
= (struct dwarf_block
*)
17861 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
17865 static struct die_info
*
17866 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
17868 struct die_info
*die
;
17869 size_t size
= sizeof (struct die_info
);
17872 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
17874 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
17875 memset (die
, 0, sizeof (struct die_info
));
17880 /* Macro support. */
17882 /* Return the full name of file number I in *LH's file name table.
17883 Use COMP_DIR as the name of the current directory of the
17884 compilation. The result is allocated using xmalloc; the caller is
17885 responsible for freeing it. */
17887 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
17889 /* Is the file number a valid index into the line header's file name
17890 table? Remember that file numbers start with one, not zero. */
17891 if (1 <= file
&& file
<= lh
->num_file_names
)
17893 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
17895 if (IS_ABSOLUTE_PATH (fe
->name
))
17896 return xstrdup (fe
->name
);
17904 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
17910 dir_len
= strlen (dir
);
17911 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
17912 strcpy (full_name
, dir
);
17913 full_name
[dir_len
] = '/';
17914 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
17918 return xstrdup (fe
->name
);
17923 /* The compiler produced a bogus file number. We can at least
17924 record the macro definitions made in the file, even if we
17925 won't be able to find the file by name. */
17926 char fake_name
[80];
17928 xsnprintf (fake_name
, sizeof (fake_name
),
17929 "<bad macro file number %d>", file
);
17931 complaint (&symfile_complaints
,
17932 _("bad file number in macro information (%d)"),
17935 return xstrdup (fake_name
);
17940 static struct macro_source_file
*
17941 macro_start_file (int file
, int line
,
17942 struct macro_source_file
*current_file
,
17943 const char *comp_dir
,
17944 struct line_header
*lh
, struct objfile
*objfile
)
17946 /* The full name of this source file. */
17947 char *full_name
= file_full_name (file
, lh
, comp_dir
);
17949 /* We don't create a macro table for this compilation unit
17950 at all until we actually get a filename. */
17951 if (! pending_macros
)
17952 pending_macros
= new_macro_table (&objfile
->per_bfd
->storage_obstack
,
17953 objfile
->per_bfd
->macro_cache
);
17955 if (! current_file
)
17957 /* If we have no current file, then this must be the start_file
17958 directive for the compilation unit's main source file. */
17959 current_file
= macro_set_main (pending_macros
, full_name
);
17960 macro_define_special (pending_macros
);
17963 current_file
= macro_include (current_file
, line
, full_name
);
17967 return current_file
;
17971 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
17972 followed by a null byte. */
17974 copy_string (const char *buf
, int len
)
17976 char *s
= xmalloc (len
+ 1);
17978 memcpy (s
, buf
, len
);
17984 static const char *
17985 consume_improper_spaces (const char *p
, const char *body
)
17989 complaint (&symfile_complaints
,
17990 _("macro definition contains spaces "
17991 "in formal argument list:\n`%s'"),
18003 parse_macro_definition (struct macro_source_file
*file
, int line
,
18008 /* The body string takes one of two forms. For object-like macro
18009 definitions, it should be:
18011 <macro name> " " <definition>
18013 For function-like macro definitions, it should be:
18015 <macro name> "() " <definition>
18017 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
18019 Spaces may appear only where explicitly indicated, and in the
18022 The Dwarf 2 spec says that an object-like macro's name is always
18023 followed by a space, but versions of GCC around March 2002 omit
18024 the space when the macro's definition is the empty string.
18026 The Dwarf 2 spec says that there should be no spaces between the
18027 formal arguments in a function-like macro's formal argument list,
18028 but versions of GCC around March 2002 include spaces after the
18032 /* Find the extent of the macro name. The macro name is terminated
18033 by either a space or null character (for an object-like macro) or
18034 an opening paren (for a function-like macro). */
18035 for (p
= body
; *p
; p
++)
18036 if (*p
== ' ' || *p
== '(')
18039 if (*p
== ' ' || *p
== '\0')
18041 /* It's an object-like macro. */
18042 int name_len
= p
- body
;
18043 char *name
= copy_string (body
, name_len
);
18044 const char *replacement
;
18047 replacement
= body
+ name_len
+ 1;
18050 dwarf2_macro_malformed_definition_complaint (body
);
18051 replacement
= body
+ name_len
;
18054 macro_define_object (file
, line
, name
, replacement
);
18058 else if (*p
== '(')
18060 /* It's a function-like macro. */
18061 char *name
= copy_string (body
, p
- body
);
18064 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
18068 p
= consume_improper_spaces (p
, body
);
18070 /* Parse the formal argument list. */
18071 while (*p
&& *p
!= ')')
18073 /* Find the extent of the current argument name. */
18074 const char *arg_start
= p
;
18076 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
18079 if (! *p
|| p
== arg_start
)
18080 dwarf2_macro_malformed_definition_complaint (body
);
18083 /* Make sure argv has room for the new argument. */
18084 if (argc
>= argv_size
)
18087 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
18090 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
18093 p
= consume_improper_spaces (p
, body
);
18095 /* Consume the comma, if present. */
18100 p
= consume_improper_spaces (p
, body
);
18109 /* Perfectly formed definition, no complaints. */
18110 macro_define_function (file
, line
, name
,
18111 argc
, (const char **) argv
,
18113 else if (*p
== '\0')
18115 /* Complain, but do define it. */
18116 dwarf2_macro_malformed_definition_complaint (body
);
18117 macro_define_function (file
, line
, name
,
18118 argc
, (const char **) argv
,
18122 /* Just complain. */
18123 dwarf2_macro_malformed_definition_complaint (body
);
18126 /* Just complain. */
18127 dwarf2_macro_malformed_definition_complaint (body
);
18133 for (i
= 0; i
< argc
; i
++)
18139 dwarf2_macro_malformed_definition_complaint (body
);
18142 /* Skip some bytes from BYTES according to the form given in FORM.
18143 Returns the new pointer. */
18146 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
18147 enum dwarf_form form
,
18148 unsigned int offset_size
,
18149 struct dwarf2_section_info
*section
)
18151 unsigned int bytes_read
;
18155 case DW_FORM_data1
:
18160 case DW_FORM_data2
:
18164 case DW_FORM_data4
:
18168 case DW_FORM_data8
:
18172 case DW_FORM_string
:
18173 read_direct_string (abfd
, bytes
, &bytes_read
);
18174 bytes
+= bytes_read
;
18177 case DW_FORM_sec_offset
:
18179 case DW_FORM_GNU_strp_alt
:
18180 bytes
+= offset_size
;
18183 case DW_FORM_block
:
18184 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
18185 bytes
+= bytes_read
;
18188 case DW_FORM_block1
:
18189 bytes
+= 1 + read_1_byte (abfd
, bytes
);
18191 case DW_FORM_block2
:
18192 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
18194 case DW_FORM_block4
:
18195 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
18198 case DW_FORM_sdata
:
18199 case DW_FORM_udata
:
18200 case DW_FORM_GNU_addr_index
:
18201 case DW_FORM_GNU_str_index
:
18202 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
18205 dwarf2_section_buffer_overflow_complaint (section
);
18213 complaint (&symfile_complaints
,
18214 _("invalid form 0x%x in `%s'"),
18216 section
->asection
->name
);
18224 /* A helper for dwarf_decode_macros that handles skipping an unknown
18225 opcode. Returns an updated pointer to the macro data buffer; or,
18226 on error, issues a complaint and returns NULL. */
18229 skip_unknown_opcode (unsigned int opcode
,
18230 gdb_byte
**opcode_definitions
,
18231 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18233 unsigned int offset_size
,
18234 struct dwarf2_section_info
*section
)
18236 unsigned int bytes_read
, i
;
18240 if (opcode_definitions
[opcode
] == NULL
)
18242 complaint (&symfile_complaints
,
18243 _("unrecognized DW_MACFINO opcode 0x%x"),
18248 defn
= opcode_definitions
[opcode
];
18249 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
18250 defn
+= bytes_read
;
18252 for (i
= 0; i
< arg
; ++i
)
18254 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
18256 if (mac_ptr
== NULL
)
18258 /* skip_form_bytes already issued the complaint. */
18266 /* A helper function which parses the header of a macro section.
18267 If the macro section is the extended (for now called "GNU") type,
18268 then this updates *OFFSET_SIZE. Returns a pointer to just after
18269 the header, or issues a complaint and returns NULL on error. */
18272 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
18275 unsigned int *offset_size
,
18276 int section_is_gnu
)
18278 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
18280 if (section_is_gnu
)
18282 unsigned int version
, flags
;
18284 version
= read_2_bytes (abfd
, mac_ptr
);
18287 complaint (&symfile_complaints
,
18288 _("unrecognized version `%d' in .debug_macro section"),
18294 flags
= read_1_byte (abfd
, mac_ptr
);
18296 *offset_size
= (flags
& 1) ? 8 : 4;
18298 if ((flags
& 2) != 0)
18299 /* We don't need the line table offset. */
18300 mac_ptr
+= *offset_size
;
18302 /* Vendor opcode descriptions. */
18303 if ((flags
& 4) != 0)
18305 unsigned int i
, count
;
18307 count
= read_1_byte (abfd
, mac_ptr
);
18309 for (i
= 0; i
< count
; ++i
)
18311 unsigned int opcode
, bytes_read
;
18314 opcode
= read_1_byte (abfd
, mac_ptr
);
18316 opcode_definitions
[opcode
] = mac_ptr
;
18317 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18318 mac_ptr
+= bytes_read
;
18327 /* A helper for dwarf_decode_macros that handles the GNU extensions,
18328 including DW_MACRO_GNU_transparent_include. */
18331 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18332 struct macro_source_file
*current_file
,
18333 struct line_header
*lh
, char *comp_dir
,
18334 struct dwarf2_section_info
*section
,
18335 int section_is_gnu
, int section_is_dwz
,
18336 unsigned int offset_size
,
18337 struct objfile
*objfile
,
18338 htab_t include_hash
)
18340 enum dwarf_macro_record_type macinfo_type
;
18341 int at_commandline
;
18342 gdb_byte
*opcode_definitions
[256];
18344 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18345 &offset_size
, section_is_gnu
);
18346 if (mac_ptr
== NULL
)
18348 /* We already issued a complaint. */
18352 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
18353 GDB is still reading the definitions from command line. First
18354 DW_MACINFO_start_file will need to be ignored as it was already executed
18355 to create CURRENT_FILE for the main source holding also the command line
18356 definitions. On first met DW_MACINFO_start_file this flag is reset to
18357 normally execute all the remaining DW_MACINFO_start_file macinfos. */
18359 at_commandline
= 1;
18363 /* Do we at least have room for a macinfo type byte? */
18364 if (mac_ptr
>= mac_end
)
18366 dwarf2_section_buffer_overflow_complaint (section
);
18370 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18373 /* Note that we rely on the fact that the corresponding GNU and
18374 DWARF constants are the same. */
18375 switch (macinfo_type
)
18377 /* A zero macinfo type indicates the end of the macro
18382 case DW_MACRO_GNU_define
:
18383 case DW_MACRO_GNU_undef
:
18384 case DW_MACRO_GNU_define_indirect
:
18385 case DW_MACRO_GNU_undef_indirect
:
18386 case DW_MACRO_GNU_define_indirect_alt
:
18387 case DW_MACRO_GNU_undef_indirect_alt
:
18389 unsigned int bytes_read
;
18394 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18395 mac_ptr
+= bytes_read
;
18397 if (macinfo_type
== DW_MACRO_GNU_define
18398 || macinfo_type
== DW_MACRO_GNU_undef
)
18400 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18401 mac_ptr
+= bytes_read
;
18405 LONGEST str_offset
;
18407 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18408 mac_ptr
+= offset_size
;
18410 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
18411 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
18414 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18416 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
18419 body
= read_indirect_string_at_offset (abfd
, str_offset
);
18422 is_define
= (macinfo_type
== DW_MACRO_GNU_define
18423 || macinfo_type
== DW_MACRO_GNU_define_indirect
18424 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
18425 if (! current_file
)
18427 /* DWARF violation as no main source is present. */
18428 complaint (&symfile_complaints
,
18429 _("debug info with no main source gives macro %s "
18431 is_define
? _("definition") : _("undefinition"),
18435 if ((line
== 0 && !at_commandline
)
18436 || (line
!= 0 && at_commandline
))
18437 complaint (&symfile_complaints
,
18438 _("debug info gives %s macro %s with %s line %d: %s"),
18439 at_commandline
? _("command-line") : _("in-file"),
18440 is_define
? _("definition") : _("undefinition"),
18441 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
18444 parse_macro_definition (current_file
, line
, body
);
18447 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
18448 || macinfo_type
== DW_MACRO_GNU_undef_indirect
18449 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
18450 macro_undef (current_file
, line
, body
);
18455 case DW_MACRO_GNU_start_file
:
18457 unsigned int bytes_read
;
18460 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18461 mac_ptr
+= bytes_read
;
18462 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18463 mac_ptr
+= bytes_read
;
18465 if ((line
== 0 && !at_commandline
)
18466 || (line
!= 0 && at_commandline
))
18467 complaint (&symfile_complaints
,
18468 _("debug info gives source %d included "
18469 "from %s at %s line %d"),
18470 file
, at_commandline
? _("command-line") : _("file"),
18471 line
== 0 ? _("zero") : _("non-zero"), line
);
18473 if (at_commandline
)
18475 /* This DW_MACRO_GNU_start_file was executed in the
18477 at_commandline
= 0;
18480 current_file
= macro_start_file (file
, line
,
18481 current_file
, comp_dir
,
18486 case DW_MACRO_GNU_end_file
:
18487 if (! current_file
)
18488 complaint (&symfile_complaints
,
18489 _("macro debug info has an unmatched "
18490 "`close_file' directive"));
18493 current_file
= current_file
->included_by
;
18494 if (! current_file
)
18496 enum dwarf_macro_record_type next_type
;
18498 /* GCC circa March 2002 doesn't produce the zero
18499 type byte marking the end of the compilation
18500 unit. Complain if it's not there, but exit no
18503 /* Do we at least have room for a macinfo type byte? */
18504 if (mac_ptr
>= mac_end
)
18506 dwarf2_section_buffer_overflow_complaint (section
);
18510 /* We don't increment mac_ptr here, so this is just
18512 next_type
= read_1_byte (abfd
, mac_ptr
);
18513 if (next_type
!= 0)
18514 complaint (&symfile_complaints
,
18515 _("no terminating 0-type entry for "
18516 "macros in `.debug_macinfo' section"));
18523 case DW_MACRO_GNU_transparent_include
:
18524 case DW_MACRO_GNU_transparent_include_alt
:
18528 bfd
*include_bfd
= abfd
;
18529 struct dwarf2_section_info
*include_section
= section
;
18530 struct dwarf2_section_info alt_section
;
18531 gdb_byte
*include_mac_end
= mac_end
;
18532 int is_dwz
= section_is_dwz
;
18533 gdb_byte
*new_mac_ptr
;
18535 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18536 mac_ptr
+= offset_size
;
18538 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
18540 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18542 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
18545 include_bfd
= dwz
->macro
.asection
->owner
;
18546 include_section
= &dwz
->macro
;
18547 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
18551 new_mac_ptr
= include_section
->buffer
+ offset
;
18552 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
18556 /* This has actually happened; see
18557 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
18558 complaint (&symfile_complaints
,
18559 _("recursive DW_MACRO_GNU_transparent_include in "
18560 ".debug_macro section"));
18564 *slot
= new_mac_ptr
;
18566 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
18567 include_mac_end
, current_file
,
18569 section
, section_is_gnu
, is_dwz
,
18570 offset_size
, objfile
, include_hash
);
18572 htab_remove_elt (include_hash
, new_mac_ptr
);
18577 case DW_MACINFO_vendor_ext
:
18578 if (!section_is_gnu
)
18580 unsigned int bytes_read
;
18583 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18584 mac_ptr
+= bytes_read
;
18585 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18586 mac_ptr
+= bytes_read
;
18588 /* We don't recognize any vendor extensions. */
18594 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18595 mac_ptr
, mac_end
, abfd
, offset_size
,
18597 if (mac_ptr
== NULL
)
18601 } while (macinfo_type
!= 0);
18605 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
18606 char *comp_dir
, int section_is_gnu
)
18608 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18609 struct line_header
*lh
= cu
->line_header
;
18611 gdb_byte
*mac_ptr
, *mac_end
;
18612 struct macro_source_file
*current_file
= 0;
18613 enum dwarf_macro_record_type macinfo_type
;
18614 unsigned int offset_size
= cu
->header
.offset_size
;
18615 gdb_byte
*opcode_definitions
[256];
18616 struct cleanup
*cleanup
;
18617 htab_t include_hash
;
18619 struct dwarf2_section_info
*section
;
18620 const char *section_name
;
18622 if (cu
->dwo_unit
!= NULL
)
18624 if (section_is_gnu
)
18626 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
18627 section_name
= ".debug_macro.dwo";
18631 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
18632 section_name
= ".debug_macinfo.dwo";
18637 if (section_is_gnu
)
18639 section
= &dwarf2_per_objfile
->macro
;
18640 section_name
= ".debug_macro";
18644 section
= &dwarf2_per_objfile
->macinfo
;
18645 section_name
= ".debug_macinfo";
18649 dwarf2_read_section (objfile
, section
);
18650 if (section
->buffer
== NULL
)
18652 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
18655 abfd
= section
->asection
->owner
;
18657 /* First pass: Find the name of the base filename.
18658 This filename is needed in order to process all macros whose definition
18659 (or undefinition) comes from the command line. These macros are defined
18660 before the first DW_MACINFO_start_file entry, and yet still need to be
18661 associated to the base file.
18663 To determine the base file name, we scan the macro definitions until we
18664 reach the first DW_MACINFO_start_file entry. We then initialize
18665 CURRENT_FILE accordingly so that any macro definition found before the
18666 first DW_MACINFO_start_file can still be associated to the base file. */
18668 mac_ptr
= section
->buffer
+ offset
;
18669 mac_end
= section
->buffer
+ section
->size
;
18671 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18672 &offset_size
, section_is_gnu
);
18673 if (mac_ptr
== NULL
)
18675 /* We already issued a complaint. */
18681 /* Do we at least have room for a macinfo type byte? */
18682 if (mac_ptr
>= mac_end
)
18684 /* Complaint is printed during the second pass as GDB will probably
18685 stop the first pass earlier upon finding
18686 DW_MACINFO_start_file. */
18690 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18693 /* Note that we rely on the fact that the corresponding GNU and
18694 DWARF constants are the same. */
18695 switch (macinfo_type
)
18697 /* A zero macinfo type indicates the end of the macro
18702 case DW_MACRO_GNU_define
:
18703 case DW_MACRO_GNU_undef
:
18704 /* Only skip the data by MAC_PTR. */
18706 unsigned int bytes_read
;
18708 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18709 mac_ptr
+= bytes_read
;
18710 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18711 mac_ptr
+= bytes_read
;
18715 case DW_MACRO_GNU_start_file
:
18717 unsigned int bytes_read
;
18720 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18721 mac_ptr
+= bytes_read
;
18722 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18723 mac_ptr
+= bytes_read
;
18725 current_file
= macro_start_file (file
, line
, current_file
,
18726 comp_dir
, lh
, objfile
);
18730 case DW_MACRO_GNU_end_file
:
18731 /* No data to skip by MAC_PTR. */
18734 case DW_MACRO_GNU_define_indirect
:
18735 case DW_MACRO_GNU_undef_indirect
:
18736 case DW_MACRO_GNU_define_indirect_alt
:
18737 case DW_MACRO_GNU_undef_indirect_alt
:
18739 unsigned int bytes_read
;
18741 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18742 mac_ptr
+= bytes_read
;
18743 mac_ptr
+= offset_size
;
18747 case DW_MACRO_GNU_transparent_include
:
18748 case DW_MACRO_GNU_transparent_include_alt
:
18749 /* Note that, according to the spec, a transparent include
18750 chain cannot call DW_MACRO_GNU_start_file. So, we can just
18751 skip this opcode. */
18752 mac_ptr
+= offset_size
;
18755 case DW_MACINFO_vendor_ext
:
18756 /* Only skip the data by MAC_PTR. */
18757 if (!section_is_gnu
)
18759 unsigned int bytes_read
;
18761 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18762 mac_ptr
+= bytes_read
;
18763 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18764 mac_ptr
+= bytes_read
;
18769 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18770 mac_ptr
, mac_end
, abfd
, offset_size
,
18772 if (mac_ptr
== NULL
)
18776 } while (macinfo_type
!= 0 && current_file
== NULL
);
18778 /* Second pass: Process all entries.
18780 Use the AT_COMMAND_LINE flag to determine whether we are still processing
18781 command-line macro definitions/undefinitions. This flag is unset when we
18782 reach the first DW_MACINFO_start_file entry. */
18784 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
18785 NULL
, xcalloc
, xfree
);
18786 cleanup
= make_cleanup_htab_delete (include_hash
);
18787 mac_ptr
= section
->buffer
+ offset
;
18788 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
18790 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
18791 current_file
, lh
, comp_dir
, section
,
18793 offset_size
, objfile
, include_hash
);
18794 do_cleanups (cleanup
);
18797 /* Check if the attribute's form is a DW_FORM_block*
18798 if so return true else false. */
18801 attr_form_is_block (struct attribute
*attr
)
18803 return (attr
== NULL
? 0 :
18804 attr
->form
== DW_FORM_block1
18805 || attr
->form
== DW_FORM_block2
18806 || attr
->form
== DW_FORM_block4
18807 || attr
->form
== DW_FORM_block
18808 || attr
->form
== DW_FORM_exprloc
);
18811 /* Return non-zero if ATTR's value is a section offset --- classes
18812 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
18813 You may use DW_UNSND (attr) to retrieve such offsets.
18815 Section 7.5.4, "Attribute Encodings", explains that no attribute
18816 may have a value that belongs to more than one of these classes; it
18817 would be ambiguous if we did, because we use the same forms for all
18821 attr_form_is_section_offset (struct attribute
*attr
)
18823 return (attr
->form
== DW_FORM_data4
18824 || attr
->form
== DW_FORM_data8
18825 || attr
->form
== DW_FORM_sec_offset
);
18828 /* Return non-zero if ATTR's value falls in the 'constant' class, or
18829 zero otherwise. When this function returns true, you can apply
18830 dwarf2_get_attr_constant_value to it.
18832 However, note that for some attributes you must check
18833 attr_form_is_section_offset before using this test. DW_FORM_data4
18834 and DW_FORM_data8 are members of both the constant class, and of
18835 the classes that contain offsets into other debug sections
18836 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
18837 that, if an attribute's can be either a constant or one of the
18838 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
18839 taken as section offsets, not constants. */
18842 attr_form_is_constant (struct attribute
*attr
)
18844 switch (attr
->form
)
18846 case DW_FORM_sdata
:
18847 case DW_FORM_udata
:
18848 case DW_FORM_data1
:
18849 case DW_FORM_data2
:
18850 case DW_FORM_data4
:
18851 case DW_FORM_data8
:
18858 /* Return the .debug_loc section to use for CU.
18859 For DWO files use .debug_loc.dwo. */
18861 static struct dwarf2_section_info
*
18862 cu_debug_loc_section (struct dwarf2_cu
*cu
)
18865 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
18866 return &dwarf2_per_objfile
->loc
;
18869 /* A helper function that fills in a dwarf2_loclist_baton. */
18872 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
18873 struct dwarf2_loclist_baton
*baton
,
18874 struct attribute
*attr
)
18876 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18878 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
18880 baton
->per_cu
= cu
->per_cu
;
18881 gdb_assert (baton
->per_cu
);
18882 /* We don't know how long the location list is, but make sure we
18883 don't run off the edge of the section. */
18884 baton
->size
= section
->size
- DW_UNSND (attr
);
18885 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
18886 baton
->base_address
= cu
->base_address
;
18887 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
18891 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
18892 struct dwarf2_cu
*cu
)
18894 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18895 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18897 if (attr_form_is_section_offset (attr
)
18898 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
18899 the section. If so, fall through to the complaint in the
18901 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
18903 struct dwarf2_loclist_baton
*baton
;
18905 baton
= obstack_alloc (&objfile
->objfile_obstack
,
18906 sizeof (struct dwarf2_loclist_baton
));
18908 fill_in_loclist_baton (cu
, baton
, attr
);
18910 if (cu
->base_known
== 0)
18911 complaint (&symfile_complaints
,
18912 _("Location list used without "
18913 "specifying the CU base address."));
18915 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
18916 SYMBOL_LOCATION_BATON (sym
) = baton
;
18920 struct dwarf2_locexpr_baton
*baton
;
18922 baton
= obstack_alloc (&objfile
->objfile_obstack
,
18923 sizeof (struct dwarf2_locexpr_baton
));
18924 baton
->per_cu
= cu
->per_cu
;
18925 gdb_assert (baton
->per_cu
);
18927 if (attr_form_is_block (attr
))
18929 /* Note that we're just copying the block's data pointer
18930 here, not the actual data. We're still pointing into the
18931 info_buffer for SYM's objfile; right now we never release
18932 that buffer, but when we do clean up properly this may
18934 baton
->size
= DW_BLOCK (attr
)->size
;
18935 baton
->data
= DW_BLOCK (attr
)->data
;
18939 dwarf2_invalid_attrib_class_complaint ("location description",
18940 SYMBOL_NATURAL_NAME (sym
));
18944 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
18945 SYMBOL_LOCATION_BATON (sym
) = baton
;
18949 /* Return the OBJFILE associated with the compilation unit CU. If CU
18950 came from a separate debuginfo file, then the master objfile is
18954 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
18956 struct objfile
*objfile
= per_cu
->objfile
;
18958 /* Return the master objfile, so that we can report and look up the
18959 correct file containing this variable. */
18960 if (objfile
->separate_debug_objfile_backlink
)
18961 objfile
= objfile
->separate_debug_objfile_backlink
;
18966 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
18967 (CU_HEADERP is unused in such case) or prepare a temporary copy at
18968 CU_HEADERP first. */
18970 static const struct comp_unit_head
*
18971 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
18972 struct dwarf2_per_cu_data
*per_cu
)
18974 gdb_byte
*info_ptr
;
18977 return &per_cu
->cu
->header
;
18979 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
18981 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
18982 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
18987 /* Return the address size given in the compilation unit header for CU. */
18990 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
18992 struct comp_unit_head cu_header_local
;
18993 const struct comp_unit_head
*cu_headerp
;
18995 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18997 return cu_headerp
->addr_size
;
19000 /* Return the offset size given in the compilation unit header for CU. */
19003 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
19005 struct comp_unit_head cu_header_local
;
19006 const struct comp_unit_head
*cu_headerp
;
19008 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19010 return cu_headerp
->offset_size
;
19013 /* See its dwarf2loc.h declaration. */
19016 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
19018 struct comp_unit_head cu_header_local
;
19019 const struct comp_unit_head
*cu_headerp
;
19021 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19023 if (cu_headerp
->version
== 2)
19024 return cu_headerp
->addr_size
;
19026 return cu_headerp
->offset_size
;
19029 /* Return the text offset of the CU. The returned offset comes from
19030 this CU's objfile. If this objfile came from a separate debuginfo
19031 file, then the offset may be different from the corresponding
19032 offset in the parent objfile. */
19035 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
19037 struct objfile
*objfile
= per_cu
->objfile
;
19039 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19042 /* Locate the .debug_info compilation unit from CU's objfile which contains
19043 the DIE at OFFSET. Raises an error on failure. */
19045 static struct dwarf2_per_cu_data
*
19046 dwarf2_find_containing_comp_unit (sect_offset offset
,
19047 unsigned int offset_in_dwz
,
19048 struct objfile
*objfile
)
19050 struct dwarf2_per_cu_data
*this_cu
;
19052 const sect_offset
*cu_off
;
19055 high
= dwarf2_per_objfile
->n_comp_units
- 1;
19058 struct dwarf2_per_cu_data
*mid_cu
;
19059 int mid
= low
+ (high
- low
) / 2;
19061 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
19062 cu_off
= &mid_cu
->offset
;
19063 if (mid_cu
->is_dwz
> offset_in_dwz
19064 || (mid_cu
->is_dwz
== offset_in_dwz
19065 && cu_off
->sect_off
>= offset
.sect_off
))
19070 gdb_assert (low
== high
);
19071 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19072 cu_off
= &this_cu
->offset
;
19073 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
19075 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
19076 error (_("Dwarf Error: could not find partial DIE containing "
19077 "offset 0x%lx [in module %s]"),
19078 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
19080 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
19081 <= offset
.sect_off
);
19082 return dwarf2_per_objfile
->all_comp_units
[low
-1];
19086 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19087 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
19088 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
19089 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
19090 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
19095 /* Initialize dwarf2_cu CU, owned by PER_CU. */
19098 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
19100 memset (cu
, 0, sizeof (*cu
));
19102 cu
->per_cu
= per_cu
;
19103 cu
->objfile
= per_cu
->objfile
;
19104 obstack_init (&cu
->comp_unit_obstack
);
19107 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
19110 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
19111 enum language pretend_language
)
19113 struct attribute
*attr
;
19115 /* Set the language we're debugging. */
19116 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
19118 set_cu_language (DW_UNSND (attr
), cu
);
19121 cu
->language
= pretend_language
;
19122 cu
->language_defn
= language_def (cu
->language
);
19125 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
19127 cu
->producer
= DW_STRING (attr
);
19130 /* Release one cached compilation unit, CU. We unlink it from the tree
19131 of compilation units, but we don't remove it from the read_in_chain;
19132 the caller is responsible for that.
19133 NOTE: DATA is a void * because this function is also used as a
19134 cleanup routine. */
19137 free_heap_comp_unit (void *data
)
19139 struct dwarf2_cu
*cu
= data
;
19141 gdb_assert (cu
->per_cu
!= NULL
);
19142 cu
->per_cu
->cu
= NULL
;
19145 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19150 /* This cleanup function is passed the address of a dwarf2_cu on the stack
19151 when we're finished with it. We can't free the pointer itself, but be
19152 sure to unlink it from the cache. Also release any associated storage. */
19155 free_stack_comp_unit (void *data
)
19157 struct dwarf2_cu
*cu
= data
;
19159 gdb_assert (cu
->per_cu
!= NULL
);
19160 cu
->per_cu
->cu
= NULL
;
19163 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19164 cu
->partial_dies
= NULL
;
19167 /* Free all cached compilation units. */
19170 free_cached_comp_units (void *data
)
19172 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19174 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19175 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19176 while (per_cu
!= NULL
)
19178 struct dwarf2_per_cu_data
*next_cu
;
19180 next_cu
= per_cu
->cu
->read_in_chain
;
19182 free_heap_comp_unit (per_cu
->cu
);
19183 *last_chain
= next_cu
;
19189 /* Increase the age counter on each cached compilation unit, and free
19190 any that are too old. */
19193 age_cached_comp_units (void)
19195 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19197 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
19198 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19199 while (per_cu
!= NULL
)
19201 per_cu
->cu
->last_used
++;
19202 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
19203 dwarf2_mark (per_cu
->cu
);
19204 per_cu
= per_cu
->cu
->read_in_chain
;
19207 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19208 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19209 while (per_cu
!= NULL
)
19211 struct dwarf2_per_cu_data
*next_cu
;
19213 next_cu
= per_cu
->cu
->read_in_chain
;
19215 if (!per_cu
->cu
->mark
)
19217 free_heap_comp_unit (per_cu
->cu
);
19218 *last_chain
= next_cu
;
19221 last_chain
= &per_cu
->cu
->read_in_chain
;
19227 /* Remove a single compilation unit from the cache. */
19230 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
19232 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19234 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19235 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19236 while (per_cu
!= NULL
)
19238 struct dwarf2_per_cu_data
*next_cu
;
19240 next_cu
= per_cu
->cu
->read_in_chain
;
19242 if (per_cu
== target_per_cu
)
19244 free_heap_comp_unit (per_cu
->cu
);
19246 *last_chain
= next_cu
;
19250 last_chain
= &per_cu
->cu
->read_in_chain
;
19256 /* Release all extra memory associated with OBJFILE. */
19259 dwarf2_free_objfile (struct objfile
*objfile
)
19261 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19263 if (dwarf2_per_objfile
== NULL
)
19266 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
19267 free_cached_comp_units (NULL
);
19269 if (dwarf2_per_objfile
->quick_file_names_table
)
19270 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
19272 /* Everything else should be on the objfile obstack. */
19275 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
19276 We store these in a hash table separate from the DIEs, and preserve them
19277 when the DIEs are flushed out of cache.
19279 The CU "per_cu" pointer is needed because offset alone is not enough to
19280 uniquely identify the type. A file may have multiple .debug_types sections,
19281 or the type may come from a DWO file. We have to use something in
19282 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
19283 routine, get_die_type_at_offset, from outside this file, and thus won't
19284 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
19287 struct dwarf2_per_cu_offset_and_type
19289 const struct dwarf2_per_cu_data
*per_cu
;
19290 sect_offset offset
;
19294 /* Hash function for a dwarf2_per_cu_offset_and_type. */
19297 per_cu_offset_and_type_hash (const void *item
)
19299 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
19301 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
19304 /* Equality function for a dwarf2_per_cu_offset_and_type. */
19307 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
19309 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
19310 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
19312 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
19313 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
19316 /* Set the type associated with DIE to TYPE. Save it in CU's hash
19317 table if necessary. For convenience, return TYPE.
19319 The DIEs reading must have careful ordering to:
19320 * Not cause infite loops trying to read in DIEs as a prerequisite for
19321 reading current DIE.
19322 * Not trying to dereference contents of still incompletely read in types
19323 while reading in other DIEs.
19324 * Enable referencing still incompletely read in types just by a pointer to
19325 the type without accessing its fields.
19327 Therefore caller should follow these rules:
19328 * Try to fetch any prerequisite types we may need to build this DIE type
19329 before building the type and calling set_die_type.
19330 * After building type call set_die_type for current DIE as soon as
19331 possible before fetching more types to complete the current type.
19332 * Make the type as complete as possible before fetching more types. */
19334 static struct type
*
19335 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19337 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
19338 struct objfile
*objfile
= cu
->objfile
;
19340 /* For Ada types, make sure that the gnat-specific data is always
19341 initialized (if not already set). There are a few types where
19342 we should not be doing so, because the type-specific area is
19343 already used to hold some other piece of info (eg: TYPE_CODE_FLT
19344 where the type-specific area is used to store the floatformat).
19345 But this is not a problem, because the gnat-specific information
19346 is actually not needed for these types. */
19347 if (need_gnat_info (cu
)
19348 && TYPE_CODE (type
) != TYPE_CODE_FUNC
19349 && TYPE_CODE (type
) != TYPE_CODE_FLT
19350 && !HAVE_GNAT_AUX_INFO (type
))
19351 INIT_GNAT_SPECIFIC (type
);
19353 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19355 dwarf2_per_objfile
->die_type_hash
=
19356 htab_create_alloc_ex (127,
19357 per_cu_offset_and_type_hash
,
19358 per_cu_offset_and_type_eq
,
19360 &objfile
->objfile_obstack
,
19361 hashtab_obstack_allocate
,
19362 dummy_obstack_deallocate
);
19365 ofs
.per_cu
= cu
->per_cu
;
19366 ofs
.offset
= die
->offset
;
19368 slot
= (struct dwarf2_per_cu_offset_and_type
**)
19369 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
19371 complaint (&symfile_complaints
,
19372 _("A problem internal to GDB: DIE 0x%x has type already set"),
19373 die
->offset
.sect_off
);
19374 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
19379 /* Look up the type for the die at OFFSET in the appropriate type_hash
19380 table, or return NULL if the die does not have a saved type. */
19382 static struct type
*
19383 get_die_type_at_offset (sect_offset offset
,
19384 struct dwarf2_per_cu_data
*per_cu
)
19386 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
19388 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19391 ofs
.per_cu
= per_cu
;
19392 ofs
.offset
= offset
;
19393 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
19400 /* Look up the type for DIE in the appropriate type_hash table,
19401 or return NULL if DIE does not have a saved type. */
19403 static struct type
*
19404 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19406 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
19409 /* Add a dependence relationship from CU to REF_PER_CU. */
19412 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
19413 struct dwarf2_per_cu_data
*ref_per_cu
)
19417 if (cu
->dependencies
== NULL
)
19419 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
19420 NULL
, &cu
->comp_unit_obstack
,
19421 hashtab_obstack_allocate
,
19422 dummy_obstack_deallocate
);
19424 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
19426 *slot
= ref_per_cu
;
19429 /* Subroutine of dwarf2_mark to pass to htab_traverse.
19430 Set the mark field in every compilation unit in the
19431 cache that we must keep because we are keeping CU. */
19434 dwarf2_mark_helper (void **slot
, void *data
)
19436 struct dwarf2_per_cu_data
*per_cu
;
19438 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
19440 /* cu->dependencies references may not yet have been ever read if QUIT aborts
19441 reading of the chain. As such dependencies remain valid it is not much
19442 useful to track and undo them during QUIT cleanups. */
19443 if (per_cu
->cu
== NULL
)
19446 if (per_cu
->cu
->mark
)
19448 per_cu
->cu
->mark
= 1;
19450 if (per_cu
->cu
->dependencies
!= NULL
)
19451 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19456 /* Set the mark field in CU and in every other compilation unit in the
19457 cache that we must keep because we are keeping CU. */
19460 dwarf2_mark (struct dwarf2_cu
*cu
)
19465 if (cu
->dependencies
!= NULL
)
19466 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19470 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
19474 per_cu
->cu
->mark
= 0;
19475 per_cu
= per_cu
->cu
->read_in_chain
;
19479 /* Trivial hash function for partial_die_info: the hash value of a DIE
19480 is its offset in .debug_info for this objfile. */
19483 partial_die_hash (const void *item
)
19485 const struct partial_die_info
*part_die
= item
;
19487 return part_die
->offset
.sect_off
;
19490 /* Trivial comparison function for partial_die_info structures: two DIEs
19491 are equal if they have the same offset. */
19494 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
19496 const struct partial_die_info
*part_die_lhs
= item_lhs
;
19497 const struct partial_die_info
*part_die_rhs
= item_rhs
;
19499 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
19502 static struct cmd_list_element
*set_dwarf2_cmdlist
;
19503 static struct cmd_list_element
*show_dwarf2_cmdlist
;
19506 set_dwarf2_cmd (char *args
, int from_tty
)
19508 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
19512 show_dwarf2_cmd (char *args
, int from_tty
)
19514 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
19517 /* Free data associated with OBJFILE, if necessary. */
19520 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
19522 struct dwarf2_per_objfile
*data
= d
;
19525 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
19526 VEC_free (dwarf2_per_cu_ptr
,
19527 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
19529 VEC_free (dwarf2_section_info_def
, data
->types
);
19531 if (data
->dwo_files
)
19532 free_dwo_files (data
->dwo_files
, objfile
);
19534 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
19535 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
19539 /* The "save gdb-index" command. */
19541 /* The contents of the hash table we create when building the string
19543 struct strtab_entry
19545 offset_type offset
;
19549 /* Hash function for a strtab_entry.
19551 Function is used only during write_hash_table so no index format backward
19552 compatibility is needed. */
19555 hash_strtab_entry (const void *e
)
19557 const struct strtab_entry
*entry
= e
;
19558 return mapped_index_string_hash (INT_MAX
, entry
->str
);
19561 /* Equality function for a strtab_entry. */
19564 eq_strtab_entry (const void *a
, const void *b
)
19566 const struct strtab_entry
*ea
= a
;
19567 const struct strtab_entry
*eb
= b
;
19568 return !strcmp (ea
->str
, eb
->str
);
19571 /* Create a strtab_entry hash table. */
19574 create_strtab (void)
19576 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
19577 xfree
, xcalloc
, xfree
);
19580 /* Add a string to the constant pool. Return the string's offset in
19584 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
19587 struct strtab_entry entry
;
19588 struct strtab_entry
*result
;
19591 slot
= htab_find_slot (table
, &entry
, INSERT
);
19596 result
= XNEW (struct strtab_entry
);
19597 result
->offset
= obstack_object_size (cpool
);
19599 obstack_grow_str0 (cpool
, str
);
19602 return result
->offset
;
19605 /* An entry in the symbol table. */
19606 struct symtab_index_entry
19608 /* The name of the symbol. */
19610 /* The offset of the name in the constant pool. */
19611 offset_type index_offset
;
19612 /* A sorted vector of the indices of all the CUs that hold an object
19614 VEC (offset_type
) *cu_indices
;
19617 /* The symbol table. This is a power-of-2-sized hash table. */
19618 struct mapped_symtab
19620 offset_type n_elements
;
19622 struct symtab_index_entry
**data
;
19625 /* Hash function for a symtab_index_entry. */
19628 hash_symtab_entry (const void *e
)
19630 const struct symtab_index_entry
*entry
= e
;
19631 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
19632 sizeof (offset_type
) * VEC_length (offset_type
,
19633 entry
->cu_indices
),
19637 /* Equality function for a symtab_index_entry. */
19640 eq_symtab_entry (const void *a
, const void *b
)
19642 const struct symtab_index_entry
*ea
= a
;
19643 const struct symtab_index_entry
*eb
= b
;
19644 int len
= VEC_length (offset_type
, ea
->cu_indices
);
19645 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
19647 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
19648 VEC_address (offset_type
, eb
->cu_indices
),
19649 sizeof (offset_type
) * len
);
19652 /* Destroy a symtab_index_entry. */
19655 delete_symtab_entry (void *p
)
19657 struct symtab_index_entry
*entry
= p
;
19658 VEC_free (offset_type
, entry
->cu_indices
);
19662 /* Create a hash table holding symtab_index_entry objects. */
19665 create_symbol_hash_table (void)
19667 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
19668 delete_symtab_entry
, xcalloc
, xfree
);
19671 /* Create a new mapped symtab object. */
19673 static struct mapped_symtab
*
19674 create_mapped_symtab (void)
19676 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
19677 symtab
->n_elements
= 0;
19678 symtab
->size
= 1024;
19679 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19683 /* Destroy a mapped_symtab. */
19686 cleanup_mapped_symtab (void *p
)
19688 struct mapped_symtab
*symtab
= p
;
19689 /* The contents of the array are freed when the other hash table is
19691 xfree (symtab
->data
);
19695 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
19698 Function is used only during write_hash_table so no index format backward
19699 compatibility is needed. */
19701 static struct symtab_index_entry
**
19702 find_slot (struct mapped_symtab
*symtab
, const char *name
)
19704 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
19706 index
= hash
& (symtab
->size
- 1);
19707 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
19711 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
19712 return &symtab
->data
[index
];
19713 index
= (index
+ step
) & (symtab
->size
- 1);
19717 /* Expand SYMTAB's hash table. */
19720 hash_expand (struct mapped_symtab
*symtab
)
19722 offset_type old_size
= symtab
->size
;
19724 struct symtab_index_entry
**old_entries
= symtab
->data
;
19727 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19729 for (i
= 0; i
< old_size
; ++i
)
19731 if (old_entries
[i
])
19733 struct symtab_index_entry
**slot
= find_slot (symtab
,
19734 old_entries
[i
]->name
);
19735 *slot
= old_entries
[i
];
19739 xfree (old_entries
);
19742 /* Add an entry to SYMTAB. NAME is the name of the symbol.
19743 CU_INDEX is the index of the CU in which the symbol appears.
19744 IS_STATIC is one if the symbol is static, otherwise zero (global). */
19747 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
19748 int is_static
, gdb_index_symbol_kind kind
,
19749 offset_type cu_index
)
19751 struct symtab_index_entry
**slot
;
19752 offset_type cu_index_and_attrs
;
19754 ++symtab
->n_elements
;
19755 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
19756 hash_expand (symtab
);
19758 slot
= find_slot (symtab
, name
);
19761 *slot
= XNEW (struct symtab_index_entry
);
19762 (*slot
)->name
= name
;
19763 /* index_offset is set later. */
19764 (*slot
)->cu_indices
= NULL
;
19767 cu_index_and_attrs
= 0;
19768 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
19769 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
19770 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
19772 /* We don't want to record an index value twice as we want to avoid the
19774 We process all global symbols and then all static symbols
19775 (which would allow us to avoid the duplication by only having to check
19776 the last entry pushed), but a symbol could have multiple kinds in one CU.
19777 To keep things simple we don't worry about the duplication here and
19778 sort and uniqufy the list after we've processed all symbols. */
19779 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
19782 /* qsort helper routine for uniquify_cu_indices. */
19785 offset_type_compare (const void *ap
, const void *bp
)
19787 offset_type a
= *(offset_type
*) ap
;
19788 offset_type b
= *(offset_type
*) bp
;
19790 return (a
> b
) - (b
> a
);
19793 /* Sort and remove duplicates of all symbols' cu_indices lists. */
19796 uniquify_cu_indices (struct mapped_symtab
*symtab
)
19800 for (i
= 0; i
< symtab
->size
; ++i
)
19802 struct symtab_index_entry
*entry
= symtab
->data
[i
];
19805 && entry
->cu_indices
!= NULL
)
19807 unsigned int next_to_insert
, next_to_check
;
19808 offset_type last_value
;
19810 qsort (VEC_address (offset_type
, entry
->cu_indices
),
19811 VEC_length (offset_type
, entry
->cu_indices
),
19812 sizeof (offset_type
), offset_type_compare
);
19814 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
19815 next_to_insert
= 1;
19816 for (next_to_check
= 1;
19817 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
19820 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
19823 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
19825 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
19830 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
19835 /* Add a vector of indices to the constant pool. */
19838 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
19839 struct symtab_index_entry
*entry
)
19843 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
19846 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
19847 offset_type val
= MAYBE_SWAP (len
);
19852 entry
->index_offset
= obstack_object_size (cpool
);
19854 obstack_grow (cpool
, &val
, sizeof (val
));
19856 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
19859 val
= MAYBE_SWAP (iter
);
19860 obstack_grow (cpool
, &val
, sizeof (val
));
19865 struct symtab_index_entry
*old_entry
= *slot
;
19866 entry
->index_offset
= old_entry
->index_offset
;
19869 return entry
->index_offset
;
19872 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
19873 constant pool entries going into the obstack CPOOL. */
19876 write_hash_table (struct mapped_symtab
*symtab
,
19877 struct obstack
*output
, struct obstack
*cpool
)
19880 htab_t symbol_hash_table
;
19883 symbol_hash_table
= create_symbol_hash_table ();
19884 str_table
= create_strtab ();
19886 /* We add all the index vectors to the constant pool first, to
19887 ensure alignment is ok. */
19888 for (i
= 0; i
< symtab
->size
; ++i
)
19890 if (symtab
->data
[i
])
19891 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
19894 /* Now write out the hash table. */
19895 for (i
= 0; i
< symtab
->size
; ++i
)
19897 offset_type str_off
, vec_off
;
19899 if (symtab
->data
[i
])
19901 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
19902 vec_off
= symtab
->data
[i
]->index_offset
;
19906 /* While 0 is a valid constant pool index, it is not valid
19907 to have 0 for both offsets. */
19912 str_off
= MAYBE_SWAP (str_off
);
19913 vec_off
= MAYBE_SWAP (vec_off
);
19915 obstack_grow (output
, &str_off
, sizeof (str_off
));
19916 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
19919 htab_delete (str_table
);
19920 htab_delete (symbol_hash_table
);
19923 /* Struct to map psymtab to CU index in the index file. */
19924 struct psymtab_cu_index_map
19926 struct partial_symtab
*psymtab
;
19927 unsigned int cu_index
;
19931 hash_psymtab_cu_index (const void *item
)
19933 const struct psymtab_cu_index_map
*map
= item
;
19935 return htab_hash_pointer (map
->psymtab
);
19939 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
19941 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
19942 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
19944 return lhs
->psymtab
== rhs
->psymtab
;
19947 /* Helper struct for building the address table. */
19948 struct addrmap_index_data
19950 struct objfile
*objfile
;
19951 struct obstack
*addr_obstack
;
19952 htab_t cu_index_htab
;
19954 /* Non-zero if the previous_* fields are valid.
19955 We can't write an entry until we see the next entry (since it is only then
19956 that we know the end of the entry). */
19957 int previous_valid
;
19958 /* Index of the CU in the table of all CUs in the index file. */
19959 unsigned int previous_cu_index
;
19960 /* Start address of the CU. */
19961 CORE_ADDR previous_cu_start
;
19964 /* Write an address entry to OBSTACK. */
19967 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
19968 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
19970 offset_type cu_index_to_write
;
19972 CORE_ADDR baseaddr
;
19974 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19976 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
19977 obstack_grow (obstack
, addr
, 8);
19978 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
19979 obstack_grow (obstack
, addr
, 8);
19980 cu_index_to_write
= MAYBE_SWAP (cu_index
);
19981 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
19984 /* Worker function for traversing an addrmap to build the address table. */
19987 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
19989 struct addrmap_index_data
*data
= datap
;
19990 struct partial_symtab
*pst
= obj
;
19992 if (data
->previous_valid
)
19993 add_address_entry (data
->objfile
, data
->addr_obstack
,
19994 data
->previous_cu_start
, start_addr
,
19995 data
->previous_cu_index
);
19997 data
->previous_cu_start
= start_addr
;
20000 struct psymtab_cu_index_map find_map
, *map
;
20001 find_map
.psymtab
= pst
;
20002 map
= htab_find (data
->cu_index_htab
, &find_map
);
20003 gdb_assert (map
!= NULL
);
20004 data
->previous_cu_index
= map
->cu_index
;
20005 data
->previous_valid
= 1;
20008 data
->previous_valid
= 0;
20013 /* Write OBJFILE's address map to OBSTACK.
20014 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
20015 in the index file. */
20018 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
20019 htab_t cu_index_htab
)
20021 struct addrmap_index_data addrmap_index_data
;
20023 /* When writing the address table, we have to cope with the fact that
20024 the addrmap iterator only provides the start of a region; we have to
20025 wait until the next invocation to get the start of the next region. */
20027 addrmap_index_data
.objfile
= objfile
;
20028 addrmap_index_data
.addr_obstack
= obstack
;
20029 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
20030 addrmap_index_data
.previous_valid
= 0;
20032 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
20033 &addrmap_index_data
);
20035 /* It's highly unlikely the last entry (end address = 0xff...ff)
20036 is valid, but we should still handle it.
20037 The end address is recorded as the start of the next region, but that
20038 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
20040 if (addrmap_index_data
.previous_valid
)
20041 add_address_entry (objfile
, obstack
,
20042 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
20043 addrmap_index_data
.previous_cu_index
);
20046 /* Return the symbol kind of PSYM. */
20048 static gdb_index_symbol_kind
20049 symbol_kind (struct partial_symbol
*psym
)
20051 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
20052 enum address_class aclass
= PSYMBOL_CLASS (psym
);
20060 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
20062 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20064 case LOC_CONST_BYTES
:
20065 case LOC_OPTIMIZED_OUT
:
20067 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20069 /* Note: It's currently impossible to recognize psyms as enum values
20070 short of reading the type info. For now punt. */
20071 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20073 /* There are other LOC_FOO values that one might want to classify
20074 as variables, but dwarf2read.c doesn't currently use them. */
20075 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20077 case STRUCT_DOMAIN
:
20078 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20080 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20084 /* Add a list of partial symbols to SYMTAB. */
20087 write_psymbols (struct mapped_symtab
*symtab
,
20089 struct partial_symbol
**psymp
,
20091 offset_type cu_index
,
20094 for (; count
-- > 0; ++psymp
)
20096 struct partial_symbol
*psym
= *psymp
;
20099 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
20100 error (_("Ada is not currently supported by the index"));
20102 /* Only add a given psymbol once. */
20103 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
20106 gdb_index_symbol_kind kind
= symbol_kind (psym
);
20109 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
20110 is_static
, kind
, cu_index
);
20115 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
20116 exception if there is an error. */
20119 write_obstack (FILE *file
, struct obstack
*obstack
)
20121 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
20123 != obstack_object_size (obstack
))
20124 error (_("couldn't data write to file"));
20127 /* Unlink a file if the argument is not NULL. */
20130 unlink_if_set (void *p
)
20132 char **filename
= p
;
20134 unlink (*filename
);
20137 /* A helper struct used when iterating over debug_types. */
20138 struct signatured_type_index_data
20140 struct objfile
*objfile
;
20141 struct mapped_symtab
*symtab
;
20142 struct obstack
*types_list
;
20147 /* A helper function that writes a single signatured_type to an
20151 write_one_signatured_type (void **slot
, void *d
)
20153 struct signatured_type_index_data
*info
= d
;
20154 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
20155 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
20156 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20159 write_psymbols (info
->symtab
,
20161 info
->objfile
->global_psymbols
.list
20162 + psymtab
->globals_offset
,
20163 psymtab
->n_global_syms
, info
->cu_index
,
20165 write_psymbols (info
->symtab
,
20167 info
->objfile
->static_psymbols
.list
20168 + psymtab
->statics_offset
,
20169 psymtab
->n_static_syms
, info
->cu_index
,
20172 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20173 entry
->per_cu
.offset
.sect_off
);
20174 obstack_grow (info
->types_list
, val
, 8);
20175 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20176 entry
->type_offset_in_tu
.cu_off
);
20177 obstack_grow (info
->types_list
, val
, 8);
20178 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
20179 obstack_grow (info
->types_list
, val
, 8);
20186 /* Recurse into all "included" dependencies and write their symbols as
20187 if they appeared in this psymtab. */
20190 recursively_write_psymbols (struct objfile
*objfile
,
20191 struct partial_symtab
*psymtab
,
20192 struct mapped_symtab
*symtab
,
20194 offset_type cu_index
)
20198 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
20199 if (psymtab
->dependencies
[i
]->user
!= NULL
)
20200 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
20201 symtab
, psyms_seen
, cu_index
);
20203 write_psymbols (symtab
,
20205 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
20206 psymtab
->n_global_syms
, cu_index
,
20208 write_psymbols (symtab
,
20210 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
20211 psymtab
->n_static_syms
, cu_index
,
20215 /* Create an index file for OBJFILE in the directory DIR. */
20218 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
20220 struct cleanup
*cleanup
;
20221 char *filename
, *cleanup_filename
;
20222 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
20223 struct obstack cu_list
, types_cu_list
;
20226 struct mapped_symtab
*symtab
;
20227 offset_type val
, size_of_contents
, total_len
;
20230 htab_t cu_index_htab
;
20231 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
20233 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
20236 if (dwarf2_per_objfile
->using_index
)
20237 error (_("Cannot use an index to create the index"));
20239 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
20240 error (_("Cannot make an index when the file has multiple .debug_types sections"));
20242 if (stat (objfile
->name
, &st
) < 0)
20243 perror_with_name (objfile
->name
);
20245 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
20246 INDEX_SUFFIX
, (char *) NULL
);
20247 cleanup
= make_cleanup (xfree
, filename
);
20249 out_file
= fopen (filename
, "wb");
20251 error (_("Can't open `%s' for writing"), filename
);
20253 cleanup_filename
= filename
;
20254 make_cleanup (unlink_if_set
, &cleanup_filename
);
20256 symtab
= create_mapped_symtab ();
20257 make_cleanup (cleanup_mapped_symtab
, symtab
);
20259 obstack_init (&addr_obstack
);
20260 make_cleanup_obstack_free (&addr_obstack
);
20262 obstack_init (&cu_list
);
20263 make_cleanup_obstack_free (&cu_list
);
20265 obstack_init (&types_cu_list
);
20266 make_cleanup_obstack_free (&types_cu_list
);
20268 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
20269 NULL
, xcalloc
, xfree
);
20270 make_cleanup_htab_delete (psyms_seen
);
20272 /* While we're scanning CU's create a table that maps a psymtab pointer
20273 (which is what addrmap records) to its index (which is what is recorded
20274 in the index file). This will later be needed to write the address
20276 cu_index_htab
= htab_create_alloc (100,
20277 hash_psymtab_cu_index
,
20278 eq_psymtab_cu_index
,
20279 NULL
, xcalloc
, xfree
);
20280 make_cleanup_htab_delete (cu_index_htab
);
20281 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
20282 xmalloc (sizeof (struct psymtab_cu_index_map
)
20283 * dwarf2_per_objfile
->n_comp_units
);
20284 make_cleanup (xfree
, psymtab_cu_index_map
);
20286 /* The CU list is already sorted, so we don't need to do additional
20287 work here. Also, the debug_types entries do not appear in
20288 all_comp_units, but only in their own hash table. */
20289 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
20291 struct dwarf2_per_cu_data
*per_cu
20292 = dwarf2_per_objfile
->all_comp_units
[i
];
20293 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20295 struct psymtab_cu_index_map
*map
;
20298 if (psymtab
->user
== NULL
)
20299 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
20301 map
= &psymtab_cu_index_map
[i
];
20302 map
->psymtab
= psymtab
;
20304 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
20305 gdb_assert (slot
!= NULL
);
20306 gdb_assert (*slot
== NULL
);
20309 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20310 per_cu
->offset
.sect_off
);
20311 obstack_grow (&cu_list
, val
, 8);
20312 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
20313 obstack_grow (&cu_list
, val
, 8);
20316 /* Dump the address map. */
20317 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
20319 /* Write out the .debug_type entries, if any. */
20320 if (dwarf2_per_objfile
->signatured_types
)
20322 struct signatured_type_index_data sig_data
;
20324 sig_data
.objfile
= objfile
;
20325 sig_data
.symtab
= symtab
;
20326 sig_data
.types_list
= &types_cu_list
;
20327 sig_data
.psyms_seen
= psyms_seen
;
20328 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
20329 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
20330 write_one_signatured_type
, &sig_data
);
20333 /* Now that we've processed all symbols we can shrink their cu_indices
20335 uniquify_cu_indices (symtab
);
20337 obstack_init (&constant_pool
);
20338 make_cleanup_obstack_free (&constant_pool
);
20339 obstack_init (&symtab_obstack
);
20340 make_cleanup_obstack_free (&symtab_obstack
);
20341 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
20343 obstack_init (&contents
);
20344 make_cleanup_obstack_free (&contents
);
20345 size_of_contents
= 6 * sizeof (offset_type
);
20346 total_len
= size_of_contents
;
20348 /* The version number. */
20349 val
= MAYBE_SWAP (7);
20350 obstack_grow (&contents
, &val
, sizeof (val
));
20352 /* The offset of the CU list from the start of the file. */
20353 val
= MAYBE_SWAP (total_len
);
20354 obstack_grow (&contents
, &val
, sizeof (val
));
20355 total_len
+= obstack_object_size (&cu_list
);
20357 /* The offset of the types CU list from the start of the file. */
20358 val
= MAYBE_SWAP (total_len
);
20359 obstack_grow (&contents
, &val
, sizeof (val
));
20360 total_len
+= obstack_object_size (&types_cu_list
);
20362 /* The offset of the address table from the start of the file. */
20363 val
= MAYBE_SWAP (total_len
);
20364 obstack_grow (&contents
, &val
, sizeof (val
));
20365 total_len
+= obstack_object_size (&addr_obstack
);
20367 /* The offset of the symbol table from the start of the file. */
20368 val
= MAYBE_SWAP (total_len
);
20369 obstack_grow (&contents
, &val
, sizeof (val
));
20370 total_len
+= obstack_object_size (&symtab_obstack
);
20372 /* The offset of the constant pool from the start of the file. */
20373 val
= MAYBE_SWAP (total_len
);
20374 obstack_grow (&contents
, &val
, sizeof (val
));
20375 total_len
+= obstack_object_size (&constant_pool
);
20377 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
20379 write_obstack (out_file
, &contents
);
20380 write_obstack (out_file
, &cu_list
);
20381 write_obstack (out_file
, &types_cu_list
);
20382 write_obstack (out_file
, &addr_obstack
);
20383 write_obstack (out_file
, &symtab_obstack
);
20384 write_obstack (out_file
, &constant_pool
);
20388 /* We want to keep the file, so we set cleanup_filename to NULL
20389 here. See unlink_if_set. */
20390 cleanup_filename
= NULL
;
20392 do_cleanups (cleanup
);
20395 /* Implementation of the `save gdb-index' command.
20397 Note that the file format used by this command is documented in the
20398 GDB manual. Any changes here must be documented there. */
20401 save_gdb_index_command (char *arg
, int from_tty
)
20403 struct objfile
*objfile
;
20406 error (_("usage: save gdb-index DIRECTORY"));
20408 ALL_OBJFILES (objfile
)
20412 /* If the objfile does not correspond to an actual file, skip it. */
20413 if (stat (objfile
->name
, &st
) < 0)
20416 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
20417 if (dwarf2_per_objfile
)
20419 volatile struct gdb_exception except
;
20421 TRY_CATCH (except
, RETURN_MASK_ERROR
)
20423 write_psymtabs_to_index (objfile
, arg
);
20425 if (except
.reason
< 0)
20426 exception_fprintf (gdb_stderr
, except
,
20427 _("Error while writing index for `%s': "),
20435 int dwarf2_always_disassemble
;
20438 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
20439 struct cmd_list_element
*c
, const char *value
)
20441 fprintf_filtered (file
,
20442 _("Whether to always disassemble "
20443 "DWARF expressions is %s.\n"),
20448 show_check_physname (struct ui_file
*file
, int from_tty
,
20449 struct cmd_list_element
*c
, const char *value
)
20451 fprintf_filtered (file
,
20452 _("Whether to check \"physname\" is %s.\n"),
20456 void _initialize_dwarf2_read (void);
20459 _initialize_dwarf2_read (void)
20461 struct cmd_list_element
*c
;
20463 dwarf2_objfile_data_key
20464 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
20466 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
20467 Set DWARF 2 specific variables.\n\
20468 Configure DWARF 2 variables such as the cache size"),
20469 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
20470 0/*allow-unknown*/, &maintenance_set_cmdlist
);
20472 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
20473 Show DWARF 2 specific variables\n\
20474 Show DWARF 2 variables such as the cache size"),
20475 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
20476 0/*allow-unknown*/, &maintenance_show_cmdlist
);
20478 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
20479 &dwarf2_max_cache_age
, _("\
20480 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
20481 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
20482 A higher limit means that cached compilation units will be stored\n\
20483 in memory longer, and more total memory will be used. Zero disables\n\
20484 caching, which can slow down startup."),
20486 show_dwarf2_max_cache_age
,
20487 &set_dwarf2_cmdlist
,
20488 &show_dwarf2_cmdlist
);
20490 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
20491 &dwarf2_always_disassemble
, _("\
20492 Set whether `info address' always disassembles DWARF expressions."), _("\
20493 Show whether `info address' always disassembles DWARF expressions."), _("\
20494 When enabled, DWARF expressions are always printed in an assembly-like\n\
20495 syntax. When disabled, expressions will be printed in a more\n\
20496 conversational style, when possible."),
20498 show_dwarf2_always_disassemble
,
20499 &set_dwarf2_cmdlist
,
20500 &show_dwarf2_cmdlist
);
20502 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
20503 Set debugging of the dwarf2 reader."), _("\
20504 Show debugging of the dwarf2 reader."), _("\
20505 When enabled, debugging messages are printed during dwarf2 reading\n\
20506 and symtab expansion."),
20509 &setdebuglist
, &showdebuglist
);
20511 add_setshow_zuinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
20512 Set debugging of the dwarf2 DIE reader."), _("\
20513 Show debugging of the dwarf2 DIE reader."), _("\
20514 When enabled (non-zero), DIEs are dumped after they are read in.\n\
20515 The value is the maximum depth to print."),
20518 &setdebuglist
, &showdebuglist
);
20520 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
20521 Set cross-checking of \"physname\" code against demangler."), _("\
20522 Show cross-checking of \"physname\" code against demangler."), _("\
20523 When enabled, GDB's internal \"physname\" code is checked against\n\
20525 NULL
, show_check_physname
,
20526 &setdebuglist
, &showdebuglist
);
20528 add_setshow_boolean_cmd ("use-deprecated-index-sections",
20529 no_class
, &use_deprecated_index_sections
, _("\
20530 Set whether to use deprecated gdb_index sections."), _("\
20531 Show whether to use deprecated gdb_index sections."), _("\
20532 When enabled, deprecated .gdb_index sections are used anyway.\n\
20533 Normally they are ignored either because of a missing feature or\n\
20534 performance issue.\n\
20535 Warning: This option must be enabled before gdb reads the file."),
20538 &setlist
, &showlist
);
20540 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
20542 Save a gdb-index file.\n\
20543 Usage: save gdb-index DIRECTORY"),
20545 set_cmd_completer (c
, filename_completer
);