1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2023 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 /* TODO: Emit .debug_line header even when there are no functions, since
24 the file numbers are used by .debug_info. Alternately, leave
25 out locations for types and decls.
26 Avoid talking about ctors and op= for PODs.
27 Factor out common prologue sequences into multiple CIEs. */
29 /* The first part of this file deals with the DWARF 2 frame unwind
30 information, which is also used by the GCC efficient exception handling
31 mechanism. The second part, controlled only by an #ifdef
32 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 /* DWARF2 Abbreviation Glossary:
37 CFA = Canonical Frame Address
38 a fixed address on the stack which identifies a call frame.
39 We define it to be the value of SP just before the call insn.
40 The CFA register and offset, which may change during the course
41 of the function, are used to calculate its value at runtime.
43 CFI = Call Frame Instruction
44 an instruction for the DWARF2 abstract machine
46 CIE = Common Information Entry
47 information describing information common to one or more FDEs
49 DIE = Debugging Information Entry
51 FDE = Frame Description Entry
52 information describing the stack call frame, in particular,
53 how to restore registers
55 DW_CFA_... = DWARF2 CFA call frame instruction
56 DW_TAG_... = DWARF2 DIE tag */
60 #include "coretypes.h"
67 #include "stringpool.h"
68 #include "insn-config.h"
71 #include "diagnostic.h"
72 #include "fold-const.h"
73 #include "stor-layout.h"
81 #include "dwarf2out.h"
82 #include "dwarf2ctf.h"
83 #include "dwarf2asm.h"
86 #include "tree-pretty-print.h"
87 #include "print-rtl.h"
89 #include "common/common-target.h"
90 #include "langhooks.h"
95 #include "gdb/gdb-index.h"
97 #include "stringpool.h"
99 #include "file-prefix-map.h" /* remap_debug_filename() */
101 static void dwarf2out_source_line (unsigned int, unsigned int, const char *,
103 static rtx_insn
*last_var_location_insn
;
104 static rtx_insn
*cached_next_real_insn
;
105 static void dwarf2out_decl (tree
);
106 static bool is_redundant_typedef (const_tree
);
108 #ifndef XCOFF_DEBUGGING_INFO
109 #define XCOFF_DEBUGGING_INFO 0
112 #ifndef HAVE_XCOFF_DWARF_EXTRAS
113 #define HAVE_XCOFF_DWARF_EXTRAS 0
116 #ifdef VMS_DEBUGGING_INFO
117 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
119 /* Define this macro to be a nonzero value if the directory specifications
120 which are output in the debug info should end with a separator. */
121 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
122 /* Define this macro to evaluate to a nonzero value if GCC should refrain
123 from generating indirect strings in DWARF2 debug information, for instance
124 if your target is stuck with an old version of GDB that is unable to
125 process them properly or uses VMS Debug. */
126 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
128 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
129 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
132 /* ??? Poison these here until it can be done generically. They've been
133 totally replaced in this file; make sure it stays that way. */
134 #undef DWARF2_UNWIND_INFO
135 #undef DWARF2_FRAME_INFO
136 #if (GCC_VERSION >= 3000)
137 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
140 /* The size of the target's pointer type. */
142 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
145 /* Array of RTXes referenced by the debugging information, which therefore
146 must be kept around forever. */
147 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
149 /* A pointer to the base of a list of incomplete types which might be
150 completed at some later time. incomplete_types_list needs to be a
151 vec<tree, va_gc> *because we want to tell the garbage collector about
153 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
155 /* Pointers to various DWARF2 sections. */
156 static GTY(()) section
*debug_info_section
;
157 static GTY(()) section
*debug_skeleton_info_section
;
158 static GTY(()) section
*debug_abbrev_section
;
159 static GTY(()) section
*debug_skeleton_abbrev_section
;
160 static GTY(()) section
*debug_aranges_section
;
161 static GTY(()) section
*debug_addr_section
;
162 static GTY(()) section
*debug_macinfo_section
;
163 static const char *debug_macinfo_section_name
;
164 static unsigned macinfo_label_base
= 1;
165 static GTY(()) section
*debug_line_section
;
166 static GTY(()) section
*debug_skeleton_line_section
;
167 static GTY(()) section
*debug_loc_section
;
168 static GTY(()) section
*debug_pubnames_section
;
169 static GTY(()) section
*debug_pubtypes_section
;
170 static GTY(()) section
*debug_str_section
;
171 static GTY(()) section
*debug_line_str_section
;
172 static GTY(()) section
*debug_str_dwo_section
;
173 static GTY(()) section
*debug_str_offsets_section
;
174 static GTY(()) section
*debug_ranges_section
;
175 static GTY(()) section
*debug_ranges_dwo_section
;
176 static GTY(()) section
*debug_frame_section
;
178 /* Maximum size (in bytes) of an artificially generated label. */
179 #define MAX_ARTIFICIAL_LABEL_BYTES 40
181 /* According to the (draft) DWARF 3 specification, the initial length
182 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
183 bytes are 0xffffffff, followed by the length stored in the next 8
186 However, the SGI/MIPS ABI uses an initial length which is equal to
187 dwarf_offset_size. It is defined (elsewhere) accordingly. */
189 #ifndef DWARF_INITIAL_LENGTH_SIZE
190 #define DWARF_INITIAL_LENGTH_SIZE (dwarf_offset_size == 4 ? 4 : 12)
193 #ifndef DWARF_INITIAL_LENGTH_SIZE_STR
194 #define DWARF_INITIAL_LENGTH_SIZE_STR (dwarf_offset_size == 4 ? "-4" : "-12")
197 /* Round SIZE up to the nearest BOUNDARY. */
198 #define DWARF_ROUND(SIZE,BOUNDARY) \
199 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
201 /* CIE identifier. */
202 #if HOST_BITS_PER_WIDE_INT >= 64
203 #define DWARF_CIE_ID \
204 (unsigned HOST_WIDE_INT) (dwarf_offset_size == 4 ? DW_CIE_ID : DW64_CIE_ID)
206 #define DWARF_CIE_ID DW_CIE_ID
210 /* A vector for a table that contains frame description
211 information for each routine. */
212 #define NOT_INDEXED (-1U)
213 #define NO_INDEX_ASSIGNED (-2U)
215 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
217 struct GTY((for_user
)) indirect_string_node
{
219 unsigned int refcount
;
220 enum dwarf_form form
;
225 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
227 typedef const char *compare_type
;
229 static hashval_t
hash (indirect_string_node
*);
230 static bool equal (indirect_string_node
*, const char *);
233 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
235 static GTY (()) hash_table
<indirect_string_hasher
> *debug_line_str_hash
;
237 /* With split_debug_info, both the comp_dir and dwo_name go in the
238 main object file, rather than the dwo, similar to the force_direct
239 parameter elsewhere but with additional complications:
241 1) The string is needed in both the main object file and the dwo.
242 That is, the comp_dir and dwo_name will appear in both places.
244 2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
245 DW_FORM_line_strp or DW_FORM_strx/GNU_str_index.
247 3) GCC chooses the form to use late, depending on the size and
250 Rather than forcing the all debug string handling functions and
251 callers to deal with these complications, simply use a separate,
252 special-cased string table for any attribute that should go in the
253 main object file. This limits the complexity to just the places
256 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
258 static GTY(()) int dw2_string_counter
;
260 /* True if the compilation unit places functions in more than one section. */
261 static GTY(()) bool have_multiple_function_sections
= false;
263 /* The default cold text section. */
264 static GTY(()) section
*cold_text_section
;
266 /* True if currently in text section. */
267 static GTY(()) bool in_text_section_p
= false;
269 /* Last debug-on location in corresponding section. */
270 static GTY(()) const char *last_text_label
;
271 static GTY(()) const char *last_cold_label
;
273 /* Mark debug-on/off locations per section.
274 NULL means the section is not used at all. */
275 static GTY(()) vec
<const char *, va_gc
> *switch_text_ranges
;
276 static GTY(()) vec
<const char *, va_gc
> *switch_cold_ranges
;
278 /* The DIE for C++14 'auto' in a function return type. */
279 static GTY(()) dw_die_ref auto_die
;
281 /* The DIE for C++14 'decltype(auto)' in a function return type. */
282 static GTY(()) dw_die_ref decltype_auto_die
;
284 /* Forward declarations for functions defined in this file. */
286 static void output_call_frame_info (int);
288 /* Personality decl of current unit. Used only when assembler does not support
290 static GTY(()) rtx current_unit_personality
;
292 /* Whether an eh_frame section is required. */
293 static GTY(()) bool do_eh_frame
= false;
295 /* .debug_rnglists next index. */
296 static unsigned int rnglist_idx
;
298 /* Data and reference forms for relocatable data. */
299 #define DW_FORM_data (dwarf_offset_size == 8 ? DW_FORM_data8 : DW_FORM_data4)
300 #define DW_FORM_ref (dwarf_offset_size == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
302 #ifndef DEBUG_FRAME_SECTION
303 #define DEBUG_FRAME_SECTION ".debug_frame"
306 #ifndef FUNC_BEGIN_LABEL
307 #define FUNC_BEGIN_LABEL "LFB"
310 #ifndef FUNC_SECOND_SECT_LABEL
311 #define FUNC_SECOND_SECT_LABEL "LFSB"
314 #ifndef FUNC_END_LABEL
315 #define FUNC_END_LABEL "LFE"
318 #ifndef PROLOGUE_END_LABEL
319 #define PROLOGUE_END_LABEL "LPE"
322 #ifndef EPILOGUE_BEGIN_LABEL
323 #define EPILOGUE_BEGIN_LABEL "LEB"
326 #ifndef FRAME_BEGIN_LABEL
327 #define FRAME_BEGIN_LABEL "Lframe"
329 #define CIE_AFTER_SIZE_LABEL "LSCIE"
330 #define CIE_END_LABEL "LECIE"
331 #define FDE_LABEL "LSFDE"
332 #define FDE_AFTER_SIZE_LABEL "LASFDE"
333 #define FDE_END_LABEL "LEFDE"
334 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
335 #define LINE_NUMBER_END_LABEL "LELT"
336 #define LN_PROLOG_AS_LABEL "LASLTP"
337 #define LN_PROLOG_END_LABEL "LELTP"
338 #define DIE_LABEL_PREFIX "DW"
340 /* Match the base name of a file to the base name of a compilation unit. */
343 matches_main_base (const char *path
)
345 /* Cache the last query. */
346 static const char *last_path
= NULL
;
347 static bool last_match
= false;
348 if (path
!= last_path
)
351 int length
= base_of_path (path
, &base
);
353 last_match
= (length
== main_input_baselength
354 && memcmp (base
, main_input_basename
, length
) == 0);
359 #ifdef DEBUG_DEBUG_STRUCT
362 dump_struct_debug (tree type
, enum debug_info_usage usage
,
363 enum debug_struct_file criterion
, int generic
,
364 bool matches
, bool result
)
366 /* Find the type name. */
367 tree type_decl
= TYPE_STUB_DECL (type
);
369 const char *name
= 0;
370 if (TREE_CODE (t
) == TYPE_DECL
)
373 name
= IDENTIFIER_POINTER (t
);
375 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
377 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
378 matches
? "bas" : "hdr",
379 generic
? "gen" : "ord",
380 usage
== DINFO_USAGE_DFN
? ";" :
381 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
383 (void*) type_decl
, name
);
386 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
387 dump_struct_debug (type, usage, criterion, generic, matches, result)
391 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
396 /* Get the number of HOST_WIDE_INTs needed to represent the precision
400 get_full_len (const dw_wide_int
&op
)
402 return CEIL (op
.get_precision (), HOST_BITS_PER_WIDE_INT
);
406 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
408 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
411 enum debug_struct_file criterion
;
413 bool generic
= lang_hooks
.types
.generic_p (type
);
416 criterion
= debug_struct_generic
[usage
];
418 criterion
= debug_struct_ordinary
[usage
];
420 if (criterion
== DINFO_STRUCT_FILE_NONE
)
421 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
422 if (criterion
== DINFO_STRUCT_FILE_ANY
)
423 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
425 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
427 if (type_decl
!= NULL
)
429 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
430 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
432 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
433 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
436 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
439 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
440 switch to the data section instead, and write out a synthetic start label
441 for collect2 the first time around. */
444 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
446 if (eh_frame_section
== 0)
450 if (EH_TABLES_CAN_BE_READ_ONLY
)
456 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
458 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
460 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
463 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
464 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
465 && (per_encoding
& 0x70) != DW_EH_PE_absptr
466 && (per_encoding
& 0x70) != DW_EH_PE_aligned
467 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
468 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
469 ? 0 : SECTION_WRITE
);
472 flags
= SECTION_WRITE
;
474 #ifdef EH_FRAME_SECTION_NAME
475 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
477 eh_frame_section
= ((flags
== SECTION_WRITE
)
478 ? data_section
: readonly_data_section
);
479 #endif /* EH_FRAME_SECTION_NAME */
482 switch_to_section (eh_frame_section
);
484 #ifdef EH_FRAME_THROUGH_COLLECT2
485 /* We have no special eh_frame section. Emit special labels to guide
489 tree label
= get_file_function_name ("F");
490 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
491 targetm
.asm_out
.globalize_label (asm_out_file
,
492 IDENTIFIER_POINTER (label
));
493 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
498 /* Switch [BACK] to the eh or debug frame table section, depending on
502 switch_to_frame_table_section (int for_eh
, bool back
)
505 switch_to_eh_frame_section (back
);
508 if (!debug_frame_section
)
509 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
510 SECTION_DEBUG
, NULL
);
511 switch_to_section (debug_frame_section
);
515 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
517 enum dw_cfi_oprnd_type
518 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
523 case DW_CFA_GNU_window_save
:
524 case DW_CFA_remember_state
:
525 case DW_CFA_restore_state
:
526 return dw_cfi_oprnd_unused
;
529 case DW_CFA_advance_loc1
:
530 case DW_CFA_advance_loc2
:
531 case DW_CFA_advance_loc4
:
532 case DW_CFA_MIPS_advance_loc8
:
533 return dw_cfi_oprnd_addr
;
536 case DW_CFA_offset_extended
:
538 case DW_CFA_offset_extended_sf
:
539 case DW_CFA_def_cfa_sf
:
541 case DW_CFA_restore_extended
:
542 case DW_CFA_undefined
:
543 case DW_CFA_same_value
:
544 case DW_CFA_def_cfa_register
:
545 case DW_CFA_register
:
546 case DW_CFA_expression
:
547 case DW_CFA_val_expression
:
548 return dw_cfi_oprnd_reg_num
;
550 case DW_CFA_def_cfa_offset
:
551 case DW_CFA_GNU_args_size
:
552 case DW_CFA_def_cfa_offset_sf
:
553 return dw_cfi_oprnd_offset
;
555 case DW_CFA_def_cfa_expression
:
556 return dw_cfi_oprnd_loc
;
563 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
565 enum dw_cfi_oprnd_type
566 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
571 case DW_CFA_def_cfa_sf
:
573 case DW_CFA_offset_extended_sf
:
574 case DW_CFA_offset_extended
:
575 return dw_cfi_oprnd_offset
;
577 case DW_CFA_register
:
578 return dw_cfi_oprnd_reg_num
;
580 case DW_CFA_expression
:
581 case DW_CFA_val_expression
:
582 return dw_cfi_oprnd_loc
;
584 case DW_CFA_def_cfa_expression
:
585 return dw_cfi_oprnd_cfa_loc
;
588 return dw_cfi_oprnd_unused
;
592 /* Output one FDE. */
595 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
596 char *section_start_label
, int fde_encoding
, char *augmentation
,
597 bool any_lsda_needed
, int lsda_encoding
)
599 const char *begin
, *end
;
600 static unsigned int j
;
601 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
603 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
605 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
607 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
608 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
609 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
611 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4 && !for_eh
)
612 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
613 " indicating 64-bit DWARF extension");
614 dw2_asm_output_delta (for_eh
? 4 : dwarf_offset_size
, l2
, l1
,
617 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
620 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
622 dw2_asm_output_offset (dwarf_offset_size
, section_start_label
,
623 debug_frame_section
, "FDE CIE offset");
625 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
626 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
630 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
631 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
632 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
633 "FDE initial location");
634 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
635 end
, begin
, "FDE address range");
639 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
640 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
647 int size
= size_of_encoded_value (lsda_encoding
);
649 if (lsda_encoding
== DW_EH_PE_aligned
)
651 int offset
= ( 4 /* Length */
653 + 2 * size_of_encoded_value (fde_encoding
)
654 + 1 /* Augmentation size */ );
655 int pad
= -offset
& (PTR_SIZE
- 1);
658 gcc_assert (size_of_uleb128 (size
) == 1);
661 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
663 if (fde
->uses_eh_lsda
)
665 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
666 fde
->funcdef_number
);
667 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
668 gen_rtx_SYMBOL_REF (Pmode
, l1
),
670 "Language Specific Data Area");
674 if (lsda_encoding
== DW_EH_PE_aligned
)
675 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
676 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
677 "Language Specific Data Area (none)");
681 dw2_asm_output_data_uleb128 (0, "Augmentation size");
684 /* Loop through the Call Frame Instructions associated with this FDE. */
685 fde
->dw_fde_current_label
= begin
;
687 size_t from
, until
, i
;
690 until
= vec_safe_length (fde
->dw_fde_cfi
);
692 if (fde
->dw_fde_second_begin
== NULL
)
695 until
= fde
->dw_fde_switch_cfi_index
;
697 from
= fde
->dw_fde_switch_cfi_index
;
699 for (i
= from
; i
< until
; i
++)
700 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
703 /* If we are to emit a ref/link from function bodies to their frame tables,
704 do it now. This is typically performed to make sure that tables
705 associated with functions are dragged with them and not discarded in
706 garbage collecting links. We need to do this on a per function basis to
707 cope with -ffunction-sections. */
709 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
710 /* Switch to the function section, emit the ref to the tables, and
711 switch *back* into the table section. */
712 switch_to_section (function_section (fde
->decl
));
713 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
714 switch_to_frame_table_section (for_eh
, true);
717 /* Pad the FDE out to an address sized boundary. */
718 ASM_OUTPUT_ALIGN (asm_out_file
,
719 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
720 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
725 /* Return true if frame description entry FDE is needed for EH. */
728 fde_needed_for_eh_p (dw_fde_ref fde
)
730 if (flag_asynchronous_unwind_tables
)
733 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
736 if (fde
->uses_eh_lsda
)
739 /* If exceptions are enabled, we have collected nothrow info. */
740 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
746 /* Output the call frame information used to record information
747 that relates to calculating the frame pointer, and records the
748 location of saved registers. */
751 output_call_frame_info (int for_eh
)
756 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
757 char section_start_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
758 bool any_lsda_needed
= false;
759 char augmentation
[6];
760 int augmentation_size
;
761 int fde_encoding
= DW_EH_PE_absptr
;
762 int per_encoding
= DW_EH_PE_absptr
;
763 int lsda_encoding
= DW_EH_PE_absptr
;
765 rtx personality
= NULL
;
768 /* Don't emit a CIE if there won't be any FDEs. */
772 /* Nothing to do if the assembler's doing it all. */
773 if (dwarf2out_do_cfi_asm ())
776 /* If we don't have any functions we'll want to unwind out of, don't emit
777 any EH unwind information. If we make FDEs linkonce, we may have to
778 emit an empty label for an FDE that wouldn't otherwise be emitted. We
779 want to avoid having an FDE kept around when the function it refers to
780 is discarded. Example where this matters: a primary function template
781 in C++ requires EH information, an explicit specialization doesn't. */
784 bool any_eh_needed
= false;
786 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
788 if (fde
->uses_eh_lsda
)
789 any_eh_needed
= any_lsda_needed
= true;
790 else if (fde_needed_for_eh_p (fde
))
791 any_eh_needed
= true;
792 else if (TARGET_USES_WEAK_UNWIND_INFO
)
793 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
800 /* We're going to be generating comments, so turn on app. */
804 /* Switch to the proper frame section, first time. */
805 switch_to_frame_table_section (for_eh
, false);
807 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
808 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
810 /* Output the CIE. */
811 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
812 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
813 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
815 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4 && !for_eh
)
816 dw2_asm_output_data (4, 0xffffffff,
817 "Initial length escape value indicating 64-bit DWARF extension");
818 dw2_asm_output_delta (for_eh
? 4 : dwarf_offset_size
, l2
, l1
,
819 "Length of Common Information Entry");
821 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
823 /* Now that the CIE pointer is PC-relative for EH,
824 use 0 to identify the CIE. */
825 dw2_asm_output_data ((for_eh
? 4 : dwarf_offset_size
),
826 (for_eh
? 0 : DWARF_CIE_ID
),
827 "CIE Identifier Tag");
829 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
830 use CIE version 1, unless that would produce incorrect results
831 due to overflowing the return register column. */
832 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
834 if (return_reg
>= 256 || dwarf_version
> 2)
836 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
839 augmentation_size
= 0;
841 personality
= current_unit_personality
;
847 z Indicates that a uleb128 is present to size the
848 augmentation section.
849 L Indicates the encoding (and thus presence) of
850 an LSDA pointer in the FDE augmentation.
851 R Indicates a non-default pointer encoding for
853 P Indicates the presence of an encoding + language
854 personality routine in the CIE augmentation. */
856 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
857 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
858 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
860 p
= augmentation
+ 1;
864 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
865 assemble_external_libcall (personality
);
870 augmentation_size
+= 1;
872 if (fde_encoding
!= DW_EH_PE_absptr
)
875 augmentation_size
+= 1;
877 if (p
> augmentation
+ 1)
879 augmentation
[0] = 'z';
883 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
884 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
886 int offset
= ( 4 /* Length */
888 + 1 /* CIE version */
889 + strlen (augmentation
) + 1 /* Augmentation */
890 + size_of_uleb128 (1) /* Code alignment */
891 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
893 + 1 /* Augmentation size */
894 + 1 /* Personality encoding */ );
895 int pad
= -offset
& (PTR_SIZE
- 1);
897 augmentation_size
+= pad
;
899 /* Augmentations should be small, so there's scarce need to
900 iterate for a solution. Die if we exceed one uleb128 byte. */
901 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
905 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
906 if (dw_cie_version
>= 4)
908 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
909 dw2_asm_output_data (1, 0, "CIE Segment Size");
911 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
912 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
913 "CIE Data Alignment Factor");
915 if (dw_cie_version
== 1)
916 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
918 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
922 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
925 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
926 eh_data_format_name (per_encoding
));
927 dw2_asm_output_encoded_addr_rtx (per_encoding
,
933 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
934 eh_data_format_name (lsda_encoding
));
936 if (fde_encoding
!= DW_EH_PE_absptr
)
937 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
938 eh_data_format_name (fde_encoding
));
941 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
942 output_cfi (cfi
, NULL
, for_eh
);
944 /* Pad the CIE out to an address sized boundary. */
945 ASM_OUTPUT_ALIGN (asm_out_file
,
946 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
947 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
949 /* Loop through all of the FDE's. */
950 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
954 /* Don't emit EH unwind info for leaf functions that don't need it. */
955 if (for_eh
&& !fde_needed_for_eh_p (fde
))
958 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
959 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
960 augmentation
, any_lsda_needed
, lsda_encoding
);
963 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
964 dw2_asm_output_data (4, 0, "End of Table");
966 /* Turn off app to make assembly quicker. */
971 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
974 dwarf2out_do_cfi_startproc (bool second
)
979 fprintf (asm_out_file
, "\t.cfi_startproc\n");
981 targetm
.asm_out
.post_cfi_startproc (asm_out_file
, current_function_decl
);
983 /* .cfi_personality and .cfi_lsda are only relevant to DWARF2
985 if (targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
)
988 rtx personality
= get_personality_function (current_function_decl
);
992 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
995 /* ??? The GAS support isn't entirely consistent. We have to
996 handle indirect support ourselves, but PC-relative is done
997 in the assembler. Further, the assembler can't handle any
998 of the weirder relocation types. */
999 if (enc
& DW_EH_PE_indirect
)
1001 if (targetm
.asm_out
.make_eh_symbol_indirect
!= NULL
)
1002 ref
= targetm
.asm_out
.make_eh_symbol_indirect (ref
, true);
1004 ref
= dw2_force_const_mem (ref
, true);
1007 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
1008 output_addr_const (asm_out_file
, ref
);
1009 fputc ('\n', asm_out_file
);
1012 if (crtl
->uses_eh_lsda
)
1014 char lab
[MAX_ARTIFICIAL_LABEL_BYTES
];
1016 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1017 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
1018 current_function_funcdef_no
);
1019 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
1020 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
1022 if (enc
& DW_EH_PE_indirect
)
1024 if (targetm
.asm_out
.make_eh_symbol_indirect
!= NULL
)
1025 ref
= targetm
.asm_out
.make_eh_symbol_indirect (ref
, true);
1027 ref
= dw2_force_const_mem (ref
, true);
1030 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
1031 output_addr_const (asm_out_file
, ref
);
1032 fputc ('\n', asm_out_file
);
1036 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1037 this allocation may be done before pass_final. */
1040 dwarf2out_alloc_current_fde (void)
1044 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1045 fde
->decl
= current_function_decl
;
1046 fde
->funcdef_number
= current_function_funcdef_no
;
1047 fde
->fde_index
= vec_safe_length (fde_vec
);
1048 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1049 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1050 fde
->nothrow
= crtl
->nothrow
;
1051 fde
->drap_reg
= INVALID_REGNUM
;
1052 fde
->vdrap_reg
= INVALID_REGNUM
;
1054 /* Record the FDE associated with this function. */
1056 vec_safe_push (fde_vec
, fde
);
1061 /* Output a marker (i.e. a label) for the beginning of a function, before
1065 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1066 unsigned int column ATTRIBUTE_UNUSED
,
1067 const char *file ATTRIBUTE_UNUSED
)
1069 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1075 current_function_func_begin_label
= NULL
;
1077 do_frame
= dwarf2out_do_frame ();
1079 /* ??? current_function_func_begin_label is also used by except.cc for
1080 call-site information. We must emit this label if it might be used. */
1082 && (!flag_exceptions
1083 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1086 fnsec
= function_section (current_function_decl
);
1087 switch_to_section (fnsec
);
1088 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1089 current_function_funcdef_no
);
1090 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1091 current_function_funcdef_no
);
1092 dup_label
= xstrdup (label
);
1093 current_function_func_begin_label
= dup_label
;
1095 /* We can elide FDE allocation if we're not emitting frame unwind info. */
1099 /* Unlike the debug version, the EH version of frame unwind info is a per-
1100 function setting so we need to record whether we need it for the unit. */
1101 do_eh_frame
|= dwarf2out_do_eh_frame ();
1103 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1104 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1105 would include pass_dwarf2_frame. If we've not created the FDE yet,
1109 fde
= dwarf2out_alloc_current_fde ();
1111 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1112 fde
->dw_fde_begin
= dup_label
;
1113 fde
->dw_fde_current_label
= dup_label
;
1114 fde
->in_std_section
= (fnsec
== text_section
1115 || (cold_text_section
&& fnsec
== cold_text_section
));
1116 fde
->ignored_debug
= DECL_IGNORED_P (current_function_decl
);
1117 in_text_section_p
= fnsec
== text_section
;
1119 /* We only want to output line number information for the genuine dwarf2
1120 prologue case, not the eh frame case. */
1121 #ifdef DWARF2_DEBUGGING_INFO
1123 dwarf2out_source_line (line
, column
, file
, 0, true);
1126 if (dwarf2out_do_cfi_asm ())
1127 dwarf2out_do_cfi_startproc (false);
1130 rtx personality
= get_personality_function (current_function_decl
);
1131 if (!current_unit_personality
)
1132 current_unit_personality
= personality
;
1134 /* We cannot keep a current personality per function as without CFI
1135 asm, at the point where we emit the CFI data, there is no current
1136 function anymore. */
1137 if (personality
&& current_unit_personality
!= personality
)
1138 sorry ("multiple EH personalities are supported only with assemblers "
1139 "supporting %<.cfi_personality%> directive");
1143 /* Output a marker (i.e. a label) for the end of the generated code
1144 for a function prologue. This gets called *after* the prologue code has
1148 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1149 const char *file ATTRIBUTE_UNUSED
)
1151 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1153 /* Output a label to mark the endpoint of the code generated for this
1155 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1156 current_function_funcdef_no
);
1157 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1158 current_function_funcdef_no
);
1159 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1162 /* Output a marker (i.e. a label) for the beginning of the generated code
1163 for a function epilogue. This gets called *before* the prologue code has
1167 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1168 const char *file ATTRIBUTE_UNUSED
)
1170 dw_fde_ref fde
= cfun
->fde
;
1171 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1173 if (fde
->dw_fde_vms_begin_epilogue
)
1176 /* Output a label to mark the endpoint of the code generated for this
1178 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1179 current_function_funcdef_no
);
1180 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1181 current_function_funcdef_no
);
1182 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1185 /* Mark the ranges of non-debug subsections in the std text sections. */
1188 mark_ignored_debug_section (dw_fde_ref fde
, bool second
)
1191 const char *begin_label
, *end_label
;
1192 const char **last_end_label
;
1193 vec
<const char *, va_gc
> **switch_ranges
;
1197 std_section
= fde
->second_in_std_section
;
1198 begin_label
= fde
->dw_fde_second_begin
;
1199 end_label
= fde
->dw_fde_second_end
;
1203 std_section
= fde
->in_std_section
;
1204 begin_label
= fde
->dw_fde_begin
;
1205 end_label
= fde
->dw_fde_end
;
1211 if (in_text_section_p
)
1213 last_end_label
= &last_text_label
;
1214 switch_ranges
= &switch_text_ranges
;
1218 last_end_label
= &last_cold_label
;
1219 switch_ranges
= &switch_cold_ranges
;
1222 if (fde
->ignored_debug
)
1224 if (*switch_ranges
&& !(vec_safe_length (*switch_ranges
) & 1))
1225 vec_safe_push (*switch_ranges
, *last_end_label
);
1229 *last_end_label
= end_label
;
1231 if (!*switch_ranges
)
1232 vec_alloc (*switch_ranges
, 16);
1233 else if (vec_safe_length (*switch_ranges
) & 1)
1234 vec_safe_push (*switch_ranges
, begin_label
);
1238 /* Output a marker (i.e. a label) for the absolute end of the generated code
1239 for a function definition. This gets called *after* the epilogue code has
1243 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1244 const char *file ATTRIBUTE_UNUSED
)
1247 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1249 last_var_location_insn
= NULL
;
1250 cached_next_real_insn
= NULL
;
1252 if (dwarf2out_do_cfi_asm ())
1253 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1255 /* Output a label to mark the endpoint of the code generated for this
1257 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1258 current_function_funcdef_no
);
1259 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1261 gcc_assert (fde
!= NULL
);
1262 if (fde
->dw_fde_second_begin
== NULL
)
1263 fde
->dw_fde_end
= xstrdup (label
);
1265 mark_ignored_debug_section (fde
, fde
->dw_fde_second_begin
!= NULL
);
1269 dwarf2out_frame_finish (void)
1271 /* Output call frame information. */
1272 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1273 output_call_frame_info (0);
1275 /* Output another copy for the unwinder. */
1277 output_call_frame_info (1);
1280 static void var_location_switch_text_section (void);
1281 static void set_cur_line_info_table (section
*);
1284 dwarf2out_switch_text_section (void)
1286 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1288 dw_fde_ref fde
= cfun
->fde
;
1290 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1292 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_SECOND_SECT_LABEL
,
1293 current_function_funcdef_no
);
1295 fde
->dw_fde_second_begin
= ggc_strdup (label
);
1296 if (!in_cold_section_p
)
1298 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1299 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1303 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1304 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1306 have_multiple_function_sections
= true;
1308 if (dwarf2out_do_cfi_asm ())
1309 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1311 mark_ignored_debug_section (fde
, false);
1313 /* Now do the real section switch. */
1314 sect
= current_function_section ();
1315 switch_to_section (sect
);
1317 fde
->second_in_std_section
1318 = (sect
== text_section
1319 || (cold_text_section
&& sect
== cold_text_section
));
1320 in_text_section_p
= sect
== text_section
;
1322 if (dwarf2out_do_cfi_asm ())
1323 dwarf2out_do_cfi_startproc (true);
1325 var_location_switch_text_section ();
1327 if (cold_text_section
!= NULL
)
1328 set_cur_line_info_table (sect
);
1331 /* And now, the subset of the debugging information support code necessary
1332 for emitting location expressions. */
1334 /* Describe an entry into the .debug_addr section. */
1338 ate_kind_rtx_dtprel
,
1342 struct GTY((for_user
)) addr_table_entry
{
1344 unsigned int refcount
;
1346 union addr_table_entry_struct_union
1348 rtx
GTY ((tag ("0"))) rtl
;
1349 char * GTY ((tag ("1"))) label
;
1351 GTY ((desc ("%1.kind"))) addr
;
1354 typedef unsigned int var_loc_view
;
1356 /* Location lists are ranges + location descriptions for that range,
1357 so you can track variables that are in different places over
1358 their entire life. */
1359 typedef struct GTY(()) dw_loc_list_struct
{
1360 dw_loc_list_ref dw_loc_next
;
1361 const char *begin
; /* Label and addr_entry for start of range */
1362 addr_table_entry
*begin_entry
;
1363 const char *end
; /* Label for end of range */
1364 addr_table_entry
*end_entry
;
1365 char *ll_symbol
; /* Label for beginning of location list.
1366 Only on head of list. */
1367 char *vl_symbol
; /* Label for beginning of view list. Ditto. */
1368 const char *section
; /* Section this loclist is relative to */
1369 dw_loc_descr_ref expr
;
1370 var_loc_view vbegin
, vend
;
1372 /* True if all addresses in this and subsequent lists are known to be
1375 /* True if this list has been replaced by dw_loc_next. */
1377 /* True if it has been emitted into .debug_loc* / .debug_loclists*
1379 unsigned char emitted
: 1;
1380 /* True if hash field is index rather than hash value. */
1381 unsigned char num_assigned
: 1;
1382 /* True if .debug_loclists.dwo offset has been emitted for it already. */
1383 unsigned char offset_emitted
: 1;
1384 /* True if note_variable_value_in_expr has been called on it. */
1385 unsigned char noted_variable_value
: 1;
1386 /* True if the range should be emitted even if begin and end
1391 static dw_loc_descr_ref
int_loc_descriptor (poly_int64
);
1392 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1394 /* Convert a DWARF stack opcode into its string name. */
1397 dwarf_stack_op_name (unsigned int op
)
1399 const char *name
= get_DW_OP_name (op
);
1404 return "OP_<unknown>";
1407 /* Return TRUE iff we're to output location view lists as a separate
1408 attribute next to the location lists, as an extension compatible
1409 with DWARF 2 and above. */
1412 dwarf2out_locviews_in_attribute ()
1414 return debug_variable_location_views
== 1;
1417 /* Return TRUE iff we're to output location view lists as part of the
1418 location lists, as proposed for standardization after DWARF 5. */
1421 dwarf2out_locviews_in_loclist ()
1423 #ifndef DW_LLE_view_pair
1426 return debug_variable_location_views
== -1;
1430 /* Return a pointer to a newly allocated location description. Location
1431 descriptions are simple expression terms that can be strung
1432 together to form more complicated location (address) descriptions. */
1434 static inline dw_loc_descr_ref
1435 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1436 unsigned HOST_WIDE_INT oprnd2
)
1438 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1440 descr
->dw_loc_opc
= op
;
1441 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1442 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1443 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1444 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1445 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1446 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1451 /* Add a location description term to a location description expression. */
1454 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1456 dw_loc_descr_ref
*d
;
1458 /* Find the end of the chain. */
1459 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1465 /* Compare two location operands for exact equality. */
1468 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1470 if (a
->val_class
!= b
->val_class
)
1472 switch (a
->val_class
)
1474 case dw_val_class_none
:
1476 case dw_val_class_addr
:
1477 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1479 case dw_val_class_offset
:
1480 case dw_val_class_unsigned_const
:
1481 case dw_val_class_const
:
1482 case dw_val_class_unsigned_const_implicit
:
1483 case dw_val_class_const_implicit
:
1484 case dw_val_class_range_list
:
1485 /* These are all HOST_WIDE_INT, signed or unsigned. */
1486 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1488 case dw_val_class_loc
:
1489 return a
->v
.val_loc
== b
->v
.val_loc
;
1490 case dw_val_class_loc_list
:
1491 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1492 case dw_val_class_view_list
:
1493 return a
->v
.val_view_list
== b
->v
.val_view_list
;
1494 case dw_val_class_die_ref
:
1495 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1496 case dw_val_class_fde_ref
:
1497 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1498 case dw_val_class_symview
:
1499 return strcmp (a
->v
.val_symbolic_view
, b
->v
.val_symbolic_view
) == 0;
1500 case dw_val_class_lbl_id
:
1501 case dw_val_class_lineptr
:
1502 case dw_val_class_macptr
:
1503 case dw_val_class_loclistsptr
:
1504 case dw_val_class_high_pc
:
1505 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1506 case dw_val_class_str
:
1507 return a
->v
.val_str
== b
->v
.val_str
;
1508 case dw_val_class_flag
:
1509 return a
->v
.val_flag
== b
->v
.val_flag
;
1510 case dw_val_class_file
:
1511 case dw_val_class_file_implicit
:
1512 return a
->v
.val_file
== b
->v
.val_file
;
1513 case dw_val_class_decl_ref
:
1514 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1516 case dw_val_class_const_double
:
1517 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1518 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1520 case dw_val_class_wide_int
:
1521 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1523 case dw_val_class_vec
:
1525 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1526 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1528 return (a_len
== b_len
1529 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1532 case dw_val_class_data8
:
1533 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1535 case dw_val_class_vms_delta
:
1536 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1537 && !strcmp (a
->v
.val_vms_delta
.lbl2
, b
->v
.val_vms_delta
.lbl2
));
1539 case dw_val_class_discr_value
:
1540 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1541 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1542 case dw_val_class_discr_list
:
1543 /* It makes no sense comparing two discriminant value lists. */
1549 /* Compare two location atoms for exact equality. */
1552 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1554 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1557 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1558 address size, but since we always allocate cleared storage it
1559 should be zero for other types of locations. */
1560 if (a
->dtprel
!= b
->dtprel
)
1563 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1564 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1567 /* Compare two complete location expressions for exact equality. */
1570 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1576 if (a
== NULL
|| b
== NULL
)
1578 if (!loc_descr_equal_p_1 (a
, b
))
1587 /* Add a constant POLY_OFFSET to a location expression. */
1590 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, poly_int64 poly_offset
)
1592 dw_loc_descr_ref loc
;
1595 gcc_assert (*list_head
!= NULL
);
1597 if (known_eq (poly_offset
, 0))
1600 /* Find the end of the chain. */
1601 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1604 HOST_WIDE_INT offset
;
1605 if (!poly_offset
.is_constant (&offset
))
1607 loc
->dw_loc_next
= int_loc_descriptor (poly_offset
);
1608 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_plus
, 0, 0));
1613 if (loc
->dw_loc_opc
== DW_OP_fbreg
1614 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1615 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1616 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1617 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1619 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1620 offset. Don't optimize if an signed integer overflow would happen. */
1622 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1623 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1626 else if (offset
> 0)
1627 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1632 = uint_loc_descriptor (-(unsigned HOST_WIDE_INT
) offset
);
1633 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1637 /* Return a pointer to a newly allocated location description for
1640 static inline dw_loc_descr_ref
1641 new_reg_loc_descr (unsigned int reg
, poly_int64 offset
)
1643 HOST_WIDE_INT const_offset
;
1644 if (offset
.is_constant (&const_offset
))
1647 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1650 return new_loc_descr (DW_OP_bregx
, reg
, const_offset
);
1654 dw_loc_descr_ref ret
= new_reg_loc_descr (reg
, 0);
1655 loc_descr_plus_const (&ret
, offset
);
1660 /* Add a constant OFFSET to a location list. */
1663 loc_list_plus_const (dw_loc_list_ref list_head
, poly_int64 offset
)
1666 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1667 loc_descr_plus_const (&d
->expr
, offset
);
1670 #define DWARF_REF_SIZE \
1671 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : dwarf_offset_size)
1673 /* The number of bits that can be encoded by largest DW_FORM_dataN.
1674 In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
1675 DW_FORM_data16 with 128 bits. */
1676 #define DWARF_LARGEST_DATA_FORM_BITS \
1677 (dwarf_version >= 5 ? 128 : 64)
1679 /* Utility inline function for construction of ops that were GNU extension
1681 static inline enum dwarf_location_atom
1682 dwarf_OP (enum dwarf_location_atom op
)
1686 case DW_OP_implicit_pointer
:
1687 if (dwarf_version
< 5)
1688 return DW_OP_GNU_implicit_pointer
;
1691 case DW_OP_entry_value
:
1692 if (dwarf_version
< 5)
1693 return DW_OP_GNU_entry_value
;
1696 case DW_OP_const_type
:
1697 if (dwarf_version
< 5)
1698 return DW_OP_GNU_const_type
;
1701 case DW_OP_regval_type
:
1702 if (dwarf_version
< 5)
1703 return DW_OP_GNU_regval_type
;
1706 case DW_OP_deref_type
:
1707 if (dwarf_version
< 5)
1708 return DW_OP_GNU_deref_type
;
1712 if (dwarf_version
< 5)
1713 return DW_OP_GNU_convert
;
1716 case DW_OP_reinterpret
:
1717 if (dwarf_version
< 5)
1718 return DW_OP_GNU_reinterpret
;
1722 if (dwarf_version
< 5)
1723 return DW_OP_GNU_addr_index
;
1727 if (dwarf_version
< 5)
1728 return DW_OP_GNU_const_index
;
1737 /* Similarly for attributes. */
1738 static inline enum dwarf_attribute
1739 dwarf_AT (enum dwarf_attribute at
)
1743 case DW_AT_call_return_pc
:
1744 if (dwarf_version
< 5)
1745 return DW_AT_low_pc
;
1748 case DW_AT_call_tail_call
:
1749 if (dwarf_version
< 5)
1750 return DW_AT_GNU_tail_call
;
1753 case DW_AT_call_origin
:
1754 if (dwarf_version
< 5)
1755 return DW_AT_abstract_origin
;
1758 case DW_AT_call_target
:
1759 if (dwarf_version
< 5)
1760 return DW_AT_GNU_call_site_target
;
1763 case DW_AT_call_target_clobbered
:
1764 if (dwarf_version
< 5)
1765 return DW_AT_GNU_call_site_target_clobbered
;
1768 case DW_AT_call_parameter
:
1769 if (dwarf_version
< 5)
1770 return DW_AT_abstract_origin
;
1773 case DW_AT_call_value
:
1774 if (dwarf_version
< 5)
1775 return DW_AT_GNU_call_site_value
;
1778 case DW_AT_call_data_value
:
1779 if (dwarf_version
< 5)
1780 return DW_AT_GNU_call_site_data_value
;
1783 case DW_AT_call_all_calls
:
1784 if (dwarf_version
< 5)
1785 return DW_AT_GNU_all_call_sites
;
1788 case DW_AT_call_all_tail_calls
:
1789 if (dwarf_version
< 5)
1790 return DW_AT_GNU_all_tail_call_sites
;
1793 case DW_AT_dwo_name
:
1794 if (dwarf_version
< 5)
1795 return DW_AT_GNU_dwo_name
;
1798 case DW_AT_addr_base
:
1799 if (dwarf_version
< 5)
1800 return DW_AT_GNU_addr_base
;
1809 /* And similarly for tags. */
1810 static inline enum dwarf_tag
1811 dwarf_TAG (enum dwarf_tag tag
)
1815 case DW_TAG_call_site
:
1816 if (dwarf_version
< 5)
1817 return DW_TAG_GNU_call_site
;
1820 case DW_TAG_call_site_parameter
:
1821 if (dwarf_version
< 5)
1822 return DW_TAG_GNU_call_site_parameter
;
1831 /* And similarly for forms. */
1832 static inline enum dwarf_form
1833 dwarf_FORM (enum dwarf_form form
)
1838 if (dwarf_version
< 5)
1839 return DW_FORM_GNU_addr_index
;
1843 if (dwarf_version
< 5)
1844 return DW_FORM_GNU_str_index
;
1853 static unsigned long int get_base_type_offset (dw_die_ref
);
1855 /* Return the size of a location descriptor. */
1857 static unsigned long
1858 size_of_loc_descr (dw_loc_descr_ref loc
)
1860 unsigned long size
= 1;
1862 switch (loc
->dw_loc_opc
)
1865 size
+= DWARF2_ADDR_SIZE
;
1867 case DW_OP_GNU_addr_index
:
1869 case DW_OP_GNU_const_index
:
1871 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1872 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1891 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1894 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1899 case DW_OP_plus_uconst
:
1900 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1938 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1941 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1944 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1947 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1948 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1951 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1953 case DW_OP_bit_piece
:
1954 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1955 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1957 case DW_OP_deref_size
:
1958 case DW_OP_xderef_size
:
1967 case DW_OP_call_ref
:
1968 case DW_OP_GNU_variable_value
:
1969 size
+= DWARF_REF_SIZE
;
1971 case DW_OP_implicit_value
:
1972 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1973 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1975 case DW_OP_implicit_pointer
:
1976 case DW_OP_GNU_implicit_pointer
:
1977 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1979 case DW_OP_entry_value
:
1980 case DW_OP_GNU_entry_value
:
1982 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1983 size
+= size_of_uleb128 (op_size
) + op_size
;
1986 case DW_OP_const_type
:
1987 case DW_OP_GNU_const_type
:
1990 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1991 size
+= size_of_uleb128 (o
) + 1;
1992 switch (loc
->dw_loc_oprnd2
.val_class
)
1994 case dw_val_class_vec
:
1995 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1996 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1998 case dw_val_class_const
:
1999 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
2001 case dw_val_class_const_double
:
2002 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
2004 case dw_val_class_wide_int
:
2005 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
2006 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
2013 case DW_OP_regval_type
:
2014 case DW_OP_GNU_regval_type
:
2017 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
2018 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
2019 + size_of_uleb128 (o
);
2022 case DW_OP_deref_type
:
2023 case DW_OP_GNU_deref_type
:
2026 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
2027 size
+= 1 + size_of_uleb128 (o
);
2031 case DW_OP_reinterpret
:
2032 case DW_OP_GNU_convert
:
2033 case DW_OP_GNU_reinterpret
:
2034 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2035 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2039 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
2040 size
+= size_of_uleb128 (o
);
2043 case DW_OP_GNU_parameter_ref
:
2053 /* Return the size of a series of location descriptors. */
2056 size_of_locs (dw_loc_descr_ref loc
)
2061 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
2062 field, to avoid writing to a PCH file. */
2063 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
2065 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
2067 size
+= size_of_loc_descr (l
);
2072 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
2074 l
->dw_loc_addr
= size
;
2075 size
+= size_of_loc_descr (l
);
2081 /* Return the size of the value in a DW_AT_discr_value attribute. */
2084 size_of_discr_value (dw_discr_value
*discr_value
)
2086 if (discr_value
->pos
)
2087 return size_of_uleb128 (discr_value
->v
.uval
);
2089 return size_of_sleb128 (discr_value
->v
.sval
);
2092 /* Return the size of the value in a DW_AT_discr_list attribute. */
2095 size_of_discr_list (dw_discr_list_ref discr_list
)
2099 for (dw_discr_list_ref list
= discr_list
;
2101 list
= list
->dw_discr_next
)
2103 /* One byte for the discriminant value descriptor, and then one or two
2104 LEB128 numbers, depending on whether it's a single case label or a
2107 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
2108 if (list
->dw_discr_range
!= 0)
2109 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
2114 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
2115 static void get_ref_die_offset_label (char *, dw_die_ref
);
2116 static unsigned long int get_ref_die_offset (dw_die_ref
);
2118 /* Output location description stack opcode's operands (if any).
2119 The for_eh_or_skip parameter controls whether register numbers are
2120 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2121 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2122 info). This should be suppressed for the cases that have not been converted
2123 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2126 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2128 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2129 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2131 switch (loc
->dw_loc_opc
)
2133 #ifdef DWARF2_DEBUGGING_INFO
2136 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2141 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2142 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
2144 fputc ('\n', asm_out_file
);
2149 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2154 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2155 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
2157 fputc ('\n', asm_out_file
);
2162 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2163 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2170 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2171 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2173 dw2_asm_output_data (2, offset
, NULL
);
2176 case DW_OP_implicit_value
:
2177 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2178 switch (val2
->val_class
)
2180 case dw_val_class_const
:
2181 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2183 case dw_val_class_vec
:
2185 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2186 unsigned int len
= val2
->v
.val_vec
.length
;
2190 if (elt_size
> sizeof (HOST_WIDE_INT
))
2195 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2198 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2199 "fp or vector constant word %u", i
);
2202 case dw_val_class_const_double
:
2204 unsigned HOST_WIDE_INT first
, second
;
2206 if (WORDS_BIG_ENDIAN
)
2208 first
= val2
->v
.val_double
.high
;
2209 second
= val2
->v
.val_double
.low
;
2213 first
= val2
->v
.val_double
.low
;
2214 second
= val2
->v
.val_double
.high
;
2216 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2218 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2222 case dw_val_class_wide_int
:
2225 int len
= get_full_len (*val2
->v
.val_wide
);
2226 if (WORDS_BIG_ENDIAN
)
2227 for (i
= len
- 1; i
>= 0; --i
)
2228 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2229 val2
->v
.val_wide
->elt (i
), NULL
);
2231 for (i
= 0; i
< len
; ++i
)
2232 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2233 val2
->v
.val_wide
->elt (i
), NULL
);
2236 case dw_val_class_addr
:
2237 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2238 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2253 case DW_OP_implicit_value
:
2254 /* We currently don't make any attempt to make sure these are
2255 aligned properly like we do for the main unwind info, so
2256 don't support emitting things larger than a byte if we're
2257 only doing unwinding. */
2262 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2265 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2268 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2271 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2273 case DW_OP_plus_uconst
:
2274 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2308 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2312 unsigned r
= val1
->v
.val_unsigned
;
2313 if (for_eh_or_skip
>= 0)
2314 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2315 gcc_assert (size_of_uleb128 (r
)
2316 == size_of_uleb128 (val1
->v
.val_unsigned
));
2317 dw2_asm_output_data_uleb128 (r
, NULL
);
2321 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2325 unsigned r
= val1
->v
.val_unsigned
;
2326 if (for_eh_or_skip
>= 0)
2327 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2328 gcc_assert (size_of_uleb128 (r
)
2329 == size_of_uleb128 (val1
->v
.val_unsigned
));
2330 dw2_asm_output_data_uleb128 (r
, NULL
);
2331 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2335 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2337 case DW_OP_bit_piece
:
2338 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2339 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2341 case DW_OP_deref_size
:
2342 case DW_OP_xderef_size
:
2343 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2349 if (targetm
.asm_out
.output_dwarf_dtprel
)
2351 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2354 fputc ('\n', asm_out_file
);
2361 #ifdef DWARF2_DEBUGGING_INFO
2362 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2369 case DW_OP_GNU_addr_index
:
2371 case DW_OP_GNU_const_index
:
2373 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2374 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2375 "(index into .debug_addr)");
2381 unsigned long die_offset
2382 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2383 /* Make sure the offset has been computed and that we can encode it as
2385 gcc_assert (die_offset
> 0
2386 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
2389 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2394 case DW_OP_call_ref
:
2395 case DW_OP_GNU_variable_value
:
2397 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2398 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2399 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2400 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2401 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2405 case DW_OP_implicit_pointer
:
2406 case DW_OP_GNU_implicit_pointer
:
2408 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2409 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2410 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2411 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2412 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2413 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2417 case DW_OP_entry_value
:
2418 case DW_OP_GNU_entry_value
:
2419 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2420 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2423 case DW_OP_const_type
:
2424 case DW_OP_GNU_const_type
:
2426 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2428 dw2_asm_output_data_uleb128 (o
, NULL
);
2429 switch (val2
->val_class
)
2431 case dw_val_class_const
:
2432 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2433 dw2_asm_output_data (1, l
, NULL
);
2434 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2436 case dw_val_class_vec
:
2438 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2439 unsigned int len
= val2
->v
.val_vec
.length
;
2444 dw2_asm_output_data (1, l
, NULL
);
2445 if (elt_size
> sizeof (HOST_WIDE_INT
))
2450 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2453 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2454 "fp or vector constant word %u", i
);
2457 case dw_val_class_const_double
:
2459 unsigned HOST_WIDE_INT first
, second
;
2460 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2462 dw2_asm_output_data (1, 2 * l
, NULL
);
2463 if (WORDS_BIG_ENDIAN
)
2465 first
= val2
->v
.val_double
.high
;
2466 second
= val2
->v
.val_double
.low
;
2470 first
= val2
->v
.val_double
.low
;
2471 second
= val2
->v
.val_double
.high
;
2473 dw2_asm_output_data (l
, first
, NULL
);
2474 dw2_asm_output_data (l
, second
, NULL
);
2477 case dw_val_class_wide_int
:
2480 int len
= get_full_len (*val2
->v
.val_wide
);
2481 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2483 dw2_asm_output_data (1, len
* l
, NULL
);
2484 if (WORDS_BIG_ENDIAN
)
2485 for (i
= len
- 1; i
>= 0; --i
)
2486 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2488 for (i
= 0; i
< len
; ++i
)
2489 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2497 case DW_OP_regval_type
:
2498 case DW_OP_GNU_regval_type
:
2500 unsigned r
= val1
->v
.val_unsigned
;
2501 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2503 if (for_eh_or_skip
>= 0)
2505 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2506 gcc_assert (size_of_uleb128 (r
)
2507 == size_of_uleb128 (val1
->v
.val_unsigned
));
2509 dw2_asm_output_data_uleb128 (r
, NULL
);
2510 dw2_asm_output_data_uleb128 (o
, NULL
);
2513 case DW_OP_deref_type
:
2514 case DW_OP_GNU_deref_type
:
2516 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2518 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2519 dw2_asm_output_data_uleb128 (o
, NULL
);
2523 case DW_OP_reinterpret
:
2524 case DW_OP_GNU_convert
:
2525 case DW_OP_GNU_reinterpret
:
2526 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2527 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2530 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2532 dw2_asm_output_data_uleb128 (o
, NULL
);
2536 case DW_OP_GNU_parameter_ref
:
2539 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2540 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2541 dw2_asm_output_data (4, o
, NULL
);
2546 /* Other codes have no operands. */
2551 /* Output a sequence of location operations.
2552 The for_eh_or_skip parameter controls whether register numbers are
2553 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2554 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2555 info). This should be suppressed for the cases that have not been converted
2556 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2559 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2561 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2563 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2564 /* Output the opcode. */
2565 if (for_eh_or_skip
>= 0
2566 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2568 unsigned r
= (opc
- DW_OP_breg0
);
2569 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2570 gcc_assert (r
<= 31);
2571 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2573 else if (for_eh_or_skip
>= 0
2574 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2576 unsigned r
= (opc
- DW_OP_reg0
);
2577 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2578 gcc_assert (r
<= 31);
2579 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2582 dw2_asm_output_data (1, opc
,
2583 "%s", dwarf_stack_op_name (opc
));
2585 /* Output the operand(s) (if any). */
2586 output_loc_operands (loc
, for_eh_or_skip
);
2590 /* Output location description stack opcode's operands (if any).
2591 The output is single bytes on a line, suitable for .cfi_escape. */
2594 output_loc_operands_raw (dw_loc_descr_ref loc
)
2596 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2597 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2599 switch (loc
->dw_loc_opc
)
2602 case DW_OP_GNU_addr_index
:
2604 case DW_OP_GNU_const_index
:
2606 case DW_OP_implicit_value
:
2607 /* We cannot output addresses in .cfi_escape, only bytes. */
2613 case DW_OP_deref_size
:
2614 case DW_OP_xderef_size
:
2615 fputc (',', asm_out_file
);
2616 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2621 fputc (',', asm_out_file
);
2622 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2627 fputc (',', asm_out_file
);
2628 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2633 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2634 fputc (',', asm_out_file
);
2635 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2643 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2644 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2646 fputc (',', asm_out_file
);
2647 dw2_asm_output_data_raw (2, offset
);
2653 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2654 gcc_assert (size_of_uleb128 (r
)
2655 == size_of_uleb128 (val1
->v
.val_unsigned
));
2656 fputc (',', asm_out_file
);
2657 dw2_asm_output_data_uleb128_raw (r
);
2662 case DW_OP_plus_uconst
:
2664 fputc (',', asm_out_file
);
2665 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2668 case DW_OP_bit_piece
:
2669 fputc (',', asm_out_file
);
2670 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2671 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2708 fputc (',', asm_out_file
);
2709 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2714 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2715 gcc_assert (size_of_uleb128 (r
)
2716 == size_of_uleb128 (val1
->v
.val_unsigned
));
2717 fputc (',', asm_out_file
);
2718 dw2_asm_output_data_uleb128_raw (r
);
2719 fputc (',', asm_out_file
);
2720 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2724 case DW_OP_implicit_pointer
:
2725 case DW_OP_entry_value
:
2726 case DW_OP_const_type
:
2727 case DW_OP_regval_type
:
2728 case DW_OP_deref_type
:
2730 case DW_OP_reinterpret
:
2731 case DW_OP_GNU_implicit_pointer
:
2732 case DW_OP_GNU_entry_value
:
2733 case DW_OP_GNU_const_type
:
2734 case DW_OP_GNU_regval_type
:
2735 case DW_OP_GNU_deref_type
:
2736 case DW_OP_GNU_convert
:
2737 case DW_OP_GNU_reinterpret
:
2738 case DW_OP_GNU_parameter_ref
:
2743 /* Other codes have no operands. */
2749 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2753 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2754 /* Output the opcode. */
2755 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2757 unsigned r
= (opc
- DW_OP_breg0
);
2758 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2759 gcc_assert (r
<= 31);
2760 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2762 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2764 unsigned r
= (opc
- DW_OP_reg0
);
2765 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2766 gcc_assert (r
<= 31);
2767 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2769 /* Output the opcode. */
2770 fprintf (asm_out_file
, "%#x", opc
);
2771 output_loc_operands_raw (loc
);
2773 if (!loc
->dw_loc_next
)
2775 loc
= loc
->dw_loc_next
;
2777 fputc (',', asm_out_file
);
2782 build_breg_loc (struct dw_loc_descr_node
**head
, unsigned int regno
)
2785 add_loc_descr (head
, new_loc_descr ((enum dwarf_location_atom
)
2786 (DW_OP_breg0
+ regno
), 0, 0));
2788 add_loc_descr (head
, new_loc_descr (DW_OP_bregx
, regno
, 0));
2791 /* Build a dwarf location for a cfa_reg spanning multiple
2792 consecutive registers. */
2794 struct dw_loc_descr_node
*
2795 build_span_loc (struct cfa_reg reg
)
2797 struct dw_loc_descr_node
*head
= NULL
;
2799 gcc_assert (reg
.span_width
> 0);
2800 gcc_assert (reg
.span
> 1);
2802 /* Start from the highest number register as it goes in the upper bits. */
2803 unsigned int regno
= reg
.reg
+ reg
.span
- 1;
2804 build_breg_loc (&head
, regno
);
2806 /* Deal with the remaining registers in the span. */
2807 for (int i
= reg
.span
- 2; i
>= 0; i
--)
2809 add_loc_descr (&head
, int_loc_descriptor (reg
.span_width
* 8));
2810 add_loc_descr (&head
, new_loc_descr (DW_OP_shl
, 0, 0));
2812 build_breg_loc (&head
, regno
);
2813 add_loc_descr (&head
, new_loc_descr (DW_OP_plus
, 0, 0));
2818 /* This function builds a dwarf location descriptor sequence from a
2819 dw_cfa_location, adding the given OFFSET to the result of the
2822 struct dw_loc_descr_node
*
2823 build_cfa_loc (dw_cfa_location
*cfa
, poly_int64 offset
)
2825 struct dw_loc_descr_node
*head
, *tmp
;
2827 offset
+= cfa
->offset
;
2829 if (cfa
->reg
.span
> 1)
2831 head
= build_span_loc (cfa
->reg
);
2833 if (maybe_ne (offset
, 0))
2834 loc_descr_plus_const (&head
, offset
);
2836 else if (cfa
->indirect
)
2838 head
= new_reg_loc_descr (cfa
->reg
.reg
, cfa
->base_offset
);
2839 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2840 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2841 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2842 add_loc_descr (&head
, tmp
);
2843 loc_descr_plus_const (&head
, offset
);
2846 head
= new_reg_loc_descr (cfa
->reg
.reg
, offset
);
2851 /* This function builds a dwarf location descriptor sequence for
2852 the address at OFFSET from the CFA when stack is aligned to
2855 struct dw_loc_descr_node
*
2856 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2857 poly_int64 offset
, HOST_WIDE_INT alignment
)
2859 struct dw_loc_descr_node
*head
;
2860 unsigned int dwarf_fp
2861 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2863 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2864 if (cfa
->reg
.reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2866 head
= new_reg_loc_descr (dwarf_fp
, 0);
2867 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2868 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2869 loc_descr_plus_const (&head
, offset
);
2872 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2876 /* And now, the support for symbolic debugging information. */
2878 /* .debug_str support. */
2880 static void dwarf2out_init (const char *);
2881 static void dwarf2out_finish (const char *);
2882 static void dwarf2out_early_finish (const char *);
2883 static void dwarf2out_assembly_start (void);
2884 static void dwarf2out_define (unsigned int, const char *);
2885 static void dwarf2out_undef (unsigned int, const char *);
2886 static void dwarf2out_start_source_file (unsigned, const char *);
2887 static void dwarf2out_end_source_file (unsigned);
2888 static void dwarf2out_function_decl (tree
);
2889 static void dwarf2out_begin_block (unsigned, unsigned);
2890 static void dwarf2out_end_block (unsigned, unsigned);
2891 static bool dwarf2out_ignore_block (const_tree
);
2892 static void dwarf2out_set_ignored_loc (unsigned, unsigned, const char *);
2893 static void dwarf2out_early_global_decl (tree
);
2894 static void dwarf2out_late_global_decl (tree
);
2895 static void dwarf2out_type_decl (tree
, int);
2896 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool, bool);
2897 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2899 static void dwarf2out_abstract_function (tree
);
2900 static void dwarf2out_var_location (rtx_insn
*);
2901 static void dwarf2out_inline_entry (tree
);
2902 static void dwarf2out_size_function (tree
);
2903 static void dwarf2out_begin_function (tree
);
2904 static void dwarf2out_end_function (unsigned int);
2905 static void dwarf2out_register_main_translation_unit (tree unit
);
2906 static void dwarf2out_set_name (tree
, tree
);
2907 static void dwarf2out_register_external_die (tree decl
, const char *sym
,
2908 unsigned HOST_WIDE_INT off
);
2909 static bool dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
2910 unsigned HOST_WIDE_INT
*off
);
2912 /* The debug hooks structure. */
2914 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2918 dwarf2out_early_finish
,
2919 dwarf2out_assembly_start
,
2922 dwarf2out_start_source_file
,
2923 dwarf2out_end_source_file
,
2924 dwarf2out_begin_block
,
2925 dwarf2out_end_block
,
2926 dwarf2out_ignore_block
,
2927 dwarf2out_source_line
,
2928 dwarf2out_set_ignored_loc
,
2929 dwarf2out_begin_prologue
,
2930 #if VMS_DEBUGGING_INFO
2931 dwarf2out_vms_end_prologue
,
2932 dwarf2out_vms_begin_epilogue
,
2934 debug_nothing_int_charstar
,
2935 debug_nothing_int_charstar
,
2937 dwarf2out_end_epilogue
,
2938 dwarf2out_begin_function
,
2939 dwarf2out_end_function
, /* end_function */
2940 dwarf2out_register_main_translation_unit
,
2941 dwarf2out_function_decl
, /* function_decl */
2942 dwarf2out_early_global_decl
,
2943 dwarf2out_late_global_decl
,
2944 dwarf2out_type_decl
, /* type_decl */
2945 dwarf2out_imported_module_or_decl
,
2946 dwarf2out_die_ref_for_decl
,
2947 dwarf2out_register_external_die
,
2948 debug_nothing_tree
, /* deferred_inline_function */
2949 /* The DWARF 2 backend tries to reduce debugging bloat by not
2950 emitting the abstract description of inline functions until
2951 something tries to reference them. */
2952 dwarf2out_abstract_function
, /* outlining_inline_function */
2953 debug_nothing_rtx_code_label
, /* label */
2954 debug_nothing_int
, /* handle_pch */
2955 dwarf2out_var_location
,
2956 dwarf2out_inline_entry
, /* inline_entry */
2957 dwarf2out_size_function
, /* size_function */
2958 dwarf2out_switch_text_section
,
2960 1, /* start_end_main_source_file */
2961 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2964 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2967 debug_nothing_charstar
,
2968 debug_nothing_charstar
,
2969 dwarf2out_assembly_start
,
2970 debug_nothing_int_charstar
,
2971 debug_nothing_int_charstar
,
2972 debug_nothing_int_charstar
,
2974 debug_nothing_int_int
, /* begin_block */
2975 debug_nothing_int_int
, /* end_block */
2976 debug_true_const_tree
, /* ignore_block */
2977 dwarf2out_source_line
, /* source_line */
2978 debug_nothing_int_int_charstar
, /* set_ignored_loc */
2979 debug_nothing_int_int_charstar
, /* begin_prologue */
2980 debug_nothing_int_charstar
, /* end_prologue */
2981 debug_nothing_int_charstar
, /* begin_epilogue */
2982 debug_nothing_int_charstar
, /* end_epilogue */
2983 debug_nothing_tree
, /* begin_function */
2984 debug_nothing_int
, /* end_function */
2985 debug_nothing_tree
, /* register_main_translation_unit */
2986 debug_nothing_tree
, /* function_decl */
2987 debug_nothing_tree
, /* early_global_decl */
2988 debug_nothing_tree
, /* late_global_decl */
2989 debug_nothing_tree_int
, /* type_decl */
2990 debug_nothing_tree_tree_tree_bool_bool
,/* imported_module_or_decl */
2991 debug_false_tree_charstarstar_uhwistar
,/* die_ref_for_decl */
2992 debug_nothing_tree_charstar_uhwi
, /* register_external_die */
2993 debug_nothing_tree
, /* deferred_inline_function */
2994 debug_nothing_tree
, /* outlining_inline_function */
2995 debug_nothing_rtx_code_label
, /* label */
2996 debug_nothing_int
, /* handle_pch */
2997 debug_nothing_rtx_insn
, /* var_location */
2998 debug_nothing_tree
, /* inline_entry */
2999 debug_nothing_tree
, /* size_function */
3000 debug_nothing_void
, /* switch_text_section */
3001 debug_nothing_tree_tree
, /* set_name */
3002 0, /* start_end_main_source_file */
3003 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
3006 /* NOTE: In the comments in this file, many references are made to
3007 "Debugging Information Entries". This term is abbreviated as `DIE'
3008 throughout the remainder of this file. */
3010 /* An internal representation of the DWARF output is built, and then
3011 walked to generate the DWARF debugging info. The walk of the internal
3012 representation is done after the entire program has been compiled.
3013 The types below are used to describe the internal representation. */
3015 /* Whether to put type DIEs into their own section .debug_types instead
3016 of making them part of the .debug_info section. Only supported for
3017 Dwarf V4 or higher and the user didn't disable them through
3018 -fno-debug-types-section. It is more efficient to put them in a
3019 separate comdat sections since the linker will then be able to
3020 remove duplicates. But not all tools support .debug_types sections
3021 yet. For Dwarf V5 or higher .debug_types doesn't exist any more,
3022 it is DW_UT_type unit type in .debug_info section. For late LTO
3023 debug there should be almost no types emitted so avoid enabling
3024 -fdebug-types-section there. */
3026 #define use_debug_types (dwarf_version >= 4 \
3027 && flag_debug_types_section \
3030 /* Various DIE's use offsets relative to the beginning of the
3031 .debug_info section to refer to each other. */
3033 typedef long int dw_offset
;
3035 struct comdat_type_node
;
3037 /* The entries in the line_info table more-or-less mirror the opcodes
3038 that are used in the real dwarf line table. Arrays of these entries
3039 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
3042 enum dw_line_info_opcode
{
3043 /* Emit DW_LNE_set_address; the operand is the label index. */
3046 /* Emit a row to the matrix with the given line. This may be done
3047 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
3051 /* Emit a DW_LNS_set_file. */
3054 /* Emit a DW_LNS_set_column. */
3057 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
3060 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
3061 LI_set_prologue_end
,
3062 LI_set_epilogue_begin
,
3064 /* Emit a DW_LNE_set_discriminator. */
3065 LI_set_discriminator
,
3067 /* Output a Fixed Advance PC; the target PC is the label index; the
3068 base PC is the previous LI_adv_address or LI_set_address entry.
3069 We only use this when emitting debug views without assembler
3070 support, at explicit user request. Ideally, we should only use
3071 it when the offset might be zero but we can't tell: it's the only
3072 way to maybe change the PC without resetting the view number. */
3076 typedef struct GTY(()) dw_line_info_struct
{
3077 enum dw_line_info_opcode opcode
;
3079 } dw_line_info_entry
;
3082 struct GTY(()) dw_line_info_table
{
3083 /* The label that marks the end of this section. */
3084 const char *end_label
;
3086 /* The values for the last row of the matrix, as collected in the table.
3087 These are used to minimize the changes to the next row. */
3088 unsigned int file_num
;
3089 unsigned int line_num
;
3090 unsigned int column_num
;
3095 /* This denotes the NEXT view number.
3097 If it is 0, it is known that the NEXT view will be the first view
3100 If it is -1, we're forcing the view number to be reset, e.g. at a
3103 The meaning of other nonzero values depends on whether we're
3104 computing views internally or leaving it for the assembler to do
3105 so. If we're emitting them internally, view denotes the view
3106 number since the last known advance of PC. If we're leaving it
3107 for the assembler, it denotes the LVU label number that we're
3108 going to ask the assembler to assign. */
3111 /* This counts the number of symbolic views emitted in this table
3112 since the latest view reset. Its max value, over all tables,
3113 sets symview_upper_bound. */
3114 var_loc_view symviews_since_reset
;
3116 #define FORCE_RESET_NEXT_VIEW(x) ((x) = (var_loc_view)-1)
3117 #define RESET_NEXT_VIEW(x) ((x) = (var_loc_view)0)
3118 #define FORCE_RESETTING_VIEW_P(x) ((x) == (var_loc_view)-1)
3119 #define RESETTING_VIEW_P(x) ((x) == (var_loc_view)0 || FORCE_RESETTING_VIEW_P (x))
3121 vec
<dw_line_info_entry
, va_gc
> *entries
;
3124 /* This is an upper bound for view numbers that the assembler may
3125 assign to symbolic views output in this translation. It is used to
3126 decide how big a field to use to represent view numbers in
3127 symview-classed attributes. */
3129 static var_loc_view symview_upper_bound
;
3131 /* If we're keep track of location views and their reset points, and
3132 INSN is a reset point (i.e., it necessarily advances the PC), mark
3133 the next view in TABLE as reset. */
3136 maybe_reset_location_view (rtx_insn
*insn
, dw_line_info_table
*table
)
3138 if (!debug_internal_reset_location_views
)
3141 /* Maybe turn (part of?) this test into a default target hook. */
3144 if (targetm
.reset_location_view
)
3145 reset
= targetm
.reset_location_view (insn
);
3149 else if (JUMP_TABLE_DATA_P (insn
))
3151 else if (GET_CODE (insn
) == USE
3152 || GET_CODE (insn
) == CLOBBER
3153 || GET_CODE (insn
) == ASM_INPUT
3154 || asm_noperands (insn
) >= 0)
3156 else if (get_attr_min_length (insn
) > 0)
3159 if (reset
> 0 && !RESETTING_VIEW_P (table
->view
))
3160 RESET_NEXT_VIEW (table
->view
);
3163 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3164 The children of each node form a circular list linked by
3165 die_sib. die_child points to the node *before* the "first" child node. */
3167 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
3168 union die_symbol_or_type_node
3170 const char * GTY ((tag ("0"))) die_symbol
;
3171 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
3173 GTY ((desc ("%0.comdat_type_p"))) die_id
;
3174 vec
<dw_attr_node
, va_gc
> *die_attr
;
3175 dw_die_ref die_parent
;
3176 dw_die_ref die_child
;
3178 dw_die_ref die_definition
; /* ref from a specification to its definition */
3179 dw_offset die_offset
;
3180 unsigned long die_abbrev
;
3182 unsigned int decl_id
;
3183 enum dwarf_tag die_tag
;
3184 /* Die is used and must not be pruned as unused. */
3185 BOOL_BITFIELD die_perennial_p
: 1;
3186 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
3187 /* For an external ref to die_symbol if die_offset contains an extra
3188 offset to that symbol. */
3189 BOOL_BITFIELD with_offset
: 1;
3190 /* Whether this DIE was removed from the DIE tree, for example via
3191 prune_unused_types. We don't consider those present from the
3192 DIE lookup routines. */
3193 BOOL_BITFIELD removed
: 1;
3194 /* Lots of spare bits. */
3198 /* Set to TRUE while dwarf2out_early_global_decl is running. */
3199 static bool early_dwarf
;
3200 static bool early_dwarf_finished
;
3201 class set_early_dwarf
{
3204 set_early_dwarf () : saved(early_dwarf
)
3206 gcc_assert (! early_dwarf_finished
);
3209 ~set_early_dwarf () { early_dwarf
= saved
; }
3212 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3213 #define FOR_EACH_CHILD(die, c, expr) do { \
3214 c = die->die_child; \
3218 } while (c != die->die_child); \
3221 /* The pubname structure */
3223 typedef struct GTY(()) pubname_struct
{
3230 struct GTY(()) dw_ranges
{
3232 /* If this is positive, it's a block number, otherwise it's a
3233 bitwise-negated index into dw_ranges_by_label. */
3235 /* If idx is equal to DW_RANGES_IDX_SKELETON, it should be emitted
3236 into .debug_rnglists section rather than .debug_rnglists.dwo
3237 for -gsplit-dwarf and DWARF >= 5. */
3238 #define DW_RANGES_IDX_SKELETON ((1U << 31) - 1)
3239 /* Index for the range list for DW_FORM_rnglistx. */
3240 unsigned int idx
: 31;
3241 /* True if this range might be possibly in a different section
3242 from previous entry. */
3243 unsigned int maybe_new_sec
: 1;
3244 addr_table_entry
*begin_entry
;
3245 addr_table_entry
*end_entry
;
3248 /* A structure to hold a macinfo entry. */
3250 typedef struct GTY(()) macinfo_struct
{
3252 unsigned HOST_WIDE_INT lineno
;
3258 struct GTY(()) dw_ranges_by_label
{
3263 /* The comdat type node structure. */
3264 struct GTY(()) comdat_type_node
3266 dw_die_ref root_die
;
3267 dw_die_ref type_die
;
3268 dw_die_ref skeleton_die
;
3269 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
3270 comdat_type_node
*next
;
3273 /* A list of DIEs for which we can't determine ancestry (parent_die
3274 field) just yet. Later in dwarf2out_finish we will fill in the
3276 typedef struct GTY(()) limbo_die_struct
{
3278 /* The tree for which this DIE was created. We use this to
3279 determine ancestry later. */
3281 struct limbo_die_struct
*next
;
3285 typedef struct skeleton_chain_struct
3289 struct skeleton_chain_struct
*parent
;
3291 skeleton_chain_node
;
3293 /* Define a macro which returns nonzero for a TYPE_DECL which was
3294 implicitly generated for a type.
3296 Note that, unlike the C front-end (which generates a NULL named
3297 TYPE_DECL node for each complete tagged type, each array type,
3298 and each function type node created) the C++ front-end generates
3299 a _named_ TYPE_DECL node for each tagged type node created.
3300 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3301 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
3302 front-end, but for each type, tagged or not. */
3304 #define TYPE_DECL_IS_STUB(decl) \
3305 (DECL_NAME (decl) == NULL_TREE \
3306 || (DECL_ARTIFICIAL (decl) \
3307 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3308 /* This is necessary for stub decls that \
3309 appear in nested inline functions. */ \
3310 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3311 && (decl_ultimate_origin (decl) \
3312 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3314 /* Information concerning the compilation unit's programming
3315 language, and compiler version. */
3317 /* Fixed size portion of the DWARF compilation unit header. */
3318 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3319 (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size \
3320 + (dwarf_version >= 5 ? 4 : 3))
3322 /* Fixed size portion of the DWARF comdat type unit header. */
3323 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3324 (DWARF_COMPILE_UNIT_HEADER_SIZE \
3325 + DWARF_TYPE_SIGNATURE_SIZE + dwarf_offset_size)
3327 /* Fixed size portion of the DWARF skeleton compilation unit header. */
3328 #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
3329 (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
3331 /* Fixed size portion of public names info. */
3332 #define DWARF_PUBNAMES_HEADER_SIZE (2 * dwarf_offset_size + 2)
3334 /* Fixed size portion of the address range info. */
3335 #define DWARF_ARANGES_HEADER_SIZE \
3336 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4, \
3337 DWARF2_ADDR_SIZE * 2) \
3338 - DWARF_INITIAL_LENGTH_SIZE)
3340 /* Size of padding portion in the address range info. It must be
3341 aligned to twice the pointer size. */
3342 #define DWARF_ARANGES_PAD_SIZE \
3343 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4, \
3344 DWARF2_ADDR_SIZE * 2) \
3345 - (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4))
3347 /* Use assembler line directives if available. */
3348 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3349 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3350 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3352 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3356 /* Use assembler views in line directives if available. */
3357 #ifndef DWARF2_ASM_VIEW_DEBUG_INFO
3358 #ifdef HAVE_AS_DWARF2_DEBUG_VIEW
3359 #define DWARF2_ASM_VIEW_DEBUG_INFO 1
3361 #define DWARF2_ASM_VIEW_DEBUG_INFO 0
3365 /* Return true if GCC configure detected assembler support for .loc. */
3368 dwarf2out_default_as_loc_support (void)
3370 return DWARF2_ASM_LINE_DEBUG_INFO
;
3371 #if (GCC_VERSION >= 3000)
3372 # undef DWARF2_ASM_LINE_DEBUG_INFO
3373 # pragma GCC poison DWARF2_ASM_LINE_DEBUG_INFO
3377 /* Return true if GCC configure detected assembler support for views
3378 in .loc directives. */
3381 dwarf2out_default_as_locview_support (void)
3383 return DWARF2_ASM_VIEW_DEBUG_INFO
;
3384 #if (GCC_VERSION >= 3000)
3385 # undef DWARF2_ASM_VIEW_DEBUG_INFO
3386 # pragma GCC poison DWARF2_ASM_VIEW_DEBUG_INFO
3390 /* A bit is set in ZERO_VIEW_P if we are using the assembler-supported
3391 view computation, and it refers to a view identifier for which we
3392 will not emit a label because it is known to map to a view number
3393 zero. We won't allocate the bitmap if we're not using assembler
3394 support for location views, but we have to make the variable
3395 visible for GGC and for code that will be optimized out for lack of
3396 support but that's still parsed and compiled. We could abstract it
3397 out with macros, but it's not worth it. */
3398 static GTY(()) bitmap zero_view_p
;
3400 /* Evaluate to TRUE iff N is known to identify the first location view
3401 at its PC. When not using assembler location view computation,
3402 that must be view number zero. Otherwise, ZERO_VIEW_P is allocated
3403 and views label numbers recorded in it are the ones known to be
3405 #define ZERO_VIEW_P(N) ((N) == (var_loc_view)0 \
3406 || (N) == (var_loc_view)-1 \
3408 && bitmap_bit_p (zero_view_p, (N))))
3410 /* Return true iff we're to emit .loc directives for the assembler to
3411 generate line number sections.
3413 When we're not emitting views, all we need from the assembler is
3414 support for .loc directives.
3416 If we are emitting views, we can only use the assembler's .loc
3417 support if it also supports views.
3419 When the compiler is emitting the line number programs and
3420 computing view numbers itself, it resets view numbers at known PC
3421 changes and counts from that, and then it emits view numbers as
3422 literal constants in locviewlists. There are cases in which the
3423 compiler is not sure about PC changes, e.g. when extra alignment is
3424 requested for a label. In these cases, the compiler may not reset
3425 the view counter, and the potential PC advance in the line number
3426 program will use an opcode that does not reset the view counter
3427 even if the PC actually changes, so that compiler and debug info
3428 consumer can keep view numbers in sync.
3430 When the compiler defers view computation to the assembler, it
3431 emits symbolic view numbers in locviewlists, with the exception of
3432 views known to be zero (forced resets, or reset after
3433 compiler-visible PC changes): instead of emitting symbols for
3434 these, we emit literal zero and assert the assembler agrees with
3435 the compiler's assessment. We could use symbolic views everywhere,
3436 instead of special-casing zero views, but then we'd be unable to
3437 optimize out locviewlists that contain only zeros. */
3440 output_asm_line_debug_info (void)
3442 return (dwarf2out_as_loc_support
3443 && (dwarf2out_as_locview_support
3444 || !debug_variable_location_views
));
3447 static bool asm_outputs_debug_line_str (void);
3449 /* Minimum line offset in a special line info. opcode.
3450 This value was chosen to give a reasonable range of values. */
3451 #define DWARF_LINE_BASE -10
3453 /* First special line opcode - leave room for the standard opcodes. */
3454 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3456 /* Range of line offsets in a special line info. opcode. */
3457 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3459 /* Flag that indicates the initial value of the is_stmt_start flag.
3460 In the present implementation, we do not mark any lines as
3461 the beginning of a source statement, because that information
3462 is not made available by the GCC front-end. */
3463 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3465 /* Maximum number of operations per instruction bundle. */
3466 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3467 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3470 /* This location is used by calc_die_sizes() to keep track
3471 the offset of each DIE within the .debug_info section. */
3472 static unsigned long next_die_offset
;
3474 /* Record the root of the DIE's built for the current compilation unit. */
3475 static GTY(()) dw_die_ref single_comp_unit_die
;
3477 /* A list of type DIEs that have been separated into comdat sections. */
3478 static GTY(()) comdat_type_node
*comdat_type_list
;
3480 /* A list of CU DIEs that have been separated. */
3481 static GTY(()) limbo_die_node
*cu_die_list
;
3483 /* A list of DIEs with a NULL parent waiting to be relocated. */
3484 static GTY(()) limbo_die_node
*limbo_die_list
;
3486 /* A list of DIEs for which we may have to generate
3487 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3488 static GTY(()) limbo_die_node
*deferred_asm_name
;
3490 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
3492 typedef const char *compare_type
;
3494 static hashval_t
hash (dwarf_file_data
*);
3495 static bool equal (dwarf_file_data
*, const char *);
3498 /* Filenames referenced by this compilation unit. */
3499 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
3501 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
3503 typedef tree compare_type
;
3505 static hashval_t
hash (die_node
*);
3506 static bool equal (die_node
*, tree
);
3508 /* A hash table of references to DIE's that describe declarations.
3509 The key is a DECL_UID() which is a unique number identifying each decl. */
3510 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
3512 struct GTY ((for_user
)) variable_value_struct
{
3513 unsigned int decl_id
;
3514 vec
<dw_die_ref
, va_gc
> *dies
;
3517 struct variable_value_hasher
: ggc_ptr_hash
<variable_value_struct
>
3519 typedef tree compare_type
;
3521 static hashval_t
hash (variable_value_struct
*);
3522 static bool equal (variable_value_struct
*, tree
);
3524 /* A hash table of DIEs that contain DW_OP_GNU_variable_value with
3525 dw_val_class_decl_ref class, indexed by FUNCTION_DECLs which is
3526 DECL_CONTEXT of the referenced VAR_DECLs. */
3527 static GTY (()) hash_table
<variable_value_hasher
> *variable_value_hash
;
3529 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
3531 static hashval_t
hash (die_struct
*);
3532 static bool equal (die_struct
*, die_struct
*);
3535 /* A hash table of references to DIE's that describe COMMON blocks.
3536 The key is DECL_UID() ^ die_parent. */
3537 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
3539 typedef struct GTY(()) die_arg_entry_struct
{
3545 /* Node of the variable location list. */
3546 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3547 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3548 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3549 in mode of the EXPR_LIST node and first EXPR_LIST operand
3550 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3551 location or NULL for padding. For larger bitsizes,
3552 mode is 0 and first operand is a CONCAT with bitsize
3553 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3554 NULL as second operand. */
3556 const char * GTY (()) label
;
3557 struct var_loc_node
* GTY (()) next
;
3561 /* Variable location list. */
3562 struct GTY ((for_user
)) var_loc_list_def
{
3563 struct var_loc_node
* GTY (()) first
;
3565 /* Pointer to the last but one or last element of the
3566 chained list. If the list is empty, both first and
3567 last are NULL, if the list contains just one node
3568 or the last node certainly is not redundant, it points
3569 to the last node, otherwise points to the last but one.
3570 Do not mark it for GC because it is marked through the chain. */
3571 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3573 /* Pointer to the last element before section switch,
3574 if NULL, either sections weren't switched or first
3575 is after section switch. */
3576 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3578 /* DECL_UID of the variable decl. */
3579 unsigned int decl_id
;
3581 typedef struct var_loc_list_def var_loc_list
;
3583 /* Call argument location list. */
3584 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3585 rtx
GTY (()) call_arg_loc_note
;
3586 const char * GTY (()) label
;
3587 tree
GTY (()) block
;
3589 rtx
GTY (()) symbol_ref
;
3590 struct call_arg_loc_node
* GTY (()) next
;
3594 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
3596 typedef const_tree compare_type
;
3598 static hashval_t
hash (var_loc_list
*);
3599 static bool equal (var_loc_list
*, const_tree
);
3602 /* Table of decl location linked lists. */
3603 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
3605 /* Head and tail of call_arg_loc chain. */
3606 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3607 static struct call_arg_loc_node
*call_arg_loc_last
;
3609 /* Number of call sites in the current function. */
3610 static int call_site_count
= -1;
3611 /* Number of tail call sites in the current function. */
3612 static int tail_call_site_count
= -1;
3614 /* A cached location list. */
3615 struct GTY ((for_user
)) cached_dw_loc_list_def
{
3616 /* The DECL_UID of the decl that this entry describes. */
3617 unsigned int decl_id
;
3619 /* The cached location list. */
3620 dw_loc_list_ref loc_list
;
3622 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3624 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3627 typedef const_tree compare_type
;
3629 static hashval_t
hash (cached_dw_loc_list
*);
3630 static bool equal (cached_dw_loc_list
*, const_tree
);
3633 /* Table of cached location lists. */
3634 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3636 /* A vector of references to DIE's that are uniquely identified by their tag,
3637 presence/absence of children DIE's, and list of attribute/value pairs. */
3638 static GTY(()) vec
<dw_die_ref
, va_gc
> *abbrev_die_table
;
3640 /* A hash map to remember the stack usage for DWARF procedures. The value
3641 stored is the stack size difference between before the DWARF procedure
3642 invokation and after it returned. In other words, for a DWARF procedure
3643 that consumes N stack slots and that pushes M ones, this stores M - N. */
3644 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3646 /* A global counter for generating labels for line number data. */
3647 static unsigned int line_info_label_num
;
3649 /* The current table to which we should emit line number information
3650 for the current function. This will be set up at the beginning of
3651 assembly for the function. */
3652 static GTY(()) dw_line_info_table
*cur_line_info_table
;
3654 /* The two default tables of line number info. */
3655 static GTY(()) dw_line_info_table
*text_section_line_info
;
3656 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3658 /* The set of all non-default tables of line number info. */
3659 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3661 /* A flag to tell pubnames/types export if there is an info section to
3663 static bool info_section_emitted
;
3665 /* A pointer to the base of a table that contains a list of publicly
3666 accessible names. */
3667 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3669 /* A pointer to the base of a table that contains a list of publicly
3670 accessible types. */
3671 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3673 /* A pointer to the base of a table that contains a list of macro
3674 defines/undefines (and file start/end markers). */
3675 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3677 /* True if .debug_macinfo or .debug_macros section is going to be
3679 #define have_macinfo \
3680 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3681 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3682 && !macinfo_table->is_empty ())
3684 /* Vector of dies for which we should generate .debug_ranges info. */
3685 static GTY (()) vec
<dw_ranges
, va_gc
> *ranges_table
;
3687 /* Vector of pairs of labels referenced in ranges_table. */
3688 static GTY (()) vec
<dw_ranges_by_label
, va_gc
> *ranges_by_label
;
3690 /* Whether we have location lists that need outputting */
3691 static GTY(()) bool have_location_lists
;
3693 /* Unique label counter. */
3694 static GTY(()) unsigned int loclabel_num
;
3696 /* Unique label counter for point-of-call tables. */
3697 static GTY(()) unsigned int poc_label_num
;
3699 /* The last file entry emitted by maybe_emit_file(). */
3700 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3702 /* Number of internal labels generated by gen_internal_sym(). */
3703 static GTY(()) int label_num
;
3705 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3707 /* Instances of generic types for which we need to generate debug
3708 info that describe their generic parameters and arguments. That
3709 generation needs to happen once all types are properly laid out so
3710 we do it at the end of compilation. */
3711 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3713 /* Offset from the "steady-state frame pointer" to the frame base,
3714 within the current function. */
3715 static poly_int64 frame_pointer_fb_offset
;
3716 static bool frame_pointer_fb_offset_valid
;
3718 static vec
<dw_die_ref
> base_types
;
3720 /* Flags to represent a set of attribute classes for attributes that represent
3721 a scalar value (bounds, pointers, ...). */
3724 dw_scalar_form_constant
= 0x01,
3725 dw_scalar_form_exprloc
= 0x02,
3726 dw_scalar_form_reference
= 0x04
3729 /* Forward declarations for functions defined in this file. */
3731 static bool is_pseudo_reg (const_rtx
);
3732 static tree
type_main_variant (tree
);
3733 static bool is_tagged_type (const_tree
);
3734 static const char *dwarf_tag_name (unsigned);
3735 static const char *dwarf_attr_name (unsigned);
3736 static const char *dwarf_form_name (unsigned);
3737 static tree
decl_ultimate_origin (const_tree
);
3738 static tree
decl_class_context (tree
);
3739 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3740 static inline unsigned int AT_index (dw_attr_node
*);
3741 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3742 static inline unsigned AT_flag (dw_attr_node
*);
3743 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3744 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3745 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3746 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3747 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3748 unsigned int, unsigned char *);
3749 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3750 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3751 static inline const char *AT_string (dw_attr_node
*);
3752 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3753 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3754 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3755 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3756 static inline int AT_ref_external (dw_attr_node
*);
3757 static inline void set_AT_ref_external (dw_attr_node
*, int);
3758 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3759 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3761 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3762 static void add_AT_view_list (dw_die_ref
, enum dwarf_attribute
);
3763 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3764 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3765 static void remove_addr_table_entry (addr_table_entry
*);
3766 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3767 static inline rtx
AT_addr (dw_attr_node
*);
3768 static void add_AT_symview (dw_die_ref
, enum dwarf_attribute
, const char *);
3769 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3770 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3771 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3772 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3773 unsigned long, bool);
3774 static inline const char *AT_lbl (dw_attr_node
*);
3775 static const char *get_AT_low_pc (dw_die_ref
);
3776 static bool is_c (void);
3777 static bool is_cxx (void);
3778 static bool is_cxx (const_tree
);
3779 static bool is_fortran (void);
3780 static bool is_ada (void);
3781 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3782 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3783 static void add_child_die (dw_die_ref
, dw_die_ref
);
3784 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3785 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3786 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3787 static void equate_type_number_to_die (tree
, dw_die_ref
);
3788 static var_loc_list
*lookup_decl_loc (const_tree
);
3789 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3790 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *, var_loc_view
);
3791 static void print_spaces (FILE *);
3792 static void print_die (dw_die_ref
, FILE *);
3793 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3794 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3795 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3796 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3797 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3798 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3799 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3800 struct md5_ctx
*, int *);
3801 struct checksum_attributes
;
3802 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3803 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3804 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3805 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3806 static bool same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3807 static bool same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3808 static bool same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3809 static bool same_die_p (dw_die_ref
, dw_die_ref
, int *);
3810 static bool is_type_die (dw_die_ref
);
3811 static inline bool is_template_instantiation (dw_die_ref
);
3812 static bool is_declaration_die (dw_die_ref
);
3813 static bool should_move_die_to_comdat (dw_die_ref
);
3814 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3815 static dw_die_ref
clone_die (dw_die_ref
);
3816 static dw_die_ref
clone_tree (dw_die_ref
);
3817 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3818 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3819 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3820 static dw_die_ref
generate_skeleton (dw_die_ref
);
3821 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3824 static void break_out_comdat_types (dw_die_ref
);
3825 static void copy_decls_for_unworthy_types (dw_die_ref
);
3827 static void add_sibling_attributes (dw_die_ref
);
3828 static void output_location_lists (dw_die_ref
);
3829 static int constant_size (unsigned HOST_WIDE_INT
);
3830 static unsigned long size_of_die (dw_die_ref
);
3831 static void calc_die_sizes (dw_die_ref
);
3832 static void calc_base_type_die_sizes (void);
3833 static void mark_dies (dw_die_ref
);
3834 static void unmark_dies (dw_die_ref
);
3835 static void unmark_all_dies (dw_die_ref
);
3836 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3837 static unsigned long size_of_aranges (void);
3838 static enum dwarf_form
value_format (dw_attr_node
*);
3839 static void output_value_format (dw_attr_node
*);
3840 static void output_abbrev_section (void);
3841 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3842 static void output_die (dw_die_ref
);
3843 static void output_compilation_unit_header (enum dwarf_unit_type
);
3844 static void output_comp_unit (dw_die_ref
, int, const unsigned char *);
3845 static void output_comdat_type_unit (comdat_type_node
*, bool);
3846 static const char *dwarf2_name (tree
, int);
3847 static void add_pubname (tree
, dw_die_ref
);
3848 static void add_enumerator_pubname (const char *, dw_die_ref
);
3849 static void add_pubname_string (const char *, dw_die_ref
);
3850 static void add_pubtype (tree
, dw_die_ref
);
3851 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3852 static void output_aranges (void);
3853 static unsigned int add_ranges (const_tree
, bool = false);
3854 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3856 static void output_ranges (void);
3857 static dw_line_info_table
*new_line_info_table (void);
3858 static void output_line_info (bool);
3859 static void output_file_names (void);
3860 static bool is_base_type (tree
);
3861 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3862 static int decl_quals (const_tree
);
3863 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3864 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3865 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3866 static unsigned int debugger_reg_number (const_rtx
);
3867 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3868 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3869 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3870 enum var_init_status
);
3871 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3872 enum var_init_status
);
3873 static dw_loc_descr_ref
based_loc_descr (rtx
, poly_int64
,
3874 enum var_init_status
);
3875 static bool is_based_loc (const_rtx
);
3876 static bool resolve_one_addr (rtx
*);
3877 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3878 enum var_init_status
);
3879 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3880 enum var_init_status
);
3881 struct loc_descr_context
;
3882 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3883 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3884 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3885 struct loc_descr_context
*);
3886 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3887 struct loc_descr_context
*);
3888 static tree
field_type (const_tree
);
3889 static unsigned int simple_type_align_in_bits (const_tree
);
3890 static unsigned int simple_decl_align_in_bits (const_tree
);
3891 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3893 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3895 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3897 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3898 struct vlr_context
*);
3899 static bool add_const_value_attribute (dw_die_ref
, machine_mode
, rtx
);
3900 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3901 static void insert_wide_int (const wide_int_ref
&, unsigned char *, int);
3902 static unsigned insert_float (const_rtx
, unsigned char *);
3903 static rtx
rtl_for_decl_location (tree
);
3904 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3905 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3906 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3907 static void add_desc_attribute (dw_die_ref
, tree
);
3908 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3909 static void add_comp_dir_attribute (dw_die_ref
);
3910 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3911 struct loc_descr_context
*);
3912 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3913 struct loc_descr_context
*);
3914 static void add_subscript_info (dw_die_ref
, tree
, bool);
3915 static void add_byte_size_attribute (dw_die_ref
, tree
);
3916 static void add_alignment_attribute (dw_die_ref
, tree
);
3917 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3918 static void add_bit_size_attribute (dw_die_ref
, tree
);
3919 static void add_prototyped_attribute (dw_die_ref
, tree
);
3920 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
3921 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3922 static void add_src_coords_attributes (dw_die_ref
, tree
);
3923 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
, bool = false);
3924 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3925 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3926 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3927 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3928 static inline bool local_scope_p (dw_die_ref
);
3929 static inline bool class_scope_p (dw_die_ref
);
3930 static inline bool class_or_namespace_scope_p (dw_die_ref
);
3931 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3932 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3933 static const char *type_tag (const_tree
);
3934 static tree
member_declared_type (const_tree
);
3936 static const char *decl_start_label (tree
);
3938 static void gen_array_type_die (tree
, dw_die_ref
);
3939 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3941 static void gen_entry_point_die (tree
, dw_die_ref
);
3943 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3944 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3945 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3946 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3947 static void gen_formal_types_die (tree
, dw_die_ref
);
3948 static void gen_subprogram_die (tree
, dw_die_ref
);
3949 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3950 static void gen_const_die (tree
, dw_die_ref
);
3951 static void gen_label_die (tree
, dw_die_ref
);
3952 static void gen_lexical_block_die (tree
, dw_die_ref
);
3953 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3954 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3955 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3956 static dw_die_ref
gen_compile_unit_die (const char *);
3957 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3958 static void gen_member_die (tree
, dw_die_ref
);
3959 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3960 enum debug_info_usage
);
3961 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3962 static void gen_typedef_die (tree
, dw_die_ref
);
3963 static void gen_type_die (tree
, dw_die_ref
);
3964 static void gen_block_die (tree
, dw_die_ref
);
3965 static void decls_for_scope (tree
, dw_die_ref
, bool = true);
3966 static bool is_naming_typedef_decl (const_tree
);
3967 static inline dw_die_ref
get_context_die (tree
);
3968 static void gen_namespace_die (tree
, dw_die_ref
);
3969 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3970 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3971 static dw_die_ref
force_decl_die (tree
);
3972 static dw_die_ref
force_type_die (tree
);
3973 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3974 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3975 static struct dwarf_file_data
* lookup_filename (const char *);
3976 static void retry_incomplete_types (void);
3977 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3978 static void gen_generic_params_dies (tree
);
3979 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3980 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3981 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3982 static int file_info_cmp (const void *, const void *);
3983 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *, var_loc_view
,
3984 const char *, var_loc_view
, const char *);
3985 static void output_loc_list (dw_loc_list_ref
);
3986 static char *gen_internal_sym (const char *);
3987 static bool want_pubnames (void);
3989 static void prune_unmark_dies (dw_die_ref
);
3990 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3991 static void prune_unused_types_mark (dw_die_ref
, int);
3992 static void prune_unused_types_walk (dw_die_ref
);
3993 static void prune_unused_types_walk_attribs (dw_die_ref
);
3994 static void prune_unused_types_prune (dw_die_ref
);
3995 static void prune_unused_types (void);
3996 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3997 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3998 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3999 #if VMS_DEBUGGING_INFO
4000 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
4001 const char *, const char *);
4003 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
4004 static void gen_remaining_tmpl_value_param_die_attribute (void);
4005 static bool generic_type_p (tree
);
4006 static void schedule_generic_params_dies_gen (tree t
);
4007 static void gen_scheduled_generic_parms_dies (void);
4008 static void resolve_variable_values (void);
4010 static const char *comp_dir_string (void);
4012 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
4014 /* enum for tracking thread-local variables whose address is really an offset
4015 relative to the TLS pointer, which will need link-time relocation, but will
4016 not need relocation by the DWARF consumer. */
4024 /* Return the operator to use for an address of a variable. For dtprel_true, we
4025 use DW_OP_const*. For regular variables, which need both link-time
4026 relocation and consumer-level relocation (e.g., to account for shared objects
4027 loaded at a random address), we use DW_OP_addr*. */
4029 static inline enum dwarf_location_atom
4030 dw_addr_op (enum dtprel_bool dtprel
)
4032 if (dtprel
== dtprel_true
)
4033 return (dwarf_split_debug_info
? dwarf_OP (DW_OP_constx
)
4034 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
4036 return dwarf_split_debug_info
? dwarf_OP (DW_OP_addrx
) : DW_OP_addr
;
4039 /* Return a pointer to a newly allocated address location description. If
4040 dwarf_split_debug_info is true, then record the address with the appropriate
4042 static inline dw_loc_descr_ref
4043 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
4045 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
4047 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
4048 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
4049 ref
->dtprel
= dtprel
;
4050 if (dwarf_split_debug_info
)
4051 ref
->dw_loc_oprnd1
.val_entry
4052 = add_addr_table_entry (addr
,
4053 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
4055 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
4060 /* Section names used to hold DWARF debugging information. */
4062 #ifndef DEBUG_INFO_SECTION
4063 #define DEBUG_INFO_SECTION ".debug_info"
4065 #ifndef DEBUG_DWO_INFO_SECTION
4066 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
4068 #ifndef DEBUG_LTO_INFO_SECTION
4069 #define DEBUG_LTO_INFO_SECTION ".gnu.debuglto_.debug_info"
4071 #ifndef DEBUG_LTO_DWO_INFO_SECTION
4072 #define DEBUG_LTO_DWO_INFO_SECTION ".gnu.debuglto_.debug_info.dwo"
4074 #ifndef DEBUG_ABBREV_SECTION
4075 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4077 #ifndef DEBUG_LTO_ABBREV_SECTION
4078 #define DEBUG_LTO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev"
4080 #ifndef DEBUG_DWO_ABBREV_SECTION
4081 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
4083 #ifndef DEBUG_LTO_DWO_ABBREV_SECTION
4084 #define DEBUG_LTO_DWO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev.dwo"
4086 #ifndef DEBUG_ARANGES_SECTION
4087 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4089 #ifndef DEBUG_ADDR_SECTION
4090 #define DEBUG_ADDR_SECTION ".debug_addr"
4092 #ifndef DEBUG_MACINFO_SECTION
4093 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4095 #ifndef DEBUG_LTO_MACINFO_SECTION
4096 #define DEBUG_LTO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo"
4098 #ifndef DEBUG_DWO_MACINFO_SECTION
4099 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
4101 #ifndef DEBUG_LTO_DWO_MACINFO_SECTION
4102 #define DEBUG_LTO_DWO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo.dwo"
4104 #ifndef DEBUG_MACRO_SECTION
4105 #define DEBUG_MACRO_SECTION ".debug_macro"
4107 #ifndef DEBUG_LTO_MACRO_SECTION
4108 #define DEBUG_LTO_MACRO_SECTION ".gnu.debuglto_.debug_macro"
4110 #ifndef DEBUG_DWO_MACRO_SECTION
4111 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
4113 #ifndef DEBUG_LTO_DWO_MACRO_SECTION
4114 #define DEBUG_LTO_DWO_MACRO_SECTION ".gnu.debuglto_.debug_macro.dwo"
4116 #ifndef DEBUG_LINE_SECTION
4117 #define DEBUG_LINE_SECTION ".debug_line"
4119 #ifndef DEBUG_LTO_LINE_SECTION
4120 #define DEBUG_LTO_LINE_SECTION ".gnu.debuglto_.debug_line"
4122 #ifndef DEBUG_DWO_LINE_SECTION
4123 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
4125 #ifndef DEBUG_LTO_DWO_LINE_SECTION
4126 #define DEBUG_LTO_DWO_LINE_SECTION ".gnu.debuglto_.debug_line.dwo"
4128 #ifndef DEBUG_LOC_SECTION
4129 #define DEBUG_LOC_SECTION ".debug_loc"
4131 #ifndef DEBUG_DWO_LOC_SECTION
4132 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
4134 #ifndef DEBUG_LOCLISTS_SECTION
4135 #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
4137 #ifndef DEBUG_DWO_LOCLISTS_SECTION
4138 #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
4140 #ifndef DEBUG_PUBNAMES_SECTION
4141 #define DEBUG_PUBNAMES_SECTION \
4142 ((debug_generate_pub_sections == 2) \
4143 ? ".debug_gnu_pubnames" : ".debug_pubnames")
4145 #ifndef DEBUG_PUBTYPES_SECTION
4146 #define DEBUG_PUBTYPES_SECTION \
4147 ((debug_generate_pub_sections == 2) \
4148 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
4150 #ifndef DEBUG_STR_OFFSETS_SECTION
4151 #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
4153 #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
4154 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
4156 #ifndef DEBUG_LTO_DWO_STR_OFFSETS_SECTION
4157 #define DEBUG_LTO_DWO_STR_OFFSETS_SECTION ".gnu.debuglto_.debug_str_offsets.dwo"
4159 #ifndef DEBUG_STR_SECTION
4160 #define DEBUG_STR_SECTION ".debug_str"
4162 #ifndef DEBUG_LTO_STR_SECTION
4163 #define DEBUG_LTO_STR_SECTION ".gnu.debuglto_.debug_str"
4165 #ifndef DEBUG_STR_DWO_SECTION
4166 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
4168 #ifndef DEBUG_LTO_STR_DWO_SECTION
4169 #define DEBUG_LTO_STR_DWO_SECTION ".gnu.debuglto_.debug_str.dwo"
4171 #ifndef DEBUG_RANGES_SECTION
4172 #define DEBUG_RANGES_SECTION ".debug_ranges"
4174 #ifndef DEBUG_RNGLISTS_SECTION
4175 #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
4177 #ifndef DEBUG_DWO_RNGLISTS_SECTION
4178 #define DEBUG_DWO_RNGLISTS_SECTION ".debug_rnglists.dwo"
4180 #ifndef DEBUG_LINE_STR_SECTION
4181 #define DEBUG_LINE_STR_SECTION ".debug_line_str"
4183 #ifndef DEBUG_LTO_LINE_STR_SECTION
4184 #define DEBUG_LTO_LINE_STR_SECTION ".gnu.debuglto_.debug_line_str"
4187 /* Section flags for .debug_str section. */
4188 #define DEBUG_STR_SECTION_FLAGS \
4189 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4190 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4193 /* Section flags for .debug_str.dwo section. */
4194 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
4196 /* Attribute used to refer to the macro section. */
4197 #define DEBUG_MACRO_ATTRIBUTE (dwarf_version >= 5 ? DW_AT_macros \
4198 : dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros)
4200 /* Labels we insert at beginning sections we can reference instead of
4201 the section names themselves. */
4203 #ifndef TEXT_SECTION_LABEL
4204 #define TEXT_SECTION_LABEL "Ltext"
4206 #ifndef COLD_TEXT_SECTION_LABEL
4207 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4209 #ifndef DEBUG_LINE_SECTION_LABEL
4210 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4212 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
4213 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
4215 #ifndef DEBUG_INFO_SECTION_LABEL
4216 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4218 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
4219 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
4221 #ifndef DEBUG_ABBREV_SECTION_LABEL
4222 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4224 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
4225 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
4227 #ifndef DEBUG_ADDR_SECTION_LABEL
4228 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
4230 #ifndef DEBUG_LOC_SECTION_LABEL
4231 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4233 #ifndef DEBUG_RANGES_SECTION_LABEL
4234 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4236 #ifndef DEBUG_MACINFO_SECTION_LABEL
4237 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4239 #ifndef DEBUG_MACRO_SECTION_LABEL
4240 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
4242 #define SKELETON_COMP_DIE_ABBREV 1
4243 #define SKELETON_TYPE_DIE_ABBREV 2
4245 /* Definitions of defaults for formats and names of various special
4246 (artificial) labels which may be generated within this file (when the -g
4247 options is used and DWARF2_DEBUGGING_INFO is in effect.
4248 If necessary, these may be overridden from within the tm.h file, but
4249 typically, overriding these defaults is unnecessary. */
4251 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4252 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4253 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4254 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4255 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4256 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4257 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4258 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4259 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4260 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4261 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4262 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4263 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4264 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4265 static char ranges_base_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4267 #ifndef TEXT_END_LABEL
4268 #define TEXT_END_LABEL "Letext"
4270 #ifndef COLD_END_LABEL
4271 #define COLD_END_LABEL "Letext_cold"
4273 #ifndef BLOCK_BEGIN_LABEL
4274 #define BLOCK_BEGIN_LABEL "LBB"
4276 #ifndef BLOCK_INLINE_ENTRY_LABEL
4277 #define BLOCK_INLINE_ENTRY_LABEL "LBI"
4279 #ifndef BLOCK_END_LABEL
4280 #define BLOCK_END_LABEL "LBE"
4282 #ifndef LINE_CODE_LABEL
4283 #define LINE_CODE_LABEL "LM"
4287 /* Return the root of the DIE's built for the current compilation unit. */
4289 comp_unit_die (void)
4291 if (!single_comp_unit_die
)
4292 single_comp_unit_die
= gen_compile_unit_die (NULL
);
4293 return single_comp_unit_die
;
4296 /* We allow a language front-end to designate a function that is to be
4297 called to "demangle" any name before it is put into a DIE. */
4299 static const char *(*demangle_name_func
) (const char *);
4302 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
4304 demangle_name_func
= func
;
4307 /* Test if rtl node points to a pseudo register. */
4310 is_pseudo_reg (const_rtx rtl
)
4312 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
4313 || (GET_CODE (rtl
) == SUBREG
4314 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
4317 /* Return a reference to a type, with its const and volatile qualifiers
4321 type_main_variant (tree type
)
4323 type
= TYPE_MAIN_VARIANT (type
);
4325 /* ??? There really should be only one main variant among any group of
4326 variants of a given type (and all of the MAIN_VARIANT values for all
4327 members of the group should point to that one type) but sometimes the C
4328 front-end messes this up for array types, so we work around that bug
4330 if (TREE_CODE (type
) == ARRAY_TYPE
)
4331 while (type
!= TYPE_MAIN_VARIANT (type
))
4332 type
= TYPE_MAIN_VARIANT (type
);
4337 /* Return true if the given type node represents a tagged type. */
4340 is_tagged_type (const_tree type
)
4342 enum tree_code code
= TREE_CODE (type
);
4344 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4345 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4348 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
4351 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
4353 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
4356 /* Return die_offset of a DIE reference to a base type. */
4358 static unsigned long int
4359 get_base_type_offset (dw_die_ref ref
)
4361 if (ref
->die_offset
)
4362 return ref
->die_offset
;
4363 if (comp_unit_die ()->die_abbrev
)
4365 calc_base_type_die_sizes ();
4366 gcc_assert (ref
->die_offset
);
4368 return ref
->die_offset
;
4371 /* Return die_offset of a DIE reference other than base type. */
4373 static unsigned long int
4374 get_ref_die_offset (dw_die_ref ref
)
4376 gcc_assert (ref
->die_offset
);
4377 return ref
->die_offset
;
4380 /* Convert a DIE tag into its string name. */
4383 dwarf_tag_name (unsigned int tag
)
4385 const char *name
= get_DW_TAG_name (tag
);
4390 return "DW_TAG_<unknown>";
4393 /* Convert a DWARF attribute code into its string name. */
4396 dwarf_attr_name (unsigned int attr
)
4402 #if VMS_DEBUGGING_INFO
4403 case DW_AT_HP_prologue
:
4404 return "DW_AT_HP_prologue";
4406 case DW_AT_MIPS_loop_unroll_factor
:
4407 return "DW_AT_MIPS_loop_unroll_factor";
4410 #if VMS_DEBUGGING_INFO
4411 case DW_AT_HP_epilogue
:
4412 return "DW_AT_HP_epilogue";
4414 case DW_AT_MIPS_stride
:
4415 return "DW_AT_MIPS_stride";
4419 name
= get_DW_AT_name (attr
);
4424 return "DW_AT_<unknown>";
4427 /* Convert a DWARF value form code into its string name. */
4430 dwarf_form_name (unsigned int form
)
4432 const char *name
= get_DW_FORM_name (form
);
4437 return "DW_FORM_<unknown>";
4440 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4441 instance of an inlined instance of a decl which is local to an inline
4442 function, so we have to trace all of the way back through the origin chain
4443 to find out what sort of node actually served as the original seed for the
4447 decl_ultimate_origin (const_tree decl
)
4449 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4452 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4453 we're trying to output the abstract instance of this function. */
4454 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4457 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4458 most distant ancestor, this should never happen. */
4459 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4461 return DECL_ABSTRACT_ORIGIN (decl
);
4464 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4465 of a virtual function may refer to a base class, so we check the 'this'
4469 decl_class_context (tree decl
)
4471 tree context
= NULL_TREE
;
4473 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4474 context
= DECL_CONTEXT (decl
);
4476 context
= TYPE_MAIN_VARIANT
4477 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4479 if (context
&& !TYPE_P (context
))
4480 context
= NULL_TREE
;
4485 /* Add an attribute/value pair to a DIE. */
4488 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
4490 /* Maybe this should be an assert? */
4496 /* Check we do not add duplicate attrs. Can't use get_AT here
4497 because that recurses to the specification/abstract origin DIE. */
4500 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4501 gcc_assert (a
->dw_attr
!= attr
->dw_attr
);
4504 vec_safe_reserve (die
->die_attr
, 1);
4505 vec_safe_push (die
->die_attr
, *attr
);
4509 AT_class (dw_attr_node
*a
)
4511 return a
->dw_attr_val
.val_class
;
4514 /* Return the index for any attribute that will be referenced with a
4515 DW_FORM_addrx/GNU_addr_index or DW_FORM_strx/GNU_str_index. String
4516 indices are stored in dw_attr_val.v.val_str for reference counting
4519 static inline unsigned int
4520 AT_index (dw_attr_node
*a
)
4522 if (AT_class (a
) == dw_val_class_str
)
4523 return a
->dw_attr_val
.v
.val_str
->index
;
4524 else if (a
->dw_attr_val
.val_entry
!= NULL
)
4525 return a
->dw_attr_val
.val_entry
->index
;
4529 /* Add a flag value attribute to a DIE. */
4532 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4536 attr
.dw_attr
= attr_kind
;
4537 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4538 attr
.dw_attr_val
.val_entry
= NULL
;
4539 attr
.dw_attr_val
.v
.val_flag
= flag
;
4540 add_dwarf_attr (die
, &attr
);
4543 static inline unsigned
4544 AT_flag (dw_attr_node
*a
)
4546 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4547 return a
->dw_attr_val
.v
.val_flag
;
4550 /* Add a signed integer attribute value to a DIE. */
4553 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4557 attr
.dw_attr
= attr_kind
;
4558 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4559 attr
.dw_attr_val
.val_entry
= NULL
;
4560 attr
.dw_attr_val
.v
.val_int
= int_val
;
4561 add_dwarf_attr (die
, &attr
);
4565 AT_int (dw_attr_node
*a
)
4567 gcc_assert (a
&& (AT_class (a
) == dw_val_class_const
4568 || AT_class (a
) == dw_val_class_const_implicit
));
4569 return a
->dw_attr_val
.v
.val_int
;
4572 /* Add an unsigned integer attribute value to a DIE. */
4575 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4576 unsigned HOST_WIDE_INT unsigned_val
)
4580 attr
.dw_attr
= attr_kind
;
4581 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4582 attr
.dw_attr_val
.val_entry
= NULL
;
4583 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4584 add_dwarf_attr (die
, &attr
);
4587 unsigned HOST_WIDE_INT
4588 AT_unsigned (dw_attr_node
*a
)
4590 gcc_assert (a
&& (AT_class (a
) == dw_val_class_unsigned_const
4591 || AT_class (a
) == dw_val_class_unsigned_const_implicit
));
4592 return a
->dw_attr_val
.v
.val_unsigned
;
4596 alloc_dw_wide_int (const wide_int_ref
&w
)
4599 = (dw_wide_int
*) ggc_internal_alloc (sizeof (dw_wide_int
)
4600 + ((w
.get_len () - 1)
4601 * sizeof (HOST_WIDE_INT
)));
4602 p
->precision
= w
.get_precision ();
4603 p
->len
= w
.get_len ();
4604 memcpy (p
->val
, w
.get_val (), p
->len
* sizeof (HOST_WIDE_INT
));
4608 /* Add an unsigned wide integer attribute value to a DIE. */
4611 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4612 const wide_int_ref
&w
)
4616 attr
.dw_attr
= attr_kind
;
4617 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
4618 attr
.dw_attr_val
.val_entry
= NULL
;
4619 attr
.dw_attr_val
.v
.val_wide
= alloc_dw_wide_int (w
);
4620 add_dwarf_attr (die
, &attr
);
4623 /* Add an unsigned double integer attribute value to a DIE. */
4626 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4627 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4631 attr
.dw_attr
= attr_kind
;
4632 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4633 attr
.dw_attr_val
.val_entry
= NULL
;
4634 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4635 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4636 add_dwarf_attr (die
, &attr
);
4639 /* Add a floating point attribute value to a DIE and return it. */
4642 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4643 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4647 attr
.dw_attr
= attr_kind
;
4648 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4649 attr
.dw_attr_val
.val_entry
= NULL
;
4650 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4651 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4652 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4653 add_dwarf_attr (die
, &attr
);
4656 /* Add an 8-byte data attribute value to a DIE. */
4659 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4660 unsigned char data8
[8])
4664 attr
.dw_attr
= attr_kind
;
4665 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4666 attr
.dw_attr_val
.val_entry
= NULL
;
4667 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4668 add_dwarf_attr (die
, &attr
);
4671 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4672 dwarf_split_debug_info, address attributes in dies destined for the
4673 final executable have force_direct set to avoid using indexed
4677 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4683 lbl_id
= xstrdup (lbl_low
);
4684 attr
.dw_attr
= DW_AT_low_pc
;
4685 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4686 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4687 if (dwarf_split_debug_info
&& !force_direct
)
4688 attr
.dw_attr_val
.val_entry
4689 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4691 attr
.dw_attr_val
.val_entry
= NULL
;
4692 add_dwarf_attr (die
, &attr
);
4694 attr
.dw_attr
= DW_AT_high_pc
;
4695 if (dwarf_version
< 4)
4696 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4698 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4699 lbl_id
= xstrdup (lbl_high
);
4700 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4701 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4702 && dwarf_split_debug_info
&& !force_direct
)
4703 attr
.dw_attr_val
.val_entry
4704 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4706 attr
.dw_attr_val
.val_entry
= NULL
;
4707 add_dwarf_attr (die
, &attr
);
4710 /* Hash and equality functions for debug_str_hash. */
4713 indirect_string_hasher::hash (indirect_string_node
*x
)
4715 return htab_hash_string (x
->str
);
4719 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4721 return strcmp (x1
->str
, x2
) == 0;
4724 /* Add STR to the given string hash table. */
4726 static struct indirect_string_node
*
4727 find_AT_string_in_table (const char *str
,
4728 hash_table
<indirect_string_hasher
> *table
,
4729 enum insert_option insert
= INSERT
)
4731 struct indirect_string_node
*node
;
4733 indirect_string_node
**slot
4734 = table
->find_slot_with_hash (str
, htab_hash_string (str
), insert
);
4737 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4738 node
->str
= ggc_strdup (str
);
4748 /* Add STR to the indirect string hash table. */
4750 static struct indirect_string_node
*
4751 find_AT_string (const char *str
, enum insert_option insert
= INSERT
)
4753 if (! debug_str_hash
)
4754 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4756 return find_AT_string_in_table (str
, debug_str_hash
, insert
);
4759 /* Add a string attribute value to a DIE. */
4762 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4765 struct indirect_string_node
*node
;
4767 node
= find_AT_string (str
);
4769 attr
.dw_attr
= attr_kind
;
4770 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4771 attr
.dw_attr_val
.val_entry
= NULL
;
4772 attr
.dw_attr_val
.v
.val_str
= node
;
4773 add_dwarf_attr (die
, &attr
);
4776 static inline const char *
4777 AT_string (dw_attr_node
*a
)
4779 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4780 return a
->dw_attr_val
.v
.val_str
->str
;
4783 /* Call this function directly to bypass AT_string_form's logic to put
4784 the string inline in the die. */
4787 set_indirect_string (struct indirect_string_node
*node
)
4789 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4790 /* Already indirect is a no op. */
4791 if (node
->form
== DW_FORM_strp
4792 || node
->form
== DW_FORM_line_strp
4793 || node
->form
== dwarf_FORM (DW_FORM_strx
))
4795 gcc_assert (node
->label
);
4798 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4799 ++dw2_string_counter
;
4800 node
->label
= xstrdup (label
);
4802 if (!dwarf_split_debug_info
)
4804 node
->form
= DW_FORM_strp
;
4805 node
->index
= NOT_INDEXED
;
4809 node
->form
= dwarf_FORM (DW_FORM_strx
);
4810 node
->index
= NO_INDEX_ASSIGNED
;
4814 /* A helper function for dwarf2out_finish, called to reset indirect
4815 string decisions done for early LTO dwarf output before fat object
4819 reset_indirect_string (indirect_string_node
**h
, void *)
4821 struct indirect_string_node
*node
= *h
;
4822 if (node
->form
== DW_FORM_strp
4823 || node
->form
== DW_FORM_line_strp
4824 || node
->form
== dwarf_FORM (DW_FORM_strx
))
4828 node
->form
= (dwarf_form
) 0;
4834 /* Add a string representing a file or filepath attribute value to a DIE. */
4837 add_filepath_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4840 if (! asm_outputs_debug_line_str ())
4841 add_AT_string (die
, attr_kind
, str
);
4845 struct indirect_string_node
*node
;
4847 if (!debug_line_str_hash
)
4849 = hash_table
<indirect_string_hasher
>::create_ggc (10);
4851 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
4852 set_indirect_string (node
);
4853 node
->form
= DW_FORM_line_strp
;
4855 attr
.dw_attr
= attr_kind
;
4856 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4857 attr
.dw_attr_val
.val_entry
= NULL
;
4858 attr
.dw_attr_val
.v
.val_str
= node
;
4859 add_dwarf_attr (die
, &attr
);
4863 /* Find out whether a string should be output inline in DIE
4864 or out-of-line in .debug_str section. */
4866 static enum dwarf_form
4867 find_string_form (struct indirect_string_node
*node
)
4874 len
= strlen (node
->str
) + 1;
4876 /* If the string is shorter or equal to the size of the reference, it is
4877 always better to put it inline. */
4878 if (len
<= (unsigned) dwarf_offset_size
|| node
->refcount
== 0)
4879 return node
->form
= DW_FORM_string
;
4881 /* If we cannot expect the linker to merge strings in .debug_str
4882 section, only put it into .debug_str if it is worth even in this
4884 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4885 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4886 && (len
- dwarf_offset_size
) * node
->refcount
<= len
))
4887 return node
->form
= DW_FORM_string
;
4889 set_indirect_string (node
);
4894 /* Find out whether the string referenced from the attribute should be
4895 output inline in DIE or out-of-line in .debug_str section. */
4897 static enum dwarf_form
4898 AT_string_form (dw_attr_node
*a
)
4900 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4901 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4904 /* Add a DIE reference attribute value to a DIE. */
4907 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4910 gcc_checking_assert (targ_die
!= NULL
);
4911 gcc_assert (targ_die
!= die
4912 || (attr_kind
!= DW_AT_abstract_origin
4913 && attr_kind
!= DW_AT_specification
));
4915 /* With LTO we can end up trying to reference something we didn't create
4916 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4917 if (targ_die
== NULL
)
4920 attr
.dw_attr
= attr_kind
;
4921 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4922 attr
.dw_attr_val
.val_entry
= NULL
;
4923 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4924 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4925 add_dwarf_attr (die
, &attr
);
4928 /* Change DIE reference REF to point to NEW_DIE instead. */
4931 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4933 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4934 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4935 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4938 /* Add an AT_specification attribute to a DIE, and also make the back
4939 pointer from the specification to the definition. */
4942 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4944 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4945 gcc_assert (!targ_die
->die_definition
);
4946 targ_die
->die_definition
= die
;
4949 static inline dw_die_ref
4950 AT_ref (dw_attr_node
*a
)
4952 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4953 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4957 AT_ref_external (dw_attr_node
*a
)
4959 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4960 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4966 set_AT_ref_external (dw_attr_node
*a
, int i
)
4968 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4969 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4972 /* Add a location description attribute value to a DIE. */
4975 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4979 attr
.dw_attr
= attr_kind
;
4980 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4981 attr
.dw_attr_val
.val_entry
= NULL
;
4982 attr
.dw_attr_val
.v
.val_loc
= loc
;
4983 add_dwarf_attr (die
, &attr
);
4987 AT_loc (dw_attr_node
*a
)
4989 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4990 return a
->dw_attr_val
.v
.val_loc
;
4994 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4998 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
5001 attr
.dw_attr
= attr_kind
;
5002 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
5003 attr
.dw_attr_val
.val_entry
= NULL
;
5004 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
5005 add_dwarf_attr (die
, &attr
);
5006 have_location_lists
= true;
5009 static inline dw_loc_list_ref
5010 AT_loc_list (dw_attr_node
*a
)
5012 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
5013 return a
->dw_attr_val
.v
.val_loc_list
;
5016 /* Add a view list attribute to DIE. It must have a DW_AT_location
5017 attribute, because the view list complements the location list. */
5020 add_AT_view_list (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5024 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
5027 attr
.dw_attr
= attr_kind
;
5028 attr
.dw_attr_val
.val_class
= dw_val_class_view_list
;
5029 attr
.dw_attr_val
.val_entry
= NULL
;
5030 attr
.dw_attr_val
.v
.val_view_list
= die
;
5031 add_dwarf_attr (die
, &attr
);
5032 gcc_checking_assert (get_AT (die
, DW_AT_location
));
5033 gcc_assert (have_location_lists
);
5036 /* Return a pointer to the location list referenced by the attribute.
5037 If the named attribute is a view list, look up the corresponding
5038 DW_AT_location attribute and return its location list. */
5040 static inline dw_loc_list_ref
*
5041 AT_loc_list_ptr (dw_attr_node
*a
)
5044 switch (AT_class (a
))
5046 case dw_val_class_loc_list
:
5047 return &a
->dw_attr_val
.v
.val_loc_list
;
5048 case dw_val_class_view_list
:
5051 l
= get_AT (a
->dw_attr_val
.v
.val_view_list
, DW_AT_location
);
5054 gcc_checking_assert (l
+ 1 == a
);
5055 return AT_loc_list_ptr (l
);
5062 /* Return the location attribute value associated with a view list
5065 static inline dw_val_node
*
5066 view_list_to_loc_list_val_node (dw_val_node
*val
)
5068 gcc_assert (val
->val_class
== dw_val_class_view_list
);
5069 dw_attr_node
*loc
= get_AT (val
->v
.val_view_list
, DW_AT_location
);
5072 gcc_checking_assert (&(loc
+ 1)->dw_attr_val
== val
);
5073 gcc_assert (AT_class (loc
) == dw_val_class_loc_list
);
5074 return &loc
->dw_attr_val
;
5077 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
5079 static hashval_t
hash (addr_table_entry
*);
5080 static bool equal (addr_table_entry
*, addr_table_entry
*);
5083 /* Table of entries into the .debug_addr section. */
5085 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
5087 /* Hash an address_table_entry. */
5090 addr_hasher::hash (addr_table_entry
*a
)
5092 inchash::hash hstate
;
5098 case ate_kind_rtx_dtprel
:
5101 case ate_kind_label
:
5102 return htab_hash_string (a
->addr
.label
);
5106 inchash::add_rtx (a
->addr
.rtl
, hstate
);
5107 return hstate
.end ();
5110 /* Determine equality for two address_table_entries. */
5113 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
5115 if (a1
->kind
!= a2
->kind
)
5120 case ate_kind_rtx_dtprel
:
5121 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
5122 case ate_kind_label
:
5123 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
5129 /* Initialize an addr_table_entry. */
5132 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
5138 case ate_kind_rtx_dtprel
:
5139 e
->addr
.rtl
= (rtx
) addr
;
5141 case ate_kind_label
:
5142 e
->addr
.label
= (char *) addr
;
5146 e
->index
= NO_INDEX_ASSIGNED
;
5149 /* Add attr to the address table entry to the table. Defer setting an
5150 index until output time. */
5152 static addr_table_entry
*
5153 add_addr_table_entry (void *addr
, enum ate_kind kind
)
5155 addr_table_entry
*node
;
5156 addr_table_entry finder
;
5158 gcc_assert (dwarf_split_debug_info
);
5159 if (! addr_index_table
)
5160 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
5161 init_addr_table_entry (&finder
, kind
, addr
);
5162 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
5164 if (*slot
== HTAB_EMPTY_ENTRY
)
5166 node
= ggc_cleared_alloc
<addr_table_entry
> ();
5167 init_addr_table_entry (node
, kind
, addr
);
5177 /* Remove an entry from the addr table by decrementing its refcount.
5178 Strictly, decrementing the refcount would be enough, but the
5179 assertion that the entry is actually in the table has found
5183 remove_addr_table_entry (addr_table_entry
*entry
)
5185 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
5186 /* After an index is assigned, the table is frozen. */
5187 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
5191 /* Given a location list, remove all addresses it refers to from the
5195 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
5197 for (; descr
; descr
= descr
->dw_loc_next
)
5198 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
5200 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
5201 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
5205 /* A helper function for dwarf2out_finish called through
5206 htab_traverse. Assign an addr_table_entry its index. All entries
5207 must be collected into the table when this function is called,
5208 because the indexing code relies on htab_traverse to traverse nodes
5209 in the same order for each run. */
5212 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
5214 addr_table_entry
*node
= *h
;
5216 /* Don't index unreferenced nodes. */
5217 if (node
->refcount
== 0)
5220 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
5221 node
->index
= *index
;
5227 /* Return the tag of a given DIE. */
5230 dw_get_die_tag (dw_die_ref die
)
5232 return die
->die_tag
;
5235 /* Return a reference to the children list of a given DIE. */
5238 dw_get_die_child (dw_die_ref die
)
5240 return die
->die_child
;
5243 /* Return a reference to the sibling of a given DIE. */
5246 dw_get_die_sib (dw_die_ref die
)
5248 return die
->die_sib
;
5251 /* Add an address constant attribute value to a DIE. When using
5252 dwarf_split_debug_info, address attributes in dies destined for the
5253 final executable should be direct references--setting the parameter
5254 force_direct ensures this behavior. */
5257 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
5262 attr
.dw_attr
= attr_kind
;
5263 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
5264 attr
.dw_attr_val
.v
.val_addr
= addr
;
5265 if (dwarf_split_debug_info
&& !force_direct
)
5266 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
5268 attr
.dw_attr_val
.val_entry
= NULL
;
5269 add_dwarf_attr (die
, &attr
);
5272 /* Get the RTX from to an address DIE attribute. */
5275 AT_addr (dw_attr_node
*a
)
5277 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
5278 return a
->dw_attr_val
.v
.val_addr
;
5281 /* Add a file attribute value to a DIE. */
5284 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5285 struct dwarf_file_data
*fd
)
5289 attr
.dw_attr
= attr_kind
;
5290 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
5291 attr
.dw_attr_val
.val_entry
= NULL
;
5292 attr
.dw_attr_val
.v
.val_file
= fd
;
5293 add_dwarf_attr (die
, &attr
);
5296 /* Get the dwarf_file_data from a file DIE attribute. */
5298 static inline struct dwarf_file_data
*
5299 AT_file (dw_attr_node
*a
)
5301 gcc_assert (a
&& (AT_class (a
) == dw_val_class_file
5302 || AT_class (a
) == dw_val_class_file_implicit
));
5303 return a
->dw_attr_val
.v
.val_file
;
5306 #if VMS_DEBUGGING_INFO
5307 /* Add a vms delta attribute value to a DIE. */
5310 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5311 const char *lbl1
, const char *lbl2
)
5315 attr
.dw_attr
= attr_kind
;
5316 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
5317 attr
.dw_attr_val
.val_entry
= NULL
;
5318 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
5319 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
5320 add_dwarf_attr (die
, &attr
);
5324 /* Add a symbolic view identifier attribute value to a DIE. */
5327 add_AT_symview (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5328 const char *view_label
)
5332 attr
.dw_attr
= attr_kind
;
5333 attr
.dw_attr_val
.val_class
= dw_val_class_symview
;
5334 attr
.dw_attr_val
.val_entry
= NULL
;
5335 attr
.dw_attr_val
.v
.val_symbolic_view
= xstrdup (view_label
);
5336 add_dwarf_attr (die
, &attr
);
5339 /* Add a label identifier attribute value to a DIE. */
5342 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5347 attr
.dw_attr
= attr_kind
;
5348 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
5349 attr
.dw_attr_val
.val_entry
= NULL
;
5350 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
5351 if (dwarf_split_debug_info
)
5352 attr
.dw_attr_val
.val_entry
5353 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
5355 add_dwarf_attr (die
, &attr
);
5358 /* Add a section offset attribute value to a DIE, an offset into the
5359 debug_line section. */
5362 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5367 attr
.dw_attr
= attr_kind
;
5368 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
5369 attr
.dw_attr_val
.val_entry
= NULL
;
5370 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5371 add_dwarf_attr (die
, &attr
);
5374 /* Add a section offset attribute value to a DIE, an offset into the
5375 debug_macinfo section. */
5378 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5383 attr
.dw_attr
= attr_kind
;
5384 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
5385 attr
.dw_attr_val
.val_entry
= NULL
;
5386 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5387 add_dwarf_attr (die
, &attr
);
5390 /* Add a range_list attribute value to a DIE. When using
5391 dwarf_split_debug_info, address attributes in dies destined for the
5392 final executable should be direct references--setting the parameter
5393 force_direct ensures this behavior. */
5395 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
5396 #define RELOCATED_OFFSET (NULL)
5399 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5400 long unsigned int offset
, bool force_direct
)
5404 attr
.dw_attr
= attr_kind
;
5405 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
5406 /* For the range_list attribute, use val_entry to store whether the
5407 offset should follow split-debug-info or normal semantics. This
5408 value is read in output_range_list_offset. */
5409 if (dwarf_split_debug_info
&& !force_direct
)
5410 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
5412 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
5413 attr
.dw_attr_val
.v
.val_offset
= offset
;
5414 add_dwarf_attr (die
, &attr
);
5417 /* Return the start label of a delta attribute. */
5419 static inline const char *
5420 AT_vms_delta1 (dw_attr_node
*a
)
5422 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
5423 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
5426 /* Return the end label of a delta attribute. */
5428 static inline const char *
5429 AT_vms_delta2 (dw_attr_node
*a
)
5431 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
5432 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
5435 static inline const char *
5436 AT_lbl (dw_attr_node
*a
)
5438 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
5439 || AT_class (a
) == dw_val_class_lineptr
5440 || AT_class (a
) == dw_val_class_macptr
5441 || AT_class (a
) == dw_val_class_loclistsptr
5442 || AT_class (a
) == dw_val_class_high_pc
));
5443 return a
->dw_attr_val
.v
.val_lbl_id
;
5446 /* Get the attribute of type attr_kind. */
5449 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5453 dw_die_ref spec
= NULL
;
5458 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5459 if (a
->dw_attr
== attr_kind
)
5461 else if (a
->dw_attr
== DW_AT_specification
5462 || a
->dw_attr
== DW_AT_abstract_origin
)
5466 return get_AT (spec
, attr_kind
);
5471 /* Returns the parent of the declaration of DIE. */
5474 get_die_parent (dw_die_ref die
)
5481 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
5482 || (t
= get_AT_ref (die
, DW_AT_specification
)))
5485 return die
->die_parent
;
5488 /* Return the "low pc" attribute value, typically associated with a subprogram
5489 DIE. Return null if the "low pc" attribute is either not present, or if it
5490 cannot be represented as an assembler label identifier. */
5492 static inline const char *
5493 get_AT_low_pc (dw_die_ref die
)
5495 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
5497 return a
? AT_lbl (a
) : NULL
;
5500 /* Return the value of the string attribute designated by ATTR_KIND, or
5501 NULL if it is not present. */
5504 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5506 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5508 return a
? AT_string (a
) : NULL
;
5511 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5512 if it is not present. */
5515 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5517 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5519 return a
? AT_flag (a
) : 0;
5522 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5523 if it is not present. */
5526 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5528 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5530 return a
? AT_unsigned (a
) : 0;
5534 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5536 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5538 return a
? AT_ref (a
) : NULL
;
5541 struct dwarf_file_data
*
5542 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5544 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5546 return a
? AT_file (a
) : NULL
;
5549 /* Return TRUE if the language is C. */
5554 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5556 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
|| lang
== DW_LANG_C99
5557 || lang
== DW_LANG_C11
|| lang
== DW_LANG_ObjC
);
5562 /* Return TRUE if the language is C++. */
5567 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5569 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
5570 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
5573 /* Return TRUE if DECL was created by the C++ frontend. */
5576 is_cxx (const_tree decl
)
5580 const_tree context
= get_ultimate_context (decl
);
5581 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5582 return startswith (TRANSLATION_UNIT_LANGUAGE (context
), "GNU C++");
5587 /* Return TRUE if the language is Fortran. */
5592 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5594 return (lang
== DW_LANG_Fortran77
5595 || lang
== DW_LANG_Fortran90
5596 || lang
== DW_LANG_Fortran95
5597 || lang
== DW_LANG_Fortran03
5598 || lang
== DW_LANG_Fortran08
);
5602 is_fortran (const_tree decl
)
5606 const_tree context
= get_ultimate_context (decl
);
5607 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5608 return (strncmp (TRANSLATION_UNIT_LANGUAGE (context
),
5609 "GNU Fortran", 11) == 0
5610 || strcmp (TRANSLATION_UNIT_LANGUAGE (context
),
5613 return is_fortran ();
5616 /* Return TRUE if the language is Rust.
5617 Note, returns FALSE for dwarf_version < 5 && dwarf_strict. */
5622 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5624 return lang
== DW_LANG_Rust
;
5627 /* Return TRUE if the language is Ada. */
5632 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5634 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5637 /* Return TRUE if the language is D. */
5642 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5644 return lang
== DW_LANG_D
;
5647 /* Remove the specified attribute if present. Return TRUE if removal
5651 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5659 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5660 if (a
->dw_attr
== attr_kind
)
5662 if (AT_class (a
) == dw_val_class_str
)
5663 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5664 a
->dw_attr_val
.v
.val_str
->refcount
--;
5666 /* vec::ordered_remove should help reduce the number of abbrevs
5668 die
->die_attr
->ordered_remove (ix
);
5674 /* Remove CHILD from its parent. PREV must have the property that
5675 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5678 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5680 gcc_assert (child
->die_parent
== prev
->die_parent
);
5681 gcc_assert (prev
->die_sib
== child
);
5684 gcc_assert (child
->die_parent
->die_child
== child
);
5688 prev
->die_sib
= child
->die_sib
;
5689 if (child
->die_parent
->die_child
== child
)
5690 child
->die_parent
->die_child
= prev
;
5691 child
->die_sib
= NULL
;
5694 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5695 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5698 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
5700 dw_die_ref parent
= old_child
->die_parent
;
5702 gcc_assert (parent
== prev
->die_parent
);
5703 gcc_assert (prev
->die_sib
== old_child
);
5705 new_child
->die_parent
= parent
;
5706 if (prev
== old_child
)
5708 gcc_assert (parent
->die_child
== old_child
);
5709 new_child
->die_sib
= new_child
;
5713 prev
->die_sib
= new_child
;
5714 new_child
->die_sib
= old_child
->die_sib
;
5716 if (old_child
->die_parent
->die_child
== old_child
)
5717 old_child
->die_parent
->die_child
= new_child
;
5718 old_child
->die_sib
= NULL
;
5721 /* Move all children from OLD_PARENT to NEW_PARENT. */
5724 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
5727 new_parent
->die_child
= old_parent
->die_child
;
5728 old_parent
->die_child
= NULL
;
5729 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
5732 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5736 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5742 dw_die_ref prev
= c
;
5744 while (c
->die_tag
== tag
)
5746 remove_child_with_prev (c
, prev
);
5747 c
->die_parent
= NULL
;
5748 /* Might have removed every child. */
5749 if (die
->die_child
== NULL
)
5753 } while (c
!= die
->die_child
);
5756 /* Add a CHILD_DIE as the last child of DIE. */
5759 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5761 /* FIXME this should probably be an assert. */
5762 if (! die
|| ! child_die
)
5764 gcc_assert (die
!= child_die
);
5766 child_die
->die_parent
= die
;
5769 child_die
->die_sib
= die
->die_child
->die_sib
;
5770 die
->die_child
->die_sib
= child_die
;
5773 child_die
->die_sib
= child_die
;
5774 die
->die_child
= child_die
;
5777 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5780 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
5781 dw_die_ref after_die
)
5787 && die
!= child_die
);
5789 child_die
->die_parent
= die
;
5790 child_die
->die_sib
= after_die
->die_sib
;
5791 after_die
->die_sib
= child_die
;
5792 if (die
->die_child
== after_die
)
5793 die
->die_child
= child_die
;
5796 /* Unassociate CHILD from its parent, and make its parent be
5800 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
5802 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5803 if (p
->die_sib
== child
)
5805 remove_child_with_prev (child
, p
);
5808 add_child_die (new_parent
, child
);
5811 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5812 is the specification, to the end of PARENT's list of children.
5813 This is done by removing and re-adding it. */
5816 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5818 /* We want the declaration DIE from inside the class, not the
5819 specification DIE at toplevel. */
5820 if (child
->die_parent
!= parent
)
5822 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5828 gcc_assert (child
->die_parent
== parent
5829 || (child
->die_parent
5830 == get_AT_ref (parent
, DW_AT_specification
)));
5832 reparent_child (child
, parent
);
5835 /* Create and return a new die with TAG_VALUE as tag. */
5838 new_die_raw (enum dwarf_tag tag_value
)
5840 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5841 die
->die_tag
= tag_value
;
5845 /* Create and return a new die with a parent of PARENT_DIE. If
5846 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5847 associated tree T must be supplied to determine parenthood
5850 static inline dw_die_ref
5851 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5853 dw_die_ref die
= new_die_raw (tag_value
);
5855 if (parent_die
!= NULL
)
5856 add_child_die (parent_die
, die
);
5859 limbo_die_node
*limbo_node
;
5861 /* No DIEs created after early dwarf should end up in limbo,
5862 because the limbo list should not persist past LTO
5864 if (tag_value
!= DW_TAG_compile_unit
5865 /* These are allowed because they're generated while
5866 breaking out COMDAT units late. */
5867 && tag_value
!= DW_TAG_type_unit
5868 && tag_value
!= DW_TAG_skeleton_unit
5870 /* Allow nested functions to live in limbo because they will
5871 only temporarily live there, as decls_for_scope will fix
5873 && (TREE_CODE (t
) != FUNCTION_DECL
5874 || !decl_function_context (t
))
5875 /* Same as nested functions above but for types. Types that
5876 are local to a function will be fixed in
5878 && (!RECORD_OR_UNION_TYPE_P (t
)
5879 || !TYPE_CONTEXT (t
)
5880 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5881 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5882 especially in the ltrans stage, but once we implement LTO
5883 dwarf streaming, we should remove this exception. */
5886 fprintf (stderr
, "symbol ended up in limbo too late:");
5887 debug_generic_stmt (t
);
5891 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5892 limbo_node
->die
= die
;
5893 limbo_node
->created_for
= t
;
5894 limbo_node
->next
= limbo_die_list
;
5895 limbo_die_list
= limbo_node
;
5901 /* Return the DIE associated with the given type specifier. */
5904 lookup_type_die (tree type
)
5906 dw_die_ref die
= TYPE_SYMTAB_DIE (type
);
5907 if (die
&& die
->removed
)
5909 TYPE_SYMTAB_DIE (type
) = NULL
;
5910 TREE_ASM_WRITTEN (type
) = 0;
5916 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5917 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5918 anonymous type instead the one of the naming typedef. */
5920 static inline dw_die_ref
5921 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5924 && TREE_CODE (type
) == RECORD_TYPE
5926 && type_die
->die_tag
== DW_TAG_typedef
5927 && is_naming_typedef_decl (TYPE_NAME (type
)))
5928 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5932 /* Like lookup_type_die, but if type is an anonymous type named by a
5933 typedef[1], return the DIE of the anonymous type instead the one of
5934 the naming typedef. This is because in gen_typedef_die, we did
5935 equate the anonymous struct named by the typedef with the DIE of
5936 the naming typedef. So by default, lookup_type_die on an anonymous
5937 struct yields the DIE of the naming typedef.
5939 [1]: Read the comment of is_naming_typedef_decl to learn about what
5940 a naming typedef is. */
5942 static inline dw_die_ref
5943 lookup_type_die_strip_naming_typedef (tree type
)
5945 dw_die_ref die
= lookup_type_die (type
);
5946 return strip_naming_typedef (type
, die
);
5949 /* Equate a DIE to a given type specifier. */
5952 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5954 TYPE_SYMTAB_DIE (type
) = type_die
;
5957 static dw_die_ref
maybe_create_die_with_external_ref (tree
);
5958 struct GTY(()) sym_off_pair
5960 const char * GTY((skip
)) sym
;
5961 unsigned HOST_WIDE_INT off
;
5963 static GTY(()) hash_map
<tree
, sym_off_pair
> *external_die_map
;
5965 /* Returns a hash value for X (which really is a die_struct). */
5968 decl_die_hasher::hash (die_node
*x
)
5970 return (hashval_t
) x
->decl_id
;
5973 /* Return true if decl_id of die_struct X is the same as UID of decl *Y. */
5976 decl_die_hasher::equal (die_node
*x
, tree y
)
5978 return (x
->decl_id
== DECL_UID (y
));
5981 /* Return the DIE associated with a given declaration. */
5984 lookup_decl_die (tree decl
)
5986 dw_die_ref
*die
= decl_die_table
->find_slot_with_hash (decl
, DECL_UID (decl
),
5991 return maybe_create_die_with_external_ref (decl
);
5994 if ((*die
)->removed
)
5996 decl_die_table
->clear_slot (die
);
6003 /* Return the DIE associated with BLOCK. */
6005 static inline dw_die_ref
6006 lookup_block_die (tree block
)
6008 dw_die_ref die
= BLOCK_DIE (block
);
6009 if (!die
&& in_lto_p
)
6010 return maybe_create_die_with_external_ref (block
);
6014 /* Associate DIE with BLOCK. */
6017 equate_block_to_die (tree block
, dw_die_ref die
)
6019 BLOCK_DIE (block
) = die
;
6024 /* For DECL which might have early dwarf output query a SYMBOL + OFFSET
6025 style reference. Return true if we found one refering to a DIE for
6026 DECL, otherwise return false. */
6029 dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
6030 unsigned HOST_WIDE_INT
*off
)
6036 /* During WPA stage and incremental linking we use a hash-map
6037 to store the decl <-> label + offset map. */
6038 if (!external_die_map
)
6040 sym_off_pair
*desc
= external_die_map
->get (decl
);
6048 if (TREE_CODE (decl
) == BLOCK
)
6049 die
= lookup_block_die (decl
);
6051 die
= lookup_decl_die (decl
);
6055 /* Similar to get_ref_die_offset_label, but using the "correct"
6057 *off
= die
->die_offset
;
6058 while (die
->die_parent
)
6059 die
= die
->die_parent
;
6060 /* For the containing CU DIE we compute a die_symbol in
6061 compute_comp_unit_symbol. */
6062 gcc_assert (die
->die_tag
== DW_TAG_compile_unit
6063 && die
->die_id
.die_symbol
!= NULL
);
6064 *sym
= die
->die_id
.die_symbol
;
6068 /* Add a reference of kind ATTR_KIND to a DIE at SYMBOL + OFFSET to DIE. */
6071 add_AT_external_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6072 const char *symbol
, HOST_WIDE_INT offset
)
6074 /* Create a fake DIE that contains the reference. Don't use
6075 new_die because we don't want to end up in the limbo list. */
6076 /* ??? We probably want to share these, thus put a ref to the DIE
6077 we create here to the external_die_map entry. */
6078 dw_die_ref ref
= new_die_raw (die
->die_tag
);
6079 ref
->die_id
.die_symbol
= symbol
;
6080 ref
->die_offset
= offset
;
6081 ref
->with_offset
= 1;
6082 add_AT_die_ref (die
, attr_kind
, ref
);
6085 /* Create a DIE for DECL if required and add a reference to a DIE
6086 at SYMBOL + OFFSET which contains attributes dumped early. */
6089 dwarf2out_register_external_die (tree decl
, const char *sym
,
6090 unsigned HOST_WIDE_INT off
)
6092 if (debug_info_level
== DINFO_LEVEL_NONE
)
6095 if (!external_die_map
)
6096 external_die_map
= hash_map
<tree
, sym_off_pair
>::create_ggc (1000);
6097 gcc_checking_assert (!external_die_map
->get (decl
));
6098 sym_off_pair p
= { IDENTIFIER_POINTER (get_identifier (sym
)), off
};
6099 external_die_map
->put (decl
, p
);
6102 /* If we have a registered external DIE for DECL return a new DIE for
6103 the concrete instance with an appropriate abstract origin. */
6106 maybe_create_die_with_external_ref (tree decl
)
6108 if (!external_die_map
)
6110 sym_off_pair
*desc
= external_die_map
->get (decl
);
6114 const char *sym
= desc
->sym
;
6115 unsigned HOST_WIDE_INT off
= desc
->off
;
6116 external_die_map
->remove (decl
);
6119 dw_die_ref die
= (TREE_CODE (decl
) == BLOCK
6120 ? lookup_block_die (decl
) : lookup_decl_die (decl
));
6125 dw_die_ref parent
= NULL
;
6126 /* Need to lookup a DIE for the decls context - the containing
6127 function or translation unit. */
6128 if (TREE_CODE (decl
) == BLOCK
)
6130 ctx
= BLOCK_SUPERCONTEXT (decl
);
6131 /* ??? We do not output DIEs for all scopes thus skip as
6132 many DIEs as needed. */
6133 while (TREE_CODE (ctx
) == BLOCK
6134 && !lookup_block_die (ctx
))
6135 ctx
= BLOCK_SUPERCONTEXT (ctx
);
6138 ctx
= DECL_CONTEXT (decl
);
6139 /* Peel types in the context stack. */
6140 while (ctx
&& TYPE_P (ctx
))
6141 ctx
= TYPE_CONTEXT (ctx
);
6142 /* Likewise namespaces in case we do not want to emit DIEs for them. */
6143 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
6144 while (ctx
&& TREE_CODE (ctx
) == NAMESPACE_DECL
)
6145 ctx
= DECL_CONTEXT (ctx
);
6148 if (TREE_CODE (ctx
) == BLOCK
)
6149 parent
= lookup_block_die (ctx
);
6150 else if (TREE_CODE (ctx
) == TRANSLATION_UNIT_DECL
6151 /* Keep the 1:1 association during WPA. */
6153 && flag_incremental_link
!= INCREMENTAL_LINK_LTO
)
6154 /* Otherwise all late annotations go to the main CU which
6155 imports the original CUs. */
6156 parent
= comp_unit_die ();
6157 else if (TREE_CODE (ctx
) == FUNCTION_DECL
6158 && TREE_CODE (decl
) != FUNCTION_DECL
6159 && TREE_CODE (decl
) != PARM_DECL
6160 && TREE_CODE (decl
) != RESULT_DECL
6161 && TREE_CODE (decl
) != BLOCK
)
6162 /* Leave function local entities parent determination to when
6163 we process scope vars. */
6166 parent
= lookup_decl_die (ctx
);
6169 /* In some cases the FEs fail to set DECL_CONTEXT properly.
6170 Handle this case gracefully by globalizing stuff. */
6171 parent
= comp_unit_die ();
6172 /* Create a DIE "stub". */
6173 switch (TREE_CODE (decl
))
6175 case TRANSLATION_UNIT_DECL
:
6177 die
= comp_unit_die ();
6178 /* We re-target all CU decls to the LTRANS CU DIE, so no need
6179 to create a DIE for the original CUs. */
6182 case NAMESPACE_DECL
:
6183 if (is_fortran (decl
))
6184 die
= new_die (DW_TAG_module
, parent
, decl
);
6186 die
= new_die (DW_TAG_namespace
, parent
, decl
);
6189 die
= new_die (DW_TAG_subprogram
, parent
, decl
);
6192 die
= new_die (DW_TAG_variable
, parent
, decl
);
6195 die
= new_die (DW_TAG_variable
, parent
, decl
);
6198 die
= new_die (DW_TAG_formal_parameter
, parent
, decl
);
6201 die
= new_die (DW_TAG_constant
, parent
, decl
);
6204 die
= new_die (DW_TAG_label
, parent
, decl
);
6207 die
= new_die (DW_TAG_lexical_block
, parent
, decl
);
6212 if (TREE_CODE (decl
) == BLOCK
)
6213 equate_block_to_die (decl
, die
);
6215 equate_decl_number_to_die (decl
, die
);
6217 add_desc_attribute (die
, decl
);
6219 /* Add a reference to the DIE providing early debug at $sym + off. */
6220 add_AT_external_die_ref (die
, DW_AT_abstract_origin
, sym
, off
);
6225 /* Returns a hash value for X (which really is a var_loc_list). */
6228 decl_loc_hasher::hash (var_loc_list
*x
)
6230 return (hashval_t
) x
->decl_id
;
6233 /* Return true if decl_id of var_loc_list X is the same as
6237 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
6239 return (x
->decl_id
== DECL_UID (y
));
6242 /* Return the var_loc list associated with a given declaration. */
6244 static inline var_loc_list
*
6245 lookup_decl_loc (const_tree decl
)
6247 if (!decl_loc_table
)
6249 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
6252 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
6255 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
6257 return (hashval_t
) x
->decl_id
;
6260 /* Return true if decl_id of cached_dw_loc_list X is the same as
6264 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
6266 return (x
->decl_id
== DECL_UID (y
));
6269 /* Equate a DIE to a particular declaration. */
6272 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
6274 unsigned int decl_id
= DECL_UID (decl
);
6276 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
6277 decl_die
->decl_id
= decl_id
;
6280 /* Return how many bits covers PIECE EXPR_LIST. */
6282 static HOST_WIDE_INT
6283 decl_piece_bitsize (rtx piece
)
6285 int ret
= (int) GET_MODE (piece
);
6288 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
6289 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
6290 return INTVAL (XEXP (XEXP (piece
, 0), 0));
6293 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
6296 decl_piece_varloc_ptr (rtx piece
)
6298 if ((int) GET_MODE (piece
))
6299 return &XEXP (piece
, 0);
6301 return &XEXP (XEXP (piece
, 0), 1);
6304 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
6305 Next is the chain of following piece nodes. */
6307 static rtx_expr_list
*
6308 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
6310 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
6311 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
6313 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
6318 /* Return rtx that should be stored into loc field for
6319 LOC_NOTE and BITPOS/BITSIZE. */
6322 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
6323 HOST_WIDE_INT bitsize
)
6327 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
6329 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
6334 /* This function either modifies location piece list *DEST in
6335 place (if SRC and INNER is NULL), or copies location piece list
6336 *SRC to *DEST while modifying it. Location BITPOS is modified
6337 to contain LOC_NOTE, any pieces overlapping it are removed resp.
6338 not copied and if needed some padding around it is added.
6339 When modifying in place, DEST should point to EXPR_LIST where
6340 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
6341 to the start of the whole list and INNER points to the EXPR_LIST
6342 where earlier pieces cover PIECE_BITPOS bits. */
6345 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
6346 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
6347 HOST_WIDE_INT bitsize
, rtx loc_note
)
6350 bool copy
= inner
!= NULL
;
6354 /* First copy all nodes preceding the current bitpos. */
6355 while (src
!= inner
)
6357 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
6358 decl_piece_bitsize (*src
), NULL_RTX
);
6359 dest
= &XEXP (*dest
, 1);
6360 src
= &XEXP (*src
, 1);
6363 /* Add padding if needed. */
6364 if (bitpos
!= piece_bitpos
)
6366 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
6367 copy
? NULL_RTX
: *dest
);
6368 dest
= &XEXP (*dest
, 1);
6370 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
6373 /* A piece with correct bitpos and bitsize already exist,
6374 just update the location for it and return. */
6375 *decl_piece_varloc_ptr (*dest
) = loc_note
;
6378 /* Add the piece that changed. */
6379 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
6380 dest
= &XEXP (*dest
, 1);
6381 /* Skip over pieces that overlap it. */
6382 diff
= bitpos
- piece_bitpos
+ bitsize
;
6385 while (diff
> 0 && *src
)
6388 diff
-= decl_piece_bitsize (piece
);
6390 src
= &XEXP (piece
, 1);
6393 *src
= XEXP (piece
, 1);
6394 free_EXPR_LIST_node (piece
);
6397 /* Add padding if needed. */
6398 if (diff
< 0 && *src
)
6402 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
6403 dest
= &XEXP (*dest
, 1);
6407 /* Finally copy all nodes following it. */
6410 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
6411 decl_piece_bitsize (*src
), NULL_RTX
);
6412 dest
= &XEXP (*dest
, 1);
6413 src
= &XEXP (*src
, 1);
6417 /* Add a variable location node to the linked list for DECL. */
6419 static struct var_loc_node
*
6420 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
, var_loc_view view
)
6422 unsigned int decl_id
;
6424 struct var_loc_node
*loc
= NULL
;
6425 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
6427 if (VAR_P (decl
) && DECL_HAS_DEBUG_EXPR_P (decl
))
6429 tree realdecl
= DECL_DEBUG_EXPR (decl
);
6430 if (handled_component_p (realdecl
)
6431 || (TREE_CODE (realdecl
) == MEM_REF
6432 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
6435 tree innerdecl
= get_ref_base_and_extent_hwi (realdecl
, &bitpos
,
6436 &bitsize
, &reverse
);
6438 || !DECL_P (innerdecl
)
6439 || DECL_IGNORED_P (innerdecl
)
6440 || TREE_STATIC (innerdecl
)
6442 || bitpos
+ bitsize
> 256)
6448 decl_id
= DECL_UID (decl
);
6450 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
6453 temp
= ggc_cleared_alloc
<var_loc_list
> ();
6454 temp
->decl_id
= decl_id
;
6460 /* For PARM_DECLs try to keep around the original incoming value,
6461 even if that means we'll emit a zero-range .debug_loc entry. */
6463 && temp
->first
== temp
->last
6464 && TREE_CODE (decl
) == PARM_DECL
6465 && NOTE_P (temp
->first
->loc
)
6466 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
6467 && DECL_INCOMING_RTL (decl
)
6468 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
6469 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
6470 == GET_CODE (DECL_INCOMING_RTL (decl
))
6471 && prev_real_insn (as_a
<rtx_insn
*> (temp
->first
->loc
)) == NULL_RTX
6473 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
6474 NOTE_VAR_LOCATION_LOC (loc_note
))
6475 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
6476 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
6478 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6479 temp
->first
->next
= loc
;
6481 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6483 else if (temp
->last
)
6485 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
6486 rtx
*piece_loc
= NULL
, last_loc_note
;
6487 HOST_WIDE_INT piece_bitpos
= 0;
6491 gcc_assert (last
->next
== NULL
);
6493 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
6495 piece_loc
= &last
->loc
;
6498 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
6499 if (piece_bitpos
+ cur_bitsize
> bitpos
)
6501 piece_bitpos
+= cur_bitsize
;
6502 piece_loc
= &XEXP (*piece_loc
, 1);
6506 /* TEMP->LAST here is either pointer to the last but one or
6507 last element in the chained list, LAST is pointer to the
6509 if (label
&& strcmp (last
->label
, label
) == 0 && last
->view
== view
)
6511 /* For SRA optimized variables if there weren't any real
6512 insns since last note, just modify the last node. */
6513 if (piece_loc
!= NULL
)
6515 adjust_piece_list (piece_loc
, NULL
, NULL
,
6516 bitpos
, piece_bitpos
, bitsize
, loc_note
);
6519 /* If the last note doesn't cover any instructions, remove it. */
6520 if (temp
->last
!= last
)
6522 temp
->last
->next
= NULL
;
6525 gcc_assert (strcmp (last
->label
, label
) != 0 || last
->view
!= view
);
6529 gcc_assert (temp
->first
== temp
->last
6530 || (temp
->first
->next
== temp
->last
6531 && TREE_CODE (decl
) == PARM_DECL
));
6532 memset (temp
->last
, '\0', sizeof (*temp
->last
));
6533 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6537 if (bitsize
== -1 && NOTE_P (last
->loc
))
6538 last_loc_note
= last
->loc
;
6539 else if (piece_loc
!= NULL
6540 && *piece_loc
!= NULL_RTX
6541 && piece_bitpos
== bitpos
6542 && decl_piece_bitsize (*piece_loc
) == bitsize
)
6543 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
6545 last_loc_note
= NULL_RTX
;
6546 /* If the current location is the same as the end of the list,
6547 and either both or neither of the locations is uninitialized,
6548 we have nothing to do. */
6549 if (last_loc_note
== NULL_RTX
6550 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
6551 NOTE_VAR_LOCATION_LOC (loc_note
)))
6552 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6553 != NOTE_VAR_LOCATION_STATUS (loc_note
))
6554 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6555 == VAR_INIT_STATUS_UNINITIALIZED
)
6556 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
6557 == VAR_INIT_STATUS_UNINITIALIZED
))))
6559 /* Add LOC to the end of list and update LAST. If the last
6560 element of the list has been removed above, reuse its
6561 memory for the new node, otherwise allocate a new one. */
6565 memset (loc
, '\0', sizeof (*loc
));
6568 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6569 if (bitsize
== -1 || piece_loc
== NULL
)
6570 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6572 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
6573 bitpos
, piece_bitpos
, bitsize
, loc_note
);
6575 /* Ensure TEMP->LAST will point either to the new last but one
6576 element of the chain, or to the last element in it. */
6577 if (last
!= temp
->last
)
6585 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6588 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6593 /* Keep track of the number of spaces used to indent the
6594 output of the debugging routines that print the structure of
6595 the DIE internal representation. */
6596 static int print_indent
;
6598 /* Indent the line the number of spaces given by print_indent. */
6601 print_spaces (FILE *outfile
)
6603 fprintf (outfile
, "%*s", print_indent
, "");
6606 /* Print a type signature in hex. */
6609 print_signature (FILE *outfile
, char *sig
)
6613 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
6614 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
6618 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
6620 if (discr_value
->pos
)
6621 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
6623 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
6626 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
6628 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
6629 RECURSE, output location descriptor operations. */
6632 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
6634 switch (val
->val_class
)
6636 case dw_val_class_addr
:
6637 fprintf (outfile
, "address");
6639 case dw_val_class_offset
:
6640 fprintf (outfile
, "offset");
6642 case dw_val_class_loc
:
6643 fprintf (outfile
, "location descriptor");
6644 if (val
->v
.val_loc
== NULL
)
6645 fprintf (outfile
, " -> <null>\n");
6648 fprintf (outfile
, ":\n");
6650 print_loc_descr (val
->v
.val_loc
, outfile
);
6655 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
6656 fprintf (outfile
, " #\n");
6658 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
6661 case dw_val_class_loc_list
:
6662 fprintf (outfile
, "location list -> label:%s",
6663 val
->v
.val_loc_list
->ll_symbol
);
6665 case dw_val_class_view_list
:
6666 val
= view_list_to_loc_list_val_node (val
);
6667 fprintf (outfile
, "location list with views -> labels:%s and %s",
6668 val
->v
.val_loc_list
->ll_symbol
,
6669 val
->v
.val_loc_list
->vl_symbol
);
6671 case dw_val_class_range_list
:
6672 fprintf (outfile
, "range list");
6674 case dw_val_class_const
:
6675 case dw_val_class_const_implicit
:
6676 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
6678 case dw_val_class_unsigned_const
:
6679 case dw_val_class_unsigned_const_implicit
:
6680 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
6682 case dw_val_class_const_double
:
6683 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
6684 HOST_WIDE_INT_PRINT_UNSIGNED
")",
6685 val
->v
.val_double
.high
,
6686 val
->v
.val_double
.low
);
6688 case dw_val_class_wide_int
:
6690 int i
= val
->v
.val_wide
->get_len ();
6691 fprintf (outfile
, "constant (");
6693 if (val
->v
.val_wide
->elt (i
- 1) == 0)
6694 fprintf (outfile
, "0x");
6695 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
6696 val
->v
.val_wide
->elt (--i
));
6698 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
6699 val
->v
.val_wide
->elt (i
));
6700 fprintf (outfile
, ")");
6703 case dw_val_class_vec
:
6704 fprintf (outfile
, "floating-point or vector constant");
6706 case dw_val_class_flag
:
6707 fprintf (outfile
, "%u", val
->v
.val_flag
);
6709 case dw_val_class_die_ref
:
6710 if (val
->v
.val_die_ref
.die
!= NULL
)
6712 dw_die_ref die
= val
->v
.val_die_ref
.die
;
6714 if (die
->comdat_type_p
)
6716 fprintf (outfile
, "die -> signature: ");
6717 print_signature (outfile
,
6718 die
->die_id
.die_type_node
->signature
);
6720 else if (die
->die_id
.die_symbol
)
6722 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
6723 if (die
->with_offset
)
6724 fprintf (outfile
, " + %ld", die
->die_offset
);
6727 fprintf (outfile
, "die -> %ld", die
->die_offset
);
6728 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
6729 fprintf (outfile
, " #");
6731 fprintf (outfile
, " (%p)", (void *) die
);
6734 fprintf (outfile
, "die -> <null>");
6736 case dw_val_class_vms_delta
:
6737 fprintf (outfile
, "delta: @slotcount(%s-%s)",
6738 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
6740 case dw_val_class_symview
:
6741 fprintf (outfile
, "view: %s", val
->v
.val_symbolic_view
);
6743 case dw_val_class_lbl_id
:
6744 case dw_val_class_lineptr
:
6745 case dw_val_class_macptr
:
6746 case dw_val_class_loclistsptr
:
6747 case dw_val_class_high_pc
:
6748 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
6750 case dw_val_class_str
:
6751 if (val
->v
.val_str
->str
!= NULL
)
6752 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
6754 fprintf (outfile
, "<null>");
6756 case dw_val_class_file
:
6757 case dw_val_class_file_implicit
:
6758 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
6759 val
->v
.val_file
->emitted_number
);
6761 case dw_val_class_data8
:
6765 for (i
= 0; i
< 8; i
++)
6766 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
6769 case dw_val_class_discr_value
:
6770 print_discr_value (outfile
, &val
->v
.val_discr_value
);
6772 case dw_val_class_discr_list
:
6773 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
6775 node
= node
->dw_discr_next
)
6777 if (node
->dw_discr_range
)
6779 fprintf (outfile
, " .. ");
6780 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6781 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
6784 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6786 if (node
->dw_discr_next
!= NULL
)
6787 fprintf (outfile
, " | ");
6794 /* Likewise, for a DIE attribute. */
6797 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
6799 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
6803 /* Print the list of operands in the LOC location description to OUTFILE. This
6804 routine is a debugging aid only. */
6807 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
6809 dw_loc_descr_ref l
= loc
;
6813 print_spaces (outfile
);
6814 fprintf (outfile
, "<null>\n");
6818 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
6820 print_spaces (outfile
);
6821 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
6822 fprintf (outfile
, "#");
6824 fprintf (outfile
, "(%p)", (void *) l
);
6825 fprintf (outfile
, " %s",
6826 dwarf_stack_op_name (l
->dw_loc_opc
));
6827 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
6829 fprintf (outfile
, " ");
6830 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
6832 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
6834 fprintf (outfile
, ", ");
6835 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
6837 fprintf (outfile
, "\n");
6841 /* Print the information associated with a given DIE, and its children.
6842 This routine is a debugging aid only. */
6845 print_die (dw_die_ref die
, FILE *outfile
)
6851 print_spaces (outfile
);
6852 fprintf (outfile
, "DIE %4ld: %s ",
6853 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6854 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
6855 fprintf (outfile
, "#\n");
6857 fprintf (outfile
, "(%p)\n", (void*) die
);
6858 print_spaces (outfile
);
6859 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
6860 fprintf (outfile
, " offset: %ld", die
->die_offset
);
6861 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
6863 if (die
->comdat_type_p
)
6865 print_spaces (outfile
);
6866 fprintf (outfile
, " signature: ");
6867 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
6868 fprintf (outfile
, "\n");
6871 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6873 print_spaces (outfile
);
6874 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6876 print_attribute (a
, true, outfile
);
6877 fprintf (outfile
, "\n");
6880 if (die
->die_child
!= NULL
)
6883 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6886 if (print_indent
== 0)
6887 fprintf (outfile
, "\n");
6890 /* Print the list of operations in the LOC location description. */
6893 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
6895 print_loc_descr (loc
, stderr
);
6898 /* Print the information collected for a given DIE. */
6901 debug_dwarf_die (dw_die_ref die
)
6903 print_die (die
, stderr
);
6907 debug (die_struct
&ref
)
6909 print_die (&ref
, stderr
);
6913 debug (die_struct
*ptr
)
6918 fprintf (stderr
, "<nil>\n");
6922 /* Print all DWARF information collected for the compilation unit.
6923 This routine is a debugging aid only. */
6929 print_die (comp_unit_die (), stderr
);
6932 /* Verify the DIE tree structure. */
6935 verify_die (dw_die_ref die
)
6937 gcc_assert (!die
->die_mark
);
6938 if (die
->die_parent
== NULL
6939 && die
->die_sib
== NULL
)
6941 /* Verify the die_sib list is cyclic. */
6948 while (x
&& !x
->die_mark
);
6949 gcc_assert (x
== die
);
6953 /* Verify all dies have the same parent. */
6954 gcc_assert (x
->die_parent
== die
->die_parent
);
6957 /* Verify the child has the proper parent and recurse. */
6958 gcc_assert (x
->die_child
->die_parent
== x
);
6959 verify_die (x
->die_child
);
6964 while (x
&& x
->die_mark
);
6967 /* Sanity checks on DIEs. */
6970 check_die (dw_die_ref die
)
6974 bool inline_found
= false;
6975 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
6976 int n_decl_line
= 0, n_decl_column
= 0, n_decl_file
= 0;
6977 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6982 if (a
->dw_attr_val
.v
.val_unsigned
)
6983 inline_found
= true;
6985 case DW_AT_location
:
6994 case DW_AT_artificial
:
6997 case DW_AT_decl_column
:
7000 case DW_AT_decl_line
:
7003 case DW_AT_decl_file
:
7010 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
7011 || n_decl_column
> 1 || n_decl_line
> 1 || n_decl_file
> 1)
7013 fprintf (stderr
, "Duplicate attributes in DIE:\n");
7014 debug_dwarf_die (die
);
7019 /* A debugging information entry that is a member of an abstract
7020 instance tree [that has DW_AT_inline] should not contain any
7021 attributes which describe aspects of the subroutine which vary
7022 between distinct inlined expansions or distinct out-of-line
7024 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7025 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
7026 && a
->dw_attr
!= DW_AT_high_pc
7027 && a
->dw_attr
!= DW_AT_location
7028 && a
->dw_attr
!= DW_AT_frame_base
7029 && a
->dw_attr
!= DW_AT_call_all_calls
7030 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
7034 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7035 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
7036 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7038 /* Calculate the checksum of a location expression. */
7041 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
7044 inchash::hash hstate
;
7047 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
7049 hash_loc_operands (loc
, hstate
);
7050 hash
= hstate
.end();
7054 /* Calculate the checksum of an attribute. */
7057 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
7059 dw_loc_descr_ref loc
;
7062 CHECKSUM (at
->dw_attr
);
7064 /* We don't care that this was compiled with a different compiler
7065 snapshot; if the output is the same, that's what matters. */
7066 if (at
->dw_attr
== DW_AT_producer
)
7069 switch (AT_class (at
))
7071 case dw_val_class_const
:
7072 case dw_val_class_const_implicit
:
7073 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
7075 case dw_val_class_unsigned_const
:
7076 case dw_val_class_unsigned_const_implicit
:
7077 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
7079 case dw_val_class_const_double
:
7080 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
7082 case dw_val_class_wide_int
:
7083 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
7084 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
7085 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
7087 case dw_val_class_vec
:
7088 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
7089 (at
->dw_attr_val
.v
.val_vec
.length
7090 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
7092 case dw_val_class_flag
:
7093 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
7095 case dw_val_class_str
:
7096 CHECKSUM_STRING (AT_string (at
));
7099 case dw_val_class_addr
:
7101 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
7102 CHECKSUM_STRING (XSTR (r
, 0));
7105 case dw_val_class_offset
:
7106 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
7109 case dw_val_class_loc
:
7110 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
7111 loc_checksum (loc
, ctx
);
7114 case dw_val_class_die_ref
:
7115 die_checksum (AT_ref (at
), ctx
, mark
);
7118 case dw_val_class_fde_ref
:
7119 case dw_val_class_vms_delta
:
7120 case dw_val_class_symview
:
7121 case dw_val_class_lbl_id
:
7122 case dw_val_class_lineptr
:
7123 case dw_val_class_macptr
:
7124 case dw_val_class_loclistsptr
:
7125 case dw_val_class_high_pc
:
7128 case dw_val_class_file
:
7129 case dw_val_class_file_implicit
:
7130 CHECKSUM_STRING (AT_file (at
)->filename
);
7133 case dw_val_class_data8
:
7134 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
7142 /* Calculate the checksum of a DIE. */
7145 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
7151 /* To avoid infinite recursion. */
7154 CHECKSUM (die
->die_mark
);
7157 die
->die_mark
= ++(*mark
);
7159 CHECKSUM (die
->die_tag
);
7161 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7162 attr_checksum (a
, ctx
, mark
);
7164 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
7168 #undef CHECKSUM_BLOCK
7169 #undef CHECKSUM_STRING
7171 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
7172 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7173 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
7174 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
7175 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
7176 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
7177 #define CHECKSUM_ATTR(FOO) \
7178 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
7180 /* Calculate the checksum of a number in signed LEB128 format. */
7183 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
7190 byte
= (value
& 0x7f);
7192 more
= !((value
== 0 && (byte
& 0x40) == 0)
7193 || (value
== -1 && (byte
& 0x40) != 0));
7202 /* Calculate the checksum of a number in unsigned LEB128 format. */
7205 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
7209 unsigned char byte
= (value
& 0x7f);
7212 /* More bytes to follow. */
7220 /* Checksum the context of the DIE. This adds the names of any
7221 surrounding namespaces or structures to the checksum. */
7224 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
7228 int tag
= die
->die_tag
;
7230 if (tag
!= DW_TAG_namespace
7231 && tag
!= DW_TAG_structure_type
7232 && tag
!= DW_TAG_class_type
)
7235 name
= get_AT_string (die
, DW_AT_name
);
7237 spec
= get_AT_ref (die
, DW_AT_specification
);
7241 if (die
->die_parent
!= NULL
)
7242 checksum_die_context (die
->die_parent
, ctx
);
7244 CHECKSUM_ULEB128 ('C');
7245 CHECKSUM_ULEB128 (tag
);
7247 CHECKSUM_STRING (name
);
7250 /* Calculate the checksum of a location expression. */
7253 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
7255 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
7256 were emitted as a DW_FORM_sdata instead of a location expression. */
7257 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
7259 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7260 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
7264 /* Otherwise, just checksum the raw location expression. */
7267 inchash::hash hstate
;
7270 CHECKSUM_ULEB128 (loc
->dtprel
);
7271 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
7272 hash_loc_operands (loc
, hstate
);
7273 hash
= hstate
.end ();
7275 loc
= loc
->dw_loc_next
;
7279 /* Calculate the checksum of an attribute. */
7282 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
7283 struct md5_ctx
*ctx
, int *mark
)
7285 dw_loc_descr_ref loc
;
7288 if (AT_class (at
) == dw_val_class_die_ref
)
7290 dw_die_ref target_die
= AT_ref (at
);
7292 /* For pointer and reference types, we checksum only the (qualified)
7293 name of the target type (if there is a name). For friend entries,
7294 we checksum only the (qualified) name of the target type or function.
7295 This allows the checksum to remain the same whether the target type
7296 is complete or not. */
7297 if ((at
->dw_attr
== DW_AT_type
7298 && (tag
== DW_TAG_pointer_type
7299 || tag
== DW_TAG_reference_type
7300 || tag
== DW_TAG_rvalue_reference_type
7301 || tag
== DW_TAG_ptr_to_member_type
))
7302 || (at
->dw_attr
== DW_AT_friend
7303 && tag
== DW_TAG_friend
))
7305 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
7307 if (name_attr
!= NULL
)
7309 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
7313 CHECKSUM_ULEB128 ('N');
7314 CHECKSUM_ULEB128 (at
->dw_attr
);
7315 if (decl
->die_parent
!= NULL
)
7316 checksum_die_context (decl
->die_parent
, ctx
);
7317 CHECKSUM_ULEB128 ('E');
7318 CHECKSUM_STRING (AT_string (name_attr
));
7323 /* For all other references to another DIE, we check to see if the
7324 target DIE has already been visited. If it has, we emit a
7325 backward reference; if not, we descend recursively. */
7326 if (target_die
->die_mark
> 0)
7328 CHECKSUM_ULEB128 ('R');
7329 CHECKSUM_ULEB128 (at
->dw_attr
);
7330 CHECKSUM_ULEB128 (target_die
->die_mark
);
7334 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
7338 target_die
->die_mark
= ++(*mark
);
7339 CHECKSUM_ULEB128 ('T');
7340 CHECKSUM_ULEB128 (at
->dw_attr
);
7341 if (decl
->die_parent
!= NULL
)
7342 checksum_die_context (decl
->die_parent
, ctx
);
7343 die_checksum_ordered (target_die
, ctx
, mark
);
7348 CHECKSUM_ULEB128 ('A');
7349 CHECKSUM_ULEB128 (at
->dw_attr
);
7351 switch (AT_class (at
))
7353 case dw_val_class_const
:
7354 case dw_val_class_const_implicit
:
7355 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7356 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
7359 case dw_val_class_unsigned_const
:
7360 case dw_val_class_unsigned_const_implicit
:
7361 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7362 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
7365 case dw_val_class_const_double
:
7366 CHECKSUM_ULEB128 (DW_FORM_block
);
7367 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
7368 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
7371 case dw_val_class_wide_int
:
7372 CHECKSUM_ULEB128 (DW_FORM_block
);
7373 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
7374 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
7375 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
7376 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
7377 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
7380 case dw_val_class_vec
:
7381 CHECKSUM_ULEB128 (DW_FORM_block
);
7382 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
7383 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
7384 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
7385 (at
->dw_attr_val
.v
.val_vec
.length
7386 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
7389 case dw_val_class_flag
:
7390 CHECKSUM_ULEB128 (DW_FORM_flag
);
7391 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
7394 case dw_val_class_str
:
7395 CHECKSUM_ULEB128 (DW_FORM_string
);
7396 CHECKSUM_STRING (AT_string (at
));
7399 case dw_val_class_addr
:
7401 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
7402 CHECKSUM_ULEB128 (DW_FORM_string
);
7403 CHECKSUM_STRING (XSTR (r
, 0));
7406 case dw_val_class_offset
:
7407 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7408 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
7411 case dw_val_class_loc
:
7412 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
7413 loc_checksum_ordered (loc
, ctx
);
7416 case dw_val_class_fde_ref
:
7417 case dw_val_class_symview
:
7418 case dw_val_class_lbl_id
:
7419 case dw_val_class_lineptr
:
7420 case dw_val_class_macptr
:
7421 case dw_val_class_loclistsptr
:
7422 case dw_val_class_high_pc
:
7425 case dw_val_class_file
:
7426 case dw_val_class_file_implicit
:
7427 CHECKSUM_ULEB128 (DW_FORM_string
);
7428 CHECKSUM_STRING (AT_file (at
)->filename
);
7431 case dw_val_class_data8
:
7432 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
7440 struct checksum_attributes
7442 dw_attr_node
*at_name
;
7443 dw_attr_node
*at_type
;
7444 dw_attr_node
*at_friend
;
7445 dw_attr_node
*at_accessibility
;
7446 dw_attr_node
*at_address_class
;
7447 dw_attr_node
*at_alignment
;
7448 dw_attr_node
*at_allocated
;
7449 dw_attr_node
*at_artificial
;
7450 dw_attr_node
*at_associated
;
7451 dw_attr_node
*at_binary_scale
;
7452 dw_attr_node
*at_bit_offset
;
7453 dw_attr_node
*at_bit_size
;
7454 dw_attr_node
*at_bit_stride
;
7455 dw_attr_node
*at_byte_size
;
7456 dw_attr_node
*at_byte_stride
;
7457 dw_attr_node
*at_const_value
;
7458 dw_attr_node
*at_containing_type
;
7459 dw_attr_node
*at_count
;
7460 dw_attr_node
*at_data_location
;
7461 dw_attr_node
*at_data_member_location
;
7462 dw_attr_node
*at_decimal_scale
;
7463 dw_attr_node
*at_decimal_sign
;
7464 dw_attr_node
*at_default_value
;
7465 dw_attr_node
*at_digit_count
;
7466 dw_attr_node
*at_discr
;
7467 dw_attr_node
*at_discr_list
;
7468 dw_attr_node
*at_discr_value
;
7469 dw_attr_node
*at_encoding
;
7470 dw_attr_node
*at_endianity
;
7471 dw_attr_node
*at_explicit
;
7472 dw_attr_node
*at_is_optional
;
7473 dw_attr_node
*at_location
;
7474 dw_attr_node
*at_lower_bound
;
7475 dw_attr_node
*at_mutable
;
7476 dw_attr_node
*at_ordering
;
7477 dw_attr_node
*at_picture_string
;
7478 dw_attr_node
*at_prototyped
;
7479 dw_attr_node
*at_small
;
7480 dw_attr_node
*at_segment
;
7481 dw_attr_node
*at_string_length
;
7482 dw_attr_node
*at_string_length_bit_size
;
7483 dw_attr_node
*at_string_length_byte_size
;
7484 dw_attr_node
*at_threads_scaled
;
7485 dw_attr_node
*at_upper_bound
;
7486 dw_attr_node
*at_use_location
;
7487 dw_attr_node
*at_use_UTF8
;
7488 dw_attr_node
*at_variable_parameter
;
7489 dw_attr_node
*at_virtuality
;
7490 dw_attr_node
*at_visibility
;
7491 dw_attr_node
*at_vtable_elem_location
;
7494 /* Collect the attributes that we will want to use for the checksum. */
7497 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
7502 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7513 attrs
->at_friend
= a
;
7515 case DW_AT_accessibility
:
7516 attrs
->at_accessibility
= a
;
7518 case DW_AT_address_class
:
7519 attrs
->at_address_class
= a
;
7521 case DW_AT_alignment
:
7522 attrs
->at_alignment
= a
;
7524 case DW_AT_allocated
:
7525 attrs
->at_allocated
= a
;
7527 case DW_AT_artificial
:
7528 attrs
->at_artificial
= a
;
7530 case DW_AT_associated
:
7531 attrs
->at_associated
= a
;
7533 case DW_AT_binary_scale
:
7534 attrs
->at_binary_scale
= a
;
7536 case DW_AT_bit_offset
:
7537 attrs
->at_bit_offset
= a
;
7539 case DW_AT_bit_size
:
7540 attrs
->at_bit_size
= a
;
7542 case DW_AT_bit_stride
:
7543 attrs
->at_bit_stride
= a
;
7545 case DW_AT_byte_size
:
7546 attrs
->at_byte_size
= a
;
7548 case DW_AT_byte_stride
:
7549 attrs
->at_byte_stride
= a
;
7551 case DW_AT_const_value
:
7552 attrs
->at_const_value
= a
;
7554 case DW_AT_containing_type
:
7555 attrs
->at_containing_type
= a
;
7558 attrs
->at_count
= a
;
7560 case DW_AT_data_location
:
7561 attrs
->at_data_location
= a
;
7563 case DW_AT_data_member_location
:
7564 attrs
->at_data_member_location
= a
;
7566 case DW_AT_decimal_scale
:
7567 attrs
->at_decimal_scale
= a
;
7569 case DW_AT_decimal_sign
:
7570 attrs
->at_decimal_sign
= a
;
7572 case DW_AT_default_value
:
7573 attrs
->at_default_value
= a
;
7575 case DW_AT_digit_count
:
7576 attrs
->at_digit_count
= a
;
7579 attrs
->at_discr
= a
;
7581 case DW_AT_discr_list
:
7582 attrs
->at_discr_list
= a
;
7584 case DW_AT_discr_value
:
7585 attrs
->at_discr_value
= a
;
7587 case DW_AT_encoding
:
7588 attrs
->at_encoding
= a
;
7590 case DW_AT_endianity
:
7591 attrs
->at_endianity
= a
;
7593 case DW_AT_explicit
:
7594 attrs
->at_explicit
= a
;
7596 case DW_AT_is_optional
:
7597 attrs
->at_is_optional
= a
;
7599 case DW_AT_location
:
7600 attrs
->at_location
= a
;
7602 case DW_AT_lower_bound
:
7603 attrs
->at_lower_bound
= a
;
7606 attrs
->at_mutable
= a
;
7608 case DW_AT_ordering
:
7609 attrs
->at_ordering
= a
;
7611 case DW_AT_picture_string
:
7612 attrs
->at_picture_string
= a
;
7614 case DW_AT_prototyped
:
7615 attrs
->at_prototyped
= a
;
7618 attrs
->at_small
= a
;
7621 attrs
->at_segment
= a
;
7623 case DW_AT_string_length
:
7624 attrs
->at_string_length
= a
;
7626 case DW_AT_string_length_bit_size
:
7627 attrs
->at_string_length_bit_size
= a
;
7629 case DW_AT_string_length_byte_size
:
7630 attrs
->at_string_length_byte_size
= a
;
7632 case DW_AT_threads_scaled
:
7633 attrs
->at_threads_scaled
= a
;
7635 case DW_AT_upper_bound
:
7636 attrs
->at_upper_bound
= a
;
7638 case DW_AT_use_location
:
7639 attrs
->at_use_location
= a
;
7641 case DW_AT_use_UTF8
:
7642 attrs
->at_use_UTF8
= a
;
7644 case DW_AT_variable_parameter
:
7645 attrs
->at_variable_parameter
= a
;
7647 case DW_AT_virtuality
:
7648 attrs
->at_virtuality
= a
;
7650 case DW_AT_visibility
:
7651 attrs
->at_visibility
= a
;
7653 case DW_AT_vtable_elem_location
:
7654 attrs
->at_vtable_elem_location
= a
;
7662 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
7665 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
7669 struct checksum_attributes attrs
;
7671 CHECKSUM_ULEB128 ('D');
7672 CHECKSUM_ULEB128 (die
->die_tag
);
7674 memset (&attrs
, 0, sizeof (attrs
));
7676 decl
= get_AT_ref (die
, DW_AT_specification
);
7678 collect_checksum_attributes (&attrs
, decl
);
7679 collect_checksum_attributes (&attrs
, die
);
7681 CHECKSUM_ATTR (attrs
.at_name
);
7682 CHECKSUM_ATTR (attrs
.at_accessibility
);
7683 CHECKSUM_ATTR (attrs
.at_address_class
);
7684 CHECKSUM_ATTR (attrs
.at_allocated
);
7685 CHECKSUM_ATTR (attrs
.at_artificial
);
7686 CHECKSUM_ATTR (attrs
.at_associated
);
7687 CHECKSUM_ATTR (attrs
.at_binary_scale
);
7688 CHECKSUM_ATTR (attrs
.at_bit_offset
);
7689 CHECKSUM_ATTR (attrs
.at_bit_size
);
7690 CHECKSUM_ATTR (attrs
.at_bit_stride
);
7691 CHECKSUM_ATTR (attrs
.at_byte_size
);
7692 CHECKSUM_ATTR (attrs
.at_byte_stride
);
7693 CHECKSUM_ATTR (attrs
.at_const_value
);
7694 CHECKSUM_ATTR (attrs
.at_containing_type
);
7695 CHECKSUM_ATTR (attrs
.at_count
);
7696 CHECKSUM_ATTR (attrs
.at_data_location
);
7697 CHECKSUM_ATTR (attrs
.at_data_member_location
);
7698 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
7699 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
7700 CHECKSUM_ATTR (attrs
.at_default_value
);
7701 CHECKSUM_ATTR (attrs
.at_digit_count
);
7702 CHECKSUM_ATTR (attrs
.at_discr
);
7703 CHECKSUM_ATTR (attrs
.at_discr_list
);
7704 CHECKSUM_ATTR (attrs
.at_discr_value
);
7705 CHECKSUM_ATTR (attrs
.at_encoding
);
7706 CHECKSUM_ATTR (attrs
.at_endianity
);
7707 CHECKSUM_ATTR (attrs
.at_explicit
);
7708 CHECKSUM_ATTR (attrs
.at_is_optional
);
7709 CHECKSUM_ATTR (attrs
.at_location
);
7710 CHECKSUM_ATTR (attrs
.at_lower_bound
);
7711 CHECKSUM_ATTR (attrs
.at_mutable
);
7712 CHECKSUM_ATTR (attrs
.at_ordering
);
7713 CHECKSUM_ATTR (attrs
.at_picture_string
);
7714 CHECKSUM_ATTR (attrs
.at_prototyped
);
7715 CHECKSUM_ATTR (attrs
.at_small
);
7716 CHECKSUM_ATTR (attrs
.at_segment
);
7717 CHECKSUM_ATTR (attrs
.at_string_length
);
7718 CHECKSUM_ATTR (attrs
.at_string_length_bit_size
);
7719 CHECKSUM_ATTR (attrs
.at_string_length_byte_size
);
7720 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
7721 CHECKSUM_ATTR (attrs
.at_upper_bound
);
7722 CHECKSUM_ATTR (attrs
.at_use_location
);
7723 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
7724 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
7725 CHECKSUM_ATTR (attrs
.at_virtuality
);
7726 CHECKSUM_ATTR (attrs
.at_visibility
);
7727 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
7728 CHECKSUM_ATTR (attrs
.at_type
);
7729 CHECKSUM_ATTR (attrs
.at_friend
);
7730 CHECKSUM_ATTR (attrs
.at_alignment
);
7732 /* Checksum the child DIEs. */
7735 dw_attr_node
*name_attr
;
7738 name_attr
= get_AT (c
, DW_AT_name
);
7739 if (is_template_instantiation (c
))
7741 /* Ignore instantiations of member type and function templates. */
7743 else if (name_attr
!= NULL
7744 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
7746 /* Use a shallow checksum for named nested types and member
7748 CHECKSUM_ULEB128 ('S');
7749 CHECKSUM_ULEB128 (c
->die_tag
);
7750 CHECKSUM_STRING (AT_string (name_attr
));
7754 /* Use a deep checksum for other children. */
7755 /* Mark this DIE so it gets processed when unmarking. */
7756 if (c
->die_mark
== 0)
7758 die_checksum_ordered (c
, ctx
, mark
);
7760 } while (c
!= die
->die_child
);
7762 CHECKSUM_ULEB128 (0);
7765 /* Add a type name and tag to a hash. */
7767 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
7769 CHECKSUM_ULEB128 (tag
);
7770 CHECKSUM_STRING (name
);
7774 #undef CHECKSUM_STRING
7775 #undef CHECKSUM_ATTR
7776 #undef CHECKSUM_LEB128
7777 #undef CHECKSUM_ULEB128
7779 /* Generate the type signature for DIE. This is computed by generating an
7780 MD5 checksum over the DIE's tag, its relevant attributes, and its
7781 children. Attributes that are references to other DIEs are processed
7782 by recursion, using the MARK field to prevent infinite recursion.
7783 If the DIE is nested inside a namespace or another type, we also
7784 need to include that context in the signature. The lower 64 bits
7785 of the resulting MD5 checksum comprise the signature. */
7788 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
7792 unsigned char checksum
[16];
7797 name
= get_AT_string (die
, DW_AT_name
);
7798 decl
= get_AT_ref (die
, DW_AT_specification
);
7799 parent
= get_die_parent (die
);
7801 /* First, compute a signature for just the type name (and its surrounding
7802 context, if any. This is stored in the type unit DIE for link-time
7803 ODR (one-definition rule) checking. */
7805 if (is_cxx () && name
!= NULL
)
7807 md5_init_ctx (&ctx
);
7809 /* Checksum the names of surrounding namespaces and structures. */
7811 checksum_die_context (parent
, &ctx
);
7813 /* Checksum the current DIE. */
7814 die_odr_checksum (die
->die_tag
, name
, &ctx
);
7815 md5_finish_ctx (&ctx
, checksum
);
7817 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
7820 /* Next, compute the complete type signature. */
7822 md5_init_ctx (&ctx
);
7824 die
->die_mark
= mark
;
7826 /* Checksum the names of surrounding namespaces and structures. */
7828 checksum_die_context (parent
, &ctx
);
7830 /* Checksum the DIE and its children. */
7831 die_checksum_ordered (die
, &ctx
, &mark
);
7832 unmark_all_dies (die
);
7833 md5_finish_ctx (&ctx
, checksum
);
7835 /* Store the signature in the type node and link the type DIE and the
7836 type node together. */
7837 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
7838 DWARF_TYPE_SIGNATURE_SIZE
);
7839 die
->comdat_type_p
= true;
7840 die
->die_id
.die_type_node
= type_node
;
7841 type_node
->type_die
= die
;
7843 /* If the DIE is a specification, link its declaration to the type node
7847 decl
->comdat_type_p
= true;
7848 decl
->die_id
.die_type_node
= type_node
;
7852 /* Do the location expressions look same? */
7854 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
7856 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
7857 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
7858 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
7861 /* Do the values look the same? */
7863 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
7865 dw_loc_descr_ref loc1
, loc2
;
7868 if (v1
->val_class
!= v2
->val_class
)
7871 switch (v1
->val_class
)
7873 case dw_val_class_const
:
7874 case dw_val_class_const_implicit
:
7875 return v1
->v
.val_int
== v2
->v
.val_int
;
7876 case dw_val_class_unsigned_const
:
7877 case dw_val_class_unsigned_const_implicit
:
7878 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
7879 case dw_val_class_const_double
:
7880 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
7881 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
7882 case dw_val_class_wide_int
:
7883 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
7884 case dw_val_class_vec
:
7885 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
7886 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7888 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7889 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7892 case dw_val_class_flag
:
7893 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7894 case dw_val_class_str
:
7895 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7897 case dw_val_class_addr
:
7898 r1
= v1
->v
.val_addr
;
7899 r2
= v2
->v
.val_addr
;
7900 if (GET_CODE (r1
) != GET_CODE (r2
))
7902 return !rtx_equal_p (r1
, r2
);
7904 case dw_val_class_offset
:
7905 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7907 case dw_val_class_loc
:
7908 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7910 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7911 if (!same_loc_p (loc1
, loc2
, mark
))
7913 return !loc1
&& !loc2
;
7915 case dw_val_class_die_ref
:
7916 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7918 case dw_val_class_symview
:
7919 return strcmp (v1
->v
.val_symbolic_view
, v2
->v
.val_symbolic_view
) == 0;
7921 case dw_val_class_fde_ref
:
7922 case dw_val_class_vms_delta
:
7923 case dw_val_class_lbl_id
:
7924 case dw_val_class_lineptr
:
7925 case dw_val_class_macptr
:
7926 case dw_val_class_loclistsptr
:
7927 case dw_val_class_high_pc
:
7930 case dw_val_class_file
:
7931 case dw_val_class_file_implicit
:
7932 return v1
->v
.val_file
== v2
->v
.val_file
;
7934 case dw_val_class_data8
:
7935 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
7942 /* Do the attributes look the same? */
7945 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
7947 if (at1
->dw_attr
!= at2
->dw_attr
)
7950 /* We don't care that this was compiled with a different compiler
7951 snapshot; if the output is the same, that's what matters. */
7952 if (at1
->dw_attr
== DW_AT_producer
)
7955 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7958 /* Do the dies look the same? */
7961 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7967 /* To avoid infinite recursion. */
7969 return die1
->die_mark
== die2
->die_mark
;
7970 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7972 if (die1
->die_tag
!= die2
->die_tag
)
7975 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
7978 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
7979 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
7982 c1
= die1
->die_child
;
7983 c2
= die2
->die_child
;
7992 if (!same_die_p (c1
, c2
, mark
))
7996 if (c1
== die1
->die_child
)
7998 if (c2
== die2
->die_child
)
8008 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
8009 children, and set die_symbol. */
8012 compute_comp_unit_symbol (dw_die_ref unit_die
)
8014 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
8015 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
8016 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
8019 unsigned char checksum
[16];
8022 /* Compute the checksum of the DIE, then append part of it as hex digits to
8023 the name filename of the unit. */
8025 md5_init_ctx (&ctx
);
8027 die_checksum (unit_die
, &ctx
, &mark
);
8028 unmark_all_dies (unit_die
);
8029 md5_finish_ctx (&ctx
, checksum
);
8031 /* When we this for comp_unit_die () we have a DW_AT_name that might
8032 not start with a letter but with anything valid for filenames and
8033 clean_symbol_name doesn't fix that up. Prepend 'g' if the first
8034 character is not a letter. */
8035 sprintf (name
, "%s%s.", ISALPHA (*base
) ? "" : "g", base
);
8036 clean_symbol_name (name
);
8038 p
= name
+ strlen (name
);
8039 for (i
= 0; i
< 4; i
++)
8041 sprintf (p
, "%.2x", checksum
[i
]);
8045 unit_die
->die_id
.die_symbol
= xstrdup (name
);
8048 /* Returns true if DIE represents a type, in the sense of TYPE_P. */
8051 is_type_die (dw_die_ref die
)
8053 switch (die
->die_tag
)
8055 case DW_TAG_array_type
:
8056 case DW_TAG_class_type
:
8057 case DW_TAG_interface_type
:
8058 case DW_TAG_enumeration_type
:
8059 case DW_TAG_pointer_type
:
8060 case DW_TAG_reference_type
:
8061 case DW_TAG_rvalue_reference_type
:
8062 case DW_TAG_string_type
:
8063 case DW_TAG_structure_type
:
8064 case DW_TAG_subroutine_type
:
8065 case DW_TAG_union_type
:
8066 case DW_TAG_ptr_to_member_type
:
8067 case DW_TAG_set_type
:
8068 case DW_TAG_subrange_type
:
8069 case DW_TAG_base_type
:
8070 case DW_TAG_const_type
:
8071 case DW_TAG_file_type
:
8072 case DW_TAG_packed_type
:
8073 case DW_TAG_volatile_type
:
8074 case DW_TAG_typedef
:
8081 /* Returns true iff C is a compile-unit DIE. */
8084 is_cu_die (dw_die_ref c
)
8086 return c
&& (c
->die_tag
== DW_TAG_compile_unit
8087 || c
->die_tag
== DW_TAG_skeleton_unit
);
8090 /* Returns true iff C is a unit DIE of some sort. */
8093 is_unit_die (dw_die_ref c
)
8095 return c
&& (c
->die_tag
== DW_TAG_compile_unit
8096 || c
->die_tag
== DW_TAG_partial_unit
8097 || c
->die_tag
== DW_TAG_type_unit
8098 || c
->die_tag
== DW_TAG_skeleton_unit
);
8101 /* Returns true iff C is a namespace DIE. */
8104 is_namespace_die (dw_die_ref c
)
8106 return c
&& c
->die_tag
== DW_TAG_namespace
;
8109 /* Return true if this DIE is a template parameter. */
8112 is_template_parameter (dw_die_ref die
)
8114 switch (die
->die_tag
)
8116 case DW_TAG_template_type_param
:
8117 case DW_TAG_template_value_param
:
8118 case DW_TAG_GNU_template_template_param
:
8119 case DW_TAG_GNU_template_parameter_pack
:
8126 /* Return true if this DIE represents a template instantiation. */
8129 is_template_instantiation (dw_die_ref die
)
8133 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
8135 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
8140 gen_internal_sym (const char *prefix
)
8142 char buf
[MAX_ARTIFICIAL_LABEL_BYTES
];
8144 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
8145 return xstrdup (buf
);
8148 /* Return true if this DIE is a declaration. */
8151 is_declaration_die (dw_die_ref die
)
8156 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8157 if (a
->dw_attr
== DW_AT_declaration
)
8163 /* Return true if this DIE is nested inside a subprogram. */
8166 is_nested_in_subprogram (dw_die_ref die
)
8168 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
8172 return local_scope_p (decl
);
8175 /* Return true if this DIE contains a defining declaration of a
8179 contains_subprogram_definition (dw_die_ref die
)
8183 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
8185 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
8189 /* Return true if this is a type DIE that should be moved to a
8190 COMDAT .debug_types section or .debug_info section with DW_UT_*type
8194 should_move_die_to_comdat (dw_die_ref die
)
8196 switch (die
->die_tag
)
8198 case DW_TAG_class_type
:
8199 case DW_TAG_structure_type
:
8200 case DW_TAG_enumeration_type
:
8201 case DW_TAG_union_type
:
8202 /* Don't move declarations, inlined instances, types nested in a
8203 subprogram, or types that contain subprogram definitions. */
8204 if (is_declaration_die (die
)
8205 || get_AT (die
, DW_AT_abstract_origin
)
8206 || is_nested_in_subprogram (die
)
8207 || contains_subprogram_definition (die
))
8210 case DW_TAG_array_type
:
8211 case DW_TAG_interface_type
:
8212 case DW_TAG_pointer_type
:
8213 case DW_TAG_reference_type
:
8214 case DW_TAG_rvalue_reference_type
:
8215 case DW_TAG_string_type
:
8216 case DW_TAG_subroutine_type
:
8217 case DW_TAG_ptr_to_member_type
:
8218 case DW_TAG_set_type
:
8219 case DW_TAG_subrange_type
:
8220 case DW_TAG_base_type
:
8221 case DW_TAG_const_type
:
8222 case DW_TAG_file_type
:
8223 case DW_TAG_packed_type
:
8224 case DW_TAG_volatile_type
:
8225 case DW_TAG_typedef
:
8231 /* Make a clone of DIE. */
8234 clone_die (dw_die_ref die
)
8236 dw_die_ref clone
= new_die_raw (die
->die_tag
);
8240 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8241 add_dwarf_attr (clone
, a
);
8246 /* Make a clone of the tree rooted at DIE. */
8249 clone_tree (dw_die_ref die
)
8252 dw_die_ref clone
= clone_die (die
);
8254 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
8259 /* Make a clone of DIE as a declaration. */
8262 clone_as_declaration (dw_die_ref die
)
8269 /* If the DIE is already a declaration, just clone it. */
8270 if (is_declaration_die (die
))
8271 return clone_die (die
);
8273 /* If the DIE is a specification, just clone its declaration DIE. */
8274 decl
= get_AT_ref (die
, DW_AT_specification
);
8277 clone
= clone_die (decl
);
8278 if (die
->comdat_type_p
)
8279 add_AT_die_ref (clone
, DW_AT_signature
, die
);
8283 clone
= new_die_raw (die
->die_tag
);
8285 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8287 /* We don't want to copy over all attributes.
8288 For example we don't want DW_AT_byte_size because otherwise we will no
8289 longer have a declaration and GDB will treat it as a definition. */
8293 case DW_AT_abstract_origin
:
8294 case DW_AT_artificial
:
8295 case DW_AT_containing_type
:
8296 case DW_AT_external
:
8299 case DW_AT_virtuality
:
8300 case DW_AT_linkage_name
:
8301 case DW_AT_MIPS_linkage_name
:
8302 add_dwarf_attr (clone
, a
);
8304 case DW_AT_byte_size
:
8305 case DW_AT_alignment
:
8311 if (die
->comdat_type_p
)
8312 add_AT_die_ref (clone
, DW_AT_signature
, die
);
8314 add_AT_flag (clone
, DW_AT_declaration
, 1);
8319 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
8321 struct decl_table_entry
8327 /* Helpers to manipulate hash table of copied declarations. */
8329 /* Hashtable helpers. */
8331 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
8333 typedef die_struct
*compare_type
;
8334 static inline hashval_t
hash (const decl_table_entry
*);
8335 static inline bool equal (const decl_table_entry
*, const die_struct
*);
8339 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
8341 return htab_hash_pointer (entry
->orig
);
8345 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
8346 const die_struct
*entry2
)
8348 return entry1
->orig
== entry2
;
8351 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
8353 /* Copy DIE and its ancestors, up to, but not including, the compile unit
8354 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
8355 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
8356 to check if the ancestor has already been copied into UNIT. */
8359 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
8360 decl_hash_type
*decl_table
)
8362 dw_die_ref parent
= die
->die_parent
;
8363 dw_die_ref new_parent
= unit
;
8365 decl_table_entry
**slot
= NULL
;
8366 struct decl_table_entry
*entry
= NULL
;
8368 /* If DIE refers to a stub unfold that so we get the appropriate
8369 DIE registered as orig in decl_table. */
8370 if (dw_die_ref c
= get_AT_ref (die
, DW_AT_signature
))
8375 /* Check if the entry has already been copied to UNIT. */
8376 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
8378 if (*slot
!= HTAB_EMPTY_ENTRY
)
8384 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
8385 entry
= XCNEW (struct decl_table_entry
);
8393 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
8396 if (!is_unit_die (parent
))
8397 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
8400 copy
= clone_as_declaration (die
);
8401 add_child_die (new_parent
, copy
);
8405 /* Record the pointer to the copy. */
8411 /* Copy the declaration context to the new type unit DIE. This includes
8412 any surrounding namespace or type declarations. If the DIE has an
8413 AT_specification attribute, it also includes attributes and children
8414 attached to the specification, and returns a pointer to the original
8415 parent of the declaration DIE. Returns NULL otherwise. */
8418 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
8421 dw_die_ref new_decl
;
8422 dw_die_ref orig_parent
= NULL
;
8424 decl
= get_AT_ref (die
, DW_AT_specification
);
8433 /* The original DIE will be changed to a declaration, and must
8434 be moved to be a child of the original declaration DIE. */
8435 orig_parent
= decl
->die_parent
;
8437 /* Copy the type node pointer from the new DIE to the original
8438 declaration DIE so we can forward references later. */
8439 decl
->comdat_type_p
= true;
8440 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
8442 remove_AT (die
, DW_AT_specification
);
8444 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
8446 if (a
->dw_attr
!= DW_AT_name
8447 && a
->dw_attr
!= DW_AT_declaration
8448 && a
->dw_attr
!= DW_AT_external
)
8449 add_dwarf_attr (die
, a
);
8452 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
8455 if (decl
->die_parent
!= NULL
8456 && !is_unit_die (decl
->die_parent
))
8458 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
8459 if (new_decl
!= NULL
)
8461 remove_AT (new_decl
, DW_AT_signature
);
8462 add_AT_specification (die
, new_decl
);
8469 /* Generate the skeleton ancestor tree for the given NODE, then clone
8470 the DIE and add the clone into the tree. */
8473 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
8475 if (node
->new_die
!= NULL
)
8478 node
->new_die
= clone_as_declaration (node
->old_die
);
8480 if (node
->parent
!= NULL
)
8482 generate_skeleton_ancestor_tree (node
->parent
);
8483 add_child_die (node
->parent
->new_die
, node
->new_die
);
8487 /* Generate a skeleton tree of DIEs containing any declarations that are
8488 found in the original tree. We traverse the tree looking for declaration
8489 DIEs, and construct the skeleton from the bottom up whenever we find one. */
8492 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
8494 skeleton_chain_node node
;
8497 dw_die_ref prev
= NULL
;
8498 dw_die_ref next
= NULL
;
8500 node
.parent
= parent
;
8502 first
= c
= parent
->old_die
->die_child
;
8506 if (prev
== NULL
|| prev
->die_sib
== c
)
8509 next
= (c
== first
? NULL
: c
->die_sib
);
8511 node
.new_die
= NULL
;
8512 if (is_declaration_die (c
))
8514 if (is_template_instantiation (c
))
8516 /* Instantiated templates do not need to be cloned into the
8517 type unit. Just move the DIE and its children back to
8518 the skeleton tree (in the main CU). */
8519 remove_child_with_prev (c
, prev
);
8520 add_child_die (parent
->new_die
, c
);
8523 else if (c
->comdat_type_p
)
8525 /* This is the skeleton of earlier break_out_comdat_types
8526 type. Clone the existing DIE, but keep the children
8527 under the original (which is in the main CU). */
8528 dw_die_ref clone
= clone_die (c
);
8530 replace_child (c
, clone
, prev
);
8531 generate_skeleton_ancestor_tree (parent
);
8532 add_child_die (parent
->new_die
, c
);
8538 /* Clone the existing DIE, move the original to the skeleton
8539 tree (which is in the main CU), and put the clone, with
8540 all the original's children, where the original came from
8541 (which is about to be moved to the type unit). */
8542 dw_die_ref clone
= clone_die (c
);
8543 move_all_children (c
, clone
);
8545 /* If the original has a DW_AT_object_pointer attribute,
8546 it would now point to a child DIE just moved to the
8547 cloned tree, so we need to remove that attribute from
8549 remove_AT (c
, DW_AT_object_pointer
);
8551 replace_child (c
, clone
, prev
);
8552 generate_skeleton_ancestor_tree (parent
);
8553 add_child_die (parent
->new_die
, c
);
8554 node
.old_die
= clone
;
8559 generate_skeleton_bottom_up (&node
);
8560 } while (next
!= NULL
);
8563 /* Wrapper function for generate_skeleton_bottom_up. */
8566 generate_skeleton (dw_die_ref die
)
8568 skeleton_chain_node node
;
8571 node
.new_die
= NULL
;
8574 /* If this type definition is nested inside another type,
8575 and is not an instantiation of a template, always leave
8576 at least a declaration in its place. */
8577 if (die
->die_parent
!= NULL
8578 && is_type_die (die
->die_parent
)
8579 && !is_template_instantiation (die
))
8580 node
.new_die
= clone_as_declaration (die
);
8582 generate_skeleton_bottom_up (&node
);
8583 return node
.new_die
;
8586 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
8587 declaration. The original DIE is moved to a new compile unit so that
8588 existing references to it follow it to the new location. If any of the
8589 original DIE's descendants is a declaration, we need to replace the
8590 original DIE with a skeleton tree and move the declarations back into the
8594 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
8597 dw_die_ref skeleton
, orig_parent
;
8599 /* Copy the declaration context to the type unit DIE. If the returned
8600 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
8602 orig_parent
= copy_declaration_context (unit
, child
);
8604 skeleton
= generate_skeleton (child
);
8605 if (skeleton
== NULL
)
8606 remove_child_with_prev (child
, prev
);
8609 skeleton
->comdat_type_p
= true;
8610 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
8612 /* If the original DIE was a specification, we need to put
8613 the skeleton under the parent DIE of the declaration.
8614 This leaves the original declaration in the tree, but
8615 it will be pruned later since there are no longer any
8616 references to it. */
8617 if (orig_parent
!= NULL
)
8619 remove_child_with_prev (child
, prev
);
8620 add_child_die (orig_parent
, skeleton
);
8623 replace_child (child
, skeleton
, prev
);
8630 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8631 comdat_type_node
*type_node
,
8632 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
8634 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8635 procedure, put it under TYPE_NODE and return the copy. Continue looking for
8636 DWARF procedure references in the DW_AT_location attribute. */
8639 copy_dwarf_procedure (dw_die_ref die
,
8640 comdat_type_node
*type_node
,
8641 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8643 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
8645 /* DWARF procedures are not supposed to have children... */
8646 gcc_assert (die
->die_child
== NULL
);
8648 /* ... and they are supposed to have only one attribute: DW_AT_location. */
8649 gcc_assert (vec_safe_length (die
->die_attr
) == 1
8650 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
8652 /* Do not copy more than once DWARF procedures. */
8654 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
8658 die_copy
= clone_die (die
);
8659 add_child_die (type_node
->root_die
, die_copy
);
8660 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
8664 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8665 procedures in DIE's attributes. */
8668 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8669 comdat_type_node
*type_node
,
8670 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8675 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
8677 dw_loc_descr_ref loc
;
8679 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
8682 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
8684 switch (loc
->dw_loc_opc
)
8688 case DW_OP_call_ref
:
8689 gcc_assert (loc
->dw_loc_oprnd1
.val_class
8690 == dw_val_class_die_ref
);
8691 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
8692 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
8694 copied_dwarf_procs
);
8703 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8704 rewrite references to point to the copies.
8706 References are looked for in DIE's attributes and recursively in all its
8707 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8708 mapping from old DWARF procedures to their copy. It is used not to copy
8709 twice the same DWARF procedure under TYPE_NODE. */
8712 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
8713 comdat_type_node
*type_node
,
8714 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8718 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
8719 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
8721 copied_dwarf_procs
));
8724 /* Traverse the DIE and set up additional .debug_types or .debug_info
8725 DW_UT_*type sections for each type worthy of being placed in a COMDAT
8729 break_out_comdat_types (dw_die_ref die
)
8733 dw_die_ref prev
= NULL
;
8734 dw_die_ref next
= NULL
;
8735 dw_die_ref unit
= NULL
;
8737 first
= c
= die
->die_child
;
8741 if (prev
== NULL
|| prev
->die_sib
== c
)
8744 next
= (c
== first
? NULL
: c
->die_sib
);
8745 if (should_move_die_to_comdat (c
))
8747 dw_die_ref replacement
;
8748 comdat_type_node
*type_node
;
8750 /* Break out nested types into their own type units. */
8751 break_out_comdat_types (c
);
8753 /* Create a new type unit DIE as the root for the new tree. */
8754 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8755 add_AT_unsigned (unit
, DW_AT_language
,
8756 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
8758 /* Add the new unit's type DIE into the comdat type list. */
8759 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
8760 type_node
->root_die
= unit
;
8761 type_node
->next
= comdat_type_list
;
8762 comdat_type_list
= type_node
;
8764 /* Generate the type signature. */
8765 generate_type_signature (c
, type_node
);
8767 /* Copy the declaration context, attributes, and children of the
8768 declaration into the new type unit DIE, then remove this DIE
8769 from the main CU (or replace it with a skeleton if necessary). */
8770 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
8771 type_node
->skeleton_die
= replacement
;
8773 /* Add the DIE to the new compunit. */
8774 add_child_die (unit
, c
);
8776 /* Types can reference DWARF procedures for type size or data location
8777 expressions. Calls in DWARF expressions cannot target procedures
8778 that are not in the same section. So we must copy DWARF procedures
8779 along with this type and then rewrite references to them. */
8780 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
8781 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
8783 if (replacement
!= NULL
)
8786 else if (c
->die_tag
== DW_TAG_namespace
8787 || c
->die_tag
== DW_TAG_class_type
8788 || c
->die_tag
== DW_TAG_structure_type
8789 || c
->die_tag
== DW_TAG_union_type
)
8791 /* Look for nested types that can be broken out. */
8792 break_out_comdat_types (c
);
8794 } while (next
!= NULL
);
8797 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8798 Enter all the cloned children into the hash table decl_table. */
8801 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
8805 struct decl_table_entry
*entry
;
8806 decl_table_entry
**slot
;
8808 if (die
->die_tag
== DW_TAG_subprogram
)
8809 clone
= clone_as_declaration (die
);
8811 clone
= clone_die (die
);
8813 slot
= decl_table
->find_slot_with_hash (die
,
8814 htab_hash_pointer (die
), INSERT
);
8816 /* Assert that DIE isn't in the hash table yet. If it would be there
8817 before, the ancestors would be necessarily there as well, therefore
8818 clone_tree_partial wouldn't be called. */
8819 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8821 entry
= XCNEW (struct decl_table_entry
);
8823 entry
->copy
= clone
;
8826 if (die
->die_tag
!= DW_TAG_subprogram
)
8827 FOR_EACH_CHILD (die
, c
,
8828 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
8833 /* Walk the DIE and its children, looking for references to incomplete
8834 or trivial types that are unmarked (i.e., that are not in the current
8838 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
8844 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8846 if (AT_class (a
) == dw_val_class_die_ref
)
8848 dw_die_ref targ
= AT_ref (a
);
8849 decl_table_entry
**slot
;
8850 struct decl_table_entry
*entry
;
8852 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
8855 slot
= decl_table
->find_slot_with_hash (targ
,
8856 htab_hash_pointer (targ
),
8859 if (*slot
!= HTAB_EMPTY_ENTRY
)
8861 /* TARG has already been copied, so we just need to
8862 modify the reference to point to the copy. */
8864 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
8868 dw_die_ref parent
= unit
;
8869 dw_die_ref copy
= clone_die (targ
);
8871 /* Record in DECL_TABLE that TARG has been copied.
8872 Need to do this now, before the recursive call,
8873 because DECL_TABLE may be expanded and SLOT
8874 would no longer be a valid pointer. */
8875 entry
= XCNEW (struct decl_table_entry
);
8880 /* If TARG is not a declaration DIE, we need to copy its
8882 if (!is_declaration_die (targ
))
8886 add_child_die (copy
,
8887 clone_tree_partial (c
, decl_table
)));
8890 /* Make sure the cloned tree is marked as part of the
8894 /* If TARG has surrounding context, copy its ancestor tree
8895 into the new type unit. */
8896 if (targ
->die_parent
!= NULL
8897 && !is_unit_die (targ
->die_parent
))
8898 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8901 add_child_die (parent
, copy
);
8902 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8904 /* Make sure the newly-copied DIE is walked. If it was
8905 installed in a previously-added context, it won't
8906 get visited otherwise. */
8909 /* Find the highest point of the newly-added tree,
8910 mark each node along the way, and walk from there. */
8911 parent
->die_mark
= 1;
8912 while (parent
->die_parent
8913 && parent
->die_parent
->die_mark
== 0)
8915 parent
= parent
->die_parent
;
8916 parent
->die_mark
= 1;
8918 copy_decls_walk (unit
, parent
, decl_table
);
8924 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8927 /* Collect skeleton dies in DIE created by break_out_comdat_types already
8928 and record them in DECL_TABLE. */
8931 collect_skeleton_dies (dw_die_ref die
, decl_hash_type
*decl_table
)
8935 if (dw_attr_node
*a
= get_AT (die
, DW_AT_signature
))
8937 dw_die_ref targ
= AT_ref (a
);
8938 gcc_assert (targ
->die_mark
== 0 && targ
->comdat_type_p
);
8939 decl_table_entry
**slot
8940 = decl_table
->find_slot_with_hash (targ
,
8941 htab_hash_pointer (targ
),
8943 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8944 /* Record in DECL_TABLE that TARG has been already copied
8945 by remove_child_or_replace_with_skeleton. */
8946 decl_table_entry
*entry
= XCNEW (struct decl_table_entry
);
8951 FOR_EACH_CHILD (die
, c
, collect_skeleton_dies (c
, decl_table
));
8954 /* Copy declarations for "unworthy" types into the new comdat section.
8955 Incomplete types, modified types, and certain other types aren't broken
8956 out into comdat sections of their own, so they don't have a signature,
8957 and we need to copy the declaration into the same section so that we
8958 don't have an external reference. */
8961 copy_decls_for_unworthy_types (dw_die_ref unit
)
8964 decl_hash_type
decl_table (10);
8965 collect_skeleton_dies (unit
, &decl_table
);
8966 copy_decls_walk (unit
, unit
, &decl_table
);
8970 /* Traverse the DIE and add a sibling attribute if it may have the
8971 effect of speeding up access to siblings. To save some space,
8972 avoid generating sibling attributes for DIE's without children. */
8975 add_sibling_attributes (dw_die_ref die
)
8979 if (! die
->die_child
)
8982 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8983 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8985 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8988 /* Output all location lists for the DIE and its children. */
8991 output_location_lists (dw_die_ref die
)
8997 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8998 if (AT_class (a
) == dw_val_class_loc_list
)
8999 output_loc_list (AT_loc_list (a
));
9001 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
9004 /* During assign_location_list_indexes and output_loclists_offset the
9005 current index, after it the number of assigned indexes (i.e. how
9006 large the .debug_loclists* offset table should be). */
9007 static unsigned int loc_list_idx
;
9009 /* Output all location list offsets for the DIE and its children. */
9012 output_loclists_offsets (dw_die_ref die
)
9018 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9019 if (AT_class (a
) == dw_val_class_loc_list
)
9021 dw_loc_list_ref l
= AT_loc_list (a
);
9022 if (l
->offset_emitted
)
9024 dw2_asm_output_delta (dwarf_offset_size
, l
->ll_symbol
,
9025 loc_section_label
, NULL
);
9026 gcc_assert (l
->hash
== loc_list_idx
);
9028 l
->offset_emitted
= true;
9031 FOR_EACH_CHILD (die
, c
, output_loclists_offsets (c
));
9034 /* Recursively set indexes of location lists. */
9037 assign_location_list_indexes (dw_die_ref die
)
9043 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9044 if (AT_class (a
) == dw_val_class_loc_list
)
9046 dw_loc_list_ref list
= AT_loc_list (a
);
9047 if (!list
->num_assigned
)
9049 list
->num_assigned
= true;
9050 list
->hash
= loc_list_idx
++;
9054 FOR_EACH_CHILD (die
, c
, assign_location_list_indexes (c
));
9057 /* We want to limit the number of external references, because they are
9058 larger than local references: a relocation takes multiple words, and
9059 even a sig8 reference is always eight bytes, whereas a local reference
9060 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
9061 So if we encounter multiple external references to the same type DIE, we
9062 make a local typedef stub for it and redirect all references there.
9064 This is the element of the hash table for keeping track of these
9074 /* Hashtable helpers. */
9076 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
9078 static inline hashval_t
hash (const external_ref
*);
9079 static inline bool equal (const external_ref
*, const external_ref
*);
9083 external_ref_hasher::hash (const external_ref
*r
)
9085 dw_die_ref die
= r
->type
;
9088 /* We can't use the address of the DIE for hashing, because
9089 that will make the order of the stub DIEs non-deterministic. */
9090 if (! die
->comdat_type_p
)
9091 /* We have a symbol; use it to compute a hash. */
9092 h
= htab_hash_string (die
->die_id
.die_symbol
);
9095 /* We have a type signature; use a subset of the bits as the hash.
9096 The 8-byte signature is at least as large as hashval_t. */
9097 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
9098 memcpy (&h
, type_node
->signature
, sizeof (h
));
9104 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
9106 return r1
->type
== r2
->type
;
9109 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
9111 /* Return a pointer to the external_ref for references to DIE. */
9113 static struct external_ref
*
9114 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
9116 struct external_ref ref
, *ref_p
;
9117 external_ref
**slot
;
9120 slot
= map
->find_slot (&ref
, INSERT
);
9121 if (*slot
!= HTAB_EMPTY_ENTRY
)
9124 ref_p
= XCNEW (struct external_ref
);
9130 /* Subroutine of optimize_external_refs, below.
9132 If we see a type skeleton, record it as our stub. If we see external
9133 references, remember how many we've seen. */
9136 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
9141 struct external_ref
*ref_p
;
9143 if (is_type_die (die
)
9144 && (c
= get_AT_ref (die
, DW_AT_signature
)))
9146 /* This is a local skeleton; use it for local references. */
9147 ref_p
= lookup_external_ref (map
, c
);
9151 /* Scan the DIE references, and remember any that refer to DIEs from
9152 other CUs (i.e. those which are not marked). */
9153 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9154 if (AT_class (a
) == dw_val_class_die_ref
9155 && (c
= AT_ref (a
))->die_mark
== 0
9158 ref_p
= lookup_external_ref (map
, c
);
9162 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
9165 /* htab_traverse callback function for optimize_external_refs, below. SLOT
9166 points to an external_ref, DATA is the CU we're processing. If we don't
9167 already have a local stub, and we have multiple refs, build a stub. */
9170 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
9172 struct external_ref
*ref_p
= *slot
;
9174 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
9176 /* We have multiple references to this type, so build a small stub.
9177 Both of these forms are a bit dodgy from the perspective of the
9178 DWARF standard, since technically they should have names. */
9179 dw_die_ref cu
= data
;
9180 dw_die_ref type
= ref_p
->type
;
9181 dw_die_ref stub
= NULL
;
9183 if (type
->comdat_type_p
)
9185 /* If we refer to this type via sig8, use AT_signature. */
9186 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
9187 add_AT_die_ref (stub
, DW_AT_signature
, type
);
9191 /* Otherwise, use a typedef with no name. */
9192 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
9193 add_AT_die_ref (stub
, DW_AT_type
, type
);
9202 /* DIE is a unit; look through all the DIE references to see if there are
9203 any external references to types, and if so, create local stubs for
9204 them which will be applied in build_abbrev_table. This is useful because
9205 references to local DIEs are smaller. */
9207 static external_ref_hash_type
*
9208 optimize_external_refs (dw_die_ref die
)
9210 external_ref_hash_type
*map
= new external_ref_hash_type (10);
9211 optimize_external_refs_1 (die
, map
);
9212 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
9216 /* The following 3 variables are temporaries that are computed only during the
9217 build_abbrev_table call and used and released during the following
9218 optimize_abbrev_table call. */
9220 /* First abbrev_id that can be optimized based on usage. */
9221 static unsigned int abbrev_opt_start
;
9223 /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
9224 abbrev_id smaller than this, because they must be already sized
9225 during build_abbrev_table). */
9226 static unsigned int abbrev_opt_base_type_end
;
9228 /* Vector of usage counts during build_abbrev_table. Indexed by
9229 abbrev_id - abbrev_opt_start. */
9230 static vec
<unsigned int> abbrev_usage_count
;
9232 /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
9233 static vec
<dw_die_ref
> sorted_abbrev_dies
;
9235 /* The format of each DIE (and its attribute value pairs) is encoded in an
9236 abbreviation table. This routine builds the abbreviation table and assigns
9237 a unique abbreviation id for each abbreviation entry. The children of each
9238 die are visited recursively. */
9241 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
9243 unsigned int abbrev_id
= 0;
9249 /* Scan the DIE references, and replace any that refer to
9250 DIEs from other CUs (i.e. those which are not marked) with
9251 the local stubs we built in optimize_external_refs. */
9252 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9253 if (AT_class (a
) == dw_val_class_die_ref
9254 && (c
= AT_ref (a
))->die_mark
== 0)
9256 struct external_ref
*ref_p
;
9257 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
9260 && (ref_p
= lookup_external_ref (extern_map
, c
))
9261 && ref_p
->stub
&& ref_p
->stub
!= die
)
9263 gcc_assert (a
->dw_attr
!= DW_AT_signature
);
9264 change_AT_die_ref (a
, ref_p
->stub
);
9267 /* We aren't changing this reference, so mark it external. */
9268 set_AT_ref_external (a
, 1);
9271 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
9273 dw_attr_node
*die_a
, *abbrev_a
;
9279 if (abbrev
->die_tag
!= die
->die_tag
)
9281 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
9284 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
9287 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
9289 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
9290 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
9291 || (value_format (abbrev_a
) != value_format (die_a
)))
9301 if (abbrev_id
>= vec_safe_length (abbrev_die_table
))
9303 vec_safe_push (abbrev_die_table
, die
);
9304 if (abbrev_opt_start
)
9305 abbrev_usage_count
.safe_push (0);
9307 if (abbrev_opt_start
&& abbrev_id
>= abbrev_opt_start
)
9309 abbrev_usage_count
[abbrev_id
- abbrev_opt_start
]++;
9310 sorted_abbrev_dies
.safe_push (die
);
9313 die
->die_abbrev
= abbrev_id
;
9314 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
9317 /* Callback function for sorted_abbrev_dies vector sorting. We sort
9318 by die_abbrev's usage count, from the most commonly used
9319 abbreviation to the least. */
9322 die_abbrev_cmp (const void *p1
, const void *p2
)
9324 dw_die_ref die1
= *(const dw_die_ref
*) p1
;
9325 dw_die_ref die2
= *(const dw_die_ref
*) p2
;
9327 gcc_checking_assert (die1
->die_abbrev
>= abbrev_opt_start
);
9328 gcc_checking_assert (die2
->die_abbrev
>= abbrev_opt_start
);
9330 if (die1
->die_abbrev
>= abbrev_opt_base_type_end
9331 && die2
->die_abbrev
>= abbrev_opt_base_type_end
)
9333 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
9334 > abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
9336 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
9337 < abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
9341 /* Stabilize the sort. */
9342 if (die1
->die_abbrev
< die2
->die_abbrev
)
9344 if (die1
->die_abbrev
> die2
->die_abbrev
)
9350 /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
9351 of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
9352 into dw_val_class_const_implicit or
9353 dw_val_class_unsigned_const_implicit. */
9356 optimize_implicit_const (unsigned int first_id
, unsigned int end
,
9357 vec
<bool> &implicit_consts
)
9359 /* It never makes sense if there is just one DIE using the abbreviation. */
9360 if (end
< first_id
+ 2)
9365 dw_die_ref die
= sorted_abbrev_dies
[first_id
];
9366 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9367 if (implicit_consts
[ix
])
9369 enum dw_val_class new_class
= dw_val_class_none
;
9370 switch (AT_class (a
))
9372 case dw_val_class_unsigned_const
:
9373 if ((HOST_WIDE_INT
) AT_unsigned (a
) < 0)
9376 /* The .debug_abbrev section will grow by
9377 size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
9378 in all the DIEs using that abbreviation. */
9379 if (constant_size (AT_unsigned (a
)) * (end
- first_id
)
9380 <= (unsigned) size_of_sleb128 (AT_unsigned (a
)))
9383 new_class
= dw_val_class_unsigned_const_implicit
;
9386 case dw_val_class_const
:
9387 new_class
= dw_val_class_const_implicit
;
9390 case dw_val_class_file
:
9391 new_class
= dw_val_class_file_implicit
;
9397 for (i
= first_id
; i
< end
; i
++)
9398 (*sorted_abbrev_dies
[i
]->die_attr
)[ix
].dw_attr_val
.val_class
9403 /* Attempt to optimize abbreviation table from abbrev_opt_start
9404 abbreviation above. */
9407 optimize_abbrev_table (void)
9409 if (abbrev_opt_start
9410 && vec_safe_length (abbrev_die_table
) > abbrev_opt_start
9411 && (dwarf_version
>= 5 || vec_safe_length (abbrev_die_table
) > 127))
9413 auto_vec
<bool, 32> implicit_consts
;
9414 sorted_abbrev_dies
.qsort (die_abbrev_cmp
);
9416 unsigned int abbrev_id
= abbrev_opt_start
- 1;
9417 unsigned int first_id
= ~0U;
9418 unsigned int last_abbrev_id
= 0;
9421 if (abbrev_opt_base_type_end
> abbrev_opt_start
)
9422 abbrev_id
= abbrev_opt_base_type_end
- 1;
9423 /* Reassign abbreviation ids from abbrev_opt_start above, so that
9424 most commonly used abbreviations come first. */
9425 FOR_EACH_VEC_ELT (sorted_abbrev_dies
, i
, die
)
9430 /* If calc_base_type_die_sizes has been called, the CU and
9431 base types after it can't be optimized, because we've already
9432 calculated their DIE offsets. We've sorted them first. */
9433 if (die
->die_abbrev
< abbrev_opt_base_type_end
)
9435 if (die
->die_abbrev
!= last_abbrev_id
)
9437 last_abbrev_id
= die
->die_abbrev
;
9438 if (dwarf_version
>= 5 && first_id
!= ~0U)
9439 optimize_implicit_const (first_id
, i
, implicit_consts
);
9441 (*abbrev_die_table
)[abbrev_id
] = die
;
9442 if (dwarf_version
>= 5)
9445 implicit_consts
.truncate (0);
9447 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9448 switch (AT_class (a
))
9450 case dw_val_class_const
:
9451 case dw_val_class_unsigned_const
:
9452 case dw_val_class_file
:
9453 implicit_consts
.safe_push (true);
9456 implicit_consts
.safe_push (false);
9461 else if (dwarf_version
>= 5)
9463 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9464 if (!implicit_consts
[ix
])
9468 dw_attr_node
*other_a
9469 = &(*(*abbrev_die_table
)[abbrev_id
]->die_attr
)[ix
];
9470 if (!dw_val_equal_p (&a
->dw_attr_val
,
9471 &other_a
->dw_attr_val
))
9472 implicit_consts
[ix
] = false;
9475 die
->die_abbrev
= abbrev_id
;
9477 gcc_assert (abbrev_id
== vec_safe_length (abbrev_die_table
) - 1);
9478 if (dwarf_version
>= 5 && first_id
!= ~0U)
9479 optimize_implicit_const (first_id
, i
, implicit_consts
);
9482 abbrev_opt_start
= 0;
9483 abbrev_opt_base_type_end
= 0;
9484 abbrev_usage_count
.release ();
9485 sorted_abbrev_dies
.release ();
9488 /* Return the power-of-two number of bytes necessary to represent VALUE. */
9491 constant_size (unsigned HOST_WIDE_INT value
)
9498 log
= floor_log2 (value
);
9501 log
= 1 << (floor_log2 (log
) + 1);
9506 /* Return the size of a DIE as it is represented in the
9507 .debug_info section. */
9509 static unsigned long
9510 size_of_die (dw_die_ref die
)
9512 unsigned long size
= 0;
9515 enum dwarf_form form
;
9517 size
+= size_of_uleb128 (die
->die_abbrev
);
9518 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9520 switch (AT_class (a
))
9522 case dw_val_class_addr
:
9523 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9525 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9526 size
+= size_of_uleb128 (AT_index (a
));
9529 size
+= DWARF2_ADDR_SIZE
;
9531 case dw_val_class_offset
:
9532 size
+= dwarf_offset_size
;
9534 case dw_val_class_loc
:
9536 unsigned long lsize
= size_of_locs (AT_loc (a
));
9539 if (dwarf_version
>= 4)
9540 size
+= size_of_uleb128 (lsize
);
9542 size
+= constant_size (lsize
);
9546 case dw_val_class_loc_list
:
9547 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
9549 gcc_assert (AT_loc_list (a
)->num_assigned
);
9550 size
+= size_of_uleb128 (AT_loc_list (a
)->hash
);
9553 size
+= dwarf_offset_size
;
9555 case dw_val_class_view_list
:
9556 size
+= dwarf_offset_size
;
9558 case dw_val_class_range_list
:
9559 if (value_format (a
) == DW_FORM_rnglistx
)
9561 gcc_assert (rnglist_idx
);
9562 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9563 size
+= size_of_uleb128 (r
->idx
);
9566 size
+= dwarf_offset_size
;
9568 case dw_val_class_const
:
9569 size
+= size_of_sleb128 (AT_int (a
));
9571 case dw_val_class_unsigned_const
:
9573 int csize
= constant_size (AT_unsigned (a
));
9574 if (dwarf_version
== 3
9575 && a
->dw_attr
== DW_AT_data_member_location
9577 size
+= size_of_uleb128 (AT_unsigned (a
));
9582 case dw_val_class_symview
:
9583 if (symview_upper_bound
<= 0xff)
9585 else if (symview_upper_bound
<= 0xffff)
9587 else if (symview_upper_bound
<= 0xffffffff)
9592 case dw_val_class_const_implicit
:
9593 case dw_val_class_unsigned_const_implicit
:
9594 case dw_val_class_file_implicit
:
9595 /* These occupy no size in the DIE, just an extra sleb128 in
9598 case dw_val_class_const_double
:
9599 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
9600 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
9603 case dw_val_class_wide_int
:
9604 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9605 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
9606 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9607 * HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
9610 case dw_val_class_vec
:
9611 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
9612 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
9613 + a
->dw_attr_val
.v
.val_vec
.length
9614 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
9616 case dw_val_class_flag
:
9617 if (dwarf_version
>= 4)
9618 /* Currently all add_AT_flag calls pass in 1 as last argument,
9619 so DW_FORM_flag_present can be used. If that ever changes,
9620 we'll need to use DW_FORM_flag and have some optimization
9621 in build_abbrev_table that will change those to
9622 DW_FORM_flag_present if it is set to 1 in all DIEs using
9623 the same abbrev entry. */
9624 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9628 case dw_val_class_die_ref
:
9629 if (AT_ref_external (a
))
9631 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
9632 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
9633 is sized by target address length, whereas in DWARF3
9634 it's always sized as an offset. */
9635 if (AT_ref (a
)->comdat_type_p
)
9636 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
9637 else if (dwarf_version
== 2)
9638 size
+= DWARF2_ADDR_SIZE
;
9640 size
+= dwarf_offset_size
;
9643 size
+= dwarf_offset_size
;
9645 case dw_val_class_fde_ref
:
9646 size
+= dwarf_offset_size
;
9648 case dw_val_class_lbl_id
:
9649 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9651 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9652 size
+= size_of_uleb128 (AT_index (a
));
9655 size
+= DWARF2_ADDR_SIZE
;
9657 case dw_val_class_lineptr
:
9658 case dw_val_class_macptr
:
9659 case dw_val_class_loclistsptr
:
9660 size
+= dwarf_offset_size
;
9662 case dw_val_class_str
:
9663 form
= AT_string_form (a
);
9664 if (form
== DW_FORM_strp
|| form
== DW_FORM_line_strp
)
9665 size
+= dwarf_offset_size
;
9666 else if (form
== dwarf_FORM (DW_FORM_strx
))
9667 size
+= size_of_uleb128 (AT_index (a
));
9669 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
9671 case dw_val_class_file
:
9672 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
9674 case dw_val_class_data8
:
9677 case dw_val_class_vms_delta
:
9678 size
+= dwarf_offset_size
;
9680 case dw_val_class_high_pc
:
9681 size
+= DWARF2_ADDR_SIZE
;
9683 case dw_val_class_discr_value
:
9684 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
9686 case dw_val_class_discr_list
:
9688 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
9690 /* This is a block, so we have the block length and then its
9692 size
+= constant_size (block_size
) + block_size
;
9703 /* Size the debugging information associated with a given DIE. Visits the
9704 DIE's children recursively. Updates the global variable next_die_offset, on
9705 each time through. Uses the current value of next_die_offset to update the
9706 die_offset field in each DIE. */
9709 calc_die_sizes (dw_die_ref die
)
9713 gcc_assert (die
->die_offset
== 0
9714 || (unsigned long int) die
->die_offset
== next_die_offset
);
9715 die
->die_offset
= next_die_offset
;
9716 next_die_offset
+= size_of_die (die
);
9718 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
9720 if (die
->die_child
!= NULL
)
9721 /* Count the null byte used to terminate sibling lists. */
9722 next_die_offset
+= 1;
9725 /* Size just the base type children at the start of the CU.
9726 This is needed because build_abbrev needs to size locs
9727 and sizing of type based stack ops needs to know die_offset
9728 values for the base types. */
9731 calc_base_type_die_sizes (void)
9733 unsigned long die_offset
= (dwarf_split_debug_info
9734 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9735 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
9737 dw_die_ref base_type
;
9738 #if ENABLE_ASSERT_CHECKING
9739 dw_die_ref prev
= comp_unit_die ()->die_child
;
9742 die_offset
+= size_of_die (comp_unit_die ());
9743 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
9745 #if ENABLE_ASSERT_CHECKING
9746 gcc_assert (base_type
->die_offset
== 0
9747 && prev
->die_sib
== base_type
9748 && base_type
->die_child
== NULL
9749 && base_type
->die_abbrev
);
9752 if (abbrev_opt_start
9753 && base_type
->die_abbrev
>= abbrev_opt_base_type_end
)
9754 abbrev_opt_base_type_end
= base_type
->die_abbrev
+ 1;
9755 base_type
->die_offset
= die_offset
;
9756 die_offset
+= size_of_die (base_type
);
9760 /* Set the marks for a die and its children. We do this so
9761 that we know whether or not a reference needs to use FORM_ref_addr; only
9762 DIEs in the same CU will be marked. We used to clear out the offset
9763 and use that as the flag, but ran into ordering problems. */
9766 mark_dies (dw_die_ref die
)
9770 gcc_assert (!die
->die_mark
);
9773 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
9776 /* Clear the marks for a die and its children. */
9779 unmark_dies (dw_die_ref die
)
9783 if (! use_debug_types
)
9784 gcc_assert (die
->die_mark
);
9787 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
9790 /* Clear the marks for a die, its children and referred dies. */
9793 unmark_all_dies (dw_die_ref die
)
9803 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
9805 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9806 if (AT_class (a
) == dw_val_class_die_ref
)
9807 unmark_all_dies (AT_ref (a
));
9810 /* Calculate if the entry should appear in the final output file. It may be
9811 from a pruned a type. */
9814 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
9816 /* By limiting gnu pubnames to definitions only, gold can generate a
9817 gdb index without entries for declarations, which don't include
9818 enough information to be useful. */
9819 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
9822 if (table
== pubname_table
)
9824 /* Enumerator names are part of the pubname table, but the
9825 parent DW_TAG_enumeration_type die may have been pruned.
9826 Don't output them if that is the case. */
9827 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
9828 (p
->die
->die_parent
== NULL
9829 || !p
->die
->die_parent
->die_perennial_p
))
9832 /* Everything else in the pubname table is included. */
9836 /* The pubtypes table shouldn't include types that have been
9838 return (p
->die
->die_offset
!= 0
9839 || !flag_eliminate_unused_debug_types
);
9842 /* Return the size of the .debug_pubnames or .debug_pubtypes table
9843 generated for the compilation unit. */
9845 static unsigned long
9846 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9851 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
9853 size
= DWARF_PUBNAMES_HEADER_SIZE
;
9854 FOR_EACH_VEC_ELT (*names
, i
, p
)
9855 if (include_pubname_in_output (names
, p
))
9856 size
+= strlen (p
->name
) + dwarf_offset_size
+ 1 + space_for_flags
;
9858 size
+= dwarf_offset_size
;
9862 /* Return the size of the information in the .debug_aranges section. */
9864 static unsigned long
9865 size_of_aranges (void)
9869 size
= DWARF_ARANGES_HEADER_SIZE
;
9871 /* Count the address/length pair for this compilation unit. */
9872 if (switch_text_ranges
)
9873 size
+= 2 * DWARF2_ADDR_SIZE
9874 * (vec_safe_length (switch_text_ranges
) / 2 + 1);
9875 if (switch_cold_ranges
)
9876 size
+= 2 * DWARF2_ADDR_SIZE
9877 * (vec_safe_length (switch_cold_ranges
) / 2 + 1);
9878 if (have_multiple_function_sections
)
9883 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9885 if (fde
->ignored_debug
)
9887 if (!fde
->in_std_section
)
9888 size
+= 2 * DWARF2_ADDR_SIZE
;
9889 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9890 size
+= 2 * DWARF2_ADDR_SIZE
;
9894 /* Count the two zero words used to terminated the address range table. */
9895 size
+= 2 * DWARF2_ADDR_SIZE
;
9899 /* Select the encoding of an attribute value. */
9901 static enum dwarf_form
9902 value_format (dw_attr_node
*a
)
9904 switch (AT_class (a
))
9906 case dw_val_class_addr
:
9907 /* Only very few attributes allow DW_FORM_addr. */
9912 case DW_AT_entry_pc
:
9913 case DW_AT_trampoline
:
9914 return (AT_index (a
) == NOT_INDEXED
9915 ? DW_FORM_addr
: dwarf_FORM (DW_FORM_addrx
));
9919 switch (DWARF2_ADDR_SIZE
)
9922 return DW_FORM_data1
;
9924 return DW_FORM_data2
;
9926 return DW_FORM_data4
;
9928 return DW_FORM_data8
;
9932 case dw_val_class_loc_list
:
9933 if (dwarf_split_debug_info
9934 && dwarf_version
>= 5
9935 && AT_loc_list (a
)->num_assigned
)
9936 return DW_FORM_loclistx
;
9938 case dw_val_class_view_list
:
9939 case dw_val_class_range_list
:
9940 /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9941 but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9942 care about sizes of .debug* sections in shared libraries and
9943 executables and don't take into account relocations that affect just
9944 relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9945 table in the .debug_rnglists section. */
9946 if (dwarf_split_debug_info
9947 && dwarf_version
>= 5
9948 && AT_class (a
) == dw_val_class_range_list
9950 && a
->dw_attr_val
.val_entry
!= RELOCATED_OFFSET
)
9951 return DW_FORM_rnglistx
;
9952 if (dwarf_version
>= 4)
9953 return DW_FORM_sec_offset
;
9955 case dw_val_class_vms_delta
:
9956 case dw_val_class_offset
:
9957 switch (dwarf_offset_size
)
9960 return DW_FORM_data4
;
9962 return DW_FORM_data8
;
9966 case dw_val_class_loc
:
9967 if (dwarf_version
>= 4)
9968 return DW_FORM_exprloc
;
9969 switch (constant_size (size_of_locs (AT_loc (a
))))
9972 return DW_FORM_block1
;
9974 return DW_FORM_block2
;
9976 return DW_FORM_block4
;
9980 case dw_val_class_const
:
9981 return DW_FORM_sdata
;
9982 case dw_val_class_unsigned_const
:
9983 switch (constant_size (AT_unsigned (a
)))
9986 return DW_FORM_data1
;
9988 return DW_FORM_data2
;
9990 /* In DWARF3 DW_AT_data_member_location with
9991 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
9992 constant, so we need to use DW_FORM_udata if we need
9993 a large constant. */
9994 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9995 return DW_FORM_udata
;
9996 return DW_FORM_data4
;
9998 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9999 return DW_FORM_udata
;
10000 return DW_FORM_data8
;
10002 gcc_unreachable ();
10004 case dw_val_class_const_implicit
:
10005 case dw_val_class_unsigned_const_implicit
:
10006 case dw_val_class_file_implicit
:
10007 return DW_FORM_implicit_const
;
10008 case dw_val_class_const_double
:
10009 switch (HOST_BITS_PER_WIDE_INT
)
10012 return DW_FORM_data2
;
10014 return DW_FORM_data4
;
10016 return DW_FORM_data8
;
10018 if (dwarf_version
>= 5)
10019 return DW_FORM_data16
;
10022 return DW_FORM_block1
;
10024 case dw_val_class_wide_int
:
10025 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
10028 return DW_FORM_data1
;
10030 return DW_FORM_data2
;
10032 return DW_FORM_data4
;
10034 return DW_FORM_data8
;
10036 if (dwarf_version
>= 5)
10037 return DW_FORM_data16
;
10040 return DW_FORM_block1
;
10042 case dw_val_class_symview
:
10043 /* ??? We might use uleb128, but then we'd have to compute
10044 .debug_info offsets in the assembler. */
10045 if (symview_upper_bound
<= 0xff)
10046 return DW_FORM_data1
;
10047 else if (symview_upper_bound
<= 0xffff)
10048 return DW_FORM_data2
;
10049 else if (symview_upper_bound
<= 0xffffffff)
10050 return DW_FORM_data4
;
10052 return DW_FORM_data8
;
10053 case dw_val_class_vec
:
10054 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
10055 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
10058 return DW_FORM_block1
;
10060 return DW_FORM_block2
;
10062 return DW_FORM_block4
;
10064 gcc_unreachable ();
10066 case dw_val_class_flag
:
10067 if (dwarf_version
>= 4)
10069 /* Currently all add_AT_flag calls pass in 1 as last argument,
10070 so DW_FORM_flag_present can be used. If that ever changes,
10071 we'll need to use DW_FORM_flag and have some optimization
10072 in build_abbrev_table that will change those to
10073 DW_FORM_flag_present if it is set to 1 in all DIEs using
10074 the same abbrev entry. */
10075 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
10076 return DW_FORM_flag_present
;
10078 return DW_FORM_flag
;
10079 case dw_val_class_die_ref
:
10080 if (AT_ref_external (a
))
10082 if (AT_ref (a
)->comdat_type_p
)
10083 return DW_FORM_ref_sig8
;
10085 return DW_FORM_ref_addr
;
10088 return DW_FORM_ref
;
10089 case dw_val_class_fde_ref
:
10090 return DW_FORM_data
;
10091 case dw_val_class_lbl_id
:
10092 return (AT_index (a
) == NOT_INDEXED
10093 ? DW_FORM_addr
: dwarf_FORM (DW_FORM_addrx
));
10094 case dw_val_class_lineptr
:
10095 case dw_val_class_macptr
:
10096 case dw_val_class_loclistsptr
:
10097 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
10098 case dw_val_class_str
:
10099 return AT_string_form (a
);
10100 case dw_val_class_file
:
10101 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
10104 return DW_FORM_data1
;
10106 return DW_FORM_data2
;
10108 return DW_FORM_data4
;
10110 gcc_unreachable ();
10113 case dw_val_class_data8
:
10114 return DW_FORM_data8
;
10116 case dw_val_class_high_pc
:
10117 switch (DWARF2_ADDR_SIZE
)
10120 return DW_FORM_data1
;
10122 return DW_FORM_data2
;
10124 return DW_FORM_data4
;
10126 return DW_FORM_data8
;
10128 gcc_unreachable ();
10131 case dw_val_class_discr_value
:
10132 return (a
->dw_attr_val
.v
.val_discr_value
.pos
10135 case dw_val_class_discr_list
:
10136 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
10139 return DW_FORM_block1
;
10141 return DW_FORM_block2
;
10143 return DW_FORM_block4
;
10145 gcc_unreachable ();
10149 gcc_unreachable ();
10153 /* Output the encoding of an attribute value. */
10156 output_value_format (dw_attr_node
*a
)
10158 enum dwarf_form form
= value_format (a
);
10160 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
10163 /* Given a die and id, produce the appropriate abbreviations. */
10166 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
10169 dw_attr_node
*a_attr
;
10171 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
10172 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
10173 dwarf_tag_name (abbrev
->die_tag
));
10175 if (abbrev
->die_child
!= NULL
)
10176 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
10178 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
10180 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
10182 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
10183 dwarf_attr_name (a_attr
->dw_attr
));
10184 output_value_format (a_attr
);
10185 if (value_format (a_attr
) == DW_FORM_implicit_const
)
10187 if (AT_class (a_attr
) == dw_val_class_file_implicit
)
10189 int f
= maybe_emit_file (a_attr
->dw_attr_val
.v
.val_file
);
10190 const char *filename
= a_attr
->dw_attr_val
.v
.val_file
->filename
;
10191 dw2_asm_output_data_sleb128 (f
, "(%s)", filename
);
10194 dw2_asm_output_data_sleb128 (a_attr
->dw_attr_val
.v
.val_int
, NULL
);
10198 dw2_asm_output_data (1, 0, NULL
);
10199 dw2_asm_output_data (1, 0, NULL
);
10203 /* Output the .debug_abbrev section which defines the DIE abbreviation
10207 output_abbrev_section (void)
10209 unsigned int abbrev_id
;
10212 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
10213 if (abbrev_id
!= 0)
10214 output_die_abbrevs (abbrev_id
, abbrev
);
10216 /* Terminate the table. */
10217 dw2_asm_output_data (1, 0, NULL
);
10220 /* Return a new location list, given the begin and end range, and the
10223 static inline dw_loc_list_ref
10224 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, var_loc_view vbegin
,
10225 const char *end
, var_loc_view vend
,
10226 const char *section
)
10228 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
10230 retlist
->begin
= begin
;
10231 retlist
->begin_entry
= NULL
;
10232 retlist
->end
= end
;
10233 retlist
->end_entry
= NULL
;
10234 retlist
->expr
= expr
;
10235 retlist
->section
= section
;
10236 retlist
->vbegin
= vbegin
;
10237 retlist
->vend
= vend
;
10242 /* Return true iff there's any nonzero view number in the loc list.
10244 ??? When views are not enabled, we'll often extend a single range
10245 to the entire function, so that we emit a single location
10246 expression rather than a location list. With views, even with a
10247 single range, we'll output a list if start or end have a nonzero
10248 view. If we change this, we may want to stop splitting a single
10249 range in dw_loc_list just because of a nonzero view, even if it
10250 straddles across hot/cold partitions. */
10253 loc_list_has_views (dw_loc_list_ref list
)
10255 if (!debug_variable_location_views
)
10258 for (dw_loc_list_ref loc
= list
;
10259 loc
!= NULL
; loc
= loc
->dw_loc_next
)
10260 if (!ZERO_VIEW_P (loc
->vbegin
) || !ZERO_VIEW_P (loc
->vend
))
10266 /* Generate a new internal symbol for this location list node, if it
10267 hasn't got one yet. */
10270 gen_llsym (dw_loc_list_ref list
)
10272 gcc_assert (!list
->ll_symbol
);
10273 list
->ll_symbol
= gen_internal_sym ("LLST");
10275 if (!loc_list_has_views (list
))
10278 if (dwarf2out_locviews_in_attribute ())
10280 /* Use the same label_num for the view list. */
10282 list
->vl_symbol
= gen_internal_sym ("LVUS");
10285 list
->vl_symbol
= list
->ll_symbol
;
10288 /* Generate a symbol for the list, but only if we really want to emit
10292 maybe_gen_llsym (dw_loc_list_ref list
)
10294 if (!list
|| (!list
->dw_loc_next
&& !loc_list_has_views (list
)))
10300 /* Determine whether or not to skip loc_list entry CURR. If SIZEP is
10301 NULL, don't consider size of the location expression. If we're not
10302 to skip it, and SIZEP is non-null, store the size of CURR->expr's
10303 representation in *SIZEP. */
10306 skip_loc_list_entry (dw_loc_list_ref curr
, unsigned long *sizep
= NULL
)
10308 /* Don't output an entry that starts and ends at the same address. */
10309 if (strcmp (curr
->begin
, curr
->end
) == 0
10310 && curr
->vbegin
== curr
->vend
&& !curr
->force
)
10316 unsigned long size
= size_of_locs (curr
->expr
);
10318 /* If the expression is too large, drop it on the floor. We could
10319 perhaps put it into DW_TAG_dwarf_procedure and refer to that
10320 in the expression, but >= 64KB expressions for a single value
10321 in a single range are unlikely very useful. */
10322 if (dwarf_version
< 5 && size
> 0xffff)
10330 /* Output a view pair loclist entry for CURR, if it requires one. */
10333 dwarf2out_maybe_output_loclist_view_pair (dw_loc_list_ref curr
)
10335 if (!dwarf2out_locviews_in_loclist ())
10338 if (ZERO_VIEW_P (curr
->vbegin
) && ZERO_VIEW_P (curr
->vend
))
10341 #ifdef DW_LLE_view_pair
10342 dw2_asm_output_data (1, DW_LLE_view_pair
, "DW_LLE_view_pair");
10344 if (dwarf2out_as_locview_support
)
10346 if (ZERO_VIEW_P (curr
->vbegin
))
10347 dw2_asm_output_data_uleb128 (0, "Location view begin");
10350 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10351 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vbegin
);
10352 dw2_asm_output_symname_uleb128 (label
, "Location view begin");
10355 if (ZERO_VIEW_P (curr
->vend
))
10356 dw2_asm_output_data_uleb128 (0, "Location view end");
10359 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10360 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vend
);
10361 dw2_asm_output_symname_uleb128 (label
, "Location view end");
10366 dw2_asm_output_data_uleb128 (curr
->vbegin
, "Location view begin");
10367 dw2_asm_output_data_uleb128 (curr
->vend
, "Location view end");
10369 #endif /* DW_LLE_view_pair */
10374 /* Output the location list given to us. */
10377 output_loc_list (dw_loc_list_ref list_head
)
10379 int vcount
= 0, lcount
= 0;
10381 if (list_head
->emitted
)
10383 list_head
->emitted
= true;
10385 if (list_head
->vl_symbol
&& dwarf2out_locviews_in_attribute ())
10387 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->vl_symbol
);
10389 for (dw_loc_list_ref curr
= list_head
; curr
!= NULL
;
10390 curr
= curr
->dw_loc_next
)
10392 unsigned long size
;
10394 if (skip_loc_list_entry (curr
, &size
))
10399 /* ?? dwarf_split_debug_info? */
10400 if (dwarf2out_as_locview_support
)
10402 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10404 if (!ZERO_VIEW_P (curr
->vbegin
))
10406 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vbegin
);
10407 dw2_asm_output_symname_uleb128 (label
,
10408 "View list begin (%s)",
10409 list_head
->vl_symbol
);
10412 dw2_asm_output_data_uleb128 (0,
10413 "View list begin (%s)",
10414 list_head
->vl_symbol
);
10416 if (!ZERO_VIEW_P (curr
->vend
))
10418 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vend
);
10419 dw2_asm_output_symname_uleb128 (label
,
10420 "View list end (%s)",
10421 list_head
->vl_symbol
);
10424 dw2_asm_output_data_uleb128 (0,
10425 "View list end (%s)",
10426 list_head
->vl_symbol
);
10430 dw2_asm_output_data_uleb128 (curr
->vbegin
,
10431 "View list begin (%s)",
10432 list_head
->vl_symbol
);
10433 dw2_asm_output_data_uleb128 (curr
->vend
,
10434 "View list end (%s)",
10435 list_head
->vl_symbol
);
10440 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
10442 const char *last_section
= NULL
;
10443 const char *base_label
= NULL
;
10445 /* Walk the location list, and output each range + expression. */
10446 for (dw_loc_list_ref curr
= list_head
; curr
!= NULL
;
10447 curr
= curr
->dw_loc_next
)
10449 unsigned long size
;
10451 /* Skip this entry? If we skip it here, we must skip it in the
10452 view list above as well. */
10453 if (skip_loc_list_entry (curr
, &size
))
10458 if (dwarf_version
>= 5)
10460 if (dwarf_split_debug_info
&& HAVE_AS_LEB128
)
10462 dwarf2out_maybe_output_loclist_view_pair (curr
);
10463 /* For -gsplit-dwarf, emit DW_LLE_startx_length, which has
10464 uleb128 index into .debug_addr and uleb128 length. */
10465 dw2_asm_output_data (1, DW_LLE_startx_length
,
10466 "DW_LLE_startx_length (%s)",
10467 list_head
->ll_symbol
);
10468 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
10469 "Location list range start index "
10470 "(%s)", curr
->begin
);
10471 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
10472 "Location list length (%s)",
10473 list_head
->ll_symbol
);
10475 else if (dwarf_split_debug_info
)
10477 dwarf2out_maybe_output_loclist_view_pair (curr
);
10478 /* For -gsplit-dwarf without usable .uleb128 support, emit
10479 DW_LLE_startx_endx, which has two uleb128 indexes into
10481 dw2_asm_output_data (1, DW_LLE_startx_endx
,
10482 "DW_LLE_startx_endx (%s)",
10483 list_head
->ll_symbol
);
10484 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
10485 "Location list range start index "
10486 "(%s)", curr
->begin
);
10487 dw2_asm_output_data_uleb128 (curr
->end_entry
->index
,
10488 "Location list range end index "
10489 "(%s)", curr
->end
);
10491 else if (!have_multiple_function_sections
&& HAVE_AS_LEB128
)
10493 dwarf2out_maybe_output_loclist_view_pair (curr
);
10494 /* If all code is in .text section, the base address is
10495 already provided by the CU attributes. Use
10496 DW_LLE_offset_pair where both addresses are uleb128 encoded
10497 offsets against that base. */
10498 dw2_asm_output_data (1, DW_LLE_offset_pair
,
10499 "DW_LLE_offset_pair (%s)",
10500 list_head
->ll_symbol
);
10501 dw2_asm_output_delta_uleb128 (curr
->begin
, curr
->section
,
10502 "Location list begin address (%s)",
10503 list_head
->ll_symbol
);
10504 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->section
,
10505 "Location list end address (%s)",
10506 list_head
->ll_symbol
);
10508 else if (HAVE_AS_LEB128
)
10510 /* Otherwise, find out how many consecutive entries could share
10511 the same base entry. If just one, emit DW_LLE_start_length,
10512 otherwise emit DW_LLE_base_address for the base address
10513 followed by a series of DW_LLE_offset_pair. */
10514 if (last_section
== NULL
|| curr
->section
!= last_section
)
10516 dw_loc_list_ref curr2
;
10517 for (curr2
= curr
->dw_loc_next
; curr2
!= NULL
;
10518 curr2
= curr2
->dw_loc_next
)
10520 if (strcmp (curr2
->begin
, curr2
->end
) == 0
10525 if (curr2
== NULL
|| curr
->section
!= curr2
->section
)
10526 last_section
= NULL
;
10529 last_section
= curr
->section
;
10530 base_label
= curr
->begin
;
10531 dw2_asm_output_data (1, DW_LLE_base_address
,
10532 "DW_LLE_base_address (%s)",
10533 list_head
->ll_symbol
);
10534 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, base_label
,
10535 "Base address (%s)",
10536 list_head
->ll_symbol
);
10539 /* Only one entry with the same base address. Use
10540 DW_LLE_start_length with absolute address and uleb128
10542 if (last_section
== NULL
)
10544 dwarf2out_maybe_output_loclist_view_pair (curr
);
10545 dw2_asm_output_data (1, DW_LLE_start_length
,
10546 "DW_LLE_start_length (%s)",
10547 list_head
->ll_symbol
);
10548 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10549 "Location list begin address (%s)",
10550 list_head
->ll_symbol
);
10551 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
10552 "Location list length "
10553 "(%s)", list_head
->ll_symbol
);
10555 /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
10556 DW_LLE_base_address. */
10559 dwarf2out_maybe_output_loclist_view_pair (curr
);
10560 dw2_asm_output_data (1, DW_LLE_offset_pair
,
10561 "DW_LLE_offset_pair (%s)",
10562 list_head
->ll_symbol
);
10563 dw2_asm_output_delta_uleb128 (curr
->begin
, base_label
,
10564 "Location list begin address "
10565 "(%s)", list_head
->ll_symbol
);
10566 dw2_asm_output_delta_uleb128 (curr
->end
, base_label
,
10567 "Location list end address "
10568 "(%s)", list_head
->ll_symbol
);
10571 /* The assembler does not support .uleb128 directive. Emit
10572 DW_LLE_start_end with a pair of absolute addresses. */
10575 dwarf2out_maybe_output_loclist_view_pair (curr
);
10576 dw2_asm_output_data (1, DW_LLE_start_end
,
10577 "DW_LLE_start_end (%s)",
10578 list_head
->ll_symbol
);
10579 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10580 "Location list begin address (%s)",
10581 list_head
->ll_symbol
);
10582 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
10583 "Location list end address (%s)",
10584 list_head
->ll_symbol
);
10587 else if (dwarf_split_debug_info
)
10589 /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
10590 and 4 byte length. */
10591 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
10592 "Location list start/length entry (%s)",
10593 list_head
->ll_symbol
);
10594 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
10595 "Location list range start index (%s)",
10597 /* The length field is 4 bytes. If we ever need to support
10598 an 8-byte length, we can add a new DW_LLE code or fall back
10599 to DW_LLE_GNU_start_end_entry. */
10600 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
10601 "Location list range length (%s)",
10602 list_head
->ll_symbol
);
10604 else if (!have_multiple_function_sections
)
10606 /* Pair of relative addresses against start of text section. */
10607 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
10608 "Location list begin address (%s)",
10609 list_head
->ll_symbol
);
10610 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
10611 "Location list end address (%s)",
10612 list_head
->ll_symbol
);
10616 /* Pair of absolute addresses. */
10617 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10618 "Location list begin address (%s)",
10619 list_head
->ll_symbol
);
10620 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
10621 "Location list end address (%s)",
10622 list_head
->ll_symbol
);
10625 /* Output the block length for this list of location operations. */
10626 if (dwarf_version
>= 5)
10627 dw2_asm_output_data_uleb128 (size
, "Location expression size");
10630 gcc_assert (size
<= 0xffff);
10631 dw2_asm_output_data (2, size
, "Location expression size");
10634 output_loc_sequence (curr
->expr
, -1);
10637 /* And finally list termination. */
10638 if (dwarf_version
>= 5)
10639 dw2_asm_output_data (1, DW_LLE_end_of_list
,
10640 "DW_LLE_end_of_list (%s)", list_head
->ll_symbol
);
10641 else if (dwarf_split_debug_info
)
10642 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
10643 "Location list terminator (%s)",
10644 list_head
->ll_symbol
);
10647 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
10648 "Location list terminator begin (%s)",
10649 list_head
->ll_symbol
);
10650 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
10651 "Location list terminator end (%s)",
10652 list_head
->ll_symbol
);
10655 gcc_assert (!list_head
->vl_symbol
10656 || vcount
== lcount
* (dwarf2out_locviews_in_attribute () ? 1 : 0));
10659 /* Output a range_list offset into the .debug_ranges or .debug_rnglists
10660 section. Emit a relocated reference if val_entry is NULL, otherwise,
10661 emit an indirect reference. */
10664 output_range_list_offset (dw_attr_node
*a
)
10666 const char *name
= dwarf_attr_name (a
->dw_attr
);
10668 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
10670 if (dwarf_version
>= 5)
10672 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
10673 dw2_asm_output_offset (dwarf_offset_size
, r
->label
,
10674 debug_ranges_section
, "%s", name
);
10678 char *p
= strchr (ranges_section_label
, '\0');
10679 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
10680 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
);
10681 dw2_asm_output_offset (dwarf_offset_size
, ranges_section_label
,
10682 debug_ranges_section
, "%s", name
);
10686 else if (dwarf_version
>= 5)
10688 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
10689 gcc_assert (rnglist_idx
);
10690 dw2_asm_output_data_uleb128 (r
->idx
, "%s", name
);
10693 dw2_asm_output_data (dwarf_offset_size
,
10694 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
,
10695 "%s (offset from %s)", name
, ranges_section_label
);
10698 /* Output the offset into the debug_loc section. */
10701 output_loc_list_offset (dw_attr_node
*a
)
10703 char *sym
= AT_loc_list (a
)->ll_symbol
;
10706 if (!dwarf_split_debug_info
)
10707 dw2_asm_output_offset (dwarf_offset_size
, sym
, debug_loc_section
,
10708 "%s", dwarf_attr_name (a
->dw_attr
));
10709 else if (dwarf_version
>= 5)
10711 gcc_assert (AT_loc_list (a
)->num_assigned
);
10712 dw2_asm_output_data_uleb128 (AT_loc_list (a
)->hash
, "%s (%s)",
10713 dwarf_attr_name (a
->dw_attr
),
10717 dw2_asm_output_delta (dwarf_offset_size
, sym
, loc_section_label
,
10718 "%s", dwarf_attr_name (a
->dw_attr
));
10721 /* Output the offset into the debug_loc section. */
10724 output_view_list_offset (dw_attr_node
*a
)
10726 char *sym
= (*AT_loc_list_ptr (a
))->vl_symbol
;
10729 if (dwarf_split_debug_info
)
10730 dw2_asm_output_delta (dwarf_offset_size
, sym
, loc_section_label
,
10731 "%s", dwarf_attr_name (a
->dw_attr
));
10733 dw2_asm_output_offset (dwarf_offset_size
, sym
, debug_loc_section
,
10734 "%s", dwarf_attr_name (a
->dw_attr
));
10737 /* Output an attribute's index or value appropriately. */
10740 output_attr_index_or_value (dw_attr_node
*a
)
10742 const char *name
= dwarf_attr_name (a
->dw_attr
);
10744 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
10746 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
10749 switch (AT_class (a
))
10751 case dw_val_class_addr
:
10752 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
10754 case dw_val_class_high_pc
:
10755 case dw_val_class_lbl_id
:
10756 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
10759 gcc_unreachable ();
10763 /* Output a type signature. */
10766 output_signature (const char *sig
, const char *name
)
10770 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10771 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
10774 /* Output a discriminant value. */
10777 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
10779 if (discr_value
->pos
)
10780 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
10782 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
10785 /* Output the DIE and its attributes. Called recursively to generate
10786 the definitions of each child DIE. */
10789 output_die (dw_die_ref die
)
10793 unsigned long size
;
10796 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
10797 (unsigned long)die
->die_offset
,
10798 dwarf_tag_name (die
->die_tag
));
10800 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
10802 const char *name
= dwarf_attr_name (a
->dw_attr
);
10804 switch (AT_class (a
))
10806 case dw_val_class_addr
:
10807 output_attr_index_or_value (a
);
10810 case dw_val_class_offset
:
10811 dw2_asm_output_data (dwarf_offset_size
, a
->dw_attr_val
.v
.val_offset
,
10815 case dw_val_class_range_list
:
10816 output_range_list_offset (a
);
10819 case dw_val_class_loc
:
10820 size
= size_of_locs (AT_loc (a
));
10822 /* Output the block length for this list of location operations. */
10823 if (dwarf_version
>= 4)
10824 dw2_asm_output_data_uleb128 (size
, "%s", name
);
10826 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
10828 output_loc_sequence (AT_loc (a
), -1);
10831 case dw_val_class_const
:
10832 /* ??? It would be slightly more efficient to use a scheme like is
10833 used for unsigned constants below, but gdb 4.x does not sign
10834 extend. Gdb 5.x does sign extend. */
10835 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
10838 case dw_val_class_unsigned_const
:
10840 int csize
= constant_size (AT_unsigned (a
));
10841 if (dwarf_version
== 3
10842 && a
->dw_attr
== DW_AT_data_member_location
10844 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
10846 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
10850 case dw_val_class_symview
:
10853 if (symview_upper_bound
<= 0xff)
10855 else if (symview_upper_bound
<= 0xffff)
10857 else if (symview_upper_bound
<= 0xffffffff)
10861 dw2_asm_output_addr (vsize
, a
->dw_attr_val
.v
.val_symbolic_view
,
10866 case dw_val_class_const_implicit
:
10867 if (flag_debug_asm
)
10868 fprintf (asm_out_file
, "\t\t\t%s %s ("
10869 HOST_WIDE_INT_PRINT_DEC
")\n",
10870 ASM_COMMENT_START
, name
, AT_int (a
));
10873 case dw_val_class_unsigned_const_implicit
:
10874 if (flag_debug_asm
)
10875 fprintf (asm_out_file
, "\t\t\t%s %s ("
10876 HOST_WIDE_INT_PRINT_HEX
")\n",
10877 ASM_COMMENT_START
, name
, AT_unsigned (a
));
10880 case dw_val_class_const_double
:
10882 unsigned HOST_WIDE_INT first
, second
;
10884 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
10885 dw2_asm_output_data (1,
10886 HOST_BITS_PER_DOUBLE_INT
10887 / HOST_BITS_PER_CHAR
,
10890 if (WORDS_BIG_ENDIAN
)
10892 first
= a
->dw_attr_val
.v
.val_double
.high
;
10893 second
= a
->dw_attr_val
.v
.val_double
.low
;
10897 first
= a
->dw_attr_val
.v
.val_double
.low
;
10898 second
= a
->dw_attr_val
.v
.val_double
.high
;
10901 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10902 first
, "%s", name
);
10903 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10908 case dw_val_class_wide_int
:
10911 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
10912 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10913 if (len
* HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
10914 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
)
10917 if (WORDS_BIG_ENDIAN
)
10918 for (i
= len
- 1; i
>= 0; --i
)
10920 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10925 for (i
= 0; i
< len
; ++i
)
10927 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10934 case dw_val_class_vec
:
10936 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
10937 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
10941 dw2_asm_output_data (constant_size (len
* elt_size
),
10942 len
* elt_size
, "%s", name
);
10943 if (elt_size
> sizeof (HOST_WIDE_INT
))
10948 for (i
= 0, p
= (unsigned char *) a
->dw_attr_val
.v
.val_vec
.array
;
10950 i
++, p
+= elt_size
)
10951 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
10952 "fp or vector constant word %u", i
);
10956 case dw_val_class_flag
:
10957 if (dwarf_version
>= 4)
10959 /* Currently all add_AT_flag calls pass in 1 as last argument,
10960 so DW_FORM_flag_present can be used. If that ever changes,
10961 we'll need to use DW_FORM_flag and have some optimization
10962 in build_abbrev_table that will change those to
10963 DW_FORM_flag_present if it is set to 1 in all DIEs using
10964 the same abbrev entry. */
10965 gcc_assert (AT_flag (a
) == 1);
10966 if (flag_debug_asm
)
10967 fprintf (asm_out_file
, "\t\t\t%s %s\n",
10968 ASM_COMMENT_START
, name
);
10971 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
10974 case dw_val_class_loc_list
:
10975 output_loc_list_offset (a
);
10978 case dw_val_class_view_list
:
10979 output_view_list_offset (a
);
10982 case dw_val_class_die_ref
:
10983 if (AT_ref_external (a
))
10985 if (AT_ref (a
)->comdat_type_p
)
10987 comdat_type_node
*type_node
10988 = AT_ref (a
)->die_id
.die_type_node
;
10990 gcc_assert (type_node
);
10991 output_signature (type_node
->signature
, name
);
10995 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
10999 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11000 length, whereas in DWARF3 it's always sized as an
11002 if (dwarf_version
== 2)
11003 size
= DWARF2_ADDR_SIZE
;
11005 size
= dwarf_offset_size
;
11006 /* ??? We cannot unconditionally output die_offset if
11007 non-zero - others might create references to those
11009 And we do not clear its DIE offset after outputting it
11010 (and the label refers to the actual DIEs, not the
11011 DWARF CU unit header which is when using label + offset
11012 would be the correct thing to do).
11013 ??? This is the reason for the with_offset flag. */
11014 if (AT_ref (a
)->with_offset
)
11015 dw2_asm_output_offset (size
, sym
, AT_ref (a
)->die_offset
,
11016 debug_info_section
, "%s", name
);
11018 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
11024 gcc_assert (AT_ref (a
)->die_offset
);
11025 dw2_asm_output_data (dwarf_offset_size
, AT_ref (a
)->die_offset
,
11030 case dw_val_class_fde_ref
:
11032 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
11034 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
11035 a
->dw_attr_val
.v
.val_fde_index
* 2);
11036 dw2_asm_output_offset (dwarf_offset_size
, l1
, debug_frame_section
,
11041 case dw_val_class_vms_delta
:
11042 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
11043 dw2_asm_output_vms_delta (dwarf_offset_size
,
11044 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
11047 dw2_asm_output_delta (dwarf_offset_size
,
11048 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
11053 case dw_val_class_lbl_id
:
11054 output_attr_index_or_value (a
);
11057 case dw_val_class_lineptr
:
11058 dw2_asm_output_offset (dwarf_offset_size
, AT_lbl (a
),
11059 debug_line_section
, "%s", name
);
11062 case dw_val_class_macptr
:
11063 dw2_asm_output_offset (dwarf_offset_size
, AT_lbl (a
),
11064 debug_macinfo_section
, "%s", name
);
11067 case dw_val_class_loclistsptr
:
11068 dw2_asm_output_offset (dwarf_offset_size
, AT_lbl (a
),
11069 debug_loc_section
, "%s", name
);
11072 case dw_val_class_str
:
11073 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
11074 dw2_asm_output_offset (dwarf_offset_size
,
11075 a
->dw_attr_val
.v
.val_str
->label
,
11077 "%s: \"%s\"", name
, AT_string (a
));
11078 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_line_strp
)
11079 dw2_asm_output_offset (dwarf_offset_size
,
11080 a
->dw_attr_val
.v
.val_str
->label
,
11081 debug_line_str_section
,
11082 "%s: \"%s\"", name
, AT_string (a
));
11083 else if (a
->dw_attr_val
.v
.val_str
->form
== dwarf_FORM (DW_FORM_strx
))
11084 dw2_asm_output_data_uleb128 (AT_index (a
),
11085 "%s: \"%s\"", name
, AT_string (a
));
11087 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
11090 case dw_val_class_file
:
11092 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
11094 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
11095 a
->dw_attr_val
.v
.val_file
->filename
);
11099 case dw_val_class_file_implicit
:
11100 if (flag_debug_asm
)
11101 fprintf (asm_out_file
, "\t\t\t%s %s (%d, %s)\n",
11102 ASM_COMMENT_START
, name
,
11103 maybe_emit_file (a
->dw_attr_val
.v
.val_file
),
11104 a
->dw_attr_val
.v
.val_file
->filename
);
11107 case dw_val_class_data8
:
11111 for (i
= 0; i
< 8; i
++)
11112 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
11113 i
== 0 ? "%s" : NULL
, name
);
11117 case dw_val_class_high_pc
:
11118 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
11119 get_AT_low_pc (die
), "DW_AT_high_pc");
11122 case dw_val_class_discr_value
:
11123 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
11126 case dw_val_class_discr_list
:
11128 dw_discr_list_ref list
= AT_discr_list (a
);
11129 const int size
= size_of_discr_list (list
);
11131 /* This is a block, so output its length first. */
11132 dw2_asm_output_data (constant_size (size
), size
,
11133 "%s: block size", name
);
11135 for (; list
!= NULL
; list
= list
->dw_discr_next
)
11137 /* One byte for the discriminant value descriptor, and then as
11138 many LEB128 numbers as required. */
11139 if (list
->dw_discr_range
)
11140 dw2_asm_output_data (1, DW_DSC_range
,
11141 "%s: DW_DSC_range", name
);
11143 dw2_asm_output_data (1, DW_DSC_label
,
11144 "%s: DW_DSC_label", name
);
11146 output_discr_value (&list
->dw_discr_lower_bound
, name
);
11147 if (list
->dw_discr_range
)
11148 output_discr_value (&list
->dw_discr_upper_bound
, name
);
11154 gcc_unreachable ();
11158 FOR_EACH_CHILD (die
, c
, output_die (c
));
11160 /* Add null byte to terminate sibling list. */
11161 if (die
->die_child
!= NULL
)
11162 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11163 (unsigned long) die
->die_offset
);
11166 /* Output the dwarf version number. */
11169 output_dwarf_version ()
11171 /* ??? For now, if -gdwarf-6 is specified, we output version 5 with
11172 views in loclist. That will change eventually. */
11173 if (dwarf_version
== 6)
11178 warning (0, "%<-gdwarf-6%> is output as version 5 with "
11179 "incompatibilities");
11182 dw2_asm_output_data (2, 5, "DWARF version number");
11185 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
11188 /* Output the compilation unit that appears at the beginning of the
11189 .debug_info section, and precedes the DIE descriptions. */
11192 output_compilation_unit_header (enum dwarf_unit_type ut
)
11194 if (!XCOFF_DEBUGGING_INFO
)
11196 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
11197 dw2_asm_output_data (4, 0xffffffff,
11198 "Initial length escape value indicating 64-bit DWARF extension");
11199 dw2_asm_output_data (dwarf_offset_size
,
11200 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
11201 "Length of Compilation Unit Info");
11204 output_dwarf_version ();
11205 if (dwarf_version
>= 5)
11210 case DW_UT_compile
: name
= "DW_UT_compile"; break;
11211 case DW_UT_type
: name
= "DW_UT_type"; break;
11212 case DW_UT_split_compile
: name
= "DW_UT_split_compile"; break;
11213 case DW_UT_split_type
: name
= "DW_UT_split_type"; break;
11214 default: gcc_unreachable ();
11216 dw2_asm_output_data (1, ut
, "%s", name
);
11217 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11219 dw2_asm_output_offset (dwarf_offset_size
, abbrev_section_label
,
11220 debug_abbrev_section
,
11221 "Offset Into Abbrev. Section");
11222 if (dwarf_version
< 5)
11223 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11226 /* Output the compilation unit DIE and its children. */
11229 output_comp_unit (dw_die_ref die
, int output_if_empty
,
11230 const unsigned char *dwo_id
)
11232 const char *secname
, *oldsym
;
11235 /* Unless we are outputting main CU, we may throw away empty ones. */
11236 if (!output_if_empty
&& die
->die_child
== NULL
)
11239 /* Even if there are no children of this DIE, we must output the information
11240 about the compilation unit. Otherwise, on an empty translation unit, we
11241 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11242 will then complain when examining the file. First mark all the DIEs in
11243 this CU so we know which get local refs. */
11246 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
11248 /* For now, optimize only the main CU, in order to optimize the rest
11249 we'd need to see all of them earlier. Leave the rest for post-linking
11251 if (die
== comp_unit_die ())
11252 abbrev_opt_start
= vec_safe_length (abbrev_die_table
);
11254 build_abbrev_table (die
, extern_map
);
11256 optimize_abbrev_table ();
11260 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11261 next_die_offset
= (dwo_id
11262 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
11263 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
11264 calc_die_sizes (die
);
11266 oldsym
= die
->die_id
.die_symbol
;
11267 if (oldsym
&& die
->comdat_type_p
)
11269 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
11271 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
11273 die
->die_id
.die_symbol
= NULL
;
11274 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11278 switch_to_section (debug_info_section
);
11279 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
11280 info_section_emitted
= true;
11283 /* For LTO cross unit DIE refs we want a symbol on the start of the
11284 debuginfo section, not on the CU DIE. */
11285 if ((flag_generate_lto
|| flag_generate_offload
) && oldsym
)
11287 /* ??? No way to get visibility assembled without a decl. */
11288 tree decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
,
11289 get_identifier (oldsym
), char_type_node
);
11290 TREE_PUBLIC (decl
) = true;
11291 TREE_STATIC (decl
) = true;
11292 DECL_ARTIFICIAL (decl
) = true;
11293 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
11294 DECL_VISIBILITY_SPECIFIED (decl
) = true;
11295 targetm
.asm_out
.assemble_visibility (decl
, VISIBILITY_HIDDEN
);
11296 #ifdef ASM_WEAKEN_LABEL
11297 /* We prefer a .weak because that handles duplicates from duplicate
11298 archive members in a graceful way. */
11299 ASM_WEAKEN_LABEL (asm_out_file
, oldsym
);
11301 targetm
.asm_out
.globalize_label (asm_out_file
, oldsym
);
11303 ASM_OUTPUT_LABEL (asm_out_file
, oldsym
);
11306 /* Output debugging information. */
11307 output_compilation_unit_header (dwo_id
11308 ? DW_UT_split_compile
: DW_UT_compile
);
11309 if (dwarf_version
>= 5)
11311 if (dwo_id
!= NULL
)
11312 for (int i
= 0; i
< 8; i
++)
11313 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
11317 /* Leave the marks on the main CU, so we can check them in
11318 output_pubnames. */
11322 die
->die_id
.die_symbol
= oldsym
;
11326 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
11327 and .debug_pubtypes. This is configured per-target, but can be
11328 overridden by the -gpubnames or -gno-pubnames options. */
11331 want_pubnames (void)
11333 if (debug_info_level
<= DINFO_LEVEL_TERSE
11334 /* Names and types go to the early debug part only. */
11337 if (debug_generate_pub_sections
!= -1)
11338 return debug_generate_pub_sections
;
11339 return targetm
.want_debug_pub_sections
;
11342 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
11345 add_AT_pubnames (dw_die_ref die
)
11347 if (want_pubnames ())
11348 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
11351 /* Add a string attribute value to a skeleton DIE. */
11354 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
11358 struct indirect_string_node
*node
;
11360 if (! skeleton_debug_str_hash
)
11361 skeleton_debug_str_hash
11362 = hash_table
<indirect_string_hasher
>::create_ggc (10);
11364 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
11365 find_string_form (node
);
11366 if (node
->form
== dwarf_FORM (DW_FORM_strx
))
11367 node
->form
= DW_FORM_strp
;
11369 attr
.dw_attr
= attr_kind
;
11370 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
11371 attr
.dw_attr_val
.val_entry
= NULL
;
11372 attr
.dw_attr_val
.v
.val_str
= node
;
11373 add_dwarf_attr (die
, &attr
);
11376 /* Helper function to generate top-level dies for skeleton debug_info and
11380 add_top_level_skeleton_die_attrs (dw_die_ref die
)
11382 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
11383 const char *comp_dir
= comp_dir_string ();
11385 add_skeleton_AT_string (die
, dwarf_AT (DW_AT_dwo_name
), dwo_file_name
);
11386 if (comp_dir
!= NULL
)
11387 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
11388 add_AT_pubnames (die
);
11389 if (addr_index_table
!= NULL
&& addr_index_table
->size () > 0)
11390 add_AT_lineptr (die
, dwarf_AT (DW_AT_addr_base
), debug_addr_section_label
);
11393 /* Output skeleton debug sections that point to the dwo file. */
11396 output_skeleton_debug_sections (dw_die_ref comp_unit
,
11397 const unsigned char *dwo_id
)
11399 /* These attributes will be found in the full debug_info section. */
11400 remove_AT (comp_unit
, DW_AT_producer
);
11401 remove_AT (comp_unit
, DW_AT_language
);
11403 switch_to_section (debug_skeleton_info_section
);
11404 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
11406 /* Produce the skeleton compilation-unit header. This one differs enough from
11407 a normal CU header that it's better not to call output_compilation_unit
11409 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
11410 dw2_asm_output_data (4, 0xffffffff,
11411 "Initial length escape value indicating 64-bit "
11412 "DWARF extension");
11414 dw2_asm_output_data (dwarf_offset_size
,
11415 DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
11416 - DWARF_INITIAL_LENGTH_SIZE
11417 + size_of_die (comp_unit
),
11418 "Length of Compilation Unit Info");
11419 output_dwarf_version ();
11420 if (dwarf_version
>= 5)
11422 dw2_asm_output_data (1, DW_UT_skeleton
, "DW_UT_skeleton");
11423 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11425 dw2_asm_output_offset (dwarf_offset_size
, debug_skeleton_abbrev_section_label
,
11426 debug_skeleton_abbrev_section
,
11427 "Offset Into Abbrev. Section");
11428 if (dwarf_version
< 5)
11429 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11431 for (int i
= 0; i
< 8; i
++)
11432 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
11434 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
11435 output_die (comp_unit
);
11437 /* Build the skeleton debug_abbrev section. */
11438 switch_to_section (debug_skeleton_abbrev_section
);
11439 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
11441 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
11443 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
11446 /* Output a comdat type unit DIE and its children. */
11449 output_comdat_type_unit (comdat_type_node
*node
,
11450 bool early_lto_debug ATTRIBUTE_UNUSED
)
11452 const char *secname
;
11455 #if defined (OBJECT_FORMAT_ELF)
11459 /* First mark all the DIEs in this CU so we know which get local refs. */
11460 mark_dies (node
->root_die
);
11462 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
11464 build_abbrev_table (node
->root_die
, extern_map
);
11469 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11470 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
11471 calc_die_sizes (node
->root_die
);
11473 #if defined (OBJECT_FORMAT_ELF)
11474 if (dwarf_version
>= 5)
11476 if (!dwarf_split_debug_info
)
11477 secname
= early_lto_debug
? DEBUG_LTO_INFO_SECTION
: DEBUG_INFO_SECTION
;
11479 secname
= (early_lto_debug
11480 ? DEBUG_LTO_DWO_INFO_SECTION
: DEBUG_DWO_INFO_SECTION
);
11482 else if (!dwarf_split_debug_info
)
11483 secname
= early_lto_debug
? ".gnu.debuglto_.debug_types" : ".debug_types";
11485 secname
= (early_lto_debug
11486 ? ".gnu.debuglto_.debug_types.dwo" : ".debug_types.dwo");
11488 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11489 sprintf (tmp
, dwarf_version
>= 5 ? "wi." : "wt.");
11490 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11491 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11492 comdat_key
= get_identifier (tmp
);
11493 targetm
.asm_out
.named_section (secname
,
11494 SECTION_DEBUG
| SECTION_LINKONCE
,
11497 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11498 sprintf (tmp
, (dwarf_version
>= 5
11499 ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
11500 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11501 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11503 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11506 /* Output debugging information. */
11507 output_compilation_unit_header (dwarf_split_debug_info
11508 ? DW_UT_split_type
: DW_UT_type
);
11509 output_signature (node
->signature
, "Type Signature");
11510 dw2_asm_output_data (dwarf_offset_size
, node
->type_die
->die_offset
,
11511 "Offset to Type DIE");
11512 output_die (node
->root_die
);
11514 unmark_dies (node
->root_die
);
11517 /* Return the DWARF2/3 pubname associated with a decl. */
11519 static const char *
11520 dwarf2_name (tree decl
, int scope
)
11522 if (DECL_NAMELESS (decl
))
11524 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
11527 /* Add a new entry to .debug_pubnames if appropriate. */
11530 add_pubname_string (const char *str
, dw_die_ref die
)
11535 e
.name
= xstrdup (str
);
11536 vec_safe_push (pubname_table
, e
);
11540 add_pubname (tree decl
, dw_die_ref die
)
11542 if (!want_pubnames ())
11545 /* Don't add items to the table when we expect that the consumer will have
11546 just read the enclosing die. For example, if the consumer is looking at a
11547 class_member, it will either be inside the class already, or will have just
11548 looked up the class to find the member. Either way, searching the class is
11549 faster than searching the index. */
11550 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
11551 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
11553 const char *name
= dwarf2_name (decl
, 1);
11556 add_pubname_string (name
, die
);
11560 /* Add an enumerator to the pubnames section. */
11563 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
11567 gcc_assert (scope_name
);
11568 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
11570 vec_safe_push (pubname_table
, e
);
11573 /* Add a new entry to .debug_pubtypes if appropriate. */
11576 add_pubtype (tree decl
, dw_die_ref die
)
11580 if (!want_pubnames ())
11583 if ((TREE_PUBLIC (decl
)
11584 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
11585 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
11588 const char *scope_name
= "";
11589 const char *sep
= is_cxx () ? "::" : ".";
11592 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
11593 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
11595 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
11596 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
11597 scope_name
= concat (scope_name
, sep
, NULL
);
11603 name
= type_tag (decl
);
11605 name
= lang_hooks
.dwarf_name (decl
, 1);
11607 /* If we don't have a name for the type, there's no point in adding
11608 it to the table. */
11609 if (name
!= NULL
&& name
[0] != '\0')
11612 e
.name
= concat (scope_name
, name
, NULL
);
11613 vec_safe_push (pubtype_table
, e
);
11616 /* Although it might be more consistent to add the pubinfo for the
11617 enumerators as their dies are created, they should only be added if the
11618 enum type meets the criteria above. So rather than re-check the parent
11619 enum type whenever an enumerator die is created, just output them all
11620 here. This isn't protected by the name conditional because anonymous
11621 enums don't have names. */
11622 if (die
->die_tag
== DW_TAG_enumeration_type
)
11626 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
11631 /* Output a single entry in the pubnames table. */
11634 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
11636 dw_die_ref die
= entry
->die
;
11637 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
11639 dw2_asm_output_data (dwarf_offset_size
, die_offset
, "DIE offset");
11641 if (debug_generate_pub_sections
== 2)
11643 /* This logic follows gdb's method for determining the value of the flag
11645 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
11646 switch (die
->die_tag
)
11648 case DW_TAG_typedef
:
11649 case DW_TAG_base_type
:
11650 case DW_TAG_subrange_type
:
11651 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
11652 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
11654 case DW_TAG_enumerator
:
11655 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11656 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
11658 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
11660 case DW_TAG_subprogram
:
11661 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11662 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
11664 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
11666 case DW_TAG_constant
:
11667 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11668 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
11669 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
11671 case DW_TAG_variable
:
11672 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11673 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
11674 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
11676 case DW_TAG_namespace
:
11677 case DW_TAG_imported_declaration
:
11678 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
11680 case DW_TAG_class_type
:
11681 case DW_TAG_interface_type
:
11682 case DW_TAG_structure_type
:
11683 case DW_TAG_union_type
:
11684 case DW_TAG_enumeration_type
:
11685 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
11687 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
11690 /* An unusual tag. Leave the flag-byte empty. */
11693 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
11694 "GDB-index flags");
11697 dw2_asm_output_nstring (entry
->name
, -1, "external name");
11701 /* Output the public names table used to speed up access to externally
11702 visible names; or the public types table used to find type definitions. */
11705 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
11708 unsigned long pubnames_length
= size_of_pubnames (names
);
11709 pubname_entry
*pub
;
11711 if (!XCOFF_DEBUGGING_INFO
)
11713 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
11714 dw2_asm_output_data (4, 0xffffffff,
11715 "Initial length escape value indicating 64-bit DWARF extension");
11716 dw2_asm_output_data (dwarf_offset_size
, pubnames_length
,
11717 "Pub Info Length");
11720 /* Version number for pubnames/pubtypes is independent of dwarf version. */
11721 dw2_asm_output_data (2, 2, "DWARF pubnames/pubtypes version");
11723 if (dwarf_split_debug_info
)
11724 dw2_asm_output_offset (dwarf_offset_size
, debug_skeleton_info_section_label
,
11725 debug_skeleton_info_section
,
11726 "Offset of Compilation Unit Info");
11728 dw2_asm_output_offset (dwarf_offset_size
, debug_info_section_label
,
11729 debug_info_section
,
11730 "Offset of Compilation Unit Info");
11731 dw2_asm_output_data (dwarf_offset_size
, next_die_offset
,
11732 "Compilation Unit Length");
11734 FOR_EACH_VEC_ELT (*names
, i
, pub
)
11736 if (include_pubname_in_output (names
, pub
))
11738 dw_offset die_offset
= pub
->die
->die_offset
;
11740 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11741 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
11742 gcc_assert (pub
->die
->die_mark
);
11744 /* If we're putting types in their own .debug_types sections,
11745 the .debug_pubtypes table will still point to the compile
11746 unit (not the type unit), so we want to use the offset of
11747 the skeleton DIE (if there is one). */
11748 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
11750 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
11752 if (type_node
!= NULL
)
11753 die_offset
= (type_node
->skeleton_die
!= NULL
11754 ? type_node
->skeleton_die
->die_offset
11755 : comp_unit_die ()->die_offset
);
11758 output_pubname (die_offset
, pub
);
11762 dw2_asm_output_data (dwarf_offset_size
, 0, NULL
);
11765 /* Output public names and types tables if necessary. */
11768 output_pubtables (void)
11770 if (!want_pubnames () || !info_section_emitted
)
11773 switch_to_section (debug_pubnames_section
);
11774 output_pubnames (pubname_table
);
11775 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
11776 It shouldn't hurt to emit it always, since pure DWARF2 consumers
11777 simply won't look for the section. */
11778 switch_to_section (debug_pubtypes_section
);
11779 output_pubnames (pubtype_table
);
11783 /* Output the information that goes into the .debug_aranges table.
11784 Namely, define the beginning and ending address range of the
11785 text section generated for this compilation unit. */
11788 output_aranges (void)
11791 unsigned long aranges_length
= size_of_aranges ();
11793 if (!XCOFF_DEBUGGING_INFO
)
11795 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
11796 dw2_asm_output_data (4, 0xffffffff,
11797 "Initial length escape value indicating 64-bit DWARF extension");
11798 dw2_asm_output_data (dwarf_offset_size
, aranges_length
,
11799 "Length of Address Ranges Info");
11802 /* Version number for aranges is still 2, even up to DWARF5. */
11803 dw2_asm_output_data (2, 2, "DWARF aranges version");
11804 if (dwarf_split_debug_info
)
11805 dw2_asm_output_offset (dwarf_offset_size
, debug_skeleton_info_section_label
,
11806 debug_skeleton_info_section
,
11807 "Offset of Compilation Unit Info");
11809 dw2_asm_output_offset (dwarf_offset_size
, debug_info_section_label
,
11810 debug_info_section
,
11811 "Offset of Compilation Unit Info");
11812 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
11813 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11815 /* We need to align to twice the pointer size here. */
11816 if (DWARF_ARANGES_PAD_SIZE
)
11818 /* Pad using a 2 byte words so that padding is correct for any
11820 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11821 2 * DWARF2_ADDR_SIZE
);
11822 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
11823 dw2_asm_output_data (2, 0, NULL
);
11826 /* It is necessary not to output these entries if the sections were
11827 not used; if the sections were not used, the length will be 0 and
11828 the address may end up as 0 if the section is discarded by ld
11829 --gc-sections, leaving an invalid (0, 0) entry that can be
11830 confused with the terminator. */
11831 if (switch_text_ranges
)
11833 const char *prev_loc
= text_section_label
;
11837 FOR_EACH_VEC_ELT (*switch_text_ranges
, idx
, loc
)
11840 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, prev_loc
, "Address");
11841 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, loc
, prev_loc
, "Length");
11849 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, prev_loc
, "Address");
11850 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
11851 prev_loc
, "Length");
11855 if (switch_cold_ranges
)
11857 const char *prev_loc
= cold_text_section_label
;
11861 FOR_EACH_VEC_ELT (*switch_cold_ranges
, idx
, loc
)
11864 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, prev_loc
, "Address");
11865 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, loc
, prev_loc
, "Length");
11873 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, prev_loc
, "Address");
11874 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
11875 prev_loc
, "Length");
11879 if (have_multiple_function_sections
)
11884 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
11886 if (fde
->ignored_debug
)
11888 if (!fde
->in_std_section
)
11890 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
11892 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
11893 fde
->dw_fde_begin
, "Length");
11895 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
11897 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
11899 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
11900 fde
->dw_fde_second_begin
, "Length");
11905 /* Output the terminator words. */
11906 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11907 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11910 /* Add a new entry to .debug_ranges. Return its index into
11911 ranges_table vector. */
11913 static unsigned int
11914 add_ranges_num (int num
, bool maybe_new_sec
)
11916 dw_ranges r
= { NULL
, num
, 0, maybe_new_sec
, NULL
, NULL
};
11917 vec_safe_push (ranges_table
, r
);
11918 return vec_safe_length (ranges_table
) - 1;
11921 /* Add a new entry to .debug_ranges corresponding to a block, or a
11922 range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
11923 this entry might be in a different section from previous range. */
11925 static unsigned int
11926 add_ranges (const_tree block
, bool maybe_new_sec
)
11928 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0, maybe_new_sec
);
11931 /* Note that (*rnglist_table)[offset] is either a head of a rnglist
11932 chain, or middle entry of a chain that will be directly referred to. */
11935 note_rnglist_head (unsigned int offset
)
11937 if (dwarf_version
< 5 || (*ranges_table
)[offset
].label
)
11939 (*ranges_table
)[offset
].label
= gen_internal_sym ("LLRL");
11942 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
11943 When using dwarf_split_debug_info, address attributes in dies destined
11944 for the final executable should be direct references--setting the
11945 parameter force_direct ensures this behavior. */
11948 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11949 bool *added
, bool force_direct
)
11951 unsigned int in_use
= vec_safe_length (ranges_by_label
);
11952 unsigned int offset
;
11953 dw_ranges_by_label rbl
= { begin
, end
};
11954 vec_safe_push (ranges_by_label
, rbl
);
11955 offset
= add_ranges_num (-(int)in_use
- 1, true);
11958 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
11960 note_rnglist_head (offset
);
11961 if (dwarf_split_debug_info
&& force_direct
)
11962 (*ranges_table
)[offset
].idx
= DW_RANGES_IDX_SKELETON
;
11966 /* Emit .debug_ranges section. */
11969 output_ranges (void)
11972 static const char *const start_fmt
= "Offset %#x";
11973 const char *fmt
= start_fmt
;
11976 switch_to_section (debug_ranges_section
);
11977 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11978 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11980 int block_num
= r
->num
;
11984 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11985 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11987 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11988 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11990 /* If all code is in the text section, then the compilation
11991 unit base address defaults to DW_AT_low_pc, which is the
11992 base of the text section. */
11993 if (!have_multiple_function_sections
)
11995 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11996 text_section_label
,
11997 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11998 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11999 text_section_label
, NULL
);
12002 /* Otherwise, the compilation unit base address is zero,
12003 which allows us to use absolute addresses, and not worry
12004 about whether the target supports cross-section
12008 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12009 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
12010 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
12016 /* Negative block_num stands for an index into ranges_by_label. */
12017 else if (block_num
< 0)
12019 int lab_idx
= - block_num
- 1;
12021 if (!have_multiple_function_sections
)
12023 gcc_unreachable ();
12025 /* If we ever use add_ranges_by_labels () for a single
12026 function section, all we have to do is to take out
12027 the #if 0 above. */
12028 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
12029 (*ranges_by_label
)[lab_idx
].begin
,
12030 text_section_label
,
12031 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
12032 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
12033 (*ranges_by_label
)[lab_idx
].end
,
12034 text_section_label
, NULL
);
12039 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
12040 (*ranges_by_label
)[lab_idx
].begin
,
12041 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
12042 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
12043 (*ranges_by_label
)[lab_idx
].end
,
12049 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
12050 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
12056 /* Non-zero if .debug_line_str should be used for .debug_line section
12057 strings or strings that are likely shareable with those. */
12058 #define DWARF5_USE_DEBUG_LINE_STR \
12059 (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
12060 && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
12061 /* FIXME: there is no .debug_line_str.dwo section, \
12062 for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
12063 && !dwarf_split_debug_info)
12066 /* Returns TRUE if we are outputting DWARF5 and the assembler supports
12067 DWARF5 .debug_line tables using .debug_line_str or we generate
12068 it ourselves, except for split-dwarf which doesn't have a
12069 .debug_line_str. */
12071 asm_outputs_debug_line_str (void)
12073 if (dwarf_version
>= 5
12074 && ! output_asm_line_debug_info ()
12075 && DWARF5_USE_DEBUG_LINE_STR
)
12079 #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
12080 return !dwarf_split_debug_info
&& dwarf_version
>= 5;
12087 /* Return true if it is beneficial to use DW_RLE_base_address{,x}.
12088 I is index of the following range. */
12091 use_distinct_base_address_for_range (unsigned int i
)
12093 if (i
>= vec_safe_length (ranges_table
))
12096 dw_ranges
*r2
= &(*ranges_table
)[i
];
12097 /* Use DW_RLE_base_address{,x} if there is a next range in the
12098 range list and is guaranteed to be in the same section. */
12099 return r2
->num
!= 0 && r2
->label
== NULL
&& !r2
->maybe_new_sec
;
12102 /* Assign .debug_rnglists indexes and unique indexes into the debug_addr
12103 section when needed. */
12106 index_rnglists (void)
12112 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
12114 if (r
->label
&& r
->idx
!= DW_RANGES_IDX_SKELETON
)
12115 r
->idx
= rnglist_idx
++;
12117 int block_num
= r
->num
;
12118 if ((HAVE_AS_LEB128
|| block_num
< 0)
12119 && !have_multiple_function_sections
)
12121 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
12125 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12126 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12128 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
12129 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
12131 if (HAVE_AS_LEB128
)
12133 if (!base
&& use_distinct_base_address_for_range (i
+ 1))
12135 r
->begin_entry
= add_addr_table_entry (xstrdup (blabel
),
12140 /* If we have a base, no need for further
12141 begin_entry/end_entry, as DW_RLE_offset_pair will be
12145 = add_addr_table_entry (xstrdup (blabel
), ate_kind_label
);
12146 /* No need for end_entry, DW_RLE_start{,x}_length will use
12147 length as opposed to a pair of addresses. */
12152 = add_addr_table_entry (xstrdup (blabel
), ate_kind_label
);
12154 = add_addr_table_entry (xstrdup (elabel
), ate_kind_label
);
12158 /* Negative block_num stands for an index into ranges_by_label. */
12159 else if (block_num
< 0)
12161 int lab_idx
= - block_num
- 1;
12162 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
12163 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
12166 = add_addr_table_entry (xstrdup (blabel
), ate_kind_label
);
12167 if (!HAVE_AS_LEB128
)
12169 = add_addr_table_entry (xstrdup (elabel
), ate_kind_label
);
12174 /* Emit .debug_rnglists or (when DWO is true) .debug_rnglists.dwo section. */
12177 output_rnglists (unsigned generation
, bool dwo
)
12181 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
12182 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
12183 char basebuf
[MAX_ARTIFICIAL_LABEL_BYTES
];
12186 switch_to_section (debug_ranges_dwo_section
);
12189 switch_to_section (debug_ranges_section
);
12190 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
12192 /* There are up to 4 unique ranges labels per generation.
12193 See also init_sections_and_labels. */
12194 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_RANGES_SECTION_LABEL
,
12195 2 + 2 * dwo
+ generation
* 6);
12196 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_RANGES_SECTION_LABEL
,
12197 3 + 2 * dwo
+ generation
* 6);
12198 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
12199 dw2_asm_output_data (4, 0xffffffff,
12200 "Initial length escape value indicating "
12201 "64-bit DWARF extension");
12202 dw2_asm_output_delta (dwarf_offset_size
, l2
, l1
,
12203 "Length of Range Lists");
12204 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
12205 output_dwarf_version ();
12206 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
12207 dw2_asm_output_data (1, 0, "Segment Size");
12208 /* Emit the offset table only for -gsplit-dwarf. If we don't care
12209 about relocation sizes and primarily care about the size of .debug*
12210 sections in linked shared libraries and executables, then
12211 the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
12212 into it are usually larger than just DW_FORM_sec_offset offsets
12213 into the .debug_rnglists section. */
12214 dw2_asm_output_data (4, dwo
? rnglist_idx
: 0,
12215 "Offset Entry Count");
12218 ASM_OUTPUT_LABEL (asm_out_file
, ranges_base_label
);
12219 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
12220 if (r
->label
&& r
->idx
!= DW_RANGES_IDX_SKELETON
)
12221 dw2_asm_output_delta (dwarf_offset_size
, r
->label
,
12222 ranges_base_label
, NULL
);
12225 const char *lab
= "";
12226 const char *base
= NULL
;
12227 bool skipping
= false;
12229 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
12231 int block_num
= r
->num
;
12235 if (dwarf_split_debug_info
12236 && (r
->idx
== DW_RANGES_IDX_SKELETON
) == dwo
)
12242 ASM_OUTPUT_LABEL (asm_out_file
, r
->label
);
12247 if (block_num
== 0)
12251 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
12255 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12256 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12258 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
12259 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
12261 if (HAVE_AS_LEB128
)
12263 /* If all code is in the text section, then the compilation
12264 unit base address defaults to DW_AT_low_pc, which is the
12265 base of the text section. */
12266 if (!have_multiple_function_sections
)
12268 dw2_asm_output_data (1, DW_RLE_offset_pair
,
12269 "DW_RLE_offset_pair (%s)", lab
);
12270 dw2_asm_output_delta_uleb128 (blabel
, text_section_label
,
12271 "Range begin address (%s)", lab
);
12272 dw2_asm_output_delta_uleb128 (elabel
, text_section_label
,
12273 "Range end address (%s)", lab
);
12276 if (base
== NULL
&& use_distinct_base_address_for_range (i
+ 1))
12278 if (dwarf_split_debug_info
)
12280 dw2_asm_output_data (1, DW_RLE_base_addressx
,
12281 "DW_RLE_base_addressx (%s)", lab
);
12282 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12283 "Base address index (%s)",
12288 dw2_asm_output_data (1, DW_RLE_base_address
,
12289 "DW_RLE_base_address (%s)", lab
);
12290 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12291 "Base address (%s)", lab
);
12293 strcpy (basebuf
, blabel
);
12298 dw2_asm_output_data (1, DW_RLE_offset_pair
,
12299 "DW_RLE_offset_pair (%s)", lab
);
12300 dw2_asm_output_delta_uleb128 (blabel
, base
,
12301 "Range begin address (%s)", lab
);
12302 dw2_asm_output_delta_uleb128 (elabel
, base
,
12303 "Range end address (%s)", lab
);
12306 if (dwarf_split_debug_info
)
12308 dw2_asm_output_data (1, DW_RLE_startx_length
,
12309 "DW_RLE_startx_length (%s)", lab
);
12310 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12311 "Range begin address index "
12316 dw2_asm_output_data (1, DW_RLE_start_length
,
12317 "DW_RLE_start_length (%s)", lab
);
12318 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12319 "Range begin address (%s)", lab
);
12321 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
12322 "Range length (%s)", lab
);
12324 else if (dwarf_split_debug_info
)
12326 dw2_asm_output_data (1, DW_RLE_startx_endx
,
12327 "DW_RLE_startx_endx (%s)", lab
);
12328 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12329 "Range begin address index "
12331 dw2_asm_output_data_uleb128 (r
->end_entry
->index
,
12332 "Range end address index "
12337 dw2_asm_output_data (1, DW_RLE_start_end
,
12338 "DW_RLE_start_end (%s)", lab
);
12339 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12340 "Range begin address (%s)", lab
);
12341 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
12342 "Range end address (%s)", lab
);
12346 /* Negative block_num stands for an index into ranges_by_label. */
12347 else if (block_num
< 0)
12349 int lab_idx
= - block_num
- 1;
12350 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
12351 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
12353 if (!have_multiple_function_sections
)
12354 gcc_unreachable ();
12355 if (HAVE_AS_LEB128
)
12357 if (dwarf_split_debug_info
)
12359 dw2_asm_output_data (1, DW_RLE_startx_length
,
12360 "DW_RLE_startx_length (%s)", lab
);
12361 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12362 "Range begin address index "
12367 dw2_asm_output_data (1, DW_RLE_start_length
,
12368 "DW_RLE_start_length (%s)", lab
);
12369 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12370 "Range begin address (%s)", lab
);
12372 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
12373 "Range length (%s)", lab
);
12375 else if (dwarf_split_debug_info
)
12377 dw2_asm_output_data (1, DW_RLE_startx_endx
,
12378 "DW_RLE_startx_endx (%s)", lab
);
12379 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12380 "Range begin address index "
12382 dw2_asm_output_data_uleb128 (r
->end_entry
->index
,
12383 "Range end address index "
12388 dw2_asm_output_data (1, DW_RLE_start_end
,
12389 "DW_RLE_start_end (%s)", lab
);
12390 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12391 "Range begin address (%s)", lab
);
12392 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
12393 "Range end address (%s)", lab
);
12397 dw2_asm_output_data (1, DW_RLE_end_of_list
,
12398 "DW_RLE_end_of_list (%s)", lab
);
12400 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12404 /* Data structure containing information about input files. */
12407 const char *path
; /* Complete file name. */
12408 const char *fname
; /* File name part. */
12409 int length
; /* Length of entire string. */
12410 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
12411 int dir_idx
; /* Index in directory table. */
12414 /* Data structure containing information about directories with source
12418 const char *path
; /* Path including directory name. */
12419 int length
; /* Path length. */
12420 int prefix
; /* Index of directory entry which is a prefix. */
12421 int count
; /* Number of files in this directory. */
12422 int dir_idx
; /* Index of directory used as base. */
12425 /* Callback function for file_info comparison. We sort by looking at
12426 the directories in the path. */
12429 file_info_cmp (const void *p1
, const void *p2
)
12431 const struct file_info
*const s1
= (const struct file_info
*) p1
;
12432 const struct file_info
*const s2
= (const struct file_info
*) p2
;
12433 const unsigned char *cp1
;
12434 const unsigned char *cp2
;
12436 /* Take care of file names without directories. We need to make sure that
12437 we return consistent values to qsort since some will get confused if
12438 we return the same value when identical operands are passed in opposite
12439 orders. So if neither has a directory, return 0 and otherwise return
12440 1 or -1 depending on which one has the directory. We want the one with
12441 the directory to sort after the one without, so all no directory files
12442 are at the start (normally only the compilation unit file). */
12443 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
12444 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
12446 cp1
= (const unsigned char *) s1
->path
;
12447 cp2
= (const unsigned char *) s2
->path
;
12453 /* Reached the end of the first path? If so, handle like above,
12454 but now we want longer directory prefixes before shorter ones. */
12455 if ((cp1
== (const unsigned char *) s1
->fname
)
12456 || (cp2
== (const unsigned char *) s2
->fname
))
12457 return ((cp1
== (const unsigned char *) s1
->fname
)
12458 - (cp2
== (const unsigned char *) s2
->fname
));
12460 /* Character of current path component the same? */
12461 else if (*cp1
!= *cp2
)
12462 return *cp1
- *cp2
;
12466 struct file_name_acquire_data
12468 struct file_info
*files
;
12473 /* Traversal function for the hash table. */
12476 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
12478 struct dwarf_file_data
*d
= *slot
;
12479 struct file_info
*fi
;
12482 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
12484 if (! d
->emitted_number
)
12487 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
12489 fi
= fnad
->files
+ fnad
->used_files
++;
12493 /* Skip all leading "./". */
12494 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
12497 /* Create a new array entry. */
12499 fi
->length
= strlen (f
);
12502 /* Search for the file name part. */
12503 f
= strrchr (f
, DIR_SEPARATOR
);
12504 #if defined (DIR_SEPARATOR_2)
12506 const char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
12510 if (f
== NULL
|| f
< g
)
12516 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
12520 /* Helper function for output_file_names. Emit a FORM encoded
12521 string STR, with assembly comment start ENTRY_KIND and
12525 output_line_string (enum dwarf_form form
, const char *str
,
12526 const char *entry_kind
, unsigned int idx
)
12530 case DW_FORM_string
:
12531 dw2_asm_output_nstring (str
, -1, "%s: %#x", entry_kind
, idx
);
12533 case DW_FORM_line_strp
:
12534 if (!debug_line_str_hash
)
12535 debug_line_str_hash
12536 = hash_table
<indirect_string_hasher
>::create_ggc (10);
12538 struct indirect_string_node
*node
;
12539 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
12540 set_indirect_string (node
);
12542 dw2_asm_output_offset (dwarf_offset_size
, node
->label
,
12543 debug_line_str_section
, "%s: %#x: \"%s\"",
12544 entry_kind
, 0, node
->str
);
12547 gcc_unreachable ();
12551 /* Output the directory table and the file name table. We try to minimize
12552 the total amount of memory needed. A heuristic is used to avoid large
12553 slowdowns with many input files. */
12556 output_file_names (void)
12558 struct file_name_acquire_data fnad
;
12560 struct file_info
*files
;
12561 struct dir_info
*dirs
;
12569 if (!last_emitted_file
)
12571 if (dwarf_version
>= 5)
12573 const char *comp_dir
= comp_dir_string ();
12574 if (comp_dir
== NULL
)
12576 dw2_asm_output_data (1, 1, "Directory entry format count");
12577 enum dwarf_form str_form
= DW_FORM_string
;
12578 if (DWARF5_USE_DEBUG_LINE_STR
)
12579 str_form
= DW_FORM_line_strp
;
12580 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12581 dw2_asm_output_data_uleb128 (str_form
, "%s",
12582 get_DW_FORM_name (str_form
));
12583 dw2_asm_output_data_uleb128 (1, "Directories count");
12584 if (str_form
== DW_FORM_string
)
12585 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
12587 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
12588 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
12589 if (filename0
== NULL
)
12591 #ifdef VMS_DEBUGGING_INFO
12592 dw2_asm_output_data (1, 4, "File name entry format count");
12594 dw2_asm_output_data (1, 2, "File name entry format count");
12596 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12597 dw2_asm_output_data_uleb128 (str_form
, "%s",
12598 get_DW_FORM_name (str_form
));
12599 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
12600 "DW_LNCT_directory_index");
12601 dw2_asm_output_data_uleb128 (DW_FORM_data1
, "%s",
12602 get_DW_FORM_name (DW_FORM_data1
));
12603 #ifdef VMS_DEBUGGING_INFO
12604 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
12605 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12606 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
12607 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12609 dw2_asm_output_data_uleb128 (1, "File names count");
12611 output_line_string (str_form
, filename0
, "File Entry", 0);
12612 dw2_asm_output_data (1, 0, NULL
);
12613 #ifdef VMS_DEBUGGING_INFO
12614 dw2_asm_output_data_uleb128 (0, NULL
);
12615 dw2_asm_output_data_uleb128 (0, NULL
);
12620 dw2_asm_output_data (1, 0, "End directory table");
12621 dw2_asm_output_data (1, 0, "End file name table");
12626 numfiles
= last_emitted_file
->emitted_number
;
12628 /* Allocate the various arrays we need. */
12629 files
= XALLOCAVEC (struct file_info
, numfiles
);
12630 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
12632 fnad
.files
= files
;
12633 fnad
.used_files
= 0;
12634 fnad
.max_files
= numfiles
;
12635 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
12636 gcc_assert (fnad
.used_files
== fnad
.max_files
);
12638 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
12640 /* Find all the different directories used. */
12641 dirs
[0].path
= files
[0].path
;
12642 dirs
[0].length
= files
[0].fname
- files
[0].path
;
12643 dirs
[0].prefix
= -1;
12645 dirs
[0].dir_idx
= 0;
12646 files
[0].dir_idx
= 0;
12649 for (i
= 1; i
< numfiles
; i
++)
12650 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
12651 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
12652 dirs
[ndirs
- 1].length
) == 0)
12654 /* Same directory as last entry. */
12655 files
[i
].dir_idx
= ndirs
- 1;
12656 ++dirs
[ndirs
- 1].count
;
12662 /* This is a new directory. */
12663 dirs
[ndirs
].path
= files
[i
].path
;
12664 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
12665 dirs
[ndirs
].count
= 1;
12666 dirs
[ndirs
].dir_idx
= ndirs
;
12667 files
[i
].dir_idx
= ndirs
;
12669 /* Search for a prefix. */
12670 dirs
[ndirs
].prefix
= -1;
12671 for (j
= 0; j
< ndirs
; j
++)
12672 if (dirs
[j
].length
< dirs
[ndirs
].length
12673 && dirs
[j
].length
> 1
12674 && (dirs
[ndirs
].prefix
== -1
12675 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
12676 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
12677 dirs
[ndirs
].prefix
= j
;
12682 /* Now to the actual work. We have to find a subset of the directories which
12683 allow expressing the file name using references to the directory table
12684 with the least amount of characters. We do not do an exhaustive search
12685 where we would have to check out every combination of every single
12686 possible prefix. Instead we use a heuristic which provides nearly optimal
12687 results in most cases and never is much off. */
12688 saved
= XALLOCAVEC (int, ndirs
);
12689 savehere
= XALLOCAVEC (int, ndirs
);
12691 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
12692 for (i
= 0; i
< ndirs
; i
++)
12697 /* We can always save some space for the current directory. But this
12698 does not mean it will be enough to justify adding the directory. */
12699 savehere
[i
] = dirs
[i
].length
;
12700 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
12702 for (j
= i
+ 1; j
< ndirs
; j
++)
12705 if (saved
[j
] < dirs
[i
].length
)
12707 /* Determine whether the dirs[i] path is a prefix of the
12711 k
= dirs
[j
].prefix
;
12712 while (k
!= -1 && k
!= (int) i
)
12713 k
= dirs
[k
].prefix
;
12717 /* Yes it is. We can possibly save some memory by
12718 writing the filenames in dirs[j] relative to
12720 savehere
[j
] = dirs
[i
].length
;
12721 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
12726 /* Check whether we can save enough to justify adding the dirs[i]
12728 if (total
> dirs
[i
].length
+ 1)
12730 /* It's worthwhile adding. */
12731 for (j
= i
; j
< ndirs
; j
++)
12732 if (savehere
[j
] > 0)
12734 /* Remember how much we saved for this directory so far. */
12735 saved
[j
] = savehere
[j
];
12737 /* Remember the prefix directory. */
12738 dirs
[j
].dir_idx
= i
;
12743 /* Emit the directory name table. */
12744 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
12745 enum dwarf_form str_form
= DW_FORM_string
;
12746 enum dwarf_form idx_form
= DW_FORM_udata
;
12747 if (dwarf_version
>= 5)
12749 const char *comp_dir
= comp_dir_string ();
12750 if (comp_dir
== NULL
)
12752 dw2_asm_output_data (1, 1, "Directory entry format count");
12753 if (DWARF5_USE_DEBUG_LINE_STR
)
12754 str_form
= DW_FORM_line_strp
;
12755 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12756 dw2_asm_output_data_uleb128 (str_form
, "%s",
12757 get_DW_FORM_name (str_form
));
12758 dw2_asm_output_data_uleb128 (ndirs
+ idx_offset
, "Directories count");
12759 if (str_form
== DW_FORM_string
)
12761 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
12762 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12763 dw2_asm_output_nstring (dirs
[i
].path
,
12765 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
12766 "Directory Entry: %#x", i
+ idx_offset
);
12770 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
12771 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12774 = ggc_alloc_string (dirs
[i
].path
,
12776 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
);
12777 output_line_string (str_form
, str
, "Directory Entry",
12778 (unsigned) i
+ idx_offset
);
12784 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12785 dw2_asm_output_nstring (dirs
[i
].path
,
12787 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
12788 "Directory Entry: %#x", i
+ idx_offset
);
12790 dw2_asm_output_data (1, 0, "End directory table");
12793 /* We have to emit them in the order of emitted_number since that's
12794 used in the debug info generation. To do this efficiently we
12795 generate a back-mapping of the indices first. */
12796 backmap
= XALLOCAVEC (int, numfiles
);
12797 for (i
= 0; i
< numfiles
; i
++)
12798 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
12800 if (dwarf_version
>= 5)
12802 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
12803 if (filename0
== NULL
)
12805 /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
12806 DW_FORM_data2. Choose one based on the number of directories
12807 and how much space would they occupy in each encoding.
12808 If we have at most 256 directories, all indexes fit into
12809 a single byte, so DW_FORM_data1 is most compact (if there
12810 are at most 128 directories, DW_FORM_udata would be as
12811 compact as that, but not shorter and slower to decode). */
12812 if (ndirs
+ idx_offset
<= 256)
12813 idx_form
= DW_FORM_data1
;
12814 /* If there are more than 65536 directories, we have to use
12815 DW_FORM_udata, DW_FORM_data2 can't refer to them.
12816 Otherwise, compute what space would occupy if all the indexes
12817 used DW_FORM_udata - sum - and compare that to how large would
12818 be DW_FORM_data2 encoding, and pick the more efficient one. */
12819 else if (ndirs
+ idx_offset
<= 65536)
12821 unsigned HOST_WIDE_INT sum
= 1;
12822 for (i
= 0; i
< numfiles
; i
++)
12824 int file_idx
= backmap
[i
];
12825 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
12826 sum
+= size_of_uleb128 (dir_idx
);
12828 if (sum
>= HOST_WIDE_INT_UC (2) * (numfiles
+ 1))
12829 idx_form
= DW_FORM_data2
;
12831 #ifdef VMS_DEBUGGING_INFO
12832 dw2_asm_output_data (1, 4, "File name entry format count");
12834 dw2_asm_output_data (1, 2, "File name entry format count");
12836 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12837 dw2_asm_output_data_uleb128 (str_form
, "%s",
12838 get_DW_FORM_name (str_form
));
12839 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
12840 "DW_LNCT_directory_index");
12841 dw2_asm_output_data_uleb128 (idx_form
, "%s",
12842 get_DW_FORM_name (idx_form
));
12843 #ifdef VMS_DEBUGGING_INFO
12844 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
12845 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12846 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
12847 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12849 dw2_asm_output_data_uleb128 (numfiles
+ 1, "File names count");
12851 output_line_string (str_form
, filename0
, "File Entry", 0);
12853 /* Include directory index. */
12854 if (idx_form
!= DW_FORM_udata
)
12855 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
12858 dw2_asm_output_data_uleb128 (0, NULL
);
12860 #ifdef VMS_DEBUGGING_INFO
12861 dw2_asm_output_data_uleb128 (0, NULL
);
12862 dw2_asm_output_data_uleb128 (0, NULL
);
12866 /* Now write all the file names. */
12867 for (i
= 0; i
< numfiles
; i
++)
12869 int file_idx
= backmap
[i
];
12870 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
12872 #ifdef VMS_DEBUGGING_INFO
12873 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12875 /* Setting these fields can lead to debugger miscomparisons,
12876 but VMS Debug requires them to be set correctly. */
12881 int maxfilelen
= (strlen (files
[file_idx
].path
)
12882 + dirs
[dir_idx
].length
12883 + MAX_VMS_VERSION_LEN
+ 1);
12884 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
12886 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
12887 snprintf (filebuf
, maxfilelen
, "%s;%d",
12888 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
12890 output_line_string (str_form
, filebuf
, "File Entry", (unsigned) i
+ 1);
12892 /* Include directory index. */
12893 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
12894 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
12895 dir_idx
+ idx_offset
, NULL
);
12897 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12899 /* Modification time. */
12900 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
12901 &cdt
, 0, 0, 0) == 0)
12904 /* File length in bytes. */
12905 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
12906 0, &siz
, 0, 0) == 0)
12909 output_line_string (str_form
,
12910 files
[file_idx
].path
+ dirs
[dir_idx
].length
,
12911 "File Entry", (unsigned) i
+ 1);
12913 /* Include directory index. */
12914 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
12915 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
12916 dir_idx
+ idx_offset
, NULL
);
12918 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12920 if (dwarf_version
>= 5)
12923 /* Modification time. */
12924 dw2_asm_output_data_uleb128 (0, NULL
);
12926 /* File length in bytes. */
12927 dw2_asm_output_data_uleb128 (0, NULL
);
12928 #endif /* VMS_DEBUGGING_INFO */
12931 if (dwarf_version
< 5)
12932 dw2_asm_output_data (1, 0, "End file name table");
12936 /* Output one line number table into the .debug_line section. */
12939 output_one_line_info_table (dw_line_info_table
*table
)
12941 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12942 unsigned int current_line
= 1;
12943 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
12944 dw_line_info_entry
*ent
, *prev_addr
= NULL
;
12950 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
12952 switch (ent
->opcode
)
12954 case LI_set_address
:
12955 /* ??? Unfortunately, we have little choice here currently, and
12956 must always use the most general form. GCC does not know the
12957 address delta itself, so we can't use DW_LNS_advance_pc. Many
12958 ports do have length attributes which will give an upper bound
12959 on the address range. We could perhaps use length attributes
12960 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
12961 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
12965 /* This can handle any delta. This takes
12966 4+DWARF2_ADDR_SIZE bytes. */
12967 dw2_asm_output_data (1, 0, "set address %s%s", line_label
,
12968 debug_variable_location_views
12969 ? ", reset view to 0" : "");
12970 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12971 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12972 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12977 case LI_adv_address
:
12979 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
12980 char prev_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12981 ASM_GENERATE_INTERNAL_LABEL (prev_label
, LINE_CODE_LABEL
, prev_addr
->val
);
12985 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
, "fixed advance PC, increment view to %i", view
);
12986 dw2_asm_output_delta (2, line_label
, prev_label
,
12987 "from %s to %s", prev_label
, line_label
);
12994 if (ent
->val
== current_line
)
12996 /* We still need to start a new row, so output a copy insn. */
12997 dw2_asm_output_data (1, DW_LNS_copy
,
12998 "copy line %u", current_line
);
13002 int line_offset
= ent
->val
- current_line
;
13003 int line_delta
= line_offset
- DWARF_LINE_BASE
;
13005 current_line
= ent
->val
;
13006 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
13008 /* This can handle deltas from -10 to 234, using the current
13009 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
13010 This takes 1 byte. */
13011 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
13012 "line %u", current_line
);
13016 /* This can handle any delta. This takes at least 4 bytes,
13017 depending on the value being encoded. */
13018 dw2_asm_output_data (1, DW_LNS_advance_line
,
13019 "advance to line %u", current_line
);
13020 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
13021 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
13027 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
13028 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
13031 case LI_set_column
:
13032 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
13033 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
13036 case LI_negate_stmt
:
13037 current_is_stmt
= !current_is_stmt
;
13038 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
13039 "is_stmt %d", current_is_stmt
);
13042 case LI_set_prologue_end
:
13043 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
13044 "set prologue end");
13047 case LI_set_epilogue_begin
:
13048 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
13049 "set epilogue begin");
13052 case LI_set_discriminator
:
13053 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
13054 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
13055 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
13056 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
13061 /* Emit debug info for the address of the end of the table. */
13062 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
13063 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
13064 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
13065 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
13067 dw2_asm_output_data (1, 0, "end sequence");
13068 dw2_asm_output_data_uleb128 (1, NULL
);
13069 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
13072 static unsigned int output_line_info_generation
;
13074 /* Output the source line number correspondence information. This
13075 information goes into the .debug_line section. */
13078 output_line_info (bool prologue_only
)
13080 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
13081 char p1
[MAX_ARTIFICIAL_LABEL_BYTES
], p2
[MAX_ARTIFICIAL_LABEL_BYTES
];
13082 bool saw_one
= false;
13085 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
,
13086 output_line_info_generation
);
13087 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
,
13088 output_line_info_generation
);
13089 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
,
13090 output_line_info_generation
);
13091 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
,
13092 output_line_info_generation
++);
13094 if (!XCOFF_DEBUGGING_INFO
)
13096 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
13097 dw2_asm_output_data (4, 0xffffffff,
13098 "Initial length escape value indicating 64-bit DWARF extension");
13099 dw2_asm_output_delta (dwarf_offset_size
, l2
, l1
,
13100 "Length of Source Line Info");
13103 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
13105 output_dwarf_version ();
13106 if (dwarf_version
>= 5)
13108 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
13109 dw2_asm_output_data (1, 0, "Segment Size");
13111 dw2_asm_output_delta (dwarf_offset_size
, p2
, p1
, "Prolog Length");
13112 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
13114 /* Define the architecture-dependent minimum instruction length (in bytes).
13115 In this implementation of DWARF, this field is used for information
13116 purposes only. Since GCC generates assembly language, we have no
13117 a priori knowledge of how many instruction bytes are generated for each
13118 source line, and therefore can use only the DW_LNE_set_address and
13119 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
13120 this as '1', which is "correct enough" for all architectures,
13121 and don't let the target override. */
13122 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
13124 if (dwarf_version
>= 4)
13125 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
13126 "Maximum Operations Per Instruction");
13127 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
13128 "Default is_stmt_start flag");
13129 dw2_asm_output_data (1, DWARF_LINE_BASE
,
13130 "Line Base Value (Special Opcodes)");
13131 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
13132 "Line Range Value (Special Opcodes)");
13133 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
13134 "Special Opcode Base");
13136 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
13141 case DW_LNS_advance_pc
:
13142 case DW_LNS_advance_line
:
13143 case DW_LNS_set_file
:
13144 case DW_LNS_set_column
:
13145 case DW_LNS_fixed_advance_pc
:
13146 case DW_LNS_set_isa
:
13154 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
13158 /* Write out the information about the files we use. */
13159 output_file_names ();
13160 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
13163 /* Output the marker for the end of the line number info. */
13164 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
13168 if (separate_line_info
)
13170 dw_line_info_table
*table
;
13173 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
13176 output_one_line_info_table (table
);
13180 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
13182 output_one_line_info_table (cold_text_section_line_info
);
13186 /* ??? Some Darwin linkers crash on a .debug_line section with no
13187 sequences. Further, merely a DW_LNE_end_sequence entry is not
13188 sufficient -- the address column must also be initialized.
13189 Make sure to output at least one set_address/end_sequence pair,
13190 choosing .text since that section is always present. */
13191 if (text_section_line_info
->in_use
|| !saw_one
)
13192 output_one_line_info_table (text_section_line_info
);
13194 /* Output the marker for the end of the line number info. */
13195 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
13198 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
13201 need_endianity_attribute_p (bool reverse
)
13203 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
13206 /* Given a pointer to a tree node for some base type, return a pointer to
13207 a DIE that describes the given type. REVERSE is true if the type is
13208 to be interpreted in the reverse storage order wrt the target order.
13210 This routine must only be called for GCC type nodes that correspond to
13211 Dwarf base (fundamental) types. */
13214 base_type_die (tree type
, bool reverse
)
13216 dw_die_ref base_type_result
;
13217 enum dwarf_type encoding
;
13218 bool fpt_used
= false;
13219 struct fixed_point_type_info fpt_info
;
13220 tree type_bias
= NULL_TREE
;
13222 /* If this is a subtype that should not be emitted as a subrange type,
13223 use the base type. See subrange_type_for_debug_p. */
13224 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
13225 type
= TREE_TYPE (type
);
13227 switch (TREE_CODE (type
))
13230 if ((dwarf_version
>= 4 || !dwarf_strict
)
13231 && TYPE_NAME (type
)
13232 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
13233 && DECL_IS_UNDECLARED_BUILTIN (TYPE_NAME (type
))
13234 && DECL_NAME (TYPE_NAME (type
)))
13236 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
13237 if (strcmp (name
, "char16_t") == 0
13238 || strcmp (name
, "char8_t") == 0
13239 || strcmp (name
, "char32_t") == 0)
13241 encoding
= DW_ATE_UTF
;
13245 if ((dwarf_version
>= 3 || !dwarf_strict
)
13246 && lang_hooks
.types
.get_fixed_point_type_info
)
13248 memset (&fpt_info
, 0, sizeof (fpt_info
));
13249 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
13252 encoding
= ((TYPE_UNSIGNED (type
))
13253 ? DW_ATE_unsigned_fixed
13254 : DW_ATE_signed_fixed
);
13258 if (TYPE_STRING_FLAG (type
))
13260 if ((dwarf_version
>= 4 || !dwarf_strict
)
13262 && int_size_in_bytes (type
) == 4)
13263 encoding
= DW_ATE_UTF
;
13264 else if (TYPE_UNSIGNED (type
))
13265 encoding
= DW_ATE_unsigned_char
;
13267 encoding
= DW_ATE_signed_char
;
13269 else if (TYPE_UNSIGNED (type
))
13270 encoding
= DW_ATE_unsigned
;
13272 encoding
= DW_ATE_signed
;
13275 && lang_hooks
.types
.get_type_bias
)
13276 type_bias
= lang_hooks
.types
.get_type_bias (type
);
13280 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
13282 if (dwarf_version
>= 3 || !dwarf_strict
)
13283 encoding
= DW_ATE_decimal_float
;
13285 encoding
= DW_ATE_lo_user
;
13288 encoding
= DW_ATE_float
;
13291 case FIXED_POINT_TYPE
:
13292 if (!(dwarf_version
>= 3 || !dwarf_strict
))
13293 encoding
= DW_ATE_lo_user
;
13294 else if (TYPE_UNSIGNED (type
))
13295 encoding
= DW_ATE_unsigned_fixed
;
13297 encoding
= DW_ATE_signed_fixed
;
13300 /* Dwarf2 doesn't know anything about complex ints, so use
13301 a user defined type for it. */
13303 if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (type
)))
13304 encoding
= DW_ATE_complex_float
;
13306 encoding
= DW_ATE_lo_user
;
13310 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
13311 encoding
= DW_ATE_boolean
;
13315 /* C23 _BitInt(N). */
13316 if (TYPE_UNSIGNED (type
))
13317 encoding
= DW_ATE_unsigned
;
13319 encoding
= DW_ATE_signed
;
13323 /* No other TREE_CODEs are Dwarf fundamental types. */
13324 gcc_unreachable ();
13327 base_type_result
= new_die_raw (DW_TAG_base_type
);
13329 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
13330 int_size_in_bytes (type
));
13331 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
13332 if (TREE_CODE (type
) == BITINT_TYPE
)
13333 add_AT_unsigned (base_type_result
, DW_AT_bit_size
, TYPE_PRECISION (type
));
13335 if (need_endianity_attribute_p (reverse
))
13336 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
13337 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
13339 add_alignment_attribute (base_type_result
, type
);
13343 switch (fpt_info
.scale_factor_kind
)
13345 case fixed_point_scale_factor_binary
:
13346 add_AT_int (base_type_result
, DW_AT_binary_scale
,
13347 fpt_info
.scale_factor
.binary
);
13350 case fixed_point_scale_factor_decimal
:
13351 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
13352 fpt_info
.scale_factor
.decimal
);
13355 case fixed_point_scale_factor_arbitrary
:
13356 /* Arbitrary scale factors cannot be described in standard DWARF. */
13359 /* Describe the scale factor as a rational constant. */
13360 const dw_die_ref scale_factor
13361 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
13363 add_scalar_info (scale_factor
, DW_AT_GNU_numerator
,
13364 fpt_info
.scale_factor
.arbitrary
.numerator
,
13365 dw_scalar_form_constant
, NULL
);
13366 add_scalar_info (scale_factor
, DW_AT_GNU_denominator
,
13367 fpt_info
.scale_factor
.arbitrary
.denominator
,
13368 dw_scalar_form_constant
, NULL
);
13370 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
13375 gcc_unreachable ();
13380 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
13381 dw_scalar_form_constant
13382 | dw_scalar_form_exprloc
13383 | dw_scalar_form_reference
,
13386 return base_type_result
;
13389 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
13390 named 'auto' in its type: return true for it, false otherwise. */
13393 is_cxx_auto (tree type
)
13397 tree name
= TYPE_IDENTIFIER (type
);
13398 if (name
== get_identifier ("auto")
13399 || name
== get_identifier ("decltype(auto)"))
13405 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if the
13406 given input type is a Dwarf "fundamental" type. Otherwise return null. */
13409 is_base_type (tree type
)
13411 switch (TREE_CODE (type
))
13415 case FIXED_POINT_TYPE
:
13426 case QUAL_UNION_TYPE
:
13427 case ENUMERAL_TYPE
:
13428 case FUNCTION_TYPE
:
13431 case REFERENCE_TYPE
:
13439 if (is_cxx_auto (type
))
13441 gcc_unreachable ();
13445 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
13446 node, return the size in bits for the type if it is a constant, or else
13447 return the alignment for the type if the type's size is not constant, or
13448 else return BITS_PER_WORD if the type actually turns out to be an
13449 ERROR_MARK node. */
13451 static inline unsigned HOST_WIDE_INT
13452 simple_type_size_in_bits (const_tree type
)
13454 if (TREE_CODE (type
) == ERROR_MARK
)
13455 return BITS_PER_WORD
;
13456 else if (TYPE_SIZE (type
) == NULL_TREE
)
13458 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
13459 return tree_to_uhwi (TYPE_SIZE (type
));
13461 return TYPE_ALIGN (type
);
13464 /* Similarly, but return an offset_int instead of UHWI. */
13466 static inline offset_int
13467 offset_int_type_size_in_bits (const_tree type
)
13469 if (TREE_CODE (type
) == ERROR_MARK
)
13470 return BITS_PER_WORD
;
13471 else if (TYPE_SIZE (type
) == NULL_TREE
)
13473 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
13474 return wi::to_offset (TYPE_SIZE (type
));
13476 return TYPE_ALIGN (type
);
13479 /* Given a pointer to a tree node for a subrange type, return a pointer
13480 to a DIE that describes the given type. */
13483 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
13484 dw_die_ref context_die
)
13486 dw_die_ref subrange_die
;
13487 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
13489 if (context_die
== NULL
)
13490 context_die
= comp_unit_die ();
13492 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
13494 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
13496 /* The size of the subrange type and its base type do not match,
13497 so we need to generate a size attribute for the subrange type. */
13498 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
13501 add_alignment_attribute (subrange_die
, type
);
13504 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
13506 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
13507 if (bias
&& !dwarf_strict
)
13508 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
13509 dw_scalar_form_constant
13510 | dw_scalar_form_exprloc
13511 | dw_scalar_form_reference
,
13514 return subrange_die
;
13517 /* Returns the (const and/or volatile) cv_qualifiers associated with
13518 the decl node. This will normally be augmented with the
13519 cv_qualifiers of the underlying type in add_type_attribute. */
13522 decl_quals (const_tree decl
)
13524 return ((TREE_READONLY (decl
)
13525 /* The C++ front-end correctly marks reference-typed
13526 variables as readonly, but from a language (and debug
13527 info) standpoint they are not const-qualified. */
13528 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
13529 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
13530 | (TREE_THIS_VOLATILE (decl
)
13531 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
13534 /* Determine the TYPE whose qualifiers match the largest strict subset
13535 of the given TYPE_QUALS, and return its qualifiers. Ignore all
13536 qualifiers outside QUAL_MASK. */
13539 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
13542 int best_rank
= 0, best_qual
= 0, max_rank
;
13544 type_quals
&= qual_mask
;
13545 max_rank
= popcount_hwi (type_quals
) - 1;
13547 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
13548 t
= TYPE_NEXT_VARIANT (t
))
13550 int q
= TYPE_QUALS (t
) & qual_mask
;
13552 if ((q
& type_quals
) == q
&& q
!= type_quals
13553 && check_base_type (t
, type
))
13555 int rank
= popcount_hwi (q
);
13557 if (rank
> best_rank
)
13568 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
13569 static const dwarf_qual_info_t dwarf_qual_info
[] =
13571 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
13572 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
13573 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
13574 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
13576 static const unsigned int dwarf_qual_info_size
= ARRAY_SIZE (dwarf_qual_info
);
13578 /* If DIE is a qualified DIE of some base DIE with the same parent,
13579 return the base DIE, otherwise return NULL. Set MASK to the
13580 qualifiers added compared to the returned DIE. */
13583 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
13586 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
13587 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
13589 if (i
== dwarf_qual_info_size
)
13591 if (vec_safe_length (die
->die_attr
) != 1)
13593 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
13594 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
13596 *mask
|= dwarf_qual_info
[i
].q
;
13599 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
13606 /* If TYPE is long double or complex long double that
13607 should be emitted as artificial typedef to _Float128 or
13608 complex _Float128, return the type it should be emitted as.
13609 This is done in case the target already supports 16-byte
13610 composite floating point type (ibm_extended_format). */
13613 long_double_as_float128 (tree type
)
13615 if (type
!= long_double_type_node
13616 && type
!= complex_long_double_type_node
)
13619 machine_mode mode
, fmode
;
13620 if (TREE_CODE (type
) == COMPLEX_TYPE
)
13621 mode
= TYPE_MODE (TREE_TYPE (type
));
13623 mode
= TYPE_MODE (type
);
13624 if (known_eq (GET_MODE_SIZE (mode
), 16) && !MODE_COMPOSITE_P (mode
))
13625 FOR_EACH_MODE_IN_CLASS (fmode
, MODE_FLOAT
)
13626 if (known_eq (GET_MODE_SIZE (fmode
), 16)
13627 && MODE_COMPOSITE_P (fmode
))
13629 if (type
== long_double_type_node
)
13631 if (float128_type_node
13632 && (TYPE_MODE (float128_type_node
)
13633 == TYPE_MODE (type
)))
13634 return float128_type_node
;
13637 for (int i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
13638 if (COMPLEX_FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
13639 && (TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i
))
13640 == TYPE_MODE (type
)))
13641 return COMPLEX_FLOATN_NX_TYPE_NODE (i
);
13647 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
13648 entry that chains the modifiers specified by CV_QUALS in front of the
13649 given type. REVERSE is true if the type is to be interpreted in the
13650 reverse storage order wrt the target order. */
13653 modified_type_die (tree type
, int cv_quals
, bool reverse
,
13654 dw_die_ref context_die
)
13656 enum tree_code code
= TREE_CODE (type
);
13657 dw_die_ref mod_type_die
;
13658 dw_die_ref sub_die
= NULL
;
13659 tree item_type
= NULL
;
13660 tree qualified_type
;
13661 tree name
, low
, high
;
13662 dw_die_ref mod_scope
;
13663 struct array_descr_info info
;
13664 /* Only these cv-qualifiers are currently handled. */
13665 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
13666 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
|
13667 ENCODE_QUAL_ADDR_SPACE(~0U));
13668 const bool reverse_base_type
13669 = need_endianity_attribute_p (reverse
) && is_base_type (type
);
13671 if (code
== ERROR_MARK
)
13674 if (lang_hooks
.types
.get_debug_type
)
13676 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
13678 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
13679 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
13682 cv_quals
&= cv_qual_mask
;
13684 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
13685 tag modifier (and not an attribute) old consumers won't be able
13687 if (dwarf_version
< 3)
13688 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
13690 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
13691 if (dwarf_version
< 5)
13692 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
13694 /* See if we already have the appropriately qualified variant of
13696 qualified_type
= get_qualified_type (type
, cv_quals
);
13698 if (qualified_type
== sizetype
)
13700 /* Try not to expose the internal sizetype type's name. */
13701 if (TYPE_NAME (qualified_type
)
13702 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
13704 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
13706 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
13707 && (TYPE_PRECISION (t
)
13708 == TYPE_PRECISION (qualified_type
))
13709 && (TYPE_UNSIGNED (t
)
13710 == TYPE_UNSIGNED (qualified_type
)));
13711 qualified_type
= t
;
13713 else if (qualified_type
== sizetype
13714 && TREE_CODE (sizetype
) == TREE_CODE (size_type_node
)
13715 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (size_type_node
)
13716 && TYPE_UNSIGNED (sizetype
) == TYPE_UNSIGNED (size_type_node
))
13717 qualified_type
= size_type_node
;
13718 if (type
== sizetype
)
13719 type
= qualified_type
;
13722 /* If we do, then we can just use its DIE, if it exists. */
13723 if (qualified_type
)
13725 mod_type_die
= lookup_type_die (qualified_type
);
13727 /* DW_AT_endianity doesn't come from a qualifier on the type, so it is
13728 dealt with specially: the DIE with the attribute, if it exists, is
13729 placed immediately after the regular DIE for the same base type. */
13731 && (!reverse_base_type
13732 || ((mod_type_die
= mod_type_die
->die_sib
) != NULL
13733 && get_AT_unsigned (mod_type_die
, DW_AT_endianity
))))
13734 return mod_type_die
;
13737 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
13739 /* Handle C typedef types. */
13741 && TREE_CODE (name
) == TYPE_DECL
13742 && DECL_ORIGINAL_TYPE (name
)
13743 && !DECL_ARTIFICIAL (name
))
13745 tree dtype
= TREE_TYPE (name
);
13747 /* Skip the typedef for base types with DW_AT_endianity, no big deal. */
13748 if (qualified_type
== dtype
&& !reverse_base_type
)
13750 tree origin
= decl_ultimate_origin (name
);
13752 /* Typedef variants that have an abstract origin don't get their own
13753 type DIE (see gen_typedef_die), so fall back on the ultimate
13754 abstract origin instead. */
13755 if (origin
!= NULL
&& origin
!= name
)
13756 return modified_type_die (TREE_TYPE (origin
), cv_quals
, reverse
,
13759 /* For a named type, use the typedef. */
13760 gen_type_die (qualified_type
, context_die
);
13761 return lookup_type_die (qualified_type
);
13765 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
13766 dquals
&= cv_qual_mask
;
13767 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
13768 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
13769 /* cv-unqualified version of named type. Just use
13770 the unnamed type to which it refers. */
13771 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
13772 reverse
, context_die
);
13773 /* Else cv-qualified version of named type; fall through. */
13777 mod_scope
= scope_die_for (type
, context_die
);
13781 int sub_quals
= 0, first_quals
= 0;
13783 dw_die_ref first
= NULL
, last
= NULL
;
13785 /* Determine a lesser qualified type that most closely matches
13786 this one. Then generate DW_TAG_* entries for the remaining
13788 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
13790 if (sub_quals
&& use_debug_types
)
13792 bool needed
= false;
13793 /* If emitting type units, make sure the order of qualifiers
13794 is canonical. Thus, start from unqualified type if
13795 an earlier qualifier is missing in sub_quals, but some later
13796 one is present there. */
13797 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
13798 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
13800 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
13806 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
13807 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
13809 /* As not all intermediate qualified DIEs have corresponding
13810 tree types, ensure that qualified DIEs in the same scope
13811 as their DW_AT_type are emitted after their DW_AT_type,
13812 only with other qualified DIEs for the same type possibly
13813 in between them. Determine the range of such qualified
13814 DIEs now (first being the base type, last being corresponding
13815 last qualified DIE for it). */
13816 unsigned int count
= 0;
13817 first
= qualified_die_p (mod_type_die
, &first_quals
,
13818 dwarf_qual_info_size
);
13820 first
= mod_type_die
;
13821 gcc_assert ((first_quals
& ~sub_quals
) == 0);
13822 for (count
= 0, last
= first
;
13823 count
< (1U << dwarf_qual_info_size
);
13824 count
++, last
= last
->die_sib
)
13827 if (last
== mod_scope
->die_child
)
13829 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
13835 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
13836 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
13839 if (first
&& first
!= last
)
13841 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
13844 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
13845 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
13861 d
= new_die_raw (dwarf_qual_info
[i
].t
);
13862 add_child_die_after (mod_scope
, d
, last
);
13866 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
13868 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
13870 first_quals
|= dwarf_qual_info
[i
].q
;
13873 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
13875 dwarf_tag tag
= DW_TAG_pointer_type
;
13876 if (code
== REFERENCE_TYPE
)
13878 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
13879 tag
= DW_TAG_rvalue_reference_type
;
13881 tag
= DW_TAG_reference_type
;
13883 mod_type_die
= new_die (tag
, mod_scope
, type
);
13885 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
13886 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
13887 add_alignment_attribute (mod_type_die
, type
);
13888 item_type
= TREE_TYPE (type
);
13890 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
13891 if (!ADDR_SPACE_GENERIC_P (as
))
13893 int action
= targetm
.addr_space
.debug (as
);
13896 /* Positive values indicate an address_class. */
13897 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
13901 /* Negative values indicate an (inverted) segment base reg. */
13903 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
13904 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
13908 else if (code
== ARRAY_TYPE
13909 || (lang_hooks
.types
.get_array_descr_info
13910 && lang_hooks
.types
.get_array_descr_info (type
, &info
)))
13912 gen_type_die (type
, context_die
);
13913 return lookup_type_die (type
);
13915 else if (code
== INTEGER_TYPE
13916 && TREE_TYPE (type
) != NULL_TREE
13917 && subrange_type_for_debug_p (type
, &low
, &high
))
13919 tree bias
= NULL_TREE
;
13920 if (lang_hooks
.types
.get_type_bias
)
13921 bias
= lang_hooks
.types
.get_type_bias (type
);
13922 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
13923 item_type
= TREE_TYPE (type
);
13925 else if (is_base_type (type
))
13927 /* If a target supports long double as different floating point
13928 modes with the same 16-byte size, use normal DW_TAG_base_type
13929 only for the composite (ibm_extended_real_format) type and
13930 for the other for the time being emit instead a "_Float128"
13931 or "complex _Float128" DW_TAG_base_type and a "long double"
13932 or "complex long double" typedef to it. */
13933 if (tree other_type
= long_double_as_float128 (type
))
13935 dw_die_ref other_die
;
13936 if (TYPE_NAME (other_type
))
13938 = modified_type_die (other_type
, TYPE_UNQUALIFIED
, reverse
,
13942 other_die
= base_type_die (type
, reverse
);
13943 add_child_die (comp_unit_die (), other_die
);
13944 add_name_attribute (other_die
,
13945 TREE_CODE (type
) == COMPLEX_TYPE
13946 ? "complex _Float128" : "_Float128");
13948 mod_type_die
= new_die_raw (DW_TAG_typedef
);
13949 add_AT_die_ref (mod_type_die
, DW_AT_type
, other_die
);
13952 mod_type_die
= base_type_die (type
, reverse
);
13954 /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
13955 if (reverse_base_type
)
13957 dw_die_ref after_die
13958 = modified_type_die (type
, cv_quals
, false, context_die
);
13959 add_child_die_after (comp_unit_die (), mod_type_die
, after_die
);
13962 add_child_die (comp_unit_die (), mod_type_die
);
13964 add_pubtype (type
, mod_type_die
);
13968 gen_type_die (type
, context_die
);
13970 /* We have to get the type_main_variant here (and pass that to the
13971 `lookup_type_die' routine) because the ..._TYPE node we have
13972 might simply be a *copy* of some original type node (where the
13973 copy was created to help us keep track of typedef names) and
13974 that copy might have a different TYPE_UID from the original
13976 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
13978 /* For function/method types, can't just use type_main_variant here,
13979 because that can have different ref-qualifiers for C++,
13980 but try to canonicalize. */
13981 tree main
= TYPE_MAIN_VARIANT (type
);
13982 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
13983 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
13984 && check_base_type (t
, main
)
13985 && check_lang_type (t
, type
))
13986 return lookup_type_die (t
);
13987 return lookup_type_die (type
);
13989 /* Vectors have the debugging information in the type,
13990 not the main variant. */
13991 else if (code
== VECTOR_TYPE
)
13992 return lookup_type_die (type
);
13994 return lookup_type_die (type_main_variant (type
));
13997 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
13998 don't output a DW_TAG_typedef, since there isn't one in the
13999 user's program; just attach a DW_AT_name to the type.
14000 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
14001 if the base type already has the same name. */
14003 && ((TREE_CODE (name
) != TYPE_DECL
14004 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
14005 || (cv_quals
== TYPE_UNQUALIFIED
)))
14006 || (TREE_CODE (name
) == TYPE_DECL
14007 && TREE_TYPE (name
) == qualified_type
14008 && DECL_NAME (name
))))
14010 if (TREE_CODE (name
) == TYPE_DECL
)
14011 /* Could just call add_name_and_src_coords_attributes here,
14012 but since this is a builtin type it doesn't have any
14013 useful source coordinates anyway. */
14014 name
= DECL_NAME (name
);
14015 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
14017 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
14019 if (TREE_CODE (type
) == BITINT_TYPE
)
14021 char name_buf
[sizeof ("unsigned _BitInt(2147483647)")];
14022 snprintf (name_buf
, sizeof (name_buf
),
14023 "%s_BitInt(%d)", TYPE_UNSIGNED (type
) ? "unsigned " : "",
14024 TYPE_PRECISION (type
));
14025 add_name_attribute (mod_type_die
, name_buf
);
14029 /* This probably indicates a bug. */
14030 name
= TYPE_IDENTIFIER (type
);
14031 add_name_attribute (mod_type_die
,
14033 ? IDENTIFIER_POINTER (name
) : "__unknown__");
14037 if (qualified_type
&& !reverse_base_type
)
14038 equate_type_number_to_die (qualified_type
, mod_type_die
);
14041 /* We must do this after the equate_type_number_to_die call, in case
14042 this is a recursive type. This ensures that the modified_type_die
14043 recursion will terminate even if the type is recursive. Recursive
14044 types are possible in Ada. */
14045 sub_die
= modified_type_die (item_type
,
14046 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
14050 if (sub_die
!= NULL
)
14051 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
14053 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
14054 if (TYPE_ARTIFICIAL (type
))
14055 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
14057 return mod_type_die
;
14060 /* Generate DIEs for the generic parameters of T.
14061 T must be either a generic type or a generic function.
14062 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
14065 gen_generic_params_dies (tree t
)
14069 dw_die_ref die
= NULL
;
14072 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
14076 die
= lookup_type_die (t
);
14077 else if (DECL_P (t
))
14078 die
= lookup_decl_die (t
);
14082 parms
= lang_hooks
.get_innermost_generic_parms (t
);
14084 /* T has no generic parameter. It means T is neither a generic type
14085 or function. End of story. */
14088 parms_num
= TREE_VEC_LENGTH (parms
);
14089 args
= lang_hooks
.get_innermost_generic_args (t
);
14090 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
14091 non_default
= int_cst_value (TREE_CHAIN (args
));
14093 non_default
= TREE_VEC_LENGTH (args
);
14094 for (i
= 0; i
< parms_num
; i
++)
14096 tree parm
, arg
, arg_pack_elems
;
14097 dw_die_ref parm_die
;
14099 parm
= TREE_VEC_ELT (parms
, i
);
14100 arg
= TREE_VEC_ELT (args
, i
);
14101 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
14102 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
14104 if (parm
&& TREE_VALUE (parm
) && arg
)
14106 /* If PARM represents a template parameter pack,
14107 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
14108 by DW_TAG_template_*_parameter DIEs for the argument
14109 pack elements of ARG. Note that ARG would then be
14110 an argument pack. */
14111 if (arg_pack_elems
)
14112 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
14116 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
14117 true /* emit name */, die
);
14118 if (i
>= non_default
)
14119 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
14124 /* Create and return a DIE for PARM which should be
14125 the representation of a generic type parameter.
14126 For instance, in the C++ front end, PARM would be a template parameter.
14127 ARG is the argument to PARM.
14128 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
14130 PARENT_DIE is the parent DIE which the new created DIE should be added to,
14131 as a child node. */
14134 generic_parameter_die (tree parm
, tree arg
,
14136 dw_die_ref parent_die
)
14138 dw_die_ref tmpl_die
= NULL
;
14139 const char *name
= NULL
;
14141 /* C++20 accepts class literals as template parameters, and var
14142 decls with initializers represent them. The VAR_DECLs would be
14143 rejected, but we can take the DECL_INITIAL constructor and
14144 attempt to expand it. */
14145 if (arg
&& VAR_P (arg
))
14146 arg
= DECL_INITIAL (arg
);
14148 if (!parm
|| !DECL_NAME (parm
) || !arg
)
14151 /* We support non-type generic parameters and arguments,
14152 type generic parameters and arguments, as well as
14153 generic generic parameters (a.k.a. template template parameters in C++)
14155 if (TREE_CODE (parm
) == PARM_DECL
)
14156 /* PARM is a nontype generic parameter */
14157 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
14158 else if (TREE_CODE (parm
) == TYPE_DECL
)
14159 /* PARM is a type generic parameter. */
14160 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
14161 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
14162 /* PARM is a generic generic parameter.
14163 Its DIE is a GNU extension. It shall have a
14164 DW_AT_name attribute to represent the name of the template template
14165 parameter, and a DW_AT_GNU_template_name attribute to represent the
14166 name of the template template argument. */
14167 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
14170 gcc_unreachable ();
14176 /* If PARM is a generic parameter pack, it means we are
14177 emitting debug info for a template argument pack element.
14178 In other terms, ARG is a template argument pack element.
14179 In that case, we don't emit any DW_AT_name attribute for
14183 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
14185 add_AT_string (tmpl_die
, DW_AT_name
, name
);
14188 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
14190 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
14191 TMPL_DIE should have a child DW_AT_type attribute that is set
14192 to the type of the argument to PARM, which is ARG.
14193 If PARM is a type generic parameter, TMPL_DIE should have a
14194 child DW_AT_type that is set to ARG. */
14195 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
14196 add_type_attribute (tmpl_die
, tmpl_type
,
14197 (TREE_THIS_VOLATILE (tmpl_type
)
14198 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
14199 false, parent_die
);
14203 /* So TMPL_DIE is a DIE representing a
14204 a generic generic template parameter, a.k.a template template
14205 parameter in C++ and arg is a template. */
14207 /* The DW_AT_GNU_template_name attribute of the DIE must be set
14208 to the name of the argument. */
14209 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
14211 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
14214 if (TREE_CODE (parm
) == PARM_DECL
)
14215 /* So PARM is a non-type generic parameter.
14216 DWARF3 5.6.8 says we must set a DW_AT_const_value child
14217 attribute of TMPL_DIE which value represents the value
14219 We must be careful here:
14220 The value of ARG might reference some function decls.
14221 We might currently be emitting debug info for a generic
14222 type and types are emitted before function decls, we don't
14223 know if the function decls referenced by ARG will actually be
14224 emitted after cgraph computations.
14225 So must defer the generation of the DW_AT_const_value to
14226 after cgraph is ready. */
14227 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
14233 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
14234 PARM_PACK must be a template parameter pack. The returned DIE
14235 will be child DIE of PARENT_DIE. */
14238 template_parameter_pack_die (tree parm_pack
,
14239 tree parm_pack_args
,
14240 dw_die_ref parent_die
)
14245 gcc_assert (parent_die
&& parm_pack
);
14247 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
14248 add_name_and_src_coords_attributes (die
, parm_pack
);
14249 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
14250 generic_parameter_die (parm_pack
,
14251 TREE_VEC_ELT (parm_pack_args
, j
),
14252 false /* Don't emit DW_AT_name */,
14257 /* Return the debugger register number described by a given RTL node. */
14259 static unsigned int
14260 debugger_reg_number (const_rtx rtl
)
14262 unsigned regno
= REGNO (rtl
);
14264 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
14266 #ifdef LEAF_REG_REMAP
14267 if (crtl
->uses_only_leaf_regs
)
14269 int leaf_reg
= LEAF_REG_REMAP (regno
);
14270 if (leaf_reg
!= -1)
14271 regno
= (unsigned) leaf_reg
;
14275 regno
= DEBUGGER_REGNO (regno
);
14276 gcc_assert (regno
!= INVALID_REGNUM
);
14280 /* Optionally add a DW_OP_piece term to a location description expression.
14281 DW_OP_piece is only added if the location description expression already
14282 doesn't end with DW_OP_piece. */
14285 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
14287 dw_loc_descr_ref loc
;
14289 if (*list_head
!= NULL
)
14291 /* Find the end of the chain. */
14292 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
14295 if (loc
->dw_loc_opc
!= DW_OP_piece
)
14296 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
14300 /* Return a location descriptor that designates a machine register or
14301 zero if there is none. */
14303 static dw_loc_descr_ref
14304 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
14308 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
14311 /* We only use "frame base" when we're sure we're talking about the
14312 post-prologue local stack frame. We do this by *not* running
14313 register elimination until this point, and recognizing the special
14314 argument pointer and soft frame pointer rtx's.
14315 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
14316 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
14318 ? lra_eliminate_regs (rtl
, VOIDmode
, NULL_RTX
)
14319 : eliminate_regs (rtl
, VOIDmode
, NULL_RTX
)) != rtl
)
14321 dw_loc_descr_ref result
= NULL
;
14323 if (dwarf_version
>= 4 || !dwarf_strict
)
14325 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
14328 add_loc_descr (&result
,
14329 new_loc_descr (DW_OP_stack_value
, 0, 0));
14334 regs
= targetm
.dwarf_register_span (rtl
);
14336 if (REG_NREGS (rtl
) > 1 || regs
)
14337 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
14340 unsigned int debugger_regnum
= debugger_reg_number (rtl
);
14341 if (debugger_regnum
== IGNORED_DWARF_REGNUM
)
14343 return one_reg_loc_descriptor (debugger_regnum
, initialized
);
14347 /* Return a location descriptor that designates a machine register for
14348 a given hard register number. */
14350 static dw_loc_descr_ref
14351 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
14353 dw_loc_descr_ref reg_loc_descr
;
14357 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
14359 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
14361 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14362 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14364 return reg_loc_descr
;
14367 /* Given an RTL of a register, return a location descriptor that
14368 designates a value that spans more than one register. */
14370 static dw_loc_descr_ref
14371 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
14372 enum var_init_status initialized
)
14375 dw_loc_descr_ref loc_result
= NULL
;
14377 /* Simple, contiguous registers. */
14378 if (regs
== NULL_RTX
)
14380 unsigned reg
= REGNO (rtl
);
14383 #ifdef LEAF_REG_REMAP
14384 if (crtl
->uses_only_leaf_regs
)
14386 int leaf_reg
= LEAF_REG_REMAP (reg
);
14387 if (leaf_reg
!= -1)
14388 reg
= (unsigned) leaf_reg
;
14392 gcc_assert ((unsigned) DEBUGGER_REGNO (reg
) == debugger_reg_number (rtl
));
14393 nregs
= REG_NREGS (rtl
);
14395 /* At present we only track constant-sized pieces. */
14396 if (!GET_MODE_SIZE (GET_MODE (rtl
)).is_constant (&size
))
14403 dw_loc_descr_ref t
;
14405 t
= one_reg_loc_descriptor (DEBUGGER_REGNO (reg
),
14406 VAR_INIT_STATUS_INITIALIZED
);
14407 add_loc_descr (&loc_result
, t
);
14408 add_loc_descr_op_piece (&loc_result
, size
);
14414 /* Now onto stupid register sets in non contiguous locations. */
14416 gcc_assert (GET_CODE (regs
) == PARALLEL
);
14418 /* At present we only track constant-sized pieces. */
14419 if (!GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0))).is_constant (&size
))
14423 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
14425 dw_loc_descr_ref t
;
14427 t
= one_reg_loc_descriptor (debugger_reg_number (XVECEXP (regs
, 0, i
)),
14428 VAR_INIT_STATUS_INITIALIZED
);
14429 add_loc_descr (&loc_result
, t
);
14430 add_loc_descr_op_piece (&loc_result
, size
);
14433 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14434 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14438 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
14440 /* Return a location descriptor that designates a constant i,
14441 as a compound operation from constant (i >> shift), constant shift
14444 static dw_loc_descr_ref
14445 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
14447 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
14448 add_loc_descr (&ret
, int_loc_descriptor (shift
));
14449 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14453 /* Return a location descriptor that designates constant POLY_I. */
14455 static dw_loc_descr_ref
14456 int_loc_descriptor (poly_int64 poly_i
)
14458 enum dwarf_location_atom op
;
14461 if (!poly_i
.is_constant (&i
))
14463 /* Create location descriptions for the non-constant part and
14464 add any constant offset at the end. */
14465 dw_loc_descr_ref ret
= NULL
;
14466 HOST_WIDE_INT constant
= poly_i
.coeffs
[0];
14467 for (unsigned int j
= 1; j
< NUM_POLY_INT_COEFFS
; ++j
)
14469 HOST_WIDE_INT coeff
= poly_i
.coeffs
[j
];
14472 dw_loc_descr_ref start
= ret
;
14473 unsigned int factor
;
14475 unsigned int regno
= targetm
.dwarf_poly_indeterminate_value
14476 (j
, &factor
, &bias
);
14478 /* Add COEFF * ((REGNO / FACTOR) - BIAS) to the value:
14479 add COEFF * (REGNO / FACTOR) now and subtract
14480 COEFF * BIAS from the final constant part. */
14481 constant
-= coeff
* bias
;
14482 add_loc_descr (&ret
, new_reg_loc_descr (regno
, 0));
14483 if (coeff
% factor
== 0)
14487 int amount
= exact_log2 (factor
);
14488 gcc_assert (amount
>= 0);
14489 add_loc_descr (&ret
, int_loc_descriptor (amount
));
14490 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14494 add_loc_descr (&ret
, int_loc_descriptor (coeff
));
14495 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14498 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14501 loc_descr_plus_const (&ret
, constant
);
14505 /* Pick the smallest representation of a constant, rather than just
14506 defaulting to the LEB encoding. */
14509 int clz
= clz_hwi (i
);
14510 int ctz
= ctz_hwi (i
);
14512 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
14513 else if (i
<= 0xff)
14514 op
= DW_OP_const1u
;
14515 else if (i
<= 0xffff)
14516 op
= DW_OP_const2u
;
14517 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
14518 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
14519 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
14520 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
14521 while DW_OP_const4u is 5 bytes. */
14522 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
14523 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14524 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
14525 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
14526 while DW_OP_const4u is 5 bytes. */
14527 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
14529 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
14530 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
14533 /* As i >= 2**31, the double cast above will yield a negative number.
14534 Since wrapping is defined in DWARF expressions we can output big
14535 positive integers as small negative ones, regardless of the size
14538 Here, since the evaluator will handle 32-bit values and since i >=
14539 2**31, we know it's going to be interpreted as a negative literal:
14540 store it this way if we can do better than 5 bytes this way. */
14541 return int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
14543 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
14544 op
= DW_OP_const4u
;
14546 /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
14547 least 6 bytes: see if we can do better before falling back to it. */
14548 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14549 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
14550 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
14551 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
14552 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
14553 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
14554 >= HOST_BITS_PER_WIDE_INT
)
14555 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
14556 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
14557 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
14558 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
14559 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
14560 && size_of_uleb128 (i
) > 6)
14561 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
14562 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
14569 op
= DW_OP_const1s
;
14570 else if (i
>= -0x8000)
14571 op
= DW_OP_const2s
;
14572 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
14574 if (size_of_int_loc_descriptor (i
) < 5)
14576 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
14577 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14580 op
= DW_OP_const4s
;
14584 if (size_of_int_loc_descriptor (i
)
14585 < (unsigned long) 1 + size_of_sleb128 (i
))
14587 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
14588 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14595 return new_loc_descr (op
, i
, 0);
14598 /* Likewise, for unsigned constants. */
14600 static dw_loc_descr_ref
14601 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
14603 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
14604 const unsigned HOST_WIDE_INT max_uint
14605 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
14607 /* If possible, use the clever signed constants handling. */
14609 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
14611 /* Here, we are left with positive numbers that cannot be represented as
14612 HOST_WIDE_INT, i.e.:
14613 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
14615 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
14616 whereas may be better to output a negative integer: thanks to integer
14617 wrapping, we know that:
14618 x = x - 2 ** DWARF2_ADDR_SIZE
14619 = x - 2 * (max (HOST_WIDE_INT) + 1)
14620 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
14621 small negative integers. Let's try that in cases it will clearly improve
14622 the encoding: there is no gain turning DW_OP_const4u into
14624 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
14625 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
14626 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
14628 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
14630 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
14631 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
14632 const HOST_WIDE_INT second_shift
14633 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
14635 /* So we finally have:
14636 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
14637 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
14638 return int_loc_descriptor (second_shift
);
14641 /* Last chance: fallback to a simple constant operation. */
14642 return new_loc_descr
14643 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
14649 /* Generate and return a location description that computes the unsigned
14650 comparison of the two stack top entries (a OP b where b is the top-most
14651 entry and a is the second one). The KIND of comparison can be LT_EXPR,
14652 LE_EXPR, GT_EXPR or GE_EXPR. */
14654 static dw_loc_descr_ref
14655 uint_comparison_loc_list (enum tree_code kind
)
14657 enum dwarf_location_atom op
, flip_op
;
14658 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
14675 gcc_unreachable ();
14678 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14679 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14681 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
14682 possible to perform unsigned comparisons: we just have to distinguish
14685 1. when a and b have the same sign (as signed integers); then we should
14686 return: a OP(signed) b;
14688 2. when a is a negative signed integer while b is a positive one, then a
14689 is a greater unsigned integer than b; likewise when a and b's roles
14692 So first, compare the sign of the two operands. */
14693 ret
= new_loc_descr (DW_OP_over
, 0, 0);
14694 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14695 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
14696 /* If they have different signs (i.e. they have different sign bits), then
14697 the stack top value has now the sign bit set and thus it's smaller than
14699 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
14700 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
14701 add_loc_descr (&ret
, bra_node
);
14703 /* We are in case 1. At this point, we know both operands have the same
14704 sign, to it's safe to use the built-in signed comparison. */
14705 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
14706 add_loc_descr (&ret
, jmp_node
);
14708 /* We are in case 2. Here, we know both operands do not have the same sign,
14709 so we have to flip the signed comparison. */
14710 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
14711 tmp
= new_loc_descr (flip_op
, 0, 0);
14712 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14713 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14714 add_loc_descr (&ret
, tmp
);
14716 /* This dummy operation is necessary to make the two branches join. */
14717 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14718 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14719 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14720 add_loc_descr (&ret
, tmp
);
14725 /* Likewise, but takes the location description lists (might be destructive on
14726 them). Return NULL if either is NULL or if concatenation fails. */
14728 static dw_loc_list_ref
14729 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
14730 enum tree_code kind
)
14732 if (left
== NULL
|| right
== NULL
)
14735 add_loc_list (&left
, right
);
14739 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
14743 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
14744 without actually allocating it. */
14746 static unsigned long
14747 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
14749 return size_of_int_loc_descriptor (i
>> shift
)
14750 + size_of_int_loc_descriptor (shift
)
14754 /* Return size_of_locs (int_loc_descriptor (i)) without
14755 actually allocating it. */
14757 static unsigned long
14758 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
14767 else if (i
<= 0xff)
14769 else if (i
<= 0xffff)
14773 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
14774 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
14775 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14777 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14778 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
14779 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14781 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
14782 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
14784 return size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
14785 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
14787 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
14788 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14789 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
14790 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14792 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
14793 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
14794 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14796 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
14797 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
14799 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14808 else if (i
>= -0x8000)
14810 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
14812 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
14814 s
= size_of_int_loc_descriptor (-i
) + 1;
14822 unsigned long r
= 1 + size_of_sleb128 (i
);
14823 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
14825 s
= size_of_int_loc_descriptor (-i
) + 1;
14834 /* Return loc description representing "address" of integer value.
14835 This can appear only as toplevel expression. */
14837 static dw_loc_descr_ref
14838 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
14841 dw_loc_descr_ref loc_result
= NULL
;
14843 if (!(dwarf_version
>= 4 || !dwarf_strict
))
14846 litsize
= size_of_int_loc_descriptor (i
);
14847 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
14848 is more compact. For DW_OP_stack_value we need:
14849 litsize + 1 (DW_OP_stack_value)
14850 and for DW_OP_implicit_value:
14851 1 (DW_OP_implicit_value) + 1 (length) + size. */
14852 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
14854 loc_result
= int_loc_descriptor (i
);
14855 add_loc_descr (&loc_result
,
14856 new_loc_descr (DW_OP_stack_value
, 0, 0));
14860 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14862 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
14863 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
14867 /* Return a location descriptor that designates a base+offset location. */
14869 static dw_loc_descr_ref
14870 based_loc_descr (rtx reg
, poly_int64 offset
,
14871 enum var_init_status initialized
)
14873 unsigned int regno
;
14874 dw_loc_descr_ref result
;
14875 dw_fde_ref fde
= cfun
->fde
;
14877 /* We only use "frame base" when we're sure we're talking about the
14878 post-prologue local stack frame. We do this by *not* running
14879 register elimination until this point, and recognizing the special
14880 argument pointer and soft frame pointer rtx's. */
14881 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
14883 rtx elim
= (ira_use_lra_p
14884 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
14885 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
14889 /* Allow hard frame pointer here even if frame pointer
14890 isn't used since hard frame pointer is encoded with
14891 DW_OP_fbreg which uses the DW_AT_frame_base attribute,
14892 not hard frame pointer directly. */
14893 elim
= strip_offset_and_add (elim
, &offset
);
14894 gcc_assert (elim
== hard_frame_pointer_rtx
14895 || elim
== stack_pointer_rtx
);
14897 /* If drap register is used to align stack, use frame
14898 pointer + offset to access stack variables. If stack
14899 is aligned without drap, use stack pointer + offset to
14900 access stack variables. */
14901 if (crtl
->stack_realign_tried
14902 && reg
== frame_pointer_rtx
)
14905 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
14906 ? HARD_FRAME_POINTER_REGNUM
14908 return new_reg_loc_descr (base_reg
, offset
);
14911 gcc_assert (frame_pointer_fb_offset_valid
);
14912 offset
+= frame_pointer_fb_offset
;
14913 HOST_WIDE_INT const_offset
;
14914 if (offset
.is_constant (&const_offset
))
14915 return new_loc_descr (DW_OP_fbreg
, const_offset
, 0);
14918 dw_loc_descr_ref ret
= new_loc_descr (DW_OP_fbreg
, 0, 0);
14919 loc_descr_plus_const (&ret
, offset
);
14925 regno
= REGNO (reg
);
14926 #ifdef LEAF_REG_REMAP
14927 if (crtl
->uses_only_leaf_regs
)
14929 int leaf_reg
= LEAF_REG_REMAP (regno
);
14930 if (leaf_reg
!= -1)
14931 regno
= (unsigned) leaf_reg
;
14934 regno
= DWARF_FRAME_REGNUM (regno
);
14936 HOST_WIDE_INT const_offset
;
14937 if (!optimize
&& fde
14938 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
)
14939 && offset
.is_constant (&const_offset
))
14941 /* Use cfa+offset to represent the location of arguments passed
14942 on the stack when drap is used to align stack.
14943 Only do this when not optimizing, for optimized code var-tracking
14944 is supposed to track where the arguments live and the register
14945 used as vdrap or drap in some spot might be used for something
14946 else in other part of the routine. */
14947 return new_loc_descr (DW_OP_fbreg
, const_offset
, 0);
14950 result
= new_reg_loc_descr (regno
, offset
);
14952 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14953 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14958 /* Return true if this RTL expression describes a base+offset calculation. */
14961 is_based_loc (const_rtx rtl
)
14963 return (GET_CODE (rtl
) == PLUS
14964 && ((REG_P (XEXP (rtl
, 0))
14965 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
14966 && CONST_INT_P (XEXP (rtl
, 1)))));
14969 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
14972 static dw_loc_descr_ref
14973 tls_mem_loc_descriptor (rtx mem
)
14976 dw_loc_descr_ref loc_result
;
14978 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
14981 base
= get_base_address (MEM_EXPR (mem
));
14984 || !DECL_THREAD_LOCAL_P (base
))
14987 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
14988 if (loc_result
== NULL
)
14991 if (maybe_ne (MEM_OFFSET (mem
), 0))
14992 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
14997 /* Output debug info about reason why we failed to expand expression as dwarf
15001 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
15003 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
15005 fprintf (dump_file
, "Failed to expand as dwarf: ");
15007 print_generic_expr (dump_file
, expr
, dump_flags
);
15010 fprintf (dump_file
, "\n");
15011 print_rtl (dump_file
, rtl
);
15013 fprintf (dump_file
, "\nReason: %s\n", reason
);
15017 /* Helper function for const_ok_for_output. */
15020 const_ok_for_output_1 (rtx rtl
)
15022 if (targetm
.const_not_ok_for_debug_p (rtl
))
15024 if (GET_CODE (rtl
) != UNSPEC
)
15026 expansion_failed (NULL_TREE
, rtl
,
15027 "Expression rejected for debug by the backend.\n");
15031 /* If delegitimize_address couldn't do anything with the UNSPEC, and
15032 the target hook doesn't explicitly allow it in debug info, assume
15033 we can't express it in the debug info. */
15034 /* Don't complain about TLS UNSPECs, those are just too hard to
15035 delegitimize. Note this could be a non-decl SYMBOL_REF such as
15036 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
15037 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
15039 && (XVECLEN (rtl
, 0) == 0
15040 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
15041 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
15042 inform (current_function_decl
15043 ? DECL_SOURCE_LOCATION (current_function_decl
)
15044 : UNKNOWN_LOCATION
,
15045 #if NUM_UNSPEC_VALUES > 0
15046 "non-delegitimized UNSPEC %s (%d) found in variable location",
15047 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
15048 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
15050 "non-delegitimized UNSPEC %d found in variable location",
15053 expansion_failed (NULL_TREE
, rtl
,
15054 "UNSPEC hasn't been delegitimized.\n");
15058 if (CONST_POLY_INT_P (rtl
))
15061 /* FIXME: Refer to PR60655. It is possible for simplification
15062 of rtl expressions in var tracking to produce such expressions.
15063 We should really identify / validate expressions
15064 enclosed in CONST that can be handled by assemblers on various
15065 targets and only handle legitimate cases here. */
15066 switch (GET_CODE (rtl
))
15075 /* Make sure SYMBOL_REFs/UNSPECs are at most in one of the
15077 subrtx_var_iterator::array_type array
;
15078 bool first
= false;
15079 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
15080 if (SYMBOL_REF_P (*iter
)
15082 || GET_CODE (*iter
) == UNSPEC
)
15089 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 1), ALL
)
15090 if (SYMBOL_REF_P (*iter
)
15092 || GET_CODE (*iter
) == UNSPEC
)
15098 /* Disallow negation of SYMBOL_REFs or UNSPECs when they
15099 appear in the second operand of MINUS. */
15100 subrtx_var_iterator::array_type array
;
15101 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 1), ALL
)
15102 if (SYMBOL_REF_P (*iter
)
15104 || GET_CODE (*iter
) == UNSPEC
)
15112 if (CONSTANT_POOL_ADDRESS_P (rtl
))
15115 get_pool_constant_mark (rtl
, &marked
);
15116 /* If all references to this pool constant were optimized away,
15117 it was not output and thus we can't represent it. */
15120 expansion_failed (NULL_TREE
, rtl
,
15121 "Constant was removed from constant pool.\n");
15126 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
15129 /* Avoid references to external symbols in debug info, on several targets
15130 the linker might even refuse to link when linking a shared library,
15131 and in many other cases the relocations for .debug_info/.debug_loc are
15132 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
15133 to be defined within the same shared library or executable are fine. */
15134 if (SYMBOL_REF_EXTERNAL_P (rtl
))
15136 tree decl
= SYMBOL_REF_DECL (rtl
);
15138 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
15140 expansion_failed (NULL_TREE
, rtl
,
15141 "Symbol not defined in current TU.\n");
15149 /* Return true if constant RTL can be emitted in DW_OP_addr or
15150 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
15151 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
15154 const_ok_for_output (rtx rtl
)
15156 if (GET_CODE (rtl
) == SYMBOL_REF
)
15157 return const_ok_for_output_1 (rtl
);
15159 if (GET_CODE (rtl
) == CONST
)
15161 subrtx_var_iterator::array_type array
;
15162 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
15163 if (!const_ok_for_output_1 (*iter
))
15171 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
15172 if possible, NULL otherwise. */
15175 base_type_for_mode (machine_mode mode
, bool unsignedp
)
15177 dw_die_ref type_die
;
15178 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
15182 switch (TREE_CODE (type
))
15190 type_die
= lookup_type_die (type
);
15192 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
15194 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
15199 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
15200 type matching MODE, or, if MODE is narrower than or as wide as
15201 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
15204 static dw_loc_descr_ref
15205 convert_descriptor_to_mode (scalar_int_mode mode
, dw_loc_descr_ref op
)
15207 machine_mode outer_mode
= mode
;
15208 dw_die_ref type_die
;
15209 dw_loc_descr_ref cvt
;
15211 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
15213 add_loc_descr (&op
, new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
15216 type_die
= base_type_for_mode (outer_mode
, 1);
15217 if (type_die
== NULL
)
15219 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15220 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15221 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15222 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15223 add_loc_descr (&op
, cvt
);
15227 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
15229 static dw_loc_descr_ref
15230 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
15231 dw_loc_descr_ref op1
)
15233 dw_loc_descr_ref ret
= op0
;
15234 add_loc_descr (&ret
, op1
);
15235 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
15236 if (STORE_FLAG_VALUE
!= 1)
15238 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
15239 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
15244 /* Subroutine of scompare_loc_descriptor for the case in which we're
15245 comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
15246 and in which OP_MODE is bigger than DWARF2_ADDR_SIZE. */
15248 static dw_loc_descr_ref
15249 scompare_loc_descriptor_wide (enum dwarf_location_atom op
,
15250 scalar_int_mode op_mode
,
15251 dw_loc_descr_ref op0
, dw_loc_descr_ref op1
)
15253 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
15254 dw_loc_descr_ref cvt
;
15256 if (type_die
== NULL
)
15258 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15259 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15260 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15261 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15262 add_loc_descr (&op0
, cvt
);
15263 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15264 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15265 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15266 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15267 add_loc_descr (&op1
, cvt
);
15268 return compare_loc_descriptor (op
, op0
, op1
);
15271 /* Subroutine of scompare_loc_descriptor for the case in which we're
15272 comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
15273 and in which OP_MODE is smaller than DWARF2_ADDR_SIZE. */
15275 static dw_loc_descr_ref
15276 scompare_loc_descriptor_narrow (enum dwarf_location_atom op
, rtx rtl
,
15277 scalar_int_mode op_mode
,
15278 dw_loc_descr_ref op0
, dw_loc_descr_ref op1
)
15280 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
15281 /* For eq/ne, if the operands are known to be zero-extended,
15282 there is no need to do the fancy shifting up. */
15283 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
15285 dw_loc_descr_ref last0
, last1
;
15286 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
15288 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
15290 /* deref_size zero extends, and for constants we can check
15291 whether they are zero extended or not. */
15292 if (((last0
->dw_loc_opc
== DW_OP_deref_size
15293 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
15294 || (CONST_INT_P (XEXP (rtl
, 0))
15295 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
15296 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
15297 && ((last1
->dw_loc_opc
== DW_OP_deref_size
15298 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
15299 || (CONST_INT_P (XEXP (rtl
, 1))
15300 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
15301 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
15302 return compare_loc_descriptor (op
, op0
, op1
);
15304 /* EQ/NE comparison against constant in narrower type than
15305 DWARF2_ADDR_SIZE can be performed either as
15306 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
15309 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
15310 DW_OP_{eq,ne}. Pick whatever is shorter. */
15311 if (CONST_INT_P (XEXP (rtl
, 1))
15312 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
15313 && (size_of_int_loc_descriptor (shift
) + 1
15314 + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
)
15315 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
15316 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
15317 & GET_MODE_MASK (op_mode
))))
15319 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
15320 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
15321 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
15322 & GET_MODE_MASK (op_mode
));
15323 return compare_loc_descriptor (op
, op0
, op1
);
15326 add_loc_descr (&op0
, int_loc_descriptor (shift
));
15327 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
15328 if (CONST_INT_P (XEXP (rtl
, 1)))
15329 op1
= int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
);
15332 add_loc_descr (&op1
, int_loc_descriptor (shift
));
15333 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
15335 return compare_loc_descriptor (op
, op0
, op1
);
15338 /* Return location descriptor for signed comparison OP RTL. */
15340 static dw_loc_descr_ref
15341 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
15342 machine_mode mem_mode
)
15344 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
15345 dw_loc_descr_ref op0
, op1
;
15347 if (op_mode
== VOIDmode
)
15348 op_mode
= GET_MODE (XEXP (rtl
, 1));
15349 if (op_mode
== VOIDmode
)
15352 scalar_int_mode int_op_mode
;
15354 && dwarf_version
< 5
15355 && (!is_a
<scalar_int_mode
> (op_mode
, &int_op_mode
)
15356 || GET_MODE_SIZE (int_op_mode
) > DWARF2_ADDR_SIZE
))
15359 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
15360 VAR_INIT_STATUS_INITIALIZED
);
15361 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
15362 VAR_INIT_STATUS_INITIALIZED
);
15364 if (op0
== NULL
|| op1
== NULL
)
15367 if (is_a
<scalar_int_mode
> (op_mode
, &int_op_mode
))
15369 if (GET_MODE_SIZE (int_op_mode
) < DWARF2_ADDR_SIZE
)
15370 return scompare_loc_descriptor_narrow (op
, rtl
, int_op_mode
, op0
, op1
);
15372 if (GET_MODE_SIZE (int_op_mode
) > DWARF2_ADDR_SIZE
)
15373 return scompare_loc_descriptor_wide (op
, int_op_mode
, op0
, op1
);
15375 return compare_loc_descriptor (op
, op0
, op1
);
15378 /* Return location descriptor for unsigned comparison OP RTL. */
15380 static dw_loc_descr_ref
15381 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
15382 machine_mode mem_mode
)
15384 dw_loc_descr_ref op0
, op1
;
15386 machine_mode test_op_mode
= GET_MODE (XEXP (rtl
, 0));
15387 if (test_op_mode
== VOIDmode
)
15388 test_op_mode
= GET_MODE (XEXP (rtl
, 1));
15390 scalar_int_mode op_mode
;
15391 if (!is_a
<scalar_int_mode
> (test_op_mode
, &op_mode
))
15395 && dwarf_version
< 5
15396 && GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
15399 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
15400 VAR_INIT_STATUS_INITIALIZED
);
15401 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
15402 VAR_INIT_STATUS_INITIALIZED
);
15404 if (op0
== NULL
|| op1
== NULL
)
15407 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
15409 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
15410 dw_loc_descr_ref last0
, last1
;
15411 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
15413 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
15415 if (CONST_INT_P (XEXP (rtl
, 0)))
15416 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
15417 /* deref_size zero extends, so no need to mask it again. */
15418 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
15419 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
15421 add_loc_descr (&op0
, int_loc_descriptor (mask
));
15422 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
15424 if (CONST_INT_P (XEXP (rtl
, 1)))
15425 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
15426 /* deref_size zero extends, so no need to mask it again. */
15427 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
15428 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
15430 add_loc_descr (&op1
, int_loc_descriptor (mask
));
15431 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
15434 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
15436 HOST_WIDE_INT bias
= 1;
15437 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
15438 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
15439 if (CONST_INT_P (XEXP (rtl
, 1)))
15440 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
15441 + INTVAL (XEXP (rtl
, 1)));
15443 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
15446 return compare_loc_descriptor (op
, op0
, op1
);
15449 /* Return location descriptor for {U,S}{MIN,MAX}. */
15451 static dw_loc_descr_ref
15452 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
15453 machine_mode mem_mode
)
15455 enum dwarf_location_atom op
;
15456 dw_loc_descr_ref op0
, op1
, ret
;
15457 dw_loc_descr_ref bra_node
, drop_node
;
15459 scalar_int_mode int_mode
;
15461 && dwarf_version
< 5
15462 && (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15463 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
))
15466 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15467 VAR_INIT_STATUS_INITIALIZED
);
15468 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15469 VAR_INIT_STATUS_INITIALIZED
);
15471 if (op0
== NULL
|| op1
== NULL
)
15474 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
15475 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
15476 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
15477 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
15479 /* Checked by the caller. */
15480 int_mode
= as_a
<scalar_int_mode
> (mode
);
15481 if (GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
15483 HOST_WIDE_INT mask
= GET_MODE_MASK (int_mode
);
15484 add_loc_descr (&op0
, int_loc_descriptor (mask
));
15485 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
15486 add_loc_descr (&op1
, int_loc_descriptor (mask
));
15487 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
15489 else if (GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
)
15491 HOST_WIDE_INT bias
= 1;
15492 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
15493 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
15494 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
15497 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15498 && GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
15500 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (int_mode
)) * BITS_PER_UNIT
;
15501 add_loc_descr (&op0
, int_loc_descriptor (shift
));
15502 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
15503 add_loc_descr (&op1
, int_loc_descriptor (shift
));
15504 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
15506 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15507 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15509 dw_die_ref type_die
= base_type_for_mode (int_mode
, 0);
15510 dw_loc_descr_ref cvt
;
15511 if (type_die
== NULL
)
15513 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15514 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15515 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15516 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15517 add_loc_descr (&op0
, cvt
);
15518 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15519 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15520 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15521 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15522 add_loc_descr (&op1
, cvt
);
15525 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
15530 add_loc_descr (&ret
, op1
);
15531 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
15532 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15533 add_loc_descr (&ret
, bra_node
);
15534 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15535 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
15536 add_loc_descr (&ret
, drop_node
);
15537 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15538 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
15539 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
15540 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15541 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15542 ret
= convert_descriptor_to_mode (int_mode
, ret
);
15546 /* Helper function for mem_loc_descriptor. Perform OP binary op,
15547 but after converting arguments to type_die, afterwards
15548 convert back to unsigned. */
15550 static dw_loc_descr_ref
15551 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
15552 scalar_int_mode mode
, machine_mode mem_mode
)
15554 dw_loc_descr_ref cvt
, op0
, op1
;
15556 if (type_die
== NULL
)
15558 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15559 VAR_INIT_STATUS_INITIALIZED
);
15560 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15561 VAR_INIT_STATUS_INITIALIZED
);
15562 if (op0
== NULL
|| op1
== NULL
)
15564 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15565 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15566 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15567 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15568 add_loc_descr (&op0
, cvt
);
15569 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15570 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15571 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15572 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15573 add_loc_descr (&op1
, cvt
);
15574 add_loc_descr (&op0
, op1
);
15575 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
15576 return convert_descriptor_to_mode (mode
, op0
);
15579 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
15580 const0 is DW_OP_lit0 or corresponding typed constant,
15581 const1 is DW_OP_lit1 or corresponding typed constant
15582 and constMSB is constant with just the MSB bit set
15584 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
15585 L1: const0 DW_OP_swap
15586 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
15587 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15592 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
15593 L1: const0 DW_OP_swap
15594 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
15595 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15600 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
15601 L1: const1 DW_OP_swap
15602 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
15603 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15607 static dw_loc_descr_ref
15608 clz_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15609 machine_mode mem_mode
)
15611 dw_loc_descr_ref op0
, ret
, tmp
;
15612 HOST_WIDE_INT valv
;
15613 dw_loc_descr_ref l1jump
, l1label
;
15614 dw_loc_descr_ref l2jump
, l2label
;
15615 dw_loc_descr_ref l3jump
, l3label
;
15616 dw_loc_descr_ref l4jump
, l4label
;
15619 if (GET_MODE (XEXP (rtl
, 0)) != mode
)
15622 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15623 VAR_INIT_STATUS_INITIALIZED
);
15627 if (GET_CODE (rtl
) == CLZ
)
15629 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
15630 valv
= GET_MODE_BITSIZE (mode
);
15632 else if (GET_CODE (rtl
) == FFS
)
15634 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
15635 valv
= GET_MODE_BITSIZE (mode
);
15636 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
15637 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15638 add_loc_descr (&ret
, l1jump
);
15639 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
15640 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
15641 VAR_INIT_STATUS_INITIALIZED
);
15644 add_loc_descr (&ret
, tmp
);
15645 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15646 add_loc_descr (&ret
, l4jump
);
15647 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
15648 ? const1_rtx
: const0_rtx
,
15650 VAR_INIT_STATUS_INITIALIZED
);
15651 if (l1label
== NULL
)
15653 add_loc_descr (&ret
, l1label
);
15654 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15655 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
15656 add_loc_descr (&ret
, l2label
);
15657 if (GET_CODE (rtl
) != CLZ
)
15659 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
15660 msb
= GEN_INT (HOST_WIDE_INT_1U
15661 << (GET_MODE_BITSIZE (mode
) - 1));
15663 msb
= immed_wide_int_const
15664 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
15665 GET_MODE_PRECISION (mode
)), mode
);
15666 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
15667 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
15668 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
15669 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
15671 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
15672 VAR_INIT_STATUS_INITIALIZED
);
15675 add_loc_descr (&ret
, tmp
);
15676 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
15677 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15678 add_loc_descr (&ret
, l3jump
);
15679 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
15680 VAR_INIT_STATUS_INITIALIZED
);
15683 add_loc_descr (&ret
, tmp
);
15684 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
15685 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
15686 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15687 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
15688 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15689 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15690 add_loc_descr (&ret
, l2jump
);
15691 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
15692 add_loc_descr (&ret
, l3label
);
15693 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
15694 add_loc_descr (&ret
, l4label
);
15695 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15696 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
15697 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15698 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
15699 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15700 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
15701 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15702 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
15706 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
15707 const1 is DW_OP_lit1 or corresponding typed constant):
15709 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
15710 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
15714 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
15715 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
15718 static dw_loc_descr_ref
15719 popcount_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15720 machine_mode mem_mode
)
15722 dw_loc_descr_ref op0
, ret
, tmp
;
15723 dw_loc_descr_ref l1jump
, l1label
;
15724 dw_loc_descr_ref l2jump
, l2label
;
15726 if (GET_MODE (XEXP (rtl
, 0)) != mode
)
15729 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15730 VAR_INIT_STATUS_INITIALIZED
);
15734 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
15735 VAR_INIT_STATUS_INITIALIZED
);
15738 add_loc_descr (&ret
, tmp
);
15739 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15740 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
15741 add_loc_descr (&ret
, l1label
);
15742 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15743 add_loc_descr (&ret
, l2jump
);
15744 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
15745 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
15746 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
15747 VAR_INIT_STATUS_INITIALIZED
);
15750 add_loc_descr (&ret
, tmp
);
15751 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
15752 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
15753 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
15754 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15755 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
15756 VAR_INIT_STATUS_INITIALIZED
);
15757 add_loc_descr (&ret
, tmp
);
15758 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
15759 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15760 add_loc_descr (&ret
, l1jump
);
15761 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
15762 add_loc_descr (&ret
, l2label
);
15763 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15764 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
15765 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15766 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
15770 /* BSWAP (constS is initial shift count, either 56 or 24):
15772 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
15773 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
15774 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
15775 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
15776 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
15778 static dw_loc_descr_ref
15779 bswap_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15780 machine_mode mem_mode
)
15782 dw_loc_descr_ref op0
, ret
, tmp
;
15783 dw_loc_descr_ref l1jump
, l1label
;
15784 dw_loc_descr_ref l2jump
, l2label
;
15786 if (BITS_PER_UNIT
!= 8
15787 || (GET_MODE_BITSIZE (mode
) != 32
15788 && GET_MODE_BITSIZE (mode
) != 64))
15791 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15792 VAR_INIT_STATUS_INITIALIZED
);
15797 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
15799 VAR_INIT_STATUS_INITIALIZED
);
15802 add_loc_descr (&ret
, tmp
);
15803 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
15804 VAR_INIT_STATUS_INITIALIZED
);
15807 add_loc_descr (&ret
, tmp
);
15808 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
15809 add_loc_descr (&ret
, l1label
);
15810 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
15812 VAR_INIT_STATUS_INITIALIZED
);
15813 add_loc_descr (&ret
, tmp
);
15814 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
15815 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
15816 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
15817 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
15818 VAR_INIT_STATUS_INITIALIZED
);
15821 add_loc_descr (&ret
, tmp
);
15822 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
15823 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
15824 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
15825 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
15826 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15827 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
15828 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
15829 VAR_INIT_STATUS_INITIALIZED
);
15830 add_loc_descr (&ret
, tmp
);
15831 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
15832 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15833 add_loc_descr (&ret
, l2jump
);
15834 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
15835 VAR_INIT_STATUS_INITIALIZED
);
15836 add_loc_descr (&ret
, tmp
);
15837 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
15838 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15839 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15840 add_loc_descr (&ret
, l1jump
);
15841 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
15842 add_loc_descr (&ret
, l2label
);
15843 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15844 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
15845 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15846 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
15847 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15848 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
15852 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
15853 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
15854 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
15855 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
15857 ROTATERT is similar:
15858 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
15859 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
15860 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
15862 static dw_loc_descr_ref
15863 rotate_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15864 machine_mode mem_mode
)
15866 rtx rtlop1
= XEXP (rtl
, 1);
15867 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
15870 if (is_narrower_int_mode (GET_MODE (rtlop1
), mode
))
15871 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
15872 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15873 VAR_INIT_STATUS_INITIALIZED
);
15874 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
15875 VAR_INIT_STATUS_INITIALIZED
);
15876 if (op0
== NULL
|| op1
== NULL
)
15878 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
15879 for (i
= 0; i
< 2; i
++)
15881 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
15882 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
15884 VAR_INIT_STATUS_INITIALIZED
);
15885 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
15886 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
15888 : HOST_BITS_PER_WIDE_INT
== 64
15889 ? DW_OP_const8u
: DW_OP_constu
,
15890 GET_MODE_MASK (mode
), 0);
15893 if (mask
[i
] == NULL
)
15895 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
15898 add_loc_descr (&ret
, op1
);
15899 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
15900 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
15901 if (GET_CODE (rtl
) == ROTATERT
)
15903 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
15904 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
15905 GET_MODE_BITSIZE (mode
), 0));
15907 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
15908 if (mask
[0] != NULL
)
15909 add_loc_descr (&ret
, mask
[0]);
15910 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
15911 if (mask
[1] != NULL
)
15913 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15914 add_loc_descr (&ret
, mask
[1]);
15915 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15917 if (GET_CODE (rtl
) == ROTATE
)
15919 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
15920 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
15921 GET_MODE_BITSIZE (mode
), 0));
15923 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
15924 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
15928 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
15929 for DEBUG_PARAMETER_REF RTL. */
15931 static dw_loc_descr_ref
15932 parameter_ref_descriptor (rtx rtl
)
15934 dw_loc_descr_ref ret
;
15939 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
15940 /* With LTO during LTRANS we get the late DIE that refers to the early
15941 DIE, thus we add another indirection here. This seems to confuse
15942 gdb enough to make gcc.dg/guality/pr68860-1.c FAIL with LTO. */
15943 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
15944 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
15947 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15948 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
15949 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15953 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
15954 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
15959 /* The following routine converts the RTL for a variable or parameter
15960 (resident in memory) into an equivalent Dwarf representation of a
15961 mechanism for getting the address of that same variable onto the top of a
15962 hypothetical "address evaluation" stack.
15964 When creating memory location descriptors, we are effectively transforming
15965 the RTL for a memory-resident object into its Dwarf postfix expression
15966 equivalent. This routine recursively descends an RTL tree, turning
15967 it into Dwarf postfix code as it goes.
15969 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
15971 MEM_MODE is the mode of the memory reference, needed to handle some
15972 autoincrement addressing modes.
15974 Return 0 if we can't represent the location. */
15977 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
15978 machine_mode mem_mode
,
15979 enum var_init_status initialized
)
15981 dw_loc_descr_ref mem_loc_result
= NULL
;
15982 enum dwarf_location_atom op
;
15983 dw_loc_descr_ref op0
, op1
;
15984 rtx inner
= NULL_RTX
;
15986 if (mode
== VOIDmode
)
15987 mode
= GET_MODE (rtl
);
15989 /* Note that for a dynamically sized array, the location we will generate a
15990 description of here will be the lowest numbered location which is
15991 actually within the array. That's *not* necessarily the same as the
15992 zeroth element of the array. */
15994 rtl
= targetm
.delegitimize_address (rtl
);
15996 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
15999 scalar_int_mode int_mode
= BImode
, inner_mode
, op1_mode
;
16000 switch (GET_CODE (rtl
))
16005 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
16008 /* The case of a subreg may arise when we have a local (register)
16009 variable or a formal (register) parameter which doesn't quite fill
16010 up an entire register. For now, just assume that it is
16011 legitimate to make the Dwarf info refer to the whole register which
16012 contains the given subreg. */
16013 if (!subreg_lowpart_p (rtl
))
16015 inner
= SUBREG_REG (rtl
);
16018 if (inner
== NULL_RTX
)
16019 inner
= XEXP (rtl
, 0);
16020 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
16021 && is_a
<scalar_int_mode
> (GET_MODE (inner
), &inner_mode
)
16022 && (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16023 #ifdef POINTERS_EXTEND_UNSIGNED
16024 || (int_mode
== Pmode
&& mem_mode
!= VOIDmode
)
16027 && GET_MODE_SIZE (inner_mode
) <= DWARF2_ADDR_SIZE
)
16029 mem_loc_result
= mem_loc_descriptor (inner
,
16031 mem_mode
, initialized
);
16034 if (dwarf_strict
&& dwarf_version
< 5)
16036 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
16037 && is_a
<scalar_int_mode
> (GET_MODE (inner
), &inner_mode
)
16038 ? GET_MODE_SIZE (int_mode
) <= GET_MODE_SIZE (inner_mode
)
16039 : known_eq (GET_MODE_SIZE (mode
), GET_MODE_SIZE (GET_MODE (inner
))))
16041 dw_die_ref type_die
;
16042 dw_loc_descr_ref cvt
;
16044 mem_loc_result
= mem_loc_descriptor (inner
,
16046 mem_mode
, initialized
);
16047 if (mem_loc_result
== NULL
)
16049 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16050 if (type_die
== NULL
)
16052 mem_loc_result
= NULL
;
16055 if (maybe_ne (GET_MODE_SIZE (mode
), GET_MODE_SIZE (GET_MODE (inner
))))
16056 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16058 cvt
= new_loc_descr (dwarf_OP (DW_OP_reinterpret
), 0, 0);
16059 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16060 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16061 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16062 add_loc_descr (&mem_loc_result
, cvt
);
16063 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
16064 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
)
16066 /* Convert it to untyped afterwards. */
16067 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16068 add_loc_descr (&mem_loc_result
, cvt
);
16074 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16075 || (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
16076 && rtl
!= arg_pointer_rtx
16077 && rtl
!= frame_pointer_rtx
16078 #ifdef POINTERS_EXTEND_UNSIGNED
16079 && (int_mode
!= Pmode
|| mem_mode
== VOIDmode
)
16083 dw_die_ref type_die
;
16084 unsigned int debugger_regnum
;
16086 if (dwarf_strict
&& dwarf_version
< 5)
16088 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
16090 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16091 if (type_die
== NULL
)
16094 debugger_regnum
= debugger_reg_number (rtl
);
16095 if (debugger_regnum
== IGNORED_DWARF_REGNUM
)
16097 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_regval_type
),
16098 debugger_regnum
, 0);
16099 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
16100 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
16101 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
16104 /* Whenever a register number forms a part of the description of the
16105 method for calculating the (dynamic) address of a memory resident
16106 object, DWARF rules require the register number be referred to as
16107 a "base register". This distinction is not based in any way upon
16108 what category of register the hardware believes the given register
16109 belongs to. This is strictly DWARF terminology we're dealing with
16110 here. Note that in cases where the location of a memory-resident
16111 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
16112 OP_CONST (0)) the actual DWARF location descriptor that we generate
16113 may just be OP_BASEREG (basereg). This may look deceptively like
16114 the object in question was allocated to a register (rather than in
16115 memory) so DWARF consumers need to be aware of the subtle
16116 distinction between OP_REG and OP_BASEREG. */
16117 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
16118 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
16119 else if (stack_realign_drap
16121 && crtl
->args
.internal_arg_pointer
== rtl
16122 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
16124 /* If RTL is internal_arg_pointer, which has been optimized
16125 out, use DRAP instead. */
16126 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
16127 VAR_INIT_STATUS_INITIALIZED
);
16133 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16134 || !is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &inner_mode
))
16136 op0
= mem_loc_descriptor (XEXP (rtl
, 0), inner_mode
,
16137 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
16140 else if (GET_CODE (rtl
) == ZERO_EXTEND
16141 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16142 && GET_MODE_BITSIZE (inner_mode
) < HOST_BITS_PER_WIDE_INT
16143 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
16144 to expand zero extend as two shifts instead of
16146 && GET_MODE_SIZE (inner_mode
) <= 4)
16148 mem_loc_result
= op0
;
16149 add_loc_descr (&mem_loc_result
,
16150 int_loc_descriptor (GET_MODE_MASK (inner_mode
)));
16151 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
16153 else if (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
)
16155 int shift
= DWARF2_ADDR_SIZE
- GET_MODE_SIZE (inner_mode
);
16156 shift
*= BITS_PER_UNIT
;
16157 if (GET_CODE (rtl
) == SIGN_EXTEND
)
16161 mem_loc_result
= op0
;
16162 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
16163 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
16164 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
16165 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16167 else if (!dwarf_strict
|| dwarf_version
>= 5)
16169 dw_die_ref type_die1
, type_die2
;
16170 dw_loc_descr_ref cvt
;
16172 type_die1
= base_type_for_mode (inner_mode
,
16173 GET_CODE (rtl
) == ZERO_EXTEND
);
16174 if (type_die1
== NULL
)
16176 type_die2
= base_type_for_mode (int_mode
, 1);
16177 if (type_die2
== NULL
)
16179 mem_loc_result
= op0
;
16180 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16181 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16182 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
16183 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16184 add_loc_descr (&mem_loc_result
, cvt
);
16185 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16186 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16187 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
16188 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16189 add_loc_descr (&mem_loc_result
, cvt
);
16195 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
16196 if (new_rtl
!= rtl
)
16198 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
16200 if (mem_loc_result
!= NULL
)
16201 return mem_loc_result
;
16204 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
16205 get_address_mode (rtl
), mode
,
16206 VAR_INIT_STATUS_INITIALIZED
);
16207 if (mem_loc_result
== NULL
)
16208 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
16209 if (mem_loc_result
!= NULL
)
16211 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16212 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
16214 dw_die_ref type_die
;
16215 dw_loc_descr_ref deref
;
16216 HOST_WIDE_INT size
;
16218 if (dwarf_strict
&& dwarf_version
< 5)
16220 if (!GET_MODE_SIZE (mode
).is_constant (&size
))
16223 = base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16224 if (type_die
== NULL
)
16226 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
), size
, 0);
16227 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
16228 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
16229 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
16230 add_loc_descr (&mem_loc_result
, deref
);
16232 else if (GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
)
16233 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
16235 add_loc_descr (&mem_loc_result
,
16236 new_loc_descr (DW_OP_deref_size
,
16237 GET_MODE_SIZE (int_mode
), 0));
16242 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
16245 /* Some ports can transform a symbol ref into a label ref, because
16246 the symbol ref is too far away and has to be dumped into a constant
16251 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16252 || (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
16253 #ifdef POINTERS_EXTEND_UNSIGNED
16254 && (int_mode
!= Pmode
|| mem_mode
== VOIDmode
)
16259 if (GET_CODE (rtl
) == UNSPEC
)
16261 /* If delegitimize_address couldn't do anything with the UNSPEC, we
16262 can't express it in the debug info. This can happen e.g. with some
16263 TLS UNSPECs. Allow UNSPECs formerly from CONST that the backend
16265 bool not_ok
= false;
16266 subrtx_var_iterator::array_type array
;
16267 FOR_EACH_SUBRTX_VAR (iter
, array
, rtl
, ALL
)
16268 if (*iter
!= rtl
&& !CONSTANT_P (*iter
))
16277 FOR_EACH_SUBRTX_VAR (iter
, array
, rtl
, ALL
)
16278 if (!const_ok_for_output_1 (*iter
))
16287 rtl
= gen_rtx_CONST (GET_MODE (rtl
), rtl
);
16291 if (GET_CODE (rtl
) == SYMBOL_REF
16292 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
16294 dw_loc_descr_ref temp
;
16296 /* If this is not defined, we have no way to emit the data. */
16297 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
16300 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
16302 /* We check for DWARF 5 here because gdb did not implement
16303 DW_OP_form_tls_address until after 7.12. */
16304 mem_loc_result
= new_loc_descr ((dwarf_version
>= 5
16305 ? DW_OP_form_tls_address
16306 : DW_OP_GNU_push_tls_address
),
16308 add_loc_descr (&mem_loc_result
, temp
);
16313 if (!const_ok_for_output (rtl
))
16315 if (GET_CODE (rtl
) == CONST
)
16316 switch (GET_CODE (XEXP (rtl
, 0)))
16320 goto try_const_unop
;
16323 goto try_const_unop
;
16326 arg
= XEXP (XEXP (rtl
, 0), 0);
16327 if (!CONSTANT_P (arg
))
16328 arg
= gen_rtx_CONST (int_mode
, arg
);
16329 op0
= mem_loc_descriptor (arg
, int_mode
, mem_mode
,
16333 mem_loc_result
= op0
;
16334 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16338 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), int_mode
,
16339 mem_mode
, initialized
);
16346 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
16347 vec_safe_push (used_rtx_array
, rtl
);
16353 case DEBUG_IMPLICIT_PTR
:
16354 expansion_failed (NULL_TREE
, rtl
,
16355 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
16359 if (dwarf_strict
&& dwarf_version
< 5)
16361 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
16363 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16364 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
16365 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
16366 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
16369 unsigned int debugger_regnum
= debugger_reg_number (ENTRY_VALUE_EXP (rtl
));
16370 if (debugger_regnum
== IGNORED_DWARF_REGNUM
)
16372 op0
= one_reg_loc_descriptor (debugger_regnum
,
16373 VAR_INIT_STATUS_INITIALIZED
);
16376 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
16377 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
16379 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
16380 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
16381 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
16385 gcc_unreachable ();
16388 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_entry_value
), 0, 0);
16389 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16390 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
16393 case DEBUG_PARAMETER_REF
:
16394 mem_loc_result
= parameter_ref_descriptor (rtl
);
16398 /* Extract the PLUS expression nested inside and fall into
16399 PLUS code below. */
16400 rtl
= XEXP (rtl
, 1);
16405 /* Turn these into a PLUS expression and fall into the PLUS code
16407 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
16408 gen_int_mode (GET_CODE (rtl
) == PRE_INC
16409 ? GET_MODE_UNIT_SIZE (mem_mode
)
16410 : -GET_MODE_UNIT_SIZE (mem_mode
),
16417 if (is_based_loc (rtl
)
16418 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
16419 && (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16420 || XEXP (rtl
, 0) == arg_pointer_rtx
16421 || XEXP (rtl
, 0) == frame_pointer_rtx
))
16422 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
16423 INTVAL (XEXP (rtl
, 1)),
16424 VAR_INIT_STATUS_INITIALIZED
);
16427 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
16428 VAR_INIT_STATUS_INITIALIZED
);
16429 if (mem_loc_result
== 0)
16432 if (CONST_INT_P (XEXP (rtl
, 1))
16433 && (GET_MODE_SIZE (as_a
<scalar_int_mode
> (mode
))
16434 <= DWARF2_ADDR_SIZE
))
16435 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
16438 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
16439 VAR_INIT_STATUS_INITIALIZED
);
16442 add_loc_descr (&mem_loc_result
, op1
);
16443 add_loc_descr (&mem_loc_result
,
16444 new_loc_descr (DW_OP_plus
, 0, 0));
16449 /* If a pseudo-reg is optimized away, it is possible for it to
16450 be replaced with a MEM containing a multiply or shift. */
16460 if ((!dwarf_strict
|| dwarf_version
>= 5)
16461 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
16462 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
16464 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
16465 base_type_for_mode (mode
, 0),
16466 int_mode
, mem_mode
);
16489 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
))
16491 op0
= mem_loc_descriptor (XEXP (rtl
, 0), int_mode
, mem_mode
,
16492 VAR_INIT_STATUS_INITIALIZED
);
16494 rtx rtlop1
= XEXP (rtl
, 1);
16495 if (is_a
<scalar_int_mode
> (GET_MODE (rtlop1
), &op1_mode
)
16496 && GET_MODE_BITSIZE (op1_mode
) < GET_MODE_BITSIZE (int_mode
))
16497 rtlop1
= gen_rtx_ZERO_EXTEND (int_mode
, rtlop1
);
16498 op1
= mem_loc_descriptor (rtlop1
, int_mode
, mem_mode
,
16499 VAR_INIT_STATUS_INITIALIZED
);
16502 if (op0
== 0 || op1
== 0)
16505 mem_loc_result
= op0
;
16506 add_loc_descr (&mem_loc_result
, op1
);
16507 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16523 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
16524 VAR_INIT_STATUS_INITIALIZED
);
16525 if (XEXP (rtl
, 0) == XEXP (rtl
, 1))
16529 mem_loc_result
= op0
;
16530 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_dup
, 0, 0));
16531 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16534 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
16535 VAR_INIT_STATUS_INITIALIZED
);
16537 if (op0
== 0 || op1
== 0)
16540 mem_loc_result
= op0
;
16541 add_loc_descr (&mem_loc_result
, op1
);
16542 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16546 if ((!dwarf_strict
|| dwarf_version
>= 5)
16547 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
16548 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
16550 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
16551 base_type_for_mode (mode
, 0),
16552 int_mode
, mem_mode
);
16556 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
16557 VAR_INIT_STATUS_INITIALIZED
);
16558 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
16559 VAR_INIT_STATUS_INITIALIZED
);
16561 if (op0
== 0 || op1
== 0)
16564 mem_loc_result
= op0
;
16565 add_loc_descr (&mem_loc_result
, op1
);
16566 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
16567 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
16568 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
16569 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
16570 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
16574 if ((!dwarf_strict
|| dwarf_version
>= 5)
16575 && is_a
<scalar_int_mode
> (mode
, &int_mode
))
16577 /* We can use a signed divide if the sign bit is not set. */
16578 if (GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
16584 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
16585 base_type_for_mode (int_mode
, 1),
16586 int_mode
, mem_mode
);
16603 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
16604 VAR_INIT_STATUS_INITIALIZED
);
16609 mem_loc_result
= op0
;
16610 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16614 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16615 || GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16616 #ifdef POINTERS_EXTEND_UNSIGNED
16617 || (int_mode
== Pmode
16618 && mem_mode
!= VOIDmode
16619 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
16623 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
16626 if ((!dwarf_strict
|| dwarf_version
>= 5)
16627 && (GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_WIDE_INT
16628 || GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_DOUBLE_INT
))
16630 dw_die_ref type_die
= base_type_for_mode (int_mode
, 1);
16631 scalar_int_mode amode
;
16632 if (type_die
== NULL
)
16634 if (INTVAL (rtl
) >= 0
16635 && (int_mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
, 0)
16637 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
16638 /* const DW_OP_convert <XXX> vs.
16639 DW_OP_const_type <XXX, 1, const>. */
16640 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
16641 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (int_mode
))
16643 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
16644 op0
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16645 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16646 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16647 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16648 add_loc_descr (&mem_loc_result
, op0
);
16649 return mem_loc_result
;
16651 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0,
16653 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16654 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16655 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16656 if (GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_WIDE_INT
)
16657 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
16660 mem_loc_result
->dw_loc_oprnd2
.val_class
16661 = dw_val_class_const_double
;
16662 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
16663 = double_int::from_shwi (INTVAL (rtl
));
16669 if (!dwarf_strict
|| dwarf_version
>= 5)
16671 dw_die_ref type_die
;
16673 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
16674 CONST_DOUBLE rtx could represent either a large integer
16675 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
16676 the value is always a floating point constant.
16678 When it is an integer, a CONST_DOUBLE is used whenever
16679 the constant requires 2 HWIs to be adequately represented.
16680 We output CONST_DOUBLEs as blocks. */
16681 if (mode
== VOIDmode
16682 || (GET_MODE (rtl
) == VOIDmode
16683 && maybe_ne (GET_MODE_BITSIZE (mode
),
16684 HOST_BITS_PER_DOUBLE_INT
)))
16686 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16687 if (type_die
== NULL
)
16689 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
16690 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16691 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16692 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16693 #if TARGET_SUPPORTS_WIDE_INT == 0
16694 if (!SCALAR_FLOAT_MODE_P (mode
))
16696 mem_loc_result
->dw_loc_oprnd2
.val_class
16697 = dw_val_class_const_double
;
16698 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
16699 = rtx_to_double_int (rtl
);
16704 scalar_float_mode float_mode
= as_a
<scalar_float_mode
> (mode
);
16705 unsigned int length
= GET_MODE_SIZE (float_mode
);
16706 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
16707 unsigned int elt_size
= insert_float (rtl
, array
);
16709 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
16710 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
16711 = length
/ elt_size
;
16712 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
16713 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
16718 case CONST_WIDE_INT
:
16719 if (!dwarf_strict
|| dwarf_version
>= 5)
16721 dw_die_ref type_die
;
16723 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16724 if (type_die
== NULL
)
16726 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
16727 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16728 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16729 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16730 mem_loc_result
->dw_loc_oprnd2
.val_class
16731 = dw_val_class_wide_int
;
16732 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
16733 = alloc_dw_wide_int (rtx_mode_t (rtl
, mode
));
16737 case CONST_POLY_INT
:
16738 mem_loc_result
= int_loc_descriptor (rtx_to_poly_int64 (rtl
));
16742 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
16746 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
16750 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
16754 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
16758 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
16762 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
16766 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
16770 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
16774 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
16778 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
16783 if (!SCALAR_INT_MODE_P (mode
))
16788 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
16793 if (CONST_INT_P (XEXP (rtl
, 1))
16794 && CONST_INT_P (XEXP (rtl
, 2))
16795 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
16796 && is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &inner_mode
)
16797 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16798 && GET_MODE_SIZE (inner_mode
) <= DWARF2_ADDR_SIZE
16799 && ((unsigned) INTVAL (XEXP (rtl
, 1))
16800 + (unsigned) INTVAL (XEXP (rtl
, 2))
16801 <= GET_MODE_BITSIZE (int_mode
)))
16804 op0
= mem_loc_descriptor (XEXP (rtl
, 0), inner_mode
,
16805 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
16808 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
16812 mem_loc_result
= op0
;
16813 size
= INTVAL (XEXP (rtl
, 1));
16814 shift
= INTVAL (XEXP (rtl
, 2));
16815 if (BITS_BIG_ENDIAN
)
16816 shift
= GET_MODE_BITSIZE (inner_mode
) - shift
- size
;
16817 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
16819 add_loc_descr (&mem_loc_result
,
16820 int_loc_descriptor (DWARF2_ADDR_SIZE
16822 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
16824 if (size
!= (int) DWARF2_ADDR_SIZE
)
16826 add_loc_descr (&mem_loc_result
,
16827 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
16828 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16835 dw_loc_descr_ref op2
, bra_node
, drop_node
;
16836 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
16837 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
16838 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
16839 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
16840 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
16841 VAR_INIT_STATUS_INITIALIZED
);
16842 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
16843 VAR_INIT_STATUS_INITIALIZED
);
16844 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
16847 mem_loc_result
= op1
;
16848 add_loc_descr (&mem_loc_result
, op2
);
16849 add_loc_descr (&mem_loc_result
, op0
);
16850 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
16851 add_loc_descr (&mem_loc_result
, bra_node
);
16852 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
16853 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
16854 add_loc_descr (&mem_loc_result
, drop_node
);
16855 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16856 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
16861 case FLOAT_TRUNCATE
:
16863 case UNSIGNED_FLOAT
:
16866 if (!dwarf_strict
|| dwarf_version
>= 5)
16868 dw_die_ref type_die
;
16869 dw_loc_descr_ref cvt
;
16871 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
16872 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
16875 if (is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &int_mode
)
16876 && (GET_CODE (rtl
) == FLOAT
16877 || GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
))
16879 type_die
= base_type_for_mode (int_mode
,
16880 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
16881 if (type_die
== NULL
)
16883 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16884 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16885 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16886 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16887 add_loc_descr (&op0
, cvt
);
16889 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
16890 if (type_die
== NULL
)
16892 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16893 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16894 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16895 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16896 add_loc_descr (&op0
, cvt
);
16897 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
16898 && (GET_CODE (rtl
) == FIX
16899 || GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
))
16901 op0
= convert_descriptor_to_mode (int_mode
, op0
);
16905 mem_loc_result
= op0
;
16912 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16913 mem_loc_result
= clz_loc_descriptor (rtl
, int_mode
, mem_mode
);
16918 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16919 mem_loc_result
= popcount_loc_descriptor (rtl
, int_mode
, mem_mode
);
16923 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16924 mem_loc_result
= bswap_loc_descriptor (rtl
, int_mode
, mem_mode
);
16929 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16930 mem_loc_result
= rotate_loc_descriptor (rtl
, int_mode
, mem_mode
);
16934 /* In theory, we could implement the above. */
16935 /* DWARF cannot represent the unsigned compare operations
16960 case FRACT_CONVERT
:
16961 case UNSIGNED_FRACT_CONVERT
:
16963 case UNSIGNED_SAT_FRACT
:
16969 case VEC_DUPLICATE
:
16973 case STRICT_LOW_PART
:
16978 case SMUL_HIGHPART
:
16979 case UMUL_HIGHPART
:
16985 resolve_one_addr (&rtl
);
16988 /* RTL sequences inside PARALLEL record a series of DWARF operations for
16989 the expression. An UNSPEC rtx represents a raw DWARF operation,
16990 new_loc_descr is called for it to build the operation directly.
16991 Otherwise mem_loc_descriptor is called recursively. */
16995 dw_loc_descr_ref exp_result
= NULL
;
16997 for (; index
< XVECLEN (rtl
, 0); index
++)
16999 rtx elem
= XVECEXP (rtl
, 0, index
);
17000 if (GET_CODE (elem
) == UNSPEC
)
17002 /* Each DWARF operation UNSPEC contain two operands, if
17003 one operand is not used for the operation, const0_rtx is
17005 gcc_assert (XVECLEN (elem
, 0) == 2);
17007 HOST_WIDE_INT dw_op
= XINT (elem
, 1);
17008 HOST_WIDE_INT oprnd1
= INTVAL (XVECEXP (elem
, 0, 0));
17009 HOST_WIDE_INT oprnd2
= INTVAL (XVECEXP (elem
, 0, 1));
17011 = new_loc_descr ((enum dwarf_location_atom
) dw_op
, oprnd1
,
17016 = mem_loc_descriptor (elem
, mode
, mem_mode
,
17017 VAR_INIT_STATUS_INITIALIZED
);
17019 if (!mem_loc_result
)
17020 mem_loc_result
= exp_result
;
17022 add_loc_descr (&mem_loc_result
, exp_result
);
17031 print_rtl (stderr
, rtl
);
17032 gcc_unreachable ();
17037 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
17038 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
17040 return mem_loc_result
;
17043 /* Return a descriptor that describes the concatenation of two locations.
17044 This is typically a complex variable. */
17046 static dw_loc_descr_ref
17047 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
17049 /* At present we only track constant-sized pieces. */
17050 unsigned int size0
, size1
;
17051 if (!GET_MODE_SIZE (GET_MODE (x0
)).is_constant (&size0
)
17052 || !GET_MODE_SIZE (GET_MODE (x1
)).is_constant (&size1
))
17055 dw_loc_descr_ref cc_loc_result
= NULL
;
17056 dw_loc_descr_ref x0_ref
17057 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
17058 dw_loc_descr_ref x1_ref
17059 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
17061 if (x0_ref
== 0 || x1_ref
== 0)
17064 cc_loc_result
= x0_ref
;
17065 add_loc_descr_op_piece (&cc_loc_result
, size0
);
17067 add_loc_descr (&cc_loc_result
, x1_ref
);
17068 add_loc_descr_op_piece (&cc_loc_result
, size1
);
17070 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
17071 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
17073 return cc_loc_result
;
17076 /* Return a descriptor that describes the concatenation of N
17079 static dw_loc_descr_ref
17080 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
17083 dw_loc_descr_ref cc_loc_result
= NULL
;
17084 unsigned int n
= XVECLEN (concatn
, 0);
17087 for (i
= 0; i
< n
; ++i
)
17089 dw_loc_descr_ref ref
;
17090 rtx x
= XVECEXP (concatn
, 0, i
);
17092 /* At present we only track constant-sized pieces. */
17093 if (!GET_MODE_SIZE (GET_MODE (x
)).is_constant (&size
))
17096 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
17100 add_loc_descr (&cc_loc_result
, ref
);
17101 add_loc_descr_op_piece (&cc_loc_result
, size
);
17104 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
17105 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
17107 return cc_loc_result
;
17110 /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
17111 for DEBUG_IMPLICIT_PTR RTL. */
17113 static dw_loc_descr_ref
17114 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
17116 dw_loc_descr_ref ret
;
17119 if (dwarf_strict
&& dwarf_version
< 5)
17121 gcc_assert (VAR_P (DEBUG_IMPLICIT_PTR_DECL (rtl
))
17122 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
17123 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
17124 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
17125 ret
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
17126 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
17129 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17130 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
17131 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17135 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
17136 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
17141 /* Output a proper Dwarf location descriptor for a variable or parameter
17142 which is either allocated in a register or in a memory location. For a
17143 register, we just generate an OP_REG and the register number. For a
17144 memory location we provide a Dwarf postfix expression describing how to
17145 generate the (dynamic) address of the object onto the address stack.
17147 MODE is mode of the decl if this loc_descriptor is going to be used in
17148 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
17149 allowed, VOIDmode otherwise.
17151 If we don't know how to describe it, return 0. */
17153 static dw_loc_descr_ref
17154 loc_descriptor (rtx rtl
, machine_mode mode
,
17155 enum var_init_status initialized
)
17157 dw_loc_descr_ref loc_result
= NULL
;
17158 scalar_int_mode int_mode
;
17160 switch (GET_CODE (rtl
))
17163 /* The case of a subreg may arise when we have a local (register)
17164 variable or a formal (register) parameter which doesn't quite fill
17165 up an entire register. For now, just assume that it is
17166 legitimate to make the Dwarf info refer to the whole register which
17167 contains the given subreg. */
17168 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
17169 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
17170 GET_MODE (SUBREG_REG (rtl
)), initialized
);
17176 loc_result
= reg_loc_descriptor (rtl
, initialized
);
17180 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
17181 GET_MODE (rtl
), initialized
);
17182 if (loc_result
== NULL
)
17183 loc_result
= tls_mem_loc_descriptor (rtl
);
17184 if (loc_result
== NULL
)
17186 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
17187 if (new_rtl
!= rtl
)
17188 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
17193 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
17198 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
17203 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
17205 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
17206 if (GET_CODE (loc
) == EXPR_LIST
)
17207 loc
= XEXP (loc
, 0);
17208 loc_result
= loc_descriptor (loc
, mode
, initialized
);
17212 rtl
= XEXP (rtl
, 1);
17217 rtvec par_elems
= XVEC (rtl
, 0);
17218 int num_elem
= GET_NUM_ELEM (par_elems
);
17222 /* Create the first one, so we have something to add to. */
17223 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
17224 VOIDmode
, initialized
);
17225 if (loc_result
== NULL
)
17227 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
17228 /* At present we only track constant-sized pieces. */
17229 if (!GET_MODE_SIZE (mode
).is_constant (&size
))
17231 add_loc_descr_op_piece (&loc_result
, size
);
17232 for (i
= 1; i
< num_elem
; i
++)
17234 dw_loc_descr_ref temp
;
17236 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
17237 VOIDmode
, initialized
);
17240 add_loc_descr (&loc_result
, temp
);
17241 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
17242 /* At present we only track constant-sized pieces. */
17243 if (!GET_MODE_SIZE (mode
).is_constant (&size
))
17245 add_loc_descr_op_piece (&loc_result
, size
);
17251 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
17253 int_mode
= as_a
<scalar_int_mode
> (mode
);
17254 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (int_mode
),
17260 if (mode
== VOIDmode
)
17261 mode
= GET_MODE (rtl
);
17263 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
17265 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
17267 /* Note that a CONST_DOUBLE rtx could represent either an integer
17268 or a floating-point constant. A CONST_DOUBLE is used whenever
17269 the constant requires more than one word in order to be
17270 adequately represented. We output CONST_DOUBLEs as blocks. */
17271 scalar_mode smode
= as_a
<scalar_mode
> (mode
);
17272 loc_result
= new_loc_descr (DW_OP_implicit_value
,
17273 GET_MODE_SIZE (smode
), 0);
17274 #if TARGET_SUPPORTS_WIDE_INT == 0
17275 if (!SCALAR_FLOAT_MODE_P (smode
))
17277 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
17278 loc_result
->dw_loc_oprnd2
.v
.val_double
17279 = rtx_to_double_int (rtl
);
17284 unsigned int length
= GET_MODE_SIZE (smode
);
17285 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
17286 unsigned int elt_size
= insert_float (rtl
, array
);
17288 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
17289 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ elt_size
;
17290 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
17291 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
17296 case CONST_WIDE_INT
:
17297 if (mode
== VOIDmode
)
17298 mode
= GET_MODE (rtl
);
17300 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
17302 int_mode
= as_a
<scalar_int_mode
> (mode
);
17303 loc_result
= new_loc_descr (DW_OP_implicit_value
,
17304 GET_MODE_SIZE (int_mode
), 0);
17305 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
17306 loc_result
->dw_loc_oprnd2
.v
.val_wide
17307 = alloc_dw_wide_int (rtx_mode_t (rtl
, int_mode
));
17312 if (mode
== VOIDmode
)
17313 mode
= GET_MODE (rtl
);
17315 if (mode
!= VOIDmode
17316 /* The combination of a length and byte elt_size doesn't extend
17317 naturally to boolean vectors, where several elements are packed
17318 into the same byte. */
17319 && GET_MODE_CLASS (mode
) != MODE_VECTOR_BOOL
17320 && (dwarf_version
>= 4 || !dwarf_strict
))
17322 unsigned int length
;
17323 if (!CONST_VECTOR_NUNITS (rtl
).is_constant (&length
))
17326 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
17327 unsigned char *array
17328 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
17331 machine_mode imode
= GET_MODE_INNER (mode
);
17333 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
17334 switch (GET_MODE_CLASS (mode
))
17336 case MODE_VECTOR_INT
:
17337 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
17339 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
17340 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
17344 case MODE_VECTOR_FLOAT
:
17345 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
17347 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
17348 insert_float (elt
, p
);
17353 gcc_unreachable ();
17356 loc_result
= new_loc_descr (DW_OP_implicit_value
,
17357 length
* elt_size
, 0);
17358 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
17359 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
17360 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
17361 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
17366 if (mode
== VOIDmode
17367 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
17368 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
17369 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
17371 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
17376 if (!const_ok_for_output (rtl
))
17380 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
17381 && GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
17382 && (dwarf_version
>= 4 || !dwarf_strict
))
17384 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
17385 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17386 vec_safe_push (used_rtx_array
, rtl
);
17390 case DEBUG_IMPLICIT_PTR
:
17391 loc_result
= implicit_ptr_descriptor (rtl
, 0);
17395 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
17396 && CONST_INT_P (XEXP (rtl
, 1)))
17399 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
17405 if ((is_a
<scalar_int_mode
> (mode
, &int_mode
)
17406 && GET_MODE (rtl
) == int_mode
17407 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
17408 && dwarf_version
>= 4)
17409 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
17411 /* Value expression. */
17412 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
17414 add_loc_descr (&loc_result
,
17415 new_loc_descr (DW_OP_stack_value
, 0, 0));
17423 /* We need to figure out what section we should use as the base for the
17424 address ranges where a given location is valid.
17425 1. If this particular DECL has a section associated with it, use that.
17426 2. If this function has a section associated with it, use that.
17427 3. Otherwise, use the text section.
17428 XXX: If you split a variable across multiple sections, we won't notice. */
17430 static const char *
17431 secname_for_decl (const_tree decl
)
17433 const char *secname
;
17435 if (VAR_OR_FUNCTION_DECL_P (decl
)
17436 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
17437 && DECL_SECTION_NAME (decl
))
17438 secname
= DECL_SECTION_NAME (decl
);
17439 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
17441 if (in_cold_section_p
)
17443 section
*sec
= current_function_section ();
17444 if (sec
->common
.flags
& SECTION_NAMED
)
17445 return sec
->named
.name
;
17447 secname
= DECL_SECTION_NAME (current_function_decl
);
17449 else if (cfun
&& in_cold_section_p
)
17450 secname
= crtl
->subsections
.cold_section_label
;
17452 secname
= text_section_label
;
17457 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
17460 decl_by_reference_p (tree decl
)
17462 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
17464 && DECL_BY_REFERENCE (decl
));
17467 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
17470 static dw_loc_descr_ref
17471 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
17472 enum var_init_status initialized
)
17474 int have_address
= 0;
17475 dw_loc_descr_ref descr
;
17478 if (want_address
!= 2)
17480 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
17482 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
17484 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
17485 if (GET_CODE (varloc
) == EXPR_LIST
)
17486 varloc
= XEXP (varloc
, 0);
17487 mode
= GET_MODE (varloc
);
17488 if (MEM_P (varloc
))
17490 rtx addr
= XEXP (varloc
, 0);
17491 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
17492 mode
, initialized
);
17497 rtx x
= avoid_constant_pool_reference (varloc
);
17499 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
17504 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
17511 if (GET_CODE (varloc
) == VAR_LOCATION
)
17512 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
17514 mode
= DECL_MODE (loc
);
17515 descr
= loc_descriptor (varloc
, mode
, initialized
);
17522 if (want_address
== 2 && !have_address
17523 && (dwarf_version
>= 4 || !dwarf_strict
))
17525 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
17527 expansion_failed (loc
, NULL_RTX
,
17528 "DWARF address size mismatch");
17531 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17534 /* Show if we can't fill the request for an address. */
17535 if (want_address
&& !have_address
)
17537 expansion_failed (loc
, NULL_RTX
,
17538 "Want address and only have value");
17542 /* If we've got an address and don't want one, dereference. */
17543 if (!want_address
&& have_address
)
17545 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
17546 enum dwarf_location_atom op
;
17548 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
17550 expansion_failed (loc
, NULL_RTX
,
17551 "DWARF address size mismatch");
17554 else if (size
== DWARF2_ADDR_SIZE
)
17557 op
= DW_OP_deref_size
;
17559 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
17565 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
17566 if it is not possible. */
17568 static dw_loc_descr_ref
17569 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
17571 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
17572 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
17573 else if (dwarf_version
>= 3 || !dwarf_strict
)
17574 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
17579 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
17580 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
17582 static dw_loc_descr_ref
17583 dw_sra_loc_expr (tree decl
, rtx loc
)
17586 unsigned HOST_WIDE_INT padsize
= 0;
17587 dw_loc_descr_ref descr
, *descr_tail
;
17588 unsigned HOST_WIDE_INT decl_size
;
17590 enum var_init_status initialized
;
17592 if (DECL_SIZE (decl
) == NULL
17593 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
17596 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
17598 descr_tail
= &descr
;
17600 for (p
= loc
; p
; p
= XEXP (p
, 1))
17602 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
17603 rtx loc_note
= *decl_piece_varloc_ptr (p
);
17604 dw_loc_descr_ref cur_descr
;
17605 dw_loc_descr_ref
*tail
, last
= NULL
;
17606 unsigned HOST_WIDE_INT opsize
= 0;
17608 if (loc_note
== NULL_RTX
17609 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
17611 padsize
+= bitsize
;
17614 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
17615 varloc
= NOTE_VAR_LOCATION (loc_note
);
17616 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
17617 if (cur_descr
== NULL
)
17619 padsize
+= bitsize
;
17623 /* Check that cur_descr either doesn't use
17624 DW_OP_*piece operations, or their sum is equal
17625 to bitsize. Otherwise we can't embed it. */
17626 for (tail
= &cur_descr
; *tail
!= NULL
;
17627 tail
= &(*tail
)->dw_loc_next
)
17628 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
17630 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
17634 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
17636 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
17640 if (last
!= NULL
&& opsize
!= bitsize
)
17642 padsize
+= bitsize
;
17643 /* Discard the current piece of the descriptor and release any
17644 addr_table entries it uses. */
17645 remove_loc_list_addr_table_entries (cur_descr
);
17649 /* If there is a hole, add DW_OP_*piece after empty DWARF
17650 expression, which means that those bits are optimized out. */
17653 if (padsize
> decl_size
)
17655 remove_loc_list_addr_table_entries (cur_descr
);
17656 goto discard_descr
;
17658 decl_size
-= padsize
;
17659 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
17660 if (*descr_tail
== NULL
)
17662 remove_loc_list_addr_table_entries (cur_descr
);
17663 goto discard_descr
;
17665 descr_tail
= &(*descr_tail
)->dw_loc_next
;
17668 *descr_tail
= cur_descr
;
17670 if (bitsize
> decl_size
)
17671 goto discard_descr
;
17672 decl_size
-= bitsize
;
17675 HOST_WIDE_INT offset
= 0;
17676 if (GET_CODE (varloc
) == VAR_LOCATION
17677 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
17679 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
17680 if (GET_CODE (varloc
) == EXPR_LIST
)
17681 varloc
= XEXP (varloc
, 0);
17685 if (GET_CODE (varloc
) == CONST
17686 || GET_CODE (varloc
) == SIGN_EXTEND
17687 || GET_CODE (varloc
) == ZERO_EXTEND
)
17688 varloc
= XEXP (varloc
, 0);
17689 else if (GET_CODE (varloc
) == SUBREG
)
17690 varloc
= SUBREG_REG (varloc
);
17695 /* DW_OP_bit_size offset should be zero for register
17696 or implicit location descriptions and empty location
17697 descriptions, but for memory addresses needs big endian
17699 if (MEM_P (varloc
))
17701 unsigned HOST_WIDE_INT memsize
;
17702 if (!poly_uint64 (MEM_SIZE (varloc
)).is_constant (&memsize
))
17703 goto discard_descr
;
17704 memsize
*= BITS_PER_UNIT
;
17705 if (memsize
!= bitsize
)
17707 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
17708 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
17709 goto discard_descr
;
17710 if (memsize
< bitsize
)
17711 goto discard_descr
;
17712 if (BITS_BIG_ENDIAN
)
17713 offset
= memsize
- bitsize
;
17717 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
17718 if (*descr_tail
== NULL
)
17719 goto discard_descr
;
17720 descr_tail
= &(*descr_tail
)->dw_loc_next
;
17724 /* If there were any non-empty expressions, add padding till the end of
17726 if (descr
!= NULL
&& decl_size
!= 0)
17728 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
17729 if (*descr_tail
== NULL
)
17730 goto discard_descr
;
17735 /* Discard the descriptor and release any addr_table entries it uses. */
17736 remove_loc_list_addr_table_entries (descr
);
17740 /* Return the dwarf representation of the location list LOC_LIST of
17741 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
17744 static dw_loc_list_ref
17745 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
17747 const char *endname
, *secname
;
17748 var_loc_view endview
;
17750 enum var_init_status initialized
;
17751 struct var_loc_node
*node
;
17752 dw_loc_descr_ref descr
;
17753 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
17754 dw_loc_list_ref list
= NULL
;
17755 dw_loc_list_ref
*listp
= &list
;
17757 /* Now that we know what section we are using for a base,
17758 actually construct the list of locations.
17759 The first location information is what is passed to the
17760 function that creates the location list, and the remaining
17761 locations just get added on to that list.
17762 Note that we only know the start address for a location
17763 (IE location changes), so to build the range, we use
17764 the range [current location start, next location start].
17765 This means we have to special case the last node, and generate
17766 a range of [last location start, end of function label]. */
17768 if (cfun
&& crtl
->has_bb_partition
)
17770 bool save_in_cold_section_p
= in_cold_section_p
;
17771 in_cold_section_p
= first_function_block_is_cold
;
17772 if (loc_list
->last_before_switch
== NULL
)
17773 in_cold_section_p
= !in_cold_section_p
;
17774 secname
= secname_for_decl (decl
);
17775 in_cold_section_p
= save_in_cold_section_p
;
17778 secname
= secname_for_decl (decl
);
17780 for (node
= loc_list
->first
; node
; node
= node
->next
)
17782 bool range_across_switch
= false;
17783 if (GET_CODE (node
->loc
) == EXPR_LIST
17784 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
17786 if (GET_CODE (node
->loc
) == EXPR_LIST
)
17789 /* This requires DW_OP_{,bit_}piece, which is not usable
17790 inside DWARF expressions. */
17791 if (want_address
== 2)
17792 descr
= dw_sra_loc_expr (decl
, node
->loc
);
17796 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
17797 varloc
= NOTE_VAR_LOCATION (node
->loc
);
17798 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
17802 /* If section switch happens in between node->label
17803 and node->next->label (or end of function) and
17804 we can't emit it as a single entry list,
17805 emit two ranges, first one ending at the end
17806 of first partition and second one starting at the
17807 beginning of second partition. */
17808 if (node
== loc_list
->last_before_switch
17809 && (node
!= loc_list
->first
|| loc_list
->first
->next
17810 /* If we are to emit a view number, we will emit
17811 a loclist rather than a single location
17812 expression for the entire function (see
17813 loc_list_has_views), so we have to split the
17814 range that straddles across partitions. */
17815 || !ZERO_VIEW_P (node
->view
))
17816 && current_function_decl
)
17818 endname
= cfun
->fde
->dw_fde_end
;
17820 range_across_switch
= true;
17822 /* The variable has a location between NODE->LABEL and
17823 NODE->NEXT->LABEL. */
17824 else if (node
->next
)
17825 endname
= node
->next
->label
, endview
= node
->next
->view
;
17826 /* If the variable has a location at the last label
17827 it keeps its location until the end of function. */
17828 else if (!current_function_decl
)
17829 endname
= text_end_label
, endview
= 0;
17832 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
17833 current_function_funcdef_no
);
17834 endname
= ggc_strdup (label_id
);
17838 *listp
= new_loc_list (descr
, node
->label
, node
->view
,
17839 endname
, endview
, secname
);
17840 if (TREE_CODE (decl
) == PARM_DECL
17841 && node
== loc_list
->first
17842 && NOTE_P (node
->loc
)
17843 && strcmp (node
->label
, endname
) == 0)
17844 (*listp
)->force
= true;
17845 listp
= &(*listp
)->dw_loc_next
;
17850 && crtl
->has_bb_partition
17851 && node
== loc_list
->last_before_switch
)
17853 bool save_in_cold_section_p
= in_cold_section_p
;
17854 in_cold_section_p
= !first_function_block_is_cold
;
17855 secname
= secname_for_decl (decl
);
17856 in_cold_section_p
= save_in_cold_section_p
;
17859 if (range_across_switch
)
17861 if (GET_CODE (node
->loc
) == EXPR_LIST
)
17862 descr
= dw_sra_loc_expr (decl
, node
->loc
);
17865 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
17866 varloc
= NOTE_VAR_LOCATION (node
->loc
);
17867 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
17870 gcc_assert (descr
);
17871 /* The variable has a location between NODE->LABEL and
17872 NODE->NEXT->LABEL. */
17874 endname
= node
->next
->label
, endview
= node
->next
->view
;
17876 endname
= cfun
->fde
->dw_fde_second_end
, endview
= 0;
17877 *listp
= new_loc_list (descr
, cfun
->fde
->dw_fde_second_begin
, 0,
17878 endname
, endview
, secname
);
17879 listp
= &(*listp
)->dw_loc_next
;
17883 /* Try to avoid the overhead of a location list emitting a location
17884 expression instead, but only if we didn't have more than one
17885 location entry in the first place. If some entries were not
17886 representable, we don't want to pretend a single entry that was
17887 applies to the entire scope in which the variable is
17889 if (list
&& loc_list
->first
->next
)
17892 maybe_gen_llsym (list
);
17897 /* Return true if the loc_list has only single element and thus
17898 can be represented as location description. */
17901 single_element_loc_list_p (dw_loc_list_ref list
)
17903 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
17904 return !list
->ll_symbol
;
17907 /* Duplicate a single element of location list. */
17909 static inline dw_loc_descr_ref
17910 copy_loc_descr (dw_loc_descr_ref ref
)
17912 dw_loc_descr_ref copy
= ggc_alloc
<dw_loc_descr_node
> ();
17913 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
17917 /* To each location in list LIST append loc descr REF. */
17920 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
17922 dw_loc_descr_ref copy
;
17923 add_loc_descr (&list
->expr
, ref
);
17924 list
= list
->dw_loc_next
;
17927 copy
= copy_loc_descr (ref
);
17928 add_loc_descr (&list
->expr
, copy
);
17929 while (copy
->dw_loc_next
)
17930 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
17931 list
= list
->dw_loc_next
;
17935 /* To each location in list LIST prepend loc descr REF. */
17938 prepend_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
17940 dw_loc_descr_ref copy
;
17941 dw_loc_descr_ref ref_end
= list
->expr
;
17942 add_loc_descr (&ref
, list
->expr
);
17944 list
= list
->dw_loc_next
;
17947 dw_loc_descr_ref end
= list
->expr
;
17948 list
->expr
= copy
= copy_loc_descr (ref
);
17949 while (copy
->dw_loc_next
!= ref_end
)
17950 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
17951 copy
->dw_loc_next
= end
;
17952 list
= list
->dw_loc_next
;
17956 /* Given two lists RET and LIST
17957 produce location list that is result of adding expression in LIST
17958 to expression in RET on each position in program.
17959 Might be destructive on both RET and LIST.
17961 TODO: We handle only simple cases of RET or LIST having at most one
17962 element. General case would involve sorting the lists in program order
17963 and merging them that will need some additional work.
17964 Adding that will improve quality of debug info especially for SRA-ed
17968 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
17977 if (!list
->dw_loc_next
)
17979 add_loc_descr_to_each (*ret
, list
->expr
);
17982 if (!(*ret
)->dw_loc_next
)
17984 prepend_loc_descr_to_each (list
, (*ret
)->expr
);
17988 expansion_failed (NULL_TREE
, NULL_RTX
,
17989 "Don't know how to merge two non-trivial"
17990 " location lists.\n");
17995 /* LOC is constant expression. Try a luck, look it up in constant
17996 pool and return its loc_descr of its address. */
17998 static dw_loc_descr_ref
17999 cst_pool_loc_descr (tree loc
)
18001 /* Get an RTL for this, if something has been emitted. */
18002 rtx rtl
= lookup_constant_def (loc
);
18004 if (!rtl
|| !MEM_P (rtl
))
18009 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
18011 /* TODO: We might get more coverage if we was actually delaying expansion
18012 of all expressions till end of compilation when constant pools are fully
18014 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
18016 expansion_failed (loc
, NULL_RTX
,
18017 "CST value in contant pool but not marked.");
18020 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
18021 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
18024 /* Return dw_loc_list representing address of addr_expr LOC
18025 by looking for inner INDIRECT_REF expression and turning
18026 it into simple arithmetics.
18028 See loc_list_from_tree for the meaning of CONTEXT. */
18030 static dw_loc_list_ref
18031 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
18032 loc_descr_context
*context
)
18035 poly_int64 bitsize
, bitpos
, bytepos
;
18037 int unsignedp
, reversep
, volatilep
= 0;
18038 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
18040 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
18041 &bitsize
, &bitpos
, &offset
, &mode
,
18042 &unsignedp
, &reversep
, &volatilep
);
18044 if (!multiple_p (bitpos
, BITS_PER_UNIT
, &bytepos
))
18046 expansion_failed (loc
, NULL_RTX
, "bitfield access");
18049 if (!INDIRECT_REF_P (obj
))
18051 expansion_failed (obj
,
18052 NULL_RTX
, "no indirect ref in inner refrence");
18055 if (!offset
&& known_eq (bitpos
, 0))
18056 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
18059 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
18060 && (dwarf_version
>= 4 || !dwarf_strict
))
18062 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
18067 /* Variable offset. */
18068 list_ret1
= loc_list_from_tree (offset
, 0, context
);
18069 if (list_ret1
== 0)
18071 add_loc_list (&list_ret
, list_ret1
);
18074 add_loc_descr_to_each (list_ret
,
18075 new_loc_descr (DW_OP_plus
, 0, 0));
18077 HOST_WIDE_INT value
;
18078 if (bytepos
.is_constant (&value
) && value
> 0)
18079 add_loc_descr_to_each (list_ret
,
18080 new_loc_descr (DW_OP_plus_uconst
, value
, 0));
18081 else if (maybe_ne (bytepos
, 0))
18082 loc_list_plus_const (list_ret
, bytepos
);
18083 add_loc_descr_to_each (list_ret
,
18084 new_loc_descr (DW_OP_stack_value
, 0, 0));
18089 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
18090 all operations from LOC are nops, move to the last one. Insert in NOPS all
18091 operations that are skipped. */
18094 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
18095 hash_set
<dw_loc_descr_ref
> &nops
)
18097 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
18100 loc
= loc
->dw_loc_next
;
18104 /* Helper for loc_descr_without_nops: free the location description operation
18108 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
18114 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
18118 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
18120 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
18123 /* Set of all DW_OP_nop operations we remove. */
18124 hash_set
<dw_loc_descr_ref
> nops
;
18126 /* First, strip all prefix NOP operations in order to keep the head of the
18127 operations list. */
18128 loc_descr_to_next_no_nop (loc
, nops
);
18130 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
18132 /* For control flow operations: strip "prefix" nops in destination
18134 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
18135 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
18136 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
18137 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
18139 /* Do the same for the operations that follow, then move to the next
18141 if (cur
->dw_loc_next
!= NULL
)
18142 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
18143 cur
= cur
->dw_loc_next
;
18146 nops
.traverse
<void *, free_loc_descr
> (NULL
);
18150 struct dwarf_procedure_info
;
18152 /* Helper structure for location descriptions generation. */
18153 struct loc_descr_context
18155 /* The type that is implicitly referenced by DW_OP_push_object_address, or
18156 NULL_TREE if DW_OP_push_object_address in invalid for this location
18157 description. This is used when processing PLACEHOLDER_EXPR nodes. */
18159 /* The ..._DECL node that should be translated as a
18160 DW_OP_push_object_address operation. */
18162 /* Information about the DWARF procedure we are currently generating. NULL if
18163 we are not generating a DWARF procedure. */
18164 struct dwarf_procedure_info
*dpi
;
18165 /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
18166 by consumer. Used for DW_TAG_generic_subrange attributes. */
18167 bool placeholder_arg
;
18168 /* True if PLACEHOLDER_EXPR has been seen. */
18169 bool placeholder_seen
;
18170 /* True if strict preservation of signedness has been requested. */
18171 bool strict_signedness
;
18174 /* DWARF procedures generation
18176 DWARF expressions (aka. location descriptions) are used to encode variable
18177 things such as sizes or offsets. Such computations can have redundant parts
18178 that can be factorized in order to reduce the size of the output debug
18179 information. This is the whole point of DWARF procedures.
18181 Thanks to stor-layout.cc, size and offset expressions in GENERIC trees are
18182 already factorized into functions ("size functions") in order to handle very
18183 big and complex types. Such functions are quite simple: they have integral
18184 arguments, they return an integral result and their body contains only a
18185 return statement with arithmetic expressions. This is the only kind of
18186 function we are interested in translating into DWARF procedures, here.
18188 DWARF expressions and DWARF procedure are executed using a stack, so we have
18189 to define some calling convention for them to interact. Let's say that:
18191 - Before calling a DWARF procedure, DWARF expressions must push on the stack
18192 all arguments in reverse order (right-to-left) so that when the DWARF
18193 procedure execution starts, the first argument is the top of the stack.
18195 - Then, when returning, the DWARF procedure must have consumed all arguments
18196 on the stack, must have pushed the result and touched nothing else.
18198 - Each integral argument and the result are integral types can be hold in a
18201 - We call "frame offset" the number of stack slots that are "under DWARF
18202 procedure control": it includes the arguments slots, the temporaries and
18203 the result slot. Thus, it is equal to the number of arguments when the
18204 procedure execution starts and must be equal to one (the result) when it
18207 /* Helper structure used when generating operations for a DWARF procedure. */
18208 struct dwarf_procedure_info
18210 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
18211 currently translated. */
18213 /* The number of arguments FNDECL takes. */
18214 unsigned args_count
;
18217 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
18218 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
18219 equate it to this DIE. */
18222 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
18223 dw_die_ref parent_die
)
18225 dw_die_ref dwarf_proc_die
;
18227 if ((dwarf_version
< 3 && dwarf_strict
)
18228 || location
== NULL
)
18231 dwarf_proc_die
= new_die (DW_TAG_dwarf_procedure
, parent_die
, fndecl
);
18233 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
18234 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
18235 return dwarf_proc_die
;
18238 /* Return whether TYPE is a supported type as a DWARF procedure argument
18239 type or return type (we handle only scalar types and pointer types that
18240 aren't wider than the DWARF expression evaluation stack). */
18243 is_handled_procedure_type (tree type
)
18245 return ((INTEGRAL_TYPE_P (type
)
18246 || TREE_CODE (type
) == OFFSET_TYPE
18247 || TREE_CODE (type
) == POINTER_TYPE
)
18248 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
18251 /* Helper for resolve_args_picking: do the same but stop when coming across
18252 visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
18253 offset *before* evaluating the corresponding operation. */
18256 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
18257 struct dwarf_procedure_info
*dpi
,
18258 hash_map
<dw_loc_descr_ref
, unsigned> &frame_offsets
)
18260 /* The "frame_offset" identifier is already used to name a macro... */
18261 unsigned frame_offset_
= initial_frame_offset
;
18262 dw_loc_descr_ref l
;
18264 for (l
= loc
; l
!= NULL
;)
18267 unsigned &l_frame_offset
= frame_offsets
.get_or_insert (l
, &existed
);
18269 /* If we already met this node, there is nothing to compute anymore. */
18272 /* Make sure that the stack size is consistent wherever the execution
18273 flow comes from. */
18274 gcc_assert ((unsigned) l_frame_offset
== frame_offset_
);
18277 l_frame_offset
= frame_offset_
;
18279 /* If needed, relocate the picking offset with respect to the frame
18281 if (l
->frame_offset_rel
)
18283 unsigned HOST_WIDE_INT off
;
18284 switch (l
->dw_loc_opc
)
18287 off
= l
->dw_loc_oprnd1
.v
.val_unsigned
;
18296 gcc_unreachable ();
18298 /* frame_offset_ is the size of the current stack frame, including
18299 incoming arguments. Besides, the arguments are pushed
18300 right-to-left. Thus, in order to access the Nth argument from
18301 this operation node, the picking has to skip temporaries *plus*
18302 one stack slot per argument (0 for the first one, 1 for the second
18305 The targetted argument number (N) is already set as the operand,
18306 and the number of temporaries can be computed with:
18307 frame_offsets_ - dpi->args_count */
18308 off
+= frame_offset_
- dpi
->args_count
;
18310 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
18316 l
->dw_loc_opc
= DW_OP_dup
;
18317 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
18321 l
->dw_loc_opc
= DW_OP_over
;
18322 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
18326 l
->dw_loc_opc
= DW_OP_pick
;
18327 l
->dw_loc_oprnd1
.v
.val_unsigned
= off
;
18331 /* Update frame_offset according to the effect the current operation has
18333 switch (l
->dw_loc_opc
)
18341 case DW_OP_plus_uconst
:
18377 case DW_OP_deref_size
:
18379 case DW_OP_bit_piece
:
18380 case DW_OP_implicit_value
:
18381 case DW_OP_stack_value
:
18382 case DW_OP_deref_type
:
18383 case DW_OP_convert
:
18384 case DW_OP_reinterpret
:
18385 case DW_OP_GNU_deref_type
:
18386 case DW_OP_GNU_convert
:
18387 case DW_OP_GNU_reinterpret
:
18391 case DW_OP_const1u
:
18392 case DW_OP_const1s
:
18393 case DW_OP_const2u
:
18394 case DW_OP_const2s
:
18395 case DW_OP_const4u
:
18396 case DW_OP_const4s
:
18397 case DW_OP_const8u
:
18398 case DW_OP_const8s
:
18469 case DW_OP_push_object_address
:
18470 case DW_OP_call_frame_cfa
:
18471 case DW_OP_GNU_variable_value
:
18472 case DW_OP_GNU_addr_index
:
18473 case DW_OP_GNU_const_index
:
18498 case DW_OP_xderef_size
:
18504 case DW_OP_call_ref
:
18506 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
18507 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
18509 if (stack_usage
== NULL
)
18511 frame_offset_
+= *stack_usage
;
18515 case DW_OP_implicit_pointer
:
18516 case DW_OP_entry_value
:
18517 case DW_OP_const_type
:
18518 case DW_OP_regval_type
:
18519 case DW_OP_form_tls_address
:
18520 case DW_OP_GNU_push_tls_address
:
18521 case DW_OP_GNU_uninit
:
18522 case DW_OP_GNU_encoded_addr
:
18523 case DW_OP_GNU_implicit_pointer
:
18524 case DW_OP_GNU_entry_value
:
18525 case DW_OP_GNU_const_type
:
18526 case DW_OP_GNU_regval_type
:
18527 case DW_OP_GNU_parameter_ref
:
18528 /* loc_list_from_tree will probably not output these operations for
18529 size functions, so assume they will not appear here. */
18530 /* Fall through... */
18533 gcc_unreachable ();
18536 /* Now, follow the control flow (except subroutine calls). */
18537 switch (l
->dw_loc_opc
)
18540 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
18543 /* Fall through. */
18546 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
18549 case DW_OP_stack_value
:
18553 l
= l
->dw_loc_next
;
18561 /* Make a DFS over operations reachable through LOC (i.e. follow branch
18562 operations) in order to resolve the operand of DW_OP_pick operations that
18563 target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
18564 offset *before* LOC is executed. Return if all relocations were
18568 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
18569 struct dwarf_procedure_info
*dpi
)
18571 /* Associate to all visited operations the frame offset *before* evaluating
18573 hash_map
<dw_loc_descr_ref
, unsigned> frame_offsets
;
18576 resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
, frame_offsets
);
18579 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
18580 Return NULL if it is not possible. */
18583 function_to_dwarf_procedure (tree fndecl
)
18585 struct dwarf_procedure_info dpi
;
18586 struct loc_descr_context ctx
= {
18587 NULL_TREE
, /* context_type */
18588 NULL_TREE
, /* base_decl */
18590 false, /* placeholder_arg */
18591 false, /* placeholder_seen */
18592 true /* strict_signedness */
18594 dw_die_ref dwarf_proc_die
;
18595 tree tree_body
= DECL_SAVED_TREE (fndecl
);
18596 dw_loc_descr_ref loc_body
, epilogue
;
18601 /* Do not generate multiple DWARF procedures for the same function
18603 dwarf_proc_die
= lookup_decl_die (fndecl
);
18604 if (dwarf_proc_die
!= NULL
)
18605 return dwarf_proc_die
;
18607 /* DWARF procedures are available starting with the DWARFv3 standard. */
18608 if (dwarf_version
< 3 && dwarf_strict
)
18611 /* We handle only functions for which we still have a body, that return a
18612 supported type and that takes arguments with supported types. Note that
18613 there is no point translating functions that return nothing. */
18614 if (tree_body
== NULL_TREE
18615 || DECL_RESULT (fndecl
) == NULL_TREE
18616 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
18619 for (cursor
= DECL_ARGUMENTS (fndecl
);
18620 cursor
!= NULL_TREE
;
18621 cursor
= TREE_CHAIN (cursor
))
18622 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
18625 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
18626 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
18628 tree_body
= TREE_OPERAND (tree_body
, 0);
18629 if (TREE_CODE (tree_body
) != MODIFY_EXPR
18630 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
18632 tree_body
= TREE_OPERAND (tree_body
, 1);
18634 /* Try to translate the body expression itself. Note that this will probably
18635 cause an infinite recursion if its call graph has a cycle. This is very
18636 unlikely for size functions, however, so don't bother with such things at
18638 dpi
.fndecl
= fndecl
;
18639 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
18640 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
18644 /* After evaluating all operands in "loc_body", we should still have on the
18645 stack all arguments plus the desired function result (top of the stack).
18646 Generate code in order to keep only the result in our stack frame. */
18648 for (i
= 0; i
< dpi
.args_count
; ++i
)
18650 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
18651 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
18652 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
18653 epilogue
= op_couple
;
18655 add_loc_descr (&loc_body
, epilogue
);
18656 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
18659 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
18660 because they are considered useful. Now there is an epilogue, they are
18661 not anymore, so give it another try. */
18662 loc_descr_without_nops (loc_body
);
18664 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
18665 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
18666 though, given that size functions do not come from source, so they should
18667 not have a dedicated DW_TAG_subprogram DIE. */
18669 = new_dwarf_proc_die (loc_body
, fndecl
,
18670 get_context_die (DECL_CONTEXT (fndecl
)));
18672 /* The called DWARF procedure consumes one stack slot per argument and
18673 returns one stack slot. */
18674 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
18676 return dwarf_proc_die
;
18679 /* Helper function for loc_list_from_tree. Perform OP binary op,
18680 but after converting arguments to type_die, afterwards convert
18681 back to unsigned. */
18683 static dw_loc_list_ref
18684 typed_binop_from_tree (enum dwarf_location_atom op
, tree loc
,
18685 dw_die_ref type_die
, scalar_int_mode mode
,
18686 struct loc_descr_context
*context
)
18688 dw_loc_list_ref op0
, op1
;
18689 dw_loc_descr_ref cvt
, binop
;
18691 if (type_die
== NULL
)
18694 op0
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
18695 op1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
18696 if (op0
== NULL
|| op1
== NULL
)
18699 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
18700 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
18701 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
18702 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
18703 add_loc_descr_to_each (op0
, cvt
);
18705 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
18706 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
18707 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
18708 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
18709 add_loc_descr_to_each (op1
, cvt
);
18711 add_loc_list (&op0
, op1
);
18715 binop
= new_loc_descr (op
, 0, 0);
18716 convert_descriptor_to_mode (mode
, binop
);
18717 add_loc_descr_to_each (op0
, binop
);
18722 /* Generate Dwarf location list representing LOC.
18723 If WANT_ADDRESS is false, expression computing LOC will be computed
18724 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
18725 if WANT_ADDRESS is 2, expression computing address useable in location
18726 will be returned (i.e. DW_OP_reg can be used
18727 to refer to register values).
18729 CONTEXT provides information to customize the location descriptions
18730 generation. Its context_type field specifies what type is implicitly
18731 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
18732 will not be generated.
18734 Its DPI field determines whether we are generating a DWARF expression for a
18735 DWARF procedure, so PARM_DECL references are processed specifically.
18737 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
18738 and dpi fields were null. */
18740 static dw_loc_list_ref
18741 loc_list_from_tree_1 (tree loc
, int want_address
,
18742 struct loc_descr_context
*context
)
18744 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
18745 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
18746 int have_address
= 0;
18747 enum dwarf_location_atom op
;
18749 /* ??? Most of the time we do not take proper care for sign/zero
18750 extending the values properly. Hopefully this won't be a real
18753 if (context
!= NULL
18754 && context
->base_decl
== loc
18755 && want_address
== 0)
18757 if (dwarf_version
>= 3 || !dwarf_strict
)
18758 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
18759 NULL
, 0, NULL
, 0, NULL
);
18764 switch (TREE_CODE (loc
))
18767 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
18770 case PLACEHOLDER_EXPR
:
18771 /* This case involves extracting fields from an object to determine the
18772 position of other fields. It is supposed to appear only as the first
18773 operand of COMPONENT_REF nodes and to reference precisely the type
18774 that the context allows or its enclosing type. */
18775 if (context
!= NULL
18776 && (TREE_TYPE (loc
) == context
->context_type
18777 || TREE_TYPE (loc
) == TYPE_CONTEXT (context
->context_type
))
18778 && want_address
>= 1)
18780 if (dwarf_version
>= 3 || !dwarf_strict
)
18782 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
18789 /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
18790 the single argument passed by consumer. */
18791 else if (context
!= NULL
18792 && context
->placeholder_arg
18793 && INTEGRAL_TYPE_P (TREE_TYPE (loc
))
18794 && want_address
== 0)
18796 ret
= new_loc_descr (DW_OP_pick
, 0, 0);
18797 ret
->frame_offset_rel
= 1;
18798 context
->placeholder_seen
= true;
18802 expansion_failed (loc
, NULL_RTX
,
18803 "PLACEHOLDER_EXPR for an unexpected type");
18808 tree callee
= get_callee_fndecl (loc
);
18809 dw_die_ref dwarf_proc
;
18812 && is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
)))
18813 && (dwarf_proc
= function_to_dwarf_procedure (callee
)))
18815 /* DWARF procedures are used for size functions, which are built
18816 when size expressions contain conditional constructs, so we
18817 request strict preservation of signedness for comparisons. */
18818 bool old_strict_signedness
;
18821 old_strict_signedness
= context
->strict_signedness
;
18822 context
->strict_signedness
= true;
18825 /* Evaluate arguments right-to-left so that the first argument
18826 will be the top-most one on the stack. */
18827 for (int i
= call_expr_nargs (loc
) - 1; i
>= 0; --i
)
18829 tree arg
= CALL_EXPR_ARG (loc
, i
);
18830 ret1
= loc_descriptor_from_tree (arg
, 0, context
);
18833 expansion_failed (arg
, NULL_RTX
, "CALL_EXPR argument");
18836 add_loc_descr (&ret
, ret1
);
18839 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
18840 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
18841 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
18842 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
18843 add_loc_descr (&ret
, ret1
);
18845 context
->strict_signedness
= old_strict_signedness
;
18848 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR target");
18852 case PREINCREMENT_EXPR
:
18853 case PREDECREMENT_EXPR
:
18854 case POSTINCREMENT_EXPR
:
18855 case POSTDECREMENT_EXPR
:
18856 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
18857 /* There are no opcodes for these operations. */
18861 /* If we already want an address, see if there is INDIRECT_REF inside
18862 e.g. for &this->field. */
18865 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
18866 (loc
, want_address
== 2, context
);
18869 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
18870 && (ret
= cst_pool_loc_descr (loc
)))
18873 /* Otherwise, process the argument and look for the address. */
18874 if (!list_ret
&& !ret
)
18875 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
18879 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
18885 if (DECL_THREAD_LOCAL_P (loc
))
18888 enum dwarf_location_atom tls_op
;
18889 enum dtprel_bool dtprel
= dtprel_false
;
18891 if (targetm
.have_tls
)
18893 /* If this is not defined, we have no way to emit the
18895 if (!targetm
.asm_out
.output_dwarf_dtprel
)
18898 /* The way DW_OP_GNU_push_tls_address is specified, we
18899 can only look up addresses of objects in the current
18900 module. We used DW_OP_addr as first op, but that's
18901 wrong, because DW_OP_addr is relocated by the debug
18902 info consumer, while DW_OP_GNU_push_tls_address
18903 operand shouldn't be. */
18904 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
18906 dtprel
= dtprel_true
;
18907 /* We check for DWARF 5 here because gdb did not implement
18908 DW_OP_form_tls_address until after 7.12. */
18909 tls_op
= (dwarf_version
>= 5 ? DW_OP_form_tls_address
18910 : DW_OP_GNU_push_tls_address
);
18914 if (!targetm
.emutls
.debug_form_tls_address
18915 || !(dwarf_version
>= 3 || !dwarf_strict
))
18917 /* We stuffed the control variable into the DECL_VALUE_EXPR
18918 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
18919 no longer appear in gimple code. We used the control
18920 variable in specific so that we could pick it up here. */
18921 loc
= DECL_VALUE_EXPR (loc
);
18922 tls_op
= DW_OP_form_tls_address
;
18925 rtl
= rtl_for_decl_location (loc
);
18926 if (rtl
== NULL_RTX
)
18931 rtl
= XEXP (rtl
, 0);
18932 if (! CONSTANT_P (rtl
))
18935 ret
= new_addr_loc_descr (rtl
, dtprel
);
18936 ret1
= new_loc_descr (tls_op
, 0, 0);
18937 add_loc_descr (&ret
, ret1
);
18945 if (context
!= NULL
&& context
->dpi
!= NULL
18946 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
18948 /* We are generating code for a DWARF procedure and we want to access
18949 one of its arguments: find the appropriate argument offset and let
18950 the resolve_args_picking pass compute the offset that complies
18951 with the stack frame size. */
18955 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
18956 cursor
!= NULL_TREE
&& cursor
!= loc
;
18957 cursor
= TREE_CHAIN (cursor
), ++i
)
18959 /* If we are translating a DWARF procedure, all referenced parameters
18960 must belong to the current function. */
18961 gcc_assert (cursor
!= NULL_TREE
);
18963 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
18964 ret
->frame_offset_rel
= 1;
18970 if (DECL_HAS_VALUE_EXPR_P (loc
))
18972 tree value_expr
= DECL_VALUE_EXPR (loc
);
18974 /* Non-local frame structures are DECL_IGNORED_P variables so we need
18975 to wait until they get an RTX in order to reference them. */
18977 && TREE_CODE (value_expr
) == COMPONENT_REF
18978 && VAR_P (TREE_OPERAND (value_expr
, 0))
18979 && DECL_NONLOCAL_FRAME (TREE_OPERAND (value_expr
, 0)))
18982 return loc_list_from_tree_1 (value_expr
, want_address
, context
);
18987 case FUNCTION_DECL
:
18990 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
18992 if (loc_list
&& loc_list
->first
)
18994 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
18995 have_address
= want_address
!= 0;
18998 rtl
= rtl_for_decl_location (loc
);
18999 if (rtl
== NULL_RTX
)
19001 if (TREE_CODE (loc
) != FUNCTION_DECL
19003 && want_address
!= 1
19004 && ! DECL_IGNORED_P (loc
)
19005 && (INTEGRAL_TYPE_P (TREE_TYPE (loc
))
19006 || POINTER_TYPE_P (TREE_TYPE (loc
)))
19007 && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc
)))
19008 <= DWARF2_ADDR_SIZE
))
19010 dw_die_ref ref
= lookup_decl_die (loc
);
19013 ret
= new_loc_descr (DW_OP_GNU_variable_value
, 0, 0);
19014 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
19015 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
19016 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
19018 else if (current_function_decl
19019 && DECL_CONTEXT (loc
) == current_function_decl
)
19021 ret
= new_loc_descr (DW_OP_GNU_variable_value
, 0, 0);
19022 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
19023 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= loc
;
19027 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
19030 else if (CONST_INT_P (rtl
))
19032 HOST_WIDE_INT val
= INTVAL (rtl
);
19033 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
19034 val
&= GET_MODE_MASK (DECL_MODE (loc
));
19035 ret
= int_loc_descriptor (val
);
19037 else if (GET_CODE (rtl
) == CONST_STRING
)
19039 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
19042 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
19043 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
19046 machine_mode mode
, mem_mode
;
19048 /* Certain constructs can only be represented at top-level. */
19049 if (want_address
== 2)
19051 ret
= loc_descriptor (rtl
, VOIDmode
,
19052 VAR_INIT_STATUS_INITIALIZED
);
19057 mode
= GET_MODE (rtl
);
19058 mem_mode
= VOIDmode
;
19062 mode
= get_address_mode (rtl
);
19063 rtl
= XEXP (rtl
, 0);
19066 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
19067 VAR_INIT_STATUS_INITIALIZED
);
19070 expansion_failed (loc
, rtl
,
19071 "failed to produce loc descriptor for rtl");
19077 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
19084 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19088 case TARGET_MEM_REF
:
19090 case DEBUG_EXPR_DECL
:
19093 case COMPOUND_EXPR
:
19094 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
19098 case VIEW_CONVERT_EXPR
:
19101 case NON_LVALUE_EXPR
:
19102 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
19105 case COMPONENT_REF
:
19106 case BIT_FIELD_REF
:
19108 case ARRAY_RANGE_REF
:
19109 case REALPART_EXPR
:
19110 case IMAGPART_EXPR
:
19113 poly_int64 bitsize
, bitpos
, bytepos
;
19115 int unsignedp
, reversep
, volatilep
= 0;
19117 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
19118 &unsignedp
, &reversep
, &volatilep
);
19120 gcc_assert (obj
!= loc
);
19122 list_ret
= loc_list_from_tree_1 (obj
,
19124 && known_eq (bitpos
, 0)
19125 && !offset
? 2 : 1,
19127 /* TODO: We can extract value of the small expression via shifting even
19128 for nonzero bitpos. */
19131 if (!multiple_p (bitpos
, BITS_PER_UNIT
, &bytepos
)
19132 || !multiple_p (bitsize
, BITS_PER_UNIT
))
19134 expansion_failed (loc
, NULL_RTX
,
19135 "bitfield access");
19139 if (offset
!= NULL_TREE
)
19141 /* Variable offset. */
19142 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
19143 if (list_ret1
== 0)
19145 add_loc_list (&list_ret
, list_ret1
);
19148 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
19151 HOST_WIDE_INT value
;
19152 if (bytepos
.is_constant (&value
) && value
> 0)
19153 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
,
19155 else if (maybe_ne (bytepos
, 0))
19156 loc_list_plus_const (list_ret
, bytepos
);
19163 if ((want_address
|| !tree_fits_shwi_p (loc
))
19164 && (ret
= cst_pool_loc_descr (loc
)))
19166 else if (want_address
== 2
19167 && tree_fits_shwi_p (loc
)
19168 && (ret
= address_of_int_loc_descriptor
19169 (int_size_in_bytes (TREE_TYPE (loc
)),
19170 tree_to_shwi (loc
))))
19172 else if (tree_fits_shwi_p (loc
))
19173 ret
= int_loc_descriptor (tree_to_shwi (loc
));
19174 else if (tree_fits_uhwi_p (loc
))
19175 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
19178 expansion_failed (loc
, NULL_RTX
,
19179 "Integer operand is not host integer");
19188 expansion_failed (loc
, NULL_RTX
,
19189 "constant address with a runtime component");
19193 if (!poly_int_tree_p (loc
, &value
))
19195 expansion_failed (loc
, NULL_RTX
, "constant too big");
19198 ret
= int_loc_descriptor (value
);
19206 if ((ret
= cst_pool_loc_descr (loc
)))
19208 else if (TREE_CODE (loc
) == CONSTRUCTOR
)
19210 tree type
= TREE_TYPE (loc
);
19211 unsigned HOST_WIDE_INT size
= int_size_in_bytes (type
);
19212 unsigned HOST_WIDE_INT offset
= 0;
19213 unsigned HOST_WIDE_INT cnt
;
19214 constructor_elt
*ce
;
19216 if (TREE_CODE (type
) == RECORD_TYPE
)
19218 /* This is very limited, but it's enough to output
19219 pointers to member functions, as long as the
19220 referenced function is defined in the current
19221 translation unit. */
19222 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc
), cnt
, ce
)
19224 tree val
= ce
->value
;
19226 tree field
= ce
->index
;
19231 if (!field
|| DECL_BIT_FIELD (field
))
19233 expansion_failed (loc
, NULL_RTX
,
19234 "bitfield in record type constructor");
19235 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
19240 HOST_WIDE_INT fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
19241 unsigned HOST_WIDE_INT pos
= int_byte_position (field
);
19242 gcc_assert (pos
+ fieldsize
<= size
);
19245 expansion_failed (loc
, NULL_RTX
,
19246 "out-of-order fields in record constructor");
19247 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
19253 ret1
= new_loc_descr (DW_OP_piece
, pos
- offset
, 0);
19254 add_loc_descr (&ret
, ret1
);
19257 if (val
&& fieldsize
!= 0)
19259 ret1
= loc_descriptor_from_tree (val
, want_address
, context
);
19262 expansion_failed (loc
, NULL_RTX
,
19263 "unsupported expression in field");
19264 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
19268 add_loc_descr (&ret
, ret1
);
19272 ret1
= new_loc_descr (DW_OP_piece
, fieldsize
, 0);
19273 add_loc_descr (&ret
, ret1
);
19274 offset
= pos
+ fieldsize
;
19278 if (offset
!= size
)
19280 ret1
= new_loc_descr (DW_OP_piece
, size
- offset
, 0);
19281 add_loc_descr (&ret
, ret1
);
19285 have_address
= !!want_address
;
19288 expansion_failed (loc
, NULL_RTX
,
19289 "constructor of non-record type");
19292 /* We can construct small constants here using int_loc_descriptor. */
19293 expansion_failed (loc
, NULL_RTX
,
19294 "constructor or constant not in constant pool");
19297 case TRUTH_AND_EXPR
:
19298 case TRUTH_ANDIF_EXPR
:
19303 case TRUTH_XOR_EXPR
:
19308 case TRUTH_OR_EXPR
:
19309 case TRUTH_ORIF_EXPR
:
19314 case EXACT_DIV_EXPR
:
19315 case FLOOR_DIV_EXPR
:
19316 case TRUNC_DIV_EXPR
:
19317 /* Turn a divide by a power of 2 into a shift when possible. */
19318 if (TYPE_UNSIGNED (TREE_TYPE (loc
))
19319 && tree_fits_uhwi_p (TREE_OPERAND (loc
, 1)))
19321 const int log2
= exact_log2 (tree_to_uhwi (TREE_OPERAND (loc
, 1)));
19325 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19329 add_loc_descr_to_each (list_ret
, uint_loc_descriptor (log2
));
19330 add_loc_descr_to_each (list_ret
,
19331 new_loc_descr (DW_OP_shr
, 0, 0));
19338 case CEIL_DIV_EXPR
:
19339 case ROUND_DIV_EXPR
:
19340 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
19342 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (loc
));
19343 scalar_int_mode int_mode
;
19345 if ((dwarf_strict
&& dwarf_version
< 5)
19346 || !is_a
<scalar_int_mode
> (mode
, &int_mode
))
19349 /* We can use a signed divide if the sign bit is not set. */
19350 if (GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
19356 list_ret
= typed_binop_from_tree (DW_OP_div
, loc
,
19357 base_type_for_mode (int_mode
, 1),
19358 int_mode
, context
);
19368 case FLOOR_MOD_EXPR
:
19369 case CEIL_MOD_EXPR
:
19370 case ROUND_MOD_EXPR
:
19371 case TRUNC_MOD_EXPR
:
19372 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
19377 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19378 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
19379 if (list_ret
== 0 || list_ret1
== 0)
19382 add_loc_list (&list_ret
, list_ret1
);
19385 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
19386 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
19387 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
19388 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
19389 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
19401 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
19404 case POINTER_PLUS_EXPR
:
19407 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
19409 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
19410 smarter to encode their opposite. The DW_OP_plus_uconst operation
19411 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
19412 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
19413 bytes, Y being the size of the operation that pushes the opposite
19414 of the addend. So let's choose the smallest representation. */
19415 const tree tree_addend
= TREE_OPERAND (loc
, 1);
19416 offset_int wi_addend
;
19417 HOST_WIDE_INT shwi_addend
;
19418 dw_loc_descr_ref loc_naddend
;
19420 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19424 /* Try to get the literal to push. It is the opposite of the addend,
19425 so as we rely on wrapping during DWARF evaluation, first decode
19426 the literal as a "DWARF-sized" signed number. */
19427 wi_addend
= wi::to_offset (tree_addend
);
19428 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
19429 shwi_addend
= wi_addend
.to_shwi ();
19430 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
19431 ? int_loc_descriptor (-shwi_addend
)
19434 if (loc_naddend
!= NULL
19435 && ((unsigned) size_of_uleb128 (shwi_addend
)
19436 > size_of_loc_descr (loc_naddend
)))
19438 add_loc_descr_to_each (list_ret
, loc_naddend
);
19439 add_loc_descr_to_each (list_ret
,
19440 new_loc_descr (DW_OP_minus
, 0, 0));
19444 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
19446 loc_naddend
= loc_cur
;
19447 loc_cur
= loc_cur
->dw_loc_next
;
19448 ggc_free (loc_naddend
);
19450 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
19460 goto do_comp_binop
;
19464 goto do_comp_binop
;
19468 goto do_comp_binop
;
19472 goto do_comp_binop
;
19475 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
19477 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
19478 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
19479 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
19495 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19496 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
19497 if (list_ret
== 0 || list_ret1
== 0)
19500 add_loc_list (&list_ret
, list_ret1
);
19503 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
19506 case TRUTH_NOT_EXPR
:
19507 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19511 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
19512 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_eq
, 0, 0));
19528 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19532 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
19538 const enum tree_code code
=
19539 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
19541 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
19542 build2 (code
, integer_type_node
,
19543 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
19544 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
19551 dw_loc_descr_ref lhs
19552 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
19553 dw_loc_list_ref rhs
19554 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
19555 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
19557 /* DW_OP_bra is branch-on-nonzero so avoid doing useless work. */
19558 if (TREE_CODE (TREE_OPERAND (loc
, 0)) == NE_EXPR
19559 && integer_zerop (TREE_OPERAND (TREE_OPERAND (loc
, 0), 1)))
19561 = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc
, 0), 0),
19563 /* Likewise, swap the operands for a logically negated condition. */
19564 else if (TREE_CODE (TREE_OPERAND (loc
, 0)) == TRUTH_NOT_EXPR
)
19566 lhs
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0, context
);
19567 rhs
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
19569 = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc
, 0), 0),
19573 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19574 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
19577 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
19578 add_loc_descr_to_each (list_ret
, bra_node
);
19580 add_loc_list (&list_ret
, rhs
);
19581 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
19582 add_loc_descr_to_each (list_ret
, jump_node
);
19584 add_loc_descr_to_each (list_ret
, lhs
);
19585 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
19586 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
19588 /* ??? Need a node to point the skip at. Use a nop. */
19589 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
19590 add_loc_descr_to_each (list_ret
, tmp
);
19591 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
19592 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
19596 case FIX_TRUNC_EXPR
:
19599 case COMPOUND_LITERAL_EXPR
:
19600 return loc_list_from_tree_1 (COMPOUND_LITERAL_EXPR_DECL (loc
),
19604 /* Leave front-end specific codes as simply unknown. This comes
19605 up, for instance, with the C STMT_EXPR. */
19606 if ((unsigned int) TREE_CODE (loc
)
19607 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
19609 expansion_failed (loc
, NULL_RTX
,
19610 "language specific tree node");
19614 /* Otherwise this is a generic code; we should just lists all of
19615 these explicitly. We forgot one. */
19617 gcc_unreachable ();
19619 /* In a release build, we want to degrade gracefully: better to
19620 generate incomplete debugging information than to crash. */
19624 if (!ret
&& !list_ret
)
19627 if (want_address
== 2 && !have_address
19628 && (dwarf_version
>= 4 || !dwarf_strict
))
19630 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
19632 expansion_failed (loc
, NULL_RTX
,
19633 "DWARF address size mismatch");
19637 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
19639 add_loc_descr_to_each (list_ret
,
19640 new_loc_descr (DW_OP_stack_value
, 0, 0));
19643 /* Show if we can't fill the request for an address. */
19644 if (want_address
&& !have_address
)
19646 expansion_failed (loc
, NULL_RTX
,
19647 "Want address and only have value");
19651 gcc_assert (!ret
|| !list_ret
);
19653 /* If we've got an address and don't want one, dereference. */
19654 if (!want_address
&& have_address
)
19656 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
19657 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (loc
));
19658 scalar_int_mode int_mode
;
19659 dw_die_ref type_die
;
19660 dw_loc_descr_ref deref
;
19662 /* If the size is greater than DWARF2_ADDR_SIZE, bail out. */
19663 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
19665 expansion_failed (loc
, NULL_RTX
,
19666 "DWARF address size mismatch");
19670 /* If it is equal to DWARF2_ADDR_SIZE, extension does not matter. */
19671 else if (size
== DWARF2_ADDR_SIZE
)
19672 deref
= new_loc_descr (DW_OP_deref
, size
, 0);
19674 /* If it is lower than DWARF2_ADDR_SIZE, DW_OP_deref_size will zero-
19675 extend the value, which is really OK for unsigned types only. */
19676 else if (!(context
&& context
->strict_signedness
)
19677 || TYPE_UNSIGNED (TREE_TYPE (loc
))
19678 || (dwarf_strict
&& dwarf_version
< 5)
19679 || !is_a
<scalar_int_mode
> (mode
, &int_mode
)
19680 || !(type_die
= base_type_for_mode (mode
, false)))
19681 deref
= new_loc_descr (DW_OP_deref_size
, size
, 0);
19683 /* Use DW_OP_deref_type for signed integral types if possible, but
19684 convert back to the generic type to avoid type mismatches later. */
19687 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
), size
, 0);
19688 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
19689 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
19690 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
19691 add_loc_descr (&deref
,
19692 new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
19696 add_loc_descr (&ret
, deref
);
19698 add_loc_descr_to_each (list_ret
, deref
);
19702 list_ret
= new_loc_list (ret
, NULL
, 0, NULL
, 0, NULL
);
19707 /* Likewise, but strip useless DW_OP_nop operations in the resulting
19710 static dw_loc_list_ref
19711 loc_list_from_tree (tree loc
, int want_address
,
19712 struct loc_descr_context
*context
)
19714 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
19716 for (dw_loc_list_ref loc_cur
= result
;
19717 loc_cur
!= NULL
; loc_cur
= loc_cur
->dw_loc_next
)
19718 loc_descr_without_nops (loc_cur
->expr
);
19722 /* Same as above but return only single location expression. */
19723 static dw_loc_descr_ref
19724 loc_descriptor_from_tree (tree loc
, int want_address
,
19725 struct loc_descr_context
*context
)
19727 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
19730 if (ret
->dw_loc_next
)
19732 expansion_failed (loc
, NULL_RTX
,
19733 "Location list where only loc descriptor needed");
19739 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
19740 pointer to the declared type for the relevant field variable, or return
19741 `integer_type_node' if the given node turns out to be an
19742 ERROR_MARK node. */
19745 field_type (const_tree decl
)
19749 if (TREE_CODE (decl
) == ERROR_MARK
)
19750 return integer_type_node
;
19752 type
= DECL_BIT_FIELD_TYPE (decl
);
19753 if (type
== NULL_TREE
)
19754 type
= TREE_TYPE (decl
);
19759 /* Given a pointer to a tree node, return the alignment in bits for
19760 it, or else return BITS_PER_WORD if the node actually turns out to
19761 be an ERROR_MARK node. */
19763 static inline unsigned
19764 simple_type_align_in_bits (const_tree type
)
19766 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
19769 static inline unsigned
19770 simple_decl_align_in_bits (const_tree decl
)
19772 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
19775 /* Return the result of rounding T up to ALIGN. */
19777 static inline offset_int
19778 round_up_to_align (const offset_int
&t
, unsigned int align
)
19780 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
19783 /* Helper structure for RECORD_TYPE processing. */
19786 /* Root RECORD_TYPE. It is needed to generate data member location
19787 descriptions in variable-length records (VLR), but also to cope with
19788 variants, which are composed of nested structures multiplexed with
19789 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
19790 function processing a FIELD_DECL, it is required to be non null. */
19793 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
19794 QUAL_UNION_TYPE), this holds an expression that computes the offset for
19795 this variant part as part of the root record (in storage units). For
19796 regular records, it must be NULL_TREE. */
19797 tree variant_part_offset
;
19800 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
19801 addressed byte of the "containing object" for the given FIELD_DECL. If
19802 possible, return a native constant through CST_OFFSET (in which case NULL is
19803 returned); otherwise return a DWARF expression that computes the offset.
19805 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
19806 that offset is, either because the argument turns out to be a pointer to an
19807 ERROR_MARK node, or because the offset expression is too complex for us.
19809 CTX is required: see the comment for VLR_CONTEXT. */
19811 static dw_loc_descr_ref
19812 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
19813 HOST_WIDE_INT
*cst_offset
)
19816 dw_loc_list_ref loc_result
;
19820 if (TREE_CODE (decl
) == ERROR_MARK
)
19823 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
19825 /* We cannot handle variable bit offsets at the moment, so abort if it's the
19827 if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
)
19830 /* We used to handle only constant offsets in all cases. Now, we handle
19831 properly dynamic byte offsets only when PCC bitfield type doesn't
19833 if (PCC_BITFIELD_TYPE_MATTERS
19834 && DECL_BIT_FIELD_TYPE (decl
)
19835 && TREE_CODE (DECL_FIELD_OFFSET (decl
)) == INTEGER_CST
)
19837 offset_int object_offset_in_bits
;
19838 offset_int object_offset_in_bytes
;
19839 offset_int bitpos_int
;
19841 tree field_size_tree
;
19842 offset_int deepest_bitpos
;
19843 offset_int field_size_in_bits
;
19844 unsigned int type_align_in_bits
;
19845 unsigned int decl_align_in_bits
;
19846 offset_int type_size_in_bits
;
19848 bitpos_int
= wi::to_offset (bit_position (decl
));
19849 type
= field_type (decl
);
19850 type_size_in_bits
= offset_int_type_size_in_bits (type
);
19851 type_align_in_bits
= simple_type_align_in_bits (type
);
19853 field_size_tree
= DECL_SIZE (decl
);
19855 /* The size could be unspecified if there was an error, or for
19856 a flexible array member. */
19857 if (!field_size_tree
)
19858 field_size_tree
= bitsize_zero_node
;
19860 /* If the size of the field is not constant, use the type size. */
19861 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
19862 field_size_in_bits
= wi::to_offset (field_size_tree
);
19864 field_size_in_bits
= type_size_in_bits
;
19866 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
19868 /* The GCC front-end doesn't make any attempt to keep track of the
19869 starting bit offset (relative to the start of the containing
19870 structure type) of the hypothetical "containing object" for a
19871 bit-field. Thus, when computing the byte offset value for the
19872 start of the "containing object" of a bit-field, we must deduce
19873 this information on our own. This can be rather tricky to do in
19874 some cases. For example, handling the following structure type
19875 definition when compiling for an i386/i486 target (which only
19876 aligns long long's to 32-bit boundaries) can be very tricky:
19878 struct S { int field1; long long field2:31; };
19880 Fortunately, there is a simple rule-of-thumb which can be used
19881 in such cases. When compiling for an i386/i486, GCC will
19882 allocate 8 bytes for the structure shown above. It decides to
19883 do this based upon one simple rule for bit-field allocation.
19884 GCC allocates each "containing object" for each bit-field at
19885 the first (i.e. lowest addressed) legitimate alignment boundary
19886 (based upon the required minimum alignment for the declared
19887 type of the field) which it can possibly use, subject to the
19888 condition that there is still enough available space remaining
19889 in the containing object (when allocated at the selected point)
19890 to fully accommodate all of the bits of the bit-field itself.
19892 This simple rule makes it obvious why GCC allocates 8 bytes for
19893 each object of the structure type shown above. When looking
19894 for a place to allocate the "containing object" for `field2',
19895 the compiler simply tries to allocate a 64-bit "containing
19896 object" at each successive 32-bit boundary (starting at zero)
19897 until it finds a place to allocate that 64- bit field such that
19898 at least 31 contiguous (and previously unallocated) bits remain
19899 within that selected 64 bit field. (As it turns out, for the
19900 example above, the compiler finds it is OK to allocate the
19901 "containing object" 64-bit field at bit-offset zero within the
19904 Here we attempt to work backwards from the limited set of facts
19905 we're given, and we try to deduce from those facts, where GCC
19906 must have believed that the containing object started (within
19907 the structure type). The value we deduce is then used (by the
19908 callers of this routine) to generate DW_AT_location and
19909 DW_AT_bit_offset attributes for fields (both bit-fields and, in
19910 the case of DW_AT_location, regular fields as well). */
19912 /* Figure out the bit-distance from the start of the structure to
19913 the "deepest" bit of the bit-field. */
19914 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
19916 /* This is the tricky part. Use some fancy footwork to deduce
19917 where the lowest addressed bit of the containing object must
19919 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
19921 /* Round up to type_align by default. This works best for
19923 object_offset_in_bits
19924 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
19926 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
19928 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
19930 /* Round up to decl_align instead. */
19931 object_offset_in_bits
19932 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
19935 object_offset_in_bytes
19936 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
19937 if (ctx
->variant_part_offset
== NULL_TREE
)
19939 *cst_offset
= object_offset_in_bytes
.to_shwi ();
19942 tree_result
= wide_int_to_tree (sizetype
, object_offset_in_bytes
);
19945 tree_result
= byte_position (decl
);
19947 if (ctx
->variant_part_offset
!= NULL_TREE
)
19948 tree_result
= fold_build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
19949 ctx
->variant_part_offset
, tree_result
);
19951 /* If the byte offset is a constant, it's simplier to handle a native
19952 constant rather than a DWARF expression. */
19953 if (TREE_CODE (tree_result
) == INTEGER_CST
)
19955 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
19959 struct loc_descr_context loc_ctx
= {
19960 ctx
->struct_type
, /* context_type */
19961 NULL_TREE
, /* base_decl */
19963 false, /* placeholder_arg */
19964 false, /* placeholder_seen */
19965 false /* strict_signedness */
19967 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
19969 /* We want a DWARF expression: abort if we only have a location list with
19970 multiple elements. */
19971 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
19974 return loc_result
->expr
;
19977 /* The following routines define various Dwarf attributes and any data
19978 associated with them. */
19980 /* Add a location description attribute value to a DIE.
19982 This emits location attributes suitable for whole variables and
19983 whole parameters. Note that the location attributes for struct fields are
19984 generated by the routine `data_member_location_attribute' below. */
19987 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
19988 dw_loc_list_ref descr
)
19990 bool check_no_locviews
= true;
19993 if (single_element_loc_list_p (descr
))
19994 add_AT_loc (die
, attr_kind
, descr
->expr
);
19997 add_AT_loc_list (die
, attr_kind
, descr
);
19998 gcc_assert (descr
->ll_symbol
);
19999 if (attr_kind
== DW_AT_location
&& descr
->vl_symbol
20000 && dwarf2out_locviews_in_attribute ())
20002 add_AT_view_list (die
, DW_AT_GNU_locviews
);
20003 check_no_locviews
= false;
20007 if (check_no_locviews
)
20008 gcc_assert (!get_AT (die
, DW_AT_GNU_locviews
));
20011 /* Add DW_AT_accessibility attribute to DIE if needed. */
20014 add_accessibility_attribute (dw_die_ref die
, tree decl
)
20016 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20017 children, otherwise the default is DW_ACCESS_public. In DWARF2
20018 the default has always been DW_ACCESS_public. */
20019 if (TREE_PROTECTED (decl
))
20020 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
20021 else if (TREE_PRIVATE (decl
))
20023 if (dwarf_version
== 2
20024 || die
->die_parent
== NULL
20025 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
20026 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
20028 else if (dwarf_version
> 2
20030 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
20031 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
20034 /* Attach the specialized form of location attribute used for data members of
20035 struct and union types. In the special case of a FIELD_DECL node which
20036 represents a bit-field, the "offset" part of this special location
20037 descriptor must indicate the distance in bytes from the lowest-addressed
20038 byte of the containing struct or union type to the lowest-addressed byte of
20039 the "containing object" for the bit-field. (See the `field_byte_offset'
20042 For any given bit-field, the "containing object" is a hypothetical object
20043 (of some integral or enum type) within which the given bit-field lives. The
20044 type of this hypothetical "containing object" is always the same as the
20045 declared type of the individual bit-field itself (for GCC anyway... the
20046 DWARF spec doesn't actually mandate this). Note that it is the size (in
20047 bytes) of the hypothetical "containing object" which will be given in the
20048 DW_AT_byte_size attribute for this bit-field. (See the
20049 `byte_size_attribute' function below.) It is also used when calculating the
20050 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
20053 CTX is required: see the comment for VLR_CONTEXT. */
20056 add_data_member_location_attribute (dw_die_ref die
,
20058 struct vlr_context
*ctx
)
20060 HOST_WIDE_INT offset
;
20061 dw_loc_descr_ref loc_descr
= 0;
20063 if (TREE_CODE (decl
) == TREE_BINFO
)
20065 /* We're working on the TAG_inheritance for a base class. */
20066 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
20068 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
20069 aren't at a fixed offset from all (sub)objects of the same
20070 type. We need to extract the appropriate offset from our
20071 vtable. The following dwarf expression means
20073 BaseAddr = ObAddr + *((*ObAddr) - Offset)
20075 This is specific to the V3 ABI, of course. */
20077 dw_loc_descr_ref tmp
;
20079 /* Make a copy of the object address. */
20080 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
20081 add_loc_descr (&loc_descr
, tmp
);
20083 /* Extract the vtable address. */
20084 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
20085 add_loc_descr (&loc_descr
, tmp
);
20087 /* Calculate the address of the offset. */
20088 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
20089 gcc_assert (offset
< 0);
20091 tmp
= int_loc_descriptor (-offset
);
20092 add_loc_descr (&loc_descr
, tmp
);
20093 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
20094 add_loc_descr (&loc_descr
, tmp
);
20096 /* Extract the offset. */
20097 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
20098 add_loc_descr (&loc_descr
, tmp
);
20100 /* Add it to the object address. */
20101 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
20102 add_loc_descr (&loc_descr
, tmp
);
20105 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
20109 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
20114 /* If loc_descr is available, then we know the offset is dynamic. */
20115 else if (gnat_encodings
== DWARF_GNAT_ENCODINGS_ALL
)
20121 /* Data member location evaluation starts with the base address on the
20122 stack. Compute the field offset and add it to this base address. */
20124 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
20129 /* While DW_AT_data_bit_offset has been added already in DWARF4,
20130 e.g. GDB only added support to it in November 2016. For DWARF5
20131 we need newer debug info consumers anyway. We might change this
20132 to dwarf_version >= 4 once most consumers catched up. */
20133 if (dwarf_version
>= 5
20134 && TREE_CODE (decl
) == FIELD_DECL
20135 && DECL_BIT_FIELD_TYPE (decl
)
20136 && (ctx
->variant_part_offset
== NULL_TREE
20137 || TREE_CODE (ctx
->variant_part_offset
) == INTEGER_CST
))
20139 tree off
= bit_position (decl
);
20140 if (ctx
->variant_part_offset
)
20141 off
= bit_from_pos (ctx
->variant_part_offset
, off
);
20142 if (tree_fits_uhwi_p (off
) && get_AT (die
, DW_AT_bit_size
))
20144 remove_AT (die
, DW_AT_byte_size
);
20145 remove_AT (die
, DW_AT_bit_offset
);
20146 add_AT_unsigned (die
, DW_AT_data_bit_offset
, tree_to_uhwi (off
));
20150 if (dwarf_version
> 2)
20152 /* Don't need to output a location expression, just the constant. */
20154 add_AT_int (die
, DW_AT_data_member_location
, offset
);
20156 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
20161 enum dwarf_location_atom op
;
20163 /* The DWARF2 standard says that we should assume that the structure
20164 address is already on the stack, so we can specify a structure
20165 field address by using DW_OP_plus_uconst. */
20166 op
= DW_OP_plus_uconst
;
20167 loc_descr
= new_loc_descr (op
, offset
, 0);
20171 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
20174 /* Writes integer values to dw_vec_const array. */
20177 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
20181 *dest
++ = val
& 0xff;
20187 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
20189 static HOST_WIDE_INT
20190 extract_int (const unsigned char *src
, unsigned int size
)
20192 HOST_WIDE_INT val
= 0;
20198 val
|= *--src
& 0xff;
20204 /* Writes wide_int values to dw_vec_const array. */
20207 insert_wide_int (const wide_int_ref
&val
, unsigned char *dest
, int elt_size
)
20211 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
20213 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
20217 /* We'd have to extend this code to support odd sizes. */
20218 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
20220 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
20222 if (WORDS_BIG_ENDIAN
)
20223 for (i
= n
- 1; i
>= 0; i
--)
20225 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
20226 dest
+= sizeof (HOST_WIDE_INT
);
20229 for (i
= 0; i
< n
; i
++)
20231 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
20232 dest
+= sizeof (HOST_WIDE_INT
);
20236 /* Writes floating point values to dw_vec_const array. */
20239 insert_float (const_rtx rtl
, unsigned char *array
)
20243 scalar_float_mode mode
= as_a
<scalar_float_mode
> (GET_MODE (rtl
));
20245 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), mode
);
20247 /* real_to_target puts 32-bit pieces in each long. Pack them. */
20248 if (GET_MODE_SIZE (mode
) < 4)
20250 gcc_assert (GET_MODE_SIZE (mode
) == 2);
20251 insert_int (val
[0], 2, array
);
20255 for (i
= 0; i
< GET_MODE_SIZE (mode
) / 4; i
++)
20257 insert_int (val
[i
], 4, array
);
20263 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
20264 does not have a "location" either in memory or in a register. These
20265 things can arise in GNU C when a constant is passed as an actual parameter
20266 to an inlined function. They can also arise in C++ where declared
20267 constants do not necessarily get memory "homes". */
20270 add_const_value_attribute (dw_die_ref die
, machine_mode mode
, rtx rtl
)
20272 scalar_mode int_mode
;
20274 switch (GET_CODE (rtl
))
20278 HOST_WIDE_INT val
= INTVAL (rtl
);
20281 add_AT_int (die
, DW_AT_const_value
, val
);
20283 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
20287 case CONST_WIDE_INT
:
20288 if (is_int_mode (mode
, &int_mode
)
20289 && (GET_MODE_PRECISION (int_mode
)
20290 & (HOST_BITS_PER_WIDE_INT
- 1)) == 0)
20292 add_AT_wide (die
, DW_AT_const_value
, rtx_mode_t (rtl
, int_mode
));
20298 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
20299 floating-point constant. A CONST_DOUBLE is used whenever the
20300 constant requires more than one word in order to be adequately
20302 if (TARGET_SUPPORTS_WIDE_INT
== 0
20303 && !SCALAR_FLOAT_MODE_P (GET_MODE (rtl
)))
20304 add_AT_double (die
, DW_AT_const_value
,
20305 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
20308 scalar_float_mode mode
= as_a
<scalar_float_mode
> (GET_MODE (rtl
));
20309 unsigned int length
= GET_MODE_SIZE (mode
);
20310 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
20311 unsigned int elt_size
= insert_float (rtl
, array
);
20313 add_AT_vec (die
, DW_AT_const_value
, length
/ elt_size
, elt_size
,
20320 unsigned int length
;
20321 if (!CONST_VECTOR_NUNITS (rtl
).is_constant (&length
))
20324 machine_mode mode
= GET_MODE (rtl
);
20325 /* The combination of a length and byte elt_size doesn't extend
20326 naturally to boolean vectors, where several elements are packed
20327 into the same byte. */
20328 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_BOOL
)
20331 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
20332 unsigned char *array
20333 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
20336 machine_mode imode
= GET_MODE_INNER (mode
);
20338 switch (GET_MODE_CLASS (mode
))
20340 case MODE_VECTOR_INT
:
20341 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
20343 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
20344 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
20348 case MODE_VECTOR_FLOAT
:
20349 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
20351 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
20352 insert_float (elt
, p
);
20357 gcc_unreachable ();
20360 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
20365 if (dwarf_version
>= 4 || !dwarf_strict
)
20367 dw_loc_descr_ref loc_result
;
20368 resolve_one_addr (&rtl
);
20370 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
20371 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
20372 add_AT_loc (die
, DW_AT_location
, loc_result
);
20373 vec_safe_push (used_rtx_array
, rtl
);
20379 if (CONSTANT_P (XEXP (rtl
, 0)))
20380 return add_const_value_attribute (die
, mode
, XEXP (rtl
, 0));
20383 if (!const_ok_for_output (rtl
))
20387 if (dwarf_version
>= 4 || !dwarf_strict
)
20392 /* In cases where an inlined instance of an inline function is passed
20393 the address of an `auto' variable (which is local to the caller) we
20394 can get a situation where the DECL_RTL of the artificial local
20395 variable (for the inlining) which acts as a stand-in for the
20396 corresponding formal parameter (of the inline function) will look
20397 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
20398 exactly a compile-time constant expression, but it isn't the address
20399 of the (artificial) local variable either. Rather, it represents the
20400 *value* which the artificial local variable always has during its
20401 lifetime. We currently have no way to represent such quasi-constant
20402 values in Dwarf, so for now we just punt and generate nothing. */
20410 case CONST_POLY_INT
:
20414 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
20415 && MEM_READONLY_P (rtl
)
20416 && GET_MODE (rtl
) == BLKmode
)
20418 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
20424 /* No other kinds of rtx should be possible here. */
20425 gcc_unreachable ();
20429 /* Determine whether the evaluation of EXPR references any variables
20430 or functions which aren't otherwise used (and therefore may not be
20433 reference_to_unused (tree
* tp
, int * walk_subtrees
,
20434 void * data ATTRIBUTE_UNUSED
)
20436 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
20437 *walk_subtrees
= 0;
20439 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
20440 && ! TREE_ASM_WRITTEN (*tp
))
20442 /* ??? The C++ FE emits debug information for using decls, so
20443 putting gcc_unreachable here falls over. See PR31899. For now
20444 be conservative. */
20445 else if (!symtab
->global_info_ready
&& VAR_P (*tp
))
20447 else if (VAR_P (*tp
))
20449 varpool_node
*node
= varpool_node::get (*tp
);
20450 if (!node
|| !node
->definition
)
20453 else if (TREE_CODE (*tp
) == FUNCTION_DECL
20454 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
20456 /* The call graph machinery must have finished analyzing,
20457 optimizing and gimplifying the CU by now.
20458 So if *TP has no call graph node associated
20459 to it, it means *TP will not be emitted. */
20460 if (!symtab
->global_info_ready
|| !cgraph_node::get (*tp
))
20463 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
20469 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
20470 for use in a later add_const_value_attribute call. */
20473 rtl_for_decl_init (tree init
, tree type
)
20475 rtx rtl
= NULL_RTX
;
20479 /* If a variable is initialized with a string constant without embedded
20480 zeros, build CONST_STRING. */
20481 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
20483 tree enttype
= TREE_TYPE (type
);
20484 tree domain
= TYPE_DOMAIN (type
);
20485 scalar_int_mode mode
;
20487 if (is_int_mode (TYPE_MODE (enttype
), &mode
)
20488 && GET_MODE_SIZE (mode
) == 1
20490 && TYPE_MAX_VALUE (domain
)
20491 && TREE_CODE (TYPE_MAX_VALUE (domain
)) == INTEGER_CST
20492 && integer_zerop (TYPE_MIN_VALUE (domain
))
20493 && compare_tree_int (TYPE_MAX_VALUE (domain
),
20494 TREE_STRING_LENGTH (init
) - 1) == 0
20495 && ((size_t) TREE_STRING_LENGTH (init
)
20496 == strlen (TREE_STRING_POINTER (init
)) + 1))
20498 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
20499 ggc_strdup (TREE_STRING_POINTER (init
)));
20500 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
20501 MEM_READONLY_P (rtl
) = 1;
20504 /* Other aggregates, and complex values, could be represented using
20506 If this changes, please adjust tree_add_const_value_attribute
20507 so that for early_dwarf it will for such initializers mangle referenced
20509 else if (AGGREGATE_TYPE_P (type
)
20510 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
20511 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
20512 || TREE_CODE (type
) == COMPLEX_TYPE
)
20514 /* Vectors only work if their mode is supported by the target.
20515 FIXME: generic vectors ought to work too. */
20516 else if (TREE_CODE (type
) == VECTOR_TYPE
20517 && !VECTOR_MODE_P (TYPE_MODE (type
)))
20519 /* If the initializer is something that we know will expand into an
20520 immediate RTL constant, expand it now. We must be careful not to
20521 reference variables which won't be output. */
20522 else if (initializer_constant_valid_p (init
, type
)
20523 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
20525 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
20527 if (TREE_CODE (type
) == VECTOR_TYPE
)
20528 switch (TREE_CODE (init
))
20533 if (TREE_CONSTANT (init
))
20535 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
20536 bool constant_p
= true;
20538 unsigned HOST_WIDE_INT ix
;
20540 /* Even when ctor is constant, it might contain non-*_CST
20541 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
20542 belong into VECTOR_CST nodes. */
20543 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
20544 if (!CONSTANT_CLASS_P (value
))
20546 constant_p
= false;
20552 init
= build_vector_from_ctor (type
, elts
);
20562 /* Large _BitInt BLKmode INTEGER_CSTs would yield a MEM. */
20563 if (TREE_CODE (init
) == INTEGER_CST
20564 && TREE_CODE (TREE_TYPE (init
)) == BITINT_TYPE
20565 && TYPE_MODE (TREE_TYPE (init
)) == BLKmode
)
20567 if (tree_fits_shwi_p (init
))
20568 return GEN_INT (tree_to_shwi (init
));
20573 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
20575 /* If expand_expr returns a MEM, it wasn't immediate. */
20576 gcc_assert (!rtl
|| !MEM_P (rtl
));
20582 /* Generate RTL for the variable DECL to represent its location. */
20585 rtl_for_decl_location (tree decl
)
20589 /* Here we have to decide where we are going to say the parameter "lives"
20590 (as far as the debugger is concerned). We only have a couple of
20591 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
20593 DECL_RTL normally indicates where the parameter lives during most of the
20594 activation of the function. If optimization is enabled however, this
20595 could be either NULL or else a pseudo-reg. Both of those cases indicate
20596 that the parameter doesn't really live anywhere (as far as the code
20597 generation parts of GCC are concerned) during most of the function's
20598 activation. That will happen (for example) if the parameter is never
20599 referenced within the function.
20601 We could just generate a location descriptor here for all non-NULL
20602 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
20603 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
20604 where DECL_RTL is NULL or is a pseudo-reg.
20606 Note however that we can only get away with using DECL_INCOMING_RTL as
20607 a backup substitute for DECL_RTL in certain limited cases. In cases
20608 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
20609 we can be sure that the parameter was passed using the same type as it is
20610 declared to have within the function, and that its DECL_INCOMING_RTL
20611 points us to a place where a value of that type is passed.
20613 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
20614 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
20615 because in these cases DECL_INCOMING_RTL points us to a value of some
20616 type which is *different* from the type of the parameter itself. Thus,
20617 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
20618 such cases, the debugger would end up (for example) trying to fetch a
20619 `float' from a place which actually contains the first part of a
20620 `double'. That would lead to really incorrect and confusing
20621 output at debug-time.
20623 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
20624 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
20625 are a couple of exceptions however. On little-endian machines we can
20626 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
20627 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
20628 an integral type that is smaller than TREE_TYPE (decl). These cases arise
20629 when (on a little-endian machine) a non-prototyped function has a
20630 parameter declared to be of type `short' or `char'. In such cases,
20631 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
20632 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
20633 passed `int' value. If the debugger then uses that address to fetch
20634 a `short' or a `char' (on a little-endian machine) the result will be
20635 the correct data, so we allow for such exceptional cases below.
20637 Note that our goal here is to describe the place where the given formal
20638 parameter lives during most of the function's activation (i.e. between the
20639 end of the prologue and the start of the epilogue). We'll do that as best
20640 as we can. Note however that if the given formal parameter is modified
20641 sometime during the execution of the function, then a stack backtrace (at
20642 debug-time) will show the function as having been called with the *new*
20643 value rather than the value which was originally passed in. This happens
20644 rarely enough that it is not a major problem, but it *is* a problem, and
20645 I'd like to fix it.
20647 A future version of dwarf2out.cc may generate two additional attributes for
20648 any given DW_TAG_formal_parameter DIE which will describe the "passed
20649 type" and the "passed location" for the given formal parameter in addition
20650 to the attributes we now generate to indicate the "declared type" and the
20651 "active location" for each parameter. This additional set of attributes
20652 could be used by debuggers for stack backtraces. Separately, note that
20653 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
20654 This happens (for example) for inlined-instances of inline function formal
20655 parameters which are never referenced. This really shouldn't be
20656 happening. All PARM_DECL nodes should get valid non-NULL
20657 DECL_INCOMING_RTL values. FIXME. */
20659 /* Use DECL_RTL as the "location" unless we find something better. */
20660 rtl
= DECL_RTL_IF_SET (decl
);
20662 /* When generating abstract instances, ignore everything except
20663 constants, symbols living in memory, and symbols living in
20664 fixed registers. */
20665 if (! reload_completed
)
20668 && (CONSTANT_P (rtl
)
20670 && CONSTANT_P (XEXP (rtl
, 0)))
20673 && TREE_STATIC (decl
))))
20675 rtl
= targetm
.delegitimize_address (rtl
);
20680 else if (TREE_CODE (decl
) == PARM_DECL
)
20682 if (rtl
== NULL_RTX
20683 || is_pseudo_reg (rtl
)
20685 && is_pseudo_reg (XEXP (rtl
, 0))
20686 && DECL_INCOMING_RTL (decl
)
20687 && MEM_P (DECL_INCOMING_RTL (decl
))
20688 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
20690 tree declared_type
= TREE_TYPE (decl
);
20691 tree passed_type
= DECL_ARG_TYPE (decl
);
20692 machine_mode dmode
= TYPE_MODE (declared_type
);
20693 machine_mode pmode
= TYPE_MODE (passed_type
);
20695 /* This decl represents a formal parameter which was optimized out.
20696 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
20697 all cases where (rtl == NULL_RTX) just below. */
20698 if (dmode
== pmode
)
20699 rtl
= DECL_INCOMING_RTL (decl
);
20700 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
20701 && SCALAR_INT_MODE_P (dmode
)
20702 && known_le (GET_MODE_SIZE (dmode
), GET_MODE_SIZE (pmode
))
20703 && DECL_INCOMING_RTL (decl
))
20705 rtx inc
= DECL_INCOMING_RTL (decl
);
20708 else if (MEM_P (inc
))
20710 if (BYTES_BIG_ENDIAN
)
20711 rtl
= adjust_address_nv (inc
, dmode
,
20712 GET_MODE_SIZE (pmode
)
20713 - GET_MODE_SIZE (dmode
));
20720 /* If the parm was passed in registers, but lives on the stack, then
20721 make a big endian correction if the mode of the type of the
20722 parameter is not the same as the mode of the rtl. */
20723 /* ??? This is the same series of checks that are made in dbxout.cc before
20724 we reach the big endian correction code there. It isn't clear if all
20725 of these checks are necessary here, but keeping them all is the safe
20727 else if (MEM_P (rtl
)
20728 && XEXP (rtl
, 0) != const0_rtx
20729 && ! CONSTANT_P (XEXP (rtl
, 0))
20730 /* Not passed in memory. */
20731 && !MEM_P (DECL_INCOMING_RTL (decl
))
20732 /* Not passed by invisible reference. */
20733 && (!REG_P (XEXP (rtl
, 0))
20734 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
20735 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
20736 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
20737 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
20740 /* Big endian correction check. */
20741 && BYTES_BIG_ENDIAN
20742 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
20743 && known_lt (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))),
20746 machine_mode addr_mode
= get_address_mode (rtl
);
20747 poly_int64 offset
= (UNITS_PER_WORD
20748 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
20750 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
20751 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
20754 else if (VAR_P (decl
)
20757 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
)))
20759 machine_mode addr_mode
= get_address_mode (rtl
);
20760 poly_int64 offset
= byte_lowpart_offset (TYPE_MODE (TREE_TYPE (decl
)),
20763 /* If a variable is declared "register" yet is smaller than
20764 a register, then if we store the variable to memory, it
20765 looks like we're storing a register-sized value, when in
20766 fact we are not. We need to adjust the offset of the
20767 storage location to reflect the actual value's bytes,
20768 else gdb will not be able to display it. */
20769 if (maybe_ne (offset
, 0))
20770 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
20771 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
20774 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
20775 and will have been substituted directly into all expressions that use it.
20776 C does not have such a concept, but C++ and other languages do. */
20777 if (!rtl
&& VAR_P (decl
) && DECL_INITIAL (decl
))
20778 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
20781 rtl
= targetm
.delegitimize_address (rtl
);
20783 /* If we don't look past the constant pool, we risk emitting a
20784 reference to a constant pool entry that isn't referenced from
20785 code, and thus is not emitted. */
20787 rtl
= avoid_constant_pool_reference (rtl
);
20789 /* Try harder to get a rtl. If this symbol ends up not being emitted
20790 in the current CU, resolve_addr will remove the expression referencing
20792 if (rtl
== NULL_RTX
20793 && !(early_dwarf
&& (flag_generate_lto
|| flag_generate_offload
))
20795 && !DECL_EXTERNAL (decl
)
20796 && TREE_STATIC (decl
)
20797 && DECL_NAME (decl
)
20798 && !DECL_HARD_REGISTER (decl
)
20799 && DECL_MODE (decl
) != VOIDmode
)
20801 rtl
= make_decl_rtl_for_debug (decl
);
20803 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
20804 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
20811 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
20812 returned. If so, the decl for the COMMON block is returned, and the
20813 value is the offset into the common block for the symbol. */
20816 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
20818 tree val_expr
, cvar
;
20820 poly_int64 bitsize
, bitpos
;
20822 HOST_WIDE_INT cbitpos
;
20823 int unsignedp
, reversep
, volatilep
= 0;
20825 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
20826 it does not have a value (the offset into the common area), or if it
20827 is thread local (as opposed to global) then it isn't common, and shouldn't
20828 be handled as such. */
20830 || !TREE_STATIC (decl
)
20831 || !DECL_HAS_VALUE_EXPR_P (decl
)
20835 val_expr
= DECL_VALUE_EXPR (decl
);
20836 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
20839 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
20840 &unsignedp
, &reversep
, &volatilep
);
20842 if (cvar
== NULL_TREE
20844 || DECL_ARTIFICIAL (cvar
)
20845 || !TREE_PUBLIC (cvar
)
20846 /* We don't expect to have to cope with variable offsets,
20847 since at present all static data must have a constant size. */
20848 || !bitpos
.is_constant (&cbitpos
))
20852 if (offset
!= NULL
)
20854 if (!tree_fits_shwi_p (offset
))
20856 *value
= tree_to_shwi (offset
);
20859 *value
+= cbitpos
/ BITS_PER_UNIT
;
20864 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
20865 data attribute for a variable or a parameter. We generate the
20866 DW_AT_const_value attribute only in those cases where the given variable
20867 or parameter does not have a true "location" either in memory or in a
20868 register. This can happen (for example) when a constant is passed as an
20869 actual argument in a call to an inline function. (It's possible that
20870 these things can crop up in other ways also.) Note that one type of
20871 constant value which can be passed into an inlined function is a constant
20872 pointer. This can happen for example if an actual argument in an inlined
20873 function call evaluates to a compile-time constant address.
20875 CACHE_P is true if it is worth caching the location list for DECL,
20876 so that future calls can reuse it rather than regenerate it from scratch.
20877 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
20878 since we will need to refer to them each time the function is inlined. */
20881 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
20884 dw_loc_list_ref list
;
20885 var_loc_list
*loc_list
;
20886 cached_dw_loc_list
*cache
;
20891 if (TREE_CODE (decl
) == ERROR_MARK
)
20894 if (get_AT (die
, DW_AT_location
)
20895 || get_AT (die
, DW_AT_const_value
))
20898 gcc_assert (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
20899 || TREE_CODE (decl
) == RESULT_DECL
);
20901 /* Try to get some constant RTL for this decl, and use that as the value of
20904 rtl
= rtl_for_decl_location (decl
);
20905 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
20906 && add_const_value_attribute (die
, DECL_MODE (decl
), rtl
))
20909 /* See if we have single element location list that is equivalent to
20910 a constant value. That way we are better to use add_const_value_attribute
20911 rather than expanding constant value equivalent. */
20912 loc_list
= lookup_decl_loc (decl
);
20915 && loc_list
->first
->next
== NULL
20916 && NOTE_P (loc_list
->first
->loc
)
20917 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
20918 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
20920 struct var_loc_node
*node
;
20922 node
= loc_list
->first
;
20923 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
20924 if (GET_CODE (rtl
) == EXPR_LIST
)
20925 rtl
= XEXP (rtl
, 0);
20926 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
20927 && add_const_value_attribute (die
, DECL_MODE (decl
), rtl
))
20930 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
20931 list several times. See if we've already cached the contents. */
20933 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
20937 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
20939 list
= cache
->loc_list
;
20943 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
20945 /* It is usually worth caching this result if the decl is from
20946 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
20947 if (cache_p
&& list
&& list
->dw_loc_next
)
20949 cached_dw_loc_list
**slot
20950 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
20953 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
20954 cache
->decl_id
= DECL_UID (decl
);
20955 cache
->loc_list
= list
;
20961 add_AT_location_description (die
, DW_AT_location
, list
);
20964 /* None of that worked, so it must not really have a location;
20965 try adding a constant value attribute from the DECL_INITIAL. */
20966 return tree_add_const_value_attribute_for_decl (die
, decl
);
20969 /* Mangle referenced decls. */
20971 mangle_referenced_decls (tree
*tp
, int *walk_subtrees
, void *)
20973 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
20974 *walk_subtrees
= 0;
20976 if (VAR_OR_FUNCTION_DECL_P (*tp
))
20977 assign_assembler_name_if_needed (*tp
);
20982 /* Attach a DW_AT_const_value attribute to DIE. The value of the
20983 attribute is the const value T. */
20986 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
20989 tree type
= TREE_TYPE (t
);
20991 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
20995 gcc_assert (!DECL_P (init
));
20997 if (TREE_CODE (init
) == INTEGER_CST
)
20999 if (tree_fits_uhwi_p (init
))
21001 add_AT_unsigned (die
, DW_AT_const_value
, tree_to_uhwi (init
));
21004 if (tree_fits_shwi_p (init
))
21006 add_AT_int (die
, DW_AT_const_value
, tree_to_shwi (init
));
21012 rtx rtl
= rtl_for_decl_init (init
, type
);
21014 return add_const_value_attribute (die
, TYPE_MODE (type
), rtl
);
21018 /* For early_dwarf force mangling of all referenced symbols. */
21019 tree initializer
= init
;
21020 STRIP_NOPS (initializer
);
21021 /* rtl_for_decl_init punts on other aggregates, and complex values. */
21022 if (AGGREGATE_TYPE_P (type
)
21023 || (TREE_CODE (initializer
) == VIEW_CONVERT_EXPR
21024 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (initializer
, 0))))
21025 || TREE_CODE (type
) == COMPLEX_TYPE
)
21027 else if (initializer_constant_valid_p (initializer
, type
))
21028 walk_tree (&initializer
, mangle_referenced_decls
, NULL
, NULL
);
21030 /* If the host and target are sane, try harder. */
21031 if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
21032 && initializer_constant_valid_p (init
, type
))
21034 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
21035 if (size
> 0 && (int) size
== size
)
21037 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
21039 if (native_encode_initializer (init
, array
, size
) == size
)
21041 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
21050 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
21051 attribute is the const value of T, where T is an integral constant
21052 variable with static storage duration
21053 (so it can't be a PARM_DECL or a RESULT_DECL). */
21056 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
21060 || (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
21061 || (VAR_P (decl
) && !TREE_STATIC (decl
)))
21064 if (TREE_READONLY (decl
)
21065 && ! TREE_THIS_VOLATILE (decl
)
21066 && DECL_INITIAL (decl
))
21071 /* Don't add DW_AT_const_value if abstract origin already has one. */
21072 if (get_AT (var_die
, DW_AT_const_value
))
21075 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
21078 /* Convert the CFI instructions for the current function into a
21079 location list. This is used for DW_AT_frame_base when we targeting
21080 a dwarf2 consumer that does not support the dwarf3
21081 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
21084 static dw_loc_list_ref
21085 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
21089 dw_loc_list_ref list
, *list_tail
;
21091 dw_cfa_location last_cfa
, next_cfa
;
21092 const char *start_label
, *last_label
, *section
;
21093 dw_cfa_location remember
;
21096 gcc_assert (fde
!= NULL
);
21098 section
= secname_for_decl (current_function_decl
);
21102 memset (&next_cfa
, 0, sizeof (next_cfa
));
21103 next_cfa
.reg
.set_by_dwreg (INVALID_REGNUM
);
21104 remember
= next_cfa
;
21106 start_label
= fde
->dw_fde_begin
;
21108 /* ??? Bald assumption that the CIE opcode list does not contain
21109 advance opcodes. */
21110 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
21111 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
21113 last_cfa
= next_cfa
;
21114 last_label
= start_label
;
21116 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
21118 /* If the first partition contained no CFI adjustments, the
21119 CIE opcodes apply to the whole first partition. */
21120 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
21121 fde
->dw_fde_begin
, 0, fde
->dw_fde_end
, 0, section
);
21122 list_tail
=&(*list_tail
)->dw_loc_next
;
21123 start_label
= last_label
= fde
->dw_fde_second_begin
;
21126 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
21128 switch (cfi
->dw_cfi_opc
)
21130 case DW_CFA_set_loc
:
21131 case DW_CFA_advance_loc1
:
21132 case DW_CFA_advance_loc2
:
21133 case DW_CFA_advance_loc4
:
21134 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
21136 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
21137 start_label
, 0, last_label
, 0, section
);
21139 list_tail
= &(*list_tail
)->dw_loc_next
;
21140 last_cfa
= next_cfa
;
21141 start_label
= last_label
;
21143 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
21146 case DW_CFA_advance_loc
:
21147 /* The encoding is complex enough that we should never emit this. */
21148 gcc_unreachable ();
21151 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
21154 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
21156 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
21158 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
21159 start_label
, 0, last_label
, 0, section
);
21161 list_tail
= &(*list_tail
)->dw_loc_next
;
21162 last_cfa
= next_cfa
;
21163 start_label
= last_label
;
21165 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
21166 start_label
, 0, fde
->dw_fde_end
, 0, section
);
21167 list_tail
= &(*list_tail
)->dw_loc_next
;
21168 start_label
= last_label
= fde
->dw_fde_second_begin
;
21172 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
21174 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
21175 start_label
, 0, last_label
, 0, section
);
21176 list_tail
= &(*list_tail
)->dw_loc_next
;
21177 start_label
= last_label
;
21180 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
21182 fde
->dw_fde_second_begin
21183 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
, 0,
21186 maybe_gen_llsym (list
);
21191 /* Compute a displacement from the "steady-state frame pointer" to the
21192 frame base (often the same as the CFA), and store it in
21193 frame_pointer_fb_offset. OFFSET is added to the displacement
21194 before the latter is negated. */
21197 compute_frame_pointer_to_fb_displacement (poly_int64 offset
)
21201 #ifdef FRAME_POINTER_CFA_OFFSET
21202 reg
= frame_pointer_rtx
;
21203 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
21205 reg
= arg_pointer_rtx
;
21206 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
21209 elim
= (ira_use_lra_p
21210 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
21211 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
21212 elim
= strip_offset_and_add (elim
, &offset
);
21214 frame_pointer_fb_offset
= -offset
;
21216 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
21217 in which to eliminate. This is because it's stack pointer isn't
21218 directly accessible as a register within the ISA. To work around
21219 this, assume that while we cannot provide a proper value for
21220 frame_pointer_fb_offset, we won't need one either. We can use
21221 hard frame pointer in debug info even if frame pointer isn't used
21222 since hard frame pointer in debug info is encoded with DW_OP_fbreg
21223 which uses the DW_AT_frame_base attribute, not hard frame pointer
21225 frame_pointer_fb_offset_valid
21226 = (elim
== hard_frame_pointer_rtx
|| elim
== stack_pointer_rtx
);
21229 /* Generate a DW_AT_name attribute given some string value to be included as
21230 the value of the attribute. */
21233 add_name_attribute (dw_die_ref die
, const char *name_string
)
21235 if (name_string
!= NULL
&& *name_string
!= 0)
21237 if (demangle_name_func
)
21238 name_string
= (*demangle_name_func
) (name_string
);
21240 add_AT_string (die
, DW_AT_name
, name_string
);
21244 /* Generate a DW_AT_name attribute given some string value representing a
21245 file or filepath to be included as value of the attribute. */
21247 add_filename_attribute (dw_die_ref die
, const char *name_string
)
21249 if (name_string
!= NULL
&& *name_string
!= 0)
21250 add_filepath_AT_string (die
, DW_AT_name
, name_string
);
21253 /* Generate a DW_AT_description attribute given some string value to be included
21254 as the value of the attribute. */
21257 add_desc_attribute (dw_die_ref die
, const char *name_string
)
21259 if (!flag_describe_dies
|| (dwarf_version
< 3 && dwarf_strict
))
21262 if (name_string
== NULL
|| *name_string
== 0)
21265 if (demangle_name_func
)
21266 name_string
= (*demangle_name_func
) (name_string
);
21268 add_AT_string (die
, DW_AT_description
, name_string
);
21271 /* Generate a DW_AT_description attribute given some decl to be included
21272 as the value of the attribute. */
21275 add_desc_attribute (dw_die_ref die
, tree decl
)
21279 if (!flag_describe_dies
|| (dwarf_version
< 3 && dwarf_strict
))
21282 if (decl
== NULL_TREE
|| !DECL_P (decl
))
21284 decl_name
= DECL_NAME (decl
);
21286 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
21288 const char *name
= dwarf2_name (decl
, 0);
21289 add_desc_attribute (die
, name
? name
: IDENTIFIER_POINTER (decl_name
));
21293 char *desc
= print_generic_expr_to_str (decl
);
21294 add_desc_attribute (die
, desc
);
21299 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
21300 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
21301 of TYPE accordingly.
21303 ??? This is a temporary measure until after we're able to generate
21304 regular DWARF for the complex Ada type system. */
21307 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
21308 dw_die_ref context_die
)
21311 dw_die_ref dtype_die
;
21313 if (!lang_hooks
.types
.descriptive_type
)
21316 dtype
= lang_hooks
.types
.descriptive_type (type
);
21320 dtype_die
= lookup_type_die (dtype
);
21323 gen_type_die (dtype
, context_die
);
21324 dtype_die
= lookup_type_die (dtype
);
21325 gcc_assert (dtype_die
);
21328 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
21331 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
21333 static const char *
21334 comp_dir_string (void)
21337 char *wd_plus_sep
= NULL
;
21338 static const char *cached_wd
= NULL
;
21340 if (cached_wd
!= NULL
)
21343 wd
= get_src_pwd ();
21347 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
21349 size_t wdlen
= strlen (wd
);
21350 wd_plus_sep
= XNEWVEC (char, wdlen
+ 2);
21351 strcpy (wd_plus_sep
, wd
);
21352 wd_plus_sep
[wdlen
] = DIR_SEPARATOR
;
21353 wd_plus_sep
[wdlen
+ 1] = 0;
21357 cached_wd
= remap_debug_filename (wd
);
21359 /* remap_debug_filename can just pass through wd or return a new gc string.
21360 These two types can't be both stored in a GTY(())-tagged string, but since
21361 the cached value lives forever just copy it if needed. */
21362 if (cached_wd
!= wd
)
21364 cached_wd
= xstrdup (cached_wd
);
21365 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
&& wd_plus_sep
!= NULL
)
21366 free (wd_plus_sep
);
21372 /* Generate a DW_AT_comp_dir attribute for DIE. */
21375 add_comp_dir_attribute (dw_die_ref die
)
21377 const char * wd
= comp_dir_string ();
21379 add_filepath_AT_string (die
, DW_AT_comp_dir
, wd
);
21382 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
21383 pointer computation, ...), output a representation for that bound according
21384 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
21385 loc_list_from_tree for the meaning of CONTEXT. */
21388 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
21389 int forms
, struct loc_descr_context
*context
)
21391 dw_die_ref context_die
, decl_die
= NULL
;
21392 dw_loc_list_ref list
;
21393 bool strip_conversions
= true;
21394 bool placeholder_seen
= false;
21396 while (strip_conversions
)
21397 switch (TREE_CODE (value
))
21404 case VIEW_CONVERT_EXPR
:
21405 value
= TREE_OPERAND (value
, 0);
21409 strip_conversions
= false;
21413 /* If possible and permitted, output the attribute as a constant. */
21414 if ((forms
& dw_scalar_form_constant
) != 0
21415 && TREE_CODE (value
) == INTEGER_CST
)
21417 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
21419 /* If HOST_WIDE_INT is big enough then represent the bound as
21420 a constant value. We need to choose a form based on
21421 whether the type is signed or unsigned. We cannot just
21422 call add_AT_unsigned if the value itself is positive
21423 (add_AT_unsigned might add the unsigned value encoded as
21424 DW_FORM_data[1248]). Some DWARF consumers will lookup the
21425 bounds type and then sign extend any unsigned values found
21426 for signed types. This is needed only for
21427 DW_AT_{lower,upper}_bound, since for most other attributes,
21428 consumers will treat DW_FORM_data[1248] as unsigned values,
21429 regardless of the underlying type. */
21430 if (prec
<= HOST_BITS_PER_WIDE_INT
21431 || tree_fits_uhwi_p (value
))
21433 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
21434 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
21436 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
21438 else if (dwarf_version
>= 5
21439 && TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (value
))) == 128)
21440 /* Otherwise represent the bound as an unsigned value with
21441 the precision of its type. The precision and signedness
21442 of the type will be necessary to re-interpret it
21444 add_AT_wide (die
, attr
, wi::to_wide (value
));
21447 rtx v
= immed_wide_int_const (wi::to_wide (value
),
21448 TYPE_MODE (TREE_TYPE (value
)));
21449 dw_loc_descr_ref loc
21450 = loc_descriptor (v
, TYPE_MODE (TREE_TYPE (value
)),
21451 VAR_INIT_STATUS_INITIALIZED
);
21453 add_AT_loc (die
, attr
, loc
);
21458 /* Otherwise, if it's possible and permitted too, output a reference to
21460 if ((forms
& dw_scalar_form_reference
) != 0)
21462 tree decl
= NULL_TREE
;
21464 /* Some type attributes reference an outer type. For instance, the upper
21465 bound of an array may reference an embedding record (this happens in
21467 if (TREE_CODE (value
) == COMPONENT_REF
21468 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
21469 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
21470 decl
= TREE_OPERAND (value
, 1);
21472 else if (VAR_P (value
)
21473 || TREE_CODE (value
) == PARM_DECL
21474 || TREE_CODE (value
) == RESULT_DECL
)
21477 if (decl
!= NULL_TREE
)
21479 decl_die
= lookup_decl_die (decl
);
21481 /* ??? Can this happen, or should the variable have been bound
21482 first? Probably it can, since I imagine that we try to create
21483 the types of parameters in the order in which they exist in
21484 the list, and won't have created a forward reference to a
21485 later parameter. */
21486 if (decl_die
!= NULL
)
21488 if (get_AT (decl_die
, DW_AT_location
)
21489 || get_AT (decl_die
, DW_AT_data_member_location
)
21490 || get_AT (decl_die
, DW_AT_data_bit_offset
)
21491 || get_AT (decl_die
, DW_AT_const_value
))
21493 add_AT_die_ref (die
, attr
, decl_die
);
21500 /* Last chance: try to create a stack operation procedure to evaluate the
21501 value. Do nothing if even that is not possible or permitted. */
21502 if ((forms
& dw_scalar_form_exprloc
) == 0)
21505 list
= loc_list_from_tree (value
, 2, context
);
21506 if (context
&& context
->placeholder_arg
)
21508 placeholder_seen
= context
->placeholder_seen
;
21509 context
->placeholder_seen
= false;
21511 if (list
== NULL
|| single_element_loc_list_p (list
))
21513 /* If this attribute is not a reference nor constant, it is
21514 a DWARF expression rather than location description. For that
21515 loc_list_from_tree (value, 0, &context) is needed. */
21516 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
21517 if (list2
&& single_element_loc_list_p (list2
))
21519 if (placeholder_seen
)
21521 struct dwarf_procedure_info dpi
;
21522 dpi
.fndecl
= NULL_TREE
;
21523 dpi
.args_count
= 1;
21524 if (!resolve_args_picking (list2
->expr
, 1, &dpi
))
21527 add_AT_loc (die
, attr
, list2
->expr
);
21532 /* If that failed to give a single element location list, fall back to
21533 outputting this as a reference... still if permitted. */
21535 || (forms
& dw_scalar_form_reference
) == 0
21536 || placeholder_seen
)
21541 if (current_function_decl
== 0)
21542 context_die
= comp_unit_die ();
21544 context_die
= lookup_decl_die (current_function_decl
);
21546 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
21547 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
21548 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
21552 add_AT_location_description (decl_die
, DW_AT_location
, list
);
21553 add_AT_die_ref (die
, attr
, decl_die
);
21556 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
21560 lower_bound_default (void)
21562 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
21568 case DW_LANG_C_plus_plus
:
21569 case DW_LANG_C_plus_plus_11
:
21570 case DW_LANG_C_plus_plus_14
:
21572 case DW_LANG_ObjC_plus_plus
:
21574 case DW_LANG_Fortran77
:
21575 case DW_LANG_Fortran90
:
21576 case DW_LANG_Fortran95
:
21577 case DW_LANG_Fortran03
:
21578 case DW_LANG_Fortran08
:
21582 case DW_LANG_Python
:
21583 return dwarf_version
>= 4 ? 0 : -1;
21584 case DW_LANG_Ada95
:
21585 case DW_LANG_Ada83
:
21586 case DW_LANG_Cobol74
:
21587 case DW_LANG_Cobol85
:
21588 case DW_LANG_Modula2
:
21590 return dwarf_version
>= 4 ? 1 : -1;
21596 /* Given a tree node describing an array bound (either lower or upper) output
21597 a representation for that bound. */
21600 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
21601 tree bound
, struct loc_descr_context
*context
)
21606 switch (TREE_CODE (bound
))
21608 /* Strip all conversions. */
21610 case VIEW_CONVERT_EXPR
:
21611 bound
= TREE_OPERAND (bound
, 0);
21614 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
21615 are even omitted when they are the default. */
21617 /* If the value for this bound is the default one, we can even omit the
21619 if (bound_attr
== DW_AT_lower_bound
21620 && tree_fits_shwi_p (bound
)
21621 && (dflt
= lower_bound_default ()) != -1
21622 && tree_to_shwi (bound
) == dflt
)
21628 /* Let GNAT encodings do the magic for self-referential bounds. */
21630 && gnat_encodings
== DWARF_GNAT_ENCODINGS_ALL
21631 && contains_placeholder_p (bound
))
21634 add_scalar_info (subrange_die
, bound_attr
, bound
,
21635 dw_scalar_form_constant
21636 | dw_scalar_form_exprloc
21637 | dw_scalar_form_reference
,
21643 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
21644 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
21646 This function reuses previously set type and bound information if
21650 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
21652 dw_die_ref child
= type_die
->die_child
;
21653 struct array_descr_info info
;
21654 int dimension_number
;
21656 if (lang_hooks
.types
.get_array_descr_info
)
21658 memset (&info
, 0, sizeof (info
));
21659 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
21660 /* Fortran sometimes emits array types with no dimension. */
21661 gcc_assert (info
.ndimensions
>= 0
21662 && info
.ndimensions
21663 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
);
21666 info
.ndimensions
= 0;
21668 for (dimension_number
= 0;
21669 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
21670 type
= TREE_TYPE (type
), dimension_number
++)
21672 tree domain
= TYPE_DOMAIN (type
);
21674 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
21677 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
21678 and (in GNU C only) variable bounds. Handle all three forms
21681 /* Find and reuse a previously generated DW_TAG_subrange_type if
21684 For multi-dimensional arrays, as we iterate through the
21685 various dimensions in the enclosing for loop above, we also
21686 iterate through the DIE children and pick at each
21687 DW_TAG_subrange_type previously generated (if available).
21688 Each child DW_TAG_subrange_type DIE describes the range of
21689 the current dimension. At this point we should have as many
21690 DW_TAG_subrange_type's as we have dimensions in the
21692 dw_die_ref subrange_die
= NULL
;
21696 child
= child
->die_sib
;
21697 if (child
->die_tag
== DW_TAG_subrange_type
)
21698 subrange_die
= child
;
21699 if (child
== type_die
->die_child
)
21701 /* If we wrapped around, stop looking next time. */
21705 if (child
->die_tag
== DW_TAG_subrange_type
)
21709 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
21713 /* We have an array type with specified bounds. */
21714 tree lower
= TYPE_MIN_VALUE (domain
);
21715 tree upper
= TYPE_MAX_VALUE (domain
);
21716 tree index_type
= TREE_TYPE (domain
);
21718 if (dimension_number
<= info
.ndimensions
- 1)
21720 lower
= info
.dimen
[dimension_number
].lower_bound
;
21721 upper
= info
.dimen
[dimension_number
].upper_bound
;
21722 index_type
= info
.dimen
[dimension_number
].bounds_type
;
21725 /* Define the index type. */
21726 if (index_type
&& !get_AT (subrange_die
, DW_AT_type
))
21727 add_type_attribute (subrange_die
, index_type
, TYPE_UNQUALIFIED
,
21730 /* ??? If upper is NULL, the array has unspecified length,
21731 but it does have a lower bound. This happens with Fortran
21733 Since the debugger is definitely going to need to know N
21734 to produce useful results, go ahead and output the lower
21735 bound solo, and hope the debugger can cope. */
21737 if (lower
&& !get_AT (subrange_die
, DW_AT_lower_bound
))
21738 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
21740 if (!get_AT (subrange_die
, DW_AT_upper_bound
)
21741 && !get_AT (subrange_die
, DW_AT_count
))
21744 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
21745 else if ((is_c () || is_cxx ()) && COMPLETE_TYPE_P (type
))
21746 /* Zero-length array. */
21747 add_bound_info (subrange_die
, DW_AT_count
,
21748 build_int_cst (TREE_TYPE (lower
), 0), NULL
);
21752 /* Otherwise we have an array type with an unspecified length. The
21753 DWARF-2 spec does not say how to handle this; let's just leave out the
21758 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
21761 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
21763 dw_die_ref decl_die
;
21764 HOST_WIDE_INT size
;
21766 switch (TREE_CODE (tree_node
))
21771 case ENUMERAL_TYPE
:
21774 case QUAL_UNION_TYPE
:
21775 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
21776 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
21778 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
21781 size
= int_size_in_bytes (tree_node
);
21784 /* For a data member of a struct or union, the DW_AT_byte_size is
21785 generally given as the number of bytes normally allocated for an
21786 object of the *declared* type of the member itself. This is true
21787 even for bit-fields. */
21788 size
= int_size_in_bytes (field_type (tree_node
));
21791 gcc_unreachable ();
21794 /* Note that `size' might be -1 when we get to this point. If it is, that
21795 indicates that the byte size of the entity in question is variable. */
21797 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
21799 /* Support for dynamically-sized objects was introduced in DWARF3. */
21800 else if (TYPE_P (tree_node
)
21801 && (dwarf_version
>= 3 || !dwarf_strict
)
21802 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_ALL
)
21804 struct loc_descr_context ctx
= {
21805 const_cast<tree
> (tree_node
), /* context_type */
21806 NULL_TREE
, /* base_decl */
21808 false, /* placeholder_arg */
21809 false, /* placeholder_seen */
21810 false /* strict_signedness */
21813 tree tree_size
= TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (tree_node
));
21814 add_scalar_info (die
, DW_AT_byte_size
, tree_size
,
21815 dw_scalar_form_constant
21816 | dw_scalar_form_exprloc
21817 | dw_scalar_form_reference
,
21822 /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
21826 add_alignment_attribute (dw_die_ref die
, tree tree_node
)
21828 if (dwarf_version
< 5 && dwarf_strict
)
21833 if (DECL_P (tree_node
))
21835 if (!DECL_USER_ALIGN (tree_node
))
21838 align
= DECL_ALIGN_UNIT (tree_node
);
21840 else if (TYPE_P (tree_node
))
21842 if (!TYPE_USER_ALIGN (tree_node
))
21845 align
= TYPE_ALIGN_UNIT (tree_node
);
21848 gcc_unreachable ();
21850 add_AT_unsigned (die
, DW_AT_alignment
, align
);
21853 /* For a FIELD_DECL node which represents a bit-field, output an attribute
21854 which specifies the distance in bits from the highest order bit of the
21855 "containing object" for the bit-field to the highest order bit of the
21858 For any given bit-field, the "containing object" is a hypothetical object
21859 (of some integral or enum type) within which the given bit-field lives. The
21860 type of this hypothetical "containing object" is always the same as the
21861 declared type of the individual bit-field itself. The determination of the
21862 exact location of the "containing object" for a bit-field is rather
21863 complicated. It's handled by the `field_byte_offset' function (above).
21865 Note that it is the size (in bytes) of the hypothetical "containing object"
21866 which will be given in the DW_AT_byte_size attribute for this bit-field.
21867 (See `byte_size_attribute' above). */
21870 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
21872 HOST_WIDE_INT object_offset_in_bytes
;
21873 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
21874 HOST_WIDE_INT bitpos_int
;
21875 HOST_WIDE_INT highest_order_object_bit_offset
;
21876 HOST_WIDE_INT highest_order_field_bit_offset
;
21877 HOST_WIDE_INT bit_offset
;
21879 /* The containing object is within the DECL_CONTEXT. */
21880 struct vlr_context ctx
= { DECL_CONTEXT (decl
), NULL_TREE
};
21882 field_byte_offset (decl
, &ctx
, &object_offset_in_bytes
);
21884 /* Must be a field and a bit field. */
21885 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
21887 /* We can't yet handle bit-fields whose offsets are variable, so if we
21888 encounter such things, just return without generating any attribute
21889 whatsoever. Likewise for variable or too large size. */
21890 if (! tree_fits_shwi_p (bit_position (decl
))
21891 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
21894 bitpos_int
= int_bit_position (decl
);
21896 /* Note that the bit offset is always the distance (in bits) from the
21897 highest-order bit of the "containing object" to the highest-order bit of
21898 the bit-field itself. Since the "high-order end" of any object or field
21899 is different on big-endian and little-endian machines, the computation
21900 below must take account of these differences. */
21901 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
21902 highest_order_field_bit_offset
= bitpos_int
;
21904 if (! BYTES_BIG_ENDIAN
)
21906 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
21907 highest_order_object_bit_offset
+=
21908 simple_type_size_in_bits (original_type
);
21912 = (! BYTES_BIG_ENDIAN
21913 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
21914 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
21916 if (bit_offset
< 0)
21917 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
21919 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
21922 /* For a FIELD_DECL node which represents a bit field, output an attribute
21923 which specifies the length in bits of the given field. */
21926 add_bit_size_attribute (dw_die_ref die
, tree decl
)
21928 /* Must be a field and a bit field. */
21929 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
21930 && DECL_BIT_FIELD_TYPE (decl
));
21932 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
21933 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
21936 /* If the compiled language is ANSI C, then add a 'prototyped'
21937 attribute, if arg types are given for the parameters of a function. */
21940 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
21942 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
21949 if (prototype_p (func_type
))
21950 add_AT_flag (die
, DW_AT_prototyped
, 1);
21957 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
21958 by looking in the type declaration, the object declaration equate table or
21959 the block mapping. */
21962 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
21964 dw_die_ref origin_die
= NULL
;
21966 /* For late LTO debug output we want to refer directly to the abstract
21967 DIE in the early debug rather to the possibly existing concrete
21968 instance and avoid creating that just for this purpose. */
21969 sym_off_pair
*desc
;
21971 && external_die_map
21972 && (desc
= external_die_map
->get (origin
)))
21974 add_AT_external_die_ref (die
, DW_AT_abstract_origin
,
21975 desc
->sym
, desc
->off
);
21979 if (DECL_P (origin
))
21980 origin_die
= lookup_decl_die (origin
);
21981 else if (TYPE_P (origin
))
21982 origin_die
= lookup_type_die (origin
);
21983 else if (TREE_CODE (origin
) == BLOCK
)
21984 origin_die
= lookup_block_die (origin
);
21986 /* XXX: Functions that are never lowered don't always have correct block
21987 trees (in the case of java, they simply have no block tree, in some other
21988 languages). For these functions, there is nothing we can really do to
21989 output correct debug info for inlined functions in all cases. Rather
21990 than die, we'll just produce deficient debug info now, in that we will
21991 have variables without a proper abstract origin. In the future, when all
21992 functions are lowered, we should re-add a gcc_assert (origin_die)
21998 /* Like above, if we already created a concrete instance DIE
21999 do not use that for the abstract origin but the early DIE
22002 && (a
= get_AT (origin_die
, DW_AT_abstract_origin
)))
22003 origin_die
= AT_ref (a
);
22004 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
22008 /* We do not currently support the pure_virtual attribute. */
22011 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
22013 if (DECL_VINDEX (func_decl
))
22015 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
22017 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
22018 add_AT_loc (die
, DW_AT_vtable_elem_location
,
22019 new_loc_descr (DW_OP_constu
,
22020 tree_to_shwi (DECL_VINDEX (func_decl
)),
22023 /* GNU extension: Record what type this method came from originally. */
22024 if (debug_info_level
> DINFO_LEVEL_TERSE
22025 && DECL_CONTEXT (func_decl
))
22026 add_AT_die_ref (die
, DW_AT_containing_type
,
22027 lookup_type_die (DECL_CONTEXT (func_decl
)));
22031 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
22032 given decl. This used to be a vendor extension until after DWARF 4
22033 standardized it. */
22036 add_linkage_attr (dw_die_ref die
, tree decl
)
22038 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
22040 /* Mimic what assemble_name_raw does with a leading '*'. */
22041 if (name
[0] == '*')
22044 if (dwarf_version
>= 4)
22045 add_AT_string (die
, DW_AT_linkage_name
, name
);
22047 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
22050 /* Add source coordinate attributes for the given decl. */
22053 add_src_coords_attributes (dw_die_ref die
, tree decl
)
22055 expanded_location s
;
22057 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
22059 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
22060 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
22061 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
22062 if (debug_column_info
&& s
.column
)
22063 add_AT_unsigned (die
, DW_AT_decl_column
, s
.column
);
22066 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
22069 add_linkage_name_raw (dw_die_ref die
, tree decl
)
22071 /* Defer until we have an assembler name set. */
22072 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
22074 limbo_die_node
*asm_name
;
22076 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
22077 asm_name
->die
= die
;
22078 asm_name
->created_for
= decl
;
22079 asm_name
->next
= deferred_asm_name
;
22080 deferred_asm_name
= asm_name
;
22082 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
22083 add_linkage_attr (die
, decl
);
22086 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
22089 add_linkage_name (dw_die_ref die
, tree decl
)
22091 if (debug_info_level
> DINFO_LEVEL_NONE
22092 && VAR_OR_FUNCTION_DECL_P (decl
)
22093 && TREE_PUBLIC (decl
)
22094 && !(VAR_P (decl
) && DECL_REGISTER (decl
))
22095 && die
->die_tag
!= DW_TAG_member
)
22096 add_linkage_name_raw (die
, decl
);
22099 /* Add a DW_AT_name attribute and source coordinate attribute for the
22100 given decl, but only if it actually has a name. */
22103 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
,
22104 bool no_linkage_name
)
22108 decl_name
= DECL_NAME (decl
);
22109 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
22111 const char *name
= dwarf2_name (decl
, 0);
22113 add_name_attribute (die
, name
);
22115 add_desc_attribute (die
, decl
);
22117 if (! DECL_ARTIFICIAL (decl
))
22118 add_src_coords_attributes (die
, decl
);
22120 if (!no_linkage_name
)
22121 add_linkage_name (die
, decl
);
22124 add_desc_attribute (die
, decl
);
22126 #ifdef VMS_DEBUGGING_INFO
22127 /* Get the function's name, as described by its RTL. This may be different
22128 from the DECL_NAME name used in the source file. */
22129 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
22131 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
22132 XEXP (DECL_RTL (decl
), 0), false);
22133 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
22135 #endif /* VMS_DEBUGGING_INFO */
22138 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
22141 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
22145 attr
.dw_attr
= DW_AT_discr_value
;
22146 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
22147 attr
.dw_attr_val
.val_entry
= NULL
;
22148 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
22150 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
22152 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
22153 add_dwarf_attr (die
, &attr
);
22156 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
22159 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
22163 attr
.dw_attr
= DW_AT_discr_list
;
22164 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
22165 attr
.dw_attr_val
.val_entry
= NULL
;
22166 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
22167 add_dwarf_attr (die
, &attr
);
22170 static inline dw_discr_list_ref
22171 AT_discr_list (dw_attr_node
*attr
)
22173 return attr
->dw_attr_val
.v
.val_discr_list
;
22176 #ifdef VMS_DEBUGGING_INFO
22177 /* Output the debug main pointer die for VMS */
22180 dwarf2out_vms_debug_main_pointer (void)
22182 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22185 /* Allocate the VMS debug main subprogram die. */
22186 die
= new_die_raw (DW_TAG_subprogram
);
22187 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
22188 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
22189 current_function_funcdef_no
);
22190 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
22192 /* Make it the first child of comp_unit_die (). */
22193 die
->die_parent
= comp_unit_die ();
22194 if (comp_unit_die ()->die_child
)
22196 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
22197 comp_unit_die ()->die_child
->die_sib
= die
;
22201 die
->die_sib
= die
;
22202 comp_unit_die ()->die_child
= die
;
22205 #endif /* VMS_DEBUGGING_INFO */
22207 /* walk_tree helper function for uses_local_type, below. */
22210 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
22213 *walk_subtrees
= 0;
22216 tree name
= TYPE_NAME (*tp
);
22217 if (name
&& DECL_P (name
) && decl_function_context (name
))
22223 /* If TYPE involves a function-local type (including a local typedef to a
22224 non-local type), returns that type; otherwise returns NULL_TREE. */
22227 uses_local_type (tree type
)
22229 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
22233 /* Return the DIE for the scope that immediately contains this type.
22234 Non-named types that do not involve a function-local type get global
22235 scope. Named types nested in namespaces or other types get their
22236 containing scope. All other types (i.e. function-local named types) get
22237 the current active scope. */
22240 scope_die_for (tree t
, dw_die_ref context_die
)
22242 dw_die_ref scope_die
= NULL
;
22243 tree containing_scope
;
22245 /* Non-types always go in the current scope. */
22246 gcc_assert (TYPE_P (t
));
22248 /* Use the scope of the typedef, rather than the scope of the type
22250 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
22251 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
22253 containing_scope
= TYPE_CONTEXT (t
);
22255 /* Use the containing namespace if there is one. */
22256 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
22258 if (context_die
== lookup_decl_die (containing_scope
))
22260 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
22261 context_die
= get_context_die (containing_scope
);
22263 containing_scope
= NULL_TREE
;
22266 /* Ignore function type "scopes" from the C frontend. They mean that
22267 a tagged type is local to a parmlist of a function declarator, but
22268 that isn't useful to DWARF. */
22269 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
22270 containing_scope
= NULL_TREE
;
22272 if (SCOPE_FILE_SCOPE_P (containing_scope
))
22274 /* If T uses a local type keep it local as well, to avoid references
22275 to function-local DIEs from outside the function. */
22276 if (current_function_decl
&& uses_local_type (t
))
22277 scope_die
= context_die
;
22279 scope_die
= comp_unit_die ();
22281 else if (TYPE_P (containing_scope
))
22283 /* For types, we can just look up the appropriate DIE. */
22284 if (debug_info_level
> DINFO_LEVEL_TERSE
)
22285 scope_die
= get_context_die (containing_scope
);
22288 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
22289 if (scope_die
== NULL
)
22290 scope_die
= comp_unit_die ();
22294 scope_die
= context_die
;
22299 /* Returns true if CONTEXT_DIE is internal to a function. */
22302 local_scope_p (dw_die_ref context_die
)
22304 for (; context_die
; context_die
= context_die
->die_parent
)
22305 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
22306 || context_die
->die_tag
== DW_TAG_subprogram
)
22312 /* Returns true if CONTEXT_DIE is a class. */
22315 class_scope_p (dw_die_ref context_die
)
22317 return (context_die
22318 && (context_die
->die_tag
== DW_TAG_structure_type
22319 || context_die
->die_tag
== DW_TAG_class_type
22320 || context_die
->die_tag
== DW_TAG_interface_type
22321 || context_die
->die_tag
== DW_TAG_union_type
));
22324 /* Returns true if CONTEXT_DIE is a class or namespace, for deciding
22325 whether or not to treat a DIE in this context as a declaration. */
22328 class_or_namespace_scope_p (dw_die_ref context_die
)
22330 return (class_scope_p (context_die
)
22331 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
22334 /* Many forms of DIEs require a "type description" attribute. This
22335 routine locates the proper "type descriptor" die for the type given
22336 by 'type' plus any additional qualifiers given by 'cv_quals', and
22337 adds a DW_AT_type attribute below the given die. */
22340 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
22341 bool reverse
, dw_die_ref context_die
)
22343 enum tree_code code
= TREE_CODE (type
);
22344 dw_die_ref type_die
= NULL
;
22346 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
22349 /* ??? If this type is an unnamed subrange type of an integral, floating-point
22350 or fixed-point type, use the inner type. This is because we have no
22351 support for unnamed types in base_type_die. This can happen if this is
22352 an Ada subrange type. Correct solution is emit a subrange type die. */
22353 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
22354 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
22355 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
22357 if (code
== ERROR_MARK
22358 /* Handle a special case. For functions whose return type is void, we
22359 generate *no* type attribute. (Note that no object may have type
22360 `void', so this only applies to function return types). */
22361 || code
== VOID_TYPE
)
22364 type_die
= modified_type_die (type
,
22365 cv_quals
| TYPE_QUALS (type
),
22369 if (type_die
!= NULL
)
22370 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
22373 /* Given an object die, add the calling convention attribute for the
22374 function call type. */
22376 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
22378 enum dwarf_calling_convention value
= DW_CC_normal
;
22380 value
= ((enum dwarf_calling_convention
)
22381 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
22384 && id_equal (DECL_ASSEMBLER_NAME (decl
), "MAIN__"))
22386 /* DWARF 2 doesn't provide a way to identify a program's source-level
22387 entry point. DW_AT_calling_convention attributes are only meant
22388 to describe functions' calling conventions. However, lacking a
22389 better way to signal the Fortran main program, we used this for
22390 a long time, following existing custom. Now, DWARF 4 has
22391 DW_AT_main_subprogram, which we add below, but some tools still
22392 rely on the old way, which we thus keep. */
22393 value
= DW_CC_program
;
22395 if (dwarf_version
>= 4 || !dwarf_strict
)
22396 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
22399 /* Only add the attribute if the backend requests it, and
22400 is not DW_CC_normal. */
22401 if (value
&& (value
!= DW_CC_normal
))
22402 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
22405 /* Given a tree pointer to a struct, class, union, or enum type node, return
22406 a pointer to the (string) tag name for the given type, or zero if the type
22407 was declared without a tag. */
22409 static const char *
22410 type_tag (const_tree type
)
22412 const char *name
= 0;
22414 if (TYPE_NAME (type
) != 0)
22418 /* Find the IDENTIFIER_NODE for the type name. */
22419 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
22420 && !TYPE_NAMELESS (type
))
22421 t
= TYPE_NAME (type
);
22423 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
22424 a TYPE_DECL node, regardless of whether or not a `typedef' was
22426 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
22427 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
22429 /* We want to be extra verbose. Don't call dwarf_name if
22430 DECL_NAME isn't set. The default hook for decl_printable_name
22431 doesn't like that, and in this context it's correct to return
22432 0, instead of "<anonymous>" or the like. */
22433 if (DECL_NAME (TYPE_NAME (type
))
22434 && !DECL_NAMELESS (TYPE_NAME (type
)))
22435 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
22438 /* Now get the name as a string, or invent one. */
22439 if (!name
&& t
!= 0)
22440 name
= IDENTIFIER_POINTER (t
);
22443 return (name
== 0 || *name
== '\0') ? 0 : name
;
22446 /* Return the type associated with a data member, make a special check
22447 for bit field types. */
22450 member_declared_type (const_tree member
)
22452 return (DECL_BIT_FIELD_TYPE (member
)
22453 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
22456 /* Get the decl's label, as described by its RTL. This may be different
22457 from the DECL_NAME name used in the source file. */
22460 static const char *
22461 decl_start_label (tree decl
)
22464 const char *fnname
;
22466 x
= DECL_RTL (decl
);
22467 gcc_assert (MEM_P (x
));
22470 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
22472 fnname
= XSTR (x
, 0);
22477 /* For variable-length arrays that have been previously generated, but
22478 may be incomplete due to missing subscript info, fill the subscript
22479 info. Return TRUE if this is one of those cases. */
22482 fill_variable_array_bounds (tree type
)
22484 if (TREE_ASM_WRITTEN (type
)
22485 && TREE_CODE (type
) == ARRAY_TYPE
22486 && variably_modified_type_p (type
, NULL
))
22488 dw_die_ref array_die
= lookup_type_die (type
);
22491 add_subscript_info (array_die
, type
, !is_ada ());
22497 /* These routines generate the internal representation of the DIE's for
22498 the compilation unit. Debugging information is collected by walking
22499 the declaration trees passed in from dwarf2out_decl(). */
22502 gen_array_type_die (tree type
, dw_die_ref context_die
)
22504 dw_die_ref array_die
;
22506 /* GNU compilers represent multidimensional array types as sequences of one
22507 dimensional array types whose element types are themselves array types.
22508 We sometimes squish that down to a single array_type DIE with multiple
22509 subscripts in the Dwarf debugging info. The draft Dwarf specification
22510 say that we are allowed to do this kind of compression in C, because
22511 there is no difference between an array of arrays and a multidimensional
22512 array. We don't do this for Ada to remain as close as possible to the
22513 actual representation, which is especially important against the language
22514 flexibilty wrt arrays of variable size. */
22516 bool collapse_nested_arrays
= !is_ada ();
22518 if (fill_variable_array_bounds (type
))
22521 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
22524 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
22525 DW_TAG_string_type doesn't have DW_AT_type attribute). */
22526 if (TREE_CODE (type
) == ARRAY_TYPE
22527 && TYPE_STRING_FLAG (type
)
22529 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
22531 HOST_WIDE_INT size
;
22533 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
22534 add_name_attribute (array_die
, type_tag (type
));
22535 equate_type_number_to_die (type
, array_die
);
22536 size
= int_size_in_bytes (type
);
22538 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
22539 /* ??? We can't annotate types late, but for LTO we may not
22540 generate a location early either (gfortran.dg/save_6.f90). */
22541 else if (! (early_dwarf
&& (flag_generate_lto
|| flag_generate_offload
))
22542 && TYPE_DOMAIN (type
) != NULL_TREE
22543 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
22545 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
22546 tree rszdecl
= szdecl
;
22548 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
22549 if (!DECL_P (szdecl
))
22551 if (INDIRECT_REF_P (szdecl
)
22552 && DECL_P (TREE_OPERAND (szdecl
, 0)))
22554 rszdecl
= TREE_OPERAND (szdecl
, 0);
22555 if (int_size_in_bytes (TREE_TYPE (rszdecl
))
22556 != DWARF2_ADDR_SIZE
)
22564 dw_loc_list_ref loc
22565 = loc_list_from_tree (rszdecl
, szdecl
== rszdecl
? 2 : 0,
22569 add_AT_location_description (array_die
, DW_AT_string_length
,
22571 if (size
!= DWARF2_ADDR_SIZE
)
22572 add_AT_unsigned (array_die
, dwarf_version
>= 5
22573 ? DW_AT_string_length_byte_size
22574 : DW_AT_byte_size
, size
);
22581 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
22582 add_name_attribute (array_die
, type_tag (type
));
22583 equate_type_number_to_die (type
, array_die
);
22585 if (VECTOR_TYPE_P (type
))
22586 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
22588 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
22590 && TREE_CODE (type
) == ARRAY_TYPE
22591 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
22592 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
22593 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
22596 /* We default the array ordering. Debuggers will probably do the right
22597 things even if DW_AT_ordering is not present. It's not even an issue
22598 until we start to get into multidimensional arrays anyway. If a debugger
22599 is ever caught doing the Wrong Thing for multi-dimensional arrays,
22600 then we'll have to put the DW_AT_ordering attribute back in. (But if
22601 and when we find out that we need to put these in, we will only do so
22602 for multidimensional arrays. */
22603 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
22606 if (VECTOR_TYPE_P (type
))
22608 /* For VECTOR_TYPEs we use an array DIE with appropriate bounds. */
22609 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
22610 int lb
= lower_bound_default ();
22613 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_int (lb
), NULL
);
22614 add_bound_info (subrange_die
, DW_AT_upper_bound
,
22615 size_int (lb
+ TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
22618 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
22620 /* Add representation of the type of the elements of this array type and
22621 emit the corresponding DIE if we haven't done it already. */
22622 element_type
= TREE_TYPE (type
);
22623 if (collapse_nested_arrays
)
22624 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
22626 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
22628 element_type
= TREE_TYPE (element_type
);
22631 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
22632 TREE_CODE (type
) == ARRAY_TYPE
22633 && TYPE_REVERSE_STORAGE_ORDER (type
),
22636 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
22637 if (TYPE_ARTIFICIAL (type
))
22638 add_AT_flag (array_die
, DW_AT_artificial
, 1);
22640 if (get_AT (array_die
, DW_AT_name
))
22641 add_pubtype (type
, array_die
);
22643 add_alignment_attribute (array_die
, type
);
22646 /* This routine generates DIE for array with hidden descriptor, details
22647 are filled into *info by a langhook. */
22650 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
22651 dw_die_ref context_die
)
22653 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
22654 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
22655 struct loc_descr_context context
= {
22656 type
, /* context_type */
22657 info
->base_decl
, /* base_decl */
22659 false, /* placeholder_arg */
22660 false, /* placeholder_seen */
22661 false /* strict_signedness */
22663 enum dwarf_tag subrange_tag
= DW_TAG_subrange_type
;
22666 add_name_attribute (array_die
, type_tag (type
));
22667 equate_type_number_to_die (type
, array_die
);
22669 if (info
->ndimensions
> 1)
22670 switch (info
->ordering
)
22672 case array_descr_ordering_row_major
:
22673 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
22675 case array_descr_ordering_column_major
:
22676 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
22682 if (dwarf_version
>= 3 || !dwarf_strict
)
22684 if (info
->data_location
)
22685 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
22686 dw_scalar_form_exprloc
, &context
);
22687 if (info
->associated
)
22688 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
22689 dw_scalar_form_constant
22690 | dw_scalar_form_exprloc
22691 | dw_scalar_form_reference
, &context
);
22692 if (info
->allocated
)
22693 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
22694 dw_scalar_form_constant
22695 | dw_scalar_form_exprloc
22696 | dw_scalar_form_reference
, &context
);
22699 const enum dwarf_attribute attr
22700 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
22702 = (info
->stride_in_bits
)
22703 ? dw_scalar_form_constant
22704 : (dw_scalar_form_constant
22705 | dw_scalar_form_exprloc
22706 | dw_scalar_form_reference
);
22708 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
22711 if (dwarf_version
>= 5)
22715 add_scalar_info (array_die
, DW_AT_rank
, info
->rank
,
22716 dw_scalar_form_constant
22717 | dw_scalar_form_exprloc
, &context
);
22718 subrange_tag
= DW_TAG_generic_subrange
;
22719 context
.placeholder_arg
= true;
22723 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
22725 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
22727 dw_die_ref subrange_die
= new_die (subrange_tag
, array_die
, NULL
);
22729 if (info
->dimen
[dim
].bounds_type
)
22730 add_type_attribute (subrange_die
,
22731 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
22732 false, context_die
);
22733 if (info
->dimen
[dim
].lower_bound
)
22734 add_bound_info (subrange_die
, DW_AT_lower_bound
,
22735 info
->dimen
[dim
].lower_bound
, &context
);
22736 if (info
->dimen
[dim
].upper_bound
)
22737 add_bound_info (subrange_die
, DW_AT_upper_bound
,
22738 info
->dimen
[dim
].upper_bound
, &context
);
22739 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
22740 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
22741 info
->dimen
[dim
].stride
,
22742 dw_scalar_form_constant
22743 | dw_scalar_form_exprloc
22744 | dw_scalar_form_reference
,
22748 gen_type_die (info
->element_type
, context_die
);
22749 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
22750 TREE_CODE (type
) == ARRAY_TYPE
22751 && TYPE_REVERSE_STORAGE_ORDER (type
),
22754 if (get_AT (array_die
, DW_AT_name
))
22755 add_pubtype (type
, array_die
);
22757 add_alignment_attribute (array_die
, type
);
22762 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
22764 tree origin
= decl_ultimate_origin (decl
);
22765 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
22767 if (origin
!= NULL
)
22768 add_abstract_origin_attribute (decl_die
, origin
);
22771 add_name_and_src_coords_attributes (decl_die
, decl
);
22772 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
22773 TYPE_UNQUALIFIED
, false, context_die
);
22776 if (DECL_ABSTRACT_P (decl
))
22777 equate_decl_number_to_die (decl
, decl_die
);
22779 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
22783 /* Walk through the list of incomplete types again, trying once more to
22784 emit full debugging info for them. */
22787 retry_incomplete_types (void)
22792 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
22793 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
22794 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
22795 vec_safe_truncate (incomplete_types
, 0);
22798 /* Determine what tag to use for a record type. */
22800 static enum dwarf_tag
22801 record_type_tag (tree type
)
22803 if (! lang_hooks
.types
.classify_record
)
22804 return DW_TAG_structure_type
;
22806 switch (lang_hooks
.types
.classify_record (type
))
22808 case RECORD_IS_STRUCT
:
22809 return DW_TAG_structure_type
;
22811 case RECORD_IS_CLASS
:
22812 return DW_TAG_class_type
;
22814 case RECORD_IS_INTERFACE
:
22815 if (dwarf_version
>= 3 || !dwarf_strict
)
22816 return DW_TAG_interface_type
;
22817 return DW_TAG_structure_type
;
22820 gcc_unreachable ();
22824 /* Generate a DIE to represent an enumeration type. Note that these DIEs
22825 include all of the information about the enumeration values also. Each
22826 enumerated type name/value is listed as a child of the enumerated type
22830 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
22832 dw_die_ref type_die
= lookup_type_die (type
);
22833 dw_die_ref orig_type_die
= type_die
;
22835 if (type_die
== NULL
)
22837 type_die
= new_die (DW_TAG_enumeration_type
,
22838 scope_die_for (type
, context_die
), type
);
22839 equate_type_number_to_die (type
, type_die
);
22840 add_name_attribute (type_die
, type_tag (type
));
22841 if ((dwarf_version
>= 4 || !dwarf_strict
)
22842 && ENUM_IS_SCOPED (type
))
22843 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
22844 if (ENUM_IS_OPAQUE (type
) && TYPE_SIZE (type
))
22845 add_AT_flag (type_die
, DW_AT_declaration
, 1);
22847 add_AT_unsigned (type_die
, DW_AT_encoding
,
22848 TYPE_UNSIGNED (type
)
22852 else if (! TYPE_SIZE (type
) || ENUM_IS_OPAQUE (type
))
22855 remove_AT (type_die
, DW_AT_declaration
);
22857 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
22858 given enum type is incomplete, do not generate the DW_AT_byte_size
22859 attribute or the DW_AT_element_list attribute. */
22860 if (TYPE_SIZE (type
))
22864 if (!ENUM_IS_OPAQUE (type
))
22865 TREE_ASM_WRITTEN (type
) = 1;
22866 if (!orig_type_die
|| !get_AT (type_die
, DW_AT_byte_size
))
22867 add_byte_size_attribute (type_die
, type
);
22868 if (!orig_type_die
|| !get_AT (type_die
, DW_AT_alignment
))
22869 add_alignment_attribute (type_die
, type
);
22870 if ((dwarf_version
>= 3 || !dwarf_strict
)
22871 && (!orig_type_die
|| !get_AT (type_die
, DW_AT_type
)))
22873 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
22874 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
22877 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
22879 if (!orig_type_die
|| !get_AT (type_die
, DW_AT_decl_file
))
22880 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
22881 if (!orig_type_die
|| !get_AT (type_die
, DW_AT_accessibility
))
22882 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
22885 /* If the first reference to this type was as the return type of an
22886 inline function, then it may not have a parent. Fix this now. */
22887 if (type_die
->die_parent
== NULL
)
22888 add_child_die (scope_die_for (type
, context_die
), type_die
);
22890 for (link
= TYPE_VALUES (type
);
22891 link
!= NULL
; link
= TREE_CHAIN (link
))
22893 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
22894 tree value
= TREE_VALUE (link
);
22896 if (DECL_P (value
))
22897 equate_decl_number_to_die (value
, enum_die
);
22899 gcc_assert (!ENUM_IS_OPAQUE (type
));
22900 add_name_attribute (enum_die
,
22901 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
22903 if (TREE_CODE (value
) == CONST_DECL
)
22904 value
= DECL_INITIAL (value
);
22906 if (simple_type_size_in_bits (TREE_TYPE (value
))
22907 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
22909 /* For constant forms created by add_AT_unsigned DWARF
22910 consumers (GDB, elfutils, etc.) always zero extend
22911 the value. Only when the actual value is negative
22912 do we need to use add_AT_int to generate a constant
22913 form that can represent negative values. */
22914 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
22915 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
22916 add_AT_unsigned (enum_die
, DW_AT_const_value
,
22917 (unsigned HOST_WIDE_INT
) val
);
22919 add_AT_int (enum_die
, DW_AT_const_value
, val
);
22922 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
22923 that here. TODO: This should be re-worked to use correct
22924 signed/unsigned double tags for all cases. */
22925 add_AT_wide (enum_die
, DW_AT_const_value
, wi::to_wide (value
));
22928 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
22929 if (TYPE_ARTIFICIAL (type
)
22930 && (!orig_type_die
|| !get_AT (type_die
, DW_AT_artificial
)))
22931 add_AT_flag (type_die
, DW_AT_artificial
, 1);
22934 add_AT_flag (type_die
, DW_AT_declaration
, 1);
22936 add_pubtype (type
, type_die
);
22941 /* Generate a DIE to represent either a real live formal parameter decl or to
22942 represent just the type of some formal parameter position in some function
22945 Note that this routine is a bit unusual because its argument may be a
22946 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
22947 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
22948 node. If it's the former then this function is being called to output a
22949 DIE to represent a formal parameter object (or some inlining thereof). If
22950 it's the latter, then this function is only being called to output a
22951 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
22952 argument type of some subprogram type.
22953 If EMIT_NAME_P is true, name and source coordinate attributes
22957 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
22958 dw_die_ref context_die
)
22960 tree node_or_origin
= node
? node
: origin
;
22961 tree ultimate_origin
;
22962 dw_die_ref parm_die
= NULL
;
22964 if (DECL_P (node_or_origin
))
22966 parm_die
= lookup_decl_die (node
);
22968 /* If the contexts differ, we may not be talking about the same
22970 ??? When in LTO the DIE parent is the "abstract" copy and the
22971 context_die is the specification "copy". */
22973 && parm_die
->die_parent
!= context_die
22974 && (parm_die
->die_parent
->die_tag
!= DW_TAG_GNU_formal_parameter_pack
22975 || parm_die
->die_parent
->die_parent
!= context_die
)
22978 gcc_assert (!DECL_ABSTRACT_P (node
));
22979 /* This can happen when creating a concrete instance, in
22980 which case we need to create a new DIE that will get
22981 annotated with DW_AT_abstract_origin. */
22985 if (parm_die
&& parm_die
->die_parent
== NULL
)
22987 /* Check that parm_die already has the right attributes that
22988 we would have added below. If any attributes are
22989 missing, fall through to add them. */
22990 if (! DECL_ABSTRACT_P (node_or_origin
)
22991 && !get_AT (parm_die
, DW_AT_location
)
22992 && !get_AT (parm_die
, DW_AT_const_value
))
22993 /* We are missing location info, and are about to add it. */
22997 add_child_die (context_die
, parm_die
);
23003 /* If we have a previously generated DIE, use it, unless this is an
23004 concrete instance (origin != NULL), in which case we need a new
23005 DIE with a corresponding DW_AT_abstract_origin. */
23007 if (parm_die
&& origin
== NULL
)
23008 reusing_die
= true;
23011 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
23012 reusing_die
= false;
23015 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
23017 case tcc_declaration
:
23018 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
23019 if (node
|| ultimate_origin
)
23020 origin
= ultimate_origin
;
23025 if (origin
!= NULL
)
23026 add_abstract_origin_attribute (parm_die
, origin
);
23027 else if (emit_name_p
)
23028 add_name_and_src_coords_attributes (parm_die
, node
);
23030 || (! DECL_ABSTRACT_P (node_or_origin
)
23031 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
23032 decl_function_context
23033 (node_or_origin
))))
23035 tree type
= TREE_TYPE (node_or_origin
);
23036 if (decl_by_reference_p (node_or_origin
))
23037 add_type_attribute (parm_die
, TREE_TYPE (type
),
23039 false, context_die
);
23041 add_type_attribute (parm_die
, type
,
23042 decl_quals (node_or_origin
),
23043 false, context_die
);
23045 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
23046 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
23048 if (node
&& node
!= origin
)
23049 equate_decl_number_to_die (node
, parm_die
);
23050 if (! DECL_ABSTRACT_P (node_or_origin
))
23051 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
23057 /* We were called with some kind of a ..._TYPE node. */
23058 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
23063 gcc_unreachable ();
23069 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
23070 children DW_TAG_formal_parameter DIEs representing the arguments of the
23073 PARM_PACK must be a function parameter pack.
23074 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
23075 must point to the subsequent arguments of the function PACK_ARG belongs to.
23076 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
23077 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
23078 following the last one for which a DIE was generated. */
23081 gen_formal_parameter_pack_die (tree parm_pack
,
23083 dw_die_ref subr_die
,
23087 dw_die_ref parm_pack_die
;
23089 gcc_assert (parm_pack
23090 && lang_hooks
.function_parameter_pack_p (parm_pack
)
23093 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
23094 add_src_coords_attributes (parm_pack_die
, parm_pack
);
23096 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
23098 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
23101 gen_formal_parameter_die (arg
, NULL
,
23102 false /* Don't emit name attribute. */,
23107 return parm_pack_die
;
23110 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
23111 at the end of an (ANSI prototyped) formal parameters list. */
23114 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
23116 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
23119 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
23120 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
23121 parameters as specified in some function type specification (except for
23122 those which appear as part of a function *definition*). */
23125 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
23128 tree formal_type
= NULL
;
23129 tree first_parm_type
;
23132 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
23134 arg
= DECL_ARGUMENTS (function_or_method_type
);
23135 function_or_method_type
= TREE_TYPE (function_or_method_type
);
23140 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
23142 /* Make our first pass over the list of formal parameter types and output a
23143 DW_TAG_formal_parameter DIE for each one. */
23144 for (link
= first_parm_type
; link
; )
23146 dw_die_ref parm_die
;
23148 formal_type
= TREE_VALUE (link
);
23149 if (formal_type
== void_type_node
)
23152 /* Output a (nameless) DIE to represent the formal parameter itself. */
23153 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
23154 true /* Emit name attribute. */,
23156 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
23157 && link
== first_parm_type
)
23159 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
23160 if (dwarf_version
>= 3 || !dwarf_strict
)
23161 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
23163 else if (arg
&& DECL_ARTIFICIAL (arg
))
23164 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
23166 link
= TREE_CHAIN (link
);
23168 arg
= DECL_CHAIN (arg
);
23171 /* If this function type has an ellipsis, add a
23172 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
23173 if (formal_type
!= void_type_node
)
23174 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
23176 /* Make our second (and final) pass over the list of formal parameter types
23177 and output DIEs to represent those types (as necessary). */
23178 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
23179 link
&& TREE_VALUE (link
);
23180 link
= TREE_CHAIN (link
))
23181 gen_type_die (TREE_VALUE (link
), context_die
);
23184 /* We want to generate the DIE for TYPE so that we can generate the
23185 die for MEMBER, which has been defined; we will need to refer back
23186 to the member declaration nested within TYPE. If we're trying to
23187 generate minimal debug info for TYPE, processing TYPE won't do the
23188 trick; we need to attach the member declaration by hand. */
23191 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
23193 gen_type_die (type
, context_die
);
23195 /* If we're trying to avoid duplicate debug info, we may not have
23196 emitted the member decl for this function. Emit it now. */
23197 if (TYPE_STUB_DECL (type
)
23198 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
23199 && ! lookup_decl_die (member
))
23201 dw_die_ref type_die
;
23202 gcc_assert (!decl_ultimate_origin (member
));
23204 type_die
= lookup_type_die_strip_naming_typedef (type
);
23205 if (TREE_CODE (member
) == FUNCTION_DECL
)
23206 gen_subprogram_die (member
, type_die
);
23207 else if (TREE_CODE (member
) == FIELD_DECL
)
23209 /* Ignore the nameless fields that are used to skip bits but handle
23210 C++ anonymous unions and structs. */
23211 if (DECL_NAME (member
) != NULL_TREE
23212 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
23213 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
23215 struct vlr_context vlr_ctx
= {
23216 DECL_CONTEXT (member
), /* struct_type */
23217 NULL_TREE
/* variant_part_offset */
23219 gen_type_die (member_declared_type (member
), type_die
);
23220 gen_field_die (member
, &vlr_ctx
, type_die
);
23224 gen_variable_die (member
, NULL_TREE
, type_die
);
23228 /* Forward declare these functions, because they are mutually recursive
23229 with their set_block_* pairing functions. */
23230 static void set_decl_origin_self (tree
);
23232 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
23233 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
23234 that it points to the node itself, thus indicating that the node is its
23235 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
23236 the given node is NULL, recursively descend the decl/block tree which
23237 it is the root of, and for each other ..._DECL or BLOCK node contained
23238 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
23239 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
23240 values to point to themselves. */
23243 set_block_origin_self (tree stmt
)
23245 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
23247 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
23252 for (local_decl
= BLOCK_VARS (stmt
);
23253 local_decl
!= NULL_TREE
;
23254 local_decl
= DECL_CHAIN (local_decl
))
23255 /* Do not recurse on nested functions since the inlining status
23256 of parent and child can be different as per the DWARF spec. */
23257 if (TREE_CODE (local_decl
) != FUNCTION_DECL
23258 && !DECL_EXTERNAL (local_decl
))
23259 set_decl_origin_self (local_decl
);
23265 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
23266 subblock
!= NULL_TREE
;
23267 subblock
= BLOCK_CHAIN (subblock
))
23268 set_block_origin_self (subblock
); /* Recurse. */
23273 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
23274 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
23275 node to so that it points to the node itself, thus indicating that the
23276 node represents its own (abstract) origin. Additionally, if the
23277 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
23278 the decl/block tree of which the given node is the root of, and for
23279 each other ..._DECL or BLOCK node contained therein whose
23280 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
23281 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
23282 point to themselves. */
23285 set_decl_origin_self (tree decl
)
23287 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
23289 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
23290 if (TREE_CODE (decl
) == FUNCTION_DECL
)
23294 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
23295 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
23296 if (DECL_INITIAL (decl
) != NULL_TREE
23297 && DECL_INITIAL (decl
) != error_mark_node
)
23298 set_block_origin_self (DECL_INITIAL (decl
));
23303 /* Mark the early DIE for DECL as the abstract instance. */
23306 dwarf2out_abstract_function (tree decl
)
23308 dw_die_ref old_die
;
23310 /* Make sure we have the actual abstract inline, not a clone. */
23311 decl
= DECL_ORIGIN (decl
);
23313 if (DECL_IGNORED_P (decl
))
23316 /* In LTO we're all set. We already created abstract instances
23317 early and we want to avoid creating a concrete instance of that
23318 if we don't output it. */
23322 old_die
= lookup_decl_die (decl
);
23323 gcc_assert (old_die
!= NULL
);
23324 if (get_AT (old_die
, DW_AT_inline
))
23325 /* We've already generated the abstract instance. */
23328 /* Go ahead and put DW_AT_inline on the DIE. */
23329 if (DECL_DECLARED_INLINE_P (decl
))
23331 if (cgraph_function_possibly_inlined_p (decl
))
23332 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_inlined
);
23334 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
23338 if (cgraph_function_possibly_inlined_p (decl
))
23339 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_inlined
);
23341 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_not_inlined
);
23344 if (DECL_DECLARED_INLINE_P (decl
)
23345 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
23346 add_AT_flag (old_die
, DW_AT_artificial
, 1);
23348 set_decl_origin_self (decl
);
23351 /* Helper function of premark_used_types() which gets called through
23354 Marks the DIE of a given type in *SLOT as perennial, so it never gets
23355 marked as unused by prune_unused_types. */
23358 premark_used_types_helper (tree
const &type
, void *)
23362 die
= lookup_type_die (type
);
23364 die
->die_perennial_p
= 1;
23368 /* Helper function of premark_types_used_by_global_vars which gets called
23369 through htab_traverse.
23371 Marks the DIE of a given type in *SLOT as perennial, so it never gets
23372 marked as unused by prune_unused_types. The DIE of the type is marked
23373 only if the global variable using the type will actually be emitted. */
23376 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
23379 struct types_used_by_vars_entry
*entry
;
23382 entry
= (struct types_used_by_vars_entry
*) *slot
;
23383 gcc_assert (entry
->type
!= NULL
23384 && entry
->var_decl
!= NULL
);
23385 die
= lookup_type_die (entry
->type
);
23388 /* Ask cgraph if the global variable really is to be emitted.
23389 If yes, then we'll keep the DIE of ENTRY->TYPE. */
23390 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
23391 if (node
&& node
->definition
)
23393 die
->die_perennial_p
= 1;
23394 /* Keep the parent DIEs as well. */
23395 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
23396 die
->die_perennial_p
= 1;
23402 /* Mark all members of used_types_hash as perennial. */
23405 premark_used_types (struct function
*fun
)
23407 if (fun
&& fun
->used_types_hash
)
23408 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
23411 /* Mark all members of types_used_by_vars_entry as perennial. */
23414 premark_types_used_by_global_vars (void)
23416 if (types_used_by_vars_hash
)
23417 types_used_by_vars_hash
23418 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
23421 /* Mark all variables used by the symtab as perennial. */
23424 premark_used_variables (void)
23426 /* Mark DIEs in the symtab as used. */
23428 FOR_EACH_VARIABLE (var
)
23430 dw_die_ref die
= lookup_decl_die (var
->decl
);
23432 die
->die_perennial_p
= 1;
23436 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
23437 for CA_LOC call arg loc node. */
23440 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
23441 struct call_arg_loc_node
*ca_loc
)
23443 dw_die_ref stmt_die
= NULL
, die
;
23444 tree block
= ca_loc
->block
;
23447 && block
!= DECL_INITIAL (decl
)
23448 && TREE_CODE (block
) == BLOCK
)
23450 stmt_die
= lookup_block_die (block
);
23453 block
= BLOCK_SUPERCONTEXT (block
);
23455 if (stmt_die
== NULL
)
23456 stmt_die
= subr_die
;
23457 die
= new_die (dwarf_TAG (DW_TAG_call_site
), stmt_die
, NULL_TREE
);
23458 add_AT_lbl_id (die
, dwarf_AT (DW_AT_call_return_pc
), ca_loc
->label
);
23459 if (ca_loc
->tail_call_p
)
23460 add_AT_flag (die
, dwarf_AT (DW_AT_call_tail_call
), 1);
23461 if (ca_loc
->symbol_ref
)
23463 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
23465 add_AT_die_ref (die
, dwarf_AT (DW_AT_call_origin
), tdie
);
23467 add_AT_addr (die
, dwarf_AT (DW_AT_call_origin
), ca_loc
->symbol_ref
,
23473 /* Generate a DIE to represent a declared function (either file-scope or
23477 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
23479 tree origin
= decl_ultimate_origin (decl
);
23480 dw_die_ref subr_die
;
23481 dw_die_ref old_die
= lookup_decl_die (decl
);
23482 bool old_die_had_no_children
= false;
23484 /* This function gets called multiple times for different stages of
23485 the debug process. For example, for func() in this code:
23489 void func() { ... }
23492 ...we get called 4 times. Twice in early debug and twice in
23498 1. Once while generating func() within the namespace. This is
23499 the declaration. The declaration bit below is set, as the
23500 context is the namespace.
23502 A new DIE will be generated with DW_AT_declaration set.
23504 2. Once for func() itself. This is the specification. The
23505 declaration bit below is clear as the context is the CU.
23507 We will use the cached DIE from (1) to create a new DIE with
23508 DW_AT_specification pointing to the declaration in (1).
23510 Late debug via rest_of_handle_final()
23511 -------------------------------------
23513 3. Once generating func() within the namespace. This is also the
23514 declaration, as in (1), but this time we will early exit below
23515 as we have a cached DIE and a declaration needs no additional
23516 annotations (no locations), as the source declaration line
23519 4. Once for func() itself. As in (2), this is the specification,
23520 but this time we will re-use the cached DIE, and just annotate
23521 it with the location information that should now be available.
23523 For something without namespaces, but with abstract instances, we
23524 are also called a multiple times:
23529 Base (); // constructor declaration (1)
23532 Base::Base () { } // constructor specification (2)
23537 1. Once for the Base() constructor by virtue of it being a
23538 member of the Base class. This is done via
23539 rest_of_type_compilation.
23541 This is a declaration, so a new DIE will be created with
23544 2. Once for the Base() constructor definition, but this time
23545 while generating the abstract instance of the base
23546 constructor (__base_ctor) which is being generated via early
23547 debug of reachable functions.
23549 Even though we have a cached version of the declaration (1),
23550 we will create a DW_AT_specification of the declaration DIE
23553 3. Once for the __base_ctor itself, but this time, we generate
23554 an DW_AT_abstract_origin version of the DW_AT_specification in
23557 Late debug via rest_of_handle_final
23558 -----------------------------------
23560 4. One final time for the __base_ctor (which will have a cached
23561 DIE with DW_AT_abstract_origin created in (3). This time,
23562 we will just annotate the location information now
23565 int declaration
= (current_function_decl
!= decl
23566 || (!DECL_INITIAL (decl
) && !origin
)
23567 || class_or_namespace_scope_p (context_die
));
23569 /* A declaration that has been previously dumped needs no
23570 additional information. */
23571 if (old_die
&& declaration
)
23574 if (in_lto_p
&& old_die
&& old_die
->die_child
== NULL
)
23575 old_die_had_no_children
= true;
23577 /* Now that the C++ front end lazily declares artificial member fns, we
23578 might need to retrofit the declaration into its class. */
23579 if (!declaration
&& !origin
&& !old_die
23580 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
23581 && !class_or_namespace_scope_p (context_die
)
23582 && debug_info_level
> DINFO_LEVEL_TERSE
)
23583 old_die
= force_decl_die (decl
);
23585 /* A concrete instance, tag a new DIE with DW_AT_abstract_origin. */
23586 if (origin
!= NULL
)
23588 gcc_assert (!declaration
|| local_scope_p (context_die
));
23590 /* Fixup die_parent for the abstract instance of a nested
23591 inline function. */
23592 if (old_die
&& old_die
->die_parent
== NULL
)
23593 add_child_die (context_die
, old_die
);
23595 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
23597 /* If we have a DW_AT_abstract_origin we have a working
23599 subr_die
= old_die
;
23603 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
23604 add_abstract_origin_attribute (subr_die
, origin
);
23605 /* This is where the actual code for a cloned function is.
23606 Let's emit linkage name attribute for it. This helps
23607 debuggers to e.g, set breakpoints into
23608 constructors/destructors when the user asks "break
23610 add_linkage_name (subr_die
, decl
);
23613 /* A cached copy, possibly from early dwarf generation. Reuse as
23614 much as possible. */
23617 if (!get_AT_flag (old_die
, DW_AT_declaration
)
23618 /* We can have a normal definition following an inline one in the
23619 case of redefinition of GNU C extern inlines.
23620 It seems reasonable to use AT_specification in this case. */
23621 && !get_AT (old_die
, DW_AT_inline
))
23623 /* Detect and ignore this case, where we are trying to output
23624 something we have already output. */
23625 if (get_AT (old_die
, DW_AT_low_pc
)
23626 || get_AT (old_die
, DW_AT_ranges
))
23629 /* If we have no location information, this must be a
23630 partially generated DIE from early dwarf generation.
23631 Fall through and generate it. */
23634 /* If the definition comes from the same place as the declaration,
23635 maybe use the old DIE. We always want the DIE for this function
23636 that has the *_pc attributes to be under comp_unit_die so the
23637 debugger can find it. We also need to do this for abstract
23638 instances of inlines, since the spec requires the out-of-line copy
23639 to have the same parent. For local class methods, this doesn't
23640 apply; we just use the old DIE. */
23641 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
23642 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
23643 if (((is_unit_die (old_die
->die_parent
)
23644 /* This condition fixes the inconsistency/ICE with the
23645 following Fortran test (or some derivative thereof) while
23646 building libgfortran:
23650 logical function funky (FLAG)
23655 || (old_die
->die_parent
23656 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
23657 || local_scope_p (old_die
->die_parent
)
23658 || context_die
== NULL
)
23659 && (DECL_ARTIFICIAL (decl
)
23660 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
23661 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
23662 == (unsigned) s
.line
)
23663 && (!debug_column_info
23665 || (get_AT_unsigned (old_die
, DW_AT_decl_column
)
23666 == (unsigned) s
.column
)))))
23667 /* With LTO if there's an abstract instance for
23668 the old DIE, this is a concrete instance and
23669 thus re-use the DIE. */
23670 || get_AT (old_die
, DW_AT_abstract_origin
))
23672 subr_die
= old_die
;
23674 /* Clear out the declaration attribute, but leave the
23675 parameters so they can be augmented with location
23676 information later. Unless this was a declaration, in
23677 which case, wipe out the nameless parameters and recreate
23678 them further down. */
23679 if (remove_AT (subr_die
, DW_AT_declaration
))
23682 remove_AT (subr_die
, DW_AT_object_pointer
);
23683 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
23686 /* Make a specification pointing to the previously built
23690 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
23691 add_AT_specification (subr_die
, old_die
);
23692 add_pubname (decl
, subr_die
);
23693 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
23694 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
23695 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
23696 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
23697 if (debug_column_info
23699 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
23700 != (unsigned) s
.column
))
23701 add_AT_unsigned (subr_die
, DW_AT_decl_column
, s
.column
);
23703 /* If the prototype had an 'auto' or 'decltype(auto)' in
23704 the return type, emit the real type on the definition die. */
23705 if (is_cxx () && debug_info_level
> DINFO_LEVEL_TERSE
)
23707 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
23709 && (die
->die_tag
== DW_TAG_reference_type
23710 || die
->die_tag
== DW_TAG_rvalue_reference_type
23711 || die
->die_tag
== DW_TAG_pointer_type
23712 || die
->die_tag
== DW_TAG_const_type
23713 || die
->die_tag
== DW_TAG_volatile_type
23714 || die
->die_tag
== DW_TAG_restrict_type
23715 || die
->die_tag
== DW_TAG_array_type
23716 || die
->die_tag
== DW_TAG_ptr_to_member_type
23717 || die
->die_tag
== DW_TAG_subroutine_type
))
23718 die
= get_AT_ref (die
, DW_AT_type
);
23719 if (die
== auto_die
|| die
== decltype_auto_die
)
23720 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
23721 TYPE_UNQUALIFIED
, false, context_die
);
23724 /* When we process the method declaration, we haven't seen
23725 the out-of-class defaulted definition yet, so we have to
23727 if ((dwarf_version
>= 5 || ! dwarf_strict
)
23728 && !get_AT (subr_die
, DW_AT_defaulted
))
23731 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23733 if (defaulted
!= -1)
23735 /* Other values must have been handled before. */
23736 gcc_assert (defaulted
== DW_DEFAULTED_out_of_class
);
23737 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
23742 /* Create a fresh DIE for anything else. */
23745 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
23747 if (TREE_PUBLIC (decl
))
23748 add_AT_flag (subr_die
, DW_AT_external
, 1);
23750 add_name_and_src_coords_attributes (subr_die
, decl
);
23751 add_pubname (decl
, subr_die
);
23752 if (debug_info_level
> DINFO_LEVEL_TERSE
)
23754 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
23755 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
23756 TYPE_UNQUALIFIED
, false, context_die
);
23759 add_pure_or_virtual_attribute (subr_die
, decl
);
23760 if (DECL_ARTIFICIAL (decl
))
23761 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
23763 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
23764 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
23766 add_alignment_attribute (subr_die
, decl
);
23768 add_accessibility_attribute (subr_die
, decl
);
23771 /* Unless we have an existing non-declaration DIE, equate the new
23773 if (!old_die
|| is_declaration_die (old_die
))
23774 equate_decl_number_to_die (decl
, subr_die
);
23778 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
23780 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
23782 /* If this is an explicit function declaration then generate
23783 a DW_AT_explicit attribute. */
23784 if ((dwarf_version
>= 3 || !dwarf_strict
)
23785 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23786 DW_AT_explicit
) == 1)
23787 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
23789 /* If this is a C++11 deleted special function member then generate
23790 a DW_AT_deleted attribute. */
23791 if ((dwarf_version
>= 5 || !dwarf_strict
)
23792 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23793 DW_AT_deleted
) == 1)
23794 add_AT_flag (subr_die
, DW_AT_deleted
, 1);
23796 /* If this is a C++11 defaulted special function member then
23797 generate a DW_AT_defaulted attribute. */
23798 if (dwarf_version
>= 5 || !dwarf_strict
)
23801 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23803 if (defaulted
!= -1)
23804 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
23807 /* If this is a C++11 non-static member function with & ref-qualifier
23808 then generate a DW_AT_reference attribute. */
23809 if ((dwarf_version
>= 5 || !dwarf_strict
)
23810 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23811 DW_AT_reference
) == 1)
23812 add_AT_flag (subr_die
, DW_AT_reference
, 1);
23814 /* If this is a C++11 non-static member function with &&
23815 ref-qualifier then generate a DW_AT_reference attribute. */
23816 if ((dwarf_version
>= 5 || !dwarf_strict
)
23817 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23818 DW_AT_rvalue_reference
)
23820 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
23823 /* For non DECL_EXTERNALs, if range information is available, fill
23824 the DIE with it. */
23825 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
23827 HOST_WIDE_INT cfa_fb_offset
;
23829 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
23831 if (!crtl
->has_bb_partition
)
23833 dw_fde_ref fde
= fun
->fde
;
23834 if (fde
->dw_fde_begin
)
23836 /* We have already generated the labels. */
23837 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
23838 fde
->dw_fde_end
, false);
23842 /* Create start/end labels and add the range. */
23843 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
23844 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
23845 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
23846 current_function_funcdef_no
);
23847 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
23848 current_function_funcdef_no
);
23849 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
23853 #if VMS_DEBUGGING_INFO
23854 /* HP OpenVMS Industry Standard 64: DWARF Extensions
23855 Section 2.3 Prologue and Epilogue Attributes:
23856 When a breakpoint is set on entry to a function, it is generally
23857 desirable for execution to be suspended, not on the very first
23858 instruction of the function, but rather at a point after the
23859 function's frame has been set up, after any language defined local
23860 declaration processing has been completed, and before execution of
23861 the first statement of the function begins. Debuggers generally
23862 cannot properly determine where this point is. Similarly for a
23863 breakpoint set on exit from a function. The prologue and epilogue
23864 attributes allow a compiler to communicate the location(s) to use. */
23867 if (fde
->dw_fde_vms_end_prologue
)
23868 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
23869 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
23871 if (fde
->dw_fde_vms_begin_epilogue
)
23872 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
23873 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
23880 /* Generate pubnames entries for the split function code ranges. */
23881 dw_fde_ref fde
= fun
->fde
;
23883 if (fde
->dw_fde_second_begin
)
23885 if (dwarf_version
>= 3 || !dwarf_strict
)
23887 /* We should use ranges for non-contiguous code section
23888 addresses. Use the actual code range for the initial
23889 section, since the HOT/COLD labels might precede an
23890 alignment offset. */
23891 bool range_list_added
= false;
23892 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
23893 fde
->dw_fde_end
, &range_list_added
,
23895 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
23896 fde
->dw_fde_second_end
,
23897 &range_list_added
, false);
23898 if (range_list_added
)
23903 /* There is no real support in DW2 for this .. so we make
23904 a work-around. First, emit the pub name for the segment
23905 containing the function label. Then make and emit a
23906 simplified subprogram DIE for the second segment with the
23907 name pre-fixed by __hot/cold_sect_of_. We use the same
23908 linkage name for the second die so that gdb will find both
23909 sections when given "b foo". */
23910 const char *name
= NULL
;
23911 tree decl_name
= DECL_NAME (decl
);
23912 dw_die_ref seg_die
;
23914 /* Do the 'primary' section. */
23915 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
23916 fde
->dw_fde_end
, false);
23918 /* Build a minimal DIE for the secondary section. */
23919 seg_die
= new_die (DW_TAG_subprogram
,
23920 subr_die
->die_parent
, decl
);
23922 if (TREE_PUBLIC (decl
))
23923 add_AT_flag (seg_die
, DW_AT_external
, 1);
23925 if (decl_name
!= NULL
23926 && IDENTIFIER_POINTER (decl_name
) != NULL
)
23928 name
= dwarf2_name (decl
, 1);
23929 if (! DECL_ARTIFICIAL (decl
))
23930 add_src_coords_attributes (seg_die
, decl
);
23932 add_linkage_name (seg_die
, decl
);
23934 gcc_assert (name
!= NULL
);
23935 add_pure_or_virtual_attribute (seg_die
, decl
);
23936 if (DECL_ARTIFICIAL (decl
))
23937 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
23939 name
= concat ("__second_sect_of_", name
, NULL
);
23940 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
23941 fde
->dw_fde_second_end
, false);
23942 add_name_attribute (seg_die
, name
);
23943 if (want_pubnames ())
23944 add_pubname_string (name
, seg_die
);
23948 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
23952 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
23954 /* We define the "frame base" as the function's CFA. This is more
23955 convenient for several reasons: (1) It's stable across the prologue
23956 and epilogue, which makes it better than just a frame pointer,
23957 (2) With dwarf3, there exists a one-byte encoding that allows us
23958 to reference the .debug_frame data by proxy, but failing that,
23959 (3) We can at least reuse the code inspection and interpretation
23960 code that determines the CFA position at various points in the
23962 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
23964 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
23965 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
23969 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
23970 if (list
->dw_loc_next
)
23971 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
23973 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
23976 /* Compute a displacement from the "steady-state frame pointer" to
23977 the CFA. The former is what all stack slots and argument slots
23978 will reference in the rtl; the latter is what we've told the
23979 debugger about. We'll need to adjust all frame_base references
23980 by this displacement. */
23981 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
23983 if (fun
->static_chain_decl
)
23985 /* DWARF requires here a location expression that computes the
23986 address of the enclosing subprogram's frame base. The machinery
23987 in tree-nested.cc is supposed to store this specific address in the
23988 last field of the FRAME record. */
23989 const tree frame_type
23990 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
23991 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
23994 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
23995 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
23996 fb_expr
, fb_decl
, NULL_TREE
);
23998 add_AT_location_description (subr_die
, DW_AT_static_link
,
23999 loc_list_from_tree (fb_expr
, 0, NULL
));
24002 resolve_variable_values ();
24005 /* Generate child dies for template parameters. */
24006 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
24007 gen_generic_params_dies (decl
);
24009 /* Now output descriptions of the arguments for this function. This gets
24010 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
24011 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
24012 `...' at the end of the formal parameter list. In order to find out if
24013 there was a trailing ellipsis or not, we must instead look at the type
24014 associated with the FUNCTION_DECL. This will be a node of type
24015 FUNCTION_TYPE. If the chain of type nodes hanging off of this
24016 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
24017 an ellipsis at the end. */
24019 /* In the case where we are describing a mere function declaration, all we
24020 need to do here (and all we *can* do here) is to describe the *types* of
24021 its formal parameters. */
24022 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24024 else if (declaration
)
24025 gen_formal_types_die (decl
, subr_die
);
24028 /* Generate DIEs to represent all known formal parameters. */
24029 tree parm
= DECL_ARGUMENTS (decl
);
24030 tree generic_decl
= early_dwarf
24031 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
24032 tree generic_decl_parm
= generic_decl
24033 ? DECL_ARGUMENTS (generic_decl
)
24036 /* Now we want to walk the list of parameters of the function and
24037 emit their relevant DIEs.
24039 We consider the case of DECL being an instance of a generic function
24040 as well as it being a normal function.
24042 If DECL is an instance of a generic function we walk the
24043 parameters of the generic function declaration _and_ the parameters of
24044 DECL itself. This is useful because we want to emit specific DIEs for
24045 function parameter packs and those are declared as part of the
24046 generic function declaration. In that particular case,
24047 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
24048 That DIE has children DIEs representing the set of arguments
24049 of the pack. Note that the set of pack arguments can be empty.
24050 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
24053 Otherwise, we just consider the parameters of DECL. */
24054 while (generic_decl_parm
|| parm
)
24056 if (generic_decl_parm
24057 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
24058 gen_formal_parameter_pack_die (generic_decl_parm
,
24063 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
24066 && parm
== DECL_ARGUMENTS (decl
)
24067 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
24069 && (dwarf_version
>= 3 || !dwarf_strict
))
24070 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
24072 parm
= DECL_CHAIN (parm
);
24075 if (generic_decl_parm
)
24076 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
24079 /* Decide whether we need an unspecified_parameters DIE at the end.
24080 There are 2 more cases to do this for: 1) the ansi ... declaration -
24081 this is detectable when the end of the arg list is not a
24082 void_type_node 2) an unprototyped function declaration (not a
24083 definition). This just means that we have no info about the
24084 parameters at all. */
24087 if (prototype_p (TREE_TYPE (decl
)))
24089 /* This is the prototyped case, check for.... */
24090 if (stdarg_p (TREE_TYPE (decl
)))
24091 gen_unspecified_parameters_die (decl
, subr_die
);
24093 else if (DECL_INITIAL (decl
) == NULL_TREE
)
24094 gen_unspecified_parameters_die (decl
, subr_die
);
24096 else if ((subr_die
!= old_die
|| old_die_had_no_children
)
24097 && prototype_p (TREE_TYPE (decl
))
24098 && stdarg_p (TREE_TYPE (decl
)))
24099 gen_unspecified_parameters_die (decl
, subr_die
);
24102 if (subr_die
!= old_die
)
24103 /* Add the calling convention attribute if requested. */
24104 add_calling_convention_attribute (subr_die
, decl
);
24106 /* Output Dwarf info for all of the stuff within the body of the function
24107 (if it has one - it may be just a declaration).
24109 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
24110 a function. This BLOCK actually represents the outermost binding contour
24111 for the function, i.e. the contour in which the function's formal
24112 parameters and labels get declared. Curiously, it appears that the front
24113 end doesn't actually put the PARM_DECL nodes for the current function onto
24114 the BLOCK_VARS list for this outer scope, but are strung off of the
24115 DECL_ARGUMENTS list for the function instead.
24117 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
24118 the LABEL_DECL nodes for the function however, and we output DWARF info
24119 for those in decls_for_scope. Just within the `outer_scope' there will be
24120 a BLOCK node representing the function's outermost pair of curly braces,
24121 and any blocks used for the base and member initializers of a C++
24122 constructor function. */
24123 tree outer_scope
= DECL_INITIAL (decl
);
24124 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
24126 int call_site_note_count
= 0;
24127 int tail_call_site_note_count
= 0;
24129 /* Emit a DW_TAG_variable DIE for a named return value. */
24130 if (DECL_NAME (DECL_RESULT (decl
)))
24131 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
24133 /* The first time through decls_for_scope we will generate the
24134 DIEs for the locals. The second time, we fill in the
24136 decls_for_scope (outer_scope
, subr_die
);
24138 if (call_arg_locations
&& (!dwarf_strict
|| dwarf_version
>= 5))
24140 struct call_arg_loc_node
*ca_loc
;
24141 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
24143 dw_die_ref die
= NULL
;
24144 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
24146 tree arg_decl
= NULL_TREE
;
24148 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
24149 ? XEXP (ca_loc
->call_arg_loc_note
, 0)
24151 arg
; arg
= next_arg
)
24153 dw_loc_descr_ref reg
, val
;
24154 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
24155 dw_die_ref cdie
, tdie
= NULL
;
24157 next_arg
= XEXP (arg
, 1);
24158 if (REG_P (XEXP (XEXP (arg
, 0), 0))
24160 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
24161 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
24162 && REGNO (XEXP (XEXP (arg
, 0), 0))
24163 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
24164 next_arg
= XEXP (next_arg
, 1);
24165 if (mode
== VOIDmode
)
24167 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
24168 if (mode
== VOIDmode
)
24169 mode
= GET_MODE (XEXP (arg
, 0));
24171 if (mode
== VOIDmode
|| mode
== BLKmode
)
24173 /* Get dynamic information about call target only if we
24174 have no static information: we cannot generate both
24175 DW_AT_call_origin and DW_AT_call_target
24177 if (ca_loc
->symbol_ref
== NULL_RTX
)
24179 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
24181 tloc
= XEXP (XEXP (arg
, 0), 1);
24184 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
24185 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
24187 tlocc
= XEXP (XEXP (arg
, 0), 1);
24192 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
24193 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
24194 VAR_INIT_STATUS_INITIALIZED
);
24195 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
24197 rtx mem
= XEXP (XEXP (arg
, 0), 0);
24198 reg
= mem_loc_descriptor (XEXP (mem
, 0),
24199 get_address_mode (mem
),
24201 VAR_INIT_STATUS_INITIALIZED
);
24203 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
24204 == DEBUG_PARAMETER_REF
)
24207 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
24208 tdie
= lookup_decl_die (tdecl
);
24216 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
24217 != DEBUG_PARAMETER_REF
)
24219 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
24221 VAR_INIT_STATUS_INITIALIZED
);
24225 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
24226 cdie
= new_die (dwarf_TAG (DW_TAG_call_site_parameter
), die
,
24228 add_desc_attribute (cdie
, arg_decl
);
24230 add_AT_loc (cdie
, DW_AT_location
, reg
);
24231 else if (tdie
!= NULL
)
24232 add_AT_die_ref (cdie
, dwarf_AT (DW_AT_call_parameter
),
24234 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_value
), val
);
24235 if (next_arg
!= XEXP (arg
, 1))
24237 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
24238 if (mode
== VOIDmode
)
24239 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
24240 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
24243 VAR_INIT_STATUS_INITIALIZED
);
24245 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_data_value
),
24250 && (ca_loc
->symbol_ref
|| tloc
))
24251 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
24252 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
24254 dw_loc_descr_ref tval
= NULL
;
24256 if (tloc
!= NULL_RTX
)
24257 tval
= mem_loc_descriptor (tloc
,
24258 GET_MODE (tloc
) == VOIDmode
24259 ? Pmode
: GET_MODE (tloc
),
24261 VAR_INIT_STATUS_INITIALIZED
);
24263 add_AT_loc (die
, dwarf_AT (DW_AT_call_target
), tval
);
24264 else if (tlocc
!= NULL_RTX
)
24266 tval
= mem_loc_descriptor (tlocc
,
24267 GET_MODE (tlocc
) == VOIDmode
24268 ? Pmode
: GET_MODE (tlocc
),
24270 VAR_INIT_STATUS_INITIALIZED
);
24273 dwarf_AT (DW_AT_call_target_clobbered
),
24279 call_site_note_count
++;
24280 if (ca_loc
->tail_call_p
)
24281 tail_call_site_note_count
++;
24285 call_arg_locations
= NULL
;
24286 call_arg_loc_last
= NULL
;
24287 if (tail_call_site_count
>= 0
24288 && tail_call_site_count
== tail_call_site_note_count
24289 && (!dwarf_strict
|| dwarf_version
>= 5))
24291 if (call_site_count
>= 0
24292 && call_site_count
== call_site_note_count
)
24293 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_calls
), 1);
24295 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_tail_calls
), 1);
24297 call_site_count
= -1;
24298 tail_call_site_count
= -1;
24301 /* Mark used types after we have created DIEs for the functions scopes. */
24302 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
24305 /* Returns a hash value for X (which really is a die_struct). */
24308 block_die_hasher::hash (die_struct
*d
)
24310 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
24313 /* Return true if decl_id and die_parent of die_struct X is the same
24314 as decl_id and die_parent of die_struct Y. */
24317 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
24319 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
24322 /* Hold information about markers for inlined entry points. */
24323 struct GTY ((for_user
)) inline_entry_data
24325 /* The block that's the inlined_function_outer_scope for an inlined
24329 /* The label at the inlined entry point. */
24330 const char *label_pfx
;
24331 unsigned int label_num
;
24333 /* The view number to be used as the inlined entry point. */
24337 struct inline_entry_data_hasher
: ggc_ptr_hash
<inline_entry_data
>
24339 typedef tree compare_type
;
24340 static inline hashval_t
hash (const inline_entry_data
*);
24341 static inline bool equal (const inline_entry_data
*, const_tree
);
24344 /* Hash table routines for inline_entry_data. */
24347 inline_entry_data_hasher::hash (const inline_entry_data
*data
)
24349 return htab_hash_pointer (data
->block
);
24353 inline_entry_data_hasher::equal (const inline_entry_data
*data
,
24356 return data
->block
== block
;
24359 /* Inlined entry points pending DIE creation in this compilation unit. */
24361 static GTY(()) hash_table
<inline_entry_data_hasher
> *inline_entry_data_table
;
24364 /* Return TRUE if DECL, which may have been previously generated as
24365 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
24366 true if decl (or its origin) is either an extern declaration or a
24367 class/namespace scoped declaration.
24369 The declare_in_namespace support causes us to get two DIEs for one
24370 variable, both of which are declarations. We want to avoid
24371 considering one to be a specification, so we must test for
24372 DECLARATION and DW_AT_declaration. */
24374 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
24376 return (old_die
&& TREE_STATIC (decl
) && !declaration
24377 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
24380 /* Return true if DECL is a local static. */
24383 local_function_static (tree decl
)
24385 gcc_assert (VAR_P (decl
));
24386 return TREE_STATIC (decl
)
24387 && DECL_CONTEXT (decl
)
24388 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
24391 /* Return true iff DECL overrides (presumably completes) the type of
24392 OLD_DIE within CONTEXT_DIE. */
24395 override_type_for_decl_p (tree decl
, dw_die_ref old_die
,
24396 dw_die_ref context_die
)
24398 tree type
= TREE_TYPE (decl
);
24401 if (decl_by_reference_p (decl
))
24403 type
= TREE_TYPE (type
);
24404 cv_quals
= TYPE_UNQUALIFIED
;
24407 cv_quals
= decl_quals (decl
);
24409 dw_die_ref type_die
= modified_type_die (type
,
24410 cv_quals
| TYPE_QUALS (type
),
24414 dw_die_ref old_type_die
= get_AT_ref (old_die
, DW_AT_type
);
24416 return type_die
!= old_type_die
;
24419 /* Generate a DIE to represent a declared data object.
24420 Either DECL or ORIGIN must be non-null. */
24423 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
24425 HOST_WIDE_INT off
= 0;
24427 tree decl_or_origin
= decl
? decl
: origin
;
24428 tree ultimate_origin
;
24429 dw_die_ref var_die
;
24430 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
24431 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
24432 || class_or_namespace_scope_p (context_die
));
24433 bool specialization_p
= false;
24434 bool no_linkage_name
= false;
24436 /* While C++ inline static data members have definitions inside of the
24437 class, force the first DIE to be a declaration, then let gen_member_die
24438 reparent it to the class context and call gen_variable_die again
24439 to create the outside of the class DIE for the definition. */
24443 && DECL_CONTEXT (decl
)
24444 && TYPE_P (DECL_CONTEXT (decl
))
24445 && lang_hooks
.decls
.decl_dwarf_attribute (decl
, DW_AT_inline
) != -1)
24447 declaration
= true;
24448 if (dwarf_version
< 5)
24449 no_linkage_name
= true;
24452 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
24453 if (decl
|| ultimate_origin
)
24454 origin
= ultimate_origin
;
24455 com_decl
= fortran_common (decl_or_origin
, &off
);
24457 /* Symbol in common gets emitted as a child of the common block, in the form
24458 of a data member. */
24461 dw_die_ref com_die
;
24462 dw_loc_list_ref loc
= NULL
;
24463 die_node com_die_arg
;
24465 var_die
= lookup_decl_die (decl_or_origin
);
24468 if (! early_dwarf
&& get_AT (var_die
, DW_AT_location
) == NULL
)
24470 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
24475 /* Optimize the common case. */
24476 if (single_element_loc_list_p (loc
)
24477 && loc
->expr
->dw_loc_opc
== DW_OP_addr
24478 && loc
->expr
->dw_loc_next
== NULL
24479 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
24482 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
24483 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
24484 = plus_constant (GET_MODE (x
), x
, off
);
24487 loc_list_plus_const (loc
, off
);
24489 add_AT_location_description (var_die
, DW_AT_location
, loc
);
24490 remove_AT (var_die
, DW_AT_declaration
);
24496 if (common_block_die_table
== NULL
)
24497 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
24499 com_die_arg
.decl_id
= DECL_UID (com_decl
);
24500 com_die_arg
.die_parent
= context_die
;
24501 com_die
= common_block_die_table
->find (&com_die_arg
);
24503 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
24504 if (com_die
== NULL
)
24507 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
24510 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
24511 add_name_and_src_coords_attributes (com_die
, com_decl
);
24514 add_AT_location_description (com_die
, DW_AT_location
, loc
);
24515 /* Avoid sharing the same loc descriptor between
24516 DW_TAG_common_block and DW_TAG_variable. */
24517 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
24519 else if (DECL_EXTERNAL (decl_or_origin
))
24520 add_AT_flag (com_die
, DW_AT_declaration
, 1);
24521 if (want_pubnames ())
24522 add_pubname_string (cnam
, com_die
); /* ??? needed? */
24523 com_die
->decl_id
= DECL_UID (com_decl
);
24524 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
24527 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
24529 add_AT_location_description (com_die
, DW_AT_location
, loc
);
24530 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
24531 remove_AT (com_die
, DW_AT_declaration
);
24533 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
24534 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
24535 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
24536 decl_quals (decl_or_origin
), false,
24538 add_alignment_attribute (var_die
, decl
);
24539 add_AT_flag (var_die
, DW_AT_external
, 1);
24544 /* Optimize the common case. */
24545 if (single_element_loc_list_p (loc
)
24546 && loc
->expr
->dw_loc_opc
== DW_OP_addr
24547 && loc
->expr
->dw_loc_next
== NULL
24548 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
24550 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
24551 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
24552 = plus_constant (GET_MODE (x
), x
, off
);
24555 loc_list_plus_const (loc
, off
);
24557 add_AT_location_description (var_die
, DW_AT_location
, loc
);
24559 else if (DECL_EXTERNAL (decl_or_origin
))
24560 add_AT_flag (var_die
, DW_AT_declaration
, 1);
24562 equate_decl_number_to_die (decl
, var_die
);
24570 /* A declaration that has been previously dumped, needs no
24571 further annotations, since it doesn't need location on
24572 the second pass. */
24575 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
24576 && !get_AT (old_die
, DW_AT_specification
))
24578 /* Fall-thru so we can make a new variable die along with a
24579 DW_AT_specification. */
24581 else if (origin
&& old_die
->die_parent
!= context_die
)
24583 /* If we will be creating an inlined instance, we need a
24584 new DIE that will get annotated with
24585 DW_AT_abstract_origin. */
24586 gcc_assert (!DECL_ABSTRACT_P (decl
));
24590 /* If a DIE was dumped early, it still needs location info.
24591 Skip to where we fill the location bits. */
24594 /* ??? In LTRANS we cannot annotate early created variably
24595 modified type DIEs without copying them and adjusting all
24596 references to them. Thus we dumped them again. Also add a
24597 reference to them but beware of -g0 compile and -g link
24598 in which case the reference will be already present. */
24599 tree type
= TREE_TYPE (decl_or_origin
);
24601 && ! get_AT (var_die
, DW_AT_type
)
24602 && variably_modified_type_p
24603 (type
, decl_function_context (decl_or_origin
)))
24605 if (decl_by_reference_p (decl_or_origin
))
24606 add_type_attribute (var_die
, TREE_TYPE (type
),
24607 TYPE_UNQUALIFIED
, false, context_die
);
24609 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
24610 false, context_die
);
24613 goto gen_variable_die_location
;
24617 /* For static data members, the declaration in the class is supposed
24618 to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
24619 also in DWARF2; the specification should still be DW_TAG_variable
24620 referencing the DW_TAG_member DIE. */
24621 if (declaration
&& class_scope_p (context_die
) && dwarf_version
< 5)
24622 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
24624 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
24626 if (origin
!= NULL
)
24627 add_abstract_origin_attribute (var_die
, origin
);
24629 /* Loop unrolling can create multiple blocks that refer to the same
24630 static variable, so we must test for the DW_AT_declaration flag.
24632 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
24633 copy decls and set the DECL_ABSTRACT_P flag on them instead of
24636 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
24637 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
24639 /* This is a definition of a C++ class level static. */
24640 add_AT_specification (var_die
, old_die
);
24641 specialization_p
= true;
24642 if (DECL_NAME (decl
))
24644 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
24645 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
24647 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
24648 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
24650 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
24651 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
24653 if (debug_column_info
24655 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
24656 != (unsigned) s
.column
))
24657 add_AT_unsigned (var_die
, DW_AT_decl_column
, s
.column
);
24659 if (old_die
->die_tag
== DW_TAG_member
)
24660 add_linkage_name (var_die
, decl
);
24664 add_name_and_src_coords_attributes (var_die
, decl
, no_linkage_name
);
24666 if ((origin
== NULL
&& !specialization_p
)
24668 && !DECL_ABSTRACT_P (decl_or_origin
)
24669 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
24670 decl_function_context
24672 || (old_die
&& specialization_p
24673 && override_type_for_decl_p (decl_or_origin
, old_die
, context_die
)))
24675 tree type
= TREE_TYPE (decl_or_origin
);
24677 if (decl_by_reference_p (decl_or_origin
))
24678 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
24681 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
24685 if (origin
== NULL
&& !specialization_p
)
24687 if (TREE_PUBLIC (decl
))
24688 add_AT_flag (var_die
, DW_AT_external
, 1);
24690 if (DECL_ARTIFICIAL (decl
))
24691 add_AT_flag (var_die
, DW_AT_artificial
, 1);
24693 add_alignment_attribute (var_die
, decl
);
24695 add_accessibility_attribute (var_die
, decl
);
24699 add_AT_flag (var_die
, DW_AT_declaration
, 1);
24701 if (decl
&& (DECL_ABSTRACT_P (decl
)
24702 || !old_die
|| is_declaration_die (old_die
)))
24703 equate_decl_number_to_die (decl
, var_die
);
24705 gen_variable_die_location
:
24707 && (! DECL_ABSTRACT_P (decl_or_origin
)
24708 /* Local static vars are shared between all clones/inlines,
24709 so emit DW_AT_location on the abstract DIE if DECL_RTL is
24711 || (VAR_P (decl_or_origin
)
24712 && TREE_STATIC (decl_or_origin
)
24713 && DECL_RTL_SET_P (decl_or_origin
))))
24717 add_pubname (decl_or_origin
, var_die
);
24718 /* For global register variables, emit DW_AT_location if possible
24719 already during early_dwarf, as late_global_decl won't be usually
24721 if (DECL_HARD_REGISTER (decl_or_origin
)
24722 && TREE_STATIC (decl_or_origin
)
24723 && !decl_by_reference_p (decl_or_origin
)
24724 && !get_AT (var_die
, DW_AT_location
)
24725 && !get_AT (var_die
, DW_AT_const_value
)
24726 && DECL_RTL_SET_P (decl_or_origin
)
24727 && REG_P (DECL_RTL (decl_or_origin
)))
24729 dw_loc_descr_ref descr
24730 = reg_loc_descriptor (DECL_RTL (decl_or_origin
),
24731 VAR_INIT_STATUS_INITIALIZED
);
24733 add_AT_loc (var_die
, DW_AT_location
, descr
);
24737 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
24741 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
24743 if ((dwarf_version
>= 4 || !dwarf_strict
)
24744 && lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
24745 DW_AT_const_expr
) == 1
24746 && !get_AT (var_die
, DW_AT_const_expr
)
24747 && !specialization_p
)
24748 add_AT_flag (var_die
, DW_AT_const_expr
, 1);
24752 int inl
= lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
24755 && !get_AT (var_die
, DW_AT_inline
)
24756 && !specialization_p
)
24757 add_AT_unsigned (var_die
, DW_AT_inline
, inl
);
24761 /* Generate a DIE to represent a named constant. */
24764 gen_const_die (tree decl
, dw_die_ref context_die
)
24766 dw_die_ref const_die
;
24767 tree type
= TREE_TYPE (decl
);
24769 const_die
= lookup_decl_die (decl
);
24773 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
24774 equate_decl_number_to_die (decl
, const_die
);
24775 add_name_and_src_coords_attributes (const_die
, decl
);
24776 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
24777 if (TREE_PUBLIC (decl
))
24778 add_AT_flag (const_die
, DW_AT_external
, 1);
24779 if (DECL_ARTIFICIAL (decl
))
24780 add_AT_flag (const_die
, DW_AT_artificial
, 1);
24781 tree_add_const_value_attribute_for_decl (const_die
, decl
);
24784 /* Generate a DIE to represent a label identifier. */
24787 gen_label_die (tree decl
, dw_die_ref context_die
)
24789 tree origin
= decl_ultimate_origin (decl
);
24790 dw_die_ref lbl_die
= lookup_decl_die (decl
);
24792 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
24796 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
24797 equate_decl_number_to_die (decl
, lbl_die
);
24799 if (origin
!= NULL
)
24800 add_abstract_origin_attribute (lbl_die
, origin
);
24802 add_name_and_src_coords_attributes (lbl_die
, decl
);
24805 if (DECL_ABSTRACT_P (decl
))
24806 equate_decl_number_to_die (decl
, lbl_die
);
24807 else if (! early_dwarf
)
24809 insn
= DECL_RTL_IF_SET (decl
);
24811 /* Deleted labels are programmer specified labels which have been
24812 eliminated because of various optimizations. We still emit them
24813 here so that it is possible to put breakpoints on them. */
24817 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
24819 /* When optimization is enabled (via -O) some parts of the compiler
24820 (e.g. jump.cc and cse.cc) may try to delete CODE_LABEL insns which
24821 represent source-level labels which were explicitly declared by
24822 the user. This really shouldn't be happening though, so catch
24823 it if it ever does happen. */
24824 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
24826 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
24827 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
24831 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
24832 && CODE_LABEL_NUMBER (insn
) != -1)
24834 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
24835 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
24840 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
24841 attributes to the DIE for a block STMT, to describe where the inlined
24842 function was called from. This is similar to add_src_coords_attributes. */
24845 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
24847 /* We can end up with BUILTINS_LOCATION here. */
24848 if (RESERVED_LOCATION_P (BLOCK_SOURCE_LOCATION (stmt
)))
24851 location_t locus
= BLOCK_SOURCE_LOCATION (stmt
);
24852 expanded_location s
= expand_location (locus
);
24854 if (dwarf_version
>= 3 || !dwarf_strict
)
24856 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
24857 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
24858 if (debug_column_info
&& s
.column
)
24859 add_AT_unsigned (die
, DW_AT_call_column
, s
.column
);
24860 unsigned discr
= get_discriminator_from_loc (locus
);
24862 add_AT_unsigned (die
, DW_AT_GNU_discriminator
, discr
);
24867 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
24868 Add low_pc and high_pc attributes to the DIE for a block STMT. */
24871 add_high_low_attributes (tree stmt
, dw_die_ref die
)
24873 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
24875 if (inline_entry_data
**iedp
24876 = !inline_entry_data_table
? NULL
24877 : inline_entry_data_table
->find_slot_with_hash (stmt
,
24878 htab_hash_pointer (stmt
),
24881 inline_entry_data
*ied
= *iedp
;
24882 gcc_assert (MAY_HAVE_DEBUG_MARKER_INSNS
);
24883 gcc_assert (debug_inline_points
);
24884 gcc_assert (inlined_function_outer_scope_p (stmt
));
24886 ASM_GENERATE_INTERNAL_LABEL (label
, ied
->label_pfx
, ied
->label_num
);
24887 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
24889 if (debug_variable_location_views
&& !ZERO_VIEW_P (ied
->view
)
24892 if (!output_asm_line_debug_info ())
24893 add_AT_unsigned (die
, DW_AT_GNU_entry_view
, ied
->view
);
24896 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", ied
->view
);
24897 /* FIXME: this will resolve to a small number. Could we
24898 possibly emit smaller data? Ideally we'd emit a
24899 uleb128, but that would make the size of DIEs
24900 impossible for the compiler to compute, since it's
24901 the assembler that computes the value of the view
24902 label in this case. Ideally, we'd have a single form
24903 encompassing both the address and the view, and
24904 indirecting them through a table might make things
24905 easier, but even that would be more wasteful,
24906 space-wise, than what we have now. */
24907 add_AT_symview (die
, DW_AT_GNU_entry_view
, label
);
24911 inline_entry_data_table
->clear_slot (iedp
);
24914 if (BLOCK_FRAGMENT_CHAIN (stmt
)
24915 && (dwarf_version
>= 3 || !dwarf_strict
))
24917 tree chain
, superblock
= NULL_TREE
;
24919 dw_attr_node
*attr
= NULL
;
24921 if (!debug_inline_points
&& inlined_function_outer_scope_p (stmt
))
24923 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
24924 BLOCK_NUMBER (stmt
));
24925 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
24928 /* Optimize duplicate .debug_ranges lists or even tails of
24929 lists. If this BLOCK has same ranges as its supercontext,
24930 lookup DW_AT_ranges attribute in the supercontext (and
24931 recursively so), verify that the ranges_table contains the
24932 right values and use it instead of adding a new .debug_range. */
24933 for (chain
= stmt
, pdie
= die
;
24934 BLOCK_SAME_RANGE (chain
);
24935 chain
= BLOCK_SUPERCONTEXT (chain
))
24937 dw_attr_node
*new_attr
;
24939 pdie
= pdie
->die_parent
;
24942 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
24944 new_attr
= get_AT (pdie
, DW_AT_ranges
);
24945 if (new_attr
== NULL
24946 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
24949 superblock
= BLOCK_SUPERCONTEXT (chain
);
24952 && ((*ranges_table
)[attr
->dw_attr_val
.v
.val_offset
].num
24953 == (int)BLOCK_NUMBER (superblock
))
24954 && BLOCK_FRAGMENT_CHAIN (superblock
))
24956 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
;
24957 unsigned long supercnt
= 0, thiscnt
= 0;
24958 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
24959 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
24962 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
].num
24963 == (int)BLOCK_NUMBER (chain
));
24965 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
+ 1].num
== 0);
24966 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
24967 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
24969 gcc_assert (supercnt
>= thiscnt
);
24970 add_AT_range_list (die
, DW_AT_ranges
, off
+ supercnt
- thiscnt
,
24972 note_rnglist_head (off
+ supercnt
- thiscnt
);
24976 unsigned int offset
= add_ranges (stmt
, true);
24977 add_AT_range_list (die
, DW_AT_ranges
, offset
, false);
24978 note_rnglist_head (offset
);
24980 bool prev_in_cold
= BLOCK_IN_COLD_SECTION_P (stmt
);
24981 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
24984 add_ranges (chain
, prev_in_cold
!= BLOCK_IN_COLD_SECTION_P (chain
));
24985 prev_in_cold
= BLOCK_IN_COLD_SECTION_P (chain
);
24986 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
24993 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
24994 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
24995 BLOCK_NUMBER (stmt
));
24996 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
24997 BLOCK_NUMBER (stmt
));
24998 add_AT_low_high_pc (die
, label
, label_high
, false);
25002 /* Generate a DIE for a lexical block. */
25005 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
25007 dw_die_ref old_die
= lookup_block_die (stmt
);
25008 dw_die_ref stmt_die
= NULL
;
25011 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
25012 equate_block_to_die (stmt
, stmt_die
);
25015 if (BLOCK_ABSTRACT_ORIGIN (stmt
))
25017 /* If this is an inlined or conrecte instance, create a new lexical
25018 die for anything below to attach DW_AT_abstract_origin to. */
25020 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
25022 tree origin
= block_ultimate_origin (stmt
);
25023 if (origin
!= NULL_TREE
&& (origin
!= stmt
|| old_die
))
25024 add_abstract_origin_attribute (stmt_die
, origin
);
25030 stmt_die
= old_die
;
25032 /* A non abstract block whose blocks have already been reordered
25033 should have the instruction range for this block. If so, set the
25034 high/low attributes. */
25035 if (!early_dwarf
&& TREE_ASM_WRITTEN (stmt
))
25037 gcc_assert (stmt_die
);
25038 add_high_low_attributes (stmt
, stmt_die
);
25041 decls_for_scope (stmt
, stmt_die
);
25044 /* Generate a DIE for an inlined subprogram. */
25047 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
25049 tree decl
= block_ultimate_origin (stmt
);
25051 /* Make sure any inlined functions are known to be inlineable. */
25052 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
25053 || cgraph_function_possibly_inlined_p (decl
));
25055 dw_die_ref subr_die
= new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
25057 if (call_arg_locations
|| debug_inline_points
)
25058 equate_block_to_die (stmt
, subr_die
);
25059 add_abstract_origin_attribute (subr_die
, decl
);
25060 if (TREE_ASM_WRITTEN (stmt
))
25061 add_high_low_attributes (stmt
, subr_die
);
25062 add_call_src_coords_attributes (stmt
, subr_die
);
25064 /* The inliner creates an extra BLOCK for the parameter setup,
25065 we want to merge that with the actual outermost BLOCK of the
25066 inlined function to avoid duplicate locals in consumers.
25067 Do that by doing the recursion to subblocks on the single subblock
25069 bool unwrap_one
= false;
25070 if (BLOCK_SUBBLOCKS (stmt
) && !BLOCK_CHAIN (BLOCK_SUBBLOCKS (stmt
)))
25072 tree origin
= block_ultimate_origin (BLOCK_SUBBLOCKS (stmt
));
25074 && TREE_CODE (origin
) == BLOCK
25075 && BLOCK_SUPERCONTEXT (origin
) == decl
)
25078 decls_for_scope (stmt
, subr_die
, !unwrap_one
);
25080 decls_for_scope (BLOCK_SUBBLOCKS (stmt
), subr_die
);
25083 /* Generate a DIE for a field in a record, or structure. CTX is required: see
25084 the comment for VLR_CONTEXT. */
25087 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
25089 dw_die_ref decl_die
;
25091 if (TREE_TYPE (decl
) == error_mark_node
)
25094 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
25095 add_name_and_src_coords_attributes (decl_die
, decl
);
25096 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
25097 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
25100 if (DECL_BIT_FIELD_TYPE (decl
))
25102 add_byte_size_attribute (decl_die
, decl
);
25103 add_bit_size_attribute (decl_die
, decl
);
25104 add_bit_offset_attribute (decl_die
, decl
);
25107 add_alignment_attribute (decl_die
, decl
);
25109 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
25110 add_data_member_location_attribute (decl_die
, decl
, ctx
);
25112 if (DECL_ARTIFICIAL (decl
))
25113 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
25115 add_accessibility_attribute (decl_die
, decl
);
25117 /* Equate decl number to die, so that we can look up this decl later on. */
25118 equate_decl_number_to_die (decl
, decl_die
);
25121 /* Generate a DIE for a pointer to a member type. TYPE can be an
25122 OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
25123 pointer to member function. */
25126 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
25128 if (lookup_type_die (type
))
25131 dw_die_ref ptr_die
= new_die (DW_TAG_ptr_to_member_type
,
25132 scope_die_for (type
, context_die
), type
);
25134 equate_type_number_to_die (type
, ptr_die
);
25135 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
25136 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
25137 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
25139 add_alignment_attribute (ptr_die
, type
);
25141 if (TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
25142 && TREE_CODE (TREE_TYPE (type
)) != METHOD_TYPE
)
25144 dw_loc_descr_ref op
= new_loc_descr (DW_OP_plus
, 0, 0);
25145 add_AT_loc (ptr_die
, DW_AT_use_location
, op
);
25149 static char *producer_string
;
25151 /* Given a C and/or C++ language/version string return the "highest".
25152 C++ is assumed to be "higher" than C in this case. Used for merging
25153 LTO translation unit languages. */
25154 static const char *
25155 highest_c_language (const char *lang1
, const char *lang2
)
25157 if (strcmp ("GNU C++26", lang1
) == 0 || strcmp ("GNU C++26", lang2
) == 0)
25158 return "GNU C++26";
25159 if (strcmp ("GNU C++23", lang1
) == 0 || strcmp ("GNU C++23", lang2
) == 0)
25160 return "GNU C++23";
25161 if (strcmp ("GNU C++20", lang1
) == 0 || strcmp ("GNU C++20", lang2
) == 0)
25162 return "GNU C++20";
25163 if (strcmp ("GNU C++17", lang1
) == 0 || strcmp ("GNU C++17", lang2
) == 0)
25164 return "GNU C++17";
25165 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
25166 return "GNU C++14";
25167 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
25168 return "GNU C++11";
25169 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
25170 return "GNU C++98";
25172 if (strcmp ("GNU C23", lang1
) == 0 || strcmp ("GNU C23", lang2
) == 0)
25174 if (strcmp ("GNU C17", lang1
) == 0 || strcmp ("GNU C17", lang2
) == 0)
25176 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
25178 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
25180 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
25183 gcc_unreachable ();
25187 /* Generate the DIE for the compilation unit. */
25190 gen_compile_unit_die (const char *filename
)
25193 const char *language_string
= lang_hooks
.name
;
25196 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
25200 add_filename_attribute (die
, filename
);
25201 /* Don't add cwd for <built-in>. */
25202 if (filename
[0] != '<')
25203 add_comp_dir_attribute (die
);
25206 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
25208 /* If our producer is LTO try to figure out a common language to use
25209 from the global list of translation units. */
25210 if (strcmp (language_string
, "GNU GIMPLE") == 0)
25214 const char *common_lang
= NULL
;
25216 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
25218 if (!TRANSLATION_UNIT_LANGUAGE (t
))
25221 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
25222 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
25224 else if (startswith (common_lang
, "GNU C")
25225 && startswith (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C"))
25226 /* Mixing C and C++ is ok, use C++ in that case. */
25227 common_lang
= highest_c_language (common_lang
,
25228 TRANSLATION_UNIT_LANGUAGE (t
));
25231 /* Fall back to C. */
25232 common_lang
= NULL
;
25238 language_string
= common_lang
;
25241 language
= DW_LANG_C
;
25242 if (startswith (language_string
, "GNU C")
25243 && ISDIGIT (language_string
[5]))
25245 language
= DW_LANG_C89
;
25246 if (dwarf_version
>= 3 || !dwarf_strict
)
25248 if (strcmp (language_string
, "GNU C89") != 0)
25249 language
= DW_LANG_C99
;
25251 if (dwarf_version
>= 5 /* || !dwarf_strict */)
25252 if (strcmp (language_string
, "GNU C11") == 0
25253 || strcmp (language_string
, "GNU C17") == 0
25254 || strcmp (language_string
, "GNU C23") == 0)
25255 language
= DW_LANG_C11
;
25258 else if (startswith (language_string
, "GNU C++"))
25260 language
= DW_LANG_C_plus_plus
;
25261 if (dwarf_version
>= 5 /* || !dwarf_strict */)
25263 if (strcmp (language_string
, "GNU C++11") == 0)
25264 language
= DW_LANG_C_plus_plus_11
;
25265 else if (strcmp (language_string
, "GNU C++14") == 0)
25266 language
= DW_LANG_C_plus_plus_14
;
25267 else if (strcmp (language_string
, "GNU C++17") == 0
25268 || strcmp (language_string
, "GNU C++20") == 0
25269 || strcmp (language_string
, "GNU C++23") == 0
25270 || strcmp (language_string
, "GNU C++26") == 0)
25272 language
= DW_LANG_C_plus_plus_14
;
25275 else if (strcmp (language_string
, "GNU F77") == 0)
25276 language
= DW_LANG_Fortran77
;
25277 else if (strcmp (language_string
, "GNU Modula-2") == 0)
25278 language
= DW_LANG_Modula2
;
25279 else if (dwarf_version
>= 3 || !dwarf_strict
)
25281 if (strcmp (language_string
, "GNU Ada") == 0)
25282 language
= DW_LANG_Ada95
;
25283 else if (startswith (language_string
, "GNU Fortran"))
25285 language
= DW_LANG_Fortran95
;
25286 if (dwarf_version
>= 5 /* || !dwarf_strict */)
25288 if (strcmp (language_string
, "GNU Fortran2003") == 0)
25289 language
= DW_LANG_Fortran03
;
25290 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
25291 language
= DW_LANG_Fortran08
;
25294 else if (strcmp (language_string
, "GNU Objective-C") == 0)
25295 language
= DW_LANG_ObjC
;
25296 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
25297 language
= DW_LANG_ObjC_plus_plus
;
25298 else if (strcmp (language_string
, "GNU D") == 0)
25299 language
= DW_LANG_D
;
25300 else if (dwarf_version
>= 5 || !dwarf_strict
)
25302 if (strcmp (language_string
, "GNU Go") == 0)
25303 language
= DW_LANG_Go
;
25304 else if (strcmp (language_string
, "GNU Rust") == 0)
25305 language
= DW_LANG_Rust
;
25308 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
25309 else if (startswith (language_string
, "GNU Fortran"))
25310 language
= DW_LANG_Fortran90
;
25311 /* Likewise for Ada. */
25312 else if (strcmp (language_string
, "GNU Ada") == 0)
25313 language
= DW_LANG_Ada83
;
25315 add_AT_unsigned (die
, DW_AT_language
, language
);
25319 case DW_LANG_Fortran77
:
25320 case DW_LANG_Fortran90
:
25321 case DW_LANG_Fortran95
:
25322 case DW_LANG_Fortran03
:
25323 case DW_LANG_Fortran08
:
25324 /* Fortran has case insensitive identifiers and the front-end
25325 lowercases everything. */
25326 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
25329 /* The default DW_ID_case_sensitive doesn't need to be specified. */
25335 /* Generate the DIE for a base class. */
25338 gen_inheritance_die (tree binfo
, tree access
, tree type
,
25339 dw_die_ref context_die
)
25341 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
25342 struct vlr_context ctx
= { type
, NULL
};
25344 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
25346 add_data_member_location_attribute (die
, binfo
, &ctx
);
25348 if (BINFO_VIRTUAL_P (binfo
))
25349 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
25351 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
25352 children, otherwise the default is DW_ACCESS_public. In DWARF2
25353 the default has always been DW_ACCESS_private. */
25354 if (access
== access_public_node
)
25356 if (dwarf_version
== 2
25357 || context_die
->die_tag
== DW_TAG_class_type
)
25358 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
25360 else if (access
== access_protected_node
)
25361 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
25362 else if (dwarf_version
> 2
25363 && context_die
->die_tag
!= DW_TAG_class_type
)
25364 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
25367 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
25371 is_variant_part (tree decl
)
25373 return (TREE_CODE (decl
) == FIELD_DECL
25374 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
25377 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
25378 return the FIELD_DECL. Return NULL_TREE otherwise. */
25381 analyze_discr_in_predicate (tree operand
, tree struct_type
)
25383 while (CONVERT_EXPR_P (operand
))
25384 operand
= TREE_OPERAND (operand
, 0);
25386 /* Match field access to members of struct_type only. */
25387 if (TREE_CODE (operand
) == COMPONENT_REF
25388 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
25389 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
25390 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
25391 return TREE_OPERAND (operand
, 1);
25396 /* Check that SRC is a constant integer that can be represented as a native
25397 integer constant (either signed or unsigned). If so, store it into DEST and
25398 return true. Return false otherwise. */
25401 get_discr_value (tree src
, dw_discr_value
*dest
)
25403 tree discr_type
= TREE_TYPE (src
);
25405 if (lang_hooks
.types
.get_debug_type
)
25407 tree debug_type
= lang_hooks
.types
.get_debug_type (discr_type
);
25408 if (debug_type
!= NULL
)
25409 discr_type
= debug_type
;
25412 if (TREE_CODE (src
) != INTEGER_CST
|| !INTEGRAL_TYPE_P (discr_type
))
25415 /* Signedness can vary between the original type and the debug type. This
25416 can happen for character types in Ada for instance: the character type
25417 used for code generation can be signed, to be compatible with the C one,
25418 but from a debugger point of view, it must be unsigned. */
25419 bool is_orig_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
25420 bool is_debug_unsigned
= TYPE_UNSIGNED (discr_type
);
25422 if (is_orig_unsigned
!= is_debug_unsigned
)
25423 src
= fold_convert (discr_type
, src
);
25425 if (!(is_debug_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
25428 dest
->pos
= is_debug_unsigned
;
25429 if (is_debug_unsigned
)
25430 dest
->v
.uval
= tree_to_uhwi (src
);
25432 dest
->v
.sval
= tree_to_shwi (src
);
25437 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
25438 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
25439 store NULL_TREE in DISCR_DECL. Otherwise:
25441 - store the discriminant field in STRUCT_TYPE that controls the variant
25442 part to *DISCR_DECL
25444 - put in *DISCR_LISTS_P an array where for each variant, the item
25445 represents the corresponding matching list of discriminant values.
25447 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
25450 Note that when the array is allocated (i.e. when the analysis is
25451 successful), it is up to the caller to free the array. */
25454 analyze_variants_discr (tree variant_part_decl
,
25457 dw_discr_list_ref
**discr_lists_p
,
25458 unsigned *discr_lists_length
)
25460 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
25462 dw_discr_list_ref
*discr_lists
;
25465 /* Compute how many variants there are in this variant part. */
25466 *discr_lists_length
= 0;
25467 for (variant
= TYPE_FIELDS (variant_part_type
);
25468 variant
!= NULL_TREE
;
25469 variant
= DECL_CHAIN (variant
))
25470 ++*discr_lists_length
;
25472 *discr_decl
= NULL_TREE
;
25474 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
25475 sizeof (**discr_lists_p
));
25476 discr_lists
= *discr_lists_p
;
25478 /* And then analyze all variants to extract discriminant information for all
25479 of them. This analysis is conservative: as soon as we detect something we
25480 do not support, abort everything and pretend we found nothing. */
25481 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
25482 variant
!= NULL_TREE
;
25483 variant
= DECL_CHAIN (variant
), ++i
)
25485 tree match_expr
= DECL_QUALIFIER (variant
);
25487 /* Now, try to analyze the predicate and deduce a discriminant for
25489 if (match_expr
== boolean_true_node
)
25490 /* Typically happens for the default variant: it matches all cases that
25491 previous variants rejected. Don't output any matching value for
25495 /* The following loop tries to iterate over each discriminant
25496 possibility: single values or ranges. */
25497 while (match_expr
!= NULL_TREE
)
25499 tree next_round_match_expr
;
25500 tree candidate_discr
= NULL_TREE
;
25501 dw_discr_list_ref new_node
= NULL
;
25503 /* Possibilities are matched one after the other by nested
25504 TRUTH_ORIF_EXPR expressions. Process the current possibility and
25505 continue with the rest at next iteration. */
25506 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
25508 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
25509 match_expr
= TREE_OPERAND (match_expr
, 1);
25512 next_round_match_expr
= NULL_TREE
;
25514 if (match_expr
== boolean_false_node
)
25515 /* This sub-expression matches nothing: just wait for the next
25519 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
25521 /* We are matching: <discr_field> == <integer_cst>
25522 This sub-expression matches a single value. */
25523 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
25526 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
25529 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
25530 if (!get_discr_value (integer_cst
,
25531 &new_node
->dw_discr_lower_bound
))
25533 new_node
->dw_discr_range
= false;
25536 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
25538 /* We are matching:
25539 <discr_field> > <integer_cst>
25540 && <discr_field> < <integer_cst>.
25541 This sub-expression matches the range of values between the
25542 two matched integer constants. Note that comparisons can be
25543 inclusive or exclusive. */
25544 tree candidate_discr_1
, candidate_discr_2
;
25545 tree lower_cst
, upper_cst
;
25546 bool lower_cst_included
, upper_cst_included
;
25547 tree lower_op
= TREE_OPERAND (match_expr
, 0);
25548 tree upper_op
= TREE_OPERAND (match_expr
, 1);
25550 /* When the comparison is exclusive, the integer constant is not
25551 the discriminant range bound we are looking for: we will have
25552 to increment or decrement it. */
25553 if (TREE_CODE (lower_op
) == GE_EXPR
)
25554 lower_cst_included
= true;
25555 else if (TREE_CODE (lower_op
) == GT_EXPR
)
25556 lower_cst_included
= false;
25560 if (TREE_CODE (upper_op
) == LE_EXPR
)
25561 upper_cst_included
= true;
25562 else if (TREE_CODE (upper_op
) == LT_EXPR
)
25563 upper_cst_included
= false;
25567 /* Extract the discriminant from the first operand and check it
25568 is consistant with the same analysis in the second
25571 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
25574 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
25576 if (candidate_discr_1
== candidate_discr_2
)
25577 candidate_discr
= candidate_discr_1
;
25581 /* Extract bounds from both. */
25582 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
25583 lower_cst
= TREE_OPERAND (lower_op
, 1);
25584 upper_cst
= TREE_OPERAND (upper_op
, 1);
25586 if (!lower_cst_included
)
25588 = fold_build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
), lower_cst
,
25589 build_int_cst (TREE_TYPE (lower_cst
), 1));
25590 if (!upper_cst_included
)
25592 = fold_build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
), upper_cst
,
25593 build_int_cst (TREE_TYPE (upper_cst
), 1));
25595 if (!get_discr_value (lower_cst
,
25596 &new_node
->dw_discr_lower_bound
)
25597 || !get_discr_value (upper_cst
,
25598 &new_node
->dw_discr_upper_bound
))
25601 new_node
->dw_discr_range
= true;
25604 else if ((candidate_discr
25605 = analyze_discr_in_predicate (match_expr
, struct_type
))
25606 && (TREE_TYPE (candidate_discr
) == boolean_type_node
25607 || TREE_TYPE (TREE_TYPE (candidate_discr
))
25608 == boolean_type_node
))
25610 /* We are matching: <discr_field> for a boolean discriminant.
25611 This sub-expression matches boolean_true_node. */
25612 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
25613 if (!get_discr_value (boolean_true_node
,
25614 &new_node
->dw_discr_lower_bound
))
25616 new_node
->dw_discr_range
= false;
25620 /* Unsupported sub-expression: we cannot determine the set of
25621 matching discriminant values. Abort everything. */
25624 /* If the discriminant info is not consistant with what we saw so
25625 far, consider the analysis failed and abort everything. */
25626 if (candidate_discr
== NULL_TREE
25627 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
25630 *discr_decl
= candidate_discr
;
25632 if (new_node
!= NULL
)
25634 new_node
->dw_discr_next
= discr_lists
[i
];
25635 discr_lists
[i
] = new_node
;
25637 match_expr
= next_round_match_expr
;
25641 /* If we reach this point, we could match everything we were interested
25646 /* Clean all data structure and return no result. */
25647 free (*discr_lists_p
);
25648 *discr_lists_p
= NULL
;
25649 *discr_decl
= NULL_TREE
;
25652 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
25653 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
25656 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
25657 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
25658 this type, which are record types, represent the available variants and each
25659 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
25660 values are inferred from these attributes.
25662 In trees, the offsets for the fields inside these sub-records are relative
25663 to the variant part itself, whereas the corresponding DIEs should have
25664 offset attributes that are relative to the embedding record base address.
25665 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
25666 must be an expression that computes the offset of the variant part to
25667 describe in DWARF. */
25670 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
25671 dw_die_ref context_die
)
25673 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
25674 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
25676 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
25677 NULL_TREE if there is no such field. */
25678 tree discr_decl
= NULL_TREE
;
25679 dw_discr_list_ref
*discr_lists
;
25680 unsigned discr_lists_length
= 0;
25683 dw_die_ref dwarf_proc_die
= NULL
;
25684 dw_die_ref variant_part_die
25685 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
25687 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
25689 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
25690 &discr_decl
, &discr_lists
, &discr_lists_length
);
25692 if (discr_decl
!= NULL_TREE
)
25694 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
25697 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
25699 /* We have no DIE for the discriminant, so just discard all
25700 discrimimant information in the output. */
25701 discr_decl
= NULL_TREE
;
25704 /* If the offset for this variant part is more complex than a constant,
25705 create a DWARF procedure for it so that we will not have to generate
25706 DWARF expressions for it for each member. */
25707 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
25708 && (dwarf_version
>= 3 || !dwarf_strict
))
25710 struct loc_descr_context ctx
= {
25711 vlr_ctx
->struct_type
, /* context_type */
25712 NULL_TREE
, /* base_decl */
25714 false, /* placeholder_arg */
25715 false, /* placeholder_seen */
25716 false /* strict_signedness */
25718 const tree dwarf_proc_fndecl
25719 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
25720 build_function_type (TREE_TYPE (variant_part_offset
),
25722 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
25723 const dw_loc_descr_ref dwarf_proc_body
25724 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
25726 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
25727 dwarf_proc_fndecl
, context_die
);
25728 if (dwarf_proc_die
!= NULL
)
25729 variant_part_offset
= dwarf_proc_call
;
25732 /* Output DIEs for all variants. */
25734 for (tree variant
= TYPE_FIELDS (variant_part_type
);
25735 variant
!= NULL_TREE
;
25736 variant
= DECL_CHAIN (variant
), ++i
)
25738 tree variant_type
= TREE_TYPE (variant
);
25739 dw_die_ref variant_die
;
25741 /* All variants (i.e. members of a variant part) are supposed to be
25742 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
25743 under these records. */
25744 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
25746 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
25747 equate_decl_number_to_die (variant
, variant_die
);
25749 /* Output discriminant values this variant matches, if any. */
25750 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
25751 /* In the case we have discriminant information at all, this is
25752 probably the default variant: as the standard says, don't
25753 output any discriminant value/list attribute. */
25755 else if (discr_lists
[i
]->dw_discr_next
== NULL
25756 && !discr_lists
[i
]->dw_discr_range
)
25757 /* If there is only one accepted value, don't bother outputting a
25759 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
25761 add_discr_list (variant_die
, discr_lists
[i
]);
25763 for (tree member
= TYPE_FIELDS (variant_type
);
25764 member
!= NULL_TREE
;
25765 member
= DECL_CHAIN (member
))
25767 struct vlr_context vlr_sub_ctx
= {
25768 vlr_ctx
->struct_type
, /* struct_type */
25769 NULL
/* variant_part_offset */
25771 if (is_variant_part (member
))
25773 /* All offsets for fields inside variant parts are relative to
25774 the top-level embedding RECORD_TYPE's base address. On the
25775 other hand, offsets in GCC's types are relative to the
25776 nested-most variant part. So we have to sum offsets each time
25779 vlr_sub_ctx
.variant_part_offset
25780 = fold_build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
25781 variant_part_offset
, byte_position (member
));
25782 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
25786 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
25787 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
25792 free (discr_lists
);
25795 /* Generate a DIE for a class member. */
25798 gen_member_die (tree type
, dw_die_ref context_die
)
25801 tree binfo
= TYPE_BINFO (type
);
25803 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
25805 /* If this is not an incomplete type, output descriptions of each of its
25806 members. Note that as we output the DIEs necessary to represent the
25807 members of this record or union type, we will also be trying to output
25808 DIEs to represent the *types* of those members. However the `type'
25809 function (above) will specifically avoid generating type DIEs for member
25810 types *within* the list of member DIEs for this (containing) type except
25811 for those types (of members) which are explicitly marked as also being
25812 members of this (containing) type themselves. The g++ front- end can
25813 force any given type to be treated as a member of some other (containing)
25814 type by setting the TYPE_CONTEXT of the given (member) type to point to
25815 the TREE node representing the appropriate (containing) type. */
25817 /* First output info about the base classes. */
25818 if (binfo
&& early_dwarf
)
25820 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
25824 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
25825 gen_inheritance_die (base
,
25826 (accesses
? (*accesses
)[i
] : access_public_node
),
25831 /* Now output info about the members. */
25832 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
25834 /* Ignore clones. */
25835 if (DECL_ABSTRACT_ORIGIN (member
))
25838 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
25839 bool static_inline_p
25841 && TREE_STATIC (member
)
25842 && (lang_hooks
.decls
.decl_dwarf_attribute (member
, DW_AT_inline
)
25845 /* If we thought we were generating minimal debug info for TYPE
25846 and then changed our minds, some of the member declarations
25847 may have already been defined. Don't define them again, but
25848 do put them in the right order. */
25850 if (dw_die_ref child
= lookup_decl_die (member
))
25852 /* Handle inline static data members, which only have in-class
25854 bool splice
= true;
25856 dw_die_ref ref
= NULL
;
25857 if (child
->die_tag
== DW_TAG_variable
25858 && child
->die_parent
== comp_unit_die ())
25860 ref
= get_AT_ref (child
, DW_AT_specification
);
25862 /* For C++17 inline static data members followed by redundant
25863 out of class redeclaration, we might get here with
25864 child being the DIE created for the out of class
25865 redeclaration and with its DW_AT_specification being
25866 the DIE created for in-class definition. We want to
25867 reparent the latter, and don't want to create another
25868 DIE with DW_AT_specification in that case, because
25869 we already have one. */
25872 && ref
->die_tag
== DW_TAG_variable
25873 && ref
->die_parent
== comp_unit_die ()
25874 && get_AT (ref
, DW_AT_specification
) == NULL
)
25878 static_inline_p
= false;
25883 reparent_child (child
, context_die
);
25884 if (dwarf_version
< 5)
25885 child
->die_tag
= DW_TAG_member
;
25889 else if (child
->die_tag
== DW_TAG_enumerator
)
25890 /* Enumerators remain under their enumeration even if
25891 their names are introduced in the enclosing scope. */
25895 splice_child_die (context_die
, child
);
25898 /* Do not generate DWARF for variant parts if we are generating the
25899 corresponding GNAT encodings: DIEs generated for the two schemes
25900 would conflict in our mappings. */
25901 else if (is_variant_part (member
)
25902 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_ALL
)
25904 vlr_ctx
.variant_part_offset
= byte_position (member
);
25905 gen_variant_part (member
, &vlr_ctx
, context_die
);
25909 vlr_ctx
.variant_part_offset
= NULL_TREE
;
25910 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
25913 /* For C++ inline static data members emit immediately a DW_TAG_variable
25914 DIE that will refer to that DW_TAG_member/DW_TAG_variable through
25915 DW_AT_specification. */
25916 if (static_inline_p
)
25918 int old_extern
= DECL_EXTERNAL (member
);
25919 DECL_EXTERNAL (member
) = 0;
25920 gen_decl_die (member
, NULL
, NULL
, comp_unit_die ());
25921 DECL_EXTERNAL (member
) = old_extern
;
25926 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
25927 is set, we pretend that the type was never defined, so we only get the
25928 member DIEs needed by later specification DIEs. */
25931 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
25932 enum debug_info_usage usage
)
25934 if (TREE_ASM_WRITTEN (type
))
25936 /* Fill in the bound of variable-length fields in late dwarf if
25937 still incomplete. */
25938 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
25939 for (tree member
= TYPE_FIELDS (type
);
25941 member
= DECL_CHAIN (member
))
25942 fill_variable_array_bounds (TREE_TYPE (member
));
25946 dw_die_ref type_die
= lookup_type_die (type
);
25947 dw_die_ref scope_die
= 0;
25948 bool nested
= false;
25949 bool complete
= (TYPE_SIZE (type
)
25950 && (! TYPE_STUB_DECL (type
)
25951 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
25952 bool ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
25953 complete
= complete
&& should_emit_struct_debug (type
, usage
);
25955 if (type_die
&& ! complete
)
25958 if (TYPE_CONTEXT (type
) != NULL_TREE
25959 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
25960 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
25963 scope_die
= scope_die_for (type
, context_die
);
25965 /* Generate child dies for template parameters. */
25966 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
25967 schedule_generic_params_dies_gen (type
);
25969 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
25970 /* First occurrence of type or toplevel definition of nested class. */
25972 dw_die_ref old_die
= type_die
;
25974 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
25975 ? record_type_tag (type
) : DW_TAG_union_type
,
25977 equate_type_number_to_die (type
, type_die
);
25979 add_AT_specification (type_die
, old_die
);
25981 add_name_attribute (type_die
, type_tag (type
));
25984 remove_AT (type_die
, DW_AT_declaration
);
25986 /* If this type has been completed, then give it a byte_size attribute and
25987 then give a list of members. */
25988 if (complete
&& !ns_decl
)
25990 /* Prevent infinite recursion in cases where the type of some member of
25991 this type is expressed in terms of this type itself. */
25992 TREE_ASM_WRITTEN (type
) = 1;
25993 add_byte_size_attribute (type_die
, type
);
25994 add_alignment_attribute (type_die
, type
);
25995 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
25997 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
25998 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
26001 /* If the first reference to this type was as the return type of an
26002 inline function, then it may not have a parent. Fix this now. */
26003 if (type_die
->die_parent
== NULL
)
26004 add_child_die (scope_die
, type_die
);
26006 gen_member_die (type
, type_die
);
26008 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
26009 if (TYPE_ARTIFICIAL (type
))
26010 add_AT_flag (type_die
, DW_AT_artificial
, 1);
26012 /* GNU extension: Record what type our vtable lives in. */
26013 if (TYPE_VFIELD (type
))
26015 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
26017 gen_type_die (vtype
, context_die
);
26018 add_AT_die_ref (type_die
, DW_AT_containing_type
,
26019 lookup_type_die (vtype
));
26024 add_AT_flag (type_die
, DW_AT_declaration
, 1);
26026 /* We don't need to do this for function-local types. */
26027 if (TYPE_STUB_DECL (type
)
26028 && ! decl_function_context (TYPE_STUB_DECL (type
)))
26029 vec_safe_push (incomplete_types
, type
);
26032 if (get_AT (type_die
, DW_AT_name
))
26033 add_pubtype (type
, type_die
);
26036 /* Generate a DIE for a subroutine _type_. */
26039 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
26041 tree return_type
= TREE_TYPE (type
);
26042 dw_die_ref subr_die
26043 = new_die (DW_TAG_subroutine_type
,
26044 scope_die_for (type
, context_die
), type
);
26046 equate_type_number_to_die (type
, subr_die
);
26047 add_prototyped_attribute (subr_die
, type
);
26048 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
26050 add_alignment_attribute (subr_die
, type
);
26051 gen_formal_types_die (type
, subr_die
);
26053 if (get_AT (subr_die
, DW_AT_name
))
26054 add_pubtype (type
, subr_die
);
26055 if ((dwarf_version
>= 5 || !dwarf_strict
)
26056 && lang_hooks
.types
.type_dwarf_attribute (type
, DW_AT_reference
) != -1)
26057 add_AT_flag (subr_die
, DW_AT_reference
, 1);
26058 if ((dwarf_version
>= 5 || !dwarf_strict
)
26059 && lang_hooks
.types
.type_dwarf_attribute (type
,
26060 DW_AT_rvalue_reference
) != -1)
26061 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
26064 /* Generate a DIE for a type definition. */
26067 gen_typedef_die (tree decl
, dw_die_ref context_die
)
26069 dw_die_ref type_die
;
26072 if (TREE_ASM_WRITTEN (decl
))
26074 if (DECL_ORIGINAL_TYPE (decl
))
26075 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
26079 /* As we avoid creating DIEs for local typedefs (see decl_ultimate_origin
26080 checks in process_scope_var and modified_type_die), this should be called
26081 only for original types. */
26082 gcc_assert (decl_ultimate_origin (decl
) == NULL
26083 || decl_ultimate_origin (decl
) == decl
);
26085 TREE_ASM_WRITTEN (decl
) = 1;
26086 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
26088 add_name_and_src_coords_attributes (type_die
, decl
);
26089 if (DECL_ORIGINAL_TYPE (decl
))
26091 type
= DECL_ORIGINAL_TYPE (decl
);
26092 if (type
== error_mark_node
)
26095 gcc_assert (type
!= TREE_TYPE (decl
));
26096 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
26100 type
= TREE_TYPE (decl
);
26101 if (type
== error_mark_node
)
26104 if (is_naming_typedef_decl (TYPE_NAME (type
)))
26106 /* Here, we are in the case of decl being a typedef naming
26107 an anonymous type, e.g:
26108 typedef struct {...} foo;
26109 In that case TREE_TYPE (decl) is not a typedef variant
26110 type and TYPE_NAME of the anonymous type is set to the
26111 TYPE_DECL of the typedef. This construct is emitted by
26114 TYPE is the anonymous struct named by the typedef
26115 DECL. As we need the DW_AT_type attribute of the
26116 DW_TAG_typedef to point to the DIE of TYPE, let's
26117 generate that DIE right away. add_type_attribute
26118 called below will then pick (via lookup_type_die) that
26119 anonymous struct DIE. */
26120 if (!TREE_ASM_WRITTEN (type
))
26121 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
26123 /* This is a GNU Extension. We are adding a
26124 DW_AT_linkage_name attribute to the DIE of the
26125 anonymous struct TYPE. The value of that attribute
26126 is the name of the typedef decl naming the anonymous
26127 struct. This greatly eases the work of consumers of
26128 this debug info. */
26129 add_linkage_name_raw (lookup_type_die (type
), decl
);
26133 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
26136 if (is_naming_typedef_decl (decl
))
26137 /* We want that all subsequent calls to lookup_type_die with
26138 TYPE in argument yield the DW_TAG_typedef we have just
26140 equate_type_number_to_die (type
, type_die
);
26142 add_alignment_attribute (type_die
, TREE_TYPE (decl
));
26144 add_accessibility_attribute (type_die
, decl
);
26146 if (DECL_ABSTRACT_P (decl
))
26147 equate_decl_number_to_die (decl
, type_die
);
26149 if (get_AT (type_die
, DW_AT_name
))
26150 add_pubtype (decl
, type_die
);
26153 /* Generate a DIE for a struct, class, enum or union type. */
26156 gen_tagged_type_die (tree type
,
26157 dw_die_ref context_die
,
26158 enum debug_info_usage usage
)
26160 if (type
== NULL_TREE
26161 || !is_tagged_type (type
))
26164 if (TREE_ASM_WRITTEN (type
))
26166 /* If this is a nested type whose containing class hasn't been written
26167 out yet, writing it out will cover this one, too. This does not apply
26168 to instantiations of member class templates; they need to be added to
26169 the containing class as they are generated. FIXME: This hurts the
26170 idea of combining type decls from multiple TUs, since we can't predict
26171 what set of template instantiations we'll get. */
26172 else if (TYPE_CONTEXT (type
)
26173 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
26174 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
26176 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
26178 if (TREE_ASM_WRITTEN (type
))
26181 /* If that failed, attach ourselves to the stub. */
26182 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
26184 else if (TYPE_CONTEXT (type
) != NULL_TREE
26185 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
26187 /* If this type is local to a function that hasn't been written
26188 out yet, use a NULL context for now; it will be fixed up in
26189 decls_for_scope. */
26190 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
26191 /* A declaration DIE doesn't count; nested types need to go in the
26193 if (context_die
&& is_declaration_die (context_die
))
26194 context_die
= NULL
;
26197 context_die
= declare_in_namespace (type
, context_die
);
26199 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
26201 /* This might have been written out by the call to
26202 declare_in_namespace. */
26203 if (!TREE_ASM_WRITTEN (type
))
26204 gen_enumeration_type_die (type
, context_die
);
26207 gen_struct_or_union_type_die (type
, context_die
, usage
);
26209 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
26210 it up if it is ever completed. gen_*_type_die will set it for us
26211 when appropriate. */
26214 /* Generate a type description DIE. */
26217 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
26218 enum debug_info_usage usage
)
26220 struct array_descr_info info
;
26222 if (type
== NULL_TREE
|| type
== error_mark_node
)
26225 if (flag_checking
&& type
)
26226 verify_type (type
);
26228 if (TYPE_NAME (type
) != NULL_TREE
26229 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
26230 && is_redundant_typedef (TYPE_NAME (type
))
26231 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
26232 /* The DECL of this type is a typedef we don't want to emit debug
26233 info for but we want debug info for its underlying typedef.
26234 This can happen for e.g, the injected-class-name of a C++
26236 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
26238 /* If TYPE is a typedef type variant, let's generate debug info
26239 for the parent typedef which TYPE is a type of. */
26240 if (typedef_variant_p (type
))
26242 if (TREE_ASM_WRITTEN (type
))
26245 tree name
= TYPE_NAME (type
);
26246 tree origin
= decl_ultimate_origin (name
);
26247 if (origin
!= NULL
&& origin
!= name
)
26249 gen_decl_die (origin
, NULL
, NULL
, context_die
);
26253 /* Prevent broken recursion; we can't hand off to the same type. */
26254 gcc_assert (DECL_ORIGINAL_TYPE (name
) != type
);
26256 /* Give typedefs the right scope. */
26257 context_die
= scope_die_for (type
, context_die
);
26259 TREE_ASM_WRITTEN (type
) = 1;
26261 gen_decl_die (name
, NULL
, NULL
, context_die
);
26265 /* If type is an anonymous tagged type named by a typedef, let's
26266 generate debug info for the typedef. */
26267 if (is_naming_typedef_decl (TYPE_NAME (type
)))
26269 /* Give typedefs the right scope. */
26270 context_die
= scope_die_for (type
, context_die
);
26272 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
26276 if (lang_hooks
.types
.get_debug_type
)
26278 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
26280 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
26282 gen_type_die_with_usage (debug_type
, context_die
, usage
);
26287 /* We are going to output a DIE to represent the unqualified version
26288 of this type (i.e. without any const or volatile qualifiers) so
26289 get the main variant (i.e. the unqualified version) of this type
26290 now. (Vectors and arrays are special because the debugging info is in the
26291 cloned type itself. Similarly function/method types can contain extra
26292 ref-qualification). */
26293 if (FUNC_OR_METHOD_TYPE_P (type
))
26295 /* For function/method types, can't use type_main_variant here,
26296 because that can have different ref-qualifiers for C++,
26297 but try to canonicalize. */
26298 tree main
= TYPE_MAIN_VARIANT (type
);
26299 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
26300 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
26301 && check_base_type (t
, main
)
26302 && check_lang_type (t
, type
))
26308 else if (TREE_CODE (type
) != VECTOR_TYPE
26309 && TREE_CODE (type
) != ARRAY_TYPE
)
26310 type
= type_main_variant (type
);
26312 /* If this is an array type with hidden descriptor, handle it first. */
26313 if (!TREE_ASM_WRITTEN (type
)
26314 && lang_hooks
.types
.get_array_descr_info
)
26316 memset (&info
, 0, sizeof (info
));
26317 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
26319 /* Fortran sometimes emits array types with no dimension. */
26320 gcc_assert (info
.ndimensions
>= 0
26321 && (info
.ndimensions
26322 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
26323 gen_descr_array_type_die (type
, &info
, context_die
);
26324 TREE_ASM_WRITTEN (type
) = 1;
26329 if (TREE_ASM_WRITTEN (type
))
26331 /* Variable-length types may be incomplete even if
26332 TREE_ASM_WRITTEN. For such types, fall through to
26333 gen_array_type_die() and possibly fill in
26334 DW_AT_{upper,lower}_bound attributes. */
26335 if ((TREE_CODE (type
) != ARRAY_TYPE
26336 && TREE_CODE (type
) != RECORD_TYPE
26337 && TREE_CODE (type
) != UNION_TYPE
26338 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
26339 || !variably_modified_type_p (type
, NULL
))
26343 switch (TREE_CODE (type
))
26349 case REFERENCE_TYPE
:
26350 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
26351 ensures that the gen_type_die recursion will terminate even if the
26352 type is recursive. Recursive types are possible in Ada. */
26353 /* ??? We could perhaps do this for all types before the switch
26355 TREE_ASM_WRITTEN (type
) = 1;
26357 /* For these types, all that is required is that we output a DIE (or a
26358 set of DIEs) to represent the "basis" type. */
26359 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
26360 DINFO_USAGE_IND_USE
);
26364 /* This code is used for C++ pointer-to-data-member types.
26365 Output a description of the relevant class type. */
26366 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
26367 DINFO_USAGE_IND_USE
);
26369 /* Output a description of the type of the object pointed to. */
26370 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
26371 DINFO_USAGE_IND_USE
);
26373 /* Now output a DIE to represent this pointer-to-data-member type
26375 gen_ptr_to_mbr_type_die (type
, context_die
);
26378 case FUNCTION_TYPE
:
26379 /* Force out return type (in case it wasn't forced out already). */
26380 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
26381 DINFO_USAGE_DIR_USE
);
26382 gen_subroutine_type_die (type
, context_die
);
26386 /* Force out return type (in case it wasn't forced out already). */
26387 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
26388 DINFO_USAGE_DIR_USE
);
26389 gen_subroutine_type_die (type
, context_die
);
26394 gen_array_type_die (type
, context_die
);
26397 case ENUMERAL_TYPE
:
26400 case QUAL_UNION_TYPE
:
26401 gen_tagged_type_die (type
, context_die
, usage
);
26408 case FIXED_POINT_TYPE
:
26412 /* No DIEs needed for fundamental types. */
26417 /* Just use DW_TAG_unspecified_type. */
26419 dw_die_ref type_die
= lookup_type_die (type
);
26420 if (type_die
== NULL
)
26422 tree name
= TYPE_IDENTIFIER (type
);
26423 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
26425 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
26426 equate_type_number_to_die (type
, type_die
);
26432 if (is_cxx_auto (type
))
26434 tree name
= TYPE_IDENTIFIER (type
);
26435 dw_die_ref
*die
= (name
== get_identifier ("auto")
26436 ? &auto_die
: &decltype_auto_die
);
26439 *die
= new_die (DW_TAG_unspecified_type
,
26440 comp_unit_die (), NULL_TREE
);
26441 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
26443 equate_type_number_to_die (type
, *die
);
26446 gcc_unreachable ();
26449 TREE_ASM_WRITTEN (type
) = 1;
26453 gen_type_die (tree type
, dw_die_ref context_die
)
26455 if (type
!= error_mark_node
)
26457 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
26460 dw_die_ref die
= lookup_type_die (type
);
26467 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
26468 things which are local to the given block. */
26471 gen_block_die (tree stmt
, dw_die_ref context_die
)
26473 int must_output_die
= 0;
26476 /* Ignore blocks that are NULL. */
26477 if (stmt
== NULL_TREE
)
26480 inlined_func
= inlined_function_outer_scope_p (stmt
);
26482 /* If the block is one fragment of a non-contiguous block, do not
26483 process the variables, since they will have been done by the
26484 origin block. Do process subblocks. */
26485 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
26489 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
26490 gen_block_die (sub
, context_die
);
26495 /* Determine if we need to output any Dwarf DIEs at all to represent this
26498 /* The outer scopes for inlinings *must* always be represented. We
26499 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
26500 must_output_die
= 1;
26501 else if (lookup_block_die (stmt
))
26502 /* If we already have a DIE then it was filled early. Meanwhile
26503 we might have pruned all BLOCK_VARS as optimized out but we
26504 still want to generate high/low PC attributes so output it. */
26505 must_output_die
= 1;
26506 else if (TREE_USED (stmt
)
26507 || TREE_ASM_WRITTEN (stmt
))
26509 /* Determine if this block directly contains any "significant"
26510 local declarations which we will need to output DIEs for. */
26511 if (debug_info_level
> DINFO_LEVEL_TERSE
)
26513 /* We are not in terse mode so any local declaration that
26514 is not ignored for debug purposes counts as being a
26515 "significant" one. */
26516 if (BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
26517 must_output_die
= 1;
26519 for (tree var
= BLOCK_VARS (stmt
); var
; var
= DECL_CHAIN (var
))
26520 if (!DECL_IGNORED_P (var
))
26522 must_output_die
= 1;
26526 else if (!dwarf2out_ignore_block (stmt
))
26527 must_output_die
= 1;
26530 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
26531 DIE for any block which contains no significant local declarations at
26532 all. Rather, in such cases we just call `decls_for_scope' so that any
26533 needed Dwarf info for any sub-blocks will get properly generated. Note
26534 that in terse mode, our definition of what constitutes a "significant"
26535 local declaration gets restricted to include only inlined function
26536 instances and local (nested) function definitions. */
26537 if (must_output_die
)
26540 gen_inlined_subroutine_die (stmt
, context_die
);
26542 gen_lexical_block_die (stmt
, context_die
);
26545 decls_for_scope (stmt
, context_die
);
26548 /* Process variable DECL (or variable with origin ORIGIN) within
26549 block STMT and add it to CONTEXT_DIE. */
26551 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
26554 tree decl_or_origin
= decl
? decl
: origin
;
26556 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
26557 die
= lookup_decl_die (decl_or_origin
);
26558 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
)
26560 if (TYPE_DECL_IS_STUB (decl_or_origin
))
26561 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
26563 die
= lookup_decl_die (decl_or_origin
);
26564 /* Avoid re-creating the DIE late if it was optimized as unused early. */
26565 if (! die
&& ! early_dwarf
)
26571 /* Avoid creating DIEs for local typedefs and concrete static variables that
26572 will only be pruned later. */
26573 if ((origin
|| decl_ultimate_origin (decl
))
26574 && (TREE_CODE (decl_or_origin
) == TYPE_DECL
26575 || (VAR_P (decl_or_origin
) && TREE_STATIC (decl_or_origin
))))
26577 origin
= decl_ultimate_origin (decl_or_origin
);
26578 if (decl
&& VAR_P (decl
) && die
!= NULL
)
26580 die
= lookup_decl_die (origin
);
26582 equate_decl_number_to_die (decl
, die
);
26587 if (die
!= NULL
&& die
->die_parent
== NULL
)
26588 add_child_die (context_die
, die
);
26590 if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
26593 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
26594 stmt
, context_die
);
26598 if (decl
&& DECL_P (decl
))
26600 die
= lookup_decl_die (decl
);
26602 /* Early created DIEs do not have a parent as the decls refer
26603 to the function as DECL_CONTEXT rather than the BLOCK. */
26604 if (die
&& die
->die_parent
== NULL
)
26606 gcc_assert (in_lto_p
);
26607 add_child_die (context_die
, die
);
26611 gen_decl_die (decl
, origin
, NULL
, context_die
);
26615 /* Generate all of the decls declared within a given scope and (recursively)
26616 all of its sub-blocks. */
26619 decls_for_scope (tree stmt
, dw_die_ref context_die
, bool recurse
)
26625 /* Ignore NULL blocks. */
26626 if (stmt
== NULL_TREE
)
26629 /* Output the DIEs to represent all of the data objects and typedefs
26630 declared directly within this block but not within any nested
26631 sub-blocks. Also, nested function and tag DIEs have been
26632 generated with a parent of NULL; fix that up now. We don't
26633 have to do this if we're at -g1. */
26634 if (debug_info_level
> DINFO_LEVEL_TERSE
)
26636 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
26637 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
26638 /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
26639 origin - avoid doing this twice as we have no good way to see
26640 if we've done it once already. */
26642 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
26644 decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
26645 if (decl
== current_function_decl
)
26646 /* Ignore declarations of the current function, while they
26647 are declarations, gen_subprogram_die would treat them
26648 as definitions again, because they are equal to
26649 current_function_decl and endlessly recurse. */;
26650 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
26651 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
26653 process_scope_var (stmt
, NULL_TREE
, decl
, context_die
);
26657 /* Even if we're at -g1, we need to process the subblocks in order to get
26658 inlined call information. */
26660 /* Output the DIEs to represent all sub-blocks (and the items declared
26661 therein) of this block. */
26663 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
26665 subblocks
= BLOCK_CHAIN (subblocks
))
26666 gen_block_die (subblocks
, context_die
);
26669 /* Is this a typedef we can avoid emitting? */
26672 is_redundant_typedef (const_tree decl
)
26674 if (TYPE_DECL_IS_STUB (decl
))
26677 if (DECL_ARTIFICIAL (decl
)
26678 && DECL_CONTEXT (decl
)
26679 && is_tagged_type (DECL_CONTEXT (decl
))
26680 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
26681 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
26682 /* Also ignore the artificial member typedef for the class name. */
26688 /* Return TRUE if TYPE is a typedef that names a type for linkage
26689 purposes. This kind of typedefs is produced by the C++ FE for
26692 typedef struct {...} foo;
26694 In that case, there is no typedef variant type produced for foo.
26695 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
26699 is_naming_typedef_decl (const_tree decl
)
26701 if (decl
== NULL_TREE
26702 || TREE_CODE (decl
) != TYPE_DECL
26703 || DECL_NAMELESS (decl
)
26704 || !is_tagged_type (TREE_TYPE (decl
))
26705 || DECL_IS_UNDECLARED_BUILTIN (decl
)
26706 || is_redundant_typedef (decl
)
26707 /* It looks like Ada produces TYPE_DECLs that are very similar
26708 to C++ naming typedefs but that have different
26709 semantics. Let's be specific to c++ for now. */
26713 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
26714 && TYPE_NAME (TREE_TYPE (decl
)) == decl
26715 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
26716 != TYPE_NAME (TREE_TYPE (decl
))));
26719 /* Looks up the DIE for a context. */
26721 static inline dw_die_ref
26722 lookup_context_die (tree context
)
26726 /* Find die that represents this context. */
26727 if (TYPE_P (context
))
26729 context
= TYPE_MAIN_VARIANT (context
);
26730 dw_die_ref ctx
= lookup_type_die (context
);
26733 return strip_naming_typedef (context
, ctx
);
26736 return lookup_decl_die (context
);
26738 return comp_unit_die ();
26741 /* Returns the DIE for a context. */
26743 static inline dw_die_ref
26744 get_context_die (tree context
)
26748 /* Find die that represents this context. */
26749 if (TYPE_P (context
))
26751 context
= TYPE_MAIN_VARIANT (context
);
26752 return strip_naming_typedef (context
, force_type_die (context
));
26755 return force_decl_die (context
);
26757 return comp_unit_die ();
26760 /* Returns the DIE for decl. A DIE will always be returned. */
26763 force_decl_die (tree decl
)
26765 dw_die_ref decl_die
;
26766 unsigned saved_external_flag
;
26767 tree save_fn
= NULL_TREE
;
26768 decl_die
= lookup_decl_die (decl
);
26771 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
26773 decl_die
= lookup_decl_die (decl
);
26777 switch (TREE_CODE (decl
))
26779 case FUNCTION_DECL
:
26780 /* Clear current_function_decl, so that gen_subprogram_die thinks
26781 that this is a declaration. At this point, we just want to force
26782 declaration die. */
26783 save_fn
= current_function_decl
;
26784 current_function_decl
= NULL_TREE
;
26785 gen_subprogram_die (decl
, context_die
);
26786 current_function_decl
= save_fn
;
26790 /* Set external flag to force declaration die. Restore it after
26791 gen_decl_die() call. */
26792 saved_external_flag
= DECL_EXTERNAL (decl
);
26793 DECL_EXTERNAL (decl
) = 1;
26794 gen_decl_die (decl
, NULL
, NULL
, context_die
);
26795 DECL_EXTERNAL (decl
) = saved_external_flag
;
26798 case NAMESPACE_DECL
:
26799 if (dwarf_version
>= 3 || !dwarf_strict
)
26800 dwarf2out_decl (decl
);
26802 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
26803 decl_die
= comp_unit_die ();
26807 /* Enumerators shouldn't need force_decl_die. */
26808 gcc_assert (DECL_CONTEXT (decl
) == NULL_TREE
26809 || TREE_CODE (DECL_CONTEXT (decl
)) != ENUMERAL_TYPE
);
26810 gen_decl_die (decl
, NULL
, NULL
, context_die
);
26813 case TRANSLATION_UNIT_DECL
:
26814 decl_die
= comp_unit_die ();
26818 gcc_unreachable ();
26821 /* We should be able to find the DIE now. */
26823 decl_die
= lookup_decl_die (decl
);
26824 gcc_assert (decl_die
);
26830 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
26831 always returned. */
26834 force_type_die (tree type
)
26836 dw_die_ref type_die
;
26838 type_die
= lookup_type_die (type
);
26841 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
26843 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
26844 false, context_die
);
26845 gcc_assert (type_die
);
26850 /* Force out any required namespaces to be able to output DECL,
26851 and return the new context_die for it, if it's changed. */
26854 setup_namespace_context (tree thing
, dw_die_ref context_die
)
26856 tree context
= (DECL_P (thing
)
26857 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
26858 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
26859 /* Force out the namespace. */
26860 context_die
= force_decl_die (context
);
26862 return context_die
;
26865 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
26866 type) within its namespace, if appropriate.
26868 For compatibility with older debuggers, namespace DIEs only contain
26869 declarations; all definitions are emitted at CU scope, with
26870 DW_AT_specification pointing to the declaration (like with class
26874 declare_in_namespace (tree thing
, dw_die_ref context_die
)
26876 dw_die_ref ns_context
;
26878 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
26879 return context_die
;
26881 /* External declarations in the local scope only need to be emitted
26882 once, not once in the namespace and once in the scope.
26884 This avoids declaring the `extern' below in the
26885 namespace DIE as well as in the innermost scope:
26898 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
26899 return context_die
;
26901 /* If this decl is from an inlined function, then don't try to emit it in its
26902 namespace, as we will get confused. It would have already been emitted
26903 when the abstract instance of the inline function was emitted anyways. */
26904 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
26905 return context_die
;
26907 ns_context
= setup_namespace_context (thing
, context_die
);
26909 if (ns_context
!= context_die
)
26911 if (is_fortran () || is_dlang ())
26913 if (DECL_P (thing
))
26914 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
26916 gen_type_die (thing
, ns_context
);
26918 return context_die
;
26921 /* Generate a DIE for a namespace or namespace alias. */
26924 gen_namespace_die (tree decl
, dw_die_ref context_die
)
26926 dw_die_ref namespace_die
;
26928 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
26929 they are an alias of. */
26930 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
26932 /* Output a real namespace or module. */
26933 context_die
= setup_namespace_context (decl
, comp_unit_die ());
26934 namespace_die
= new_die (is_fortran () || is_dlang ()
26935 ? DW_TAG_module
: DW_TAG_namespace
,
26936 context_die
, decl
);
26937 /* For Fortran modules defined in different CU don't add src coords. */
26938 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
26940 const char *name
= dwarf2_name (decl
, 0);
26942 add_name_attribute (namespace_die
, name
);
26945 add_name_and_src_coords_attributes (namespace_die
, decl
);
26946 if (DECL_EXTERNAL (decl
))
26947 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
26948 equate_decl_number_to_die (decl
, namespace_die
);
26952 /* Output a namespace alias. */
26954 /* Force out the namespace we are an alias of, if necessary. */
26955 dw_die_ref origin_die
26956 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
26958 if (DECL_FILE_SCOPE_P (decl
)
26959 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
26960 context_die
= setup_namespace_context (decl
, comp_unit_die ());
26961 /* Now create the namespace alias DIE. */
26962 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
26963 add_name_and_src_coords_attributes (namespace_die
, decl
);
26964 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
26965 equate_decl_number_to_die (decl
, namespace_die
);
26967 if ((dwarf_version
>= 5 || !dwarf_strict
)
26968 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
26969 DW_AT_export_symbols
) == 1)
26970 add_AT_flag (namespace_die
, DW_AT_export_symbols
, 1);
26972 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
26973 if (want_pubnames ())
26974 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
26977 /* Generate Dwarf debug information for a decl described by DECL.
26978 The return value is currently only meaningful for PARM_DECLs,
26979 for all other decls it returns NULL.
26981 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
26982 It can be NULL otherwise. */
26985 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
26986 dw_die_ref context_die
)
26988 tree decl_or_origin
= decl
? decl
: origin
;
26989 tree class_origin
= NULL
, ultimate_origin
;
26991 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
26994 switch (TREE_CODE (decl_or_origin
))
27000 if (!is_fortran () && !is_ada () && !is_dlang ())
27002 /* The individual enumerators of an enum type get output when we output
27003 the Dwarf representation of the relevant enum type itself. */
27007 /* Emit its type. */
27008 gen_type_die (TREE_TYPE (decl
), context_die
);
27010 /* And its containing namespace. */
27011 context_die
= declare_in_namespace (decl
, context_die
);
27013 gen_const_die (decl
, context_die
);
27016 case FUNCTION_DECL
:
27019 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
27020 on local redeclarations of global functions. That seems broken. */
27021 if (current_function_decl
!= decl
)
27022 /* This is only a declaration. */;
27025 /* We should have abstract copies already and should not generate
27026 stray type DIEs in late LTO dumping. */
27030 /* If we're emitting a clone, emit info for the abstract instance. */
27031 else if (origin
|| DECL_ORIGIN (decl
) != decl
)
27032 dwarf2out_abstract_function (origin
27033 ? DECL_ORIGIN (origin
)
27034 : DECL_ABSTRACT_ORIGIN (decl
));
27036 /* If we're emitting a possibly inlined function emit it as
27037 abstract instance. */
27038 else if (cgraph_function_possibly_inlined_p (decl
)
27039 && ! DECL_ABSTRACT_P (decl
)
27040 && ! class_or_namespace_scope_p (context_die
)
27041 /* dwarf2out_abstract_function won't emit a die if this is just
27042 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
27043 that case, because that works only if we have a die. */
27044 && DECL_INITIAL (decl
) != NULL_TREE
)
27045 dwarf2out_abstract_function (decl
);
27047 /* Otherwise we're emitting the primary DIE for this decl. */
27048 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
27050 /* Before we describe the FUNCTION_DECL itself, make sure that we
27051 have its containing type. */
27053 origin
= decl_class_context (decl
);
27054 if (origin
!= NULL_TREE
)
27055 gen_type_die (origin
, context_die
);
27057 /* And its return type. */
27058 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
27060 /* And its virtual context. */
27061 if (DECL_VINDEX (decl
) != NULL_TREE
)
27062 gen_type_die (DECL_CONTEXT (decl
), context_die
);
27064 /* Make sure we have a member DIE for decl. */
27065 if (origin
!= NULL_TREE
)
27066 gen_type_die_for_member (origin
, decl
, context_die
);
27068 /* And its containing namespace. */
27069 context_die
= declare_in_namespace (decl
, context_die
);
27072 /* Now output a DIE to represent the function itself. */
27074 gen_subprogram_die (decl
, context_die
);
27078 /* If we are in terse mode, don't generate any DIEs to represent any
27079 actual typedefs. */
27080 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27083 /* In the special case of a TYPE_DECL node representing the declaration
27084 of some type tag, if the given TYPE_DECL is marked as having been
27085 instantiated from some other (original) TYPE_DECL node (e.g. one which
27086 was generated within the original definition of an inline function) we
27087 used to generate a special (abbreviated) DW_TAG_structure_type,
27088 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
27089 should be actually referencing those DIEs, as variable DIEs with that
27090 type would be emitted already in the abstract origin, so it was always
27091 removed during unused type prunning. Don't add anything in this
27093 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
27096 if (is_redundant_typedef (decl
))
27097 gen_type_die (TREE_TYPE (decl
), context_die
);
27099 /* Output a DIE to represent the typedef itself. */
27100 gen_typedef_die (decl
, context_die
);
27104 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
27105 gen_label_die (decl
, context_die
);
27110 /* If we are in terse mode, don't generate any DIEs to represent any
27111 variable declarations or definitions unless it is external. */
27112 if (debug_info_level
< DINFO_LEVEL_TERSE
27113 || (debug_info_level
== DINFO_LEVEL_TERSE
27114 && !TREE_PUBLIC (decl_or_origin
)))
27117 if (debug_info_level
> DINFO_LEVEL_TERSE
)
27119 /* Avoid generating stray type DIEs during late dwarf dumping.
27120 All types have been dumped early. */
27122 /* ??? But in LTRANS we cannot annotate early created variably
27123 modified type DIEs without copying them and adjusting all
27124 references to them. Dump them again as happens for inlining
27125 which copies both the decl and the types. */
27126 /* ??? And even non-LTO needs to re-visit type DIEs to fill
27127 in VLA bound information for example. */
27128 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
27129 current_function_decl
)))
27131 /* Output any DIEs that are needed to specify the type of this data
27133 if (decl_by_reference_p (decl_or_origin
))
27134 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
27136 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
27141 /* And its containing type. */
27142 class_origin
= decl_class_context (decl_or_origin
);
27143 if (class_origin
!= NULL_TREE
)
27144 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
27146 /* And its containing namespace. */
27147 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
27151 /* Now output the DIE to represent the data object itself. This gets
27152 complicated because of the possibility that the VAR_DECL really
27153 represents an inlined instance of a formal parameter for an inline
27155 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
27156 if (ultimate_origin
!= NULL_TREE
27157 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
27158 gen_formal_parameter_die (decl
, origin
,
27159 true /* Emit name attribute. */,
27162 gen_variable_die (decl
, origin
, context_die
);
27166 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
27167 /* Ignore the nameless fields that are used to skip bits but handle C++
27168 anonymous unions and structs. */
27169 if (DECL_NAME (decl
) != NULL_TREE
27170 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
27171 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
27173 gen_type_die (member_declared_type (decl
), context_die
);
27174 gen_field_die (decl
, ctx
, context_die
);
27179 /* Avoid generating stray type DIEs during late dwarf dumping.
27180 All types have been dumped early. */
27182 /* ??? But in LTRANS we cannot annotate early created variably
27183 modified type DIEs without copying them and adjusting all
27184 references to them. Dump them again as happens for inlining
27185 which copies both the decl and the types. */
27186 /* ??? And even non-LTO needs to re-visit type DIEs to fill
27187 in VLA bound information for example. */
27188 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
27189 current_function_decl
)))
27191 if (DECL_BY_REFERENCE (decl_or_origin
))
27192 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
27194 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
27196 return gen_formal_parameter_die (decl
, origin
,
27197 true /* Emit name attribute. */,
27200 case NAMESPACE_DECL
:
27201 if (dwarf_version
>= 3 || !dwarf_strict
)
27202 gen_namespace_die (decl
, context_die
);
27205 case IMPORTED_DECL
:
27206 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
27207 DECL_CONTEXT (decl
), context_die
);
27210 case NAMELIST_DECL
:
27211 gen_namelist_decl (DECL_NAME (decl
), context_die
,
27212 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
27216 /* Probably some frontend-internal decl. Assume we don't care. */
27217 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
27224 /* Output initial debug information for global DECL. Called at the
27225 end of the parsing process.
27227 This is the initial debug generation process. As such, the DIEs
27228 generated may be incomplete. A later debug generation pass
27229 (dwarf2out_late_global_decl) will augment the information generated
27230 in this pass (e.g., with complete location info). */
27233 dwarf2out_early_global_decl (tree decl
)
27237 /* gen_decl_die() will set DECL_ABSTRACT because
27238 cgraph_function_possibly_inlined_p() returns true. This is in
27239 turn will cause DW_AT_inline attributes to be set.
27241 This happens because at early dwarf generation, there is no
27242 cgraph information, causing cgraph_function_possibly_inlined_p()
27243 to return true. Trick cgraph_function_possibly_inlined_p()
27244 while we generate dwarf early. */
27245 bool save
= symtab
->global_info_ready
;
27246 symtab
->global_info_ready
= true;
27248 /* We don't handle TYPE_DECLs. If required, they'll be reached via
27249 other DECLs and they can point to template types or other things
27250 that dwarf2out can't handle when done via dwarf2out_decl. */
27251 if (TREE_CODE (decl
) != TYPE_DECL
27252 && TREE_CODE (decl
) != PARM_DECL
)
27254 if (TREE_CODE (decl
) == FUNCTION_DECL
)
27256 tree save_fndecl
= current_function_decl
;
27258 /* For nested functions, make sure we have DIEs for the parents first
27259 so that all nested DIEs are generated at the proper scope in the
27261 tree context
= decl_function_context (decl
);
27262 if (context
!= NULL
)
27264 dw_die_ref context_die
= lookup_decl_die (context
);
27265 current_function_decl
= context
;
27267 /* Avoid emitting DIEs multiple times, but still process CONTEXT
27268 enough so that it lands in its own context. This avoids type
27269 pruning issues later on. */
27270 if (context_die
== NULL
|| is_declaration_die (context_die
))
27271 dwarf2out_early_global_decl (context
);
27274 /* Emit an abstract origin of a function first. This happens
27275 with C++ constructor clones for example and makes
27276 dwarf2out_abstract_function happy which requires the early
27277 DIE of the abstract instance to be present. */
27278 tree origin
= DECL_ABSTRACT_ORIGIN (decl
);
27279 dw_die_ref origin_die
;
27281 /* Do not emit the DIE multiple times but make sure to
27282 process it fully here in case we just saw a declaration. */
27283 && ((origin_die
= lookup_decl_die (origin
)) == NULL
27284 || is_declaration_die (origin_die
)))
27286 current_function_decl
= origin
;
27287 dwarf2out_decl (origin
);
27290 /* Emit the DIE for decl but avoid doing that multiple times. */
27291 dw_die_ref old_die
;
27292 if ((old_die
= lookup_decl_die (decl
)) == NULL
27293 || is_declaration_die (old_die
))
27295 current_function_decl
= decl
;
27296 dwarf2out_decl (decl
);
27299 current_function_decl
= save_fndecl
;
27302 dwarf2out_decl (decl
);
27304 symtab
->global_info_ready
= save
;
27307 /* Return whether EXPR is an expression with the following pattern:
27308 INDIRECT_REF (NOP_EXPR (INTEGER_CST)). */
27311 is_trivial_indirect_ref (tree expr
)
27313 if (expr
== NULL_TREE
|| TREE_CODE (expr
) != INDIRECT_REF
)
27316 tree nop
= TREE_OPERAND (expr
, 0);
27317 if (nop
== NULL_TREE
|| TREE_CODE (nop
) != NOP_EXPR
)
27320 tree int_cst
= TREE_OPERAND (nop
, 0);
27321 return int_cst
!= NULL_TREE
&& TREE_CODE (int_cst
) == INTEGER_CST
;
27324 /* Output debug information for global decl DECL. Called from
27325 toplev.cc after compilation proper has finished. */
27328 dwarf2out_late_global_decl (tree decl
)
27330 /* Fill-in any location information we were unable to determine
27331 on the first pass. */
27334 dw_die_ref die
= lookup_decl_die (decl
);
27336 /* We may have to generate full debug late for LTO in case debug
27337 was not enabled at compile-time or the target doesn't support
27338 the LTO early debug scheme. */
27339 if (! die
&& in_lto_p
27340 /* Function scope variables are emitted when emitting the
27341 DIE for the function. */
27342 && ! local_function_static (decl
))
27343 dwarf2out_decl (decl
);
27346 /* We get called via the symtab code invoking late_global_decl
27347 for symbols that are optimized out.
27349 Do not add locations for those, except if they have a
27350 DECL_VALUE_EXPR, in which case they are relevant for debuggers.
27351 Still don't add a location if the DECL_VALUE_EXPR is not a trivial
27352 INDIRECT_REF expression, as this could generate relocations to
27353 text symbols in LTO object files, which is invalid. */
27354 varpool_node
*node
= varpool_node::get (decl
);
27355 if ((! node
|| ! node
->definition
)
27356 && ! (DECL_HAS_VALUE_EXPR_P (decl
)
27357 && is_trivial_indirect_ref (DECL_VALUE_EXPR (decl
))))
27358 tree_add_const_value_attribute_for_decl (die
, decl
);
27360 add_location_or_const_value_attribute (die
, decl
, false);
27365 /* Output debug information for type decl DECL. Called from toplev.cc
27366 and from language front ends (to record built-in types). */
27368 dwarf2out_type_decl (tree decl
, int local
)
27373 dwarf2out_decl (decl
);
27377 /* Output debug information for imported module or decl DECL.
27378 NAME is non-NULL name in the lexical block if the decl has been renamed.
27379 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
27380 that DECL belongs to.
27381 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
27383 dwarf2out_imported_module_or_decl_1 (tree decl
,
27385 tree lexical_block
,
27386 dw_die_ref lexical_block_die
)
27388 expanded_location xloc
;
27389 dw_die_ref imported_die
= NULL
;
27390 dw_die_ref at_import_die
;
27392 if (TREE_CODE (decl
) == IMPORTED_DECL
)
27394 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
27395 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
27399 xloc
= expand_location (input_location
);
27401 if (TREE_CODE (decl
) == TYPE_DECL
)
27403 at_import_die
= force_type_die (TREE_TYPE (decl
));
27404 /* For namespace N { typedef void T; } using N::T; base_type_die
27405 returns NULL, but DW_TAG_imported_declaration requires
27406 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
27407 if (!at_import_die
)
27409 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
27410 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
27411 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
27412 gcc_assert (at_import_die
);
27417 at_import_die
= lookup_decl_die (decl
);
27418 if (!at_import_die
)
27420 /* If we're trying to avoid duplicate debug info, we may not have
27421 emitted the member decl for this field. Emit it now. */
27422 if (TREE_CODE (decl
) == FIELD_DECL
)
27424 tree type
= DECL_CONTEXT (decl
);
27426 if (TYPE_CONTEXT (type
)
27427 && TYPE_P (TYPE_CONTEXT (type
))
27428 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
27429 DINFO_USAGE_DIR_USE
))
27431 gen_type_die_for_member (type
, decl
,
27432 get_context_die (TYPE_CONTEXT (type
)));
27434 if (TREE_CODE (decl
) == CONST_DECL
)
27436 /* Individual enumerators of an enum type do not get output here
27437 (see gen_decl_die), so we cannot call force_decl_die. */
27438 if (!is_fortran () && !is_ada () && !is_dlang ())
27441 if (TREE_CODE (decl
) == NAMELIST_DECL
)
27442 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
27443 get_context_die (DECL_CONTEXT (decl
)),
27446 at_import_die
= force_decl_die (decl
);
27450 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
27452 if (dwarf_version
>= 3 || !dwarf_strict
)
27453 imported_die
= new_die (DW_TAG_imported_module
,
27460 imported_die
= new_die (DW_TAG_imported_declaration
,
27464 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
27465 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
27466 if (debug_column_info
&& xloc
.column
)
27467 add_AT_unsigned (imported_die
, DW_AT_decl_column
, xloc
.column
);
27469 add_AT_string (imported_die
, DW_AT_name
,
27470 IDENTIFIER_POINTER (name
));
27471 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
27474 /* Output debug information for imported module or decl DECL.
27475 NAME is non-NULL name in context if the decl has been renamed.
27476 CHILD is true if decl is one of the renamed decls as part of
27477 importing whole module.
27478 IMPLICIT is set if this hook is called for an implicit import
27479 such as inline namespace. */
27482 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
27483 bool child
, bool implicit
)
27485 /* dw_die_ref at_import_die; */
27486 dw_die_ref scope_die
;
27488 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27493 /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
27494 should be enough, for DWARF4 and older even if we emit as extension
27495 DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
27496 for the benefit of consumers unaware of DW_AT_export_symbols. */
27498 && dwarf_version
>= 5
27499 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
27500 DW_AT_export_symbols
) == 1)
27505 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
27506 We need decl DIE for reference and scope die. First, get DIE for the decl
27509 /* Get the scope die for decl context. Use comp_unit_die for global module
27510 or decl. If die is not found for non globals, force new die. */
27512 && TYPE_P (context
)
27513 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
27516 scope_die
= get_context_die (context
);
27520 /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
27521 there is nothing we can do, here. */
27522 if (dwarf_version
< 3 && dwarf_strict
)
27525 gcc_assert (scope_die
->die_child
);
27526 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
27527 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
27528 scope_die
= scope_die
->die_child
;
27531 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
27532 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
27535 /* Output debug information for namelists. */
27538 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
27540 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
27544 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27547 gcc_assert (scope_die
!= NULL
);
27548 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
27549 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
27551 /* If there are no item_decls, we have a nondefining namelist, e.g.
27552 with USE association; hence, set DW_AT_declaration. */
27553 if (item_decls
== NULL_TREE
)
27555 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
27559 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
27561 nml_item_ref_die
= lookup_decl_die (value
);
27562 if (!nml_item_ref_die
)
27563 nml_item_ref_die
= force_decl_die (value
);
27565 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
27566 add_AT_die_ref (nml_item_die
, DW_AT_namelist_item
, nml_item_ref_die
);
27572 /* Write the debugging output for DECL and return the DIE. */
27575 dwarf2out_decl (tree decl
)
27577 dw_die_ref context_die
= comp_unit_die ();
27579 switch (TREE_CODE (decl
))
27584 case FUNCTION_DECL
:
27585 /* If we're a nested function, initially use a parent of NULL; if we're
27586 a plain function, this will be fixed up in decls_for_scope. If
27587 we're a method, it will be ignored, since we already have a DIE.
27588 Avoid doing this late though since clones of class methods may
27589 otherwise end up in limbo and create type DIEs late. */
27591 && decl_function_context (decl
)
27592 /* But if we're in terse mode, we don't care about scope. */
27593 && debug_info_level
> DINFO_LEVEL_TERSE
)
27594 context_die
= NULL
;
27598 /* For local statics lookup proper context die. */
27599 if (local_function_static (decl
))
27600 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
27602 /* If we are in terse mode, don't generate any DIEs to represent any
27603 variable declarations or definitions unless it is external. */
27604 if (debug_info_level
< DINFO_LEVEL_TERSE
27605 || (debug_info_level
== DINFO_LEVEL_TERSE
27606 && !TREE_PUBLIC (decl
)))
27611 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27613 if (!is_fortran () && !is_ada () && !is_dlang ())
27615 if (TREE_STATIC (decl
) && decl_function_context (decl
))
27616 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
27619 case NAMESPACE_DECL
:
27620 case IMPORTED_DECL
:
27621 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27623 if (lookup_decl_die (decl
) != NULL
)
27628 /* Don't emit stubs for types unless they are needed by other DIEs. */
27629 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
27632 /* Don't bother trying to generate any DIEs to represent any of the
27633 normal built-in types for the language we are compiling. */
27634 if (DECL_IS_UNDECLARED_BUILTIN (decl
))
27637 /* If we are in terse mode, don't generate any DIEs for types. */
27638 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27641 /* If we're a function-scope tag, initially use a parent of NULL;
27642 this will be fixed up in decls_for_scope. */
27643 if (decl_function_context (decl
))
27644 context_die
= NULL
;
27648 case NAMELIST_DECL
:
27655 gen_decl_die (decl
, NULL
, NULL
, context_die
);
27659 dw_die_ref die
= lookup_decl_die (decl
);
27665 /* Write the debugging output for DECL. */
27668 dwarf2out_function_decl (tree decl
)
27670 dwarf2out_decl (decl
);
27671 call_arg_locations
= NULL
;
27672 call_arg_loc_last
= NULL
;
27673 call_site_count
= -1;
27674 tail_call_site_count
= -1;
27675 decl_loc_table
->empty ();
27676 cached_dw_loc_list_table
->empty ();
27679 /* Output a marker (i.e. a label) for the beginning of the generated code for
27680 a lexical block. */
27683 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
27684 unsigned int blocknum
)
27686 switch_to_section (current_function_section ());
27687 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
27690 /* Output a marker (i.e. a label) for the end of the generated code for a
27694 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
27696 switch_to_section (current_function_section ());
27697 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
27700 /* Returns true if it is appropriate not to emit any debugging
27701 information for BLOCK, because it doesn't contain any instructions.
27703 Don't allow this for blocks with nested functions or local classes
27704 as we would end up with orphans, and in the presence of scheduling
27705 we may end up calling them anyway. */
27708 dwarf2out_ignore_block (const_tree block
)
27713 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
27714 if (TREE_CODE (decl
) == FUNCTION_DECL
27715 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
27717 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
27719 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
27720 if (TREE_CODE (decl
) == FUNCTION_DECL
27721 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
27728 /* Hash table routines for file_hash. */
27731 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
27733 return filename_cmp (p1
->key
, p2
) == 0;
27737 dwarf_file_hasher::hash (dwarf_file_data
*p
)
27739 return htab_hash_string (p
->key
);
27742 /* Lookup FILE_NAME (in the list of filenames that we know about here in
27743 dwarf2out.cc) and return its "index". The index of each (known) filename is
27744 just a unique number which is associated with only that one filename. We
27745 need such numbers for the sake of generating labels (in the .debug_sfnames
27746 section) and references to those files numbers (in the .debug_srcinfo
27747 and .debug_macinfo sections). If the filename given as an argument is not
27748 found in our current list, add it to the list and assign it the next
27749 available unique index number. */
27751 static struct dwarf_file_data
*
27752 lookup_filename (const char *file_name
)
27754 struct dwarf_file_data
* created
;
27760 file_name
= "<stdin>";
27762 dwarf_file_data
**slot
27763 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
27768 created
= ggc_alloc
<dwarf_file_data
> ();
27769 created
->key
= file_name
;
27770 created
->filename
= remap_debug_filename (file_name
);
27771 created
->emitted_number
= 0;
27776 /* If the assembler will construct the file table, then translate the compiler
27777 internal file table number into the assembler file table number, and emit
27778 a .file directive if we haven't already emitted one yet. The file table
27779 numbers are different because we prune debug info for unused variables and
27780 types, which may include filenames. */
27783 maybe_emit_file (struct dwarf_file_data
* fd
)
27785 if (! fd
->emitted_number
)
27787 if (last_emitted_file
)
27788 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
27790 fd
->emitted_number
= 1;
27791 last_emitted_file
= fd
;
27793 if (output_asm_line_debug_info ())
27795 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
27796 output_quoted_string (asm_out_file
, fd
->filename
);
27797 fputc ('\n', asm_out_file
);
27801 return fd
->emitted_number
;
27804 /* Schedule generation of a DW_AT_const_value attribute to DIE.
27805 That generation should happen after function debug info has been
27806 generated. The value of the attribute is the constant value of ARG. */
27809 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
27811 die_arg_entry entry
;
27816 gcc_assert (early_dwarf
);
27818 if (!tmpl_value_parm_die_table
)
27819 vec_alloc (tmpl_value_parm_die_table
, 32);
27823 vec_safe_push (tmpl_value_parm_die_table
, entry
);
27826 /* Return TRUE if T is an instance of generic type, FALSE
27830 generic_type_p (tree t
)
27832 if (t
== NULL_TREE
|| !TYPE_P (t
))
27834 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
27837 /* Schedule the generation of the generic parameter dies for the
27838 instance of generic type T. The proper generation itself is later
27839 done by gen_scheduled_generic_parms_dies. */
27842 schedule_generic_params_dies_gen (tree t
)
27844 if (!generic_type_p (t
))
27847 gcc_assert (early_dwarf
);
27849 if (!generic_type_instances
)
27850 vec_alloc (generic_type_instances
, 256);
27852 vec_safe_push (generic_type_instances
, t
);
27855 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
27856 by append_entry_to_tmpl_value_parm_die_table. This function must
27857 be called after function DIEs have been generated. */
27860 gen_remaining_tmpl_value_param_die_attribute (void)
27862 if (tmpl_value_parm_die_table
)
27867 /* We do this in two phases - first get the cases we can
27868 handle during early-finish, preserving those we cannot
27869 (containing symbolic constants where we don't yet know
27870 whether we are going to output the referenced symbols).
27871 For those we try again at late-finish. */
27873 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
27875 if (!e
->die
->removed
27876 && !tree_add_const_value_attribute (e
->die
, e
->arg
))
27878 dw_loc_descr_ref loc
= NULL
;
27880 && (dwarf_version
>= 5 || !dwarf_strict
))
27881 loc
= loc_descriptor_from_tree (e
->arg
, 2, NULL
);
27883 add_AT_loc (e
->die
, DW_AT_location
, loc
);
27885 (*tmpl_value_parm_die_table
)[j
++] = *e
;
27888 tmpl_value_parm_die_table
->truncate (j
);
27892 /* Generate generic parameters DIEs for instances of generic types
27893 that have been previously scheduled by
27894 schedule_generic_params_dies_gen. This function must be called
27895 after all the types of the CU have been laid out. */
27898 gen_scheduled_generic_parms_dies (void)
27903 if (!generic_type_instances
)
27906 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
27907 if (COMPLETE_TYPE_P (t
))
27908 gen_generic_params_dies (t
);
27910 generic_type_instances
= NULL
;
27914 /* Replace DW_AT_name for the decl with name. */
27917 dwarf2out_set_name (tree decl
, tree name
)
27920 dw_attr_node
*attr
;
27923 die
= TYPE_SYMTAB_DIE (decl
);
27927 dname
= dwarf2_name (name
, 0);
27931 attr
= get_AT (die
, DW_AT_name
);
27934 struct indirect_string_node
*node
;
27936 node
= find_AT_string (dname
);
27937 /* replace the string. */
27938 attr
->dw_attr_val
.v
.val_str
= node
;
27942 add_name_attribute (die
, dname
);
27945 /* True if before or during processing of the first function being emitted. */
27946 static bool in_first_function_p
= true;
27947 /* True if loc_note during dwarf2out_var_location call might still be
27948 before first real instruction at address equal to .Ltext0. */
27949 static bool maybe_at_text_label_p
= true;
27950 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
27951 static unsigned int first_loclabel_num_not_at_text_label
;
27953 /* Look ahead for a real insn. */
27956 dwarf2out_next_real_insn (rtx_insn
*loc_note
)
27958 rtx_insn
*next_real
= NEXT_INSN (loc_note
);
27961 if (INSN_P (next_real
))
27964 next_real
= NEXT_INSN (next_real
);
27969 /* Called by the final INSN scan whenever we see a var location. We
27970 use it to drop labels in the right places, and throw the location in
27971 our lookup table. */
27974 dwarf2out_var_location (rtx_insn
*loc_note
)
27976 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
27977 struct var_loc_node
*newloc
;
27978 rtx_insn
*next_real
;
27979 rtx_insn
*call_insn
= NULL
;
27980 static const char *last_label
;
27981 static const char *last_postcall_label
;
27982 static bool last_in_cold_section_p
;
27983 static rtx_insn
*expected_next_loc_note
;
27986 var_loc_view view
= 0;
27988 if (!NOTE_P (loc_note
))
27990 if (CALL_P (loc_note
))
27992 maybe_reset_location_view (loc_note
, cur_line_info_table
);
27994 if (SIBLING_CALL_P (loc_note
))
27995 tail_call_site_count
++;
27996 if (find_reg_note (loc_note
, REG_CALL_ARG_LOCATION
, NULL_RTX
))
27998 call_insn
= loc_note
;
28002 next_real
= dwarf2out_next_real_insn (call_insn
);
28003 cached_next_real_insn
= NULL
;
28006 if (optimize
== 0 && !flag_var_tracking
)
28008 /* When the var-tracking pass is not running, there is no note
28009 for indirect calls whose target is compile-time known. In this
28010 case, process such calls specifically so that we generate call
28011 sites for them anyway. */
28012 rtx x
= PATTERN (loc_note
);
28013 if (GET_CODE (x
) == PARALLEL
)
28014 x
= XVECEXP (x
, 0, 0);
28015 if (GET_CODE (x
) == SET
)
28017 if (GET_CODE (x
) == CALL
)
28020 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
28021 || !SYMBOL_REF_DECL (XEXP (x
, 0))
28022 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
28025 call_insn
= loc_note
;
28029 next_real
= dwarf2out_next_real_insn (call_insn
);
28030 cached_next_real_insn
= NULL
;
28035 else if (!debug_variable_location_views
)
28036 gcc_unreachable ();
28038 maybe_reset_location_view (loc_note
, cur_line_info_table
);
28043 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
28044 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
28047 /* Optimize processing a large consecutive sequence of location
28048 notes so we don't spend too much time in next_real_insn. If the
28049 next insn is another location note, remember the next_real_insn
28050 calculation for next time. */
28051 next_real
= cached_next_real_insn
;
28054 if (expected_next_loc_note
!= loc_note
)
28059 next_real
= dwarf2out_next_real_insn (loc_note
);
28063 rtx_insn
*next_note
= NEXT_INSN (loc_note
);
28064 while (next_note
!= next_real
)
28066 if (! next_note
->deleted ()
28067 && NOTE_P (next_note
)
28068 && NOTE_KIND (next_note
) == NOTE_INSN_VAR_LOCATION
)
28070 next_note
= NEXT_INSN (next_note
);
28073 if (next_note
== next_real
)
28074 cached_next_real_insn
= NULL
;
28077 expected_next_loc_note
= next_note
;
28078 cached_next_real_insn
= next_real
;
28082 cached_next_real_insn
= NULL
;
28084 /* If there are no instructions which would be affected by this note,
28085 don't do anything. */
28087 && next_real
== NULL_RTX
28088 && !NOTE_DURING_CALL_P (loc_note
))
28093 if (next_real
== NULL_RTX
)
28094 next_real
= get_last_insn ();
28096 /* If there were any real insns between note we processed last time
28097 and this note (or if it is the first note), clear
28098 last_{,postcall_}label so that they are not reused this time. */
28099 if (last_var_location_insn
== NULL_RTX
28100 || last_var_location_insn
!= next_real
28101 || last_in_cold_section_p
!= in_cold_section_p
)
28104 last_postcall_label
= NULL
;
28110 = NOTE_DURING_CALL_P (loc_note
) ? last_postcall_label
: last_label
;
28111 view
= cur_line_info_table
->view
;
28112 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
28113 newloc
= add_var_loc_to_decl (decl
, loc_note
, label
, view
);
28114 if (newloc
== NULL
)
28123 /* If there were no real insns between note we processed last time
28124 and this note, use the label we emitted last time. Otherwise
28125 create a new label and emit it. */
28126 if (last_label
== NULL
)
28128 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
28129 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
28131 last_label
= ggc_strdup (loclabel
);
28132 /* See if loclabel might be equal to .Ltext0. If yes,
28133 bump first_loclabel_num_not_at_text_label. */
28134 if (!have_multiple_function_sections
28135 && in_first_function_p
28136 && maybe_at_text_label_p
)
28138 static rtx_insn
*last_start
;
28140 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
28141 if (insn
== last_start
)
28143 else if (!NONDEBUG_INSN_P (insn
))
28147 rtx body
= PATTERN (insn
);
28148 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
28150 /* Inline asm could occupy zero bytes. */
28151 else if (GET_CODE (body
) == ASM_INPUT
28152 || asm_noperands (body
) >= 0)
28154 #ifdef HAVE_ATTR_length /* ??? We don't include insn-attr.h. */
28155 else if (HAVE_ATTR_length
&& get_attr_min_length (insn
) == 0)
28160 /* Assume insn has non-zero length. */
28161 maybe_at_text_label_p
= false;
28165 if (maybe_at_text_label_p
)
28167 last_start
= loc_note
;
28168 first_loclabel_num_not_at_text_label
= loclabel_num
;
28173 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
28174 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
28178 struct call_arg_loc_node
*ca_loc
28179 = ggc_cleared_alloc
<call_arg_loc_node
> ();
28180 rtx_insn
*prev
= call_insn
;
28182 ca_loc
->call_arg_loc_note
28183 = find_reg_note (call_insn
, REG_CALL_ARG_LOCATION
, NULL_RTX
);
28184 ca_loc
->next
= NULL
;
28185 ca_loc
->label
= last_label
;
28188 || (NONJUMP_INSN_P (prev
)
28189 && GET_CODE (PATTERN (prev
)) == SEQUENCE
28190 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
28191 if (!CALL_P (prev
))
28192 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
28193 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
28195 /* Look for a SYMBOL_REF in the "prev" instruction. */
28196 rtx x
= get_call_rtx_from (prev
);
28199 /* Try to get the call symbol, if any. */
28200 if (MEM_P (XEXP (x
, 0)))
28202 /* First, look for a memory access to a symbol_ref. */
28203 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
28204 && SYMBOL_REF_DECL (XEXP (x
, 0))
28205 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
28206 ca_loc
->symbol_ref
= XEXP (x
, 0);
28207 /* Otherwise, look at a compile-time known user-level function
28211 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
28212 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
28215 ca_loc
->block
= insn_scope (prev
);
28216 if (call_arg_locations
)
28217 call_arg_loc_last
->next
= ca_loc
;
28219 call_arg_locations
= ca_loc
;
28220 call_arg_loc_last
= ca_loc
;
28222 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
28224 newloc
->label
= last_label
;
28225 newloc
->view
= view
;
28229 if (!last_postcall_label
)
28231 sprintf (loclabel
, "%s-1", last_label
);
28232 last_postcall_label
= ggc_strdup (loclabel
);
28234 newloc
->label
= last_postcall_label
;
28235 /* ??? This view is at last_label, not last_label-1, but we
28236 could only assume view at last_label-1 is zero if we could
28237 assume calls always have length greater than one. This is
28238 probably true in general, though there might be a rare
28239 exception to this rule, e.g. if a call insn is optimized out
28240 by target magic. Then, even the -1 in the label will be
28241 wrong, which might invalidate the range. Anyway, using view,
28242 though technically possibly incorrect, will work as far as
28243 ranges go: since L-1 is in the middle of the call insn,
28244 (L-1).0 and (L-1).V shouldn't make any difference, and having
28245 the loclist entry refer to the .loc entry might be useful, so
28246 leave it like this. */
28247 newloc
->view
= view
;
28250 if (var_loc_p
&& flag_debug_asm
)
28252 const char *name
, *sep
, *patstr
;
28253 if (decl
&& DECL_NAME (decl
))
28254 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
28257 if (NOTE_VAR_LOCATION_LOC (loc_note
))
28260 patstr
= str_pattern_slim (NOTE_VAR_LOCATION_LOC (loc_note
));
28267 fprintf (asm_out_file
, "\t%s DEBUG %s%s%s\n", ASM_COMMENT_START
,
28268 name
, sep
, patstr
);
28271 last_var_location_insn
= next_real
;
28272 last_in_cold_section_p
= in_cold_section_p
;
28275 /* Check whether BLOCK, a lexical block, is nested within OUTER, or is
28276 OUTER itself. If BOTHWAYS, check not only that BLOCK can reach
28277 OUTER through BLOCK_SUPERCONTEXT links, but also that there is a
28278 path from OUTER to BLOCK through BLOCK_SUBBLOCKs and
28279 BLOCK_FRAGMENT_ORIGIN links. */
28281 block_within_block_p (tree block
, tree outer
, bool bothways
)
28283 if (block
== outer
)
28286 /* Quickly check that OUTER is up BLOCK's supercontext chain. */
28287 for (tree context
= BLOCK_SUPERCONTEXT (block
);
28289 context
= BLOCK_SUPERCONTEXT (context
))
28290 if (!context
|| TREE_CODE (context
) != BLOCK
)
28296 /* Now check that each block is actually referenced by its
28298 for (tree context
= BLOCK_SUPERCONTEXT (block
); ;
28299 context
= BLOCK_SUPERCONTEXT (context
))
28301 if (BLOCK_FRAGMENT_ORIGIN (context
))
28303 gcc_assert (!BLOCK_SUBBLOCKS (context
));
28304 context
= BLOCK_FRAGMENT_ORIGIN (context
);
28306 for (tree sub
= BLOCK_SUBBLOCKS (context
);
28308 sub
= BLOCK_CHAIN (sub
))
28311 if (context
== outer
)
28318 /* Called during final while assembling the marker of the entry point
28319 for an inlined function. */
28322 dwarf2out_inline_entry (tree block
)
28324 gcc_assert (debug_inline_points
);
28326 /* If we can't represent it, don't bother. */
28327 if (!(dwarf_version
>= 3 || !dwarf_strict
))
28330 gcc_assert (DECL_P (block_ultimate_origin (block
)));
28332 /* Sanity check the block tree. This would catch a case in which
28333 BLOCK got removed from the tree reachable from the outermost
28334 lexical block, but got retained in markers. It would still link
28335 back to its parents, but some ancestor would be missing a link
28336 down the path to the sub BLOCK. If the block got removed, its
28337 BLOCK_NUMBER will not be a usable value. */
28339 gcc_assert (block_within_block_p (block
,
28340 DECL_INITIAL (current_function_decl
),
28343 gcc_assert (inlined_function_outer_scope_p (block
));
28344 gcc_assert (!lookup_block_die (block
));
28346 if (BLOCK_FRAGMENT_ORIGIN (block
))
28347 block
= BLOCK_FRAGMENT_ORIGIN (block
);
28348 /* Can the entry point ever not be at the beginning of an
28349 unfragmented lexical block? */
28350 else if (!(BLOCK_FRAGMENT_CHAIN (block
)
28351 || (cur_line_info_table
28352 && !ZERO_VIEW_P (cur_line_info_table
->view
))))
28355 if (!inline_entry_data_table
)
28356 inline_entry_data_table
28357 = hash_table
<inline_entry_data_hasher
>::create_ggc (10);
28360 inline_entry_data
**iedp
28361 = inline_entry_data_table
->find_slot_with_hash (block
,
28362 htab_hash_pointer (block
),
28365 /* ??? Ideally, we'd record all entry points for the same inlined
28366 function (some may have been duplicated by e.g. unrolling), but
28367 we have no way to represent that ATM. */
28370 inline_entry_data
*ied
= *iedp
= ggc_cleared_alloc
<inline_entry_data
> ();
28371 ied
->block
= block
;
28372 ied
->label_pfx
= BLOCK_INLINE_ENTRY_LABEL
;
28373 ied
->label_num
= BLOCK_NUMBER (block
);
28374 if (cur_line_info_table
)
28375 ied
->view
= cur_line_info_table
->view
;
28377 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_INLINE_ENTRY_LABEL
,
28378 BLOCK_NUMBER (block
));
28381 /* Called from finalize_size_functions for size functions so that their body
28382 can be encoded in the debug info to describe the layout of variable-length
28386 dwarf2out_size_function (tree decl
)
28389 function_to_dwarf_procedure (decl
);
28392 /* Note in one location list that text section has changed. */
28395 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
28397 var_loc_list
*list
= *slot
;
28399 list
->last_before_switch
28400 = list
->last
->next
? list
->last
->next
: list
->last
;
28404 /* Note in all location lists that text section has changed. */
28407 var_location_switch_text_section (void)
28409 if (decl_loc_table
== NULL
)
28412 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
28415 /* Create a new line number table. */
28417 static dw_line_info_table
*
28418 new_line_info_table (void)
28420 dw_line_info_table
*table
;
28422 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
28423 table
->file_num
= 1;
28424 table
->line_num
= 1;
28425 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
28426 FORCE_RESET_NEXT_VIEW (table
->view
);
28427 table
->symviews_since_reset
= 0;
28432 /* Lookup the "current" table into which we emit line info, so
28433 that we don't have to do it for every source line. */
28436 set_cur_line_info_table (section
*sec
)
28438 dw_line_info_table
*table
;
28440 if (sec
== text_section
)
28441 table
= text_section_line_info
;
28442 else if (sec
== cold_text_section
)
28444 table
= cold_text_section_line_info
;
28447 cold_text_section_line_info
= table
= new_line_info_table ();
28448 table
->end_label
= cold_end_label
;
28453 const char *end_label
;
28455 if (crtl
->has_bb_partition
)
28457 if (in_cold_section_p
)
28458 end_label
= crtl
->subsections
.cold_section_end_label
;
28460 end_label
= crtl
->subsections
.hot_section_end_label
;
28464 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
28465 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
28466 current_function_funcdef_no
);
28467 end_label
= ggc_strdup (label
);
28470 table
= new_line_info_table ();
28471 table
->end_label
= end_label
;
28473 vec_safe_push (separate_line_info
, table
);
28476 if (output_asm_line_debug_info ())
28477 table
->is_stmt
= (cur_line_info_table
28478 ? cur_line_info_table
->is_stmt
28479 : DWARF_LINE_DEFAULT_IS_STMT_START
);
28480 cur_line_info_table
= table
;
28484 /* We need to reset the locations at the beginning of each
28485 function. We can't do this in the end_function hook, because the
28486 declarations that use the locations won't have been output when
28487 that hook is called. Also compute have_multiple_function_sections here. */
28490 dwarf2out_begin_function (tree fun
)
28492 section
*sec
= function_section (fun
);
28494 if (sec
!= text_section
)
28495 have_multiple_function_sections
= true;
28497 if (crtl
->has_bb_partition
&& !cold_text_section
)
28499 gcc_assert (current_function_decl
== fun
);
28500 cold_text_section
= unlikely_text_section ();
28501 switch_to_section (cold_text_section
);
28502 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
28503 switch_to_section (sec
);
28506 call_site_count
= 0;
28507 tail_call_site_count
= 0;
28509 set_cur_line_info_table (sec
);
28510 FORCE_RESET_NEXT_VIEW (cur_line_info_table
->view
);
28513 /* Helper function of dwarf2out_end_function, called only after emitting
28514 the very first function into assembly. Check if some .debug_loc range
28515 might end with a .LVL* label that could be equal to .Ltext0.
28516 In that case we must force using absolute addresses in .debug_loc ranges,
28517 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
28518 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
28520 Set have_multiple_function_sections to true in that case and
28521 terminate htab traversal. */
28524 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
28526 var_loc_list
*entry
= *slot
;
28527 struct var_loc_node
*node
;
28529 node
= entry
->first
;
28530 if (node
&& node
->next
&& node
->next
->label
)
28533 const char *label
= node
->next
->label
;
28534 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
28536 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
28538 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
28539 if (strcmp (label
, loclabel
) == 0)
28541 have_multiple_function_sections
= true;
28549 /* Hook called after emitting a function into assembly.
28550 This does something only for the very first function emitted. */
28553 dwarf2out_end_function (unsigned int)
28555 if (in_first_function_p
28556 && !have_multiple_function_sections
28557 && first_loclabel_num_not_at_text_label
28559 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
28560 in_first_function_p
= false;
28561 maybe_at_text_label_p
= false;
28564 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
28565 front-ends register a translation unit even before dwarf2out_init is
28567 static tree main_translation_unit
= NULL_TREE
;
28569 /* Hook called by front-ends after they built their main translation unit.
28570 Associate comp_unit_die to UNIT. */
28573 dwarf2out_register_main_translation_unit (tree unit
)
28575 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
28576 && main_translation_unit
== NULL_TREE
);
28577 main_translation_unit
= unit
;
28578 /* If dwarf2out_init has not been called yet, it will perform the association
28579 itself looking at main_translation_unit. */
28580 if (decl_die_table
!= NULL
)
28581 equate_decl_number_to_die (unit
, comp_unit_die ());
28584 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
28587 push_dw_line_info_entry (dw_line_info_table
*table
,
28588 enum dw_line_info_opcode opcode
, unsigned int val
)
28590 dw_line_info_entry e
;
28593 vec_safe_push (table
->entries
, e
);
28596 /* Output a label to mark the beginning of a source code line entry
28597 and record information relating to this source line, in
28598 'line_info_table' for later output of the .debug_line section. */
28599 /* ??? The discriminator parameter ought to be unsigned. */
28602 dwarf2out_source_line (unsigned int line
, unsigned int column
,
28603 const char *filename
,
28604 int discriminator
, bool is_stmt
)
28606 unsigned int file_num
;
28607 dw_line_info_table
*table
;
28608 static var_loc_view lvugid
;
28610 /* 'line_info_table' information gathering is not needed when the debug
28611 info level is set to the lowest value. Also, the current DWARF-based
28612 debug formats do not use this info. */
28613 if (debug_info_level
< DINFO_LEVEL_TERSE
|| !dwarf_debuginfo_p ())
28616 table
= cur_line_info_table
;
28620 if (debug_variable_location_views
28621 && output_asm_line_debug_info ()
28622 && table
&& !RESETTING_VIEW_P (table
->view
))
28624 /* If we're using the assembler to compute view numbers, we
28625 can't issue a .loc directive for line zero, so we can't
28626 get a view number at this point. We might attempt to
28627 compute it from the previous view, or equate it to a
28628 subsequent view (though it might not be there!), but
28629 since we're omitting the line number entry, we might as
28630 well omit the view number as well. That means pretending
28631 it's a view number zero, which might very well turn out
28632 to be correct. ??? Extend the assembler so that the
28633 compiler could emit e.g. ".locview .LVU#", to output a
28634 view without changing line number information. We'd then
28635 have to count it in symviews_since_reset; when it's omitted,
28636 it doesn't count. */
28638 zero_view_p
= BITMAP_GGC_ALLOC ();
28639 bitmap_set_bit (zero_view_p
, table
->view
);
28640 if (flag_debug_asm
)
28642 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
28643 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", table
->view
);
28644 fprintf (asm_out_file
, "\t%s line 0, omitted view ",
28645 ASM_COMMENT_START
);
28646 assemble_name (asm_out_file
, label
);
28647 putc ('\n', asm_out_file
);
28649 table
->view
= ++lvugid
;
28654 /* The discriminator column was added in dwarf4. Simplify the below
28655 by simply removing it if we're not supposed to output it. */
28656 if (dwarf_version
< 4 && dwarf_strict
)
28659 if (!debug_column_info
)
28662 file_num
= maybe_emit_file (lookup_filename (filename
));
28664 /* ??? TODO: Elide duplicate line number entries. Traditionally,
28665 the debugger has used the second (possibly duplicate) line number
28666 at the beginning of the function to mark the end of the prologue.
28667 We could eliminate any other duplicates within the function. For
28668 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
28669 that second line number entry. */
28670 /* Recall that this end-of-prologue indication is *not* the same thing
28671 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
28672 to which the hook corresponds, follows the last insn that was
28673 emitted by gen_prologue. What we need is to precede the first insn
28674 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
28675 insn that corresponds to something the user wrote. These may be
28676 very different locations once scheduling is enabled. */
28678 if (0 && file_num
== table
->file_num
28679 && line
== table
->line_num
28680 && column
== table
->column_num
28681 && discriminator
== table
->discrim_num
28682 && is_stmt
== table
->is_stmt
)
28685 switch_to_section (current_function_section ());
28687 /* If requested, emit something human-readable. */
28688 if (flag_debug_asm
)
28690 if (debug_column_info
)
28691 fprintf (asm_out_file
, "\t%s %s:%d:%d\n", ASM_COMMENT_START
,
28692 filename
, line
, column
);
28694 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
28698 if (output_asm_line_debug_info ())
28700 /* Emit the .loc directive understood by GNU as. */
28701 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
28702 file_num, line, is_stmt, discriminator */
28703 fputs ("\t.loc ", asm_out_file
);
28704 fprint_ul (asm_out_file
, file_num
);
28705 putc (' ', asm_out_file
);
28706 fprint_ul (asm_out_file
, line
);
28707 putc (' ', asm_out_file
);
28708 fprint_ul (asm_out_file
, column
);
28710 if (is_stmt
!= table
->is_stmt
)
28712 #if HAVE_GAS_LOC_STMT
28713 fputs (" is_stmt ", asm_out_file
);
28714 putc (is_stmt
? '1' : '0', asm_out_file
);
28717 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
28719 gcc_assert (discriminator
> 0);
28720 fputs (" discriminator ", asm_out_file
);
28721 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
28723 if (debug_variable_location_views
)
28725 if (!RESETTING_VIEW_P (table
->view
))
28727 table
->symviews_since_reset
++;
28728 if (table
->symviews_since_reset
> symview_upper_bound
)
28729 symview_upper_bound
= table
->symviews_since_reset
;
28730 /* When we're using the assembler to compute view
28731 numbers, we output symbolic labels after "view" in
28732 .loc directives, and the assembler will set them for
28733 us, so that we can refer to the view numbers in
28734 location lists. The only exceptions are when we know
28735 a view will be zero: "-0" is a forced reset, used
28736 e.g. in the beginning of functions, whereas "0" tells
28737 the assembler to check that there was a PC change
28738 since the previous view, in a way that implicitly
28739 resets the next view. */
28740 fputs (" view ", asm_out_file
);
28741 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
28742 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", table
->view
);
28743 assemble_name (asm_out_file
, label
);
28744 table
->view
= ++lvugid
;
28748 table
->symviews_since_reset
= 0;
28749 if (FORCE_RESETTING_VIEW_P (table
->view
))
28750 fputs (" view -0", asm_out_file
);
28752 fputs (" view 0", asm_out_file
);
28753 /* Mark the present view as a zero view. Earlier debug
28754 binds may have already added its id to loclists to be
28755 emitted later, so we can't reuse the id for something
28756 else. However, it's good to know whether a view is
28757 known to be zero, because then we may be able to
28758 optimize out locviews that are all zeros, so take
28759 note of it in zero_view_p. */
28761 zero_view_p
= BITMAP_GGC_ALLOC ();
28762 bitmap_set_bit (zero_view_p
, lvugid
);
28763 table
->view
= ++lvugid
;
28766 putc ('\n', asm_out_file
);
28770 unsigned int label_num
= ++line_info_label_num
;
28772 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
28774 if (debug_variable_location_views
&& !RESETTING_VIEW_P (table
->view
))
28775 push_dw_line_info_entry (table
, LI_adv_address
, label_num
);
28777 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
28778 if (debug_variable_location_views
)
28780 bool resetting
= FORCE_RESETTING_VIEW_P (table
->view
);
28784 if (flag_debug_asm
)
28785 fprintf (asm_out_file
, "\t%s view %s%d\n",
28787 resetting
? "-" : "",
28792 if (file_num
!= table
->file_num
)
28793 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
28794 if (discriminator
!= table
->discrim_num
)
28795 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
28796 if (is_stmt
!= table
->is_stmt
)
28797 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
28798 push_dw_line_info_entry (table
, LI_set_line
, line
);
28799 if (debug_column_info
)
28800 push_dw_line_info_entry (table
, LI_set_column
, column
);
28803 table
->file_num
= file_num
;
28804 table
->line_num
= line
;
28805 table
->column_num
= column
;
28806 table
->discrim_num
= discriminator
;
28807 table
->is_stmt
= is_stmt
;
28808 table
->in_use
= true;
28811 /* Record a source file location for a DECL_IGNORED_P function. */
28814 dwarf2out_set_ignored_loc (unsigned int line
, unsigned int column
,
28815 const char *filename
)
28817 dw_fde_ref fde
= cfun
->fde
;
28819 fde
->ignored_debug
= false;
28820 set_cur_line_info_table (function_section (fde
->decl
));
28822 dwarf2out_source_line (line
, column
, filename
, 0, true);
28825 /* Record the beginning of a new source file. */
28828 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
28830 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28833 e
.code
= DW_MACINFO_start_file
;
28835 e
.info
= ggc_strdup (filename
);
28836 vec_safe_push (macinfo_table
, e
);
28840 /* Record the end of a source file. */
28843 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
28845 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28848 e
.code
= DW_MACINFO_end_file
;
28851 vec_safe_push (macinfo_table
, e
);
28855 /* Called from debug_define in toplev.cc. The `buffer' parameter contains
28856 the tail part of the directive line, i.e. the part which is past the
28857 initial whitespace, #, whitespace, directive-name, whitespace part. */
28860 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
28861 const char *buffer ATTRIBUTE_UNUSED
)
28863 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28866 /* Insert a dummy first entry to be able to optimize the whole
28867 predefined macro block using DW_MACRO_import. */
28868 if (macinfo_table
->is_empty () && lineno
<= 1)
28873 vec_safe_push (macinfo_table
, e
);
28875 e
.code
= DW_MACINFO_define
;
28877 e
.info
= ggc_strdup (buffer
);
28878 vec_safe_push (macinfo_table
, e
);
28882 /* Called from debug_undef in toplev.cc. The `buffer' parameter contains
28883 the tail part of the directive line, i.e. the part which is past the
28884 initial whitespace, #, whitespace, directive-name, whitespace part. */
28887 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
28888 const char *buffer ATTRIBUTE_UNUSED
)
28890 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28893 /* Insert a dummy first entry to be able to optimize the whole
28894 predefined macro block using DW_MACRO_import. */
28895 if (macinfo_table
->is_empty () && lineno
<= 1)
28900 vec_safe_push (macinfo_table
, e
);
28902 e
.code
= DW_MACINFO_undef
;
28904 e
.info
= ggc_strdup (buffer
);
28905 vec_safe_push (macinfo_table
, e
);
28909 /* Helpers to manipulate hash table of CUs. */
28911 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
28913 static inline hashval_t
hash (const macinfo_entry
*);
28914 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
28918 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
28920 return htab_hash_string (entry
->info
);
28924 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
28925 const macinfo_entry
*entry2
)
28927 return !strcmp (entry1
->info
, entry2
->info
);
28930 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
28932 /* Output a single .debug_macinfo entry. */
28935 output_macinfo_op (macinfo_entry
*ref
)
28939 struct indirect_string_node
*node
;
28940 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
28941 struct dwarf_file_data
*fd
;
28945 case DW_MACINFO_start_file
:
28946 fd
= lookup_filename (ref
->info
);
28947 file_num
= maybe_emit_file (fd
);
28948 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
28949 dw2_asm_output_data_uleb128 (ref
->lineno
,
28950 "Included from line number %lu",
28951 (unsigned long) ref
->lineno
);
28952 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
28954 case DW_MACINFO_end_file
:
28955 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
28957 case DW_MACINFO_define
:
28958 case DW_MACINFO_undef
:
28959 len
= strlen (ref
->info
) + 1;
28960 if ((!dwarf_strict
|| dwarf_version
>= 5)
28961 && len
> (size_t) dwarf_offset_size
28962 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
28963 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
28965 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
28966 ref
->code
= ref
->code
== DW_MACINFO_define
28967 ? DW_MACRO_define_strx
: DW_MACRO_undef_strx
;
28969 ref
->code
= ref
->code
== DW_MACINFO_define
28970 ? DW_MACRO_define_strp
: DW_MACRO_undef_strp
;
28971 output_macinfo_op (ref
);
28974 dw2_asm_output_data (1, ref
->code
,
28975 ref
->code
== DW_MACINFO_define
28976 ? "Define macro" : "Undefine macro");
28977 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
28978 (unsigned long) ref
->lineno
);
28979 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
28981 case DW_MACRO_define_strp
:
28982 dw2_asm_output_data (1, ref
->code
, "Define macro strp");
28983 goto do_DW_MACRO_define_strpx
;
28984 case DW_MACRO_undef_strp
:
28985 dw2_asm_output_data (1, ref
->code
, "Undefine macro strp");
28986 goto do_DW_MACRO_define_strpx
;
28987 case DW_MACRO_define_strx
:
28988 dw2_asm_output_data (1, ref
->code
, "Define macro strx");
28989 goto do_DW_MACRO_define_strpx
;
28990 case DW_MACRO_undef_strx
:
28991 dw2_asm_output_data (1, ref
->code
, "Undefine macro strx");
28993 do_DW_MACRO_define_strpx
:
28994 /* NB: dwarf2out_finish performs:
28995 1. save_macinfo_strings
28996 2. hash table traverse of index_string
28997 3. output_macinfo -> output_macinfo_op
28998 4. output_indirect_strings
28999 -> hash table traverse of output_index_string
29001 When output_macinfo_op is called, all index strings have been
29002 added to hash table by save_macinfo_strings and we can't pass
29003 INSERT to find_slot_with_hash which may expand hash table, even
29004 if no insertion is needed, and change hash table traverse order
29005 between index_string and output_index_string. */
29006 node
= find_AT_string (ref
->info
, NO_INSERT
);
29008 && (node
->form
== DW_FORM_strp
29009 || node
->form
== dwarf_FORM (DW_FORM_strx
)));
29010 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
29011 (unsigned long) ref
->lineno
);
29012 if (node
->form
== DW_FORM_strp
)
29013 dw2_asm_output_offset (dwarf_offset_size
, node
->label
,
29014 debug_str_section
, "The macro: \"%s\"",
29017 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
29020 case DW_MACRO_import
:
29021 dw2_asm_output_data (1, ref
->code
, "Import");
29022 ASM_GENERATE_INTERNAL_LABEL (label
,
29023 DEBUG_MACRO_SECTION_LABEL
,
29024 ref
->lineno
+ macinfo_label_base
);
29025 dw2_asm_output_offset (dwarf_offset_size
, label
, NULL
, NULL
);
29028 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
29029 ASM_COMMENT_START
, (unsigned long) ref
->code
);
29034 /* Attempt to make a sequence of define/undef macinfo ops shareable with
29035 other compilation unit .debug_macinfo sections. IDX is the first
29036 index of a define/undef, return the number of ops that should be
29037 emitted in a comdat .debug_macinfo section and emit
29038 a DW_MACRO_import entry referencing it.
29039 If the define/undef entry should be emitted normally, return 0. */
29042 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
29043 macinfo_hash_type
**macinfo_htab
)
29045 macinfo_entry
*first
, *second
, *cur
, *inc
;
29046 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
29047 unsigned char checksum
[16];
29048 struct md5_ctx ctx
;
29049 char *grp_name
, *tail
;
29051 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
29052 macinfo_entry
**slot
;
29054 first
= &(*macinfo_table
)[idx
];
29055 second
= &(*macinfo_table
)[idx
+ 1];
29057 /* Optimize only if there are at least two consecutive define/undef ops,
29058 and either all of them are before first DW_MACINFO_start_file
29059 with lineno {0,1} (i.e. predefined macro block), or all of them are
29060 in some included header file. */
29061 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
29063 if (vec_safe_is_empty (files
))
29065 if (first
->lineno
> 1 || second
->lineno
> 1)
29068 else if (first
->lineno
== 0)
29071 /* Find the last define/undef entry that can be grouped together
29072 with first and at the same time compute md5 checksum of their
29073 codes, linenumbers and strings. */
29074 md5_init_ctx (&ctx
);
29075 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
29076 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
29078 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
29082 unsigned char code
= cur
->code
;
29083 md5_process_bytes (&code
, 1, &ctx
);
29084 checksum_uleb128 (cur
->lineno
, &ctx
);
29085 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
29087 md5_finish_ctx (&ctx
, checksum
);
29090 /* From the containing include filename (if any) pick up just
29091 usable characters from its basename. */
29092 if (vec_safe_is_empty (files
))
29095 base
= lbasename (files
->last ().info
);
29096 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
29097 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
29098 encoded_filename_len
++;
29099 /* Count . at the end. */
29100 if (encoded_filename_len
)
29101 encoded_filename_len
++;
29103 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
29104 linebuf_len
= strlen (linebuf
);
29106 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
29107 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
29109 memcpy (grp_name
, dwarf_offset_size
== 4 ? "wm4." : "wm8.", 4);
29110 tail
= grp_name
+ 4;
29111 if (encoded_filename_len
)
29113 for (i
= 0; base
[i
]; i
++)
29114 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
29118 memcpy (tail
, linebuf
, linebuf_len
);
29119 tail
+= linebuf_len
;
29121 for (i
= 0; i
< 16; i
++)
29122 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
29124 /* Construct a macinfo_entry for DW_MACRO_import
29125 in the empty vector entry before the first define/undef. */
29126 inc
= &(*macinfo_table
)[idx
- 1];
29127 inc
->code
= DW_MACRO_import
;
29129 inc
->info
= ggc_strdup (grp_name
);
29130 if (!*macinfo_htab
)
29131 *macinfo_htab
= new macinfo_hash_type (10);
29132 /* Avoid emitting duplicates. */
29133 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
29138 /* If such an entry has been used before, just emit
29139 a DW_MACRO_import op. */
29141 output_macinfo_op (inc
);
29142 /* And clear all macinfo_entry in the range to avoid emitting them
29143 in the second pass. */
29144 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
29153 inc
->lineno
= (*macinfo_htab
)->elements ();
29154 output_macinfo_op (inc
);
29159 /* Save any strings needed by the macinfo table in the debug str
29160 table. All strings must be collected into the table by the time
29161 index_string is called. */
29164 save_macinfo_strings (void)
29168 macinfo_entry
*ref
;
29170 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
29174 /* Match the logic in output_macinfo_op to decide on
29175 indirect strings. */
29176 case DW_MACINFO_define
:
29177 case DW_MACINFO_undef
:
29178 len
= strlen (ref
->info
) + 1;
29179 if ((!dwarf_strict
|| dwarf_version
>= 5)
29180 && len
> (unsigned) dwarf_offset_size
29181 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
29182 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
29183 set_indirect_string (find_AT_string (ref
->info
));
29185 case DW_MACINFO_start_file
:
29186 /* -gsplit-dwarf -g3 will also output filename as indirect
29188 if (!dwarf_split_debug_info
)
29190 /* Fall through. */
29191 case DW_MACRO_define_strp
:
29192 case DW_MACRO_undef_strp
:
29193 case DW_MACRO_define_strx
:
29194 case DW_MACRO_undef_strx
:
29195 set_indirect_string (find_AT_string (ref
->info
));
29203 /* Output macinfo section(s). */
29206 output_macinfo (const char *debug_line_label
, bool early_lto_debug
)
29209 unsigned long length
= vec_safe_length (macinfo_table
);
29210 macinfo_entry
*ref
;
29211 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
29212 macinfo_hash_type
*macinfo_htab
= NULL
;
29213 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
29218 /* output_macinfo* uses these interchangeably. */
29219 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_define
29220 && (int) DW_MACINFO_undef
== (int) DW_MACRO_undef
29221 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_start_file
29222 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_end_file
);
29224 /* AIX Assembler inserts the length, so adjust the reference to match the
29225 offset expected by debuggers. */
29226 strcpy (dl_section_ref
, debug_line_label
);
29227 if (XCOFF_DEBUGGING_INFO
)
29228 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
29230 /* For .debug_macro emit the section header. */
29231 if (!dwarf_strict
|| dwarf_version
>= 5)
29233 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
29234 "DWARF macro version number");
29235 if (dwarf_offset_size
== 8)
29236 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
29238 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
29239 dw2_asm_output_offset (dwarf_offset_size
, debug_line_label
,
29240 debug_line_section
, NULL
);
29243 /* In the first loop, it emits the primary .debug_macinfo section
29244 and after each emitted op the macinfo_entry is cleared.
29245 If a longer range of define/undef ops can be optimized using
29246 DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
29247 the vector before the first define/undef in the range and the
29248 whole range of define/undef ops is not emitted and kept. */
29249 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
29253 case DW_MACINFO_start_file
:
29254 vec_safe_push (files
, *ref
);
29256 case DW_MACINFO_end_file
:
29257 if (!vec_safe_is_empty (files
))
29260 case DW_MACINFO_define
:
29261 case DW_MACINFO_undef
:
29262 if ((!dwarf_strict
|| dwarf_version
>= 5)
29263 && !dwarf_split_debug_info
29264 && HAVE_COMDAT_GROUP
29265 && vec_safe_length (files
) != 1
29268 && (*macinfo_table
)[i
- 1].code
== 0)
29270 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
29279 /* A dummy entry may be inserted at the beginning to be able
29280 to optimize the whole block of predefined macros. */
29286 output_macinfo_op (ref
);
29294 /* Save the number of transparent includes so we can adjust the
29295 label number for the fat LTO object DWARF. */
29296 unsigned macinfo_label_base_adj
= macinfo_htab
->elements ();
29298 delete macinfo_htab
;
29299 macinfo_htab
= NULL
;
29301 /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
29302 terminate the current chain and switch to a new comdat .debug_macinfo
29303 section and emit the define/undef entries within it. */
29304 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
29309 case DW_MACRO_import
:
29311 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
29312 tree comdat_key
= get_identifier (ref
->info
);
29313 /* Terminate the previous .debug_macinfo section. */
29314 dw2_asm_output_data (1, 0, "End compilation unit");
29315 targetm
.asm_out
.named_section (debug_macinfo_section_name
,
29319 ? SECTION_EXCLUDE
: 0),
29321 ASM_GENERATE_INTERNAL_LABEL (label
,
29322 DEBUG_MACRO_SECTION_LABEL
,
29323 ref
->lineno
+ macinfo_label_base
);
29324 ASM_OUTPUT_LABEL (asm_out_file
, label
);
29327 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
29328 "DWARF macro version number");
29329 if (dwarf_offset_size
== 8)
29330 dw2_asm_output_data (1, 1, "Flags: 64-bit");
29332 dw2_asm_output_data (1, 0, "Flags: 32-bit");
29335 case DW_MACINFO_define
:
29336 case DW_MACINFO_undef
:
29337 output_macinfo_op (ref
);
29342 gcc_unreachable ();
29345 macinfo_label_base
+= macinfo_label_base_adj
;
29348 /* As init_sections_and_labels may get called multiple times, have a
29349 generation count for labels. */
29350 static unsigned init_sections_and_labels_generation
;
29352 /* Initialize the various sections and labels for dwarf output and prefix
29353 them with PREFIX if non-NULL. Returns the generation (zero based
29354 number of times function was called). */
29357 init_sections_and_labels (bool early_lto_debug
)
29359 if (early_lto_debug
)
29361 if (!dwarf_split_debug_info
)
29363 debug_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
29364 SECTION_DEBUG
| SECTION_EXCLUDE
,
29366 debug_abbrev_section
= get_section (DEBUG_LTO_ABBREV_SECTION
,
29367 SECTION_DEBUG
| SECTION_EXCLUDE
,
29369 debug_macinfo_section_name
29370 = ((dwarf_strict
&& dwarf_version
< 5)
29371 ? DEBUG_LTO_MACINFO_SECTION
: DEBUG_LTO_MACRO_SECTION
);
29372 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
29374 | SECTION_EXCLUDE
, NULL
);
29378 /* ??? Which of the following do we need early? */
29379 debug_info_section
= get_section (DEBUG_LTO_DWO_INFO_SECTION
,
29380 SECTION_DEBUG
| SECTION_EXCLUDE
,
29382 debug_abbrev_section
= get_section (DEBUG_LTO_DWO_ABBREV_SECTION
,
29383 SECTION_DEBUG
| SECTION_EXCLUDE
,
29385 debug_skeleton_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
29387 | SECTION_EXCLUDE
, NULL
);
29388 debug_skeleton_abbrev_section
29389 = get_section (DEBUG_LTO_ABBREV_SECTION
,
29390 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29391 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
29392 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
29393 init_sections_and_labels_generation
);
29395 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
29396 stay in the main .o, but the skeleton_line goes into the split
29398 debug_skeleton_line_section
29399 = get_section (DEBUG_LTO_LINE_SECTION
,
29400 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29401 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
29402 DEBUG_SKELETON_LINE_SECTION_LABEL
,
29403 init_sections_and_labels_generation
);
29404 debug_str_offsets_section
29405 = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION
,
29406 SECTION_DEBUG
| SECTION_EXCLUDE
,
29408 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
29409 DEBUG_SKELETON_INFO_SECTION_LABEL
,
29410 init_sections_and_labels_generation
);
29411 debug_str_dwo_section
= get_section (DEBUG_LTO_STR_DWO_SECTION
,
29412 DEBUG_STR_DWO_SECTION_FLAGS
,
29414 debug_macinfo_section_name
29415 = ((dwarf_strict
&& dwarf_version
< 5)
29416 ? DEBUG_LTO_DWO_MACINFO_SECTION
: DEBUG_LTO_DWO_MACRO_SECTION
);
29417 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
29418 SECTION_DEBUG
| SECTION_EXCLUDE
,
29421 /* For macro info and the file table we have to refer to a
29422 debug_line section. */
29423 debug_line_section
= get_section (DEBUG_LTO_LINE_SECTION
,
29424 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29425 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
29426 DEBUG_LINE_SECTION_LABEL
,
29427 init_sections_and_labels_generation
);
29429 debug_str_section
= get_section (DEBUG_LTO_STR_SECTION
,
29430 DEBUG_STR_SECTION_FLAGS
29431 | SECTION_EXCLUDE
, NULL
);
29432 if (!dwarf_split_debug_info
)
29433 debug_line_str_section
29434 = get_section (DEBUG_LTO_LINE_STR_SECTION
,
29435 DEBUG_STR_SECTION_FLAGS
| SECTION_EXCLUDE
, NULL
);
29439 if (!dwarf_split_debug_info
)
29441 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
29442 SECTION_DEBUG
, NULL
);
29443 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
29444 SECTION_DEBUG
, NULL
);
29445 debug_loc_section
= get_section (dwarf_version
>= 5
29446 ? DEBUG_LOCLISTS_SECTION
29447 : DEBUG_LOC_SECTION
,
29448 SECTION_DEBUG
, NULL
);
29449 debug_macinfo_section_name
29450 = ((dwarf_strict
&& dwarf_version
< 5)
29451 ? DEBUG_MACINFO_SECTION
: DEBUG_MACRO_SECTION
);
29452 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
29453 SECTION_DEBUG
, NULL
);
29457 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
29458 SECTION_DEBUG
| SECTION_EXCLUDE
,
29460 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
29461 SECTION_DEBUG
| SECTION_EXCLUDE
,
29463 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
29464 SECTION_DEBUG
, NULL
);
29465 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
29466 SECTION_DEBUG
, NULL
);
29467 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
29468 SECTION_DEBUG
, NULL
);
29469 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
29470 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
29471 init_sections_and_labels_generation
);
29473 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
29474 stay in the main .o, but the skeleton_line goes into the
29476 debug_skeleton_line_section
29477 = get_section (DEBUG_DWO_LINE_SECTION
,
29478 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29479 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
29480 DEBUG_SKELETON_LINE_SECTION_LABEL
,
29481 init_sections_and_labels_generation
);
29482 debug_str_offsets_section
29483 = get_section (DEBUG_DWO_STR_OFFSETS_SECTION
,
29484 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29485 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
29486 DEBUG_SKELETON_INFO_SECTION_LABEL
,
29487 init_sections_and_labels_generation
);
29488 debug_loc_section
= get_section (dwarf_version
>= 5
29489 ? DEBUG_DWO_LOCLISTS_SECTION
29490 : DEBUG_DWO_LOC_SECTION
,
29491 SECTION_DEBUG
| SECTION_EXCLUDE
,
29493 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
29494 DEBUG_STR_DWO_SECTION_FLAGS
,
29496 debug_macinfo_section_name
29497 = ((dwarf_strict
&& dwarf_version
< 5)
29498 ? DEBUG_DWO_MACINFO_SECTION
: DEBUG_DWO_MACRO_SECTION
);
29499 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
29500 SECTION_DEBUG
| SECTION_EXCLUDE
,
29502 if (dwarf_version
>= 5)
29503 debug_ranges_dwo_section
29504 = get_section (DEBUG_DWO_RNGLISTS_SECTION
,
29505 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29507 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
29508 SECTION_DEBUG
, NULL
);
29509 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
29510 SECTION_DEBUG
, NULL
);
29511 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
29512 SECTION_DEBUG
, NULL
);
29513 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
29514 SECTION_DEBUG
, NULL
);
29515 debug_str_section
= get_section (DEBUG_STR_SECTION
,
29516 DEBUG_STR_SECTION_FLAGS
, NULL
);
29517 if ((!dwarf_split_debug_info
&& !output_asm_line_debug_info ())
29518 || asm_outputs_debug_line_str ())
29519 debug_line_str_section
= get_section (DEBUG_LINE_STR_SECTION
,
29520 DEBUG_STR_SECTION_FLAGS
, NULL
);
29522 debug_ranges_section
= get_section (dwarf_version
>= 5
29523 ? DEBUG_RNGLISTS_SECTION
29524 : DEBUG_RANGES_SECTION
,
29525 SECTION_DEBUG
, NULL
);
29526 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
29527 SECTION_DEBUG
, NULL
);
29530 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
29531 DEBUG_ABBREV_SECTION_LABEL
,
29532 init_sections_and_labels_generation
);
29533 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
29534 DEBUG_INFO_SECTION_LABEL
,
29535 init_sections_and_labels_generation
);
29536 info_section_emitted
= false;
29537 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
29538 DEBUG_LINE_SECTION_LABEL
,
29539 init_sections_and_labels_generation
);
29540 /* There are up to 6 unique ranges labels per generation.
29541 See also output_rnglists. */
29542 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
29543 DEBUG_RANGES_SECTION_LABEL
,
29544 init_sections_and_labels_generation
* 6);
29545 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
29546 ASM_GENERATE_INTERNAL_LABEL (ranges_base_label
,
29547 DEBUG_RANGES_SECTION_LABEL
,
29548 1 + init_sections_and_labels_generation
* 6);
29549 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
29550 DEBUG_ADDR_SECTION_LABEL
,
29551 init_sections_and_labels_generation
);
29552 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
29553 (dwarf_strict
&& dwarf_version
< 5)
29554 ? DEBUG_MACINFO_SECTION_LABEL
29555 : DEBUG_MACRO_SECTION_LABEL
,
29556 init_sections_and_labels_generation
);
29557 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
,
29558 init_sections_and_labels_generation
);
29560 ++init_sections_and_labels_generation
;
29561 return init_sections_and_labels_generation
- 1;
29564 /* Set up for Dwarf output at the start of compilation. */
29567 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
29569 /* Allocate the file_table. */
29570 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
29572 #ifndef DWARF2_LINENO_DEBUGGING_INFO
29573 /* Allocate the decl_die_table. */
29574 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
29576 /* Allocate the decl_loc_table. */
29577 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
29579 /* Allocate the cached_dw_loc_list_table. */
29580 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
29582 /* Allocate the initial hunk of the abbrev_die_table. */
29583 vec_alloc (abbrev_die_table
, 256);
29584 /* Zero-th entry is allocated, but unused. */
29585 abbrev_die_table
->quick_push (NULL
);
29587 /* Allocate the dwarf_proc_stack_usage_map. */
29588 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
29590 /* Allocate the pubtypes and pubnames vectors. */
29591 vec_alloc (pubname_table
, 32);
29592 vec_alloc (pubtype_table
, 32);
29594 vec_alloc (incomplete_types
, 64);
29596 vec_alloc (used_rtx_array
, 32);
29598 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
29599 vec_alloc (macinfo_table
, 64);
29602 /* If front-ends already registered a main translation unit but we were not
29603 ready to perform the association, do this now. */
29604 if (main_translation_unit
!= NULL_TREE
)
29605 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
29608 /* Called before compile () starts outputtting functions, variables
29609 and toplevel asms into assembly. */
29612 dwarf2out_assembly_start (void)
29614 if (text_section_line_info
)
29617 #ifndef DWARF2_LINENO_DEBUGGING_INFO
29618 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
29619 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
29620 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
29621 COLD_TEXT_SECTION_LABEL
, 0);
29622 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
29624 switch_to_section (text_section
);
29625 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
29628 /* Make sure the line number table for .text always exists. */
29629 text_section_line_info
= new_line_info_table ();
29630 text_section_line_info
->end_label
= text_end_label
;
29632 #ifdef DWARF2_LINENO_DEBUGGING_INFO
29633 cur_line_info_table
= text_section_line_info
;
29636 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
29637 && dwarf2out_do_cfi_asm ()
29638 && !dwarf2out_do_eh_frame ())
29639 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
29641 #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
29642 if (output_asm_line_debug_info () && dwarf_version
>= 5)
29644 /* When gas outputs DWARF5 .debug_line[_str] then we have to
29645 tell it the comp_dir and main file name for the zero entry
29647 const char *comp_dir
, *filename0
;
29649 comp_dir
= comp_dir_string ();
29650 if (comp_dir
== NULL
)
29653 filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
29654 if (filename0
== NULL
)
29657 fprintf (asm_out_file
, "\t.file 0 ");
29658 output_quoted_string (asm_out_file
, remap_debug_filename (comp_dir
));
29659 fputc (' ', asm_out_file
);
29660 output_quoted_string (asm_out_file
, remap_debug_filename (filename0
));
29661 fputc ('\n', asm_out_file
);
29665 /* Work around for PR101575: output a dummy .file directive. */
29666 if (!last_emitted_file
&& dwarf_debuginfo_p ()
29667 && debug_info_level
>= DINFO_LEVEL_TERSE
)
29669 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
29671 if (filename0
== NULL
)
29672 filename0
= "<dummy>";
29673 maybe_emit_file (lookup_filename (filename0
));
29677 /* A helper function for dwarf2out_finish called through
29678 htab_traverse. Assign a string its index. All strings must be
29679 collected into the table by the time index_string is called,
29680 because the indexing code relies on htab_traverse to traverse nodes
29681 in the same order for each run. */
29684 index_string (indirect_string_node
**h
, unsigned int *index
)
29686 indirect_string_node
*node
= *h
;
29688 find_string_form (node
);
29689 if (node
->form
== dwarf_FORM (DW_FORM_strx
) && node
->refcount
> 0)
29691 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
29692 node
->index
= *index
;
29698 /* A helper function for output_indirect_strings called through
29699 htab_traverse. Output the offset to a string and update the
29703 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
29705 indirect_string_node
*node
= *h
;
29707 if (node
->form
== dwarf_FORM (DW_FORM_strx
) && node
->refcount
> 0)
29709 /* Assert that this node has been assigned an index. */
29710 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
29711 && node
->index
!= NOT_INDEXED
);
29712 dw2_asm_output_data (dwarf_offset_size
, *offset
,
29713 "indexed string 0x%x: %s", node
->index
, node
->str
);
29714 *offset
+= strlen (node
->str
) + 1;
29719 /* A helper function for dwarf2out_finish called through
29720 htab_traverse. Output the indexed string. */
29723 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
29725 struct indirect_string_node
*node
= *h
;
29727 if (node
->form
== dwarf_FORM (DW_FORM_strx
) && node
->refcount
> 0)
29729 /* Assert that the strings are output in the same order as their
29730 indexes were assigned. */
29731 gcc_assert (*cur_idx
== node
->index
);
29732 assemble_string (node
->str
, strlen (node
->str
) + 1);
29738 /* A helper function for output_indirect_strings. Counts the number
29739 of index strings offsets. Must match the logic of the functions
29740 output_index_string[_offsets] above. */
29742 count_index_strings (indirect_string_node
**h
, unsigned int *last_idx
)
29744 struct indirect_string_node
*node
= *h
;
29746 if (node
->form
== dwarf_FORM (DW_FORM_strx
) && node
->refcount
> 0)
29751 /* A helper function for dwarf2out_finish called through
29752 htab_traverse. Emit one queued .debug_str string. */
29755 output_indirect_string (indirect_string_node
**h
, enum dwarf_form form
)
29757 struct indirect_string_node
*node
= *h
;
29759 node
->form
= find_string_form (node
);
29760 if (node
->form
== form
&& node
->refcount
> 0)
29762 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
29763 assemble_string (node
->str
, strlen (node
->str
) + 1);
29769 /* Output the indexed string table. */
29772 output_indirect_strings (void)
29774 switch_to_section (debug_str_section
);
29775 if (!dwarf_split_debug_info
)
29776 debug_str_hash
->traverse
<enum dwarf_form
,
29777 output_indirect_string
> (DW_FORM_strp
);
29780 unsigned int offset
= 0;
29781 unsigned int cur_idx
= 0;
29783 if (skeleton_debug_str_hash
)
29784 skeleton_debug_str_hash
->traverse
<enum dwarf_form
,
29785 output_indirect_string
> (DW_FORM_strp
);
29787 switch_to_section (debug_str_offsets_section
);
29788 /* For DWARF5 the .debug_str_offsets[.dwo] section needs a unit
29789 header. Note that we don't need to generate a label to the
29790 actual index table following the header here, because this is
29791 for the split dwarf case only. In an .dwo file there is only
29792 one string offsets table (and one debug info section). But
29793 if we would start using string offset tables for the main (or
29794 skeleton) unit, then we have to add a DW_AT_str_offsets_base
29795 pointing to the actual index after the header. Split dwarf
29796 units will never have a string offsets base attribute. When
29797 a split unit is moved into a .dwp file the string offsets can
29798 be found through the .debug_cu_index section table. */
29799 if (dwarf_version
>= 5)
29801 unsigned int last_idx
= 0;
29802 unsigned long str_offsets_length
;
29804 debug_str_hash
->traverse_noresize
29805 <unsigned int *, count_index_strings
> (&last_idx
);
29806 str_offsets_length
= last_idx
* dwarf_offset_size
+ 4;
29807 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
29808 dw2_asm_output_data (4, 0xffffffff,
29809 "Escape value for 64-bit DWARF extension");
29810 dw2_asm_output_data (dwarf_offset_size
, str_offsets_length
,
29811 "Length of string offsets unit");
29812 dw2_asm_output_data (2, 5, "DWARF string offsets version");
29813 dw2_asm_output_data (2, 0, "Header zero padding");
29815 debug_str_hash
->traverse_noresize
29816 <unsigned int *, output_index_string_offset
> (&offset
);
29817 switch_to_section (debug_str_dwo_section
);
29818 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
29823 /* Callback for htab_traverse to assign an index to an entry in the
29824 table, and to write that entry to the .debug_addr section. */
29827 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
29829 addr_table_entry
*entry
= *slot
;
29831 if (entry
->refcount
== 0)
29833 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
29834 || entry
->index
== NOT_INDEXED
);
29838 gcc_assert (entry
->index
== *cur_index
);
29841 switch (entry
->kind
)
29844 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
29845 "0x%x", entry
->index
);
29847 case ate_kind_rtx_dtprel
:
29848 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
29849 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
29852 fputc ('\n', asm_out_file
);
29854 case ate_kind_label
:
29855 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
29856 "0x%x", entry
->index
);
29859 gcc_unreachable ();
29864 /* A helper function for dwarf2out_finish. Counts the number
29865 of indexed addresses. Must match the logic of the functions
29866 output_addr_table_entry above. */
29868 count_index_addrs (addr_table_entry
**slot
, unsigned int *last_idx
)
29870 addr_table_entry
*entry
= *slot
;
29872 if (entry
->refcount
> 0)
29877 /* Produce the .debug_addr section. */
29880 output_addr_table (void)
29882 unsigned int index
= 0;
29883 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
29886 switch_to_section (debug_addr_section
);
29887 /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission
29888 which GCC uses to implement -gsplit-dwarf as DWARF GNU extension
29889 before DWARF5, didn't have a header for .debug_addr units.
29890 DWARF5 specifies a small header when address tables are used. */
29891 if (dwarf_version
>= 5)
29893 unsigned int last_idx
= 0;
29894 unsigned long addrs_length
;
29896 addr_index_table
->traverse_noresize
29897 <unsigned int *, count_index_addrs
> (&last_idx
);
29898 addrs_length
= last_idx
* DWARF2_ADDR_SIZE
+ 4;
29900 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
29901 dw2_asm_output_data (4, 0xffffffff,
29902 "Escape value for 64-bit DWARF extension");
29903 dw2_asm_output_data (dwarf_offset_size
, addrs_length
,
29904 "Length of Address Unit");
29905 dw2_asm_output_data (2, 5, "DWARF addr version");
29906 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
29907 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
29909 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
29912 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
29915 #if ENABLE_ASSERT_CHECKING
29916 /* Verify that all marks are clear. */
29919 verify_marks_clear (dw_die_ref die
)
29923 gcc_assert (! die
->die_mark
);
29924 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
29926 #endif /* ENABLE_ASSERT_CHECKING */
29928 /* Clear the marks for a die and its children.
29929 Be cool if the mark isn't set. */
29932 prune_unmark_dies (dw_die_ref die
)
29938 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
29941 /* Given LOC that is referenced by a DIE we're marking as used, find all
29942 referenced DWARF procedures it references and mark them as used. */
29945 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
29947 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
29948 switch (loc
->dw_loc_opc
)
29950 case DW_OP_implicit_pointer
:
29951 case DW_OP_convert
:
29952 case DW_OP_reinterpret
:
29953 case DW_OP_GNU_implicit_pointer
:
29954 case DW_OP_GNU_convert
:
29955 case DW_OP_GNU_reinterpret
:
29956 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
29957 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
29959 case DW_OP_GNU_variable_value
:
29960 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
29963 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
29966 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
29967 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
29968 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
29973 case DW_OP_call_ref
:
29974 case DW_OP_const_type
:
29975 case DW_OP_GNU_const_type
:
29976 case DW_OP_GNU_parameter_ref
:
29977 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
29978 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
29980 case DW_OP_regval_type
:
29981 case DW_OP_deref_type
:
29982 case DW_OP_GNU_regval_type
:
29983 case DW_OP_GNU_deref_type
:
29984 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
29985 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
29987 case DW_OP_entry_value
:
29988 case DW_OP_GNU_entry_value
:
29989 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
29990 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
29997 /* Given DIE that we're marking as used, find any other dies
29998 it references as attributes and mark them as used. */
30001 prune_unused_types_walk_attribs (dw_die_ref die
)
30006 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30008 switch (AT_class (a
))
30010 /* Make sure DWARF procedures referenced by location descriptions will
30012 case dw_val_class_loc
:
30013 prune_unused_types_walk_loc_descr (AT_loc (a
));
30015 case dw_val_class_loc_list
:
30016 for (dw_loc_list_ref list
= AT_loc_list (a
);
30018 list
= list
->dw_loc_next
)
30019 prune_unused_types_walk_loc_descr (list
->expr
);
30022 case dw_val_class_view_list
:
30023 /* This points to a loc_list in another attribute, so it's
30024 already covered. */
30027 case dw_val_class_die_ref
:
30028 /* A reference to another DIE.
30029 Make sure that it will get emitted.
30030 If it was broken out into a comdat group, don't follow it. */
30031 if (! AT_ref (a
)->comdat_type_p
30032 || a
->dw_attr
== DW_AT_specification
)
30033 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
30036 case dw_val_class_str
:
30037 /* Set the string's refcount to 0 so that prune_unused_types_mark
30038 accounts properly for it. */
30039 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
30048 /* Mark the generic parameters and arguments children DIEs of DIE. */
30051 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
30055 if (die
== NULL
|| die
->die_child
== NULL
)
30057 c
= die
->die_child
;
30060 if (is_template_parameter (c
))
30061 prune_unused_types_mark (c
, 1);
30063 } while (c
&& c
!= die
->die_child
);
30066 /* Mark DIE as being used. If DOKIDS is true, then walk down
30067 to DIE's children. */
30070 prune_unused_types_mark (dw_die_ref die
, int dokids
)
30074 if (die
->die_mark
== 0)
30076 /* We haven't done this node yet. Mark it as used. */
30078 /* If this is the DIE of a generic type instantiation,
30079 mark the children DIEs that describe its generic parms and
30081 prune_unused_types_mark_generic_parms_dies (die
);
30083 /* We also have to mark its parents as used.
30084 (But we don't want to mark our parent's kids due to this,
30085 unless it is a class.) */
30086 if (die
->die_parent
)
30087 prune_unused_types_mark (die
->die_parent
,
30088 class_scope_p (die
->die_parent
));
30090 /* Mark any referenced nodes. */
30091 prune_unused_types_walk_attribs (die
);
30093 /* If this node is a specification,
30094 also mark the definition, if it exists. */
30095 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
30096 prune_unused_types_mark (die
->die_definition
, 1);
30099 if (dokids
&& die
->die_mark
!= 2)
30101 /* We need to walk the children, but haven't done so yet.
30102 Remember that we've walked the kids. */
30105 /* If this is an array type, we need to make sure our
30106 kids get marked, even if they're types. If we're
30107 breaking out types into comdat sections, do this
30108 for all type definitions. */
30109 if (die
->die_tag
== DW_TAG_array_type
30110 || (use_debug_types
30111 && is_type_die (die
) && ! is_declaration_die (die
)))
30112 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
30114 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
30118 /* For local classes, look if any static member functions were emitted
30119 and if so, mark them. */
30122 prune_unused_types_walk_local_classes (dw_die_ref die
)
30126 if (die
->die_mark
== 2)
30129 switch (die
->die_tag
)
30131 case DW_TAG_structure_type
:
30132 case DW_TAG_union_type
:
30133 case DW_TAG_class_type
:
30134 case DW_TAG_interface_type
:
30137 case DW_TAG_subprogram
:
30138 if (!get_AT_flag (die
, DW_AT_declaration
)
30139 || die
->die_definition
!= NULL
)
30140 prune_unused_types_mark (die
, 1);
30147 /* Mark children. */
30148 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
30151 /* Walk the tree DIE and mark types that we actually use. */
30154 prune_unused_types_walk (dw_die_ref die
)
30158 /* Don't do anything if this node is already marked and
30159 children have been marked as well. */
30160 if (die
->die_mark
== 2)
30163 switch (die
->die_tag
)
30165 case DW_TAG_structure_type
:
30166 case DW_TAG_union_type
:
30167 case DW_TAG_class_type
:
30168 case DW_TAG_interface_type
:
30169 if (die
->die_perennial_p
)
30172 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
30173 if (c
->die_tag
== DW_TAG_subprogram
)
30176 /* Finding used static member functions inside of classes
30177 is needed just for local classes, because for other classes
30178 static member function DIEs with DW_AT_specification
30179 are emitted outside of the DW_TAG_*_type. If we ever change
30180 it, we'd need to call this even for non-local classes. */
30182 prune_unused_types_walk_local_classes (die
);
30184 /* It's a type node --- don't mark it. */
30187 case DW_TAG_const_type
:
30188 case DW_TAG_packed_type
:
30189 case DW_TAG_pointer_type
:
30190 case DW_TAG_reference_type
:
30191 case DW_TAG_rvalue_reference_type
:
30192 case DW_TAG_volatile_type
:
30193 case DW_TAG_restrict_type
:
30194 case DW_TAG_shared_type
:
30195 case DW_TAG_atomic_type
:
30196 case DW_TAG_immutable_type
:
30197 case DW_TAG_typedef
:
30198 case DW_TAG_array_type
:
30199 case DW_TAG_coarray_type
:
30200 case DW_TAG_friend
:
30201 case DW_TAG_enumeration_type
:
30202 case DW_TAG_subroutine_type
:
30203 case DW_TAG_string_type
:
30204 case DW_TAG_set_type
:
30205 case DW_TAG_subrange_type
:
30206 case DW_TAG_ptr_to_member_type
:
30207 case DW_TAG_file_type
:
30208 case DW_TAG_unspecified_type
:
30209 case DW_TAG_dynamic_type
:
30210 /* Type nodes are useful only when other DIEs reference them --- don't
30214 case DW_TAG_dwarf_procedure
:
30215 /* Likewise for DWARF procedures. */
30217 if (die
->die_perennial_p
)
30222 case DW_TAG_variable
:
30223 if (flag_debug_only_used_symbols
)
30225 if (die
->die_perennial_p
)
30228 /* For static data members, the declaration in the class is supposed
30229 to have DW_TAG_member tag in DWARF{3,4} but DW_TAG_variable in
30230 DWARF5. DW_TAG_member will be marked, so mark even such
30231 DW_TAG_variables in DWARF5, as long as it has DW_AT_const_value
30233 if (dwarf_version
>= 5
30234 && class_scope_p (die
->die_parent
)
30235 && get_AT (die
, DW_AT_const_value
))
30238 /* premark_used_variables marks external variables --- don't mark
30239 them here. But function-local externals are always considered
30241 if (get_AT (die
, DW_AT_external
))
30243 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
30244 if (c
->die_tag
== DW_TAG_subprogram
)
30253 /* Mark everything else. */
30257 if (die
->die_mark
== 0)
30261 /* Now, mark any dies referenced from here. */
30262 prune_unused_types_walk_attribs (die
);
30267 /* Mark children. */
30268 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
30271 /* Increment the string counts on strings referred to from DIE's
30275 prune_unused_types_update_strings (dw_die_ref die
)
30280 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30281 if (AT_class (a
) == dw_val_class_str
)
30283 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
30285 /* Avoid unnecessarily putting strings that are used less than
30286 twice in the hash table. */
30287 if (s
->form
!= DW_FORM_line_strp
30289 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2)))
30291 indirect_string_node
**slot
30292 = debug_str_hash
->find_slot_with_hash (s
->str
,
30293 htab_hash_string (s
->str
),
30295 gcc_assert (*slot
== NULL
);
30301 /* Mark DIE and its children as removed. */
30304 mark_removed (dw_die_ref die
)
30307 die
->removed
= true;
30308 FOR_EACH_CHILD (die
, c
, mark_removed (c
));
30311 /* Remove from the tree DIE any dies that aren't marked. */
30314 prune_unused_types_prune (dw_die_ref die
)
30318 gcc_assert (die
->die_mark
);
30319 prune_unused_types_update_strings (die
);
30321 if (! die
->die_child
)
30324 c
= die
->die_child
;
30326 dw_die_ref prev
= c
, next
;
30327 for (c
= c
->die_sib
; ! c
->die_mark
; c
= next
)
30328 if (c
== die
->die_child
)
30330 /* No marked children between 'prev' and the end of the list. */
30332 /* No marked children at all. */
30333 die
->die_child
= NULL
;
30336 prev
->die_sib
= c
->die_sib
;
30337 die
->die_child
= prev
;
30350 if (c
!= prev
->die_sib
)
30352 prune_unused_types_prune (c
);
30353 } while (c
!= die
->die_child
);
30356 /* Remove dies representing declarations that we never use. */
30359 prune_unused_types (void)
30362 limbo_die_node
*node
;
30363 comdat_type_node
*ctnode
;
30364 pubname_entry
*pub
;
30365 dw_die_ref base_type
;
30367 #if ENABLE_ASSERT_CHECKING
30368 /* All the marks should already be clear. */
30369 verify_marks_clear (comp_unit_die ());
30370 for (node
= limbo_die_list
; node
; node
= node
->next
)
30371 verify_marks_clear (node
->die
);
30372 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
30373 verify_marks_clear (ctnode
->root_die
);
30374 #endif /* ENABLE_ASSERT_CHECKING */
30376 /* Mark types that are used in global variables. */
30377 premark_types_used_by_global_vars ();
30379 /* Mark variables used in the symtab. */
30380 if (flag_debug_only_used_symbols
)
30381 premark_used_variables ();
30383 /* Set the mark on nodes that are actually used. */
30384 prune_unused_types_walk (comp_unit_die ());
30385 for (node
= limbo_die_list
; node
; node
= node
->next
)
30386 prune_unused_types_walk (node
->die
);
30387 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
30389 prune_unused_types_walk (ctnode
->root_die
);
30390 prune_unused_types_mark (ctnode
->type_die
, 1);
30393 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
30394 are unusual in that they are pubnames that are the children of pubtypes.
30395 They should only be marked via their parent DW_TAG_enumeration_type die,
30396 not as roots in themselves. */
30397 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
30398 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
30399 prune_unused_types_mark (pub
->die
, 1);
30400 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
30401 prune_unused_types_mark (base_type
, 1);
30403 /* Also set the mark on nodes that could be referenced by
30404 DW_TAG_call_site DW_AT_call_origin (i.e. direct call callees) or
30405 by DW_TAG_inlined_subroutine origins. */
30406 cgraph_node
*cnode
;
30407 FOR_EACH_FUNCTION (cnode
)
30408 if (cnode
->referred_to_p (false))
30410 dw_die_ref die
= lookup_decl_die (cnode
->decl
);
30411 if (die
== NULL
|| die
->die_mark
)
30413 for (cgraph_edge
*e
= cnode
->callers
; e
; e
= e
->next_caller
)
30414 if (e
->caller
!= cnode
)
30416 prune_unused_types_mark (die
, 1);
30421 if (debug_str_hash
)
30422 debug_str_hash
->empty ();
30423 if (skeleton_debug_str_hash
)
30424 skeleton_debug_str_hash
->empty ();
30425 prune_unused_types_prune (comp_unit_die ());
30426 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
30429 if (!node
->die
->die_mark
)
30430 *pnode
= node
->next
;
30433 prune_unused_types_prune (node
->die
);
30434 pnode
= &node
->next
;
30437 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
30438 prune_unused_types_prune (ctnode
->root_die
);
30440 /* Leave the marks clear. */
30441 prune_unmark_dies (comp_unit_die ());
30442 for (node
= limbo_die_list
; node
; node
= node
->next
)
30443 prune_unmark_dies (node
->die
);
30444 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
30445 prune_unmark_dies (ctnode
->root_die
);
30448 /* Helpers to manipulate hash table of comdat type units. */
30450 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
30452 static inline hashval_t
hash (const comdat_type_node
*);
30453 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
30457 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
30460 memcpy (&h
, type_node
->signature
, sizeof (h
));
30465 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
30466 const comdat_type_node
*type_node_2
)
30468 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
30469 DWARF_TYPE_SIGNATURE_SIZE
));
30472 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
30473 to the location it would have been added, should we know its
30474 DECL_ASSEMBLER_NAME when we added other attributes. This will
30475 probably improve compactness of debug info, removing equivalent
30476 abbrevs, and hide any differences caused by deferring the
30477 computation of the assembler name, triggered by e.g. PCH. */
30480 move_linkage_attr (dw_die_ref die
)
30482 unsigned ix
= vec_safe_length (die
->die_attr
);
30483 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
30485 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
30486 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
30490 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
30492 if (prev
->dw_attr
== DW_AT_decl_line
30493 || prev
->dw_attr
== DW_AT_decl_column
30494 || prev
->dw_attr
== DW_AT_name
)
30498 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
30500 die
->die_attr
->pop ();
30501 die
->die_attr
->quick_insert (ix
, linkage
);
30505 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
30506 referenced from typed stack ops and count how often they are used. */
30509 mark_base_types (dw_loc_descr_ref loc
)
30511 dw_die_ref base_type
= NULL
;
30513 for (; loc
; loc
= loc
->dw_loc_next
)
30515 switch (loc
->dw_loc_opc
)
30517 case DW_OP_regval_type
:
30518 case DW_OP_deref_type
:
30519 case DW_OP_GNU_regval_type
:
30520 case DW_OP_GNU_deref_type
:
30521 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
30523 case DW_OP_convert
:
30524 case DW_OP_reinterpret
:
30525 case DW_OP_GNU_convert
:
30526 case DW_OP_GNU_reinterpret
:
30527 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
30530 case DW_OP_const_type
:
30531 case DW_OP_GNU_const_type
:
30532 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
30534 case DW_OP_entry_value
:
30535 case DW_OP_GNU_entry_value
:
30536 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
30541 gcc_assert (base_type
->die_parent
== comp_unit_die ());
30542 if (base_type
->die_mark
)
30543 base_type
->die_mark
++;
30546 base_types
.safe_push (base_type
);
30547 base_type
->die_mark
= 1;
30552 /* Stripped-down variant of resolve_addr, mark DW_TAG_base_type nodes
30553 referenced from typed stack ops and count how often they are used. */
30556 mark_base_types (dw_die_ref die
)
30560 dw_loc_list_ref
*curr
;
30563 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30564 switch (AT_class (a
))
30566 case dw_val_class_loc_list
:
30567 curr
= AT_loc_list_ptr (a
);
30570 mark_base_types ((*curr
)->expr
);
30571 curr
= &(*curr
)->dw_loc_next
;
30575 case dw_val_class_loc
:
30576 mark_base_types (AT_loc (a
));
30583 FOR_EACH_CHILD (die
, c
, mark_base_types (c
));
30586 /* Comparison function for sorting marked base types. */
30589 base_type_cmp (const void *x
, const void *y
)
30591 dw_die_ref dx
= *(const dw_die_ref
*) x
;
30592 dw_die_ref dy
= *(const dw_die_ref
*) y
;
30593 unsigned int byte_size1
, byte_size2
;
30594 unsigned int encoding1
, encoding2
;
30595 unsigned int align1
, align2
;
30596 if (dx
->die_mark
> dy
->die_mark
)
30598 if (dx
->die_mark
< dy
->die_mark
)
30600 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
30601 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
30602 if (byte_size1
< byte_size2
)
30604 if (byte_size1
> byte_size2
)
30606 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
30607 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
30608 if (encoding1
< encoding2
)
30610 if (encoding1
> encoding2
)
30612 align1
= get_AT_unsigned (dx
, DW_AT_alignment
);
30613 align2
= get_AT_unsigned (dy
, DW_AT_alignment
);
30614 if (align1
< align2
)
30616 if (align1
> align2
)
30621 /* Move base types marked by mark_base_types as early as possible
30622 in the CU, sorted by decreasing usage count both to make the
30623 uleb128 references as small as possible and to make sure they
30624 will have die_offset already computed by calc_die_sizes when
30625 sizes of typed stack loc ops is computed. */
30628 move_marked_base_types (void)
30631 dw_die_ref base_type
, die
, c
;
30633 if (base_types
.is_empty ())
30636 /* Sort by decreasing usage count, they will be added again in that
30638 base_types
.qsort (base_type_cmp
);
30639 die
= comp_unit_die ();
30640 c
= die
->die_child
;
30643 dw_die_ref prev
= c
;
30645 while (c
->die_mark
)
30647 remove_child_with_prev (c
, prev
);
30648 /* As base types got marked, there must be at least
30649 one node other than DW_TAG_base_type. */
30650 gcc_assert (die
->die_child
!= NULL
);
30654 while (c
!= die
->die_child
);
30655 gcc_assert (die
->die_child
);
30656 c
= die
->die_child
;
30657 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
30659 base_type
->die_mark
= 0;
30660 base_type
->die_sib
= c
->die_sib
;
30661 c
->die_sib
= base_type
;
30666 /* Helper function for resolve_addr, attempt to resolve
30667 one CONST_STRING, return true if successful. Similarly verify that
30668 SYMBOL_REFs refer to variables emitted in the current CU. */
30671 resolve_one_addr (rtx
*addr
)
30675 if (GET_CODE (rtl
) == CONST_STRING
)
30677 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
30678 tree t
= build_string (len
, XSTR (rtl
, 0));
30679 tree tlen
= size_int (len
- 1);
30681 = build_array_type (char_type_node
, build_index_type (tlen
));
30682 rtl
= lookup_constant_def (t
);
30683 if (!rtl
|| !MEM_P (rtl
))
30685 rtl
= XEXP (rtl
, 0);
30686 if (GET_CODE (rtl
) == SYMBOL_REF
30687 && SYMBOL_REF_DECL (rtl
)
30688 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
30690 vec_safe_push (used_rtx_array
, rtl
);
30695 if (GET_CODE (rtl
) == SYMBOL_REF
30696 && SYMBOL_REF_DECL (rtl
))
30698 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
30700 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
30703 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
30707 if (GET_CODE (rtl
) == CONST
)
30709 subrtx_ptr_iterator::array_type array
;
30710 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
30711 if (!resolve_one_addr (*iter
))
30718 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
30719 if possible, and create DW_TAG_dwarf_procedure that can be referenced
30720 from DW_OP_implicit_pointer if the string hasn't been seen yet. */
30723 string_cst_pool_decl (tree t
)
30725 rtx rtl
= output_constant_def (t
, 1);
30726 unsigned char *array
;
30727 dw_loc_descr_ref l
;
30732 if (!rtl
|| !MEM_P (rtl
))
30734 rtl
= XEXP (rtl
, 0);
30735 if (GET_CODE (rtl
) != SYMBOL_REF
30736 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
30739 decl
= SYMBOL_REF_DECL (rtl
);
30740 if (!lookup_decl_die (decl
))
30742 len
= TREE_STRING_LENGTH (t
);
30743 vec_safe_push (used_rtx_array
, rtl
);
30744 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
30745 array
= ggc_vec_alloc
<unsigned char> (len
);
30746 memcpy (array
, TREE_STRING_POINTER (t
), len
);
30747 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
30748 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
30749 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
30750 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
30751 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
30752 add_AT_loc (ref
, DW_AT_location
, l
);
30753 equate_decl_number_to_die (decl
, ref
);
30758 /* Helper function of resolve_addr_in_expr. LOC is
30759 a DW_OP_addr followed by DW_OP_stack_value, either at the start
30760 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
30761 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
30762 with DW_OP_implicit_pointer if possible
30763 and return true, if unsuccessful, return false. */
30766 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
30768 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
30769 HOST_WIDE_INT offset
= 0;
30770 dw_die_ref ref
= NULL
;
30773 if (GET_CODE (rtl
) == CONST
30774 && GET_CODE (XEXP (rtl
, 0)) == PLUS
30775 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
30777 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
30778 rtl
= XEXP (XEXP (rtl
, 0), 0);
30780 if (GET_CODE (rtl
) == CONST_STRING
)
30782 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
30783 tree t
= build_string (len
, XSTR (rtl
, 0));
30784 tree tlen
= size_int (len
- 1);
30787 = build_array_type (char_type_node
, build_index_type (tlen
));
30788 rtl
= string_cst_pool_decl (t
);
30792 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
30794 decl
= SYMBOL_REF_DECL (rtl
);
30795 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
30797 ref
= lookup_decl_die (decl
);
30798 if (ref
&& (get_AT (ref
, DW_AT_location
)
30799 || get_AT (ref
, DW_AT_const_value
)))
30801 loc
->dw_loc_opc
= dwarf_OP (DW_OP_implicit_pointer
);
30802 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30803 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
30804 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30805 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30806 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
30807 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
30815 /* Helper function for resolve_addr, handle one location
30816 expression, return false if at least one CONST_STRING or SYMBOL_REF in
30817 the location list couldn't be resolved. */
30820 resolve_addr_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
30822 dw_loc_descr_ref keep
= NULL
;
30823 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
30824 switch (loc
->dw_loc_opc
)
30827 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
30830 || prev
->dw_loc_opc
== DW_OP_piece
30831 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
30832 && loc
->dw_loc_next
30833 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
30834 && (!dwarf_strict
|| dwarf_version
>= 5)
30835 && optimize_one_addr_into_implicit_ptr (loc
))
30840 case DW_OP_GNU_addr_index
:
30842 case DW_OP_GNU_const_index
:
30844 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
30845 || loc
->dw_loc_opc
== DW_OP_addrx
)
30846 || ((loc
->dw_loc_opc
== DW_OP_GNU_const_index
30847 || loc
->dw_loc_opc
== DW_OP_constx
)
30850 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
30851 if (!resolve_one_addr (&rtl
))
30853 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
30854 loc
->dw_loc_oprnd1
.val_entry
30855 = add_addr_table_entry (rtl
, ate_kind_rtx
);
30858 case DW_OP_const4u
:
30859 case DW_OP_const8u
:
30861 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
30864 case DW_OP_plus_uconst
:
30865 if (size_of_loc_descr (loc
)
30866 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
30868 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
30870 dw_loc_descr_ref repl
30871 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
30872 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
30873 add_loc_descr (&repl
, loc
->dw_loc_next
);
30877 case DW_OP_implicit_value
:
30878 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
30879 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
30882 case DW_OP_implicit_pointer
:
30883 case DW_OP_GNU_implicit_pointer
:
30884 case DW_OP_GNU_parameter_ref
:
30885 case DW_OP_GNU_variable_value
:
30886 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
30889 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
30892 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30893 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30894 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30896 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
)
30899 && loc
->dw_loc_next
== NULL
30900 && AT_class (a
) == dw_val_class_loc
)
30901 switch (a
->dw_attr
)
30903 /* Following attributes allow both exprloc and reference,
30904 so if the whole expression is DW_OP_GNU_variable_value
30905 alone we could transform it into reference. */
30906 case DW_AT_byte_size
:
30907 case DW_AT_bit_size
:
30908 case DW_AT_lower_bound
:
30909 case DW_AT_upper_bound
:
30910 case DW_AT_bit_stride
:
30912 case DW_AT_allocated
:
30913 case DW_AT_associated
:
30914 case DW_AT_byte_stride
:
30915 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
30916 a
->dw_attr_val
.val_entry
= NULL
;
30917 a
->dw_attr_val
.v
.val_die_ref
.die
30918 = loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
30919 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
30928 case DW_OP_const_type
:
30929 case DW_OP_regval_type
:
30930 case DW_OP_deref_type
:
30931 case DW_OP_convert
:
30932 case DW_OP_reinterpret
:
30933 case DW_OP_GNU_const_type
:
30934 case DW_OP_GNU_regval_type
:
30935 case DW_OP_GNU_deref_type
:
30936 case DW_OP_GNU_convert
:
30937 case DW_OP_GNU_reinterpret
:
30938 while (loc
->dw_loc_next
30939 && (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_convert
30940 || loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
))
30942 dw_die_ref base1
, base2
;
30943 unsigned enc1
, enc2
, size1
, size2
;
30944 if (loc
->dw_loc_opc
== DW_OP_regval_type
30945 || loc
->dw_loc_opc
== DW_OP_deref_type
30946 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
30947 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
30948 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
30949 else if (loc
->dw_loc_oprnd1
.val_class
30950 == dw_val_class_unsigned_const
)
30953 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
30954 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
30955 == dw_val_class_unsigned_const
)
30957 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
30958 gcc_assert (base1
->die_tag
== DW_TAG_base_type
30959 && base2
->die_tag
== DW_TAG_base_type
);
30960 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
30961 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
30962 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
30963 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
30965 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
30966 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
30970 /* Optimize away next DW_OP_convert after
30971 adjusting LOC's base type die reference. */
30972 if (loc
->dw_loc_opc
== DW_OP_regval_type
30973 || loc
->dw_loc_opc
== DW_OP_deref_type
30974 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
30975 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
30976 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
30978 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
30979 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
30982 /* Don't change integer DW_OP_convert after e.g. floating
30983 point typed stack entry. */
30984 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
30985 keep
= loc
->dw_loc_next
;
30995 /* Helper function of resolve_addr. DIE had DW_AT_location of
30996 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
30997 and DW_OP_addr couldn't be resolved. resolve_addr has already
30998 removed the DW_AT_location attribute. This function attempts to
30999 add a new DW_AT_location attribute with DW_OP_implicit_pointer
31000 to it or DW_AT_const_value attribute, if possible. */
31003 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
31006 || lookup_decl_die (decl
) != die
31007 || DECL_EXTERNAL (decl
)
31008 || !TREE_STATIC (decl
)
31009 || DECL_INITIAL (decl
) == NULL_TREE
31010 || DECL_P (DECL_INITIAL (decl
))
31011 || get_AT (die
, DW_AT_const_value
))
31014 tree init
= DECL_INITIAL (decl
);
31015 HOST_WIDE_INT offset
= 0;
31016 /* For variables that have been optimized away and thus
31017 don't have a memory location, see if we can emit
31018 DW_AT_const_value instead. */
31019 if (tree_add_const_value_attribute (die
, init
))
31021 if (dwarf_strict
&& dwarf_version
< 5)
31023 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
31024 and ADDR_EXPR refers to a decl that has DW_AT_location or
31025 DW_AT_const_value (but isn't addressable, otherwise
31026 resolving the original DW_OP_addr wouldn't fail), see if
31027 we can add DW_OP_implicit_pointer. */
31029 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
31030 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
31032 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
31033 init
= TREE_OPERAND (init
, 0);
31036 if (TREE_CODE (init
) != ADDR_EXPR
)
31038 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
31039 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
31040 || (VAR_P (TREE_OPERAND (init
, 0))
31041 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
31042 && TREE_OPERAND (init
, 0) != decl
))
31045 dw_loc_descr_ref l
;
31047 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
31049 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
31052 decl
= SYMBOL_REF_DECL (rtl
);
31055 decl
= TREE_OPERAND (init
, 0);
31056 ref
= lookup_decl_die (decl
);
31058 || (!get_AT (ref
, DW_AT_location
)
31059 && !get_AT (ref
, DW_AT_const_value
)))
31061 l
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
31062 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
31063 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
31064 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
31065 add_AT_loc (die
, DW_AT_location
, l
);
31069 /* Return NULL if l is a DWARF expression, or first op that is not
31070 valid DWARF expression. */
31072 static dw_loc_descr_ref
31073 non_dwarf_expression (dw_loc_descr_ref l
)
31077 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
31079 switch (l
->dw_loc_opc
)
31082 case DW_OP_implicit_value
:
31083 case DW_OP_stack_value
:
31084 case DW_OP_implicit_pointer
:
31085 case DW_OP_GNU_implicit_pointer
:
31086 case DW_OP_GNU_parameter_ref
:
31088 case DW_OP_bit_piece
:
31093 l
= l
->dw_loc_next
;
31098 /* Return adjusted copy of EXPR:
31099 If it is empty DWARF expression, return it.
31100 If it is valid non-empty DWARF expression,
31101 return copy of EXPR with DW_OP_deref appended to it.
31102 If it is DWARF expression followed by DW_OP_reg{N,x}, return
31103 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
31104 If it is DWARF expression followed by DW_OP_stack_value, return
31105 copy of the DWARF expression without anything appended.
31106 Otherwise, return NULL. */
31108 static dw_loc_descr_ref
31109 copy_deref_exprloc (dw_loc_descr_ref expr
)
31111 dw_loc_descr_ref tail
= NULL
;
31116 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
31117 if (l
&& l
->dw_loc_next
)
31122 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
31123 tail
= new_loc_descr ((enum dwarf_location_atom
)
31124 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
31127 switch (l
->dw_loc_opc
)
31130 tail
= new_loc_descr (DW_OP_bregx
,
31131 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
31133 case DW_OP_stack_value
:
31140 tail
= new_loc_descr (DW_OP_deref
, 0, 0);
31142 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
31145 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
31146 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
31147 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
31148 p
= &(*p
)->dw_loc_next
;
31149 expr
= expr
->dw_loc_next
;
31155 /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
31156 reference to a variable or argument, adjust it if needed and return:
31157 -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
31158 attribute if present should be removed
31159 0 keep the attribute perhaps with minor modifications, no need to rescan
31160 1 if the attribute has been successfully adjusted. */
31163 optimize_string_length (dw_attr_node
*a
)
31165 dw_loc_descr_ref l
= AT_loc (a
), lv
;
31167 if (l
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
31169 tree decl
= l
->dw_loc_oprnd1
.v
.val_decl_ref
;
31170 die
= lookup_decl_die (decl
);
31173 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
31174 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= die
;
31175 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
31181 die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
31183 /* DWARF5 allows reference class, so we can then reference the DIE.
31184 Only do this for DW_OP_GNU_variable_value DW_OP_stack_value. */
31185 if (l
->dw_loc_next
!= NULL
&& dwarf_version
>= 5)
31187 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
31188 a
->dw_attr_val
.val_entry
= NULL
;
31189 a
->dw_attr_val
.v
.val_die_ref
.die
= die
;
31190 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
31194 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
31196 bool non_dwarf_expr
= false;
31199 return dwarf_strict
? -1 : 0;
31200 switch (AT_class (av
))
31202 case dw_val_class_loc_list
:
31203 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
31204 if (d
->expr
&& non_dwarf_expression (d
->expr
))
31205 non_dwarf_expr
= true;
31207 case dw_val_class_view_list
:
31208 gcc_unreachable ();
31209 case dw_val_class_loc
:
31212 return dwarf_strict
? -1 : 0;
31213 if (non_dwarf_expression (lv
))
31214 non_dwarf_expr
= true;
31217 return dwarf_strict
? -1 : 0;
31220 /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
31221 into DW_OP_call4 or DW_OP_GNU_variable_value into
31222 DW_OP_call4 DW_OP_deref, do so. */
31223 if (!non_dwarf_expr
31224 && (l
->dw_loc_next
!= NULL
|| AT_class (av
) == dw_val_class_loc
))
31226 l
->dw_loc_opc
= DW_OP_call4
;
31227 if (l
->dw_loc_next
)
31228 l
->dw_loc_next
= NULL
;
31230 l
->dw_loc_next
= new_loc_descr (DW_OP_deref
, 0, 0);
31234 /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
31235 copy over the DW_AT_location attribute from die to a. */
31236 if (l
->dw_loc_next
!= NULL
)
31238 a
->dw_attr_val
= av
->dw_attr_val
;
31242 dw_loc_list_ref list
, *p
;
31243 switch (AT_class (av
))
31245 case dw_val_class_loc_list
:
31248 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
31250 lv
= copy_deref_exprloc (d
->expr
);
31253 *p
= new_loc_list (lv
, d
->begin
, d
->vbegin
, d
->end
, d
->vend
, d
->section
);
31254 p
= &(*p
)->dw_loc_next
;
31256 else if (!dwarf_strict
&& d
->expr
)
31260 return dwarf_strict
? -1 : 0;
31261 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
31263 *AT_loc_list_ptr (a
) = list
;
31265 case dw_val_class_loc
:
31266 lv
= copy_deref_exprloc (AT_loc (av
));
31268 return dwarf_strict
? -1 : 0;
31269 a
->dw_attr_val
.v
.val_loc
= lv
;
31272 gcc_unreachable ();
31276 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
31277 an address in .rodata section if the string literal is emitted there,
31278 or remove the containing location list or replace DW_AT_const_value
31279 with DW_AT_location and empty location expression, if it isn't found
31280 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
31281 to something that has been emitted in the current CU. */
31284 resolve_addr (dw_die_ref die
)
31288 dw_loc_list_ref
*curr
, *start
, loc
;
31290 bool remove_AT_byte_size
= false;
31292 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
31293 switch (AT_class (a
))
31295 case dw_val_class_loc_list
:
31296 start
= curr
= AT_loc_list_ptr (a
);
31299 /* The same list can be referenced more than once. See if we have
31300 already recorded the result from a previous pass. */
31302 *curr
= loc
->dw_loc_next
;
31303 else if (!loc
->resolved_addr
)
31305 /* As things stand, we do not expect or allow one die to
31306 reference a suffix of another die's location list chain.
31307 References must be identical or completely separate.
31308 There is therefore no need to cache the result of this
31309 pass on any list other than the first; doing so
31310 would lead to unnecessary writes. */
31313 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
31314 if (!resolve_addr_in_expr (a
, (*curr
)->expr
))
31316 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
31317 dw_loc_descr_ref l
= (*curr
)->expr
;
31319 if (next
&& (*curr
)->ll_symbol
)
31321 gcc_assert (!next
->ll_symbol
);
31322 next
->ll_symbol
= (*curr
)->ll_symbol
;
31323 next
->vl_symbol
= (*curr
)->vl_symbol
;
31325 if (dwarf_split_debug_info
)
31326 remove_loc_list_addr_table_entries (l
);
31331 mark_base_types ((*curr
)->expr
);
31332 curr
= &(*curr
)->dw_loc_next
;
31336 loc
->resolved_addr
= 1;
31340 loc
->dw_loc_next
= *start
;
31345 remove_AT (die
, a
->dw_attr
);
31349 case dw_val_class_view_list
:
31351 gcc_checking_assert (a
->dw_attr
== DW_AT_GNU_locviews
);
31352 gcc_checking_assert (dwarf2out_locviews_in_attribute ());
31353 dw_val_node
*llnode
31354 = view_list_to_loc_list_val_node (&a
->dw_attr_val
);
31355 /* If we no longer have a loclist, or it no longer needs
31356 views, drop this attribute. */
31357 if (!llnode
|| !llnode
->v
.val_loc_list
->vl_symbol
)
31359 remove_AT (die
, a
->dw_attr
);
31364 case dw_val_class_loc
:
31366 dw_loc_descr_ref l
= AT_loc (a
);
31367 /* DW_OP_GNU_variable_value DW_OP_stack_value or
31368 DW_OP_GNU_variable_value in DW_AT_string_length can be converted
31369 into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
31370 DWARF4 unlike DW_OP_GNU_variable_value. Or for DWARF5
31371 DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
31372 with DW_FORM_ref referencing the same DIE as
31373 DW_OP_GNU_variable_value used to reference. */
31374 if (a
->dw_attr
== DW_AT_string_length
31376 && l
->dw_loc_opc
== DW_OP_GNU_variable_value
31377 && (l
->dw_loc_next
== NULL
31378 || (l
->dw_loc_next
->dw_loc_next
== NULL
31379 && l
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
)))
31381 switch (optimize_string_length (a
))
31384 remove_AT (die
, a
->dw_attr
);
31386 /* If we drop DW_AT_string_length, we need to drop also
31387 DW_AT_{string_length_,}byte_size. */
31388 remove_AT_byte_size
= true;
31393 /* Even if we keep the optimized DW_AT_string_length,
31394 it might have changed AT_class, so process it again. */
31399 /* For -gdwarf-2 don't attempt to optimize
31400 DW_AT_data_member_location containing
31401 DW_OP_plus_uconst - older consumers might
31402 rely on it being that op instead of a more complex,
31403 but shorter, location description. */
31404 if ((dwarf_version
> 2
31405 || a
->dw_attr
!= DW_AT_data_member_location
31407 || l
->dw_loc_opc
!= DW_OP_plus_uconst
31408 || l
->dw_loc_next
!= NULL
)
31409 && !resolve_addr_in_expr (a
, l
))
31411 if (dwarf_split_debug_info
)
31412 remove_loc_list_addr_table_entries (l
);
31414 && l
->dw_loc_next
== NULL
31415 && l
->dw_loc_opc
== DW_OP_addr
31416 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
31417 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
31418 && a
->dw_attr
== DW_AT_location
)
31420 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
31421 remove_AT (die
, a
->dw_attr
);
31423 optimize_location_into_implicit_ptr (die
, decl
);
31426 if (a
->dw_attr
== DW_AT_string_length
)
31427 /* If we drop DW_AT_string_length, we need to drop also
31428 DW_AT_{string_length_,}byte_size. */
31429 remove_AT_byte_size
= true;
31430 remove_AT (die
, a
->dw_attr
);
31434 mark_base_types (l
);
31437 case dw_val_class_addr
:
31438 if (a
->dw_attr
== DW_AT_const_value
31439 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
31441 if (AT_index (a
) != NOT_INDEXED
)
31442 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
31443 remove_AT (die
, a
->dw_attr
);
31446 if ((die
->die_tag
== DW_TAG_call_site
31447 && a
->dw_attr
== DW_AT_call_origin
)
31448 || (die
->die_tag
== DW_TAG_GNU_call_site
31449 && a
->dw_attr
== DW_AT_abstract_origin
))
31451 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
31452 dw_die_ref tdie
= lookup_decl_die (tdecl
);
31455 && DECL_EXTERNAL (tdecl
)
31456 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
31457 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
31459 dw_die_ref pdie
= cdie
;
31460 /* Make sure we don't add these DIEs into type units.
31461 We could emit skeleton DIEs for context (namespaces,
31462 outer structs/classes) and a skeleton DIE for the
31463 innermost context with DW_AT_signature pointing to the
31464 type unit. See PR78835. */
31465 while (pdie
&& pdie
->die_tag
!= DW_TAG_type_unit
)
31466 pdie
= pdie
->die_parent
;
31469 /* Creating a full DIE for tdecl is overly expensive and
31470 at this point even wrong when in the LTO phase
31471 as it can end up generating new type DIEs we didn't
31472 output and thus optimize_external_refs will crash. */
31473 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
31474 add_AT_flag (tdie
, DW_AT_external
, 1);
31475 add_AT_flag (tdie
, DW_AT_declaration
, 1);
31476 add_linkage_attr (tdie
, tdecl
);
31477 add_name_and_src_coords_attributes (tdie
, tdecl
, true);
31478 equate_decl_number_to_die (tdecl
, tdie
);
31483 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
31484 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
31485 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
31489 if (AT_index (a
) != NOT_INDEXED
)
31490 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
31491 remove_AT (die
, a
->dw_attr
);
31500 if (remove_AT_byte_size
)
31501 remove_AT (die
, dwarf_version
>= 5
31502 ? DW_AT_string_length_byte_size
31503 : DW_AT_byte_size
);
31505 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
31508 /* Helper routines for optimize_location_lists.
31509 This pass tries to share identical local lists in .debug_loc
31512 /* Iteratively hash operands of LOC opcode into HSTATE. */
31515 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
31517 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
31518 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
31520 switch (loc
->dw_loc_opc
)
31522 case DW_OP_const4u
:
31523 case DW_OP_const8u
:
31527 case DW_OP_const1u
:
31528 case DW_OP_const1s
:
31529 case DW_OP_const2u
:
31530 case DW_OP_const2s
:
31531 case DW_OP_const4s
:
31532 case DW_OP_const8s
:
31536 case DW_OP_plus_uconst
:
31572 case DW_OP_deref_size
:
31573 case DW_OP_xderef_size
:
31574 hstate
.add_object (val1
->v
.val_int
);
31581 gcc_assert (val1
->val_class
== dw_val_class_loc
);
31582 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
31583 hstate
.add_object (offset
);
31586 case DW_OP_implicit_value
:
31587 hstate
.add_object (val1
->v
.val_unsigned
);
31588 switch (val2
->val_class
)
31590 case dw_val_class_const
:
31591 hstate
.add_object (val2
->v
.val_int
);
31593 case dw_val_class_vec
:
31595 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
31596 unsigned int len
= val2
->v
.val_vec
.length
;
31598 hstate
.add_int (elt_size
);
31599 hstate
.add_int (len
);
31600 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
31603 case dw_val_class_const_double
:
31604 hstate
.add_object (val2
->v
.val_double
.low
);
31605 hstate
.add_object (val2
->v
.val_double
.high
);
31607 case dw_val_class_wide_int
:
31608 hstate
.add (val2
->v
.val_wide
->get_val (),
31609 get_full_len (*val2
->v
.val_wide
)
31610 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
31612 case dw_val_class_addr
:
31613 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
31616 gcc_unreachable ();
31620 case DW_OP_bit_piece
:
31621 hstate
.add_object (val1
->v
.val_int
);
31622 hstate
.add_object (val2
->v
.val_int
);
31628 unsigned char dtprel
= 0xd1;
31629 hstate
.add_object (dtprel
);
31631 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
31633 case DW_OP_GNU_addr_index
:
31635 case DW_OP_GNU_const_index
:
31640 unsigned char dtprel
= 0xd1;
31641 hstate
.add_object (dtprel
);
31643 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
31646 case DW_OP_implicit_pointer
:
31647 case DW_OP_GNU_implicit_pointer
:
31648 hstate
.add_int (val2
->v
.val_int
);
31650 case DW_OP_entry_value
:
31651 case DW_OP_GNU_entry_value
:
31652 hstate
.add_object (val1
->v
.val_loc
);
31654 case DW_OP_regval_type
:
31655 case DW_OP_deref_type
:
31656 case DW_OP_GNU_regval_type
:
31657 case DW_OP_GNU_deref_type
:
31659 unsigned int byte_size
31660 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
31661 unsigned int encoding
31662 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
31663 hstate
.add_object (val1
->v
.val_int
);
31664 hstate
.add_object (byte_size
);
31665 hstate
.add_object (encoding
);
31668 case DW_OP_convert
:
31669 case DW_OP_reinterpret
:
31670 case DW_OP_GNU_convert
:
31671 case DW_OP_GNU_reinterpret
:
31672 if (val1
->val_class
== dw_val_class_unsigned_const
)
31674 hstate
.add_object (val1
->v
.val_unsigned
);
31678 case DW_OP_const_type
:
31679 case DW_OP_GNU_const_type
:
31681 unsigned int byte_size
31682 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
31683 unsigned int encoding
31684 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
31685 hstate
.add_object (byte_size
);
31686 hstate
.add_object (encoding
);
31687 if (loc
->dw_loc_opc
!= DW_OP_const_type
31688 && loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
31690 hstate
.add_object (val2
->val_class
);
31691 switch (val2
->val_class
)
31693 case dw_val_class_const
:
31694 hstate
.add_object (val2
->v
.val_int
);
31696 case dw_val_class_vec
:
31698 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
31699 unsigned int len
= val2
->v
.val_vec
.length
;
31701 hstate
.add_object (elt_size
);
31702 hstate
.add_object (len
);
31703 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
31706 case dw_val_class_const_double
:
31707 hstate
.add_object (val2
->v
.val_double
.low
);
31708 hstate
.add_object (val2
->v
.val_double
.high
);
31710 case dw_val_class_wide_int
:
31711 hstate
.add (val2
->v
.val_wide
->get_val (),
31712 get_full_len (*val2
->v
.val_wide
)
31713 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
31716 gcc_unreachable ();
31722 /* Other codes have no operands. */
31727 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
31730 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
31732 dw_loc_descr_ref l
;
31733 bool sizes_computed
= false;
31734 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
31735 size_of_locs (loc
);
31737 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
31739 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
31740 hstate
.add_object (opc
);
31741 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
31743 size_of_locs (loc
);
31744 sizes_computed
= true;
31746 hash_loc_operands (l
, hstate
);
31750 /* Compute hash of the whole location list LIST_HEAD. */
31753 hash_loc_list (dw_loc_list_ref list_head
)
31755 dw_loc_list_ref curr
= list_head
;
31756 inchash::hash hstate
;
31758 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
31760 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
31761 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
31762 hstate
.add_object (curr
->vbegin
);
31763 hstate
.add_object (curr
->vend
);
31765 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
31766 hash_locs (curr
->expr
, hstate
);
31768 list_head
->hash
= hstate
.end ();
31771 /* Return true if X and Y opcodes have the same operands. */
31774 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
31776 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
31777 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
31778 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
31779 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
31781 switch (x
->dw_loc_opc
)
31783 case DW_OP_const4u
:
31784 case DW_OP_const8u
:
31788 case DW_OP_const1u
:
31789 case DW_OP_const1s
:
31790 case DW_OP_const2u
:
31791 case DW_OP_const2s
:
31792 case DW_OP_const4s
:
31793 case DW_OP_const8s
:
31797 case DW_OP_plus_uconst
:
31833 case DW_OP_deref_size
:
31834 case DW_OP_xderef_size
:
31835 return valx1
->v
.val_int
== valy1
->v
.val_int
;
31838 /* If splitting debug info, the use of DW_OP_GNU_addr_index
31839 can cause irrelevant differences in dw_loc_addr. */
31840 gcc_assert (valx1
->val_class
== dw_val_class_loc
31841 && valy1
->val_class
== dw_val_class_loc
31842 && (dwarf_split_debug_info
31843 || x
->dw_loc_addr
== y
->dw_loc_addr
));
31844 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
31845 case DW_OP_implicit_value
:
31846 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
31847 || valx2
->val_class
!= valy2
->val_class
)
31849 switch (valx2
->val_class
)
31851 case dw_val_class_const
:
31852 return valx2
->v
.val_int
== valy2
->v
.val_int
;
31853 case dw_val_class_vec
:
31854 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
31855 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
31856 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
31857 valx2
->v
.val_vec
.elt_size
31858 * valx2
->v
.val_vec
.length
) == 0;
31859 case dw_val_class_const_double
:
31860 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
31861 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
31862 case dw_val_class_wide_int
:
31863 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
31864 case dw_val_class_addr
:
31865 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
31867 gcc_unreachable ();
31870 case DW_OP_bit_piece
:
31871 return valx1
->v
.val_int
== valy1
->v
.val_int
31872 && valx2
->v
.val_int
== valy2
->v
.val_int
;
31875 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
31876 case DW_OP_GNU_addr_index
:
31878 case DW_OP_GNU_const_index
:
31881 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
31882 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
31883 return rtx_equal_p (ax1
, ay1
);
31885 case DW_OP_implicit_pointer
:
31886 case DW_OP_GNU_implicit_pointer
:
31887 return valx1
->val_class
== dw_val_class_die_ref
31888 && valx1
->val_class
== valy1
->val_class
31889 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
31890 && valx2
->v
.val_int
== valy2
->v
.val_int
;
31891 case DW_OP_entry_value
:
31892 case DW_OP_GNU_entry_value
:
31893 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
31894 case DW_OP_const_type
:
31895 case DW_OP_GNU_const_type
:
31896 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
31897 || valx2
->val_class
!= valy2
->val_class
)
31899 switch (valx2
->val_class
)
31901 case dw_val_class_const
:
31902 return valx2
->v
.val_int
== valy2
->v
.val_int
;
31903 case dw_val_class_vec
:
31904 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
31905 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
31906 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
31907 valx2
->v
.val_vec
.elt_size
31908 * valx2
->v
.val_vec
.length
) == 0;
31909 case dw_val_class_const_double
:
31910 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
31911 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
31912 case dw_val_class_wide_int
:
31913 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
31915 gcc_unreachable ();
31917 case DW_OP_regval_type
:
31918 case DW_OP_deref_type
:
31919 case DW_OP_GNU_regval_type
:
31920 case DW_OP_GNU_deref_type
:
31921 return valx1
->v
.val_int
== valy1
->v
.val_int
31922 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
31923 case DW_OP_convert
:
31924 case DW_OP_reinterpret
:
31925 case DW_OP_GNU_convert
:
31926 case DW_OP_GNU_reinterpret
:
31927 if (valx1
->val_class
!= valy1
->val_class
)
31929 if (valx1
->val_class
== dw_val_class_unsigned_const
)
31930 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
31931 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
31932 case DW_OP_GNU_parameter_ref
:
31933 return valx1
->val_class
== dw_val_class_die_ref
31934 && valx1
->val_class
== valy1
->val_class
31935 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
31937 /* Other codes have no operands. */
31942 /* Return true if DWARF location expressions X and Y are the same. */
31945 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
31947 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
31948 if (x
->dw_loc_opc
!= y
->dw_loc_opc
31949 || x
->dtprel
!= y
->dtprel
31950 || !compare_loc_operands (x
, y
))
31952 return x
== NULL
&& y
== NULL
;
31955 /* Hashtable helpers. */
31957 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
31959 static inline hashval_t
hash (const dw_loc_list_struct
*);
31960 static inline bool equal (const dw_loc_list_struct
*,
31961 const dw_loc_list_struct
*);
31964 /* Return precomputed hash of location list X. */
31967 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
31972 /* Return true if location lists A and B are the same. */
31975 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
31976 const dw_loc_list_struct
*b
)
31980 if (a
->hash
!= b
->hash
)
31982 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
31983 if (strcmp (a
->begin
, b
->begin
) != 0
31984 || strcmp (a
->end
, b
->end
) != 0
31985 || (a
->section
== NULL
) != (b
->section
== NULL
)
31986 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
31987 || a
->vbegin
!= b
->vbegin
|| a
->vend
!= b
->vend
31988 || !compare_locs (a
->expr
, b
->expr
))
31990 return a
== NULL
&& b
== NULL
;
31993 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
31996 /* Recursively optimize location lists referenced from DIE
31997 children and share them whenever possible. */
32000 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
32005 dw_loc_list_struct
**slot
;
32006 bool drop_locviews
= false;
32007 bool has_locviews
= false;
32009 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
32010 if (AT_class (a
) == dw_val_class_loc_list
)
32012 dw_loc_list_ref list
= AT_loc_list (a
);
32013 /* TODO: perform some optimizations here, before hashing
32014 it and storing into the hash table. */
32015 hash_loc_list (list
);
32016 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
32020 if (loc_list_has_views (list
))
32021 gcc_assert (list
->vl_symbol
);
32022 else if (list
->vl_symbol
)
32024 drop_locviews
= true;
32025 list
->vl_symbol
= NULL
;
32030 if (list
->vl_symbol
&& !(*slot
)->vl_symbol
)
32031 drop_locviews
= true;
32032 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
32035 else if (AT_class (a
) == dw_val_class_view_list
)
32037 gcc_checking_assert (a
->dw_attr
== DW_AT_GNU_locviews
);
32038 has_locviews
= true;
32042 if (drop_locviews
&& has_locviews
)
32043 remove_AT (die
, DW_AT_GNU_locviews
);
32045 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
32049 /* Recursively assign each location list a unique index into the debug_addr
32053 index_location_lists (dw_die_ref die
)
32059 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
32060 if (AT_class (a
) == dw_val_class_loc_list
)
32062 dw_loc_list_ref list
= AT_loc_list (a
);
32063 dw_loc_list_ref curr
;
32064 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
32066 /* Don't index an entry that has already been indexed
32067 or won't be output. Make sure skip_loc_list_entry doesn't
32068 call size_of_locs, because that might cause circular dependency,
32069 index_location_lists requiring address table indexes to be
32070 computed, but adding new indexes through add_addr_table_entry
32071 and address table index computation requiring no new additions
32072 to the hash table. In the rare case of DWARF[234] >= 64KB
32073 location expression, we'll just waste unused address table entry
32075 if (curr
->begin_entry
!= NULL
|| skip_loc_list_entry (curr
))
32079 = add_addr_table_entry (xstrdup (curr
->begin
), ate_kind_label
);
32080 if (dwarf_version
>= 5 && !HAVE_AS_LEB128
)
32082 = add_addr_table_entry (xstrdup (curr
->end
), ate_kind_label
);
32086 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
32089 /* Optimize location lists referenced from DIE
32090 children and share them whenever possible. */
32093 optimize_location_lists (dw_die_ref die
)
32095 loc_list_hash_type
htab (500);
32096 optimize_location_lists_1 (die
, &htab
);
32099 /* Traverse the limbo die list, and add parent/child links. The only
32100 dies without parents that should be here are concrete instances of
32101 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
32102 For concrete instances, we can get the parent die from the abstract
32106 flush_limbo_die_list (void)
32108 limbo_die_node
*node
;
32110 /* get_context_die calls force_decl_die, which can put new DIEs on the
32111 limbo list in LTO mode when nested functions are put in a different
32112 partition than that of their parent function. */
32113 while ((node
= limbo_die_list
))
32115 dw_die_ref die
= node
->die
;
32116 limbo_die_list
= node
->next
;
32118 if (die
->die_parent
== NULL
)
32120 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
32122 if (origin
&& origin
->die_parent
)
32123 add_child_die (origin
->die_parent
, die
);
32124 else if (is_cu_die (die
))
32126 else if (seen_error ())
32127 /* It's OK to be confused by errors in the input. */
32128 add_child_die (comp_unit_die (), die
);
32131 /* In certain situations, the lexical block containing a
32132 nested function can be optimized away, which results
32133 in the nested function die being orphaned. Likewise
32134 with the return type of that nested function. Force
32135 this to be a child of the containing function.
32137 It may happen that even the containing function got fully
32138 inlined and optimized out. In that case we are lost and
32139 assign the empty child. This should not be big issue as
32140 the function is likely unreachable too. */
32141 gcc_assert (node
->created_for
);
32143 if (DECL_P (node
->created_for
))
32144 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
32145 else if (TYPE_P (node
->created_for
))
32146 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
32148 origin
= comp_unit_die ();
32150 add_child_die (origin
, die
);
32156 /* Reset DIEs so we can output them again. */
32159 reset_dies (dw_die_ref die
)
32163 /* Remove stuff we re-generate. */
32165 die
->die_offset
= 0;
32166 die
->die_abbrev
= 0;
32167 remove_AT (die
, DW_AT_sibling
);
32169 FOR_EACH_CHILD (die
, c
, reset_dies (c
));
32172 /* reset_indirect_string removed the references coming from DW_AT_name
32173 and DW_AT_comp_dir attributes on compilation unit DIEs. Readd them as
32174 .debug_line_str strings again. */
32177 adjust_name_comp_dir (dw_die_ref die
)
32179 for (int i
= 0; i
< 2; i
++)
32181 dwarf_attribute attr_kind
= i
? DW_AT_comp_dir
: DW_AT_name
;
32182 dw_attr_node
*a
= get_AT (die
, attr_kind
);
32183 if (a
== NULL
|| a
->dw_attr_val
.val_class
!= dw_val_class_str
)
32186 if (!debug_line_str_hash
)
32187 debug_line_str_hash
32188 = hash_table
<indirect_string_hasher
>::create_ggc (10);
32190 struct indirect_string_node
*node
32191 = find_AT_string_in_table (a
->dw_attr_val
.v
.val_str
->str
,
32192 debug_line_str_hash
);
32193 set_indirect_string (node
);
32194 node
->form
= DW_FORM_line_strp
;
32195 a
->dw_attr_val
.v
.val_str
= node
;
32199 /* Output stuff that dwarf requires at the end of every file,
32200 and generate the DWARF-2 debugging info. */
32203 dwarf2out_finish (const char *filename
)
32205 comdat_type_node
*ctnode
;
32206 dw_die_ref main_comp_unit_die
;
32207 unsigned char checksum
[16];
32208 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
32210 /* Generate CTF/BTF debug info. */
32211 if ((ctf_debug_info_level
> CTFINFO_LEVEL_NONE
32212 || btf_debuginfo_p ()) && lang_GNU_C ())
32213 ctf_debug_finish (filename
);
32215 /* Skip emitting DWARF if not required. */
32216 if (!dwarf_debuginfo_p ())
32219 /* Flush out any latecomers to the limbo party. */
32220 flush_limbo_die_list ();
32222 if (inline_entry_data_table
)
32223 gcc_assert (inline_entry_data_table
->is_empty ());
32227 verify_die (comp_unit_die ());
32228 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
32229 verify_die (node
->die
);
32232 /* We shouldn't have any symbols with delayed asm names for
32233 DIEs generated after early finish. */
32234 gcc_assert (deferred_asm_name
== NULL
);
32236 gen_remaining_tmpl_value_param_die_attribute ();
32238 if (flag_generate_lto
|| flag_generate_offload
)
32240 gcc_assert (flag_fat_lto_objects
|| flag_generate_offload
);
32242 /* Prune stuff so that dwarf2out_finish runs successfully
32243 for the fat part of the object. */
32244 reset_dies (comp_unit_die ());
32245 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
32246 reset_dies (node
->die
);
32248 hash_table
<comdat_type_hasher
> comdat_type_table (100);
32249 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32251 comdat_type_node
**slot
32252 = comdat_type_table
.find_slot (ctnode
, INSERT
);
32254 /* Don't reset types twice. */
32255 if (*slot
!= HTAB_EMPTY_ENTRY
)
32258 /* Remove the pointer to the line table. */
32259 remove_AT (ctnode
->root_die
, DW_AT_stmt_list
);
32261 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
32262 reset_dies (ctnode
->root_die
);
32267 /* Reset die CU symbol so we don't output it twice. */
32268 comp_unit_die ()->die_id
.die_symbol
= NULL
;
32270 /* Remove DW_AT_macro and DW_AT_stmt_list from the early output. */
32271 remove_AT (comp_unit_die (), DW_AT_stmt_list
);
32273 remove_AT (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
);
32275 /* Remove indirect string decisions. */
32276 debug_str_hash
->traverse
<void *, reset_indirect_string
> (NULL
);
32277 if (debug_line_str_hash
)
32279 debug_line_str_hash
->traverse
<void *, reset_indirect_string
> (NULL
);
32280 debug_line_str_hash
= NULL
;
32281 if (asm_outputs_debug_line_str ())
32283 adjust_name_comp_dir (comp_unit_die ());
32284 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
32285 adjust_name_comp_dir (node
->die
);
32290 #if ENABLE_ASSERT_CHECKING
32292 dw_die_ref die
= comp_unit_die (), c
;
32293 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
32296 base_types
.truncate (0);
32297 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32298 resolve_addr (ctnode
->root_die
);
32299 resolve_addr (comp_unit_die ());
32300 move_marked_base_types ();
32304 fprintf (dump_file
, "DWARF for %s\n", filename
);
32305 print_die (comp_unit_die (), dump_file
);
32308 /* Initialize sections and labels used for actual assembler output. */
32309 unsigned generation
= init_sections_and_labels (false);
32311 /* Traverse the DIE's and add sibling attributes to those DIE's that
32313 add_sibling_attributes (comp_unit_die ());
32314 limbo_die_node
*node
;
32315 for (node
= cu_die_list
; node
; node
= node
->next
)
32316 add_sibling_attributes (node
->die
);
32317 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32318 add_sibling_attributes (ctnode
->root_die
);
32320 /* When splitting DWARF info, we put some attributes in the
32321 skeleton compile_unit DIE that remains in the .o, while
32322 most attributes go in the DWO compile_unit_die. */
32323 if (dwarf_split_debug_info
)
32325 limbo_die_node
*cu
;
32326 main_comp_unit_die
= gen_compile_unit_die (NULL
);
32327 if (dwarf_version
>= 5)
32328 main_comp_unit_die
->die_tag
= DW_TAG_skeleton_unit
;
32329 cu
= limbo_die_list
;
32330 gcc_assert (cu
->die
== main_comp_unit_die
);
32331 limbo_die_list
= limbo_die_list
->next
;
32332 cu
->next
= cu_die_list
;
32336 main_comp_unit_die
= comp_unit_die ();
32338 /* Output a terminator label for the .text section. */
32339 switch_to_section (text_section
);
32340 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
32341 if (cold_text_section
)
32343 switch_to_section (cold_text_section
);
32344 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
32347 /* We can only use the low/high_pc attributes if all of the code was
32349 if ((!have_multiple_function_sections
32350 && vec_safe_length (switch_text_ranges
) < 2)
32351 || (dwarf_version
< 3 && dwarf_strict
))
32353 const char *end_label
= text_end_label
;
32354 if (vec_safe_length (switch_text_ranges
) == 1)
32355 end_label
= (*switch_text_ranges
)[0];
32356 /* Don't add if the CU has no associated code. */
32357 if (switch_text_ranges
)
32358 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
32365 bool range_list_added
= false;
32366 if (switch_text_ranges
)
32368 const char *prev_loc
= text_section_label
;
32372 FOR_EACH_VEC_ELT (*switch_text_ranges
, idx
, loc
)
32375 add_ranges_by_labels (main_comp_unit_die
, prev_loc
,
32376 loc
, &range_list_added
, true);
32383 add_ranges_by_labels (main_comp_unit_die
, prev_loc
,
32384 text_end_label
, &range_list_added
, true);
32387 if (switch_cold_ranges
)
32389 const char *prev_loc
= cold_text_section_label
;
32393 FOR_EACH_VEC_ELT (*switch_cold_ranges
, idx
, loc
)
32396 add_ranges_by_labels (main_comp_unit_die
, prev_loc
,
32397 loc
, &range_list_added
, true);
32404 add_ranges_by_labels (main_comp_unit_die
, prev_loc
,
32405 cold_end_label
, &range_list_added
, true);
32408 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
32410 if (fde
->ignored_debug
)
32412 if (!fde
->in_std_section
)
32413 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
32414 fde
->dw_fde_end
, &range_list_added
,
32416 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
32417 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
32418 fde
->dw_fde_second_end
, &range_list_added
,
32422 if (range_list_added
)
32424 /* We need to give .debug_loc and .debug_ranges an appropriate
32425 "base address". Use zero so that these addresses become
32426 absolute. Historically, we've emitted the unexpected
32427 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
32428 Emit both to give time for other tools to adapt. */
32429 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
32430 if (! dwarf_strict
&& dwarf_version
< 4)
32431 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
32434 have_multiple_function_sections
= true;
32438 /* AIX Assembler inserts the length, so adjust the reference to match the
32439 offset expected by debuggers. */
32440 strcpy (dl_section_ref
, debug_line_section_label
);
32441 if (XCOFF_DEBUGGING_INFO
)
32442 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
32444 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
32445 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
32449 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
32450 macinfo_section_label
);
32452 if (dwarf_split_debug_info
)
32454 if (have_location_lists
)
32456 /* Since we generate the loclists in the split DWARF .dwo
32457 file itself, we don't need to generate a loclists_base
32458 attribute for the split compile unit DIE. That attribute
32459 (and using relocatable sec_offset FORMs) isn't allowed
32460 for a split compile unit. Only if the .debug_loclists
32461 section was in the main file, would we need to generate a
32462 loclists_base attribute here (for the full or skeleton
32465 /* optimize_location_lists calculates the size of the lists,
32466 so index them first, and assign indices to the entries.
32467 Although optimize_location_lists will remove entries from
32468 the table, it only does so for duplicates, and therefore
32469 only reduces ref_counts to 1. */
32470 index_location_lists (comp_unit_die ());
32473 if (dwarf_version
>= 5 && !vec_safe_is_empty (ranges_table
))
32476 if (addr_index_table
!= NULL
)
32478 unsigned int index
= 0;
32480 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
32486 if (have_location_lists
)
32488 optimize_location_lists (comp_unit_die ());
32489 /* And finally assign indexes to the entries for -gsplit-dwarf. */
32490 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
32491 assign_location_list_indexes (comp_unit_die ());
32494 save_macinfo_strings ();
32496 if (dwarf_split_debug_info
)
32498 unsigned int index
= 0;
32500 /* Add attributes common to skeleton compile_units and
32501 type_units. Because these attributes include strings, it
32502 must be done before freezing the string table. Top-level
32503 skeleton die attrs are added when the skeleton type unit is
32504 created, so ensure it is created by this point. */
32505 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
32506 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
32509 /* Output all of the compilation units. We put the main one last so that
32510 the offsets are available to output_pubnames. */
32511 for (node
= cu_die_list
; node
; node
= node
->next
)
32512 output_comp_unit (node
->die
, 0, NULL
);
32514 hash_table
<comdat_type_hasher
> comdat_type_table (100);
32515 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32517 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
32519 /* Don't output duplicate types. */
32520 if (*slot
!= HTAB_EMPTY_ENTRY
)
32523 /* Add a pointer to the line table for the main compilation unit
32524 so that the debugger can make sense of DW_AT_decl_file
32526 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
32527 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
32528 (!dwarf_split_debug_info
32530 : debug_skeleton_line_section_label
));
32532 output_comdat_type_unit (ctnode
, false);
32536 if (dwarf_split_debug_info
)
32539 struct md5_ctx ctx
;
32541 /* Compute a checksum of the comp_unit to use as the dwo_id. */
32542 md5_init_ctx (&ctx
);
32544 die_checksum (comp_unit_die (), &ctx
, &mark
);
32545 unmark_all_dies (comp_unit_die ());
32546 md5_finish_ctx (&ctx
, checksum
);
32548 if (dwarf_version
< 5)
32550 /* Use the first 8 bytes of the checksum as the dwo_id,
32551 and add it to both comp-unit DIEs. */
32552 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
32553 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
32556 /* Add the base offset of the ranges table to the skeleton
32558 if (!vec_safe_is_empty (ranges_table
))
32560 if (dwarf_version
< 5)
32561 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
32562 ranges_section_label
);
32565 output_addr_table ();
32568 /* Output the main compilation unit if non-empty or if .debug_macinfo
32569 or .debug_macro will be emitted. */
32570 output_comp_unit (comp_unit_die (), have_macinfo
,
32571 dwarf_split_debug_info
? checksum
: NULL
);
32573 if (dwarf_split_debug_info
&& info_section_emitted
)
32574 output_skeleton_debug_sections (main_comp_unit_die
, checksum
);
32576 /* Output the abbreviation table. */
32577 if (vec_safe_length (abbrev_die_table
) != 1)
32579 switch_to_section (debug_abbrev_section
);
32580 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
32581 output_abbrev_section ();
32584 /* Output location list section if necessary. */
32585 if (have_location_lists
)
32587 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
32588 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
32589 /* Output the location lists info. */
32590 switch_to_section (debug_loc_section
);
32591 if (dwarf_version
>= 5)
32593 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_LOC_SECTION_LABEL
, 2);
32594 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_LOC_SECTION_LABEL
, 3);
32595 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
32596 dw2_asm_output_data (4, 0xffffffff,
32597 "Initial length escape value indicating "
32598 "64-bit DWARF extension");
32599 dw2_asm_output_delta (dwarf_offset_size
, l2
, l1
,
32600 "Length of Location Lists");
32601 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
32602 output_dwarf_version ();
32603 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
32604 dw2_asm_output_data (1, 0, "Segment Size");
32605 dw2_asm_output_data (4, dwarf_split_debug_info
? loc_list_idx
: 0,
32606 "Offset Entry Count");
32608 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
32609 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
32611 unsigned int save_loc_list_idx
= loc_list_idx
;
32613 output_loclists_offsets (comp_unit_die ());
32614 gcc_assert (save_loc_list_idx
== loc_list_idx
);
32616 output_location_lists (comp_unit_die ());
32617 if (dwarf_version
>= 5)
32618 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
32621 output_pubtables ();
32623 /* Output the address range information if a CU (.debug_info section)
32624 was emitted. We output an empty table even if we had no functions
32625 to put in it. This because the consumer has no way to tell the
32626 difference between an empty table that we omitted and failure to
32627 generate a table that would have contained data. */
32628 if (info_section_emitted
)
32630 switch_to_section (debug_aranges_section
);
32634 /* Output ranges section if necessary. */
32635 if (!vec_safe_is_empty (ranges_table
))
32637 if (dwarf_version
>= 5)
32639 if (dwarf_split_debug_info
)
32641 /* We don't know right now whether there are any
32642 ranges for .debug_rnglists and any for .debug_rnglists.dwo.
32643 Depending on into which of those two belongs the first
32644 ranges_table entry, emit that section first and that
32645 output_rnglists call will return true if the other kind of
32646 ranges needs to be emitted as well. */
32647 bool dwo
= (*ranges_table
)[0].idx
!= DW_RANGES_IDX_SKELETON
;
32648 if (output_rnglists (generation
, dwo
))
32649 output_rnglists (generation
, !dwo
);
32652 output_rnglists (generation
, false);
32658 /* Have to end the macro section. */
32661 switch_to_section (debug_macinfo_section
);
32662 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
32663 output_macinfo (!dwarf_split_debug_info
? debug_line_section_label
32664 : debug_skeleton_line_section_label
, false);
32665 dw2_asm_output_data (1, 0, "End compilation unit");
32668 /* Output the source line correspondence table. We must do this
32669 even if there is no line information. Otherwise, on an empty
32670 translation unit, we will generate a present, but empty,
32671 .debug_info section. IRIX 6.5 `nm' will then complain when
32672 examining the file. This is done late so that any filenames
32673 used by the debug_info section are marked as 'used'. */
32674 switch_to_section (debug_line_section
);
32675 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
32676 if (! output_asm_line_debug_info ())
32677 output_line_info (false);
32679 if (dwarf_split_debug_info
&& info_section_emitted
)
32681 switch_to_section (debug_skeleton_line_section
);
32682 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
32683 output_line_info (true);
32686 /* If we emitted any indirect strings, output the string table too. */
32687 if (debug_str_hash
|| skeleton_debug_str_hash
)
32688 output_indirect_strings ();
32689 if (debug_line_str_hash
)
32691 switch_to_section (debug_line_str_section
);
32692 const enum dwarf_form form
= DW_FORM_line_strp
;
32693 debug_line_str_hash
->traverse
<enum dwarf_form
,
32694 output_indirect_string
> (form
);
32697 /* ??? Move lvugid out of dwarf2out_source_line and reset it too? */
32698 symview_upper_bound
= 0;
32700 bitmap_clear (zero_view_p
);
32703 /* Returns a hash value for X (which really is a variable_value_struct). */
32706 variable_value_hasher::hash (variable_value_struct
*x
)
32708 return (hashval_t
) x
->decl_id
;
32711 /* Return true if decl_id of variable_value_struct X is the same as
32715 variable_value_hasher::equal (variable_value_struct
*x
, tree y
)
32717 return x
->decl_id
== DECL_UID (y
);
32720 /* Helper function for resolve_variable_value, handle
32721 DW_OP_GNU_variable_value in one location expression.
32722 Return true if exprloc has been changed into loclist. */
32725 resolve_variable_value_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
32727 dw_loc_descr_ref next
;
32728 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= next
)
32730 next
= loc
->dw_loc_next
;
32731 if (loc
->dw_loc_opc
!= DW_OP_GNU_variable_value
32732 || loc
->dw_loc_oprnd1
.val_class
!= dw_val_class_decl_ref
)
32735 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
32736 if (DECL_CONTEXT (decl
) != current_function_decl
)
32739 dw_die_ref ref
= lookup_decl_die (decl
);
32742 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
32743 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
32744 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
32747 dw_loc_list_ref l
= loc_list_from_tree (decl
, 0, NULL
);
32750 if (l
->dw_loc_next
)
32752 if (AT_class (a
) != dw_val_class_loc
)
32754 switch (a
->dw_attr
)
32756 /* Following attributes allow both exprloc and loclist
32757 classes, so we can change them into a loclist. */
32758 case DW_AT_location
:
32759 case DW_AT_string_length
:
32760 case DW_AT_return_addr
:
32761 case DW_AT_data_member_location
:
32762 case DW_AT_frame_base
:
32763 case DW_AT_segment
:
32764 case DW_AT_static_link
:
32765 case DW_AT_use_location
:
32766 case DW_AT_vtable_elem_location
:
32769 prev
->dw_loc_next
= NULL
;
32770 prepend_loc_descr_to_each (l
, AT_loc (a
));
32773 add_loc_descr_to_each (l
, next
);
32774 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
32775 a
->dw_attr_val
.val_entry
= NULL
;
32776 a
->dw_attr_val
.v
.val_loc_list
= l
;
32777 have_location_lists
= true;
32779 /* Following attributes allow both exprloc and reference,
32780 so if the whole expression is DW_OP_GNU_variable_value alone
32781 we could transform it into reference. */
32782 case DW_AT_byte_size
:
32783 case DW_AT_bit_size
:
32784 case DW_AT_lower_bound
:
32785 case DW_AT_upper_bound
:
32786 case DW_AT_bit_stride
:
32788 case DW_AT_allocated
:
32789 case DW_AT_associated
:
32790 case DW_AT_byte_stride
:
32791 if (prev
== NULL
&& next
== NULL
)
32799 /* Create DW_TAG_variable that we can refer to. */
32800 gen_decl_die (decl
, NULL_TREE
, NULL
,
32801 lookup_decl_die (current_function_decl
));
32802 ref
= lookup_decl_die (decl
);
32805 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
32806 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
32807 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
32813 prev
->dw_loc_next
= l
->expr
;
32814 add_loc_descr (&prev
->dw_loc_next
, next
);
32815 free_loc_descr (loc
, NULL
);
32816 next
= prev
->dw_loc_next
;
32820 memcpy (loc
, l
->expr
, sizeof (dw_loc_descr_node
));
32821 add_loc_descr (&loc
, next
);
32829 /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree. */
32832 resolve_variable_value (dw_die_ref die
)
32835 dw_loc_list_ref loc
;
32838 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
32839 switch (AT_class (a
))
32841 case dw_val_class_loc
:
32842 if (!resolve_variable_value_in_expr (a
, AT_loc (a
)))
32845 case dw_val_class_loc_list
:
32846 loc
= AT_loc_list (a
);
32848 for (; loc
; loc
= loc
->dw_loc_next
)
32849 resolve_variable_value_in_expr (a
, loc
->expr
);
32856 /* Attempt to optimize DW_OP_GNU_variable_value refering to
32857 temporaries in the current function. */
32860 resolve_variable_values (void)
32862 if (!variable_value_hash
|| !current_function_decl
)
32865 struct variable_value_struct
*node
32866 = variable_value_hash
->find_with_hash (current_function_decl
,
32867 DECL_UID (current_function_decl
));
32874 FOR_EACH_VEC_SAFE_ELT (node
->dies
, i
, die
)
32875 resolve_variable_value (die
);
32878 /* Helper function for note_variable_value, handle one location
32882 note_variable_value_in_expr (dw_die_ref die
, dw_loc_descr_ref loc
)
32884 for (; loc
; loc
= loc
->dw_loc_next
)
32885 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
32886 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
32888 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
32889 dw_die_ref ref
= lookup_decl_die (decl
);
32890 if (! ref
&& (flag_generate_lto
|| flag_generate_offload
))
32892 /* ??? This is somewhat a hack because we do not create DIEs
32893 for variables not in BLOCK trees early but when generating
32894 early LTO output we need the dw_val_class_decl_ref to be
32895 fully resolved. For fat LTO objects we'd also like to
32896 undo this after LTO dwarf output. */
32897 gcc_assert (DECL_CONTEXT (decl
));
32898 dw_die_ref ctx
= lookup_decl_die (DECL_CONTEXT (decl
));
32899 gcc_assert (ctx
!= NULL
);
32900 gen_decl_die (decl
, NULL_TREE
, NULL
, ctx
);
32901 ref
= lookup_decl_die (decl
);
32902 gcc_assert (ref
!= NULL
);
32906 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
32907 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
32908 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
32912 && DECL_CONTEXT (decl
)
32913 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
32914 && lookup_decl_die (DECL_CONTEXT (decl
)))
32916 if (!variable_value_hash
)
32917 variable_value_hash
32918 = hash_table
<variable_value_hasher
>::create_ggc (10);
32920 tree fndecl
= DECL_CONTEXT (decl
);
32921 struct variable_value_struct
*node
;
32922 struct variable_value_struct
**slot
32923 = variable_value_hash
->find_slot_with_hash (fndecl
,
32928 node
= ggc_cleared_alloc
<variable_value_struct
> ();
32929 node
->decl_id
= DECL_UID (fndecl
);
32935 vec_safe_push (node
->dies
, die
);
32940 /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
32941 with dw_val_class_decl_ref operand. */
32944 note_variable_value (dw_die_ref die
)
32948 dw_loc_list_ref loc
;
32951 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
32952 switch (AT_class (a
))
32954 case dw_val_class_loc_list
:
32955 loc
= AT_loc_list (a
);
32957 if (!loc
->noted_variable_value
)
32959 loc
->noted_variable_value
= 1;
32960 for (; loc
; loc
= loc
->dw_loc_next
)
32961 note_variable_value_in_expr (die
, loc
->expr
);
32964 case dw_val_class_loc
:
32965 note_variable_value_in_expr (die
, AT_loc (a
));
32971 /* Mark children. */
32972 FOR_EACH_CHILD (die
, c
, note_variable_value (c
));
32975 /* Process DWARF dies for CTF generation. */
32978 ctf_debug_do_cu (dw_die_ref die
)
32982 if (!ctf_do_die (die
))
32985 FOR_EACH_CHILD (die
, c
, ctf_do_die (c
));
32988 /* Perform any cleanups needed after the early debug generation pass
32992 dwarf2out_early_finish (const char *filename
)
32994 comdat_type_node
*ctnode
;
32996 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
32998 /* PCH might result in DW_AT_producer string being restored from the
32999 header compilation, so always fill it with empty string initially
33000 and overwrite only here. */
33001 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
33003 if (dwarf_record_gcc_switches
)
33004 producer_string
= gen_producer_string (lang_hooks
.name
,
33005 save_decoded_options
,
33006 save_decoded_options_count
);
33008 producer_string
= concat (lang_hooks
.name
, " ", version_string
, NULL
);
33010 producer
->dw_attr_val
.v
.val_str
->refcount
--;
33011 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
33013 /* Add the name for the main input file now. We delayed this from
33014 dwarf2out_init to avoid complications with PCH. */
33015 add_filename_attribute (comp_unit_die (), remap_debug_filename (filename
));
33016 add_comp_dir_attribute (comp_unit_die ());
33018 /* With LTO early dwarf was really finished at compile-time, so make
33019 sure to adjust the phase after annotating the LTRANS CU DIE. */
33022 early_dwarf_finished
= true;
33025 fprintf (dump_file
, "LTO EARLY DWARF for %s\n", filename
);
33026 print_die (comp_unit_die (), dump_file
);
33031 /* Walk through the list of incomplete types again, trying once more to
33032 emit full debugging info for them. */
33033 retry_incomplete_types ();
33035 gen_scheduled_generic_parms_dies ();
33036 gen_remaining_tmpl_value_param_die_attribute ();
33038 /* The point here is to flush out the limbo list so that it is empty
33039 and we don't need to stream it for LTO. */
33040 flush_limbo_die_list ();
33042 /* Add DW_AT_linkage_name for all deferred DIEs. */
33043 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
33045 tree decl
= node
->created_for
;
33046 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
33047 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
33048 ended up in deferred_asm_name before we knew it was
33049 constant and never written to disk. */
33050 && DECL_ASSEMBLER_NAME (decl
))
33052 add_linkage_attr (node
->die
, decl
);
33053 move_linkage_attr (node
->die
);
33056 deferred_asm_name
= NULL
;
33058 if (flag_eliminate_unused_debug_types
)
33059 prune_unused_types ();
33061 /* Generate separate COMDAT sections for type DIEs. */
33062 if (use_debug_types
)
33064 break_out_comdat_types (comp_unit_die ());
33066 /* Each new type_unit DIE was added to the limbo die list when created.
33067 Since these have all been added to comdat_type_list, clear the
33069 limbo_die_list
= NULL
;
33071 /* For each new comdat type unit, copy declarations for incomplete
33072 types to make the new unit self-contained (i.e., no direct
33073 references to the main compile unit). */
33074 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
33075 copy_decls_for_unworthy_types (ctnode
->root_die
);
33076 copy_decls_for_unworthy_types (comp_unit_die ());
33078 /* In the process of copying declarations from one unit to another,
33079 we may have left some declarations behind that are no longer
33080 referenced. Prune them. */
33081 prune_unused_types ();
33084 /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
33085 with dw_val_class_decl_ref operand. */
33086 note_variable_value (comp_unit_die ());
33087 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
33088 note_variable_value (node
->die
);
33089 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
33090 note_variable_value (ctnode
->root_die
);
33091 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
33092 note_variable_value (node
->die
);
33094 /* The AT_pubnames attribute needs to go in all skeleton dies, including
33095 both the main_cu and all skeleton TUs. Making this call unconditional
33096 would end up either adding a second copy of the AT_pubnames attribute, or
33097 requiring a special case in add_top_level_skeleton_die_attrs. */
33098 if (!dwarf_split_debug_info
)
33099 add_AT_pubnames (comp_unit_die ());
33101 /* The early debug phase is now finished. */
33102 early_dwarf_finished
= true;
33105 fprintf (dump_file
, "EARLY DWARF for %s\n", filename
);
33106 print_die (comp_unit_die (), dump_file
);
33109 /* Generate CTF/BTF debug info. */
33110 if ((ctf_debug_info_level
> CTFINFO_LEVEL_NONE
33111 || btf_debuginfo_p ()) && lang_GNU_C ())
33114 ctf_debug_do_cu (comp_unit_die ());
33115 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
33116 ctf_debug_do_cu (node
->die
);
33117 /* Post process the debug data in the CTF container if necessary. */
33118 ctf_debug_init_postprocess (btf_debuginfo_p ());
33120 ctf_debug_early_finish (filename
);
33123 /* Do not generate DWARF assembler now when not producing LTO bytecode. */
33124 if ((!flag_generate_lto
&& !flag_generate_offload
)
33125 /* FIXME: Disable debug info generation for (PE-)COFF targets since the
33126 copy_lto_debug_sections operation of the simple object support in
33127 libiberty is not implemented for them yet. */
33128 || TARGET_PECOFF
|| TARGET_COFF
)
33131 /* Now as we are going to output for LTO initialize sections and labels
33132 to the LTO variants. We don't need a random-seed postfix as other
33133 LTO sections as linking the LTO debug sections into one in a partial
33135 init_sections_and_labels (true);
33137 /* The output below is modeled after dwarf2out_finish with all
33138 location related output removed and some LTO specific changes.
33139 Some refactoring might make both smaller and easier to match up. */
33141 base_types
.truncate (0);
33142 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
33143 mark_base_types (ctnode
->root_die
);
33144 mark_base_types (comp_unit_die ());
33145 move_marked_base_types ();
33147 /* Traverse the DIE's and add sibling attributes to those DIE's
33148 that have children. */
33149 add_sibling_attributes (comp_unit_die ());
33150 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
33151 add_sibling_attributes (node
->die
);
33152 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
33153 add_sibling_attributes (ctnode
->root_die
);
33155 /* AIX Assembler inserts the length, so adjust the reference to match the
33156 offset expected by debuggers. */
33157 strcpy (dl_section_ref
, debug_line_section_label
);
33158 if (XCOFF_DEBUGGING_INFO
)
33159 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
33161 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
33162 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list
, dl_section_ref
);
33165 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
33166 macinfo_section_label
);
33168 save_macinfo_strings ();
33170 if (dwarf_split_debug_info
)
33172 unsigned int index
= 0;
33173 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
33176 /* Output all of the compilation units. We put the main one last so that
33177 the offsets are available to output_pubnames. */
33178 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
33179 output_comp_unit (node
->die
, 0, NULL
);
33181 hash_table
<comdat_type_hasher
> comdat_type_table (100);
33182 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
33184 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
33186 /* Don't output duplicate types. */
33187 if (*slot
!= HTAB_EMPTY_ENTRY
)
33190 /* Add a pointer to the line table for the main compilation unit
33191 so that the debugger can make sense of DW_AT_decl_file
33193 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
33194 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
33195 (!dwarf_split_debug_info
33196 ? debug_line_section_label
33197 : debug_skeleton_line_section_label
));
33199 output_comdat_type_unit (ctnode
, true);
33203 /* Stick a unique symbol to the main debuginfo section. */
33204 compute_comp_unit_symbol (comp_unit_die ());
33206 /* Output the main compilation unit. We always need it if only for
33208 output_comp_unit (comp_unit_die (), true, NULL
);
33210 /* Output the abbreviation table. */
33211 if (vec_safe_length (abbrev_die_table
) != 1)
33213 switch_to_section (debug_abbrev_section
);
33214 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
33215 output_abbrev_section ();
33218 /* Have to end the macro section. */
33221 /* We have to save macinfo state if we need to output it again
33222 for the FAT part of the object. */
33223 vec
<macinfo_entry
, va_gc
> *saved_macinfo_table
= macinfo_table
;
33224 if (flag_fat_lto_objects
)
33225 macinfo_table
= macinfo_table
->copy ();
33227 switch_to_section (debug_macinfo_section
);
33228 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
33229 output_macinfo (debug_line_section_label
, true);
33230 dw2_asm_output_data (1, 0, "End compilation unit");
33232 if (flag_fat_lto_objects
)
33234 vec_free (macinfo_table
);
33235 macinfo_table
= saved_macinfo_table
;
33239 /* Emit a skeleton debug_line section. */
33240 switch_to_section (debug_line_section
);
33241 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
33242 output_line_info (true);
33244 /* If we emitted any indirect strings, output the string table too. */
33245 if (debug_str_hash
|| skeleton_debug_str_hash
)
33246 output_indirect_strings ();
33247 if (debug_line_str_hash
)
33249 switch_to_section (debug_line_str_section
);
33250 const enum dwarf_form form
= DW_FORM_line_strp
;
33251 debug_line_str_hash
->traverse
<enum dwarf_form
,
33252 output_indirect_string
> (form
);
33255 /* Switch back to the text section. */
33256 switch_to_section (text_section
);
33259 /* Reset all state within dwarf2out.cc so that we can rerun the compiler
33260 within the same process. For use by toplev::finalize. */
33263 dwarf2out_cc_finalize (void)
33265 last_var_location_insn
= NULL
;
33266 cached_next_real_insn
= NULL
;
33267 used_rtx_array
= NULL
;
33268 incomplete_types
= NULL
;
33269 debug_info_section
= NULL
;
33270 debug_skeleton_info_section
= NULL
;
33271 debug_abbrev_section
= NULL
;
33272 debug_skeleton_abbrev_section
= NULL
;
33273 debug_aranges_section
= NULL
;
33274 debug_addr_section
= NULL
;
33275 debug_macinfo_section
= NULL
;
33276 debug_line_section
= NULL
;
33277 debug_skeleton_line_section
= NULL
;
33278 debug_loc_section
= NULL
;
33279 debug_pubnames_section
= NULL
;
33280 debug_pubtypes_section
= NULL
;
33281 debug_str_section
= NULL
;
33282 debug_line_str_section
= NULL
;
33283 debug_str_dwo_section
= NULL
;
33284 debug_str_offsets_section
= NULL
;
33285 debug_ranges_section
= NULL
;
33286 debug_ranges_dwo_section
= NULL
;
33287 debug_frame_section
= NULL
;
33289 debug_str_hash
= NULL
;
33290 debug_line_str_hash
= NULL
;
33291 skeleton_debug_str_hash
= NULL
;
33292 dw2_string_counter
= 0;
33293 have_multiple_function_sections
= false;
33294 in_text_section_p
= false;
33295 cold_text_section
= NULL
;
33296 last_text_label
= NULL
;
33297 last_cold_label
= NULL
;
33298 switch_text_ranges
= NULL
;
33299 switch_cold_ranges
= NULL
;
33300 current_unit_personality
= NULL
;
33302 early_dwarf
= false;
33303 early_dwarf_finished
= false;
33305 next_die_offset
= 0;
33306 single_comp_unit_die
= NULL
;
33307 comdat_type_list
= NULL
;
33308 limbo_die_list
= NULL
;
33310 decl_die_table
= NULL
;
33311 common_block_die_table
= NULL
;
33312 decl_loc_table
= NULL
;
33313 call_arg_locations
= NULL
;
33314 call_arg_loc_last
= NULL
;
33315 call_site_count
= -1;
33316 tail_call_site_count
= -1;
33317 cached_dw_loc_list_table
= NULL
;
33318 abbrev_die_table
= NULL
;
33319 delete dwarf_proc_stack_usage_map
;
33320 dwarf_proc_stack_usage_map
= NULL
;
33321 line_info_label_num
= 0;
33322 cur_line_info_table
= NULL
;
33323 text_section_line_info
= NULL
;
33324 cold_text_section_line_info
= NULL
;
33325 separate_line_info
= NULL
;
33326 info_section_emitted
= false;
33327 pubname_table
= NULL
;
33328 pubtype_table
= NULL
;
33329 macinfo_table
= NULL
;
33330 ranges_table
= NULL
;
33331 ranges_by_label
= NULL
;
33333 have_location_lists
= false;
33336 last_emitted_file
= NULL
;
33338 tmpl_value_parm_die_table
= NULL
;
33339 generic_type_instances
= NULL
;
33340 frame_pointer_fb_offset
= 0;
33341 frame_pointer_fb_offset_valid
= false;
33342 base_types
.release ();
33343 XDELETEVEC (producer_string
);
33344 producer_string
= NULL
;
33345 output_line_info_generation
= 0;
33346 init_sections_and_labels_generation
= 0;
33349 #include "gt-dwarf2out.h"