1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2018 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 "dwarf2asm.h"
85 #include "tree-pretty-print.h"
86 #include "print-rtl.h"
88 #include "common/common-target.h"
89 #include "langhooks.h"
94 #include "gdb/gdb-index.h"
96 #include "stringpool.h"
98 #include "file-prefix-map.h" /* remap_debug_filename() */
100 static void dwarf2out_source_line (unsigned int, unsigned int, const char *,
102 static rtx_insn
*last_var_location_insn
;
103 static rtx_insn
*cached_next_real_insn
;
104 static void dwarf2out_decl (tree
);
106 #ifndef XCOFF_DEBUGGING_INFO
107 #define XCOFF_DEBUGGING_INFO 0
110 #ifndef HAVE_XCOFF_DWARF_EXTRAS
111 #define HAVE_XCOFF_DWARF_EXTRAS 0
114 #ifdef VMS_DEBUGGING_INFO
115 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
117 /* Define this macro to be a nonzero value if the directory specifications
118 which are output in the debug info should end with a separator. */
119 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
120 /* Define this macro to evaluate to a nonzero value if GCC should refrain
121 from generating indirect strings in DWARF2 debug information, for instance
122 if your target is stuck with an old version of GDB that is unable to
123 process them properly or uses VMS Debug. */
124 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
126 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
127 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
130 /* ??? Poison these here until it can be done generically. They've been
131 totally replaced in this file; make sure it stays that way. */
132 #undef DWARF2_UNWIND_INFO
133 #undef DWARF2_FRAME_INFO
134 #if (GCC_VERSION >= 3000)
135 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
138 /* The size of the target's pointer type. */
140 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
143 /* Array of RTXes referenced by the debugging information, which therefore
144 must be kept around forever. */
145 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
147 /* A pointer to the base of a list of incomplete types which might be
148 completed at some later time. incomplete_types_list needs to be a
149 vec<tree, va_gc> *because we want to tell the garbage collector about
151 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
153 /* A pointer to the base of a table of references to declaration
154 scopes. This table is a display which tracks the nesting
155 of declaration scopes at the current scope and containing
156 scopes. This table is used to find the proper place to
157 define type declaration DIE's. */
158 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
160 /* Pointers to various DWARF2 sections. */
161 static GTY(()) section
*debug_info_section
;
162 static GTY(()) section
*debug_skeleton_info_section
;
163 static GTY(()) section
*debug_abbrev_section
;
164 static GTY(()) section
*debug_skeleton_abbrev_section
;
165 static GTY(()) section
*debug_aranges_section
;
166 static GTY(()) section
*debug_addr_section
;
167 static GTY(()) section
*debug_macinfo_section
;
168 static const char *debug_macinfo_section_name
;
169 static unsigned macinfo_label_base
= 1;
170 static GTY(()) section
*debug_line_section
;
171 static GTY(()) section
*debug_skeleton_line_section
;
172 static GTY(()) section
*debug_loc_section
;
173 static GTY(()) section
*debug_pubnames_section
;
174 static GTY(()) section
*debug_pubtypes_section
;
175 static GTY(()) section
*debug_str_section
;
176 static GTY(()) section
*debug_line_str_section
;
177 static GTY(()) section
*debug_str_dwo_section
;
178 static GTY(()) section
*debug_str_offsets_section
;
179 static GTY(()) section
*debug_ranges_section
;
180 static GTY(()) section
*debug_frame_section
;
182 /* Maximum size (in bytes) of an artificially generated label. */
183 #define MAX_ARTIFICIAL_LABEL_BYTES 40
185 /* According to the (draft) DWARF 3 specification, the initial length
186 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
187 bytes are 0xffffffff, followed by the length stored in the next 8
190 However, the SGI/MIPS ABI uses an initial length which is equal to
191 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
193 #ifndef DWARF_INITIAL_LENGTH_SIZE
194 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
197 #ifndef DWARF_INITIAL_LENGTH_SIZE_STR
198 #define DWARF_INITIAL_LENGTH_SIZE_STR (DWARF_OFFSET_SIZE == 4 ? "-4" : "-12")
201 /* Round SIZE up to the nearest BOUNDARY. */
202 #define DWARF_ROUND(SIZE,BOUNDARY) \
203 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
205 /* CIE identifier. */
206 #if HOST_BITS_PER_WIDE_INT >= 64
207 #define DWARF_CIE_ID \
208 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
210 #define DWARF_CIE_ID DW_CIE_ID
214 /* A vector for a table that contains frame description
215 information for each routine. */
216 #define NOT_INDEXED (-1U)
217 #define NO_INDEX_ASSIGNED (-2U)
219 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
221 struct GTY((for_user
)) indirect_string_node
{
223 unsigned int refcount
;
224 enum dwarf_form form
;
229 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
231 typedef const char *compare_type
;
233 static hashval_t
hash (indirect_string_node
*);
234 static bool equal (indirect_string_node
*, const char *);
237 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
239 static GTY (()) hash_table
<indirect_string_hasher
> *debug_line_str_hash
;
241 /* With split_debug_info, both the comp_dir and dwo_name go in the
242 main object file, rather than the dwo, similar to the force_direct
243 parameter elsewhere but with additional complications:
245 1) The string is needed in both the main object file and the dwo.
246 That is, the comp_dir and dwo_name will appear in both places.
248 2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
249 DW_FORM_line_strp or DW_FORM_GNU_str_index.
251 3) GCC chooses the form to use late, depending on the size and
254 Rather than forcing the all debug string handling functions and
255 callers to deal with these complications, simply use a separate,
256 special-cased string table for any attribute that should go in the
257 main object file. This limits the complexity to just the places
260 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
262 static GTY(()) int dw2_string_counter
;
264 /* True if the compilation unit places functions in more than one section. */
265 static GTY(()) bool have_multiple_function_sections
= false;
267 /* Whether the default text and cold text sections have been used at all. */
268 static GTY(()) bool text_section_used
= false;
269 static GTY(()) bool cold_text_section_used
= false;
271 /* The default cold text section. */
272 static GTY(()) section
*cold_text_section
;
274 /* The DIE for C++14 'auto' in a function return type. */
275 static GTY(()) dw_die_ref auto_die
;
277 /* The DIE for C++14 'decltype(auto)' in a function return type. */
278 static GTY(()) dw_die_ref decltype_auto_die
;
280 /* Forward declarations for functions defined in this file. */
282 static void output_call_frame_info (int);
283 static void dwarf2out_note_section_used (void);
285 /* Personality decl of current unit. Used only when assembler does not support
287 static GTY(()) rtx current_unit_personality
;
289 /* Whether an eh_frame section is required. */
290 static GTY(()) bool do_eh_frame
= false;
292 /* .debug_rnglists next index. */
293 static unsigned int rnglist_idx
;
295 /* Data and reference forms for relocatable data. */
296 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
297 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
299 #ifndef DEBUG_FRAME_SECTION
300 #define DEBUG_FRAME_SECTION ".debug_frame"
303 #ifndef FUNC_BEGIN_LABEL
304 #define FUNC_BEGIN_LABEL "LFB"
307 #ifndef FUNC_END_LABEL
308 #define FUNC_END_LABEL "LFE"
311 #ifndef PROLOGUE_END_LABEL
312 #define PROLOGUE_END_LABEL "LPE"
315 #ifndef EPILOGUE_BEGIN_LABEL
316 #define EPILOGUE_BEGIN_LABEL "LEB"
319 #ifndef FRAME_BEGIN_LABEL
320 #define FRAME_BEGIN_LABEL "Lframe"
322 #define CIE_AFTER_SIZE_LABEL "LSCIE"
323 #define CIE_END_LABEL "LECIE"
324 #define FDE_LABEL "LSFDE"
325 #define FDE_AFTER_SIZE_LABEL "LASFDE"
326 #define FDE_END_LABEL "LEFDE"
327 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
328 #define LINE_NUMBER_END_LABEL "LELT"
329 #define LN_PROLOG_AS_LABEL "LASLTP"
330 #define LN_PROLOG_END_LABEL "LELTP"
331 #define DIE_LABEL_PREFIX "DW"
333 /* Match the base name of a file to the base name of a compilation unit. */
336 matches_main_base (const char *path
)
338 /* Cache the last query. */
339 static const char *last_path
= NULL
;
340 static int last_match
= 0;
341 if (path
!= last_path
)
344 int length
= base_of_path (path
, &base
);
346 last_match
= (length
== main_input_baselength
347 && memcmp (base
, main_input_basename
, length
) == 0);
352 #ifdef DEBUG_DEBUG_STRUCT
355 dump_struct_debug (tree type
, enum debug_info_usage usage
,
356 enum debug_struct_file criterion
, int generic
,
357 int matches
, int result
)
359 /* Find the type name. */
360 tree type_decl
= TYPE_STUB_DECL (type
);
362 const char *name
= 0;
363 if (TREE_CODE (t
) == TYPE_DECL
)
366 name
= IDENTIFIER_POINTER (t
);
368 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
370 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
371 matches
? "bas" : "hdr",
372 generic
? "gen" : "ord",
373 usage
== DINFO_USAGE_DFN
? ";" :
374 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
376 (void*) type_decl
, name
);
379 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
380 dump_struct_debug (type, usage, criterion, generic, matches, result)
384 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
389 /* Get the number of HOST_WIDE_INTs needed to represent the precision
390 of the number. Some constants have a large uniform precision, so
391 we get the precision needed for the actual value of the number. */
394 get_full_len (const wide_int
&op
)
396 int prec
= wi::min_precision (op
, UNSIGNED
);
397 return ((prec
+ HOST_BITS_PER_WIDE_INT
- 1)
398 / HOST_BITS_PER_WIDE_INT
);
402 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
404 enum debug_struct_file criterion
;
406 bool generic
= lang_hooks
.types
.generic_p (type
);
409 criterion
= debug_struct_generic
[usage
];
411 criterion
= debug_struct_ordinary
[usage
];
413 if (criterion
== DINFO_STRUCT_FILE_NONE
)
414 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
415 if (criterion
== DINFO_STRUCT_FILE_ANY
)
416 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
418 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
420 if (type_decl
!= NULL
)
422 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
423 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
425 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
426 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
429 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
432 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
433 switch to the data section instead, and write out a synthetic start label
434 for collect2 the first time around. */
437 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
439 if (eh_frame_section
== 0)
443 if (EH_TABLES_CAN_BE_READ_ONLY
)
449 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
451 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
453 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
456 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
457 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
458 && (per_encoding
& 0x70) != DW_EH_PE_absptr
459 && (per_encoding
& 0x70) != DW_EH_PE_aligned
460 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
461 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
462 ? 0 : SECTION_WRITE
);
465 flags
= SECTION_WRITE
;
467 #ifdef EH_FRAME_SECTION_NAME
468 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
470 eh_frame_section
= ((flags
== SECTION_WRITE
)
471 ? data_section
: readonly_data_section
);
472 #endif /* EH_FRAME_SECTION_NAME */
475 switch_to_section (eh_frame_section
);
477 #ifdef EH_FRAME_THROUGH_COLLECT2
478 /* We have no special eh_frame section. Emit special labels to guide
482 tree label
= get_file_function_name ("F");
483 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
484 targetm
.asm_out
.globalize_label (asm_out_file
,
485 IDENTIFIER_POINTER (label
));
486 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
491 /* Switch [BACK] to the eh or debug frame table section, depending on
495 switch_to_frame_table_section (int for_eh
, bool back
)
498 switch_to_eh_frame_section (back
);
501 if (!debug_frame_section
)
502 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
503 SECTION_DEBUG
, NULL
);
504 switch_to_section (debug_frame_section
);
508 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
510 enum dw_cfi_oprnd_type
511 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
516 case DW_CFA_GNU_window_save
:
517 case DW_CFA_remember_state
:
518 case DW_CFA_restore_state
:
519 return dw_cfi_oprnd_unused
;
522 case DW_CFA_advance_loc1
:
523 case DW_CFA_advance_loc2
:
524 case DW_CFA_advance_loc4
:
525 case DW_CFA_MIPS_advance_loc8
:
526 return dw_cfi_oprnd_addr
;
529 case DW_CFA_offset_extended
:
531 case DW_CFA_offset_extended_sf
:
532 case DW_CFA_def_cfa_sf
:
534 case DW_CFA_restore_extended
:
535 case DW_CFA_undefined
:
536 case DW_CFA_same_value
:
537 case DW_CFA_def_cfa_register
:
538 case DW_CFA_register
:
539 case DW_CFA_expression
:
540 case DW_CFA_val_expression
:
541 return dw_cfi_oprnd_reg_num
;
543 case DW_CFA_def_cfa_offset
:
544 case DW_CFA_GNU_args_size
:
545 case DW_CFA_def_cfa_offset_sf
:
546 return dw_cfi_oprnd_offset
;
548 case DW_CFA_def_cfa_expression
:
549 return dw_cfi_oprnd_loc
;
556 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
558 enum dw_cfi_oprnd_type
559 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
564 case DW_CFA_def_cfa_sf
:
566 case DW_CFA_offset_extended_sf
:
567 case DW_CFA_offset_extended
:
568 return dw_cfi_oprnd_offset
;
570 case DW_CFA_register
:
571 return dw_cfi_oprnd_reg_num
;
573 case DW_CFA_expression
:
574 case DW_CFA_val_expression
:
575 return dw_cfi_oprnd_loc
;
577 case DW_CFA_def_cfa_expression
:
578 return dw_cfi_oprnd_cfa_loc
;
581 return dw_cfi_oprnd_unused
;
585 /* Output one FDE. */
588 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
589 char *section_start_label
, int fde_encoding
, char *augmentation
,
590 bool any_lsda_needed
, int lsda_encoding
)
592 const char *begin
, *end
;
593 static unsigned int j
;
594 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
596 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
598 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
600 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
601 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
602 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
604 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
605 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
606 " indicating 64-bit DWARF extension");
607 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
610 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
613 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
615 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
616 debug_frame_section
, "FDE CIE offset");
618 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
619 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
623 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
624 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
625 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
626 "FDE initial location");
627 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
628 end
, begin
, "FDE address range");
632 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
633 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
640 int size
= size_of_encoded_value (lsda_encoding
);
642 if (lsda_encoding
== DW_EH_PE_aligned
)
644 int offset
= ( 4 /* Length */
646 + 2 * size_of_encoded_value (fde_encoding
)
647 + 1 /* Augmentation size */ );
648 int pad
= -offset
& (PTR_SIZE
- 1);
651 gcc_assert (size_of_uleb128 (size
) == 1);
654 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
656 if (fde
->uses_eh_lsda
)
658 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
659 fde
->funcdef_number
);
660 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
661 gen_rtx_SYMBOL_REF (Pmode
, l1
),
663 "Language Specific Data Area");
667 if (lsda_encoding
== DW_EH_PE_aligned
)
668 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
669 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
670 "Language Specific Data Area (none)");
674 dw2_asm_output_data_uleb128 (0, "Augmentation size");
677 /* Loop through the Call Frame Instructions associated with this FDE. */
678 fde
->dw_fde_current_label
= begin
;
680 size_t from
, until
, i
;
683 until
= vec_safe_length (fde
->dw_fde_cfi
);
685 if (fde
->dw_fde_second_begin
== NULL
)
688 until
= fde
->dw_fde_switch_cfi_index
;
690 from
= fde
->dw_fde_switch_cfi_index
;
692 for (i
= from
; i
< until
; i
++)
693 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
696 /* If we are to emit a ref/link from function bodies to their frame tables,
697 do it now. This is typically performed to make sure that tables
698 associated with functions are dragged with them and not discarded in
699 garbage collecting links. We need to do this on a per function basis to
700 cope with -ffunction-sections. */
702 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
703 /* Switch to the function section, emit the ref to the tables, and
704 switch *back* into the table section. */
705 switch_to_section (function_section (fde
->decl
));
706 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
707 switch_to_frame_table_section (for_eh
, true);
710 /* Pad the FDE out to an address sized boundary. */
711 ASM_OUTPUT_ALIGN (asm_out_file
,
712 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
713 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
718 /* Return true if frame description entry FDE is needed for EH. */
721 fde_needed_for_eh_p (dw_fde_ref fde
)
723 if (flag_asynchronous_unwind_tables
)
726 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
729 if (fde
->uses_eh_lsda
)
732 /* If exceptions are enabled, we have collected nothrow info. */
733 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
739 /* Output the call frame information used to record information
740 that relates to calculating the frame pointer, and records the
741 location of saved registers. */
744 output_call_frame_info (int for_eh
)
749 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
750 char section_start_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
751 bool any_lsda_needed
= false;
752 char augmentation
[6];
753 int augmentation_size
;
754 int fde_encoding
= DW_EH_PE_absptr
;
755 int per_encoding
= DW_EH_PE_absptr
;
756 int lsda_encoding
= DW_EH_PE_absptr
;
758 rtx personality
= NULL
;
761 /* Don't emit a CIE if there won't be any FDEs. */
765 /* Nothing to do if the assembler's doing it all. */
766 if (dwarf2out_do_cfi_asm ())
769 /* If we don't have any functions we'll want to unwind out of, don't emit
770 any EH unwind information. If we make FDEs linkonce, we may have to
771 emit an empty label for an FDE that wouldn't otherwise be emitted. We
772 want to avoid having an FDE kept around when the function it refers to
773 is discarded. Example where this matters: a primary function template
774 in C++ requires EH information, an explicit specialization doesn't. */
777 bool any_eh_needed
= false;
779 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
781 if (fde
->uses_eh_lsda
)
782 any_eh_needed
= any_lsda_needed
= true;
783 else if (fde_needed_for_eh_p (fde
))
784 any_eh_needed
= true;
785 else if (TARGET_USES_WEAK_UNWIND_INFO
)
786 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
793 /* We're going to be generating comments, so turn on app. */
797 /* Switch to the proper frame section, first time. */
798 switch_to_frame_table_section (for_eh
, false);
800 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
801 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
803 /* Output the CIE. */
804 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
805 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
806 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
808 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
809 dw2_asm_output_data (4, 0xffffffff,
810 "Initial length escape value indicating 64-bit DWARF extension");
811 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
812 "Length of Common Information Entry");
814 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
816 /* Now that the CIE pointer is PC-relative for EH,
817 use 0 to identify the CIE. */
818 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
819 (for_eh
? 0 : DWARF_CIE_ID
),
820 "CIE Identifier Tag");
822 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
823 use CIE version 1, unless that would produce incorrect results
824 due to overflowing the return register column. */
825 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
827 if (return_reg
>= 256 || dwarf_version
> 2)
829 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
832 augmentation_size
= 0;
834 personality
= current_unit_personality
;
840 z Indicates that a uleb128 is present to size the
841 augmentation section.
842 L Indicates the encoding (and thus presence) of
843 an LSDA pointer in the FDE augmentation.
844 R Indicates a non-default pointer encoding for
846 P Indicates the presence of an encoding + language
847 personality routine in the CIE augmentation. */
849 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
850 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
851 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
853 p
= augmentation
+ 1;
857 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
858 assemble_external_libcall (personality
);
863 augmentation_size
+= 1;
865 if (fde_encoding
!= DW_EH_PE_absptr
)
868 augmentation_size
+= 1;
870 if (p
> augmentation
+ 1)
872 augmentation
[0] = 'z';
876 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
877 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
879 int offset
= ( 4 /* Length */
881 + 1 /* CIE version */
882 + strlen (augmentation
) + 1 /* Augmentation */
883 + size_of_uleb128 (1) /* Code alignment */
884 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
886 + 1 /* Augmentation size */
887 + 1 /* Personality encoding */ );
888 int pad
= -offset
& (PTR_SIZE
- 1);
890 augmentation_size
+= pad
;
892 /* Augmentations should be small, so there's scarce need to
893 iterate for a solution. Die if we exceed one uleb128 byte. */
894 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
898 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
899 if (dw_cie_version
>= 4)
901 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
902 dw2_asm_output_data (1, 0, "CIE Segment Size");
904 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
905 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
906 "CIE Data Alignment Factor");
908 if (dw_cie_version
== 1)
909 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
911 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
915 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
918 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
919 eh_data_format_name (per_encoding
));
920 dw2_asm_output_encoded_addr_rtx (per_encoding
,
926 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
927 eh_data_format_name (lsda_encoding
));
929 if (fde_encoding
!= DW_EH_PE_absptr
)
930 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
931 eh_data_format_name (fde_encoding
));
934 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
935 output_cfi (cfi
, NULL
, for_eh
);
937 /* Pad the CIE out to an address sized boundary. */
938 ASM_OUTPUT_ALIGN (asm_out_file
,
939 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
940 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
942 /* Loop through all of the FDE's. */
943 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
947 /* Don't emit EH unwind info for leaf functions that don't need it. */
948 if (for_eh
&& !fde_needed_for_eh_p (fde
))
951 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
952 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
953 augmentation
, any_lsda_needed
, lsda_encoding
);
956 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
957 dw2_asm_output_data (4, 0, "End of Table");
959 /* Turn off app to make assembly quicker. */
964 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
967 dwarf2out_do_cfi_startproc (bool second
)
972 fprintf (asm_out_file
, "\t.cfi_startproc\n");
974 /* .cfi_personality and .cfi_lsda are only relevant to DWARF2
976 if (targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
)
979 rtx personality
= get_personality_function (current_function_decl
);
983 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
986 /* ??? The GAS support isn't entirely consistent. We have to
987 handle indirect support ourselves, but PC-relative is done
988 in the assembler. Further, the assembler can't handle any
989 of the weirder relocation types. */
990 if (enc
& DW_EH_PE_indirect
)
991 ref
= dw2_force_const_mem (ref
, true);
993 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
994 output_addr_const (asm_out_file
, ref
);
995 fputc ('\n', asm_out_file
);
998 if (crtl
->uses_eh_lsda
)
1000 char lab
[MAX_ARTIFICIAL_LABEL_BYTES
];
1002 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1003 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
1004 current_function_funcdef_no
);
1005 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
1006 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
1008 if (enc
& DW_EH_PE_indirect
)
1009 ref
= dw2_force_const_mem (ref
, true);
1011 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
1012 output_addr_const (asm_out_file
, ref
);
1013 fputc ('\n', asm_out_file
);
1017 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1018 this allocation may be done before pass_final. */
1021 dwarf2out_alloc_current_fde (void)
1025 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1026 fde
->decl
= current_function_decl
;
1027 fde
->funcdef_number
= current_function_funcdef_no
;
1028 fde
->fde_index
= vec_safe_length (fde_vec
);
1029 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1030 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1031 fde
->nothrow
= crtl
->nothrow
;
1032 fde
->drap_reg
= INVALID_REGNUM
;
1033 fde
->vdrap_reg
= INVALID_REGNUM
;
1035 /* Record the FDE associated with this function. */
1037 vec_safe_push (fde_vec
, fde
);
1042 /* Output a marker (i.e. a label) for the beginning of a function, before
1046 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1047 unsigned int column ATTRIBUTE_UNUSED
,
1048 const char *file ATTRIBUTE_UNUSED
)
1050 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1056 current_function_func_begin_label
= NULL
;
1058 do_frame
= dwarf2out_do_frame ();
1060 /* ??? current_function_func_begin_label is also used by except.c for
1061 call-site information. We must emit this label if it might be used. */
1063 && (!flag_exceptions
1064 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1067 fnsec
= function_section (current_function_decl
);
1068 switch_to_section (fnsec
);
1069 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1070 current_function_funcdef_no
);
1071 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1072 current_function_funcdef_no
);
1073 dup_label
= xstrdup (label
);
1074 current_function_func_begin_label
= dup_label
;
1076 /* We can elide FDE allocation if we're not emitting frame unwind info. */
1080 /* Unlike the debug version, the EH version of frame unwind info is a per-
1081 function setting so we need to record whether we need it for the unit. */
1082 do_eh_frame
|= dwarf2out_do_eh_frame ();
1084 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1085 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1086 would include pass_dwarf2_frame. If we've not created the FDE yet,
1090 fde
= dwarf2out_alloc_current_fde ();
1092 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1093 fde
->dw_fde_begin
= dup_label
;
1094 fde
->dw_fde_current_label
= dup_label
;
1095 fde
->in_std_section
= (fnsec
== text_section
1096 || (cold_text_section
&& fnsec
== cold_text_section
));
1098 /* We only want to output line number information for the genuine dwarf2
1099 prologue case, not the eh frame case. */
1100 #ifdef DWARF2_DEBUGGING_INFO
1102 dwarf2out_source_line (line
, column
, file
, 0, true);
1105 if (dwarf2out_do_cfi_asm ())
1106 dwarf2out_do_cfi_startproc (false);
1109 rtx personality
= get_personality_function (current_function_decl
);
1110 if (!current_unit_personality
)
1111 current_unit_personality
= personality
;
1113 /* We cannot keep a current personality per function as without CFI
1114 asm, at the point where we emit the CFI data, there is no current
1115 function anymore. */
1116 if (personality
&& current_unit_personality
!= personality
)
1117 sorry ("multiple EH personalities are supported only with assemblers "
1118 "supporting .cfi_personality directive");
1122 /* Output a marker (i.e. a label) for the end of the generated code
1123 for a function prologue. This gets called *after* the prologue code has
1127 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1128 const char *file ATTRIBUTE_UNUSED
)
1130 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1132 /* Output a label to mark the endpoint of the code generated for this
1134 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1135 current_function_funcdef_no
);
1136 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1137 current_function_funcdef_no
);
1138 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1141 /* Output a marker (i.e. a label) for the beginning of the generated code
1142 for a function epilogue. This gets called *before* the prologue code has
1146 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1147 const char *file ATTRIBUTE_UNUSED
)
1149 dw_fde_ref fde
= cfun
->fde
;
1150 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1152 if (fde
->dw_fde_vms_begin_epilogue
)
1155 /* Output a label to mark the endpoint of the code generated for this
1157 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1158 current_function_funcdef_no
);
1159 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1160 current_function_funcdef_no
);
1161 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1164 /* Output a marker (i.e. a label) for the absolute end of the generated code
1165 for a function definition. This gets called *after* the epilogue code has
1169 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1170 const char *file ATTRIBUTE_UNUSED
)
1173 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1175 last_var_location_insn
= NULL
;
1176 cached_next_real_insn
= NULL
;
1178 if (dwarf2out_do_cfi_asm ())
1179 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1181 /* Output a label to mark the endpoint of the code generated for this
1183 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1184 current_function_funcdef_no
);
1185 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1187 gcc_assert (fde
!= NULL
);
1188 if (fde
->dw_fde_second_begin
== NULL
)
1189 fde
->dw_fde_end
= xstrdup (label
);
1193 dwarf2out_frame_finish (void)
1195 /* Output call frame information. */
1196 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1197 output_call_frame_info (0);
1199 /* Output another copy for the unwinder. */
1201 output_call_frame_info (1);
1204 /* Note that the current function section is being used for code. */
1207 dwarf2out_note_section_used (void)
1209 section
*sec
= current_function_section ();
1210 if (sec
== text_section
)
1211 text_section_used
= true;
1212 else if (sec
== cold_text_section
)
1213 cold_text_section_used
= true;
1216 static void var_location_switch_text_section (void);
1217 static void set_cur_line_info_table (section
*);
1220 dwarf2out_switch_text_section (void)
1223 dw_fde_ref fde
= cfun
->fde
;
1225 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1227 if (!in_cold_section_p
)
1229 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1230 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1231 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1235 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1236 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1237 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1239 have_multiple_function_sections
= true;
1241 /* There is no need to mark used sections when not debugging. */
1242 if (cold_text_section
!= NULL
)
1243 dwarf2out_note_section_used ();
1245 if (dwarf2out_do_cfi_asm ())
1246 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1248 /* Now do the real section switch. */
1249 sect
= current_function_section ();
1250 switch_to_section (sect
);
1252 fde
->second_in_std_section
1253 = (sect
== text_section
1254 || (cold_text_section
&& sect
== cold_text_section
));
1256 if (dwarf2out_do_cfi_asm ())
1257 dwarf2out_do_cfi_startproc (true);
1259 var_location_switch_text_section ();
1261 if (cold_text_section
!= NULL
)
1262 set_cur_line_info_table (sect
);
1265 /* And now, the subset of the debugging information support code necessary
1266 for emitting location expressions. */
1268 /* Data about a single source file. */
1269 struct GTY((for_user
)) dwarf_file_data
{
1270 const char * filename
;
1274 /* Describe an entry into the .debug_addr section. */
1278 ate_kind_rtx_dtprel
,
1282 struct GTY((for_user
)) addr_table_entry
{
1284 unsigned int refcount
;
1286 union addr_table_entry_struct_union
1288 rtx
GTY ((tag ("0"))) rtl
;
1289 char * GTY ((tag ("1"))) label
;
1291 GTY ((desc ("%1.kind"))) addr
;
1294 typedef unsigned int var_loc_view
;
1296 /* Location lists are ranges + location descriptions for that range,
1297 so you can track variables that are in different places over
1298 their entire life. */
1299 typedef struct GTY(()) dw_loc_list_struct
{
1300 dw_loc_list_ref dw_loc_next
;
1301 const char *begin
; /* Label and addr_entry for start of range */
1302 addr_table_entry
*begin_entry
;
1303 const char *end
; /* Label for end of range */
1304 char *ll_symbol
; /* Label for beginning of location list.
1305 Only on head of list. */
1306 char *vl_symbol
; /* Label for beginning of view list. Ditto. */
1307 const char *section
; /* Section this loclist is relative to */
1308 dw_loc_descr_ref expr
;
1309 var_loc_view vbegin
, vend
;
1311 /* True if all addresses in this and subsequent lists are known to be
1314 /* True if this list has been replaced by dw_loc_next. */
1316 /* True if it has been emitted into .debug_loc* / .debug_loclists*
1318 unsigned char emitted
: 1;
1319 /* True if hash field is index rather than hash value. */
1320 unsigned char num_assigned
: 1;
1321 /* True if .debug_loclists.dwo offset has been emitted for it already. */
1322 unsigned char offset_emitted
: 1;
1323 /* True if note_variable_value_in_expr has been called on it. */
1324 unsigned char noted_variable_value
: 1;
1325 /* True if the range should be emitted even if begin and end
1330 static dw_loc_descr_ref
int_loc_descriptor (poly_int64
);
1331 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1333 /* Convert a DWARF stack opcode into its string name. */
1336 dwarf_stack_op_name (unsigned int op
)
1338 const char *name
= get_DW_OP_name (op
);
1343 return "OP_<unknown>";
1346 /* Return TRUE iff we're to output location view lists as a separate
1347 attribute next to the location lists, as an extension compatible
1348 with DWARF 2 and above. */
1351 dwarf2out_locviews_in_attribute ()
1353 return debug_variable_location_views
== 1;
1356 /* Return TRUE iff we're to output location view lists as part of the
1357 location lists, as proposed for standardization after DWARF 5. */
1360 dwarf2out_locviews_in_loclist ()
1362 #ifndef DW_LLE_view_pair
1365 return debug_variable_location_views
== -1;
1369 /* Return a pointer to a newly allocated location description. Location
1370 descriptions are simple expression terms that can be strung
1371 together to form more complicated location (address) descriptions. */
1373 static inline dw_loc_descr_ref
1374 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1375 unsigned HOST_WIDE_INT oprnd2
)
1377 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1379 descr
->dw_loc_opc
= op
;
1380 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1381 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1382 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1383 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1384 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1385 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1390 /* Add a location description term to a location description expression. */
1393 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1395 dw_loc_descr_ref
*d
;
1397 /* Find the end of the chain. */
1398 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1404 /* Compare two location operands for exact equality. */
1407 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1409 if (a
->val_class
!= b
->val_class
)
1411 switch (a
->val_class
)
1413 case dw_val_class_none
:
1415 case dw_val_class_addr
:
1416 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1418 case dw_val_class_offset
:
1419 case dw_val_class_unsigned_const
:
1420 case dw_val_class_const
:
1421 case dw_val_class_unsigned_const_implicit
:
1422 case dw_val_class_const_implicit
:
1423 case dw_val_class_range_list
:
1424 /* These are all HOST_WIDE_INT, signed or unsigned. */
1425 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1427 case dw_val_class_loc
:
1428 return a
->v
.val_loc
== b
->v
.val_loc
;
1429 case dw_val_class_loc_list
:
1430 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1431 case dw_val_class_view_list
:
1432 return a
->v
.val_view_list
== b
->v
.val_view_list
;
1433 case dw_val_class_die_ref
:
1434 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1435 case dw_val_class_fde_ref
:
1436 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1437 case dw_val_class_lbl_id
:
1438 case dw_val_class_lineptr
:
1439 case dw_val_class_macptr
:
1440 case dw_val_class_loclistsptr
:
1441 case dw_val_class_high_pc
:
1442 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1443 case dw_val_class_str
:
1444 return a
->v
.val_str
== b
->v
.val_str
;
1445 case dw_val_class_flag
:
1446 return a
->v
.val_flag
== b
->v
.val_flag
;
1447 case dw_val_class_file
:
1448 case dw_val_class_file_implicit
:
1449 return a
->v
.val_file
== b
->v
.val_file
;
1450 case dw_val_class_decl_ref
:
1451 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1453 case dw_val_class_const_double
:
1454 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1455 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1457 case dw_val_class_wide_int
:
1458 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1460 case dw_val_class_vec
:
1462 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1463 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1465 return (a_len
== b_len
1466 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1469 case dw_val_class_data8
:
1470 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1472 case dw_val_class_vms_delta
:
1473 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1474 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1476 case dw_val_class_discr_value
:
1477 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1478 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1479 case dw_val_class_discr_list
:
1480 /* It makes no sense comparing two discriminant value lists. */
1486 /* Compare two location atoms for exact equality. */
1489 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1491 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1494 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1495 address size, but since we always allocate cleared storage it
1496 should be zero for other types of locations. */
1497 if (a
->dtprel
!= b
->dtprel
)
1500 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1501 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1504 /* Compare two complete location expressions for exact equality. */
1507 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1513 if (a
== NULL
|| b
== NULL
)
1515 if (!loc_descr_equal_p_1 (a
, b
))
1524 /* Add a constant POLY_OFFSET to a location expression. */
1527 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, poly_int64 poly_offset
)
1529 dw_loc_descr_ref loc
;
1532 gcc_assert (*list_head
!= NULL
);
1534 if (known_eq (poly_offset
, 0))
1537 /* Find the end of the chain. */
1538 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1541 HOST_WIDE_INT offset
;
1542 if (!poly_offset
.is_constant (&offset
))
1544 loc
->dw_loc_next
= int_loc_descriptor (poly_offset
);
1545 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_plus
, 0, 0));
1550 if (loc
->dw_loc_opc
== DW_OP_fbreg
1551 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1552 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1553 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1554 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1556 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1557 offset. Don't optimize if an signed integer overflow would happen. */
1559 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1560 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1563 else if (offset
> 0)
1564 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1569 = uint_loc_descriptor (-(unsigned HOST_WIDE_INT
) offset
);
1570 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1574 /* Return a pointer to a newly allocated location description for
1577 static inline dw_loc_descr_ref
1578 new_reg_loc_descr (unsigned int reg
, poly_int64 offset
)
1580 HOST_WIDE_INT const_offset
;
1581 if (offset
.is_constant (&const_offset
))
1584 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1587 return new_loc_descr (DW_OP_bregx
, reg
, const_offset
);
1591 dw_loc_descr_ref ret
= new_reg_loc_descr (reg
, 0);
1592 loc_descr_plus_const (&ret
, offset
);
1597 /* Add a constant OFFSET to a location list. */
1600 loc_list_plus_const (dw_loc_list_ref list_head
, poly_int64 offset
)
1603 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1604 loc_descr_plus_const (&d
->expr
, offset
);
1607 #define DWARF_REF_SIZE \
1608 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1610 /* The number of bits that can be encoded by largest DW_FORM_dataN.
1611 In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
1612 DW_FORM_data16 with 128 bits. */
1613 #define DWARF_LARGEST_DATA_FORM_BITS \
1614 (dwarf_version >= 5 ? 128 : 64)
1616 /* Utility inline function for construction of ops that were GNU extension
1618 static inline enum dwarf_location_atom
1619 dwarf_OP (enum dwarf_location_atom op
)
1623 case DW_OP_implicit_pointer
:
1624 if (dwarf_version
< 5)
1625 return DW_OP_GNU_implicit_pointer
;
1628 case DW_OP_entry_value
:
1629 if (dwarf_version
< 5)
1630 return DW_OP_GNU_entry_value
;
1633 case DW_OP_const_type
:
1634 if (dwarf_version
< 5)
1635 return DW_OP_GNU_const_type
;
1638 case DW_OP_regval_type
:
1639 if (dwarf_version
< 5)
1640 return DW_OP_GNU_regval_type
;
1643 case DW_OP_deref_type
:
1644 if (dwarf_version
< 5)
1645 return DW_OP_GNU_deref_type
;
1649 if (dwarf_version
< 5)
1650 return DW_OP_GNU_convert
;
1653 case DW_OP_reinterpret
:
1654 if (dwarf_version
< 5)
1655 return DW_OP_GNU_reinterpret
;
1664 /* Similarly for attributes. */
1665 static inline enum dwarf_attribute
1666 dwarf_AT (enum dwarf_attribute at
)
1670 case DW_AT_call_return_pc
:
1671 if (dwarf_version
< 5)
1672 return DW_AT_low_pc
;
1675 case DW_AT_call_tail_call
:
1676 if (dwarf_version
< 5)
1677 return DW_AT_GNU_tail_call
;
1680 case DW_AT_call_origin
:
1681 if (dwarf_version
< 5)
1682 return DW_AT_abstract_origin
;
1685 case DW_AT_call_target
:
1686 if (dwarf_version
< 5)
1687 return DW_AT_GNU_call_site_target
;
1690 case DW_AT_call_target_clobbered
:
1691 if (dwarf_version
< 5)
1692 return DW_AT_GNU_call_site_target_clobbered
;
1695 case DW_AT_call_parameter
:
1696 if (dwarf_version
< 5)
1697 return DW_AT_abstract_origin
;
1700 case DW_AT_call_value
:
1701 if (dwarf_version
< 5)
1702 return DW_AT_GNU_call_site_value
;
1705 case DW_AT_call_data_value
:
1706 if (dwarf_version
< 5)
1707 return DW_AT_GNU_call_site_data_value
;
1710 case DW_AT_call_all_calls
:
1711 if (dwarf_version
< 5)
1712 return DW_AT_GNU_all_call_sites
;
1715 case DW_AT_call_all_tail_calls
:
1716 if (dwarf_version
< 5)
1717 return DW_AT_GNU_all_tail_call_sites
;
1720 case DW_AT_dwo_name
:
1721 if (dwarf_version
< 5)
1722 return DW_AT_GNU_dwo_name
;
1731 /* And similarly for tags. */
1732 static inline enum dwarf_tag
1733 dwarf_TAG (enum dwarf_tag tag
)
1737 case DW_TAG_call_site
:
1738 if (dwarf_version
< 5)
1739 return DW_TAG_GNU_call_site
;
1742 case DW_TAG_call_site_parameter
:
1743 if (dwarf_version
< 5)
1744 return DW_TAG_GNU_call_site_parameter
;
1753 static unsigned long int get_base_type_offset (dw_die_ref
);
1755 /* Return the size of a location descriptor. */
1757 static unsigned long
1758 size_of_loc_descr (dw_loc_descr_ref loc
)
1760 unsigned long size
= 1;
1762 switch (loc
->dw_loc_opc
)
1765 size
+= DWARF2_ADDR_SIZE
;
1767 case DW_OP_GNU_addr_index
:
1768 case DW_OP_GNU_const_index
:
1769 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1770 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1789 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1792 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1797 case DW_OP_plus_uconst
:
1798 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1836 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1839 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1842 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1845 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1846 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1849 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1851 case DW_OP_bit_piece
:
1852 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1853 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1855 case DW_OP_deref_size
:
1856 case DW_OP_xderef_size
:
1865 case DW_OP_call_ref
:
1866 case DW_OP_GNU_variable_value
:
1867 size
+= DWARF_REF_SIZE
;
1869 case DW_OP_implicit_value
:
1870 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1871 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1873 case DW_OP_implicit_pointer
:
1874 case DW_OP_GNU_implicit_pointer
:
1875 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1877 case DW_OP_entry_value
:
1878 case DW_OP_GNU_entry_value
:
1880 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1881 size
+= size_of_uleb128 (op_size
) + op_size
;
1884 case DW_OP_const_type
:
1885 case DW_OP_GNU_const_type
:
1888 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1889 size
+= size_of_uleb128 (o
) + 1;
1890 switch (loc
->dw_loc_oprnd2
.val_class
)
1892 case dw_val_class_vec
:
1893 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1894 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1896 case dw_val_class_const
:
1897 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1899 case dw_val_class_const_double
:
1900 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1902 case dw_val_class_wide_int
:
1903 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1904 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1911 case DW_OP_regval_type
:
1912 case DW_OP_GNU_regval_type
:
1915 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1916 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1917 + size_of_uleb128 (o
);
1920 case DW_OP_deref_type
:
1921 case DW_OP_GNU_deref_type
:
1924 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1925 size
+= 1 + size_of_uleb128 (o
);
1929 case DW_OP_reinterpret
:
1930 case DW_OP_GNU_convert
:
1931 case DW_OP_GNU_reinterpret
:
1932 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1933 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1937 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1938 size
+= size_of_uleb128 (o
);
1941 case DW_OP_GNU_parameter_ref
:
1951 /* Return the size of a series of location descriptors. */
1954 size_of_locs (dw_loc_descr_ref loc
)
1959 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1960 field, to avoid writing to a PCH file. */
1961 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1963 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1965 size
+= size_of_loc_descr (l
);
1970 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1972 l
->dw_loc_addr
= size
;
1973 size
+= size_of_loc_descr (l
);
1979 /* Return the size of the value in a DW_AT_discr_value attribute. */
1982 size_of_discr_value (dw_discr_value
*discr_value
)
1984 if (discr_value
->pos
)
1985 return size_of_uleb128 (discr_value
->v
.uval
);
1987 return size_of_sleb128 (discr_value
->v
.sval
);
1990 /* Return the size of the value in a DW_AT_discr_list attribute. */
1993 size_of_discr_list (dw_discr_list_ref discr_list
)
1997 for (dw_discr_list_ref list
= discr_list
;
1999 list
= list
->dw_discr_next
)
2001 /* One byte for the discriminant value descriptor, and then one or two
2002 LEB128 numbers, depending on whether it's a single case label or a
2005 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
2006 if (list
->dw_discr_range
!= 0)
2007 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
2012 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
2013 static void get_ref_die_offset_label (char *, dw_die_ref
);
2014 static unsigned long int get_ref_die_offset (dw_die_ref
);
2016 /* Output location description stack opcode's operands (if any).
2017 The for_eh_or_skip parameter controls whether register numbers are
2018 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2019 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2020 info). This should be suppressed for the cases that have not been converted
2021 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2024 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2026 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2027 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2029 switch (loc
->dw_loc_opc
)
2031 #ifdef DWARF2_DEBUGGING_INFO
2034 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2039 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2040 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
2042 fputc ('\n', asm_out_file
);
2047 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2052 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2053 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
2055 fputc ('\n', asm_out_file
);
2060 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2061 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2068 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2069 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2071 dw2_asm_output_data (2, offset
, NULL
);
2074 case DW_OP_implicit_value
:
2075 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2076 switch (val2
->val_class
)
2078 case dw_val_class_const
:
2079 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2081 case dw_val_class_vec
:
2083 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2084 unsigned int len
= val2
->v
.val_vec
.length
;
2088 if (elt_size
> sizeof (HOST_WIDE_INT
))
2093 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2096 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2097 "fp or vector constant word %u", i
);
2100 case dw_val_class_const_double
:
2102 unsigned HOST_WIDE_INT first
, second
;
2104 if (WORDS_BIG_ENDIAN
)
2106 first
= val2
->v
.val_double
.high
;
2107 second
= val2
->v
.val_double
.low
;
2111 first
= val2
->v
.val_double
.low
;
2112 second
= val2
->v
.val_double
.high
;
2114 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2116 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2120 case dw_val_class_wide_int
:
2123 int len
= get_full_len (*val2
->v
.val_wide
);
2124 if (WORDS_BIG_ENDIAN
)
2125 for (i
= len
- 1; i
>= 0; --i
)
2126 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2127 val2
->v
.val_wide
->elt (i
), NULL
);
2129 for (i
= 0; i
< len
; ++i
)
2130 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2131 val2
->v
.val_wide
->elt (i
), NULL
);
2134 case dw_val_class_addr
:
2135 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2136 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2151 case DW_OP_implicit_value
:
2152 /* We currently don't make any attempt to make sure these are
2153 aligned properly like we do for the main unwind info, so
2154 don't support emitting things larger than a byte if we're
2155 only doing unwinding. */
2160 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2163 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2166 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2169 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2171 case DW_OP_plus_uconst
:
2172 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2206 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2210 unsigned r
= val1
->v
.val_unsigned
;
2211 if (for_eh_or_skip
>= 0)
2212 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2213 gcc_assert (size_of_uleb128 (r
)
2214 == size_of_uleb128 (val1
->v
.val_unsigned
));
2215 dw2_asm_output_data_uleb128 (r
, NULL
);
2219 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2223 unsigned r
= val1
->v
.val_unsigned
;
2224 if (for_eh_or_skip
>= 0)
2225 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2226 gcc_assert (size_of_uleb128 (r
)
2227 == size_of_uleb128 (val1
->v
.val_unsigned
));
2228 dw2_asm_output_data_uleb128 (r
, NULL
);
2229 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2233 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2235 case DW_OP_bit_piece
:
2236 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2237 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2239 case DW_OP_deref_size
:
2240 case DW_OP_xderef_size
:
2241 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2247 if (targetm
.asm_out
.output_dwarf_dtprel
)
2249 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2252 fputc ('\n', asm_out_file
);
2259 #ifdef DWARF2_DEBUGGING_INFO
2260 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2267 case DW_OP_GNU_addr_index
:
2268 case DW_OP_GNU_const_index
:
2269 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2270 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2271 "(index into .debug_addr)");
2277 unsigned long die_offset
2278 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2279 /* Make sure the offset has been computed and that we can encode it as
2281 gcc_assert (die_offset
> 0
2282 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
2285 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2290 case DW_OP_call_ref
:
2291 case DW_OP_GNU_variable_value
:
2293 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2294 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2295 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2296 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2297 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2301 case DW_OP_implicit_pointer
:
2302 case DW_OP_GNU_implicit_pointer
:
2304 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2305 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2306 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2307 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2308 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2309 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2313 case DW_OP_entry_value
:
2314 case DW_OP_GNU_entry_value
:
2315 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2316 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2319 case DW_OP_const_type
:
2320 case DW_OP_GNU_const_type
:
2322 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2324 dw2_asm_output_data_uleb128 (o
, NULL
);
2325 switch (val2
->val_class
)
2327 case dw_val_class_const
:
2328 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2329 dw2_asm_output_data (1, l
, NULL
);
2330 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2332 case dw_val_class_vec
:
2334 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2335 unsigned int len
= val2
->v
.val_vec
.length
;
2340 dw2_asm_output_data (1, l
, NULL
);
2341 if (elt_size
> sizeof (HOST_WIDE_INT
))
2346 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2349 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2350 "fp or vector constant word %u", i
);
2353 case dw_val_class_const_double
:
2355 unsigned HOST_WIDE_INT first
, second
;
2356 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2358 dw2_asm_output_data (1, 2 * l
, NULL
);
2359 if (WORDS_BIG_ENDIAN
)
2361 first
= val2
->v
.val_double
.high
;
2362 second
= val2
->v
.val_double
.low
;
2366 first
= val2
->v
.val_double
.low
;
2367 second
= val2
->v
.val_double
.high
;
2369 dw2_asm_output_data (l
, first
, NULL
);
2370 dw2_asm_output_data (l
, second
, NULL
);
2373 case dw_val_class_wide_int
:
2376 int len
= get_full_len (*val2
->v
.val_wide
);
2377 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2379 dw2_asm_output_data (1, len
* l
, NULL
);
2380 if (WORDS_BIG_ENDIAN
)
2381 for (i
= len
- 1; i
>= 0; --i
)
2382 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2384 for (i
= 0; i
< len
; ++i
)
2385 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2393 case DW_OP_regval_type
:
2394 case DW_OP_GNU_regval_type
:
2396 unsigned r
= val1
->v
.val_unsigned
;
2397 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2399 if (for_eh_or_skip
>= 0)
2401 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2402 gcc_assert (size_of_uleb128 (r
)
2403 == size_of_uleb128 (val1
->v
.val_unsigned
));
2405 dw2_asm_output_data_uleb128 (r
, NULL
);
2406 dw2_asm_output_data_uleb128 (o
, NULL
);
2409 case DW_OP_deref_type
:
2410 case DW_OP_GNU_deref_type
:
2412 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2414 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2415 dw2_asm_output_data_uleb128 (o
, NULL
);
2419 case DW_OP_reinterpret
:
2420 case DW_OP_GNU_convert
:
2421 case DW_OP_GNU_reinterpret
:
2422 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2423 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2426 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2428 dw2_asm_output_data_uleb128 (o
, NULL
);
2432 case DW_OP_GNU_parameter_ref
:
2435 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2436 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2437 dw2_asm_output_data (4, o
, NULL
);
2442 /* Other codes have no operands. */
2447 /* Output a sequence of location operations.
2448 The for_eh_or_skip parameter controls whether register numbers are
2449 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2450 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2451 info). This should be suppressed for the cases that have not been converted
2452 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2455 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2457 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2459 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2460 /* Output the opcode. */
2461 if (for_eh_or_skip
>= 0
2462 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2464 unsigned r
= (opc
- DW_OP_breg0
);
2465 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2466 gcc_assert (r
<= 31);
2467 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2469 else if (for_eh_or_skip
>= 0
2470 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2472 unsigned r
= (opc
- DW_OP_reg0
);
2473 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2474 gcc_assert (r
<= 31);
2475 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2478 dw2_asm_output_data (1, opc
,
2479 "%s", dwarf_stack_op_name (opc
));
2481 /* Output the operand(s) (if any). */
2482 output_loc_operands (loc
, for_eh_or_skip
);
2486 /* Output location description stack opcode's operands (if any).
2487 The output is single bytes on a line, suitable for .cfi_escape. */
2490 output_loc_operands_raw (dw_loc_descr_ref loc
)
2492 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2493 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2495 switch (loc
->dw_loc_opc
)
2498 case DW_OP_GNU_addr_index
:
2499 case DW_OP_GNU_const_index
:
2500 case DW_OP_implicit_value
:
2501 /* We cannot output addresses in .cfi_escape, only bytes. */
2507 case DW_OP_deref_size
:
2508 case DW_OP_xderef_size
:
2509 fputc (',', asm_out_file
);
2510 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2515 fputc (',', asm_out_file
);
2516 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2521 fputc (',', asm_out_file
);
2522 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2527 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2528 fputc (',', asm_out_file
);
2529 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2537 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2538 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2540 fputc (',', asm_out_file
);
2541 dw2_asm_output_data_raw (2, offset
);
2547 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2548 gcc_assert (size_of_uleb128 (r
)
2549 == size_of_uleb128 (val1
->v
.val_unsigned
));
2550 fputc (',', asm_out_file
);
2551 dw2_asm_output_data_uleb128_raw (r
);
2556 case DW_OP_plus_uconst
:
2558 fputc (',', asm_out_file
);
2559 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2562 case DW_OP_bit_piece
:
2563 fputc (',', asm_out_file
);
2564 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2565 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2602 fputc (',', asm_out_file
);
2603 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2608 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2609 gcc_assert (size_of_uleb128 (r
)
2610 == size_of_uleb128 (val1
->v
.val_unsigned
));
2611 fputc (',', asm_out_file
);
2612 dw2_asm_output_data_uleb128_raw (r
);
2613 fputc (',', asm_out_file
);
2614 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2618 case DW_OP_implicit_pointer
:
2619 case DW_OP_entry_value
:
2620 case DW_OP_const_type
:
2621 case DW_OP_regval_type
:
2622 case DW_OP_deref_type
:
2624 case DW_OP_reinterpret
:
2625 case DW_OP_GNU_implicit_pointer
:
2626 case DW_OP_GNU_entry_value
:
2627 case DW_OP_GNU_const_type
:
2628 case DW_OP_GNU_regval_type
:
2629 case DW_OP_GNU_deref_type
:
2630 case DW_OP_GNU_convert
:
2631 case DW_OP_GNU_reinterpret
:
2632 case DW_OP_GNU_parameter_ref
:
2637 /* Other codes have no operands. */
2643 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2647 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2648 /* Output the opcode. */
2649 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2651 unsigned r
= (opc
- DW_OP_breg0
);
2652 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2653 gcc_assert (r
<= 31);
2654 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2656 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2658 unsigned r
= (opc
- DW_OP_reg0
);
2659 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2660 gcc_assert (r
<= 31);
2661 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2663 /* Output the opcode. */
2664 fprintf (asm_out_file
, "%#x", opc
);
2665 output_loc_operands_raw (loc
);
2667 if (!loc
->dw_loc_next
)
2669 loc
= loc
->dw_loc_next
;
2671 fputc (',', asm_out_file
);
2675 /* This function builds a dwarf location descriptor sequence from a
2676 dw_cfa_location, adding the given OFFSET to the result of the
2679 struct dw_loc_descr_node
*
2680 build_cfa_loc (dw_cfa_location
*cfa
, poly_int64 offset
)
2682 struct dw_loc_descr_node
*head
, *tmp
;
2684 offset
+= cfa
->offset
;
2688 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2689 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2690 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2691 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2692 add_loc_descr (&head
, tmp
);
2693 loc_descr_plus_const (&head
, offset
);
2696 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2701 /* This function builds a dwarf location descriptor sequence for
2702 the address at OFFSET from the CFA when stack is aligned to
2705 struct dw_loc_descr_node
*
2706 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2707 poly_int64 offset
, HOST_WIDE_INT alignment
)
2709 struct dw_loc_descr_node
*head
;
2710 unsigned int dwarf_fp
2711 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2713 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2714 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2716 head
= new_reg_loc_descr (dwarf_fp
, 0);
2717 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2718 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2719 loc_descr_plus_const (&head
, offset
);
2722 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2726 /* And now, the support for symbolic debugging information. */
2728 /* .debug_str support. */
2730 static void dwarf2out_init (const char *);
2731 static void dwarf2out_finish (const char *);
2732 static void dwarf2out_early_finish (const char *);
2733 static void dwarf2out_assembly_start (void);
2734 static void dwarf2out_define (unsigned int, const char *);
2735 static void dwarf2out_undef (unsigned int, const char *);
2736 static void dwarf2out_start_source_file (unsigned, const char *);
2737 static void dwarf2out_end_source_file (unsigned);
2738 static void dwarf2out_function_decl (tree
);
2739 static void dwarf2out_begin_block (unsigned, unsigned);
2740 static void dwarf2out_end_block (unsigned, unsigned);
2741 static bool dwarf2out_ignore_block (const_tree
);
2742 static void dwarf2out_early_global_decl (tree
);
2743 static void dwarf2out_late_global_decl (tree
);
2744 static void dwarf2out_type_decl (tree
, int);
2745 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool, bool);
2746 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2748 static void dwarf2out_abstract_function (tree
);
2749 static void dwarf2out_var_location (rtx_insn
*);
2750 static void dwarf2out_inline_entry (tree
);
2751 static void dwarf2out_size_function (tree
);
2752 static void dwarf2out_begin_function (tree
);
2753 static void dwarf2out_end_function (unsigned int);
2754 static void dwarf2out_register_main_translation_unit (tree unit
);
2755 static void dwarf2out_set_name (tree
, tree
);
2756 static void dwarf2out_register_external_die (tree decl
, const char *sym
,
2757 unsigned HOST_WIDE_INT off
);
2758 static bool dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
2759 unsigned HOST_WIDE_INT
*off
);
2761 /* The debug hooks structure. */
2763 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2767 dwarf2out_early_finish
,
2768 dwarf2out_assembly_start
,
2771 dwarf2out_start_source_file
,
2772 dwarf2out_end_source_file
,
2773 dwarf2out_begin_block
,
2774 dwarf2out_end_block
,
2775 dwarf2out_ignore_block
,
2776 dwarf2out_source_line
,
2777 dwarf2out_begin_prologue
,
2778 #if VMS_DEBUGGING_INFO
2779 dwarf2out_vms_end_prologue
,
2780 dwarf2out_vms_begin_epilogue
,
2782 debug_nothing_int_charstar
,
2783 debug_nothing_int_charstar
,
2785 dwarf2out_end_epilogue
,
2786 dwarf2out_begin_function
,
2787 dwarf2out_end_function
, /* end_function */
2788 dwarf2out_register_main_translation_unit
,
2789 dwarf2out_function_decl
, /* function_decl */
2790 dwarf2out_early_global_decl
,
2791 dwarf2out_late_global_decl
,
2792 dwarf2out_type_decl
, /* type_decl */
2793 dwarf2out_imported_module_or_decl
,
2794 dwarf2out_die_ref_for_decl
,
2795 dwarf2out_register_external_die
,
2796 debug_nothing_tree
, /* deferred_inline_function */
2797 /* The DWARF 2 backend tries to reduce debugging bloat by not
2798 emitting the abstract description of inline functions until
2799 something tries to reference them. */
2800 dwarf2out_abstract_function
, /* outlining_inline_function */
2801 debug_nothing_rtx_code_label
, /* label */
2802 debug_nothing_int
, /* handle_pch */
2803 dwarf2out_var_location
,
2804 dwarf2out_inline_entry
, /* inline_entry */
2805 dwarf2out_size_function
, /* size_function */
2806 dwarf2out_switch_text_section
,
2808 1, /* start_end_main_source_file */
2809 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2812 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2815 debug_nothing_charstar
,
2816 debug_nothing_charstar
,
2817 dwarf2out_assembly_start
,
2818 debug_nothing_int_charstar
,
2819 debug_nothing_int_charstar
,
2820 debug_nothing_int_charstar
,
2822 debug_nothing_int_int
, /* begin_block */
2823 debug_nothing_int_int
, /* end_block */
2824 debug_true_const_tree
, /* ignore_block */
2825 dwarf2out_source_line
, /* source_line */
2826 debug_nothing_int_int_charstar
, /* begin_prologue */
2827 debug_nothing_int_charstar
, /* end_prologue */
2828 debug_nothing_int_charstar
, /* begin_epilogue */
2829 debug_nothing_int_charstar
, /* end_epilogue */
2830 debug_nothing_tree
, /* begin_function */
2831 debug_nothing_int
, /* end_function */
2832 debug_nothing_tree
, /* register_main_translation_unit */
2833 debug_nothing_tree
, /* function_decl */
2834 debug_nothing_tree
, /* early_global_decl */
2835 debug_nothing_tree
, /* late_global_decl */
2836 debug_nothing_tree_int
, /* type_decl */
2837 debug_nothing_tree_tree_tree_bool_bool
,/* imported_module_or_decl */
2838 debug_false_tree_charstarstar_uhwistar
,/* die_ref_for_decl */
2839 debug_nothing_tree_charstar_uhwi
, /* register_external_die */
2840 debug_nothing_tree
, /* deferred_inline_function */
2841 debug_nothing_tree
, /* outlining_inline_function */
2842 debug_nothing_rtx_code_label
, /* label */
2843 debug_nothing_int
, /* handle_pch */
2844 debug_nothing_rtx_insn
, /* var_location */
2845 debug_nothing_tree
, /* inline_entry */
2846 debug_nothing_tree
, /* size_function */
2847 debug_nothing_void
, /* switch_text_section */
2848 debug_nothing_tree_tree
, /* set_name */
2849 0, /* start_end_main_source_file */
2850 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2853 /* NOTE: In the comments in this file, many references are made to
2854 "Debugging Information Entries". This term is abbreviated as `DIE'
2855 throughout the remainder of this file. */
2857 /* An internal representation of the DWARF output is built, and then
2858 walked to generate the DWARF debugging info. The walk of the internal
2859 representation is done after the entire program has been compiled.
2860 The types below are used to describe the internal representation. */
2862 /* Whether to put type DIEs into their own section .debug_types instead
2863 of making them part of the .debug_info section. Only supported for
2864 Dwarf V4 or higher and the user didn't disable them through
2865 -fno-debug-types-section. It is more efficient to put them in a
2866 separate comdat sections since the linker will then be able to
2867 remove duplicates. But not all tools support .debug_types sections
2868 yet. For Dwarf V5 or higher .debug_types doesn't exist any more,
2869 it is DW_UT_type unit type in .debug_info section. */
2871 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2873 /* Various DIE's use offsets relative to the beginning of the
2874 .debug_info section to refer to each other. */
2876 typedef long int dw_offset
;
2878 struct comdat_type_node
;
2880 /* The entries in the line_info table more-or-less mirror the opcodes
2881 that are used in the real dwarf line table. Arrays of these entries
2882 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2885 enum dw_line_info_opcode
{
2886 /* Emit DW_LNE_set_address; the operand is the label index. */
2889 /* Emit a row to the matrix with the given line. This may be done
2890 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2894 /* Emit a DW_LNS_set_file. */
2897 /* Emit a DW_LNS_set_column. */
2900 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2903 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2904 LI_set_prologue_end
,
2905 LI_set_epilogue_begin
,
2907 /* Emit a DW_LNE_set_discriminator. */
2908 LI_set_discriminator
,
2910 /* Output a Fixed Advance PC; the target PC is the label index; the
2911 base PC is the previous LI_adv_address or LI_set_address entry.
2912 We only use this when emitting debug views without assembler
2913 support, at explicit user request. Ideally, we should only use
2914 it when the offset might be zero but we can't tell: it's the only
2915 way to maybe change the PC without resetting the view number. */
2919 typedef struct GTY(()) dw_line_info_struct
{
2920 enum dw_line_info_opcode opcode
;
2922 } dw_line_info_entry
;
2925 struct GTY(()) dw_line_info_table
{
2926 /* The label that marks the end of this section. */
2927 const char *end_label
;
2929 /* The values for the last row of the matrix, as collected in the table.
2930 These are used to minimize the changes to the next row. */
2931 unsigned int file_num
;
2932 unsigned int line_num
;
2933 unsigned int column_num
;
2938 /* This denotes the NEXT view number.
2940 If it is 0, it is known that the NEXT view will be the first view
2943 If it is -1, we've advanced PC but we haven't emitted a line location yet,
2944 so we shouldn't use this view number.
2946 The meaning of other nonzero values depends on whether we're
2947 computing views internally or leaving it for the assembler to do
2948 so. If we're emitting them internally, view denotes the view
2949 number since the last known advance of PC. If we're leaving it
2950 for the assembler, it denotes the LVU label number that we're
2951 going to ask the assembler to assign. */
2954 #define RESET_NEXT_VIEW(x) ((x) = (var_loc_view)0)
2955 #define RESETTING_VIEW_P(x) ((x) == (var_loc_view)0)
2957 vec
<dw_line_info_entry
, va_gc
> *entries
;
2961 /* Each DIE attribute has a field specifying the attribute kind,
2962 a link to the next attribute in the chain, and an attribute value.
2963 Attributes are typically linked below the DIE they modify. */
2965 typedef struct GTY(()) dw_attr_struct
{
2966 enum dwarf_attribute dw_attr
;
2967 dw_val_node dw_attr_val
;
2972 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2973 The children of each node form a circular list linked by
2974 die_sib. die_child points to the node *before* the "first" child node. */
2976 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2977 union die_symbol_or_type_node
2979 const char * GTY ((tag ("0"))) die_symbol
;
2980 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
2982 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2983 vec
<dw_attr_node
, va_gc
> *die_attr
;
2984 dw_die_ref die_parent
;
2985 dw_die_ref die_child
;
2987 dw_die_ref die_definition
; /* ref from a specification to its definition */
2988 dw_offset die_offset
;
2989 unsigned long die_abbrev
;
2991 unsigned int decl_id
;
2992 enum dwarf_tag die_tag
;
2993 /* Die is used and must not be pruned as unused. */
2994 BOOL_BITFIELD die_perennial_p
: 1;
2995 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2996 /* For an external ref to die_symbol if die_offset contains an extra
2997 offset to that symbol. */
2998 BOOL_BITFIELD with_offset
: 1;
2999 /* Whether this DIE was removed from the DIE tree, for example via
3000 prune_unused_types. We don't consider those present from the
3001 DIE lookup routines. */
3002 BOOL_BITFIELD removed
: 1;
3003 /* Lots of spare bits. */
3007 /* Set to TRUE while dwarf2out_early_global_decl is running. */
3008 static bool early_dwarf
;
3009 static bool early_dwarf_finished
;
3010 struct set_early_dwarf
{
3012 set_early_dwarf () : saved(early_dwarf
)
3014 gcc_assert (! early_dwarf_finished
);
3017 ~set_early_dwarf () { early_dwarf
= saved
; }
3020 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3021 #define FOR_EACH_CHILD(die, c, expr) do { \
3022 c = die->die_child; \
3026 } while (c != die->die_child); \
3029 /* The pubname structure */
3031 typedef struct GTY(()) pubname_struct
{
3038 struct GTY(()) dw_ranges
{
3040 /* If this is positive, it's a block number, otherwise it's a
3041 bitwise-negated index into dw_ranges_by_label. */
3043 /* Index for the range list for DW_FORM_rnglistx. */
3044 unsigned int idx
: 31;
3045 /* True if this range might be possibly in a different section
3046 from previous entry. */
3047 unsigned int maybe_new_sec
: 1;
3050 /* A structure to hold a macinfo entry. */
3052 typedef struct GTY(()) macinfo_struct
{
3054 unsigned HOST_WIDE_INT lineno
;
3060 struct GTY(()) dw_ranges_by_label
{
3065 /* The comdat type node structure. */
3066 struct GTY(()) comdat_type_node
3068 dw_die_ref root_die
;
3069 dw_die_ref type_die
;
3070 dw_die_ref skeleton_die
;
3071 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
3072 comdat_type_node
*next
;
3075 /* A list of DIEs for which we can't determine ancestry (parent_die
3076 field) just yet. Later in dwarf2out_finish we will fill in the
3078 typedef struct GTY(()) limbo_die_struct
{
3080 /* The tree for which this DIE was created. We use this to
3081 determine ancestry later. */
3083 struct limbo_die_struct
*next
;
3087 typedef struct skeleton_chain_struct
3091 struct skeleton_chain_struct
*parent
;
3093 skeleton_chain_node
;
3095 /* Define a macro which returns nonzero for a TYPE_DECL which was
3096 implicitly generated for a type.
3098 Note that, unlike the C front-end (which generates a NULL named
3099 TYPE_DECL node for each complete tagged type, each array type,
3100 and each function type node created) the C++ front-end generates
3101 a _named_ TYPE_DECL node for each tagged type node created.
3102 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3103 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
3104 front-end, but for each type, tagged or not. */
3106 #define TYPE_DECL_IS_STUB(decl) \
3107 (DECL_NAME (decl) == NULL_TREE \
3108 || (DECL_ARTIFICIAL (decl) \
3109 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3110 /* This is necessary for stub decls that \
3111 appear in nested inline functions. */ \
3112 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3113 && (decl_ultimate_origin (decl) \
3114 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3116 /* Information concerning the compilation unit's programming
3117 language, and compiler version. */
3119 /* Fixed size portion of the DWARF compilation unit header. */
3120 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3121 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE \
3122 + (dwarf_version >= 5 ? 4 : 3))
3124 /* Fixed size portion of the DWARF comdat type unit header. */
3125 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3126 (DWARF_COMPILE_UNIT_HEADER_SIZE \
3127 + DWARF_TYPE_SIGNATURE_SIZE + DWARF_OFFSET_SIZE)
3129 /* Fixed size portion of the DWARF skeleton compilation unit header. */
3130 #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
3131 (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
3133 /* Fixed size portion of public names info. */
3134 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3136 /* Fixed size portion of the address range info. */
3137 #define DWARF_ARANGES_HEADER_SIZE \
3138 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3139 DWARF2_ADDR_SIZE * 2) \
3140 - DWARF_INITIAL_LENGTH_SIZE)
3142 /* Size of padding portion in the address range info. It must be
3143 aligned to twice the pointer size. */
3144 #define DWARF_ARANGES_PAD_SIZE \
3145 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3146 DWARF2_ADDR_SIZE * 2) \
3147 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3149 /* Use assembler line directives if available. */
3150 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3151 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3152 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3154 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3158 /* Use assembler views in line directives if available. */
3159 #ifndef DWARF2_ASM_VIEW_DEBUG_INFO
3160 #ifdef HAVE_AS_DWARF2_DEBUG_VIEW
3161 #define DWARF2_ASM_VIEW_DEBUG_INFO 1
3163 #define DWARF2_ASM_VIEW_DEBUG_INFO 0
3167 /* A bit is set in ZERO_VIEW_P if we are using the assembler-supported
3168 view computation, and it refers to a view identifier for which we
3169 will not emit a label because it is known to map to a view number
3170 zero. We won't allocate the bitmap if we're not using assembler
3171 support for location views, but we have to make the variable
3172 visible for GGC and for code that will be optimized out for lack of
3173 support but that's still parsed and compiled. We could abstract it
3174 out with macros, but it's not worth it. */
3175 static GTY(()) bitmap zero_view_p
;
3177 /* Evaluate to TRUE iff N is known to identify the first location view
3178 at its PC. When not using assembler location view computation,
3179 that must be view number zero. Otherwise, ZERO_VIEW_P is allocated
3180 and views label numbers recorded in it are the ones known to be
3182 #define ZERO_VIEW_P(N) (zero_view_p \
3183 ? bitmap_bit_p (zero_view_p, (N)) \
3186 /* Return true iff we're to emit .loc directives for the assembler to
3187 generate line number sections.
3189 When we're not emitting views, all we need from the assembler is
3190 support for .loc directives.
3192 If we are emitting views, we can only use the assembler's .loc
3193 support if it also supports views.
3195 When the compiler is emitting the line number programs and
3196 computing view numbers itself, it resets view numbers at known PC
3197 changes and counts from that, and then it emits view numbers as
3198 literal constants in locviewlists. There are cases in which the
3199 compiler is not sure about PC changes, e.g. when extra alignment is
3200 requested for a label. In these cases, the compiler may not reset
3201 the view counter, and the potential PC advance in the line number
3202 program will use an opcode that does not reset the view counter
3203 even if the PC actually changes, so that compiler and debug info
3204 consumer can keep view numbers in sync.
3206 When the compiler defers view computation to the assembler, it
3207 emits symbolic view numbers in locviewlists, with the exception of
3208 views known to be zero (forced resets, or reset after
3209 compiler-visible PC changes): instead of emitting symbols for
3210 these, we emit literal zero and assert the assembler agrees with
3211 the compiler's assessment. We could use symbolic views everywhere,
3212 instead of special-casing zero views, but then we'd be unable to
3213 optimize out locviewlists that contain only zeros. */
3216 output_asm_line_debug_info (void)
3218 return (DWARF2_ASM_VIEW_DEBUG_INFO
3219 || (DWARF2_ASM_LINE_DEBUG_INFO
3220 && !debug_variable_location_views
));
3223 /* Minimum line offset in a special line info. opcode.
3224 This value was chosen to give a reasonable range of values. */
3225 #define DWARF_LINE_BASE -10
3227 /* First special line opcode - leave room for the standard opcodes. */
3228 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3230 /* Range of line offsets in a special line info. opcode. */
3231 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3233 /* Flag that indicates the initial value of the is_stmt_start flag.
3234 In the present implementation, we do not mark any lines as
3235 the beginning of a source statement, because that information
3236 is not made available by the GCC front-end. */
3237 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3239 /* Maximum number of operations per instruction bundle. */
3240 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3241 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3244 /* This location is used by calc_die_sizes() to keep track
3245 the offset of each DIE within the .debug_info section. */
3246 static unsigned long next_die_offset
;
3248 /* Record the root of the DIE's built for the current compilation unit. */
3249 static GTY(()) dw_die_ref single_comp_unit_die
;
3251 /* A list of type DIEs that have been separated into comdat sections. */
3252 static GTY(()) comdat_type_node
*comdat_type_list
;
3254 /* A list of CU DIEs that have been separated. */
3255 static GTY(()) limbo_die_node
*cu_die_list
;
3257 /* A list of DIEs with a NULL parent waiting to be relocated. */
3258 static GTY(()) limbo_die_node
*limbo_die_list
;
3260 /* A list of DIEs for which we may have to generate
3261 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3262 static GTY(()) limbo_die_node
*deferred_asm_name
;
3264 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
3266 typedef const char *compare_type
;
3268 static hashval_t
hash (dwarf_file_data
*);
3269 static bool equal (dwarf_file_data
*, const char *);
3272 /* Filenames referenced by this compilation unit. */
3273 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
3275 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
3277 typedef tree compare_type
;
3279 static hashval_t
hash (die_node
*);
3280 static bool equal (die_node
*, tree
);
3282 /* A hash table of references to DIE's that describe declarations.
3283 The key is a DECL_UID() which is a unique number identifying each decl. */
3284 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
3286 struct GTY ((for_user
)) variable_value_struct
{
3287 unsigned int decl_id
;
3288 vec
<dw_die_ref
, va_gc
> *dies
;
3291 struct variable_value_hasher
: ggc_ptr_hash
<variable_value_struct
>
3293 typedef tree compare_type
;
3295 static hashval_t
hash (variable_value_struct
*);
3296 static bool equal (variable_value_struct
*, tree
);
3298 /* A hash table of DIEs that contain DW_OP_GNU_variable_value with
3299 dw_val_class_decl_ref class, indexed by FUNCTION_DECLs which is
3300 DECL_CONTEXT of the referenced VAR_DECLs. */
3301 static GTY (()) hash_table
<variable_value_hasher
> *variable_value_hash
;
3303 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
3305 static hashval_t
hash (die_struct
*);
3306 static bool equal (die_struct
*, die_struct
*);
3309 /* A hash table of references to DIE's that describe COMMON blocks.
3310 The key is DECL_UID() ^ die_parent. */
3311 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
3313 typedef struct GTY(()) die_arg_entry_struct
{
3319 /* Node of the variable location list. */
3320 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3321 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3322 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3323 in mode of the EXPR_LIST node and first EXPR_LIST operand
3324 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3325 location or NULL for padding. For larger bitsizes,
3326 mode is 0 and first operand is a CONCAT with bitsize
3327 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3328 NULL as second operand. */
3330 const char * GTY (()) label
;
3331 struct var_loc_node
* GTY (()) next
;
3335 /* Variable location list. */
3336 struct GTY ((for_user
)) var_loc_list_def
{
3337 struct var_loc_node
* GTY (()) first
;
3339 /* Pointer to the last but one or last element of the
3340 chained list. If the list is empty, both first and
3341 last are NULL, if the list contains just one node
3342 or the last node certainly is not redundant, it points
3343 to the last node, otherwise points to the last but one.
3344 Do not mark it for GC because it is marked through the chain. */
3345 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3347 /* Pointer to the last element before section switch,
3348 if NULL, either sections weren't switched or first
3349 is after section switch. */
3350 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3352 /* DECL_UID of the variable decl. */
3353 unsigned int decl_id
;
3355 typedef struct var_loc_list_def var_loc_list
;
3357 /* Call argument location list. */
3358 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3359 rtx
GTY (()) call_arg_loc_note
;
3360 const char * GTY (()) label
;
3361 tree
GTY (()) block
;
3363 rtx
GTY (()) symbol_ref
;
3364 struct call_arg_loc_node
* GTY (()) next
;
3368 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
3370 typedef const_tree compare_type
;
3372 static hashval_t
hash (var_loc_list
*);
3373 static bool equal (var_loc_list
*, const_tree
);
3376 /* Table of decl location linked lists. */
3377 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
3379 /* Head and tail of call_arg_loc chain. */
3380 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3381 static struct call_arg_loc_node
*call_arg_loc_last
;
3383 /* Number of call sites in the current function. */
3384 static int call_site_count
= -1;
3385 /* Number of tail call sites in the current function. */
3386 static int tail_call_site_count
= -1;
3388 /* A cached location list. */
3389 struct GTY ((for_user
)) cached_dw_loc_list_def
{
3390 /* The DECL_UID of the decl that this entry describes. */
3391 unsigned int decl_id
;
3393 /* The cached location list. */
3394 dw_loc_list_ref loc_list
;
3396 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3398 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3401 typedef const_tree compare_type
;
3403 static hashval_t
hash (cached_dw_loc_list
*);
3404 static bool equal (cached_dw_loc_list
*, const_tree
);
3407 /* Table of cached location lists. */
3408 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3410 /* A vector of references to DIE's that are uniquely identified by their tag,
3411 presence/absence of children DIE's, and list of attribute/value pairs. */
3412 static GTY(()) vec
<dw_die_ref
, va_gc
> *abbrev_die_table
;
3414 /* A hash map to remember the stack usage for DWARF procedures. The value
3415 stored is the stack size difference between before the DWARF procedure
3416 invokation and after it returned. In other words, for a DWARF procedure
3417 that consumes N stack slots and that pushes M ones, this stores M - N. */
3418 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3420 /* A global counter for generating labels for line number data. */
3421 static unsigned int line_info_label_num
;
3423 /* The current table to which we should emit line number information
3424 for the current function. This will be set up at the beginning of
3425 assembly for the function. */
3426 static GTY(()) dw_line_info_table
*cur_line_info_table
;
3428 /* The two default tables of line number info. */
3429 static GTY(()) dw_line_info_table
*text_section_line_info
;
3430 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3432 /* The set of all non-default tables of line number info. */
3433 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3435 /* A flag to tell pubnames/types export if there is an info section to
3437 static bool info_section_emitted
;
3439 /* A pointer to the base of a table that contains a list of publicly
3440 accessible names. */
3441 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3443 /* A pointer to the base of a table that contains a list of publicly
3444 accessible types. */
3445 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3447 /* A pointer to the base of a table that contains a list of macro
3448 defines/undefines (and file start/end markers). */
3449 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3451 /* True if .debug_macinfo or .debug_macros section is going to be
3453 #define have_macinfo \
3454 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3455 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3456 && !macinfo_table->is_empty ())
3458 /* Vector of dies for which we should generate .debug_ranges info. */
3459 static GTY (()) vec
<dw_ranges
, va_gc
> *ranges_table
;
3461 /* Vector of pairs of labels referenced in ranges_table. */
3462 static GTY (()) vec
<dw_ranges_by_label
, va_gc
> *ranges_by_label
;
3464 /* Whether we have location lists that need outputting */
3465 static GTY(()) bool have_location_lists
;
3467 /* Unique label counter. */
3468 static GTY(()) unsigned int loclabel_num
;
3470 /* Unique label counter for point-of-call tables. */
3471 static GTY(()) unsigned int poc_label_num
;
3473 /* The last file entry emitted by maybe_emit_file(). */
3474 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3476 /* Number of internal labels generated by gen_internal_sym(). */
3477 static GTY(()) int label_num
;
3479 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3481 /* Instances of generic types for which we need to generate debug
3482 info that describe their generic parameters and arguments. That
3483 generation needs to happen once all types are properly laid out so
3484 we do it at the end of compilation. */
3485 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3487 /* Offset from the "steady-state frame pointer" to the frame base,
3488 within the current function. */
3489 static poly_int64 frame_pointer_fb_offset
;
3490 static bool frame_pointer_fb_offset_valid
;
3492 static vec
<dw_die_ref
> base_types
;
3494 /* Flags to represent a set of attribute classes for attributes that represent
3495 a scalar value (bounds, pointers, ...). */
3498 dw_scalar_form_constant
= 0x01,
3499 dw_scalar_form_exprloc
= 0x02,
3500 dw_scalar_form_reference
= 0x04
3503 /* Forward declarations for functions defined in this file. */
3505 static int is_pseudo_reg (const_rtx
);
3506 static tree
type_main_variant (tree
);
3507 static int is_tagged_type (const_tree
);
3508 static const char *dwarf_tag_name (unsigned);
3509 static const char *dwarf_attr_name (unsigned);
3510 static const char *dwarf_form_name (unsigned);
3511 static tree
decl_ultimate_origin (const_tree
);
3512 static tree
decl_class_context (tree
);
3513 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3514 static inline enum dw_val_class
AT_class (dw_attr_node
*);
3515 static inline unsigned int AT_index (dw_attr_node
*);
3516 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3517 static inline unsigned AT_flag (dw_attr_node
*);
3518 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3519 static inline HOST_WIDE_INT
AT_int (dw_attr_node
*);
3520 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3521 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_node
*);
3522 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3523 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3524 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3525 unsigned int, unsigned char *);
3526 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3527 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3528 static inline const char *AT_string (dw_attr_node
*);
3529 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3530 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3531 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3532 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3533 static inline int AT_ref_external (dw_attr_node
*);
3534 static inline void set_AT_ref_external (dw_attr_node
*, int);
3535 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3536 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3537 static inline dw_loc_descr_ref
AT_loc (dw_attr_node
*);
3538 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3540 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3541 static void add_AT_view_list (dw_die_ref
, enum dwarf_attribute
);
3542 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3543 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3544 static void remove_addr_table_entry (addr_table_entry
*);
3545 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3546 static inline rtx
AT_addr (dw_attr_node
*);
3547 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3548 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3549 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3550 static void add_AT_loclistsptr (dw_die_ref
, enum dwarf_attribute
,
3552 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3553 unsigned HOST_WIDE_INT
);
3554 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3555 unsigned long, bool);
3556 static inline const char *AT_lbl (dw_attr_node
*);
3557 static dw_attr_node
*get_AT (dw_die_ref
, enum dwarf_attribute
);
3558 static const char *get_AT_low_pc (dw_die_ref
);
3559 static const char *get_AT_hi_pc (dw_die_ref
);
3560 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3561 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3562 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3563 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3564 static bool is_cxx (void);
3565 static bool is_cxx (const_tree
);
3566 static bool is_fortran (void);
3567 static bool is_ada (void);
3568 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3569 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3570 static void add_child_die (dw_die_ref
, dw_die_ref
);
3571 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3572 static dw_die_ref
lookup_type_die (tree
);
3573 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3574 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3575 static void equate_type_number_to_die (tree
, dw_die_ref
);
3576 static dw_die_ref
lookup_decl_die (tree
);
3577 static var_loc_list
*lookup_decl_loc (const_tree
);
3578 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3579 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *, var_loc_view
);
3580 static void print_spaces (FILE *);
3581 static void print_die (dw_die_ref
, FILE *);
3582 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3583 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3584 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3585 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3586 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3587 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3588 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3589 struct md5_ctx
*, int *);
3590 struct checksum_attributes
;
3591 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3592 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3593 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3594 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3595 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3596 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3597 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3598 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3599 static int is_type_die (dw_die_ref
);
3600 static int is_comdat_die (dw_die_ref
);
3601 static inline bool is_template_instantiation (dw_die_ref
);
3602 static int is_declaration_die (dw_die_ref
);
3603 static int should_move_die_to_comdat (dw_die_ref
);
3604 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3605 static dw_die_ref
clone_die (dw_die_ref
);
3606 static dw_die_ref
clone_tree (dw_die_ref
);
3607 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3608 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3609 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3610 static dw_die_ref
generate_skeleton (dw_die_ref
);
3611 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3614 static void break_out_comdat_types (dw_die_ref
);
3615 static void copy_decls_for_unworthy_types (dw_die_ref
);
3617 static void add_sibling_attributes (dw_die_ref
);
3618 static void output_location_lists (dw_die_ref
);
3619 static int constant_size (unsigned HOST_WIDE_INT
);
3620 static unsigned long size_of_die (dw_die_ref
);
3621 static void calc_die_sizes (dw_die_ref
);
3622 static void calc_base_type_die_sizes (void);
3623 static void mark_dies (dw_die_ref
);
3624 static void unmark_dies (dw_die_ref
);
3625 static void unmark_all_dies (dw_die_ref
);
3626 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3627 static unsigned long size_of_aranges (void);
3628 static enum dwarf_form
value_format (dw_attr_node
*);
3629 static void output_value_format (dw_attr_node
*);
3630 static void output_abbrev_section (void);
3631 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3632 static void output_die (dw_die_ref
);
3633 static void output_compilation_unit_header (enum dwarf_unit_type
);
3634 static void output_comp_unit (dw_die_ref
, int, const unsigned char *);
3635 static void output_comdat_type_unit (comdat_type_node
*);
3636 static const char *dwarf2_name (tree
, int);
3637 static void add_pubname (tree
, dw_die_ref
);
3638 static void add_enumerator_pubname (const char *, dw_die_ref
);
3639 static void add_pubname_string (const char *, dw_die_ref
);
3640 static void add_pubtype (tree
, dw_die_ref
);
3641 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3642 static void output_aranges (void);
3643 static unsigned int add_ranges (const_tree
, bool = false);
3644 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3646 static void output_ranges (void);
3647 static dw_line_info_table
*new_line_info_table (void);
3648 static void output_line_info (bool);
3649 static void output_file_names (void);
3650 static dw_die_ref
base_type_die (tree
, bool);
3651 static int is_base_type (tree
);
3652 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3653 static int decl_quals (const_tree
);
3654 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3655 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3656 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3657 static int type_is_enum (const_tree
);
3658 static unsigned int dbx_reg_number (const_rtx
);
3659 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3660 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3661 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3662 enum var_init_status
);
3663 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3664 enum var_init_status
);
3665 static dw_loc_descr_ref
based_loc_descr (rtx
, poly_int64
,
3666 enum var_init_status
);
3667 static int is_based_loc (const_rtx
);
3668 static bool resolve_one_addr (rtx
*);
3669 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3670 enum var_init_status
);
3671 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3672 enum var_init_status
);
3673 struct loc_descr_context
;
3674 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3675 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3676 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3677 struct loc_descr_context
*);
3678 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3679 struct loc_descr_context
*);
3680 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3681 static tree
field_type (const_tree
);
3682 static unsigned int simple_type_align_in_bits (const_tree
);
3683 static unsigned int simple_decl_align_in_bits (const_tree
);
3684 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3686 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3688 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3690 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3691 struct vlr_context
*);
3692 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3693 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3694 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3695 static void insert_float (const_rtx
, unsigned char *);
3696 static rtx
rtl_for_decl_location (tree
);
3697 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3698 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3699 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3700 static void add_name_attribute (dw_die_ref
, const char *);
3701 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3702 static void add_comp_dir_attribute (dw_die_ref
);
3703 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3704 struct loc_descr_context
*);
3705 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3706 struct loc_descr_context
*);
3707 static void add_subscript_info (dw_die_ref
, tree
, bool);
3708 static void add_byte_size_attribute (dw_die_ref
, tree
);
3709 static void add_alignment_attribute (dw_die_ref
, tree
);
3710 static inline void add_bit_offset_attribute (dw_die_ref
, tree
,
3711 struct vlr_context
*);
3712 static void add_bit_size_attribute (dw_die_ref
, tree
);
3713 static void add_prototyped_attribute (dw_die_ref
, tree
);
3714 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3715 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3716 static void add_src_coords_attributes (dw_die_ref
, tree
);
3717 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
, bool = false);
3718 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3719 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3720 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3721 static void push_decl_scope (tree
);
3722 static void pop_decl_scope (void);
3723 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3724 static inline int local_scope_p (dw_die_ref
);
3725 static inline int class_scope_p (dw_die_ref
);
3726 static inline int class_or_namespace_scope_p (dw_die_ref
);
3727 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3728 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3729 static const char *type_tag (const_tree
);
3730 static tree
member_declared_type (const_tree
);
3732 static const char *decl_start_label (tree
);
3734 static void gen_array_type_die (tree
, dw_die_ref
);
3735 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3737 static void gen_entry_point_die (tree
, dw_die_ref
);
3739 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3740 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3741 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3742 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3743 static void gen_formal_types_die (tree
, dw_die_ref
);
3744 static void gen_subprogram_die (tree
, dw_die_ref
);
3745 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3746 static void gen_const_die (tree
, dw_die_ref
);
3747 static void gen_label_die (tree
, dw_die_ref
);
3748 static void gen_lexical_block_die (tree
, dw_die_ref
);
3749 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3750 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3751 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3752 static dw_die_ref
gen_compile_unit_die (const char *);
3753 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3754 static void gen_member_die (tree
, dw_die_ref
);
3755 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3756 enum debug_info_usage
);
3757 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3758 static void gen_typedef_die (tree
, dw_die_ref
);
3759 static void gen_type_die (tree
, dw_die_ref
);
3760 static void gen_block_die (tree
, dw_die_ref
);
3761 static void decls_for_scope (tree
, dw_die_ref
);
3762 static bool is_naming_typedef_decl (const_tree
);
3763 static inline dw_die_ref
get_context_die (tree
);
3764 static void gen_namespace_die (tree
, dw_die_ref
);
3765 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3766 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3767 static dw_die_ref
force_decl_die (tree
);
3768 static dw_die_ref
force_type_die (tree
);
3769 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3770 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3771 static struct dwarf_file_data
* lookup_filename (const char *);
3772 static void retry_incomplete_types (void);
3773 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3774 static void gen_generic_params_dies (tree
);
3775 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3776 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3777 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3778 static int file_info_cmp (const void *, const void *);
3779 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *, var_loc_view
,
3780 const char *, var_loc_view
, const char *);
3781 static void output_loc_list (dw_loc_list_ref
);
3782 static char *gen_internal_sym (const char *);
3783 static bool want_pubnames (void);
3785 static void prune_unmark_dies (dw_die_ref
);
3786 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3787 static void prune_unused_types_mark (dw_die_ref
, int);
3788 static void prune_unused_types_walk (dw_die_ref
);
3789 static void prune_unused_types_walk_attribs (dw_die_ref
);
3790 static void prune_unused_types_prune (dw_die_ref
);
3791 static void prune_unused_types (void);
3792 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3793 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3794 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3795 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3796 const char *, const char *);
3797 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3798 static void gen_remaining_tmpl_value_param_die_attribute (void);
3799 static bool generic_type_p (tree
);
3800 static void schedule_generic_params_dies_gen (tree t
);
3801 static void gen_scheduled_generic_parms_dies (void);
3802 static void resolve_variable_values (void);
3804 static const char *comp_dir_string (void);
3806 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3808 /* enum for tracking thread-local variables whose address is really an offset
3809 relative to the TLS pointer, which will need link-time relocation, but will
3810 not need relocation by the DWARF consumer. */
3818 /* Return the operator to use for an address of a variable. For dtprel_true, we
3819 use DW_OP_const*. For regular variables, which need both link-time
3820 relocation and consumer-level relocation (e.g., to account for shared objects
3821 loaded at a random address), we use DW_OP_addr*. */
3823 static inline enum dwarf_location_atom
3824 dw_addr_op (enum dtprel_bool dtprel
)
3826 if (dtprel
== dtprel_true
)
3827 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3828 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3830 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3833 /* Return a pointer to a newly allocated address location description. If
3834 dwarf_split_debug_info is true, then record the address with the appropriate
3836 static inline dw_loc_descr_ref
3837 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3839 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3841 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3842 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3843 ref
->dtprel
= dtprel
;
3844 if (dwarf_split_debug_info
)
3845 ref
->dw_loc_oprnd1
.val_entry
3846 = add_addr_table_entry (addr
,
3847 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3849 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3854 /* Section names used to hold DWARF debugging information. */
3856 #ifndef DEBUG_INFO_SECTION
3857 #define DEBUG_INFO_SECTION ".debug_info"
3859 #ifndef DEBUG_DWO_INFO_SECTION
3860 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3862 #ifndef DEBUG_LTO_INFO_SECTION
3863 #define DEBUG_LTO_INFO_SECTION ".gnu.debuglto_.debug_info"
3865 #ifndef DEBUG_LTO_DWO_INFO_SECTION
3866 #define DEBUG_LTO_DWO_INFO_SECTION ".gnu.debuglto_.debug_info.dwo"
3868 #ifndef DEBUG_ABBREV_SECTION
3869 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3871 #ifndef DEBUG_LTO_ABBREV_SECTION
3872 #define DEBUG_LTO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev"
3874 #ifndef DEBUG_DWO_ABBREV_SECTION
3875 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3877 #ifndef DEBUG_LTO_DWO_ABBREV_SECTION
3878 #define DEBUG_LTO_DWO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev.dwo"
3880 #ifndef DEBUG_ARANGES_SECTION
3881 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3883 #ifndef DEBUG_ADDR_SECTION
3884 #define DEBUG_ADDR_SECTION ".debug_addr"
3886 #ifndef DEBUG_MACINFO_SECTION
3887 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3889 #ifndef DEBUG_LTO_MACINFO_SECTION
3890 #define DEBUG_LTO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo"
3892 #ifndef DEBUG_DWO_MACINFO_SECTION
3893 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3895 #ifndef DEBUG_LTO_DWO_MACINFO_SECTION
3896 #define DEBUG_LTO_DWO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo.dwo"
3898 #ifndef DEBUG_MACRO_SECTION
3899 #define DEBUG_MACRO_SECTION ".debug_macro"
3901 #ifndef DEBUG_LTO_MACRO_SECTION
3902 #define DEBUG_LTO_MACRO_SECTION ".gnu.debuglto_.debug_macro"
3904 #ifndef DEBUG_DWO_MACRO_SECTION
3905 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3907 #ifndef DEBUG_LTO_DWO_MACRO_SECTION
3908 #define DEBUG_LTO_DWO_MACRO_SECTION ".gnu.debuglto_.debug_macro.dwo"
3910 #ifndef DEBUG_LINE_SECTION
3911 #define DEBUG_LINE_SECTION ".debug_line"
3913 #ifndef DEBUG_LTO_LINE_SECTION
3914 #define DEBUG_LTO_LINE_SECTION ".gnu.debuglto_.debug_line"
3916 #ifndef DEBUG_DWO_LINE_SECTION
3917 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3919 #ifndef DEBUG_LTO_DWO_LINE_SECTION
3920 #define DEBUG_LTO_DWO_LINE_SECTION ".gnu.debuglto_.debug_line.dwo"
3922 #ifndef DEBUG_LOC_SECTION
3923 #define DEBUG_LOC_SECTION ".debug_loc"
3925 #ifndef DEBUG_DWO_LOC_SECTION
3926 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3928 #ifndef DEBUG_LOCLISTS_SECTION
3929 #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
3931 #ifndef DEBUG_DWO_LOCLISTS_SECTION
3932 #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
3934 #ifndef DEBUG_PUBNAMES_SECTION
3935 #define DEBUG_PUBNAMES_SECTION \
3936 ((debug_generate_pub_sections == 2) \
3937 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3939 #ifndef DEBUG_PUBTYPES_SECTION
3940 #define DEBUG_PUBTYPES_SECTION \
3941 ((debug_generate_pub_sections == 2) \
3942 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3944 #ifndef DEBUG_STR_OFFSETS_SECTION
3945 #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
3947 #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
3948 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3950 #ifndef DEBUG_LTO_DWO_STR_OFFSETS_SECTION
3951 #define DEBUG_LTO_DWO_STR_OFFSETS_SECTION ".gnu.debuglto_.debug_str_offsets.dwo"
3953 #ifndef DEBUG_STR_SECTION
3954 #define DEBUG_STR_SECTION ".debug_str"
3956 #ifndef DEBUG_LTO_STR_SECTION
3957 #define DEBUG_LTO_STR_SECTION ".gnu.debuglto_.debug_str"
3959 #ifndef DEBUG_STR_DWO_SECTION
3960 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3962 #ifndef DEBUG_LTO_STR_DWO_SECTION
3963 #define DEBUG_LTO_STR_DWO_SECTION ".gnu.debuglto_.debug_str.dwo"
3965 #ifndef DEBUG_RANGES_SECTION
3966 #define DEBUG_RANGES_SECTION ".debug_ranges"
3968 #ifndef DEBUG_RNGLISTS_SECTION
3969 #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
3971 #ifndef DEBUG_LINE_STR_SECTION
3972 #define DEBUG_LINE_STR_SECTION ".debug_line_str"
3974 #ifndef DEBUG_LTO_LINE_STR_SECTION
3975 #define DEBUG_LTO_LINE_STR_SECTION ".gnu.debuglto_.debug_line_str"
3978 /* Standard ELF section names for compiled code and data. */
3979 #ifndef TEXT_SECTION_NAME
3980 #define TEXT_SECTION_NAME ".text"
3983 /* Section flags for .debug_str section. */
3984 #define DEBUG_STR_SECTION_FLAGS \
3985 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3986 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3989 /* Section flags for .debug_str.dwo section. */
3990 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3992 /* Attribute used to refer to the macro section. */
3993 #define DEBUG_MACRO_ATTRIBUTE (dwarf_version >= 5 ? DW_AT_macros \
3994 : dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros)
3996 /* Labels we insert at beginning sections we can reference instead of
3997 the section names themselves. */
3999 #ifndef TEXT_SECTION_LABEL
4000 #define TEXT_SECTION_LABEL "Ltext"
4002 #ifndef COLD_TEXT_SECTION_LABEL
4003 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4005 #ifndef DEBUG_LINE_SECTION_LABEL
4006 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4008 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
4009 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
4011 #ifndef DEBUG_INFO_SECTION_LABEL
4012 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4014 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
4015 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
4017 #ifndef DEBUG_ABBREV_SECTION_LABEL
4018 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4020 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
4021 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
4023 #ifndef DEBUG_ADDR_SECTION_LABEL
4024 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
4026 #ifndef DEBUG_LOC_SECTION_LABEL
4027 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4029 #ifndef DEBUG_RANGES_SECTION_LABEL
4030 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4032 #ifndef DEBUG_MACINFO_SECTION_LABEL
4033 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4035 #ifndef DEBUG_MACRO_SECTION_LABEL
4036 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
4038 #define SKELETON_COMP_DIE_ABBREV 1
4039 #define SKELETON_TYPE_DIE_ABBREV 2
4041 /* Definitions of defaults for formats and names of various special
4042 (artificial) labels which may be generated within this file (when the -g
4043 options is used and DWARF2_DEBUGGING_INFO is in effect.
4044 If necessary, these may be overridden from within the tm.h file, but
4045 typically, overriding these defaults is unnecessary. */
4047 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4048 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4049 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4050 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4051 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4052 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4053 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4054 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4055 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4056 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4057 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4058 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4059 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4060 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4061 static char ranges_base_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4063 #ifndef TEXT_END_LABEL
4064 #define TEXT_END_LABEL "Letext"
4066 #ifndef COLD_END_LABEL
4067 #define COLD_END_LABEL "Letext_cold"
4069 #ifndef BLOCK_BEGIN_LABEL
4070 #define BLOCK_BEGIN_LABEL "LBB"
4072 #ifndef BLOCK_INLINE_ENTRY_LABEL
4073 #define BLOCK_INLINE_ENTRY_LABEL "LBI"
4075 #ifndef BLOCK_END_LABEL
4076 #define BLOCK_END_LABEL "LBE"
4078 #ifndef LINE_CODE_LABEL
4079 #define LINE_CODE_LABEL "LM"
4083 /* Return the root of the DIE's built for the current compilation unit. */
4085 comp_unit_die (void)
4087 if (!single_comp_unit_die
)
4088 single_comp_unit_die
= gen_compile_unit_die (NULL
);
4089 return single_comp_unit_die
;
4092 /* We allow a language front-end to designate a function that is to be
4093 called to "demangle" any name before it is put into a DIE. */
4095 static const char *(*demangle_name_func
) (const char *);
4098 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
4100 demangle_name_func
= func
;
4103 /* Test if rtl node points to a pseudo register. */
4106 is_pseudo_reg (const_rtx rtl
)
4108 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
4109 || (GET_CODE (rtl
) == SUBREG
4110 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
4113 /* Return a reference to a type, with its const and volatile qualifiers
4117 type_main_variant (tree type
)
4119 type
= TYPE_MAIN_VARIANT (type
);
4121 /* ??? There really should be only one main variant among any group of
4122 variants of a given type (and all of the MAIN_VARIANT values for all
4123 members of the group should point to that one type) but sometimes the C
4124 front-end messes this up for array types, so we work around that bug
4126 if (TREE_CODE (type
) == ARRAY_TYPE
)
4127 while (type
!= TYPE_MAIN_VARIANT (type
))
4128 type
= TYPE_MAIN_VARIANT (type
);
4133 /* Return nonzero if the given type node represents a tagged type. */
4136 is_tagged_type (const_tree type
)
4138 enum tree_code code
= TREE_CODE (type
);
4140 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4141 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4144 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
4147 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
4149 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
4152 /* Return die_offset of a DIE reference to a base type. */
4154 static unsigned long int
4155 get_base_type_offset (dw_die_ref ref
)
4157 if (ref
->die_offset
)
4158 return ref
->die_offset
;
4159 if (comp_unit_die ()->die_abbrev
)
4161 calc_base_type_die_sizes ();
4162 gcc_assert (ref
->die_offset
);
4164 return ref
->die_offset
;
4167 /* Return die_offset of a DIE reference other than base type. */
4169 static unsigned long int
4170 get_ref_die_offset (dw_die_ref ref
)
4172 gcc_assert (ref
->die_offset
);
4173 return ref
->die_offset
;
4176 /* Convert a DIE tag into its string name. */
4179 dwarf_tag_name (unsigned int tag
)
4181 const char *name
= get_DW_TAG_name (tag
);
4186 return "DW_TAG_<unknown>";
4189 /* Convert a DWARF attribute code into its string name. */
4192 dwarf_attr_name (unsigned int attr
)
4198 #if VMS_DEBUGGING_INFO
4199 case DW_AT_HP_prologue
:
4200 return "DW_AT_HP_prologue";
4202 case DW_AT_MIPS_loop_unroll_factor
:
4203 return "DW_AT_MIPS_loop_unroll_factor";
4206 #if VMS_DEBUGGING_INFO
4207 case DW_AT_HP_epilogue
:
4208 return "DW_AT_HP_epilogue";
4210 case DW_AT_MIPS_stride
:
4211 return "DW_AT_MIPS_stride";
4215 name
= get_DW_AT_name (attr
);
4220 return "DW_AT_<unknown>";
4223 /* Convert a DWARF value form code into its string name. */
4226 dwarf_form_name (unsigned int form
)
4228 const char *name
= get_DW_FORM_name (form
);
4233 return "DW_FORM_<unknown>";
4236 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4237 instance of an inlined instance of a decl which is local to an inline
4238 function, so we have to trace all of the way back through the origin chain
4239 to find out what sort of node actually served as the original seed for the
4243 decl_ultimate_origin (const_tree decl
)
4245 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4248 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4249 we're trying to output the abstract instance of this function. */
4250 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4253 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4254 most distant ancestor, this should never happen. */
4255 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4257 return DECL_ABSTRACT_ORIGIN (decl
);
4260 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4261 of a virtual function may refer to a base class, so we check the 'this'
4265 decl_class_context (tree decl
)
4267 tree context
= NULL_TREE
;
4269 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4270 context
= DECL_CONTEXT (decl
);
4272 context
= TYPE_MAIN_VARIANT
4273 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4275 if (context
&& !TYPE_P (context
))
4276 context
= NULL_TREE
;
4281 /* Add an attribute/value pair to a DIE. */
4284 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
4286 /* Maybe this should be an assert? */
4292 /* Check we do not add duplicate attrs. Can't use get_AT here
4293 because that recurses to the specification/abstract origin DIE. */
4296 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4297 gcc_assert (a
->dw_attr
!= attr
->dw_attr
);
4300 vec_safe_reserve (die
->die_attr
, 1);
4301 vec_safe_push (die
->die_attr
, *attr
);
4304 static inline enum dw_val_class
4305 AT_class (dw_attr_node
*a
)
4307 return a
->dw_attr_val
.val_class
;
4310 /* Return the index for any attribute that will be referenced with a
4311 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
4312 are stored in dw_attr_val.v.val_str for reference counting
4315 static inline unsigned int
4316 AT_index (dw_attr_node
*a
)
4318 if (AT_class (a
) == dw_val_class_str
)
4319 return a
->dw_attr_val
.v
.val_str
->index
;
4320 else if (a
->dw_attr_val
.val_entry
!= NULL
)
4321 return a
->dw_attr_val
.val_entry
->index
;
4325 /* Add a flag value attribute to a DIE. */
4328 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4332 attr
.dw_attr
= attr_kind
;
4333 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4334 attr
.dw_attr_val
.val_entry
= NULL
;
4335 attr
.dw_attr_val
.v
.val_flag
= flag
;
4336 add_dwarf_attr (die
, &attr
);
4339 static inline unsigned
4340 AT_flag (dw_attr_node
*a
)
4342 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4343 return a
->dw_attr_val
.v
.val_flag
;
4346 /* Add a signed integer attribute value to a DIE. */
4349 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4353 attr
.dw_attr
= attr_kind
;
4354 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4355 attr
.dw_attr_val
.val_entry
= NULL
;
4356 attr
.dw_attr_val
.v
.val_int
= int_val
;
4357 add_dwarf_attr (die
, &attr
);
4360 static inline HOST_WIDE_INT
4361 AT_int (dw_attr_node
*a
)
4363 gcc_assert (a
&& (AT_class (a
) == dw_val_class_const
4364 || AT_class (a
) == dw_val_class_const_implicit
));
4365 return a
->dw_attr_val
.v
.val_int
;
4368 /* Add an unsigned integer attribute value to a DIE. */
4371 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4372 unsigned HOST_WIDE_INT unsigned_val
)
4376 attr
.dw_attr
= attr_kind
;
4377 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4378 attr
.dw_attr_val
.val_entry
= NULL
;
4379 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4380 add_dwarf_attr (die
, &attr
);
4383 static inline unsigned HOST_WIDE_INT
4384 AT_unsigned (dw_attr_node
*a
)
4386 gcc_assert (a
&& (AT_class (a
) == dw_val_class_unsigned_const
4387 || AT_class (a
) == dw_val_class_unsigned_const_implicit
));
4388 return a
->dw_attr_val
.v
.val_unsigned
;
4391 /* Add an unsigned wide integer attribute value to a DIE. */
4394 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4399 attr
.dw_attr
= attr_kind
;
4400 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
4401 attr
.dw_attr_val
.val_entry
= NULL
;
4402 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
4403 *attr
.dw_attr_val
.v
.val_wide
= w
;
4404 add_dwarf_attr (die
, &attr
);
4407 /* Add an unsigned double integer attribute value to a DIE. */
4410 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4411 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4415 attr
.dw_attr
= attr_kind
;
4416 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4417 attr
.dw_attr_val
.val_entry
= NULL
;
4418 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4419 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4420 add_dwarf_attr (die
, &attr
);
4423 /* Add a floating point attribute value to a DIE and return it. */
4426 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4427 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4431 attr
.dw_attr
= attr_kind
;
4432 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4433 attr
.dw_attr_val
.val_entry
= NULL
;
4434 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4435 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4436 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4437 add_dwarf_attr (die
, &attr
);
4440 /* Add an 8-byte data attribute value to a DIE. */
4443 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4444 unsigned char data8
[8])
4448 attr
.dw_attr
= attr_kind
;
4449 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4450 attr
.dw_attr_val
.val_entry
= NULL
;
4451 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4452 add_dwarf_attr (die
, &attr
);
4455 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4456 dwarf_split_debug_info, address attributes in dies destined for the
4457 final executable have force_direct set to avoid using indexed
4461 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4467 lbl_id
= xstrdup (lbl_low
);
4468 attr
.dw_attr
= DW_AT_low_pc
;
4469 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4470 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4471 if (dwarf_split_debug_info
&& !force_direct
)
4472 attr
.dw_attr_val
.val_entry
4473 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4475 attr
.dw_attr_val
.val_entry
= NULL
;
4476 add_dwarf_attr (die
, &attr
);
4478 attr
.dw_attr
= DW_AT_high_pc
;
4479 if (dwarf_version
< 4)
4480 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4482 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4483 lbl_id
= xstrdup (lbl_high
);
4484 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4485 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4486 && dwarf_split_debug_info
&& !force_direct
)
4487 attr
.dw_attr_val
.val_entry
4488 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4490 attr
.dw_attr_val
.val_entry
= NULL
;
4491 add_dwarf_attr (die
, &attr
);
4494 /* Hash and equality functions for debug_str_hash. */
4497 indirect_string_hasher::hash (indirect_string_node
*x
)
4499 return htab_hash_string (x
->str
);
4503 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4505 return strcmp (x1
->str
, x2
) == 0;
4508 /* Add STR to the given string hash table. */
4510 static struct indirect_string_node
*
4511 find_AT_string_in_table (const char *str
,
4512 hash_table
<indirect_string_hasher
> *table
)
4514 struct indirect_string_node
*node
;
4516 indirect_string_node
**slot
4517 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
4520 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4521 node
->str
= ggc_strdup (str
);
4531 /* Add STR to the indirect string hash table. */
4533 static struct indirect_string_node
*
4534 find_AT_string (const char *str
)
4536 if (! debug_str_hash
)
4537 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4539 return find_AT_string_in_table (str
, debug_str_hash
);
4542 /* Add a string attribute value to a DIE. */
4545 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4548 struct indirect_string_node
*node
;
4550 node
= find_AT_string (str
);
4552 attr
.dw_attr
= attr_kind
;
4553 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4554 attr
.dw_attr_val
.val_entry
= NULL
;
4555 attr
.dw_attr_val
.v
.val_str
= node
;
4556 add_dwarf_attr (die
, &attr
);
4559 static inline const char *
4560 AT_string (dw_attr_node
*a
)
4562 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4563 return a
->dw_attr_val
.v
.val_str
->str
;
4566 /* Call this function directly to bypass AT_string_form's logic to put
4567 the string inline in the die. */
4570 set_indirect_string (struct indirect_string_node
*node
)
4572 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4573 /* Already indirect is a no op. */
4574 if (node
->form
== DW_FORM_strp
4575 || node
->form
== DW_FORM_line_strp
4576 || node
->form
== DW_FORM_GNU_str_index
)
4578 gcc_assert (node
->label
);
4581 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4582 ++dw2_string_counter
;
4583 node
->label
= xstrdup (label
);
4585 if (!dwarf_split_debug_info
)
4587 node
->form
= DW_FORM_strp
;
4588 node
->index
= NOT_INDEXED
;
4592 node
->form
= DW_FORM_GNU_str_index
;
4593 node
->index
= NO_INDEX_ASSIGNED
;
4597 /* A helper function for dwarf2out_finish, called to reset indirect
4598 string decisions done for early LTO dwarf output before fat object
4602 reset_indirect_string (indirect_string_node
**h
, void *)
4604 struct indirect_string_node
*node
= *h
;
4605 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4609 node
->form
= (dwarf_form
) 0;
4615 /* Find out whether a string should be output inline in DIE
4616 or out-of-line in .debug_str section. */
4618 static enum dwarf_form
4619 find_string_form (struct indirect_string_node
*node
)
4626 len
= strlen (node
->str
) + 1;
4628 /* If the string is shorter or equal to the size of the reference, it is
4629 always better to put it inline. */
4630 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4631 return node
->form
= DW_FORM_string
;
4633 /* If we cannot expect the linker to merge strings in .debug_str
4634 section, only put it into .debug_str if it is worth even in this
4636 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4637 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4638 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4639 return node
->form
= DW_FORM_string
;
4641 set_indirect_string (node
);
4646 /* Find out whether the string referenced from the attribute should be
4647 output inline in DIE or out-of-line in .debug_str section. */
4649 static enum dwarf_form
4650 AT_string_form (dw_attr_node
*a
)
4652 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4653 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4656 /* Add a DIE reference attribute value to a DIE. */
4659 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4662 gcc_checking_assert (targ_die
!= NULL
);
4664 /* With LTO we can end up trying to reference something we didn't create
4665 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4666 if (targ_die
== NULL
)
4669 attr
.dw_attr
= attr_kind
;
4670 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4671 attr
.dw_attr_val
.val_entry
= NULL
;
4672 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4673 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4674 add_dwarf_attr (die
, &attr
);
4677 /* Change DIE reference REF to point to NEW_DIE instead. */
4680 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4682 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4683 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4684 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4687 /* Add an AT_specification attribute to a DIE, and also make the back
4688 pointer from the specification to the definition. */
4691 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4693 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4694 gcc_assert (!targ_die
->die_definition
);
4695 targ_die
->die_definition
= die
;
4698 static inline dw_die_ref
4699 AT_ref (dw_attr_node
*a
)
4701 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4702 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4706 AT_ref_external (dw_attr_node
*a
)
4708 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4709 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4715 set_AT_ref_external (dw_attr_node
*a
, int i
)
4717 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4718 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4721 /* Add an FDE reference attribute value to a DIE. */
4724 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4728 attr
.dw_attr
= attr_kind
;
4729 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4730 attr
.dw_attr_val
.val_entry
= NULL
;
4731 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4732 add_dwarf_attr (die
, &attr
);
4735 /* Add a location description attribute value to a DIE. */
4738 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4742 attr
.dw_attr
= attr_kind
;
4743 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4744 attr
.dw_attr_val
.val_entry
= NULL
;
4745 attr
.dw_attr_val
.v
.val_loc
= loc
;
4746 add_dwarf_attr (die
, &attr
);
4749 static inline dw_loc_descr_ref
4750 AT_loc (dw_attr_node
*a
)
4752 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4753 return a
->dw_attr_val
.v
.val_loc
;
4757 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4761 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4764 attr
.dw_attr
= attr_kind
;
4765 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4766 attr
.dw_attr_val
.val_entry
= NULL
;
4767 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4768 add_dwarf_attr (die
, &attr
);
4769 have_location_lists
= true;
4772 static inline dw_loc_list_ref
4773 AT_loc_list (dw_attr_node
*a
)
4775 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4776 return a
->dw_attr_val
.v
.val_loc_list
;
4779 /* Add a view list attribute to DIE. It must have a DW_AT_location
4780 attribute, because the view list complements the location list. */
4783 add_AT_view_list (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4787 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4790 attr
.dw_attr
= attr_kind
;
4791 attr
.dw_attr_val
.val_class
= dw_val_class_view_list
;
4792 attr
.dw_attr_val
.val_entry
= NULL
;
4793 attr
.dw_attr_val
.v
.val_view_list
= die
;
4794 add_dwarf_attr (die
, &attr
);
4795 gcc_checking_assert (get_AT (die
, DW_AT_location
));
4796 gcc_assert (have_location_lists
);
4799 /* Return a pointer to the location list referenced by the attribute.
4800 If the named attribute is a view list, look up the corresponding
4801 DW_AT_location attribute and return its location list. */
4803 static inline dw_loc_list_ref
*
4804 AT_loc_list_ptr (dw_attr_node
*a
)
4807 switch (AT_class (a
))
4809 case dw_val_class_loc_list
:
4810 return &a
->dw_attr_val
.v
.val_loc_list
;
4811 case dw_val_class_view_list
:
4814 l
= get_AT (a
->dw_attr_val
.v
.val_view_list
, DW_AT_location
);
4817 gcc_checking_assert (l
+ 1 == a
);
4818 return AT_loc_list_ptr (l
);
4825 /* Return the location attribute value associated with a view list
4828 static inline dw_val_node
*
4829 view_list_to_loc_list_val_node (dw_val_node
*val
)
4831 gcc_assert (val
->val_class
== dw_val_class_view_list
);
4832 dw_attr_node
*loc
= get_AT (val
->v
.val_view_list
, DW_AT_location
);
4835 gcc_checking_assert (&(loc
+ 1)->dw_attr_val
== val
);
4836 gcc_assert (AT_class (loc
) == dw_val_class_loc_list
);
4837 return &loc
->dw_attr_val
;
4840 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4842 static hashval_t
hash (addr_table_entry
*);
4843 static bool equal (addr_table_entry
*, addr_table_entry
*);
4846 /* Table of entries into the .debug_addr section. */
4848 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4850 /* Hash an address_table_entry. */
4853 addr_hasher::hash (addr_table_entry
*a
)
4855 inchash::hash hstate
;
4861 case ate_kind_rtx_dtprel
:
4864 case ate_kind_label
:
4865 return htab_hash_string (a
->addr
.label
);
4869 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4870 return hstate
.end ();
4873 /* Determine equality for two address_table_entries. */
4876 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4878 if (a1
->kind
!= a2
->kind
)
4883 case ate_kind_rtx_dtprel
:
4884 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4885 case ate_kind_label
:
4886 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4892 /* Initialize an addr_table_entry. */
4895 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4901 case ate_kind_rtx_dtprel
:
4902 e
->addr
.rtl
= (rtx
) addr
;
4904 case ate_kind_label
:
4905 e
->addr
.label
= (char *) addr
;
4909 e
->index
= NO_INDEX_ASSIGNED
;
4912 /* Add attr to the address table entry to the table. Defer setting an
4913 index until output time. */
4915 static addr_table_entry
*
4916 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4918 addr_table_entry
*node
;
4919 addr_table_entry finder
;
4921 gcc_assert (dwarf_split_debug_info
);
4922 if (! addr_index_table
)
4923 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4924 init_addr_table_entry (&finder
, kind
, addr
);
4925 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4927 if (*slot
== HTAB_EMPTY_ENTRY
)
4929 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4930 init_addr_table_entry (node
, kind
, addr
);
4940 /* Remove an entry from the addr table by decrementing its refcount.
4941 Strictly, decrementing the refcount would be enough, but the
4942 assertion that the entry is actually in the table has found
4946 remove_addr_table_entry (addr_table_entry
*entry
)
4948 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4949 /* After an index is assigned, the table is frozen. */
4950 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4954 /* Given a location list, remove all addresses it refers to from the
4958 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4960 for (; descr
; descr
= descr
->dw_loc_next
)
4961 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4963 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4964 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4968 /* A helper function for dwarf2out_finish called through
4969 htab_traverse. Assign an addr_table_entry its index. All entries
4970 must be collected into the table when this function is called,
4971 because the indexing code relies on htab_traverse to traverse nodes
4972 in the same order for each run. */
4975 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4977 addr_table_entry
*node
= *h
;
4979 /* Don't index unreferenced nodes. */
4980 if (node
->refcount
== 0)
4983 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4984 node
->index
= *index
;
4990 /* Add an address constant attribute value to a DIE. When using
4991 dwarf_split_debug_info, address attributes in dies destined for the
4992 final executable should be direct references--setting the parameter
4993 force_direct ensures this behavior. */
4996 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
5001 attr
.dw_attr
= attr_kind
;
5002 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
5003 attr
.dw_attr_val
.v
.val_addr
= addr
;
5004 if (dwarf_split_debug_info
&& !force_direct
)
5005 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
5007 attr
.dw_attr_val
.val_entry
= NULL
;
5008 add_dwarf_attr (die
, &attr
);
5011 /* Get the RTX from to an address DIE attribute. */
5014 AT_addr (dw_attr_node
*a
)
5016 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
5017 return a
->dw_attr_val
.v
.val_addr
;
5020 /* Add a file attribute value to a DIE. */
5023 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5024 struct dwarf_file_data
*fd
)
5028 attr
.dw_attr
= attr_kind
;
5029 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
5030 attr
.dw_attr_val
.val_entry
= NULL
;
5031 attr
.dw_attr_val
.v
.val_file
= fd
;
5032 add_dwarf_attr (die
, &attr
);
5035 /* Get the dwarf_file_data from a file DIE attribute. */
5037 static inline struct dwarf_file_data
*
5038 AT_file (dw_attr_node
*a
)
5040 gcc_assert (a
&& (AT_class (a
) == dw_val_class_file
5041 || AT_class (a
) == dw_val_class_file_implicit
));
5042 return a
->dw_attr_val
.v
.val_file
;
5045 /* Add a vms delta attribute value to a DIE. */
5048 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5049 const char *lbl1
, const char *lbl2
)
5053 attr
.dw_attr
= attr_kind
;
5054 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
5055 attr
.dw_attr_val
.val_entry
= NULL
;
5056 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
5057 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
5058 add_dwarf_attr (die
, &attr
);
5061 /* Add a label identifier attribute value to a DIE. */
5064 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5069 attr
.dw_attr
= attr_kind
;
5070 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
5071 attr
.dw_attr_val
.val_entry
= NULL
;
5072 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
5073 if (dwarf_split_debug_info
)
5074 attr
.dw_attr_val
.val_entry
5075 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
5077 add_dwarf_attr (die
, &attr
);
5080 /* Add a section offset attribute value to a DIE, an offset into the
5081 debug_line section. */
5084 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5089 attr
.dw_attr
= attr_kind
;
5090 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
5091 attr
.dw_attr_val
.val_entry
= NULL
;
5092 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5093 add_dwarf_attr (die
, &attr
);
5096 /* Add a section offset attribute value to a DIE, an offset into the
5097 debug_loclists section. */
5100 add_AT_loclistsptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5105 attr
.dw_attr
= attr_kind
;
5106 attr
.dw_attr_val
.val_class
= dw_val_class_loclistsptr
;
5107 attr
.dw_attr_val
.val_entry
= NULL
;
5108 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5109 add_dwarf_attr (die
, &attr
);
5112 /* Add a section offset attribute value to a DIE, an offset into the
5113 debug_macinfo section. */
5116 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5121 attr
.dw_attr
= attr_kind
;
5122 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
5123 attr
.dw_attr_val
.val_entry
= NULL
;
5124 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5125 add_dwarf_attr (die
, &attr
);
5128 /* Add an offset attribute value to a DIE. */
5131 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5132 unsigned HOST_WIDE_INT offset
)
5136 attr
.dw_attr
= attr_kind
;
5137 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
5138 attr
.dw_attr_val
.val_entry
= NULL
;
5139 attr
.dw_attr_val
.v
.val_offset
= offset
;
5140 add_dwarf_attr (die
, &attr
);
5143 /* Add a range_list attribute value to a DIE. When using
5144 dwarf_split_debug_info, address attributes in dies destined for the
5145 final executable should be direct references--setting the parameter
5146 force_direct ensures this behavior. */
5148 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
5149 #define RELOCATED_OFFSET (NULL)
5152 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5153 long unsigned int offset
, bool force_direct
)
5157 attr
.dw_attr
= attr_kind
;
5158 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
5159 /* For the range_list attribute, use val_entry to store whether the
5160 offset should follow split-debug-info or normal semantics. This
5161 value is read in output_range_list_offset. */
5162 if (dwarf_split_debug_info
&& !force_direct
)
5163 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
5165 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
5166 attr
.dw_attr_val
.v
.val_offset
= offset
;
5167 add_dwarf_attr (die
, &attr
);
5170 /* Return the start label of a delta attribute. */
5172 static inline const char *
5173 AT_vms_delta1 (dw_attr_node
*a
)
5175 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
5176 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
5179 /* Return the end label of a delta attribute. */
5181 static inline const char *
5182 AT_vms_delta2 (dw_attr_node
*a
)
5184 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
5185 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
5188 static inline const char *
5189 AT_lbl (dw_attr_node
*a
)
5191 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
5192 || AT_class (a
) == dw_val_class_lineptr
5193 || AT_class (a
) == dw_val_class_macptr
5194 || AT_class (a
) == dw_val_class_loclistsptr
5195 || AT_class (a
) == dw_val_class_high_pc
));
5196 return a
->dw_attr_val
.v
.val_lbl_id
;
5199 /* Get the attribute of type attr_kind. */
5201 static dw_attr_node
*
5202 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5206 dw_die_ref spec
= NULL
;
5211 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5212 if (a
->dw_attr
== attr_kind
)
5214 else if (a
->dw_attr
== DW_AT_specification
5215 || a
->dw_attr
== DW_AT_abstract_origin
)
5219 return get_AT (spec
, attr_kind
);
5224 /* Returns the parent of the declaration of DIE. */
5227 get_die_parent (dw_die_ref die
)
5234 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
5235 || (t
= get_AT_ref (die
, DW_AT_specification
)))
5238 return die
->die_parent
;
5241 /* Return the "low pc" attribute value, typically associated with a subprogram
5242 DIE. Return null if the "low pc" attribute is either not present, or if it
5243 cannot be represented as an assembler label identifier. */
5245 static inline const char *
5246 get_AT_low_pc (dw_die_ref die
)
5248 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
5250 return a
? AT_lbl (a
) : NULL
;
5253 /* Return the "high pc" attribute value, typically associated with a subprogram
5254 DIE. Return null if the "high pc" attribute is either not present, or if it
5255 cannot be represented as an assembler label identifier. */
5257 static inline const char *
5258 get_AT_hi_pc (dw_die_ref die
)
5260 dw_attr_node
*a
= get_AT (die
, DW_AT_high_pc
);
5262 return a
? AT_lbl (a
) : NULL
;
5265 /* Return the value of the string attribute designated by ATTR_KIND, or
5266 NULL if it is not present. */
5268 static inline const char *
5269 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5271 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5273 return a
? AT_string (a
) : NULL
;
5276 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5277 if it is not present. */
5280 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5282 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5284 return a
? AT_flag (a
) : 0;
5287 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5288 if it is not present. */
5290 static inline unsigned
5291 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5293 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5295 return a
? AT_unsigned (a
) : 0;
5298 static inline dw_die_ref
5299 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5301 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5303 return a
? AT_ref (a
) : NULL
;
5306 static inline struct dwarf_file_data
*
5307 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5309 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5311 return a
? AT_file (a
) : NULL
;
5314 /* Return TRUE if the language is C++. */
5319 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5321 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
5322 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
5325 /* Return TRUE if DECL was created by the C++ frontend. */
5328 is_cxx (const_tree decl
)
5332 const_tree context
= get_ultimate_context (decl
);
5333 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5334 return strncmp (TRANSLATION_UNIT_LANGUAGE (context
), "GNU C++", 7) == 0;
5339 /* Return TRUE if the language is Fortran. */
5344 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5346 return (lang
== DW_LANG_Fortran77
5347 || lang
== DW_LANG_Fortran90
5348 || lang
== DW_LANG_Fortran95
5349 || lang
== DW_LANG_Fortran03
5350 || lang
== DW_LANG_Fortran08
);
5354 is_fortran (const_tree decl
)
5358 const_tree context
= get_ultimate_context (decl
);
5359 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5360 return (strncmp (TRANSLATION_UNIT_LANGUAGE (context
),
5361 "GNU Fortran", 11) == 0
5362 || strcmp (TRANSLATION_UNIT_LANGUAGE (context
),
5365 return is_fortran ();
5368 /* Return TRUE if the language is Ada. */
5373 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5375 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5378 /* Remove the specified attribute if present. Return TRUE if removal
5382 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5390 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5391 if (a
->dw_attr
== attr_kind
)
5393 if (AT_class (a
) == dw_val_class_str
)
5394 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5395 a
->dw_attr_val
.v
.val_str
->refcount
--;
5397 /* vec::ordered_remove should help reduce the number of abbrevs
5399 die
->die_attr
->ordered_remove (ix
);
5405 /* Remove CHILD from its parent. PREV must have the property that
5406 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5409 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5411 gcc_assert (child
->die_parent
== prev
->die_parent
);
5412 gcc_assert (prev
->die_sib
== child
);
5415 gcc_assert (child
->die_parent
->die_child
== child
);
5419 prev
->die_sib
= child
->die_sib
;
5420 if (child
->die_parent
->die_child
== child
)
5421 child
->die_parent
->die_child
= prev
;
5422 child
->die_sib
= NULL
;
5425 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5426 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5429 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
5431 dw_die_ref parent
= old_child
->die_parent
;
5433 gcc_assert (parent
== prev
->die_parent
);
5434 gcc_assert (prev
->die_sib
== old_child
);
5436 new_child
->die_parent
= parent
;
5437 if (prev
== old_child
)
5439 gcc_assert (parent
->die_child
== old_child
);
5440 new_child
->die_sib
= new_child
;
5444 prev
->die_sib
= new_child
;
5445 new_child
->die_sib
= old_child
->die_sib
;
5447 if (old_child
->die_parent
->die_child
== old_child
)
5448 old_child
->die_parent
->die_child
= new_child
;
5449 old_child
->die_sib
= NULL
;
5452 /* Move all children from OLD_PARENT to NEW_PARENT. */
5455 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
5458 new_parent
->die_child
= old_parent
->die_child
;
5459 old_parent
->die_child
= NULL
;
5460 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
5463 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5467 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5473 dw_die_ref prev
= c
;
5475 while (c
->die_tag
== tag
)
5477 remove_child_with_prev (c
, prev
);
5478 c
->die_parent
= NULL
;
5479 /* Might have removed every child. */
5480 if (die
->die_child
== NULL
)
5484 } while (c
!= die
->die_child
);
5487 /* Add a CHILD_DIE as the last child of DIE. */
5490 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5492 /* FIXME this should probably be an assert. */
5493 if (! die
|| ! child_die
)
5495 gcc_assert (die
!= child_die
);
5497 child_die
->die_parent
= die
;
5500 child_die
->die_sib
= die
->die_child
->die_sib
;
5501 die
->die_child
->die_sib
= child_die
;
5504 child_die
->die_sib
= child_die
;
5505 die
->die_child
= child_die
;
5508 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5511 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
5512 dw_die_ref after_die
)
5518 && die
!= child_die
);
5520 child_die
->die_parent
= die
;
5521 child_die
->die_sib
= after_die
->die_sib
;
5522 after_die
->die_sib
= child_die
;
5523 if (die
->die_child
== after_die
)
5524 die
->die_child
= child_die
;
5527 /* Unassociate CHILD from its parent, and make its parent be
5531 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
5533 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5534 if (p
->die_sib
== child
)
5536 remove_child_with_prev (child
, p
);
5539 add_child_die (new_parent
, child
);
5542 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5543 is the specification, to the end of PARENT's list of children.
5544 This is done by removing and re-adding it. */
5547 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5549 /* We want the declaration DIE from inside the class, not the
5550 specification DIE at toplevel. */
5551 if (child
->die_parent
!= parent
)
5553 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5559 gcc_assert (child
->die_parent
== parent
5560 || (child
->die_parent
5561 == get_AT_ref (parent
, DW_AT_specification
)));
5563 reparent_child (child
, parent
);
5566 /* Create and return a new die with TAG_VALUE as tag. */
5568 static inline dw_die_ref
5569 new_die_raw (enum dwarf_tag tag_value
)
5571 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5572 die
->die_tag
= tag_value
;
5576 /* Create and return a new die with a parent of PARENT_DIE. If
5577 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5578 associated tree T must be supplied to determine parenthood
5581 static inline dw_die_ref
5582 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5584 dw_die_ref die
= new_die_raw (tag_value
);
5586 if (parent_die
!= NULL
)
5587 add_child_die (parent_die
, die
);
5590 limbo_die_node
*limbo_node
;
5592 /* No DIEs created after early dwarf should end up in limbo,
5593 because the limbo list should not persist past LTO
5595 if (tag_value
!= DW_TAG_compile_unit
5596 /* These are allowed because they're generated while
5597 breaking out COMDAT units late. */
5598 && tag_value
!= DW_TAG_type_unit
5599 && tag_value
!= DW_TAG_skeleton_unit
5601 /* Allow nested functions to live in limbo because they will
5602 only temporarily live there, as decls_for_scope will fix
5604 && (TREE_CODE (t
) != FUNCTION_DECL
5605 || !decl_function_context (t
))
5606 /* Same as nested functions above but for types. Types that
5607 are local to a function will be fixed in
5609 && (!RECORD_OR_UNION_TYPE_P (t
)
5610 || !TYPE_CONTEXT (t
)
5611 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5612 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5613 especially in the ltrans stage, but once we implement LTO
5614 dwarf streaming, we should remove this exception. */
5617 fprintf (stderr
, "symbol ended up in limbo too late:");
5618 debug_generic_stmt (t
);
5622 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5623 limbo_node
->die
= die
;
5624 limbo_node
->created_for
= t
;
5625 limbo_node
->next
= limbo_die_list
;
5626 limbo_die_list
= limbo_node
;
5632 /* Return the DIE associated with the given type specifier. */
5634 static inline dw_die_ref
5635 lookup_type_die (tree type
)
5637 dw_die_ref die
= TYPE_SYMTAB_DIE (type
);
5638 if (die
&& die
->removed
)
5640 TYPE_SYMTAB_DIE (type
) = NULL
;
5646 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5647 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5648 anonymous type instead the one of the naming typedef. */
5650 static inline dw_die_ref
5651 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5654 && TREE_CODE (type
) == RECORD_TYPE
5656 && type_die
->die_tag
== DW_TAG_typedef
5657 && is_naming_typedef_decl (TYPE_NAME (type
)))
5658 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5662 /* Like lookup_type_die, but if type is an anonymous type named by a
5663 typedef[1], return the DIE of the anonymous type instead the one of
5664 the naming typedef. This is because in gen_typedef_die, we did
5665 equate the anonymous struct named by the typedef with the DIE of
5666 the naming typedef. So by default, lookup_type_die on an anonymous
5667 struct yields the DIE of the naming typedef.
5669 [1]: Read the comment of is_naming_typedef_decl to learn about what
5670 a naming typedef is. */
5672 static inline dw_die_ref
5673 lookup_type_die_strip_naming_typedef (tree type
)
5675 dw_die_ref die
= lookup_type_die (type
);
5676 return strip_naming_typedef (type
, die
);
5679 /* Equate a DIE to a given type specifier. */
5682 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5684 TYPE_SYMTAB_DIE (type
) = type_die
;
5687 /* Returns a hash value for X (which really is a die_struct). */
5690 decl_die_hasher::hash (die_node
*x
)
5692 return (hashval_t
) x
->decl_id
;
5695 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5698 decl_die_hasher::equal (die_node
*x
, tree y
)
5700 return (x
->decl_id
== DECL_UID (y
));
5703 /* Return the DIE associated with a given declaration. */
5705 static inline dw_die_ref
5706 lookup_decl_die (tree decl
)
5708 dw_die_ref
*die
= decl_die_table
->find_slot_with_hash (decl
, DECL_UID (decl
),
5712 if ((*die
)->removed
)
5714 decl_die_table
->clear_slot (die
);
5721 /* For DECL which might have early dwarf output query a SYMBOL + OFFSET
5722 style reference. Return true if we found one refering to a DIE for
5723 DECL, otherwise return false. */
5726 dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
5727 unsigned HOST_WIDE_INT
*off
)
5731 if (flag_wpa
&& !decl_die_table
)
5734 if (TREE_CODE (decl
) == BLOCK
)
5735 die
= BLOCK_DIE (decl
);
5737 die
= lookup_decl_die (decl
);
5741 /* During WPA stage we currently use DIEs to store the
5742 decl <-> label + offset map. That's quite inefficient but it
5746 dw_die_ref ref
= get_AT_ref (die
, DW_AT_abstract_origin
);
5749 gcc_assert (die
== comp_unit_die ());
5752 *off
= ref
->die_offset
;
5753 *sym
= ref
->die_id
.die_symbol
;
5757 /* Similar to get_ref_die_offset_label, but using the "correct"
5759 *off
= die
->die_offset
;
5760 while (die
->die_parent
)
5761 die
= die
->die_parent
;
5762 /* For the containing CU DIE we compute a die_symbol in
5763 compute_comp_unit_symbol. */
5764 gcc_assert (die
->die_tag
== DW_TAG_compile_unit
5765 && die
->die_id
.die_symbol
!= NULL
);
5766 *sym
= die
->die_id
.die_symbol
;
5770 /* Add a reference of kind ATTR_KIND to a DIE at SYMBOL + OFFSET to DIE. */
5773 add_AT_external_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5774 const char *symbol
, HOST_WIDE_INT offset
)
5776 /* Create a fake DIE that contains the reference. Don't use
5777 new_die because we don't want to end up in the limbo list. */
5778 dw_die_ref ref
= new_die_raw (die
->die_tag
);
5779 ref
->die_id
.die_symbol
= IDENTIFIER_POINTER (get_identifier (symbol
));
5780 ref
->die_offset
= offset
;
5781 ref
->with_offset
= 1;
5782 add_AT_die_ref (die
, attr_kind
, ref
);
5785 /* Create a DIE for DECL if required and add a reference to a DIE
5786 at SYMBOL + OFFSET which contains attributes dumped early. */
5789 dwarf2out_register_external_die (tree decl
, const char *sym
,
5790 unsigned HOST_WIDE_INT off
)
5792 if (debug_info_level
== DINFO_LEVEL_NONE
)
5795 if (flag_wpa
&& !decl_die_table
)
5796 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (1000);
5799 = TREE_CODE (decl
) == BLOCK
? BLOCK_DIE (decl
) : lookup_decl_die (decl
);
5803 dw_die_ref parent
= NULL
;
5804 /* Need to lookup a DIE for the decls context - the containing
5805 function or translation unit. */
5806 if (TREE_CODE (decl
) == BLOCK
)
5808 ctx
= BLOCK_SUPERCONTEXT (decl
);
5809 /* ??? We do not output DIEs for all scopes thus skip as
5810 many DIEs as needed. */
5811 while (TREE_CODE (ctx
) == BLOCK
5812 && !BLOCK_DIE (ctx
))
5813 ctx
= BLOCK_SUPERCONTEXT (ctx
);
5816 ctx
= DECL_CONTEXT (decl
);
5817 while (ctx
&& TYPE_P (ctx
))
5818 ctx
= TYPE_CONTEXT (ctx
);
5821 if (TREE_CODE (ctx
) == BLOCK
)
5822 parent
= BLOCK_DIE (ctx
);
5823 else if (TREE_CODE (ctx
) == TRANSLATION_UNIT_DECL
5824 /* Keep the 1:1 association during WPA. */
5826 /* Otherwise all late annotations go to the main CU which
5827 imports the original CUs. */
5828 parent
= comp_unit_die ();
5829 else if (TREE_CODE (ctx
) == FUNCTION_DECL
5830 && TREE_CODE (decl
) != PARM_DECL
5831 && TREE_CODE (decl
) != BLOCK
)
5832 /* Leave function local entities parent determination to when
5833 we process scope vars. */
5836 parent
= lookup_decl_die (ctx
);
5839 /* In some cases the FEs fail to set DECL_CONTEXT properly.
5840 Handle this case gracefully by globalizing stuff. */
5841 parent
= comp_unit_die ();
5842 /* Create a DIE "stub". */
5843 switch (TREE_CODE (decl
))
5845 case TRANSLATION_UNIT_DECL
:
5848 die
= comp_unit_die ();
5849 dw_die_ref import
= new_die (DW_TAG_imported_unit
, die
, NULL_TREE
);
5850 add_AT_external_die_ref (import
, DW_AT_import
, sym
, off
);
5851 /* We re-target all CU decls to the LTRANS CU DIE, so no need
5852 to create a DIE for the original CUs. */
5855 /* Keep the 1:1 association during WPA. */
5856 die
= new_die (DW_TAG_compile_unit
, NULL
, decl
);
5858 case NAMESPACE_DECL
:
5859 if (is_fortran (decl
))
5860 die
= new_die (DW_TAG_module
, parent
, decl
);
5862 die
= new_die (DW_TAG_namespace
, parent
, decl
);
5865 die
= new_die (DW_TAG_subprogram
, parent
, decl
);
5868 die
= new_die (DW_TAG_variable
, parent
, decl
);
5871 die
= new_die (DW_TAG_variable
, parent
, decl
);
5874 die
= new_die (DW_TAG_formal_parameter
, parent
, decl
);
5877 die
= new_die (DW_TAG_constant
, parent
, decl
);
5880 die
= new_die (DW_TAG_label
, parent
, decl
);
5883 die
= new_die (DW_TAG_lexical_block
, parent
, decl
);
5888 if (TREE_CODE (decl
) == BLOCK
)
5889 BLOCK_DIE (decl
) = die
;
5891 equate_decl_number_to_die (decl
, die
);
5893 /* Add a reference to the DIE providing early debug at $sym + off. */
5894 add_AT_external_die_ref (die
, DW_AT_abstract_origin
, sym
, off
);
5897 /* Returns a hash value for X (which really is a var_loc_list). */
5900 decl_loc_hasher::hash (var_loc_list
*x
)
5902 return (hashval_t
) x
->decl_id
;
5905 /* Return nonzero if decl_id of var_loc_list X is the same as
5909 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5911 return (x
->decl_id
== DECL_UID (y
));
5914 /* Return the var_loc list associated with a given declaration. */
5916 static inline var_loc_list
*
5917 lookup_decl_loc (const_tree decl
)
5919 if (!decl_loc_table
)
5921 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5924 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5927 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5929 return (hashval_t
) x
->decl_id
;
5932 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5936 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5938 return (x
->decl_id
== DECL_UID (y
));
5941 /* Equate a DIE to a particular declaration. */
5944 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5946 unsigned int decl_id
= DECL_UID (decl
);
5948 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5949 decl_die
->decl_id
= decl_id
;
5952 /* Return how many bits covers PIECE EXPR_LIST. */
5954 static HOST_WIDE_INT
5955 decl_piece_bitsize (rtx piece
)
5957 int ret
= (int) GET_MODE (piece
);
5960 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5961 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5962 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5965 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5968 decl_piece_varloc_ptr (rtx piece
)
5970 if ((int) GET_MODE (piece
))
5971 return &XEXP (piece
, 0);
5973 return &XEXP (XEXP (piece
, 0), 1);
5976 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5977 Next is the chain of following piece nodes. */
5979 static rtx_expr_list
*
5980 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5982 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5983 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5985 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5990 /* Return rtx that should be stored into loc field for
5991 LOC_NOTE and BITPOS/BITSIZE. */
5994 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5995 HOST_WIDE_INT bitsize
)
5999 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
6001 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
6006 /* This function either modifies location piece list *DEST in
6007 place (if SRC and INNER is NULL), or copies location piece list
6008 *SRC to *DEST while modifying it. Location BITPOS is modified
6009 to contain LOC_NOTE, any pieces overlapping it are removed resp.
6010 not copied and if needed some padding around it is added.
6011 When modifying in place, DEST should point to EXPR_LIST where
6012 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
6013 to the start of the whole list and INNER points to the EXPR_LIST
6014 where earlier pieces cover PIECE_BITPOS bits. */
6017 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
6018 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
6019 HOST_WIDE_INT bitsize
, rtx loc_note
)
6022 bool copy
= inner
!= NULL
;
6026 /* First copy all nodes preceding the current bitpos. */
6027 while (src
!= inner
)
6029 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
6030 decl_piece_bitsize (*src
), NULL_RTX
);
6031 dest
= &XEXP (*dest
, 1);
6032 src
= &XEXP (*src
, 1);
6035 /* Add padding if needed. */
6036 if (bitpos
!= piece_bitpos
)
6038 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
6039 copy
? NULL_RTX
: *dest
);
6040 dest
= &XEXP (*dest
, 1);
6042 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
6045 /* A piece with correct bitpos and bitsize already exist,
6046 just update the location for it and return. */
6047 *decl_piece_varloc_ptr (*dest
) = loc_note
;
6050 /* Add the piece that changed. */
6051 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
6052 dest
= &XEXP (*dest
, 1);
6053 /* Skip over pieces that overlap it. */
6054 diff
= bitpos
- piece_bitpos
+ bitsize
;
6057 while (diff
> 0 && *src
)
6060 diff
-= decl_piece_bitsize (piece
);
6062 src
= &XEXP (piece
, 1);
6065 *src
= XEXP (piece
, 1);
6066 free_EXPR_LIST_node (piece
);
6069 /* Add padding if needed. */
6070 if (diff
< 0 && *src
)
6074 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
6075 dest
= &XEXP (*dest
, 1);
6079 /* Finally copy all nodes following it. */
6082 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
6083 decl_piece_bitsize (*src
), NULL_RTX
);
6084 dest
= &XEXP (*dest
, 1);
6085 src
= &XEXP (*src
, 1);
6089 /* Add a variable location node to the linked list for DECL. */
6091 static struct var_loc_node
*
6092 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
, var_loc_view view
)
6094 unsigned int decl_id
;
6096 struct var_loc_node
*loc
= NULL
;
6097 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
6099 if (VAR_P (decl
) && DECL_HAS_DEBUG_EXPR_P (decl
))
6101 tree realdecl
= DECL_DEBUG_EXPR (decl
);
6102 if (handled_component_p (realdecl
)
6103 || (TREE_CODE (realdecl
) == MEM_REF
6104 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
6107 tree innerdecl
= get_ref_base_and_extent_hwi (realdecl
, &bitpos
,
6108 &bitsize
, &reverse
);
6110 || !DECL_P (innerdecl
)
6111 || DECL_IGNORED_P (innerdecl
)
6112 || TREE_STATIC (innerdecl
)
6114 || bitpos
+ bitsize
> 256)
6120 decl_id
= DECL_UID (decl
);
6122 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
6125 temp
= ggc_cleared_alloc
<var_loc_list
> ();
6126 temp
->decl_id
= decl_id
;
6132 /* For PARM_DECLs try to keep around the original incoming value,
6133 even if that means we'll emit a zero-range .debug_loc entry. */
6135 && temp
->first
== temp
->last
6136 && TREE_CODE (decl
) == PARM_DECL
6137 && NOTE_P (temp
->first
->loc
)
6138 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
6139 && DECL_INCOMING_RTL (decl
)
6140 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
6141 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
6142 == GET_CODE (DECL_INCOMING_RTL (decl
))
6143 && prev_real_insn (as_a
<rtx_insn
*> (temp
->first
->loc
)) == NULL_RTX
6145 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
6146 NOTE_VAR_LOCATION_LOC (loc_note
))
6147 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
6148 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
6150 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6151 temp
->first
->next
= loc
;
6153 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6155 else if (temp
->last
)
6157 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
6158 rtx
*piece_loc
= NULL
, last_loc_note
;
6159 HOST_WIDE_INT piece_bitpos
= 0;
6163 gcc_assert (last
->next
== NULL
);
6165 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
6167 piece_loc
= &last
->loc
;
6170 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
6171 if (piece_bitpos
+ cur_bitsize
> bitpos
)
6173 piece_bitpos
+= cur_bitsize
;
6174 piece_loc
= &XEXP (*piece_loc
, 1);
6178 /* TEMP->LAST here is either pointer to the last but one or
6179 last element in the chained list, LAST is pointer to the
6181 if (label
&& strcmp (last
->label
, label
) == 0 && last
->view
== view
)
6183 /* For SRA optimized variables if there weren't any real
6184 insns since last note, just modify the last node. */
6185 if (piece_loc
!= NULL
)
6187 adjust_piece_list (piece_loc
, NULL
, NULL
,
6188 bitpos
, piece_bitpos
, bitsize
, loc_note
);
6191 /* If the last note doesn't cover any instructions, remove it. */
6192 if (temp
->last
!= last
)
6194 temp
->last
->next
= NULL
;
6197 gcc_assert (strcmp (last
->label
, label
) != 0 || last
->view
!= view
);
6201 gcc_assert (temp
->first
== temp
->last
6202 || (temp
->first
->next
== temp
->last
6203 && TREE_CODE (decl
) == PARM_DECL
));
6204 memset (temp
->last
, '\0', sizeof (*temp
->last
));
6205 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6209 if (bitsize
== -1 && NOTE_P (last
->loc
))
6210 last_loc_note
= last
->loc
;
6211 else if (piece_loc
!= NULL
6212 && *piece_loc
!= NULL_RTX
6213 && piece_bitpos
== bitpos
6214 && decl_piece_bitsize (*piece_loc
) == bitsize
)
6215 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
6217 last_loc_note
= NULL_RTX
;
6218 /* If the current location is the same as the end of the list,
6219 and either both or neither of the locations is uninitialized,
6220 we have nothing to do. */
6221 if (last_loc_note
== NULL_RTX
6222 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
6223 NOTE_VAR_LOCATION_LOC (loc_note
)))
6224 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6225 != NOTE_VAR_LOCATION_STATUS (loc_note
))
6226 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6227 == VAR_INIT_STATUS_UNINITIALIZED
)
6228 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
6229 == VAR_INIT_STATUS_UNINITIALIZED
))))
6231 /* Add LOC to the end of list and update LAST. If the last
6232 element of the list has been removed above, reuse its
6233 memory for the new node, otherwise allocate a new one. */
6237 memset (loc
, '\0', sizeof (*loc
));
6240 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6241 if (bitsize
== -1 || piece_loc
== NULL
)
6242 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6244 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
6245 bitpos
, piece_bitpos
, bitsize
, loc_note
);
6247 /* Ensure TEMP->LAST will point either to the new last but one
6248 element of the chain, or to the last element in it. */
6249 if (last
!= temp
->last
)
6257 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6260 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6265 /* Keep track of the number of spaces used to indent the
6266 output of the debugging routines that print the structure of
6267 the DIE internal representation. */
6268 static int print_indent
;
6270 /* Indent the line the number of spaces given by print_indent. */
6273 print_spaces (FILE *outfile
)
6275 fprintf (outfile
, "%*s", print_indent
, "");
6278 /* Print a type signature in hex. */
6281 print_signature (FILE *outfile
, char *sig
)
6285 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
6286 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
6290 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
6292 if (discr_value
->pos
)
6293 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
6295 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
6298 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
6300 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
6301 RECURSE, output location descriptor operations. */
6304 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
6306 switch (val
->val_class
)
6308 case dw_val_class_addr
:
6309 fprintf (outfile
, "address");
6311 case dw_val_class_offset
:
6312 fprintf (outfile
, "offset");
6314 case dw_val_class_loc
:
6315 fprintf (outfile
, "location descriptor");
6316 if (val
->v
.val_loc
== NULL
)
6317 fprintf (outfile
, " -> <null>\n");
6320 fprintf (outfile
, ":\n");
6322 print_loc_descr (val
->v
.val_loc
, outfile
);
6326 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
6328 case dw_val_class_loc_list
:
6329 fprintf (outfile
, "location list -> label:%s",
6330 val
->v
.val_loc_list
->ll_symbol
);
6332 case dw_val_class_view_list
:
6333 val
= view_list_to_loc_list_val_node (val
);
6334 fprintf (outfile
, "location list with views -> labels:%s and %s",
6335 val
->v
.val_loc_list
->ll_symbol
,
6336 val
->v
.val_loc_list
->vl_symbol
);
6338 case dw_val_class_range_list
:
6339 fprintf (outfile
, "range list");
6341 case dw_val_class_const
:
6342 case dw_val_class_const_implicit
:
6343 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
6345 case dw_val_class_unsigned_const
:
6346 case dw_val_class_unsigned_const_implicit
:
6347 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
6349 case dw_val_class_const_double
:
6350 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
6351 HOST_WIDE_INT_PRINT_UNSIGNED
")",
6352 val
->v
.val_double
.high
,
6353 val
->v
.val_double
.low
);
6355 case dw_val_class_wide_int
:
6357 int i
= val
->v
.val_wide
->get_len ();
6358 fprintf (outfile
, "constant (");
6360 if (val
->v
.val_wide
->elt (i
- 1) == 0)
6361 fprintf (outfile
, "0x");
6362 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
6363 val
->v
.val_wide
->elt (--i
));
6365 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
6366 val
->v
.val_wide
->elt (i
));
6367 fprintf (outfile
, ")");
6370 case dw_val_class_vec
:
6371 fprintf (outfile
, "floating-point or vector constant");
6373 case dw_val_class_flag
:
6374 fprintf (outfile
, "%u", val
->v
.val_flag
);
6376 case dw_val_class_die_ref
:
6377 if (val
->v
.val_die_ref
.die
!= NULL
)
6379 dw_die_ref die
= val
->v
.val_die_ref
.die
;
6381 if (die
->comdat_type_p
)
6383 fprintf (outfile
, "die -> signature: ");
6384 print_signature (outfile
,
6385 die
->die_id
.die_type_node
->signature
);
6387 else if (die
->die_id
.die_symbol
)
6389 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
6390 if (die
->with_offset
)
6391 fprintf (outfile
, " + %ld", die
->die_offset
);
6394 fprintf (outfile
, "die -> %ld", die
->die_offset
);
6395 fprintf (outfile
, " (%p)", (void *) die
);
6398 fprintf (outfile
, "die -> <null>");
6400 case dw_val_class_vms_delta
:
6401 fprintf (outfile
, "delta: @slotcount(%s-%s)",
6402 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
6404 case dw_val_class_lbl_id
:
6405 case dw_val_class_lineptr
:
6406 case dw_val_class_macptr
:
6407 case dw_val_class_loclistsptr
:
6408 case dw_val_class_high_pc
:
6409 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
6411 case dw_val_class_str
:
6412 if (val
->v
.val_str
->str
!= NULL
)
6413 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
6415 fprintf (outfile
, "<null>");
6417 case dw_val_class_file
:
6418 case dw_val_class_file_implicit
:
6419 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
6420 val
->v
.val_file
->emitted_number
);
6422 case dw_val_class_data8
:
6426 for (i
= 0; i
< 8; i
++)
6427 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
6430 case dw_val_class_discr_value
:
6431 print_discr_value (outfile
, &val
->v
.val_discr_value
);
6433 case dw_val_class_discr_list
:
6434 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
6436 node
= node
->dw_discr_next
)
6438 if (node
->dw_discr_range
)
6440 fprintf (outfile
, " .. ");
6441 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6442 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
6445 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6447 if (node
->dw_discr_next
!= NULL
)
6448 fprintf (outfile
, " | ");
6455 /* Likewise, for a DIE attribute. */
6458 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
6460 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
6464 /* Print the list of operands in the LOC location description to OUTFILE. This
6465 routine is a debugging aid only. */
6468 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
6470 dw_loc_descr_ref l
= loc
;
6474 print_spaces (outfile
);
6475 fprintf (outfile
, "<null>\n");
6479 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
6481 print_spaces (outfile
);
6482 fprintf (outfile
, "(%p) %s",
6484 dwarf_stack_op_name (l
->dw_loc_opc
));
6485 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
6487 fprintf (outfile
, " ");
6488 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
6490 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
6492 fprintf (outfile
, ", ");
6493 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
6495 fprintf (outfile
, "\n");
6499 /* Print the information associated with a given DIE, and its children.
6500 This routine is a debugging aid only. */
6503 print_die (dw_die_ref die
, FILE *outfile
)
6509 print_spaces (outfile
);
6510 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
6511 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
6513 print_spaces (outfile
);
6514 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
6515 fprintf (outfile
, " offset: %ld", die
->die_offset
);
6516 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
6518 if (die
->comdat_type_p
)
6520 print_spaces (outfile
);
6521 fprintf (outfile
, " signature: ");
6522 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
6523 fprintf (outfile
, "\n");
6526 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6528 print_spaces (outfile
);
6529 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6531 print_attribute (a
, true, outfile
);
6532 fprintf (outfile
, "\n");
6535 if (die
->die_child
!= NULL
)
6538 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6541 if (print_indent
== 0)
6542 fprintf (outfile
, "\n");
6545 /* Print the list of operations in the LOC location description. */
6548 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
6550 print_loc_descr (loc
, stderr
);
6553 /* Print the information collected for a given DIE. */
6556 debug_dwarf_die (dw_die_ref die
)
6558 print_die (die
, stderr
);
6562 debug (die_struct
&ref
)
6564 print_die (&ref
, stderr
);
6568 debug (die_struct
*ptr
)
6573 fprintf (stderr
, "<nil>\n");
6577 /* Print all DWARF information collected for the compilation unit.
6578 This routine is a debugging aid only. */
6584 print_die (comp_unit_die (), stderr
);
6587 /* Verify the DIE tree structure. */
6590 verify_die (dw_die_ref die
)
6592 gcc_assert (!die
->die_mark
);
6593 if (die
->die_parent
== NULL
6594 && die
->die_sib
== NULL
)
6596 /* Verify the die_sib list is cyclic. */
6603 while (x
&& !x
->die_mark
);
6604 gcc_assert (x
== die
);
6608 /* Verify all dies have the same parent. */
6609 gcc_assert (x
->die_parent
== die
->die_parent
);
6612 /* Verify the child has the proper parent and recurse. */
6613 gcc_assert (x
->die_child
->die_parent
== x
);
6614 verify_die (x
->die_child
);
6619 while (x
&& x
->die_mark
);
6622 /* Sanity checks on DIEs. */
6625 check_die (dw_die_ref die
)
6629 bool inline_found
= false;
6630 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
6631 int n_decl_line
= 0, n_decl_column
= 0, n_decl_file
= 0;
6632 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6637 if (a
->dw_attr_val
.v
.val_unsigned
)
6638 inline_found
= true;
6640 case DW_AT_location
:
6649 case DW_AT_artificial
:
6652 case DW_AT_decl_column
:
6655 case DW_AT_decl_line
:
6658 case DW_AT_decl_file
:
6665 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
6666 || n_decl_column
> 1 || n_decl_line
> 1 || n_decl_file
> 1)
6668 fprintf (stderr
, "Duplicate attributes in DIE:\n");
6669 debug_dwarf_die (die
);
6674 /* A debugging information entry that is a member of an abstract
6675 instance tree [that has DW_AT_inline] should not contain any
6676 attributes which describe aspects of the subroutine which vary
6677 between distinct inlined expansions or distinct out-of-line
6679 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6680 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
6681 && a
->dw_attr
!= DW_AT_high_pc
6682 && a
->dw_attr
!= DW_AT_location
6683 && a
->dw_attr
!= DW_AT_frame_base
6684 && a
->dw_attr
!= DW_AT_call_all_calls
6685 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
6689 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6690 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6691 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6693 /* Calculate the checksum of a location expression. */
6696 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6699 inchash::hash hstate
;
6702 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
6704 hash_loc_operands (loc
, hstate
);
6705 hash
= hstate
.end();
6709 /* Calculate the checksum of an attribute. */
6712 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
6714 dw_loc_descr_ref loc
;
6717 CHECKSUM (at
->dw_attr
);
6719 /* We don't care that this was compiled with a different compiler
6720 snapshot; if the output is the same, that's what matters. */
6721 if (at
->dw_attr
== DW_AT_producer
)
6724 switch (AT_class (at
))
6726 case dw_val_class_const
:
6727 case dw_val_class_const_implicit
:
6728 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
6730 case dw_val_class_unsigned_const
:
6731 case dw_val_class_unsigned_const_implicit
:
6732 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
6734 case dw_val_class_const_double
:
6735 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6737 case dw_val_class_wide_int
:
6738 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6739 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6740 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6742 case dw_val_class_vec
:
6743 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6744 (at
->dw_attr_val
.v
.val_vec
.length
6745 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6747 case dw_val_class_flag
:
6748 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
6750 case dw_val_class_str
:
6751 CHECKSUM_STRING (AT_string (at
));
6754 case dw_val_class_addr
:
6756 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6757 CHECKSUM_STRING (XSTR (r
, 0));
6760 case dw_val_class_offset
:
6761 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6764 case dw_val_class_loc
:
6765 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6766 loc_checksum (loc
, ctx
);
6769 case dw_val_class_die_ref
:
6770 die_checksum (AT_ref (at
), ctx
, mark
);
6773 case dw_val_class_fde_ref
:
6774 case dw_val_class_vms_delta
:
6775 case dw_val_class_lbl_id
:
6776 case dw_val_class_lineptr
:
6777 case dw_val_class_macptr
:
6778 case dw_val_class_loclistsptr
:
6779 case dw_val_class_high_pc
:
6782 case dw_val_class_file
:
6783 case dw_val_class_file_implicit
:
6784 CHECKSUM_STRING (AT_file (at
)->filename
);
6787 case dw_val_class_data8
:
6788 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6796 /* Calculate the checksum of a DIE. */
6799 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6805 /* To avoid infinite recursion. */
6808 CHECKSUM (die
->die_mark
);
6811 die
->die_mark
= ++(*mark
);
6813 CHECKSUM (die
->die_tag
);
6815 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6816 attr_checksum (a
, ctx
, mark
);
6818 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6822 #undef CHECKSUM_BLOCK
6823 #undef CHECKSUM_STRING
6825 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6826 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6827 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6828 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6829 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6830 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6831 #define CHECKSUM_ATTR(FOO) \
6832 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6834 /* Calculate the checksum of a number in signed LEB128 format. */
6837 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6844 byte
= (value
& 0x7f);
6846 more
= !((value
== 0 && (byte
& 0x40) == 0)
6847 || (value
== -1 && (byte
& 0x40) != 0));
6856 /* Calculate the checksum of a number in unsigned LEB128 format. */
6859 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6863 unsigned char byte
= (value
& 0x7f);
6866 /* More bytes to follow. */
6874 /* Checksum the context of the DIE. This adds the names of any
6875 surrounding namespaces or structures to the checksum. */
6878 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
6882 int tag
= die
->die_tag
;
6884 if (tag
!= DW_TAG_namespace
6885 && tag
!= DW_TAG_structure_type
6886 && tag
!= DW_TAG_class_type
)
6889 name
= get_AT_string (die
, DW_AT_name
);
6891 spec
= get_AT_ref (die
, DW_AT_specification
);
6895 if (die
->die_parent
!= NULL
)
6896 checksum_die_context (die
->die_parent
, ctx
);
6898 CHECKSUM_ULEB128 ('C');
6899 CHECKSUM_ULEB128 (tag
);
6901 CHECKSUM_STRING (name
);
6904 /* Calculate the checksum of a location expression. */
6907 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6909 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6910 were emitted as a DW_FORM_sdata instead of a location expression. */
6911 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6913 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6914 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6918 /* Otherwise, just checksum the raw location expression. */
6921 inchash::hash hstate
;
6924 CHECKSUM_ULEB128 (loc
->dtprel
);
6925 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6926 hash_loc_operands (loc
, hstate
);
6927 hash
= hstate
.end ();
6929 loc
= loc
->dw_loc_next
;
6933 /* Calculate the checksum of an attribute. */
6936 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
6937 struct md5_ctx
*ctx
, int *mark
)
6939 dw_loc_descr_ref loc
;
6942 if (AT_class (at
) == dw_val_class_die_ref
)
6944 dw_die_ref target_die
= AT_ref (at
);
6946 /* For pointer and reference types, we checksum only the (qualified)
6947 name of the target type (if there is a name). For friend entries,
6948 we checksum only the (qualified) name of the target type or function.
6949 This allows the checksum to remain the same whether the target type
6950 is complete or not. */
6951 if ((at
->dw_attr
== DW_AT_type
6952 && (tag
== DW_TAG_pointer_type
6953 || tag
== DW_TAG_reference_type
6954 || tag
== DW_TAG_rvalue_reference_type
6955 || tag
== DW_TAG_ptr_to_member_type
))
6956 || (at
->dw_attr
== DW_AT_friend
6957 && tag
== DW_TAG_friend
))
6959 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
6961 if (name_attr
!= NULL
)
6963 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6967 CHECKSUM_ULEB128 ('N');
6968 CHECKSUM_ULEB128 (at
->dw_attr
);
6969 if (decl
->die_parent
!= NULL
)
6970 checksum_die_context (decl
->die_parent
, ctx
);
6971 CHECKSUM_ULEB128 ('E');
6972 CHECKSUM_STRING (AT_string (name_attr
));
6977 /* For all other references to another DIE, we check to see if the
6978 target DIE has already been visited. If it has, we emit a
6979 backward reference; if not, we descend recursively. */
6980 if (target_die
->die_mark
> 0)
6982 CHECKSUM_ULEB128 ('R');
6983 CHECKSUM_ULEB128 (at
->dw_attr
);
6984 CHECKSUM_ULEB128 (target_die
->die_mark
);
6988 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6992 target_die
->die_mark
= ++(*mark
);
6993 CHECKSUM_ULEB128 ('T');
6994 CHECKSUM_ULEB128 (at
->dw_attr
);
6995 if (decl
->die_parent
!= NULL
)
6996 checksum_die_context (decl
->die_parent
, ctx
);
6997 die_checksum_ordered (target_die
, ctx
, mark
);
7002 CHECKSUM_ULEB128 ('A');
7003 CHECKSUM_ULEB128 (at
->dw_attr
);
7005 switch (AT_class (at
))
7007 case dw_val_class_const
:
7008 case dw_val_class_const_implicit
:
7009 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7010 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
7013 case dw_val_class_unsigned_const
:
7014 case dw_val_class_unsigned_const_implicit
:
7015 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7016 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
7019 case dw_val_class_const_double
:
7020 CHECKSUM_ULEB128 (DW_FORM_block
);
7021 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
7022 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
7025 case dw_val_class_wide_int
:
7026 CHECKSUM_ULEB128 (DW_FORM_block
);
7027 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
7028 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
7029 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
7030 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
7031 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
7034 case dw_val_class_vec
:
7035 CHECKSUM_ULEB128 (DW_FORM_block
);
7036 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
7037 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
7038 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
7039 (at
->dw_attr_val
.v
.val_vec
.length
7040 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
7043 case dw_val_class_flag
:
7044 CHECKSUM_ULEB128 (DW_FORM_flag
);
7045 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
7048 case dw_val_class_str
:
7049 CHECKSUM_ULEB128 (DW_FORM_string
);
7050 CHECKSUM_STRING (AT_string (at
));
7053 case dw_val_class_addr
:
7055 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
7056 CHECKSUM_ULEB128 (DW_FORM_string
);
7057 CHECKSUM_STRING (XSTR (r
, 0));
7060 case dw_val_class_offset
:
7061 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7062 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
7065 case dw_val_class_loc
:
7066 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
7067 loc_checksum_ordered (loc
, ctx
);
7070 case dw_val_class_fde_ref
:
7071 case dw_val_class_lbl_id
:
7072 case dw_val_class_lineptr
:
7073 case dw_val_class_macptr
:
7074 case dw_val_class_loclistsptr
:
7075 case dw_val_class_high_pc
:
7078 case dw_val_class_file
:
7079 case dw_val_class_file_implicit
:
7080 CHECKSUM_ULEB128 (DW_FORM_string
);
7081 CHECKSUM_STRING (AT_file (at
)->filename
);
7084 case dw_val_class_data8
:
7085 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
7093 struct checksum_attributes
7095 dw_attr_node
*at_name
;
7096 dw_attr_node
*at_type
;
7097 dw_attr_node
*at_friend
;
7098 dw_attr_node
*at_accessibility
;
7099 dw_attr_node
*at_address_class
;
7100 dw_attr_node
*at_alignment
;
7101 dw_attr_node
*at_allocated
;
7102 dw_attr_node
*at_artificial
;
7103 dw_attr_node
*at_associated
;
7104 dw_attr_node
*at_binary_scale
;
7105 dw_attr_node
*at_bit_offset
;
7106 dw_attr_node
*at_bit_size
;
7107 dw_attr_node
*at_bit_stride
;
7108 dw_attr_node
*at_byte_size
;
7109 dw_attr_node
*at_byte_stride
;
7110 dw_attr_node
*at_const_value
;
7111 dw_attr_node
*at_containing_type
;
7112 dw_attr_node
*at_count
;
7113 dw_attr_node
*at_data_location
;
7114 dw_attr_node
*at_data_member_location
;
7115 dw_attr_node
*at_decimal_scale
;
7116 dw_attr_node
*at_decimal_sign
;
7117 dw_attr_node
*at_default_value
;
7118 dw_attr_node
*at_digit_count
;
7119 dw_attr_node
*at_discr
;
7120 dw_attr_node
*at_discr_list
;
7121 dw_attr_node
*at_discr_value
;
7122 dw_attr_node
*at_encoding
;
7123 dw_attr_node
*at_endianity
;
7124 dw_attr_node
*at_explicit
;
7125 dw_attr_node
*at_is_optional
;
7126 dw_attr_node
*at_location
;
7127 dw_attr_node
*at_lower_bound
;
7128 dw_attr_node
*at_mutable
;
7129 dw_attr_node
*at_ordering
;
7130 dw_attr_node
*at_picture_string
;
7131 dw_attr_node
*at_prototyped
;
7132 dw_attr_node
*at_small
;
7133 dw_attr_node
*at_segment
;
7134 dw_attr_node
*at_string_length
;
7135 dw_attr_node
*at_string_length_bit_size
;
7136 dw_attr_node
*at_string_length_byte_size
;
7137 dw_attr_node
*at_threads_scaled
;
7138 dw_attr_node
*at_upper_bound
;
7139 dw_attr_node
*at_use_location
;
7140 dw_attr_node
*at_use_UTF8
;
7141 dw_attr_node
*at_variable_parameter
;
7142 dw_attr_node
*at_virtuality
;
7143 dw_attr_node
*at_visibility
;
7144 dw_attr_node
*at_vtable_elem_location
;
7147 /* Collect the attributes that we will want to use for the checksum. */
7150 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
7155 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7166 attrs
->at_friend
= a
;
7168 case DW_AT_accessibility
:
7169 attrs
->at_accessibility
= a
;
7171 case DW_AT_address_class
:
7172 attrs
->at_address_class
= a
;
7174 case DW_AT_alignment
:
7175 attrs
->at_alignment
= a
;
7177 case DW_AT_allocated
:
7178 attrs
->at_allocated
= a
;
7180 case DW_AT_artificial
:
7181 attrs
->at_artificial
= a
;
7183 case DW_AT_associated
:
7184 attrs
->at_associated
= a
;
7186 case DW_AT_binary_scale
:
7187 attrs
->at_binary_scale
= a
;
7189 case DW_AT_bit_offset
:
7190 attrs
->at_bit_offset
= a
;
7192 case DW_AT_bit_size
:
7193 attrs
->at_bit_size
= a
;
7195 case DW_AT_bit_stride
:
7196 attrs
->at_bit_stride
= a
;
7198 case DW_AT_byte_size
:
7199 attrs
->at_byte_size
= a
;
7201 case DW_AT_byte_stride
:
7202 attrs
->at_byte_stride
= a
;
7204 case DW_AT_const_value
:
7205 attrs
->at_const_value
= a
;
7207 case DW_AT_containing_type
:
7208 attrs
->at_containing_type
= a
;
7211 attrs
->at_count
= a
;
7213 case DW_AT_data_location
:
7214 attrs
->at_data_location
= a
;
7216 case DW_AT_data_member_location
:
7217 attrs
->at_data_member_location
= a
;
7219 case DW_AT_decimal_scale
:
7220 attrs
->at_decimal_scale
= a
;
7222 case DW_AT_decimal_sign
:
7223 attrs
->at_decimal_sign
= a
;
7225 case DW_AT_default_value
:
7226 attrs
->at_default_value
= a
;
7228 case DW_AT_digit_count
:
7229 attrs
->at_digit_count
= a
;
7232 attrs
->at_discr
= a
;
7234 case DW_AT_discr_list
:
7235 attrs
->at_discr_list
= a
;
7237 case DW_AT_discr_value
:
7238 attrs
->at_discr_value
= a
;
7240 case DW_AT_encoding
:
7241 attrs
->at_encoding
= a
;
7243 case DW_AT_endianity
:
7244 attrs
->at_endianity
= a
;
7246 case DW_AT_explicit
:
7247 attrs
->at_explicit
= a
;
7249 case DW_AT_is_optional
:
7250 attrs
->at_is_optional
= a
;
7252 case DW_AT_location
:
7253 attrs
->at_location
= a
;
7255 case DW_AT_lower_bound
:
7256 attrs
->at_lower_bound
= a
;
7259 attrs
->at_mutable
= a
;
7261 case DW_AT_ordering
:
7262 attrs
->at_ordering
= a
;
7264 case DW_AT_picture_string
:
7265 attrs
->at_picture_string
= a
;
7267 case DW_AT_prototyped
:
7268 attrs
->at_prototyped
= a
;
7271 attrs
->at_small
= a
;
7274 attrs
->at_segment
= a
;
7276 case DW_AT_string_length
:
7277 attrs
->at_string_length
= a
;
7279 case DW_AT_string_length_bit_size
:
7280 attrs
->at_string_length_bit_size
= a
;
7282 case DW_AT_string_length_byte_size
:
7283 attrs
->at_string_length_byte_size
= a
;
7285 case DW_AT_threads_scaled
:
7286 attrs
->at_threads_scaled
= a
;
7288 case DW_AT_upper_bound
:
7289 attrs
->at_upper_bound
= a
;
7291 case DW_AT_use_location
:
7292 attrs
->at_use_location
= a
;
7294 case DW_AT_use_UTF8
:
7295 attrs
->at_use_UTF8
= a
;
7297 case DW_AT_variable_parameter
:
7298 attrs
->at_variable_parameter
= a
;
7300 case DW_AT_virtuality
:
7301 attrs
->at_virtuality
= a
;
7303 case DW_AT_visibility
:
7304 attrs
->at_visibility
= a
;
7306 case DW_AT_vtable_elem_location
:
7307 attrs
->at_vtable_elem_location
= a
;
7315 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
7318 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
7322 struct checksum_attributes attrs
;
7324 CHECKSUM_ULEB128 ('D');
7325 CHECKSUM_ULEB128 (die
->die_tag
);
7327 memset (&attrs
, 0, sizeof (attrs
));
7329 decl
= get_AT_ref (die
, DW_AT_specification
);
7331 collect_checksum_attributes (&attrs
, decl
);
7332 collect_checksum_attributes (&attrs
, die
);
7334 CHECKSUM_ATTR (attrs
.at_name
);
7335 CHECKSUM_ATTR (attrs
.at_accessibility
);
7336 CHECKSUM_ATTR (attrs
.at_address_class
);
7337 CHECKSUM_ATTR (attrs
.at_allocated
);
7338 CHECKSUM_ATTR (attrs
.at_artificial
);
7339 CHECKSUM_ATTR (attrs
.at_associated
);
7340 CHECKSUM_ATTR (attrs
.at_binary_scale
);
7341 CHECKSUM_ATTR (attrs
.at_bit_offset
);
7342 CHECKSUM_ATTR (attrs
.at_bit_size
);
7343 CHECKSUM_ATTR (attrs
.at_bit_stride
);
7344 CHECKSUM_ATTR (attrs
.at_byte_size
);
7345 CHECKSUM_ATTR (attrs
.at_byte_stride
);
7346 CHECKSUM_ATTR (attrs
.at_const_value
);
7347 CHECKSUM_ATTR (attrs
.at_containing_type
);
7348 CHECKSUM_ATTR (attrs
.at_count
);
7349 CHECKSUM_ATTR (attrs
.at_data_location
);
7350 CHECKSUM_ATTR (attrs
.at_data_member_location
);
7351 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
7352 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
7353 CHECKSUM_ATTR (attrs
.at_default_value
);
7354 CHECKSUM_ATTR (attrs
.at_digit_count
);
7355 CHECKSUM_ATTR (attrs
.at_discr
);
7356 CHECKSUM_ATTR (attrs
.at_discr_list
);
7357 CHECKSUM_ATTR (attrs
.at_discr_value
);
7358 CHECKSUM_ATTR (attrs
.at_encoding
);
7359 CHECKSUM_ATTR (attrs
.at_endianity
);
7360 CHECKSUM_ATTR (attrs
.at_explicit
);
7361 CHECKSUM_ATTR (attrs
.at_is_optional
);
7362 CHECKSUM_ATTR (attrs
.at_location
);
7363 CHECKSUM_ATTR (attrs
.at_lower_bound
);
7364 CHECKSUM_ATTR (attrs
.at_mutable
);
7365 CHECKSUM_ATTR (attrs
.at_ordering
);
7366 CHECKSUM_ATTR (attrs
.at_picture_string
);
7367 CHECKSUM_ATTR (attrs
.at_prototyped
);
7368 CHECKSUM_ATTR (attrs
.at_small
);
7369 CHECKSUM_ATTR (attrs
.at_segment
);
7370 CHECKSUM_ATTR (attrs
.at_string_length
);
7371 CHECKSUM_ATTR (attrs
.at_string_length_bit_size
);
7372 CHECKSUM_ATTR (attrs
.at_string_length_byte_size
);
7373 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
7374 CHECKSUM_ATTR (attrs
.at_upper_bound
);
7375 CHECKSUM_ATTR (attrs
.at_use_location
);
7376 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
7377 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
7378 CHECKSUM_ATTR (attrs
.at_virtuality
);
7379 CHECKSUM_ATTR (attrs
.at_visibility
);
7380 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
7381 CHECKSUM_ATTR (attrs
.at_type
);
7382 CHECKSUM_ATTR (attrs
.at_friend
);
7383 CHECKSUM_ATTR (attrs
.at_alignment
);
7385 /* Checksum the child DIEs. */
7388 dw_attr_node
*name_attr
;
7391 name_attr
= get_AT (c
, DW_AT_name
);
7392 if (is_template_instantiation (c
))
7394 /* Ignore instantiations of member type and function templates. */
7396 else if (name_attr
!= NULL
7397 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
7399 /* Use a shallow checksum for named nested types and member
7401 CHECKSUM_ULEB128 ('S');
7402 CHECKSUM_ULEB128 (c
->die_tag
);
7403 CHECKSUM_STRING (AT_string (name_attr
));
7407 /* Use a deep checksum for other children. */
7408 /* Mark this DIE so it gets processed when unmarking. */
7409 if (c
->die_mark
== 0)
7411 die_checksum_ordered (c
, ctx
, mark
);
7413 } while (c
!= die
->die_child
);
7415 CHECKSUM_ULEB128 (0);
7418 /* Add a type name and tag to a hash. */
7420 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
7422 CHECKSUM_ULEB128 (tag
);
7423 CHECKSUM_STRING (name
);
7427 #undef CHECKSUM_STRING
7428 #undef CHECKSUM_ATTR
7429 #undef CHECKSUM_LEB128
7430 #undef CHECKSUM_ULEB128
7432 /* Generate the type signature for DIE. This is computed by generating an
7433 MD5 checksum over the DIE's tag, its relevant attributes, and its
7434 children. Attributes that are references to other DIEs are processed
7435 by recursion, using the MARK field to prevent infinite recursion.
7436 If the DIE is nested inside a namespace or another type, we also
7437 need to include that context in the signature. The lower 64 bits
7438 of the resulting MD5 checksum comprise the signature. */
7441 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
7445 unsigned char checksum
[16];
7450 name
= get_AT_string (die
, DW_AT_name
);
7451 decl
= get_AT_ref (die
, DW_AT_specification
);
7452 parent
= get_die_parent (die
);
7454 /* First, compute a signature for just the type name (and its surrounding
7455 context, if any. This is stored in the type unit DIE for link-time
7456 ODR (one-definition rule) checking. */
7458 if (is_cxx () && name
!= NULL
)
7460 md5_init_ctx (&ctx
);
7462 /* Checksum the names of surrounding namespaces and structures. */
7464 checksum_die_context (parent
, &ctx
);
7466 /* Checksum the current DIE. */
7467 die_odr_checksum (die
->die_tag
, name
, &ctx
);
7468 md5_finish_ctx (&ctx
, checksum
);
7470 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
7473 /* Next, compute the complete type signature. */
7475 md5_init_ctx (&ctx
);
7477 die
->die_mark
= mark
;
7479 /* Checksum the names of surrounding namespaces and structures. */
7481 checksum_die_context (parent
, &ctx
);
7483 /* Checksum the DIE and its children. */
7484 die_checksum_ordered (die
, &ctx
, &mark
);
7485 unmark_all_dies (die
);
7486 md5_finish_ctx (&ctx
, checksum
);
7488 /* Store the signature in the type node and link the type DIE and the
7489 type node together. */
7490 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
7491 DWARF_TYPE_SIGNATURE_SIZE
);
7492 die
->comdat_type_p
= true;
7493 die
->die_id
.die_type_node
= type_node
;
7494 type_node
->type_die
= die
;
7496 /* If the DIE is a specification, link its declaration to the type node
7500 decl
->comdat_type_p
= true;
7501 decl
->die_id
.die_type_node
= type_node
;
7505 /* Do the location expressions look same? */
7507 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
7509 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
7510 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
7511 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
7514 /* Do the values look the same? */
7516 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
7518 dw_loc_descr_ref loc1
, loc2
;
7521 if (v1
->val_class
!= v2
->val_class
)
7524 switch (v1
->val_class
)
7526 case dw_val_class_const
:
7527 case dw_val_class_const_implicit
:
7528 return v1
->v
.val_int
== v2
->v
.val_int
;
7529 case dw_val_class_unsigned_const
:
7530 case dw_val_class_unsigned_const_implicit
:
7531 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
7532 case dw_val_class_const_double
:
7533 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
7534 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
7535 case dw_val_class_wide_int
:
7536 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
7537 case dw_val_class_vec
:
7538 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
7539 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7541 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7542 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7545 case dw_val_class_flag
:
7546 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7547 case dw_val_class_str
:
7548 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7550 case dw_val_class_addr
:
7551 r1
= v1
->v
.val_addr
;
7552 r2
= v2
->v
.val_addr
;
7553 if (GET_CODE (r1
) != GET_CODE (r2
))
7555 return !rtx_equal_p (r1
, r2
);
7557 case dw_val_class_offset
:
7558 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7560 case dw_val_class_loc
:
7561 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7563 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7564 if (!same_loc_p (loc1
, loc2
, mark
))
7566 return !loc1
&& !loc2
;
7568 case dw_val_class_die_ref
:
7569 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7571 case dw_val_class_fde_ref
:
7572 case dw_val_class_vms_delta
:
7573 case dw_val_class_lbl_id
:
7574 case dw_val_class_lineptr
:
7575 case dw_val_class_macptr
:
7576 case dw_val_class_loclistsptr
:
7577 case dw_val_class_high_pc
:
7580 case dw_val_class_file
:
7581 case dw_val_class_file_implicit
:
7582 return v1
->v
.val_file
== v2
->v
.val_file
;
7584 case dw_val_class_data8
:
7585 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
7592 /* Do the attributes look the same? */
7595 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
7597 if (at1
->dw_attr
!= at2
->dw_attr
)
7600 /* We don't care that this was compiled with a different compiler
7601 snapshot; if the output is the same, that's what matters. */
7602 if (at1
->dw_attr
== DW_AT_producer
)
7605 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7608 /* Do the dies look the same? */
7611 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7617 /* To avoid infinite recursion. */
7619 return die1
->die_mark
== die2
->die_mark
;
7620 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7622 if (die1
->die_tag
!= die2
->die_tag
)
7625 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
7628 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
7629 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
7632 c1
= die1
->die_child
;
7633 c2
= die2
->die_child
;
7642 if (!same_die_p (c1
, c2
, mark
))
7646 if (c1
== die1
->die_child
)
7648 if (c2
== die2
->die_child
)
7658 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7659 children, and set die_symbol. */
7662 compute_comp_unit_symbol (dw_die_ref unit_die
)
7664 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
7665 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
7666 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
7669 unsigned char checksum
[16];
7672 /* Compute the checksum of the DIE, then append part of it as hex digits to
7673 the name filename of the unit. */
7675 md5_init_ctx (&ctx
);
7677 die_checksum (unit_die
, &ctx
, &mark
);
7678 unmark_all_dies (unit_die
);
7679 md5_finish_ctx (&ctx
, checksum
);
7681 /* When we this for comp_unit_die () we have a DW_AT_name that might
7682 not start with a letter but with anything valid for filenames and
7683 clean_symbol_name doesn't fix that up. Prepend 'g' if the first
7684 character is not a letter. */
7685 sprintf (name
, "%s%s.", ISALPHA (*base
) ? "" : "g", base
);
7686 clean_symbol_name (name
);
7688 p
= name
+ strlen (name
);
7689 for (i
= 0; i
< 4; i
++)
7691 sprintf (p
, "%.2x", checksum
[i
]);
7695 unit_die
->die_id
.die_symbol
= xstrdup (name
);
7698 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7701 is_type_die (dw_die_ref die
)
7703 switch (die
->die_tag
)
7705 case DW_TAG_array_type
:
7706 case DW_TAG_class_type
:
7707 case DW_TAG_interface_type
:
7708 case DW_TAG_enumeration_type
:
7709 case DW_TAG_pointer_type
:
7710 case DW_TAG_reference_type
:
7711 case DW_TAG_rvalue_reference_type
:
7712 case DW_TAG_string_type
:
7713 case DW_TAG_structure_type
:
7714 case DW_TAG_subroutine_type
:
7715 case DW_TAG_union_type
:
7716 case DW_TAG_ptr_to_member_type
:
7717 case DW_TAG_set_type
:
7718 case DW_TAG_subrange_type
:
7719 case DW_TAG_base_type
:
7720 case DW_TAG_const_type
:
7721 case DW_TAG_file_type
:
7722 case DW_TAG_packed_type
:
7723 case DW_TAG_volatile_type
:
7724 case DW_TAG_typedef
:
7731 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7732 Basically, we want to choose the bits that are likely to be shared between
7733 compilations (types) and leave out the bits that are specific to individual
7734 compilations (functions). */
7737 is_comdat_die (dw_die_ref c
)
7739 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7740 we do for stabs. The advantage is a greater likelihood of sharing between
7741 objects that don't include headers in the same order (and therefore would
7742 put the base types in a different comdat). jason 8/28/00 */
7744 if (c
->die_tag
== DW_TAG_base_type
)
7747 if (c
->die_tag
== DW_TAG_pointer_type
7748 || c
->die_tag
== DW_TAG_reference_type
7749 || c
->die_tag
== DW_TAG_rvalue_reference_type
7750 || c
->die_tag
== DW_TAG_const_type
7751 || c
->die_tag
== DW_TAG_volatile_type
)
7753 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
7755 return t
? is_comdat_die (t
) : 0;
7758 return is_type_die (c
);
7761 /* Returns true iff C is a compile-unit DIE. */
7764 is_cu_die (dw_die_ref c
)
7766 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7767 || c
->die_tag
== DW_TAG_skeleton_unit
);
7770 /* Returns true iff C is a unit DIE of some sort. */
7773 is_unit_die (dw_die_ref c
)
7775 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7776 || c
->die_tag
== DW_TAG_partial_unit
7777 || c
->die_tag
== DW_TAG_type_unit
7778 || c
->die_tag
== DW_TAG_skeleton_unit
);
7781 /* Returns true iff C is a namespace DIE. */
7784 is_namespace_die (dw_die_ref c
)
7786 return c
&& c
->die_tag
== DW_TAG_namespace
;
7789 /* Returns true iff C is a class or structure DIE. */
7792 is_class_die (dw_die_ref c
)
7794 return c
&& (c
->die_tag
== DW_TAG_class_type
7795 || c
->die_tag
== DW_TAG_structure_type
);
7798 /* Return non-zero if this DIE is a template parameter. */
7801 is_template_parameter (dw_die_ref die
)
7803 switch (die
->die_tag
)
7805 case DW_TAG_template_type_param
:
7806 case DW_TAG_template_value_param
:
7807 case DW_TAG_GNU_template_template_param
:
7808 case DW_TAG_GNU_template_parameter_pack
:
7815 /* Return non-zero if this DIE represents a template instantiation. */
7818 is_template_instantiation (dw_die_ref die
)
7822 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
7824 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
7829 gen_internal_sym (const char *prefix
)
7831 char buf
[MAX_ARTIFICIAL_LABEL_BYTES
];
7833 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7834 return xstrdup (buf
);
7837 /* Return non-zero if this DIE is a declaration. */
7840 is_declaration_die (dw_die_ref die
)
7845 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7846 if (a
->dw_attr
== DW_AT_declaration
)
7852 /* Return non-zero if this DIE is nested inside a subprogram. */
7855 is_nested_in_subprogram (dw_die_ref die
)
7857 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7861 return local_scope_p (decl
);
7864 /* Return non-zero if this DIE contains a defining declaration of a
7868 contains_subprogram_definition (dw_die_ref die
)
7872 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7874 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7878 /* Return non-zero if this is a type DIE that should be moved to a
7879 COMDAT .debug_types section or .debug_info section with DW_UT_*type
7883 should_move_die_to_comdat (dw_die_ref die
)
7885 switch (die
->die_tag
)
7887 case DW_TAG_class_type
:
7888 case DW_TAG_structure_type
:
7889 case DW_TAG_enumeration_type
:
7890 case DW_TAG_union_type
:
7891 /* Don't move declarations, inlined instances, types nested in a
7892 subprogram, or types that contain subprogram definitions. */
7893 if (is_declaration_die (die
)
7894 || get_AT (die
, DW_AT_abstract_origin
)
7895 || is_nested_in_subprogram (die
)
7896 || contains_subprogram_definition (die
))
7899 case DW_TAG_array_type
:
7900 case DW_TAG_interface_type
:
7901 case DW_TAG_pointer_type
:
7902 case DW_TAG_reference_type
:
7903 case DW_TAG_rvalue_reference_type
:
7904 case DW_TAG_string_type
:
7905 case DW_TAG_subroutine_type
:
7906 case DW_TAG_ptr_to_member_type
:
7907 case DW_TAG_set_type
:
7908 case DW_TAG_subrange_type
:
7909 case DW_TAG_base_type
:
7910 case DW_TAG_const_type
:
7911 case DW_TAG_file_type
:
7912 case DW_TAG_packed_type
:
7913 case DW_TAG_volatile_type
:
7914 case DW_TAG_typedef
:
7920 /* Make a clone of DIE. */
7923 clone_die (dw_die_ref die
)
7925 dw_die_ref clone
= new_die_raw (die
->die_tag
);
7929 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7930 add_dwarf_attr (clone
, a
);
7935 /* Make a clone of the tree rooted at DIE. */
7938 clone_tree (dw_die_ref die
)
7941 dw_die_ref clone
= clone_die (die
);
7943 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7948 /* Make a clone of DIE as a declaration. */
7951 clone_as_declaration (dw_die_ref die
)
7958 /* If the DIE is already a declaration, just clone it. */
7959 if (is_declaration_die (die
))
7960 return clone_die (die
);
7962 /* If the DIE is a specification, just clone its declaration DIE. */
7963 decl
= get_AT_ref (die
, DW_AT_specification
);
7966 clone
= clone_die (decl
);
7967 if (die
->comdat_type_p
)
7968 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7972 clone
= new_die_raw (die
->die_tag
);
7974 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7976 /* We don't want to copy over all attributes.
7977 For example we don't want DW_AT_byte_size because otherwise we will no
7978 longer have a declaration and GDB will treat it as a definition. */
7982 case DW_AT_abstract_origin
:
7983 case DW_AT_artificial
:
7984 case DW_AT_containing_type
:
7985 case DW_AT_external
:
7988 case DW_AT_virtuality
:
7989 case DW_AT_linkage_name
:
7990 case DW_AT_MIPS_linkage_name
:
7991 add_dwarf_attr (clone
, a
);
7993 case DW_AT_byte_size
:
7994 case DW_AT_alignment
:
8000 if (die
->comdat_type_p
)
8001 add_AT_die_ref (clone
, DW_AT_signature
, die
);
8003 add_AT_flag (clone
, DW_AT_declaration
, 1);
8008 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
8010 struct decl_table_entry
8016 /* Helpers to manipulate hash table of copied declarations. */
8018 /* Hashtable helpers. */
8020 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
8022 typedef die_struct
*compare_type
;
8023 static inline hashval_t
hash (const decl_table_entry
*);
8024 static inline bool equal (const decl_table_entry
*, const die_struct
*);
8028 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
8030 return htab_hash_pointer (entry
->orig
);
8034 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
8035 const die_struct
*entry2
)
8037 return entry1
->orig
== entry2
;
8040 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
8042 /* Copy DIE and its ancestors, up to, but not including, the compile unit
8043 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
8044 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
8045 to check if the ancestor has already been copied into UNIT. */
8048 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
8049 decl_hash_type
*decl_table
)
8051 dw_die_ref parent
= die
->die_parent
;
8052 dw_die_ref new_parent
= unit
;
8054 decl_table_entry
**slot
= NULL
;
8055 struct decl_table_entry
*entry
= NULL
;
8059 /* Check if the entry has already been copied to UNIT. */
8060 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
8062 if (*slot
!= HTAB_EMPTY_ENTRY
)
8068 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
8069 entry
= XCNEW (struct decl_table_entry
);
8077 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
8080 if (!is_unit_die (parent
))
8081 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
8084 copy
= clone_as_declaration (die
);
8085 add_child_die (new_parent
, copy
);
8089 /* Record the pointer to the copy. */
8095 /* Copy the declaration context to the new type unit DIE. This includes
8096 any surrounding namespace or type declarations. If the DIE has an
8097 AT_specification attribute, it also includes attributes and children
8098 attached to the specification, and returns a pointer to the original
8099 parent of the declaration DIE. Returns NULL otherwise. */
8102 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
8105 dw_die_ref new_decl
;
8106 dw_die_ref orig_parent
= NULL
;
8108 decl
= get_AT_ref (die
, DW_AT_specification
);
8117 /* The original DIE will be changed to a declaration, and must
8118 be moved to be a child of the original declaration DIE. */
8119 orig_parent
= decl
->die_parent
;
8121 /* Copy the type node pointer from the new DIE to the original
8122 declaration DIE so we can forward references later. */
8123 decl
->comdat_type_p
= true;
8124 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
8126 remove_AT (die
, DW_AT_specification
);
8128 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
8130 if (a
->dw_attr
!= DW_AT_name
8131 && a
->dw_attr
!= DW_AT_declaration
8132 && a
->dw_attr
!= DW_AT_external
)
8133 add_dwarf_attr (die
, a
);
8136 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
8139 if (decl
->die_parent
!= NULL
8140 && !is_unit_die (decl
->die_parent
))
8142 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
8143 if (new_decl
!= NULL
)
8145 remove_AT (new_decl
, DW_AT_signature
);
8146 add_AT_specification (die
, new_decl
);
8153 /* Generate the skeleton ancestor tree for the given NODE, then clone
8154 the DIE and add the clone into the tree. */
8157 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
8159 if (node
->new_die
!= NULL
)
8162 node
->new_die
= clone_as_declaration (node
->old_die
);
8164 if (node
->parent
!= NULL
)
8166 generate_skeleton_ancestor_tree (node
->parent
);
8167 add_child_die (node
->parent
->new_die
, node
->new_die
);
8171 /* Generate a skeleton tree of DIEs containing any declarations that are
8172 found in the original tree. We traverse the tree looking for declaration
8173 DIEs, and construct the skeleton from the bottom up whenever we find one. */
8176 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
8178 skeleton_chain_node node
;
8181 dw_die_ref prev
= NULL
;
8182 dw_die_ref next
= NULL
;
8184 node
.parent
= parent
;
8186 first
= c
= parent
->old_die
->die_child
;
8190 if (prev
== NULL
|| prev
->die_sib
== c
)
8193 next
= (c
== first
? NULL
: c
->die_sib
);
8195 node
.new_die
= NULL
;
8196 if (is_declaration_die (c
))
8198 if (is_template_instantiation (c
))
8200 /* Instantiated templates do not need to be cloned into the
8201 type unit. Just move the DIE and its children back to
8202 the skeleton tree (in the main CU). */
8203 remove_child_with_prev (c
, prev
);
8204 add_child_die (parent
->new_die
, c
);
8207 else if (c
->comdat_type_p
)
8209 /* This is the skeleton of earlier break_out_comdat_types
8210 type. Clone the existing DIE, but keep the children
8211 under the original (which is in the main CU). */
8212 dw_die_ref clone
= clone_die (c
);
8214 replace_child (c
, clone
, prev
);
8215 generate_skeleton_ancestor_tree (parent
);
8216 add_child_die (parent
->new_die
, c
);
8222 /* Clone the existing DIE, move the original to the skeleton
8223 tree (which is in the main CU), and put the clone, with
8224 all the original's children, where the original came from
8225 (which is about to be moved to the type unit). */
8226 dw_die_ref clone
= clone_die (c
);
8227 move_all_children (c
, clone
);
8229 /* If the original has a DW_AT_object_pointer attribute,
8230 it would now point to a child DIE just moved to the
8231 cloned tree, so we need to remove that attribute from
8233 remove_AT (c
, DW_AT_object_pointer
);
8235 replace_child (c
, clone
, prev
);
8236 generate_skeleton_ancestor_tree (parent
);
8237 add_child_die (parent
->new_die
, c
);
8238 node
.old_die
= clone
;
8243 generate_skeleton_bottom_up (&node
);
8244 } while (next
!= NULL
);
8247 /* Wrapper function for generate_skeleton_bottom_up. */
8250 generate_skeleton (dw_die_ref die
)
8252 skeleton_chain_node node
;
8255 node
.new_die
= NULL
;
8258 /* If this type definition is nested inside another type,
8259 and is not an instantiation of a template, always leave
8260 at least a declaration in its place. */
8261 if (die
->die_parent
!= NULL
8262 && is_type_die (die
->die_parent
)
8263 && !is_template_instantiation (die
))
8264 node
.new_die
= clone_as_declaration (die
);
8266 generate_skeleton_bottom_up (&node
);
8267 return node
.new_die
;
8270 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
8271 declaration. The original DIE is moved to a new compile unit so that
8272 existing references to it follow it to the new location. If any of the
8273 original DIE's descendants is a declaration, we need to replace the
8274 original DIE with a skeleton tree and move the declarations back into the
8278 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
8281 dw_die_ref skeleton
, orig_parent
;
8283 /* Copy the declaration context to the type unit DIE. If the returned
8284 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
8286 orig_parent
= copy_declaration_context (unit
, child
);
8288 skeleton
= generate_skeleton (child
);
8289 if (skeleton
== NULL
)
8290 remove_child_with_prev (child
, prev
);
8293 skeleton
->comdat_type_p
= true;
8294 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
8296 /* If the original DIE was a specification, we need to put
8297 the skeleton under the parent DIE of the declaration.
8298 This leaves the original declaration in the tree, but
8299 it will be pruned later since there are no longer any
8300 references to it. */
8301 if (orig_parent
!= NULL
)
8303 remove_child_with_prev (child
, prev
);
8304 add_child_die (orig_parent
, skeleton
);
8307 replace_child (child
, skeleton
, prev
);
8314 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8315 comdat_type_node
*type_node
,
8316 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
8318 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8319 procedure, put it under TYPE_NODE and return the copy. Continue looking for
8320 DWARF procedure references in the DW_AT_location attribute. */
8323 copy_dwarf_procedure (dw_die_ref die
,
8324 comdat_type_node
*type_node
,
8325 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8327 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
8329 /* DWARF procedures are not supposed to have children... */
8330 gcc_assert (die
->die_child
== NULL
);
8332 /* ... and they are supposed to have only one attribute: DW_AT_location. */
8333 gcc_assert (vec_safe_length (die
->die_attr
) == 1
8334 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
8336 /* Do not copy more than once DWARF procedures. */
8338 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
8342 die_copy
= clone_die (die
);
8343 add_child_die (type_node
->root_die
, die_copy
);
8344 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
8348 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8349 procedures in DIE's attributes. */
8352 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8353 comdat_type_node
*type_node
,
8354 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8359 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
8361 dw_loc_descr_ref loc
;
8363 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
8366 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
8368 switch (loc
->dw_loc_opc
)
8372 case DW_OP_call_ref
:
8373 gcc_assert (loc
->dw_loc_oprnd1
.val_class
8374 == dw_val_class_die_ref
);
8375 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
8376 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
8378 copied_dwarf_procs
);
8387 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8388 rewrite references to point to the copies.
8390 References are looked for in DIE's attributes and recursively in all its
8391 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8392 mapping from old DWARF procedures to their copy. It is used not to copy
8393 twice the same DWARF procedure under TYPE_NODE. */
8396 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
8397 comdat_type_node
*type_node
,
8398 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8402 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
8403 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
8405 copied_dwarf_procs
));
8408 /* Traverse the DIE and set up additional .debug_types or .debug_info
8409 DW_UT_*type sections for each type worthy of being placed in a COMDAT
8413 break_out_comdat_types (dw_die_ref die
)
8417 dw_die_ref prev
= NULL
;
8418 dw_die_ref next
= NULL
;
8419 dw_die_ref unit
= NULL
;
8421 first
= c
= die
->die_child
;
8425 if (prev
== NULL
|| prev
->die_sib
== c
)
8428 next
= (c
== first
? NULL
: c
->die_sib
);
8429 if (should_move_die_to_comdat (c
))
8431 dw_die_ref replacement
;
8432 comdat_type_node
*type_node
;
8434 /* Break out nested types into their own type units. */
8435 break_out_comdat_types (c
);
8437 /* Create a new type unit DIE as the root for the new tree, and
8438 add it to the list of comdat types. */
8439 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8440 add_AT_unsigned (unit
, DW_AT_language
,
8441 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
8442 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
8443 type_node
->root_die
= unit
;
8444 type_node
->next
= comdat_type_list
;
8445 comdat_type_list
= type_node
;
8447 /* Generate the type signature. */
8448 generate_type_signature (c
, type_node
);
8450 /* Copy the declaration context, attributes, and children of the
8451 declaration into the new type unit DIE, then remove this DIE
8452 from the main CU (or replace it with a skeleton if necessary). */
8453 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
8454 type_node
->skeleton_die
= replacement
;
8456 /* Add the DIE to the new compunit. */
8457 add_child_die (unit
, c
);
8459 /* Types can reference DWARF procedures for type size or data location
8460 expressions. Calls in DWARF expressions cannot target procedures
8461 that are not in the same section. So we must copy DWARF procedures
8462 along with this type and then rewrite references to them. */
8463 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
8464 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
8466 if (replacement
!= NULL
)
8469 else if (c
->die_tag
== DW_TAG_namespace
8470 || c
->die_tag
== DW_TAG_class_type
8471 || c
->die_tag
== DW_TAG_structure_type
8472 || c
->die_tag
== DW_TAG_union_type
)
8474 /* Look for nested types that can be broken out. */
8475 break_out_comdat_types (c
);
8477 } while (next
!= NULL
);
8480 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8481 Enter all the cloned children into the hash table decl_table. */
8484 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
8488 struct decl_table_entry
*entry
;
8489 decl_table_entry
**slot
;
8491 if (die
->die_tag
== DW_TAG_subprogram
)
8492 clone
= clone_as_declaration (die
);
8494 clone
= clone_die (die
);
8496 slot
= decl_table
->find_slot_with_hash (die
,
8497 htab_hash_pointer (die
), INSERT
);
8499 /* Assert that DIE isn't in the hash table yet. If it would be there
8500 before, the ancestors would be necessarily there as well, therefore
8501 clone_tree_partial wouldn't be called. */
8502 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8504 entry
= XCNEW (struct decl_table_entry
);
8506 entry
->copy
= clone
;
8509 if (die
->die_tag
!= DW_TAG_subprogram
)
8510 FOR_EACH_CHILD (die
, c
,
8511 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
8516 /* Walk the DIE and its children, looking for references to incomplete
8517 or trivial types that are unmarked (i.e., that are not in the current
8521 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
8527 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8529 if (AT_class (a
) == dw_val_class_die_ref
)
8531 dw_die_ref targ
= AT_ref (a
);
8532 decl_table_entry
**slot
;
8533 struct decl_table_entry
*entry
;
8535 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
8538 slot
= decl_table
->find_slot_with_hash (targ
,
8539 htab_hash_pointer (targ
),
8542 if (*slot
!= HTAB_EMPTY_ENTRY
)
8544 /* TARG has already been copied, so we just need to
8545 modify the reference to point to the copy. */
8547 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
8551 dw_die_ref parent
= unit
;
8552 dw_die_ref copy
= clone_die (targ
);
8554 /* Record in DECL_TABLE that TARG has been copied.
8555 Need to do this now, before the recursive call,
8556 because DECL_TABLE may be expanded and SLOT
8557 would no longer be a valid pointer. */
8558 entry
= XCNEW (struct decl_table_entry
);
8563 /* If TARG is not a declaration DIE, we need to copy its
8565 if (!is_declaration_die (targ
))
8569 add_child_die (copy
,
8570 clone_tree_partial (c
, decl_table
)));
8573 /* Make sure the cloned tree is marked as part of the
8577 /* If TARG has surrounding context, copy its ancestor tree
8578 into the new type unit. */
8579 if (targ
->die_parent
!= NULL
8580 && !is_unit_die (targ
->die_parent
))
8581 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8584 add_child_die (parent
, copy
);
8585 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8587 /* Make sure the newly-copied DIE is walked. If it was
8588 installed in a previously-added context, it won't
8589 get visited otherwise. */
8592 /* Find the highest point of the newly-added tree,
8593 mark each node along the way, and walk from there. */
8594 parent
->die_mark
= 1;
8595 while (parent
->die_parent
8596 && parent
->die_parent
->die_mark
== 0)
8598 parent
= parent
->die_parent
;
8599 parent
->die_mark
= 1;
8601 copy_decls_walk (unit
, parent
, decl_table
);
8607 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8610 /* Copy declarations for "unworthy" types into the new comdat section.
8611 Incomplete types, modified types, and certain other types aren't broken
8612 out into comdat sections of their own, so they don't have a signature,
8613 and we need to copy the declaration into the same section so that we
8614 don't have an external reference. */
8617 copy_decls_for_unworthy_types (dw_die_ref unit
)
8620 decl_hash_type
decl_table (10);
8621 copy_decls_walk (unit
, unit
, &decl_table
);
8625 /* Traverse the DIE and add a sibling attribute if it may have the
8626 effect of speeding up access to siblings. To save some space,
8627 avoid generating sibling attributes for DIE's without children. */
8630 add_sibling_attributes (dw_die_ref die
)
8634 if (! die
->die_child
)
8637 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8638 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8640 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8643 /* Output all location lists for the DIE and its children. */
8646 output_location_lists (dw_die_ref die
)
8652 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8653 if (AT_class (a
) == dw_val_class_loc_list
)
8654 output_loc_list (AT_loc_list (a
));
8656 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
8659 /* During assign_location_list_indexes and output_loclists_offset the
8660 current index, after it the number of assigned indexes (i.e. how
8661 large the .debug_loclists* offset table should be). */
8662 static unsigned int loc_list_idx
;
8664 /* Output all location list offsets for the DIE and its children. */
8667 output_loclists_offsets (dw_die_ref die
)
8673 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8674 if (AT_class (a
) == dw_val_class_loc_list
)
8676 dw_loc_list_ref l
= AT_loc_list (a
);
8677 if (l
->offset_emitted
)
8679 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l
->ll_symbol
,
8680 loc_section_label
, NULL
);
8681 gcc_assert (l
->hash
== loc_list_idx
);
8683 l
->offset_emitted
= true;
8686 FOR_EACH_CHILD (die
, c
, output_loclists_offsets (c
));
8689 /* Recursively set indexes of location lists. */
8692 assign_location_list_indexes (dw_die_ref die
)
8698 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8699 if (AT_class (a
) == dw_val_class_loc_list
)
8701 dw_loc_list_ref list
= AT_loc_list (a
);
8702 if (!list
->num_assigned
)
8704 list
->num_assigned
= true;
8705 list
->hash
= loc_list_idx
++;
8709 FOR_EACH_CHILD (die
, c
, assign_location_list_indexes (c
));
8712 /* We want to limit the number of external references, because they are
8713 larger than local references: a relocation takes multiple words, and
8714 even a sig8 reference is always eight bytes, whereas a local reference
8715 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8716 So if we encounter multiple external references to the same type DIE, we
8717 make a local typedef stub for it and redirect all references there.
8719 This is the element of the hash table for keeping track of these
8729 /* Hashtable helpers. */
8731 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
8733 static inline hashval_t
hash (const external_ref
*);
8734 static inline bool equal (const external_ref
*, const external_ref
*);
8738 external_ref_hasher::hash (const external_ref
*r
)
8740 dw_die_ref die
= r
->type
;
8743 /* We can't use the address of the DIE for hashing, because
8744 that will make the order of the stub DIEs non-deterministic. */
8745 if (! die
->comdat_type_p
)
8746 /* We have a symbol; use it to compute a hash. */
8747 h
= htab_hash_string (die
->die_id
.die_symbol
);
8750 /* We have a type signature; use a subset of the bits as the hash.
8751 The 8-byte signature is at least as large as hashval_t. */
8752 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
8753 memcpy (&h
, type_node
->signature
, sizeof (h
));
8759 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
8761 return r1
->type
== r2
->type
;
8764 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
8766 /* Return a pointer to the external_ref for references to DIE. */
8768 static struct external_ref
*
8769 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
8771 struct external_ref ref
, *ref_p
;
8772 external_ref
**slot
;
8775 slot
= map
->find_slot (&ref
, INSERT
);
8776 if (*slot
!= HTAB_EMPTY_ENTRY
)
8779 ref_p
= XCNEW (struct external_ref
);
8785 /* Subroutine of optimize_external_refs, below.
8787 If we see a type skeleton, record it as our stub. If we see external
8788 references, remember how many we've seen. */
8791 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
8796 struct external_ref
*ref_p
;
8798 if (is_type_die (die
)
8799 && (c
= get_AT_ref (die
, DW_AT_signature
)))
8801 /* This is a local skeleton; use it for local references. */
8802 ref_p
= lookup_external_ref (map
, c
);
8806 /* Scan the DIE references, and remember any that refer to DIEs from
8807 other CUs (i.e. those which are not marked). */
8808 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8809 if (AT_class (a
) == dw_val_class_die_ref
8810 && (c
= AT_ref (a
))->die_mark
== 0
8813 ref_p
= lookup_external_ref (map
, c
);
8817 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
8820 /* htab_traverse callback function for optimize_external_refs, below. SLOT
8821 points to an external_ref, DATA is the CU we're processing. If we don't
8822 already have a local stub, and we have multiple refs, build a stub. */
8825 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
8827 struct external_ref
*ref_p
= *slot
;
8829 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
8831 /* We have multiple references to this type, so build a small stub.
8832 Both of these forms are a bit dodgy from the perspective of the
8833 DWARF standard, since technically they should have names. */
8834 dw_die_ref cu
= data
;
8835 dw_die_ref type
= ref_p
->type
;
8836 dw_die_ref stub
= NULL
;
8838 if (type
->comdat_type_p
)
8840 /* If we refer to this type via sig8, use AT_signature. */
8841 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
8842 add_AT_die_ref (stub
, DW_AT_signature
, type
);
8846 /* Otherwise, use a typedef with no name. */
8847 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
8848 add_AT_die_ref (stub
, DW_AT_type
, type
);
8857 /* DIE is a unit; look through all the DIE references to see if there are
8858 any external references to types, and if so, create local stubs for
8859 them which will be applied in build_abbrev_table. This is useful because
8860 references to local DIEs are smaller. */
8862 static external_ref_hash_type
*
8863 optimize_external_refs (dw_die_ref die
)
8865 external_ref_hash_type
*map
= new external_ref_hash_type (10);
8866 optimize_external_refs_1 (die
, map
);
8867 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
8871 /* The following 3 variables are temporaries that are computed only during the
8872 build_abbrev_table call and used and released during the following
8873 optimize_abbrev_table call. */
8875 /* First abbrev_id that can be optimized based on usage. */
8876 static unsigned int abbrev_opt_start
;
8878 /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
8879 abbrev_id smaller than this, because they must be already sized
8880 during build_abbrev_table). */
8881 static unsigned int abbrev_opt_base_type_end
;
8883 /* Vector of usage counts during build_abbrev_table. Indexed by
8884 abbrev_id - abbrev_opt_start. */
8885 static vec
<unsigned int> abbrev_usage_count
;
8887 /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
8888 static vec
<dw_die_ref
> sorted_abbrev_dies
;
8890 /* The format of each DIE (and its attribute value pairs) is encoded in an
8891 abbreviation table. This routine builds the abbreviation table and assigns
8892 a unique abbreviation id for each abbreviation entry. The children of each
8893 die are visited recursively. */
8896 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
8898 unsigned int abbrev_id
= 0;
8904 /* Scan the DIE references, and replace any that refer to
8905 DIEs from other CUs (i.e. those which are not marked) with
8906 the local stubs we built in optimize_external_refs. */
8907 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8908 if (AT_class (a
) == dw_val_class_die_ref
8909 && (c
= AT_ref (a
))->die_mark
== 0)
8911 struct external_ref
*ref_p
;
8912 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8914 ref_p
= lookup_external_ref (extern_map
, c
);
8915 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8916 change_AT_die_ref (a
, ref_p
->stub
);
8918 /* We aren't changing this reference, so mark it external. */
8919 set_AT_ref_external (a
, 1);
8922 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
8924 dw_attr_node
*die_a
, *abbrev_a
;
8930 if (abbrev
->die_tag
!= die
->die_tag
)
8932 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8935 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8938 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8940 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8941 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8942 || (value_format (abbrev_a
) != value_format (die_a
)))
8952 if (abbrev_id
>= vec_safe_length (abbrev_die_table
))
8954 vec_safe_push (abbrev_die_table
, die
);
8955 if (abbrev_opt_start
)
8956 abbrev_usage_count
.safe_push (0);
8958 if (abbrev_opt_start
&& abbrev_id
>= abbrev_opt_start
)
8960 abbrev_usage_count
[abbrev_id
- abbrev_opt_start
]++;
8961 sorted_abbrev_dies
.safe_push (die
);
8964 die
->die_abbrev
= abbrev_id
;
8965 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8968 /* Callback function for sorted_abbrev_dies vector sorting. We sort
8969 by die_abbrev's usage count, from the most commonly used
8970 abbreviation to the least. */
8973 die_abbrev_cmp (const void *p1
, const void *p2
)
8975 dw_die_ref die1
= *(const dw_die_ref
*) p1
;
8976 dw_die_ref die2
= *(const dw_die_ref
*) p2
;
8978 gcc_checking_assert (die1
->die_abbrev
>= abbrev_opt_start
);
8979 gcc_checking_assert (die2
->die_abbrev
>= abbrev_opt_start
);
8981 if (die1
->die_abbrev
>= abbrev_opt_base_type_end
8982 && die2
->die_abbrev
>= abbrev_opt_base_type_end
)
8984 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8985 > abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8987 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8988 < abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8992 /* Stabilize the sort. */
8993 if (die1
->die_abbrev
< die2
->die_abbrev
)
8995 if (die1
->die_abbrev
> die2
->die_abbrev
)
9001 /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
9002 of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
9003 into dw_val_class_const_implicit or
9004 dw_val_class_unsigned_const_implicit. */
9007 optimize_implicit_const (unsigned int first_id
, unsigned int end
,
9008 vec
<bool> &implicit_consts
)
9010 /* It never makes sense if there is just one DIE using the abbreviation. */
9011 if (end
< first_id
+ 2)
9016 dw_die_ref die
= sorted_abbrev_dies
[first_id
];
9017 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9018 if (implicit_consts
[ix
])
9020 enum dw_val_class new_class
= dw_val_class_none
;
9021 switch (AT_class (a
))
9023 case dw_val_class_unsigned_const
:
9024 if ((HOST_WIDE_INT
) AT_unsigned (a
) < 0)
9027 /* The .debug_abbrev section will grow by
9028 size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
9029 in all the DIEs using that abbreviation. */
9030 if (constant_size (AT_unsigned (a
)) * (end
- first_id
)
9031 <= (unsigned) size_of_sleb128 (AT_unsigned (a
)))
9034 new_class
= dw_val_class_unsigned_const_implicit
;
9037 case dw_val_class_const
:
9038 new_class
= dw_val_class_const_implicit
;
9041 case dw_val_class_file
:
9042 new_class
= dw_val_class_file_implicit
;
9048 for (i
= first_id
; i
< end
; i
++)
9049 (*sorted_abbrev_dies
[i
]->die_attr
)[ix
].dw_attr_val
.val_class
9054 /* Attempt to optimize abbreviation table from abbrev_opt_start
9055 abbreviation above. */
9058 optimize_abbrev_table (void)
9060 if (abbrev_opt_start
9061 && vec_safe_length (abbrev_die_table
) > abbrev_opt_start
9062 && (dwarf_version
>= 5 || vec_safe_length (abbrev_die_table
) > 127))
9064 auto_vec
<bool, 32> implicit_consts
;
9065 sorted_abbrev_dies
.qsort (die_abbrev_cmp
);
9067 unsigned int abbrev_id
= abbrev_opt_start
- 1;
9068 unsigned int first_id
= ~0U;
9069 unsigned int last_abbrev_id
= 0;
9072 if (abbrev_opt_base_type_end
> abbrev_opt_start
)
9073 abbrev_id
= abbrev_opt_base_type_end
- 1;
9074 /* Reassign abbreviation ids from abbrev_opt_start above, so that
9075 most commonly used abbreviations come first. */
9076 FOR_EACH_VEC_ELT (sorted_abbrev_dies
, i
, die
)
9081 /* If calc_base_type_die_sizes has been called, the CU and
9082 base types after it can't be optimized, because we've already
9083 calculated their DIE offsets. We've sorted them first. */
9084 if (die
->die_abbrev
< abbrev_opt_base_type_end
)
9086 if (die
->die_abbrev
!= last_abbrev_id
)
9088 last_abbrev_id
= die
->die_abbrev
;
9089 if (dwarf_version
>= 5 && first_id
!= ~0U)
9090 optimize_implicit_const (first_id
, i
, implicit_consts
);
9092 (*abbrev_die_table
)[abbrev_id
] = die
;
9093 if (dwarf_version
>= 5)
9096 implicit_consts
.truncate (0);
9098 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9099 switch (AT_class (a
))
9101 case dw_val_class_const
:
9102 case dw_val_class_unsigned_const
:
9103 case dw_val_class_file
:
9104 implicit_consts
.safe_push (true);
9107 implicit_consts
.safe_push (false);
9112 else if (dwarf_version
>= 5)
9114 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9115 if (!implicit_consts
[ix
])
9119 dw_attr_node
*other_a
9120 = &(*(*abbrev_die_table
)[abbrev_id
]->die_attr
)[ix
];
9121 if (!dw_val_equal_p (&a
->dw_attr_val
,
9122 &other_a
->dw_attr_val
))
9123 implicit_consts
[ix
] = false;
9126 die
->die_abbrev
= abbrev_id
;
9128 gcc_assert (abbrev_id
== vec_safe_length (abbrev_die_table
) - 1);
9129 if (dwarf_version
>= 5 && first_id
!= ~0U)
9130 optimize_implicit_const (first_id
, i
, implicit_consts
);
9133 abbrev_opt_start
= 0;
9134 abbrev_opt_base_type_end
= 0;
9135 abbrev_usage_count
.release ();
9136 sorted_abbrev_dies
.release ();
9139 /* Return the power-of-two number of bytes necessary to represent VALUE. */
9142 constant_size (unsigned HOST_WIDE_INT value
)
9149 log
= floor_log2 (value
);
9152 log
= 1 << (floor_log2 (log
) + 1);
9157 /* Return the size of a DIE as it is represented in the
9158 .debug_info section. */
9160 static unsigned long
9161 size_of_die (dw_die_ref die
)
9163 unsigned long size
= 0;
9166 enum dwarf_form form
;
9168 size
+= size_of_uleb128 (die
->die_abbrev
);
9169 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9171 switch (AT_class (a
))
9173 case dw_val_class_addr
:
9174 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9176 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9177 size
+= size_of_uleb128 (AT_index (a
));
9180 size
+= DWARF2_ADDR_SIZE
;
9182 case dw_val_class_offset
:
9183 size
+= DWARF_OFFSET_SIZE
;
9185 case dw_val_class_loc
:
9187 unsigned long lsize
= size_of_locs (AT_loc (a
));
9190 if (dwarf_version
>= 4)
9191 size
+= size_of_uleb128 (lsize
);
9193 size
+= constant_size (lsize
);
9197 case dw_val_class_loc_list
:
9198 case dw_val_class_view_list
:
9199 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
9201 gcc_assert (AT_loc_list (a
)->num_assigned
);
9202 size
+= size_of_uleb128 (AT_loc_list (a
)->hash
);
9205 size
+= DWARF_OFFSET_SIZE
;
9207 case dw_val_class_range_list
:
9208 if (value_format (a
) == DW_FORM_rnglistx
)
9210 gcc_assert (rnglist_idx
);
9211 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9212 size
+= size_of_uleb128 (r
->idx
);
9215 size
+= DWARF_OFFSET_SIZE
;
9217 case dw_val_class_const
:
9218 size
+= size_of_sleb128 (AT_int (a
));
9220 case dw_val_class_unsigned_const
:
9222 int csize
= constant_size (AT_unsigned (a
));
9223 if (dwarf_version
== 3
9224 && a
->dw_attr
== DW_AT_data_member_location
9226 size
+= size_of_uleb128 (AT_unsigned (a
));
9231 case dw_val_class_const_implicit
:
9232 case dw_val_class_unsigned_const_implicit
:
9233 case dw_val_class_file_implicit
:
9234 /* These occupy no size in the DIE, just an extra sleb128 in
9237 case dw_val_class_const_double
:
9238 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
9239 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
9242 case dw_val_class_wide_int
:
9243 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9244 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
9245 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9246 * HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
9249 case dw_val_class_vec
:
9250 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
9251 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
9252 + a
->dw_attr_val
.v
.val_vec
.length
9253 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
9255 case dw_val_class_flag
:
9256 if (dwarf_version
>= 4)
9257 /* Currently all add_AT_flag calls pass in 1 as last argument,
9258 so DW_FORM_flag_present can be used. If that ever changes,
9259 we'll need to use DW_FORM_flag and have some optimization
9260 in build_abbrev_table that will change those to
9261 DW_FORM_flag_present if it is set to 1 in all DIEs using
9262 the same abbrev entry. */
9263 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9267 case dw_val_class_die_ref
:
9268 if (AT_ref_external (a
))
9270 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
9271 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
9272 is sized by target address length, whereas in DWARF3
9273 it's always sized as an offset. */
9274 if (use_debug_types
)
9275 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
9276 else if (dwarf_version
== 2)
9277 size
+= DWARF2_ADDR_SIZE
;
9279 size
+= DWARF_OFFSET_SIZE
;
9282 size
+= DWARF_OFFSET_SIZE
;
9284 case dw_val_class_fde_ref
:
9285 size
+= DWARF_OFFSET_SIZE
;
9287 case dw_val_class_lbl_id
:
9288 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9290 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9291 size
+= size_of_uleb128 (AT_index (a
));
9294 size
+= DWARF2_ADDR_SIZE
;
9296 case dw_val_class_lineptr
:
9297 case dw_val_class_macptr
:
9298 case dw_val_class_loclistsptr
:
9299 size
+= DWARF_OFFSET_SIZE
;
9301 case dw_val_class_str
:
9302 form
= AT_string_form (a
);
9303 if (form
== DW_FORM_strp
|| form
== DW_FORM_line_strp
)
9304 size
+= DWARF_OFFSET_SIZE
;
9305 else if (form
== DW_FORM_GNU_str_index
)
9306 size
+= size_of_uleb128 (AT_index (a
));
9308 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
9310 case dw_val_class_file
:
9311 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
9313 case dw_val_class_data8
:
9316 case dw_val_class_vms_delta
:
9317 size
+= DWARF_OFFSET_SIZE
;
9319 case dw_val_class_high_pc
:
9320 size
+= DWARF2_ADDR_SIZE
;
9322 case dw_val_class_discr_value
:
9323 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
9325 case dw_val_class_discr_list
:
9327 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
9329 /* This is a block, so we have the block length and then its
9331 size
+= constant_size (block_size
) + block_size
;
9342 /* Size the debugging information associated with a given DIE. Visits the
9343 DIE's children recursively. Updates the global variable next_die_offset, on
9344 each time through. Uses the current value of next_die_offset to update the
9345 die_offset field in each DIE. */
9348 calc_die_sizes (dw_die_ref die
)
9352 gcc_assert (die
->die_offset
== 0
9353 || (unsigned long int) die
->die_offset
== next_die_offset
);
9354 die
->die_offset
= next_die_offset
;
9355 next_die_offset
+= size_of_die (die
);
9357 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
9359 if (die
->die_child
!= NULL
)
9360 /* Count the null byte used to terminate sibling lists. */
9361 next_die_offset
+= 1;
9364 /* Size just the base type children at the start of the CU.
9365 This is needed because build_abbrev needs to size locs
9366 and sizing of type based stack ops needs to know die_offset
9367 values for the base types. */
9370 calc_base_type_die_sizes (void)
9372 unsigned long die_offset
= (dwarf_split_debug_info
9373 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9374 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
9376 dw_die_ref base_type
;
9377 #if ENABLE_ASSERT_CHECKING
9378 dw_die_ref prev
= comp_unit_die ()->die_child
;
9381 die_offset
+= size_of_die (comp_unit_die ());
9382 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
9384 #if ENABLE_ASSERT_CHECKING
9385 gcc_assert (base_type
->die_offset
== 0
9386 && prev
->die_sib
== base_type
9387 && base_type
->die_child
== NULL
9388 && base_type
->die_abbrev
);
9391 if (abbrev_opt_start
9392 && base_type
->die_abbrev
>= abbrev_opt_base_type_end
)
9393 abbrev_opt_base_type_end
= base_type
->die_abbrev
+ 1;
9394 base_type
->die_offset
= die_offset
;
9395 die_offset
+= size_of_die (base_type
);
9399 /* Set the marks for a die and its children. We do this so
9400 that we know whether or not a reference needs to use FORM_ref_addr; only
9401 DIEs in the same CU will be marked. We used to clear out the offset
9402 and use that as the flag, but ran into ordering problems. */
9405 mark_dies (dw_die_ref die
)
9409 gcc_assert (!die
->die_mark
);
9412 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
9415 /* Clear the marks for a die and its children. */
9418 unmark_dies (dw_die_ref die
)
9422 if (! use_debug_types
)
9423 gcc_assert (die
->die_mark
);
9426 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
9429 /* Clear the marks for a die, its children and referred dies. */
9432 unmark_all_dies (dw_die_ref die
)
9442 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
9444 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9445 if (AT_class (a
) == dw_val_class_die_ref
)
9446 unmark_all_dies (AT_ref (a
));
9449 /* Calculate if the entry should appear in the final output file. It may be
9450 from a pruned a type. */
9453 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
9455 /* By limiting gnu pubnames to definitions only, gold can generate a
9456 gdb index without entries for declarations, which don't include
9457 enough information to be useful. */
9458 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
9461 if (table
== pubname_table
)
9463 /* Enumerator names are part of the pubname table, but the
9464 parent DW_TAG_enumeration_type die may have been pruned.
9465 Don't output them if that is the case. */
9466 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
9467 (p
->die
->die_parent
== NULL
9468 || !p
->die
->die_parent
->die_perennial_p
))
9471 /* Everything else in the pubname table is included. */
9475 /* The pubtypes table shouldn't include types that have been
9477 return (p
->die
->die_offset
!= 0
9478 || !flag_eliminate_unused_debug_types
);
9481 /* Return the size of the .debug_pubnames or .debug_pubtypes table
9482 generated for the compilation unit. */
9484 static unsigned long
9485 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9490 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
9492 size
= DWARF_PUBNAMES_HEADER_SIZE
;
9493 FOR_EACH_VEC_ELT (*names
, i
, p
)
9494 if (include_pubname_in_output (names
, p
))
9495 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
9497 size
+= DWARF_OFFSET_SIZE
;
9501 /* Return the size of the information in the .debug_aranges section. */
9503 static unsigned long
9504 size_of_aranges (void)
9508 size
= DWARF_ARANGES_HEADER_SIZE
;
9510 /* Count the address/length pair for this compilation unit. */
9511 if (text_section_used
)
9512 size
+= 2 * DWARF2_ADDR_SIZE
;
9513 if (cold_text_section_used
)
9514 size
+= 2 * DWARF2_ADDR_SIZE
;
9515 if (have_multiple_function_sections
)
9520 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9522 if (DECL_IGNORED_P (fde
->decl
))
9524 if (!fde
->in_std_section
)
9525 size
+= 2 * DWARF2_ADDR_SIZE
;
9526 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9527 size
+= 2 * DWARF2_ADDR_SIZE
;
9531 /* Count the two zero words used to terminated the address range table. */
9532 size
+= 2 * DWARF2_ADDR_SIZE
;
9536 /* Select the encoding of an attribute value. */
9538 static enum dwarf_form
9539 value_format (dw_attr_node
*a
)
9541 switch (AT_class (a
))
9543 case dw_val_class_addr
:
9544 /* Only very few attributes allow DW_FORM_addr. */
9549 case DW_AT_entry_pc
:
9550 case DW_AT_trampoline
:
9551 return (AT_index (a
) == NOT_INDEXED
9552 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9556 switch (DWARF2_ADDR_SIZE
)
9559 return DW_FORM_data1
;
9561 return DW_FORM_data2
;
9563 return DW_FORM_data4
;
9565 return DW_FORM_data8
;
9569 case dw_val_class_loc_list
:
9570 case dw_val_class_view_list
:
9571 if (dwarf_split_debug_info
9572 && dwarf_version
>= 5
9573 && AT_loc_list (a
)->num_assigned
)
9574 return DW_FORM_loclistx
;
9576 case dw_val_class_range_list
:
9577 /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9578 but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9579 care about sizes of .debug* sections in shared libraries and
9580 executables and don't take into account relocations that affect just
9581 relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9582 table in the .debug_rnglists section. */
9583 if (dwarf_split_debug_info
9584 && dwarf_version
>= 5
9585 && AT_class (a
) == dw_val_class_range_list
9587 && a
->dw_attr_val
.val_entry
!= RELOCATED_OFFSET
)
9588 return DW_FORM_rnglistx
;
9589 if (dwarf_version
>= 4)
9590 return DW_FORM_sec_offset
;
9592 case dw_val_class_vms_delta
:
9593 case dw_val_class_offset
:
9594 switch (DWARF_OFFSET_SIZE
)
9597 return DW_FORM_data4
;
9599 return DW_FORM_data8
;
9603 case dw_val_class_loc
:
9604 if (dwarf_version
>= 4)
9605 return DW_FORM_exprloc
;
9606 switch (constant_size (size_of_locs (AT_loc (a
))))
9609 return DW_FORM_block1
;
9611 return DW_FORM_block2
;
9613 return DW_FORM_block4
;
9617 case dw_val_class_const
:
9618 return DW_FORM_sdata
;
9619 case dw_val_class_unsigned_const
:
9620 switch (constant_size (AT_unsigned (a
)))
9623 return DW_FORM_data1
;
9625 return DW_FORM_data2
;
9627 /* In DWARF3 DW_AT_data_member_location with
9628 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
9629 constant, so we need to use DW_FORM_udata if we need
9630 a large constant. */
9631 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9632 return DW_FORM_udata
;
9633 return DW_FORM_data4
;
9635 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9636 return DW_FORM_udata
;
9637 return DW_FORM_data8
;
9641 case dw_val_class_const_implicit
:
9642 case dw_val_class_unsigned_const_implicit
:
9643 case dw_val_class_file_implicit
:
9644 return DW_FORM_implicit_const
;
9645 case dw_val_class_const_double
:
9646 switch (HOST_BITS_PER_WIDE_INT
)
9649 return DW_FORM_data2
;
9651 return DW_FORM_data4
;
9653 return DW_FORM_data8
;
9655 if (dwarf_version
>= 5)
9656 return DW_FORM_data16
;
9659 return DW_FORM_block1
;
9661 case dw_val_class_wide_int
:
9662 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
9665 return DW_FORM_data1
;
9667 return DW_FORM_data2
;
9669 return DW_FORM_data4
;
9671 return DW_FORM_data8
;
9673 if (dwarf_version
>= 5)
9674 return DW_FORM_data16
;
9677 return DW_FORM_block1
;
9679 case dw_val_class_vec
:
9680 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
9681 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
9684 return DW_FORM_block1
;
9686 return DW_FORM_block2
;
9688 return DW_FORM_block4
;
9692 case dw_val_class_flag
:
9693 if (dwarf_version
>= 4)
9695 /* Currently all add_AT_flag calls pass in 1 as last argument,
9696 so DW_FORM_flag_present can be used. If that ever changes,
9697 we'll need to use DW_FORM_flag and have some optimization
9698 in build_abbrev_table that will change those to
9699 DW_FORM_flag_present if it is set to 1 in all DIEs using
9700 the same abbrev entry. */
9701 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9702 return DW_FORM_flag_present
;
9704 return DW_FORM_flag
;
9705 case dw_val_class_die_ref
:
9706 if (AT_ref_external (a
))
9707 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
9710 case dw_val_class_fde_ref
:
9711 return DW_FORM_data
;
9712 case dw_val_class_lbl_id
:
9713 return (AT_index (a
) == NOT_INDEXED
9714 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9715 case dw_val_class_lineptr
:
9716 case dw_val_class_macptr
:
9717 case dw_val_class_loclistsptr
:
9718 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
9719 case dw_val_class_str
:
9720 return AT_string_form (a
);
9721 case dw_val_class_file
:
9722 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
9725 return DW_FORM_data1
;
9727 return DW_FORM_data2
;
9729 return DW_FORM_data4
;
9734 case dw_val_class_data8
:
9735 return DW_FORM_data8
;
9737 case dw_val_class_high_pc
:
9738 switch (DWARF2_ADDR_SIZE
)
9741 return DW_FORM_data1
;
9743 return DW_FORM_data2
;
9745 return DW_FORM_data4
;
9747 return DW_FORM_data8
;
9752 case dw_val_class_discr_value
:
9753 return (a
->dw_attr_val
.v
.val_discr_value
.pos
9756 case dw_val_class_discr_list
:
9757 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
9760 return DW_FORM_block1
;
9762 return DW_FORM_block2
;
9764 return DW_FORM_block4
;
9774 /* Output the encoding of an attribute value. */
9777 output_value_format (dw_attr_node
*a
)
9779 enum dwarf_form form
= value_format (a
);
9781 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
9784 /* Given a die and id, produce the appropriate abbreviations. */
9787 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
9790 dw_attr_node
*a_attr
;
9792 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
9793 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
9794 dwarf_tag_name (abbrev
->die_tag
));
9796 if (abbrev
->die_child
!= NULL
)
9797 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
9799 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
9801 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
9803 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
9804 dwarf_attr_name (a_attr
->dw_attr
));
9805 output_value_format (a_attr
);
9806 if (value_format (a_attr
) == DW_FORM_implicit_const
)
9808 if (AT_class (a_attr
) == dw_val_class_file_implicit
)
9810 int f
= maybe_emit_file (a_attr
->dw_attr_val
.v
.val_file
);
9811 const char *filename
= a_attr
->dw_attr_val
.v
.val_file
->filename
;
9812 dw2_asm_output_data_sleb128 (f
, "(%s)", filename
);
9815 dw2_asm_output_data_sleb128 (a_attr
->dw_attr_val
.v
.val_int
, NULL
);
9819 dw2_asm_output_data (1, 0, NULL
);
9820 dw2_asm_output_data (1, 0, NULL
);
9824 /* Output the .debug_abbrev section which defines the DIE abbreviation
9828 output_abbrev_section (void)
9830 unsigned int abbrev_id
;
9833 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
9835 output_die_abbrevs (abbrev_id
, abbrev
);
9837 /* Terminate the table. */
9838 dw2_asm_output_data (1, 0, NULL
);
9841 /* Return a new location list, given the begin and end range, and the
9844 static inline dw_loc_list_ref
9845 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, var_loc_view vbegin
,
9846 const char *end
, var_loc_view vend
,
9847 const char *section
)
9849 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
9851 retlist
->begin
= begin
;
9852 retlist
->begin_entry
= NULL
;
9854 retlist
->expr
= expr
;
9855 retlist
->section
= section
;
9856 retlist
->vbegin
= vbegin
;
9857 retlist
->vend
= vend
;
9862 /* Return true iff there's any nonzero view number in the loc list. */
9865 loc_list_has_views (dw_loc_list_ref list
)
9867 if (!debug_variable_location_views
)
9870 for (dw_loc_list_ref loc
= list
;
9871 loc
!= NULL
; loc
= loc
->dw_loc_next
)
9872 if (!ZERO_VIEW_P (loc
->vbegin
) || !ZERO_VIEW_P (loc
->vend
))
9878 /* Generate a new internal symbol for this location list node, if it
9879 hasn't got one yet. */
9882 gen_llsym (dw_loc_list_ref list
)
9884 gcc_assert (!list
->ll_symbol
);
9885 list
->ll_symbol
= gen_internal_sym ("LLST");
9887 if (!loc_list_has_views (list
))
9890 if (dwarf2out_locviews_in_attribute ())
9892 /* Use the same label_num for the view list. */
9894 list
->vl_symbol
= gen_internal_sym ("LVUS");
9897 list
->vl_symbol
= list
->ll_symbol
;
9900 /* Generate a symbol for the list, but only if we really want to emit
9904 maybe_gen_llsym (dw_loc_list_ref list
)
9906 if (!list
|| (!list
->dw_loc_next
&& !loc_list_has_views (list
)))
9912 /* Determine whether or not to skip loc_list entry CURR. If we're not
9913 to skip it, and SIZEP is non-null, store the size of CURR->expr's
9914 representation in *SIZEP. */
9917 skip_loc_list_entry (dw_loc_list_ref curr
, unsigned long *sizep
= 0)
9919 /* Don't output an entry that starts and ends at the same address. */
9920 if (strcmp (curr
->begin
, curr
->end
) == 0
9921 && curr
->vbegin
== curr
->vend
&& !curr
->force
)
9924 unsigned long size
= size_of_locs (curr
->expr
);
9926 /* If the expression is too large, drop it on the floor. We could
9927 perhaps put it into DW_TAG_dwarf_procedure and refer to that
9928 in the expression, but >= 64KB expressions for a single value
9929 in a single range are unlikely very useful. */
9930 if (dwarf_version
< 5 && size
> 0xffff)
9939 /* Output a view pair loclist entry for CURR, if it requires one. */
9942 dwarf2out_maybe_output_loclist_view_pair (dw_loc_list_ref curr
)
9944 if (!dwarf2out_locviews_in_loclist ())
9947 if (ZERO_VIEW_P (curr
->vbegin
) && ZERO_VIEW_P (curr
->vend
))
9950 #ifdef DW_LLE_view_pair
9951 dw2_asm_output_data (1, DW_LLE_view_pair
, "DW_LLE_view_pair");
9953 # if DWARF2_ASM_VIEW_DEBUG_INFO
9954 if (ZERO_VIEW_P (curr
->vbegin
))
9955 dw2_asm_output_data_uleb128 (0, "Location view begin");
9958 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9959 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vbegin
);
9960 dw2_asm_output_symname_uleb128 (label
, "Location view begin");
9963 if (ZERO_VIEW_P (curr
->vend
))
9964 dw2_asm_output_data_uleb128 (0, "Location view end");
9967 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9968 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vend
);
9969 dw2_asm_output_symname_uleb128 (label
, "Location view end");
9971 # else /* !DWARF2_ASM_VIEW_DEBUG_INFO */
9972 dw2_asm_output_data_uleb128 (curr
->vbegin
, "Location view begin");
9973 dw2_asm_output_data_uleb128 (curr
->vend
, "Location view end");
9974 # endif /* DWARF2_ASM_VIEW_DEBUG_INFO */
9975 #endif /* DW_LLE_view_pair */
9980 /* Output the location list given to us. */
9983 output_loc_list (dw_loc_list_ref list_head
)
9985 int vcount
= 0, lcount
= 0;
9987 if (list_head
->emitted
)
9989 list_head
->emitted
= true;
9991 if (list_head
->vl_symbol
&& dwarf2out_locviews_in_attribute ())
9993 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->vl_symbol
);
9995 for (dw_loc_list_ref curr
= list_head
; curr
!= NULL
;
9996 curr
= curr
->dw_loc_next
)
9998 if (skip_loc_list_entry (curr
))
10003 /* ?? dwarf_split_debug_info? */
10004 #if DWARF2_ASM_VIEW_DEBUG_INFO
10005 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10007 if (!ZERO_VIEW_P (curr
->vbegin
))
10009 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vbegin
);
10010 dw2_asm_output_symname_uleb128 (label
,
10011 "View list begin (%s)",
10012 list_head
->vl_symbol
);
10015 dw2_asm_output_data_uleb128 (0,
10016 "View list begin (%s)",
10017 list_head
->vl_symbol
);
10019 if (!ZERO_VIEW_P (curr
->vend
))
10021 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vend
);
10022 dw2_asm_output_symname_uleb128 (label
,
10023 "View list end (%s)",
10024 list_head
->vl_symbol
);
10027 dw2_asm_output_data_uleb128 (0,
10028 "View list end (%s)",
10029 list_head
->vl_symbol
);
10030 #else /* !DWARF2_ASM_VIEW_DEBUG_INFO */
10031 dw2_asm_output_data_uleb128 (curr
->vbegin
,
10032 "View list begin (%s)",
10033 list_head
->vl_symbol
);
10034 dw2_asm_output_data_uleb128 (curr
->vend
,
10035 "View list end (%s)",
10036 list_head
->vl_symbol
);
10041 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
10043 const char *last_section
= NULL
;
10044 const char *base_label
= NULL
;
10046 /* Walk the location list, and output each range + expression. */
10047 for (dw_loc_list_ref curr
= list_head
; curr
!= NULL
;
10048 curr
= curr
->dw_loc_next
)
10050 unsigned long size
;
10052 /* Skip this entry? If we skip it here, we must skip it in the
10053 view list above as well. */
10054 if (skip_loc_list_entry (curr
, &size
))
10059 if (dwarf_version
>= 5)
10061 if (dwarf_split_debug_info
)
10063 dwarf2out_maybe_output_loclist_view_pair (curr
);
10064 /* For -gsplit-dwarf, emit DW_LLE_starx_length, which has
10065 uleb128 index into .debug_addr and uleb128 length. */
10066 dw2_asm_output_data (1, DW_LLE_startx_length
,
10067 "DW_LLE_startx_length (%s)",
10068 list_head
->ll_symbol
);
10069 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
10070 "Location list range start index "
10071 "(%s)", curr
->begin
);
10072 /* FIXME: This will ICE ifndef HAVE_AS_LEB128.
10073 For that case we probably need to emit DW_LLE_startx_endx,
10074 but we'd need 2 .debug_addr entries rather than just one. */
10075 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
10076 "Location list length (%s)",
10077 list_head
->ll_symbol
);
10079 else if (!have_multiple_function_sections
&& HAVE_AS_LEB128
)
10081 dwarf2out_maybe_output_loclist_view_pair (curr
);
10082 /* If all code is in .text section, the base address is
10083 already provided by the CU attributes. Use
10084 DW_LLE_offset_pair where both addresses are uleb128 encoded
10085 offsets against that base. */
10086 dw2_asm_output_data (1, DW_LLE_offset_pair
,
10087 "DW_LLE_offset_pair (%s)",
10088 list_head
->ll_symbol
);
10089 dw2_asm_output_delta_uleb128 (curr
->begin
, curr
->section
,
10090 "Location list begin address (%s)",
10091 list_head
->ll_symbol
);
10092 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->section
,
10093 "Location list end address (%s)",
10094 list_head
->ll_symbol
);
10096 else if (HAVE_AS_LEB128
)
10098 /* Otherwise, find out how many consecutive entries could share
10099 the same base entry. If just one, emit DW_LLE_start_length,
10100 otherwise emit DW_LLE_base_address for the base address
10101 followed by a series of DW_LLE_offset_pair. */
10102 if (last_section
== NULL
|| curr
->section
!= last_section
)
10104 dw_loc_list_ref curr2
;
10105 for (curr2
= curr
->dw_loc_next
; curr2
!= NULL
;
10106 curr2
= curr2
->dw_loc_next
)
10108 if (strcmp (curr2
->begin
, curr2
->end
) == 0
10113 if (curr2
== NULL
|| curr
->section
!= curr2
->section
)
10114 last_section
= NULL
;
10117 last_section
= curr
->section
;
10118 base_label
= curr
->begin
;
10119 dw2_asm_output_data (1, DW_LLE_base_address
,
10120 "DW_LLE_base_address (%s)",
10121 list_head
->ll_symbol
);
10122 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, base_label
,
10123 "Base address (%s)",
10124 list_head
->ll_symbol
);
10127 /* Only one entry with the same base address. Use
10128 DW_LLE_start_length with absolute address and uleb128
10130 if (last_section
== NULL
)
10132 dwarf2out_maybe_output_loclist_view_pair (curr
);
10133 dw2_asm_output_data (1, DW_LLE_start_length
,
10134 "DW_LLE_start_length (%s)",
10135 list_head
->ll_symbol
);
10136 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10137 "Location list begin address (%s)",
10138 list_head
->ll_symbol
);
10139 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
10140 "Location list length "
10141 "(%s)", list_head
->ll_symbol
);
10143 /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
10144 DW_LLE_base_address. */
10147 dwarf2out_maybe_output_loclist_view_pair (curr
);
10148 dw2_asm_output_data (1, DW_LLE_offset_pair
,
10149 "DW_LLE_offset_pair (%s)",
10150 list_head
->ll_symbol
);
10151 dw2_asm_output_delta_uleb128 (curr
->begin
, base_label
,
10152 "Location list begin address "
10153 "(%s)", list_head
->ll_symbol
);
10154 dw2_asm_output_delta_uleb128 (curr
->end
, base_label
,
10155 "Location list end address "
10156 "(%s)", list_head
->ll_symbol
);
10159 /* The assembler does not support .uleb128 directive. Emit
10160 DW_LLE_start_end with a pair of absolute addresses. */
10163 dwarf2out_maybe_output_loclist_view_pair (curr
);
10164 dw2_asm_output_data (1, DW_LLE_start_end
,
10165 "DW_LLE_start_end (%s)",
10166 list_head
->ll_symbol
);
10167 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10168 "Location list begin address (%s)",
10169 list_head
->ll_symbol
);
10170 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
10171 "Location list end address (%s)",
10172 list_head
->ll_symbol
);
10175 else if (dwarf_split_debug_info
)
10177 /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
10178 and 4 byte length. */
10179 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
10180 "Location list start/length entry (%s)",
10181 list_head
->ll_symbol
);
10182 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
10183 "Location list range start index (%s)",
10185 /* The length field is 4 bytes. If we ever need to support
10186 an 8-byte length, we can add a new DW_LLE code or fall back
10187 to DW_LLE_GNU_start_end_entry. */
10188 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
10189 "Location list range length (%s)",
10190 list_head
->ll_symbol
);
10192 else if (!have_multiple_function_sections
)
10194 /* Pair of relative addresses against start of text section. */
10195 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
10196 "Location list begin address (%s)",
10197 list_head
->ll_symbol
);
10198 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
10199 "Location list end address (%s)",
10200 list_head
->ll_symbol
);
10204 /* Pair of absolute addresses. */
10205 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10206 "Location list begin address (%s)",
10207 list_head
->ll_symbol
);
10208 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
10209 "Location list end address (%s)",
10210 list_head
->ll_symbol
);
10213 /* Output the block length for this list of location operations. */
10214 if (dwarf_version
>= 5)
10215 dw2_asm_output_data_uleb128 (size
, "Location expression size");
10218 gcc_assert (size
<= 0xffff);
10219 dw2_asm_output_data (2, size
, "Location expression size");
10222 output_loc_sequence (curr
->expr
, -1);
10225 /* And finally list termination. */
10226 if (dwarf_version
>= 5)
10227 dw2_asm_output_data (1, DW_LLE_end_of_list
,
10228 "DW_LLE_end_of_list (%s)", list_head
->ll_symbol
);
10229 else if (dwarf_split_debug_info
)
10230 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
10231 "Location list terminator (%s)",
10232 list_head
->ll_symbol
);
10235 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
10236 "Location list terminator begin (%s)",
10237 list_head
->ll_symbol
);
10238 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
10239 "Location list terminator end (%s)",
10240 list_head
->ll_symbol
);
10243 gcc_assert (!list_head
->vl_symbol
10244 || vcount
== lcount
* (dwarf2out_locviews_in_attribute () ? 1 : 0));
10247 /* Output a range_list offset into the .debug_ranges or .debug_rnglists
10248 section. Emit a relocated reference if val_entry is NULL, otherwise,
10249 emit an indirect reference. */
10252 output_range_list_offset (dw_attr_node
*a
)
10254 const char *name
= dwarf_attr_name (a
->dw_attr
);
10256 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
10258 if (dwarf_version
>= 5)
10260 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
10261 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, r
->label
,
10262 debug_ranges_section
, "%s", name
);
10266 char *p
= strchr (ranges_section_label
, '\0');
10267 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
10268 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
);
10269 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
10270 debug_ranges_section
, "%s", name
);
10274 else if (dwarf_version
>= 5)
10276 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
10277 gcc_assert (rnglist_idx
);
10278 dw2_asm_output_data_uleb128 (r
->idx
, "%s", name
);
10281 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10282 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
,
10283 "%s (offset from %s)", name
, ranges_section_label
);
10286 /* Output the offset into the debug_loc section. */
10289 output_loc_list_offset (dw_attr_node
*a
)
10291 char *sym
= AT_loc_list (a
)->ll_symbol
;
10294 if (!dwarf_split_debug_info
)
10295 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
10296 "%s", dwarf_attr_name (a
->dw_attr
));
10297 else if (dwarf_version
>= 5)
10299 gcc_assert (AT_loc_list (a
)->num_assigned
);
10300 dw2_asm_output_data_uleb128 (AT_loc_list (a
)->hash
, "%s (%s)",
10301 dwarf_attr_name (a
->dw_attr
),
10305 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
10306 "%s", dwarf_attr_name (a
->dw_attr
));
10309 /* Output the offset into the debug_loc section. */
10312 output_view_list_offset (dw_attr_node
*a
)
10314 char *sym
= (*AT_loc_list_ptr (a
))->vl_symbol
;
10317 if (dwarf_split_debug_info
)
10318 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
10319 "%s", dwarf_attr_name (a
->dw_attr
));
10321 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
10322 "%s", dwarf_attr_name (a
->dw_attr
));
10325 /* Output an attribute's index or value appropriately. */
10328 output_attr_index_or_value (dw_attr_node
*a
)
10330 const char *name
= dwarf_attr_name (a
->dw_attr
);
10332 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
10334 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
10337 switch (AT_class (a
))
10339 case dw_val_class_addr
:
10340 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
10342 case dw_val_class_high_pc
:
10343 case dw_val_class_lbl_id
:
10344 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
10347 gcc_unreachable ();
10351 /* Output a type signature. */
10354 output_signature (const char *sig
, const char *name
)
10358 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10359 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
10362 /* Output a discriminant value. */
10365 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
10367 if (discr_value
->pos
)
10368 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
10370 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
10373 /* Output the DIE and its attributes. Called recursively to generate
10374 the definitions of each child DIE. */
10377 output_die (dw_die_ref die
)
10381 unsigned long size
;
10384 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
10385 (unsigned long)die
->die_offset
,
10386 dwarf_tag_name (die
->die_tag
));
10388 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
10390 const char *name
= dwarf_attr_name (a
->dw_attr
);
10392 switch (AT_class (a
))
10394 case dw_val_class_addr
:
10395 output_attr_index_or_value (a
);
10398 case dw_val_class_offset
:
10399 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
10403 case dw_val_class_range_list
:
10404 output_range_list_offset (a
);
10407 case dw_val_class_loc
:
10408 size
= size_of_locs (AT_loc (a
));
10410 /* Output the block length for this list of location operations. */
10411 if (dwarf_version
>= 4)
10412 dw2_asm_output_data_uleb128 (size
, "%s", name
);
10414 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
10416 output_loc_sequence (AT_loc (a
), -1);
10419 case dw_val_class_const
:
10420 /* ??? It would be slightly more efficient to use a scheme like is
10421 used for unsigned constants below, but gdb 4.x does not sign
10422 extend. Gdb 5.x does sign extend. */
10423 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
10426 case dw_val_class_unsigned_const
:
10428 int csize
= constant_size (AT_unsigned (a
));
10429 if (dwarf_version
== 3
10430 && a
->dw_attr
== DW_AT_data_member_location
10432 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
10434 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
10438 case dw_val_class_const_implicit
:
10439 if (flag_debug_asm
)
10440 fprintf (asm_out_file
, "\t\t\t%s %s ("
10441 HOST_WIDE_INT_PRINT_DEC
")\n",
10442 ASM_COMMENT_START
, name
, AT_int (a
));
10445 case dw_val_class_unsigned_const_implicit
:
10446 if (flag_debug_asm
)
10447 fprintf (asm_out_file
, "\t\t\t%s %s ("
10448 HOST_WIDE_INT_PRINT_HEX
")\n",
10449 ASM_COMMENT_START
, name
, AT_unsigned (a
));
10452 case dw_val_class_const_double
:
10454 unsigned HOST_WIDE_INT first
, second
;
10456 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
10457 dw2_asm_output_data (1,
10458 HOST_BITS_PER_DOUBLE_INT
10459 / HOST_BITS_PER_CHAR
,
10462 if (WORDS_BIG_ENDIAN
)
10464 first
= a
->dw_attr_val
.v
.val_double
.high
;
10465 second
= a
->dw_attr_val
.v
.val_double
.low
;
10469 first
= a
->dw_attr_val
.v
.val_double
.low
;
10470 second
= a
->dw_attr_val
.v
.val_double
.high
;
10473 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10474 first
, "%s", name
);
10475 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10480 case dw_val_class_wide_int
:
10483 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
10484 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10485 if (len
* HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
10486 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
)
10489 if (WORDS_BIG_ENDIAN
)
10490 for (i
= len
- 1; i
>= 0; --i
)
10492 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10497 for (i
= 0; i
< len
; ++i
)
10499 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10506 case dw_val_class_vec
:
10508 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
10509 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
10513 dw2_asm_output_data (constant_size (len
* elt_size
),
10514 len
* elt_size
, "%s", name
);
10515 if (elt_size
> sizeof (HOST_WIDE_INT
))
10520 for (i
= 0, p
= (unsigned char *) a
->dw_attr_val
.v
.val_vec
.array
;
10522 i
++, p
+= elt_size
)
10523 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
10524 "fp or vector constant word %u", i
);
10528 case dw_val_class_flag
:
10529 if (dwarf_version
>= 4)
10531 /* Currently all add_AT_flag calls pass in 1 as last argument,
10532 so DW_FORM_flag_present can be used. If that ever changes,
10533 we'll need to use DW_FORM_flag and have some optimization
10534 in build_abbrev_table that will change those to
10535 DW_FORM_flag_present if it is set to 1 in all DIEs using
10536 the same abbrev entry. */
10537 gcc_assert (AT_flag (a
) == 1);
10538 if (flag_debug_asm
)
10539 fprintf (asm_out_file
, "\t\t\t%s %s\n",
10540 ASM_COMMENT_START
, name
);
10543 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
10546 case dw_val_class_loc_list
:
10547 output_loc_list_offset (a
);
10550 case dw_val_class_view_list
:
10551 output_view_list_offset (a
);
10554 case dw_val_class_die_ref
:
10555 if (AT_ref_external (a
))
10557 if (AT_ref (a
)->comdat_type_p
)
10559 comdat_type_node
*type_node
10560 = AT_ref (a
)->die_id
.die_type_node
;
10562 gcc_assert (type_node
);
10563 output_signature (type_node
->signature
, name
);
10567 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
10571 /* In DWARF2, DW_FORM_ref_addr is sized by target address
10572 length, whereas in DWARF3 it's always sized as an
10574 if (dwarf_version
== 2)
10575 size
= DWARF2_ADDR_SIZE
;
10577 size
= DWARF_OFFSET_SIZE
;
10578 /* ??? We cannot unconditionally output die_offset if
10579 non-zero - others might create references to those
10581 And we do not clear its DIE offset after outputting it
10582 (and the label refers to the actual DIEs, not the
10583 DWARF CU unit header which is when using label + offset
10584 would be the correct thing to do).
10585 ??? This is the reason for the with_offset flag. */
10586 if (AT_ref (a
)->with_offset
)
10587 dw2_asm_output_offset (size
, sym
, AT_ref (a
)->die_offset
,
10588 debug_info_section
, "%s", name
);
10590 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
10596 gcc_assert (AT_ref (a
)->die_offset
);
10597 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
10602 case dw_val_class_fde_ref
:
10604 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
10606 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
10607 a
->dw_attr_val
.v
.val_fde_index
* 2);
10608 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
10613 case dw_val_class_vms_delta
:
10614 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
10615 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
10616 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10619 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
10620 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10625 case dw_val_class_lbl_id
:
10626 output_attr_index_or_value (a
);
10629 case dw_val_class_lineptr
:
10630 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10631 debug_line_section
, "%s", name
);
10634 case dw_val_class_macptr
:
10635 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10636 debug_macinfo_section
, "%s", name
);
10639 case dw_val_class_loclistsptr
:
10640 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10641 debug_loc_section
, "%s", name
);
10644 case dw_val_class_str
:
10645 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
10646 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10647 a
->dw_attr_val
.v
.val_str
->label
,
10649 "%s: \"%s\"", name
, AT_string (a
));
10650 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_line_strp
)
10651 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10652 a
->dw_attr_val
.v
.val_str
->label
,
10653 debug_line_str_section
,
10654 "%s: \"%s\"", name
, AT_string (a
));
10655 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
10656 dw2_asm_output_data_uleb128 (AT_index (a
),
10657 "%s: \"%s\"", name
, AT_string (a
));
10659 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
10662 case dw_val_class_file
:
10664 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
10666 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
10667 a
->dw_attr_val
.v
.val_file
->filename
);
10671 case dw_val_class_file_implicit
:
10672 if (flag_debug_asm
)
10673 fprintf (asm_out_file
, "\t\t\t%s %s (%d, %s)\n",
10674 ASM_COMMENT_START
, name
,
10675 maybe_emit_file (a
->dw_attr_val
.v
.val_file
),
10676 a
->dw_attr_val
.v
.val_file
->filename
);
10679 case dw_val_class_data8
:
10683 for (i
= 0; i
< 8; i
++)
10684 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
10685 i
== 0 ? "%s" : NULL
, name
);
10689 case dw_val_class_high_pc
:
10690 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
10691 get_AT_low_pc (die
), "DW_AT_high_pc");
10694 case dw_val_class_discr_value
:
10695 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
10698 case dw_val_class_discr_list
:
10700 dw_discr_list_ref list
= AT_discr_list (a
);
10701 const int size
= size_of_discr_list (list
);
10703 /* This is a block, so output its length first. */
10704 dw2_asm_output_data (constant_size (size
), size
,
10705 "%s: block size", name
);
10707 for (; list
!= NULL
; list
= list
->dw_discr_next
)
10709 /* One byte for the discriminant value descriptor, and then as
10710 many LEB128 numbers as required. */
10711 if (list
->dw_discr_range
)
10712 dw2_asm_output_data (1, DW_DSC_range
,
10713 "%s: DW_DSC_range", name
);
10715 dw2_asm_output_data (1, DW_DSC_label
,
10716 "%s: DW_DSC_label", name
);
10718 output_discr_value (&list
->dw_discr_lower_bound
, name
);
10719 if (list
->dw_discr_range
)
10720 output_discr_value (&list
->dw_discr_upper_bound
, name
);
10726 gcc_unreachable ();
10730 FOR_EACH_CHILD (die
, c
, output_die (c
));
10732 /* Add null byte to terminate sibling list. */
10733 if (die
->die_child
!= NULL
)
10734 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
10735 (unsigned long) die
->die_offset
);
10738 /* Output the dwarf version number. */
10741 output_dwarf_version ()
10743 /* ??? For now, if -gdwarf-6 is specified, we output version 5 with
10744 views in loclist. That will change eventually. */
10745 if (dwarf_version
== 6)
10751 "-gdwarf-6 is output as version 5 with incompatibilities");
10754 dw2_asm_output_data (2, 5, "DWARF version number");
10757 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10760 /* Output the compilation unit that appears at the beginning of the
10761 .debug_info section, and precedes the DIE descriptions. */
10764 output_compilation_unit_header (enum dwarf_unit_type ut
)
10766 if (!XCOFF_DEBUGGING_INFO
)
10768 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10769 dw2_asm_output_data (4, 0xffffffff,
10770 "Initial length escape value indicating 64-bit DWARF extension");
10771 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10772 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
10773 "Length of Compilation Unit Info");
10776 output_dwarf_version ();
10777 if (dwarf_version
>= 5)
10782 case DW_UT_compile
: name
= "DW_UT_compile"; break;
10783 case DW_UT_type
: name
= "DW_UT_type"; break;
10784 case DW_UT_split_compile
: name
= "DW_UT_split_compile"; break;
10785 case DW_UT_split_type
: name
= "DW_UT_split_type"; break;
10786 default: gcc_unreachable ();
10788 dw2_asm_output_data (1, ut
, "%s", name
);
10789 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10791 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
10792 debug_abbrev_section
,
10793 "Offset Into Abbrev. Section");
10794 if (dwarf_version
< 5)
10795 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10798 /* Output the compilation unit DIE and its children. */
10801 output_comp_unit (dw_die_ref die
, int output_if_empty
,
10802 const unsigned char *dwo_id
)
10804 const char *secname
, *oldsym
;
10807 /* Unless we are outputting main CU, we may throw away empty ones. */
10808 if (!output_if_empty
&& die
->die_child
== NULL
)
10811 /* Even if there are no children of this DIE, we must output the information
10812 about the compilation unit. Otherwise, on an empty translation unit, we
10813 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
10814 will then complain when examining the file. First mark all the DIEs in
10815 this CU so we know which get local refs. */
10818 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
10820 /* For now, optimize only the main CU, in order to optimize the rest
10821 we'd need to see all of them earlier. Leave the rest for post-linking
10823 if (die
== comp_unit_die ())
10824 abbrev_opt_start
= vec_safe_length (abbrev_die_table
);
10826 build_abbrev_table (die
, extern_map
);
10828 optimize_abbrev_table ();
10832 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10833 next_die_offset
= (dwo_id
10834 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10835 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
10836 calc_die_sizes (die
);
10838 oldsym
= die
->die_id
.die_symbol
;
10839 if (oldsym
&& die
->comdat_type_p
)
10841 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
10843 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
10845 die
->die_id
.die_symbol
= NULL
;
10846 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10850 switch_to_section (debug_info_section
);
10851 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
10852 info_section_emitted
= true;
10855 /* For LTO cross unit DIE refs we want a symbol on the start of the
10856 debuginfo section, not on the CU DIE. */
10857 if ((flag_generate_lto
|| flag_generate_offload
) && oldsym
)
10859 /* ??? No way to get visibility assembled without a decl. */
10860 tree decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
,
10861 get_identifier (oldsym
), char_type_node
);
10862 TREE_PUBLIC (decl
) = true;
10863 TREE_STATIC (decl
) = true;
10864 DECL_ARTIFICIAL (decl
) = true;
10865 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
10866 DECL_VISIBILITY_SPECIFIED (decl
) = true;
10867 targetm
.asm_out
.assemble_visibility (decl
, VISIBILITY_HIDDEN
);
10868 #ifdef ASM_WEAKEN_LABEL
10869 /* We prefer a .weak because that handles duplicates from duplicate
10870 archive members in a graceful way. */
10871 ASM_WEAKEN_LABEL (asm_out_file
, oldsym
);
10873 targetm
.asm_out
.globalize_label (asm_out_file
, oldsym
);
10875 ASM_OUTPUT_LABEL (asm_out_file
, oldsym
);
10878 /* Output debugging information. */
10879 output_compilation_unit_header (dwo_id
10880 ? DW_UT_split_compile
: DW_UT_compile
);
10881 if (dwarf_version
>= 5)
10883 if (dwo_id
!= NULL
)
10884 for (int i
= 0; i
< 8; i
++)
10885 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10889 /* Leave the marks on the main CU, so we can check them in
10890 output_pubnames. */
10894 die
->die_id
.die_symbol
= oldsym
;
10898 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
10899 and .debug_pubtypes. This is configured per-target, but can be
10900 overridden by the -gpubnames or -gno-pubnames options. */
10903 want_pubnames (void)
10905 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10907 if (debug_generate_pub_sections
!= -1)
10908 return debug_generate_pub_sections
;
10909 return targetm
.want_debug_pub_sections
;
10912 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
10915 add_AT_pubnames (dw_die_ref die
)
10917 if (want_pubnames ())
10918 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
10921 /* Add a string attribute value to a skeleton DIE. */
10924 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
10928 struct indirect_string_node
*node
;
10930 if (! skeleton_debug_str_hash
)
10931 skeleton_debug_str_hash
10932 = hash_table
<indirect_string_hasher
>::create_ggc (10);
10934 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
10935 find_string_form (node
);
10936 if (node
->form
== DW_FORM_GNU_str_index
)
10937 node
->form
= DW_FORM_strp
;
10939 attr
.dw_attr
= attr_kind
;
10940 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
10941 attr
.dw_attr_val
.val_entry
= NULL
;
10942 attr
.dw_attr_val
.v
.val_str
= node
;
10943 add_dwarf_attr (die
, &attr
);
10946 /* Helper function to generate top-level dies for skeleton debug_info and
10950 add_top_level_skeleton_die_attrs (dw_die_ref die
)
10952 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
10953 const char *comp_dir
= comp_dir_string ();
10955 add_skeleton_AT_string (die
, dwarf_AT (DW_AT_dwo_name
), dwo_file_name
);
10956 if (comp_dir
!= NULL
)
10957 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
10958 add_AT_pubnames (die
);
10959 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
10962 /* Output skeleton debug sections that point to the dwo file. */
10965 output_skeleton_debug_sections (dw_die_ref comp_unit
,
10966 const unsigned char *dwo_id
)
10968 /* These attributes will be found in the full debug_info section. */
10969 remove_AT (comp_unit
, DW_AT_producer
);
10970 remove_AT (comp_unit
, DW_AT_language
);
10972 switch_to_section (debug_skeleton_info_section
);
10973 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
10975 /* Produce the skeleton compilation-unit header. This one differs enough from
10976 a normal CU header that it's better not to call output_compilation_unit
10978 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10979 dw2_asm_output_data (4, 0xffffffff,
10980 "Initial length escape value indicating 64-bit "
10981 "DWARF extension");
10983 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10984 DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10985 - DWARF_INITIAL_LENGTH_SIZE
10986 + size_of_die (comp_unit
),
10987 "Length of Compilation Unit Info");
10988 output_dwarf_version ();
10989 if (dwarf_version
>= 5)
10991 dw2_asm_output_data (1, DW_UT_skeleton
, "DW_UT_skeleton");
10992 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10994 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
10995 debug_skeleton_abbrev_section
,
10996 "Offset Into Abbrev. Section");
10997 if (dwarf_version
< 5)
10998 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11000 for (int i
= 0; i
< 8; i
++)
11001 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
11003 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
11004 output_die (comp_unit
);
11006 /* Build the skeleton debug_abbrev section. */
11007 switch_to_section (debug_skeleton_abbrev_section
);
11008 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
11010 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
11012 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
11015 /* Output a comdat type unit DIE and its children. */
11018 output_comdat_type_unit (comdat_type_node
*node
)
11020 const char *secname
;
11023 #if defined (OBJECT_FORMAT_ELF)
11027 /* First mark all the DIEs in this CU so we know which get local refs. */
11028 mark_dies (node
->root_die
);
11030 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
11032 build_abbrev_table (node
->root_die
, extern_map
);
11037 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11038 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
11039 calc_die_sizes (node
->root_die
);
11041 #if defined (OBJECT_FORMAT_ELF)
11042 if (dwarf_version
>= 5)
11044 if (!dwarf_split_debug_info
)
11045 secname
= ".debug_info";
11047 secname
= ".debug_info.dwo";
11049 else if (!dwarf_split_debug_info
)
11050 secname
= ".debug_types";
11052 secname
= ".debug_types.dwo";
11054 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11055 sprintf (tmp
, dwarf_version
>= 5 ? "wi." : "wt.");
11056 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11057 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11058 comdat_key
= get_identifier (tmp
);
11059 targetm
.asm_out
.named_section (secname
,
11060 SECTION_DEBUG
| SECTION_LINKONCE
,
11063 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11064 sprintf (tmp
, (dwarf_version
>= 5
11065 ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
11066 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11067 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11069 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11072 /* Output debugging information. */
11073 output_compilation_unit_header (dwarf_split_debug_info
11074 ? DW_UT_split_type
: DW_UT_type
);
11075 output_signature (node
->signature
, "Type Signature");
11076 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
11077 "Offset to Type DIE");
11078 output_die (node
->root_die
);
11080 unmark_dies (node
->root_die
);
11083 /* Return the DWARF2/3 pubname associated with a decl. */
11085 static const char *
11086 dwarf2_name (tree decl
, int scope
)
11088 if (DECL_NAMELESS (decl
))
11090 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
11093 /* Add a new entry to .debug_pubnames if appropriate. */
11096 add_pubname_string (const char *str
, dw_die_ref die
)
11101 e
.name
= xstrdup (str
);
11102 vec_safe_push (pubname_table
, e
);
11106 add_pubname (tree decl
, dw_die_ref die
)
11108 if (!want_pubnames ())
11111 /* Don't add items to the table when we expect that the consumer will have
11112 just read the enclosing die. For example, if the consumer is looking at a
11113 class_member, it will either be inside the class already, or will have just
11114 looked up the class to find the member. Either way, searching the class is
11115 faster than searching the index. */
11116 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
11117 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
11119 const char *name
= dwarf2_name (decl
, 1);
11122 add_pubname_string (name
, die
);
11126 /* Add an enumerator to the pubnames section. */
11129 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
11133 gcc_assert (scope_name
);
11134 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
11136 vec_safe_push (pubname_table
, e
);
11139 /* Add a new entry to .debug_pubtypes if appropriate. */
11142 add_pubtype (tree decl
, dw_die_ref die
)
11146 if (!want_pubnames ())
11149 if ((TREE_PUBLIC (decl
)
11150 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
11151 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
11154 const char *scope_name
= "";
11155 const char *sep
= is_cxx () ? "::" : ".";
11158 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
11159 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
11161 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
11162 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
11163 scope_name
= concat (scope_name
, sep
, NULL
);
11169 name
= type_tag (decl
);
11171 name
= lang_hooks
.dwarf_name (decl
, 1);
11173 /* If we don't have a name for the type, there's no point in adding
11174 it to the table. */
11175 if (name
!= NULL
&& name
[0] != '\0')
11178 e
.name
= concat (scope_name
, name
, NULL
);
11179 vec_safe_push (pubtype_table
, e
);
11182 /* Although it might be more consistent to add the pubinfo for the
11183 enumerators as their dies are created, they should only be added if the
11184 enum type meets the criteria above. So rather than re-check the parent
11185 enum type whenever an enumerator die is created, just output them all
11186 here. This isn't protected by the name conditional because anonymous
11187 enums don't have names. */
11188 if (die
->die_tag
== DW_TAG_enumeration_type
)
11192 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
11197 /* Output a single entry in the pubnames table. */
11200 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
11202 dw_die_ref die
= entry
->die
;
11203 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
11205 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
11207 if (debug_generate_pub_sections
== 2)
11209 /* This logic follows gdb's method for determining the value of the flag
11211 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
11212 switch (die
->die_tag
)
11214 case DW_TAG_typedef
:
11215 case DW_TAG_base_type
:
11216 case DW_TAG_subrange_type
:
11217 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
11218 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
11220 case DW_TAG_enumerator
:
11221 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11222 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
11224 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
11226 case DW_TAG_subprogram
:
11227 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11228 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
11230 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
11232 case DW_TAG_constant
:
11233 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11234 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
11235 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
11237 case DW_TAG_variable
:
11238 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11239 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
11240 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
11242 case DW_TAG_namespace
:
11243 case DW_TAG_imported_declaration
:
11244 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
11246 case DW_TAG_class_type
:
11247 case DW_TAG_interface_type
:
11248 case DW_TAG_structure_type
:
11249 case DW_TAG_union_type
:
11250 case DW_TAG_enumeration_type
:
11251 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
11253 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
11256 /* An unusual tag. Leave the flag-byte empty. */
11259 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
11260 "GDB-index flags");
11263 dw2_asm_output_nstring (entry
->name
, -1, "external name");
11267 /* Output the public names table used to speed up access to externally
11268 visible names; or the public types table used to find type definitions. */
11271 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
11274 unsigned long pubnames_length
= size_of_pubnames (names
);
11275 pubname_entry
*pub
;
11277 if (!XCOFF_DEBUGGING_INFO
)
11279 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11280 dw2_asm_output_data (4, 0xffffffff,
11281 "Initial length escape value indicating 64-bit DWARF extension");
11282 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
11283 "Pub Info Length");
11286 /* Version number for pubnames/pubtypes is independent of dwarf version. */
11287 dw2_asm_output_data (2, 2, "DWARF pubnames/pubtypes version");
11289 if (dwarf_split_debug_info
)
11290 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
11291 debug_skeleton_info_section
,
11292 "Offset of Compilation Unit Info");
11294 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
11295 debug_info_section
,
11296 "Offset of Compilation Unit Info");
11297 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
11298 "Compilation Unit Length");
11300 FOR_EACH_VEC_ELT (*names
, i
, pub
)
11302 if (include_pubname_in_output (names
, pub
))
11304 dw_offset die_offset
= pub
->die
->die_offset
;
11306 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11307 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
11308 gcc_assert (pub
->die
->die_mark
);
11310 /* If we're putting types in their own .debug_types sections,
11311 the .debug_pubtypes table will still point to the compile
11312 unit (not the type unit), so we want to use the offset of
11313 the skeleton DIE (if there is one). */
11314 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
11316 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
11318 if (type_node
!= NULL
)
11319 die_offset
= (type_node
->skeleton_die
!= NULL
11320 ? type_node
->skeleton_die
->die_offset
11321 : comp_unit_die ()->die_offset
);
11324 output_pubname (die_offset
, pub
);
11328 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
11331 /* Output public names and types tables if necessary. */
11334 output_pubtables (void)
11336 if (!want_pubnames () || !info_section_emitted
)
11339 switch_to_section (debug_pubnames_section
);
11340 output_pubnames (pubname_table
);
11341 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
11342 It shouldn't hurt to emit it always, since pure DWARF2 consumers
11343 simply won't look for the section. */
11344 switch_to_section (debug_pubtypes_section
);
11345 output_pubnames (pubtype_table
);
11349 /* Output the information that goes into the .debug_aranges table.
11350 Namely, define the beginning and ending address range of the
11351 text section generated for this compilation unit. */
11354 output_aranges (void)
11357 unsigned long aranges_length
= size_of_aranges ();
11359 if (!XCOFF_DEBUGGING_INFO
)
11361 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11362 dw2_asm_output_data (4, 0xffffffff,
11363 "Initial length escape value indicating 64-bit DWARF extension");
11364 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
11365 "Length of Address Ranges Info");
11368 /* Version number for aranges is still 2, even up to DWARF5. */
11369 dw2_asm_output_data (2, 2, "DWARF aranges version");
11370 if (dwarf_split_debug_info
)
11371 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
11372 debug_skeleton_info_section
,
11373 "Offset of Compilation Unit Info");
11375 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
11376 debug_info_section
,
11377 "Offset of Compilation Unit Info");
11378 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
11379 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11381 /* We need to align to twice the pointer size here. */
11382 if (DWARF_ARANGES_PAD_SIZE
)
11384 /* Pad using a 2 byte words so that padding is correct for any
11386 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11387 2 * DWARF2_ADDR_SIZE
);
11388 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
11389 dw2_asm_output_data (2, 0, NULL
);
11392 /* It is necessary not to output these entries if the sections were
11393 not used; if the sections were not used, the length will be 0 and
11394 the address may end up as 0 if the section is discarded by ld
11395 --gc-sections, leaving an invalid (0, 0) entry that can be
11396 confused with the terminator. */
11397 if (text_section_used
)
11399 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
11400 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
11401 text_section_label
, "Length");
11403 if (cold_text_section_used
)
11405 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
11407 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
11408 cold_text_section_label
, "Length");
11411 if (have_multiple_function_sections
)
11416 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
11418 if (DECL_IGNORED_P (fde
->decl
))
11420 if (!fde
->in_std_section
)
11422 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
11424 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
11425 fde
->dw_fde_begin
, "Length");
11427 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
11429 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
11431 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
11432 fde
->dw_fde_second_begin
, "Length");
11437 /* Output the terminator words. */
11438 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11439 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11442 /* Add a new entry to .debug_ranges. Return its index into
11443 ranges_table vector. */
11445 static unsigned int
11446 add_ranges_num (int num
, bool maybe_new_sec
)
11448 dw_ranges r
= { NULL
, num
, 0, maybe_new_sec
};
11449 vec_safe_push (ranges_table
, r
);
11450 return vec_safe_length (ranges_table
) - 1;
11453 /* Add a new entry to .debug_ranges corresponding to a block, or a
11454 range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
11455 this entry might be in a different section from previous range. */
11457 static unsigned int
11458 add_ranges (const_tree block
, bool maybe_new_sec
)
11460 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0, maybe_new_sec
);
11463 /* Note that (*rnglist_table)[offset] is either a head of a rnglist
11464 chain, or middle entry of a chain that will be directly referred to. */
11467 note_rnglist_head (unsigned int offset
)
11469 if (dwarf_version
< 5 || (*ranges_table
)[offset
].label
)
11471 (*ranges_table
)[offset
].label
= gen_internal_sym ("LLRL");
11474 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
11475 When using dwarf_split_debug_info, address attributes in dies destined
11476 for the final executable should be direct references--setting the
11477 parameter force_direct ensures this behavior. */
11480 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11481 bool *added
, bool force_direct
)
11483 unsigned int in_use
= vec_safe_length (ranges_by_label
);
11484 unsigned int offset
;
11485 dw_ranges_by_label rbl
= { begin
, end
};
11486 vec_safe_push (ranges_by_label
, rbl
);
11487 offset
= add_ranges_num (-(int)in_use
- 1, true);
11490 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
11492 note_rnglist_head (offset
);
11496 /* Emit .debug_ranges section. */
11499 output_ranges (void)
11502 static const char *const start_fmt
= "Offset %#x";
11503 const char *fmt
= start_fmt
;
11506 switch_to_section (debug_ranges_section
);
11507 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11508 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11510 int block_num
= r
->num
;
11514 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11515 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11517 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11518 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11520 /* If all code is in the text section, then the compilation
11521 unit base address defaults to DW_AT_low_pc, which is the
11522 base of the text section. */
11523 if (!have_multiple_function_sections
)
11525 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11526 text_section_label
,
11527 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11528 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11529 text_section_label
, NULL
);
11532 /* Otherwise, the compilation unit base address is zero,
11533 which allows us to use absolute addresses, and not worry
11534 about whether the target supports cross-section
11538 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11539 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11540 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11546 /* Negative block_num stands for an index into ranges_by_label. */
11547 else if (block_num
< 0)
11549 int lab_idx
= - block_num
- 1;
11551 if (!have_multiple_function_sections
)
11553 gcc_unreachable ();
11555 /* If we ever use add_ranges_by_labels () for a single
11556 function section, all we have to do is to take out
11557 the #if 0 above. */
11558 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11559 (*ranges_by_label
)[lab_idx
].begin
,
11560 text_section_label
,
11561 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11562 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11563 (*ranges_by_label
)[lab_idx
].end
,
11564 text_section_label
, NULL
);
11569 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11570 (*ranges_by_label
)[lab_idx
].begin
,
11571 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11572 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11573 (*ranges_by_label
)[lab_idx
].end
,
11579 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11580 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11586 /* Non-zero if .debug_line_str should be used for .debug_line section
11587 strings or strings that are likely shareable with those. */
11588 #define DWARF5_USE_DEBUG_LINE_STR \
11589 (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
11590 && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
11591 /* FIXME: there is no .debug_line_str.dwo section, \
11592 for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
11593 && !dwarf_split_debug_info)
11595 /* Assign .debug_rnglists indexes. */
11598 index_rnglists (void)
11603 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11605 r
->idx
= rnglist_idx
++;
11608 /* Emit .debug_rnglists section. */
11611 output_rnglists (unsigned generation
)
11615 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
11616 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11617 char basebuf
[MAX_ARTIFICIAL_LABEL_BYTES
];
11619 switch_to_section (debug_ranges_section
);
11620 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11621 /* There are up to 4 unique ranges labels per generation.
11622 See also init_sections_and_labels. */
11623 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_RANGES_SECTION_LABEL
,
11624 2 + generation
* 4);
11625 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_RANGES_SECTION_LABEL
,
11626 3 + generation
* 4);
11627 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11628 dw2_asm_output_data (4, 0xffffffff,
11629 "Initial length escape value indicating "
11630 "64-bit DWARF extension");
11631 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11632 "Length of Range Lists");
11633 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11634 output_dwarf_version ();
11635 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11636 dw2_asm_output_data (1, 0, "Segment Size");
11637 /* Emit the offset table only for -gsplit-dwarf. If we don't care
11638 about relocation sizes and primarily care about the size of .debug*
11639 sections in linked shared libraries and executables, then
11640 the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
11641 into it are usually larger than just DW_FORM_sec_offset offsets
11642 into the .debug_rnglists section. */
11643 dw2_asm_output_data (4, dwarf_split_debug_info
? rnglist_idx
: 0,
11644 "Offset Entry Count");
11645 if (dwarf_split_debug_info
)
11647 ASM_OUTPUT_LABEL (asm_out_file
, ranges_base_label
);
11648 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11650 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, r
->label
,
11651 ranges_base_label
, NULL
);
11654 const char *lab
= "";
11655 unsigned int len
= vec_safe_length (ranges_table
);
11656 const char *base
= NULL
;
11657 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11659 int block_num
= r
->num
;
11663 ASM_OUTPUT_LABEL (asm_out_file
, r
->label
);
11666 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
11670 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11671 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11673 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11674 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11676 if (HAVE_AS_LEB128
)
11678 /* If all code is in the text section, then the compilation
11679 unit base address defaults to DW_AT_low_pc, which is the
11680 base of the text section. */
11681 if (!have_multiple_function_sections
)
11683 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11684 "DW_RLE_offset_pair (%s)", lab
);
11685 dw2_asm_output_delta_uleb128 (blabel
, text_section_label
,
11686 "Range begin address (%s)", lab
);
11687 dw2_asm_output_delta_uleb128 (elabel
, text_section_label
,
11688 "Range end address (%s)", lab
);
11693 dw_ranges
*r2
= NULL
;
11695 r2
= &(*ranges_table
)[i
+ 1];
11698 && r2
->label
== NULL
11699 && !r2
->maybe_new_sec
)
11701 dw2_asm_output_data (1, DW_RLE_base_address
,
11702 "DW_RLE_base_address (%s)", lab
);
11703 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11704 "Base address (%s)", lab
);
11705 strcpy (basebuf
, blabel
);
11711 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11712 "DW_RLE_offset_pair (%s)", lab
);
11713 dw2_asm_output_delta_uleb128 (blabel
, base
,
11714 "Range begin address (%s)", lab
);
11715 dw2_asm_output_delta_uleb128 (elabel
, base
,
11716 "Range end address (%s)", lab
);
11719 dw2_asm_output_data (1, DW_RLE_start_length
,
11720 "DW_RLE_start_length (%s)", lab
);
11721 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11722 "Range begin address (%s)", lab
);
11723 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11724 "Range length (%s)", lab
);
11728 dw2_asm_output_data (1, DW_RLE_start_end
,
11729 "DW_RLE_start_end (%s)", lab
);
11730 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11731 "Range begin address (%s)", lab
);
11732 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11733 "Range end address (%s)", lab
);
11737 /* Negative block_num stands for an index into ranges_by_label. */
11738 else if (block_num
< 0)
11740 int lab_idx
= - block_num
- 1;
11741 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
11742 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
11744 if (!have_multiple_function_sections
)
11745 gcc_unreachable ();
11746 if (HAVE_AS_LEB128
)
11748 dw2_asm_output_data (1, DW_RLE_start_length
,
11749 "DW_RLE_start_length (%s)", lab
);
11750 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11751 "Range begin address (%s)", lab
);
11752 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11753 "Range length (%s)", lab
);
11757 dw2_asm_output_data (1, DW_RLE_start_end
,
11758 "DW_RLE_start_end (%s)", lab
);
11759 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11760 "Range begin address (%s)", lab
);
11761 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11762 "Range end address (%s)", lab
);
11766 dw2_asm_output_data (1, DW_RLE_end_of_list
,
11767 "DW_RLE_end_of_list (%s)", lab
);
11769 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11772 /* Data structure containing information about input files. */
11775 const char *path
; /* Complete file name. */
11776 const char *fname
; /* File name part. */
11777 int length
; /* Length of entire string. */
11778 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
11779 int dir_idx
; /* Index in directory table. */
11782 /* Data structure containing information about directories with source
11786 const char *path
; /* Path including directory name. */
11787 int length
; /* Path length. */
11788 int prefix
; /* Index of directory entry which is a prefix. */
11789 int count
; /* Number of files in this directory. */
11790 int dir_idx
; /* Index of directory used as base. */
11793 /* Callback function for file_info comparison. We sort by looking at
11794 the directories in the path. */
11797 file_info_cmp (const void *p1
, const void *p2
)
11799 const struct file_info
*const s1
= (const struct file_info
*) p1
;
11800 const struct file_info
*const s2
= (const struct file_info
*) p2
;
11801 const unsigned char *cp1
;
11802 const unsigned char *cp2
;
11804 /* Take care of file names without directories. We need to make sure that
11805 we return consistent values to qsort since some will get confused if
11806 we return the same value when identical operands are passed in opposite
11807 orders. So if neither has a directory, return 0 and otherwise return
11808 1 or -1 depending on which one has the directory. */
11809 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
11810 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
11812 cp1
= (const unsigned char *) s1
->path
;
11813 cp2
= (const unsigned char *) s2
->path
;
11819 /* Reached the end of the first path? If so, handle like above. */
11820 if ((cp1
== (const unsigned char *) s1
->fname
)
11821 || (cp2
== (const unsigned char *) s2
->fname
))
11822 return ((cp2
== (const unsigned char *) s2
->fname
)
11823 - (cp1
== (const unsigned char *) s1
->fname
));
11825 /* Character of current path component the same? */
11826 else if (*cp1
!= *cp2
)
11827 return *cp1
- *cp2
;
11831 struct file_name_acquire_data
11833 struct file_info
*files
;
11838 /* Traversal function for the hash table. */
11841 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
11843 struct dwarf_file_data
*d
= *slot
;
11844 struct file_info
*fi
;
11847 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
11849 if (! d
->emitted_number
)
11852 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
11854 fi
= fnad
->files
+ fnad
->used_files
++;
11856 /* Skip all leading "./". */
11858 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
11861 /* Create a new array entry. */
11863 fi
->length
= strlen (f
);
11866 /* Search for the file name part. */
11867 f
= strrchr (f
, DIR_SEPARATOR
);
11868 #if defined (DIR_SEPARATOR_2)
11870 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
11874 if (f
== NULL
|| f
< g
)
11880 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
11884 /* Helper function for output_file_names. Emit a FORM encoded
11885 string STR, with assembly comment start ENTRY_KIND and
11889 output_line_string (enum dwarf_form form
, const char *str
,
11890 const char *entry_kind
, unsigned int idx
)
11894 case DW_FORM_string
:
11895 dw2_asm_output_nstring (str
, -1, "%s: %#x", entry_kind
, idx
);
11897 case DW_FORM_line_strp
:
11898 if (!debug_line_str_hash
)
11899 debug_line_str_hash
11900 = hash_table
<indirect_string_hasher
>::create_ggc (10);
11902 struct indirect_string_node
*node
;
11903 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
11904 set_indirect_string (node
);
11906 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
11907 debug_line_str_section
, "%s: %#x: \"%s\"",
11908 entry_kind
, 0, node
->str
);
11911 gcc_unreachable ();
11915 /* Output the directory table and the file name table. We try to minimize
11916 the total amount of memory needed. A heuristic is used to avoid large
11917 slowdowns with many input files. */
11920 output_file_names (void)
11922 struct file_name_acquire_data fnad
;
11924 struct file_info
*files
;
11925 struct dir_info
*dirs
;
11933 if (!last_emitted_file
)
11935 if (dwarf_version
>= 5)
11937 dw2_asm_output_data (1, 0, "Directory entry format count");
11938 dw2_asm_output_data_uleb128 (0, "Directories count");
11939 dw2_asm_output_data (1, 0, "File name entry format count");
11940 dw2_asm_output_data_uleb128 (0, "File names count");
11944 dw2_asm_output_data (1, 0, "End directory table");
11945 dw2_asm_output_data (1, 0, "End file name table");
11950 numfiles
= last_emitted_file
->emitted_number
;
11952 /* Allocate the various arrays we need. */
11953 files
= XALLOCAVEC (struct file_info
, numfiles
);
11954 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
11956 fnad
.files
= files
;
11957 fnad
.used_files
= 0;
11958 fnad
.max_files
= numfiles
;
11959 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
11960 gcc_assert (fnad
.used_files
== fnad
.max_files
);
11962 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
11964 /* Find all the different directories used. */
11965 dirs
[0].path
= files
[0].path
;
11966 dirs
[0].length
= files
[0].fname
- files
[0].path
;
11967 dirs
[0].prefix
= -1;
11969 dirs
[0].dir_idx
= 0;
11970 files
[0].dir_idx
= 0;
11973 for (i
= 1; i
< numfiles
; i
++)
11974 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
11975 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
11976 dirs
[ndirs
- 1].length
) == 0)
11978 /* Same directory as last entry. */
11979 files
[i
].dir_idx
= ndirs
- 1;
11980 ++dirs
[ndirs
- 1].count
;
11986 /* This is a new directory. */
11987 dirs
[ndirs
].path
= files
[i
].path
;
11988 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
11989 dirs
[ndirs
].count
= 1;
11990 dirs
[ndirs
].dir_idx
= ndirs
;
11991 files
[i
].dir_idx
= ndirs
;
11993 /* Search for a prefix. */
11994 dirs
[ndirs
].prefix
= -1;
11995 for (j
= 0; j
< ndirs
; j
++)
11996 if (dirs
[j
].length
< dirs
[ndirs
].length
11997 && dirs
[j
].length
> 1
11998 && (dirs
[ndirs
].prefix
== -1
11999 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
12000 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
12001 dirs
[ndirs
].prefix
= j
;
12006 /* Now to the actual work. We have to find a subset of the directories which
12007 allow expressing the file name using references to the directory table
12008 with the least amount of characters. We do not do an exhaustive search
12009 where we would have to check out every combination of every single
12010 possible prefix. Instead we use a heuristic which provides nearly optimal
12011 results in most cases and never is much off. */
12012 saved
= XALLOCAVEC (int, ndirs
);
12013 savehere
= XALLOCAVEC (int, ndirs
);
12015 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
12016 for (i
= 0; i
< ndirs
; i
++)
12021 /* We can always save some space for the current directory. But this
12022 does not mean it will be enough to justify adding the directory. */
12023 savehere
[i
] = dirs
[i
].length
;
12024 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
12026 for (j
= i
+ 1; j
< ndirs
; j
++)
12029 if (saved
[j
] < dirs
[i
].length
)
12031 /* Determine whether the dirs[i] path is a prefix of the
12035 k
= dirs
[j
].prefix
;
12036 while (k
!= -1 && k
!= (int) i
)
12037 k
= dirs
[k
].prefix
;
12041 /* Yes it is. We can possibly save some memory by
12042 writing the filenames in dirs[j] relative to
12044 savehere
[j
] = dirs
[i
].length
;
12045 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
12050 /* Check whether we can save enough to justify adding the dirs[i]
12052 if (total
> dirs
[i
].length
+ 1)
12054 /* It's worthwhile adding. */
12055 for (j
= i
; j
< ndirs
; j
++)
12056 if (savehere
[j
] > 0)
12058 /* Remember how much we saved for this directory so far. */
12059 saved
[j
] = savehere
[j
];
12061 /* Remember the prefix directory. */
12062 dirs
[j
].dir_idx
= i
;
12067 /* Emit the directory name table. */
12068 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
12069 enum dwarf_form str_form
= DW_FORM_string
;
12070 enum dwarf_form idx_form
= DW_FORM_udata
;
12071 if (dwarf_version
>= 5)
12073 const char *comp_dir
= comp_dir_string ();
12074 if (comp_dir
== NULL
)
12076 dw2_asm_output_data (1, 1, "Directory entry format count");
12077 if (DWARF5_USE_DEBUG_LINE_STR
)
12078 str_form
= DW_FORM_line_strp
;
12079 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12080 dw2_asm_output_data_uleb128 (str_form
, "%s",
12081 get_DW_FORM_name (str_form
));
12082 dw2_asm_output_data_uleb128 (ndirs
+ idx_offset
, "Directories count");
12083 if (str_form
== DW_FORM_string
)
12085 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
12086 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12087 dw2_asm_output_nstring (dirs
[i
].path
,
12089 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
12090 "Directory Entry: %#x", i
+ idx_offset
);
12094 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
12095 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12098 = ggc_alloc_string (dirs
[i
].path
,
12100 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
);
12101 output_line_string (str_form
, str
, "Directory Entry",
12102 (unsigned) i
+ idx_offset
);
12108 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12109 dw2_asm_output_nstring (dirs
[i
].path
,
12111 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
12112 "Directory Entry: %#x", i
+ idx_offset
);
12114 dw2_asm_output_data (1, 0, "End directory table");
12117 /* We have to emit them in the order of emitted_number since that's
12118 used in the debug info generation. To do this efficiently we
12119 generate a back-mapping of the indices first. */
12120 backmap
= XALLOCAVEC (int, numfiles
);
12121 for (i
= 0; i
< numfiles
; i
++)
12122 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
12124 if (dwarf_version
>= 5)
12126 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
12127 if (filename0
== NULL
)
12129 /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
12130 DW_FORM_data2. Choose one based on the number of directories
12131 and how much space would they occupy in each encoding.
12132 If we have at most 256 directories, all indexes fit into
12133 a single byte, so DW_FORM_data1 is most compact (if there
12134 are at most 128 directories, DW_FORM_udata would be as
12135 compact as that, but not shorter and slower to decode). */
12136 if (ndirs
+ idx_offset
<= 256)
12137 idx_form
= DW_FORM_data1
;
12138 /* If there are more than 65536 directories, we have to use
12139 DW_FORM_udata, DW_FORM_data2 can't refer to them.
12140 Otherwise, compute what space would occupy if all the indexes
12141 used DW_FORM_udata - sum - and compare that to how large would
12142 be DW_FORM_data2 encoding, and pick the more efficient one. */
12143 else if (ndirs
+ idx_offset
<= 65536)
12145 unsigned HOST_WIDE_INT sum
= 1;
12146 for (i
= 0; i
< numfiles
; i
++)
12148 int file_idx
= backmap
[i
];
12149 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
12150 sum
+= size_of_uleb128 (dir_idx
);
12152 if (sum
>= HOST_WIDE_INT_UC (2) * (numfiles
+ 1))
12153 idx_form
= DW_FORM_data2
;
12155 #ifdef VMS_DEBUGGING_INFO
12156 dw2_asm_output_data (1, 4, "File name entry format count");
12158 dw2_asm_output_data (1, 2, "File name entry format count");
12160 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12161 dw2_asm_output_data_uleb128 (str_form
, "%s",
12162 get_DW_FORM_name (str_form
));
12163 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
12164 "DW_LNCT_directory_index");
12165 dw2_asm_output_data_uleb128 (idx_form
, "%s",
12166 get_DW_FORM_name (idx_form
));
12167 #ifdef VMS_DEBUGGING_INFO
12168 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
12169 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12170 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
12171 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12173 dw2_asm_output_data_uleb128 (numfiles
+ 1, "File names count");
12175 output_line_string (str_form
, filename0
, "File Entry", 0);
12177 /* Include directory index. */
12178 if (idx_form
!= DW_FORM_udata
)
12179 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
12182 dw2_asm_output_data_uleb128 (0, NULL
);
12184 #ifdef VMS_DEBUGGING_INFO
12185 dw2_asm_output_data_uleb128 (0, NULL
);
12186 dw2_asm_output_data_uleb128 (0, NULL
);
12190 /* Now write all the file names. */
12191 for (i
= 0; i
< numfiles
; i
++)
12193 int file_idx
= backmap
[i
];
12194 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
12196 #ifdef VMS_DEBUGGING_INFO
12197 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12199 /* Setting these fields can lead to debugger miscomparisons,
12200 but VMS Debug requires them to be set correctly. */
12205 int maxfilelen
= (strlen (files
[file_idx
].path
)
12206 + dirs
[dir_idx
].length
12207 + MAX_VMS_VERSION_LEN
+ 1);
12208 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
12210 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
12211 snprintf (filebuf
, maxfilelen
, "%s;%d",
12212 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
12214 output_line_string (str_form
, filebuf
, "File Entry", (unsigned) i
+ 1);
12216 /* Include directory index. */
12217 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
12218 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
12219 dir_idx
+ idx_offset
, NULL
);
12221 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12223 /* Modification time. */
12224 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
12225 &cdt
, 0, 0, 0) == 0)
12228 /* File length in bytes. */
12229 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
12230 0, &siz
, 0, 0) == 0)
12233 output_line_string (str_form
,
12234 files
[file_idx
].path
+ dirs
[dir_idx
].length
,
12235 "File Entry", (unsigned) i
+ 1);
12237 /* Include directory index. */
12238 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
12239 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
12240 dir_idx
+ idx_offset
, NULL
);
12242 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12244 if (dwarf_version
>= 5)
12247 /* Modification time. */
12248 dw2_asm_output_data_uleb128 (0, NULL
);
12250 /* File length in bytes. */
12251 dw2_asm_output_data_uleb128 (0, NULL
);
12252 #endif /* VMS_DEBUGGING_INFO */
12255 if (dwarf_version
< 5)
12256 dw2_asm_output_data (1, 0, "End file name table");
12260 /* Output one line number table into the .debug_line section. */
12263 output_one_line_info_table (dw_line_info_table
*table
)
12265 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12266 unsigned int current_line
= 1;
12267 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
12268 dw_line_info_entry
*ent
, *prev_addr
;
12274 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
12276 switch (ent
->opcode
)
12278 case LI_set_address
:
12279 /* ??? Unfortunately, we have little choice here currently, and
12280 must always use the most general form. GCC does not know the
12281 address delta itself, so we can't use DW_LNS_advance_pc. Many
12282 ports do have length attributes which will give an upper bound
12283 on the address range. We could perhaps use length attributes
12284 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
12285 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
12289 /* This can handle any delta. This takes
12290 4+DWARF2_ADDR_SIZE bytes. */
12291 dw2_asm_output_data (1, 0, "set address %s%s", line_label
,
12292 debug_variable_location_views
12293 ? ", reset view to 0" : "");
12294 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12295 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12296 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12301 case LI_adv_address
:
12303 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
12304 char prev_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12305 ASM_GENERATE_INTERNAL_LABEL (prev_label
, LINE_CODE_LABEL
, prev_addr
->val
);
12309 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
, "fixed advance PC, increment view to %i", view
);
12310 dw2_asm_output_delta (2, line_label
, prev_label
,
12311 "from %s to %s", prev_label
, line_label
);
12318 if (ent
->val
== current_line
)
12320 /* We still need to start a new row, so output a copy insn. */
12321 dw2_asm_output_data (1, DW_LNS_copy
,
12322 "copy line %u", current_line
);
12326 int line_offset
= ent
->val
- current_line
;
12327 int line_delta
= line_offset
- DWARF_LINE_BASE
;
12329 current_line
= ent
->val
;
12330 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
12332 /* This can handle deltas from -10 to 234, using the current
12333 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
12334 This takes 1 byte. */
12335 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
12336 "line %u", current_line
);
12340 /* This can handle any delta. This takes at least 4 bytes,
12341 depending on the value being encoded. */
12342 dw2_asm_output_data (1, DW_LNS_advance_line
,
12343 "advance to line %u", current_line
);
12344 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
12345 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
12351 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
12352 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
12355 case LI_set_column
:
12356 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
12357 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
12360 case LI_negate_stmt
:
12361 current_is_stmt
= !current_is_stmt
;
12362 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
12363 "is_stmt %d", current_is_stmt
);
12366 case LI_set_prologue_end
:
12367 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
12368 "set prologue end");
12371 case LI_set_epilogue_begin
:
12372 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
12373 "set epilogue begin");
12376 case LI_set_discriminator
:
12377 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
12378 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
12379 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
12380 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
12385 /* Emit debug info for the address of the end of the table. */
12386 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
12387 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12388 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12389 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
12391 dw2_asm_output_data (1, 0, "end sequence");
12392 dw2_asm_output_data_uleb128 (1, NULL
);
12393 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
12396 /* Output the source line number correspondence information. This
12397 information goes into the .debug_line section. */
12400 output_line_info (bool prologue_only
)
12402 static unsigned int generation
;
12403 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
12404 char p1
[MAX_ARTIFICIAL_LABEL_BYTES
], p2
[MAX_ARTIFICIAL_LABEL_BYTES
];
12405 bool saw_one
= false;
12408 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, generation
);
12409 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, generation
);
12410 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, generation
);
12411 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, generation
++);
12413 if (!XCOFF_DEBUGGING_INFO
)
12415 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
12416 dw2_asm_output_data (4, 0xffffffff,
12417 "Initial length escape value indicating 64-bit DWARF extension");
12418 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
12419 "Length of Source Line Info");
12422 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
12424 output_dwarf_version ();
12425 if (dwarf_version
>= 5)
12427 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
12428 dw2_asm_output_data (1, 0, "Segment Size");
12430 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
12431 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
12433 /* Define the architecture-dependent minimum instruction length (in bytes).
12434 In this implementation of DWARF, this field is used for information
12435 purposes only. Since GCC generates assembly language, we have no
12436 a priori knowledge of how many instruction bytes are generated for each
12437 source line, and therefore can use only the DW_LNE_set_address and
12438 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
12439 this as '1', which is "correct enough" for all architectures,
12440 and don't let the target override. */
12441 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
12443 if (dwarf_version
>= 4)
12444 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
12445 "Maximum Operations Per Instruction");
12446 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
12447 "Default is_stmt_start flag");
12448 dw2_asm_output_data (1, DWARF_LINE_BASE
,
12449 "Line Base Value (Special Opcodes)");
12450 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
12451 "Line Range Value (Special Opcodes)");
12452 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
12453 "Special Opcode Base");
12455 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
12460 case DW_LNS_advance_pc
:
12461 case DW_LNS_advance_line
:
12462 case DW_LNS_set_file
:
12463 case DW_LNS_set_column
:
12464 case DW_LNS_fixed_advance_pc
:
12465 case DW_LNS_set_isa
:
12473 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
12477 /* Write out the information about the files we use. */
12478 output_file_names ();
12479 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
12482 /* Output the marker for the end of the line number info. */
12483 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12487 if (separate_line_info
)
12489 dw_line_info_table
*table
;
12492 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
12495 output_one_line_info_table (table
);
12499 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
12501 output_one_line_info_table (cold_text_section_line_info
);
12505 /* ??? Some Darwin linkers crash on a .debug_line section with no
12506 sequences. Further, merely a DW_LNE_end_sequence entry is not
12507 sufficient -- the address column must also be initialized.
12508 Make sure to output at least one set_address/end_sequence pair,
12509 choosing .text since that section is always present. */
12510 if (text_section_line_info
->in_use
|| !saw_one
)
12511 output_one_line_info_table (text_section_line_info
);
12513 /* Output the marker for the end of the line number info. */
12514 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12517 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
12520 need_endianity_attribute_p (bool reverse
)
12522 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
12525 /* Given a pointer to a tree node for some base type, return a pointer to
12526 a DIE that describes the given type. REVERSE is true if the type is
12527 to be interpreted in the reverse storage order wrt the target order.
12529 This routine must only be called for GCC type nodes that correspond to
12530 Dwarf base (fundamental) types. */
12533 base_type_die (tree type
, bool reverse
)
12535 dw_die_ref base_type_result
;
12536 enum dwarf_type encoding
;
12537 bool fpt_used
= false;
12538 struct fixed_point_type_info fpt_info
;
12539 tree type_bias
= NULL_TREE
;
12541 /* If this is a subtype that should not be emitted as a subrange type,
12542 use the base type. See subrange_type_for_debug_p. */
12543 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
12544 type
= TREE_TYPE (type
);
12546 switch (TREE_CODE (type
))
12549 if ((dwarf_version
>= 4 || !dwarf_strict
)
12550 && TYPE_NAME (type
)
12551 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12552 && DECL_IS_BUILTIN (TYPE_NAME (type
))
12553 && DECL_NAME (TYPE_NAME (type
)))
12555 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
12556 if (strcmp (name
, "char16_t") == 0
12557 || strcmp (name
, "char32_t") == 0)
12559 encoding
= DW_ATE_UTF
;
12563 if ((dwarf_version
>= 3 || !dwarf_strict
)
12564 && lang_hooks
.types
.get_fixed_point_type_info
)
12566 memset (&fpt_info
, 0, sizeof (fpt_info
));
12567 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
12570 encoding
= ((TYPE_UNSIGNED (type
))
12571 ? DW_ATE_unsigned_fixed
12572 : DW_ATE_signed_fixed
);
12576 if (TYPE_STRING_FLAG (type
))
12578 if (TYPE_UNSIGNED (type
))
12579 encoding
= DW_ATE_unsigned_char
;
12581 encoding
= DW_ATE_signed_char
;
12583 else if (TYPE_UNSIGNED (type
))
12584 encoding
= DW_ATE_unsigned
;
12586 encoding
= DW_ATE_signed
;
12589 && lang_hooks
.types
.get_type_bias
)
12590 type_bias
= lang_hooks
.types
.get_type_bias (type
);
12594 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
12596 if (dwarf_version
>= 3 || !dwarf_strict
)
12597 encoding
= DW_ATE_decimal_float
;
12599 encoding
= DW_ATE_lo_user
;
12602 encoding
= DW_ATE_float
;
12605 case FIXED_POINT_TYPE
:
12606 if (!(dwarf_version
>= 3 || !dwarf_strict
))
12607 encoding
= DW_ATE_lo_user
;
12608 else if (TYPE_UNSIGNED (type
))
12609 encoding
= DW_ATE_unsigned_fixed
;
12611 encoding
= DW_ATE_signed_fixed
;
12614 /* Dwarf2 doesn't know anything about complex ints, so use
12615 a user defined type for it. */
12617 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
12618 encoding
= DW_ATE_complex_float
;
12620 encoding
= DW_ATE_lo_user
;
12624 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12625 encoding
= DW_ATE_boolean
;
12629 /* No other TREE_CODEs are Dwarf fundamental types. */
12630 gcc_unreachable ();
12633 base_type_result
= new_die_raw (DW_TAG_base_type
);
12635 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
12636 int_size_in_bytes (type
));
12637 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
12639 if (need_endianity_attribute_p (reverse
))
12640 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
12641 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
12643 add_alignment_attribute (base_type_result
, type
);
12647 switch (fpt_info
.scale_factor_kind
)
12649 case fixed_point_scale_factor_binary
:
12650 add_AT_int (base_type_result
, DW_AT_binary_scale
,
12651 fpt_info
.scale_factor
.binary
);
12654 case fixed_point_scale_factor_decimal
:
12655 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
12656 fpt_info
.scale_factor
.decimal
);
12659 case fixed_point_scale_factor_arbitrary
:
12660 /* Arbitrary scale factors cannot be described in standard DWARF,
12664 /* Describe the scale factor as a rational constant. */
12665 const dw_die_ref scale_factor
12666 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
12668 add_AT_unsigned (scale_factor
, DW_AT_GNU_numerator
,
12669 fpt_info
.scale_factor
.arbitrary
.numerator
);
12670 add_AT_int (scale_factor
, DW_AT_GNU_denominator
,
12671 fpt_info
.scale_factor
.arbitrary
.denominator
);
12673 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
12678 gcc_unreachable ();
12683 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
12684 dw_scalar_form_constant
12685 | dw_scalar_form_exprloc
12686 | dw_scalar_form_reference
,
12689 return base_type_result
;
12692 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
12693 named 'auto' in its type: return true for it, false otherwise. */
12696 is_cxx_auto (tree type
)
12700 tree name
= TYPE_IDENTIFIER (type
);
12701 if (name
== get_identifier ("auto")
12702 || name
== get_identifier ("decltype(auto)"))
12708 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12709 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12712 is_base_type (tree type
)
12714 switch (TREE_CODE (type
))
12718 case FIXED_POINT_TYPE
:
12721 case POINTER_BOUNDS_TYPE
:
12728 case QUAL_UNION_TYPE
:
12729 case ENUMERAL_TYPE
:
12730 case FUNCTION_TYPE
:
12733 case REFERENCE_TYPE
:
12741 if (is_cxx_auto (type
))
12743 gcc_unreachable ();
12749 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12750 node, return the size in bits for the type if it is a constant, or else
12751 return the alignment for the type if the type's size is not constant, or
12752 else return BITS_PER_WORD if the type actually turns out to be an
12753 ERROR_MARK node. */
12755 static inline unsigned HOST_WIDE_INT
12756 simple_type_size_in_bits (const_tree type
)
12758 if (TREE_CODE (type
) == ERROR_MARK
)
12759 return BITS_PER_WORD
;
12760 else if (TYPE_SIZE (type
) == NULL_TREE
)
12762 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
12763 return tree_to_uhwi (TYPE_SIZE (type
));
12765 return TYPE_ALIGN (type
);
12768 /* Similarly, but return an offset_int instead of UHWI. */
12770 static inline offset_int
12771 offset_int_type_size_in_bits (const_tree type
)
12773 if (TREE_CODE (type
) == ERROR_MARK
)
12774 return BITS_PER_WORD
;
12775 else if (TYPE_SIZE (type
) == NULL_TREE
)
12777 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
12778 return wi::to_offset (TYPE_SIZE (type
));
12780 return TYPE_ALIGN (type
);
12783 /* Given a pointer to a tree node for a subrange type, return a pointer
12784 to a DIE that describes the given type. */
12787 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
12788 dw_die_ref context_die
)
12790 dw_die_ref subrange_die
;
12791 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
12793 if (context_die
== NULL
)
12794 context_die
= comp_unit_die ();
12796 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
12798 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
12800 /* The size of the subrange type and its base type do not match,
12801 so we need to generate a size attribute for the subrange type. */
12802 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
12805 add_alignment_attribute (subrange_die
, type
);
12808 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
12810 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
12811 if (bias
&& !dwarf_strict
)
12812 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
12813 dw_scalar_form_constant
12814 | dw_scalar_form_exprloc
12815 | dw_scalar_form_reference
,
12818 return subrange_die
;
12821 /* Returns the (const and/or volatile) cv_qualifiers associated with
12822 the decl node. This will normally be augmented with the
12823 cv_qualifiers of the underlying type in add_type_attribute. */
12826 decl_quals (const_tree decl
)
12828 return ((TREE_READONLY (decl
)
12829 /* The C++ front-end correctly marks reference-typed
12830 variables as readonly, but from a language (and debug
12831 info) standpoint they are not const-qualified. */
12832 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
12833 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
12834 | (TREE_THIS_VOLATILE (decl
)
12835 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
12838 /* Determine the TYPE whose qualifiers match the largest strict subset
12839 of the given TYPE_QUALS, and return its qualifiers. Ignore all
12840 qualifiers outside QUAL_MASK. */
12843 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
12846 int best_rank
= 0, best_qual
= 0, max_rank
;
12848 type_quals
&= qual_mask
;
12849 max_rank
= popcount_hwi (type_quals
) - 1;
12851 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
12852 t
= TYPE_NEXT_VARIANT (t
))
12854 int q
= TYPE_QUALS (t
) & qual_mask
;
12856 if ((q
& type_quals
) == q
&& q
!= type_quals
12857 && check_base_type (t
, type
))
12859 int rank
= popcount_hwi (q
);
12861 if (rank
> best_rank
)
12872 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
12873 static const dwarf_qual_info_t dwarf_qual_info
[] =
12875 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
12876 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
12877 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
12878 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
12880 static const unsigned int dwarf_qual_info_size
12881 = sizeof (dwarf_qual_info
) / sizeof (dwarf_qual_info
[0]);
12883 /* If DIE is a qualified DIE of some base DIE with the same parent,
12884 return the base DIE, otherwise return NULL. Set MASK to the
12885 qualifiers added compared to the returned DIE. */
12888 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
12891 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12892 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
12894 if (i
== dwarf_qual_info_size
)
12896 if (vec_safe_length (die
->die_attr
) != 1)
12898 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
12899 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
12901 *mask
|= dwarf_qual_info
[i
].q
;
12904 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
12911 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12912 entry that chains the modifiers specified by CV_QUALS in front of the
12913 given type. REVERSE is true if the type is to be interpreted in the
12914 reverse storage order wrt the target order. */
12917 modified_type_die (tree type
, int cv_quals
, bool reverse
,
12918 dw_die_ref context_die
)
12920 enum tree_code code
= TREE_CODE (type
);
12921 dw_die_ref mod_type_die
;
12922 dw_die_ref sub_die
= NULL
;
12923 tree item_type
= NULL
;
12924 tree qualified_type
;
12925 tree name
, low
, high
;
12926 dw_die_ref mod_scope
;
12927 /* Only these cv-qualifiers are currently handled. */
12928 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
12929 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
|
12930 ENCODE_QUAL_ADDR_SPACE(~0U));
12931 const bool reverse_base_type
12932 = need_endianity_attribute_p (reverse
) && is_base_type (type
);
12934 if (code
== ERROR_MARK
)
12937 if (lang_hooks
.types
.get_debug_type
)
12939 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
12941 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
12942 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
12945 cv_quals
&= cv_qual_mask
;
12947 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
12948 tag modifier (and not an attribute) old consumers won't be able
12950 if (dwarf_version
< 3)
12951 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
12953 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
12954 if (dwarf_version
< 5)
12955 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
12957 /* See if we already have the appropriately qualified variant of
12959 qualified_type
= get_qualified_type (type
, cv_quals
);
12961 if (qualified_type
== sizetype
)
12963 /* Try not to expose the internal sizetype type's name. */
12964 if (TYPE_NAME (qualified_type
)
12965 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
12967 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
12969 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
12970 && (TYPE_PRECISION (t
)
12971 == TYPE_PRECISION (qualified_type
))
12972 && (TYPE_UNSIGNED (t
)
12973 == TYPE_UNSIGNED (qualified_type
)));
12974 qualified_type
= t
;
12976 else if (qualified_type
== sizetype
12977 && TREE_CODE (sizetype
) == TREE_CODE (size_type_node
)
12978 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (size_type_node
)
12979 && TYPE_UNSIGNED (sizetype
) == TYPE_UNSIGNED (size_type_node
))
12980 qualified_type
= size_type_node
;
12983 /* If we do, then we can just use its DIE, if it exists. */
12984 if (qualified_type
)
12986 mod_type_die
= lookup_type_die (qualified_type
);
12988 /* DW_AT_endianity doesn't come from a qualifier on the type, so it is
12989 dealt with specially: the DIE with the attribute, if it exists, is
12990 placed immediately after the regular DIE for the same base type. */
12992 && (!reverse_base_type
12993 || ((mod_type_die
= mod_type_die
->die_sib
) != NULL
12994 && get_AT_unsigned (mod_type_die
, DW_AT_endianity
))))
12995 return mod_type_die
;
12998 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
13000 /* Handle C typedef types. */
13002 && TREE_CODE (name
) == TYPE_DECL
13003 && DECL_ORIGINAL_TYPE (name
)
13004 && !DECL_ARTIFICIAL (name
))
13006 tree dtype
= TREE_TYPE (name
);
13008 /* Skip the typedef for base types with DW_AT_endianity, no big deal. */
13009 if (qualified_type
== dtype
&& !reverse_base_type
)
13011 tree origin
= decl_ultimate_origin (name
);
13013 /* Typedef variants that have an abstract origin don't get their own
13014 type DIE (see gen_typedef_die), so fall back on the ultimate
13015 abstract origin instead. */
13016 if (origin
!= NULL
&& origin
!= name
)
13017 return modified_type_die (TREE_TYPE (origin
), cv_quals
, reverse
,
13020 /* For a named type, use the typedef. */
13021 gen_type_die (qualified_type
, context_die
);
13022 return lookup_type_die (qualified_type
);
13026 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
13027 dquals
&= cv_qual_mask
;
13028 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
13029 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
13030 /* cv-unqualified version of named type. Just use
13031 the unnamed type to which it refers. */
13032 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
13033 reverse
, context_die
);
13034 /* Else cv-qualified version of named type; fall through. */
13038 mod_scope
= scope_die_for (type
, context_die
);
13042 int sub_quals
= 0, first_quals
= 0;
13044 dw_die_ref first
= NULL
, last
= NULL
;
13046 /* Determine a lesser qualified type that most closely matches
13047 this one. Then generate DW_TAG_* entries for the remaining
13049 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
13051 if (sub_quals
&& use_debug_types
)
13053 bool needed
= false;
13054 /* If emitting type units, make sure the order of qualifiers
13055 is canonical. Thus, start from unqualified type if
13056 an earlier qualifier is missing in sub_quals, but some later
13057 one is present there. */
13058 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
13059 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
13061 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
13067 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
13068 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
13070 /* As not all intermediate qualified DIEs have corresponding
13071 tree types, ensure that qualified DIEs in the same scope
13072 as their DW_AT_type are emitted after their DW_AT_type,
13073 only with other qualified DIEs for the same type possibly
13074 in between them. Determine the range of such qualified
13075 DIEs now (first being the base type, last being corresponding
13076 last qualified DIE for it). */
13077 unsigned int count
= 0;
13078 first
= qualified_die_p (mod_type_die
, &first_quals
,
13079 dwarf_qual_info_size
);
13081 first
= mod_type_die
;
13082 gcc_assert ((first_quals
& ~sub_quals
) == 0);
13083 for (count
= 0, last
= first
;
13084 count
< (1U << dwarf_qual_info_size
);
13085 count
++, last
= last
->die_sib
)
13088 if (last
== mod_scope
->die_child
)
13090 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
13096 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
13097 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
13100 if (first
&& first
!= last
)
13102 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
13105 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
13106 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
13122 d
= new_die_raw (dwarf_qual_info
[i
].t
);
13123 add_child_die_after (mod_scope
, d
, last
);
13127 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
13129 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
13131 first_quals
|= dwarf_qual_info
[i
].q
;
13134 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
13136 dwarf_tag tag
= DW_TAG_pointer_type
;
13137 if (code
== REFERENCE_TYPE
)
13139 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
13140 tag
= DW_TAG_rvalue_reference_type
;
13142 tag
= DW_TAG_reference_type
;
13144 mod_type_die
= new_die (tag
, mod_scope
, type
);
13146 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
13147 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
13148 add_alignment_attribute (mod_type_die
, type
);
13149 item_type
= TREE_TYPE (type
);
13151 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
13152 if (!ADDR_SPACE_GENERIC_P (as
))
13154 int action
= targetm
.addr_space
.debug (as
);
13157 /* Positive values indicate an address_class. */
13158 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
13162 /* Negative values indicate an (inverted) segment base reg. */
13164 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
13165 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
13169 else if (code
== INTEGER_TYPE
13170 && TREE_TYPE (type
) != NULL_TREE
13171 && subrange_type_for_debug_p (type
, &low
, &high
))
13173 tree bias
= NULL_TREE
;
13174 if (lang_hooks
.types
.get_type_bias
)
13175 bias
= lang_hooks
.types
.get_type_bias (type
);
13176 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
13177 item_type
= TREE_TYPE (type
);
13179 else if (is_base_type (type
))
13181 mod_type_die
= base_type_die (type
, reverse
);
13183 /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
13184 if (reverse_base_type
)
13186 dw_die_ref after_die
13187 = modified_type_die (type
, cv_quals
, false, context_die
);
13188 add_child_die_after (comp_unit_die (), mod_type_die
, after_die
);
13191 add_child_die (comp_unit_die (), mod_type_die
);
13193 add_pubtype (type
, mod_type_die
);
13197 gen_type_die (type
, context_die
);
13199 /* We have to get the type_main_variant here (and pass that to the
13200 `lookup_type_die' routine) because the ..._TYPE node we have
13201 might simply be a *copy* of some original type node (where the
13202 copy was created to help us keep track of typedef names) and
13203 that copy might have a different TYPE_UID from the original
13205 if (TREE_CODE (type
) == FUNCTION_TYPE
13206 || TREE_CODE (type
) == METHOD_TYPE
)
13208 /* For function/method types, can't just use type_main_variant here,
13209 because that can have different ref-qualifiers for C++,
13210 but try to canonicalize. */
13211 tree main
= TYPE_MAIN_VARIANT (type
);
13212 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
13213 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
13214 && check_base_type (t
, main
)
13215 && check_lang_type (t
, type
))
13216 return lookup_type_die (t
);
13217 return lookup_type_die (type
);
13219 else if (TREE_CODE (type
) != VECTOR_TYPE
13220 && TREE_CODE (type
) != ARRAY_TYPE
)
13221 return lookup_type_die (type_main_variant (type
));
13223 /* Vectors have the debugging information in the type,
13224 not the main variant. */
13225 return lookup_type_die (type
);
13228 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
13229 don't output a DW_TAG_typedef, since there isn't one in the
13230 user's program; just attach a DW_AT_name to the type.
13231 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
13232 if the base type already has the same name. */
13234 && ((TREE_CODE (name
) != TYPE_DECL
13235 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
13236 || (cv_quals
== TYPE_UNQUALIFIED
)))
13237 || (TREE_CODE (name
) == TYPE_DECL
13238 && TREE_TYPE (name
) == qualified_type
13239 && DECL_NAME (name
))))
13241 if (TREE_CODE (name
) == TYPE_DECL
)
13242 /* Could just call add_name_and_src_coords_attributes here,
13243 but since this is a builtin type it doesn't have any
13244 useful source coordinates anyway. */
13245 name
= DECL_NAME (name
);
13246 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
13248 /* This probably indicates a bug. */
13249 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
13251 name
= TYPE_IDENTIFIER (type
);
13252 add_name_attribute (mod_type_die
,
13253 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
13256 if (qualified_type
&& !reverse_base_type
)
13257 equate_type_number_to_die (qualified_type
, mod_type_die
);
13260 /* We must do this after the equate_type_number_to_die call, in case
13261 this is a recursive type. This ensures that the modified_type_die
13262 recursion will terminate even if the type is recursive. Recursive
13263 types are possible in Ada. */
13264 sub_die
= modified_type_die (item_type
,
13265 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
13269 if (sub_die
!= NULL
)
13270 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
13272 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
13273 if (TYPE_ARTIFICIAL (type
))
13274 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
13276 return mod_type_die
;
13279 /* Generate DIEs for the generic parameters of T.
13280 T must be either a generic type or a generic function.
13281 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
13284 gen_generic_params_dies (tree t
)
13288 dw_die_ref die
= NULL
;
13291 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
13295 die
= lookup_type_die (t
);
13296 else if (DECL_P (t
))
13297 die
= lookup_decl_die (t
);
13301 parms
= lang_hooks
.get_innermost_generic_parms (t
);
13303 /* T has no generic parameter. It means T is neither a generic type
13304 or function. End of story. */
13307 parms_num
= TREE_VEC_LENGTH (parms
);
13308 args
= lang_hooks
.get_innermost_generic_args (t
);
13309 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
13310 non_default
= int_cst_value (TREE_CHAIN (args
));
13312 non_default
= TREE_VEC_LENGTH (args
);
13313 for (i
= 0; i
< parms_num
; i
++)
13315 tree parm
, arg
, arg_pack_elems
;
13316 dw_die_ref parm_die
;
13318 parm
= TREE_VEC_ELT (parms
, i
);
13319 arg
= TREE_VEC_ELT (args
, i
);
13320 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
13321 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
13323 if (parm
&& TREE_VALUE (parm
) && arg
)
13325 /* If PARM represents a template parameter pack,
13326 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13327 by DW_TAG_template_*_parameter DIEs for the argument
13328 pack elements of ARG. Note that ARG would then be
13329 an argument pack. */
13330 if (arg_pack_elems
)
13331 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
13335 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
13336 true /* emit name */, die
);
13337 if (i
>= non_default
)
13338 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
13343 /* Create and return a DIE for PARM which should be
13344 the representation of a generic type parameter.
13345 For instance, in the C++ front end, PARM would be a template parameter.
13346 ARG is the argument to PARM.
13347 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13349 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13350 as a child node. */
13353 generic_parameter_die (tree parm
, tree arg
,
13355 dw_die_ref parent_die
)
13357 dw_die_ref tmpl_die
= NULL
;
13358 const char *name
= NULL
;
13360 if (!parm
|| !DECL_NAME (parm
) || !arg
)
13363 /* We support non-type generic parameters and arguments,
13364 type generic parameters and arguments, as well as
13365 generic generic parameters (a.k.a. template template parameters in C++)
13367 if (TREE_CODE (parm
) == PARM_DECL
)
13368 /* PARM is a nontype generic parameter */
13369 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
13370 else if (TREE_CODE (parm
) == TYPE_DECL
)
13371 /* PARM is a type generic parameter. */
13372 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
13373 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
13374 /* PARM is a generic generic parameter.
13375 Its DIE is a GNU extension. It shall have a
13376 DW_AT_name attribute to represent the name of the template template
13377 parameter, and a DW_AT_GNU_template_name attribute to represent the
13378 name of the template template argument. */
13379 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
13382 gcc_unreachable ();
13388 /* If PARM is a generic parameter pack, it means we are
13389 emitting debug info for a template argument pack element.
13390 In other terms, ARG is a template argument pack element.
13391 In that case, we don't emit any DW_AT_name attribute for
13395 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
13397 add_AT_string (tmpl_die
, DW_AT_name
, name
);
13400 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
13402 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13403 TMPL_DIE should have a child DW_AT_type attribute that is set
13404 to the type of the argument to PARM, which is ARG.
13405 If PARM is a type generic parameter, TMPL_DIE should have a
13406 child DW_AT_type that is set to ARG. */
13407 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
13408 add_type_attribute (tmpl_die
, tmpl_type
,
13409 (TREE_THIS_VOLATILE (tmpl_type
)
13410 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
13411 false, parent_die
);
13415 /* So TMPL_DIE is a DIE representing a
13416 a generic generic template parameter, a.k.a template template
13417 parameter in C++ and arg is a template. */
13419 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13420 to the name of the argument. */
13421 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
13423 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
13426 if (TREE_CODE (parm
) == PARM_DECL
)
13427 /* So PARM is a non-type generic parameter.
13428 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13429 attribute of TMPL_DIE which value represents the value
13431 We must be careful here:
13432 The value of ARG might reference some function decls.
13433 We might currently be emitting debug info for a generic
13434 type and types are emitted before function decls, we don't
13435 know if the function decls referenced by ARG will actually be
13436 emitted after cgraph computations.
13437 So must defer the generation of the DW_AT_const_value to
13438 after cgraph is ready. */
13439 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
13445 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13446 PARM_PACK must be a template parameter pack. The returned DIE
13447 will be child DIE of PARENT_DIE. */
13450 template_parameter_pack_die (tree parm_pack
,
13451 tree parm_pack_args
,
13452 dw_die_ref parent_die
)
13457 gcc_assert (parent_die
&& parm_pack
);
13459 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
13460 add_name_and_src_coords_attributes (die
, parm_pack
);
13461 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
13462 generic_parameter_die (parm_pack
,
13463 TREE_VEC_ELT (parm_pack_args
, j
),
13464 false /* Don't emit DW_AT_name */,
13469 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13470 an enumerated type. */
13473 type_is_enum (const_tree type
)
13475 return TREE_CODE (type
) == ENUMERAL_TYPE
;
13478 /* Return the DBX register number described by a given RTL node. */
13480 static unsigned int
13481 dbx_reg_number (const_rtx rtl
)
13483 unsigned regno
= REGNO (rtl
);
13485 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
13487 #ifdef LEAF_REG_REMAP
13488 if (crtl
->uses_only_leaf_regs
)
13490 int leaf_reg
= LEAF_REG_REMAP (regno
);
13491 if (leaf_reg
!= -1)
13492 regno
= (unsigned) leaf_reg
;
13496 regno
= DBX_REGISTER_NUMBER (regno
);
13497 gcc_assert (regno
!= INVALID_REGNUM
);
13501 /* Optionally add a DW_OP_piece term to a location description expression.
13502 DW_OP_piece is only added if the location description expression already
13503 doesn't end with DW_OP_piece. */
13506 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
13508 dw_loc_descr_ref loc
;
13510 if (*list_head
!= NULL
)
13512 /* Find the end of the chain. */
13513 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
13516 if (loc
->dw_loc_opc
!= DW_OP_piece
)
13517 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
13521 /* Return a location descriptor that designates a machine register or
13522 zero if there is none. */
13524 static dw_loc_descr_ref
13525 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
13529 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
13532 /* We only use "frame base" when we're sure we're talking about the
13533 post-prologue local stack frame. We do this by *not* running
13534 register elimination until this point, and recognizing the special
13535 argument pointer and soft frame pointer rtx's.
13536 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13537 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
13538 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
13540 dw_loc_descr_ref result
= NULL
;
13542 if (dwarf_version
>= 4 || !dwarf_strict
)
13544 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
13547 add_loc_descr (&result
,
13548 new_loc_descr (DW_OP_stack_value
, 0, 0));
13553 regs
= targetm
.dwarf_register_span (rtl
);
13555 if (REG_NREGS (rtl
) > 1 || regs
)
13556 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
13559 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
13560 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
13562 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
13566 /* Return a location descriptor that designates a machine register for
13567 a given hard register number. */
13569 static dw_loc_descr_ref
13570 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
13572 dw_loc_descr_ref reg_loc_descr
;
13576 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
13578 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
13580 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13581 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13583 return reg_loc_descr
;
13586 /* Given an RTL of a register, return a location descriptor that
13587 designates a value that spans more than one register. */
13589 static dw_loc_descr_ref
13590 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
13591 enum var_init_status initialized
)
13594 dw_loc_descr_ref loc_result
= NULL
;
13596 /* Simple, contiguous registers. */
13597 if (regs
== NULL_RTX
)
13599 unsigned reg
= REGNO (rtl
);
13602 #ifdef LEAF_REG_REMAP
13603 if (crtl
->uses_only_leaf_regs
)
13605 int leaf_reg
= LEAF_REG_REMAP (reg
);
13606 if (leaf_reg
!= -1)
13607 reg
= (unsigned) leaf_reg
;
13611 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
13612 nregs
= REG_NREGS (rtl
);
13614 /* At present we only track constant-sized pieces. */
13615 if (!GET_MODE_SIZE (GET_MODE (rtl
)).is_constant (&size
))
13622 dw_loc_descr_ref t
;
13624 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
13625 VAR_INIT_STATUS_INITIALIZED
);
13626 add_loc_descr (&loc_result
, t
);
13627 add_loc_descr_op_piece (&loc_result
, size
);
13633 /* Now onto stupid register sets in non contiguous locations. */
13635 gcc_assert (GET_CODE (regs
) == PARALLEL
);
13637 /* At present we only track constant-sized pieces. */
13638 if (!GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0))).is_constant (&size
))
13642 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
13644 dw_loc_descr_ref t
;
13646 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
13647 VAR_INIT_STATUS_INITIALIZED
);
13648 add_loc_descr (&loc_result
, t
);
13649 add_loc_descr_op_piece (&loc_result
, size
);
13652 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13653 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13657 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
13659 /* Return a location descriptor that designates a constant i,
13660 as a compound operation from constant (i >> shift), constant shift
13663 static dw_loc_descr_ref
13664 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13666 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
13667 add_loc_descr (&ret
, int_loc_descriptor (shift
));
13668 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13672 /* Return a location descriptor that designates constant POLY_I. */
13674 static dw_loc_descr_ref
13675 int_loc_descriptor (poly_int64 poly_i
)
13677 enum dwarf_location_atom op
;
13680 if (!poly_i
.is_constant (&i
))
13682 /* Create location descriptions for the non-constant part and
13683 add any constant offset at the end. */
13684 dw_loc_descr_ref ret
= NULL
;
13685 HOST_WIDE_INT constant
= poly_i
.coeffs
[0];
13686 for (unsigned int j
= 1; j
< NUM_POLY_INT_COEFFS
; ++j
)
13688 HOST_WIDE_INT coeff
= poly_i
.coeffs
[j
];
13691 dw_loc_descr_ref start
= ret
;
13692 unsigned int factor
;
13694 unsigned int regno
= targetm
.dwarf_poly_indeterminate_value
13695 (j
, &factor
, &bias
);
13697 /* Add COEFF * ((REGNO / FACTOR) - BIAS) to the value:
13698 add COEFF * (REGNO / FACTOR) now and subtract
13699 COEFF * BIAS from the final constant part. */
13700 constant
-= coeff
* bias
;
13701 add_loc_descr (&ret
, new_reg_loc_descr (regno
, 0));
13702 if (coeff
% factor
== 0)
13706 int amount
= exact_log2 (factor
);
13707 gcc_assert (amount
>= 0);
13708 add_loc_descr (&ret
, int_loc_descriptor (amount
));
13709 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
13713 add_loc_descr (&ret
, int_loc_descriptor (coeff
));
13714 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13717 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
13720 loc_descr_plus_const (&ret
, constant
);
13724 /* Pick the smallest representation of a constant, rather than just
13725 defaulting to the LEB encoding. */
13728 int clz
= clz_hwi (i
);
13729 int ctz
= ctz_hwi (i
);
13731 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
13732 else if (i
<= 0xff)
13733 op
= DW_OP_const1u
;
13734 else if (i
<= 0xffff)
13735 op
= DW_OP_const2u
;
13736 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13737 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13738 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
13739 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
13740 while DW_OP_const4u is 5 bytes. */
13741 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
13742 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13743 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13744 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
13745 while DW_OP_const4u is 5 bytes. */
13746 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13748 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13749 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13752 /* As i >= 2**31, the double cast above will yield a negative number.
13753 Since wrapping is defined in DWARF expressions we can output big
13754 positive integers as small negative ones, regardless of the size
13757 Here, since the evaluator will handle 32-bit values and since i >=
13758 2**31, we know it's going to be interpreted as a negative literal:
13759 store it this way if we can do better than 5 bytes this way. */
13760 return int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13762 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13763 op
= DW_OP_const4u
;
13765 /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
13766 least 6 bytes: see if we can do better before falling back to it. */
13767 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13768 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13769 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
13770 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13771 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13772 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
13773 >= HOST_BITS_PER_WIDE_INT
)
13774 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
13775 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
13776 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
13777 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13778 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13779 && size_of_uleb128 (i
) > 6)
13780 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
13781 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
13788 op
= DW_OP_const1s
;
13789 else if (i
>= -0x8000)
13790 op
= DW_OP_const2s
;
13791 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13793 if (size_of_int_loc_descriptor (i
) < 5)
13795 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13796 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13799 op
= DW_OP_const4s
;
13803 if (size_of_int_loc_descriptor (i
)
13804 < (unsigned long) 1 + size_of_sleb128 (i
))
13806 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13807 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13814 return new_loc_descr (op
, i
, 0);
13817 /* Likewise, for unsigned constants. */
13819 static dw_loc_descr_ref
13820 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
13822 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
13823 const unsigned HOST_WIDE_INT max_uint
13824 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
13826 /* If possible, use the clever signed constants handling. */
13828 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
13830 /* Here, we are left with positive numbers that cannot be represented as
13831 HOST_WIDE_INT, i.e.:
13832 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
13834 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
13835 whereas may be better to output a negative integer: thanks to integer
13836 wrapping, we know that:
13837 x = x - 2 ** DWARF2_ADDR_SIZE
13838 = x - 2 * (max (HOST_WIDE_INT) + 1)
13839 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
13840 small negative integers. Let's try that in cases it will clearly improve
13841 the encoding: there is no gain turning DW_OP_const4u into
13843 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
13844 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
13845 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
13847 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
13849 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
13850 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
13851 const HOST_WIDE_INT second_shift
13852 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
13854 /* So we finally have:
13855 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
13856 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
13857 return int_loc_descriptor (second_shift
);
13860 /* Last chance: fallback to a simple constant operation. */
13861 return new_loc_descr
13862 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13868 /* Generate and return a location description that computes the unsigned
13869 comparison of the two stack top entries (a OP b where b is the top-most
13870 entry and a is the second one). The KIND of comparison can be LT_EXPR,
13871 LE_EXPR, GT_EXPR or GE_EXPR. */
13873 static dw_loc_descr_ref
13874 uint_comparison_loc_list (enum tree_code kind
)
13876 enum dwarf_location_atom op
, flip_op
;
13877 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
13894 gcc_unreachable ();
13897 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13898 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13900 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
13901 possible to perform unsigned comparisons: we just have to distinguish
13904 1. when a and b have the same sign (as signed integers); then we should
13905 return: a OP(signed) b;
13907 2. when a is a negative signed integer while b is a positive one, then a
13908 is a greater unsigned integer than b; likewise when a and b's roles
13911 So first, compare the sign of the two operands. */
13912 ret
= new_loc_descr (DW_OP_over
, 0, 0);
13913 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13914 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
13915 /* If they have different signs (i.e. they have different sign bits), then
13916 the stack top value has now the sign bit set and thus it's smaller than
13918 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
13919 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
13920 add_loc_descr (&ret
, bra_node
);
13922 /* We are in case 1. At this point, we know both operands have the same
13923 sign, to it's safe to use the built-in signed comparison. */
13924 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13925 add_loc_descr (&ret
, jmp_node
);
13927 /* We are in case 2. Here, we know both operands do not have the same sign,
13928 so we have to flip the signed comparison. */
13929 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
13930 tmp
= new_loc_descr (flip_op
, 0, 0);
13931 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13932 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13933 add_loc_descr (&ret
, tmp
);
13935 /* This dummy operation is necessary to make the two branches join. */
13936 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13937 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13938 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13939 add_loc_descr (&ret
, tmp
);
13944 /* Likewise, but takes the location description lists (might be destructive on
13945 them). Return NULL if either is NULL or if concatenation fails. */
13947 static dw_loc_list_ref
13948 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
13949 enum tree_code kind
)
13951 if (left
== NULL
|| right
== NULL
)
13954 add_loc_list (&left
, right
);
13958 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
13962 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
13963 without actually allocating it. */
13965 static unsigned long
13966 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13968 return size_of_int_loc_descriptor (i
>> shift
)
13969 + size_of_int_loc_descriptor (shift
)
13973 /* Return size_of_locs (int_loc_descriptor (i)) without
13974 actually allocating it. */
13976 static unsigned long
13977 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
13986 else if (i
<= 0xff)
13988 else if (i
<= 0xffff)
13992 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13993 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13994 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13996 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13997 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13998 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14000 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
14001 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
14003 return size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
14004 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
14006 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
14007 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14008 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
14009 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14011 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
14012 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
14013 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14015 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
14016 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
14018 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14027 else if (i
>= -0x8000)
14029 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
14031 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
14033 s
= size_of_int_loc_descriptor (-i
) + 1;
14041 unsigned long r
= 1 + size_of_sleb128 (i
);
14042 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
14044 s
= size_of_int_loc_descriptor (-i
) + 1;
14053 /* Return loc description representing "address" of integer value.
14054 This can appear only as toplevel expression. */
14056 static dw_loc_descr_ref
14057 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
14060 dw_loc_descr_ref loc_result
= NULL
;
14062 if (!(dwarf_version
>= 4 || !dwarf_strict
))
14065 litsize
= size_of_int_loc_descriptor (i
);
14066 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
14067 is more compact. For DW_OP_stack_value we need:
14068 litsize + 1 (DW_OP_stack_value)
14069 and for DW_OP_implicit_value:
14070 1 (DW_OP_implicit_value) + 1 (length) + size. */
14071 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
14073 loc_result
= int_loc_descriptor (i
);
14074 add_loc_descr (&loc_result
,
14075 new_loc_descr (DW_OP_stack_value
, 0, 0));
14079 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14081 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
14082 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
14086 /* Return a location descriptor that designates a base+offset location. */
14088 static dw_loc_descr_ref
14089 based_loc_descr (rtx reg
, poly_int64 offset
,
14090 enum var_init_status initialized
)
14092 unsigned int regno
;
14093 dw_loc_descr_ref result
;
14094 dw_fde_ref fde
= cfun
->fde
;
14096 /* We only use "frame base" when we're sure we're talking about the
14097 post-prologue local stack frame. We do this by *not* running
14098 register elimination until this point, and recognizing the special
14099 argument pointer and soft frame pointer rtx's. */
14100 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
14102 rtx elim
= (ira_use_lra_p
14103 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
14104 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
14108 elim
= strip_offset_and_add (elim
, &offset
);
14109 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
14110 && (elim
== hard_frame_pointer_rtx
14111 || elim
== stack_pointer_rtx
))
14112 || elim
== (frame_pointer_needed
14113 ? hard_frame_pointer_rtx
14114 : stack_pointer_rtx
));
14116 /* If drap register is used to align stack, use frame
14117 pointer + offset to access stack variables. If stack
14118 is aligned without drap, use stack pointer + offset to
14119 access stack variables. */
14120 if (crtl
->stack_realign_tried
14121 && reg
== frame_pointer_rtx
)
14124 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
14125 ? HARD_FRAME_POINTER_REGNUM
14127 return new_reg_loc_descr (base_reg
, offset
);
14130 gcc_assert (frame_pointer_fb_offset_valid
);
14131 offset
+= frame_pointer_fb_offset
;
14132 HOST_WIDE_INT const_offset
;
14133 if (offset
.is_constant (&const_offset
))
14134 return new_loc_descr (DW_OP_fbreg
, const_offset
, 0);
14137 dw_loc_descr_ref ret
= new_loc_descr (DW_OP_fbreg
, 0, 0);
14138 loc_descr_plus_const (&ret
, offset
);
14144 regno
= REGNO (reg
);
14145 #ifdef LEAF_REG_REMAP
14146 if (crtl
->uses_only_leaf_regs
)
14148 int leaf_reg
= LEAF_REG_REMAP (regno
);
14149 if (leaf_reg
!= -1)
14150 regno
= (unsigned) leaf_reg
;
14153 regno
= DWARF_FRAME_REGNUM (regno
);
14155 HOST_WIDE_INT const_offset
;
14156 if (!optimize
&& fde
14157 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
)
14158 && offset
.is_constant (&const_offset
))
14160 /* Use cfa+offset to represent the location of arguments passed
14161 on the stack when drap is used to align stack.
14162 Only do this when not optimizing, for optimized code var-tracking
14163 is supposed to track where the arguments live and the register
14164 used as vdrap or drap in some spot might be used for something
14165 else in other part of the routine. */
14166 return new_loc_descr (DW_OP_fbreg
, const_offset
, 0);
14169 result
= new_reg_loc_descr (regno
, offset
);
14171 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14172 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14177 /* Return true if this RTL expression describes a base+offset calculation. */
14180 is_based_loc (const_rtx rtl
)
14182 return (GET_CODE (rtl
) == PLUS
14183 && ((REG_P (XEXP (rtl
, 0))
14184 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
14185 && CONST_INT_P (XEXP (rtl
, 1)))));
14188 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
14191 static dw_loc_descr_ref
14192 tls_mem_loc_descriptor (rtx mem
)
14195 dw_loc_descr_ref loc_result
;
14197 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
14200 base
= get_base_address (MEM_EXPR (mem
));
14203 || !DECL_THREAD_LOCAL_P (base
))
14206 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
14207 if (loc_result
== NULL
)
14210 if (maybe_ne (MEM_OFFSET (mem
), 0))
14211 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
14216 /* Output debug info about reason why we failed to expand expression as dwarf
14220 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
14222 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
14224 fprintf (dump_file
, "Failed to expand as dwarf: ");
14226 print_generic_expr (dump_file
, expr
, dump_flags
);
14229 fprintf (dump_file
, "\n");
14230 print_rtl (dump_file
, rtl
);
14232 fprintf (dump_file
, "\nReason: %s\n", reason
);
14236 /* Helper function for const_ok_for_output. */
14239 const_ok_for_output_1 (rtx rtl
)
14241 if (targetm
.const_not_ok_for_debug_p (rtl
))
14243 if (GET_CODE (rtl
) != UNSPEC
)
14245 expansion_failed (NULL_TREE
, rtl
,
14246 "Expression rejected for debug by the backend.\n");
14250 /* If delegitimize_address couldn't do anything with the UNSPEC, and
14251 the target hook doesn't explicitly allow it in debug info, assume
14252 we can't express it in the debug info. */
14253 /* Don't complain about TLS UNSPECs, those are just too hard to
14254 delegitimize. Note this could be a non-decl SYMBOL_REF such as
14255 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
14256 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
14258 && (XVECLEN (rtl
, 0) == 0
14259 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
14260 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
14261 inform (current_function_decl
14262 ? DECL_SOURCE_LOCATION (current_function_decl
)
14263 : UNKNOWN_LOCATION
,
14264 #if NUM_UNSPEC_VALUES > 0
14265 "non-delegitimized UNSPEC %s (%d) found in variable location",
14266 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
14267 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
14270 "non-delegitimized UNSPEC %d found in variable location",
14273 expansion_failed (NULL_TREE
, rtl
,
14274 "UNSPEC hasn't been delegitimized.\n");
14278 if (CONST_POLY_INT_P (rtl
))
14281 if (targetm
.const_not_ok_for_debug_p (rtl
))
14283 expansion_failed (NULL_TREE
, rtl
,
14284 "Expression rejected for debug by the backend.\n");
14288 /* FIXME: Refer to PR60655. It is possible for simplification
14289 of rtl expressions in var tracking to produce such expressions.
14290 We should really identify / validate expressions
14291 enclosed in CONST that can be handled by assemblers on various
14292 targets and only handle legitimate cases here. */
14293 switch (GET_CODE (rtl
))
14304 if (CONSTANT_POOL_ADDRESS_P (rtl
))
14307 get_pool_constant_mark (rtl
, &marked
);
14308 /* If all references to this pool constant were optimized away,
14309 it was not output and thus we can't represent it. */
14312 expansion_failed (NULL_TREE
, rtl
,
14313 "Constant was removed from constant pool.\n");
14318 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
14321 /* Avoid references to external symbols in debug info, on several targets
14322 the linker might even refuse to link when linking a shared library,
14323 and in many other cases the relocations for .debug_info/.debug_loc are
14324 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
14325 to be defined within the same shared library or executable are fine. */
14326 if (SYMBOL_REF_EXTERNAL_P (rtl
))
14328 tree decl
= SYMBOL_REF_DECL (rtl
);
14330 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
14332 expansion_failed (NULL_TREE
, rtl
,
14333 "Symbol not defined in current TU.\n");
14341 /* Return true if constant RTL can be emitted in DW_OP_addr or
14342 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
14343 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
14346 const_ok_for_output (rtx rtl
)
14348 if (GET_CODE (rtl
) == SYMBOL_REF
)
14349 return const_ok_for_output_1 (rtl
);
14351 if (GET_CODE (rtl
) == CONST
)
14353 subrtx_var_iterator::array_type array
;
14354 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
14355 if (!const_ok_for_output_1 (*iter
))
14363 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
14364 if possible, NULL otherwise. */
14367 base_type_for_mode (machine_mode mode
, bool unsignedp
)
14369 dw_die_ref type_die
;
14370 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
14374 switch (TREE_CODE (type
))
14382 type_die
= lookup_type_die (type
);
14384 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
14386 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
14391 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
14392 type matching MODE, or, if MODE is narrower than or as wide as
14393 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
14396 static dw_loc_descr_ref
14397 convert_descriptor_to_mode (scalar_int_mode mode
, dw_loc_descr_ref op
)
14399 machine_mode outer_mode
= mode
;
14400 dw_die_ref type_die
;
14401 dw_loc_descr_ref cvt
;
14403 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14405 add_loc_descr (&op
, new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
14408 type_die
= base_type_for_mode (outer_mode
, 1);
14409 if (type_die
== NULL
)
14411 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14412 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14413 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14414 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14415 add_loc_descr (&op
, cvt
);
14419 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
14421 static dw_loc_descr_ref
14422 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
14423 dw_loc_descr_ref op1
)
14425 dw_loc_descr_ref ret
= op0
;
14426 add_loc_descr (&ret
, op1
);
14427 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
14428 if (STORE_FLAG_VALUE
!= 1)
14430 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
14431 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14436 /* Subroutine of scompare_loc_descriptor for the case in which we're
14437 comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
14438 and in which OP_MODE is bigger than DWARF2_ADDR_SIZE. */
14440 static dw_loc_descr_ref
14441 scompare_loc_descriptor_wide (enum dwarf_location_atom op
,
14442 scalar_int_mode op_mode
,
14443 dw_loc_descr_ref op0
, dw_loc_descr_ref op1
)
14445 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
14446 dw_loc_descr_ref cvt
;
14448 if (type_die
== NULL
)
14450 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14451 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14452 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14453 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14454 add_loc_descr (&op0
, cvt
);
14455 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14456 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14457 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14458 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14459 add_loc_descr (&op1
, cvt
);
14460 return compare_loc_descriptor (op
, op0
, op1
);
14463 /* Subroutine of scompare_loc_descriptor for the case in which we're
14464 comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
14465 and in which OP_MODE is smaller than DWARF2_ADDR_SIZE. */
14467 static dw_loc_descr_ref
14468 scompare_loc_descriptor_narrow (enum dwarf_location_atom op
, rtx rtl
,
14469 scalar_int_mode op_mode
,
14470 dw_loc_descr_ref op0
, dw_loc_descr_ref op1
)
14472 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
14473 /* For eq/ne, if the operands are known to be zero-extended,
14474 there is no need to do the fancy shifting up. */
14475 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
14477 dw_loc_descr_ref last0
, last1
;
14478 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
14480 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
14482 /* deref_size zero extends, and for constants we can check
14483 whether they are zero extended or not. */
14484 if (((last0
->dw_loc_opc
== DW_OP_deref_size
14485 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
14486 || (CONST_INT_P (XEXP (rtl
, 0))
14487 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
14488 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
14489 && ((last1
->dw_loc_opc
== DW_OP_deref_size
14490 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
14491 || (CONST_INT_P (XEXP (rtl
, 1))
14492 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
14493 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
14494 return compare_loc_descriptor (op
, op0
, op1
);
14496 /* EQ/NE comparison against constant in narrower type than
14497 DWARF2_ADDR_SIZE can be performed either as
14498 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
14501 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
14502 DW_OP_{eq,ne}. Pick whatever is shorter. */
14503 if (CONST_INT_P (XEXP (rtl
, 1))
14504 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
14505 && (size_of_int_loc_descriptor (shift
) + 1
14506 + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
)
14507 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
14508 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
14509 & GET_MODE_MASK (op_mode
))))
14511 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
14512 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14513 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
14514 & GET_MODE_MASK (op_mode
));
14515 return compare_loc_descriptor (op
, op0
, op1
);
14518 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14519 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14520 if (CONST_INT_P (XEXP (rtl
, 1)))
14521 op1
= int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
);
14524 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14525 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14527 return compare_loc_descriptor (op
, op0
, op1
);
14530 /* Return location descriptor for unsigned comparison OP RTL. */
14532 static dw_loc_descr_ref
14533 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
14534 machine_mode mem_mode
)
14536 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
14537 dw_loc_descr_ref op0
, op1
;
14539 if (op_mode
== VOIDmode
)
14540 op_mode
= GET_MODE (XEXP (rtl
, 1));
14541 if (op_mode
== VOIDmode
)
14544 scalar_int_mode int_op_mode
;
14546 && dwarf_version
< 5
14547 && (!is_a
<scalar_int_mode
> (op_mode
, &int_op_mode
)
14548 || GET_MODE_SIZE (int_op_mode
) > DWARF2_ADDR_SIZE
))
14551 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
14552 VAR_INIT_STATUS_INITIALIZED
);
14553 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
14554 VAR_INIT_STATUS_INITIALIZED
);
14556 if (op0
== NULL
|| op1
== NULL
)
14559 if (is_a
<scalar_int_mode
> (op_mode
, &int_op_mode
))
14561 if (GET_MODE_SIZE (int_op_mode
) < DWARF2_ADDR_SIZE
)
14562 return scompare_loc_descriptor_narrow (op
, rtl
, int_op_mode
, op0
, op1
);
14564 if (GET_MODE_SIZE (int_op_mode
) > DWARF2_ADDR_SIZE
)
14565 return scompare_loc_descriptor_wide (op
, int_op_mode
, op0
, op1
);
14567 return compare_loc_descriptor (op
, op0
, op1
);
14570 /* Return location descriptor for unsigned comparison OP RTL. */
14572 static dw_loc_descr_ref
14573 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
14574 machine_mode mem_mode
)
14576 dw_loc_descr_ref op0
, op1
;
14578 machine_mode test_op_mode
= GET_MODE (XEXP (rtl
, 0));
14579 if (test_op_mode
== VOIDmode
)
14580 test_op_mode
= GET_MODE (XEXP (rtl
, 1));
14582 scalar_int_mode op_mode
;
14583 if (!is_a
<scalar_int_mode
> (test_op_mode
, &op_mode
))
14587 && dwarf_version
< 5
14588 && GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
14591 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
14592 VAR_INIT_STATUS_INITIALIZED
);
14593 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
14594 VAR_INIT_STATUS_INITIALIZED
);
14596 if (op0
== NULL
|| op1
== NULL
)
14599 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
14601 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
14602 dw_loc_descr_ref last0
, last1
;
14603 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
14605 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
14607 if (CONST_INT_P (XEXP (rtl
, 0)))
14608 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
14609 /* deref_size zero extends, so no need to mask it again. */
14610 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
14611 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
14613 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14614 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14616 if (CONST_INT_P (XEXP (rtl
, 1)))
14617 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
14618 /* deref_size zero extends, so no need to mask it again. */
14619 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
14620 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
14622 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14623 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14626 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
14628 HOST_WIDE_INT bias
= 1;
14629 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14630 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14631 if (CONST_INT_P (XEXP (rtl
, 1)))
14632 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
14633 + INTVAL (XEXP (rtl
, 1)));
14635 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
14638 return compare_loc_descriptor (op
, op0
, op1
);
14641 /* Return location descriptor for {U,S}{MIN,MAX}. */
14643 static dw_loc_descr_ref
14644 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
14645 machine_mode mem_mode
)
14647 enum dwarf_location_atom op
;
14648 dw_loc_descr_ref op0
, op1
, ret
;
14649 dw_loc_descr_ref bra_node
, drop_node
;
14651 scalar_int_mode int_mode
;
14653 && dwarf_version
< 5
14654 && (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
14655 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
))
14658 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14659 VAR_INIT_STATUS_INITIALIZED
);
14660 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14661 VAR_INIT_STATUS_INITIALIZED
);
14663 if (op0
== NULL
|| op1
== NULL
)
14666 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
14667 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
14668 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
14669 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
14671 /* Checked by the caller. */
14672 int_mode
= as_a
<scalar_int_mode
> (mode
);
14673 if (GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
14675 HOST_WIDE_INT mask
= GET_MODE_MASK (int_mode
);
14676 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14677 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14678 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14679 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14681 else if (GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
)
14683 HOST_WIDE_INT bias
= 1;
14684 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14685 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14686 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14689 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
14690 && GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
14692 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (int_mode
)) * BITS_PER_UNIT
;
14693 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14694 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14695 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14696 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14698 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
14699 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
14701 dw_die_ref type_die
= base_type_for_mode (int_mode
, 0);
14702 dw_loc_descr_ref cvt
;
14703 if (type_die
== NULL
)
14705 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14706 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14707 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14708 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14709 add_loc_descr (&op0
, cvt
);
14710 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14711 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14712 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14713 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14714 add_loc_descr (&op1
, cvt
);
14717 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
14722 add_loc_descr (&ret
, op1
);
14723 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
14724 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14725 add_loc_descr (&ret
, bra_node
);
14726 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14727 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14728 add_loc_descr (&ret
, drop_node
);
14729 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14730 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14731 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
14732 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
14733 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
14734 ret
= convert_descriptor_to_mode (int_mode
, ret
);
14738 /* Helper function for mem_loc_descriptor. Perform OP binary op,
14739 but after converting arguments to type_die, afterwards
14740 convert back to unsigned. */
14742 static dw_loc_descr_ref
14743 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
14744 scalar_int_mode mode
, machine_mode mem_mode
)
14746 dw_loc_descr_ref cvt
, op0
, op1
;
14748 if (type_die
== NULL
)
14750 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14751 VAR_INIT_STATUS_INITIALIZED
);
14752 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14753 VAR_INIT_STATUS_INITIALIZED
);
14754 if (op0
== NULL
|| op1
== NULL
)
14756 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14757 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14758 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14759 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14760 add_loc_descr (&op0
, cvt
);
14761 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14762 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14763 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14764 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14765 add_loc_descr (&op1
, cvt
);
14766 add_loc_descr (&op0
, op1
);
14767 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
14768 return convert_descriptor_to_mode (mode
, op0
);
14771 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
14772 const0 is DW_OP_lit0 or corresponding typed constant,
14773 const1 is DW_OP_lit1 or corresponding typed constant
14774 and constMSB is constant with just the MSB bit set
14776 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14777 L1: const0 DW_OP_swap
14778 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
14779 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14784 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14785 L1: const0 DW_OP_swap
14786 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14787 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14792 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
14793 L1: const1 DW_OP_swap
14794 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14795 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14799 static dw_loc_descr_ref
14800 clz_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
14801 machine_mode mem_mode
)
14803 dw_loc_descr_ref op0
, ret
, tmp
;
14804 HOST_WIDE_INT valv
;
14805 dw_loc_descr_ref l1jump
, l1label
;
14806 dw_loc_descr_ref l2jump
, l2label
;
14807 dw_loc_descr_ref l3jump
, l3label
;
14808 dw_loc_descr_ref l4jump
, l4label
;
14811 if (GET_MODE (XEXP (rtl
, 0)) != mode
)
14814 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14815 VAR_INIT_STATUS_INITIALIZED
);
14819 if (GET_CODE (rtl
) == CLZ
)
14821 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14822 valv
= GET_MODE_BITSIZE (mode
);
14824 else if (GET_CODE (rtl
) == FFS
)
14826 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14827 valv
= GET_MODE_BITSIZE (mode
);
14828 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14829 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14830 add_loc_descr (&ret
, l1jump
);
14831 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14832 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
14833 VAR_INIT_STATUS_INITIALIZED
);
14836 add_loc_descr (&ret
, tmp
);
14837 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14838 add_loc_descr (&ret
, l4jump
);
14839 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
14840 ? const1_rtx
: const0_rtx
,
14842 VAR_INIT_STATUS_INITIALIZED
);
14843 if (l1label
== NULL
)
14845 add_loc_descr (&ret
, l1label
);
14846 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14847 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
14848 add_loc_descr (&ret
, l2label
);
14849 if (GET_CODE (rtl
) != CLZ
)
14851 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
14852 msb
= GEN_INT (HOST_WIDE_INT_1U
14853 << (GET_MODE_BITSIZE (mode
) - 1));
14855 msb
= immed_wide_int_const
14856 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
14857 GET_MODE_PRECISION (mode
)), mode
);
14858 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
14859 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14860 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
14861 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
14863 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
14864 VAR_INIT_STATUS_INITIALIZED
);
14867 add_loc_descr (&ret
, tmp
);
14868 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14869 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14870 add_loc_descr (&ret
, l3jump
);
14871 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14872 VAR_INIT_STATUS_INITIALIZED
);
14875 add_loc_descr (&ret
, tmp
);
14876 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
14877 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
14878 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14879 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
14880 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14881 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14882 add_loc_descr (&ret
, l2jump
);
14883 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
14884 add_loc_descr (&ret
, l3label
);
14885 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
14886 add_loc_descr (&ret
, l4label
);
14887 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14888 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14889 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14890 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14891 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14892 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
14893 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14894 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
14898 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
14899 const1 is DW_OP_lit1 or corresponding typed constant):
14901 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14902 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14906 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14907 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14910 static dw_loc_descr_ref
14911 popcount_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
14912 machine_mode mem_mode
)
14914 dw_loc_descr_ref op0
, ret
, tmp
;
14915 dw_loc_descr_ref l1jump
, l1label
;
14916 dw_loc_descr_ref l2jump
, l2label
;
14918 if (GET_MODE (XEXP (rtl
, 0)) != mode
)
14921 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14922 VAR_INIT_STATUS_INITIALIZED
);
14926 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14927 VAR_INIT_STATUS_INITIALIZED
);
14930 add_loc_descr (&ret
, tmp
);
14931 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14932 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
14933 add_loc_descr (&ret
, l1label
);
14934 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14935 add_loc_descr (&ret
, l2jump
);
14936 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14937 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14938 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14939 VAR_INIT_STATUS_INITIALIZED
);
14942 add_loc_descr (&ret
, tmp
);
14943 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14944 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
14945 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
14946 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14947 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14948 VAR_INIT_STATUS_INITIALIZED
);
14949 add_loc_descr (&ret
, tmp
);
14950 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14951 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14952 add_loc_descr (&ret
, l1jump
);
14953 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14954 add_loc_descr (&ret
, l2label
);
14955 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14956 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14957 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14958 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14962 /* BSWAP (constS is initial shift count, either 56 or 24):
14964 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
14965 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
14966 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
14967 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
14968 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
14970 static dw_loc_descr_ref
14971 bswap_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
14972 machine_mode mem_mode
)
14974 dw_loc_descr_ref op0
, ret
, tmp
;
14975 dw_loc_descr_ref l1jump
, l1label
;
14976 dw_loc_descr_ref l2jump
, l2label
;
14978 if (BITS_PER_UNIT
!= 8
14979 || (GET_MODE_BITSIZE (mode
) != 32
14980 && GET_MODE_BITSIZE (mode
) != 64))
14983 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14984 VAR_INIT_STATUS_INITIALIZED
);
14989 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14991 VAR_INIT_STATUS_INITIALIZED
);
14994 add_loc_descr (&ret
, tmp
);
14995 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14996 VAR_INIT_STATUS_INITIALIZED
);
14999 add_loc_descr (&ret
, tmp
);
15000 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
15001 add_loc_descr (&ret
, l1label
);
15002 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
15004 VAR_INIT_STATUS_INITIALIZED
);
15005 add_loc_descr (&ret
, tmp
);
15006 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
15007 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
15008 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
15009 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
15010 VAR_INIT_STATUS_INITIALIZED
);
15013 add_loc_descr (&ret
, tmp
);
15014 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
15015 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
15016 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
15017 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
15018 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15019 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
15020 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
15021 VAR_INIT_STATUS_INITIALIZED
);
15022 add_loc_descr (&ret
, tmp
);
15023 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
15024 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15025 add_loc_descr (&ret
, l2jump
);
15026 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
15027 VAR_INIT_STATUS_INITIALIZED
);
15028 add_loc_descr (&ret
, tmp
);
15029 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
15030 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15031 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15032 add_loc_descr (&ret
, l1jump
);
15033 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
15034 add_loc_descr (&ret
, l2label
);
15035 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15036 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
15037 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15038 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
15039 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15040 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
15044 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
15045 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
15046 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
15047 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
15049 ROTATERT is similar:
15050 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
15051 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
15052 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
15054 static dw_loc_descr_ref
15055 rotate_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15056 machine_mode mem_mode
)
15058 rtx rtlop1
= XEXP (rtl
, 1);
15059 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
15062 if (is_narrower_int_mode (GET_MODE (rtlop1
), mode
))
15063 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
15064 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15065 VAR_INIT_STATUS_INITIALIZED
);
15066 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
15067 VAR_INIT_STATUS_INITIALIZED
);
15068 if (op0
== NULL
|| op1
== NULL
)
15070 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
15071 for (i
= 0; i
< 2; i
++)
15073 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
15074 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
15076 VAR_INIT_STATUS_INITIALIZED
);
15077 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
15078 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
15080 : HOST_BITS_PER_WIDE_INT
== 64
15081 ? DW_OP_const8u
: DW_OP_constu
,
15082 GET_MODE_MASK (mode
), 0);
15085 if (mask
[i
] == NULL
)
15087 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
15090 add_loc_descr (&ret
, op1
);
15091 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
15092 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
15093 if (GET_CODE (rtl
) == ROTATERT
)
15095 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
15096 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
15097 GET_MODE_BITSIZE (mode
), 0));
15099 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
15100 if (mask
[0] != NULL
)
15101 add_loc_descr (&ret
, mask
[0]);
15102 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
15103 if (mask
[1] != NULL
)
15105 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15106 add_loc_descr (&ret
, mask
[1]);
15107 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15109 if (GET_CODE (rtl
) == ROTATE
)
15111 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
15112 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
15113 GET_MODE_BITSIZE (mode
), 0));
15115 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
15116 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
15120 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
15121 for DEBUG_PARAMETER_REF RTL. */
15123 static dw_loc_descr_ref
15124 parameter_ref_descriptor (rtx rtl
)
15126 dw_loc_descr_ref ret
;
15131 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
15132 /* With LTO during LTRANS we get the late DIE that refers to the early
15133 DIE, thus we add another indirection here. This seems to confuse
15134 gdb enough to make gcc.dg/guality/pr68860-1.c FAIL with LTO. */
15135 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
15136 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
15139 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15140 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
15141 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15145 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
15146 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
15151 /* The following routine converts the RTL for a variable or parameter
15152 (resident in memory) into an equivalent Dwarf representation of a
15153 mechanism for getting the address of that same variable onto the top of a
15154 hypothetical "address evaluation" stack.
15156 When creating memory location descriptors, we are effectively transforming
15157 the RTL for a memory-resident object into its Dwarf postfix expression
15158 equivalent. This routine recursively descends an RTL tree, turning
15159 it into Dwarf postfix code as it goes.
15161 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
15163 MEM_MODE is the mode of the memory reference, needed to handle some
15164 autoincrement addressing modes.
15166 Return 0 if we can't represent the location. */
15169 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
15170 machine_mode mem_mode
,
15171 enum var_init_status initialized
)
15173 dw_loc_descr_ref mem_loc_result
= NULL
;
15174 enum dwarf_location_atom op
;
15175 dw_loc_descr_ref op0
, op1
;
15176 rtx inner
= NULL_RTX
;
15179 if (mode
== VOIDmode
)
15180 mode
= GET_MODE (rtl
);
15182 /* Note that for a dynamically sized array, the location we will generate a
15183 description of here will be the lowest numbered location which is
15184 actually within the array. That's *not* necessarily the same as the
15185 zeroth element of the array. */
15187 rtl
= targetm
.delegitimize_address (rtl
);
15189 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
15192 scalar_int_mode int_mode
, inner_mode
, op1_mode
;
15193 switch (GET_CODE (rtl
))
15198 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
15201 /* The case of a subreg may arise when we have a local (register)
15202 variable or a formal (register) parameter which doesn't quite fill
15203 up an entire register. For now, just assume that it is
15204 legitimate to make the Dwarf info refer to the whole register which
15205 contains the given subreg. */
15206 if (!subreg_lowpart_p (rtl
))
15208 inner
= SUBREG_REG (rtl
);
15211 if (inner
== NULL_RTX
)
15212 inner
= XEXP (rtl
, 0);
15213 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15214 && is_a
<scalar_int_mode
> (GET_MODE (inner
), &inner_mode
)
15215 && (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15216 #ifdef POINTERS_EXTEND_UNSIGNED
15217 || (int_mode
== Pmode
&& mem_mode
!= VOIDmode
)
15220 && GET_MODE_SIZE (inner_mode
) <= DWARF2_ADDR_SIZE
)
15222 mem_loc_result
= mem_loc_descriptor (inner
,
15224 mem_mode
, initialized
);
15227 if (dwarf_strict
&& dwarf_version
< 5)
15229 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15230 && is_a
<scalar_int_mode
> (GET_MODE (inner
), &inner_mode
)
15231 ? GET_MODE_SIZE (int_mode
) <= GET_MODE_SIZE (inner_mode
)
15232 : known_eq (GET_MODE_SIZE (mode
), GET_MODE_SIZE (GET_MODE (inner
))))
15234 dw_die_ref type_die
;
15235 dw_loc_descr_ref cvt
;
15237 mem_loc_result
= mem_loc_descriptor (inner
,
15239 mem_mode
, initialized
);
15240 if (mem_loc_result
== NULL
)
15242 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15243 if (type_die
== NULL
)
15245 mem_loc_result
= NULL
;
15248 if (maybe_ne (GET_MODE_SIZE (mode
), GET_MODE_SIZE (GET_MODE (inner
))))
15249 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15251 cvt
= new_loc_descr (dwarf_OP (DW_OP_reinterpret
), 0, 0);
15252 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15253 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15254 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15255 add_loc_descr (&mem_loc_result
, cvt
);
15256 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15257 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
)
15259 /* Convert it to untyped afterwards. */
15260 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15261 add_loc_descr (&mem_loc_result
, cvt
);
15267 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15268 || (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
15269 && rtl
!= arg_pointer_rtx
15270 && rtl
!= frame_pointer_rtx
15271 #ifdef POINTERS_EXTEND_UNSIGNED
15272 && (int_mode
!= Pmode
|| mem_mode
== VOIDmode
)
15276 dw_die_ref type_die
;
15277 unsigned int dbx_regnum
;
15279 if (dwarf_strict
&& dwarf_version
< 5)
15281 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
15283 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15284 if (type_die
== NULL
)
15287 dbx_regnum
= dbx_reg_number (rtl
);
15288 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
15290 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_regval_type
),
15292 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
15293 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
15294 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
15297 /* Whenever a register number forms a part of the description of the
15298 method for calculating the (dynamic) address of a memory resident
15299 object, DWARF rules require the register number be referred to as
15300 a "base register". This distinction is not based in any way upon
15301 what category of register the hardware believes the given register
15302 belongs to. This is strictly DWARF terminology we're dealing with
15303 here. Note that in cases where the location of a memory-resident
15304 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
15305 OP_CONST (0)) the actual DWARF location descriptor that we generate
15306 may just be OP_BASEREG (basereg). This may look deceptively like
15307 the object in question was allocated to a register (rather than in
15308 memory) so DWARF consumers need to be aware of the subtle
15309 distinction between OP_REG and OP_BASEREG. */
15310 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
15311 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
15312 else if (stack_realign_drap
15314 && crtl
->args
.internal_arg_pointer
== rtl
15315 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
15317 /* If RTL is internal_arg_pointer, which has been optimized
15318 out, use DRAP instead. */
15319 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
15320 VAR_INIT_STATUS_INITIALIZED
);
15326 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15327 || !is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &inner_mode
))
15329 op0
= mem_loc_descriptor (XEXP (rtl
, 0), inner_mode
,
15330 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15333 else if (GET_CODE (rtl
) == ZERO_EXTEND
15334 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15335 && GET_MODE_BITSIZE (inner_mode
) < HOST_BITS_PER_WIDE_INT
15336 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
15337 to expand zero extend as two shifts instead of
15339 && GET_MODE_SIZE (inner_mode
) <= 4)
15341 mem_loc_result
= op0
;
15342 add_loc_descr (&mem_loc_result
,
15343 int_loc_descriptor (GET_MODE_MASK (inner_mode
)));
15344 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
15346 else if (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
)
15348 int shift
= DWARF2_ADDR_SIZE
- GET_MODE_SIZE (inner_mode
);
15349 shift
*= BITS_PER_UNIT
;
15350 if (GET_CODE (rtl
) == SIGN_EXTEND
)
15354 mem_loc_result
= op0
;
15355 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
15356 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
15357 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
15358 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15360 else if (!dwarf_strict
|| dwarf_version
>= 5)
15362 dw_die_ref type_die1
, type_die2
;
15363 dw_loc_descr_ref cvt
;
15365 type_die1
= base_type_for_mode (inner_mode
,
15366 GET_CODE (rtl
) == ZERO_EXTEND
);
15367 if (type_die1
== NULL
)
15369 type_die2
= base_type_for_mode (int_mode
, 1);
15370 if (type_die2
== NULL
)
15372 mem_loc_result
= op0
;
15373 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15374 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15375 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
15376 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15377 add_loc_descr (&mem_loc_result
, cvt
);
15378 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15379 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15380 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
15381 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15382 add_loc_descr (&mem_loc_result
, cvt
);
15388 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
15389 if (new_rtl
!= rtl
)
15391 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
15393 if (mem_loc_result
!= NULL
)
15394 return mem_loc_result
;
15397 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
15398 get_address_mode (rtl
), mode
,
15399 VAR_INIT_STATUS_INITIALIZED
);
15400 if (mem_loc_result
== NULL
)
15401 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
15402 if (mem_loc_result
!= NULL
)
15404 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15405 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15407 dw_die_ref type_die
;
15408 dw_loc_descr_ref deref
;
15409 HOST_WIDE_INT size
;
15411 if (dwarf_strict
&& dwarf_version
< 5)
15413 if (!GET_MODE_SIZE (mode
).is_constant (&size
))
15416 = base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15417 if (type_die
== NULL
)
15419 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
), size
, 0);
15420 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
15421 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
15422 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
15423 add_loc_descr (&mem_loc_result
, deref
);
15425 else if (GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
)
15426 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
15428 add_loc_descr (&mem_loc_result
,
15429 new_loc_descr (DW_OP_deref_size
,
15430 GET_MODE_SIZE (int_mode
), 0));
15435 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
15438 /* Some ports can transform a symbol ref into a label ref, because
15439 the symbol ref is too far away and has to be dumped into a constant
15443 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15444 || (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
15445 #ifdef POINTERS_EXTEND_UNSIGNED
15446 && (int_mode
!= Pmode
|| mem_mode
== VOIDmode
)
15450 if (GET_CODE (rtl
) == SYMBOL_REF
15451 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
15453 dw_loc_descr_ref temp
;
15455 /* If this is not defined, we have no way to emit the data. */
15456 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
15459 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
15461 /* We check for DWARF 5 here because gdb did not implement
15462 DW_OP_form_tls_address until after 7.12. */
15463 mem_loc_result
= new_loc_descr ((dwarf_version
>= 5
15464 ? DW_OP_form_tls_address
15465 : DW_OP_GNU_push_tls_address
),
15467 add_loc_descr (&mem_loc_result
, temp
);
15472 if (!const_ok_for_output (rtl
))
15474 if (GET_CODE (rtl
) == CONST
)
15475 switch (GET_CODE (XEXP (rtl
, 0)))
15479 goto try_const_unop
;
15482 goto try_const_unop
;
15485 arg
= XEXP (XEXP (rtl
, 0), 0);
15486 if (!CONSTANT_P (arg
))
15487 arg
= gen_rtx_CONST (int_mode
, arg
);
15488 op0
= mem_loc_descriptor (arg
, int_mode
, mem_mode
,
15492 mem_loc_result
= op0
;
15493 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15497 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), int_mode
,
15498 mem_mode
, initialized
);
15505 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15506 vec_safe_push (used_rtx_array
, rtl
);
15512 case DEBUG_IMPLICIT_PTR
:
15513 expansion_failed (NULL_TREE
, rtl
,
15514 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
15518 if (dwarf_strict
&& dwarf_version
< 5)
15520 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
15522 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15523 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15524 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
15525 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15528 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
15529 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
15531 op0
= one_reg_loc_descriptor (dbx_regnum
,
15532 VAR_INIT_STATUS_INITIALIZED
);
15535 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
15536 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
15538 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
15539 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15540 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
15544 gcc_unreachable ();
15547 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_entry_value
), 0, 0);
15548 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15549 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
15552 case DEBUG_PARAMETER_REF
:
15553 mem_loc_result
= parameter_ref_descriptor (rtl
);
15557 /* Extract the PLUS expression nested inside and fall into
15558 PLUS code below. */
15559 rtl
= XEXP (rtl
, 1);
15564 /* Turn these into a PLUS expression and fall into the PLUS code
15566 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
15567 gen_int_mode (GET_CODE (rtl
) == PRE_INC
15568 ? GET_MODE_UNIT_SIZE (mem_mode
)
15569 : -GET_MODE_UNIT_SIZE (mem_mode
),
15576 if (is_based_loc (rtl
)
15577 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15578 && (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15579 || XEXP (rtl
, 0) == arg_pointer_rtx
15580 || XEXP (rtl
, 0) == frame_pointer_rtx
))
15581 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
15582 INTVAL (XEXP (rtl
, 1)),
15583 VAR_INIT_STATUS_INITIALIZED
);
15586 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15587 VAR_INIT_STATUS_INITIALIZED
);
15588 if (mem_loc_result
== 0)
15591 if (CONST_INT_P (XEXP (rtl
, 1))
15592 && (GET_MODE_SIZE (as_a
<scalar_int_mode
> (mode
))
15593 <= DWARF2_ADDR_SIZE
))
15594 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
15597 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15598 VAR_INIT_STATUS_INITIALIZED
);
15601 add_loc_descr (&mem_loc_result
, op1
);
15602 add_loc_descr (&mem_loc_result
,
15603 new_loc_descr (DW_OP_plus
, 0, 0));
15608 /* If a pseudo-reg is optimized away, it is possible for it to
15609 be replaced with a MEM containing a multiply or shift. */
15619 if ((!dwarf_strict
|| dwarf_version
>= 5)
15620 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15621 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15623 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
15624 base_type_for_mode (mode
, 0),
15625 int_mode
, mem_mode
);
15648 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
))
15650 op0
= mem_loc_descriptor (XEXP (rtl
, 0), int_mode
, mem_mode
,
15651 VAR_INIT_STATUS_INITIALIZED
);
15653 rtx rtlop1
= XEXP (rtl
, 1);
15654 if (is_a
<scalar_int_mode
> (GET_MODE (rtlop1
), &op1_mode
)
15655 && GET_MODE_BITSIZE (op1_mode
) < GET_MODE_BITSIZE (int_mode
))
15656 rtlop1
= gen_rtx_ZERO_EXTEND (int_mode
, rtlop1
);
15657 op1
= mem_loc_descriptor (rtlop1
, int_mode
, mem_mode
,
15658 VAR_INIT_STATUS_INITIALIZED
);
15661 if (op0
== 0 || op1
== 0)
15664 mem_loc_result
= op0
;
15665 add_loc_descr (&mem_loc_result
, op1
);
15666 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15682 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15683 VAR_INIT_STATUS_INITIALIZED
);
15684 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15685 VAR_INIT_STATUS_INITIALIZED
);
15687 if (op0
== 0 || op1
== 0)
15690 mem_loc_result
= op0
;
15691 add_loc_descr (&mem_loc_result
, op1
);
15692 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15696 if ((!dwarf_strict
|| dwarf_version
>= 5)
15697 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15698 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15700 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
15701 base_type_for_mode (mode
, 0),
15702 int_mode
, mem_mode
);
15706 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15707 VAR_INIT_STATUS_INITIALIZED
);
15708 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15709 VAR_INIT_STATUS_INITIALIZED
);
15711 if (op0
== 0 || op1
== 0)
15714 mem_loc_result
= op0
;
15715 add_loc_descr (&mem_loc_result
, op1
);
15716 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15717 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15718 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
15719 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
15720 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
15724 if ((!dwarf_strict
|| dwarf_version
>= 5)
15725 && is_a
<scalar_int_mode
> (mode
, &int_mode
))
15727 if (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15732 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
15733 base_type_for_mode (int_mode
, 1),
15734 int_mode
, mem_mode
);
15751 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15752 VAR_INIT_STATUS_INITIALIZED
);
15757 mem_loc_result
= op0
;
15758 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15762 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15763 || GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15764 #ifdef POINTERS_EXTEND_UNSIGNED
15765 || (int_mode
== Pmode
15766 && mem_mode
!= VOIDmode
15767 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
15771 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15774 if ((!dwarf_strict
|| dwarf_version
>= 5)
15775 && (GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_WIDE_INT
15776 || GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_DOUBLE_INT
))
15778 dw_die_ref type_die
= base_type_for_mode (int_mode
, 1);
15779 scalar_int_mode amode
;
15780 if (type_die
== NULL
)
15782 if (INTVAL (rtl
) >= 0
15783 && (int_mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
, 0)
15785 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
15786 /* const DW_OP_convert <XXX> vs.
15787 DW_OP_const_type <XXX, 1, const>. */
15788 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
15789 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (int_mode
))
15791 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15792 op0
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15793 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15794 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15795 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15796 add_loc_descr (&mem_loc_result
, op0
);
15797 return mem_loc_result
;
15799 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0,
15801 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15802 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15803 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15804 if (GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_WIDE_INT
)
15805 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15808 mem_loc_result
->dw_loc_oprnd2
.val_class
15809 = dw_val_class_const_double
;
15810 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15811 = double_int::from_shwi (INTVAL (rtl
));
15817 if (!dwarf_strict
|| dwarf_version
>= 5)
15819 dw_die_ref type_die
;
15821 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
15822 CONST_DOUBLE rtx could represent either a large integer
15823 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
15824 the value is always a floating point constant.
15826 When it is an integer, a CONST_DOUBLE is used whenever
15827 the constant requires 2 HWIs to be adequately represented.
15828 We output CONST_DOUBLEs as blocks. */
15829 if (mode
== VOIDmode
15830 || (GET_MODE (rtl
) == VOIDmode
15831 && maybe_ne (GET_MODE_BITSIZE (mode
),
15832 HOST_BITS_PER_DOUBLE_INT
)))
15834 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15835 if (type_die
== NULL
)
15837 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15838 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15839 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15840 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15841 #if TARGET_SUPPORTS_WIDE_INT == 0
15842 if (!SCALAR_FLOAT_MODE_P (mode
))
15844 mem_loc_result
->dw_loc_oprnd2
.val_class
15845 = dw_val_class_const_double
;
15846 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15847 = rtx_to_double_int (rtl
);
15852 scalar_float_mode float_mode
= as_a
<scalar_float_mode
> (mode
);
15853 unsigned int length
= GET_MODE_SIZE (float_mode
);
15854 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15856 insert_float (rtl
, array
);
15857 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15858 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15859 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15860 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15865 case CONST_WIDE_INT
:
15866 if (!dwarf_strict
|| dwarf_version
>= 5)
15868 dw_die_ref type_die
;
15870 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15871 if (type_die
== NULL
)
15873 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15874 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15875 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15876 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15877 mem_loc_result
->dw_loc_oprnd2
.val_class
15878 = dw_val_class_wide_int
;
15879 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15880 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15884 case CONST_POLY_INT
:
15885 mem_loc_result
= int_loc_descriptor (rtx_to_poly_int64 (rtl
));
15889 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
15893 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15897 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15901 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15905 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15909 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
15913 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15917 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15921 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15925 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15930 if (!SCALAR_INT_MODE_P (mode
))
15935 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
15940 if (CONST_INT_P (XEXP (rtl
, 1))
15941 && CONST_INT_P (XEXP (rtl
, 2))
15942 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15943 && is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &inner_mode
)
15944 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15945 && GET_MODE_SIZE (inner_mode
) <= DWARF2_ADDR_SIZE
15946 && ((unsigned) INTVAL (XEXP (rtl
, 1))
15947 + (unsigned) INTVAL (XEXP (rtl
, 2))
15948 <= GET_MODE_BITSIZE (int_mode
)))
15951 op0
= mem_loc_descriptor (XEXP (rtl
, 0), inner_mode
,
15952 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15955 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
15959 mem_loc_result
= op0
;
15960 size
= INTVAL (XEXP (rtl
, 1));
15961 shift
= INTVAL (XEXP (rtl
, 2));
15962 if (BITS_BIG_ENDIAN
)
15963 shift
= GET_MODE_BITSIZE (inner_mode
) - shift
- size
;
15964 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
15966 add_loc_descr (&mem_loc_result
,
15967 int_loc_descriptor (DWARF2_ADDR_SIZE
15969 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
15971 if (size
!= (int) DWARF2_ADDR_SIZE
)
15973 add_loc_descr (&mem_loc_result
,
15974 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
15975 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15982 dw_loc_descr_ref op2
, bra_node
, drop_node
;
15983 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
15984 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
15985 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
15986 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15987 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15988 VAR_INIT_STATUS_INITIALIZED
);
15989 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
15990 VAR_INIT_STATUS_INITIALIZED
);
15991 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
15994 mem_loc_result
= op1
;
15995 add_loc_descr (&mem_loc_result
, op2
);
15996 add_loc_descr (&mem_loc_result
, op0
);
15997 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15998 add_loc_descr (&mem_loc_result
, bra_node
);
15999 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
16000 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
16001 add_loc_descr (&mem_loc_result
, drop_node
);
16002 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16003 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
16008 case FLOAT_TRUNCATE
:
16010 case UNSIGNED_FLOAT
:
16013 if (!dwarf_strict
|| dwarf_version
>= 5)
16015 dw_die_ref type_die
;
16016 dw_loc_descr_ref cvt
;
16018 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
16019 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
16022 if (is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &int_mode
)
16023 && (GET_CODE (rtl
) == FLOAT
16024 || GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
))
16026 type_die
= base_type_for_mode (int_mode
,
16027 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
16028 if (type_die
== NULL
)
16030 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16031 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16032 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16033 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16034 add_loc_descr (&op0
, cvt
);
16036 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
16037 if (type_die
== NULL
)
16039 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16040 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16041 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16042 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16043 add_loc_descr (&op0
, cvt
);
16044 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
16045 && (GET_CODE (rtl
) == FIX
16046 || GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
))
16048 op0
= convert_descriptor_to_mode (int_mode
, op0
);
16052 mem_loc_result
= op0
;
16059 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16060 mem_loc_result
= clz_loc_descriptor (rtl
, int_mode
, mem_mode
);
16065 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16066 mem_loc_result
= popcount_loc_descriptor (rtl
, int_mode
, mem_mode
);
16070 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16071 mem_loc_result
= bswap_loc_descriptor (rtl
, int_mode
, mem_mode
);
16076 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16077 mem_loc_result
= rotate_loc_descriptor (rtl
, int_mode
, mem_mode
);
16081 /* In theory, we could implement the above. */
16082 /* DWARF cannot represent the unsigned compare operations
16107 case FRACT_CONVERT
:
16108 case UNSIGNED_FRACT_CONVERT
:
16110 case UNSIGNED_SAT_FRACT
:
16116 case VEC_DUPLICATE
:
16121 case STRICT_LOW_PART
:
16126 /* If delegitimize_address couldn't do anything with the UNSPEC, we
16127 can't express it in the debug info. This can happen e.g. with some
16132 resolve_one_addr (&rtl
);
16135 /* RTL sequences inside PARALLEL record a series of DWARF operations for
16136 the expression. An UNSPEC rtx represents a raw DWARF operation,
16137 new_loc_descr is called for it to build the operation directly.
16138 Otherwise mem_loc_descriptor is called recursively. */
16142 dw_loc_descr_ref exp_result
= NULL
;
16144 for (; index
< XVECLEN (rtl
, 0); index
++)
16146 rtx elem
= XVECEXP (rtl
, 0, index
);
16147 if (GET_CODE (elem
) == UNSPEC
)
16149 /* Each DWARF operation UNSPEC contain two operands, if
16150 one operand is not used for the operation, const0_rtx is
16152 gcc_assert (XVECLEN (elem
, 0) == 2);
16154 HOST_WIDE_INT dw_op
= XINT (elem
, 1);
16155 HOST_WIDE_INT oprnd1
= INTVAL (XVECEXP (elem
, 0, 0));
16156 HOST_WIDE_INT oprnd2
= INTVAL (XVECEXP (elem
, 0, 1));
16158 = new_loc_descr ((enum dwarf_location_atom
) dw_op
, oprnd1
,
16163 = mem_loc_descriptor (elem
, mode
, mem_mode
,
16164 VAR_INIT_STATUS_INITIALIZED
);
16166 if (!mem_loc_result
)
16167 mem_loc_result
= exp_result
;
16169 add_loc_descr (&mem_loc_result
, exp_result
);
16178 print_rtl (stderr
, rtl
);
16179 gcc_unreachable ();
16184 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
16185 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
16187 return mem_loc_result
;
16190 /* Return a descriptor that describes the concatenation of two locations.
16191 This is typically a complex variable. */
16193 static dw_loc_descr_ref
16194 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
16196 /* At present we only track constant-sized pieces. */
16197 unsigned int size0
, size1
;
16198 if (!GET_MODE_SIZE (GET_MODE (x0
)).is_constant (&size0
)
16199 || !GET_MODE_SIZE (GET_MODE (x1
)).is_constant (&size1
))
16202 dw_loc_descr_ref cc_loc_result
= NULL
;
16203 dw_loc_descr_ref x0_ref
16204 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
16205 dw_loc_descr_ref x1_ref
16206 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
16208 if (x0_ref
== 0 || x1_ref
== 0)
16211 cc_loc_result
= x0_ref
;
16212 add_loc_descr_op_piece (&cc_loc_result
, size0
);
16214 add_loc_descr (&cc_loc_result
, x1_ref
);
16215 add_loc_descr_op_piece (&cc_loc_result
, size1
);
16217 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
16218 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
16220 return cc_loc_result
;
16223 /* Return a descriptor that describes the concatenation of N
16226 static dw_loc_descr_ref
16227 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
16230 dw_loc_descr_ref cc_loc_result
= NULL
;
16231 unsigned int n
= XVECLEN (concatn
, 0);
16234 for (i
= 0; i
< n
; ++i
)
16236 dw_loc_descr_ref ref
;
16237 rtx x
= XVECEXP (concatn
, 0, i
);
16239 /* At present we only track constant-sized pieces. */
16240 if (!GET_MODE_SIZE (GET_MODE (x
)).is_constant (&size
))
16243 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
16247 add_loc_descr (&cc_loc_result
, ref
);
16248 add_loc_descr_op_piece (&cc_loc_result
, size
);
16251 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
16252 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
16254 return cc_loc_result
;
16257 /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
16258 for DEBUG_IMPLICIT_PTR RTL. */
16260 static dw_loc_descr_ref
16261 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
16263 dw_loc_descr_ref ret
;
16266 if (dwarf_strict
&& dwarf_version
< 5)
16268 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
16269 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
16270 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
16271 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
16272 ret
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
16273 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
16276 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16277 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
16278 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16282 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
16283 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
16288 /* Output a proper Dwarf location descriptor for a variable or parameter
16289 which is either allocated in a register or in a memory location. For a
16290 register, we just generate an OP_REG and the register number. For a
16291 memory location we provide a Dwarf postfix expression describing how to
16292 generate the (dynamic) address of the object onto the address stack.
16294 MODE is mode of the decl if this loc_descriptor is going to be used in
16295 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
16296 allowed, VOIDmode otherwise.
16298 If we don't know how to describe it, return 0. */
16300 static dw_loc_descr_ref
16301 loc_descriptor (rtx rtl
, machine_mode mode
,
16302 enum var_init_status initialized
)
16304 dw_loc_descr_ref loc_result
= NULL
;
16305 scalar_int_mode int_mode
;
16307 switch (GET_CODE (rtl
))
16310 /* The case of a subreg may arise when we have a local (register)
16311 variable or a formal (register) parameter which doesn't quite fill
16312 up an entire register. For now, just assume that it is
16313 legitimate to make the Dwarf info refer to the whole register which
16314 contains the given subreg. */
16315 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
16316 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
16317 GET_MODE (SUBREG_REG (rtl
)), initialized
);
16323 loc_result
= reg_loc_descriptor (rtl
, initialized
);
16327 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
16328 GET_MODE (rtl
), initialized
);
16329 if (loc_result
== NULL
)
16330 loc_result
= tls_mem_loc_descriptor (rtl
);
16331 if (loc_result
== NULL
)
16333 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
16334 if (new_rtl
!= rtl
)
16335 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
16340 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
16345 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
16350 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
16352 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
16353 if (GET_CODE (loc
) == EXPR_LIST
)
16354 loc
= XEXP (loc
, 0);
16355 loc_result
= loc_descriptor (loc
, mode
, initialized
);
16359 rtl
= XEXP (rtl
, 1);
16364 rtvec par_elems
= XVEC (rtl
, 0);
16365 int num_elem
= GET_NUM_ELEM (par_elems
);
16369 /* Create the first one, so we have something to add to. */
16370 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
16371 VOIDmode
, initialized
);
16372 if (loc_result
== NULL
)
16374 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
16375 /* At present we only track constant-sized pieces. */
16376 if (!GET_MODE_SIZE (mode
).is_constant (&size
))
16378 add_loc_descr_op_piece (&loc_result
, size
);
16379 for (i
= 1; i
< num_elem
; i
++)
16381 dw_loc_descr_ref temp
;
16383 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
16384 VOIDmode
, initialized
);
16387 add_loc_descr (&loc_result
, temp
);
16388 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
16389 /* At present we only track constant-sized pieces. */
16390 if (!GET_MODE_SIZE (mode
).is_constant (&size
))
16392 add_loc_descr_op_piece (&loc_result
, size
);
16398 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
16400 int_mode
= as_a
<scalar_int_mode
> (mode
);
16401 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (int_mode
),
16407 if (mode
== VOIDmode
)
16408 mode
= GET_MODE (rtl
);
16410 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
16412 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
16414 /* Note that a CONST_DOUBLE rtx could represent either an integer
16415 or a floating-point constant. A CONST_DOUBLE is used whenever
16416 the constant requires more than one word in order to be
16417 adequately represented. We output CONST_DOUBLEs as blocks. */
16418 scalar_mode smode
= as_a
<scalar_mode
> (mode
);
16419 loc_result
= new_loc_descr (DW_OP_implicit_value
,
16420 GET_MODE_SIZE (smode
), 0);
16421 #if TARGET_SUPPORTS_WIDE_INT == 0
16422 if (!SCALAR_FLOAT_MODE_P (smode
))
16424 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
16425 loc_result
->dw_loc_oprnd2
.v
.val_double
16426 = rtx_to_double_int (rtl
);
16431 unsigned int length
= GET_MODE_SIZE (smode
);
16432 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
16434 insert_float (rtl
, array
);
16435 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
16436 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
16437 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
16438 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
16443 case CONST_WIDE_INT
:
16444 if (mode
== VOIDmode
)
16445 mode
= GET_MODE (rtl
);
16447 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
16449 int_mode
= as_a
<scalar_int_mode
> (mode
);
16450 loc_result
= new_loc_descr (DW_OP_implicit_value
,
16451 GET_MODE_SIZE (int_mode
), 0);
16452 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
16453 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
16454 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, int_mode
);
16459 if (mode
== VOIDmode
)
16460 mode
= GET_MODE (rtl
);
16462 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
16464 unsigned int length
;
16465 if (!CONST_VECTOR_NUNITS (rtl
).is_constant (&length
))
16468 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
16469 unsigned char *array
16470 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
16473 machine_mode imode
= GET_MODE_INNER (mode
);
16475 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
16476 switch (GET_MODE_CLASS (mode
))
16478 case MODE_VECTOR_INT
:
16479 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16481 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16482 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
16486 case MODE_VECTOR_FLOAT
:
16487 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16489 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16490 insert_float (elt
, p
);
16495 gcc_unreachable ();
16498 loc_result
= new_loc_descr (DW_OP_implicit_value
,
16499 length
* elt_size
, 0);
16500 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
16501 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
16502 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
16503 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
16508 if (mode
== VOIDmode
16509 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
16510 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
16511 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
16513 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
16518 if (!const_ok_for_output (rtl
))
16522 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
16523 && GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
16524 && (dwarf_version
>= 4 || !dwarf_strict
))
16526 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
16527 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16528 vec_safe_push (used_rtx_array
, rtl
);
16532 case DEBUG_IMPLICIT_PTR
:
16533 loc_result
= implicit_ptr_descriptor (rtl
, 0);
16537 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
16538 && CONST_INT_P (XEXP (rtl
, 1)))
16541 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
16547 if ((is_a
<scalar_int_mode
> (mode
, &int_mode
)
16548 && GET_MODE (rtl
) == int_mode
16549 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16550 && dwarf_version
>= 4)
16551 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
16553 /* Value expression. */
16554 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
16556 add_loc_descr (&loc_result
,
16557 new_loc_descr (DW_OP_stack_value
, 0, 0));
16565 /* We need to figure out what section we should use as the base for the
16566 address ranges where a given location is valid.
16567 1. If this particular DECL has a section associated with it, use that.
16568 2. If this function has a section associated with it, use that.
16569 3. Otherwise, use the text section.
16570 XXX: If you split a variable across multiple sections, we won't notice. */
16572 static const char *
16573 secname_for_decl (const_tree decl
)
16575 const char *secname
;
16577 if (VAR_OR_FUNCTION_DECL_P (decl
)
16578 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
16579 && DECL_SECTION_NAME (decl
))
16580 secname
= DECL_SECTION_NAME (decl
);
16581 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
16582 secname
= DECL_SECTION_NAME (current_function_decl
);
16583 else if (cfun
&& in_cold_section_p
)
16584 secname
= crtl
->subsections
.cold_section_label
;
16586 secname
= text_section_label
;
16591 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
16594 decl_by_reference_p (tree decl
)
16596 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
16598 && DECL_BY_REFERENCE (decl
));
16601 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
16604 static dw_loc_descr_ref
16605 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
16606 enum var_init_status initialized
)
16608 int have_address
= 0;
16609 dw_loc_descr_ref descr
;
16612 if (want_address
!= 2)
16614 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
16616 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
16618 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
16619 if (GET_CODE (varloc
) == EXPR_LIST
)
16620 varloc
= XEXP (varloc
, 0);
16621 mode
= GET_MODE (varloc
);
16622 if (MEM_P (varloc
))
16624 rtx addr
= XEXP (varloc
, 0);
16625 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
16626 mode
, initialized
);
16631 rtx x
= avoid_constant_pool_reference (varloc
);
16633 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
16638 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
16645 if (GET_CODE (varloc
) == VAR_LOCATION
)
16646 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
16648 mode
= DECL_MODE (loc
);
16649 descr
= loc_descriptor (varloc
, mode
, initialized
);
16656 if (want_address
== 2 && !have_address
16657 && (dwarf_version
>= 4 || !dwarf_strict
))
16659 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
16661 expansion_failed (loc
, NULL_RTX
,
16662 "DWARF address size mismatch");
16665 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16668 /* Show if we can't fill the request for an address. */
16669 if (want_address
&& !have_address
)
16671 expansion_failed (loc
, NULL_RTX
,
16672 "Want address and only have value");
16676 /* If we've got an address and don't want one, dereference. */
16677 if (!want_address
&& have_address
)
16679 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
16680 enum dwarf_location_atom op
;
16682 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
16684 expansion_failed (loc
, NULL_RTX
,
16685 "DWARF address size mismatch");
16688 else if (size
== DWARF2_ADDR_SIZE
)
16691 op
= DW_OP_deref_size
;
16693 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
16699 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
16700 if it is not possible. */
16702 static dw_loc_descr_ref
16703 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
16705 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
16706 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
16707 else if (dwarf_version
>= 3 || !dwarf_strict
)
16708 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
16713 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
16714 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
16716 static dw_loc_descr_ref
16717 dw_sra_loc_expr (tree decl
, rtx loc
)
16720 unsigned HOST_WIDE_INT padsize
= 0;
16721 dw_loc_descr_ref descr
, *descr_tail
;
16722 unsigned HOST_WIDE_INT decl_size
;
16724 enum var_init_status initialized
;
16726 if (DECL_SIZE (decl
) == NULL
16727 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
16730 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
16732 descr_tail
= &descr
;
16734 for (p
= loc
; p
; p
= XEXP (p
, 1))
16736 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
16737 rtx loc_note
= *decl_piece_varloc_ptr (p
);
16738 dw_loc_descr_ref cur_descr
;
16739 dw_loc_descr_ref
*tail
, last
= NULL
;
16740 unsigned HOST_WIDE_INT opsize
= 0;
16742 if (loc_note
== NULL_RTX
16743 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
16745 padsize
+= bitsize
;
16748 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
16749 varloc
= NOTE_VAR_LOCATION (loc_note
);
16750 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
16751 if (cur_descr
== NULL
)
16753 padsize
+= bitsize
;
16757 /* Check that cur_descr either doesn't use
16758 DW_OP_*piece operations, or their sum is equal
16759 to bitsize. Otherwise we can't embed it. */
16760 for (tail
= &cur_descr
; *tail
!= NULL
;
16761 tail
= &(*tail
)->dw_loc_next
)
16762 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
16764 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
16768 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
16770 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
16774 if (last
!= NULL
&& opsize
!= bitsize
)
16776 padsize
+= bitsize
;
16777 /* Discard the current piece of the descriptor and release any
16778 addr_table entries it uses. */
16779 remove_loc_list_addr_table_entries (cur_descr
);
16783 /* If there is a hole, add DW_OP_*piece after empty DWARF
16784 expression, which means that those bits are optimized out. */
16787 if (padsize
> decl_size
)
16789 remove_loc_list_addr_table_entries (cur_descr
);
16790 goto discard_descr
;
16792 decl_size
-= padsize
;
16793 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
16794 if (*descr_tail
== NULL
)
16796 remove_loc_list_addr_table_entries (cur_descr
);
16797 goto discard_descr
;
16799 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16802 *descr_tail
= cur_descr
;
16804 if (bitsize
> decl_size
)
16805 goto discard_descr
;
16806 decl_size
-= bitsize
;
16809 HOST_WIDE_INT offset
= 0;
16810 if (GET_CODE (varloc
) == VAR_LOCATION
16811 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
16813 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
16814 if (GET_CODE (varloc
) == EXPR_LIST
)
16815 varloc
= XEXP (varloc
, 0);
16819 if (GET_CODE (varloc
) == CONST
16820 || GET_CODE (varloc
) == SIGN_EXTEND
16821 || GET_CODE (varloc
) == ZERO_EXTEND
)
16822 varloc
= XEXP (varloc
, 0);
16823 else if (GET_CODE (varloc
) == SUBREG
)
16824 varloc
= SUBREG_REG (varloc
);
16829 /* DW_OP_bit_size offset should be zero for register
16830 or implicit location descriptions and empty location
16831 descriptions, but for memory addresses needs big endian
16833 if (MEM_P (varloc
))
16835 unsigned HOST_WIDE_INT memsize
;
16836 if (!poly_uint64 (MEM_SIZE (varloc
)).is_constant (&memsize
))
16837 goto discard_descr
;
16838 memsize
*= BITS_PER_UNIT
;
16839 if (memsize
!= bitsize
)
16841 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
16842 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
16843 goto discard_descr
;
16844 if (memsize
< bitsize
)
16845 goto discard_descr
;
16846 if (BITS_BIG_ENDIAN
)
16847 offset
= memsize
- bitsize
;
16851 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
16852 if (*descr_tail
== NULL
)
16853 goto discard_descr
;
16854 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16858 /* If there were any non-empty expressions, add padding till the end of
16860 if (descr
!= NULL
&& decl_size
!= 0)
16862 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
16863 if (*descr_tail
== NULL
)
16864 goto discard_descr
;
16869 /* Discard the descriptor and release any addr_table entries it uses. */
16870 remove_loc_list_addr_table_entries (descr
);
16874 /* Return the dwarf representation of the location list LOC_LIST of
16875 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
16878 static dw_loc_list_ref
16879 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
16881 const char *endname
, *secname
;
16882 var_loc_view endview
;
16884 enum var_init_status initialized
;
16885 struct var_loc_node
*node
;
16886 dw_loc_descr_ref descr
;
16887 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
16888 dw_loc_list_ref list
= NULL
;
16889 dw_loc_list_ref
*listp
= &list
;
16891 /* Now that we know what section we are using for a base,
16892 actually construct the list of locations.
16893 The first location information is what is passed to the
16894 function that creates the location list, and the remaining
16895 locations just get added on to that list.
16896 Note that we only know the start address for a location
16897 (IE location changes), so to build the range, we use
16898 the range [current location start, next location start].
16899 This means we have to special case the last node, and generate
16900 a range of [last location start, end of function label]. */
16902 if (cfun
&& crtl
->has_bb_partition
)
16904 bool save_in_cold_section_p
= in_cold_section_p
;
16905 in_cold_section_p
= first_function_block_is_cold
;
16906 if (loc_list
->last_before_switch
== NULL
)
16907 in_cold_section_p
= !in_cold_section_p
;
16908 secname
= secname_for_decl (decl
);
16909 in_cold_section_p
= save_in_cold_section_p
;
16912 secname
= secname_for_decl (decl
);
16914 for (node
= loc_list
->first
; node
; node
= node
->next
)
16916 bool range_across_switch
= false;
16917 if (GET_CODE (node
->loc
) == EXPR_LIST
16918 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
16920 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16923 /* This requires DW_OP_{,bit_}piece, which is not usable
16924 inside DWARF expressions. */
16925 if (want_address
== 2)
16926 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16930 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16931 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16932 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
16936 /* If section switch happens in between node->label
16937 and node->next->label (or end of function) and
16938 we can't emit it as a single entry list,
16939 emit two ranges, first one ending at the end
16940 of first partition and second one starting at the
16941 beginning of second partition. */
16942 if (node
== loc_list
->last_before_switch
16943 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
16944 && current_function_decl
)
16946 endname
= cfun
->fde
->dw_fde_end
;
16948 range_across_switch
= true;
16950 /* The variable has a location between NODE->LABEL and
16951 NODE->NEXT->LABEL. */
16952 else if (node
->next
)
16953 endname
= node
->next
->label
, endview
= node
->next
->view
;
16954 /* If the variable has a location at the last label
16955 it keeps its location until the end of function. */
16956 else if (!current_function_decl
)
16957 endname
= text_end_label
, endview
= 0;
16960 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
16961 current_function_funcdef_no
);
16962 endname
= ggc_strdup (label_id
);
16966 *listp
= new_loc_list (descr
, node
->label
, node
->view
,
16967 endname
, endview
, secname
);
16968 if (TREE_CODE (decl
) == PARM_DECL
16969 && node
== loc_list
->first
16970 && NOTE_P (node
->loc
)
16971 && strcmp (node
->label
, endname
) == 0)
16972 (*listp
)->force
= true;
16973 listp
= &(*listp
)->dw_loc_next
;
16978 && crtl
->has_bb_partition
16979 && node
== loc_list
->last_before_switch
)
16981 bool save_in_cold_section_p
= in_cold_section_p
;
16982 in_cold_section_p
= !first_function_block_is_cold
;
16983 secname
= secname_for_decl (decl
);
16984 in_cold_section_p
= save_in_cold_section_p
;
16987 if (range_across_switch
)
16989 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16990 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16993 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16994 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16995 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
16998 gcc_assert (descr
);
16999 /* The variable has a location between NODE->LABEL and
17000 NODE->NEXT->LABEL. */
17002 endname
= node
->next
->label
, endview
= node
->next
->view
;
17004 endname
= cfun
->fde
->dw_fde_second_end
, endview
= 0;
17005 *listp
= new_loc_list (descr
, cfun
->fde
->dw_fde_second_begin
, 0,
17006 endname
, endview
, secname
);
17007 listp
= &(*listp
)->dw_loc_next
;
17011 /* Try to avoid the overhead of a location list emitting a location
17012 expression instead, but only if we didn't have more than one
17013 location entry in the first place. If some entries were not
17014 representable, we don't want to pretend a single entry that was
17015 applies to the entire scope in which the variable is
17017 maybe_gen_llsym (list
);
17022 /* Return if the loc_list has only single element and thus can be represented
17023 as location description. */
17026 single_element_loc_list_p (dw_loc_list_ref list
)
17028 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
17029 return !list
->ll_symbol
;
17032 /* Duplicate a single element of location list. */
17034 static inline dw_loc_descr_ref
17035 copy_loc_descr (dw_loc_descr_ref ref
)
17037 dw_loc_descr_ref copy
= ggc_alloc
<dw_loc_descr_node
> ();
17038 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
17042 /* To each location in list LIST append loc descr REF. */
17045 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
17047 dw_loc_descr_ref copy
;
17048 add_loc_descr (&list
->expr
, ref
);
17049 list
= list
->dw_loc_next
;
17052 copy
= copy_loc_descr (ref
);
17053 add_loc_descr (&list
->expr
, copy
);
17054 while (copy
->dw_loc_next
)
17055 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
17056 list
= list
->dw_loc_next
;
17060 /* To each location in list LIST prepend loc descr REF. */
17063 prepend_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
17065 dw_loc_descr_ref copy
;
17066 dw_loc_descr_ref ref_end
= list
->expr
;
17067 add_loc_descr (&ref
, list
->expr
);
17069 list
= list
->dw_loc_next
;
17072 dw_loc_descr_ref end
= list
->expr
;
17073 list
->expr
= copy
= copy_loc_descr (ref
);
17074 while (copy
->dw_loc_next
!= ref_end
)
17075 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
17076 copy
->dw_loc_next
= end
;
17077 list
= list
->dw_loc_next
;
17081 /* Given two lists RET and LIST
17082 produce location list that is result of adding expression in LIST
17083 to expression in RET on each position in program.
17084 Might be destructive on both RET and LIST.
17086 TODO: We handle only simple cases of RET or LIST having at most one
17087 element. General case would involve sorting the lists in program order
17088 and merging them that will need some additional work.
17089 Adding that will improve quality of debug info especially for SRA-ed
17093 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
17102 if (!list
->dw_loc_next
)
17104 add_loc_descr_to_each (*ret
, list
->expr
);
17107 if (!(*ret
)->dw_loc_next
)
17109 prepend_loc_descr_to_each (list
, (*ret
)->expr
);
17113 expansion_failed (NULL_TREE
, NULL_RTX
,
17114 "Don't know how to merge two non-trivial"
17115 " location lists.\n");
17120 /* LOC is constant expression. Try a luck, look it up in constant
17121 pool and return its loc_descr of its address. */
17123 static dw_loc_descr_ref
17124 cst_pool_loc_descr (tree loc
)
17126 /* Get an RTL for this, if something has been emitted. */
17127 rtx rtl
= lookup_constant_def (loc
);
17129 if (!rtl
|| !MEM_P (rtl
))
17134 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
17136 /* TODO: We might get more coverage if we was actually delaying expansion
17137 of all expressions till end of compilation when constant pools are fully
17139 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
17141 expansion_failed (loc
, NULL_RTX
,
17142 "CST value in contant pool but not marked.");
17145 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
17146 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
17149 /* Return dw_loc_list representing address of addr_expr LOC
17150 by looking for inner INDIRECT_REF expression and turning
17151 it into simple arithmetics.
17153 See loc_list_from_tree for the meaning of CONTEXT. */
17155 static dw_loc_list_ref
17156 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
17157 loc_descr_context
*context
)
17160 poly_int64 bitsize
, bitpos
, bytepos
;
17162 int unsignedp
, reversep
, volatilep
= 0;
17163 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
17165 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
17166 &bitsize
, &bitpos
, &offset
, &mode
,
17167 &unsignedp
, &reversep
, &volatilep
);
17169 if (!multiple_p (bitpos
, BITS_PER_UNIT
, &bytepos
))
17171 expansion_failed (loc
, NULL_RTX
, "bitfield access");
17174 if (!INDIRECT_REF_P (obj
))
17176 expansion_failed (obj
,
17177 NULL_RTX
, "no indirect ref in inner refrence");
17180 if (!offset
&& known_eq (bitpos
, 0))
17181 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
17184 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
17185 && (dwarf_version
>= 4 || !dwarf_strict
))
17187 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
17192 /* Variable offset. */
17193 list_ret1
= loc_list_from_tree (offset
, 0, context
);
17194 if (list_ret1
== 0)
17196 add_loc_list (&list_ret
, list_ret1
);
17199 add_loc_descr_to_each (list_ret
,
17200 new_loc_descr (DW_OP_plus
, 0, 0));
17202 HOST_WIDE_INT value
;
17203 if (bytepos
.is_constant (&value
) && value
> 0)
17204 add_loc_descr_to_each (list_ret
,
17205 new_loc_descr (DW_OP_plus_uconst
, value
, 0));
17206 else if (maybe_ne (bytepos
, 0))
17207 loc_list_plus_const (list_ret
, bytepos
);
17208 add_loc_descr_to_each (list_ret
,
17209 new_loc_descr (DW_OP_stack_value
, 0, 0));
17214 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
17215 all operations from LOC are nops, move to the last one. Insert in NOPS all
17216 operations that are skipped. */
17219 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
17220 hash_set
<dw_loc_descr_ref
> &nops
)
17222 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
17225 loc
= loc
->dw_loc_next
;
17229 /* Helper for loc_descr_without_nops: free the location description operation
17233 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
17239 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
17243 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
17245 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
17248 /* Set of all DW_OP_nop operations we remove. */
17249 hash_set
<dw_loc_descr_ref
> nops
;
17251 /* First, strip all prefix NOP operations in order to keep the head of the
17252 operations list. */
17253 loc_descr_to_next_no_nop (loc
, nops
);
17255 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
17257 /* For control flow operations: strip "prefix" nops in destination
17259 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
17260 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
17261 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
17262 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
17264 /* Do the same for the operations that follow, then move to the next
17266 if (cur
->dw_loc_next
!= NULL
)
17267 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
17268 cur
= cur
->dw_loc_next
;
17271 nops
.traverse
<void *, free_loc_descr
> (NULL
);
17275 struct dwarf_procedure_info
;
17277 /* Helper structure for location descriptions generation. */
17278 struct loc_descr_context
17280 /* The type that is implicitly referenced by DW_OP_push_object_address, or
17281 NULL_TREE if DW_OP_push_object_address in invalid for this location
17282 description. This is used when processing PLACEHOLDER_EXPR nodes. */
17284 /* The ..._DECL node that should be translated as a
17285 DW_OP_push_object_address operation. */
17287 /* Information about the DWARF procedure we are currently generating. NULL if
17288 we are not generating a DWARF procedure. */
17289 struct dwarf_procedure_info
*dpi
;
17290 /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
17291 by consumer. Used for DW_TAG_generic_subrange attributes. */
17292 bool placeholder_arg
;
17293 /* True if PLACEHOLDER_EXPR has been seen. */
17294 bool placeholder_seen
;
17297 /* DWARF procedures generation
17299 DWARF expressions (aka. location descriptions) are used to encode variable
17300 things such as sizes or offsets. Such computations can have redundant parts
17301 that can be factorized in order to reduce the size of the output debug
17302 information. This is the whole point of DWARF procedures.
17304 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
17305 already factorized into functions ("size functions") in order to handle very
17306 big and complex types. Such functions are quite simple: they have integral
17307 arguments, they return an integral result and their body contains only a
17308 return statement with arithmetic expressions. This is the only kind of
17309 function we are interested in translating into DWARF procedures, here.
17311 DWARF expressions and DWARF procedure are executed using a stack, so we have
17312 to define some calling convention for them to interact. Let's say that:
17314 - Before calling a DWARF procedure, DWARF expressions must push on the stack
17315 all arguments in reverse order (right-to-left) so that when the DWARF
17316 procedure execution starts, the first argument is the top of the stack.
17318 - Then, when returning, the DWARF procedure must have consumed all arguments
17319 on the stack, must have pushed the result and touched nothing else.
17321 - Each integral argument and the result are integral types can be hold in a
17324 - We call "frame offset" the number of stack slots that are "under DWARF
17325 procedure control": it includes the arguments slots, the temporaries and
17326 the result slot. Thus, it is equal to the number of arguments when the
17327 procedure execution starts and must be equal to one (the result) when it
17330 /* Helper structure used when generating operations for a DWARF procedure. */
17331 struct dwarf_procedure_info
17333 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
17334 currently translated. */
17336 /* The number of arguments FNDECL takes. */
17337 unsigned args_count
;
17340 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
17341 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
17342 equate it to this DIE. */
17345 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
17346 dw_die_ref parent_die
)
17348 dw_die_ref dwarf_proc_die
;
17350 if ((dwarf_version
< 3 && dwarf_strict
)
17351 || location
== NULL
)
17354 dwarf_proc_die
= new_die (DW_TAG_dwarf_procedure
, parent_die
, fndecl
);
17356 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
17357 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
17358 return dwarf_proc_die
;
17361 /* Return whether TYPE is a supported type as a DWARF procedure argument
17362 type or return type (we handle only scalar types and pointer types that
17363 aren't wider than the DWARF expression evaluation stack. */
17366 is_handled_procedure_type (tree type
)
17368 return ((INTEGRAL_TYPE_P (type
)
17369 || TREE_CODE (type
) == OFFSET_TYPE
17370 || TREE_CODE (type
) == POINTER_TYPE
)
17371 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
17374 /* Helper for resolve_args_picking: do the same but stop when coming across
17375 visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
17376 offset *before* evaluating the corresponding operation. */
17379 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
17380 struct dwarf_procedure_info
*dpi
,
17381 hash_map
<dw_loc_descr_ref
, unsigned> &frame_offsets
)
17383 /* The "frame_offset" identifier is already used to name a macro... */
17384 unsigned frame_offset_
= initial_frame_offset
;
17385 dw_loc_descr_ref l
;
17387 for (l
= loc
; l
!= NULL
;)
17390 unsigned &l_frame_offset
= frame_offsets
.get_or_insert (l
, &existed
);
17392 /* If we already met this node, there is nothing to compute anymore. */
17395 /* Make sure that the stack size is consistent wherever the execution
17396 flow comes from. */
17397 gcc_assert ((unsigned) l_frame_offset
== frame_offset_
);
17400 l_frame_offset
= frame_offset_
;
17402 /* If needed, relocate the picking offset with respect to the frame
17404 if (l
->frame_offset_rel
)
17406 unsigned HOST_WIDE_INT off
;
17407 switch (l
->dw_loc_opc
)
17410 off
= l
->dw_loc_oprnd1
.v
.val_unsigned
;
17419 gcc_unreachable ();
17421 /* frame_offset_ is the size of the current stack frame, including
17422 incoming arguments. Besides, the arguments are pushed
17423 right-to-left. Thus, in order to access the Nth argument from
17424 this operation node, the picking has to skip temporaries *plus*
17425 one stack slot per argument (0 for the first one, 1 for the second
17428 The targetted argument number (N) is already set as the operand,
17429 and the number of temporaries can be computed with:
17430 frame_offsets_ - dpi->args_count */
17431 off
+= frame_offset_
- dpi
->args_count
;
17433 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
17439 l
->dw_loc_opc
= DW_OP_dup
;
17440 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
17444 l
->dw_loc_opc
= DW_OP_over
;
17445 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
17449 l
->dw_loc_opc
= DW_OP_pick
;
17450 l
->dw_loc_oprnd1
.v
.val_unsigned
= off
;
17454 /* Update frame_offset according to the effect the current operation has
17456 switch (l
->dw_loc_opc
)
17464 case DW_OP_plus_uconst
:
17500 case DW_OP_deref_size
:
17502 case DW_OP_bit_piece
:
17503 case DW_OP_implicit_value
:
17504 case DW_OP_stack_value
:
17508 case DW_OP_const1u
:
17509 case DW_OP_const1s
:
17510 case DW_OP_const2u
:
17511 case DW_OP_const2s
:
17512 case DW_OP_const4u
:
17513 case DW_OP_const4s
:
17514 case DW_OP_const8u
:
17515 case DW_OP_const8s
:
17586 case DW_OP_push_object_address
:
17587 case DW_OP_call_frame_cfa
:
17588 case DW_OP_GNU_variable_value
:
17613 case DW_OP_xderef_size
:
17619 case DW_OP_call_ref
:
17621 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
17622 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
17624 if (stack_usage
== NULL
)
17626 frame_offset_
+= *stack_usage
;
17630 case DW_OP_implicit_pointer
:
17631 case DW_OP_entry_value
:
17632 case DW_OP_const_type
:
17633 case DW_OP_regval_type
:
17634 case DW_OP_deref_type
:
17635 case DW_OP_convert
:
17636 case DW_OP_reinterpret
:
17637 case DW_OP_form_tls_address
:
17638 case DW_OP_GNU_push_tls_address
:
17639 case DW_OP_GNU_uninit
:
17640 case DW_OP_GNU_encoded_addr
:
17641 case DW_OP_GNU_implicit_pointer
:
17642 case DW_OP_GNU_entry_value
:
17643 case DW_OP_GNU_const_type
:
17644 case DW_OP_GNU_regval_type
:
17645 case DW_OP_GNU_deref_type
:
17646 case DW_OP_GNU_convert
:
17647 case DW_OP_GNU_reinterpret
:
17648 case DW_OP_GNU_parameter_ref
:
17649 /* loc_list_from_tree will probably not output these operations for
17650 size functions, so assume they will not appear here. */
17651 /* Fall through... */
17654 gcc_unreachable ();
17657 /* Now, follow the control flow (except subroutine calls). */
17658 switch (l
->dw_loc_opc
)
17661 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
17664 /* Fall through. */
17667 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
17670 case DW_OP_stack_value
:
17674 l
= l
->dw_loc_next
;
17682 /* Make a DFS over operations reachable through LOC (i.e. follow branch
17683 operations) in order to resolve the operand of DW_OP_pick operations that
17684 target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
17685 offset *before* LOC is executed. Return if all relocations were
17689 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
17690 struct dwarf_procedure_info
*dpi
)
17692 /* Associate to all visited operations the frame offset *before* evaluating
17694 hash_map
<dw_loc_descr_ref
, unsigned> frame_offsets
;
17696 return resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
,
17700 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
17701 Return NULL if it is not possible. */
17704 function_to_dwarf_procedure (tree fndecl
)
17706 struct loc_descr_context ctx
;
17707 struct dwarf_procedure_info dpi
;
17708 dw_die_ref dwarf_proc_die
;
17709 tree tree_body
= DECL_SAVED_TREE (fndecl
);
17710 dw_loc_descr_ref loc_body
, epilogue
;
17715 /* Do not generate multiple DWARF procedures for the same function
17717 dwarf_proc_die
= lookup_decl_die (fndecl
);
17718 if (dwarf_proc_die
!= NULL
)
17719 return dwarf_proc_die
;
17721 /* DWARF procedures are available starting with the DWARFv3 standard. */
17722 if (dwarf_version
< 3 && dwarf_strict
)
17725 /* We handle only functions for which we still have a body, that return a
17726 supported type and that takes arguments with supported types. Note that
17727 there is no point translating functions that return nothing. */
17728 if (tree_body
== NULL_TREE
17729 || DECL_RESULT (fndecl
) == NULL_TREE
17730 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
17733 for (cursor
= DECL_ARGUMENTS (fndecl
);
17734 cursor
!= NULL_TREE
;
17735 cursor
= TREE_CHAIN (cursor
))
17736 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
17739 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
17740 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
17742 tree_body
= TREE_OPERAND (tree_body
, 0);
17743 if (TREE_CODE (tree_body
) != MODIFY_EXPR
17744 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
17746 tree_body
= TREE_OPERAND (tree_body
, 1);
17748 /* Try to translate the body expression itself. Note that this will probably
17749 cause an infinite recursion if its call graph has a cycle. This is very
17750 unlikely for size functions, however, so don't bother with such things at
17752 ctx
.context_type
= NULL_TREE
;
17753 ctx
.base_decl
= NULL_TREE
;
17755 ctx
.placeholder_arg
= false;
17756 ctx
.placeholder_seen
= false;
17757 dpi
.fndecl
= fndecl
;
17758 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
17759 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
17763 /* After evaluating all operands in "loc_body", we should still have on the
17764 stack all arguments plus the desired function result (top of the stack).
17765 Generate code in order to keep only the result in our stack frame. */
17767 for (i
= 0; i
< dpi
.args_count
; ++i
)
17769 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
17770 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
17771 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
17772 epilogue
= op_couple
;
17774 add_loc_descr (&loc_body
, epilogue
);
17775 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
17778 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
17779 because they are considered useful. Now there is an epilogue, they are
17780 not anymore, so give it another try. */
17781 loc_descr_without_nops (loc_body
);
17783 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
17784 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
17785 though, given that size functions do not come from source, so they should
17786 not have a dedicated DW_TAG_subprogram DIE. */
17788 = new_dwarf_proc_die (loc_body
, fndecl
,
17789 get_context_die (DECL_CONTEXT (fndecl
)));
17791 /* The called DWARF procedure consumes one stack slot per argument and
17792 returns one stack slot. */
17793 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
17795 return dwarf_proc_die
;
17799 /* Generate Dwarf location list representing LOC.
17800 If WANT_ADDRESS is false, expression computing LOC will be computed
17801 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
17802 if WANT_ADDRESS is 2, expression computing address useable in location
17803 will be returned (i.e. DW_OP_reg can be used
17804 to refer to register values).
17806 CONTEXT provides information to customize the location descriptions
17807 generation. Its context_type field specifies what type is implicitly
17808 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
17809 will not be generated.
17811 Its DPI field determines whether we are generating a DWARF expression for a
17812 DWARF procedure, so PARM_DECL references are processed specifically.
17814 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
17815 and dpi fields were null. */
17817 static dw_loc_list_ref
17818 loc_list_from_tree_1 (tree loc
, int want_address
,
17819 struct loc_descr_context
*context
)
17821 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
17822 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
17823 int have_address
= 0;
17824 enum dwarf_location_atom op
;
17826 /* ??? Most of the time we do not take proper care for sign/zero
17827 extending the values properly. Hopefully this won't be a real
17830 if (context
!= NULL
17831 && context
->base_decl
== loc
17832 && want_address
== 0)
17834 if (dwarf_version
>= 3 || !dwarf_strict
)
17835 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
17836 NULL
, 0, NULL
, 0, NULL
);
17841 switch (TREE_CODE (loc
))
17844 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
17847 case PLACEHOLDER_EXPR
:
17848 /* This case involves extracting fields from an object to determine the
17849 position of other fields. It is supposed to appear only as the first
17850 operand of COMPONENT_REF nodes and to reference precisely the type
17851 that the context allows. */
17852 if (context
!= NULL
17853 && TREE_TYPE (loc
) == context
->context_type
17854 && want_address
>= 1)
17856 if (dwarf_version
>= 3 || !dwarf_strict
)
17858 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
17865 /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
17866 the single argument passed by consumer. */
17867 else if (context
!= NULL
17868 && context
->placeholder_arg
17869 && INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17870 && want_address
== 0)
17872 ret
= new_loc_descr (DW_OP_pick
, 0, 0);
17873 ret
->frame_offset_rel
= 1;
17874 context
->placeholder_seen
= true;
17878 expansion_failed (loc
, NULL_RTX
,
17879 "PLACEHOLDER_EXPR for an unexpected type");
17884 const int nargs
= call_expr_nargs (loc
);
17885 tree callee
= get_callee_fndecl (loc
);
17887 dw_die_ref dwarf_proc
;
17889 if (callee
== NULL_TREE
)
17890 goto call_expansion_failed
;
17892 /* We handle only functions that return an integer. */
17893 if (!is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
))))
17894 goto call_expansion_failed
;
17896 dwarf_proc
= function_to_dwarf_procedure (callee
);
17897 if (dwarf_proc
== NULL
)
17898 goto call_expansion_failed
;
17900 /* Evaluate arguments right-to-left so that the first argument will
17901 be the top-most one on the stack. */
17902 for (i
= nargs
- 1; i
>= 0; --i
)
17904 dw_loc_descr_ref loc_descr
17905 = loc_descriptor_from_tree (CALL_EXPR_ARG (loc
, i
), 0,
17908 if (loc_descr
== NULL
)
17909 goto call_expansion_failed
;
17911 add_loc_descr (&ret
, loc_descr
);
17914 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
17915 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17916 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
17917 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17918 add_loc_descr (&ret
, ret1
);
17921 call_expansion_failed
:
17922 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
17923 /* There are no opcodes for these operations. */
17927 case PREINCREMENT_EXPR
:
17928 case PREDECREMENT_EXPR
:
17929 case POSTINCREMENT_EXPR
:
17930 case POSTDECREMENT_EXPR
:
17931 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
17932 /* There are no opcodes for these operations. */
17936 /* If we already want an address, see if there is INDIRECT_REF inside
17937 e.g. for &this->field. */
17940 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
17941 (loc
, want_address
== 2, context
);
17944 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
17945 && (ret
= cst_pool_loc_descr (loc
)))
17948 /* Otherwise, process the argument and look for the address. */
17949 if (!list_ret
&& !ret
)
17950 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
17954 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
17960 if (DECL_THREAD_LOCAL_P (loc
))
17963 enum dwarf_location_atom tls_op
;
17964 enum dtprel_bool dtprel
= dtprel_false
;
17966 if (targetm
.have_tls
)
17968 /* If this is not defined, we have no way to emit the
17970 if (!targetm
.asm_out
.output_dwarf_dtprel
)
17973 /* The way DW_OP_GNU_push_tls_address is specified, we
17974 can only look up addresses of objects in the current
17975 module. We used DW_OP_addr as first op, but that's
17976 wrong, because DW_OP_addr is relocated by the debug
17977 info consumer, while DW_OP_GNU_push_tls_address
17978 operand shouldn't be. */
17979 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
17981 dtprel
= dtprel_true
;
17982 /* We check for DWARF 5 here because gdb did not implement
17983 DW_OP_form_tls_address until after 7.12. */
17984 tls_op
= (dwarf_version
>= 5 ? DW_OP_form_tls_address
17985 : DW_OP_GNU_push_tls_address
);
17989 if (!targetm
.emutls
.debug_form_tls_address
17990 || !(dwarf_version
>= 3 || !dwarf_strict
))
17992 /* We stuffed the control variable into the DECL_VALUE_EXPR
17993 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
17994 no longer appear in gimple code. We used the control
17995 variable in specific so that we could pick it up here. */
17996 loc
= DECL_VALUE_EXPR (loc
);
17997 tls_op
= DW_OP_form_tls_address
;
18000 rtl
= rtl_for_decl_location (loc
);
18001 if (rtl
== NULL_RTX
)
18006 rtl
= XEXP (rtl
, 0);
18007 if (! CONSTANT_P (rtl
))
18010 ret
= new_addr_loc_descr (rtl
, dtprel
);
18011 ret1
= new_loc_descr (tls_op
, 0, 0);
18012 add_loc_descr (&ret
, ret1
);
18020 if (context
!= NULL
&& context
->dpi
!= NULL
18021 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
18023 /* We are generating code for a DWARF procedure and we want to access
18024 one of its arguments: find the appropriate argument offset and let
18025 the resolve_args_picking pass compute the offset that complies
18026 with the stack frame size. */
18030 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
18031 cursor
!= NULL_TREE
&& cursor
!= loc
;
18032 cursor
= TREE_CHAIN (cursor
), ++i
)
18034 /* If we are translating a DWARF procedure, all referenced parameters
18035 must belong to the current function. */
18036 gcc_assert (cursor
!= NULL_TREE
);
18038 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
18039 ret
->frame_offset_rel
= 1;
18045 if (DECL_HAS_VALUE_EXPR_P (loc
))
18046 return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc
),
18047 want_address
, context
);
18050 case FUNCTION_DECL
:
18053 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
18055 if (loc_list
&& loc_list
->first
)
18057 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
18058 have_address
= want_address
!= 0;
18061 rtl
= rtl_for_decl_location (loc
);
18062 if (rtl
== NULL_RTX
)
18064 if (TREE_CODE (loc
) != FUNCTION_DECL
18066 && current_function_decl
18067 && want_address
!= 1
18068 && ! DECL_IGNORED_P (loc
)
18069 && (INTEGRAL_TYPE_P (TREE_TYPE (loc
))
18070 || POINTER_TYPE_P (TREE_TYPE (loc
)))
18071 && DECL_CONTEXT (loc
) == current_function_decl
18072 && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc
)))
18073 <= DWARF2_ADDR_SIZE
))
18075 dw_die_ref ref
= lookup_decl_die (loc
);
18076 ret
= new_loc_descr (DW_OP_GNU_variable_value
, 0, 0);
18079 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
18080 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
18081 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
18085 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
18086 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= loc
;
18090 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
18093 else if (CONST_INT_P (rtl
))
18095 HOST_WIDE_INT val
= INTVAL (rtl
);
18096 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
18097 val
&= GET_MODE_MASK (DECL_MODE (loc
));
18098 ret
= int_loc_descriptor (val
);
18100 else if (GET_CODE (rtl
) == CONST_STRING
)
18102 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
18105 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
18106 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
18109 machine_mode mode
, mem_mode
;
18111 /* Certain constructs can only be represented at top-level. */
18112 if (want_address
== 2)
18114 ret
= loc_descriptor (rtl
, VOIDmode
,
18115 VAR_INIT_STATUS_INITIALIZED
);
18120 mode
= GET_MODE (rtl
);
18121 mem_mode
= VOIDmode
;
18125 mode
= get_address_mode (rtl
);
18126 rtl
= XEXP (rtl
, 0);
18129 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
18130 VAR_INIT_STATUS_INITIALIZED
);
18133 expansion_failed (loc
, rtl
,
18134 "failed to produce loc descriptor for rtl");
18140 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
18147 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
18151 case TARGET_MEM_REF
:
18153 case DEBUG_EXPR_DECL
:
18156 case COMPOUND_EXPR
:
18157 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
18161 case VIEW_CONVERT_EXPR
:
18164 case NON_LVALUE_EXPR
:
18165 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
18168 case COMPONENT_REF
:
18169 case BIT_FIELD_REF
:
18171 case ARRAY_RANGE_REF
:
18172 case REALPART_EXPR
:
18173 case IMAGPART_EXPR
:
18176 poly_int64 bitsize
, bitpos
, bytepos
;
18178 int unsignedp
, reversep
, volatilep
= 0;
18180 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
18181 &unsignedp
, &reversep
, &volatilep
);
18183 gcc_assert (obj
!= loc
);
18185 list_ret
= loc_list_from_tree_1 (obj
,
18187 && known_eq (bitpos
, 0)
18188 && !offset
? 2 : 1,
18190 /* TODO: We can extract value of the small expression via shifting even
18191 for nonzero bitpos. */
18194 if (!multiple_p (bitpos
, BITS_PER_UNIT
, &bytepos
)
18195 || !multiple_p (bitsize
, BITS_PER_UNIT
))
18197 expansion_failed (loc
, NULL_RTX
,
18198 "bitfield access");
18202 if (offset
!= NULL_TREE
)
18204 /* Variable offset. */
18205 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
18206 if (list_ret1
== 0)
18208 add_loc_list (&list_ret
, list_ret1
);
18211 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
18214 HOST_WIDE_INT value
;
18215 if (bytepos
.is_constant (&value
) && value
> 0)
18216 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
,
18218 else if (maybe_ne (bytepos
, 0))
18219 loc_list_plus_const (list_ret
, bytepos
);
18226 if ((want_address
|| !tree_fits_shwi_p (loc
))
18227 && (ret
= cst_pool_loc_descr (loc
)))
18229 else if (want_address
== 2
18230 && tree_fits_shwi_p (loc
)
18231 && (ret
= address_of_int_loc_descriptor
18232 (int_size_in_bytes (TREE_TYPE (loc
)),
18233 tree_to_shwi (loc
))))
18235 else if (tree_fits_shwi_p (loc
))
18236 ret
= int_loc_descriptor (tree_to_shwi (loc
));
18237 else if (tree_fits_uhwi_p (loc
))
18238 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
18241 expansion_failed (loc
, NULL_RTX
,
18242 "Integer operand is not host integer");
18251 if ((ret
= cst_pool_loc_descr (loc
)))
18253 else if (TREE_CODE (loc
) == CONSTRUCTOR
)
18255 tree type
= TREE_TYPE (loc
);
18256 unsigned HOST_WIDE_INT size
= int_size_in_bytes (type
);
18257 unsigned HOST_WIDE_INT offset
= 0;
18258 unsigned HOST_WIDE_INT cnt
;
18259 constructor_elt
*ce
;
18261 if (TREE_CODE (type
) == RECORD_TYPE
)
18263 /* This is very limited, but it's enough to output
18264 pointers to member functions, as long as the
18265 referenced function is defined in the current
18266 translation unit. */
18267 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc
), cnt
, ce
)
18269 tree val
= ce
->value
;
18271 tree field
= ce
->index
;
18276 if (!field
|| DECL_BIT_FIELD (field
))
18278 expansion_failed (loc
, NULL_RTX
,
18279 "bitfield in record type constructor");
18280 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
18285 HOST_WIDE_INT fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
18286 unsigned HOST_WIDE_INT pos
= int_byte_position (field
);
18287 gcc_assert (pos
+ fieldsize
<= size
);
18290 expansion_failed (loc
, NULL_RTX
,
18291 "out-of-order fields in record constructor");
18292 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
18298 ret1
= new_loc_descr (DW_OP_piece
, pos
- offset
, 0);
18299 add_loc_descr (&ret
, ret1
);
18302 if (val
&& fieldsize
!= 0)
18304 ret1
= loc_descriptor_from_tree (val
, want_address
, context
);
18307 expansion_failed (loc
, NULL_RTX
,
18308 "unsupported expression in field");
18309 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
18313 add_loc_descr (&ret
, ret1
);
18317 ret1
= new_loc_descr (DW_OP_piece
, fieldsize
, 0);
18318 add_loc_descr (&ret
, ret1
);
18319 offset
= pos
+ fieldsize
;
18323 if (offset
!= size
)
18325 ret1
= new_loc_descr (DW_OP_piece
, size
- offset
, 0);
18326 add_loc_descr (&ret
, ret1
);
18330 have_address
= !!want_address
;
18333 expansion_failed (loc
, NULL_RTX
,
18334 "constructor of non-record type");
18337 /* We can construct small constants here using int_loc_descriptor. */
18338 expansion_failed (loc
, NULL_RTX
,
18339 "constructor or constant not in constant pool");
18342 case TRUTH_AND_EXPR
:
18343 case TRUTH_ANDIF_EXPR
:
18348 case TRUTH_XOR_EXPR
:
18353 case TRUTH_OR_EXPR
:
18354 case TRUTH_ORIF_EXPR
:
18359 case FLOOR_DIV_EXPR
:
18360 case CEIL_DIV_EXPR
:
18361 case ROUND_DIV_EXPR
:
18362 case TRUNC_DIV_EXPR
:
18363 case EXACT_DIV_EXPR
:
18364 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
18373 case FLOOR_MOD_EXPR
:
18374 case CEIL_MOD_EXPR
:
18375 case ROUND_MOD_EXPR
:
18376 case TRUNC_MOD_EXPR
:
18377 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
18382 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
18383 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
18384 if (list_ret
== 0 || list_ret1
== 0)
18387 add_loc_list (&list_ret
, list_ret1
);
18390 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
18391 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
18392 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
18393 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
18394 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
18406 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
18409 case POINTER_PLUS_EXPR
:
18412 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
18414 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
18415 smarter to encode their opposite. The DW_OP_plus_uconst operation
18416 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
18417 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
18418 bytes, Y being the size of the operation that pushes the opposite
18419 of the addend. So let's choose the smallest representation. */
18420 const tree tree_addend
= TREE_OPERAND (loc
, 1);
18421 offset_int wi_addend
;
18422 HOST_WIDE_INT shwi_addend
;
18423 dw_loc_descr_ref loc_naddend
;
18425 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
18429 /* Try to get the literal to push. It is the opposite of the addend,
18430 so as we rely on wrapping during DWARF evaluation, first decode
18431 the literal as a "DWARF-sized" signed number. */
18432 wi_addend
= wi::to_offset (tree_addend
);
18433 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
18434 shwi_addend
= wi_addend
.to_shwi ();
18435 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
18436 ? int_loc_descriptor (-shwi_addend
)
18439 if (loc_naddend
!= NULL
18440 && ((unsigned) size_of_uleb128 (shwi_addend
)
18441 > size_of_loc_descr (loc_naddend
)))
18443 add_loc_descr_to_each (list_ret
, loc_naddend
);
18444 add_loc_descr_to_each (list_ret
,
18445 new_loc_descr (DW_OP_minus
, 0, 0));
18449 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
18451 loc_naddend
= loc_cur
;
18452 loc_cur
= loc_cur
->dw_loc_next
;
18453 ggc_free (loc_naddend
);
18455 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
18465 goto do_comp_binop
;
18469 goto do_comp_binop
;
18473 goto do_comp_binop
;
18477 goto do_comp_binop
;
18480 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
18482 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
18483 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
18484 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
18500 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
18501 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
18502 if (list_ret
== 0 || list_ret1
== 0)
18505 add_loc_list (&list_ret
, list_ret1
);
18508 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
18511 case TRUTH_NOT_EXPR
:
18525 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
18529 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
18535 const enum tree_code code
=
18536 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
18538 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
18539 build2 (code
, integer_type_node
,
18540 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
18541 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
18548 dw_loc_descr_ref lhs
18549 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
18550 dw_loc_list_ref rhs
18551 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
18552 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
18554 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
18555 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
18558 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
18559 add_loc_descr_to_each (list_ret
, bra_node
);
18561 add_loc_list (&list_ret
, rhs
);
18562 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
18563 add_loc_descr_to_each (list_ret
, jump_node
);
18565 add_loc_descr_to_each (list_ret
, lhs
);
18566 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
18567 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
18569 /* ??? Need a node to point the skip at. Use a nop. */
18570 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
18571 add_loc_descr_to_each (list_ret
, tmp
);
18572 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
18573 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
18577 case FIX_TRUNC_EXPR
:
18581 /* Leave front-end specific codes as simply unknown. This comes
18582 up, for instance, with the C STMT_EXPR. */
18583 if ((unsigned int) TREE_CODE (loc
)
18584 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
18586 expansion_failed (loc
, NULL_RTX
,
18587 "language specific tree node");
18591 /* Otherwise this is a generic code; we should just lists all of
18592 these explicitly. We forgot one. */
18594 gcc_unreachable ();
18596 /* In a release build, we want to degrade gracefully: better to
18597 generate incomplete debugging information than to crash. */
18601 if (!ret
&& !list_ret
)
18604 if (want_address
== 2 && !have_address
18605 && (dwarf_version
>= 4 || !dwarf_strict
))
18607 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
18609 expansion_failed (loc
, NULL_RTX
,
18610 "DWARF address size mismatch");
18614 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
18616 add_loc_descr_to_each (list_ret
,
18617 new_loc_descr (DW_OP_stack_value
, 0, 0));
18620 /* Show if we can't fill the request for an address. */
18621 if (want_address
&& !have_address
)
18623 expansion_failed (loc
, NULL_RTX
,
18624 "Want address and only have value");
18628 gcc_assert (!ret
|| !list_ret
);
18630 /* If we've got an address and don't want one, dereference. */
18631 if (!want_address
&& have_address
)
18633 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
18635 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
18637 expansion_failed (loc
, NULL_RTX
,
18638 "DWARF address size mismatch");
18641 else if (size
== DWARF2_ADDR_SIZE
)
18644 op
= DW_OP_deref_size
;
18647 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
18649 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
18652 list_ret
= new_loc_list (ret
, NULL
, 0, NULL
, 0, NULL
);
18657 /* Likewise, but strip useless DW_OP_nop operations in the resulting
18660 static dw_loc_list_ref
18661 loc_list_from_tree (tree loc
, int want_address
,
18662 struct loc_descr_context
*context
)
18664 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
18666 for (dw_loc_list_ref loc_cur
= result
;
18667 loc_cur
!= NULL
; loc_cur
= loc_cur
->dw_loc_next
)
18668 loc_descr_without_nops (loc_cur
->expr
);
18672 /* Same as above but return only single location expression. */
18673 static dw_loc_descr_ref
18674 loc_descriptor_from_tree (tree loc
, int want_address
,
18675 struct loc_descr_context
*context
)
18677 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
18680 if (ret
->dw_loc_next
)
18682 expansion_failed (loc
, NULL_RTX
,
18683 "Location list where only loc descriptor needed");
18689 /* Given a value, round it up to the lowest multiple of `boundary'
18690 which is not less than the value itself. */
18692 static inline HOST_WIDE_INT
18693 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
18695 return (((value
+ boundary
- 1) / boundary
) * boundary
);
18698 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
18699 pointer to the declared type for the relevant field variable, or return
18700 `integer_type_node' if the given node turns out to be an
18701 ERROR_MARK node. */
18704 field_type (const_tree decl
)
18708 if (TREE_CODE (decl
) == ERROR_MARK
)
18709 return integer_type_node
;
18711 type
= DECL_BIT_FIELD_TYPE (decl
);
18712 if (type
== NULL_TREE
)
18713 type
= TREE_TYPE (decl
);
18718 /* Given a pointer to a tree node, return the alignment in bits for
18719 it, or else return BITS_PER_WORD if the node actually turns out to
18720 be an ERROR_MARK node. */
18722 static inline unsigned
18723 simple_type_align_in_bits (const_tree type
)
18725 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
18728 static inline unsigned
18729 simple_decl_align_in_bits (const_tree decl
)
18731 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
18734 /* Return the result of rounding T up to ALIGN. */
18736 static inline offset_int
18737 round_up_to_align (const offset_int
&t
, unsigned int align
)
18739 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
18742 /* Compute the size of TYPE in bytes. If possible, return NULL and store the
18743 size as an integer constant in CST_SIZE. Otherwise, if possible, return a
18744 DWARF expression that computes the size. Return NULL and set CST_SIZE to -1
18745 if we fail to return the size in one of these two forms. */
18747 static dw_loc_descr_ref
18748 type_byte_size (const_tree type
, HOST_WIDE_INT
*cst_size
)
18751 struct loc_descr_context ctx
;
18753 /* Return a constant integer in priority, if possible. */
18754 *cst_size
= int_size_in_bytes (type
);
18755 if (*cst_size
!= -1)
18758 ctx
.context_type
= const_cast<tree
> (type
);
18759 ctx
.base_decl
= NULL_TREE
;
18761 ctx
.placeholder_arg
= false;
18762 ctx
.placeholder_seen
= false;
18764 type
= TYPE_MAIN_VARIANT (type
);
18765 tree_size
= TYPE_SIZE_UNIT (type
);
18766 return ((tree_size
!= NULL_TREE
)
18767 ? loc_descriptor_from_tree (tree_size
, 0, &ctx
)
18771 /* Helper structure for RECORD_TYPE processing. */
18774 /* Root RECORD_TYPE. It is needed to generate data member location
18775 descriptions in variable-length records (VLR), but also to cope with
18776 variants, which are composed of nested structures multiplexed with
18777 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
18778 function processing a FIELD_DECL, it is required to be non null. */
18780 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
18781 QUAL_UNION_TYPE), this holds an expression that computes the offset for
18782 this variant part as part of the root record (in storage units). For
18783 regular records, it must be NULL_TREE. */
18784 tree variant_part_offset
;
18787 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
18788 addressed byte of the "containing object" for the given FIELD_DECL. If
18789 possible, return a native constant through CST_OFFSET (in which case NULL is
18790 returned); otherwise return a DWARF expression that computes the offset.
18792 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
18793 that offset is, either because the argument turns out to be a pointer to an
18794 ERROR_MARK node, or because the offset expression is too complex for us.
18796 CTX is required: see the comment for VLR_CONTEXT. */
18798 static dw_loc_descr_ref
18799 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
18800 HOST_WIDE_INT
*cst_offset
)
18803 dw_loc_list_ref loc_result
;
18807 if (TREE_CODE (decl
) == ERROR_MARK
)
18810 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
18812 /* We cannot handle variable bit offsets at the moment, so abort if it's the
18814 if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
)
18817 #ifdef PCC_BITFIELD_TYPE_MATTERS
18818 /* We used to handle only constant offsets in all cases. Now, we handle
18819 properly dynamic byte offsets only when PCC bitfield type doesn't
18821 if (PCC_BITFIELD_TYPE_MATTERS
18822 && TREE_CODE (DECL_FIELD_OFFSET (decl
)) == INTEGER_CST
)
18824 offset_int object_offset_in_bits
;
18825 offset_int object_offset_in_bytes
;
18826 offset_int bitpos_int
;
18828 tree field_size_tree
;
18829 offset_int deepest_bitpos
;
18830 offset_int field_size_in_bits
;
18831 unsigned int type_align_in_bits
;
18832 unsigned int decl_align_in_bits
;
18833 offset_int type_size_in_bits
;
18835 bitpos_int
= wi::to_offset (bit_position (decl
));
18836 type
= field_type (decl
);
18837 type_size_in_bits
= offset_int_type_size_in_bits (type
);
18838 type_align_in_bits
= simple_type_align_in_bits (type
);
18840 field_size_tree
= DECL_SIZE (decl
);
18842 /* The size could be unspecified if there was an error, or for
18843 a flexible array member. */
18844 if (!field_size_tree
)
18845 field_size_tree
= bitsize_zero_node
;
18847 /* If the size of the field is not constant, use the type size. */
18848 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
18849 field_size_in_bits
= wi::to_offset (field_size_tree
);
18851 field_size_in_bits
= type_size_in_bits
;
18853 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
18855 /* The GCC front-end doesn't make any attempt to keep track of the
18856 starting bit offset (relative to the start of the containing
18857 structure type) of the hypothetical "containing object" for a
18858 bit-field. Thus, when computing the byte offset value for the
18859 start of the "containing object" of a bit-field, we must deduce
18860 this information on our own. This can be rather tricky to do in
18861 some cases. For example, handling the following structure type
18862 definition when compiling for an i386/i486 target (which only
18863 aligns long long's to 32-bit boundaries) can be very tricky:
18865 struct S { int field1; long long field2:31; };
18867 Fortunately, there is a simple rule-of-thumb which can be used
18868 in such cases. When compiling for an i386/i486, GCC will
18869 allocate 8 bytes for the structure shown above. It decides to
18870 do this based upon one simple rule for bit-field allocation.
18871 GCC allocates each "containing object" for each bit-field at
18872 the first (i.e. lowest addressed) legitimate alignment boundary
18873 (based upon the required minimum alignment for the declared
18874 type of the field) which it can possibly use, subject to the
18875 condition that there is still enough available space remaining
18876 in the containing object (when allocated at the selected point)
18877 to fully accommodate all of the bits of the bit-field itself.
18879 This simple rule makes it obvious why GCC allocates 8 bytes for
18880 each object of the structure type shown above. When looking
18881 for a place to allocate the "containing object" for `field2',
18882 the compiler simply tries to allocate a 64-bit "containing
18883 object" at each successive 32-bit boundary (starting at zero)
18884 until it finds a place to allocate that 64- bit field such that
18885 at least 31 contiguous (and previously unallocated) bits remain
18886 within that selected 64 bit field. (As it turns out, for the
18887 example above, the compiler finds it is OK to allocate the
18888 "containing object" 64-bit field at bit-offset zero within the
18891 Here we attempt to work backwards from the limited set of facts
18892 we're given, and we try to deduce from those facts, where GCC
18893 must have believed that the containing object started (within
18894 the structure type). The value we deduce is then used (by the
18895 callers of this routine) to generate DW_AT_location and
18896 DW_AT_bit_offset attributes for fields (both bit-fields and, in
18897 the case of DW_AT_location, regular fields as well). */
18899 /* Figure out the bit-distance from the start of the structure to
18900 the "deepest" bit of the bit-field. */
18901 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
18903 /* This is the tricky part. Use some fancy footwork to deduce
18904 where the lowest addressed bit of the containing object must
18906 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18908 /* Round up to type_align by default. This works best for
18910 object_offset_in_bits
18911 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
18913 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
18915 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18917 /* Round up to decl_align instead. */
18918 object_offset_in_bits
18919 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
18922 object_offset_in_bytes
18923 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
18924 if (ctx
->variant_part_offset
== NULL_TREE
)
18926 *cst_offset
= object_offset_in_bytes
.to_shwi ();
18929 tree_result
= wide_int_to_tree (sizetype
, object_offset_in_bytes
);
18932 #endif /* PCC_BITFIELD_TYPE_MATTERS */
18933 tree_result
= byte_position (decl
);
18935 if (ctx
->variant_part_offset
!= NULL_TREE
)
18936 tree_result
= fold_build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
18937 ctx
->variant_part_offset
, tree_result
);
18939 /* If the byte offset is a constant, it's simplier to handle a native
18940 constant rather than a DWARF expression. */
18941 if (TREE_CODE (tree_result
) == INTEGER_CST
)
18943 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
18946 struct loc_descr_context loc_ctx
= {
18947 ctx
->struct_type
, /* context_type */
18948 NULL_TREE
, /* base_decl */
18950 false, /* placeholder_arg */
18951 false /* placeholder_seen */
18953 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
18955 /* We want a DWARF expression: abort if we only have a location list with
18956 multiple elements. */
18957 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
18960 return loc_result
->expr
;
18963 /* The following routines define various Dwarf attributes and any data
18964 associated with them. */
18966 /* Add a location description attribute value to a DIE.
18968 This emits location attributes suitable for whole variables and
18969 whole parameters. Note that the location attributes for struct fields are
18970 generated by the routine `data_member_location_attribute' below. */
18973 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
18974 dw_loc_list_ref descr
)
18976 bool check_no_locviews
= true;
18979 if (single_element_loc_list_p (descr
))
18980 add_AT_loc (die
, attr_kind
, descr
->expr
);
18983 add_AT_loc_list (die
, attr_kind
, descr
);
18984 gcc_assert (descr
->ll_symbol
);
18985 if (attr_kind
== DW_AT_location
&& descr
->vl_symbol
18986 && dwarf2out_locviews_in_attribute ())
18988 add_AT_view_list (die
, DW_AT_GNU_locviews
);
18989 check_no_locviews
= false;
18993 if (check_no_locviews
)
18994 gcc_assert (!get_AT (die
, DW_AT_GNU_locviews
));
18997 /* Add DW_AT_accessibility attribute to DIE if needed. */
19000 add_accessibility_attribute (dw_die_ref die
, tree decl
)
19002 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19003 children, otherwise the default is DW_ACCESS_public. In DWARF2
19004 the default has always been DW_ACCESS_public. */
19005 if (TREE_PROTECTED (decl
))
19006 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19007 else if (TREE_PRIVATE (decl
))
19009 if (dwarf_version
== 2
19010 || die
->die_parent
== NULL
19011 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
19012 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19014 else if (dwarf_version
> 2
19016 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
19017 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19020 /* Attach the specialized form of location attribute used for data members of
19021 struct and union types. In the special case of a FIELD_DECL node which
19022 represents a bit-field, the "offset" part of this special location
19023 descriptor must indicate the distance in bytes from the lowest-addressed
19024 byte of the containing struct or union type to the lowest-addressed byte of
19025 the "containing object" for the bit-field. (See the `field_byte_offset'
19028 For any given bit-field, the "containing object" is a hypothetical object
19029 (of some integral or enum type) within which the given bit-field lives. The
19030 type of this hypothetical "containing object" is always the same as the
19031 declared type of the individual bit-field itself (for GCC anyway... the
19032 DWARF spec doesn't actually mandate this). Note that it is the size (in
19033 bytes) of the hypothetical "containing object" which will be given in the
19034 DW_AT_byte_size attribute for this bit-field. (See the
19035 `byte_size_attribute' function below.) It is also used when calculating the
19036 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
19039 CTX is required: see the comment for VLR_CONTEXT. */
19042 add_data_member_location_attribute (dw_die_ref die
,
19044 struct vlr_context
*ctx
)
19046 HOST_WIDE_INT offset
;
19047 dw_loc_descr_ref loc_descr
= 0;
19049 if (TREE_CODE (decl
) == TREE_BINFO
)
19051 /* We're working on the TAG_inheritance for a base class. */
19052 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
19054 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
19055 aren't at a fixed offset from all (sub)objects of the same
19056 type. We need to extract the appropriate offset from our
19057 vtable. The following dwarf expression means
19059 BaseAddr = ObAddr + *((*ObAddr) - Offset)
19061 This is specific to the V3 ABI, of course. */
19063 dw_loc_descr_ref tmp
;
19065 /* Make a copy of the object address. */
19066 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
19067 add_loc_descr (&loc_descr
, tmp
);
19069 /* Extract the vtable address. */
19070 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
19071 add_loc_descr (&loc_descr
, tmp
);
19073 /* Calculate the address of the offset. */
19074 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
19075 gcc_assert (offset
< 0);
19077 tmp
= int_loc_descriptor (-offset
);
19078 add_loc_descr (&loc_descr
, tmp
);
19079 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
19080 add_loc_descr (&loc_descr
, tmp
);
19082 /* Extract the offset. */
19083 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
19084 add_loc_descr (&loc_descr
, tmp
);
19086 /* Add it to the object address. */
19087 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
19088 add_loc_descr (&loc_descr
, tmp
);
19091 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
19095 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
19097 /* If loc_descr is available then we know the field offset is dynamic.
19098 However, GDB does not handle dynamic field offsets very well at the
19100 if (loc_descr
!= NULL
&& gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
)
19106 /* Data member location evalutation starts with the base address on the
19107 stack. Compute the field offset and add it to this base address. */
19108 else if (loc_descr
!= NULL
)
19109 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
19114 /* While DW_AT_data_bit_offset has been added already in DWARF4,
19115 e.g. GDB only added support to it in November 2016. For DWARF5
19116 we need newer debug info consumers anyway. We might change this
19117 to dwarf_version >= 4 once most consumers catched up. */
19118 if (dwarf_version
>= 5
19119 && TREE_CODE (decl
) == FIELD_DECL
19120 && DECL_BIT_FIELD_TYPE (decl
))
19122 tree off
= bit_position (decl
);
19123 if (tree_fits_uhwi_p (off
) && get_AT (die
, DW_AT_bit_size
))
19125 remove_AT (die
, DW_AT_byte_size
);
19126 remove_AT (die
, DW_AT_bit_offset
);
19127 add_AT_unsigned (die
, DW_AT_data_bit_offset
, tree_to_uhwi (off
));
19131 if (dwarf_version
> 2)
19133 /* Don't need to output a location expression, just the constant. */
19135 add_AT_int (die
, DW_AT_data_member_location
, offset
);
19137 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
19142 enum dwarf_location_atom op
;
19144 /* The DWARF2 standard says that we should assume that the structure
19145 address is already on the stack, so we can specify a structure
19146 field address by using DW_OP_plus_uconst. */
19147 op
= DW_OP_plus_uconst
;
19148 loc_descr
= new_loc_descr (op
, offset
, 0);
19152 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
19155 /* Writes integer values to dw_vec_const array. */
19158 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
19162 *dest
++ = val
& 0xff;
19168 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
19170 static HOST_WIDE_INT
19171 extract_int (const unsigned char *src
, unsigned int size
)
19173 HOST_WIDE_INT val
= 0;
19179 val
|= *--src
& 0xff;
19185 /* Writes wide_int values to dw_vec_const array. */
19188 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
19192 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
19194 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
19198 /* We'd have to extend this code to support odd sizes. */
19199 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
19201 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
19203 if (WORDS_BIG_ENDIAN
)
19204 for (i
= n
- 1; i
>= 0; i
--)
19206 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
19207 dest
+= sizeof (HOST_WIDE_INT
);
19210 for (i
= 0; i
< n
; i
++)
19212 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
19213 dest
+= sizeof (HOST_WIDE_INT
);
19217 /* Writes floating point values to dw_vec_const array. */
19220 insert_float (const_rtx rtl
, unsigned char *array
)
19224 scalar_float_mode mode
= as_a
<scalar_float_mode
> (GET_MODE (rtl
));
19226 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), mode
);
19228 /* real_to_target puts 32-bit pieces in each long. Pack them. */
19229 for (i
= 0; i
< GET_MODE_SIZE (mode
) / 4; i
++)
19231 insert_int (val
[i
], 4, array
);
19236 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
19237 does not have a "location" either in memory or in a register. These
19238 things can arise in GNU C when a constant is passed as an actual parameter
19239 to an inlined function. They can also arise in C++ where declared
19240 constants do not necessarily get memory "homes". */
19243 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
19245 switch (GET_CODE (rtl
))
19249 HOST_WIDE_INT val
= INTVAL (rtl
);
19252 add_AT_int (die
, DW_AT_const_value
, val
);
19254 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
19258 case CONST_WIDE_INT
:
19260 wide_int w1
= rtx_mode_t (rtl
, MAX_MODE_INT
);
19261 unsigned int prec
= MIN (wi::min_precision (w1
, UNSIGNED
),
19262 (unsigned int)CONST_WIDE_INT_NUNITS (rtl
) * HOST_BITS_PER_WIDE_INT
);
19263 wide_int w
= wi::zext (w1
, prec
);
19264 add_AT_wide (die
, DW_AT_const_value
, w
);
19269 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
19270 floating-point constant. A CONST_DOUBLE is used whenever the
19271 constant requires more than one word in order to be adequately
19273 if (TARGET_SUPPORTS_WIDE_INT
== 0
19274 && !SCALAR_FLOAT_MODE_P (GET_MODE (rtl
)))
19275 add_AT_double (die
, DW_AT_const_value
,
19276 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
19279 scalar_float_mode mode
= as_a
<scalar_float_mode
> (GET_MODE (rtl
));
19280 unsigned int length
= GET_MODE_SIZE (mode
);
19281 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
19283 insert_float (rtl
, array
);
19284 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
19290 unsigned int length
;
19291 if (!CONST_VECTOR_NUNITS (rtl
).is_constant (&length
))
19294 machine_mode mode
= GET_MODE (rtl
);
19295 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
19296 unsigned char *array
19297 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
19300 machine_mode imode
= GET_MODE_INNER (mode
);
19302 switch (GET_MODE_CLASS (mode
))
19304 case MODE_VECTOR_INT
:
19305 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
19307 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
19308 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
19312 case MODE_VECTOR_FLOAT
:
19313 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
19315 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
19316 insert_float (elt
, p
);
19321 gcc_unreachable ();
19324 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
19329 if (dwarf_version
>= 4 || !dwarf_strict
)
19331 dw_loc_descr_ref loc_result
;
19332 resolve_one_addr (&rtl
);
19334 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
19335 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
19336 add_AT_loc (die
, DW_AT_location
, loc_result
);
19337 vec_safe_push (used_rtx_array
, rtl
);
19343 if (CONSTANT_P (XEXP (rtl
, 0)))
19344 return add_const_value_attribute (die
, XEXP (rtl
, 0));
19347 if (!const_ok_for_output (rtl
))
19351 if (dwarf_version
>= 4 || !dwarf_strict
)
19356 /* In cases where an inlined instance of an inline function is passed
19357 the address of an `auto' variable (which is local to the caller) we
19358 can get a situation where the DECL_RTL of the artificial local
19359 variable (for the inlining) which acts as a stand-in for the
19360 corresponding formal parameter (of the inline function) will look
19361 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
19362 exactly a compile-time constant expression, but it isn't the address
19363 of the (artificial) local variable either. Rather, it represents the
19364 *value* which the artificial local variable always has during its
19365 lifetime. We currently have no way to represent such quasi-constant
19366 values in Dwarf, so for now we just punt and generate nothing. */
19374 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
19375 && MEM_READONLY_P (rtl
)
19376 && GET_MODE (rtl
) == BLKmode
)
19378 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
19384 /* No other kinds of rtx should be possible here. */
19385 gcc_unreachable ();
19390 /* Determine whether the evaluation of EXPR references any variables
19391 or functions which aren't otherwise used (and therefore may not be
19394 reference_to_unused (tree
* tp
, int * walk_subtrees
,
19395 void * data ATTRIBUTE_UNUSED
)
19397 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
19398 *walk_subtrees
= 0;
19400 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
19401 && ! TREE_ASM_WRITTEN (*tp
))
19403 /* ??? The C++ FE emits debug information for using decls, so
19404 putting gcc_unreachable here falls over. See PR31899. For now
19405 be conservative. */
19406 else if (!symtab
->global_info_ready
&& VAR_OR_FUNCTION_DECL_P (*tp
))
19408 else if (VAR_P (*tp
))
19410 varpool_node
*node
= varpool_node::get (*tp
);
19411 if (!node
|| !node
->definition
)
19414 else if (TREE_CODE (*tp
) == FUNCTION_DECL
19415 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
19417 /* The call graph machinery must have finished analyzing,
19418 optimizing and gimplifying the CU by now.
19419 So if *TP has no call graph node associated
19420 to it, it means *TP will not be emitted. */
19421 if (!cgraph_node::get (*tp
))
19424 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
19430 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
19431 for use in a later add_const_value_attribute call. */
19434 rtl_for_decl_init (tree init
, tree type
)
19436 rtx rtl
= NULL_RTX
;
19440 /* If a variable is initialized with a string constant without embedded
19441 zeros, build CONST_STRING. */
19442 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
19444 tree enttype
= TREE_TYPE (type
);
19445 tree domain
= TYPE_DOMAIN (type
);
19446 scalar_int_mode mode
;
19448 if (is_int_mode (TYPE_MODE (enttype
), &mode
)
19449 && GET_MODE_SIZE (mode
) == 1
19451 && integer_zerop (TYPE_MIN_VALUE (domain
))
19452 && compare_tree_int (TYPE_MAX_VALUE (domain
),
19453 TREE_STRING_LENGTH (init
) - 1) == 0
19454 && ((size_t) TREE_STRING_LENGTH (init
)
19455 == strlen (TREE_STRING_POINTER (init
)) + 1))
19457 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
19458 ggc_strdup (TREE_STRING_POINTER (init
)));
19459 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
19460 MEM_READONLY_P (rtl
) = 1;
19463 /* Other aggregates, and complex values, could be represented using
19465 else if (AGGREGATE_TYPE_P (type
)
19466 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
19467 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
19468 || TREE_CODE (type
) == COMPLEX_TYPE
)
19470 /* Vectors only work if their mode is supported by the target.
19471 FIXME: generic vectors ought to work too. */
19472 else if (TREE_CODE (type
) == VECTOR_TYPE
19473 && !VECTOR_MODE_P (TYPE_MODE (type
)))
19475 /* If the initializer is something that we know will expand into an
19476 immediate RTL constant, expand it now. We must be careful not to
19477 reference variables which won't be output. */
19478 else if (initializer_constant_valid_p (init
, type
)
19479 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
19481 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
19483 if (TREE_CODE (type
) == VECTOR_TYPE
)
19484 switch (TREE_CODE (init
))
19489 if (TREE_CONSTANT (init
))
19491 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
19492 bool constant_p
= true;
19494 unsigned HOST_WIDE_INT ix
;
19496 /* Even when ctor is constant, it might contain non-*_CST
19497 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
19498 belong into VECTOR_CST nodes. */
19499 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
19500 if (!CONSTANT_CLASS_P (value
))
19502 constant_p
= false;
19508 init
= build_vector_from_ctor (type
, elts
);
19518 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
19520 /* If expand_expr returns a MEM, it wasn't immediate. */
19521 gcc_assert (!rtl
|| !MEM_P (rtl
));
19527 /* Generate RTL for the variable DECL to represent its location. */
19530 rtl_for_decl_location (tree decl
)
19534 /* Here we have to decide where we are going to say the parameter "lives"
19535 (as far as the debugger is concerned). We only have a couple of
19536 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
19538 DECL_RTL normally indicates where the parameter lives during most of the
19539 activation of the function. If optimization is enabled however, this
19540 could be either NULL or else a pseudo-reg. Both of those cases indicate
19541 that the parameter doesn't really live anywhere (as far as the code
19542 generation parts of GCC are concerned) during most of the function's
19543 activation. That will happen (for example) if the parameter is never
19544 referenced within the function.
19546 We could just generate a location descriptor here for all non-NULL
19547 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
19548 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
19549 where DECL_RTL is NULL or is a pseudo-reg.
19551 Note however that we can only get away with using DECL_INCOMING_RTL as
19552 a backup substitute for DECL_RTL in certain limited cases. In cases
19553 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
19554 we can be sure that the parameter was passed using the same type as it is
19555 declared to have within the function, and that its DECL_INCOMING_RTL
19556 points us to a place where a value of that type is passed.
19558 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
19559 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
19560 because in these cases DECL_INCOMING_RTL points us to a value of some
19561 type which is *different* from the type of the parameter itself. Thus,
19562 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
19563 such cases, the debugger would end up (for example) trying to fetch a
19564 `float' from a place which actually contains the first part of a
19565 `double'. That would lead to really incorrect and confusing
19566 output at debug-time.
19568 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
19569 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
19570 are a couple of exceptions however. On little-endian machines we can
19571 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
19572 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
19573 an integral type that is smaller than TREE_TYPE (decl). These cases arise
19574 when (on a little-endian machine) a non-prototyped function has a
19575 parameter declared to be of type `short' or `char'. In such cases,
19576 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
19577 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
19578 passed `int' value. If the debugger then uses that address to fetch
19579 a `short' or a `char' (on a little-endian machine) the result will be
19580 the correct data, so we allow for such exceptional cases below.
19582 Note that our goal here is to describe the place where the given formal
19583 parameter lives during most of the function's activation (i.e. between the
19584 end of the prologue and the start of the epilogue). We'll do that as best
19585 as we can. Note however that if the given formal parameter is modified
19586 sometime during the execution of the function, then a stack backtrace (at
19587 debug-time) will show the function as having been called with the *new*
19588 value rather than the value which was originally passed in. This happens
19589 rarely enough that it is not a major problem, but it *is* a problem, and
19590 I'd like to fix it.
19592 A future version of dwarf2out.c may generate two additional attributes for
19593 any given DW_TAG_formal_parameter DIE which will describe the "passed
19594 type" and the "passed location" for the given formal parameter in addition
19595 to the attributes we now generate to indicate the "declared type" and the
19596 "active location" for each parameter. This additional set of attributes
19597 could be used by debuggers for stack backtraces. Separately, note that
19598 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
19599 This happens (for example) for inlined-instances of inline function formal
19600 parameters which are never referenced. This really shouldn't be
19601 happening. All PARM_DECL nodes should get valid non-NULL
19602 DECL_INCOMING_RTL values. FIXME. */
19604 /* Use DECL_RTL as the "location" unless we find something better. */
19605 rtl
= DECL_RTL_IF_SET (decl
);
19607 /* When generating abstract instances, ignore everything except
19608 constants, symbols living in memory, and symbols living in
19609 fixed registers. */
19610 if (! reload_completed
)
19613 && (CONSTANT_P (rtl
)
19615 && CONSTANT_P (XEXP (rtl
, 0)))
19618 && TREE_STATIC (decl
))))
19620 rtl
= targetm
.delegitimize_address (rtl
);
19625 else if (TREE_CODE (decl
) == PARM_DECL
)
19627 if (rtl
== NULL_RTX
19628 || is_pseudo_reg (rtl
)
19630 && is_pseudo_reg (XEXP (rtl
, 0))
19631 && DECL_INCOMING_RTL (decl
)
19632 && MEM_P (DECL_INCOMING_RTL (decl
))
19633 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
19635 tree declared_type
= TREE_TYPE (decl
);
19636 tree passed_type
= DECL_ARG_TYPE (decl
);
19637 machine_mode dmode
= TYPE_MODE (declared_type
);
19638 machine_mode pmode
= TYPE_MODE (passed_type
);
19640 /* This decl represents a formal parameter which was optimized out.
19641 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
19642 all cases where (rtl == NULL_RTX) just below. */
19643 if (dmode
== pmode
)
19644 rtl
= DECL_INCOMING_RTL (decl
);
19645 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
19646 && SCALAR_INT_MODE_P (dmode
)
19647 && known_le (GET_MODE_SIZE (dmode
), GET_MODE_SIZE (pmode
))
19648 && DECL_INCOMING_RTL (decl
))
19650 rtx inc
= DECL_INCOMING_RTL (decl
);
19653 else if (MEM_P (inc
))
19655 if (BYTES_BIG_ENDIAN
)
19656 rtl
= adjust_address_nv (inc
, dmode
,
19657 GET_MODE_SIZE (pmode
)
19658 - GET_MODE_SIZE (dmode
));
19665 /* If the parm was passed in registers, but lives on the stack, then
19666 make a big endian correction if the mode of the type of the
19667 parameter is not the same as the mode of the rtl. */
19668 /* ??? This is the same series of checks that are made in dbxout.c before
19669 we reach the big endian correction code there. It isn't clear if all
19670 of these checks are necessary here, but keeping them all is the safe
19672 else if (MEM_P (rtl
)
19673 && XEXP (rtl
, 0) != const0_rtx
19674 && ! CONSTANT_P (XEXP (rtl
, 0))
19675 /* Not passed in memory. */
19676 && !MEM_P (DECL_INCOMING_RTL (decl
))
19677 /* Not passed by invisible reference. */
19678 && (!REG_P (XEXP (rtl
, 0))
19679 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
19680 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
19681 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
19682 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
19685 /* Big endian correction check. */
19686 && BYTES_BIG_ENDIAN
19687 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
19688 && known_lt (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))),
19691 machine_mode addr_mode
= get_address_mode (rtl
);
19692 poly_int64 offset
= (UNITS_PER_WORD
19693 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
19695 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
19696 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
19699 else if (VAR_P (decl
)
19702 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
)))
19704 machine_mode addr_mode
= get_address_mode (rtl
);
19705 poly_int64 offset
= byte_lowpart_offset (TYPE_MODE (TREE_TYPE (decl
)),
19708 /* If a variable is declared "register" yet is smaller than
19709 a register, then if we store the variable to memory, it
19710 looks like we're storing a register-sized value, when in
19711 fact we are not. We need to adjust the offset of the
19712 storage location to reflect the actual value's bytes,
19713 else gdb will not be able to display it. */
19714 if (maybe_ne (offset
, 0))
19715 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
19716 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
19719 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
19720 and will have been substituted directly into all expressions that use it.
19721 C does not have such a concept, but C++ and other languages do. */
19722 if (!rtl
&& VAR_P (decl
) && DECL_INITIAL (decl
))
19723 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
19726 rtl
= targetm
.delegitimize_address (rtl
);
19728 /* If we don't look past the constant pool, we risk emitting a
19729 reference to a constant pool entry that isn't referenced from
19730 code, and thus is not emitted. */
19732 rtl
= avoid_constant_pool_reference (rtl
);
19734 /* Try harder to get a rtl. If this symbol ends up not being emitted
19735 in the current CU, resolve_addr will remove the expression referencing
19737 if (rtl
== NULL_RTX
19739 && !DECL_EXTERNAL (decl
)
19740 && TREE_STATIC (decl
)
19741 && DECL_NAME (decl
)
19742 && !DECL_HARD_REGISTER (decl
)
19743 && DECL_MODE (decl
) != VOIDmode
)
19745 rtl
= make_decl_rtl_for_debug (decl
);
19747 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
19748 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
19755 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
19756 returned. If so, the decl for the COMMON block is returned, and the
19757 value is the offset into the common block for the symbol. */
19760 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
19762 tree val_expr
, cvar
;
19764 poly_int64 bitsize
, bitpos
;
19766 HOST_WIDE_INT cbitpos
;
19767 int unsignedp
, reversep
, volatilep
= 0;
19769 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
19770 it does not have a value (the offset into the common area), or if it
19771 is thread local (as opposed to global) then it isn't common, and shouldn't
19772 be handled as such. */
19774 || !TREE_STATIC (decl
)
19775 || !DECL_HAS_VALUE_EXPR_P (decl
)
19779 val_expr
= DECL_VALUE_EXPR (decl
);
19780 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
19783 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
19784 &unsignedp
, &reversep
, &volatilep
);
19786 if (cvar
== NULL_TREE
19788 || DECL_ARTIFICIAL (cvar
)
19789 || !TREE_PUBLIC (cvar
)
19790 /* We don't expect to have to cope with variable offsets,
19791 since at present all static data must have a constant size. */
19792 || !bitpos
.is_constant (&cbitpos
))
19796 if (offset
!= NULL
)
19798 if (!tree_fits_shwi_p (offset
))
19800 *value
= tree_to_shwi (offset
);
19803 *value
+= cbitpos
/ BITS_PER_UNIT
;
19808 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
19809 data attribute for a variable or a parameter. We generate the
19810 DW_AT_const_value attribute only in those cases where the given variable
19811 or parameter does not have a true "location" either in memory or in a
19812 register. This can happen (for example) when a constant is passed as an
19813 actual argument in a call to an inline function. (It's possible that
19814 these things can crop up in other ways also.) Note that one type of
19815 constant value which can be passed into an inlined function is a constant
19816 pointer. This can happen for example if an actual argument in an inlined
19817 function call evaluates to a compile-time constant address.
19819 CACHE_P is true if it is worth caching the location list for DECL,
19820 so that future calls can reuse it rather than regenerate it from scratch.
19821 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
19822 since we will need to refer to them each time the function is inlined. */
19825 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
19828 dw_loc_list_ref list
;
19829 var_loc_list
*loc_list
;
19830 cached_dw_loc_list
*cache
;
19835 if (TREE_CODE (decl
) == ERROR_MARK
)
19838 if (get_AT (die
, DW_AT_location
)
19839 || get_AT (die
, DW_AT_const_value
))
19842 gcc_assert (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
19843 || TREE_CODE (decl
) == RESULT_DECL
);
19845 /* Try to get some constant RTL for this decl, and use that as the value of
19848 rtl
= rtl_for_decl_location (decl
);
19849 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19850 && add_const_value_attribute (die
, rtl
))
19853 /* See if we have single element location list that is equivalent to
19854 a constant value. That way we are better to use add_const_value_attribute
19855 rather than expanding constant value equivalent. */
19856 loc_list
= lookup_decl_loc (decl
);
19859 && loc_list
->first
->next
== NULL
19860 && NOTE_P (loc_list
->first
->loc
)
19861 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
19862 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
19864 struct var_loc_node
*node
;
19866 node
= loc_list
->first
;
19867 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
19868 if (GET_CODE (rtl
) == EXPR_LIST
)
19869 rtl
= XEXP (rtl
, 0);
19870 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19871 && add_const_value_attribute (die
, rtl
))
19874 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
19875 list several times. See if we've already cached the contents. */
19877 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
19881 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
19883 list
= cache
->loc_list
;
19887 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
19889 /* It is usually worth caching this result if the decl is from
19890 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
19891 if (cache_p
&& list
&& list
->dw_loc_next
)
19893 cached_dw_loc_list
**slot
19894 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
19897 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
19898 cache
->decl_id
= DECL_UID (decl
);
19899 cache
->loc_list
= list
;
19905 add_AT_location_description (die
, DW_AT_location
, list
);
19908 /* None of that worked, so it must not really have a location;
19909 try adding a constant value attribute from the DECL_INITIAL. */
19910 return tree_add_const_value_attribute_for_decl (die
, decl
);
19913 /* Helper function for tree_add_const_value_attribute. Natively encode
19914 initializer INIT into an array. Return true if successful. */
19917 native_encode_initializer (tree init
, unsigned char *array
, int size
)
19921 if (init
== NULL_TREE
)
19925 switch (TREE_CODE (init
))
19928 type
= TREE_TYPE (init
);
19929 if (TREE_CODE (type
) == ARRAY_TYPE
)
19931 tree enttype
= TREE_TYPE (type
);
19932 scalar_int_mode mode
;
19934 if (!is_int_mode (TYPE_MODE (enttype
), &mode
)
19935 || GET_MODE_SIZE (mode
) != 1)
19937 if (int_size_in_bytes (type
) != size
)
19939 if (size
> TREE_STRING_LENGTH (init
))
19941 memcpy (array
, TREE_STRING_POINTER (init
),
19942 TREE_STRING_LENGTH (init
));
19943 memset (array
+ TREE_STRING_LENGTH (init
),
19944 '\0', size
- TREE_STRING_LENGTH (init
));
19947 memcpy (array
, TREE_STRING_POINTER (init
), size
);
19952 type
= TREE_TYPE (init
);
19953 if (int_size_in_bytes (type
) != size
)
19955 if (TREE_CODE (type
) == ARRAY_TYPE
)
19957 HOST_WIDE_INT min_index
;
19958 unsigned HOST_WIDE_INT cnt
;
19959 int curpos
= 0, fieldsize
;
19960 constructor_elt
*ce
;
19962 if (TYPE_DOMAIN (type
) == NULL_TREE
19963 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
19966 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
19967 if (fieldsize
<= 0)
19970 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
19971 memset (array
, '\0', size
);
19972 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19974 tree val
= ce
->value
;
19975 tree index
= ce
->index
;
19977 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19978 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
19981 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
19986 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
19989 curpos
= pos
+ fieldsize
;
19990 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19992 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
19993 - tree_to_shwi (TREE_OPERAND (index
, 0));
19994 while (count
-- > 0)
19997 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
19998 curpos
+= fieldsize
;
20001 gcc_assert (curpos
<= size
);
20005 else if (TREE_CODE (type
) == RECORD_TYPE
20006 || TREE_CODE (type
) == UNION_TYPE
)
20008 tree field
= NULL_TREE
;
20009 unsigned HOST_WIDE_INT cnt
;
20010 constructor_elt
*ce
;
20012 if (int_size_in_bytes (type
) != size
)
20015 if (TREE_CODE (type
) == RECORD_TYPE
)
20016 field
= TYPE_FIELDS (type
);
20018 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
20020 tree val
= ce
->value
;
20021 int pos
, fieldsize
;
20023 if (ce
->index
!= 0)
20029 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
20032 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
20033 && TYPE_DOMAIN (TREE_TYPE (field
))
20034 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
20036 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
20037 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
20039 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
20040 pos
= int_byte_position (field
);
20041 gcc_assert (pos
+ fieldsize
<= size
);
20042 if (val
&& fieldsize
!= 0
20043 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
20049 case VIEW_CONVERT_EXPR
:
20050 case NON_LVALUE_EXPR
:
20051 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
20053 return native_encode_expr (init
, array
, size
) == size
;
20057 /* Attach a DW_AT_const_value attribute to DIE. The value of the
20058 attribute is the const value T. */
20061 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
20064 tree type
= TREE_TYPE (t
);
20067 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
20071 gcc_assert (!DECL_P (init
));
20073 if (TREE_CODE (init
) == INTEGER_CST
)
20075 if (tree_fits_uhwi_p (init
))
20077 add_AT_unsigned (die
, DW_AT_const_value
, tree_to_uhwi (init
));
20080 if (tree_fits_shwi_p (init
))
20082 add_AT_int (die
, DW_AT_const_value
, tree_to_shwi (init
));
20088 rtl
= rtl_for_decl_init (init
, type
);
20090 return add_const_value_attribute (die
, rtl
);
20092 /* If the host and target are sane, try harder. */
20093 if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
20094 && initializer_constant_valid_p (init
, type
))
20096 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
20097 if (size
> 0 && (int) size
== size
)
20099 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
20101 if (native_encode_initializer (init
, array
, size
))
20103 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
20112 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
20113 attribute is the const value of T, where T is an integral constant
20114 variable with static storage duration
20115 (so it can't be a PARM_DECL or a RESULT_DECL). */
20118 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
20122 || (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
20123 || (VAR_P (decl
) && !TREE_STATIC (decl
)))
20126 if (TREE_READONLY (decl
)
20127 && ! TREE_THIS_VOLATILE (decl
)
20128 && DECL_INITIAL (decl
))
20133 /* Don't add DW_AT_const_value if abstract origin already has one. */
20134 if (get_AT (var_die
, DW_AT_const_value
))
20137 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
20140 /* Convert the CFI instructions for the current function into a
20141 location list. This is used for DW_AT_frame_base when we targeting
20142 a dwarf2 consumer that does not support the dwarf3
20143 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
20146 static dw_loc_list_ref
20147 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
20151 dw_loc_list_ref list
, *list_tail
;
20153 dw_cfa_location last_cfa
, next_cfa
;
20154 const char *start_label
, *last_label
, *section
;
20155 dw_cfa_location remember
;
20158 gcc_assert (fde
!= NULL
);
20160 section
= secname_for_decl (current_function_decl
);
20164 memset (&next_cfa
, 0, sizeof (next_cfa
));
20165 next_cfa
.reg
= INVALID_REGNUM
;
20166 remember
= next_cfa
;
20168 start_label
= fde
->dw_fde_begin
;
20170 /* ??? Bald assumption that the CIE opcode list does not contain
20171 advance opcodes. */
20172 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
20173 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
20175 last_cfa
= next_cfa
;
20176 last_label
= start_label
;
20178 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
20180 /* If the first partition contained no CFI adjustments, the
20181 CIE opcodes apply to the whole first partition. */
20182 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
20183 fde
->dw_fde_begin
, 0, fde
->dw_fde_end
, 0, section
);
20184 list_tail
=&(*list_tail
)->dw_loc_next
;
20185 start_label
= last_label
= fde
->dw_fde_second_begin
;
20188 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
20190 switch (cfi
->dw_cfi_opc
)
20192 case DW_CFA_set_loc
:
20193 case DW_CFA_advance_loc1
:
20194 case DW_CFA_advance_loc2
:
20195 case DW_CFA_advance_loc4
:
20196 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
20198 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
20199 start_label
, 0, last_label
, 0, section
);
20201 list_tail
= &(*list_tail
)->dw_loc_next
;
20202 last_cfa
= next_cfa
;
20203 start_label
= last_label
;
20205 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
20208 case DW_CFA_advance_loc
:
20209 /* The encoding is complex enough that we should never emit this. */
20210 gcc_unreachable ();
20213 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
20216 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
20218 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
20220 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
20221 start_label
, 0, last_label
, 0, section
);
20223 list_tail
= &(*list_tail
)->dw_loc_next
;
20224 last_cfa
= next_cfa
;
20225 start_label
= last_label
;
20227 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
20228 start_label
, 0, fde
->dw_fde_end
, 0, section
);
20229 list_tail
= &(*list_tail
)->dw_loc_next
;
20230 start_label
= last_label
= fde
->dw_fde_second_begin
;
20234 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
20236 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
20237 start_label
, 0, last_label
, 0, section
);
20238 list_tail
= &(*list_tail
)->dw_loc_next
;
20239 start_label
= last_label
;
20242 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
20244 fde
->dw_fde_second_begin
20245 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
, 0,
20248 maybe_gen_llsym (list
);
20253 /* Compute a displacement from the "steady-state frame pointer" to the
20254 frame base (often the same as the CFA), and store it in
20255 frame_pointer_fb_offset. OFFSET is added to the displacement
20256 before the latter is negated. */
20259 compute_frame_pointer_to_fb_displacement (poly_int64 offset
)
20263 #ifdef FRAME_POINTER_CFA_OFFSET
20264 reg
= frame_pointer_rtx
;
20265 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
20267 reg
= arg_pointer_rtx
;
20268 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
20271 elim
= (ira_use_lra_p
20272 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
20273 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
20274 elim
= strip_offset_and_add (elim
, &offset
);
20276 frame_pointer_fb_offset
= -offset
;
20278 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
20279 in which to eliminate. This is because it's stack pointer isn't
20280 directly accessible as a register within the ISA. To work around
20281 this, assume that while we cannot provide a proper value for
20282 frame_pointer_fb_offset, we won't need one either. */
20283 frame_pointer_fb_offset_valid
20284 = ((SUPPORTS_STACK_ALIGNMENT
20285 && (elim
== hard_frame_pointer_rtx
20286 || elim
== stack_pointer_rtx
))
20287 || elim
== (frame_pointer_needed
20288 ? hard_frame_pointer_rtx
20289 : stack_pointer_rtx
));
20292 /* Generate a DW_AT_name attribute given some string value to be included as
20293 the value of the attribute. */
20296 add_name_attribute (dw_die_ref die
, const char *name_string
)
20298 if (name_string
!= NULL
&& *name_string
!= 0)
20300 if (demangle_name_func
)
20301 name_string
= (*demangle_name_func
) (name_string
);
20303 add_AT_string (die
, DW_AT_name
, name_string
);
20307 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
20308 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
20309 of TYPE accordingly.
20311 ??? This is a temporary measure until after we're able to generate
20312 regular DWARF for the complex Ada type system. */
20315 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
20316 dw_die_ref context_die
)
20319 dw_die_ref dtype_die
;
20321 if (!lang_hooks
.types
.descriptive_type
)
20324 dtype
= lang_hooks
.types
.descriptive_type (type
);
20328 dtype_die
= lookup_type_die (dtype
);
20331 gen_type_die (dtype
, context_die
);
20332 dtype_die
= lookup_type_die (dtype
);
20333 gcc_assert (dtype_die
);
20336 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
20339 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
20341 static const char *
20342 comp_dir_string (void)
20346 static const char *cached_wd
= NULL
;
20348 if (cached_wd
!= NULL
)
20351 wd
= get_src_pwd ();
20355 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
20359 wdlen
= strlen (wd
);
20360 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
20362 wd1
[wdlen
] = DIR_SEPARATOR
;
20363 wd1
[wdlen
+ 1] = 0;
20367 cached_wd
= remap_debug_filename (wd
);
20371 /* Generate a DW_AT_comp_dir attribute for DIE. */
20374 add_comp_dir_attribute (dw_die_ref die
)
20376 const char * wd
= comp_dir_string ();
20378 add_AT_string (die
, DW_AT_comp_dir
, wd
);
20381 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
20382 pointer computation, ...), output a representation for that bound according
20383 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
20384 loc_list_from_tree for the meaning of CONTEXT. */
20387 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
20388 int forms
, struct loc_descr_context
*context
)
20390 dw_die_ref context_die
, decl_die
;
20391 dw_loc_list_ref list
;
20392 bool strip_conversions
= true;
20393 bool placeholder_seen
= false;
20395 while (strip_conversions
)
20396 switch (TREE_CODE (value
))
20403 case VIEW_CONVERT_EXPR
:
20404 value
= TREE_OPERAND (value
, 0);
20408 strip_conversions
= false;
20412 /* If possible and permitted, output the attribute as a constant. */
20413 if ((forms
& dw_scalar_form_constant
) != 0
20414 && TREE_CODE (value
) == INTEGER_CST
)
20416 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
20418 /* If HOST_WIDE_INT is big enough then represent the bound as
20419 a constant value. We need to choose a form based on
20420 whether the type is signed or unsigned. We cannot just
20421 call add_AT_unsigned if the value itself is positive
20422 (add_AT_unsigned might add the unsigned value encoded as
20423 DW_FORM_data[1248]). Some DWARF consumers will lookup the
20424 bounds type and then sign extend any unsigned values found
20425 for signed types. This is needed only for
20426 DW_AT_{lower,upper}_bound, since for most other attributes,
20427 consumers will treat DW_FORM_data[1248] as unsigned values,
20428 regardless of the underlying type. */
20429 if (prec
<= HOST_BITS_PER_WIDE_INT
20430 || tree_fits_uhwi_p (value
))
20432 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
20433 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
20435 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
20438 /* Otherwise represent the bound as an unsigned value with
20439 the precision of its type. The precision and signedness
20440 of the type will be necessary to re-interpret it
20442 add_AT_wide (die
, attr
, wi::to_wide (value
));
20446 /* Otherwise, if it's possible and permitted too, output a reference to
20448 if ((forms
& dw_scalar_form_reference
) != 0)
20450 tree decl
= NULL_TREE
;
20452 /* Some type attributes reference an outer type. For instance, the upper
20453 bound of an array may reference an embedding record (this happens in
20455 if (TREE_CODE (value
) == COMPONENT_REF
20456 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
20457 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
20458 decl
= TREE_OPERAND (value
, 1);
20460 else if (VAR_P (value
)
20461 || TREE_CODE (value
) == PARM_DECL
20462 || TREE_CODE (value
) == RESULT_DECL
)
20465 if (decl
!= NULL_TREE
)
20467 dw_die_ref decl_die
= lookup_decl_die (decl
);
20469 /* ??? Can this happen, or should the variable have been bound
20470 first? Probably it can, since I imagine that we try to create
20471 the types of parameters in the order in which they exist in
20472 the list, and won't have created a forward reference to a
20473 later parameter. */
20474 if (decl_die
!= NULL
)
20476 add_AT_die_ref (die
, attr
, decl_die
);
20482 /* Last chance: try to create a stack operation procedure to evaluate the
20483 value. Do nothing if even that is not possible or permitted. */
20484 if ((forms
& dw_scalar_form_exprloc
) == 0)
20487 list
= loc_list_from_tree (value
, 2, context
);
20488 if (context
&& context
->placeholder_arg
)
20490 placeholder_seen
= context
->placeholder_seen
;
20491 context
->placeholder_seen
= false;
20493 if (list
== NULL
|| single_element_loc_list_p (list
))
20495 /* If this attribute is not a reference nor constant, it is
20496 a DWARF expression rather than location description. For that
20497 loc_list_from_tree (value, 0, &context) is needed. */
20498 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
20499 if (list2
&& single_element_loc_list_p (list2
))
20501 if (placeholder_seen
)
20503 struct dwarf_procedure_info dpi
;
20504 dpi
.fndecl
= NULL_TREE
;
20505 dpi
.args_count
= 1;
20506 if (!resolve_args_picking (list2
->expr
, 1, &dpi
))
20509 add_AT_loc (die
, attr
, list2
->expr
);
20514 /* If that failed to give a single element location list, fall back to
20515 outputting this as a reference... still if permitted. */
20517 || (forms
& dw_scalar_form_reference
) == 0
20518 || placeholder_seen
)
20521 if (current_function_decl
== 0)
20522 context_die
= comp_unit_die ();
20524 context_die
= lookup_decl_die (current_function_decl
);
20526 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
20527 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
20528 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
20530 add_AT_location_description (decl_die
, DW_AT_location
, list
);
20531 add_AT_die_ref (die
, attr
, decl_die
);
20534 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
20538 lower_bound_default (void)
20540 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
20546 case DW_LANG_C_plus_plus
:
20547 case DW_LANG_C_plus_plus_11
:
20548 case DW_LANG_C_plus_plus_14
:
20550 case DW_LANG_ObjC_plus_plus
:
20552 case DW_LANG_Fortran77
:
20553 case DW_LANG_Fortran90
:
20554 case DW_LANG_Fortran95
:
20555 case DW_LANG_Fortran03
:
20556 case DW_LANG_Fortran08
:
20560 case DW_LANG_Python
:
20561 return dwarf_version
>= 4 ? 0 : -1;
20562 case DW_LANG_Ada95
:
20563 case DW_LANG_Ada83
:
20564 case DW_LANG_Cobol74
:
20565 case DW_LANG_Cobol85
:
20566 case DW_LANG_Modula2
:
20568 return dwarf_version
>= 4 ? 1 : -1;
20574 /* Given a tree node describing an array bound (either lower or upper) output
20575 a representation for that bound. */
20578 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
20579 tree bound
, struct loc_descr_context
*context
)
20584 switch (TREE_CODE (bound
))
20586 /* Strip all conversions. */
20588 case VIEW_CONVERT_EXPR
:
20589 bound
= TREE_OPERAND (bound
, 0);
20592 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
20593 are even omitted when they are the default. */
20595 /* If the value for this bound is the default one, we can even omit the
20597 if (bound_attr
== DW_AT_lower_bound
20598 && tree_fits_shwi_p (bound
)
20599 && (dflt
= lower_bound_default ()) != -1
20600 && tree_to_shwi (bound
) == dflt
)
20606 /* Because of the complex interaction there can be with other GNAT
20607 encodings, GDB isn't ready yet to handle proper DWARF description
20608 for self-referencial subrange bounds: let GNAT encodings do the
20609 magic in such a case. */
20611 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
20612 && contains_placeholder_p (bound
))
20615 add_scalar_info (subrange_die
, bound_attr
, bound
,
20616 dw_scalar_form_constant
20617 | dw_scalar_form_exprloc
20618 | dw_scalar_form_reference
,
20624 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
20625 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
20626 Note that the block of subscript information for an array type also
20627 includes information about the element type of the given array type.
20629 This function reuses previously set type and bound information if
20633 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
20635 unsigned dimension_number
;
20637 dw_die_ref child
= type_die
->die_child
;
20639 for (dimension_number
= 0;
20640 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
20641 type
= TREE_TYPE (type
), dimension_number
++)
20643 tree domain
= TYPE_DOMAIN (type
);
20645 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
20648 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
20649 and (in GNU C only) variable bounds. Handle all three forms
20652 /* Find and reuse a previously generated DW_TAG_subrange_type if
20655 For multi-dimensional arrays, as we iterate through the
20656 various dimensions in the enclosing for loop above, we also
20657 iterate through the DIE children and pick at each
20658 DW_TAG_subrange_type previously generated (if available).
20659 Each child DW_TAG_subrange_type DIE describes the range of
20660 the current dimension. At this point we should have as many
20661 DW_TAG_subrange_type's as we have dimensions in the
20663 dw_die_ref subrange_die
= NULL
;
20667 child
= child
->die_sib
;
20668 if (child
->die_tag
== DW_TAG_subrange_type
)
20669 subrange_die
= child
;
20670 if (child
== type_die
->die_child
)
20672 /* If we wrapped around, stop looking next time. */
20676 if (child
->die_tag
== DW_TAG_subrange_type
)
20680 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
20684 /* We have an array type with specified bounds. */
20685 lower
= TYPE_MIN_VALUE (domain
);
20686 upper
= TYPE_MAX_VALUE (domain
);
20688 /* Define the index type. */
20689 if (TREE_TYPE (domain
)
20690 && !get_AT (subrange_die
, DW_AT_type
))
20692 /* ??? This is probably an Ada unnamed subrange type. Ignore the
20693 TREE_TYPE field. We can't emit debug info for this
20694 because it is an unnamed integral type. */
20695 if (TREE_CODE (domain
) == INTEGER_TYPE
20696 && TYPE_NAME (domain
) == NULL_TREE
20697 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
20698 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
20701 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
20702 TYPE_UNQUALIFIED
, false, type_die
);
20705 /* ??? If upper is NULL, the array has unspecified length,
20706 but it does have a lower bound. This happens with Fortran
20708 Since the debugger is definitely going to need to know N
20709 to produce useful results, go ahead and output the lower
20710 bound solo, and hope the debugger can cope. */
20712 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
20713 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
20714 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
20715 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
20718 /* Otherwise we have an array type with an unspecified length. The
20719 DWARF-2 spec does not say how to handle this; let's just leave out the
20724 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
20727 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
20729 dw_die_ref decl_die
;
20730 HOST_WIDE_INT size
;
20731 dw_loc_descr_ref size_expr
= NULL
;
20733 switch (TREE_CODE (tree_node
))
20738 case ENUMERAL_TYPE
:
20741 case QUAL_UNION_TYPE
:
20742 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
20743 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
20745 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
20748 size_expr
= type_byte_size (tree_node
, &size
);
20751 /* For a data member of a struct or union, the DW_AT_byte_size is
20752 generally given as the number of bytes normally allocated for an
20753 object of the *declared* type of the member itself. This is true
20754 even for bit-fields. */
20755 size
= int_size_in_bytes (field_type (tree_node
));
20758 gcc_unreachable ();
20761 /* Support for dynamically-sized objects was introduced by DWARFv3.
20762 At the moment, GDB does not handle variable byte sizes very well,
20764 if ((dwarf_version
>= 3 || !dwarf_strict
)
20765 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
20766 && size_expr
!= NULL
)
20767 add_AT_loc (die
, DW_AT_byte_size
, size_expr
);
20769 /* Note that `size' might be -1 when we get to this point. If it is, that
20770 indicates that the byte size of the entity in question is variable and
20771 that we could not generate a DWARF expression that computes it. */
20773 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
20776 /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
20780 add_alignment_attribute (dw_die_ref die
, tree tree_node
)
20782 if (dwarf_version
< 5 && dwarf_strict
)
20787 if (DECL_P (tree_node
))
20789 if (!DECL_USER_ALIGN (tree_node
))
20792 align
= DECL_ALIGN_UNIT (tree_node
);
20794 else if (TYPE_P (tree_node
))
20796 if (!TYPE_USER_ALIGN (tree_node
))
20799 align
= TYPE_ALIGN_UNIT (tree_node
);
20802 gcc_unreachable ();
20804 add_AT_unsigned (die
, DW_AT_alignment
, align
);
20807 /* For a FIELD_DECL node which represents a bit-field, output an attribute
20808 which specifies the distance in bits from the highest order bit of the
20809 "containing object" for the bit-field to the highest order bit of the
20812 For any given bit-field, the "containing object" is a hypothetical object
20813 (of some integral or enum type) within which the given bit-field lives. The
20814 type of this hypothetical "containing object" is always the same as the
20815 declared type of the individual bit-field itself. The determination of the
20816 exact location of the "containing object" for a bit-field is rather
20817 complicated. It's handled by the `field_byte_offset' function (above).
20819 CTX is required: see the comment for VLR_CONTEXT.
20821 Note that it is the size (in bytes) of the hypothetical "containing object"
20822 which will be given in the DW_AT_byte_size attribute for this bit-field.
20823 (See `byte_size_attribute' above). */
20826 add_bit_offset_attribute (dw_die_ref die
, tree decl
, struct vlr_context
*ctx
)
20828 HOST_WIDE_INT object_offset_in_bytes
;
20829 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
20830 HOST_WIDE_INT bitpos_int
;
20831 HOST_WIDE_INT highest_order_object_bit_offset
;
20832 HOST_WIDE_INT highest_order_field_bit_offset
;
20833 HOST_WIDE_INT bit_offset
;
20835 field_byte_offset (decl
, ctx
, &object_offset_in_bytes
);
20837 /* Must be a field and a bit field. */
20838 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
20840 /* We can't yet handle bit-fields whose offsets are variable, so if we
20841 encounter such things, just return without generating any attribute
20842 whatsoever. Likewise for variable or too large size. */
20843 if (! tree_fits_shwi_p (bit_position (decl
))
20844 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
20847 bitpos_int
= int_bit_position (decl
);
20849 /* Note that the bit offset is always the distance (in bits) from the
20850 highest-order bit of the "containing object" to the highest-order bit of
20851 the bit-field itself. Since the "high-order end" of any object or field
20852 is different on big-endian and little-endian machines, the computation
20853 below must take account of these differences. */
20854 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
20855 highest_order_field_bit_offset
= bitpos_int
;
20857 if (! BYTES_BIG_ENDIAN
)
20859 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
20860 highest_order_object_bit_offset
+=
20861 simple_type_size_in_bits (original_type
);
20865 = (! BYTES_BIG_ENDIAN
20866 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
20867 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
20869 if (bit_offset
< 0)
20870 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
20872 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
20875 /* For a FIELD_DECL node which represents a bit field, output an attribute
20876 which specifies the length in bits of the given field. */
20879 add_bit_size_attribute (dw_die_ref die
, tree decl
)
20881 /* Must be a field and a bit field. */
20882 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
20883 && DECL_BIT_FIELD_TYPE (decl
));
20885 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
20886 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
20889 /* If the compiled language is ANSI C, then add a 'prototyped'
20890 attribute, if arg types are given for the parameters of a function. */
20893 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
20895 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
20902 if (prototype_p (func_type
))
20903 add_AT_flag (die
, DW_AT_prototyped
, 1);
20910 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
20911 by looking in the type declaration, the object declaration equate table or
20912 the block mapping. */
20914 static inline dw_die_ref
20915 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
20917 dw_die_ref origin_die
= NULL
;
20919 if (DECL_P (origin
))
20922 origin_die
= lookup_decl_die (origin
);
20923 /* "Unwrap" the decls DIE which we put in the imported unit context.
20924 We are looking for the abstract copy here. */
20927 && (c
= get_AT_ref (origin_die
, DW_AT_abstract_origin
))
20928 /* ??? Identify this better. */
20932 else if (TYPE_P (origin
))
20933 origin_die
= lookup_type_die (origin
);
20934 else if (TREE_CODE (origin
) == BLOCK
)
20935 origin_die
= BLOCK_DIE (origin
);
20937 /* XXX: Functions that are never lowered don't always have correct block
20938 trees (in the case of java, they simply have no block tree, in some other
20939 languages). For these functions, there is nothing we can really do to
20940 output correct debug info for inlined functions in all cases. Rather
20941 than die, we'll just produce deficient debug info now, in that we will
20942 have variables without a proper abstract origin. In the future, when all
20943 functions are lowered, we should re-add a gcc_assert (origin_die)
20947 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
20951 /* We do not currently support the pure_virtual attribute. */
20954 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
20956 if (DECL_VINDEX (func_decl
))
20958 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20960 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
20961 add_AT_loc (die
, DW_AT_vtable_elem_location
,
20962 new_loc_descr (DW_OP_constu
,
20963 tree_to_shwi (DECL_VINDEX (func_decl
)),
20966 /* GNU extension: Record what type this method came from originally. */
20967 if (debug_info_level
> DINFO_LEVEL_TERSE
20968 && DECL_CONTEXT (func_decl
))
20969 add_AT_die_ref (die
, DW_AT_containing_type
,
20970 lookup_type_die (DECL_CONTEXT (func_decl
)));
20974 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
20975 given decl. This used to be a vendor extension until after DWARF 4
20976 standardized it. */
20979 add_linkage_attr (dw_die_ref die
, tree decl
)
20981 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
20983 /* Mimic what assemble_name_raw does with a leading '*'. */
20984 if (name
[0] == '*')
20987 if (dwarf_version
>= 4)
20988 add_AT_string (die
, DW_AT_linkage_name
, name
);
20990 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
20993 /* Add source coordinate attributes for the given decl. */
20996 add_src_coords_attributes (dw_die_ref die
, tree decl
)
20998 expanded_location s
;
21000 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
21002 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
21003 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
21004 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
21005 if (debug_column_info
&& s
.column
)
21006 add_AT_unsigned (die
, DW_AT_decl_column
, s
.column
);
21009 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
21012 add_linkage_name_raw (dw_die_ref die
, tree decl
)
21014 /* Defer until we have an assembler name set. */
21015 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
21017 limbo_die_node
*asm_name
;
21019 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
21020 asm_name
->die
= die
;
21021 asm_name
->created_for
= decl
;
21022 asm_name
->next
= deferred_asm_name
;
21023 deferred_asm_name
= asm_name
;
21025 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
21026 add_linkage_attr (die
, decl
);
21029 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
21032 add_linkage_name (dw_die_ref die
, tree decl
)
21034 if (debug_info_level
> DINFO_LEVEL_NONE
21035 && VAR_OR_FUNCTION_DECL_P (decl
)
21036 && TREE_PUBLIC (decl
)
21037 && !(VAR_P (decl
) && DECL_REGISTER (decl
))
21038 && die
->die_tag
!= DW_TAG_member
)
21039 add_linkage_name_raw (die
, decl
);
21042 /* Add a DW_AT_name attribute and source coordinate attribute for the
21043 given decl, but only if it actually has a name. */
21046 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
,
21047 bool no_linkage_name
)
21051 decl_name
= DECL_NAME (decl
);
21052 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
21054 const char *name
= dwarf2_name (decl
, 0);
21056 add_name_attribute (die
, name
);
21057 if (! DECL_ARTIFICIAL (decl
))
21058 add_src_coords_attributes (die
, decl
);
21060 if (!no_linkage_name
)
21061 add_linkage_name (die
, decl
);
21064 #ifdef VMS_DEBUGGING_INFO
21065 /* Get the function's name, as described by its RTL. This may be different
21066 from the DECL_NAME name used in the source file. */
21067 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
21069 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
21070 XEXP (DECL_RTL (decl
), 0), false);
21071 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
21073 #endif /* VMS_DEBUGGING_INFO */
21076 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
21079 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
21083 attr
.dw_attr
= DW_AT_discr_value
;
21084 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
21085 attr
.dw_attr_val
.val_entry
= NULL
;
21086 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
21088 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
21090 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
21091 add_dwarf_attr (die
, &attr
);
21094 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
21097 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
21101 attr
.dw_attr
= DW_AT_discr_list
;
21102 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
21103 attr
.dw_attr_val
.val_entry
= NULL
;
21104 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
21105 add_dwarf_attr (die
, &attr
);
21108 static inline dw_discr_list_ref
21109 AT_discr_list (dw_attr_node
*attr
)
21111 return attr
->dw_attr_val
.v
.val_discr_list
;
21114 #ifdef VMS_DEBUGGING_INFO
21115 /* Output the debug main pointer die for VMS */
21118 dwarf2out_vms_debug_main_pointer (void)
21120 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21123 /* Allocate the VMS debug main subprogram die. */
21124 die
= new_die_raw (DW_TAG_subprogram
);
21125 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
21126 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
21127 current_function_funcdef_no
);
21128 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
21130 /* Make it the first child of comp_unit_die (). */
21131 die
->die_parent
= comp_unit_die ();
21132 if (comp_unit_die ()->die_child
)
21134 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
21135 comp_unit_die ()->die_child
->die_sib
= die
;
21139 die
->die_sib
= die
;
21140 comp_unit_die ()->die_child
= die
;
21143 #endif /* VMS_DEBUGGING_INFO */
21145 /* Push a new declaration scope. */
21148 push_decl_scope (tree scope
)
21150 vec_safe_push (decl_scope_table
, scope
);
21153 /* Pop a declaration scope. */
21156 pop_decl_scope (void)
21158 decl_scope_table
->pop ();
21161 /* walk_tree helper function for uses_local_type, below. */
21164 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
21167 *walk_subtrees
= 0;
21170 tree name
= TYPE_NAME (*tp
);
21171 if (name
&& DECL_P (name
) && decl_function_context (name
))
21177 /* If TYPE involves a function-local type (including a local typedef to a
21178 non-local type), returns that type; otherwise returns NULL_TREE. */
21181 uses_local_type (tree type
)
21183 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
21187 /* Return the DIE for the scope that immediately contains this type.
21188 Non-named types that do not involve a function-local type get global
21189 scope. Named types nested in namespaces or other types get their
21190 containing scope. All other types (i.e. function-local named types) get
21191 the current active scope. */
21194 scope_die_for (tree t
, dw_die_ref context_die
)
21196 dw_die_ref scope_die
= NULL
;
21197 tree containing_scope
;
21199 /* Non-types always go in the current scope. */
21200 gcc_assert (TYPE_P (t
));
21202 /* Use the scope of the typedef, rather than the scope of the type
21204 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
21205 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
21207 containing_scope
= TYPE_CONTEXT (t
);
21209 /* Use the containing namespace if there is one. */
21210 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
21212 if (context_die
== lookup_decl_die (containing_scope
))
21214 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
21215 context_die
= get_context_die (containing_scope
);
21217 containing_scope
= NULL_TREE
;
21220 /* Ignore function type "scopes" from the C frontend. They mean that
21221 a tagged type is local to a parmlist of a function declarator, but
21222 that isn't useful to DWARF. */
21223 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
21224 containing_scope
= NULL_TREE
;
21226 if (SCOPE_FILE_SCOPE_P (containing_scope
))
21228 /* If T uses a local type keep it local as well, to avoid references
21229 to function-local DIEs from outside the function. */
21230 if (current_function_decl
&& uses_local_type (t
))
21231 scope_die
= context_die
;
21233 scope_die
= comp_unit_die ();
21235 else if (TYPE_P (containing_scope
))
21237 /* For types, we can just look up the appropriate DIE. */
21238 if (debug_info_level
> DINFO_LEVEL_TERSE
)
21239 scope_die
= get_context_die (containing_scope
);
21242 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
21243 if (scope_die
== NULL
)
21244 scope_die
= comp_unit_die ();
21248 scope_die
= context_die
;
21253 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
21256 local_scope_p (dw_die_ref context_die
)
21258 for (; context_die
; context_die
= context_die
->die_parent
)
21259 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
21260 || context_die
->die_tag
== DW_TAG_subprogram
)
21266 /* Returns nonzero if CONTEXT_DIE is a class. */
21269 class_scope_p (dw_die_ref context_die
)
21271 return (context_die
21272 && (context_die
->die_tag
== DW_TAG_structure_type
21273 || context_die
->die_tag
== DW_TAG_class_type
21274 || context_die
->die_tag
== DW_TAG_interface_type
21275 || context_die
->die_tag
== DW_TAG_union_type
));
21278 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
21279 whether or not to treat a DIE in this context as a declaration. */
21282 class_or_namespace_scope_p (dw_die_ref context_die
)
21284 return (class_scope_p (context_die
)
21285 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
21288 /* Many forms of DIEs require a "type description" attribute. This
21289 routine locates the proper "type descriptor" die for the type given
21290 by 'type' plus any additional qualifiers given by 'cv_quals', and
21291 adds a DW_AT_type attribute below the given die. */
21294 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
21295 bool reverse
, dw_die_ref context_die
)
21297 enum tree_code code
= TREE_CODE (type
);
21298 dw_die_ref type_die
= NULL
;
21300 /* ??? If this type is an unnamed subrange type of an integral, floating-point
21301 or fixed-point type, use the inner type. This is because we have no
21302 support for unnamed types in base_type_die. This can happen if this is
21303 an Ada subrange type. Correct solution is emit a subrange type die. */
21304 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
21305 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
21306 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
21308 if (code
== ERROR_MARK
21309 /* Handle a special case. For functions whose return type is void, we
21310 generate *no* type attribute. (Note that no object may have type
21311 `void', so this only applies to function return types). */
21312 || code
== VOID_TYPE
)
21315 type_die
= modified_type_die (type
,
21316 cv_quals
| TYPE_QUALS (type
),
21320 if (type_die
!= NULL
)
21321 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
21324 /* Given an object die, add the calling convention attribute for the
21325 function call type. */
21327 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
21329 enum dwarf_calling_convention value
= DW_CC_normal
;
21331 value
= ((enum dwarf_calling_convention
)
21332 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
21335 && id_equal (DECL_ASSEMBLER_NAME (decl
), "MAIN__"))
21337 /* DWARF 2 doesn't provide a way to identify a program's source-level
21338 entry point. DW_AT_calling_convention attributes are only meant
21339 to describe functions' calling conventions. However, lacking a
21340 better way to signal the Fortran main program, we used this for
21341 a long time, following existing custom. Now, DWARF 4 has
21342 DW_AT_main_subprogram, which we add below, but some tools still
21343 rely on the old way, which we thus keep. */
21344 value
= DW_CC_program
;
21346 if (dwarf_version
>= 4 || !dwarf_strict
)
21347 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
21350 /* Only add the attribute if the backend requests it, and
21351 is not DW_CC_normal. */
21352 if (value
&& (value
!= DW_CC_normal
))
21353 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
21356 /* Given a tree pointer to a struct, class, union, or enum type node, return
21357 a pointer to the (string) tag name for the given type, or zero if the type
21358 was declared without a tag. */
21360 static const char *
21361 type_tag (const_tree type
)
21363 const char *name
= 0;
21365 if (TYPE_NAME (type
) != 0)
21369 /* Find the IDENTIFIER_NODE for the type name. */
21370 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
21371 && !TYPE_NAMELESS (type
))
21372 t
= TYPE_NAME (type
);
21374 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
21375 a TYPE_DECL node, regardless of whether or not a `typedef' was
21377 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
21378 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
21380 /* We want to be extra verbose. Don't call dwarf_name if
21381 DECL_NAME isn't set. The default hook for decl_printable_name
21382 doesn't like that, and in this context it's correct to return
21383 0, instead of "<anonymous>" or the like. */
21384 if (DECL_NAME (TYPE_NAME (type
))
21385 && !DECL_NAMELESS (TYPE_NAME (type
)))
21386 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
21389 /* Now get the name as a string, or invent one. */
21390 if (!name
&& t
!= 0)
21391 name
= IDENTIFIER_POINTER (t
);
21394 return (name
== 0 || *name
== '\0') ? 0 : name
;
21397 /* Return the type associated with a data member, make a special check
21398 for bit field types. */
21401 member_declared_type (const_tree member
)
21403 return (DECL_BIT_FIELD_TYPE (member
)
21404 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
21407 /* Get the decl's label, as described by its RTL. This may be different
21408 from the DECL_NAME name used in the source file. */
21411 static const char *
21412 decl_start_label (tree decl
)
21415 const char *fnname
;
21417 x
= DECL_RTL (decl
);
21418 gcc_assert (MEM_P (x
));
21421 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
21423 fnname
= XSTR (x
, 0);
21428 /* For variable-length arrays that have been previously generated, but
21429 may be incomplete due to missing subscript info, fill the subscript
21430 info. Return TRUE if this is one of those cases. */
21432 fill_variable_array_bounds (tree type
)
21434 if (TREE_ASM_WRITTEN (type
)
21435 && TREE_CODE (type
) == ARRAY_TYPE
21436 && variably_modified_type_p (type
, NULL
))
21438 dw_die_ref array_die
= lookup_type_die (type
);
21441 add_subscript_info (array_die
, type
, !is_ada ());
21447 /* These routines generate the internal representation of the DIE's for
21448 the compilation unit. Debugging information is collected by walking
21449 the declaration trees passed in from dwarf2out_decl(). */
21452 gen_array_type_die (tree type
, dw_die_ref context_die
)
21454 dw_die_ref array_die
;
21456 /* GNU compilers represent multidimensional array types as sequences of one
21457 dimensional array types whose element types are themselves array types.
21458 We sometimes squish that down to a single array_type DIE with multiple
21459 subscripts in the Dwarf debugging info. The draft Dwarf specification
21460 say that we are allowed to do this kind of compression in C, because
21461 there is no difference between an array of arrays and a multidimensional
21462 array. We don't do this for Ada to remain as close as possible to the
21463 actual representation, which is especially important against the language
21464 flexibilty wrt arrays of variable size. */
21466 bool collapse_nested_arrays
= !is_ada ();
21468 if (fill_variable_array_bounds (type
))
21471 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
21474 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
21475 DW_TAG_string_type doesn't have DW_AT_type attribute). */
21476 if (TYPE_STRING_FLAG (type
)
21477 && TREE_CODE (type
) == ARRAY_TYPE
21479 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
21481 HOST_WIDE_INT size
;
21483 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
21484 add_name_attribute (array_die
, type_tag (type
));
21485 equate_type_number_to_die (type
, array_die
);
21486 size
= int_size_in_bytes (type
);
21488 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
21489 /* ??? We can't annotate types late, but for LTO we may not
21490 generate a location early either (gfortran.dg/save_6.f90). */
21491 else if (! (early_dwarf
&& (flag_generate_lto
|| flag_generate_offload
))
21492 && TYPE_DOMAIN (type
) != NULL_TREE
21493 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
21495 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
21496 tree rszdecl
= szdecl
;
21498 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
21499 if (!DECL_P (szdecl
))
21501 if (TREE_CODE (szdecl
) == INDIRECT_REF
21502 && DECL_P (TREE_OPERAND (szdecl
, 0)))
21504 rszdecl
= TREE_OPERAND (szdecl
, 0);
21505 if (int_size_in_bytes (TREE_TYPE (rszdecl
))
21506 != DWARF2_ADDR_SIZE
)
21514 dw_loc_list_ref loc
21515 = loc_list_from_tree (rszdecl
, szdecl
== rszdecl
? 2 : 0,
21519 add_AT_location_description (array_die
, DW_AT_string_length
,
21521 if (size
!= DWARF2_ADDR_SIZE
)
21522 add_AT_unsigned (array_die
, dwarf_version
>= 5
21523 ? DW_AT_string_length_byte_size
21524 : DW_AT_byte_size
, size
);
21531 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
21532 add_name_attribute (array_die
, type_tag (type
));
21533 equate_type_number_to_die (type
, array_die
);
21535 if (TREE_CODE (type
) == VECTOR_TYPE
)
21536 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
21538 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
21540 && TREE_CODE (type
) == ARRAY_TYPE
21541 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
21542 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
21543 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
21546 /* We default the array ordering. Debuggers will probably do the right
21547 things even if DW_AT_ordering is not present. It's not even an issue
21548 until we start to get into multidimensional arrays anyway. If a debugger
21549 is ever caught doing the Wrong Thing for multi-dimensional arrays,
21550 then we'll have to put the DW_AT_ordering attribute back in. (But if
21551 and when we find out that we need to put these in, we will only do so
21552 for multidimensional arrays. */
21553 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
21556 if (TREE_CODE (type
) == VECTOR_TYPE
)
21558 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
21559 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
21560 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
21561 add_bound_info (subrange_die
, DW_AT_upper_bound
,
21562 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
21565 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
21567 /* Add representation of the type of the elements of this array type and
21568 emit the corresponding DIE if we haven't done it already. */
21569 element_type
= TREE_TYPE (type
);
21570 if (collapse_nested_arrays
)
21571 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
21573 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
21575 element_type
= TREE_TYPE (element_type
);
21578 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
21579 TREE_CODE (type
) == ARRAY_TYPE
21580 && TYPE_REVERSE_STORAGE_ORDER (type
),
21583 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
21584 if (TYPE_ARTIFICIAL (type
))
21585 add_AT_flag (array_die
, DW_AT_artificial
, 1);
21587 if (get_AT (array_die
, DW_AT_name
))
21588 add_pubtype (type
, array_die
);
21590 add_alignment_attribute (array_die
, type
);
21593 /* This routine generates DIE for array with hidden descriptor, details
21594 are filled into *info by a langhook. */
21597 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
21598 dw_die_ref context_die
)
21600 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
21601 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
21602 struct loc_descr_context context
= { type
, info
->base_decl
, NULL
,
21604 enum dwarf_tag subrange_tag
= DW_TAG_subrange_type
;
21607 add_name_attribute (array_die
, type_tag (type
));
21608 equate_type_number_to_die (type
, array_die
);
21610 if (info
->ndimensions
> 1)
21611 switch (info
->ordering
)
21613 case array_descr_ordering_row_major
:
21614 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
21616 case array_descr_ordering_column_major
:
21617 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
21623 if (dwarf_version
>= 3 || !dwarf_strict
)
21625 if (info
->data_location
)
21626 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
21627 dw_scalar_form_exprloc
, &context
);
21628 if (info
->associated
)
21629 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
21630 dw_scalar_form_constant
21631 | dw_scalar_form_exprloc
21632 | dw_scalar_form_reference
, &context
);
21633 if (info
->allocated
)
21634 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
21635 dw_scalar_form_constant
21636 | dw_scalar_form_exprloc
21637 | dw_scalar_form_reference
, &context
);
21640 const enum dwarf_attribute attr
21641 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
21643 = (info
->stride_in_bits
)
21644 ? dw_scalar_form_constant
21645 : (dw_scalar_form_constant
21646 | dw_scalar_form_exprloc
21647 | dw_scalar_form_reference
);
21649 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
21652 if (dwarf_version
>= 5)
21656 add_scalar_info (array_die
, DW_AT_rank
, info
->rank
,
21657 dw_scalar_form_constant
21658 | dw_scalar_form_exprloc
, &context
);
21659 subrange_tag
= DW_TAG_generic_subrange
;
21660 context
.placeholder_arg
= true;
21664 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
21666 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
21668 dw_die_ref subrange_die
= new_die (subrange_tag
, array_die
, NULL
);
21670 if (info
->dimen
[dim
].bounds_type
)
21671 add_type_attribute (subrange_die
,
21672 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
21673 false, context_die
);
21674 if (info
->dimen
[dim
].lower_bound
)
21675 add_bound_info (subrange_die
, DW_AT_lower_bound
,
21676 info
->dimen
[dim
].lower_bound
, &context
);
21677 if (info
->dimen
[dim
].upper_bound
)
21678 add_bound_info (subrange_die
, DW_AT_upper_bound
,
21679 info
->dimen
[dim
].upper_bound
, &context
);
21680 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
21681 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
21682 info
->dimen
[dim
].stride
,
21683 dw_scalar_form_constant
21684 | dw_scalar_form_exprloc
21685 | dw_scalar_form_reference
,
21689 gen_type_die (info
->element_type
, context_die
);
21690 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
21691 TREE_CODE (type
) == ARRAY_TYPE
21692 && TYPE_REVERSE_STORAGE_ORDER (type
),
21695 if (get_AT (array_die
, DW_AT_name
))
21696 add_pubtype (type
, array_die
);
21698 add_alignment_attribute (array_die
, type
);
21703 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
21705 tree origin
= decl_ultimate_origin (decl
);
21706 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
21708 if (origin
!= NULL
)
21709 add_abstract_origin_attribute (decl_die
, origin
);
21712 add_name_and_src_coords_attributes (decl_die
, decl
);
21713 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
21714 TYPE_UNQUALIFIED
, false, context_die
);
21717 if (DECL_ABSTRACT_P (decl
))
21718 equate_decl_number_to_die (decl
, decl_die
);
21720 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
21724 /* Walk through the list of incomplete types again, trying once more to
21725 emit full debugging info for them. */
21728 retry_incomplete_types (void)
21733 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
21734 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
21735 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
21736 vec_safe_truncate (incomplete_types
, 0);
21739 /* Determine what tag to use for a record type. */
21741 static enum dwarf_tag
21742 record_type_tag (tree type
)
21744 if (! lang_hooks
.types
.classify_record
)
21745 return DW_TAG_structure_type
;
21747 switch (lang_hooks
.types
.classify_record (type
))
21749 case RECORD_IS_STRUCT
:
21750 return DW_TAG_structure_type
;
21752 case RECORD_IS_CLASS
:
21753 return DW_TAG_class_type
;
21755 case RECORD_IS_INTERFACE
:
21756 if (dwarf_version
>= 3 || !dwarf_strict
)
21757 return DW_TAG_interface_type
;
21758 return DW_TAG_structure_type
;
21761 gcc_unreachable ();
21765 /* Generate a DIE to represent an enumeration type. Note that these DIEs
21766 include all of the information about the enumeration values also. Each
21767 enumerated type name/value is listed as a child of the enumerated type
21771 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
21773 dw_die_ref type_die
= lookup_type_die (type
);
21775 if (type_die
== NULL
)
21777 type_die
= new_die (DW_TAG_enumeration_type
,
21778 scope_die_for (type
, context_die
), type
);
21779 equate_type_number_to_die (type
, type_die
);
21780 add_name_attribute (type_die
, type_tag (type
));
21781 if (dwarf_version
>= 4 || !dwarf_strict
)
21783 if (ENUM_IS_SCOPED (type
))
21784 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
21785 if (ENUM_IS_OPAQUE (type
))
21786 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21789 add_AT_unsigned (type_die
, DW_AT_encoding
,
21790 TYPE_UNSIGNED (type
)
21794 else if (! TYPE_SIZE (type
))
21797 remove_AT (type_die
, DW_AT_declaration
);
21799 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
21800 given enum type is incomplete, do not generate the DW_AT_byte_size
21801 attribute or the DW_AT_element_list attribute. */
21802 if (TYPE_SIZE (type
))
21806 TREE_ASM_WRITTEN (type
) = 1;
21807 add_byte_size_attribute (type_die
, type
);
21808 add_alignment_attribute (type_die
, type
);
21809 if (dwarf_version
>= 3 || !dwarf_strict
)
21811 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
21812 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
21815 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
21817 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
21818 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
21821 /* If the first reference to this type was as the return type of an
21822 inline function, then it may not have a parent. Fix this now. */
21823 if (type_die
->die_parent
== NULL
)
21824 add_child_die (scope_die_for (type
, context_die
), type_die
);
21826 for (link
= TYPE_VALUES (type
);
21827 link
!= NULL
; link
= TREE_CHAIN (link
))
21829 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
21830 tree value
= TREE_VALUE (link
);
21832 add_name_attribute (enum_die
,
21833 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
21835 if (TREE_CODE (value
) == CONST_DECL
)
21836 value
= DECL_INITIAL (value
);
21838 if (simple_type_size_in_bits (TREE_TYPE (value
))
21839 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
21841 /* For constant forms created by add_AT_unsigned DWARF
21842 consumers (GDB, elfutils, etc.) always zero extend
21843 the value. Only when the actual value is negative
21844 do we need to use add_AT_int to generate a constant
21845 form that can represent negative values. */
21846 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
21847 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
21848 add_AT_unsigned (enum_die
, DW_AT_const_value
,
21849 (unsigned HOST_WIDE_INT
) val
);
21851 add_AT_int (enum_die
, DW_AT_const_value
, val
);
21854 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
21855 that here. TODO: This should be re-worked to use correct
21856 signed/unsigned double tags for all cases. */
21857 add_AT_wide (enum_die
, DW_AT_const_value
, wi::to_wide (value
));
21860 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
21861 if (TYPE_ARTIFICIAL (type
))
21862 add_AT_flag (type_die
, DW_AT_artificial
, 1);
21865 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21867 add_pubtype (type
, type_die
);
21872 /* Generate a DIE to represent either a real live formal parameter decl or to
21873 represent just the type of some formal parameter position in some function
21876 Note that this routine is a bit unusual because its argument may be a
21877 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
21878 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
21879 node. If it's the former then this function is being called to output a
21880 DIE to represent a formal parameter object (or some inlining thereof). If
21881 it's the latter, then this function is only being called to output a
21882 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
21883 argument type of some subprogram type.
21884 If EMIT_NAME_P is true, name and source coordinate attributes
21888 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
21889 dw_die_ref context_die
)
21891 tree node_or_origin
= node
? node
: origin
;
21892 tree ultimate_origin
;
21893 dw_die_ref parm_die
= NULL
;
21895 if (DECL_P (node_or_origin
))
21897 parm_die
= lookup_decl_die (node
);
21899 /* If the contexts differ, we may not be talking about the same
21901 ??? When in LTO the DIE parent is the "abstract" copy and the
21902 context_die is the specification "copy". But this whole block
21903 should eventually be no longer needed. */
21904 if (parm_die
&& parm_die
->die_parent
!= context_die
&& !in_lto_p
)
21906 if (!DECL_ABSTRACT_P (node
))
21908 /* This can happen when creating an inlined instance, in
21909 which case we need to create a new DIE that will get
21910 annotated with DW_AT_abstract_origin. */
21914 gcc_unreachable ();
21917 if (parm_die
&& parm_die
->die_parent
== NULL
)
21919 /* Check that parm_die already has the right attributes that
21920 we would have added below. If any attributes are
21921 missing, fall through to add them. */
21922 if (! DECL_ABSTRACT_P (node_or_origin
)
21923 && !get_AT (parm_die
, DW_AT_location
)
21924 && !get_AT (parm_die
, DW_AT_const_value
))
21925 /* We are missing location info, and are about to add it. */
21929 add_child_die (context_die
, parm_die
);
21935 /* If we have a previously generated DIE, use it, unless this is an
21936 concrete instance (origin != NULL), in which case we need a new
21937 DIE with a corresponding DW_AT_abstract_origin. */
21939 if (parm_die
&& origin
== NULL
)
21940 reusing_die
= true;
21943 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
21944 reusing_die
= false;
21947 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
21949 case tcc_declaration
:
21950 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
21951 if (node
|| ultimate_origin
)
21952 origin
= ultimate_origin
;
21957 if (origin
!= NULL
)
21958 add_abstract_origin_attribute (parm_die
, origin
);
21959 else if (emit_name_p
)
21960 add_name_and_src_coords_attributes (parm_die
, node
);
21962 || (! DECL_ABSTRACT_P (node_or_origin
)
21963 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
21964 decl_function_context
21965 (node_or_origin
))))
21967 tree type
= TREE_TYPE (node_or_origin
);
21968 if (decl_by_reference_p (node_or_origin
))
21969 add_type_attribute (parm_die
, TREE_TYPE (type
),
21971 false, context_die
);
21973 add_type_attribute (parm_die
, type
,
21974 decl_quals (node_or_origin
),
21975 false, context_die
);
21977 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
21978 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21980 if (node
&& node
!= origin
)
21981 equate_decl_number_to_die (node
, parm_die
);
21982 if (! DECL_ABSTRACT_P (node_or_origin
))
21983 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
21989 /* We were called with some kind of a ..._TYPE node. */
21990 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
21995 gcc_unreachable ();
22001 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
22002 children DW_TAG_formal_parameter DIEs representing the arguments of the
22005 PARM_PACK must be a function parameter pack.
22006 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
22007 must point to the subsequent arguments of the function PACK_ARG belongs to.
22008 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
22009 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
22010 following the last one for which a DIE was generated. */
22013 gen_formal_parameter_pack_die (tree parm_pack
,
22015 dw_die_ref subr_die
,
22019 dw_die_ref parm_pack_die
;
22021 gcc_assert (parm_pack
22022 && lang_hooks
.function_parameter_pack_p (parm_pack
)
22025 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
22026 add_src_coords_attributes (parm_pack_die
, parm_pack
);
22028 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
22030 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
22033 gen_formal_parameter_die (arg
, NULL
,
22034 false /* Don't emit name attribute. */,
22039 return parm_pack_die
;
22042 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
22043 at the end of an (ANSI prototyped) formal parameters list. */
22046 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
22048 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
22051 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
22052 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
22053 parameters as specified in some function type specification (except for
22054 those which appear as part of a function *definition*). */
22057 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
22060 tree formal_type
= NULL
;
22061 tree first_parm_type
;
22064 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
22066 arg
= DECL_ARGUMENTS (function_or_method_type
);
22067 function_or_method_type
= TREE_TYPE (function_or_method_type
);
22072 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
22074 /* Make our first pass over the list of formal parameter types and output a
22075 DW_TAG_formal_parameter DIE for each one. */
22076 for (link
= first_parm_type
; link
; )
22078 dw_die_ref parm_die
;
22080 formal_type
= TREE_VALUE (link
);
22081 if (formal_type
== void_type_node
)
22084 /* Output a (nameless) DIE to represent the formal parameter itself. */
22085 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
22087 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
22088 true /* Emit name attribute. */,
22090 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
22091 && link
== first_parm_type
)
22093 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
22094 if (dwarf_version
>= 3 || !dwarf_strict
)
22095 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
22097 else if (arg
&& DECL_ARTIFICIAL (arg
))
22098 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
22101 link
= TREE_CHAIN (link
);
22103 arg
= DECL_CHAIN (arg
);
22106 /* If this function type has an ellipsis, add a
22107 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
22108 if (formal_type
!= void_type_node
)
22109 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
22111 /* Make our second (and final) pass over the list of formal parameter types
22112 and output DIEs to represent those types (as necessary). */
22113 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
22114 link
&& TREE_VALUE (link
);
22115 link
= TREE_CHAIN (link
))
22116 gen_type_die (TREE_VALUE (link
), context_die
);
22119 /* We want to generate the DIE for TYPE so that we can generate the
22120 die for MEMBER, which has been defined; we will need to refer back
22121 to the member declaration nested within TYPE. If we're trying to
22122 generate minimal debug info for TYPE, processing TYPE won't do the
22123 trick; we need to attach the member declaration by hand. */
22126 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
22128 gen_type_die (type
, context_die
);
22130 /* If we're trying to avoid duplicate debug info, we may not have
22131 emitted the member decl for this function. Emit it now. */
22132 if (TYPE_STUB_DECL (type
)
22133 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
22134 && ! lookup_decl_die (member
))
22136 dw_die_ref type_die
;
22137 gcc_assert (!decl_ultimate_origin (member
));
22139 push_decl_scope (type
);
22140 type_die
= lookup_type_die_strip_naming_typedef (type
);
22141 if (TREE_CODE (member
) == FUNCTION_DECL
)
22142 gen_subprogram_die (member
, type_die
);
22143 else if (TREE_CODE (member
) == FIELD_DECL
)
22145 /* Ignore the nameless fields that are used to skip bits but handle
22146 C++ anonymous unions and structs. */
22147 if (DECL_NAME (member
) != NULL_TREE
22148 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
22149 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
22151 struct vlr_context vlr_ctx
= {
22152 DECL_CONTEXT (member
), /* struct_type */
22153 NULL_TREE
/* variant_part_offset */
22155 gen_type_die (member_declared_type (member
), type_die
);
22156 gen_field_die (member
, &vlr_ctx
, type_die
);
22160 gen_variable_die (member
, NULL_TREE
, type_die
);
22166 /* Forward declare these functions, because they are mutually recursive
22167 with their set_block_* pairing functions. */
22168 static void set_decl_origin_self (tree
);
22170 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
22171 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
22172 that it points to the node itself, thus indicating that the node is its
22173 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
22174 the given node is NULL, recursively descend the decl/block tree which
22175 it is the root of, and for each other ..._DECL or BLOCK node contained
22176 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
22177 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
22178 values to point to themselves. */
22181 set_block_origin_self (tree stmt
)
22183 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
22185 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
22190 for (local_decl
= BLOCK_VARS (stmt
);
22191 local_decl
!= NULL_TREE
;
22192 local_decl
= DECL_CHAIN (local_decl
))
22193 /* Do not recurse on nested functions since the inlining status
22194 of parent and child can be different as per the DWARF spec. */
22195 if (TREE_CODE (local_decl
) != FUNCTION_DECL
22196 && !DECL_EXTERNAL (local_decl
))
22197 set_decl_origin_self (local_decl
);
22203 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
22204 subblock
!= NULL_TREE
;
22205 subblock
= BLOCK_CHAIN (subblock
))
22206 set_block_origin_self (subblock
); /* Recurse. */
22211 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
22212 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
22213 node to so that it points to the node itself, thus indicating that the
22214 node represents its own (abstract) origin. Additionally, if the
22215 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
22216 the decl/block tree of which the given node is the root of, and for
22217 each other ..._DECL or BLOCK node contained therein whose
22218 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
22219 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
22220 point to themselves. */
22223 set_decl_origin_self (tree decl
)
22225 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
22227 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
22228 if (TREE_CODE (decl
) == FUNCTION_DECL
)
22232 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
22233 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
22234 if (DECL_INITIAL (decl
) != NULL_TREE
22235 && DECL_INITIAL (decl
) != error_mark_node
)
22236 set_block_origin_self (DECL_INITIAL (decl
));
22241 /* Mark the early DIE for DECL as the abstract instance. */
22244 dwarf2out_abstract_function (tree decl
)
22246 dw_die_ref old_die
;
22248 /* Make sure we have the actual abstract inline, not a clone. */
22249 decl
= DECL_ORIGIN (decl
);
22251 if (DECL_IGNORED_P (decl
))
22254 old_die
= lookup_decl_die (decl
);
22255 /* With early debug we always have an old DIE unless we are in LTO
22256 and the user did not compile but only link with debug. */
22257 if (in_lto_p
&& ! old_die
)
22259 gcc_assert (old_die
!= NULL
);
22260 if (get_AT (old_die
, DW_AT_inline
)
22261 || get_AT (old_die
, DW_AT_abstract_origin
))
22262 /* We've already generated the abstract instance. */
22265 /* Go ahead and put DW_AT_inline on the DIE. */
22266 if (DECL_DECLARED_INLINE_P (decl
))
22268 if (cgraph_function_possibly_inlined_p (decl
))
22269 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_inlined
);
22271 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
22275 if (cgraph_function_possibly_inlined_p (decl
))
22276 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_inlined
);
22278 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_not_inlined
);
22281 if (DECL_DECLARED_INLINE_P (decl
)
22282 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
22283 add_AT_flag (old_die
, DW_AT_artificial
, 1);
22285 set_decl_origin_self (decl
);
22288 /* Helper function of premark_used_types() which gets called through
22291 Marks the DIE of a given type in *SLOT as perennial, so it never gets
22292 marked as unused by prune_unused_types. */
22295 premark_used_types_helper (tree
const &type
, void *)
22299 die
= lookup_type_die (type
);
22301 die
->die_perennial_p
= 1;
22305 /* Helper function of premark_types_used_by_global_vars which gets called
22306 through htab_traverse.
22308 Marks the DIE of a given type in *SLOT as perennial, so it never gets
22309 marked as unused by prune_unused_types. The DIE of the type is marked
22310 only if the global variable using the type will actually be emitted. */
22313 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
22316 struct types_used_by_vars_entry
*entry
;
22319 entry
= (struct types_used_by_vars_entry
*) *slot
;
22320 gcc_assert (entry
->type
!= NULL
22321 && entry
->var_decl
!= NULL
);
22322 die
= lookup_type_die (entry
->type
);
22325 /* Ask cgraph if the global variable really is to be emitted.
22326 If yes, then we'll keep the DIE of ENTRY->TYPE. */
22327 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
22328 if (node
&& node
->definition
)
22330 die
->die_perennial_p
= 1;
22331 /* Keep the parent DIEs as well. */
22332 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
22333 die
->die_perennial_p
= 1;
22339 /* Mark all members of used_types_hash as perennial. */
22342 premark_used_types (struct function
*fun
)
22344 if (fun
&& fun
->used_types_hash
)
22345 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
22348 /* Mark all members of types_used_by_vars_entry as perennial. */
22351 premark_types_used_by_global_vars (void)
22353 if (types_used_by_vars_hash
)
22354 types_used_by_vars_hash
22355 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
22358 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
22359 for CA_LOC call arg loc node. */
22362 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
22363 struct call_arg_loc_node
*ca_loc
)
22365 dw_die_ref stmt_die
= NULL
, die
;
22366 tree block
= ca_loc
->block
;
22369 && block
!= DECL_INITIAL (decl
)
22370 && TREE_CODE (block
) == BLOCK
)
22372 stmt_die
= BLOCK_DIE (block
);
22375 block
= BLOCK_SUPERCONTEXT (block
);
22377 if (stmt_die
== NULL
)
22378 stmt_die
= subr_die
;
22379 die
= new_die (dwarf_TAG (DW_TAG_call_site
), stmt_die
, NULL_TREE
);
22380 add_AT_lbl_id (die
, dwarf_AT (DW_AT_call_return_pc
), ca_loc
->label
);
22381 if (ca_loc
->tail_call_p
)
22382 add_AT_flag (die
, dwarf_AT (DW_AT_call_tail_call
), 1);
22383 if (ca_loc
->symbol_ref
)
22385 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
22387 add_AT_die_ref (die
, dwarf_AT (DW_AT_call_origin
), tdie
);
22389 add_AT_addr (die
, dwarf_AT (DW_AT_call_origin
), ca_loc
->symbol_ref
,
22395 /* Generate a DIE to represent a declared function (either file-scope or
22399 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
22401 tree origin
= decl_ultimate_origin (decl
);
22402 dw_die_ref subr_die
;
22403 dw_die_ref old_die
= lookup_decl_die (decl
);
22405 /* This function gets called multiple times for different stages of
22406 the debug process. For example, for func() in this code:
22410 void func() { ... }
22413 ...we get called 4 times. Twice in early debug and twice in
22419 1. Once while generating func() within the namespace. This is
22420 the declaration. The declaration bit below is set, as the
22421 context is the namespace.
22423 A new DIE will be generated with DW_AT_declaration set.
22425 2. Once for func() itself. This is the specification. The
22426 declaration bit below is clear as the context is the CU.
22428 We will use the cached DIE from (1) to create a new DIE with
22429 DW_AT_specification pointing to the declaration in (1).
22431 Late debug via rest_of_handle_final()
22432 -------------------------------------
22434 3. Once generating func() within the namespace. This is also the
22435 declaration, as in (1), but this time we will early exit below
22436 as we have a cached DIE and a declaration needs no additional
22437 annotations (no locations), as the source declaration line
22440 4. Once for func() itself. As in (2), this is the specification,
22441 but this time we will re-use the cached DIE, and just annotate
22442 it with the location information that should now be available.
22444 For something without namespaces, but with abstract instances, we
22445 are also called a multiple times:
22450 Base (); // constructor declaration (1)
22453 Base::Base () { } // constructor specification (2)
22458 1. Once for the Base() constructor by virtue of it being a
22459 member of the Base class. This is done via
22460 rest_of_type_compilation.
22462 This is a declaration, so a new DIE will be created with
22465 2. Once for the Base() constructor definition, but this time
22466 while generating the abstract instance of the base
22467 constructor (__base_ctor) which is being generated via early
22468 debug of reachable functions.
22470 Even though we have a cached version of the declaration (1),
22471 we will create a DW_AT_specification of the declaration DIE
22474 3. Once for the __base_ctor itself, but this time, we generate
22475 an DW_AT_abstract_origin version of the DW_AT_specification in
22478 Late debug via rest_of_handle_final
22479 -----------------------------------
22481 4. One final time for the __base_ctor (which will have a cached
22482 DIE with DW_AT_abstract_origin created in (3). This time,
22483 we will just annotate the location information now
22486 int declaration
= (current_function_decl
!= decl
22487 || class_or_namespace_scope_p (context_die
));
22489 /* A declaration that has been previously dumped needs no
22490 additional information. */
22491 if (old_die
&& declaration
)
22494 /* Now that the C++ front end lazily declares artificial member fns, we
22495 might need to retrofit the declaration into its class. */
22496 if (!declaration
&& !origin
&& !old_die
22497 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
22498 && !class_or_namespace_scope_p (context_die
)
22499 && debug_info_level
> DINFO_LEVEL_TERSE
)
22500 old_die
= force_decl_die (decl
);
22502 /* A concrete instance, tag a new DIE with DW_AT_abstract_origin. */
22503 if (origin
!= NULL
)
22505 gcc_assert (!declaration
|| local_scope_p (context_die
));
22507 /* Fixup die_parent for the abstract instance of a nested
22508 inline function. */
22509 if (old_die
&& old_die
->die_parent
== NULL
)
22510 add_child_die (context_die
, old_die
);
22512 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
22514 /* If we have a DW_AT_abstract_origin we have a working
22516 subr_die
= old_die
;
22520 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22521 add_abstract_origin_attribute (subr_die
, origin
);
22522 /* This is where the actual code for a cloned function is.
22523 Let's emit linkage name attribute for it. This helps
22524 debuggers to e.g, set breakpoints into
22525 constructors/destructors when the user asks "break
22527 add_linkage_name (subr_die
, decl
);
22530 /* A cached copy, possibly from early dwarf generation. Reuse as
22531 much as possible. */
22534 if (!get_AT_flag (old_die
, DW_AT_declaration
)
22535 /* We can have a normal definition following an inline one in the
22536 case of redefinition of GNU C extern inlines.
22537 It seems reasonable to use AT_specification in this case. */
22538 && !get_AT (old_die
, DW_AT_inline
))
22540 /* Detect and ignore this case, where we are trying to output
22541 something we have already output. */
22542 if (get_AT (old_die
, DW_AT_low_pc
)
22543 || get_AT (old_die
, DW_AT_ranges
))
22546 /* If we have no location information, this must be a
22547 partially generated DIE from early dwarf generation.
22548 Fall through and generate it. */
22551 /* If the definition comes from the same place as the declaration,
22552 maybe use the old DIE. We always want the DIE for this function
22553 that has the *_pc attributes to be under comp_unit_die so the
22554 debugger can find it. We also need to do this for abstract
22555 instances of inlines, since the spec requires the out-of-line copy
22556 to have the same parent. For local class methods, this doesn't
22557 apply; we just use the old DIE. */
22558 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
22559 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
22560 if ((is_cu_die (old_die
->die_parent
)
22561 /* This condition fixes the inconsistency/ICE with the
22562 following Fortran test (or some derivative thereof) while
22563 building libgfortran:
22567 logical function funky (FLAG)
22572 || (old_die
->die_parent
22573 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
22574 || context_die
== NULL
)
22575 && (DECL_ARTIFICIAL (decl
)
22576 /* The location attributes may be in the abstract origin
22577 which in the case of LTO might be not available to
22579 || get_AT (old_die
, DW_AT_abstract_origin
)
22580 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
22581 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
22582 == (unsigned) s
.line
)
22583 && (!debug_column_info
22585 || (get_AT_unsigned (old_die
, DW_AT_decl_column
)
22586 == (unsigned) s
.column
)))))
22588 subr_die
= old_die
;
22590 /* Clear out the declaration attribute, but leave the
22591 parameters so they can be augmented with location
22592 information later. Unless this was a declaration, in
22593 which case, wipe out the nameless parameters and recreate
22594 them further down. */
22595 if (remove_AT (subr_die
, DW_AT_declaration
))
22598 remove_AT (subr_die
, DW_AT_object_pointer
);
22599 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
22602 /* Make a specification pointing to the previously built
22606 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22607 add_AT_specification (subr_die
, old_die
);
22608 add_pubname (decl
, subr_die
);
22609 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
22610 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
22611 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
22612 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
22613 if (debug_column_info
22615 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
22616 != (unsigned) s
.column
))
22617 add_AT_unsigned (subr_die
, DW_AT_decl_column
, s
.column
);
22619 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
22620 emit the real type on the definition die. */
22621 if (is_cxx () && debug_info_level
> DINFO_LEVEL_TERSE
)
22623 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
22624 if (die
== auto_die
|| die
== decltype_auto_die
)
22625 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
22626 TYPE_UNQUALIFIED
, false, context_die
);
22629 /* When we process the method declaration, we haven't seen
22630 the out-of-class defaulted definition yet, so we have to
22632 if ((dwarf_version
>= 5 || ! dwarf_strict
)
22633 && !get_AT (subr_die
, DW_AT_defaulted
))
22636 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22638 if (defaulted
!= -1)
22640 /* Other values must have been handled before. */
22641 gcc_assert (defaulted
== DW_DEFAULTED_out_of_class
);
22642 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22647 /* Create a fresh DIE for anything else. */
22650 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22652 if (TREE_PUBLIC (decl
))
22653 add_AT_flag (subr_die
, DW_AT_external
, 1);
22655 add_name_and_src_coords_attributes (subr_die
, decl
);
22656 add_pubname (decl
, subr_die
);
22657 if (debug_info_level
> DINFO_LEVEL_TERSE
)
22659 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
22660 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
22661 TYPE_UNQUALIFIED
, false, context_die
);
22664 add_pure_or_virtual_attribute (subr_die
, decl
);
22665 if (DECL_ARTIFICIAL (decl
))
22666 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
22668 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
22669 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
22671 add_alignment_attribute (subr_die
, decl
);
22673 add_accessibility_attribute (subr_die
, decl
);
22676 /* Unless we have an existing non-declaration DIE, equate the new
22678 if (!old_die
|| is_declaration_die (old_die
))
22679 equate_decl_number_to_die (decl
, subr_die
);
22683 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
22685 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
22687 /* If this is an explicit function declaration then generate
22688 a DW_AT_explicit attribute. */
22689 if ((dwarf_version
>= 3 || !dwarf_strict
)
22690 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22691 DW_AT_explicit
) == 1)
22692 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
22694 /* If this is a C++11 deleted special function member then generate
22695 a DW_AT_deleted attribute. */
22696 if ((dwarf_version
>= 5 || !dwarf_strict
)
22697 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22698 DW_AT_deleted
) == 1)
22699 add_AT_flag (subr_die
, DW_AT_deleted
, 1);
22701 /* If this is a C++11 defaulted special function member then
22702 generate a DW_AT_defaulted attribute. */
22703 if (dwarf_version
>= 5 || !dwarf_strict
)
22706 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22708 if (defaulted
!= -1)
22709 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22712 /* If this is a C++11 non-static member function with & ref-qualifier
22713 then generate a DW_AT_reference attribute. */
22714 if ((dwarf_version
>= 5 || !dwarf_strict
)
22715 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22716 DW_AT_reference
) == 1)
22717 add_AT_flag (subr_die
, DW_AT_reference
, 1);
22719 /* If this is a C++11 non-static member function with &&
22720 ref-qualifier then generate a DW_AT_reference attribute. */
22721 if ((dwarf_version
>= 5 || !dwarf_strict
)
22722 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22723 DW_AT_rvalue_reference
)
22725 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
22728 /* For non DECL_EXTERNALs, if range information is available, fill
22729 the DIE with it. */
22730 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
22732 HOST_WIDE_INT cfa_fb_offset
;
22734 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
22736 if (!crtl
->has_bb_partition
)
22738 dw_fde_ref fde
= fun
->fde
;
22739 if (fde
->dw_fde_begin
)
22741 /* We have already generated the labels. */
22742 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22743 fde
->dw_fde_end
, false);
22747 /* Create start/end labels and add the range. */
22748 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
22749 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
22750 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
22751 current_function_funcdef_no
);
22752 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
22753 current_function_funcdef_no
);
22754 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
22758 #if VMS_DEBUGGING_INFO
22759 /* HP OpenVMS Industry Standard 64: DWARF Extensions
22760 Section 2.3 Prologue and Epilogue Attributes:
22761 When a breakpoint is set on entry to a function, it is generally
22762 desirable for execution to be suspended, not on the very first
22763 instruction of the function, but rather at a point after the
22764 function's frame has been set up, after any language defined local
22765 declaration processing has been completed, and before execution of
22766 the first statement of the function begins. Debuggers generally
22767 cannot properly determine where this point is. Similarly for a
22768 breakpoint set on exit from a function. The prologue and epilogue
22769 attributes allow a compiler to communicate the location(s) to use. */
22772 if (fde
->dw_fde_vms_end_prologue
)
22773 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
22774 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
22776 if (fde
->dw_fde_vms_begin_epilogue
)
22777 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
22778 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
22785 /* Generate pubnames entries for the split function code ranges. */
22786 dw_fde_ref fde
= fun
->fde
;
22788 if (fde
->dw_fde_second_begin
)
22790 if (dwarf_version
>= 3 || !dwarf_strict
)
22792 /* We should use ranges for non-contiguous code section
22793 addresses. Use the actual code range for the initial
22794 section, since the HOT/COLD labels might precede an
22795 alignment offset. */
22796 bool range_list_added
= false;
22797 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
22798 fde
->dw_fde_end
, &range_list_added
,
22800 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
22801 fde
->dw_fde_second_end
,
22802 &range_list_added
, false);
22803 if (range_list_added
)
22808 /* There is no real support in DW2 for this .. so we make
22809 a work-around. First, emit the pub name for the segment
22810 containing the function label. Then make and emit a
22811 simplified subprogram DIE for the second segment with the
22812 name pre-fixed by __hot/cold_sect_of_. We use the same
22813 linkage name for the second die so that gdb will find both
22814 sections when given "b foo". */
22815 const char *name
= NULL
;
22816 tree decl_name
= DECL_NAME (decl
);
22817 dw_die_ref seg_die
;
22819 /* Do the 'primary' section. */
22820 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22821 fde
->dw_fde_end
, false);
22823 /* Build a minimal DIE for the secondary section. */
22824 seg_die
= new_die (DW_TAG_subprogram
,
22825 subr_die
->die_parent
, decl
);
22827 if (TREE_PUBLIC (decl
))
22828 add_AT_flag (seg_die
, DW_AT_external
, 1);
22830 if (decl_name
!= NULL
22831 && IDENTIFIER_POINTER (decl_name
) != NULL
)
22833 name
= dwarf2_name (decl
, 1);
22834 if (! DECL_ARTIFICIAL (decl
))
22835 add_src_coords_attributes (seg_die
, decl
);
22837 add_linkage_name (seg_die
, decl
);
22839 gcc_assert (name
!= NULL
);
22840 add_pure_or_virtual_attribute (seg_die
, decl
);
22841 if (DECL_ARTIFICIAL (decl
))
22842 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
22844 name
= concat ("__second_sect_of_", name
, NULL
);
22845 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
22846 fde
->dw_fde_second_end
, false);
22847 add_name_attribute (seg_die
, name
);
22848 if (want_pubnames ())
22849 add_pubname_string (name
, seg_die
);
22853 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
22857 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
22859 /* We define the "frame base" as the function's CFA. This is more
22860 convenient for several reasons: (1) It's stable across the prologue
22861 and epilogue, which makes it better than just a frame pointer,
22862 (2) With dwarf3, there exists a one-byte encoding that allows us
22863 to reference the .debug_frame data by proxy, but failing that,
22864 (3) We can at least reuse the code inspection and interpretation
22865 code that determines the CFA position at various points in the
22867 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
22869 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
22870 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
22874 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
22875 if (list
->dw_loc_next
)
22876 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
22878 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
22881 /* Compute a displacement from the "steady-state frame pointer" to
22882 the CFA. The former is what all stack slots and argument slots
22883 will reference in the rtl; the latter is what we've told the
22884 debugger about. We'll need to adjust all frame_base references
22885 by this displacement. */
22886 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
22888 if (fun
->static_chain_decl
)
22890 /* DWARF requires here a location expression that computes the
22891 address of the enclosing subprogram's frame base. The machinery
22892 in tree-nested.c is supposed to store this specific address in the
22893 last field of the FRAME record. */
22894 const tree frame_type
22895 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
22896 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
22899 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
22900 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
22901 fb_expr
, fb_decl
, NULL_TREE
);
22903 add_AT_location_description (subr_die
, DW_AT_static_link
,
22904 loc_list_from_tree (fb_expr
, 0, NULL
));
22907 resolve_variable_values ();
22910 /* Generate child dies for template paramaters. */
22911 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
22912 gen_generic_params_dies (decl
);
22914 /* Now output descriptions of the arguments for this function. This gets
22915 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
22916 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
22917 `...' at the end of the formal parameter list. In order to find out if
22918 there was a trailing ellipsis or not, we must instead look at the type
22919 associated with the FUNCTION_DECL. This will be a node of type
22920 FUNCTION_TYPE. If the chain of type nodes hanging off of this
22921 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
22922 an ellipsis at the end. */
22924 /* In the case where we are describing a mere function declaration, all we
22925 need to do here (and all we *can* do here) is to describe the *types* of
22926 its formal parameters. */
22927 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
22929 else if (declaration
)
22930 gen_formal_types_die (decl
, subr_die
);
22933 /* Generate DIEs to represent all known formal parameters. */
22934 tree parm
= DECL_ARGUMENTS (decl
);
22935 tree generic_decl
= early_dwarf
22936 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
22937 tree generic_decl_parm
= generic_decl
22938 ? DECL_ARGUMENTS (generic_decl
)
22941 /* Now we want to walk the list of parameters of the function and
22942 emit their relevant DIEs.
22944 We consider the case of DECL being an instance of a generic function
22945 as well as it being a normal function.
22947 If DECL is an instance of a generic function we walk the
22948 parameters of the generic function declaration _and_ the parameters of
22949 DECL itself. This is useful because we want to emit specific DIEs for
22950 function parameter packs and those are declared as part of the
22951 generic function declaration. In that particular case,
22952 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
22953 That DIE has children DIEs representing the set of arguments
22954 of the pack. Note that the set of pack arguments can be empty.
22955 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
22958 Otherwise, we just consider the parameters of DECL. */
22959 while (generic_decl_parm
|| parm
)
22961 if (generic_decl_parm
22962 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
22963 gen_formal_parameter_pack_die (generic_decl_parm
,
22966 else if (parm
&& !POINTER_BOUNDS_P (parm
))
22968 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
22971 && parm
== DECL_ARGUMENTS (decl
)
22972 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
22974 && (dwarf_version
>= 3 || !dwarf_strict
))
22975 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
22977 parm
= DECL_CHAIN (parm
);
22980 parm
= DECL_CHAIN (parm
);
22982 if (generic_decl_parm
)
22983 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
22986 /* Decide whether we need an unspecified_parameters DIE at the end.
22987 There are 2 more cases to do this for: 1) the ansi ... declaration -
22988 this is detectable when the end of the arg list is not a
22989 void_type_node 2) an unprototyped function declaration (not a
22990 definition). This just means that we have no info about the
22991 parameters at all. */
22994 if (prototype_p (TREE_TYPE (decl
)))
22996 /* This is the prototyped case, check for.... */
22997 if (stdarg_p (TREE_TYPE (decl
)))
22998 gen_unspecified_parameters_die (decl
, subr_die
);
23000 else if (DECL_INITIAL (decl
) == NULL_TREE
)
23001 gen_unspecified_parameters_die (decl
, subr_die
);
23005 if (subr_die
!= old_die
)
23006 /* Add the calling convention attribute if requested. */
23007 add_calling_convention_attribute (subr_die
, decl
);
23009 /* Output Dwarf info for all of the stuff within the body of the function
23010 (if it has one - it may be just a declaration).
23012 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
23013 a function. This BLOCK actually represents the outermost binding contour
23014 for the function, i.e. the contour in which the function's formal
23015 parameters and labels get declared. Curiously, it appears that the front
23016 end doesn't actually put the PARM_DECL nodes for the current function onto
23017 the BLOCK_VARS list for this outer scope, but are strung off of the
23018 DECL_ARGUMENTS list for the function instead.
23020 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
23021 the LABEL_DECL nodes for the function however, and we output DWARF info
23022 for those in decls_for_scope. Just within the `outer_scope' there will be
23023 a BLOCK node representing the function's outermost pair of curly braces,
23024 and any blocks used for the base and member initializers of a C++
23025 constructor function. */
23026 tree outer_scope
= DECL_INITIAL (decl
);
23027 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
23029 int call_site_note_count
= 0;
23030 int tail_call_site_note_count
= 0;
23032 /* Emit a DW_TAG_variable DIE for a named return value. */
23033 if (DECL_NAME (DECL_RESULT (decl
)))
23034 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
23036 /* The first time through decls_for_scope we will generate the
23037 DIEs for the locals. The second time, we fill in the
23039 decls_for_scope (outer_scope
, subr_die
);
23041 if (call_arg_locations
&& (!dwarf_strict
|| dwarf_version
>= 5))
23043 struct call_arg_loc_node
*ca_loc
;
23044 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
23046 dw_die_ref die
= NULL
;
23047 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
23050 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
23051 ? NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
)
23053 arg
; arg
= next_arg
)
23055 dw_loc_descr_ref reg
, val
;
23056 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
23057 dw_die_ref cdie
, tdie
= NULL
;
23059 next_arg
= XEXP (arg
, 1);
23060 if (REG_P (XEXP (XEXP (arg
, 0), 0))
23062 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
23063 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
23064 && REGNO (XEXP (XEXP (arg
, 0), 0))
23065 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
23066 next_arg
= XEXP (next_arg
, 1);
23067 if (mode
== VOIDmode
)
23069 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
23070 if (mode
== VOIDmode
)
23071 mode
= GET_MODE (XEXP (arg
, 0));
23073 if (mode
== VOIDmode
|| mode
== BLKmode
)
23075 /* Get dynamic information about call target only if we
23076 have no static information: we cannot generate both
23077 DW_AT_call_origin and DW_AT_call_target
23079 if (ca_loc
->symbol_ref
== NULL_RTX
)
23081 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
23083 tloc
= XEXP (XEXP (arg
, 0), 1);
23086 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
23087 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
23089 tlocc
= XEXP (XEXP (arg
, 0), 1);
23094 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
23095 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
23096 VAR_INIT_STATUS_INITIALIZED
);
23097 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
23099 rtx mem
= XEXP (XEXP (arg
, 0), 0);
23100 reg
= mem_loc_descriptor (XEXP (mem
, 0),
23101 get_address_mode (mem
),
23103 VAR_INIT_STATUS_INITIALIZED
);
23105 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
23106 == DEBUG_PARAMETER_REF
)
23109 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
23110 tdie
= lookup_decl_die (tdecl
);
23117 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
23118 != DEBUG_PARAMETER_REF
)
23120 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
23122 VAR_INIT_STATUS_INITIALIZED
);
23126 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
23127 cdie
= new_die (dwarf_TAG (DW_TAG_call_site_parameter
), die
,
23130 add_AT_loc (cdie
, DW_AT_location
, reg
);
23131 else if (tdie
!= NULL
)
23132 add_AT_die_ref (cdie
, dwarf_AT (DW_AT_call_parameter
),
23134 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_value
), val
);
23135 if (next_arg
!= XEXP (arg
, 1))
23137 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
23138 if (mode
== VOIDmode
)
23139 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
23140 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
23143 VAR_INIT_STATUS_INITIALIZED
);
23145 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_data_value
),
23150 && (ca_loc
->symbol_ref
|| tloc
))
23151 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
23152 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
23154 dw_loc_descr_ref tval
= NULL
;
23156 if (tloc
!= NULL_RTX
)
23157 tval
= mem_loc_descriptor (tloc
,
23158 GET_MODE (tloc
) == VOIDmode
23159 ? Pmode
: GET_MODE (tloc
),
23161 VAR_INIT_STATUS_INITIALIZED
);
23163 add_AT_loc (die
, dwarf_AT (DW_AT_call_target
), tval
);
23164 else if (tlocc
!= NULL_RTX
)
23166 tval
= mem_loc_descriptor (tlocc
,
23167 GET_MODE (tlocc
) == VOIDmode
23168 ? Pmode
: GET_MODE (tlocc
),
23170 VAR_INIT_STATUS_INITIALIZED
);
23173 dwarf_AT (DW_AT_call_target_clobbered
),
23179 call_site_note_count
++;
23180 if (ca_loc
->tail_call_p
)
23181 tail_call_site_note_count
++;
23185 call_arg_locations
= NULL
;
23186 call_arg_loc_last
= NULL
;
23187 if (tail_call_site_count
>= 0
23188 && tail_call_site_count
== tail_call_site_note_count
23189 && (!dwarf_strict
|| dwarf_version
>= 5))
23191 if (call_site_count
>= 0
23192 && call_site_count
== call_site_note_count
)
23193 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_calls
), 1);
23195 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_tail_calls
), 1);
23197 call_site_count
= -1;
23198 tail_call_site_count
= -1;
23201 /* Mark used types after we have created DIEs for the functions scopes. */
23202 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
23205 /* Returns a hash value for X (which really is a die_struct). */
23208 block_die_hasher::hash (die_struct
*d
)
23210 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
23213 /* Return nonzero if decl_id and die_parent of die_struct X is the same
23214 as decl_id and die_parent of die_struct Y. */
23217 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
23219 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
23222 /* Hold information about markers for inlined entry points. */
23223 struct GTY ((for_user
)) inline_entry_data
23225 /* The block that's the inlined_function_outer_scope for an inlined
23229 /* The label at the inlined entry point. */
23230 const char *label_pfx
;
23231 unsigned int label_num
;
23233 /* The view number to be used as the inlined entry point. */
23237 struct inline_entry_data_hasher
: ggc_ptr_hash
<inline_entry_data
>
23239 typedef tree compare_type
;
23240 static inline hashval_t
hash (const inline_entry_data
*);
23241 static inline bool equal (const inline_entry_data
*, const_tree
);
23244 /* Hash table routines for inline_entry_data. */
23247 inline_entry_data_hasher::hash (const inline_entry_data
*data
)
23249 return htab_hash_pointer (data
->block
);
23253 inline_entry_data_hasher::equal (const inline_entry_data
*data
,
23256 return data
->block
== block
;
23259 /* Inlined entry points pending DIE creation in this compilation unit. */
23261 static GTY(()) hash_table
<inline_entry_data_hasher
> *inline_entry_data_table
;
23264 /* Return TRUE if DECL, which may have been previously generated as
23265 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
23266 true if decl (or its origin) is either an extern declaration or a
23267 class/namespace scoped declaration.
23269 The declare_in_namespace support causes us to get two DIEs for one
23270 variable, both of which are declarations. We want to avoid
23271 considering one to be a specification, so we must test for
23272 DECLARATION and DW_AT_declaration. */
23274 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
23276 return (old_die
&& TREE_STATIC (decl
) && !declaration
23277 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
23280 /* Return true if DECL is a local static. */
23283 local_function_static (tree decl
)
23285 gcc_assert (VAR_P (decl
));
23286 return TREE_STATIC (decl
)
23287 && DECL_CONTEXT (decl
)
23288 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
23291 /* Generate a DIE to represent a declared data object.
23292 Either DECL or ORIGIN must be non-null. */
23295 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
23297 HOST_WIDE_INT off
= 0;
23299 tree decl_or_origin
= decl
? decl
: origin
;
23300 tree ultimate_origin
;
23301 dw_die_ref var_die
;
23302 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
23303 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
23304 || class_or_namespace_scope_p (context_die
));
23305 bool specialization_p
= false;
23306 bool no_linkage_name
= false;
23308 /* While C++ inline static data members have definitions inside of the
23309 class, force the first DIE to be a declaration, then let gen_member_die
23310 reparent it to the class context and call gen_variable_die again
23311 to create the outside of the class DIE for the definition. */
23315 && DECL_CONTEXT (decl
)
23316 && TYPE_P (DECL_CONTEXT (decl
))
23317 && lang_hooks
.decls
.decl_dwarf_attribute (decl
, DW_AT_inline
) != -1)
23319 declaration
= true;
23320 if (dwarf_version
< 5)
23321 no_linkage_name
= true;
23324 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
23325 if (decl
|| ultimate_origin
)
23326 origin
= ultimate_origin
;
23327 com_decl
= fortran_common (decl_or_origin
, &off
);
23329 /* Symbol in common gets emitted as a child of the common block, in the form
23330 of a data member. */
23333 dw_die_ref com_die
;
23334 dw_loc_list_ref loc
= NULL
;
23335 die_node com_die_arg
;
23337 var_die
= lookup_decl_die (decl_or_origin
);
23340 if (! early_dwarf
&& get_AT (var_die
, DW_AT_location
) == NULL
)
23342 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
23347 /* Optimize the common case. */
23348 if (single_element_loc_list_p (loc
)
23349 && loc
->expr
->dw_loc_opc
== DW_OP_addr
23350 && loc
->expr
->dw_loc_next
== NULL
23351 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
23354 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
23355 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
23356 = plus_constant (GET_MODE (x
), x
, off
);
23359 loc_list_plus_const (loc
, off
);
23361 add_AT_location_description (var_die
, DW_AT_location
, loc
);
23362 remove_AT (var_die
, DW_AT_declaration
);
23368 if (common_block_die_table
== NULL
)
23369 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
23371 com_die_arg
.decl_id
= DECL_UID (com_decl
);
23372 com_die_arg
.die_parent
= context_die
;
23373 com_die
= common_block_die_table
->find (&com_die_arg
);
23375 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
23376 if (com_die
== NULL
)
23379 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
23382 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
23383 add_name_and_src_coords_attributes (com_die
, com_decl
);
23386 add_AT_location_description (com_die
, DW_AT_location
, loc
);
23387 /* Avoid sharing the same loc descriptor between
23388 DW_TAG_common_block and DW_TAG_variable. */
23389 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
23391 else if (DECL_EXTERNAL (decl_or_origin
))
23392 add_AT_flag (com_die
, DW_AT_declaration
, 1);
23393 if (want_pubnames ())
23394 add_pubname_string (cnam
, com_die
); /* ??? needed? */
23395 com_die
->decl_id
= DECL_UID (com_decl
);
23396 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
23399 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
23401 add_AT_location_description (com_die
, DW_AT_location
, loc
);
23402 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
23403 remove_AT (com_die
, DW_AT_declaration
);
23405 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
23406 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
23407 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
23408 decl_quals (decl_or_origin
), false,
23410 add_alignment_attribute (var_die
, decl
);
23411 add_AT_flag (var_die
, DW_AT_external
, 1);
23416 /* Optimize the common case. */
23417 if (single_element_loc_list_p (loc
)
23418 && loc
->expr
->dw_loc_opc
== DW_OP_addr
23419 && loc
->expr
->dw_loc_next
== NULL
23420 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
23422 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
23423 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
23424 = plus_constant (GET_MODE (x
), x
, off
);
23427 loc_list_plus_const (loc
, off
);
23429 add_AT_location_description (var_die
, DW_AT_location
, loc
);
23431 else if (DECL_EXTERNAL (decl_or_origin
))
23432 add_AT_flag (var_die
, DW_AT_declaration
, 1);
23434 equate_decl_number_to_die (decl
, var_die
);
23442 /* A declaration that has been previously dumped, needs no
23443 further annotations, since it doesn't need location on
23444 the second pass. */
23447 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
23448 && !get_AT (old_die
, DW_AT_specification
))
23450 /* Fall-thru so we can make a new variable die along with a
23451 DW_AT_specification. */
23453 else if (origin
&& old_die
->die_parent
!= context_die
)
23455 /* If we will be creating an inlined instance, we need a
23456 new DIE that will get annotated with
23457 DW_AT_abstract_origin. */
23458 gcc_assert (!DECL_ABSTRACT_P (decl
));
23462 /* If a DIE was dumped early, it still needs location info.
23463 Skip to where we fill the location bits. */
23466 /* ??? In LTRANS we cannot annotate early created variably
23467 modified type DIEs without copying them and adjusting all
23468 references to them. Thus we dumped them again, also add a
23469 reference to them. */
23470 tree type
= TREE_TYPE (decl_or_origin
);
23472 && variably_modified_type_p
23473 (type
, decl_function_context (decl_or_origin
)))
23475 if (decl_by_reference_p (decl_or_origin
))
23476 add_type_attribute (var_die
, TREE_TYPE (type
),
23477 TYPE_UNQUALIFIED
, false, context_die
);
23479 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
23480 false, context_die
);
23483 goto gen_variable_die_location
;
23487 /* For static data members, the declaration in the class is supposed
23488 to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
23489 also in DWARF2; the specification should still be DW_TAG_variable
23490 referencing the DW_TAG_member DIE. */
23491 if (declaration
&& class_scope_p (context_die
) && dwarf_version
< 5)
23492 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
23494 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
23496 if (origin
!= NULL
)
23497 add_abstract_origin_attribute (var_die
, origin
);
23499 /* Loop unrolling can create multiple blocks that refer to the same
23500 static variable, so we must test for the DW_AT_declaration flag.
23502 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
23503 copy decls and set the DECL_ABSTRACT_P flag on them instead of
23506 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
23507 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
23509 /* This is a definition of a C++ class level static. */
23510 add_AT_specification (var_die
, old_die
);
23511 specialization_p
= true;
23512 if (DECL_NAME (decl
))
23514 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
23515 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
23517 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
23518 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
23520 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
23521 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
23523 if (debug_column_info
23525 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
23526 != (unsigned) s
.column
))
23527 add_AT_unsigned (var_die
, DW_AT_decl_column
, s
.column
);
23529 if (old_die
->die_tag
== DW_TAG_member
)
23530 add_linkage_name (var_die
, decl
);
23534 add_name_and_src_coords_attributes (var_die
, decl
, no_linkage_name
);
23536 if ((origin
== NULL
&& !specialization_p
)
23538 && !DECL_ABSTRACT_P (decl_or_origin
)
23539 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
23540 decl_function_context
23541 (decl_or_origin
))))
23543 tree type
= TREE_TYPE (decl_or_origin
);
23545 if (decl_by_reference_p (decl_or_origin
))
23546 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23549 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
23553 if (origin
== NULL
&& !specialization_p
)
23555 if (TREE_PUBLIC (decl
))
23556 add_AT_flag (var_die
, DW_AT_external
, 1);
23558 if (DECL_ARTIFICIAL (decl
))
23559 add_AT_flag (var_die
, DW_AT_artificial
, 1);
23561 add_alignment_attribute (var_die
, decl
);
23563 add_accessibility_attribute (var_die
, decl
);
23567 add_AT_flag (var_die
, DW_AT_declaration
, 1);
23569 if (decl
&& (DECL_ABSTRACT_P (decl
)
23570 || !old_die
|| is_declaration_die (old_die
)))
23571 equate_decl_number_to_die (decl
, var_die
);
23573 gen_variable_die_location
:
23575 && (! DECL_ABSTRACT_P (decl_or_origin
)
23576 /* Local static vars are shared between all clones/inlines,
23577 so emit DW_AT_location on the abstract DIE if DECL_RTL is
23579 || (VAR_P (decl_or_origin
)
23580 && TREE_STATIC (decl_or_origin
)
23581 && DECL_RTL_SET_P (decl_or_origin
))))
23584 add_pubname (decl_or_origin
, var_die
);
23586 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
23590 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
23592 if ((dwarf_version
>= 4 || !dwarf_strict
)
23593 && lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
23594 DW_AT_const_expr
) == 1
23595 && !get_AT (var_die
, DW_AT_const_expr
)
23596 && !specialization_p
)
23597 add_AT_flag (var_die
, DW_AT_const_expr
, 1);
23601 int inl
= lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
23604 && !get_AT (var_die
, DW_AT_inline
)
23605 && !specialization_p
)
23606 add_AT_unsigned (var_die
, DW_AT_inline
, inl
);
23610 /* Generate a DIE to represent a named constant. */
23613 gen_const_die (tree decl
, dw_die_ref context_die
)
23615 dw_die_ref const_die
;
23616 tree type
= TREE_TYPE (decl
);
23618 const_die
= lookup_decl_die (decl
);
23622 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
23623 equate_decl_number_to_die (decl
, const_die
);
23624 add_name_and_src_coords_attributes (const_die
, decl
);
23625 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
23626 if (TREE_PUBLIC (decl
))
23627 add_AT_flag (const_die
, DW_AT_external
, 1);
23628 if (DECL_ARTIFICIAL (decl
))
23629 add_AT_flag (const_die
, DW_AT_artificial
, 1);
23630 tree_add_const_value_attribute_for_decl (const_die
, decl
);
23633 /* Generate a DIE to represent a label identifier. */
23636 gen_label_die (tree decl
, dw_die_ref context_die
)
23638 tree origin
= decl_ultimate_origin (decl
);
23639 dw_die_ref lbl_die
= lookup_decl_die (decl
);
23641 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23645 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
23646 equate_decl_number_to_die (decl
, lbl_die
);
23648 if (origin
!= NULL
)
23649 add_abstract_origin_attribute (lbl_die
, origin
);
23651 add_name_and_src_coords_attributes (lbl_die
, decl
);
23654 if (DECL_ABSTRACT_P (decl
))
23655 equate_decl_number_to_die (decl
, lbl_die
);
23656 else if (! early_dwarf
)
23658 insn
= DECL_RTL_IF_SET (decl
);
23660 /* Deleted labels are programmer specified labels which have been
23661 eliminated because of various optimizations. We still emit them
23662 here so that it is possible to put breakpoints on them. */
23666 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
23668 /* When optimization is enabled (via -O) some parts of the compiler
23669 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
23670 represent source-level labels which were explicitly declared by
23671 the user. This really shouldn't be happening though, so catch
23672 it if it ever does happen. */
23673 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
23675 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
23676 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23680 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
23681 && CODE_LABEL_NUMBER (insn
) != -1)
23683 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
23684 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23689 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
23690 attributes to the DIE for a block STMT, to describe where the inlined
23691 function was called from. This is similar to add_src_coords_attributes. */
23694 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
23696 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
23698 if (dwarf_version
>= 3 || !dwarf_strict
)
23700 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
23701 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
23702 if (debug_column_info
&& s
.column
)
23703 add_AT_unsigned (die
, DW_AT_call_column
, s
.column
);
23708 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
23709 Add low_pc and high_pc attributes to the DIE for a block STMT. */
23712 add_high_low_attributes (tree stmt
, dw_die_ref die
)
23714 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23716 if (inline_entry_data
**iedp
23717 = !inline_entry_data_table
? NULL
23718 : inline_entry_data_table
->find_slot_with_hash (stmt
,
23719 htab_hash_pointer (stmt
),
23722 inline_entry_data
*ied
= *iedp
;
23723 gcc_assert (MAY_HAVE_DEBUG_MARKER_INSNS
);
23724 gcc_assert (inlined_function_outer_scope_p (stmt
));
23725 ASM_GENERATE_INTERNAL_LABEL (label
, ied
->label_pfx
, ied
->label_num
);
23726 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
23728 if (debug_variable_location_views
&& !ZERO_VIEW_P (ied
->view
))
23730 if (!output_asm_line_debug_info ())
23731 add_AT_unsigned (die
, DW_AT_GNU_entry_view
, ied
->view
);
23734 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", ied
->view
);
23735 /* FIXME: this will resolve to a small number. Could we
23736 possibly emit smaller data? Ideally we'd emit a
23737 uleb128, but that would make the size of DIEs
23738 impossible for the compiler to compute, since it's
23739 the assembler that computes the value of the view
23740 label in this case. Ideally, we'd have a single form
23741 encompassing both the address and the view, and
23742 indirecting them through a table might make things
23743 easier, but even that would be more wasteful,
23744 space-wise, than what we have now. */
23745 add_AT_lbl_id (die
, DW_AT_GNU_entry_view
, label
);
23749 inline_entry_data_table
->clear_slot (iedp
);
23752 if (BLOCK_FRAGMENT_CHAIN (stmt
)
23753 && (dwarf_version
>= 3 || !dwarf_strict
))
23755 tree chain
, superblock
= NULL_TREE
;
23757 dw_attr_node
*attr
= NULL
;
23759 if (!MAY_HAVE_DEBUG_MARKER_INSNS
&& inlined_function_outer_scope_p (stmt
))
23761 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23762 BLOCK_NUMBER (stmt
));
23763 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
23766 /* Optimize duplicate .debug_ranges lists or even tails of
23767 lists. If this BLOCK has same ranges as its supercontext,
23768 lookup DW_AT_ranges attribute in the supercontext (and
23769 recursively so), verify that the ranges_table contains the
23770 right values and use it instead of adding a new .debug_range. */
23771 for (chain
= stmt
, pdie
= die
;
23772 BLOCK_SAME_RANGE (chain
);
23773 chain
= BLOCK_SUPERCONTEXT (chain
))
23775 dw_attr_node
*new_attr
;
23777 pdie
= pdie
->die_parent
;
23780 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
23782 new_attr
= get_AT (pdie
, DW_AT_ranges
);
23783 if (new_attr
== NULL
23784 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
23787 superblock
= BLOCK_SUPERCONTEXT (chain
);
23790 && ((*ranges_table
)[attr
->dw_attr_val
.v
.val_offset
].num
23791 == BLOCK_NUMBER (superblock
))
23792 && BLOCK_FRAGMENT_CHAIN (superblock
))
23794 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
;
23795 unsigned long supercnt
= 0, thiscnt
= 0;
23796 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
23797 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23800 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
].num
23801 == BLOCK_NUMBER (chain
));
23803 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
+ 1].num
== 0);
23804 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23805 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23807 gcc_assert (supercnt
>= thiscnt
);
23808 add_AT_range_list (die
, DW_AT_ranges
, off
+ supercnt
- thiscnt
,
23810 note_rnglist_head (off
+ supercnt
- thiscnt
);
23814 unsigned int offset
= add_ranges (stmt
, true);
23815 add_AT_range_list (die
, DW_AT_ranges
, offset
, false);
23816 note_rnglist_head (offset
);
23818 bool prev_in_cold
= BLOCK_IN_COLD_SECTION_P (stmt
);
23819 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23822 add_ranges (chain
, prev_in_cold
!= BLOCK_IN_COLD_SECTION_P (chain
));
23823 prev_in_cold
= BLOCK_IN_COLD_SECTION_P (chain
);
23824 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
23831 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
23832 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23833 BLOCK_NUMBER (stmt
));
23834 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
23835 BLOCK_NUMBER (stmt
));
23836 add_AT_low_high_pc (die
, label
, label_high
, false);
23840 /* Generate a DIE for a lexical block. */
23843 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
23845 dw_die_ref old_die
= BLOCK_DIE (stmt
);
23846 dw_die_ref stmt_die
= NULL
;
23849 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23850 BLOCK_DIE (stmt
) = stmt_die
;
23853 if (BLOCK_ABSTRACT (stmt
))
23857 /* This must have been generated early and it won't even
23858 need location information since it's a DW_AT_inline
23861 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
23862 if (c
->die_tag
== DW_TAG_inlined_subroutine
23863 || c
->die_tag
== DW_TAG_subprogram
)
23865 gcc_assert (get_AT (c
, DW_AT_inline
));
23871 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
23873 /* If this is an inlined instance, create a new lexical die for
23874 anything below to attach DW_AT_abstract_origin to. */
23877 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23878 BLOCK_DIE (stmt
) = stmt_die
;
23882 tree origin
= block_ultimate_origin (stmt
);
23883 if (origin
!= NULL_TREE
&& origin
!= stmt
)
23884 add_abstract_origin_attribute (stmt_die
, origin
);
23888 stmt_die
= old_die
;
23890 /* A non abstract block whose blocks have already been reordered
23891 should have the instruction range for this block. If so, set the
23892 high/low attributes. */
23893 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
23895 gcc_assert (stmt_die
);
23896 add_high_low_attributes (stmt
, stmt_die
);
23899 decls_for_scope (stmt
, stmt_die
);
23902 /* Generate a DIE for an inlined subprogram. */
23905 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
23909 /* The instance of function that is effectively being inlined shall not
23911 gcc_assert (! BLOCK_ABSTRACT (stmt
));
23913 decl
= block_ultimate_origin (stmt
);
23915 /* Make sure any inlined functions are known to be inlineable. */
23916 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
23917 || cgraph_function_possibly_inlined_p (decl
));
23919 if (! BLOCK_ABSTRACT (stmt
))
23921 dw_die_ref subr_die
23922 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
23924 if (call_arg_locations
|| MAY_HAVE_DEBUG_MARKER_INSNS
)
23925 BLOCK_DIE (stmt
) = subr_die
;
23926 add_abstract_origin_attribute (subr_die
, decl
);
23927 if (TREE_ASM_WRITTEN (stmt
))
23928 add_high_low_attributes (stmt
, subr_die
);
23929 add_call_src_coords_attributes (stmt
, subr_die
);
23931 decls_for_scope (stmt
, subr_die
);
23935 /* Generate a DIE for a field in a record, or structure. CTX is required: see
23936 the comment for VLR_CONTEXT. */
23939 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
23941 dw_die_ref decl_die
;
23943 if (TREE_TYPE (decl
) == error_mark_node
)
23946 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
23947 add_name_and_src_coords_attributes (decl_die
, decl
);
23948 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
23949 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
23952 if (DECL_BIT_FIELD_TYPE (decl
))
23954 add_byte_size_attribute (decl_die
, decl
);
23955 add_bit_size_attribute (decl_die
, decl
);
23956 add_bit_offset_attribute (decl_die
, decl
, ctx
);
23959 add_alignment_attribute (decl_die
, decl
);
23961 /* If we have a variant part offset, then we are supposed to process a member
23962 of a QUAL_UNION_TYPE, which is how we represent variant parts in
23964 gcc_assert (ctx
->variant_part_offset
== NULL_TREE
23965 || TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != QUAL_UNION_TYPE
);
23966 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
23967 add_data_member_location_attribute (decl_die
, decl
, ctx
);
23969 if (DECL_ARTIFICIAL (decl
))
23970 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
23972 add_accessibility_attribute (decl_die
, decl
);
23974 /* Equate decl number to die, so that we can look up this decl later on. */
23975 equate_decl_number_to_die (decl
, decl_die
);
23978 /* Generate a DIE for a pointer to a member type. TYPE can be an
23979 OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
23980 pointer to member function. */
23983 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
23985 if (lookup_type_die (type
))
23988 dw_die_ref ptr_die
= new_die (DW_TAG_ptr_to_member_type
,
23989 scope_die_for (type
, context_die
), type
);
23991 equate_type_number_to_die (type
, ptr_die
);
23992 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
23993 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
23994 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23996 add_alignment_attribute (ptr_die
, type
);
23998 if (TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
23999 && TREE_CODE (TREE_TYPE (type
)) != METHOD_TYPE
)
24001 dw_loc_descr_ref op
= new_loc_descr (DW_OP_plus
, 0, 0);
24002 add_AT_loc (ptr_die
, DW_AT_use_location
, op
);
24006 static char *producer_string
;
24008 /* Return a heap allocated producer string including command line options
24009 if -grecord-gcc-switches. */
24012 gen_producer_string (void)
24015 auto_vec
<const char *> switches
;
24016 const char *language_string
= lang_hooks
.name
;
24017 char *producer
, *tail
;
24019 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
24020 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
24022 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
24023 switch (save_decoded_options
[j
].opt_index
)
24030 case OPT_auxbase_strip
:
24039 case OPT_SPECIAL_unknown
:
24040 case OPT_SPECIAL_ignore
:
24041 case OPT_SPECIAL_program_name
:
24042 case OPT_SPECIAL_input_file
:
24043 case OPT_grecord_gcc_switches
:
24044 case OPT__output_pch_
:
24045 case OPT_fdiagnostics_show_location_
:
24046 case OPT_fdiagnostics_show_option
:
24047 case OPT_fdiagnostics_show_caret
:
24048 case OPT_fdiagnostics_color_
:
24049 case OPT_fverbose_asm
:
24051 case OPT__sysroot_
:
24053 case OPT_nostdinc__
:
24054 case OPT_fpreprocessed
:
24055 case OPT_fltrans_output_list_
:
24056 case OPT_fresolution_
:
24057 case OPT_fdebug_prefix_map_
:
24058 case OPT_fmacro_prefix_map_
:
24059 case OPT_ffile_prefix_map_
:
24060 case OPT_fcompare_debug
:
24061 /* Ignore these. */
24064 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
24065 & CL_NO_DWARF_RECORD
)
24067 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
24069 switch (save_decoded_options
[j
].canonical_option
[0][1])
24076 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
24083 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
24084 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
24088 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
24090 sprintf (tail
, "%s %s", language_string
, version_string
);
24093 FOR_EACH_VEC_ELT (switches
, j
, p
)
24097 memcpy (tail
+ 1, p
, len
);
24105 /* Given a C and/or C++ language/version string return the "highest".
24106 C++ is assumed to be "higher" than C in this case. Used for merging
24107 LTO translation unit languages. */
24108 static const char *
24109 highest_c_language (const char *lang1
, const char *lang2
)
24111 if (strcmp ("GNU C++17", lang1
) == 0 || strcmp ("GNU C++17", lang2
) == 0)
24112 return "GNU C++17";
24113 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
24114 return "GNU C++14";
24115 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
24116 return "GNU C++11";
24117 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
24118 return "GNU C++98";
24120 if (strcmp ("GNU C17", lang1
) == 0 || strcmp ("GNU C17", lang2
) == 0)
24122 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
24124 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
24126 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
24129 gcc_unreachable ();
24133 /* Generate the DIE for the compilation unit. */
24136 gen_compile_unit_die (const char *filename
)
24139 const char *language_string
= lang_hooks
.name
;
24142 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
24146 add_name_attribute (die
, filename
);
24147 /* Don't add cwd for <built-in>. */
24148 if (filename
[0] != '<')
24149 add_comp_dir_attribute (die
);
24152 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
24154 /* If our producer is LTO try to figure out a common language to use
24155 from the global list of translation units. */
24156 if (strcmp (language_string
, "GNU GIMPLE") == 0)
24160 const char *common_lang
= NULL
;
24162 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
24164 if (!TRANSLATION_UNIT_LANGUAGE (t
))
24167 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
24168 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
24170 else if (strncmp (common_lang
, "GNU C", 5) == 0
24171 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
24172 /* Mixing C and C++ is ok, use C++ in that case. */
24173 common_lang
= highest_c_language (common_lang
,
24174 TRANSLATION_UNIT_LANGUAGE (t
));
24177 /* Fall back to C. */
24178 common_lang
= NULL
;
24184 language_string
= common_lang
;
24187 language
= DW_LANG_C
;
24188 if (strncmp (language_string
, "GNU C", 5) == 0
24189 && ISDIGIT (language_string
[5]))
24191 language
= DW_LANG_C89
;
24192 if (dwarf_version
>= 3 || !dwarf_strict
)
24194 if (strcmp (language_string
, "GNU C89") != 0)
24195 language
= DW_LANG_C99
;
24197 if (dwarf_version
>= 5 /* || !dwarf_strict */)
24198 if (strcmp (language_string
, "GNU C11") == 0
24199 || strcmp (language_string
, "GNU C17") == 0)
24200 language
= DW_LANG_C11
;
24203 else if (strncmp (language_string
, "GNU C++", 7) == 0)
24205 language
= DW_LANG_C_plus_plus
;
24206 if (dwarf_version
>= 5 /* || !dwarf_strict */)
24208 if (strcmp (language_string
, "GNU C++11") == 0)
24209 language
= DW_LANG_C_plus_plus_11
;
24210 else if (strcmp (language_string
, "GNU C++14") == 0)
24211 language
= DW_LANG_C_plus_plus_14
;
24212 else if (strcmp (language_string
, "GNU C++17") == 0)
24214 language
= DW_LANG_C_plus_plus_14
;
24217 else if (strcmp (language_string
, "GNU F77") == 0)
24218 language
= DW_LANG_Fortran77
;
24219 else if (dwarf_version
>= 3 || !dwarf_strict
)
24221 if (strcmp (language_string
, "GNU Ada") == 0)
24222 language
= DW_LANG_Ada95
;
24223 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
24225 language
= DW_LANG_Fortran95
;
24226 if (dwarf_version
>= 5 /* || !dwarf_strict */)
24228 if (strcmp (language_string
, "GNU Fortran2003") == 0)
24229 language
= DW_LANG_Fortran03
;
24230 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
24231 language
= DW_LANG_Fortran08
;
24234 else if (strcmp (language_string
, "GNU Objective-C") == 0)
24235 language
= DW_LANG_ObjC
;
24236 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
24237 language
= DW_LANG_ObjC_plus_plus
;
24238 else if (dwarf_version
>= 5 || !dwarf_strict
)
24240 if (strcmp (language_string
, "GNU Go") == 0)
24241 language
= DW_LANG_Go
;
24244 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
24245 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
24246 language
= DW_LANG_Fortran90
;
24248 add_AT_unsigned (die
, DW_AT_language
, language
);
24252 case DW_LANG_Fortran77
:
24253 case DW_LANG_Fortran90
:
24254 case DW_LANG_Fortran95
:
24255 case DW_LANG_Fortran03
:
24256 case DW_LANG_Fortran08
:
24257 /* Fortran has case insensitive identifiers and the front-end
24258 lowercases everything. */
24259 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
24262 /* The default DW_ID_case_sensitive doesn't need to be specified. */
24268 /* Generate the DIE for a base class. */
24271 gen_inheritance_die (tree binfo
, tree access
, tree type
,
24272 dw_die_ref context_die
)
24274 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
24275 struct vlr_context ctx
= { type
, NULL
};
24277 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
24279 add_data_member_location_attribute (die
, binfo
, &ctx
);
24281 if (BINFO_VIRTUAL_P (binfo
))
24282 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
24284 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
24285 children, otherwise the default is DW_ACCESS_public. In DWARF2
24286 the default has always been DW_ACCESS_private. */
24287 if (access
== access_public_node
)
24289 if (dwarf_version
== 2
24290 || context_die
->die_tag
== DW_TAG_class_type
)
24291 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
24293 else if (access
== access_protected_node
)
24294 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
24295 else if (dwarf_version
> 2
24296 && context_die
->die_tag
!= DW_TAG_class_type
)
24297 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
24300 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
24303 is_variant_part (tree decl
)
24305 return (TREE_CODE (decl
) == FIELD_DECL
24306 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
24309 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
24310 return the FIELD_DECL. Return NULL_TREE otherwise. */
24313 analyze_discr_in_predicate (tree operand
, tree struct_type
)
24315 bool continue_stripping
= true;
24316 while (continue_stripping
)
24317 switch (TREE_CODE (operand
))
24320 operand
= TREE_OPERAND (operand
, 0);
24323 continue_stripping
= false;
24327 /* Match field access to members of struct_type only. */
24328 if (TREE_CODE (operand
) == COMPONENT_REF
24329 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
24330 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
24331 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
24332 return TREE_OPERAND (operand
, 1);
24337 /* Check that SRC is a constant integer that can be represented as a native
24338 integer constant (either signed or unsigned). If so, store it into DEST and
24339 return true. Return false otherwise. */
24342 get_discr_value (tree src
, dw_discr_value
*dest
)
24344 tree discr_type
= TREE_TYPE (src
);
24346 if (lang_hooks
.types
.get_debug_type
)
24348 tree debug_type
= lang_hooks
.types
.get_debug_type (discr_type
);
24349 if (debug_type
!= NULL
)
24350 discr_type
= debug_type
;
24353 if (TREE_CODE (src
) != INTEGER_CST
|| !INTEGRAL_TYPE_P (discr_type
))
24356 /* Signedness can vary between the original type and the debug type. This
24357 can happen for character types in Ada for instance: the character type
24358 used for code generation can be signed, to be compatible with the C one,
24359 but from a debugger point of view, it must be unsigned. */
24360 bool is_orig_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
24361 bool is_debug_unsigned
= TYPE_UNSIGNED (discr_type
);
24363 if (is_orig_unsigned
!= is_debug_unsigned
)
24364 src
= fold_convert (discr_type
, src
);
24366 if (!(is_debug_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
24369 dest
->pos
= is_debug_unsigned
;
24370 if (is_debug_unsigned
)
24371 dest
->v
.uval
= tree_to_uhwi (src
);
24373 dest
->v
.sval
= tree_to_shwi (src
);
24378 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
24379 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
24380 store NULL_TREE in DISCR_DECL. Otherwise:
24382 - store the discriminant field in STRUCT_TYPE that controls the variant
24383 part to *DISCR_DECL
24385 - put in *DISCR_LISTS_P an array where for each variant, the item
24386 represents the corresponding matching list of discriminant values.
24388 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
24391 Note that when the array is allocated (i.e. when the analysis is
24392 successful), it is up to the caller to free the array. */
24395 analyze_variants_discr (tree variant_part_decl
,
24398 dw_discr_list_ref
**discr_lists_p
,
24399 unsigned *discr_lists_length
)
24401 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
24403 dw_discr_list_ref
*discr_lists
;
24406 /* Compute how many variants there are in this variant part. */
24407 *discr_lists_length
= 0;
24408 for (variant
= TYPE_FIELDS (variant_part_type
);
24409 variant
!= NULL_TREE
;
24410 variant
= DECL_CHAIN (variant
))
24411 ++*discr_lists_length
;
24413 *discr_decl
= NULL_TREE
;
24415 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
24416 sizeof (**discr_lists_p
));
24417 discr_lists
= *discr_lists_p
;
24419 /* And then analyze all variants to extract discriminant information for all
24420 of them. This analysis is conservative: as soon as we detect something we
24421 do not support, abort everything and pretend we found nothing. */
24422 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
24423 variant
!= NULL_TREE
;
24424 variant
= DECL_CHAIN (variant
), ++i
)
24426 tree match_expr
= DECL_QUALIFIER (variant
);
24428 /* Now, try to analyze the predicate and deduce a discriminant for
24430 if (match_expr
== boolean_true_node
)
24431 /* Typically happens for the default variant: it matches all cases that
24432 previous variants rejected. Don't output any matching value for
24436 /* The following loop tries to iterate over each discriminant
24437 possibility: single values or ranges. */
24438 while (match_expr
!= NULL_TREE
)
24440 tree next_round_match_expr
;
24441 tree candidate_discr
= NULL_TREE
;
24442 dw_discr_list_ref new_node
= NULL
;
24444 /* Possibilities are matched one after the other by nested
24445 TRUTH_ORIF_EXPR expressions. Process the current possibility and
24446 continue with the rest at next iteration. */
24447 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
24449 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
24450 match_expr
= TREE_OPERAND (match_expr
, 1);
24453 next_round_match_expr
= NULL_TREE
;
24455 if (match_expr
== boolean_false_node
)
24456 /* This sub-expression matches nothing: just wait for the next
24460 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
24462 /* We are matching: <discr_field> == <integer_cst>
24463 This sub-expression matches a single value. */
24464 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
24467 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
24470 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
24471 if (!get_discr_value (integer_cst
,
24472 &new_node
->dw_discr_lower_bound
))
24474 new_node
->dw_discr_range
= false;
24477 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
24479 /* We are matching:
24480 <discr_field> > <integer_cst>
24481 && <discr_field> < <integer_cst>.
24482 This sub-expression matches the range of values between the
24483 two matched integer constants. Note that comparisons can be
24484 inclusive or exclusive. */
24485 tree candidate_discr_1
, candidate_discr_2
;
24486 tree lower_cst
, upper_cst
;
24487 bool lower_cst_included
, upper_cst_included
;
24488 tree lower_op
= TREE_OPERAND (match_expr
, 0);
24489 tree upper_op
= TREE_OPERAND (match_expr
, 1);
24491 /* When the comparison is exclusive, the integer constant is not
24492 the discriminant range bound we are looking for: we will have
24493 to increment or decrement it. */
24494 if (TREE_CODE (lower_op
) == GE_EXPR
)
24495 lower_cst_included
= true;
24496 else if (TREE_CODE (lower_op
) == GT_EXPR
)
24497 lower_cst_included
= false;
24501 if (TREE_CODE (upper_op
) == LE_EXPR
)
24502 upper_cst_included
= true;
24503 else if (TREE_CODE (upper_op
) == LT_EXPR
)
24504 upper_cst_included
= false;
24508 /* Extract the discriminant from the first operand and check it
24509 is consistant with the same analysis in the second
24512 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
24515 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
24517 if (candidate_discr_1
== candidate_discr_2
)
24518 candidate_discr
= candidate_discr_1
;
24522 /* Extract bounds from both. */
24523 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
24524 lower_cst
= TREE_OPERAND (lower_op
, 1);
24525 upper_cst
= TREE_OPERAND (upper_op
, 1);
24527 if (!lower_cst_included
)
24529 = fold_build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
), lower_cst
,
24530 build_int_cst (TREE_TYPE (lower_cst
), 1));
24531 if (!upper_cst_included
)
24533 = fold_build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
), upper_cst
,
24534 build_int_cst (TREE_TYPE (upper_cst
), 1));
24536 if (!get_discr_value (lower_cst
,
24537 &new_node
->dw_discr_lower_bound
)
24538 || !get_discr_value (upper_cst
,
24539 &new_node
->dw_discr_upper_bound
))
24542 new_node
->dw_discr_range
= true;
24546 /* Unsupported sub-expression: we cannot determine the set of
24547 matching discriminant values. Abort everything. */
24550 /* If the discriminant info is not consistant with what we saw so
24551 far, consider the analysis failed and abort everything. */
24552 if (candidate_discr
== NULL_TREE
24553 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
24556 *discr_decl
= candidate_discr
;
24558 if (new_node
!= NULL
)
24560 new_node
->dw_discr_next
= discr_lists
[i
];
24561 discr_lists
[i
] = new_node
;
24563 match_expr
= next_round_match_expr
;
24567 /* If we reach this point, we could match everything we were interested
24572 /* Clean all data structure and return no result. */
24573 free (*discr_lists_p
);
24574 *discr_lists_p
= NULL
;
24575 *discr_decl
= NULL_TREE
;
24578 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
24579 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
24582 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
24583 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
24584 this type, which are record types, represent the available variants and each
24585 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
24586 values are inferred from these attributes.
24588 In trees, the offsets for the fields inside these sub-records are relative
24589 to the variant part itself, whereas the corresponding DIEs should have
24590 offset attributes that are relative to the embedding record base address.
24591 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
24592 must be an expression that computes the offset of the variant part to
24593 describe in DWARF. */
24596 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
24597 dw_die_ref context_die
)
24599 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
24600 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
24601 struct loc_descr_context ctx
= {
24602 vlr_ctx
->struct_type
, /* context_type */
24603 NULL_TREE
, /* base_decl */
24605 false, /* placeholder_arg */
24606 false /* placeholder_seen */
24609 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
24610 NULL_TREE if there is no such field. */
24611 tree discr_decl
= NULL_TREE
;
24612 dw_discr_list_ref
*discr_lists
;
24613 unsigned discr_lists_length
= 0;
24616 dw_die_ref dwarf_proc_die
= NULL
;
24617 dw_die_ref variant_part_die
24618 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
24620 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
24622 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
24623 &discr_decl
, &discr_lists
, &discr_lists_length
);
24625 if (discr_decl
!= NULL_TREE
)
24627 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
24630 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
24632 /* We have no DIE for the discriminant, so just discard all
24633 discrimimant information in the output. */
24634 discr_decl
= NULL_TREE
;
24637 /* If the offset for this variant part is more complex than a constant,
24638 create a DWARF procedure for it so that we will not have to generate DWARF
24639 expressions for it for each member. */
24640 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
24641 && (dwarf_version
>= 3 || !dwarf_strict
))
24643 const tree dwarf_proc_fndecl
24644 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
24645 build_function_type (TREE_TYPE (variant_part_offset
),
24647 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
24648 const dw_loc_descr_ref dwarf_proc_body
24649 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
24651 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
24652 dwarf_proc_fndecl
, context_die
);
24653 if (dwarf_proc_die
!= NULL
)
24654 variant_part_offset
= dwarf_proc_call
;
24657 /* Output DIEs for all variants. */
24659 for (tree variant
= TYPE_FIELDS (variant_part_type
);
24660 variant
!= NULL_TREE
;
24661 variant
= DECL_CHAIN (variant
), ++i
)
24663 tree variant_type
= TREE_TYPE (variant
);
24664 dw_die_ref variant_die
;
24666 /* All variants (i.e. members of a variant part) are supposed to be
24667 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
24668 under these records. */
24669 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
24671 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
24672 equate_decl_number_to_die (variant
, variant_die
);
24674 /* Output discriminant values this variant matches, if any. */
24675 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
24676 /* In the case we have discriminant information at all, this is
24677 probably the default variant: as the standard says, don't
24678 output any discriminant value/list attribute. */
24680 else if (discr_lists
[i
]->dw_discr_next
== NULL
24681 && !discr_lists
[i
]->dw_discr_range
)
24682 /* If there is only one accepted value, don't bother outputting a
24684 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
24686 add_discr_list (variant_die
, discr_lists
[i
]);
24688 for (tree member
= TYPE_FIELDS (variant_type
);
24689 member
!= NULL_TREE
;
24690 member
= DECL_CHAIN (member
))
24692 struct vlr_context vlr_sub_ctx
= {
24693 vlr_ctx
->struct_type
, /* struct_type */
24694 NULL
/* variant_part_offset */
24696 if (is_variant_part (member
))
24698 /* All offsets for fields inside variant parts are relative to
24699 the top-level embedding RECORD_TYPE's base address. On the
24700 other hand, offsets in GCC's types are relative to the
24701 nested-most variant part. So we have to sum offsets each time
24704 vlr_sub_ctx
.variant_part_offset
24705 = fold_build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
24706 variant_part_offset
, byte_position (member
));
24707 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
24711 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
24712 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
24717 free (discr_lists
);
24720 /* Generate a DIE for a class member. */
24723 gen_member_die (tree type
, dw_die_ref context_die
)
24726 tree binfo
= TYPE_BINFO (type
);
24728 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
24730 /* If this is not an incomplete type, output descriptions of each of its
24731 members. Note that as we output the DIEs necessary to represent the
24732 members of this record or union type, we will also be trying to output
24733 DIEs to represent the *types* of those members. However the `type'
24734 function (above) will specifically avoid generating type DIEs for member
24735 types *within* the list of member DIEs for this (containing) type except
24736 for those types (of members) which are explicitly marked as also being
24737 members of this (containing) type themselves. The g++ front- end can
24738 force any given type to be treated as a member of some other (containing)
24739 type by setting the TYPE_CONTEXT of the given (member) type to point to
24740 the TREE node representing the appropriate (containing) type. */
24742 /* First output info about the base classes. */
24745 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
24749 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
24750 gen_inheritance_die (base
,
24751 (accesses
? (*accesses
)[i
] : access_public_node
),
24756 /* Now output info about the data members and type members. */
24757 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
24759 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
24760 bool static_inline_p
24761 = (TREE_STATIC (member
)
24762 && (lang_hooks
.decls
.decl_dwarf_attribute (member
, DW_AT_inline
)
24765 /* Ignore clones. */
24766 if (DECL_ABSTRACT_ORIGIN (member
))
24769 /* If we thought we were generating minimal debug info for TYPE
24770 and then changed our minds, some of the member declarations
24771 may have already been defined. Don't define them again, but
24772 do put them in the right order. */
24774 if (dw_die_ref child
= lookup_decl_die (member
))
24776 /* Handle inline static data members, which only have in-class
24778 dw_die_ref ref
= NULL
;
24779 if (child
->die_tag
== DW_TAG_variable
24780 && child
->die_parent
== comp_unit_die ())
24782 ref
= get_AT_ref (child
, DW_AT_specification
);
24783 /* For C++17 inline static data members followed by redundant
24784 out of class redeclaration, we might get here with
24785 child being the DIE created for the out of class
24786 redeclaration and with its DW_AT_specification being
24787 the DIE created for in-class definition. We want to
24788 reparent the latter, and don't want to create another
24789 DIE with DW_AT_specification in that case, because
24790 we already have one. */
24793 && ref
->die_tag
== DW_TAG_variable
24794 && ref
->die_parent
== comp_unit_die ()
24795 && get_AT (ref
, DW_AT_specification
) == NULL
)
24799 static_inline_p
= false;
24803 if (child
->die_tag
== DW_TAG_variable
24804 && child
->die_parent
== comp_unit_die ()
24807 reparent_child (child
, context_die
);
24808 if (dwarf_version
< 5)
24809 child
->die_tag
= DW_TAG_member
;
24812 splice_child_die (context_die
, child
);
24815 /* Do not generate standard DWARF for variant parts if we are generating
24816 the corresponding GNAT encodings: DIEs generated for both would
24817 conflict in our mappings. */
24818 else if (is_variant_part (member
)
24819 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
)
24821 vlr_ctx
.variant_part_offset
= byte_position (member
);
24822 gen_variant_part (member
, &vlr_ctx
, context_die
);
24826 vlr_ctx
.variant_part_offset
= NULL_TREE
;
24827 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
24830 /* For C++ inline static data members emit immediately a DW_TAG_variable
24831 DIE that will refer to that DW_TAG_member/DW_TAG_variable through
24832 DW_AT_specification. */
24833 if (static_inline_p
)
24835 int old_extern
= DECL_EXTERNAL (member
);
24836 DECL_EXTERNAL (member
) = 0;
24837 gen_decl_die (member
, NULL
, NULL
, comp_unit_die ());
24838 DECL_EXTERNAL (member
) = old_extern
;
24843 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
24844 is set, we pretend that the type was never defined, so we only get the
24845 member DIEs needed by later specification DIEs. */
24848 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
24849 enum debug_info_usage usage
)
24851 if (TREE_ASM_WRITTEN (type
))
24853 /* Fill in the bound of variable-length fields in late dwarf if
24854 still incomplete. */
24855 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
24856 for (tree member
= TYPE_FIELDS (type
);
24858 member
= DECL_CHAIN (member
))
24859 fill_variable_array_bounds (TREE_TYPE (member
));
24863 dw_die_ref type_die
= lookup_type_die (type
);
24864 dw_die_ref scope_die
= 0;
24866 int complete
= (TYPE_SIZE (type
)
24867 && (! TYPE_STUB_DECL (type
)
24868 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
24869 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
24870 complete
= complete
&& should_emit_struct_debug (type
, usage
);
24872 if (type_die
&& ! complete
)
24875 if (TYPE_CONTEXT (type
) != NULL_TREE
24876 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24877 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
24880 scope_die
= scope_die_for (type
, context_die
);
24882 /* Generate child dies for template paramaters. */
24883 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
24884 schedule_generic_params_dies_gen (type
);
24886 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
24887 /* First occurrence of type or toplevel definition of nested class. */
24889 dw_die_ref old_die
= type_die
;
24891 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
24892 ? record_type_tag (type
) : DW_TAG_union_type
,
24894 equate_type_number_to_die (type
, type_die
);
24896 add_AT_specification (type_die
, old_die
);
24898 add_name_attribute (type_die
, type_tag (type
));
24901 remove_AT (type_die
, DW_AT_declaration
);
24903 /* If this type has been completed, then give it a byte_size attribute and
24904 then give a list of members. */
24905 if (complete
&& !ns_decl
)
24907 /* Prevent infinite recursion in cases where the type of some member of
24908 this type is expressed in terms of this type itself. */
24909 TREE_ASM_WRITTEN (type
) = 1;
24910 add_byte_size_attribute (type_die
, type
);
24911 add_alignment_attribute (type_die
, type
);
24912 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
24914 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
24915 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
24918 /* If the first reference to this type was as the return type of an
24919 inline function, then it may not have a parent. Fix this now. */
24920 if (type_die
->die_parent
== NULL
)
24921 add_child_die (scope_die
, type_die
);
24923 push_decl_scope (type
);
24924 gen_member_die (type
, type_die
);
24927 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
24928 if (TYPE_ARTIFICIAL (type
))
24929 add_AT_flag (type_die
, DW_AT_artificial
, 1);
24931 /* GNU extension: Record what type our vtable lives in. */
24932 if (TYPE_VFIELD (type
))
24934 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
24936 gen_type_die (vtype
, context_die
);
24937 add_AT_die_ref (type_die
, DW_AT_containing_type
,
24938 lookup_type_die (vtype
));
24943 add_AT_flag (type_die
, DW_AT_declaration
, 1);
24945 /* We don't need to do this for function-local types. */
24946 if (TYPE_STUB_DECL (type
)
24947 && ! decl_function_context (TYPE_STUB_DECL (type
)))
24948 vec_safe_push (incomplete_types
, type
);
24951 if (get_AT (type_die
, DW_AT_name
))
24952 add_pubtype (type
, type_die
);
24955 /* Generate a DIE for a subroutine _type_. */
24958 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
24960 tree return_type
= TREE_TYPE (type
);
24961 dw_die_ref subr_die
24962 = new_die (DW_TAG_subroutine_type
,
24963 scope_die_for (type
, context_die
), type
);
24965 equate_type_number_to_die (type
, subr_die
);
24966 add_prototyped_attribute (subr_die
, type
);
24967 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
24969 add_alignment_attribute (subr_die
, type
);
24970 gen_formal_types_die (type
, subr_die
);
24972 if (get_AT (subr_die
, DW_AT_name
))
24973 add_pubtype (type
, subr_die
);
24974 if ((dwarf_version
>= 5 || !dwarf_strict
)
24975 && lang_hooks
.types
.type_dwarf_attribute (type
, DW_AT_reference
) != -1)
24976 add_AT_flag (subr_die
, DW_AT_reference
, 1);
24977 if ((dwarf_version
>= 5 || !dwarf_strict
)
24978 && lang_hooks
.types
.type_dwarf_attribute (type
,
24979 DW_AT_rvalue_reference
) != -1)
24980 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
24983 /* Generate a DIE for a type definition. */
24986 gen_typedef_die (tree decl
, dw_die_ref context_die
)
24988 dw_die_ref type_die
;
24991 if (TREE_ASM_WRITTEN (decl
))
24993 if (DECL_ORIGINAL_TYPE (decl
))
24994 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
24998 /* As we avoid creating DIEs for local typedefs (see decl_ultimate_origin
24999 checks in process_scope_var and modified_type_die), this should be called
25000 only for original types. */
25001 gcc_assert (decl_ultimate_origin (decl
) == NULL
25002 || decl_ultimate_origin (decl
) == decl
);
25004 TREE_ASM_WRITTEN (decl
) = 1;
25005 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
25007 add_name_and_src_coords_attributes (type_die
, decl
);
25008 if (DECL_ORIGINAL_TYPE (decl
))
25010 type
= DECL_ORIGINAL_TYPE (decl
);
25011 if (type
== error_mark_node
)
25014 gcc_assert (type
!= TREE_TYPE (decl
));
25015 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
25019 type
= TREE_TYPE (decl
);
25020 if (type
== error_mark_node
)
25023 if (is_naming_typedef_decl (TYPE_NAME (type
)))
25025 /* Here, we are in the case of decl being a typedef naming
25026 an anonymous type, e.g:
25027 typedef struct {...} foo;
25028 In that case TREE_TYPE (decl) is not a typedef variant
25029 type and TYPE_NAME of the anonymous type is set to the
25030 TYPE_DECL of the typedef. This construct is emitted by
25033 TYPE is the anonymous struct named by the typedef
25034 DECL. As we need the DW_AT_type attribute of the
25035 DW_TAG_typedef to point to the DIE of TYPE, let's
25036 generate that DIE right away. add_type_attribute
25037 called below will then pick (via lookup_type_die) that
25038 anonymous struct DIE. */
25039 if (!TREE_ASM_WRITTEN (type
))
25040 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
25042 /* This is a GNU Extension. We are adding a
25043 DW_AT_linkage_name attribute to the DIE of the
25044 anonymous struct TYPE. The value of that attribute
25045 is the name of the typedef decl naming the anonymous
25046 struct. This greatly eases the work of consumers of
25047 this debug info. */
25048 add_linkage_name_raw (lookup_type_die (type
), decl
);
25052 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
25055 if (is_naming_typedef_decl (decl
))
25056 /* We want that all subsequent calls to lookup_type_die with
25057 TYPE in argument yield the DW_TAG_typedef we have just
25059 equate_type_number_to_die (type
, type_die
);
25061 add_alignment_attribute (type_die
, TREE_TYPE (decl
));
25063 add_accessibility_attribute (type_die
, decl
);
25065 if (DECL_ABSTRACT_P (decl
))
25066 equate_decl_number_to_die (decl
, type_die
);
25068 if (get_AT (type_die
, DW_AT_name
))
25069 add_pubtype (decl
, type_die
);
25072 /* Generate a DIE for a struct, class, enum or union type. */
25075 gen_tagged_type_die (tree type
,
25076 dw_die_ref context_die
,
25077 enum debug_info_usage usage
)
25081 if (type
== NULL_TREE
25082 || !is_tagged_type (type
))
25085 if (TREE_ASM_WRITTEN (type
))
25087 /* If this is a nested type whose containing class hasn't been written
25088 out yet, writing it out will cover this one, too. This does not apply
25089 to instantiations of member class templates; they need to be added to
25090 the containing class as they are generated. FIXME: This hurts the
25091 idea of combining type decls from multiple TUs, since we can't predict
25092 what set of template instantiations we'll get. */
25093 else if (TYPE_CONTEXT (type
)
25094 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
25095 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
25097 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
25099 if (TREE_ASM_WRITTEN (type
))
25102 /* If that failed, attach ourselves to the stub. */
25103 push_decl_scope (TYPE_CONTEXT (type
));
25104 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
25107 else if (TYPE_CONTEXT (type
) != NULL_TREE
25108 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
25110 /* If this type is local to a function that hasn't been written
25111 out yet, use a NULL context for now; it will be fixed up in
25112 decls_for_scope. */
25113 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
25114 /* A declaration DIE doesn't count; nested types need to go in the
25116 if (context_die
&& is_declaration_die (context_die
))
25117 context_die
= NULL
;
25122 context_die
= declare_in_namespace (type
, context_die
);
25126 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
25128 /* This might have been written out by the call to
25129 declare_in_namespace. */
25130 if (!TREE_ASM_WRITTEN (type
))
25131 gen_enumeration_type_die (type
, context_die
);
25134 gen_struct_or_union_type_die (type
, context_die
, usage
);
25139 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
25140 it up if it is ever completed. gen_*_type_die will set it for us
25141 when appropriate. */
25144 /* Generate a type description DIE. */
25147 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
25148 enum debug_info_usage usage
)
25150 struct array_descr_info info
;
25152 if (type
== NULL_TREE
|| type
== error_mark_node
)
25155 if (flag_checking
&& type
)
25156 verify_type (type
);
25158 if (TYPE_NAME (type
) != NULL_TREE
25159 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
25160 && is_redundant_typedef (TYPE_NAME (type
))
25161 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
25162 /* The DECL of this type is a typedef we don't want to emit debug
25163 info for but we want debug info for its underlying typedef.
25164 This can happen for e.g, the injected-class-name of a C++
25166 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
25168 /* If TYPE is a typedef type variant, let's generate debug info
25169 for the parent typedef which TYPE is a type of. */
25170 if (typedef_variant_p (type
))
25172 if (TREE_ASM_WRITTEN (type
))
25175 tree name
= TYPE_NAME (type
);
25176 tree origin
= decl_ultimate_origin (name
);
25177 if (origin
!= NULL
&& origin
!= name
)
25179 gen_decl_die (origin
, NULL
, NULL
, context_die
);
25183 /* Prevent broken recursion; we can't hand off to the same type. */
25184 gcc_assert (DECL_ORIGINAL_TYPE (name
) != type
);
25186 /* Give typedefs the right scope. */
25187 context_die
= scope_die_for (type
, context_die
);
25189 TREE_ASM_WRITTEN (type
) = 1;
25191 gen_decl_die (name
, NULL
, NULL
, context_die
);
25195 /* If type is an anonymous tagged type named by a typedef, let's
25196 generate debug info for the typedef. */
25197 if (is_naming_typedef_decl (TYPE_NAME (type
)))
25199 /* Use the DIE of the containing namespace as the parent DIE of
25200 the type description DIE we want to generate. */
25201 if (DECL_CONTEXT (TYPE_NAME (type
))
25202 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
25203 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
25205 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
25209 if (lang_hooks
.types
.get_debug_type
)
25211 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
25213 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
25215 gen_type_die_with_usage (debug_type
, context_die
, usage
);
25220 /* We are going to output a DIE to represent the unqualified version
25221 of this type (i.e. without any const or volatile qualifiers) so
25222 get the main variant (i.e. the unqualified version) of this type
25223 now. (Vectors and arrays are special because the debugging info is in the
25224 cloned type itself. Similarly function/method types can contain extra
25225 ref-qualification). */
25226 if (TREE_CODE (type
) == FUNCTION_TYPE
25227 || TREE_CODE (type
) == METHOD_TYPE
)
25229 /* For function/method types, can't use type_main_variant here,
25230 because that can have different ref-qualifiers for C++,
25231 but try to canonicalize. */
25232 tree main
= TYPE_MAIN_VARIANT (type
);
25233 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
25234 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
25235 && check_base_type (t
, main
)
25236 && check_lang_type (t
, type
))
25242 else if (TREE_CODE (type
) != VECTOR_TYPE
25243 && TREE_CODE (type
) != ARRAY_TYPE
)
25244 type
= type_main_variant (type
);
25246 /* If this is an array type with hidden descriptor, handle it first. */
25247 if (!TREE_ASM_WRITTEN (type
)
25248 && lang_hooks
.types
.get_array_descr_info
)
25250 memset (&info
, 0, sizeof (info
));
25251 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
25253 /* Fortran sometimes emits array types with no dimension. */
25254 gcc_assert (info
.ndimensions
>= 0
25255 && (info
.ndimensions
25256 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
25257 gen_descr_array_type_die (type
, &info
, context_die
);
25258 TREE_ASM_WRITTEN (type
) = 1;
25263 if (TREE_ASM_WRITTEN (type
))
25265 /* Variable-length types may be incomplete even if
25266 TREE_ASM_WRITTEN. For such types, fall through to
25267 gen_array_type_die() and possibly fill in
25268 DW_AT_{upper,lower}_bound attributes. */
25269 if ((TREE_CODE (type
) != ARRAY_TYPE
25270 && TREE_CODE (type
) != RECORD_TYPE
25271 && TREE_CODE (type
) != UNION_TYPE
25272 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
25273 || !variably_modified_type_p (type
, NULL
))
25277 switch (TREE_CODE (type
))
25283 case REFERENCE_TYPE
:
25284 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
25285 ensures that the gen_type_die recursion will terminate even if the
25286 type is recursive. Recursive types are possible in Ada. */
25287 /* ??? We could perhaps do this for all types before the switch
25289 TREE_ASM_WRITTEN (type
) = 1;
25291 /* For these types, all that is required is that we output a DIE (or a
25292 set of DIEs) to represent the "basis" type. */
25293 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
25294 DINFO_USAGE_IND_USE
);
25298 /* This code is used for C++ pointer-to-data-member types.
25299 Output a description of the relevant class type. */
25300 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
25301 DINFO_USAGE_IND_USE
);
25303 /* Output a description of the type of the object pointed to. */
25304 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
25305 DINFO_USAGE_IND_USE
);
25307 /* Now output a DIE to represent this pointer-to-data-member type
25309 gen_ptr_to_mbr_type_die (type
, context_die
);
25312 case FUNCTION_TYPE
:
25313 /* Force out return type (in case it wasn't forced out already). */
25314 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
25315 DINFO_USAGE_DIR_USE
);
25316 gen_subroutine_type_die (type
, context_die
);
25320 /* Force out return type (in case it wasn't forced out already). */
25321 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
25322 DINFO_USAGE_DIR_USE
);
25323 gen_subroutine_type_die (type
, context_die
);
25328 gen_array_type_die (type
, context_die
);
25331 case ENUMERAL_TYPE
:
25334 case QUAL_UNION_TYPE
:
25335 gen_tagged_type_die (type
, context_die
, usage
);
25341 case FIXED_POINT_TYPE
:
25344 case POINTER_BOUNDS_TYPE
:
25345 /* No DIEs needed for fundamental types. */
25350 /* Just use DW_TAG_unspecified_type. */
25352 dw_die_ref type_die
= lookup_type_die (type
);
25353 if (type_die
== NULL
)
25355 tree name
= TYPE_IDENTIFIER (type
);
25356 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
25358 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
25359 equate_type_number_to_die (type
, type_die
);
25365 if (is_cxx_auto (type
))
25367 tree name
= TYPE_IDENTIFIER (type
);
25368 dw_die_ref
*die
= (name
== get_identifier ("auto")
25369 ? &auto_die
: &decltype_auto_die
);
25372 *die
= new_die (DW_TAG_unspecified_type
,
25373 comp_unit_die (), NULL_TREE
);
25374 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
25376 equate_type_number_to_die (type
, *die
);
25379 gcc_unreachable ();
25382 TREE_ASM_WRITTEN (type
) = 1;
25386 gen_type_die (tree type
, dw_die_ref context_die
)
25388 if (type
!= error_mark_node
)
25390 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
25393 dw_die_ref die
= lookup_type_die (type
);
25400 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
25401 things which are local to the given block. */
25404 gen_block_die (tree stmt
, dw_die_ref context_die
)
25406 int must_output_die
= 0;
25409 /* Ignore blocks that are NULL. */
25410 if (stmt
== NULL_TREE
)
25413 inlined_func
= inlined_function_outer_scope_p (stmt
);
25415 /* If the block is one fragment of a non-contiguous block, do not
25416 process the variables, since they will have been done by the
25417 origin block. Do process subblocks. */
25418 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
25422 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
25423 gen_block_die (sub
, context_die
);
25428 /* Determine if we need to output any Dwarf DIEs at all to represent this
25431 /* The outer scopes for inlinings *must* always be represented. We
25432 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
25433 must_output_die
= 1;
25436 /* Determine if this block directly contains any "significant"
25437 local declarations which we will need to output DIEs for. */
25438 if (debug_info_level
> DINFO_LEVEL_TERSE
)
25439 /* We are not in terse mode so *any* local declaration counts
25440 as being a "significant" one. */
25441 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
25442 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
25443 && (TREE_USED (stmt
)
25444 || TREE_ASM_WRITTEN (stmt
)
25445 || BLOCK_ABSTRACT (stmt
)));
25446 else if ((TREE_USED (stmt
)
25447 || TREE_ASM_WRITTEN (stmt
)
25448 || BLOCK_ABSTRACT (stmt
))
25449 && !dwarf2out_ignore_block (stmt
))
25450 must_output_die
= 1;
25453 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
25454 DIE for any block which contains no significant local declarations at
25455 all. Rather, in such cases we just call `decls_for_scope' so that any
25456 needed Dwarf info for any sub-blocks will get properly generated. Note
25457 that in terse mode, our definition of what constitutes a "significant"
25458 local declaration gets restricted to include only inlined function
25459 instances and local (nested) function definitions. */
25460 if (must_output_die
)
25464 /* If STMT block is abstract, that means we have been called
25465 indirectly from dwarf2out_abstract_function.
25466 That function rightfully marks the descendent blocks (of
25467 the abstract function it is dealing with) as being abstract,
25468 precisely to prevent us from emitting any
25469 DW_TAG_inlined_subroutine DIE as a descendent
25470 of an abstract function instance. So in that case, we should
25471 not call gen_inlined_subroutine_die.
25473 Later though, when cgraph asks dwarf2out to emit info
25474 for the concrete instance of the function decl into which
25475 the concrete instance of STMT got inlined, the later will lead
25476 to the generation of a DW_TAG_inlined_subroutine DIE. */
25477 if (! BLOCK_ABSTRACT (stmt
))
25478 gen_inlined_subroutine_die (stmt
, context_die
);
25481 gen_lexical_block_die (stmt
, context_die
);
25484 decls_for_scope (stmt
, context_die
);
25487 /* Process variable DECL (or variable with origin ORIGIN) within
25488 block STMT and add it to CONTEXT_DIE. */
25490 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
25493 tree decl_or_origin
= decl
? decl
: origin
;
25495 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
25496 die
= lookup_decl_die (decl_or_origin
);
25497 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
)
25499 if (TYPE_DECL_IS_STUB (decl_or_origin
))
25500 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
25502 die
= lookup_decl_die (decl_or_origin
);
25503 /* Avoid re-creating the DIE late if it was optimized as unused early. */
25504 if (! die
&& ! early_dwarf
)
25510 /* Avoid creating DIEs for local typedefs and concrete static variables that
25511 will only be pruned later. */
25512 if ((origin
|| decl_ultimate_origin (decl
))
25513 && (TREE_CODE (decl_or_origin
) == TYPE_DECL
25514 || (VAR_P (decl_or_origin
) && TREE_STATIC (decl_or_origin
))))
25516 origin
= decl_ultimate_origin (decl_or_origin
);
25517 if (decl
&& VAR_P (decl
) && die
!= NULL
)
25519 die
= lookup_decl_die (origin
);
25521 equate_decl_number_to_die (decl
, die
);
25526 if (die
!= NULL
&& die
->die_parent
== NULL
)
25527 add_child_die (context_die
, die
);
25528 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
25531 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
25532 stmt
, context_die
);
25536 if (decl
&& DECL_P (decl
))
25538 die
= lookup_decl_die (decl
);
25540 /* Early created DIEs do not have a parent as the decls refer
25541 to the function as DECL_CONTEXT rather than the BLOCK. */
25542 if (die
&& die
->die_parent
== NULL
)
25544 gcc_assert (in_lto_p
);
25545 add_child_die (context_die
, die
);
25549 gen_decl_die (decl
, origin
, NULL
, context_die
);
25553 /* Generate all of the decls declared within a given scope and (recursively)
25554 all of its sub-blocks. */
25557 decls_for_scope (tree stmt
, dw_die_ref context_die
)
25563 /* Ignore NULL blocks. */
25564 if (stmt
== NULL_TREE
)
25567 /* Output the DIEs to represent all of the data objects and typedefs
25568 declared directly within this block but not within any nested
25569 sub-blocks. Also, nested function and tag DIEs have been
25570 generated with a parent of NULL; fix that up now. We don't
25571 have to do this if we're at -g1. */
25572 if (debug_info_level
> DINFO_LEVEL_TERSE
)
25574 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
25575 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
25576 /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
25577 origin - avoid doing this twice as we have no good way to see
25578 if we've done it once already. */
25580 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
25582 decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
25583 if (decl
== current_function_decl
)
25584 /* Ignore declarations of the current function, while they
25585 are declarations, gen_subprogram_die would treat them
25586 as definitions again, because they are equal to
25587 current_function_decl and endlessly recurse. */;
25588 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
25589 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
25591 process_scope_var (stmt
, NULL_TREE
, decl
, context_die
);
25595 /* Even if we're at -g1, we need to process the subblocks in order to get
25596 inlined call information. */
25598 /* Output the DIEs to represent all sub-blocks (and the items declared
25599 therein) of this block. */
25600 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
25602 subblocks
= BLOCK_CHAIN (subblocks
))
25603 gen_block_die (subblocks
, context_die
);
25606 /* Is this a typedef we can avoid emitting? */
25609 is_redundant_typedef (const_tree decl
)
25611 if (TYPE_DECL_IS_STUB (decl
))
25614 if (DECL_ARTIFICIAL (decl
)
25615 && DECL_CONTEXT (decl
)
25616 && is_tagged_type (DECL_CONTEXT (decl
))
25617 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
25618 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
25619 /* Also ignore the artificial member typedef for the class name. */
25625 /* Return TRUE if TYPE is a typedef that names a type for linkage
25626 purposes. This kind of typedefs is produced by the C++ FE for
25629 typedef struct {...} foo;
25631 In that case, there is no typedef variant type produced for foo.
25632 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
25636 is_naming_typedef_decl (const_tree decl
)
25638 if (decl
== NULL_TREE
25639 || TREE_CODE (decl
) != TYPE_DECL
25640 || DECL_NAMELESS (decl
)
25641 || !is_tagged_type (TREE_TYPE (decl
))
25642 || DECL_IS_BUILTIN (decl
)
25643 || is_redundant_typedef (decl
)
25644 /* It looks like Ada produces TYPE_DECLs that are very similar
25645 to C++ naming typedefs but that have different
25646 semantics. Let's be specific to c++ for now. */
25650 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
25651 && TYPE_NAME (TREE_TYPE (decl
)) == decl
25652 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
25653 != TYPE_NAME (TREE_TYPE (decl
))));
25656 /* Looks up the DIE for a context. */
25658 static inline dw_die_ref
25659 lookup_context_die (tree context
)
25663 /* Find die that represents this context. */
25664 if (TYPE_P (context
))
25666 context
= TYPE_MAIN_VARIANT (context
);
25667 dw_die_ref ctx
= lookup_type_die (context
);
25670 return strip_naming_typedef (context
, ctx
);
25673 return lookup_decl_die (context
);
25675 return comp_unit_die ();
25678 /* Returns the DIE for a context. */
25680 static inline dw_die_ref
25681 get_context_die (tree context
)
25685 /* Find die that represents this context. */
25686 if (TYPE_P (context
))
25688 context
= TYPE_MAIN_VARIANT (context
);
25689 return strip_naming_typedef (context
, force_type_die (context
));
25692 return force_decl_die (context
);
25694 return comp_unit_die ();
25697 /* Returns the DIE for decl. A DIE will always be returned. */
25700 force_decl_die (tree decl
)
25702 dw_die_ref decl_die
;
25703 unsigned saved_external_flag
;
25704 tree save_fn
= NULL_TREE
;
25705 decl_die
= lookup_decl_die (decl
);
25708 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
25710 decl_die
= lookup_decl_die (decl
);
25714 switch (TREE_CODE (decl
))
25716 case FUNCTION_DECL
:
25717 /* Clear current_function_decl, so that gen_subprogram_die thinks
25718 that this is a declaration. At this point, we just want to force
25719 declaration die. */
25720 save_fn
= current_function_decl
;
25721 current_function_decl
= NULL_TREE
;
25722 gen_subprogram_die (decl
, context_die
);
25723 current_function_decl
= save_fn
;
25727 /* Set external flag to force declaration die. Restore it after
25728 gen_decl_die() call. */
25729 saved_external_flag
= DECL_EXTERNAL (decl
);
25730 DECL_EXTERNAL (decl
) = 1;
25731 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25732 DECL_EXTERNAL (decl
) = saved_external_flag
;
25735 case NAMESPACE_DECL
:
25736 if (dwarf_version
>= 3 || !dwarf_strict
)
25737 dwarf2out_decl (decl
);
25739 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
25740 decl_die
= comp_unit_die ();
25743 case TRANSLATION_UNIT_DECL
:
25744 decl_die
= comp_unit_die ();
25748 gcc_unreachable ();
25751 /* We should be able to find the DIE now. */
25753 decl_die
= lookup_decl_die (decl
);
25754 gcc_assert (decl_die
);
25760 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
25761 always returned. */
25764 force_type_die (tree type
)
25766 dw_die_ref type_die
;
25768 type_die
= lookup_type_die (type
);
25771 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
25773 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
25774 false, context_die
);
25775 gcc_assert (type_die
);
25780 /* Force out any required namespaces to be able to output DECL,
25781 and return the new context_die for it, if it's changed. */
25784 setup_namespace_context (tree thing
, dw_die_ref context_die
)
25786 tree context
= (DECL_P (thing
)
25787 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
25788 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
25789 /* Force out the namespace. */
25790 context_die
= force_decl_die (context
);
25792 return context_die
;
25795 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
25796 type) within its namespace, if appropriate.
25798 For compatibility with older debuggers, namespace DIEs only contain
25799 declarations; all definitions are emitted at CU scope, with
25800 DW_AT_specification pointing to the declaration (like with class
25804 declare_in_namespace (tree thing
, dw_die_ref context_die
)
25806 dw_die_ref ns_context
;
25808 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25809 return context_die
;
25811 /* External declarations in the local scope only need to be emitted
25812 once, not once in the namespace and once in the scope.
25814 This avoids declaring the `extern' below in the
25815 namespace DIE as well as in the innermost scope:
25828 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
25829 return context_die
;
25831 /* If this decl is from an inlined function, then don't try to emit it in its
25832 namespace, as we will get confused. It would have already been emitted
25833 when the abstract instance of the inline function was emitted anyways. */
25834 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
25835 return context_die
;
25837 ns_context
= setup_namespace_context (thing
, context_die
);
25839 if (ns_context
!= context_die
)
25843 if (DECL_P (thing
))
25844 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
25846 gen_type_die (thing
, ns_context
);
25848 return context_die
;
25851 /* Generate a DIE for a namespace or namespace alias. */
25854 gen_namespace_die (tree decl
, dw_die_ref context_die
)
25856 dw_die_ref namespace_die
;
25858 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
25859 they are an alias of. */
25860 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
25862 /* Output a real namespace or module. */
25863 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25864 namespace_die
= new_die (is_fortran ()
25865 ? DW_TAG_module
: DW_TAG_namespace
,
25866 context_die
, decl
);
25867 /* For Fortran modules defined in different CU don't add src coords. */
25868 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
25870 const char *name
= dwarf2_name (decl
, 0);
25872 add_name_attribute (namespace_die
, name
);
25875 add_name_and_src_coords_attributes (namespace_die
, decl
);
25876 if (DECL_EXTERNAL (decl
))
25877 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
25878 equate_decl_number_to_die (decl
, namespace_die
);
25882 /* Output a namespace alias. */
25884 /* Force out the namespace we are an alias of, if necessary. */
25885 dw_die_ref origin_die
25886 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
25888 if (DECL_FILE_SCOPE_P (decl
)
25889 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
25890 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25891 /* Now create the namespace alias DIE. */
25892 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
25893 add_name_and_src_coords_attributes (namespace_die
, decl
);
25894 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
25895 equate_decl_number_to_die (decl
, namespace_die
);
25897 if ((dwarf_version
>= 5 || !dwarf_strict
)
25898 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
25899 DW_AT_export_symbols
) == 1)
25900 add_AT_flag (namespace_die
, DW_AT_export_symbols
, 1);
25902 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
25903 if (want_pubnames ())
25904 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
25907 /* Generate Dwarf debug information for a decl described by DECL.
25908 The return value is currently only meaningful for PARM_DECLs,
25909 for all other decls it returns NULL.
25911 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
25912 It can be NULL otherwise. */
25915 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
25916 dw_die_ref context_die
)
25918 tree decl_or_origin
= decl
? decl
: origin
;
25919 tree class_origin
= NULL
, ultimate_origin
;
25921 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
25924 /* Ignore pointer bounds decls. */
25925 if (DECL_P (decl_or_origin
)
25926 && TREE_TYPE (decl_or_origin
)
25927 && POINTER_BOUNDS_P (decl_or_origin
))
25930 switch (TREE_CODE (decl_or_origin
))
25936 if (!is_fortran () && !is_ada ())
25938 /* The individual enumerators of an enum type get output when we output
25939 the Dwarf representation of the relevant enum type itself. */
25943 /* Emit its type. */
25944 gen_type_die (TREE_TYPE (decl
), context_die
);
25946 /* And its containing namespace. */
25947 context_die
= declare_in_namespace (decl
, context_die
);
25949 gen_const_die (decl
, context_die
);
25952 case FUNCTION_DECL
:
25955 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
25956 on local redeclarations of global functions. That seems broken. */
25957 if (current_function_decl
!= decl
)
25958 /* This is only a declaration. */;
25961 /* We should have abstract copies already and should not generate
25962 stray type DIEs in late LTO dumping. */
25966 /* If we're emitting a clone, emit info for the abstract instance. */
25967 else if (origin
|| DECL_ORIGIN (decl
) != decl
)
25968 dwarf2out_abstract_function (origin
25969 ? DECL_ORIGIN (origin
)
25970 : DECL_ABSTRACT_ORIGIN (decl
));
25972 /* If we're emitting a possibly inlined function emit it as
25973 abstract instance. */
25974 else if (cgraph_function_possibly_inlined_p (decl
)
25975 && ! DECL_ABSTRACT_P (decl
)
25976 && ! class_or_namespace_scope_p (context_die
)
25977 /* dwarf2out_abstract_function won't emit a die if this is just
25978 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
25979 that case, because that works only if we have a die. */
25980 && DECL_INITIAL (decl
) != NULL_TREE
)
25981 dwarf2out_abstract_function (decl
);
25983 /* Otherwise we're emitting the primary DIE for this decl. */
25984 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
25986 /* Before we describe the FUNCTION_DECL itself, make sure that we
25987 have its containing type. */
25989 origin
= decl_class_context (decl
);
25990 if (origin
!= NULL_TREE
)
25991 gen_type_die (origin
, context_die
);
25993 /* And its return type. */
25994 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
25996 /* And its virtual context. */
25997 if (DECL_VINDEX (decl
) != NULL_TREE
)
25998 gen_type_die (DECL_CONTEXT (decl
), context_die
);
26000 /* Make sure we have a member DIE for decl. */
26001 if (origin
!= NULL_TREE
)
26002 gen_type_die_for_member (origin
, decl
, context_die
);
26004 /* And its containing namespace. */
26005 context_die
= declare_in_namespace (decl
, context_die
);
26008 /* Now output a DIE to represent the function itself. */
26010 gen_subprogram_die (decl
, context_die
);
26014 /* If we are in terse mode, don't generate any DIEs to represent any
26015 actual typedefs. */
26016 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
26019 /* In the special case of a TYPE_DECL node representing the declaration
26020 of some type tag, if the given TYPE_DECL is marked as having been
26021 instantiated from some other (original) TYPE_DECL node (e.g. one which
26022 was generated within the original definition of an inline function) we
26023 used to generate a special (abbreviated) DW_TAG_structure_type,
26024 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
26025 should be actually referencing those DIEs, as variable DIEs with that
26026 type would be emitted already in the abstract origin, so it was always
26027 removed during unused type prunning. Don't add anything in this
26029 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
26032 if (is_redundant_typedef (decl
))
26033 gen_type_die (TREE_TYPE (decl
), context_die
);
26035 /* Output a DIE to represent the typedef itself. */
26036 gen_typedef_die (decl
, context_die
);
26040 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
26041 gen_label_die (decl
, context_die
);
26046 /* If we are in terse mode, don't generate any DIEs to represent any
26047 variable declarations or definitions. */
26048 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
26051 /* Avoid generating stray type DIEs during late dwarf dumping.
26052 All types have been dumped early. */
26054 /* ??? But in LTRANS we cannot annotate early created variably
26055 modified type DIEs without copying them and adjusting all
26056 references to them. Dump them again as happens for inlining
26057 which copies both the decl and the types. */
26058 /* ??? And even non-LTO needs to re-visit type DIEs to fill
26059 in VLA bound information for example. */
26060 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
26061 current_function_decl
)))
26063 /* Output any DIEs that are needed to specify the type of this data
26065 if (decl_by_reference_p (decl_or_origin
))
26066 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
26068 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
26073 /* And its containing type. */
26074 class_origin
= decl_class_context (decl_or_origin
);
26075 if (class_origin
!= NULL_TREE
)
26076 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
26078 /* And its containing namespace. */
26079 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
26082 /* Now output the DIE to represent the data object itself. This gets
26083 complicated because of the possibility that the VAR_DECL really
26084 represents an inlined instance of a formal parameter for an inline
26086 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
26087 if (ultimate_origin
!= NULL_TREE
26088 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
26089 gen_formal_parameter_die (decl
, origin
,
26090 true /* Emit name attribute. */,
26093 gen_variable_die (decl
, origin
, context_die
);
26097 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
26098 /* Ignore the nameless fields that are used to skip bits but handle C++
26099 anonymous unions and structs. */
26100 if (DECL_NAME (decl
) != NULL_TREE
26101 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
26102 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
26104 gen_type_die (member_declared_type (decl
), context_die
);
26105 gen_field_die (decl
, ctx
, context_die
);
26110 /* Avoid generating stray type DIEs during late dwarf dumping.
26111 All types have been dumped early. */
26113 /* ??? But in LTRANS we cannot annotate early created variably
26114 modified type DIEs without copying them and adjusting all
26115 references to them. Dump them again as happens for inlining
26116 which copies both the decl and the types. */
26117 /* ??? And even non-LTO needs to re-visit type DIEs to fill
26118 in VLA bound information for example. */
26119 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
26120 current_function_decl
)))
26122 if (DECL_BY_REFERENCE (decl_or_origin
))
26123 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
26125 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
26127 return gen_formal_parameter_die (decl
, origin
,
26128 true /* Emit name attribute. */,
26131 case NAMESPACE_DECL
:
26132 if (dwarf_version
>= 3 || !dwarf_strict
)
26133 gen_namespace_die (decl
, context_die
);
26136 case IMPORTED_DECL
:
26137 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
26138 DECL_CONTEXT (decl
), context_die
);
26141 case NAMELIST_DECL
:
26142 gen_namelist_decl (DECL_NAME (decl
), context_die
,
26143 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
26147 /* Probably some frontend-internal decl. Assume we don't care. */
26148 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
26155 /* Output initial debug information for global DECL. Called at the
26156 end of the parsing process.
26158 This is the initial debug generation process. As such, the DIEs
26159 generated may be incomplete. A later debug generation pass
26160 (dwarf2out_late_global_decl) will augment the information generated
26161 in this pass (e.g., with complete location info). */
26164 dwarf2out_early_global_decl (tree decl
)
26168 /* gen_decl_die() will set DECL_ABSTRACT because
26169 cgraph_function_possibly_inlined_p() returns true. This is in
26170 turn will cause DW_AT_inline attributes to be set.
26172 This happens because at early dwarf generation, there is no
26173 cgraph information, causing cgraph_function_possibly_inlined_p()
26174 to return true. Trick cgraph_function_possibly_inlined_p()
26175 while we generate dwarf early. */
26176 bool save
= symtab
->global_info_ready
;
26177 symtab
->global_info_ready
= true;
26179 /* We don't handle TYPE_DECLs. If required, they'll be reached via
26180 other DECLs and they can point to template types or other things
26181 that dwarf2out can't handle when done via dwarf2out_decl. */
26182 if (TREE_CODE (decl
) != TYPE_DECL
26183 && TREE_CODE (decl
) != PARM_DECL
)
26185 if (TREE_CODE (decl
) == FUNCTION_DECL
)
26187 tree save_fndecl
= current_function_decl
;
26189 /* For nested functions, make sure we have DIEs for the parents first
26190 so that all nested DIEs are generated at the proper scope in the
26192 tree context
= decl_function_context (decl
);
26193 if (context
!= NULL
)
26195 dw_die_ref context_die
= lookup_decl_die (context
);
26196 current_function_decl
= context
;
26198 /* Avoid emitting DIEs multiple times, but still process CONTEXT
26199 enough so that it lands in its own context. This avoids type
26200 pruning issues later on. */
26201 if (context_die
== NULL
|| is_declaration_die (context_die
))
26202 dwarf2out_decl (context
);
26205 /* Emit an abstract origin of a function first. This happens
26206 with C++ constructor clones for example and makes
26207 dwarf2out_abstract_function happy which requires the early
26208 DIE of the abstract instance to be present. */
26209 tree origin
= DECL_ABSTRACT_ORIGIN (decl
);
26210 dw_die_ref origin_die
;
26212 /* Do not emit the DIE multiple times but make sure to
26213 process it fully here in case we just saw a declaration. */
26214 && ((origin_die
= lookup_decl_die (origin
)) == NULL
26215 || is_declaration_die (origin_die
)))
26217 current_function_decl
= origin
;
26218 dwarf2out_decl (origin
);
26221 /* Emit the DIE for decl but avoid doing that multiple times. */
26222 dw_die_ref old_die
;
26223 if ((old_die
= lookup_decl_die (decl
)) == NULL
26224 || is_declaration_die (old_die
))
26226 current_function_decl
= decl
;
26227 dwarf2out_decl (decl
);
26230 current_function_decl
= save_fndecl
;
26233 dwarf2out_decl (decl
);
26235 symtab
->global_info_ready
= save
;
26238 /* Output debug information for global decl DECL. Called from
26239 toplev.c after compilation proper has finished. */
26242 dwarf2out_late_global_decl (tree decl
)
26244 /* Fill-in any location information we were unable to determine
26245 on the first pass. */
26246 if (VAR_P (decl
) && !POINTER_BOUNDS_P (decl
))
26248 dw_die_ref die
= lookup_decl_die (decl
);
26250 /* We may have to generate early debug late for LTO in case debug
26251 was not enabled at compile-time or the target doesn't support
26252 the LTO early debug scheme. */
26253 if (! die
&& in_lto_p
)
26255 dwarf2out_decl (decl
);
26256 die
= lookup_decl_die (decl
);
26261 /* We get called via the symtab code invoking late_global_decl
26262 for symbols that are optimized out. Do not add locations
26263 for those, except if they have a DECL_VALUE_EXPR, in which case
26264 they are relevant for debuggers. */
26265 varpool_node
*node
= varpool_node::get (decl
);
26266 if ((! node
|| ! node
->definition
) && ! DECL_HAS_VALUE_EXPR_P (decl
))
26267 tree_add_const_value_attribute_for_decl (die
, decl
);
26269 add_location_or_const_value_attribute (die
, decl
, false);
26274 /* Output debug information for type decl DECL. Called from toplev.c
26275 and from language front ends (to record built-in types). */
26277 dwarf2out_type_decl (tree decl
, int local
)
26282 dwarf2out_decl (decl
);
26286 /* Output debug information for imported module or decl DECL.
26287 NAME is non-NULL name in the lexical block if the decl has been renamed.
26288 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
26289 that DECL belongs to.
26290 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
26292 dwarf2out_imported_module_or_decl_1 (tree decl
,
26294 tree lexical_block
,
26295 dw_die_ref lexical_block_die
)
26297 expanded_location xloc
;
26298 dw_die_ref imported_die
= NULL
;
26299 dw_die_ref at_import_die
;
26301 if (TREE_CODE (decl
) == IMPORTED_DECL
)
26303 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
26304 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
26308 xloc
= expand_location (input_location
);
26310 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
26312 at_import_die
= force_type_die (TREE_TYPE (decl
));
26313 /* For namespace N { typedef void T; } using N::T; base_type_die
26314 returns NULL, but DW_TAG_imported_declaration requires
26315 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
26316 if (!at_import_die
)
26318 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
26319 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
26320 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
26321 gcc_assert (at_import_die
);
26326 at_import_die
= lookup_decl_die (decl
);
26327 if (!at_import_die
)
26329 /* If we're trying to avoid duplicate debug info, we may not have
26330 emitted the member decl for this field. Emit it now. */
26331 if (TREE_CODE (decl
) == FIELD_DECL
)
26333 tree type
= DECL_CONTEXT (decl
);
26335 if (TYPE_CONTEXT (type
)
26336 && TYPE_P (TYPE_CONTEXT (type
))
26337 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
26338 DINFO_USAGE_DIR_USE
))
26340 gen_type_die_for_member (type
, decl
,
26341 get_context_die (TYPE_CONTEXT (type
)));
26343 if (TREE_CODE (decl
) == NAMELIST_DECL
)
26344 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
26345 get_context_die (DECL_CONTEXT (decl
)),
26348 at_import_die
= force_decl_die (decl
);
26352 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
26354 if (dwarf_version
>= 3 || !dwarf_strict
)
26355 imported_die
= new_die (DW_TAG_imported_module
,
26362 imported_die
= new_die (DW_TAG_imported_declaration
,
26366 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
26367 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
26368 if (debug_column_info
&& xloc
.column
)
26369 add_AT_unsigned (imported_die
, DW_AT_decl_column
, xloc
.column
);
26371 add_AT_string (imported_die
, DW_AT_name
,
26372 IDENTIFIER_POINTER (name
));
26373 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
26376 /* Output debug information for imported module or decl DECL.
26377 NAME is non-NULL name in context if the decl has been renamed.
26378 CHILD is true if decl is one of the renamed decls as part of
26379 importing whole module.
26380 IMPLICIT is set if this hook is called for an implicit import
26381 such as inline namespace. */
26384 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
26385 bool child
, bool implicit
)
26387 /* dw_die_ref at_import_die; */
26388 dw_die_ref scope_die
;
26390 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
26395 /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
26396 should be enough, for DWARF4 and older even if we emit as extension
26397 DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
26398 for the benefit of consumers unaware of DW_AT_export_symbols. */
26400 && dwarf_version
>= 5
26401 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
26402 DW_AT_export_symbols
) == 1)
26407 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
26408 We need decl DIE for reference and scope die. First, get DIE for the decl
26411 /* Get the scope die for decl context. Use comp_unit_die for global module
26412 or decl. If die is not found for non globals, force new die. */
26414 && TYPE_P (context
)
26415 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
26418 scope_die
= get_context_die (context
);
26422 /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
26423 there is nothing we can do, here. */
26424 if (dwarf_version
< 3 && dwarf_strict
)
26427 gcc_assert (scope_die
->die_child
);
26428 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
26429 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
26430 scope_die
= scope_die
->die_child
;
26433 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
26434 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
26437 /* Output debug information for namelists. */
26440 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
26442 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
26446 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
26449 gcc_assert (scope_die
!= NULL
);
26450 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
26451 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
26453 /* If there are no item_decls, we have a nondefining namelist, e.g.
26454 with USE association; hence, set DW_AT_declaration. */
26455 if (item_decls
== NULL_TREE
)
26457 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
26461 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
26463 nml_item_ref_die
= lookup_decl_die (value
);
26464 if (!nml_item_ref_die
)
26465 nml_item_ref_die
= force_decl_die (value
);
26467 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
26468 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
26474 /* Write the debugging output for DECL and return the DIE. */
26477 dwarf2out_decl (tree decl
)
26479 dw_die_ref context_die
= comp_unit_die ();
26481 switch (TREE_CODE (decl
))
26486 case FUNCTION_DECL
:
26487 /* If we're a nested function, initially use a parent of NULL; if we're
26488 a plain function, this will be fixed up in decls_for_scope. If
26489 we're a method, it will be ignored, since we already have a DIE. */
26490 if (decl_function_context (decl
)
26491 /* But if we're in terse mode, we don't care about scope. */
26492 && debug_info_level
> DINFO_LEVEL_TERSE
)
26493 context_die
= NULL
;
26497 /* For local statics lookup proper context die. */
26498 if (local_function_static (decl
))
26499 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
26501 /* If we are in terse mode, don't generate any DIEs to represent any
26502 variable declarations or definitions. */
26503 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
26508 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
26510 if (!is_fortran () && !is_ada ())
26512 if (TREE_STATIC (decl
) && decl_function_context (decl
))
26513 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
26516 case NAMESPACE_DECL
:
26517 case IMPORTED_DECL
:
26518 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
26520 if (lookup_decl_die (decl
) != NULL
)
26525 /* Don't emit stubs for types unless they are needed by other DIEs. */
26526 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
26529 /* Don't bother trying to generate any DIEs to represent any of the
26530 normal built-in types for the language we are compiling. */
26531 if (DECL_IS_BUILTIN (decl
))
26534 /* If we are in terse mode, don't generate any DIEs for types. */
26535 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
26538 /* If we're a function-scope tag, initially use a parent of NULL;
26539 this will be fixed up in decls_for_scope. */
26540 if (decl_function_context (decl
))
26541 context_die
= NULL
;
26545 case NAMELIST_DECL
:
26552 gen_decl_die (decl
, NULL
, NULL
, context_die
);
26556 dw_die_ref die
= lookup_decl_die (decl
);
26562 /* Write the debugging output for DECL. */
26565 dwarf2out_function_decl (tree decl
)
26567 dwarf2out_decl (decl
);
26568 call_arg_locations
= NULL
;
26569 call_arg_loc_last
= NULL
;
26570 call_site_count
= -1;
26571 tail_call_site_count
= -1;
26572 decl_loc_table
->empty ();
26573 cached_dw_loc_list_table
->empty ();
26576 /* Output a marker (i.e. a label) for the beginning of the generated code for
26577 a lexical block. */
26580 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
26581 unsigned int blocknum
)
26583 switch_to_section (current_function_section ());
26584 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
26587 /* Output a marker (i.e. a label) for the end of the generated code for a
26591 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
26593 switch_to_section (current_function_section ());
26594 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
26597 /* Returns nonzero if it is appropriate not to emit any debugging
26598 information for BLOCK, because it doesn't contain any instructions.
26600 Don't allow this for blocks with nested functions or local classes
26601 as we would end up with orphans, and in the presence of scheduling
26602 we may end up calling them anyway. */
26605 dwarf2out_ignore_block (const_tree block
)
26610 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
26611 if (TREE_CODE (decl
) == FUNCTION_DECL
26612 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
26614 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
26616 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
26617 if (TREE_CODE (decl
) == FUNCTION_DECL
26618 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
26625 /* Hash table routines for file_hash. */
26628 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
26630 return filename_cmp (p1
->filename
, p2
) == 0;
26634 dwarf_file_hasher::hash (dwarf_file_data
*p
)
26636 return htab_hash_string (p
->filename
);
26639 /* Lookup FILE_NAME (in the list of filenames that we know about here in
26640 dwarf2out.c) and return its "index". The index of each (known) filename is
26641 just a unique number which is associated with only that one filename. We
26642 need such numbers for the sake of generating labels (in the .debug_sfnames
26643 section) and references to those files numbers (in the .debug_srcinfo
26644 and .debug_macinfo sections). If the filename given as an argument is not
26645 found in our current list, add it to the list and assign it the next
26646 available unique index number. */
26648 static struct dwarf_file_data
*
26649 lookup_filename (const char *file_name
)
26651 struct dwarf_file_data
* created
;
26656 dwarf_file_data
**slot
26657 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
26662 created
= ggc_alloc
<dwarf_file_data
> ();
26663 created
->filename
= file_name
;
26664 created
->emitted_number
= 0;
26669 /* If the assembler will construct the file table, then translate the compiler
26670 internal file table number into the assembler file table number, and emit
26671 a .file directive if we haven't already emitted one yet. The file table
26672 numbers are different because we prune debug info for unused variables and
26673 types, which may include filenames. */
26676 maybe_emit_file (struct dwarf_file_data
* fd
)
26678 if (! fd
->emitted_number
)
26680 if (last_emitted_file
)
26681 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
26683 fd
->emitted_number
= 1;
26684 last_emitted_file
= fd
;
26686 if (output_asm_line_debug_info ())
26688 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
26689 output_quoted_string (asm_out_file
,
26690 remap_debug_filename (fd
->filename
));
26691 fputc ('\n', asm_out_file
);
26695 return fd
->emitted_number
;
26698 /* Schedule generation of a DW_AT_const_value attribute to DIE.
26699 That generation should happen after function debug info has been
26700 generated. The value of the attribute is the constant value of ARG. */
26703 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
26705 die_arg_entry entry
;
26710 gcc_assert (early_dwarf
);
26712 if (!tmpl_value_parm_die_table
)
26713 vec_alloc (tmpl_value_parm_die_table
, 32);
26717 vec_safe_push (tmpl_value_parm_die_table
, entry
);
26720 /* Return TRUE if T is an instance of generic type, FALSE
26724 generic_type_p (tree t
)
26726 if (t
== NULL_TREE
|| !TYPE_P (t
))
26728 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
26731 /* Schedule the generation of the generic parameter dies for the
26732 instance of generic type T. The proper generation itself is later
26733 done by gen_scheduled_generic_parms_dies. */
26736 schedule_generic_params_dies_gen (tree t
)
26738 if (!generic_type_p (t
))
26741 gcc_assert (early_dwarf
);
26743 if (!generic_type_instances
)
26744 vec_alloc (generic_type_instances
, 256);
26746 vec_safe_push (generic_type_instances
, t
);
26749 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
26750 by append_entry_to_tmpl_value_parm_die_table. This function must
26751 be called after function DIEs have been generated. */
26754 gen_remaining_tmpl_value_param_die_attribute (void)
26756 if (tmpl_value_parm_die_table
)
26761 /* We do this in two phases - first get the cases we can
26762 handle during early-finish, preserving those we cannot
26763 (containing symbolic constants where we don't yet know
26764 whether we are going to output the referenced symbols).
26765 For those we try again at late-finish. */
26767 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
26769 if (!e
->die
->removed
26770 && !tree_add_const_value_attribute (e
->die
, e
->arg
))
26772 dw_loc_descr_ref loc
= NULL
;
26774 && (dwarf_version
>= 5 || !dwarf_strict
))
26775 loc
= loc_descriptor_from_tree (e
->arg
, 2, NULL
);
26777 add_AT_loc (e
->die
, DW_AT_location
, loc
);
26779 (*tmpl_value_parm_die_table
)[j
++] = *e
;
26782 tmpl_value_parm_die_table
->truncate (j
);
26786 /* Generate generic parameters DIEs for instances of generic types
26787 that have been previously scheduled by
26788 schedule_generic_params_dies_gen. This function must be called
26789 after all the types of the CU have been laid out. */
26792 gen_scheduled_generic_parms_dies (void)
26797 if (!generic_type_instances
)
26800 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
26801 if (COMPLETE_TYPE_P (t
))
26802 gen_generic_params_dies (t
);
26804 generic_type_instances
= NULL
;
26808 /* Replace DW_AT_name for the decl with name. */
26811 dwarf2out_set_name (tree decl
, tree name
)
26814 dw_attr_node
*attr
;
26817 die
= TYPE_SYMTAB_DIE (decl
);
26821 dname
= dwarf2_name (name
, 0);
26825 attr
= get_AT (die
, DW_AT_name
);
26828 struct indirect_string_node
*node
;
26830 node
= find_AT_string (dname
);
26831 /* replace the string. */
26832 attr
->dw_attr_val
.v
.val_str
= node
;
26836 add_name_attribute (die
, dname
);
26839 /* True if before or during processing of the first function being emitted. */
26840 static bool in_first_function_p
= true;
26841 /* True if loc_note during dwarf2out_var_location call might still be
26842 before first real instruction at address equal to .Ltext0. */
26843 static bool maybe_at_text_label_p
= true;
26844 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
26845 static unsigned int first_loclabel_num_not_at_text_label
;
26847 /* Look ahead for a real insn, or for a begin stmt marker. */
26850 dwarf2out_next_real_insn (rtx_insn
*loc_note
)
26852 rtx_insn
*next_real
= NEXT_INSN (loc_note
);
26855 if (INSN_P (next_real
))
26858 next_real
= NEXT_INSN (next_real
);
26863 /* Called by the final INSN scan whenever we see a var location. We
26864 use it to drop labels in the right places, and throw the location in
26865 our lookup table. */
26868 dwarf2out_var_location (rtx_insn
*loc_note
)
26870 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
26871 struct var_loc_node
*newloc
;
26872 rtx_insn
*next_real
, *next_note
;
26873 rtx_insn
*call_insn
= NULL
;
26874 static const char *last_label
;
26875 static const char *last_postcall_label
;
26876 static bool last_in_cold_section_p
;
26877 static rtx_insn
*expected_next_loc_note
;
26880 var_loc_view view
= 0;
26882 if (!NOTE_P (loc_note
))
26884 if (CALL_P (loc_note
))
26886 RESET_NEXT_VIEW (cur_line_info_table
->view
);
26888 if (SIBLING_CALL_P (loc_note
))
26889 tail_call_site_count
++;
26890 if (optimize
== 0 && !flag_var_tracking
)
26892 /* When the var-tracking pass is not running, there is no note
26893 for indirect calls whose target is compile-time known. In this
26894 case, process such calls specifically so that we generate call
26895 sites for them anyway. */
26896 rtx x
= PATTERN (loc_note
);
26897 if (GET_CODE (x
) == PARALLEL
)
26898 x
= XVECEXP (x
, 0, 0);
26899 if (GET_CODE (x
) == SET
)
26901 if (GET_CODE (x
) == CALL
)
26904 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
26905 || !SYMBOL_REF_DECL (XEXP (x
, 0))
26906 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
26909 call_insn
= loc_note
;
26913 next_real
= dwarf2out_next_real_insn (call_insn
);
26915 cached_next_real_insn
= NULL
;
26920 else if (!debug_variable_location_views
)
26921 gcc_unreachable ();
26922 else if (JUMP_TABLE_DATA_P (loc_note
))
26923 RESET_NEXT_VIEW (cur_line_info_table
->view
);
26924 else if (GET_CODE (loc_note
) == USE
26925 || GET_CODE (loc_note
) == CLOBBER
26926 || GET_CODE (loc_note
) == ASM_INPUT
26927 || asm_noperands (loc_note
) >= 0)
26929 else if (get_attr_min_length (loc_note
) > 0)
26930 RESET_NEXT_VIEW (cur_line_info_table
->view
);
26935 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
26936 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
26939 /* Optimize processing a large consecutive sequence of location
26940 notes so we don't spend too much time in next_real_insn. If the
26941 next insn is another location note, remember the next_real_insn
26942 calculation for next time. */
26943 next_real
= cached_next_real_insn
;
26946 if (expected_next_loc_note
!= loc_note
)
26950 next_note
= NEXT_INSN (loc_note
);
26952 || next_note
->deleted ()
26953 || ! NOTE_P (next_note
)
26954 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
26955 && NOTE_KIND (next_note
) != NOTE_INSN_BEGIN_STMT
26956 && NOTE_KIND (next_note
) != NOTE_INSN_INLINE_ENTRY
26957 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
26961 next_real
= dwarf2out_next_real_insn (loc_note
);
26965 expected_next_loc_note
= next_note
;
26966 cached_next_real_insn
= next_real
;
26969 cached_next_real_insn
= NULL
;
26971 /* If there are no instructions which would be affected by this note,
26972 don't do anything. */
26974 && next_real
== NULL_RTX
26975 && !NOTE_DURING_CALL_P (loc_note
))
26980 if (next_real
== NULL_RTX
)
26981 next_real
= get_last_insn ();
26983 /* If there were any real insns between note we processed last time
26984 and this note (or if it is the first note), clear
26985 last_{,postcall_}label so that they are not reused this time. */
26986 if (last_var_location_insn
== NULL_RTX
26987 || last_var_location_insn
!= next_real
26988 || last_in_cold_section_p
!= in_cold_section_p
)
26991 last_postcall_label
= NULL
;
26997 = NOTE_DURING_CALL_P (loc_note
) ? last_postcall_label
: last_label
;
26998 view
= cur_line_info_table
->view
;
26999 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
27000 newloc
= add_var_loc_to_decl (decl
, loc_note
, label
, view
);
27001 if (newloc
== NULL
)
27010 /* If there were no real insns between note we processed last time
27011 and this note, use the label we emitted last time. Otherwise
27012 create a new label and emit it. */
27013 if (last_label
== NULL
)
27015 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
27016 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
27018 last_label
= ggc_strdup (loclabel
);
27019 /* See if loclabel might be equal to .Ltext0. If yes,
27020 bump first_loclabel_num_not_at_text_label. */
27021 if (!have_multiple_function_sections
27022 && in_first_function_p
27023 && maybe_at_text_label_p
)
27025 static rtx_insn
*last_start
;
27027 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
27028 if (insn
== last_start
)
27030 else if (!NONDEBUG_INSN_P (insn
))
27034 rtx body
= PATTERN (insn
);
27035 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
27037 /* Inline asm could occupy zero bytes. */
27038 else if (GET_CODE (body
) == ASM_INPUT
27039 || asm_noperands (body
) >= 0)
27041 #ifdef HAVE_ATTR_length /* ??? We don't include insn-attr.h. */
27042 else if (HAVE_ATTR_length
&& get_attr_min_length (insn
) == 0)
27047 /* Assume insn has non-zero length. */
27048 maybe_at_text_label_p
= false;
27052 if (maybe_at_text_label_p
)
27054 last_start
= loc_note
;
27055 first_loclabel_num_not_at_text_label
= loclabel_num
;
27060 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
27061 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
27065 struct call_arg_loc_node
*ca_loc
27066 = ggc_cleared_alloc
<call_arg_loc_node
> ();
27068 = loc_note
!= NULL_RTX
? prev_real_insn (loc_note
) : call_insn
;
27070 ca_loc
->call_arg_loc_note
= loc_note
;
27071 ca_loc
->next
= NULL
;
27072 ca_loc
->label
= last_label
;
27075 || (NONJUMP_INSN_P (prev
)
27076 && GET_CODE (PATTERN (prev
)) == SEQUENCE
27077 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
27078 if (!CALL_P (prev
))
27079 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
27080 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
27082 /* Look for a SYMBOL_REF in the "prev" instruction. */
27083 rtx x
= get_call_rtx_from (PATTERN (prev
));
27086 /* Try to get the call symbol, if any. */
27087 if (MEM_P (XEXP (x
, 0)))
27089 /* First, look for a memory access to a symbol_ref. */
27090 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
27091 && SYMBOL_REF_DECL (XEXP (x
, 0))
27092 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
27093 ca_loc
->symbol_ref
= XEXP (x
, 0);
27094 /* Otherwise, look at a compile-time known user-level function
27098 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
27099 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
27102 ca_loc
->block
= insn_scope (prev
);
27103 if (call_arg_locations
)
27104 call_arg_loc_last
->next
= ca_loc
;
27106 call_arg_locations
= ca_loc
;
27107 call_arg_loc_last
= ca_loc
;
27109 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
27111 newloc
->label
= last_label
;
27112 newloc
->view
= view
;
27116 if (!last_postcall_label
)
27118 sprintf (loclabel
, "%s-1", last_label
);
27119 last_postcall_label
= ggc_strdup (loclabel
);
27121 newloc
->label
= last_postcall_label
;
27122 newloc
->view
= view
;
27125 if (var_loc_p
&& flag_debug_asm
)
27127 const char *name
, *sep
, *patstr
;
27128 if (decl
&& DECL_NAME (decl
))
27129 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
27132 if (NOTE_VAR_LOCATION_LOC (loc_note
))
27135 patstr
= str_pattern_slim (NOTE_VAR_LOCATION_LOC (loc_note
));
27142 fprintf (asm_out_file
, "\t%s DEBUG %s%s%s\n", ASM_COMMENT_START
,
27143 name
, sep
, patstr
);
27146 last_var_location_insn
= next_real
;
27147 last_in_cold_section_p
= in_cold_section_p
;
27150 /* Check whether BLOCK, a lexical block, is nested within OUTER, or is
27151 OUTER itself. If BOTHWAYS, check not only that BLOCK can reach
27152 OUTER through BLOCK_SUPERCONTEXT links, but also that there is a
27153 path from OUTER to BLOCK through BLOCK_SUBBLOCKs and
27154 BLOCK_FRAGMENT_ORIGIN links. */
27156 block_within_block_p (tree block
, tree outer
, bool bothways
)
27158 if (block
== outer
)
27161 /* Quickly check that OUTER is up BLOCK's supercontext chain. */
27162 for (tree context
= BLOCK_SUPERCONTEXT (block
);
27164 context
= BLOCK_SUPERCONTEXT (context
))
27165 if (!context
|| TREE_CODE (context
) != BLOCK
)
27171 /* Now check that each block is actually referenced by its
27173 for (tree context
= BLOCK_SUPERCONTEXT (block
); ;
27174 context
= BLOCK_SUPERCONTEXT (context
))
27176 if (BLOCK_FRAGMENT_ORIGIN (context
))
27178 gcc_assert (!BLOCK_SUBBLOCKS (context
));
27179 context
= BLOCK_FRAGMENT_ORIGIN (context
);
27181 for (tree sub
= BLOCK_SUBBLOCKS (context
);
27183 sub
= BLOCK_CHAIN (sub
))
27186 if (context
== outer
)
27193 /* Called during final while assembling the marker of the entry point
27194 for an inlined function. */
27197 dwarf2out_inline_entry (tree block
)
27199 /* If we can't represent it, don't bother. */
27200 if (!(dwarf_version
>= 3 || !dwarf_strict
))
27203 gcc_assert (DECL_P (block_ultimate_origin (block
)));
27205 /* Sanity check the block tree. This would catch a case in which
27206 BLOCK got removed from the tree reachable from the outermost
27207 lexical block, but got retained in markers. It would still link
27208 back to its parents, but some ancestor would be missing a link
27209 down the path to the sub BLOCK. If the block got removed, its
27210 BLOCK_NUMBER will not be a usable value. */
27212 gcc_assert (block_within_block_p (block
,
27213 DECL_INITIAL (current_function_decl
),
27216 gcc_assert (inlined_function_outer_scope_p (block
));
27217 gcc_assert (!BLOCK_DIE (block
));
27219 if (BLOCK_FRAGMENT_ORIGIN (block
))
27220 block
= BLOCK_FRAGMENT_ORIGIN (block
);
27221 /* Can the entry point ever not be at the beginning of an
27222 unfragmented lexical block? */
27223 else if (!(BLOCK_FRAGMENT_CHAIN (block
)
27224 || (cur_line_info_table
27225 && !ZERO_VIEW_P (cur_line_info_table
->view
))))
27228 if (!inline_entry_data_table
)
27229 inline_entry_data_table
27230 = hash_table
<inline_entry_data_hasher
>::create_ggc (10);
27233 inline_entry_data
**iedp
27234 = inline_entry_data_table
->find_slot_with_hash (block
,
27235 htab_hash_pointer (block
),
27238 /* ??? Ideally, we'd record all entry points for the same inlined
27239 function (some may have been duplicated by e.g. unrolling), but
27240 we have no way to represent that ATM. */
27243 inline_entry_data
*ied
= *iedp
= ggc_cleared_alloc
<inline_entry_data
> ();
27244 ied
->block
= block
;
27245 ied
->label_pfx
= BLOCK_INLINE_ENTRY_LABEL
;
27246 ied
->label_num
= BLOCK_NUMBER (block
);
27247 if (cur_line_info_table
)
27248 ied
->view
= cur_line_info_table
->view
;
27250 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
27252 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_INLINE_ENTRY_LABEL
,
27253 BLOCK_NUMBER (block
));
27254 ASM_OUTPUT_LABEL (asm_out_file
, label
);
27257 /* Called from finalize_size_functions for size functions so that their body
27258 can be encoded in the debug info to describe the layout of variable-length
27262 dwarf2out_size_function (tree decl
)
27264 function_to_dwarf_procedure (decl
);
27267 /* Note in one location list that text section has changed. */
27270 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
27272 var_loc_list
*list
= *slot
;
27274 list
->last_before_switch
27275 = list
->last
->next
? list
->last
->next
: list
->last
;
27279 /* Note in all location lists that text section has changed. */
27282 var_location_switch_text_section (void)
27284 if (decl_loc_table
== NULL
)
27287 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
27290 /* Create a new line number table. */
27292 static dw_line_info_table
*
27293 new_line_info_table (void)
27295 dw_line_info_table
*table
;
27297 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
27298 table
->file_num
= 1;
27299 table
->line_num
= 1;
27300 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
27301 RESET_NEXT_VIEW (table
->view
);
27306 /* Lookup the "current" table into which we emit line info, so
27307 that we don't have to do it for every source line. */
27310 set_cur_line_info_table (section
*sec
)
27312 dw_line_info_table
*table
;
27314 if (sec
== text_section
)
27315 table
= text_section_line_info
;
27316 else if (sec
== cold_text_section
)
27318 table
= cold_text_section_line_info
;
27321 cold_text_section_line_info
= table
= new_line_info_table ();
27322 table
->end_label
= cold_end_label
;
27327 const char *end_label
;
27329 if (crtl
->has_bb_partition
)
27331 if (in_cold_section_p
)
27332 end_label
= crtl
->subsections
.cold_section_end_label
;
27334 end_label
= crtl
->subsections
.hot_section_end_label
;
27338 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
27339 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
27340 current_function_funcdef_no
);
27341 end_label
= ggc_strdup (label
);
27344 table
= new_line_info_table ();
27345 table
->end_label
= end_label
;
27347 vec_safe_push (separate_line_info
, table
);
27350 if (output_asm_line_debug_info ())
27351 table
->is_stmt
= (cur_line_info_table
27352 ? cur_line_info_table
->is_stmt
27353 : DWARF_LINE_DEFAULT_IS_STMT_START
);
27354 cur_line_info_table
= table
;
27358 /* We need to reset the locations at the beginning of each
27359 function. We can't do this in the end_function hook, because the
27360 declarations that use the locations won't have been output when
27361 that hook is called. Also compute have_multiple_function_sections here. */
27364 dwarf2out_begin_function (tree fun
)
27366 section
*sec
= function_section (fun
);
27368 if (sec
!= text_section
)
27369 have_multiple_function_sections
= true;
27371 if (crtl
->has_bb_partition
&& !cold_text_section
)
27373 gcc_assert (current_function_decl
== fun
);
27374 cold_text_section
= unlikely_text_section ();
27375 switch_to_section (cold_text_section
);
27376 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
27377 switch_to_section (sec
);
27380 dwarf2out_note_section_used ();
27381 call_site_count
= 0;
27382 tail_call_site_count
= 0;
27384 set_cur_line_info_table (sec
);
27387 /* Helper function of dwarf2out_end_function, called only after emitting
27388 the very first function into assembly. Check if some .debug_loc range
27389 might end with a .LVL* label that could be equal to .Ltext0.
27390 In that case we must force using absolute addresses in .debug_loc ranges,
27391 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
27392 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
27394 Set have_multiple_function_sections to true in that case and
27395 terminate htab traversal. */
27398 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
27400 var_loc_list
*entry
= *slot
;
27401 struct var_loc_node
*node
;
27403 node
= entry
->first
;
27404 if (node
&& node
->next
&& node
->next
->label
)
27407 const char *label
= node
->next
->label
;
27408 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
27410 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
27412 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
27413 if (strcmp (label
, loclabel
) == 0)
27415 have_multiple_function_sections
= true;
27423 /* Hook called after emitting a function into assembly.
27424 This does something only for the very first function emitted. */
27427 dwarf2out_end_function (unsigned int)
27429 if (in_first_function_p
27430 && !have_multiple_function_sections
27431 && first_loclabel_num_not_at_text_label
27433 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
27434 in_first_function_p
= false;
27435 maybe_at_text_label_p
= false;
27438 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
27439 front-ends register a translation unit even before dwarf2out_init is
27441 static tree main_translation_unit
= NULL_TREE
;
27443 /* Hook called by front-ends after they built their main translation unit.
27444 Associate comp_unit_die to UNIT. */
27447 dwarf2out_register_main_translation_unit (tree unit
)
27449 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
27450 && main_translation_unit
== NULL_TREE
);
27451 main_translation_unit
= unit
;
27452 /* If dwarf2out_init has not been called yet, it will perform the association
27453 itself looking at main_translation_unit. */
27454 if (decl_die_table
!= NULL
)
27455 equate_decl_number_to_die (unit
, comp_unit_die ());
27458 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
27461 push_dw_line_info_entry (dw_line_info_table
*table
,
27462 enum dw_line_info_opcode opcode
, unsigned int val
)
27464 dw_line_info_entry e
;
27467 vec_safe_push (table
->entries
, e
);
27470 /* Output a label to mark the beginning of a source code line entry
27471 and record information relating to this source line, in
27472 'line_info_table' for later output of the .debug_line section. */
27473 /* ??? The discriminator parameter ought to be unsigned. */
27476 dwarf2out_source_line (unsigned int line
, unsigned int column
,
27477 const char *filename
,
27478 int discriminator
, bool is_stmt
)
27480 unsigned int file_num
;
27481 dw_line_info_table
*table
;
27483 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
27486 /* The discriminator column was added in dwarf4. Simplify the below
27487 by simply removing it if we're not supposed to output it. */
27488 if (dwarf_version
< 4 && dwarf_strict
)
27491 if (!debug_column_info
)
27494 table
= cur_line_info_table
;
27495 file_num
= maybe_emit_file (lookup_filename (filename
));
27497 /* ??? TODO: Elide duplicate line number entries. Traditionally,
27498 the debugger has used the second (possibly duplicate) line number
27499 at the beginning of the function to mark the end of the prologue.
27500 We could eliminate any other duplicates within the function. For
27501 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
27502 that second line number entry. */
27503 /* Recall that this end-of-prologue indication is *not* the same thing
27504 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
27505 to which the hook corresponds, follows the last insn that was
27506 emitted by gen_prologue. What we need is to precede the first insn
27507 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
27508 insn that corresponds to something the user wrote. These may be
27509 very different locations once scheduling is enabled. */
27511 if (0 && file_num
== table
->file_num
27512 && line
== table
->line_num
27513 && column
== table
->column_num
27514 && discriminator
== table
->discrim_num
27515 && is_stmt
== table
->is_stmt
)
27518 switch_to_section (current_function_section ());
27520 /* If requested, emit something human-readable. */
27521 if (flag_debug_asm
)
27523 if (debug_column_info
)
27524 fprintf (asm_out_file
, "\t%s %s:%d:%d\n", ASM_COMMENT_START
,
27525 filename
, line
, column
);
27527 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
27531 if (output_asm_line_debug_info ())
27533 /* Emit the .loc directive understood by GNU as. */
27534 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
27535 file_num, line, is_stmt, discriminator */
27536 fputs ("\t.loc ", asm_out_file
);
27537 fprint_ul (asm_out_file
, file_num
);
27538 putc (' ', asm_out_file
);
27539 fprint_ul (asm_out_file
, line
);
27540 putc (' ', asm_out_file
);
27541 fprint_ul (asm_out_file
, column
);
27543 if (is_stmt
!= table
->is_stmt
)
27545 fputs (" is_stmt ", asm_out_file
);
27546 putc (is_stmt
? '1' : '0', asm_out_file
);
27548 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
27550 gcc_assert (discriminator
> 0);
27551 fputs (" discriminator ", asm_out_file
);
27552 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
27554 if (debug_variable_location_views
)
27556 static var_loc_view lvugid
;
27559 gcc_assert (!zero_view_p
);
27560 zero_view_p
= BITMAP_GGC_ALLOC ();
27561 bitmap_set_bit (zero_view_p
, 0);
27563 if (!RESETTING_VIEW_P (table
->view
))
27565 /* When we're using the assembler to compute view
27566 numbers, we output symbolic labels after "view" in
27567 .loc directives, and the assembler will set them for
27568 us, so that we can refer to the view numbers in
27569 location lists. The only exceptions are when we know
27570 a view will be zero: "-0" is a forced reset, used
27571 e.g. in the beginning of functions, whereas "0" tells
27572 the assembler to check that there was a PC change
27573 since the previous view, in a way that implicitly
27574 resets the next view. */
27575 fputs (" view ", asm_out_file
);
27576 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
27577 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", table
->view
);
27578 assemble_name (asm_out_file
, label
);
27579 table
->view
= ++lvugid
;
27583 if (!table
->in_use
)
27584 fputs (" view -0", asm_out_file
);
27586 fputs (" view 0", asm_out_file
);
27587 /* Mark the present view as a zero view. Earlier debug
27588 binds may have already added its id to loclists to be
27589 emitted later, so we can't reuse the id for something
27590 else. However, it's good to know whether a view is
27591 known to be zero, because then we may be able to
27592 optimize out locviews that are all zeros, so take
27593 note of it in zero_view_p. */
27594 bitmap_set_bit (zero_view_p
, lvugid
);
27595 table
->view
= ++lvugid
;
27598 putc ('\n', asm_out_file
);
27602 unsigned int label_num
= ++line_info_label_num
;
27604 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
27606 if (debug_variable_location_views
&& table
->view
)
27607 push_dw_line_info_entry (table
, LI_adv_address
, label_num
);
27609 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
27610 if (debug_variable_location_views
)
27612 if (flag_debug_asm
)
27613 fprintf (asm_out_file
, "\t%s view %s%d\n",
27615 table
->in_use
? "" : "-",
27619 if (file_num
!= table
->file_num
)
27620 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
27621 if (discriminator
!= table
->discrim_num
)
27622 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
27623 if (is_stmt
!= table
->is_stmt
)
27624 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
27625 push_dw_line_info_entry (table
, LI_set_line
, line
);
27626 if (debug_column_info
)
27627 push_dw_line_info_entry (table
, LI_set_column
, column
);
27630 table
->file_num
= file_num
;
27631 table
->line_num
= line
;
27632 table
->column_num
= column
;
27633 table
->discrim_num
= discriminator
;
27634 table
->is_stmt
= is_stmt
;
27635 table
->in_use
= true;
27638 /* Record the beginning of a new source file. */
27641 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
27643 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
27646 e
.code
= DW_MACINFO_start_file
;
27648 e
.info
= ggc_strdup (filename
);
27649 vec_safe_push (macinfo_table
, e
);
27653 /* Record the end of a source file. */
27656 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
27658 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
27661 e
.code
= DW_MACINFO_end_file
;
27664 vec_safe_push (macinfo_table
, e
);
27668 /* Called from debug_define in toplev.c. The `buffer' parameter contains
27669 the tail part of the directive line, i.e. the part which is past the
27670 initial whitespace, #, whitespace, directive-name, whitespace part. */
27673 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
27674 const char *buffer ATTRIBUTE_UNUSED
)
27676 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
27679 /* Insert a dummy first entry to be able to optimize the whole
27680 predefined macro block using DW_MACRO_import. */
27681 if (macinfo_table
->is_empty () && lineno
<= 1)
27686 vec_safe_push (macinfo_table
, e
);
27688 e
.code
= DW_MACINFO_define
;
27690 e
.info
= ggc_strdup (buffer
);
27691 vec_safe_push (macinfo_table
, e
);
27695 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
27696 the tail part of the directive line, i.e. the part which is past the
27697 initial whitespace, #, whitespace, directive-name, whitespace part. */
27700 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
27701 const char *buffer ATTRIBUTE_UNUSED
)
27703 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
27706 /* Insert a dummy first entry to be able to optimize the whole
27707 predefined macro block using DW_MACRO_import. */
27708 if (macinfo_table
->is_empty () && lineno
<= 1)
27713 vec_safe_push (macinfo_table
, e
);
27715 e
.code
= DW_MACINFO_undef
;
27717 e
.info
= ggc_strdup (buffer
);
27718 vec_safe_push (macinfo_table
, e
);
27722 /* Helpers to manipulate hash table of CUs. */
27724 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
27726 static inline hashval_t
hash (const macinfo_entry
*);
27727 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
27731 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
27733 return htab_hash_string (entry
->info
);
27737 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
27738 const macinfo_entry
*entry2
)
27740 return !strcmp (entry1
->info
, entry2
->info
);
27743 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
27745 /* Output a single .debug_macinfo entry. */
27748 output_macinfo_op (macinfo_entry
*ref
)
27752 struct indirect_string_node
*node
;
27753 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
27754 struct dwarf_file_data
*fd
;
27758 case DW_MACINFO_start_file
:
27759 fd
= lookup_filename (ref
->info
);
27760 file_num
= maybe_emit_file (fd
);
27761 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
27762 dw2_asm_output_data_uleb128 (ref
->lineno
,
27763 "Included from line number %lu",
27764 (unsigned long) ref
->lineno
);
27765 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
27767 case DW_MACINFO_end_file
:
27768 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
27770 case DW_MACINFO_define
:
27771 case DW_MACINFO_undef
:
27772 len
= strlen (ref
->info
) + 1;
27774 && len
> DWARF_OFFSET_SIZE
27775 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
27776 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
27778 ref
->code
= ref
->code
== DW_MACINFO_define
27779 ? DW_MACRO_define_strp
: DW_MACRO_undef_strp
;
27780 output_macinfo_op (ref
);
27783 dw2_asm_output_data (1, ref
->code
,
27784 ref
->code
== DW_MACINFO_define
27785 ? "Define macro" : "Undefine macro");
27786 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
27787 (unsigned long) ref
->lineno
);
27788 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
27790 case DW_MACRO_define_strp
:
27791 case DW_MACRO_undef_strp
:
27792 node
= find_AT_string (ref
->info
);
27794 && (node
->form
== DW_FORM_strp
27795 || node
->form
== DW_FORM_GNU_str_index
));
27796 dw2_asm_output_data (1, ref
->code
,
27797 ref
->code
== DW_MACRO_define_strp
27798 ? "Define macro strp"
27799 : "Undefine macro strp");
27800 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
27801 (unsigned long) ref
->lineno
);
27802 if (node
->form
== DW_FORM_strp
)
27803 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
27804 debug_str_section
, "The macro: \"%s\"",
27807 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
27810 case DW_MACRO_import
:
27811 dw2_asm_output_data (1, ref
->code
, "Import");
27812 ASM_GENERATE_INTERNAL_LABEL (label
,
27813 DEBUG_MACRO_SECTION_LABEL
,
27814 ref
->lineno
+ macinfo_label_base
);
27815 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
27818 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
27819 ASM_COMMENT_START
, (unsigned long) ref
->code
);
27824 /* Attempt to make a sequence of define/undef macinfo ops shareable with
27825 other compilation unit .debug_macinfo sections. IDX is the first
27826 index of a define/undef, return the number of ops that should be
27827 emitted in a comdat .debug_macinfo section and emit
27828 a DW_MACRO_import entry referencing it.
27829 If the define/undef entry should be emitted normally, return 0. */
27832 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
27833 macinfo_hash_type
**macinfo_htab
)
27835 macinfo_entry
*first
, *second
, *cur
, *inc
;
27836 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
27837 unsigned char checksum
[16];
27838 struct md5_ctx ctx
;
27839 char *grp_name
, *tail
;
27841 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
27842 macinfo_entry
**slot
;
27844 first
= &(*macinfo_table
)[idx
];
27845 second
= &(*macinfo_table
)[idx
+ 1];
27847 /* Optimize only if there are at least two consecutive define/undef ops,
27848 and either all of them are before first DW_MACINFO_start_file
27849 with lineno {0,1} (i.e. predefined macro block), or all of them are
27850 in some included header file. */
27851 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
27853 if (vec_safe_is_empty (files
))
27855 if (first
->lineno
> 1 || second
->lineno
> 1)
27858 else if (first
->lineno
== 0)
27861 /* Find the last define/undef entry that can be grouped together
27862 with first and at the same time compute md5 checksum of their
27863 codes, linenumbers and strings. */
27864 md5_init_ctx (&ctx
);
27865 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
27866 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
27868 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
27872 unsigned char code
= cur
->code
;
27873 md5_process_bytes (&code
, 1, &ctx
);
27874 checksum_uleb128 (cur
->lineno
, &ctx
);
27875 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
27877 md5_finish_ctx (&ctx
, checksum
);
27880 /* From the containing include filename (if any) pick up just
27881 usable characters from its basename. */
27882 if (vec_safe_is_empty (files
))
27885 base
= lbasename (files
->last ().info
);
27886 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
27887 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
27888 encoded_filename_len
++;
27889 /* Count . at the end. */
27890 if (encoded_filename_len
)
27891 encoded_filename_len
++;
27893 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
27894 linebuf_len
= strlen (linebuf
);
27896 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
27897 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
27899 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
27900 tail
= grp_name
+ 4;
27901 if (encoded_filename_len
)
27903 for (i
= 0; base
[i
]; i
++)
27904 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
27908 memcpy (tail
, linebuf
, linebuf_len
);
27909 tail
+= linebuf_len
;
27911 for (i
= 0; i
< 16; i
++)
27912 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
27914 /* Construct a macinfo_entry for DW_MACRO_import
27915 in the empty vector entry before the first define/undef. */
27916 inc
= &(*macinfo_table
)[idx
- 1];
27917 inc
->code
= DW_MACRO_import
;
27919 inc
->info
= ggc_strdup (grp_name
);
27920 if (!*macinfo_htab
)
27921 *macinfo_htab
= new macinfo_hash_type (10);
27922 /* Avoid emitting duplicates. */
27923 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
27928 /* If such an entry has been used before, just emit
27929 a DW_MACRO_import op. */
27931 output_macinfo_op (inc
);
27932 /* And clear all macinfo_entry in the range to avoid emitting them
27933 in the second pass. */
27934 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
27943 inc
->lineno
= (*macinfo_htab
)->elements ();
27944 output_macinfo_op (inc
);
27949 /* Save any strings needed by the macinfo table in the debug str
27950 table. All strings must be collected into the table by the time
27951 index_string is called. */
27954 save_macinfo_strings (void)
27958 macinfo_entry
*ref
;
27960 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
27964 /* Match the logic in output_macinfo_op to decide on
27965 indirect strings. */
27966 case DW_MACINFO_define
:
27967 case DW_MACINFO_undef
:
27968 len
= strlen (ref
->info
) + 1;
27970 && len
> DWARF_OFFSET_SIZE
27971 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
27972 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
27973 set_indirect_string (find_AT_string (ref
->info
));
27975 case DW_MACRO_define_strp
:
27976 case DW_MACRO_undef_strp
:
27977 set_indirect_string (find_AT_string (ref
->info
));
27985 /* Output macinfo section(s). */
27988 output_macinfo (const char *debug_line_label
, bool early_lto_debug
)
27991 unsigned long length
= vec_safe_length (macinfo_table
);
27992 macinfo_entry
*ref
;
27993 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
27994 macinfo_hash_type
*macinfo_htab
= NULL
;
27995 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
28000 /* output_macinfo* uses these interchangeably. */
28001 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_define
28002 && (int) DW_MACINFO_undef
== (int) DW_MACRO_undef
28003 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_start_file
28004 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_end_file
);
28006 /* AIX Assembler inserts the length, so adjust the reference to match the
28007 offset expected by debuggers. */
28008 strcpy (dl_section_ref
, debug_line_label
);
28009 if (XCOFF_DEBUGGING_INFO
)
28010 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
28012 /* For .debug_macro emit the section header. */
28013 if (!dwarf_strict
|| dwarf_version
>= 5)
28015 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
28016 "DWARF macro version number");
28017 if (DWARF_OFFSET_SIZE
== 8)
28018 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
28020 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
28021 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_line_label
,
28022 debug_line_section
, NULL
);
28025 /* In the first loop, it emits the primary .debug_macinfo section
28026 and after each emitted op the macinfo_entry is cleared.
28027 If a longer range of define/undef ops can be optimized using
28028 DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
28029 the vector before the first define/undef in the range and the
28030 whole range of define/undef ops is not emitted and kept. */
28031 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
28035 case DW_MACINFO_start_file
:
28036 vec_safe_push (files
, *ref
);
28038 case DW_MACINFO_end_file
:
28039 if (!vec_safe_is_empty (files
))
28042 case DW_MACINFO_define
:
28043 case DW_MACINFO_undef
:
28044 if ((!dwarf_strict
|| dwarf_version
>= 5)
28045 && HAVE_COMDAT_GROUP
28046 && vec_safe_length (files
) != 1
28049 && (*macinfo_table
)[i
- 1].code
== 0)
28051 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
28060 /* A dummy entry may be inserted at the beginning to be able
28061 to optimize the whole block of predefined macros. */
28067 output_macinfo_op (ref
);
28075 /* Save the number of transparent includes so we can adjust the
28076 label number for the fat LTO object DWARF. */
28077 unsigned macinfo_label_base_adj
= macinfo_htab
->elements ();
28079 delete macinfo_htab
;
28080 macinfo_htab
= NULL
;
28082 /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
28083 terminate the current chain and switch to a new comdat .debug_macinfo
28084 section and emit the define/undef entries within it. */
28085 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
28090 case DW_MACRO_import
:
28092 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
28093 tree comdat_key
= get_identifier (ref
->info
);
28094 /* Terminate the previous .debug_macinfo section. */
28095 dw2_asm_output_data (1, 0, "End compilation unit");
28096 targetm
.asm_out
.named_section (debug_macinfo_section_name
,
28100 ? SECTION_EXCLUDE
: 0),
28102 ASM_GENERATE_INTERNAL_LABEL (label
,
28103 DEBUG_MACRO_SECTION_LABEL
,
28104 ref
->lineno
+ macinfo_label_base
);
28105 ASM_OUTPUT_LABEL (asm_out_file
, label
);
28108 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
28109 "DWARF macro version number");
28110 if (DWARF_OFFSET_SIZE
== 8)
28111 dw2_asm_output_data (1, 1, "Flags: 64-bit");
28113 dw2_asm_output_data (1, 0, "Flags: 32-bit");
28116 case DW_MACINFO_define
:
28117 case DW_MACINFO_undef
:
28118 output_macinfo_op (ref
);
28123 gcc_unreachable ();
28126 macinfo_label_base
+= macinfo_label_base_adj
;
28129 /* Initialize the various sections and labels for dwarf output and prefix
28130 them with PREFIX if non-NULL. Returns the generation (zero based
28131 number of times function was called). */
28134 init_sections_and_labels (bool early_lto_debug
)
28136 /* As we may get called multiple times have a generation count for
28138 static unsigned generation
= 0;
28140 if (early_lto_debug
)
28142 if (!dwarf_split_debug_info
)
28144 debug_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
28145 SECTION_DEBUG
| SECTION_EXCLUDE
,
28147 debug_abbrev_section
= get_section (DEBUG_LTO_ABBREV_SECTION
,
28148 SECTION_DEBUG
| SECTION_EXCLUDE
,
28150 debug_macinfo_section_name
28151 = ((dwarf_strict
&& dwarf_version
< 5)
28152 ? DEBUG_LTO_MACINFO_SECTION
: DEBUG_LTO_MACRO_SECTION
);
28153 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
28155 | SECTION_EXCLUDE
, NULL
);
28156 /* For macro info we have to refer to a debug_line section, so
28157 similar to split-dwarf emit a skeleton one for early debug. */
28158 debug_skeleton_line_section
28159 = get_section (DEBUG_LTO_LINE_SECTION
,
28160 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
28161 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
28162 DEBUG_SKELETON_LINE_SECTION_LABEL
,
28167 /* ??? Which of the following do we need early? */
28168 debug_info_section
= get_section (DEBUG_LTO_DWO_INFO_SECTION
,
28169 SECTION_DEBUG
| SECTION_EXCLUDE
,
28171 debug_abbrev_section
= get_section (DEBUG_LTO_DWO_ABBREV_SECTION
,
28172 SECTION_DEBUG
| SECTION_EXCLUDE
,
28174 debug_skeleton_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
28176 | SECTION_EXCLUDE
, NULL
);
28177 debug_skeleton_abbrev_section
28178 = get_section (DEBUG_LTO_ABBREV_SECTION
,
28179 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
28180 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
28181 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
28184 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
28185 stay in the main .o, but the skeleton_line goes into the split
28187 debug_skeleton_line_section
28188 = get_section (DEBUG_LTO_LINE_SECTION
,
28189 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
28190 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
28191 DEBUG_SKELETON_LINE_SECTION_LABEL
,
28193 debug_str_offsets_section
28194 = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION
,
28195 SECTION_DEBUG
| SECTION_EXCLUDE
,
28197 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
28198 DEBUG_SKELETON_INFO_SECTION_LABEL
,
28200 debug_str_dwo_section
= get_section (DEBUG_LTO_STR_DWO_SECTION
,
28201 DEBUG_STR_DWO_SECTION_FLAGS
,
28203 debug_macinfo_section_name
28204 = ((dwarf_strict
&& dwarf_version
< 5)
28205 ? DEBUG_LTO_DWO_MACINFO_SECTION
: DEBUG_LTO_DWO_MACRO_SECTION
);
28206 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
28207 SECTION_DEBUG
| SECTION_EXCLUDE
,
28210 debug_str_section
= get_section (DEBUG_LTO_STR_SECTION
,
28211 DEBUG_STR_SECTION_FLAGS
28212 | SECTION_EXCLUDE
, NULL
);
28213 if (!dwarf_split_debug_info
&& !DWARF2_ASM_LINE_DEBUG_INFO
)
28214 debug_line_str_section
28215 = get_section (DEBUG_LTO_LINE_STR_SECTION
,
28216 DEBUG_STR_SECTION_FLAGS
| SECTION_EXCLUDE
, NULL
);
28220 if (!dwarf_split_debug_info
)
28222 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
28223 SECTION_DEBUG
, NULL
);
28224 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
28225 SECTION_DEBUG
, NULL
);
28226 debug_loc_section
= get_section (dwarf_version
>= 5
28227 ? DEBUG_LOCLISTS_SECTION
28228 : DEBUG_LOC_SECTION
,
28229 SECTION_DEBUG
, NULL
);
28230 debug_macinfo_section_name
28231 = ((dwarf_strict
&& dwarf_version
< 5)
28232 ? DEBUG_MACINFO_SECTION
: DEBUG_MACRO_SECTION
);
28233 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
28234 SECTION_DEBUG
, NULL
);
28238 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
28239 SECTION_DEBUG
| SECTION_EXCLUDE
,
28241 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
28242 SECTION_DEBUG
| SECTION_EXCLUDE
,
28244 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
28245 SECTION_DEBUG
, NULL
);
28246 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
28247 SECTION_DEBUG
, NULL
);
28248 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
28249 SECTION_DEBUG
, NULL
);
28250 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
28251 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
28254 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
28255 stay in the main .o, but the skeleton_line goes into the
28257 debug_skeleton_line_section
28258 = get_section (DEBUG_DWO_LINE_SECTION
,
28259 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
28260 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
28261 DEBUG_SKELETON_LINE_SECTION_LABEL
,
28263 debug_str_offsets_section
28264 = get_section (DEBUG_DWO_STR_OFFSETS_SECTION
,
28265 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
28266 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
28267 DEBUG_SKELETON_INFO_SECTION_LABEL
,
28269 debug_loc_section
= get_section (dwarf_version
>= 5
28270 ? DEBUG_DWO_LOCLISTS_SECTION
28271 : DEBUG_DWO_LOC_SECTION
,
28272 SECTION_DEBUG
| SECTION_EXCLUDE
,
28274 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
28275 DEBUG_STR_DWO_SECTION_FLAGS
,
28277 debug_macinfo_section_name
28278 = ((dwarf_strict
&& dwarf_version
< 5)
28279 ? DEBUG_DWO_MACINFO_SECTION
: DEBUG_DWO_MACRO_SECTION
);
28280 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
28281 SECTION_DEBUG
| SECTION_EXCLUDE
,
28284 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
28285 SECTION_DEBUG
, NULL
);
28286 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
28287 SECTION_DEBUG
, NULL
);
28288 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
28289 SECTION_DEBUG
, NULL
);
28290 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
28291 SECTION_DEBUG
, NULL
);
28292 debug_str_section
= get_section (DEBUG_STR_SECTION
,
28293 DEBUG_STR_SECTION_FLAGS
, NULL
);
28294 if (!dwarf_split_debug_info
&& !output_asm_line_debug_info ())
28295 debug_line_str_section
= get_section (DEBUG_LINE_STR_SECTION
,
28296 DEBUG_STR_SECTION_FLAGS
, NULL
);
28298 debug_ranges_section
= get_section (dwarf_version
>= 5
28299 ? DEBUG_RNGLISTS_SECTION
28300 : DEBUG_RANGES_SECTION
,
28301 SECTION_DEBUG
, NULL
);
28302 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
28303 SECTION_DEBUG
, NULL
);
28306 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
28307 DEBUG_ABBREV_SECTION_LABEL
, generation
);
28308 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
28309 DEBUG_INFO_SECTION_LABEL
, generation
);
28310 info_section_emitted
= false;
28311 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
28312 DEBUG_LINE_SECTION_LABEL
, generation
);
28313 /* There are up to 4 unique ranges labels per generation.
28314 See also output_rnglists. */
28315 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
28316 DEBUG_RANGES_SECTION_LABEL
, generation
* 4);
28317 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
28318 ASM_GENERATE_INTERNAL_LABEL (ranges_base_label
,
28319 DEBUG_RANGES_SECTION_LABEL
,
28320 1 + generation
* 4);
28321 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
28322 DEBUG_ADDR_SECTION_LABEL
, generation
);
28323 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
28324 (dwarf_strict
&& dwarf_version
< 5)
28325 ? DEBUG_MACINFO_SECTION_LABEL
28326 : DEBUG_MACRO_SECTION_LABEL
, generation
);
28327 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
,
28331 return generation
- 1;
28334 /* Set up for Dwarf output at the start of compilation. */
28337 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
28339 /* Allocate the file_table. */
28340 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
28342 #ifndef DWARF2_LINENO_DEBUGGING_INFO
28343 /* Allocate the decl_die_table. */
28344 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
28346 /* Allocate the decl_loc_table. */
28347 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
28349 /* Allocate the cached_dw_loc_list_table. */
28350 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
28352 /* Allocate the initial hunk of the decl_scope_table. */
28353 vec_alloc (decl_scope_table
, 256);
28355 /* Allocate the initial hunk of the abbrev_die_table. */
28356 vec_alloc (abbrev_die_table
, 256);
28357 /* Zero-th entry is allocated, but unused. */
28358 abbrev_die_table
->quick_push (NULL
);
28360 /* Allocate the dwarf_proc_stack_usage_map. */
28361 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
28363 /* Allocate the pubtypes and pubnames vectors. */
28364 vec_alloc (pubname_table
, 32);
28365 vec_alloc (pubtype_table
, 32);
28367 vec_alloc (incomplete_types
, 64);
28369 vec_alloc (used_rtx_array
, 32);
28371 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28372 vec_alloc (macinfo_table
, 64);
28375 /* If front-ends already registered a main translation unit but we were not
28376 ready to perform the association, do this now. */
28377 if (main_translation_unit
!= NULL_TREE
)
28378 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
28381 /* Called before compile () starts outputtting functions, variables
28382 and toplevel asms into assembly. */
28385 dwarf2out_assembly_start (void)
28387 if (text_section_line_info
)
28390 #ifndef DWARF2_LINENO_DEBUGGING_INFO
28391 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
28392 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
28393 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
28394 COLD_TEXT_SECTION_LABEL
, 0);
28395 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
28397 switch_to_section (text_section
);
28398 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
28401 /* Make sure the line number table for .text always exists. */
28402 text_section_line_info
= new_line_info_table ();
28403 text_section_line_info
->end_label
= text_end_label
;
28405 #ifdef DWARF2_LINENO_DEBUGGING_INFO
28406 cur_line_info_table
= text_section_line_info
;
28409 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
28410 && dwarf2out_do_cfi_asm ()
28411 && !dwarf2out_do_eh_frame ())
28412 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
28415 /* A helper function for dwarf2out_finish called through
28416 htab_traverse. Assign a string its index. All strings must be
28417 collected into the table by the time index_string is called,
28418 because the indexing code relies on htab_traverse to traverse nodes
28419 in the same order for each run. */
28422 index_string (indirect_string_node
**h
, unsigned int *index
)
28424 indirect_string_node
*node
= *h
;
28426 find_string_form (node
);
28427 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
28429 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
28430 node
->index
= *index
;
28436 /* A helper function for output_indirect_strings called through
28437 htab_traverse. Output the offset to a string and update the
28441 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
28443 indirect_string_node
*node
= *h
;
28445 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
28447 /* Assert that this node has been assigned an index. */
28448 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
28449 && node
->index
!= NOT_INDEXED
);
28450 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
28451 "indexed string 0x%x: %s", node
->index
, node
->str
);
28452 *offset
+= strlen (node
->str
) + 1;
28457 /* A helper function for dwarf2out_finish called through
28458 htab_traverse. Output the indexed string. */
28461 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
28463 struct indirect_string_node
*node
= *h
;
28465 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
28467 /* Assert that the strings are output in the same order as their
28468 indexes were assigned. */
28469 gcc_assert (*cur_idx
== node
->index
);
28470 assemble_string (node
->str
, strlen (node
->str
) + 1);
28476 /* A helper function for dwarf2out_finish called through
28477 htab_traverse. Emit one queued .debug_str string. */
28480 output_indirect_string (indirect_string_node
**h
, enum dwarf_form form
)
28482 struct indirect_string_node
*node
= *h
;
28484 node
->form
= find_string_form (node
);
28485 if (node
->form
== form
&& node
->refcount
> 0)
28487 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
28488 assemble_string (node
->str
, strlen (node
->str
) + 1);
28494 /* Output the indexed string table. */
28497 output_indirect_strings (void)
28499 switch_to_section (debug_str_section
);
28500 if (!dwarf_split_debug_info
)
28501 debug_str_hash
->traverse
<enum dwarf_form
,
28502 output_indirect_string
> (DW_FORM_strp
);
28505 unsigned int offset
= 0;
28506 unsigned int cur_idx
= 0;
28508 if (skeleton_debug_str_hash
)
28509 skeleton_debug_str_hash
->traverse
<enum dwarf_form
,
28510 output_indirect_string
> (DW_FORM_strp
);
28512 switch_to_section (debug_str_offsets_section
);
28513 debug_str_hash
->traverse_noresize
28514 <unsigned int *, output_index_string_offset
> (&offset
);
28515 switch_to_section (debug_str_dwo_section
);
28516 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
28521 /* Callback for htab_traverse to assign an index to an entry in the
28522 table, and to write that entry to the .debug_addr section. */
28525 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
28527 addr_table_entry
*entry
= *slot
;
28529 if (entry
->refcount
== 0)
28531 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
28532 || entry
->index
== NOT_INDEXED
);
28536 gcc_assert (entry
->index
== *cur_index
);
28539 switch (entry
->kind
)
28542 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
28543 "0x%x", entry
->index
);
28545 case ate_kind_rtx_dtprel
:
28546 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
28547 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
28550 fputc ('\n', asm_out_file
);
28552 case ate_kind_label
:
28553 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
28554 "0x%x", entry
->index
);
28557 gcc_unreachable ();
28562 /* Produce the .debug_addr section. */
28565 output_addr_table (void)
28567 unsigned int index
= 0;
28568 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
28571 switch_to_section (debug_addr_section
);
28573 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
28576 #if ENABLE_ASSERT_CHECKING
28577 /* Verify that all marks are clear. */
28580 verify_marks_clear (dw_die_ref die
)
28584 gcc_assert (! die
->die_mark
);
28585 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
28587 #endif /* ENABLE_ASSERT_CHECKING */
28589 /* Clear the marks for a die and its children.
28590 Be cool if the mark isn't set. */
28593 prune_unmark_dies (dw_die_ref die
)
28599 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
28602 /* Given LOC that is referenced by a DIE we're marking as used, find all
28603 referenced DWARF procedures it references and mark them as used. */
28606 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
28608 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
28609 switch (loc
->dw_loc_opc
)
28611 case DW_OP_implicit_pointer
:
28612 case DW_OP_convert
:
28613 case DW_OP_reinterpret
:
28614 case DW_OP_GNU_implicit_pointer
:
28615 case DW_OP_GNU_convert
:
28616 case DW_OP_GNU_reinterpret
:
28617 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
28618 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
28620 case DW_OP_GNU_variable_value
:
28621 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28624 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
28627 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28628 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28629 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28634 case DW_OP_call_ref
:
28635 case DW_OP_const_type
:
28636 case DW_OP_GNU_const_type
:
28637 case DW_OP_GNU_parameter_ref
:
28638 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
28639 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
28641 case DW_OP_regval_type
:
28642 case DW_OP_deref_type
:
28643 case DW_OP_GNU_regval_type
:
28644 case DW_OP_GNU_deref_type
:
28645 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
28646 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
28648 case DW_OP_entry_value
:
28649 case DW_OP_GNU_entry_value
:
28650 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
28651 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
28658 /* Given DIE that we're marking as used, find any other dies
28659 it references as attributes and mark them as used. */
28662 prune_unused_types_walk_attribs (dw_die_ref die
)
28667 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
28669 switch (AT_class (a
))
28671 /* Make sure DWARF procedures referenced by location descriptions will
28673 case dw_val_class_loc
:
28674 prune_unused_types_walk_loc_descr (AT_loc (a
));
28676 case dw_val_class_loc_list
:
28677 for (dw_loc_list_ref list
= AT_loc_list (a
);
28679 list
= list
->dw_loc_next
)
28680 prune_unused_types_walk_loc_descr (list
->expr
);
28683 case dw_val_class_view_list
:
28684 /* This points to a loc_list in another attribute, so it's
28685 already covered. */
28688 case dw_val_class_die_ref
:
28689 /* A reference to another DIE.
28690 Make sure that it will get emitted.
28691 If it was broken out into a comdat group, don't follow it. */
28692 if (! AT_ref (a
)->comdat_type_p
28693 || a
->dw_attr
== DW_AT_specification
)
28694 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
28697 case dw_val_class_str
:
28698 /* Set the string's refcount to 0 so that prune_unused_types_mark
28699 accounts properly for it. */
28700 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
28709 /* Mark the generic parameters and arguments children DIEs of DIE. */
28712 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
28716 if (die
== NULL
|| die
->die_child
== NULL
)
28718 c
= die
->die_child
;
28721 if (is_template_parameter (c
))
28722 prune_unused_types_mark (c
, 1);
28724 } while (c
&& c
!= die
->die_child
);
28727 /* Mark DIE as being used. If DOKIDS is true, then walk down
28728 to DIE's children. */
28731 prune_unused_types_mark (dw_die_ref die
, int dokids
)
28735 if (die
->die_mark
== 0)
28737 /* We haven't done this node yet. Mark it as used. */
28739 /* If this is the DIE of a generic type instantiation,
28740 mark the children DIEs that describe its generic parms and
28742 prune_unused_types_mark_generic_parms_dies (die
);
28744 /* We also have to mark its parents as used.
28745 (But we don't want to mark our parent's kids due to this,
28746 unless it is a class.) */
28747 if (die
->die_parent
)
28748 prune_unused_types_mark (die
->die_parent
,
28749 class_scope_p (die
->die_parent
));
28751 /* Mark any referenced nodes. */
28752 prune_unused_types_walk_attribs (die
);
28754 /* If this node is a specification,
28755 also mark the definition, if it exists. */
28756 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
28757 prune_unused_types_mark (die
->die_definition
, 1);
28760 if (dokids
&& die
->die_mark
!= 2)
28762 /* We need to walk the children, but haven't done so yet.
28763 Remember that we've walked the kids. */
28766 /* If this is an array type, we need to make sure our
28767 kids get marked, even if they're types. If we're
28768 breaking out types into comdat sections, do this
28769 for all type definitions. */
28770 if (die
->die_tag
== DW_TAG_array_type
28771 || (use_debug_types
28772 && is_type_die (die
) && ! is_declaration_die (die
)))
28773 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
28775 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
28779 /* For local classes, look if any static member functions were emitted
28780 and if so, mark them. */
28783 prune_unused_types_walk_local_classes (dw_die_ref die
)
28787 if (die
->die_mark
== 2)
28790 switch (die
->die_tag
)
28792 case DW_TAG_structure_type
:
28793 case DW_TAG_union_type
:
28794 case DW_TAG_class_type
:
28797 case DW_TAG_subprogram
:
28798 if (!get_AT_flag (die
, DW_AT_declaration
)
28799 || die
->die_definition
!= NULL
)
28800 prune_unused_types_mark (die
, 1);
28807 /* Mark children. */
28808 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
28811 /* Walk the tree DIE and mark types that we actually use. */
28814 prune_unused_types_walk (dw_die_ref die
)
28818 /* Don't do anything if this node is already marked and
28819 children have been marked as well. */
28820 if (die
->die_mark
== 2)
28823 switch (die
->die_tag
)
28825 case DW_TAG_structure_type
:
28826 case DW_TAG_union_type
:
28827 case DW_TAG_class_type
:
28828 if (die
->die_perennial_p
)
28831 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
28832 if (c
->die_tag
== DW_TAG_subprogram
)
28835 /* Finding used static member functions inside of classes
28836 is needed just for local classes, because for other classes
28837 static member function DIEs with DW_AT_specification
28838 are emitted outside of the DW_TAG_*_type. If we ever change
28839 it, we'd need to call this even for non-local classes. */
28841 prune_unused_types_walk_local_classes (die
);
28843 /* It's a type node --- don't mark it. */
28846 case DW_TAG_const_type
:
28847 case DW_TAG_packed_type
:
28848 case DW_TAG_pointer_type
:
28849 case DW_TAG_reference_type
:
28850 case DW_TAG_rvalue_reference_type
:
28851 case DW_TAG_volatile_type
:
28852 case DW_TAG_typedef
:
28853 case DW_TAG_array_type
:
28854 case DW_TAG_interface_type
:
28855 case DW_TAG_friend
:
28856 case DW_TAG_enumeration_type
:
28857 case DW_TAG_subroutine_type
:
28858 case DW_TAG_string_type
:
28859 case DW_TAG_set_type
:
28860 case DW_TAG_subrange_type
:
28861 case DW_TAG_ptr_to_member_type
:
28862 case DW_TAG_file_type
:
28863 /* Type nodes are useful only when other DIEs reference them --- don't
28867 case DW_TAG_dwarf_procedure
:
28868 /* Likewise for DWARF procedures. */
28870 if (die
->die_perennial_p
)
28876 /* Mark everything else. */
28880 if (die
->die_mark
== 0)
28884 /* Now, mark any dies referenced from here. */
28885 prune_unused_types_walk_attribs (die
);
28890 /* Mark children. */
28891 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
28894 /* Increment the string counts on strings referred to from DIE's
28898 prune_unused_types_update_strings (dw_die_ref die
)
28903 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
28904 if (AT_class (a
) == dw_val_class_str
)
28906 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
28908 /* Avoid unnecessarily putting strings that are used less than
28909 twice in the hash table. */
28911 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
28913 indirect_string_node
**slot
28914 = debug_str_hash
->find_slot_with_hash (s
->str
,
28915 htab_hash_string (s
->str
),
28917 gcc_assert (*slot
== NULL
);
28923 /* Mark DIE and its children as removed. */
28926 mark_removed (dw_die_ref die
)
28929 die
->removed
= true;
28930 FOR_EACH_CHILD (die
, c
, mark_removed (c
));
28933 /* Remove from the tree DIE any dies that aren't marked. */
28936 prune_unused_types_prune (dw_die_ref die
)
28940 gcc_assert (die
->die_mark
);
28941 prune_unused_types_update_strings (die
);
28943 if (! die
->die_child
)
28946 c
= die
->die_child
;
28948 dw_die_ref prev
= c
, next
;
28949 for (c
= c
->die_sib
; ! c
->die_mark
; c
= next
)
28950 if (c
== die
->die_child
)
28952 /* No marked children between 'prev' and the end of the list. */
28954 /* No marked children at all. */
28955 die
->die_child
= NULL
;
28958 prev
->die_sib
= c
->die_sib
;
28959 die
->die_child
= prev
;
28972 if (c
!= prev
->die_sib
)
28974 prune_unused_types_prune (c
);
28975 } while (c
!= die
->die_child
);
28978 /* Remove dies representing declarations that we never use. */
28981 prune_unused_types (void)
28984 limbo_die_node
*node
;
28985 comdat_type_node
*ctnode
;
28986 pubname_entry
*pub
;
28987 dw_die_ref base_type
;
28989 #if ENABLE_ASSERT_CHECKING
28990 /* All the marks should already be clear. */
28991 verify_marks_clear (comp_unit_die ());
28992 for (node
= limbo_die_list
; node
; node
= node
->next
)
28993 verify_marks_clear (node
->die
);
28994 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28995 verify_marks_clear (ctnode
->root_die
);
28996 #endif /* ENABLE_ASSERT_CHECKING */
28998 /* Mark types that are used in global variables. */
28999 premark_types_used_by_global_vars ();
29001 /* Set the mark on nodes that are actually used. */
29002 prune_unused_types_walk (comp_unit_die ());
29003 for (node
= limbo_die_list
; node
; node
= node
->next
)
29004 prune_unused_types_walk (node
->die
);
29005 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
29007 prune_unused_types_walk (ctnode
->root_die
);
29008 prune_unused_types_mark (ctnode
->type_die
, 1);
29011 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
29012 are unusual in that they are pubnames that are the children of pubtypes.
29013 They should only be marked via their parent DW_TAG_enumeration_type die,
29014 not as roots in themselves. */
29015 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
29016 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
29017 prune_unused_types_mark (pub
->die
, 1);
29018 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
29019 prune_unused_types_mark (base_type
, 1);
29021 /* For -fvar-tracking-assignments, also set the mark on nodes that could be
29022 referenced by DW_TAG_call_site DW_AT_call_origin (i.e. direct call
29024 cgraph_node
*cnode
;
29025 FOR_EACH_FUNCTION (cnode
)
29026 if (cnode
->referred_to_p (false))
29028 dw_die_ref die
= lookup_decl_die (cnode
->decl
);
29029 if (die
== NULL
|| die
->die_mark
)
29031 for (cgraph_edge
*e
= cnode
->callers
; e
; e
= e
->next_caller
)
29032 if (e
->caller
!= cnode
29033 && opt_for_fn (e
->caller
->decl
, flag_var_tracking_assignments
))
29035 prune_unused_types_mark (die
, 1);
29040 if (debug_str_hash
)
29041 debug_str_hash
->empty ();
29042 if (skeleton_debug_str_hash
)
29043 skeleton_debug_str_hash
->empty ();
29044 prune_unused_types_prune (comp_unit_die ());
29045 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
29048 if (!node
->die
->die_mark
)
29049 *pnode
= node
->next
;
29052 prune_unused_types_prune (node
->die
);
29053 pnode
= &node
->next
;
29056 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
29057 prune_unused_types_prune (ctnode
->root_die
);
29059 /* Leave the marks clear. */
29060 prune_unmark_dies (comp_unit_die ());
29061 for (node
= limbo_die_list
; node
; node
= node
->next
)
29062 prune_unmark_dies (node
->die
);
29063 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
29064 prune_unmark_dies (ctnode
->root_die
);
29067 /* Helpers to manipulate hash table of comdat type units. */
29069 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
29071 static inline hashval_t
hash (const comdat_type_node
*);
29072 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
29076 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
29079 memcpy (&h
, type_node
->signature
, sizeof (h
));
29084 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
29085 const comdat_type_node
*type_node_2
)
29087 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
29088 DWARF_TYPE_SIGNATURE_SIZE
));
29091 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
29092 to the location it would have been added, should we know its
29093 DECL_ASSEMBLER_NAME when we added other attributes. This will
29094 probably improve compactness of debug info, removing equivalent
29095 abbrevs, and hide any differences caused by deferring the
29096 computation of the assembler name, triggered by e.g. PCH. */
29099 move_linkage_attr (dw_die_ref die
)
29101 unsigned ix
= vec_safe_length (die
->die_attr
);
29102 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
29104 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
29105 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
29109 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
29111 if (prev
->dw_attr
== DW_AT_decl_line
29112 || prev
->dw_attr
== DW_AT_decl_column
29113 || prev
->dw_attr
== DW_AT_name
)
29117 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
29119 die
->die_attr
->pop ();
29120 die
->die_attr
->quick_insert (ix
, linkage
);
29124 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
29125 referenced from typed stack ops and count how often they are used. */
29128 mark_base_types (dw_loc_descr_ref loc
)
29130 dw_die_ref base_type
= NULL
;
29132 for (; loc
; loc
= loc
->dw_loc_next
)
29134 switch (loc
->dw_loc_opc
)
29136 case DW_OP_regval_type
:
29137 case DW_OP_deref_type
:
29138 case DW_OP_GNU_regval_type
:
29139 case DW_OP_GNU_deref_type
:
29140 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
29142 case DW_OP_convert
:
29143 case DW_OP_reinterpret
:
29144 case DW_OP_GNU_convert
:
29145 case DW_OP_GNU_reinterpret
:
29146 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
29149 case DW_OP_const_type
:
29150 case DW_OP_GNU_const_type
:
29151 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
29153 case DW_OP_entry_value
:
29154 case DW_OP_GNU_entry_value
:
29155 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
29160 gcc_assert (base_type
->die_parent
== comp_unit_die ());
29161 if (base_type
->die_mark
)
29162 base_type
->die_mark
++;
29165 base_types
.safe_push (base_type
);
29166 base_type
->die_mark
= 1;
29171 /* Comparison function for sorting marked base types. */
29174 base_type_cmp (const void *x
, const void *y
)
29176 dw_die_ref dx
= *(const dw_die_ref
*) x
;
29177 dw_die_ref dy
= *(const dw_die_ref
*) y
;
29178 unsigned int byte_size1
, byte_size2
;
29179 unsigned int encoding1
, encoding2
;
29180 unsigned int align1
, align2
;
29181 if (dx
->die_mark
> dy
->die_mark
)
29183 if (dx
->die_mark
< dy
->die_mark
)
29185 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
29186 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
29187 if (byte_size1
< byte_size2
)
29189 if (byte_size1
> byte_size2
)
29191 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
29192 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
29193 if (encoding1
< encoding2
)
29195 if (encoding1
> encoding2
)
29197 align1
= get_AT_unsigned (dx
, DW_AT_alignment
);
29198 align2
= get_AT_unsigned (dy
, DW_AT_alignment
);
29199 if (align1
< align2
)
29201 if (align1
> align2
)
29206 /* Move base types marked by mark_base_types as early as possible
29207 in the CU, sorted by decreasing usage count both to make the
29208 uleb128 references as small as possible and to make sure they
29209 will have die_offset already computed by calc_die_sizes when
29210 sizes of typed stack loc ops is computed. */
29213 move_marked_base_types (void)
29216 dw_die_ref base_type
, die
, c
;
29218 if (base_types
.is_empty ())
29221 /* Sort by decreasing usage count, they will be added again in that
29223 base_types
.qsort (base_type_cmp
);
29224 die
= comp_unit_die ();
29225 c
= die
->die_child
;
29228 dw_die_ref prev
= c
;
29230 while (c
->die_mark
)
29232 remove_child_with_prev (c
, prev
);
29233 /* As base types got marked, there must be at least
29234 one node other than DW_TAG_base_type. */
29235 gcc_assert (die
->die_child
!= NULL
);
29239 while (c
!= die
->die_child
);
29240 gcc_assert (die
->die_child
);
29241 c
= die
->die_child
;
29242 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
29244 base_type
->die_mark
= 0;
29245 base_type
->die_sib
= c
->die_sib
;
29246 c
->die_sib
= base_type
;
29251 /* Helper function for resolve_addr, attempt to resolve
29252 one CONST_STRING, return true if successful. Similarly verify that
29253 SYMBOL_REFs refer to variables emitted in the current CU. */
29256 resolve_one_addr (rtx
*addr
)
29260 if (GET_CODE (rtl
) == CONST_STRING
)
29262 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
29263 tree t
= build_string (len
, XSTR (rtl
, 0));
29264 tree tlen
= size_int (len
- 1);
29266 = build_array_type (char_type_node
, build_index_type (tlen
));
29267 rtl
= lookup_constant_def (t
);
29268 if (!rtl
|| !MEM_P (rtl
))
29270 rtl
= XEXP (rtl
, 0);
29271 if (GET_CODE (rtl
) == SYMBOL_REF
29272 && SYMBOL_REF_DECL (rtl
)
29273 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
29275 vec_safe_push (used_rtx_array
, rtl
);
29280 if (GET_CODE (rtl
) == SYMBOL_REF
29281 && SYMBOL_REF_DECL (rtl
))
29283 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
29285 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
29288 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
29292 if (GET_CODE (rtl
) == CONST
)
29294 subrtx_ptr_iterator::array_type array
;
29295 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
29296 if (!resolve_one_addr (*iter
))
29303 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
29304 if possible, and create DW_TAG_dwarf_procedure that can be referenced
29305 from DW_OP_implicit_pointer if the string hasn't been seen yet. */
29308 string_cst_pool_decl (tree t
)
29310 rtx rtl
= output_constant_def (t
, 1);
29311 unsigned char *array
;
29312 dw_loc_descr_ref l
;
29317 if (!rtl
|| !MEM_P (rtl
))
29319 rtl
= XEXP (rtl
, 0);
29320 if (GET_CODE (rtl
) != SYMBOL_REF
29321 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
29324 decl
= SYMBOL_REF_DECL (rtl
);
29325 if (!lookup_decl_die (decl
))
29327 len
= TREE_STRING_LENGTH (t
);
29328 vec_safe_push (used_rtx_array
, rtl
);
29329 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
29330 array
= ggc_vec_alloc
<unsigned char> (len
);
29331 memcpy (array
, TREE_STRING_POINTER (t
), len
);
29332 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
29333 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
29334 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
29335 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
29336 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
29337 add_AT_loc (ref
, DW_AT_location
, l
);
29338 equate_decl_number_to_die (decl
, ref
);
29343 /* Helper function of resolve_addr_in_expr. LOC is
29344 a DW_OP_addr followed by DW_OP_stack_value, either at the start
29345 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
29346 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
29347 with DW_OP_implicit_pointer if possible
29348 and return true, if unsuccessful, return false. */
29351 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
29353 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
29354 HOST_WIDE_INT offset
= 0;
29355 dw_die_ref ref
= NULL
;
29358 if (GET_CODE (rtl
) == CONST
29359 && GET_CODE (XEXP (rtl
, 0)) == PLUS
29360 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
29362 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
29363 rtl
= XEXP (XEXP (rtl
, 0), 0);
29365 if (GET_CODE (rtl
) == CONST_STRING
)
29367 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
29368 tree t
= build_string (len
, XSTR (rtl
, 0));
29369 tree tlen
= size_int (len
- 1);
29372 = build_array_type (char_type_node
, build_index_type (tlen
));
29373 rtl
= string_cst_pool_decl (t
);
29377 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
29379 decl
= SYMBOL_REF_DECL (rtl
);
29380 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
29382 ref
= lookup_decl_die (decl
);
29383 if (ref
&& (get_AT (ref
, DW_AT_location
)
29384 || get_AT (ref
, DW_AT_const_value
)))
29386 loc
->dw_loc_opc
= dwarf_OP (DW_OP_implicit_pointer
);
29387 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
29388 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
29389 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
29390 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
29391 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
29392 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
29400 /* Helper function for resolve_addr, handle one location
29401 expression, return false if at least one CONST_STRING or SYMBOL_REF in
29402 the location list couldn't be resolved. */
29405 resolve_addr_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
29407 dw_loc_descr_ref keep
= NULL
;
29408 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
29409 switch (loc
->dw_loc_opc
)
29412 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
29415 || prev
->dw_loc_opc
== DW_OP_piece
29416 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
29417 && loc
->dw_loc_next
29418 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
29419 && (!dwarf_strict
|| dwarf_version
>= 5)
29420 && optimize_one_addr_into_implicit_ptr (loc
))
29425 case DW_OP_GNU_addr_index
:
29426 case DW_OP_GNU_const_index
:
29427 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
29428 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
29430 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
29431 if (!resolve_one_addr (&rtl
))
29433 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
29434 loc
->dw_loc_oprnd1
.val_entry
29435 = add_addr_table_entry (rtl
, ate_kind_rtx
);
29438 case DW_OP_const4u
:
29439 case DW_OP_const8u
:
29441 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
29444 case DW_OP_plus_uconst
:
29445 if (size_of_loc_descr (loc
)
29446 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
29448 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
29450 dw_loc_descr_ref repl
29451 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
29452 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
29453 add_loc_descr (&repl
, loc
->dw_loc_next
);
29457 case DW_OP_implicit_value
:
29458 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
29459 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
29462 case DW_OP_implicit_pointer
:
29463 case DW_OP_GNU_implicit_pointer
:
29464 case DW_OP_GNU_parameter_ref
:
29465 case DW_OP_GNU_variable_value
:
29466 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
29469 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
29472 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
29473 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
29474 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
29476 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
)
29479 && loc
->dw_loc_next
== NULL
29480 && AT_class (a
) == dw_val_class_loc
)
29481 switch (a
->dw_attr
)
29483 /* Following attributes allow both exprloc and reference,
29484 so if the whole expression is DW_OP_GNU_variable_value
29485 alone we could transform it into reference. */
29486 case DW_AT_byte_size
:
29487 case DW_AT_bit_size
:
29488 case DW_AT_lower_bound
:
29489 case DW_AT_upper_bound
:
29490 case DW_AT_bit_stride
:
29492 case DW_AT_allocated
:
29493 case DW_AT_associated
:
29494 case DW_AT_byte_stride
:
29495 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
29496 a
->dw_attr_val
.val_entry
= NULL
;
29497 a
->dw_attr_val
.v
.val_die_ref
.die
29498 = loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
29499 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
29508 case DW_OP_const_type
:
29509 case DW_OP_regval_type
:
29510 case DW_OP_deref_type
:
29511 case DW_OP_convert
:
29512 case DW_OP_reinterpret
:
29513 case DW_OP_GNU_const_type
:
29514 case DW_OP_GNU_regval_type
:
29515 case DW_OP_GNU_deref_type
:
29516 case DW_OP_GNU_convert
:
29517 case DW_OP_GNU_reinterpret
:
29518 while (loc
->dw_loc_next
29519 && (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_convert
29520 || loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
))
29522 dw_die_ref base1
, base2
;
29523 unsigned enc1
, enc2
, size1
, size2
;
29524 if (loc
->dw_loc_opc
== DW_OP_regval_type
29525 || loc
->dw_loc_opc
== DW_OP_deref_type
29526 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
29527 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
29528 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
29529 else if (loc
->dw_loc_oprnd1
.val_class
29530 == dw_val_class_unsigned_const
)
29533 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
29534 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
29535 == dw_val_class_unsigned_const
)
29537 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
29538 gcc_assert (base1
->die_tag
== DW_TAG_base_type
29539 && base2
->die_tag
== DW_TAG_base_type
);
29540 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
29541 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
29542 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
29543 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
29545 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
29546 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
29550 /* Optimize away next DW_OP_convert after
29551 adjusting LOC's base type die reference. */
29552 if (loc
->dw_loc_opc
== DW_OP_regval_type
29553 || loc
->dw_loc_opc
== DW_OP_deref_type
29554 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
29555 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
29556 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
29558 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
29559 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
29562 /* Don't change integer DW_OP_convert after e.g. floating
29563 point typed stack entry. */
29564 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
29565 keep
= loc
->dw_loc_next
;
29575 /* Helper function of resolve_addr. DIE had DW_AT_location of
29576 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
29577 and DW_OP_addr couldn't be resolved. resolve_addr has already
29578 removed the DW_AT_location attribute. This function attempts to
29579 add a new DW_AT_location attribute with DW_OP_implicit_pointer
29580 to it or DW_AT_const_value attribute, if possible. */
29583 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
29586 || lookup_decl_die (decl
) != die
29587 || DECL_EXTERNAL (decl
)
29588 || !TREE_STATIC (decl
)
29589 || DECL_INITIAL (decl
) == NULL_TREE
29590 || DECL_P (DECL_INITIAL (decl
))
29591 || get_AT (die
, DW_AT_const_value
))
29594 tree init
= DECL_INITIAL (decl
);
29595 HOST_WIDE_INT offset
= 0;
29596 /* For variables that have been optimized away and thus
29597 don't have a memory location, see if we can emit
29598 DW_AT_const_value instead. */
29599 if (tree_add_const_value_attribute (die
, init
))
29601 if (dwarf_strict
&& dwarf_version
< 5)
29603 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
29604 and ADDR_EXPR refers to a decl that has DW_AT_location or
29605 DW_AT_const_value (but isn't addressable, otherwise
29606 resolving the original DW_OP_addr wouldn't fail), see if
29607 we can add DW_OP_implicit_pointer. */
29609 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
29610 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
29612 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
29613 init
= TREE_OPERAND (init
, 0);
29616 if (TREE_CODE (init
) != ADDR_EXPR
)
29618 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
29619 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
29620 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
29621 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
29622 && TREE_OPERAND (init
, 0) != decl
))
29625 dw_loc_descr_ref l
;
29627 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
29629 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
29632 decl
= SYMBOL_REF_DECL (rtl
);
29635 decl
= TREE_OPERAND (init
, 0);
29636 ref
= lookup_decl_die (decl
);
29638 || (!get_AT (ref
, DW_AT_location
)
29639 && !get_AT (ref
, DW_AT_const_value
)))
29641 l
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
29642 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
29643 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
29644 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
29645 add_AT_loc (die
, DW_AT_location
, l
);
29649 /* Return NULL if l is a DWARF expression, or first op that is not
29650 valid DWARF expression. */
29652 static dw_loc_descr_ref
29653 non_dwarf_expression (dw_loc_descr_ref l
)
29657 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
29659 switch (l
->dw_loc_opc
)
29662 case DW_OP_implicit_value
:
29663 case DW_OP_stack_value
:
29664 case DW_OP_implicit_pointer
:
29665 case DW_OP_GNU_implicit_pointer
:
29666 case DW_OP_GNU_parameter_ref
:
29668 case DW_OP_bit_piece
:
29673 l
= l
->dw_loc_next
;
29678 /* Return adjusted copy of EXPR:
29679 If it is empty DWARF expression, return it.
29680 If it is valid non-empty DWARF expression,
29681 return copy of EXPR with DW_OP_deref appended to it.
29682 If it is DWARF expression followed by DW_OP_reg{N,x}, return
29683 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
29684 If it is DWARF expression followed by DW_OP_stack_value, return
29685 copy of the DWARF expression without anything appended.
29686 Otherwise, return NULL. */
29688 static dw_loc_descr_ref
29689 copy_deref_exprloc (dw_loc_descr_ref expr
)
29691 dw_loc_descr_ref tail
= NULL
;
29696 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
29697 if (l
&& l
->dw_loc_next
)
29702 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
29703 tail
= new_loc_descr ((enum dwarf_location_atom
)
29704 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
29707 switch (l
->dw_loc_opc
)
29710 tail
= new_loc_descr (DW_OP_bregx
,
29711 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
29713 case DW_OP_stack_value
:
29720 tail
= new_loc_descr (DW_OP_deref
, 0, 0);
29722 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
29725 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
29726 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
29727 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
29728 p
= &(*p
)->dw_loc_next
;
29729 expr
= expr
->dw_loc_next
;
29735 /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
29736 reference to a variable or argument, adjust it if needed and return:
29737 -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
29738 attribute if present should be removed
29739 0 keep the attribute perhaps with minor modifications, no need to rescan
29740 1 if the attribute has been successfully adjusted. */
29743 optimize_string_length (dw_attr_node
*a
)
29745 dw_loc_descr_ref l
= AT_loc (a
), lv
;
29747 if (l
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
29749 tree decl
= l
->dw_loc_oprnd1
.v
.val_decl_ref
;
29750 die
= lookup_decl_die (decl
);
29753 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
29754 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= die
;
29755 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
29761 die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
29763 /* DWARF5 allows reference class, so we can then reference the DIE.
29764 Only do this for DW_OP_GNU_variable_value DW_OP_stack_value. */
29765 if (l
->dw_loc_next
!= NULL
&& dwarf_version
>= 5)
29767 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
29768 a
->dw_attr_val
.val_entry
= NULL
;
29769 a
->dw_attr_val
.v
.val_die_ref
.die
= die
;
29770 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
29774 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
29776 bool non_dwarf_expr
= false;
29779 return dwarf_strict
? -1 : 0;
29780 switch (AT_class (av
))
29782 case dw_val_class_loc_list
:
29783 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
29784 if (d
->expr
&& non_dwarf_expression (d
->expr
))
29785 non_dwarf_expr
= true;
29787 case dw_val_class_view_list
:
29788 gcc_unreachable ();
29789 case dw_val_class_loc
:
29792 return dwarf_strict
? -1 : 0;
29793 if (non_dwarf_expression (lv
))
29794 non_dwarf_expr
= true;
29797 return dwarf_strict
? -1 : 0;
29800 /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
29801 into DW_OP_call4 or DW_OP_GNU_variable_value into
29802 DW_OP_call4 DW_OP_deref, do so. */
29803 if (!non_dwarf_expr
29804 && (l
->dw_loc_next
!= NULL
|| AT_class (av
) == dw_val_class_loc
))
29806 l
->dw_loc_opc
= DW_OP_call4
;
29807 if (l
->dw_loc_next
)
29808 l
->dw_loc_next
= NULL
;
29810 l
->dw_loc_next
= new_loc_descr (DW_OP_deref
, 0, 0);
29814 /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
29815 copy over the DW_AT_location attribute from die to a. */
29816 if (l
->dw_loc_next
!= NULL
)
29818 a
->dw_attr_val
= av
->dw_attr_val
;
29822 dw_loc_list_ref list
, *p
;
29823 switch (AT_class (av
))
29825 case dw_val_class_loc_list
:
29828 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
29830 lv
= copy_deref_exprloc (d
->expr
);
29833 *p
= new_loc_list (lv
, d
->begin
, d
->vbegin
, d
->end
, d
->vend
, d
->section
);
29834 p
= &(*p
)->dw_loc_next
;
29836 else if (!dwarf_strict
&& d
->expr
)
29840 return dwarf_strict
? -1 : 0;
29841 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
29843 *AT_loc_list_ptr (a
) = list
;
29845 case dw_val_class_loc
:
29846 lv
= copy_deref_exprloc (AT_loc (av
));
29848 return dwarf_strict
? -1 : 0;
29849 a
->dw_attr_val
.v
.val_loc
= lv
;
29852 gcc_unreachable ();
29856 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
29857 an address in .rodata section if the string literal is emitted there,
29858 or remove the containing location list or replace DW_AT_const_value
29859 with DW_AT_location and empty location expression, if it isn't found
29860 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
29861 to something that has been emitted in the current CU. */
29864 resolve_addr (dw_die_ref die
)
29868 dw_loc_list_ref
*curr
, *start
, loc
;
29870 bool remove_AT_byte_size
= false;
29872 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29873 switch (AT_class (a
))
29875 case dw_val_class_loc_list
:
29876 start
= curr
= AT_loc_list_ptr (a
);
29879 /* The same list can be referenced more than once. See if we have
29880 already recorded the result from a previous pass. */
29882 *curr
= loc
->dw_loc_next
;
29883 else if (!loc
->resolved_addr
)
29885 /* As things stand, we do not expect or allow one die to
29886 reference a suffix of another die's location list chain.
29887 References must be identical or completely separate.
29888 There is therefore no need to cache the result of this
29889 pass on any list other than the first; doing so
29890 would lead to unnecessary writes. */
29893 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
29894 if (!resolve_addr_in_expr (a
, (*curr
)->expr
))
29896 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
29897 dw_loc_descr_ref l
= (*curr
)->expr
;
29899 if (next
&& (*curr
)->ll_symbol
)
29901 gcc_assert (!next
->ll_symbol
);
29902 next
->ll_symbol
= (*curr
)->ll_symbol
;
29903 next
->vl_symbol
= (*curr
)->vl_symbol
;
29905 if (dwarf_split_debug_info
)
29906 remove_loc_list_addr_table_entries (l
);
29911 mark_base_types ((*curr
)->expr
);
29912 curr
= &(*curr
)->dw_loc_next
;
29916 loc
->resolved_addr
= 1;
29920 loc
->dw_loc_next
= *start
;
29925 remove_AT (die
, a
->dw_attr
);
29929 case dw_val_class_view_list
:
29931 gcc_checking_assert (a
->dw_attr
== DW_AT_GNU_locviews
);
29932 gcc_checking_assert (dwarf2out_locviews_in_attribute ());
29933 dw_val_node
*llnode
29934 = view_list_to_loc_list_val_node (&a
->dw_attr_val
);
29935 /* If we no longer have a loclist, or it no longer needs
29936 views, drop this attribute. */
29937 if (!llnode
|| !llnode
->v
.val_loc_list
->vl_symbol
)
29939 remove_AT (die
, a
->dw_attr
);
29944 case dw_val_class_loc
:
29946 dw_loc_descr_ref l
= AT_loc (a
);
29947 /* DW_OP_GNU_variable_value DW_OP_stack_value or
29948 DW_OP_GNU_variable_value in DW_AT_string_length can be converted
29949 into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
29950 DWARF4 unlike DW_OP_GNU_variable_value. Or for DWARF5
29951 DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
29952 with DW_FORM_ref referencing the same DIE as
29953 DW_OP_GNU_variable_value used to reference. */
29954 if (a
->dw_attr
== DW_AT_string_length
29956 && l
->dw_loc_opc
== DW_OP_GNU_variable_value
29957 && (l
->dw_loc_next
== NULL
29958 || (l
->dw_loc_next
->dw_loc_next
== NULL
29959 && l
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
)))
29961 switch (optimize_string_length (a
))
29964 remove_AT (die
, a
->dw_attr
);
29966 /* If we drop DW_AT_string_length, we need to drop also
29967 DW_AT_{string_length_,}byte_size. */
29968 remove_AT_byte_size
= true;
29973 /* Even if we keep the optimized DW_AT_string_length,
29974 it might have changed AT_class, so process it again. */
29979 /* For -gdwarf-2 don't attempt to optimize
29980 DW_AT_data_member_location containing
29981 DW_OP_plus_uconst - older consumers might
29982 rely on it being that op instead of a more complex,
29983 but shorter, location description. */
29984 if ((dwarf_version
> 2
29985 || a
->dw_attr
!= DW_AT_data_member_location
29987 || l
->dw_loc_opc
!= DW_OP_plus_uconst
29988 || l
->dw_loc_next
!= NULL
)
29989 && !resolve_addr_in_expr (a
, l
))
29991 if (dwarf_split_debug_info
)
29992 remove_loc_list_addr_table_entries (l
);
29994 && l
->dw_loc_next
== NULL
29995 && l
->dw_loc_opc
== DW_OP_addr
29996 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
29997 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
29998 && a
->dw_attr
== DW_AT_location
)
30000 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
30001 remove_AT (die
, a
->dw_attr
);
30003 optimize_location_into_implicit_ptr (die
, decl
);
30006 if (a
->dw_attr
== DW_AT_string_length
)
30007 /* If we drop DW_AT_string_length, we need to drop also
30008 DW_AT_{string_length_,}byte_size. */
30009 remove_AT_byte_size
= true;
30010 remove_AT (die
, a
->dw_attr
);
30014 mark_base_types (l
);
30017 case dw_val_class_addr
:
30018 if (a
->dw_attr
== DW_AT_const_value
30019 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
30021 if (AT_index (a
) != NOT_INDEXED
)
30022 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
30023 remove_AT (die
, a
->dw_attr
);
30026 if ((die
->die_tag
== DW_TAG_call_site
30027 && a
->dw_attr
== DW_AT_call_origin
)
30028 || (die
->die_tag
== DW_TAG_GNU_call_site
30029 && a
->dw_attr
== DW_AT_abstract_origin
))
30031 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
30032 dw_die_ref tdie
= lookup_decl_die (tdecl
);
30035 && DECL_EXTERNAL (tdecl
)
30036 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
30037 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
30039 dw_die_ref pdie
= cdie
;
30040 /* Make sure we don't add these DIEs into type units.
30041 We could emit skeleton DIEs for context (namespaces,
30042 outer structs/classes) and a skeleton DIE for the
30043 innermost context with DW_AT_signature pointing to the
30044 type unit. See PR78835. */
30045 while (pdie
&& pdie
->die_tag
!= DW_TAG_type_unit
)
30046 pdie
= pdie
->die_parent
;
30049 /* Creating a full DIE for tdecl is overly expensive and
30050 at this point even wrong when in the LTO phase
30051 as it can end up generating new type DIEs we didn't
30052 output and thus optimize_external_refs will crash. */
30053 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
30054 add_AT_flag (tdie
, DW_AT_external
, 1);
30055 add_AT_flag (tdie
, DW_AT_declaration
, 1);
30056 add_linkage_attr (tdie
, tdecl
);
30057 add_name_and_src_coords_attributes (tdie
, tdecl
, true);
30058 equate_decl_number_to_die (tdecl
, tdie
);
30063 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
30064 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
30065 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
30069 if (AT_index (a
) != NOT_INDEXED
)
30070 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
30071 remove_AT (die
, a
->dw_attr
);
30080 if (remove_AT_byte_size
)
30081 remove_AT (die
, dwarf_version
>= 5
30082 ? DW_AT_string_length_byte_size
30083 : DW_AT_byte_size
);
30085 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
30088 /* Helper routines for optimize_location_lists.
30089 This pass tries to share identical local lists in .debug_loc
30092 /* Iteratively hash operands of LOC opcode into HSTATE. */
30095 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
30097 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
30098 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
30100 switch (loc
->dw_loc_opc
)
30102 case DW_OP_const4u
:
30103 case DW_OP_const8u
:
30107 case DW_OP_const1u
:
30108 case DW_OP_const1s
:
30109 case DW_OP_const2u
:
30110 case DW_OP_const2s
:
30111 case DW_OP_const4s
:
30112 case DW_OP_const8s
:
30116 case DW_OP_plus_uconst
:
30152 case DW_OP_deref_size
:
30153 case DW_OP_xderef_size
:
30154 hstate
.add_object (val1
->v
.val_int
);
30161 gcc_assert (val1
->val_class
== dw_val_class_loc
);
30162 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
30163 hstate
.add_object (offset
);
30166 case DW_OP_implicit_value
:
30167 hstate
.add_object (val1
->v
.val_unsigned
);
30168 switch (val2
->val_class
)
30170 case dw_val_class_const
:
30171 hstate
.add_object (val2
->v
.val_int
);
30173 case dw_val_class_vec
:
30175 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
30176 unsigned int len
= val2
->v
.val_vec
.length
;
30178 hstate
.add_int (elt_size
);
30179 hstate
.add_int (len
);
30180 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
30183 case dw_val_class_const_double
:
30184 hstate
.add_object (val2
->v
.val_double
.low
);
30185 hstate
.add_object (val2
->v
.val_double
.high
);
30187 case dw_val_class_wide_int
:
30188 hstate
.add (val2
->v
.val_wide
->get_val (),
30189 get_full_len (*val2
->v
.val_wide
)
30190 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
30192 case dw_val_class_addr
:
30193 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
30196 gcc_unreachable ();
30200 case DW_OP_bit_piece
:
30201 hstate
.add_object (val1
->v
.val_int
);
30202 hstate
.add_object (val2
->v
.val_int
);
30208 unsigned char dtprel
= 0xd1;
30209 hstate
.add_object (dtprel
);
30211 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
30213 case DW_OP_GNU_addr_index
:
30214 case DW_OP_GNU_const_index
:
30218 unsigned char dtprel
= 0xd1;
30219 hstate
.add_object (dtprel
);
30221 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
30224 case DW_OP_implicit_pointer
:
30225 case DW_OP_GNU_implicit_pointer
:
30226 hstate
.add_int (val2
->v
.val_int
);
30228 case DW_OP_entry_value
:
30229 case DW_OP_GNU_entry_value
:
30230 hstate
.add_object (val1
->v
.val_loc
);
30232 case DW_OP_regval_type
:
30233 case DW_OP_deref_type
:
30234 case DW_OP_GNU_regval_type
:
30235 case DW_OP_GNU_deref_type
:
30237 unsigned int byte_size
30238 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
30239 unsigned int encoding
30240 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
30241 hstate
.add_object (val1
->v
.val_int
);
30242 hstate
.add_object (byte_size
);
30243 hstate
.add_object (encoding
);
30246 case DW_OP_convert
:
30247 case DW_OP_reinterpret
:
30248 case DW_OP_GNU_convert
:
30249 case DW_OP_GNU_reinterpret
:
30250 if (val1
->val_class
== dw_val_class_unsigned_const
)
30252 hstate
.add_object (val1
->v
.val_unsigned
);
30256 case DW_OP_const_type
:
30257 case DW_OP_GNU_const_type
:
30259 unsigned int byte_size
30260 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
30261 unsigned int encoding
30262 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
30263 hstate
.add_object (byte_size
);
30264 hstate
.add_object (encoding
);
30265 if (loc
->dw_loc_opc
!= DW_OP_const_type
30266 && loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
30268 hstate
.add_object (val2
->val_class
);
30269 switch (val2
->val_class
)
30271 case dw_val_class_const
:
30272 hstate
.add_object (val2
->v
.val_int
);
30274 case dw_val_class_vec
:
30276 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
30277 unsigned int len
= val2
->v
.val_vec
.length
;
30279 hstate
.add_object (elt_size
);
30280 hstate
.add_object (len
);
30281 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
30284 case dw_val_class_const_double
:
30285 hstate
.add_object (val2
->v
.val_double
.low
);
30286 hstate
.add_object (val2
->v
.val_double
.high
);
30288 case dw_val_class_wide_int
:
30289 hstate
.add (val2
->v
.val_wide
->get_val (),
30290 get_full_len (*val2
->v
.val_wide
)
30291 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
30294 gcc_unreachable ();
30300 /* Other codes have no operands. */
30305 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
30308 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
30310 dw_loc_descr_ref l
;
30311 bool sizes_computed
= false;
30312 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
30313 size_of_locs (loc
);
30315 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
30317 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
30318 hstate
.add_object (opc
);
30319 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
30321 size_of_locs (loc
);
30322 sizes_computed
= true;
30324 hash_loc_operands (l
, hstate
);
30328 /* Compute hash of the whole location list LIST_HEAD. */
30331 hash_loc_list (dw_loc_list_ref list_head
)
30333 dw_loc_list_ref curr
= list_head
;
30334 inchash::hash hstate
;
30336 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
30338 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
30339 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
30340 hstate
.add_object (curr
->vbegin
);
30341 hstate
.add_object (curr
->vend
);
30343 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
30344 hash_locs (curr
->expr
, hstate
);
30346 list_head
->hash
= hstate
.end ();
30349 /* Return true if X and Y opcodes have the same operands. */
30352 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
30354 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
30355 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
30356 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
30357 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
30359 switch (x
->dw_loc_opc
)
30361 case DW_OP_const4u
:
30362 case DW_OP_const8u
:
30366 case DW_OP_const1u
:
30367 case DW_OP_const1s
:
30368 case DW_OP_const2u
:
30369 case DW_OP_const2s
:
30370 case DW_OP_const4s
:
30371 case DW_OP_const8s
:
30375 case DW_OP_plus_uconst
:
30411 case DW_OP_deref_size
:
30412 case DW_OP_xderef_size
:
30413 return valx1
->v
.val_int
== valy1
->v
.val_int
;
30416 /* If splitting debug info, the use of DW_OP_GNU_addr_index
30417 can cause irrelevant differences in dw_loc_addr. */
30418 gcc_assert (valx1
->val_class
== dw_val_class_loc
30419 && valy1
->val_class
== dw_val_class_loc
30420 && (dwarf_split_debug_info
30421 || x
->dw_loc_addr
== y
->dw_loc_addr
));
30422 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
30423 case DW_OP_implicit_value
:
30424 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
30425 || valx2
->val_class
!= valy2
->val_class
)
30427 switch (valx2
->val_class
)
30429 case dw_val_class_const
:
30430 return valx2
->v
.val_int
== valy2
->v
.val_int
;
30431 case dw_val_class_vec
:
30432 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
30433 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
30434 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
30435 valx2
->v
.val_vec
.elt_size
30436 * valx2
->v
.val_vec
.length
) == 0;
30437 case dw_val_class_const_double
:
30438 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
30439 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
30440 case dw_val_class_wide_int
:
30441 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
30442 case dw_val_class_addr
:
30443 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
30445 gcc_unreachable ();
30448 case DW_OP_bit_piece
:
30449 return valx1
->v
.val_int
== valy1
->v
.val_int
30450 && valx2
->v
.val_int
== valy2
->v
.val_int
;
30453 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
30454 case DW_OP_GNU_addr_index
:
30455 case DW_OP_GNU_const_index
:
30457 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
30458 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
30459 return rtx_equal_p (ax1
, ay1
);
30461 case DW_OP_implicit_pointer
:
30462 case DW_OP_GNU_implicit_pointer
:
30463 return valx1
->val_class
== dw_val_class_die_ref
30464 && valx1
->val_class
== valy1
->val_class
30465 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
30466 && valx2
->v
.val_int
== valy2
->v
.val_int
;
30467 case DW_OP_entry_value
:
30468 case DW_OP_GNU_entry_value
:
30469 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
30470 case DW_OP_const_type
:
30471 case DW_OP_GNU_const_type
:
30472 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
30473 || valx2
->val_class
!= valy2
->val_class
)
30475 switch (valx2
->val_class
)
30477 case dw_val_class_const
:
30478 return valx2
->v
.val_int
== valy2
->v
.val_int
;
30479 case dw_val_class_vec
:
30480 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
30481 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
30482 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
30483 valx2
->v
.val_vec
.elt_size
30484 * valx2
->v
.val_vec
.length
) == 0;
30485 case dw_val_class_const_double
:
30486 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
30487 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
30488 case dw_val_class_wide_int
:
30489 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
30491 gcc_unreachable ();
30493 case DW_OP_regval_type
:
30494 case DW_OP_deref_type
:
30495 case DW_OP_GNU_regval_type
:
30496 case DW_OP_GNU_deref_type
:
30497 return valx1
->v
.val_int
== valy1
->v
.val_int
30498 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
30499 case DW_OP_convert
:
30500 case DW_OP_reinterpret
:
30501 case DW_OP_GNU_convert
:
30502 case DW_OP_GNU_reinterpret
:
30503 if (valx1
->val_class
!= valy1
->val_class
)
30505 if (valx1
->val_class
== dw_val_class_unsigned_const
)
30506 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
30507 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
30508 case DW_OP_GNU_parameter_ref
:
30509 return valx1
->val_class
== dw_val_class_die_ref
30510 && valx1
->val_class
== valy1
->val_class
30511 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
30513 /* Other codes have no operands. */
30518 /* Return true if DWARF location expressions X and Y are the same. */
30521 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
30523 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
30524 if (x
->dw_loc_opc
!= y
->dw_loc_opc
30525 || x
->dtprel
!= y
->dtprel
30526 || !compare_loc_operands (x
, y
))
30528 return x
== NULL
&& y
== NULL
;
30531 /* Hashtable helpers. */
30533 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
30535 static inline hashval_t
hash (const dw_loc_list_struct
*);
30536 static inline bool equal (const dw_loc_list_struct
*,
30537 const dw_loc_list_struct
*);
30540 /* Return precomputed hash of location list X. */
30543 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
30548 /* Return true if location lists A and B are the same. */
30551 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
30552 const dw_loc_list_struct
*b
)
30556 if (a
->hash
!= b
->hash
)
30558 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
30559 if (strcmp (a
->begin
, b
->begin
) != 0
30560 || strcmp (a
->end
, b
->end
) != 0
30561 || (a
->section
== NULL
) != (b
->section
== NULL
)
30562 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
30563 || a
->vbegin
!= b
->vbegin
|| a
->vend
!= b
->vend
30564 || !compare_locs (a
->expr
, b
->expr
))
30566 return a
== NULL
&& b
== NULL
;
30569 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
30572 /* Recursively optimize location lists referenced from DIE
30573 children and share them whenever possible. */
30576 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
30581 dw_loc_list_struct
**slot
;
30582 bool drop_locviews
= false;
30583 bool has_locviews
= false;
30585 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30586 if (AT_class (a
) == dw_val_class_loc_list
)
30588 dw_loc_list_ref list
= AT_loc_list (a
);
30589 /* TODO: perform some optimizations here, before hashing
30590 it and storing into the hash table. */
30591 hash_loc_list (list
);
30592 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
30596 if (loc_list_has_views (list
))
30597 gcc_assert (list
->vl_symbol
);
30598 else if (list
->vl_symbol
)
30600 drop_locviews
= true;
30601 list
->vl_symbol
= NULL
;
30606 if (list
->vl_symbol
&& !(*slot
)->vl_symbol
)
30607 drop_locviews
= true;
30608 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
30611 else if (AT_class (a
) == dw_val_class_view_list
)
30613 gcc_checking_assert (a
->dw_attr
== DW_AT_GNU_locviews
);
30614 has_locviews
= true;
30618 if (drop_locviews
&& has_locviews
)
30619 remove_AT (die
, DW_AT_GNU_locviews
);
30621 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
30625 /* Recursively assign each location list a unique index into the debug_addr
30629 index_location_lists (dw_die_ref die
)
30635 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30636 if (AT_class (a
) == dw_val_class_loc_list
)
30638 dw_loc_list_ref list
= AT_loc_list (a
);
30639 dw_loc_list_ref curr
;
30640 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
30642 /* Don't index an entry that has already been indexed
30643 or won't be output. */
30644 if (curr
->begin_entry
!= NULL
30645 || skip_loc_list_entry (curr
))
30649 = add_addr_table_entry (xstrdup (curr
->begin
), ate_kind_label
);
30653 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
30656 /* Optimize location lists referenced from DIE
30657 children and share them whenever possible. */
30660 optimize_location_lists (dw_die_ref die
)
30662 loc_list_hash_type
htab (500);
30663 optimize_location_lists_1 (die
, &htab
);
30666 /* Traverse the limbo die list, and add parent/child links. The only
30667 dies without parents that should be here are concrete instances of
30668 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
30669 For concrete instances, we can get the parent die from the abstract
30673 flush_limbo_die_list (void)
30675 limbo_die_node
*node
;
30677 /* get_context_die calls force_decl_die, which can put new DIEs on the
30678 limbo list in LTO mode when nested functions are put in a different
30679 partition than that of their parent function. */
30680 while ((node
= limbo_die_list
))
30682 dw_die_ref die
= node
->die
;
30683 limbo_die_list
= node
->next
;
30685 if (die
->die_parent
== NULL
)
30687 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
30689 if (origin
&& origin
->die_parent
)
30690 add_child_die (origin
->die_parent
, die
);
30691 else if (is_cu_die (die
))
30693 else if (seen_error ())
30694 /* It's OK to be confused by errors in the input. */
30695 add_child_die (comp_unit_die (), die
);
30698 /* In certain situations, the lexical block containing a
30699 nested function can be optimized away, which results
30700 in the nested function die being orphaned. Likewise
30701 with the return type of that nested function. Force
30702 this to be a child of the containing function.
30704 It may happen that even the containing function got fully
30705 inlined and optimized out. In that case we are lost and
30706 assign the empty child. This should not be big issue as
30707 the function is likely unreachable too. */
30708 gcc_assert (node
->created_for
);
30710 if (DECL_P (node
->created_for
))
30711 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
30712 else if (TYPE_P (node
->created_for
))
30713 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
30715 origin
= comp_unit_die ();
30717 add_child_die (origin
, die
);
30723 /* Reset DIEs so we can output them again. */
30726 reset_dies (dw_die_ref die
)
30730 /* Remove stuff we re-generate. */
30732 die
->die_offset
= 0;
30733 die
->die_abbrev
= 0;
30734 remove_AT (die
, DW_AT_sibling
);
30736 FOR_EACH_CHILD (die
, c
, reset_dies (c
));
30739 /* Output stuff that dwarf requires at the end of every file,
30740 and generate the DWARF-2 debugging info. */
30743 dwarf2out_finish (const char *)
30745 comdat_type_node
*ctnode
;
30746 dw_die_ref main_comp_unit_die
;
30747 unsigned char checksum
[16];
30748 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
30750 /* Flush out any latecomers to the limbo party. */
30751 flush_limbo_die_list ();
30753 if (inline_entry_data_table
)
30754 gcc_assert (inline_entry_data_table
->elements () == 0);
30758 verify_die (comp_unit_die ());
30759 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
30760 verify_die (node
->die
);
30763 /* We shouldn't have any symbols with delayed asm names for
30764 DIEs generated after early finish. */
30765 gcc_assert (deferred_asm_name
== NULL
);
30767 gen_remaining_tmpl_value_param_die_attribute ();
30769 if (flag_generate_lto
|| flag_generate_offload
)
30771 gcc_assert (flag_fat_lto_objects
|| flag_generate_offload
);
30773 /* Prune stuff so that dwarf2out_finish runs successfully
30774 for the fat part of the object. */
30775 reset_dies (comp_unit_die ());
30776 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
30777 reset_dies (node
->die
);
30779 hash_table
<comdat_type_hasher
> comdat_type_table (100);
30780 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
30782 comdat_type_node
**slot
30783 = comdat_type_table
.find_slot (ctnode
, INSERT
);
30785 /* Don't reset types twice. */
30786 if (*slot
!= HTAB_EMPTY_ENTRY
)
30789 /* Add a pointer to the line table for the main compilation unit
30790 so that the debugger can make sense of DW_AT_decl_file
30792 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
30793 reset_dies (ctnode
->root_die
);
30798 /* Reset die CU symbol so we don't output it twice. */
30799 comp_unit_die ()->die_id
.die_symbol
= NULL
;
30801 /* Remove DW_AT_macro from the early output. */
30803 remove_AT (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
);
30805 /* Remove indirect string decisions. */
30806 debug_str_hash
->traverse
<void *, reset_indirect_string
> (NULL
);
30809 #if ENABLE_ASSERT_CHECKING
30811 dw_die_ref die
= comp_unit_die (), c
;
30812 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
30815 resolve_addr (comp_unit_die ());
30816 move_marked_base_types ();
30818 /* Initialize sections and labels used for actual assembler output. */
30819 unsigned generation
= init_sections_and_labels (false);
30821 /* Traverse the DIE's and add sibling attributes to those DIE's that
30823 add_sibling_attributes (comp_unit_die ());
30824 limbo_die_node
*node
;
30825 for (node
= cu_die_list
; node
; node
= node
->next
)
30826 add_sibling_attributes (node
->die
);
30827 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
30828 add_sibling_attributes (ctnode
->root_die
);
30830 /* When splitting DWARF info, we put some attributes in the
30831 skeleton compile_unit DIE that remains in the .o, while
30832 most attributes go in the DWO compile_unit_die. */
30833 if (dwarf_split_debug_info
)
30835 limbo_die_node
*cu
;
30836 main_comp_unit_die
= gen_compile_unit_die (NULL
);
30837 if (dwarf_version
>= 5)
30838 main_comp_unit_die
->die_tag
= DW_TAG_skeleton_unit
;
30839 cu
= limbo_die_list
;
30840 gcc_assert (cu
->die
== main_comp_unit_die
);
30841 limbo_die_list
= limbo_die_list
->next
;
30842 cu
->next
= cu_die_list
;
30846 main_comp_unit_die
= comp_unit_die ();
30848 /* Output a terminator label for the .text section. */
30849 switch_to_section (text_section
);
30850 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
30851 if (cold_text_section
)
30853 switch_to_section (cold_text_section
);
30854 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
30857 /* We can only use the low/high_pc attributes if all of the code was
30859 if (!have_multiple_function_sections
30860 || (dwarf_version
< 3 && dwarf_strict
))
30862 /* Don't add if the CU has no associated code. */
30863 if (text_section_used
)
30864 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
30865 text_end_label
, true);
30871 bool range_list_added
= false;
30873 if (text_section_used
)
30874 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
30875 text_end_label
, &range_list_added
, true);
30876 if (cold_text_section_used
)
30877 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
30878 cold_end_label
, &range_list_added
, true);
30880 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
30882 if (DECL_IGNORED_P (fde
->decl
))
30884 if (!fde
->in_std_section
)
30885 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
30886 fde
->dw_fde_end
, &range_list_added
,
30888 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
30889 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
30890 fde
->dw_fde_second_end
, &range_list_added
,
30894 if (range_list_added
)
30896 /* We need to give .debug_loc and .debug_ranges an appropriate
30897 "base address". Use zero so that these addresses become
30898 absolute. Historically, we've emitted the unexpected
30899 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
30900 Emit both to give time for other tools to adapt. */
30901 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
30902 if (! dwarf_strict
&& dwarf_version
< 4)
30903 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
30909 /* AIX Assembler inserts the length, so adjust the reference to match the
30910 offset expected by debuggers. */
30911 strcpy (dl_section_ref
, debug_line_section_label
);
30912 if (XCOFF_DEBUGGING_INFO
)
30913 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
30915 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
30916 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
30920 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
30921 macinfo_section_label
);
30923 if (dwarf_split_debug_info
)
30925 if (have_location_lists
)
30927 if (dwarf_version
>= 5)
30928 add_AT_loclistsptr (comp_unit_die (), DW_AT_loclists_base
,
30929 loc_section_label
);
30930 /* optimize_location_lists calculates the size of the lists,
30931 so index them first, and assign indices to the entries.
30932 Although optimize_location_lists will remove entries from
30933 the table, it only does so for duplicates, and therefore
30934 only reduces ref_counts to 1. */
30935 index_location_lists (comp_unit_die ());
30938 if (addr_index_table
!= NULL
)
30940 unsigned int index
= 0;
30942 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
30948 if (have_location_lists
)
30950 optimize_location_lists (comp_unit_die ());
30951 /* And finally assign indexes to the entries for -gsplit-dwarf. */
30952 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
30953 assign_location_list_indexes (comp_unit_die ());
30956 save_macinfo_strings ();
30958 if (dwarf_split_debug_info
)
30960 unsigned int index
= 0;
30962 /* Add attributes common to skeleton compile_units and
30963 type_units. Because these attributes include strings, it
30964 must be done before freezing the string table. Top-level
30965 skeleton die attrs are added when the skeleton type unit is
30966 created, so ensure it is created by this point. */
30967 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
30968 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
30971 /* Output all of the compilation units. We put the main one last so that
30972 the offsets are available to output_pubnames. */
30973 for (node
= cu_die_list
; node
; node
= node
->next
)
30974 output_comp_unit (node
->die
, 0, NULL
);
30976 hash_table
<comdat_type_hasher
> comdat_type_table (100);
30977 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
30979 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
30981 /* Don't output duplicate types. */
30982 if (*slot
!= HTAB_EMPTY_ENTRY
)
30985 /* Add a pointer to the line table for the main compilation unit
30986 so that the debugger can make sense of DW_AT_decl_file
30988 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
30989 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
30990 (!dwarf_split_debug_info
30992 : debug_skeleton_line_section_label
));
30994 output_comdat_type_unit (ctnode
);
30998 if (dwarf_split_debug_info
)
31001 struct md5_ctx ctx
;
31003 if (dwarf_version
>= 5 && !vec_safe_is_empty (ranges_table
))
31006 /* Compute a checksum of the comp_unit to use as the dwo_id. */
31007 md5_init_ctx (&ctx
);
31009 die_checksum (comp_unit_die (), &ctx
, &mark
);
31010 unmark_all_dies (comp_unit_die ());
31011 md5_finish_ctx (&ctx
, checksum
);
31013 if (dwarf_version
< 5)
31015 /* Use the first 8 bytes of the checksum as the dwo_id,
31016 and add it to both comp-unit DIEs. */
31017 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
31018 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
31021 /* Add the base offset of the ranges table to the skeleton
31023 if (!vec_safe_is_empty (ranges_table
))
31025 if (dwarf_version
>= 5)
31026 add_AT_lineptr (main_comp_unit_die
, DW_AT_rnglists_base
,
31027 ranges_base_label
);
31029 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
31030 ranges_section_label
);
31033 switch_to_section (debug_addr_section
);
31034 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
31035 output_addr_table ();
31038 /* Output the main compilation unit if non-empty or if .debug_macinfo
31039 or .debug_macro will be emitted. */
31040 output_comp_unit (comp_unit_die (), have_macinfo
,
31041 dwarf_split_debug_info
? checksum
: NULL
);
31043 if (dwarf_split_debug_info
&& info_section_emitted
)
31044 output_skeleton_debug_sections (main_comp_unit_die
, checksum
);
31046 /* Output the abbreviation table. */
31047 if (vec_safe_length (abbrev_die_table
) != 1)
31049 switch_to_section (debug_abbrev_section
);
31050 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
31051 output_abbrev_section ();
31054 /* Output location list section if necessary. */
31055 if (have_location_lists
)
31057 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
31058 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
31059 /* Output the location lists info. */
31060 switch_to_section (debug_loc_section
);
31061 if (dwarf_version
>= 5)
31063 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_LOC_SECTION_LABEL
, 1);
31064 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_LOC_SECTION_LABEL
, 2);
31065 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
31066 dw2_asm_output_data (4, 0xffffffff,
31067 "Initial length escape value indicating "
31068 "64-bit DWARF extension");
31069 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
31070 "Length of Location Lists");
31071 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
31072 output_dwarf_version ();
31073 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
31074 dw2_asm_output_data (1, 0, "Segment Size");
31075 dw2_asm_output_data (4, dwarf_split_debug_info
? loc_list_idx
: 0,
31076 "Offset Entry Count");
31078 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
31079 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
31081 unsigned int save_loc_list_idx
= loc_list_idx
;
31083 output_loclists_offsets (comp_unit_die ());
31084 gcc_assert (save_loc_list_idx
== loc_list_idx
);
31086 output_location_lists (comp_unit_die ());
31087 if (dwarf_version
>= 5)
31088 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
31091 output_pubtables ();
31093 /* Output the address range information if a CU (.debug_info section)
31094 was emitted. We output an empty table even if we had no functions
31095 to put in it. This because the consumer has no way to tell the
31096 difference between an empty table that we omitted and failure to
31097 generate a table that would have contained data. */
31098 if (info_section_emitted
)
31100 switch_to_section (debug_aranges_section
);
31104 /* Output ranges section if necessary. */
31105 if (!vec_safe_is_empty (ranges_table
))
31107 if (dwarf_version
>= 5)
31108 output_rnglists (generation
);
31113 /* Have to end the macro section. */
31116 switch_to_section (debug_macinfo_section
);
31117 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
31118 output_macinfo (!dwarf_split_debug_info
? debug_line_section_label
31119 : debug_skeleton_line_section_label
, false);
31120 dw2_asm_output_data (1, 0, "End compilation unit");
31123 /* Output the source line correspondence table. We must do this
31124 even if there is no line information. Otherwise, on an empty
31125 translation unit, we will generate a present, but empty,
31126 .debug_info section. IRIX 6.5 `nm' will then complain when
31127 examining the file. This is done late so that any filenames
31128 used by the debug_info section are marked as 'used'. */
31129 switch_to_section (debug_line_section
);
31130 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
31131 if (! output_asm_line_debug_info ())
31132 output_line_info (false);
31134 if (dwarf_split_debug_info
&& info_section_emitted
)
31136 switch_to_section (debug_skeleton_line_section
);
31137 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
31138 output_line_info (true);
31141 /* If we emitted any indirect strings, output the string table too. */
31142 if (debug_str_hash
|| skeleton_debug_str_hash
)
31143 output_indirect_strings ();
31144 if (debug_line_str_hash
)
31146 switch_to_section (debug_line_str_section
);
31147 const enum dwarf_form form
= DW_FORM_line_strp
;
31148 debug_line_str_hash
->traverse
<enum dwarf_form
,
31149 output_indirect_string
> (form
);
31153 /* Returns a hash value for X (which really is a variable_value_struct). */
31156 variable_value_hasher::hash (variable_value_struct
*x
)
31158 return (hashval_t
) x
->decl_id
;
31161 /* Return nonzero if decl_id of variable_value_struct X is the same as
31165 variable_value_hasher::equal (variable_value_struct
*x
, tree y
)
31167 return x
->decl_id
== DECL_UID (y
);
31170 /* Helper function for resolve_variable_value, handle
31171 DW_OP_GNU_variable_value in one location expression.
31172 Return true if exprloc has been changed into loclist. */
31175 resolve_variable_value_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
31177 dw_loc_descr_ref next
;
31178 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= next
)
31180 next
= loc
->dw_loc_next
;
31181 if (loc
->dw_loc_opc
!= DW_OP_GNU_variable_value
31182 || loc
->dw_loc_oprnd1
.val_class
!= dw_val_class_decl_ref
)
31185 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
31186 if (DECL_CONTEXT (decl
) != current_function_decl
)
31189 dw_die_ref ref
= lookup_decl_die (decl
);
31192 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
31193 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
31194 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
31197 dw_loc_list_ref l
= loc_list_from_tree (decl
, 0, NULL
);
31200 if (l
->dw_loc_next
)
31202 if (AT_class (a
) != dw_val_class_loc
)
31204 switch (a
->dw_attr
)
31206 /* Following attributes allow both exprloc and loclist
31207 classes, so we can change them into a loclist. */
31208 case DW_AT_location
:
31209 case DW_AT_string_length
:
31210 case DW_AT_return_addr
:
31211 case DW_AT_data_member_location
:
31212 case DW_AT_frame_base
:
31213 case DW_AT_segment
:
31214 case DW_AT_static_link
:
31215 case DW_AT_use_location
:
31216 case DW_AT_vtable_elem_location
:
31219 prev
->dw_loc_next
= NULL
;
31220 prepend_loc_descr_to_each (l
, AT_loc (a
));
31223 add_loc_descr_to_each (l
, next
);
31224 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
31225 a
->dw_attr_val
.val_entry
= NULL
;
31226 a
->dw_attr_val
.v
.val_loc_list
= l
;
31227 have_location_lists
= true;
31229 /* Following attributes allow both exprloc and reference,
31230 so if the whole expression is DW_OP_GNU_variable_value alone
31231 we could transform it into reference. */
31232 case DW_AT_byte_size
:
31233 case DW_AT_bit_size
:
31234 case DW_AT_lower_bound
:
31235 case DW_AT_upper_bound
:
31236 case DW_AT_bit_stride
:
31238 case DW_AT_allocated
:
31239 case DW_AT_associated
:
31240 case DW_AT_byte_stride
:
31241 if (prev
== NULL
&& next
== NULL
)
31249 /* Create DW_TAG_variable that we can refer to. */
31250 gen_decl_die (decl
, NULL_TREE
, NULL
,
31251 lookup_decl_die (current_function_decl
));
31252 ref
= lookup_decl_die (decl
);
31255 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
31256 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
31257 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
31263 prev
->dw_loc_next
= l
->expr
;
31264 add_loc_descr (&prev
->dw_loc_next
, next
);
31265 free_loc_descr (loc
, NULL
);
31266 next
= prev
->dw_loc_next
;
31270 memcpy (loc
, l
->expr
, sizeof (dw_loc_descr_node
));
31271 add_loc_descr (&loc
, next
);
31279 /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree. */
31282 resolve_variable_value (dw_die_ref die
)
31285 dw_loc_list_ref loc
;
31288 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
31289 switch (AT_class (a
))
31291 case dw_val_class_loc
:
31292 if (!resolve_variable_value_in_expr (a
, AT_loc (a
)))
31295 case dw_val_class_loc_list
:
31296 loc
= AT_loc_list (a
);
31298 for (; loc
; loc
= loc
->dw_loc_next
)
31299 resolve_variable_value_in_expr (a
, loc
->expr
);
31306 /* Attempt to optimize DW_OP_GNU_variable_value refering to
31307 temporaries in the current function. */
31310 resolve_variable_values (void)
31312 if (!variable_value_hash
|| !current_function_decl
)
31315 struct variable_value_struct
*node
31316 = variable_value_hash
->find_with_hash (current_function_decl
,
31317 DECL_UID (current_function_decl
));
31324 FOR_EACH_VEC_SAFE_ELT (node
->dies
, i
, die
)
31325 resolve_variable_value (die
);
31328 /* Helper function for note_variable_value, handle one location
31332 note_variable_value_in_expr (dw_die_ref die
, dw_loc_descr_ref loc
)
31334 for (; loc
; loc
= loc
->dw_loc_next
)
31335 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
31336 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
31338 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
31339 dw_die_ref ref
= lookup_decl_die (decl
);
31340 if (! ref
&& (flag_generate_lto
|| flag_generate_offload
))
31342 /* ??? This is somewhat a hack because we do not create DIEs
31343 for variables not in BLOCK trees early but when generating
31344 early LTO output we need the dw_val_class_decl_ref to be
31345 fully resolved. For fat LTO objects we'd also like to
31346 undo this after LTO dwarf output. */
31347 gcc_assert (DECL_CONTEXT (decl
));
31348 dw_die_ref ctx
= lookup_decl_die (DECL_CONTEXT (decl
));
31349 gcc_assert (ctx
!= NULL
);
31350 gen_decl_die (decl
, NULL_TREE
, NULL
, ctx
);
31351 ref
= lookup_decl_die (decl
);
31352 gcc_assert (ref
!= NULL
);
31356 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
31357 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
31358 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
31362 && DECL_CONTEXT (decl
)
31363 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
31364 && lookup_decl_die (DECL_CONTEXT (decl
)))
31366 if (!variable_value_hash
)
31367 variable_value_hash
31368 = hash_table
<variable_value_hasher
>::create_ggc (10);
31370 tree fndecl
= DECL_CONTEXT (decl
);
31371 struct variable_value_struct
*node
;
31372 struct variable_value_struct
**slot
31373 = variable_value_hash
->find_slot_with_hash (fndecl
,
31378 node
= ggc_cleared_alloc
<variable_value_struct
> ();
31379 node
->decl_id
= DECL_UID (fndecl
);
31385 vec_safe_push (node
->dies
, die
);
31390 /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
31391 with dw_val_class_decl_ref operand. */
31394 note_variable_value (dw_die_ref die
)
31398 dw_loc_list_ref loc
;
31401 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
31402 switch (AT_class (a
))
31404 case dw_val_class_loc_list
:
31405 loc
= AT_loc_list (a
);
31407 if (!loc
->noted_variable_value
)
31409 loc
->noted_variable_value
= 1;
31410 for (; loc
; loc
= loc
->dw_loc_next
)
31411 note_variable_value_in_expr (die
, loc
->expr
);
31414 case dw_val_class_loc
:
31415 note_variable_value_in_expr (die
, AT_loc (a
));
31421 /* Mark children. */
31422 FOR_EACH_CHILD (die
, c
, note_variable_value (c
));
31425 /* Perform any cleanups needed after the early debug generation pass
31429 dwarf2out_early_finish (const char *filename
)
31433 /* PCH might result in DW_AT_producer string being restored from the
31434 header compilation, so always fill it with empty string initially
31435 and overwrite only here. */
31436 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
31437 producer_string
= gen_producer_string ();
31438 producer
->dw_attr_val
.v
.val_str
->refcount
--;
31439 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
31441 /* Add the name for the main input file now. We delayed this from
31442 dwarf2out_init to avoid complications with PCH. */
31443 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
31444 add_comp_dir_attribute (comp_unit_die ());
31446 /* When emitting DWARF5 .debug_line_str, move DW_AT_name and
31447 DW_AT_comp_dir into .debug_line_str section. */
31448 if (!DWARF2_ASM_LINE_DEBUG_INFO
31449 && dwarf_version
>= 5
31450 && DWARF5_USE_DEBUG_LINE_STR
)
31452 for (int i
= 0; i
< 2; i
++)
31454 dw_attr_node
*a
= get_AT (comp_unit_die (),
31455 i
? DW_AT_comp_dir
: DW_AT_name
);
31457 || AT_class (a
) != dw_val_class_str
31458 || strlen (AT_string (a
)) + 1 <= DWARF_OFFSET_SIZE
)
31461 if (! debug_line_str_hash
)
31462 debug_line_str_hash
31463 = hash_table
<indirect_string_hasher
>::create_ggc (10);
31465 struct indirect_string_node
*node
31466 = find_AT_string_in_table (AT_string (a
), debug_line_str_hash
);
31467 set_indirect_string (node
);
31468 node
->form
= DW_FORM_line_strp
;
31469 a
->dw_attr_val
.v
.val_str
->refcount
--;
31470 a
->dw_attr_val
.v
.val_str
= node
;
31474 /* With LTO early dwarf was really finished at compile-time, so make
31475 sure to adjust the phase after annotating the LTRANS CU DIE. */
31478 early_dwarf_finished
= true;
31482 /* Walk through the list of incomplete types again, trying once more to
31483 emit full debugging info for them. */
31484 retry_incomplete_types ();
31486 /* The point here is to flush out the limbo list so that it is empty
31487 and we don't need to stream it for LTO. */
31488 flush_limbo_die_list ();
31490 gen_scheduled_generic_parms_dies ();
31491 gen_remaining_tmpl_value_param_die_attribute ();
31493 /* Add DW_AT_linkage_name for all deferred DIEs. */
31494 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
31496 tree decl
= node
->created_for
;
31497 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
31498 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
31499 ended up in deferred_asm_name before we knew it was
31500 constant and never written to disk. */
31501 && DECL_ASSEMBLER_NAME (decl
))
31503 add_linkage_attr (node
->die
, decl
);
31504 move_linkage_attr (node
->die
);
31507 deferred_asm_name
= NULL
;
31509 if (flag_eliminate_unused_debug_types
)
31510 prune_unused_types ();
31512 /* Generate separate COMDAT sections for type DIEs. */
31513 if (use_debug_types
)
31515 break_out_comdat_types (comp_unit_die ());
31517 /* Each new type_unit DIE was added to the limbo die list when created.
31518 Since these have all been added to comdat_type_list, clear the
31520 limbo_die_list
= NULL
;
31522 /* For each new comdat type unit, copy declarations for incomplete
31523 types to make the new unit self-contained (i.e., no direct
31524 references to the main compile unit). */
31525 for (comdat_type_node
*ctnode
= comdat_type_list
;
31526 ctnode
!= NULL
; ctnode
= ctnode
->next
)
31527 copy_decls_for_unworthy_types (ctnode
->root_die
);
31528 copy_decls_for_unworthy_types (comp_unit_die ());
31530 /* In the process of copying declarations from one unit to another,
31531 we may have left some declarations behind that are no longer
31532 referenced. Prune them. */
31533 prune_unused_types ();
31536 /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
31537 with dw_val_class_decl_ref operand. */
31538 note_variable_value (comp_unit_die ());
31539 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
31540 note_variable_value (node
->die
);
31541 for (comdat_type_node
*ctnode
= comdat_type_list
; ctnode
!= NULL
;
31542 ctnode
= ctnode
->next
)
31543 note_variable_value (ctnode
->root_die
);
31544 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
31545 note_variable_value (node
->die
);
31547 /* The AT_pubnames attribute needs to go in all skeleton dies, including
31548 both the main_cu and all skeleton TUs. Making this call unconditional
31549 would end up either adding a second copy of the AT_pubnames attribute, or
31550 requiring a special case in add_top_level_skeleton_die_attrs. */
31551 if (!dwarf_split_debug_info
)
31552 add_AT_pubnames (comp_unit_die ());
31554 /* The early debug phase is now finished. */
31555 early_dwarf_finished
= true;
31557 /* Do not generate DWARF assembler now when not producing LTO bytecode. */
31558 if (!flag_generate_lto
&& !flag_generate_offload
)
31561 /* Now as we are going to output for LTO initialize sections and labels
31562 to the LTO variants. We don't need a random-seed postfix as other
31563 LTO sections as linking the LTO debug sections into one in a partial
31565 init_sections_and_labels (true);
31567 /* The output below is modeled after dwarf2out_finish with all
31568 location related output removed and some LTO specific changes.
31569 Some refactoring might make both smaller and easier to match up. */
31571 /* Traverse the DIE's and add add sibling attributes to those DIE's
31572 that have children. */
31573 add_sibling_attributes (comp_unit_die ());
31574 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
31575 add_sibling_attributes (node
->die
);
31576 for (comdat_type_node
*ctnode
= comdat_type_list
;
31577 ctnode
!= NULL
; ctnode
= ctnode
->next
)
31578 add_sibling_attributes (ctnode
->root_die
);
31581 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
31582 macinfo_section_label
);
31584 save_macinfo_strings ();
31586 if (dwarf_split_debug_info
)
31588 unsigned int index
= 0;
31589 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
31592 /* Output all of the compilation units. We put the main one last so that
31593 the offsets are available to output_pubnames. */
31594 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
31595 output_comp_unit (node
->die
, 0, NULL
);
31597 hash_table
<comdat_type_hasher
> comdat_type_table (100);
31598 for (comdat_type_node
*ctnode
= comdat_type_list
;
31599 ctnode
!= NULL
; ctnode
= ctnode
->next
)
31601 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
31603 /* Don't output duplicate types. */
31604 if (*slot
!= HTAB_EMPTY_ENTRY
)
31607 /* Add a pointer to the line table for the main compilation unit
31608 so that the debugger can make sense of DW_AT_decl_file
31610 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
31611 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
31612 (!dwarf_split_debug_info
31613 ? debug_line_section_label
31614 : debug_skeleton_line_section_label
));
31616 output_comdat_type_unit (ctnode
);
31620 /* Stick a unique symbol to the main debuginfo section. */
31621 compute_comp_unit_symbol (comp_unit_die ());
31623 /* Output the main compilation unit. We always need it if only for
31625 output_comp_unit (comp_unit_die (), true, NULL
);
31627 /* Output the abbreviation table. */
31628 if (vec_safe_length (abbrev_die_table
) != 1)
31630 switch_to_section (debug_abbrev_section
);
31631 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
31632 output_abbrev_section ();
31635 /* Have to end the macro section. */
31638 /* We have to save macinfo state if we need to output it again
31639 for the FAT part of the object. */
31640 vec
<macinfo_entry
, va_gc
> *saved_macinfo_table
= macinfo_table
;
31641 if (flag_fat_lto_objects
)
31642 macinfo_table
= macinfo_table
->copy ();
31644 switch_to_section (debug_macinfo_section
);
31645 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
31646 output_macinfo (debug_skeleton_line_section_label
, true);
31647 dw2_asm_output_data (1, 0, "End compilation unit");
31649 /* Emit a skeleton debug_line section. */
31650 switch_to_section (debug_skeleton_line_section
);
31651 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
31652 output_line_info (true);
31654 if (flag_fat_lto_objects
)
31656 vec_free (macinfo_table
);
31657 macinfo_table
= saved_macinfo_table
;
31662 /* If we emitted any indirect strings, output the string table too. */
31663 if (debug_str_hash
|| skeleton_debug_str_hash
)
31664 output_indirect_strings ();
31666 /* Switch back to the text section. */
31667 switch_to_section (text_section
);
31670 /* Reset all state within dwarf2out.c so that we can rerun the compiler
31671 within the same process. For use by toplev::finalize. */
31674 dwarf2out_c_finalize (void)
31676 last_var_location_insn
= NULL
;
31677 cached_next_real_insn
= NULL
;
31678 used_rtx_array
= NULL
;
31679 incomplete_types
= NULL
;
31680 decl_scope_table
= NULL
;
31681 debug_info_section
= NULL
;
31682 debug_skeleton_info_section
= NULL
;
31683 debug_abbrev_section
= NULL
;
31684 debug_skeleton_abbrev_section
= NULL
;
31685 debug_aranges_section
= NULL
;
31686 debug_addr_section
= NULL
;
31687 debug_macinfo_section
= NULL
;
31688 debug_line_section
= NULL
;
31689 debug_skeleton_line_section
= NULL
;
31690 debug_loc_section
= NULL
;
31691 debug_pubnames_section
= NULL
;
31692 debug_pubtypes_section
= NULL
;
31693 debug_str_section
= NULL
;
31694 debug_line_str_section
= NULL
;
31695 debug_str_dwo_section
= NULL
;
31696 debug_str_offsets_section
= NULL
;
31697 debug_ranges_section
= NULL
;
31698 debug_frame_section
= NULL
;
31700 debug_str_hash
= NULL
;
31701 debug_line_str_hash
= NULL
;
31702 skeleton_debug_str_hash
= NULL
;
31703 dw2_string_counter
= 0;
31704 have_multiple_function_sections
= false;
31705 text_section_used
= false;
31706 cold_text_section_used
= false;
31707 cold_text_section
= NULL
;
31708 current_unit_personality
= NULL
;
31710 early_dwarf
= false;
31711 early_dwarf_finished
= false;
31713 next_die_offset
= 0;
31714 single_comp_unit_die
= NULL
;
31715 comdat_type_list
= NULL
;
31716 limbo_die_list
= NULL
;
31718 decl_die_table
= NULL
;
31719 common_block_die_table
= NULL
;
31720 decl_loc_table
= NULL
;
31721 call_arg_locations
= NULL
;
31722 call_arg_loc_last
= NULL
;
31723 call_site_count
= -1;
31724 tail_call_site_count
= -1;
31725 cached_dw_loc_list_table
= NULL
;
31726 abbrev_die_table
= NULL
;
31727 delete dwarf_proc_stack_usage_map
;
31728 dwarf_proc_stack_usage_map
= NULL
;
31729 line_info_label_num
= 0;
31730 cur_line_info_table
= NULL
;
31731 text_section_line_info
= NULL
;
31732 cold_text_section_line_info
= NULL
;
31733 separate_line_info
= NULL
;
31734 info_section_emitted
= false;
31735 pubname_table
= NULL
;
31736 pubtype_table
= NULL
;
31737 macinfo_table
= NULL
;
31738 ranges_table
= NULL
;
31739 ranges_by_label
= NULL
;
31741 have_location_lists
= false;
31744 last_emitted_file
= NULL
;
31746 tmpl_value_parm_die_table
= NULL
;
31747 generic_type_instances
= NULL
;
31748 frame_pointer_fb_offset
= 0;
31749 frame_pointer_fb_offset_valid
= false;
31750 base_types
.release ();
31751 XDELETEVEC (producer_string
);
31752 producer_string
= NULL
;
31755 #include "gt-dwarf2out.h"