1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2017 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"
99 static void dwarf2out_source_line (unsigned int, unsigned int, const char *,
101 static rtx_insn
*last_var_location_insn
;
102 static rtx_insn
*cached_next_real_insn
;
103 static void dwarf2out_decl (tree
);
105 #ifndef XCOFF_DEBUGGING_INFO
106 #define XCOFF_DEBUGGING_INFO 0
109 #ifndef HAVE_XCOFF_DWARF_EXTRAS
110 #define HAVE_XCOFF_DWARF_EXTRAS 0
113 #ifdef VMS_DEBUGGING_INFO
114 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
116 /* Define this macro to be a nonzero value if the directory specifications
117 which are output in the debug info should end with a separator. */
118 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
119 /* Define this macro to evaluate to a nonzero value if GCC should refrain
120 from generating indirect strings in DWARF2 debug information, for instance
121 if your target is stuck with an old version of GDB that is unable to
122 process them properly or uses VMS Debug. */
123 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
125 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
126 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
129 /* ??? Poison these here until it can be done generically. They've been
130 totally replaced in this file; make sure it stays that way. */
131 #undef DWARF2_UNWIND_INFO
132 #undef DWARF2_FRAME_INFO
133 #if (GCC_VERSION >= 3000)
134 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
137 /* The size of the target's pointer type. */
139 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
142 /* Array of RTXes referenced by the debugging information, which therefore
143 must be kept around forever. */
144 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
146 /* A pointer to the base of a list of incomplete types which might be
147 completed at some later time. incomplete_types_list needs to be a
148 vec<tree, va_gc> *because we want to tell the garbage collector about
150 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
152 /* A pointer to the base of a table of references to declaration
153 scopes. This table is a display which tracks the nesting
154 of declaration scopes at the current scope and containing
155 scopes. This table is used to find the proper place to
156 define type declaration DIE's. */
157 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
159 /* Pointers to various DWARF2 sections. */
160 static GTY(()) section
*debug_info_section
;
161 static GTY(()) section
*debug_skeleton_info_section
;
162 static GTY(()) section
*debug_abbrev_section
;
163 static GTY(()) section
*debug_skeleton_abbrev_section
;
164 static GTY(()) section
*debug_aranges_section
;
165 static GTY(()) section
*debug_addr_section
;
166 static GTY(()) section
*debug_macinfo_section
;
167 static const char *debug_macinfo_section_name
;
168 static unsigned macinfo_label_base
= 1;
169 static GTY(()) section
*debug_line_section
;
170 static GTY(()) section
*debug_skeleton_line_section
;
171 static GTY(()) section
*debug_loc_section
;
172 static GTY(()) section
*debug_pubnames_section
;
173 static GTY(()) section
*debug_pubtypes_section
;
174 static GTY(()) section
*debug_str_section
;
175 static GTY(()) section
*debug_line_str_section
;
176 static GTY(()) section
*debug_str_dwo_section
;
177 static GTY(()) section
*debug_str_offsets_section
;
178 static GTY(()) section
*debug_ranges_section
;
179 static GTY(()) section
*debug_frame_section
;
181 /* Maximum size (in bytes) of an artificially generated label. */
182 #define MAX_ARTIFICIAL_LABEL_BYTES 40
184 /* According to the (draft) DWARF 3 specification, the initial length
185 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
186 bytes are 0xffffffff, followed by the length stored in the next 8
189 However, the SGI/MIPS ABI uses an initial length which is equal to
190 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
192 #ifndef DWARF_INITIAL_LENGTH_SIZE
193 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
196 #ifndef DWARF_INITIAL_LENGTH_SIZE_STR
197 #define DWARF_INITIAL_LENGTH_SIZE_STR (DWARF_OFFSET_SIZE == 4 ? "-4" : "-12")
200 /* Round SIZE up to the nearest BOUNDARY. */
201 #define DWARF_ROUND(SIZE,BOUNDARY) \
202 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
204 /* CIE identifier. */
205 #if HOST_BITS_PER_WIDE_INT >= 64
206 #define DWARF_CIE_ID \
207 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
209 #define DWARF_CIE_ID DW_CIE_ID
213 /* A vector for a table that contains frame description
214 information for each routine. */
215 #define NOT_INDEXED (-1U)
216 #define NO_INDEX_ASSIGNED (-2U)
218 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
220 struct GTY((for_user
)) indirect_string_node
{
222 unsigned int refcount
;
223 enum dwarf_form form
;
228 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
230 typedef const char *compare_type
;
232 static hashval_t
hash (indirect_string_node
*);
233 static bool equal (indirect_string_node
*, const char *);
236 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
238 static GTY (()) hash_table
<indirect_string_hasher
> *debug_line_str_hash
;
240 /* With split_debug_info, both the comp_dir and dwo_name go in the
241 main object file, rather than the dwo, similar to the force_direct
242 parameter elsewhere but with additional complications:
244 1) The string is needed in both the main object file and the dwo.
245 That is, the comp_dir and dwo_name will appear in both places.
247 2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
248 DW_FORM_line_strp or DW_FORM_GNU_str_index.
250 3) GCC chooses the form to use late, depending on the size and
253 Rather than forcing the all debug string handling functions and
254 callers to deal with these complications, simply use a separate,
255 special-cased string table for any attribute that should go in the
256 main object file. This limits the complexity to just the places
259 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
261 static GTY(()) int dw2_string_counter
;
263 /* True if the compilation unit places functions in more than one section. */
264 static GTY(()) bool have_multiple_function_sections
= false;
266 /* Whether the default text and cold text sections have been used at all. */
267 static GTY(()) bool text_section_used
= false;
268 static GTY(()) bool cold_text_section_used
= false;
270 /* The default cold text section. */
271 static GTY(()) section
*cold_text_section
;
273 /* The DIE for C++14 'auto' in a function return type. */
274 static GTY(()) dw_die_ref auto_die
;
276 /* The DIE for C++14 'decltype(auto)' in a function return type. */
277 static GTY(()) dw_die_ref decltype_auto_die
;
279 /* Forward declarations for functions defined in this file. */
281 static void output_call_frame_info (int);
282 static void dwarf2out_note_section_used (void);
284 /* Personality decl of current unit. Used only when assembler does not support
286 static GTY(()) rtx current_unit_personality
;
288 /* Whether an eh_frame section is required. */
289 static GTY(()) bool do_eh_frame
= false;
291 /* .debug_rnglists next index. */
292 static unsigned int rnglist_idx
;
294 /* Data and reference forms for relocatable data. */
295 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
296 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
298 #ifndef DEBUG_FRAME_SECTION
299 #define DEBUG_FRAME_SECTION ".debug_frame"
302 #ifndef FUNC_BEGIN_LABEL
303 #define FUNC_BEGIN_LABEL "LFB"
306 #ifndef FUNC_END_LABEL
307 #define FUNC_END_LABEL "LFE"
310 #ifndef PROLOGUE_END_LABEL
311 #define PROLOGUE_END_LABEL "LPE"
314 #ifndef EPILOGUE_BEGIN_LABEL
315 #define EPILOGUE_BEGIN_LABEL "LEB"
318 #ifndef FRAME_BEGIN_LABEL
319 #define FRAME_BEGIN_LABEL "Lframe"
321 #define CIE_AFTER_SIZE_LABEL "LSCIE"
322 #define CIE_END_LABEL "LECIE"
323 #define FDE_LABEL "LSFDE"
324 #define FDE_AFTER_SIZE_LABEL "LASFDE"
325 #define FDE_END_LABEL "LEFDE"
326 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
327 #define LINE_NUMBER_END_LABEL "LELT"
328 #define LN_PROLOG_AS_LABEL "LASLTP"
329 #define LN_PROLOG_END_LABEL "LELTP"
330 #define DIE_LABEL_PREFIX "DW"
332 /* Match the base name of a file to the base name of a compilation unit. */
335 matches_main_base (const char *path
)
337 /* Cache the last query. */
338 static const char *last_path
= NULL
;
339 static int last_match
= 0;
340 if (path
!= last_path
)
343 int length
= base_of_path (path
, &base
);
345 last_match
= (length
== main_input_baselength
346 && memcmp (base
, main_input_basename
, length
) == 0);
351 #ifdef DEBUG_DEBUG_STRUCT
354 dump_struct_debug (tree type
, enum debug_info_usage usage
,
355 enum debug_struct_file criterion
, int generic
,
356 int matches
, int result
)
358 /* Find the type name. */
359 tree type_decl
= TYPE_STUB_DECL (type
);
361 const char *name
= 0;
362 if (TREE_CODE (t
) == TYPE_DECL
)
365 name
= IDENTIFIER_POINTER (t
);
367 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
369 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
370 matches
? "bas" : "hdr",
371 generic
? "gen" : "ord",
372 usage
== DINFO_USAGE_DFN
? ";" :
373 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
375 (void*) type_decl
, name
);
378 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
379 dump_struct_debug (type, usage, criterion, generic, matches, result)
383 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
388 /* Get the number of HOST_WIDE_INTs needed to represent the precision
389 of the number. Some constants have a large uniform precision, so
390 we get the precision needed for the actual value of the number. */
393 get_full_len (const wide_int
&op
)
395 int prec
= wi::min_precision (op
, UNSIGNED
);
396 return ((prec
+ HOST_BITS_PER_WIDE_INT
- 1)
397 / HOST_BITS_PER_WIDE_INT
);
401 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
403 enum debug_struct_file criterion
;
405 bool generic
= lang_hooks
.types
.generic_p (type
);
408 criterion
= debug_struct_generic
[usage
];
410 criterion
= debug_struct_ordinary
[usage
];
412 if (criterion
== DINFO_STRUCT_FILE_NONE
)
413 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
414 if (criterion
== DINFO_STRUCT_FILE_ANY
)
415 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
417 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
419 if (type_decl
!= NULL
)
421 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
422 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
424 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
425 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
428 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
431 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
432 switch to the data section instead, and write out a synthetic start label
433 for collect2 the first time around. */
436 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
438 if (eh_frame_section
== 0)
442 if (EH_TABLES_CAN_BE_READ_ONLY
)
448 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
450 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
452 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
455 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
456 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
457 && (per_encoding
& 0x70) != DW_EH_PE_absptr
458 && (per_encoding
& 0x70) != DW_EH_PE_aligned
459 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
460 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
461 ? 0 : SECTION_WRITE
);
464 flags
= SECTION_WRITE
;
466 #ifdef EH_FRAME_SECTION_NAME
467 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
469 eh_frame_section
= ((flags
== SECTION_WRITE
)
470 ? data_section
: readonly_data_section
);
471 #endif /* EH_FRAME_SECTION_NAME */
474 switch_to_section (eh_frame_section
);
476 #ifdef EH_FRAME_THROUGH_COLLECT2
477 /* We have no special eh_frame section. Emit special labels to guide
481 tree label
= get_file_function_name ("F");
482 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
483 targetm
.asm_out
.globalize_label (asm_out_file
,
484 IDENTIFIER_POINTER (label
));
485 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
490 /* Switch [BACK] to the eh or debug frame table section, depending on
494 switch_to_frame_table_section (int for_eh
, bool back
)
497 switch_to_eh_frame_section (back
);
500 if (!debug_frame_section
)
501 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
502 SECTION_DEBUG
, NULL
);
503 switch_to_section (debug_frame_section
);
507 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
509 enum dw_cfi_oprnd_type
510 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
515 case DW_CFA_GNU_window_save
:
516 case DW_CFA_remember_state
:
517 case DW_CFA_restore_state
:
518 return dw_cfi_oprnd_unused
;
521 case DW_CFA_advance_loc1
:
522 case DW_CFA_advance_loc2
:
523 case DW_CFA_advance_loc4
:
524 case DW_CFA_MIPS_advance_loc8
:
525 return dw_cfi_oprnd_addr
;
528 case DW_CFA_offset_extended
:
530 case DW_CFA_offset_extended_sf
:
531 case DW_CFA_def_cfa_sf
:
533 case DW_CFA_restore_extended
:
534 case DW_CFA_undefined
:
535 case DW_CFA_same_value
:
536 case DW_CFA_def_cfa_register
:
537 case DW_CFA_register
:
538 case DW_CFA_expression
:
539 case DW_CFA_val_expression
:
540 return dw_cfi_oprnd_reg_num
;
542 case DW_CFA_def_cfa_offset
:
543 case DW_CFA_GNU_args_size
:
544 case DW_CFA_def_cfa_offset_sf
:
545 return dw_cfi_oprnd_offset
;
547 case DW_CFA_def_cfa_expression
:
548 return dw_cfi_oprnd_loc
;
555 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
557 enum dw_cfi_oprnd_type
558 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
563 case DW_CFA_def_cfa_sf
:
565 case DW_CFA_offset_extended_sf
:
566 case DW_CFA_offset_extended
:
567 return dw_cfi_oprnd_offset
;
569 case DW_CFA_register
:
570 return dw_cfi_oprnd_reg_num
;
572 case DW_CFA_expression
:
573 case DW_CFA_val_expression
:
574 return dw_cfi_oprnd_loc
;
577 return dw_cfi_oprnd_unused
;
581 /* Output one FDE. */
584 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
585 char *section_start_label
, int fde_encoding
, char *augmentation
,
586 bool any_lsda_needed
, int lsda_encoding
)
588 const char *begin
, *end
;
589 static unsigned int j
;
590 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
592 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
594 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
596 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
597 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
598 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
600 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
601 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
602 " indicating 64-bit DWARF extension");
603 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
606 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
609 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
611 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
612 debug_frame_section
, "FDE CIE offset");
614 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
615 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
619 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
620 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
621 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
622 "FDE initial location");
623 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
624 end
, begin
, "FDE address range");
628 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
629 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
636 int size
= size_of_encoded_value (lsda_encoding
);
638 if (lsda_encoding
== DW_EH_PE_aligned
)
640 int offset
= ( 4 /* Length */
642 + 2 * size_of_encoded_value (fde_encoding
)
643 + 1 /* Augmentation size */ );
644 int pad
= -offset
& (PTR_SIZE
- 1);
647 gcc_assert (size_of_uleb128 (size
) == 1);
650 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
652 if (fde
->uses_eh_lsda
)
654 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
655 fde
->funcdef_number
);
656 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
657 gen_rtx_SYMBOL_REF (Pmode
, l1
),
659 "Language Specific Data Area");
663 if (lsda_encoding
== DW_EH_PE_aligned
)
664 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
665 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
666 "Language Specific Data Area (none)");
670 dw2_asm_output_data_uleb128 (0, "Augmentation size");
673 /* Loop through the Call Frame Instructions associated with this FDE. */
674 fde
->dw_fde_current_label
= begin
;
676 size_t from
, until
, i
;
679 until
= vec_safe_length (fde
->dw_fde_cfi
);
681 if (fde
->dw_fde_second_begin
== NULL
)
684 until
= fde
->dw_fde_switch_cfi_index
;
686 from
= fde
->dw_fde_switch_cfi_index
;
688 for (i
= from
; i
< until
; i
++)
689 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
692 /* If we are to emit a ref/link from function bodies to their frame tables,
693 do it now. This is typically performed to make sure that tables
694 associated with functions are dragged with them and not discarded in
695 garbage collecting links. We need to do this on a per function basis to
696 cope with -ffunction-sections. */
698 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
699 /* Switch to the function section, emit the ref to the tables, and
700 switch *back* into the table section. */
701 switch_to_section (function_section (fde
->decl
));
702 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
703 switch_to_frame_table_section (for_eh
, true);
706 /* Pad the FDE out to an address sized boundary. */
707 ASM_OUTPUT_ALIGN (asm_out_file
,
708 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
709 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
714 /* Return true if frame description entry FDE is needed for EH. */
717 fde_needed_for_eh_p (dw_fde_ref fde
)
719 if (flag_asynchronous_unwind_tables
)
722 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
725 if (fde
->uses_eh_lsda
)
728 /* If exceptions are enabled, we have collected nothrow info. */
729 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
735 /* Output the call frame information used to record information
736 that relates to calculating the frame pointer, and records the
737 location of saved registers. */
740 output_call_frame_info (int for_eh
)
745 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
746 char section_start_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
747 bool any_lsda_needed
= false;
748 char augmentation
[6];
749 int augmentation_size
;
750 int fde_encoding
= DW_EH_PE_absptr
;
751 int per_encoding
= DW_EH_PE_absptr
;
752 int lsda_encoding
= DW_EH_PE_absptr
;
754 rtx personality
= NULL
;
757 /* Don't emit a CIE if there won't be any FDEs. */
761 /* Nothing to do if the assembler's doing it all. */
762 if (dwarf2out_do_cfi_asm ())
765 /* If we don't have any functions we'll want to unwind out of, don't emit
766 any EH unwind information. If we make FDEs linkonce, we may have to
767 emit an empty label for an FDE that wouldn't otherwise be emitted. We
768 want to avoid having an FDE kept around when the function it refers to
769 is discarded. Example where this matters: a primary function template
770 in C++ requires EH information, an explicit specialization doesn't. */
773 bool any_eh_needed
= false;
775 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
777 if (fde
->uses_eh_lsda
)
778 any_eh_needed
= any_lsda_needed
= true;
779 else if (fde_needed_for_eh_p (fde
))
780 any_eh_needed
= true;
781 else if (TARGET_USES_WEAK_UNWIND_INFO
)
782 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
789 /* We're going to be generating comments, so turn on app. */
793 /* Switch to the proper frame section, first time. */
794 switch_to_frame_table_section (for_eh
, false);
796 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
797 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
799 /* Output the CIE. */
800 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
801 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
802 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
804 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
805 dw2_asm_output_data (4, 0xffffffff,
806 "Initial length escape value indicating 64-bit DWARF extension");
807 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
808 "Length of Common Information Entry");
810 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
812 /* Now that the CIE pointer is PC-relative for EH,
813 use 0 to identify the CIE. */
814 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
815 (for_eh
? 0 : DWARF_CIE_ID
),
816 "CIE Identifier Tag");
818 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
819 use CIE version 1, unless that would produce incorrect results
820 due to overflowing the return register column. */
821 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
823 if (return_reg
>= 256 || dwarf_version
> 2)
825 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
828 augmentation_size
= 0;
830 personality
= current_unit_personality
;
836 z Indicates that a uleb128 is present to size the
837 augmentation section.
838 L Indicates the encoding (and thus presence) of
839 an LSDA pointer in the FDE augmentation.
840 R Indicates a non-default pointer encoding for
842 P Indicates the presence of an encoding + language
843 personality routine in the CIE augmentation. */
845 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
846 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
847 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
849 p
= augmentation
+ 1;
853 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
854 assemble_external_libcall (personality
);
859 augmentation_size
+= 1;
861 if (fde_encoding
!= DW_EH_PE_absptr
)
864 augmentation_size
+= 1;
866 if (p
> augmentation
+ 1)
868 augmentation
[0] = 'z';
872 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
873 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
875 int offset
= ( 4 /* Length */
877 + 1 /* CIE version */
878 + strlen (augmentation
) + 1 /* Augmentation */
879 + size_of_uleb128 (1) /* Code alignment */
880 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
882 + 1 /* Augmentation size */
883 + 1 /* Personality encoding */ );
884 int pad
= -offset
& (PTR_SIZE
- 1);
886 augmentation_size
+= pad
;
888 /* Augmentations should be small, so there's scarce need to
889 iterate for a solution. Die if we exceed one uleb128 byte. */
890 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
894 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
895 if (dw_cie_version
>= 4)
897 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
898 dw2_asm_output_data (1, 0, "CIE Segment Size");
900 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
901 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
902 "CIE Data Alignment Factor");
904 if (dw_cie_version
== 1)
905 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
907 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
911 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
914 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
915 eh_data_format_name (per_encoding
));
916 dw2_asm_output_encoded_addr_rtx (per_encoding
,
922 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
923 eh_data_format_name (lsda_encoding
));
925 if (fde_encoding
!= DW_EH_PE_absptr
)
926 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
927 eh_data_format_name (fde_encoding
));
930 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
931 output_cfi (cfi
, NULL
, for_eh
);
933 /* Pad the CIE out to an address sized boundary. */
934 ASM_OUTPUT_ALIGN (asm_out_file
,
935 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
936 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
938 /* Loop through all of the FDE's. */
939 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
943 /* Don't emit EH unwind info for leaf functions that don't need it. */
944 if (for_eh
&& !fde_needed_for_eh_p (fde
))
947 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
948 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
949 augmentation
, any_lsda_needed
, lsda_encoding
);
952 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
953 dw2_asm_output_data (4, 0, "End of Table");
955 /* Turn off app to make assembly quicker. */
960 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
963 dwarf2out_do_cfi_startproc (bool second
)
968 fprintf (asm_out_file
, "\t.cfi_startproc\n");
970 /* .cfi_personality and .cfi_lsda are only relevant to DWARF2
972 if (targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
)
975 rtx personality
= get_personality_function (current_function_decl
);
979 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
982 /* ??? The GAS support isn't entirely consistent. We have to
983 handle indirect support ourselves, but PC-relative is done
984 in the assembler. Further, the assembler can't handle any
985 of the weirder relocation types. */
986 if (enc
& DW_EH_PE_indirect
)
987 ref
= dw2_force_const_mem (ref
, true);
989 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
990 output_addr_const (asm_out_file
, ref
);
991 fputc ('\n', asm_out_file
);
994 if (crtl
->uses_eh_lsda
)
996 char lab
[MAX_ARTIFICIAL_LABEL_BYTES
];
998 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
999 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
1000 current_function_funcdef_no
);
1001 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
1002 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
1004 if (enc
& DW_EH_PE_indirect
)
1005 ref
= dw2_force_const_mem (ref
, true);
1007 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
1008 output_addr_const (asm_out_file
, ref
);
1009 fputc ('\n', asm_out_file
);
1013 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1014 this allocation may be done before pass_final. */
1017 dwarf2out_alloc_current_fde (void)
1021 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1022 fde
->decl
= current_function_decl
;
1023 fde
->funcdef_number
= current_function_funcdef_no
;
1024 fde
->fde_index
= vec_safe_length (fde_vec
);
1025 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1026 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1027 fde
->nothrow
= crtl
->nothrow
;
1028 fde
->drap_reg
= INVALID_REGNUM
;
1029 fde
->vdrap_reg
= INVALID_REGNUM
;
1031 /* Record the FDE associated with this function. */
1033 vec_safe_push (fde_vec
, fde
);
1038 /* Output a marker (i.e. a label) for the beginning of a function, before
1042 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1043 unsigned int column ATTRIBUTE_UNUSED
,
1044 const char *file ATTRIBUTE_UNUSED
)
1046 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1052 current_function_func_begin_label
= NULL
;
1054 do_frame
= dwarf2out_do_frame ();
1056 /* ??? current_function_func_begin_label is also used by except.c for
1057 call-site information. We must emit this label if it might be used. */
1059 && (!flag_exceptions
1060 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1063 fnsec
= function_section (current_function_decl
);
1064 switch_to_section (fnsec
);
1065 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1066 current_function_funcdef_no
);
1067 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1068 current_function_funcdef_no
);
1069 dup_label
= xstrdup (label
);
1070 current_function_func_begin_label
= dup_label
;
1072 /* We can elide FDE allocation if we're not emitting frame unwind info. */
1076 /* Unlike the debug version, the EH version of frame unwind info is a per-
1077 function setting so we need to record whether we need it for the unit. */
1078 do_eh_frame
|= dwarf2out_do_eh_frame ();
1080 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1081 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1082 would include pass_dwarf2_frame. If we've not created the FDE yet,
1086 fde
= dwarf2out_alloc_current_fde ();
1088 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1089 fde
->dw_fde_begin
= dup_label
;
1090 fde
->dw_fde_current_label
= dup_label
;
1091 fde
->in_std_section
= (fnsec
== text_section
1092 || (cold_text_section
&& fnsec
== cold_text_section
));
1094 /* We only want to output line number information for the genuine dwarf2
1095 prologue case, not the eh frame case. */
1096 #ifdef DWARF2_DEBUGGING_INFO
1098 dwarf2out_source_line (line
, column
, file
, 0, true);
1101 if (dwarf2out_do_cfi_asm ())
1102 dwarf2out_do_cfi_startproc (false);
1105 rtx personality
= get_personality_function (current_function_decl
);
1106 if (!current_unit_personality
)
1107 current_unit_personality
= personality
;
1109 /* We cannot keep a current personality per function as without CFI
1110 asm, at the point where we emit the CFI data, there is no current
1111 function anymore. */
1112 if (personality
&& current_unit_personality
!= personality
)
1113 sorry ("multiple EH personalities are supported only with assemblers "
1114 "supporting .cfi_personality directive");
1118 /* Output a marker (i.e. a label) for the end of the generated code
1119 for a function prologue. This gets called *after* the prologue code has
1123 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1124 const char *file ATTRIBUTE_UNUSED
)
1126 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1128 /* Output a label to mark the endpoint of the code generated for this
1130 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1131 current_function_funcdef_no
);
1132 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1133 current_function_funcdef_no
);
1134 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1137 /* Output a marker (i.e. a label) for the beginning of the generated code
1138 for a function epilogue. This gets called *before* the prologue code has
1142 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1143 const char *file ATTRIBUTE_UNUSED
)
1145 dw_fde_ref fde
= cfun
->fde
;
1146 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1148 if (fde
->dw_fde_vms_begin_epilogue
)
1151 /* Output a label to mark the endpoint of the code generated for this
1153 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1154 current_function_funcdef_no
);
1155 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1156 current_function_funcdef_no
);
1157 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1160 /* Output a marker (i.e. a label) for the absolute end of the generated code
1161 for a function definition. This gets called *after* the epilogue code has
1165 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1166 const char *file ATTRIBUTE_UNUSED
)
1169 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1171 last_var_location_insn
= NULL
;
1172 cached_next_real_insn
= NULL
;
1174 if (dwarf2out_do_cfi_asm ())
1175 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1177 /* Output a label to mark the endpoint of the code generated for this
1179 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1180 current_function_funcdef_no
);
1181 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1183 gcc_assert (fde
!= NULL
);
1184 if (fde
->dw_fde_second_begin
== NULL
)
1185 fde
->dw_fde_end
= xstrdup (label
);
1189 dwarf2out_frame_finish (void)
1191 /* Output call frame information. */
1192 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1193 output_call_frame_info (0);
1195 /* Output another copy for the unwinder. */
1197 output_call_frame_info (1);
1200 /* Note that the current function section is being used for code. */
1203 dwarf2out_note_section_used (void)
1205 section
*sec
= current_function_section ();
1206 if (sec
== text_section
)
1207 text_section_used
= true;
1208 else if (sec
== cold_text_section
)
1209 cold_text_section_used
= true;
1212 static void var_location_switch_text_section (void);
1213 static void set_cur_line_info_table (section
*);
1216 dwarf2out_switch_text_section (void)
1219 dw_fde_ref fde
= cfun
->fde
;
1221 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1223 if (!in_cold_section_p
)
1225 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1226 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1227 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1231 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1232 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1233 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1235 have_multiple_function_sections
= true;
1237 /* There is no need to mark used sections when not debugging. */
1238 if (cold_text_section
!= NULL
)
1239 dwarf2out_note_section_used ();
1241 if (dwarf2out_do_cfi_asm ())
1242 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1244 /* Now do the real section switch. */
1245 sect
= current_function_section ();
1246 switch_to_section (sect
);
1248 fde
->second_in_std_section
1249 = (sect
== text_section
1250 || (cold_text_section
&& sect
== cold_text_section
));
1252 if (dwarf2out_do_cfi_asm ())
1253 dwarf2out_do_cfi_startproc (true);
1255 var_location_switch_text_section ();
1257 if (cold_text_section
!= NULL
)
1258 set_cur_line_info_table (sect
);
1261 /* And now, the subset of the debugging information support code necessary
1262 for emitting location expressions. */
1264 /* Data about a single source file. */
1265 struct GTY((for_user
)) dwarf_file_data
{
1266 const char * filename
;
1270 /* Describe an entry into the .debug_addr section. */
1274 ate_kind_rtx_dtprel
,
1278 struct GTY((for_user
)) addr_table_entry
{
1280 unsigned int refcount
;
1282 union addr_table_entry_struct_union
1284 rtx
GTY ((tag ("0"))) rtl
;
1285 char * GTY ((tag ("1"))) label
;
1287 GTY ((desc ("%1.kind"))) addr
;
1290 /* Location lists are ranges + location descriptions for that range,
1291 so you can track variables that are in different places over
1292 their entire life. */
1293 typedef struct GTY(()) dw_loc_list_struct
{
1294 dw_loc_list_ref dw_loc_next
;
1295 const char *begin
; /* Label and addr_entry for start of range */
1296 addr_table_entry
*begin_entry
;
1297 const char *end
; /* Label for end of range */
1298 char *ll_symbol
; /* Label for beginning of location list.
1299 Only on head of list */
1300 const char *section
; /* Section this loclist is relative to */
1301 dw_loc_descr_ref expr
;
1303 /* True if all addresses in this and subsequent lists are known to be
1306 /* True if this list has been replaced by dw_loc_next. */
1308 /* True if it has been emitted into .debug_loc* / .debug_loclists*
1310 unsigned char emitted
: 1;
1311 /* True if hash field is index rather than hash value. */
1312 unsigned char num_assigned
: 1;
1313 /* True if .debug_loclists.dwo offset has been emitted for it already. */
1314 unsigned char offset_emitted
: 1;
1315 /* True if note_variable_value_in_expr has been called on it. */
1316 unsigned char noted_variable_value
: 1;
1317 /* True if the range should be emitted even if begin and end
1322 static dw_loc_descr_ref
int_loc_descriptor (poly_int64
);
1323 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1325 /* Convert a DWARF stack opcode into its string name. */
1328 dwarf_stack_op_name (unsigned int op
)
1330 const char *name
= get_DW_OP_name (op
);
1335 return "OP_<unknown>";
1338 /* Return a pointer to a newly allocated location description. Location
1339 descriptions are simple expression terms that can be strung
1340 together to form more complicated location (address) descriptions. */
1342 static inline dw_loc_descr_ref
1343 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1344 unsigned HOST_WIDE_INT oprnd2
)
1346 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1348 descr
->dw_loc_opc
= op
;
1349 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1350 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1351 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1352 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1353 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1354 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1359 /* Add a location description term to a location description expression. */
1362 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1364 dw_loc_descr_ref
*d
;
1366 /* Find the end of the chain. */
1367 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1373 /* Compare two location operands for exact equality. */
1376 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1378 if (a
->val_class
!= b
->val_class
)
1380 switch (a
->val_class
)
1382 case dw_val_class_none
:
1384 case dw_val_class_addr
:
1385 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1387 case dw_val_class_offset
:
1388 case dw_val_class_unsigned_const
:
1389 case dw_val_class_const
:
1390 case dw_val_class_unsigned_const_implicit
:
1391 case dw_val_class_const_implicit
:
1392 case dw_val_class_range_list
:
1393 /* These are all HOST_WIDE_INT, signed or unsigned. */
1394 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1396 case dw_val_class_loc
:
1397 return a
->v
.val_loc
== b
->v
.val_loc
;
1398 case dw_val_class_loc_list
:
1399 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1400 case dw_val_class_die_ref
:
1401 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1402 case dw_val_class_fde_ref
:
1403 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1404 case dw_val_class_lbl_id
:
1405 case dw_val_class_lineptr
:
1406 case dw_val_class_macptr
:
1407 case dw_val_class_loclistsptr
:
1408 case dw_val_class_high_pc
:
1409 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1410 case dw_val_class_str
:
1411 return a
->v
.val_str
== b
->v
.val_str
;
1412 case dw_val_class_flag
:
1413 return a
->v
.val_flag
== b
->v
.val_flag
;
1414 case dw_val_class_file
:
1415 case dw_val_class_file_implicit
:
1416 return a
->v
.val_file
== b
->v
.val_file
;
1417 case dw_val_class_decl_ref
:
1418 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1420 case dw_val_class_const_double
:
1421 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1422 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1424 case dw_val_class_wide_int
:
1425 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1427 case dw_val_class_vec
:
1429 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1430 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1432 return (a_len
== b_len
1433 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1436 case dw_val_class_data8
:
1437 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1439 case dw_val_class_vms_delta
:
1440 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1441 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1443 case dw_val_class_discr_value
:
1444 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1445 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1446 case dw_val_class_discr_list
:
1447 /* It makes no sense comparing two discriminant value lists. */
1453 /* Compare two location atoms for exact equality. */
1456 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1458 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1461 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1462 address size, but since we always allocate cleared storage it
1463 should be zero for other types of locations. */
1464 if (a
->dtprel
!= b
->dtprel
)
1467 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1468 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1471 /* Compare two complete location expressions for exact equality. */
1474 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1480 if (a
== NULL
|| b
== NULL
)
1482 if (!loc_descr_equal_p_1 (a
, b
))
1491 /* Add a constant POLY_OFFSET to a location expression. */
1494 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, poly_int64 poly_offset
)
1496 dw_loc_descr_ref loc
;
1499 gcc_assert (*list_head
!= NULL
);
1501 if (known_eq (poly_offset
, 0))
1504 /* Find the end of the chain. */
1505 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1508 HOST_WIDE_INT offset
;
1509 if (!poly_offset
.is_constant (&offset
))
1511 loc
->dw_loc_next
= int_loc_descriptor (poly_offset
);
1512 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_plus
, 0, 0));
1517 if (loc
->dw_loc_opc
== DW_OP_fbreg
1518 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1519 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1520 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1521 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1523 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1524 offset. Don't optimize if an signed integer overflow would happen. */
1526 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1527 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1530 else if (offset
> 0)
1531 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1536 = uint_loc_descriptor (-(unsigned HOST_WIDE_INT
) offset
);
1537 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1541 /* Return a pointer to a newly allocated location description for
1544 static inline dw_loc_descr_ref
1545 new_reg_loc_descr (unsigned int reg
, poly_int64 offset
)
1547 HOST_WIDE_INT const_offset
;
1548 if (offset
.is_constant (&const_offset
))
1551 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1554 return new_loc_descr (DW_OP_bregx
, reg
, const_offset
);
1558 dw_loc_descr_ref ret
= new_reg_loc_descr (reg
, 0);
1559 loc_descr_plus_const (&ret
, offset
);
1564 /* Add a constant OFFSET to a location list. */
1567 loc_list_plus_const (dw_loc_list_ref list_head
, poly_int64 offset
)
1570 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1571 loc_descr_plus_const (&d
->expr
, offset
);
1574 #define DWARF_REF_SIZE \
1575 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1577 /* The number of bits that can be encoded by largest DW_FORM_dataN.
1578 In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
1579 DW_FORM_data16 with 128 bits. */
1580 #define DWARF_LARGEST_DATA_FORM_BITS \
1581 (dwarf_version >= 5 ? 128 : 64)
1583 /* Utility inline function for construction of ops that were GNU extension
1585 static inline enum dwarf_location_atom
1586 dwarf_OP (enum dwarf_location_atom op
)
1590 case DW_OP_implicit_pointer
:
1591 if (dwarf_version
< 5)
1592 return DW_OP_GNU_implicit_pointer
;
1595 case DW_OP_entry_value
:
1596 if (dwarf_version
< 5)
1597 return DW_OP_GNU_entry_value
;
1600 case DW_OP_const_type
:
1601 if (dwarf_version
< 5)
1602 return DW_OP_GNU_const_type
;
1605 case DW_OP_regval_type
:
1606 if (dwarf_version
< 5)
1607 return DW_OP_GNU_regval_type
;
1610 case DW_OP_deref_type
:
1611 if (dwarf_version
< 5)
1612 return DW_OP_GNU_deref_type
;
1616 if (dwarf_version
< 5)
1617 return DW_OP_GNU_convert
;
1620 case DW_OP_reinterpret
:
1621 if (dwarf_version
< 5)
1622 return DW_OP_GNU_reinterpret
;
1631 /* Similarly for attributes. */
1632 static inline enum dwarf_attribute
1633 dwarf_AT (enum dwarf_attribute at
)
1637 case DW_AT_call_return_pc
:
1638 if (dwarf_version
< 5)
1639 return DW_AT_low_pc
;
1642 case DW_AT_call_tail_call
:
1643 if (dwarf_version
< 5)
1644 return DW_AT_GNU_tail_call
;
1647 case DW_AT_call_origin
:
1648 if (dwarf_version
< 5)
1649 return DW_AT_abstract_origin
;
1652 case DW_AT_call_target
:
1653 if (dwarf_version
< 5)
1654 return DW_AT_GNU_call_site_target
;
1657 case DW_AT_call_target_clobbered
:
1658 if (dwarf_version
< 5)
1659 return DW_AT_GNU_call_site_target_clobbered
;
1662 case DW_AT_call_parameter
:
1663 if (dwarf_version
< 5)
1664 return DW_AT_abstract_origin
;
1667 case DW_AT_call_value
:
1668 if (dwarf_version
< 5)
1669 return DW_AT_GNU_call_site_value
;
1672 case DW_AT_call_data_value
:
1673 if (dwarf_version
< 5)
1674 return DW_AT_GNU_call_site_data_value
;
1677 case DW_AT_call_all_calls
:
1678 if (dwarf_version
< 5)
1679 return DW_AT_GNU_all_call_sites
;
1682 case DW_AT_call_all_tail_calls
:
1683 if (dwarf_version
< 5)
1684 return DW_AT_GNU_all_tail_call_sites
;
1687 case DW_AT_dwo_name
:
1688 if (dwarf_version
< 5)
1689 return DW_AT_GNU_dwo_name
;
1698 /* And similarly for tags. */
1699 static inline enum dwarf_tag
1700 dwarf_TAG (enum dwarf_tag tag
)
1704 case DW_TAG_call_site
:
1705 if (dwarf_version
< 5)
1706 return DW_TAG_GNU_call_site
;
1709 case DW_TAG_call_site_parameter
:
1710 if (dwarf_version
< 5)
1711 return DW_TAG_GNU_call_site_parameter
;
1720 static unsigned long int get_base_type_offset (dw_die_ref
);
1722 /* Return the size of a location descriptor. */
1724 static unsigned long
1725 size_of_loc_descr (dw_loc_descr_ref loc
)
1727 unsigned long size
= 1;
1729 switch (loc
->dw_loc_opc
)
1732 size
+= DWARF2_ADDR_SIZE
;
1734 case DW_OP_GNU_addr_index
:
1735 case DW_OP_GNU_const_index
:
1736 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1737 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1756 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1759 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1764 case DW_OP_plus_uconst
:
1765 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1803 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1806 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1809 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1812 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1813 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1816 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1818 case DW_OP_bit_piece
:
1819 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1820 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1822 case DW_OP_deref_size
:
1823 case DW_OP_xderef_size
:
1832 case DW_OP_call_ref
:
1833 case DW_OP_GNU_variable_value
:
1834 size
+= DWARF_REF_SIZE
;
1836 case DW_OP_implicit_value
:
1837 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1838 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1840 case DW_OP_implicit_pointer
:
1841 case DW_OP_GNU_implicit_pointer
:
1842 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1844 case DW_OP_entry_value
:
1845 case DW_OP_GNU_entry_value
:
1847 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1848 size
+= size_of_uleb128 (op_size
) + op_size
;
1851 case DW_OP_const_type
:
1852 case DW_OP_GNU_const_type
:
1855 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1856 size
+= size_of_uleb128 (o
) + 1;
1857 switch (loc
->dw_loc_oprnd2
.val_class
)
1859 case dw_val_class_vec
:
1860 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1861 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1863 case dw_val_class_const
:
1864 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1866 case dw_val_class_const_double
:
1867 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1869 case dw_val_class_wide_int
:
1870 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1871 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1878 case DW_OP_regval_type
:
1879 case DW_OP_GNU_regval_type
:
1882 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1883 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1884 + size_of_uleb128 (o
);
1887 case DW_OP_deref_type
:
1888 case DW_OP_GNU_deref_type
:
1891 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1892 size
+= 1 + size_of_uleb128 (o
);
1896 case DW_OP_reinterpret
:
1897 case DW_OP_GNU_convert
:
1898 case DW_OP_GNU_reinterpret
:
1899 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1900 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1904 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1905 size
+= size_of_uleb128 (o
);
1908 case DW_OP_GNU_parameter_ref
:
1918 /* Return the size of a series of location descriptors. */
1921 size_of_locs (dw_loc_descr_ref loc
)
1926 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1927 field, to avoid writing to a PCH file. */
1928 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1930 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1932 size
+= size_of_loc_descr (l
);
1937 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1939 l
->dw_loc_addr
= size
;
1940 size
+= size_of_loc_descr (l
);
1946 /* Return the size of the value in a DW_AT_discr_value attribute. */
1949 size_of_discr_value (dw_discr_value
*discr_value
)
1951 if (discr_value
->pos
)
1952 return size_of_uleb128 (discr_value
->v
.uval
);
1954 return size_of_sleb128 (discr_value
->v
.sval
);
1957 /* Return the size of the value in a DW_AT_discr_list attribute. */
1960 size_of_discr_list (dw_discr_list_ref discr_list
)
1964 for (dw_discr_list_ref list
= discr_list
;
1966 list
= list
->dw_discr_next
)
1968 /* One byte for the discriminant value descriptor, and then one or two
1969 LEB128 numbers, depending on whether it's a single case label or a
1972 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
1973 if (list
->dw_discr_range
!= 0)
1974 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
1979 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1980 static void get_ref_die_offset_label (char *, dw_die_ref
);
1981 static unsigned long int get_ref_die_offset (dw_die_ref
);
1983 /* Output location description stack opcode's operands (if any).
1984 The for_eh_or_skip parameter controls whether register numbers are
1985 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1986 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1987 info). This should be suppressed for the cases that have not been converted
1988 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1991 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1993 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1994 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1996 switch (loc
->dw_loc_opc
)
1998 #ifdef DWARF2_DEBUGGING_INFO
2001 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2006 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2007 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
2009 fputc ('\n', asm_out_file
);
2014 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2019 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2020 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
2022 fputc ('\n', asm_out_file
);
2027 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2028 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2035 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2036 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2038 dw2_asm_output_data (2, offset
, NULL
);
2041 case DW_OP_implicit_value
:
2042 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2043 switch (val2
->val_class
)
2045 case dw_val_class_const
:
2046 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2048 case dw_val_class_vec
:
2050 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2051 unsigned int len
= val2
->v
.val_vec
.length
;
2055 if (elt_size
> sizeof (HOST_WIDE_INT
))
2060 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2063 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2064 "fp or vector constant word %u", i
);
2067 case dw_val_class_const_double
:
2069 unsigned HOST_WIDE_INT first
, second
;
2071 if (WORDS_BIG_ENDIAN
)
2073 first
= val2
->v
.val_double
.high
;
2074 second
= val2
->v
.val_double
.low
;
2078 first
= val2
->v
.val_double
.low
;
2079 second
= val2
->v
.val_double
.high
;
2081 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2083 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2087 case dw_val_class_wide_int
:
2090 int len
= get_full_len (*val2
->v
.val_wide
);
2091 if (WORDS_BIG_ENDIAN
)
2092 for (i
= len
- 1; i
>= 0; --i
)
2093 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2094 val2
->v
.val_wide
->elt (i
), NULL
);
2096 for (i
= 0; i
< len
; ++i
)
2097 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2098 val2
->v
.val_wide
->elt (i
), NULL
);
2101 case dw_val_class_addr
:
2102 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2103 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2118 case DW_OP_implicit_value
:
2119 /* We currently don't make any attempt to make sure these are
2120 aligned properly like we do for the main unwind info, so
2121 don't support emitting things larger than a byte if we're
2122 only doing unwinding. */
2127 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2130 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2133 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2136 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2138 case DW_OP_plus_uconst
:
2139 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2173 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2177 unsigned r
= val1
->v
.val_unsigned
;
2178 if (for_eh_or_skip
>= 0)
2179 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2180 gcc_assert (size_of_uleb128 (r
)
2181 == size_of_uleb128 (val1
->v
.val_unsigned
));
2182 dw2_asm_output_data_uleb128 (r
, NULL
);
2186 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2190 unsigned r
= val1
->v
.val_unsigned
;
2191 if (for_eh_or_skip
>= 0)
2192 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2193 gcc_assert (size_of_uleb128 (r
)
2194 == size_of_uleb128 (val1
->v
.val_unsigned
));
2195 dw2_asm_output_data_uleb128 (r
, NULL
);
2196 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2200 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2202 case DW_OP_bit_piece
:
2203 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2204 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2206 case DW_OP_deref_size
:
2207 case DW_OP_xderef_size
:
2208 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2214 if (targetm
.asm_out
.output_dwarf_dtprel
)
2216 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2219 fputc ('\n', asm_out_file
);
2226 #ifdef DWARF2_DEBUGGING_INFO
2227 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2234 case DW_OP_GNU_addr_index
:
2235 case DW_OP_GNU_const_index
:
2236 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2237 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2238 "(index into .debug_addr)");
2244 unsigned long die_offset
2245 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2246 /* Make sure the offset has been computed and that we can encode it as
2248 gcc_assert (die_offset
> 0
2249 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
2252 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2257 case DW_OP_call_ref
:
2258 case DW_OP_GNU_variable_value
:
2260 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2261 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2262 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2263 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2264 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2268 case DW_OP_implicit_pointer
:
2269 case DW_OP_GNU_implicit_pointer
:
2271 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2272 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2273 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2274 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2275 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2276 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2280 case DW_OP_entry_value
:
2281 case DW_OP_GNU_entry_value
:
2282 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2283 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2286 case DW_OP_const_type
:
2287 case DW_OP_GNU_const_type
:
2289 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2291 dw2_asm_output_data_uleb128 (o
, NULL
);
2292 switch (val2
->val_class
)
2294 case dw_val_class_const
:
2295 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2296 dw2_asm_output_data (1, l
, NULL
);
2297 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2299 case dw_val_class_vec
:
2301 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2302 unsigned int len
= val2
->v
.val_vec
.length
;
2307 dw2_asm_output_data (1, l
, NULL
);
2308 if (elt_size
> sizeof (HOST_WIDE_INT
))
2313 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2316 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2317 "fp or vector constant word %u", i
);
2320 case dw_val_class_const_double
:
2322 unsigned HOST_WIDE_INT first
, second
;
2323 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2325 dw2_asm_output_data (1, 2 * l
, NULL
);
2326 if (WORDS_BIG_ENDIAN
)
2328 first
= val2
->v
.val_double
.high
;
2329 second
= val2
->v
.val_double
.low
;
2333 first
= val2
->v
.val_double
.low
;
2334 second
= val2
->v
.val_double
.high
;
2336 dw2_asm_output_data (l
, first
, NULL
);
2337 dw2_asm_output_data (l
, second
, NULL
);
2340 case dw_val_class_wide_int
:
2343 int len
= get_full_len (*val2
->v
.val_wide
);
2344 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2346 dw2_asm_output_data (1, len
* l
, NULL
);
2347 if (WORDS_BIG_ENDIAN
)
2348 for (i
= len
- 1; i
>= 0; --i
)
2349 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2351 for (i
= 0; i
< len
; ++i
)
2352 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2360 case DW_OP_regval_type
:
2361 case DW_OP_GNU_regval_type
:
2363 unsigned r
= val1
->v
.val_unsigned
;
2364 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2366 if (for_eh_or_skip
>= 0)
2368 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2369 gcc_assert (size_of_uleb128 (r
)
2370 == size_of_uleb128 (val1
->v
.val_unsigned
));
2372 dw2_asm_output_data_uleb128 (r
, NULL
);
2373 dw2_asm_output_data_uleb128 (o
, NULL
);
2376 case DW_OP_deref_type
:
2377 case DW_OP_GNU_deref_type
:
2379 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2381 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2382 dw2_asm_output_data_uleb128 (o
, NULL
);
2386 case DW_OP_reinterpret
:
2387 case DW_OP_GNU_convert
:
2388 case DW_OP_GNU_reinterpret
:
2389 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2390 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2393 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2395 dw2_asm_output_data_uleb128 (o
, NULL
);
2399 case DW_OP_GNU_parameter_ref
:
2402 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2403 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2404 dw2_asm_output_data (4, o
, NULL
);
2409 /* Other codes have no operands. */
2414 /* Output a sequence of location operations.
2415 The for_eh_or_skip parameter controls whether register numbers are
2416 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2417 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2418 info). This should be suppressed for the cases that have not been converted
2419 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2422 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2424 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2426 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2427 /* Output the opcode. */
2428 if (for_eh_or_skip
>= 0
2429 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2431 unsigned r
= (opc
- DW_OP_breg0
);
2432 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2433 gcc_assert (r
<= 31);
2434 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2436 else if (for_eh_or_skip
>= 0
2437 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2439 unsigned r
= (opc
- DW_OP_reg0
);
2440 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2441 gcc_assert (r
<= 31);
2442 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2445 dw2_asm_output_data (1, opc
,
2446 "%s", dwarf_stack_op_name (opc
));
2448 /* Output the operand(s) (if any). */
2449 output_loc_operands (loc
, for_eh_or_skip
);
2453 /* Output location description stack opcode's operands (if any).
2454 The output is single bytes on a line, suitable for .cfi_escape. */
2457 output_loc_operands_raw (dw_loc_descr_ref loc
)
2459 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2460 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2462 switch (loc
->dw_loc_opc
)
2465 case DW_OP_GNU_addr_index
:
2466 case DW_OP_GNU_const_index
:
2467 case DW_OP_implicit_value
:
2468 /* We cannot output addresses in .cfi_escape, only bytes. */
2474 case DW_OP_deref_size
:
2475 case DW_OP_xderef_size
:
2476 fputc (',', asm_out_file
);
2477 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2482 fputc (',', asm_out_file
);
2483 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2488 fputc (',', asm_out_file
);
2489 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2494 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2495 fputc (',', asm_out_file
);
2496 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2504 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2505 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2507 fputc (',', asm_out_file
);
2508 dw2_asm_output_data_raw (2, offset
);
2514 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2515 gcc_assert (size_of_uleb128 (r
)
2516 == size_of_uleb128 (val1
->v
.val_unsigned
));
2517 fputc (',', asm_out_file
);
2518 dw2_asm_output_data_uleb128_raw (r
);
2523 case DW_OP_plus_uconst
:
2525 fputc (',', asm_out_file
);
2526 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2529 case DW_OP_bit_piece
:
2530 fputc (',', asm_out_file
);
2531 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2532 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2569 fputc (',', asm_out_file
);
2570 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2575 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2576 gcc_assert (size_of_uleb128 (r
)
2577 == size_of_uleb128 (val1
->v
.val_unsigned
));
2578 fputc (',', asm_out_file
);
2579 dw2_asm_output_data_uleb128_raw (r
);
2580 fputc (',', asm_out_file
);
2581 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2585 case DW_OP_implicit_pointer
:
2586 case DW_OP_entry_value
:
2587 case DW_OP_const_type
:
2588 case DW_OP_regval_type
:
2589 case DW_OP_deref_type
:
2591 case DW_OP_reinterpret
:
2592 case DW_OP_GNU_implicit_pointer
:
2593 case DW_OP_GNU_entry_value
:
2594 case DW_OP_GNU_const_type
:
2595 case DW_OP_GNU_regval_type
:
2596 case DW_OP_GNU_deref_type
:
2597 case DW_OP_GNU_convert
:
2598 case DW_OP_GNU_reinterpret
:
2599 case DW_OP_GNU_parameter_ref
:
2604 /* Other codes have no operands. */
2610 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2614 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2615 /* Output the opcode. */
2616 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2618 unsigned r
= (opc
- DW_OP_breg0
);
2619 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2620 gcc_assert (r
<= 31);
2621 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2623 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2625 unsigned r
= (opc
- DW_OP_reg0
);
2626 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2627 gcc_assert (r
<= 31);
2628 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2630 /* Output the opcode. */
2631 fprintf (asm_out_file
, "%#x", opc
);
2632 output_loc_operands_raw (loc
);
2634 if (!loc
->dw_loc_next
)
2636 loc
= loc
->dw_loc_next
;
2638 fputc (',', asm_out_file
);
2642 /* This function builds a dwarf location descriptor sequence from a
2643 dw_cfa_location, adding the given OFFSET to the result of the
2646 struct dw_loc_descr_node
*
2647 build_cfa_loc (dw_cfa_location
*cfa
, poly_int64 offset
)
2649 struct dw_loc_descr_node
*head
, *tmp
;
2651 offset
+= cfa
->offset
;
2655 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2656 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2657 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2658 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2659 add_loc_descr (&head
, tmp
);
2660 loc_descr_plus_const (&head
, offset
);
2663 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2668 /* This function builds a dwarf location descriptor sequence for
2669 the address at OFFSET from the CFA when stack is aligned to
2672 struct dw_loc_descr_node
*
2673 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2674 poly_int64 offset
, HOST_WIDE_INT alignment
)
2676 struct dw_loc_descr_node
*head
;
2677 unsigned int dwarf_fp
2678 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2680 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2681 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2683 head
= new_reg_loc_descr (dwarf_fp
, 0);
2684 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2685 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2686 loc_descr_plus_const (&head
, offset
);
2689 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2693 /* And now, the support for symbolic debugging information. */
2695 /* .debug_str support. */
2697 static void dwarf2out_init (const char *);
2698 static void dwarf2out_finish (const char *);
2699 static void dwarf2out_early_finish (const char *);
2700 static void dwarf2out_assembly_start (void);
2701 static void dwarf2out_define (unsigned int, const char *);
2702 static void dwarf2out_undef (unsigned int, const char *);
2703 static void dwarf2out_start_source_file (unsigned, const char *);
2704 static void dwarf2out_end_source_file (unsigned);
2705 static void dwarf2out_function_decl (tree
);
2706 static void dwarf2out_begin_block (unsigned, unsigned);
2707 static void dwarf2out_end_block (unsigned, unsigned);
2708 static bool dwarf2out_ignore_block (const_tree
);
2709 static void dwarf2out_early_global_decl (tree
);
2710 static void dwarf2out_late_global_decl (tree
);
2711 static void dwarf2out_type_decl (tree
, int);
2712 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool, bool);
2713 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2715 static void dwarf2out_abstract_function (tree
);
2716 static void dwarf2out_var_location (rtx_insn
*);
2717 static void dwarf2out_size_function (tree
);
2718 static void dwarf2out_begin_function (tree
);
2719 static void dwarf2out_end_function (unsigned int);
2720 static void dwarf2out_register_main_translation_unit (tree unit
);
2721 static void dwarf2out_set_name (tree
, tree
);
2722 static void dwarf2out_register_external_die (tree decl
, const char *sym
,
2723 unsigned HOST_WIDE_INT off
);
2724 static bool dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
2725 unsigned HOST_WIDE_INT
*off
);
2727 /* The debug hooks structure. */
2729 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2733 dwarf2out_early_finish
,
2734 dwarf2out_assembly_start
,
2737 dwarf2out_start_source_file
,
2738 dwarf2out_end_source_file
,
2739 dwarf2out_begin_block
,
2740 dwarf2out_end_block
,
2741 dwarf2out_ignore_block
,
2742 dwarf2out_source_line
,
2743 dwarf2out_begin_prologue
,
2744 #if VMS_DEBUGGING_INFO
2745 dwarf2out_vms_end_prologue
,
2746 dwarf2out_vms_begin_epilogue
,
2748 debug_nothing_int_charstar
,
2749 debug_nothing_int_charstar
,
2751 dwarf2out_end_epilogue
,
2752 dwarf2out_begin_function
,
2753 dwarf2out_end_function
, /* end_function */
2754 dwarf2out_register_main_translation_unit
,
2755 dwarf2out_function_decl
, /* function_decl */
2756 dwarf2out_early_global_decl
,
2757 dwarf2out_late_global_decl
,
2758 dwarf2out_type_decl
, /* type_decl */
2759 dwarf2out_imported_module_or_decl
,
2760 dwarf2out_die_ref_for_decl
,
2761 dwarf2out_register_external_die
,
2762 debug_nothing_tree
, /* deferred_inline_function */
2763 /* The DWARF 2 backend tries to reduce debugging bloat by not
2764 emitting the abstract description of inline functions until
2765 something tries to reference them. */
2766 dwarf2out_abstract_function
, /* outlining_inline_function */
2767 debug_nothing_rtx_code_label
, /* label */
2768 debug_nothing_int
, /* handle_pch */
2769 dwarf2out_var_location
,
2770 debug_nothing_tree
, /* inline_entry */
2771 dwarf2out_size_function
, /* size_function */
2772 dwarf2out_switch_text_section
,
2774 1, /* start_end_main_source_file */
2775 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2778 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2781 debug_nothing_charstar
,
2782 debug_nothing_charstar
,
2783 dwarf2out_assembly_start
,
2784 debug_nothing_int_charstar
,
2785 debug_nothing_int_charstar
,
2786 debug_nothing_int_charstar
,
2788 debug_nothing_int_int
, /* begin_block */
2789 debug_nothing_int_int
, /* end_block */
2790 debug_true_const_tree
, /* ignore_block */
2791 dwarf2out_source_line
, /* source_line */
2792 debug_nothing_int_int_charstar
, /* begin_prologue */
2793 debug_nothing_int_charstar
, /* end_prologue */
2794 debug_nothing_int_charstar
, /* begin_epilogue */
2795 debug_nothing_int_charstar
, /* end_epilogue */
2796 debug_nothing_tree
, /* begin_function */
2797 debug_nothing_int
, /* end_function */
2798 debug_nothing_tree
, /* register_main_translation_unit */
2799 debug_nothing_tree
, /* function_decl */
2800 debug_nothing_tree
, /* early_global_decl */
2801 debug_nothing_tree
, /* late_global_decl */
2802 debug_nothing_tree_int
, /* type_decl */
2803 debug_nothing_tree_tree_tree_bool_bool
,/* imported_module_or_decl */
2804 debug_false_tree_charstarstar_uhwistar
,/* die_ref_for_decl */
2805 debug_nothing_tree_charstar_uhwi
, /* register_external_die */
2806 debug_nothing_tree
, /* deferred_inline_function */
2807 debug_nothing_tree
, /* outlining_inline_function */
2808 debug_nothing_rtx_code_label
, /* label */
2809 debug_nothing_int
, /* handle_pch */
2810 debug_nothing_rtx_insn
, /* var_location */
2811 debug_nothing_tree
, /* inline_entry */
2812 debug_nothing_tree
, /* size_function */
2813 debug_nothing_void
, /* switch_text_section */
2814 debug_nothing_tree_tree
, /* set_name */
2815 0, /* start_end_main_source_file */
2816 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2819 /* NOTE: In the comments in this file, many references are made to
2820 "Debugging Information Entries". This term is abbreviated as `DIE'
2821 throughout the remainder of this file. */
2823 /* An internal representation of the DWARF output is built, and then
2824 walked to generate the DWARF debugging info. The walk of the internal
2825 representation is done after the entire program has been compiled.
2826 The types below are used to describe the internal representation. */
2828 /* Whether to put type DIEs into their own section .debug_types instead
2829 of making them part of the .debug_info section. Only supported for
2830 Dwarf V4 or higher and the user didn't disable them through
2831 -fno-debug-types-section. It is more efficient to put them in a
2832 separate comdat sections since the linker will then be able to
2833 remove duplicates. But not all tools support .debug_types sections
2834 yet. For Dwarf V5 or higher .debug_types doesn't exist any more,
2835 it is DW_UT_type unit type in .debug_info section. */
2837 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2839 /* Various DIE's use offsets relative to the beginning of the
2840 .debug_info section to refer to each other. */
2842 typedef long int dw_offset
;
2844 struct comdat_type_node
;
2846 /* The entries in the line_info table more-or-less mirror the opcodes
2847 that are used in the real dwarf line table. Arrays of these entries
2848 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2851 enum dw_line_info_opcode
{
2852 /* Emit DW_LNE_set_address; the operand is the label index. */
2855 /* Emit a row to the matrix with the given line. This may be done
2856 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2860 /* Emit a DW_LNS_set_file. */
2863 /* Emit a DW_LNS_set_column. */
2866 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2869 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2870 LI_set_prologue_end
,
2871 LI_set_epilogue_begin
,
2873 /* Emit a DW_LNE_set_discriminator. */
2874 LI_set_discriminator
2877 typedef struct GTY(()) dw_line_info_struct
{
2878 enum dw_line_info_opcode opcode
;
2880 } dw_line_info_entry
;
2883 struct GTY(()) dw_line_info_table
{
2884 /* The label that marks the end of this section. */
2885 const char *end_label
;
2887 /* The values for the last row of the matrix, as collected in the table.
2888 These are used to minimize the changes to the next row. */
2889 unsigned int file_num
;
2890 unsigned int line_num
;
2891 unsigned int column_num
;
2896 vec
<dw_line_info_entry
, va_gc
> *entries
;
2900 /* Each DIE attribute has a field specifying the attribute kind,
2901 a link to the next attribute in the chain, and an attribute value.
2902 Attributes are typically linked below the DIE they modify. */
2904 typedef struct GTY(()) dw_attr_struct
{
2905 enum dwarf_attribute dw_attr
;
2906 dw_val_node dw_attr_val
;
2911 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2912 The children of each node form a circular list linked by
2913 die_sib. die_child points to the node *before* the "first" child node. */
2915 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2916 union die_symbol_or_type_node
2918 const char * GTY ((tag ("0"))) die_symbol
;
2919 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
2921 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2922 vec
<dw_attr_node
, va_gc
> *die_attr
;
2923 dw_die_ref die_parent
;
2924 dw_die_ref die_child
;
2926 dw_die_ref die_definition
; /* ref from a specification to its definition */
2927 dw_offset die_offset
;
2928 unsigned long die_abbrev
;
2930 unsigned int decl_id
;
2931 enum dwarf_tag die_tag
;
2932 /* Die is used and must not be pruned as unused. */
2933 BOOL_BITFIELD die_perennial_p
: 1;
2934 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2935 /* For an external ref to die_symbol if die_offset contains an extra
2936 offset to that symbol. */
2937 BOOL_BITFIELD with_offset
: 1;
2938 /* Whether this DIE was removed from the DIE tree, for example via
2939 prune_unused_types. We don't consider those present from the
2940 DIE lookup routines. */
2941 BOOL_BITFIELD removed
: 1;
2942 /* Lots of spare bits. */
2946 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2947 static bool early_dwarf
;
2948 static bool early_dwarf_finished
;
2949 struct set_early_dwarf
{
2951 set_early_dwarf () : saved(early_dwarf
)
2953 gcc_assert (! early_dwarf_finished
);
2956 ~set_early_dwarf () { early_dwarf
= saved
; }
2959 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2960 #define FOR_EACH_CHILD(die, c, expr) do { \
2961 c = die->die_child; \
2965 } while (c != die->die_child); \
2968 /* The pubname structure */
2970 typedef struct GTY(()) pubname_struct
{
2977 struct GTY(()) dw_ranges
{
2979 /* If this is positive, it's a block number, otherwise it's a
2980 bitwise-negated index into dw_ranges_by_label. */
2982 /* Index for the range list for DW_FORM_rnglistx. */
2983 unsigned int idx
: 31;
2984 /* True if this range might be possibly in a different section
2985 from previous entry. */
2986 unsigned int maybe_new_sec
: 1;
2989 /* A structure to hold a macinfo entry. */
2991 typedef struct GTY(()) macinfo_struct
{
2993 unsigned HOST_WIDE_INT lineno
;
2999 struct GTY(()) dw_ranges_by_label
{
3004 /* The comdat type node structure. */
3005 struct GTY(()) comdat_type_node
3007 dw_die_ref root_die
;
3008 dw_die_ref type_die
;
3009 dw_die_ref skeleton_die
;
3010 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
3011 comdat_type_node
*next
;
3014 /* A list of DIEs for which we can't determine ancestry (parent_die
3015 field) just yet. Later in dwarf2out_finish we will fill in the
3017 typedef struct GTY(()) limbo_die_struct
{
3019 /* The tree for which this DIE was created. We use this to
3020 determine ancestry later. */
3022 struct limbo_die_struct
*next
;
3026 typedef struct skeleton_chain_struct
3030 struct skeleton_chain_struct
*parent
;
3032 skeleton_chain_node
;
3034 /* Define a macro which returns nonzero for a TYPE_DECL which was
3035 implicitly generated for a type.
3037 Note that, unlike the C front-end (which generates a NULL named
3038 TYPE_DECL node for each complete tagged type, each array type,
3039 and each function type node created) the C++ front-end generates
3040 a _named_ TYPE_DECL node for each tagged type node created.
3041 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3042 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
3043 front-end, but for each type, tagged or not. */
3045 #define TYPE_DECL_IS_STUB(decl) \
3046 (DECL_NAME (decl) == NULL_TREE \
3047 || (DECL_ARTIFICIAL (decl) \
3048 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3049 /* This is necessary for stub decls that \
3050 appear in nested inline functions. */ \
3051 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3052 && (decl_ultimate_origin (decl) \
3053 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3055 /* Information concerning the compilation unit's programming
3056 language, and compiler version. */
3058 /* Fixed size portion of the DWARF compilation unit header. */
3059 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3060 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE \
3061 + (dwarf_version >= 5 ? 4 : 3))
3063 /* Fixed size portion of the DWARF comdat type unit header. */
3064 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3065 (DWARF_COMPILE_UNIT_HEADER_SIZE \
3066 + DWARF_TYPE_SIGNATURE_SIZE + DWARF_OFFSET_SIZE)
3068 /* Fixed size portion of the DWARF skeleton compilation unit header. */
3069 #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
3070 (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
3072 /* Fixed size portion of public names info. */
3073 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3075 /* Fixed size portion of the address range info. */
3076 #define DWARF_ARANGES_HEADER_SIZE \
3077 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3078 DWARF2_ADDR_SIZE * 2) \
3079 - DWARF_INITIAL_LENGTH_SIZE)
3081 /* Size of padding portion in the address range info. It must be
3082 aligned to twice the pointer size. */
3083 #define DWARF_ARANGES_PAD_SIZE \
3084 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3085 DWARF2_ADDR_SIZE * 2) \
3086 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3088 /* Use assembler line directives if available. */
3089 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3090 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3091 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3093 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3097 /* Minimum line offset in a special line info. opcode.
3098 This value was chosen to give a reasonable range of values. */
3099 #define DWARF_LINE_BASE -10
3101 /* First special line opcode - leave room for the standard opcodes. */
3102 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3104 /* Range of line offsets in a special line info. opcode. */
3105 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3107 /* Flag that indicates the initial value of the is_stmt_start flag.
3108 In the present implementation, we do not mark any lines as
3109 the beginning of a source statement, because that information
3110 is not made available by the GCC front-end. */
3111 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3113 /* Maximum number of operations per instruction bundle. */
3114 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3115 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3118 /* This location is used by calc_die_sizes() to keep track
3119 the offset of each DIE within the .debug_info section. */
3120 static unsigned long next_die_offset
;
3122 /* Record the root of the DIE's built for the current compilation unit. */
3123 static GTY(()) dw_die_ref single_comp_unit_die
;
3125 /* A list of type DIEs that have been separated into comdat sections. */
3126 static GTY(()) comdat_type_node
*comdat_type_list
;
3128 /* A list of CU DIEs that have been separated. */
3129 static GTY(()) limbo_die_node
*cu_die_list
;
3131 /* A list of DIEs with a NULL parent waiting to be relocated. */
3132 static GTY(()) limbo_die_node
*limbo_die_list
;
3134 /* A list of DIEs for which we may have to generate
3135 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3136 static GTY(()) limbo_die_node
*deferred_asm_name
;
3138 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
3140 typedef const char *compare_type
;
3142 static hashval_t
hash (dwarf_file_data
*);
3143 static bool equal (dwarf_file_data
*, const char *);
3146 /* Filenames referenced by this compilation unit. */
3147 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
3149 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
3151 typedef tree compare_type
;
3153 static hashval_t
hash (die_node
*);
3154 static bool equal (die_node
*, tree
);
3156 /* A hash table of references to DIE's that describe declarations.
3157 The key is a DECL_UID() which is a unique number identifying each decl. */
3158 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
3160 struct GTY ((for_user
)) variable_value_struct
{
3161 unsigned int decl_id
;
3162 vec
<dw_die_ref
, va_gc
> *dies
;
3165 struct variable_value_hasher
: ggc_ptr_hash
<variable_value_struct
>
3167 typedef tree compare_type
;
3169 static hashval_t
hash (variable_value_struct
*);
3170 static bool equal (variable_value_struct
*, tree
);
3172 /* A hash table of DIEs that contain DW_OP_GNU_variable_value with
3173 dw_val_class_decl_ref class, indexed by FUNCTION_DECLs which is
3174 DECL_CONTEXT of the referenced VAR_DECLs. */
3175 static GTY (()) hash_table
<variable_value_hasher
> *variable_value_hash
;
3177 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
3179 static hashval_t
hash (die_struct
*);
3180 static bool equal (die_struct
*, die_struct
*);
3183 /* A hash table of references to DIE's that describe COMMON blocks.
3184 The key is DECL_UID() ^ die_parent. */
3185 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
3187 typedef struct GTY(()) die_arg_entry_struct
{
3193 /* Node of the variable location list. */
3194 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3195 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3196 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3197 in mode of the EXPR_LIST node and first EXPR_LIST operand
3198 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3199 location or NULL for padding. For larger bitsizes,
3200 mode is 0 and first operand is a CONCAT with bitsize
3201 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3202 NULL as second operand. */
3204 const char * GTY (()) label
;
3205 struct var_loc_node
* GTY (()) next
;
3208 /* Variable location list. */
3209 struct GTY ((for_user
)) var_loc_list_def
{
3210 struct var_loc_node
* GTY (()) first
;
3212 /* Pointer to the last but one or last element of the
3213 chained list. If the list is empty, both first and
3214 last are NULL, if the list contains just one node
3215 or the last node certainly is not redundant, it points
3216 to the last node, otherwise points to the last but one.
3217 Do not mark it for GC because it is marked through the chain. */
3218 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3220 /* Pointer to the last element before section switch,
3221 if NULL, either sections weren't switched or first
3222 is after section switch. */
3223 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3225 /* DECL_UID of the variable decl. */
3226 unsigned int decl_id
;
3228 typedef struct var_loc_list_def var_loc_list
;
3230 /* Call argument location list. */
3231 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3232 rtx
GTY (()) call_arg_loc_note
;
3233 const char * GTY (()) label
;
3234 tree
GTY (()) block
;
3236 rtx
GTY (()) symbol_ref
;
3237 struct call_arg_loc_node
* GTY (()) next
;
3241 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
3243 typedef const_tree compare_type
;
3245 static hashval_t
hash (var_loc_list
*);
3246 static bool equal (var_loc_list
*, const_tree
);
3249 /* Table of decl location linked lists. */
3250 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
3252 /* Head and tail of call_arg_loc chain. */
3253 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3254 static struct call_arg_loc_node
*call_arg_loc_last
;
3256 /* Number of call sites in the current function. */
3257 static int call_site_count
= -1;
3258 /* Number of tail call sites in the current function. */
3259 static int tail_call_site_count
= -1;
3261 /* A cached location list. */
3262 struct GTY ((for_user
)) cached_dw_loc_list_def
{
3263 /* The DECL_UID of the decl that this entry describes. */
3264 unsigned int decl_id
;
3266 /* The cached location list. */
3267 dw_loc_list_ref loc_list
;
3269 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3271 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3274 typedef const_tree compare_type
;
3276 static hashval_t
hash (cached_dw_loc_list
*);
3277 static bool equal (cached_dw_loc_list
*, const_tree
);
3280 /* Table of cached location lists. */
3281 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3283 /* A vector of references to DIE's that are uniquely identified by their tag,
3284 presence/absence of children DIE's, and list of attribute/value pairs. */
3285 static GTY(()) vec
<dw_die_ref
, va_gc
> *abbrev_die_table
;
3287 /* A hash map to remember the stack usage for DWARF procedures. The value
3288 stored is the stack size difference between before the DWARF procedure
3289 invokation and after it returned. In other words, for a DWARF procedure
3290 that consumes N stack slots and that pushes M ones, this stores M - N. */
3291 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3293 /* A global counter for generating labels for line number data. */
3294 static unsigned int line_info_label_num
;
3296 /* The current table to which we should emit line number information
3297 for the current function. This will be set up at the beginning of
3298 assembly for the function. */
3299 static GTY(()) dw_line_info_table
*cur_line_info_table
;
3301 /* The two default tables of line number info. */
3302 static GTY(()) dw_line_info_table
*text_section_line_info
;
3303 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3305 /* The set of all non-default tables of line number info. */
3306 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3308 /* A flag to tell pubnames/types export if there is an info section to
3310 static bool info_section_emitted
;
3312 /* A pointer to the base of a table that contains a list of publicly
3313 accessible names. */
3314 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3316 /* A pointer to the base of a table that contains a list of publicly
3317 accessible types. */
3318 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3320 /* A pointer to the base of a table that contains a list of macro
3321 defines/undefines (and file start/end markers). */
3322 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3324 /* True if .debug_macinfo or .debug_macros section is going to be
3326 #define have_macinfo \
3327 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3328 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3329 && !macinfo_table->is_empty ())
3331 /* Vector of dies for which we should generate .debug_ranges info. */
3332 static GTY (()) vec
<dw_ranges
, va_gc
> *ranges_table
;
3334 /* Vector of pairs of labels referenced in ranges_table. */
3335 static GTY (()) vec
<dw_ranges_by_label
, va_gc
> *ranges_by_label
;
3337 /* Whether we have location lists that need outputting */
3338 static GTY(()) bool have_location_lists
;
3340 /* Unique label counter. */
3341 static GTY(()) unsigned int loclabel_num
;
3343 /* Unique label counter for point-of-call tables. */
3344 static GTY(()) unsigned int poc_label_num
;
3346 /* The last file entry emitted by maybe_emit_file(). */
3347 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3349 /* Number of internal labels generated by gen_internal_sym(). */
3350 static GTY(()) int label_num
;
3352 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3354 /* Instances of generic types for which we need to generate debug
3355 info that describe their generic parameters and arguments. That
3356 generation needs to happen once all types are properly laid out so
3357 we do it at the end of compilation. */
3358 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3360 /* Offset from the "steady-state frame pointer" to the frame base,
3361 within the current function. */
3362 static poly_int64 frame_pointer_fb_offset
;
3363 static bool frame_pointer_fb_offset_valid
;
3365 static vec
<dw_die_ref
> base_types
;
3367 /* Flags to represent a set of attribute classes for attributes that represent
3368 a scalar value (bounds, pointers, ...). */
3371 dw_scalar_form_constant
= 0x01,
3372 dw_scalar_form_exprloc
= 0x02,
3373 dw_scalar_form_reference
= 0x04
3376 /* Forward declarations for functions defined in this file. */
3378 static int is_pseudo_reg (const_rtx
);
3379 static tree
type_main_variant (tree
);
3380 static int is_tagged_type (const_tree
);
3381 static const char *dwarf_tag_name (unsigned);
3382 static const char *dwarf_attr_name (unsigned);
3383 static const char *dwarf_form_name (unsigned);
3384 static tree
decl_ultimate_origin (const_tree
);
3385 static tree
decl_class_context (tree
);
3386 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3387 static inline enum dw_val_class
AT_class (dw_attr_node
*);
3388 static inline unsigned int AT_index (dw_attr_node
*);
3389 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3390 static inline unsigned AT_flag (dw_attr_node
*);
3391 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3392 static inline HOST_WIDE_INT
AT_int (dw_attr_node
*);
3393 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3394 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_node
*);
3395 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3396 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3397 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3398 unsigned int, unsigned char *);
3399 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3400 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3401 static inline const char *AT_string (dw_attr_node
*);
3402 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3403 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3404 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3405 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3406 static inline int AT_ref_external (dw_attr_node
*);
3407 static inline void set_AT_ref_external (dw_attr_node
*, int);
3408 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3409 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3410 static inline dw_loc_descr_ref
AT_loc (dw_attr_node
*);
3411 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3413 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3414 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3415 static void remove_addr_table_entry (addr_table_entry
*);
3416 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3417 static inline rtx
AT_addr (dw_attr_node
*);
3418 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3419 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3420 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3421 static void add_AT_loclistsptr (dw_die_ref
, enum dwarf_attribute
,
3423 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3424 unsigned HOST_WIDE_INT
);
3425 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3426 unsigned long, bool);
3427 static inline const char *AT_lbl (dw_attr_node
*);
3428 static dw_attr_node
*get_AT (dw_die_ref
, enum dwarf_attribute
);
3429 static const char *get_AT_low_pc (dw_die_ref
);
3430 static const char *get_AT_hi_pc (dw_die_ref
);
3431 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3432 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3433 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3434 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3435 static bool is_cxx (void);
3436 static bool is_cxx (const_tree
);
3437 static bool is_fortran (void);
3438 static bool is_ada (void);
3439 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3440 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3441 static void add_child_die (dw_die_ref
, dw_die_ref
);
3442 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3443 static dw_die_ref
lookup_type_die (tree
);
3444 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3445 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3446 static void equate_type_number_to_die (tree
, dw_die_ref
);
3447 static dw_die_ref
lookup_decl_die (tree
);
3448 static var_loc_list
*lookup_decl_loc (const_tree
);
3449 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3450 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3451 static void print_spaces (FILE *);
3452 static void print_die (dw_die_ref
, FILE *);
3453 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3454 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3455 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3456 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3457 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3458 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3459 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3460 struct md5_ctx
*, int *);
3461 struct checksum_attributes
;
3462 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3463 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3464 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3465 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3466 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3467 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3468 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3469 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3470 static int is_type_die (dw_die_ref
);
3471 static int is_comdat_die (dw_die_ref
);
3472 static inline bool is_template_instantiation (dw_die_ref
);
3473 static int is_declaration_die (dw_die_ref
);
3474 static int should_move_die_to_comdat (dw_die_ref
);
3475 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3476 static dw_die_ref
clone_die (dw_die_ref
);
3477 static dw_die_ref
clone_tree (dw_die_ref
);
3478 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3479 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3480 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3481 static dw_die_ref
generate_skeleton (dw_die_ref
);
3482 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3485 static void break_out_comdat_types (dw_die_ref
);
3486 static void copy_decls_for_unworthy_types (dw_die_ref
);
3488 static void add_sibling_attributes (dw_die_ref
);
3489 static void output_location_lists (dw_die_ref
);
3490 static int constant_size (unsigned HOST_WIDE_INT
);
3491 static unsigned long size_of_die (dw_die_ref
);
3492 static void calc_die_sizes (dw_die_ref
);
3493 static void calc_base_type_die_sizes (void);
3494 static void mark_dies (dw_die_ref
);
3495 static void unmark_dies (dw_die_ref
);
3496 static void unmark_all_dies (dw_die_ref
);
3497 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3498 static unsigned long size_of_aranges (void);
3499 static enum dwarf_form
value_format (dw_attr_node
*);
3500 static void output_value_format (dw_attr_node
*);
3501 static void output_abbrev_section (void);
3502 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3503 static void output_die (dw_die_ref
);
3504 static void output_compilation_unit_header (enum dwarf_unit_type
);
3505 static void output_comp_unit (dw_die_ref
, int, const unsigned char *);
3506 static void output_comdat_type_unit (comdat_type_node
*);
3507 static const char *dwarf2_name (tree
, int);
3508 static void add_pubname (tree
, dw_die_ref
);
3509 static void add_enumerator_pubname (const char *, dw_die_ref
);
3510 static void add_pubname_string (const char *, dw_die_ref
);
3511 static void add_pubtype (tree
, dw_die_ref
);
3512 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3513 static void output_aranges (void);
3514 static unsigned int add_ranges (const_tree
, bool = false);
3515 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3517 static void output_ranges (void);
3518 static dw_line_info_table
*new_line_info_table (void);
3519 static void output_line_info (bool);
3520 static void output_file_names (void);
3521 static dw_die_ref
base_type_die (tree
, bool);
3522 static int is_base_type (tree
);
3523 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3524 static int decl_quals (const_tree
);
3525 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3526 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3527 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3528 static int type_is_enum (const_tree
);
3529 static unsigned int dbx_reg_number (const_rtx
);
3530 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3531 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3532 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3533 enum var_init_status
);
3534 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3535 enum var_init_status
);
3536 static dw_loc_descr_ref
based_loc_descr (rtx
, poly_int64
,
3537 enum var_init_status
);
3538 static int is_based_loc (const_rtx
);
3539 static bool resolve_one_addr (rtx
*);
3540 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3541 enum var_init_status
);
3542 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3543 enum var_init_status
);
3544 struct loc_descr_context
;
3545 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3546 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3547 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3548 struct loc_descr_context
*);
3549 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3550 struct loc_descr_context
*);
3551 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3552 static tree
field_type (const_tree
);
3553 static unsigned int simple_type_align_in_bits (const_tree
);
3554 static unsigned int simple_decl_align_in_bits (const_tree
);
3555 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3557 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3559 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3561 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3562 struct vlr_context
*);
3563 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3564 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3565 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3566 static void insert_float (const_rtx
, unsigned char *);
3567 static rtx
rtl_for_decl_location (tree
);
3568 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3569 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3570 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3571 static void add_name_attribute (dw_die_ref
, const char *);
3572 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3573 static void add_comp_dir_attribute (dw_die_ref
);
3574 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3575 struct loc_descr_context
*);
3576 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3577 struct loc_descr_context
*);
3578 static void add_subscript_info (dw_die_ref
, tree
, bool);
3579 static void add_byte_size_attribute (dw_die_ref
, tree
);
3580 static void add_alignment_attribute (dw_die_ref
, tree
);
3581 static inline void add_bit_offset_attribute (dw_die_ref
, tree
,
3582 struct vlr_context
*);
3583 static void add_bit_size_attribute (dw_die_ref
, tree
);
3584 static void add_prototyped_attribute (dw_die_ref
, tree
);
3585 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3586 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3587 static void add_src_coords_attributes (dw_die_ref
, tree
);
3588 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
, bool = false);
3589 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3590 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3591 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3592 static void push_decl_scope (tree
);
3593 static void pop_decl_scope (void);
3594 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3595 static inline int local_scope_p (dw_die_ref
);
3596 static inline int class_scope_p (dw_die_ref
);
3597 static inline int class_or_namespace_scope_p (dw_die_ref
);
3598 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3599 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3600 static const char *type_tag (const_tree
);
3601 static tree
member_declared_type (const_tree
);
3603 static const char *decl_start_label (tree
);
3605 static void gen_array_type_die (tree
, dw_die_ref
);
3606 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3608 static void gen_entry_point_die (tree
, dw_die_ref
);
3610 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3611 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3612 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3613 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3614 static void gen_formal_types_die (tree
, dw_die_ref
);
3615 static void gen_subprogram_die (tree
, dw_die_ref
);
3616 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3617 static void gen_const_die (tree
, dw_die_ref
);
3618 static void gen_label_die (tree
, dw_die_ref
);
3619 static void gen_lexical_block_die (tree
, dw_die_ref
);
3620 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3621 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3622 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3623 static dw_die_ref
gen_compile_unit_die (const char *);
3624 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3625 static void gen_member_die (tree
, dw_die_ref
);
3626 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3627 enum debug_info_usage
);
3628 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3629 static void gen_typedef_die (tree
, dw_die_ref
);
3630 static void gen_type_die (tree
, dw_die_ref
);
3631 static void gen_block_die (tree
, dw_die_ref
);
3632 static void decls_for_scope (tree
, dw_die_ref
);
3633 static bool is_naming_typedef_decl (const_tree
);
3634 static inline dw_die_ref
get_context_die (tree
);
3635 static void gen_namespace_die (tree
, dw_die_ref
);
3636 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3637 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3638 static dw_die_ref
force_decl_die (tree
);
3639 static dw_die_ref
force_type_die (tree
);
3640 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3641 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3642 static struct dwarf_file_data
* lookup_filename (const char *);
3643 static void retry_incomplete_types (void);
3644 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3645 static void gen_generic_params_dies (tree
);
3646 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3647 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3648 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3649 static int file_info_cmp (const void *, const void *);
3650 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3651 const char *, const char *);
3652 static void output_loc_list (dw_loc_list_ref
);
3653 static char *gen_internal_sym (const char *);
3654 static bool want_pubnames (void);
3656 static void prune_unmark_dies (dw_die_ref
);
3657 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3658 static void prune_unused_types_mark (dw_die_ref
, int);
3659 static void prune_unused_types_walk (dw_die_ref
);
3660 static void prune_unused_types_walk_attribs (dw_die_ref
);
3661 static void prune_unused_types_prune (dw_die_ref
);
3662 static void prune_unused_types (void);
3663 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3664 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3665 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3666 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3667 const char *, const char *);
3668 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3669 static void gen_remaining_tmpl_value_param_die_attribute (void);
3670 static bool generic_type_p (tree
);
3671 static void schedule_generic_params_dies_gen (tree t
);
3672 static void gen_scheduled_generic_parms_dies (void);
3673 static void resolve_variable_values (void);
3675 static const char *comp_dir_string (void);
3677 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3679 /* enum for tracking thread-local variables whose address is really an offset
3680 relative to the TLS pointer, which will need link-time relocation, but will
3681 not need relocation by the DWARF consumer. */
3689 /* Return the operator to use for an address of a variable. For dtprel_true, we
3690 use DW_OP_const*. For regular variables, which need both link-time
3691 relocation and consumer-level relocation (e.g., to account for shared objects
3692 loaded at a random address), we use DW_OP_addr*. */
3694 static inline enum dwarf_location_atom
3695 dw_addr_op (enum dtprel_bool dtprel
)
3697 if (dtprel
== dtprel_true
)
3698 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3699 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3701 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3704 /* Return a pointer to a newly allocated address location description. If
3705 dwarf_split_debug_info is true, then record the address with the appropriate
3707 static inline dw_loc_descr_ref
3708 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3710 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3712 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3713 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3714 ref
->dtprel
= dtprel
;
3715 if (dwarf_split_debug_info
)
3716 ref
->dw_loc_oprnd1
.val_entry
3717 = add_addr_table_entry (addr
,
3718 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3720 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3725 /* Section names used to hold DWARF debugging information. */
3727 #ifndef DEBUG_INFO_SECTION
3728 #define DEBUG_INFO_SECTION ".debug_info"
3730 #ifndef DEBUG_DWO_INFO_SECTION
3731 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3733 #ifndef DEBUG_LTO_INFO_SECTION
3734 #define DEBUG_LTO_INFO_SECTION ".gnu.debuglto_.debug_info"
3736 #ifndef DEBUG_LTO_DWO_INFO_SECTION
3737 #define DEBUG_LTO_DWO_INFO_SECTION ".gnu.debuglto_.debug_info.dwo"
3739 #ifndef DEBUG_ABBREV_SECTION
3740 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3742 #ifndef DEBUG_LTO_ABBREV_SECTION
3743 #define DEBUG_LTO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev"
3745 #ifndef DEBUG_DWO_ABBREV_SECTION
3746 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3748 #ifndef DEBUG_LTO_DWO_ABBREV_SECTION
3749 #define DEBUG_LTO_DWO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev.dwo"
3751 #ifndef DEBUG_ARANGES_SECTION
3752 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3754 #ifndef DEBUG_ADDR_SECTION
3755 #define DEBUG_ADDR_SECTION ".debug_addr"
3757 #ifndef DEBUG_MACINFO_SECTION
3758 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3760 #ifndef DEBUG_LTO_MACINFO_SECTION
3761 #define DEBUG_LTO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo"
3763 #ifndef DEBUG_DWO_MACINFO_SECTION
3764 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3766 #ifndef DEBUG_LTO_DWO_MACINFO_SECTION
3767 #define DEBUG_LTO_DWO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo.dwo"
3769 #ifndef DEBUG_MACRO_SECTION
3770 #define DEBUG_MACRO_SECTION ".debug_macro"
3772 #ifndef DEBUG_LTO_MACRO_SECTION
3773 #define DEBUG_LTO_MACRO_SECTION ".gnu.debuglto_.debug_macro"
3775 #ifndef DEBUG_DWO_MACRO_SECTION
3776 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3778 #ifndef DEBUG_LTO_DWO_MACRO_SECTION
3779 #define DEBUG_LTO_DWO_MACRO_SECTION ".gnu.debuglto_.debug_macro.dwo"
3781 #ifndef DEBUG_LINE_SECTION
3782 #define DEBUG_LINE_SECTION ".debug_line"
3784 #ifndef DEBUG_LTO_LINE_SECTION
3785 #define DEBUG_LTO_LINE_SECTION ".gnu.debuglto_.debug_line"
3787 #ifndef DEBUG_DWO_LINE_SECTION
3788 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3790 #ifndef DEBUG_LTO_DWO_LINE_SECTION
3791 #define DEBUG_LTO_DWO_LINE_SECTION ".gnu.debuglto_.debug_line.dwo"
3793 #ifndef DEBUG_LOC_SECTION
3794 #define DEBUG_LOC_SECTION ".debug_loc"
3796 #ifndef DEBUG_DWO_LOC_SECTION
3797 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3799 #ifndef DEBUG_LOCLISTS_SECTION
3800 #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
3802 #ifndef DEBUG_DWO_LOCLISTS_SECTION
3803 #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
3805 #ifndef DEBUG_PUBNAMES_SECTION
3806 #define DEBUG_PUBNAMES_SECTION \
3807 ((debug_generate_pub_sections == 2) \
3808 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3810 #ifndef DEBUG_PUBTYPES_SECTION
3811 #define DEBUG_PUBTYPES_SECTION \
3812 ((debug_generate_pub_sections == 2) \
3813 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3815 #ifndef DEBUG_STR_OFFSETS_SECTION
3816 #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
3818 #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
3819 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3821 #ifndef DEBUG_LTO_DWO_STR_OFFSETS_SECTION
3822 #define DEBUG_LTO_DWO_STR_OFFSETS_SECTION ".gnu.debuglto_.debug_str_offsets.dwo"
3824 #ifndef DEBUG_STR_SECTION
3825 #define DEBUG_STR_SECTION ".debug_str"
3827 #ifndef DEBUG_LTO_STR_SECTION
3828 #define DEBUG_LTO_STR_SECTION ".gnu.debuglto_.debug_str"
3830 #ifndef DEBUG_STR_DWO_SECTION
3831 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3833 #ifndef DEBUG_LTO_STR_DWO_SECTION
3834 #define DEBUG_LTO_STR_DWO_SECTION ".gnu.debuglto_.debug_str.dwo"
3836 #ifndef DEBUG_RANGES_SECTION
3837 #define DEBUG_RANGES_SECTION ".debug_ranges"
3839 #ifndef DEBUG_RNGLISTS_SECTION
3840 #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
3842 #ifndef DEBUG_LINE_STR_SECTION
3843 #define DEBUG_LINE_STR_SECTION ".debug_line_str"
3845 #ifndef DEBUG_LTO_LINE_STR_SECTION
3846 #define DEBUG_LTO_LINE_STR_SECTION ".gnu.debuglto_.debug_line_str"
3849 /* Standard ELF section names for compiled code and data. */
3850 #ifndef TEXT_SECTION_NAME
3851 #define TEXT_SECTION_NAME ".text"
3854 /* Section flags for .debug_str section. */
3855 #define DEBUG_STR_SECTION_FLAGS \
3856 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3857 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3860 /* Section flags for .debug_str.dwo section. */
3861 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3863 /* Attribute used to refer to the macro section. */
3864 #define DEBUG_MACRO_ATTRIBUTE (dwarf_version >= 5 ? DW_AT_macros \
3865 : dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros)
3867 /* Labels we insert at beginning sections we can reference instead of
3868 the section names themselves. */
3870 #ifndef TEXT_SECTION_LABEL
3871 #define TEXT_SECTION_LABEL "Ltext"
3873 #ifndef COLD_TEXT_SECTION_LABEL
3874 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3876 #ifndef DEBUG_LINE_SECTION_LABEL
3877 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3879 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3880 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3882 #ifndef DEBUG_INFO_SECTION_LABEL
3883 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3885 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3886 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3888 #ifndef DEBUG_ABBREV_SECTION_LABEL
3889 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3891 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3892 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3894 #ifndef DEBUG_ADDR_SECTION_LABEL
3895 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3897 #ifndef DEBUG_LOC_SECTION_LABEL
3898 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3900 #ifndef DEBUG_RANGES_SECTION_LABEL
3901 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3903 #ifndef DEBUG_MACINFO_SECTION_LABEL
3904 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3906 #ifndef DEBUG_MACRO_SECTION_LABEL
3907 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3909 #define SKELETON_COMP_DIE_ABBREV 1
3910 #define SKELETON_TYPE_DIE_ABBREV 2
3912 /* Definitions of defaults for formats and names of various special
3913 (artificial) labels which may be generated within this file (when the -g
3914 options is used and DWARF2_DEBUGGING_INFO is in effect.
3915 If necessary, these may be overridden from within the tm.h file, but
3916 typically, overriding these defaults is unnecessary. */
3918 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3919 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3920 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3921 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3922 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3923 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3924 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3925 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3926 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3927 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3928 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3929 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3930 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3931 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3932 static char ranges_base_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3934 #ifndef TEXT_END_LABEL
3935 #define TEXT_END_LABEL "Letext"
3937 #ifndef COLD_END_LABEL
3938 #define COLD_END_LABEL "Letext_cold"
3940 #ifndef BLOCK_BEGIN_LABEL
3941 #define BLOCK_BEGIN_LABEL "LBB"
3943 #ifndef BLOCK_END_LABEL
3944 #define BLOCK_END_LABEL "LBE"
3946 #ifndef LINE_CODE_LABEL
3947 #define LINE_CODE_LABEL "LM"
3951 /* Return the root of the DIE's built for the current compilation unit. */
3953 comp_unit_die (void)
3955 if (!single_comp_unit_die
)
3956 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3957 return single_comp_unit_die
;
3960 /* We allow a language front-end to designate a function that is to be
3961 called to "demangle" any name before it is put into a DIE. */
3963 static const char *(*demangle_name_func
) (const char *);
3966 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3968 demangle_name_func
= func
;
3971 /* Test if rtl node points to a pseudo register. */
3974 is_pseudo_reg (const_rtx rtl
)
3976 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3977 || (GET_CODE (rtl
) == SUBREG
3978 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3981 /* Return a reference to a type, with its const and volatile qualifiers
3985 type_main_variant (tree type
)
3987 type
= TYPE_MAIN_VARIANT (type
);
3989 /* ??? There really should be only one main variant among any group of
3990 variants of a given type (and all of the MAIN_VARIANT values for all
3991 members of the group should point to that one type) but sometimes the C
3992 front-end messes this up for array types, so we work around that bug
3994 if (TREE_CODE (type
) == ARRAY_TYPE
)
3995 while (type
!= TYPE_MAIN_VARIANT (type
))
3996 type
= TYPE_MAIN_VARIANT (type
);
4001 /* Return nonzero if the given type node represents a tagged type. */
4004 is_tagged_type (const_tree type
)
4006 enum tree_code code
= TREE_CODE (type
);
4008 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4009 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4012 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
4015 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
4017 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
4020 /* Return die_offset of a DIE reference to a base type. */
4022 static unsigned long int
4023 get_base_type_offset (dw_die_ref ref
)
4025 if (ref
->die_offset
)
4026 return ref
->die_offset
;
4027 if (comp_unit_die ()->die_abbrev
)
4029 calc_base_type_die_sizes ();
4030 gcc_assert (ref
->die_offset
);
4032 return ref
->die_offset
;
4035 /* Return die_offset of a DIE reference other than base type. */
4037 static unsigned long int
4038 get_ref_die_offset (dw_die_ref ref
)
4040 gcc_assert (ref
->die_offset
);
4041 return ref
->die_offset
;
4044 /* Convert a DIE tag into its string name. */
4047 dwarf_tag_name (unsigned int tag
)
4049 const char *name
= get_DW_TAG_name (tag
);
4054 return "DW_TAG_<unknown>";
4057 /* Convert a DWARF attribute code into its string name. */
4060 dwarf_attr_name (unsigned int attr
)
4066 #if VMS_DEBUGGING_INFO
4067 case DW_AT_HP_prologue
:
4068 return "DW_AT_HP_prologue";
4070 case DW_AT_MIPS_loop_unroll_factor
:
4071 return "DW_AT_MIPS_loop_unroll_factor";
4074 #if VMS_DEBUGGING_INFO
4075 case DW_AT_HP_epilogue
:
4076 return "DW_AT_HP_epilogue";
4078 case DW_AT_MIPS_stride
:
4079 return "DW_AT_MIPS_stride";
4083 name
= get_DW_AT_name (attr
);
4088 return "DW_AT_<unknown>";
4091 /* Convert a DWARF value form code into its string name. */
4094 dwarf_form_name (unsigned int form
)
4096 const char *name
= get_DW_FORM_name (form
);
4101 return "DW_FORM_<unknown>";
4104 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4105 instance of an inlined instance of a decl which is local to an inline
4106 function, so we have to trace all of the way back through the origin chain
4107 to find out what sort of node actually served as the original seed for the
4111 decl_ultimate_origin (const_tree decl
)
4113 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4116 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4117 we're trying to output the abstract instance of this function. */
4118 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4121 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4122 most distant ancestor, this should never happen. */
4123 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4125 return DECL_ABSTRACT_ORIGIN (decl
);
4128 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4129 of a virtual function may refer to a base class, so we check the 'this'
4133 decl_class_context (tree decl
)
4135 tree context
= NULL_TREE
;
4137 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4138 context
= DECL_CONTEXT (decl
);
4140 context
= TYPE_MAIN_VARIANT
4141 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4143 if (context
&& !TYPE_P (context
))
4144 context
= NULL_TREE
;
4149 /* Add an attribute/value pair to a DIE. */
4152 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
4154 /* Maybe this should be an assert? */
4160 /* Check we do not add duplicate attrs. Can't use get_AT here
4161 because that recurses to the specification/abstract origin DIE. */
4164 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4165 gcc_assert (a
->dw_attr
!= attr
->dw_attr
);
4168 vec_safe_reserve (die
->die_attr
, 1);
4169 vec_safe_push (die
->die_attr
, *attr
);
4172 static inline enum dw_val_class
4173 AT_class (dw_attr_node
*a
)
4175 return a
->dw_attr_val
.val_class
;
4178 /* Return the index for any attribute that will be referenced with a
4179 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
4180 are stored in dw_attr_val.v.val_str for reference counting
4183 static inline unsigned int
4184 AT_index (dw_attr_node
*a
)
4186 if (AT_class (a
) == dw_val_class_str
)
4187 return a
->dw_attr_val
.v
.val_str
->index
;
4188 else if (a
->dw_attr_val
.val_entry
!= NULL
)
4189 return a
->dw_attr_val
.val_entry
->index
;
4193 /* Add a flag value attribute to a DIE. */
4196 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4200 attr
.dw_attr
= attr_kind
;
4201 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4202 attr
.dw_attr_val
.val_entry
= NULL
;
4203 attr
.dw_attr_val
.v
.val_flag
= flag
;
4204 add_dwarf_attr (die
, &attr
);
4207 static inline unsigned
4208 AT_flag (dw_attr_node
*a
)
4210 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4211 return a
->dw_attr_val
.v
.val_flag
;
4214 /* Add a signed integer attribute value to a DIE. */
4217 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4221 attr
.dw_attr
= attr_kind
;
4222 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4223 attr
.dw_attr_val
.val_entry
= NULL
;
4224 attr
.dw_attr_val
.v
.val_int
= int_val
;
4225 add_dwarf_attr (die
, &attr
);
4228 static inline HOST_WIDE_INT
4229 AT_int (dw_attr_node
*a
)
4231 gcc_assert (a
&& (AT_class (a
) == dw_val_class_const
4232 || AT_class (a
) == dw_val_class_const_implicit
));
4233 return a
->dw_attr_val
.v
.val_int
;
4236 /* Add an unsigned integer attribute value to a DIE. */
4239 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4240 unsigned HOST_WIDE_INT unsigned_val
)
4244 attr
.dw_attr
= attr_kind
;
4245 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4246 attr
.dw_attr_val
.val_entry
= NULL
;
4247 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4248 add_dwarf_attr (die
, &attr
);
4251 static inline unsigned HOST_WIDE_INT
4252 AT_unsigned (dw_attr_node
*a
)
4254 gcc_assert (a
&& (AT_class (a
) == dw_val_class_unsigned_const
4255 || AT_class (a
) == dw_val_class_unsigned_const_implicit
));
4256 return a
->dw_attr_val
.v
.val_unsigned
;
4259 /* Add an unsigned wide integer attribute value to a DIE. */
4262 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4267 attr
.dw_attr
= attr_kind
;
4268 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
4269 attr
.dw_attr_val
.val_entry
= NULL
;
4270 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
4271 *attr
.dw_attr_val
.v
.val_wide
= w
;
4272 add_dwarf_attr (die
, &attr
);
4275 /* Add an unsigned double integer attribute value to a DIE. */
4278 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4279 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4283 attr
.dw_attr
= attr_kind
;
4284 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4285 attr
.dw_attr_val
.val_entry
= NULL
;
4286 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4287 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4288 add_dwarf_attr (die
, &attr
);
4291 /* Add a floating point attribute value to a DIE and return it. */
4294 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4295 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4299 attr
.dw_attr
= attr_kind
;
4300 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4301 attr
.dw_attr_val
.val_entry
= NULL
;
4302 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4303 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4304 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4305 add_dwarf_attr (die
, &attr
);
4308 /* Add an 8-byte data attribute value to a DIE. */
4311 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4312 unsigned char data8
[8])
4316 attr
.dw_attr
= attr_kind
;
4317 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4318 attr
.dw_attr_val
.val_entry
= NULL
;
4319 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4320 add_dwarf_attr (die
, &attr
);
4323 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4324 dwarf_split_debug_info, address attributes in dies destined for the
4325 final executable have force_direct set to avoid using indexed
4329 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4335 lbl_id
= xstrdup (lbl_low
);
4336 attr
.dw_attr
= DW_AT_low_pc
;
4337 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4338 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4339 if (dwarf_split_debug_info
&& !force_direct
)
4340 attr
.dw_attr_val
.val_entry
4341 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4343 attr
.dw_attr_val
.val_entry
= NULL
;
4344 add_dwarf_attr (die
, &attr
);
4346 attr
.dw_attr
= DW_AT_high_pc
;
4347 if (dwarf_version
< 4)
4348 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4350 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4351 lbl_id
= xstrdup (lbl_high
);
4352 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4353 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4354 && dwarf_split_debug_info
&& !force_direct
)
4355 attr
.dw_attr_val
.val_entry
4356 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4358 attr
.dw_attr_val
.val_entry
= NULL
;
4359 add_dwarf_attr (die
, &attr
);
4362 /* Hash and equality functions for debug_str_hash. */
4365 indirect_string_hasher::hash (indirect_string_node
*x
)
4367 return htab_hash_string (x
->str
);
4371 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4373 return strcmp (x1
->str
, x2
) == 0;
4376 /* Add STR to the given string hash table. */
4378 static struct indirect_string_node
*
4379 find_AT_string_in_table (const char *str
,
4380 hash_table
<indirect_string_hasher
> *table
)
4382 struct indirect_string_node
*node
;
4384 indirect_string_node
**slot
4385 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
4388 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4389 node
->str
= ggc_strdup (str
);
4399 /* Add STR to the indirect string hash table. */
4401 static struct indirect_string_node
*
4402 find_AT_string (const char *str
)
4404 if (! debug_str_hash
)
4405 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4407 return find_AT_string_in_table (str
, debug_str_hash
);
4410 /* Add a string attribute value to a DIE. */
4413 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4416 struct indirect_string_node
*node
;
4418 node
= find_AT_string (str
);
4420 attr
.dw_attr
= attr_kind
;
4421 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4422 attr
.dw_attr_val
.val_entry
= NULL
;
4423 attr
.dw_attr_val
.v
.val_str
= node
;
4424 add_dwarf_attr (die
, &attr
);
4427 static inline const char *
4428 AT_string (dw_attr_node
*a
)
4430 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4431 return a
->dw_attr_val
.v
.val_str
->str
;
4434 /* Call this function directly to bypass AT_string_form's logic to put
4435 the string inline in the die. */
4438 set_indirect_string (struct indirect_string_node
*node
)
4440 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4441 /* Already indirect is a no op. */
4442 if (node
->form
== DW_FORM_strp
4443 || node
->form
== DW_FORM_line_strp
4444 || node
->form
== DW_FORM_GNU_str_index
)
4446 gcc_assert (node
->label
);
4449 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4450 ++dw2_string_counter
;
4451 node
->label
= xstrdup (label
);
4453 if (!dwarf_split_debug_info
)
4455 node
->form
= DW_FORM_strp
;
4456 node
->index
= NOT_INDEXED
;
4460 node
->form
= DW_FORM_GNU_str_index
;
4461 node
->index
= NO_INDEX_ASSIGNED
;
4465 /* A helper function for dwarf2out_finish, called to reset indirect
4466 string decisions done for early LTO dwarf output before fat object
4470 reset_indirect_string (indirect_string_node
**h
, void *)
4472 struct indirect_string_node
*node
= *h
;
4473 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4477 node
->form
= (dwarf_form
) 0;
4483 /* Find out whether a string should be output inline in DIE
4484 or out-of-line in .debug_str section. */
4486 static enum dwarf_form
4487 find_string_form (struct indirect_string_node
*node
)
4494 len
= strlen (node
->str
) + 1;
4496 /* If the string is shorter or equal to the size of the reference, it is
4497 always better to put it inline. */
4498 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4499 return node
->form
= DW_FORM_string
;
4501 /* If we cannot expect the linker to merge strings in .debug_str
4502 section, only put it into .debug_str if it is worth even in this
4504 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4505 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4506 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4507 return node
->form
= DW_FORM_string
;
4509 set_indirect_string (node
);
4514 /* Find out whether the string referenced from the attribute should be
4515 output inline in DIE or out-of-line in .debug_str section. */
4517 static enum dwarf_form
4518 AT_string_form (dw_attr_node
*a
)
4520 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4521 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4524 /* Add a DIE reference attribute value to a DIE. */
4527 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4530 gcc_checking_assert (targ_die
!= NULL
);
4532 /* With LTO we can end up trying to reference something we didn't create
4533 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4534 if (targ_die
== NULL
)
4537 attr
.dw_attr
= attr_kind
;
4538 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4539 attr
.dw_attr_val
.val_entry
= NULL
;
4540 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4541 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4542 add_dwarf_attr (die
, &attr
);
4545 /* Change DIE reference REF to point to NEW_DIE instead. */
4548 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4550 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4551 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4552 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4555 /* Add an AT_specification attribute to a DIE, and also make the back
4556 pointer from the specification to the definition. */
4559 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4561 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4562 gcc_assert (!targ_die
->die_definition
);
4563 targ_die
->die_definition
= die
;
4566 static inline dw_die_ref
4567 AT_ref (dw_attr_node
*a
)
4569 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4570 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4574 AT_ref_external (dw_attr_node
*a
)
4576 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4577 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4583 set_AT_ref_external (dw_attr_node
*a
, int i
)
4585 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4586 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4589 /* Add an FDE reference attribute value to a DIE. */
4592 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4596 attr
.dw_attr
= attr_kind
;
4597 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4598 attr
.dw_attr_val
.val_entry
= NULL
;
4599 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4600 add_dwarf_attr (die
, &attr
);
4603 /* Add a location description attribute value to a DIE. */
4606 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4610 attr
.dw_attr
= attr_kind
;
4611 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4612 attr
.dw_attr_val
.val_entry
= NULL
;
4613 attr
.dw_attr_val
.v
.val_loc
= loc
;
4614 add_dwarf_attr (die
, &attr
);
4617 static inline dw_loc_descr_ref
4618 AT_loc (dw_attr_node
*a
)
4620 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4621 return a
->dw_attr_val
.v
.val_loc
;
4625 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4629 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4632 attr
.dw_attr
= attr_kind
;
4633 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4634 attr
.dw_attr_val
.val_entry
= NULL
;
4635 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4636 add_dwarf_attr (die
, &attr
);
4637 have_location_lists
= true;
4640 static inline dw_loc_list_ref
4641 AT_loc_list (dw_attr_node
*a
)
4643 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4644 return a
->dw_attr_val
.v
.val_loc_list
;
4647 static inline dw_loc_list_ref
*
4648 AT_loc_list_ptr (dw_attr_node
*a
)
4650 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4651 return &a
->dw_attr_val
.v
.val_loc_list
;
4654 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4656 static hashval_t
hash (addr_table_entry
*);
4657 static bool equal (addr_table_entry
*, addr_table_entry
*);
4660 /* Table of entries into the .debug_addr section. */
4662 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4664 /* Hash an address_table_entry. */
4667 addr_hasher::hash (addr_table_entry
*a
)
4669 inchash::hash hstate
;
4675 case ate_kind_rtx_dtprel
:
4678 case ate_kind_label
:
4679 return htab_hash_string (a
->addr
.label
);
4683 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4684 return hstate
.end ();
4687 /* Determine equality for two address_table_entries. */
4690 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4692 if (a1
->kind
!= a2
->kind
)
4697 case ate_kind_rtx_dtprel
:
4698 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4699 case ate_kind_label
:
4700 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4706 /* Initialize an addr_table_entry. */
4709 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4715 case ate_kind_rtx_dtprel
:
4716 e
->addr
.rtl
= (rtx
) addr
;
4718 case ate_kind_label
:
4719 e
->addr
.label
= (char *) addr
;
4723 e
->index
= NO_INDEX_ASSIGNED
;
4726 /* Add attr to the address table entry to the table. Defer setting an
4727 index until output time. */
4729 static addr_table_entry
*
4730 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4732 addr_table_entry
*node
;
4733 addr_table_entry finder
;
4735 gcc_assert (dwarf_split_debug_info
);
4736 if (! addr_index_table
)
4737 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4738 init_addr_table_entry (&finder
, kind
, addr
);
4739 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4741 if (*slot
== HTAB_EMPTY_ENTRY
)
4743 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4744 init_addr_table_entry (node
, kind
, addr
);
4754 /* Remove an entry from the addr table by decrementing its refcount.
4755 Strictly, decrementing the refcount would be enough, but the
4756 assertion that the entry is actually in the table has found
4760 remove_addr_table_entry (addr_table_entry
*entry
)
4762 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4763 /* After an index is assigned, the table is frozen. */
4764 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4768 /* Given a location list, remove all addresses it refers to from the
4772 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4774 for (; descr
; descr
= descr
->dw_loc_next
)
4775 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4777 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4778 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4782 /* A helper function for dwarf2out_finish called through
4783 htab_traverse. Assign an addr_table_entry its index. All entries
4784 must be collected into the table when this function is called,
4785 because the indexing code relies on htab_traverse to traverse nodes
4786 in the same order for each run. */
4789 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4791 addr_table_entry
*node
= *h
;
4793 /* Don't index unreferenced nodes. */
4794 if (node
->refcount
== 0)
4797 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4798 node
->index
= *index
;
4804 /* Add an address constant attribute value to a DIE. When using
4805 dwarf_split_debug_info, address attributes in dies destined for the
4806 final executable should be direct references--setting the parameter
4807 force_direct ensures this behavior. */
4810 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4815 attr
.dw_attr
= attr_kind
;
4816 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4817 attr
.dw_attr_val
.v
.val_addr
= addr
;
4818 if (dwarf_split_debug_info
&& !force_direct
)
4819 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4821 attr
.dw_attr_val
.val_entry
= NULL
;
4822 add_dwarf_attr (die
, &attr
);
4825 /* Get the RTX from to an address DIE attribute. */
4828 AT_addr (dw_attr_node
*a
)
4830 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4831 return a
->dw_attr_val
.v
.val_addr
;
4834 /* Add a file attribute value to a DIE. */
4837 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4838 struct dwarf_file_data
*fd
)
4842 attr
.dw_attr
= attr_kind
;
4843 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4844 attr
.dw_attr_val
.val_entry
= NULL
;
4845 attr
.dw_attr_val
.v
.val_file
= fd
;
4846 add_dwarf_attr (die
, &attr
);
4849 /* Get the dwarf_file_data from a file DIE attribute. */
4851 static inline struct dwarf_file_data
*
4852 AT_file (dw_attr_node
*a
)
4854 gcc_assert (a
&& (AT_class (a
) == dw_val_class_file
4855 || AT_class (a
) == dw_val_class_file_implicit
));
4856 return a
->dw_attr_val
.v
.val_file
;
4859 /* Add a vms delta attribute value to a DIE. */
4862 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4863 const char *lbl1
, const char *lbl2
)
4867 attr
.dw_attr
= attr_kind
;
4868 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4869 attr
.dw_attr_val
.val_entry
= NULL
;
4870 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4871 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4872 add_dwarf_attr (die
, &attr
);
4875 /* Add a label identifier attribute value to a DIE. */
4878 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4883 attr
.dw_attr
= attr_kind
;
4884 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4885 attr
.dw_attr_val
.val_entry
= NULL
;
4886 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4887 if (dwarf_split_debug_info
)
4888 attr
.dw_attr_val
.val_entry
4889 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4891 add_dwarf_attr (die
, &attr
);
4894 /* Add a section offset attribute value to a DIE, an offset into the
4895 debug_line section. */
4898 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4903 attr
.dw_attr
= attr_kind
;
4904 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4905 attr
.dw_attr_val
.val_entry
= NULL
;
4906 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4907 add_dwarf_attr (die
, &attr
);
4910 /* Add a section offset attribute value to a DIE, an offset into the
4911 debug_loclists section. */
4914 add_AT_loclistsptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4919 attr
.dw_attr
= attr_kind
;
4920 attr
.dw_attr_val
.val_class
= dw_val_class_loclistsptr
;
4921 attr
.dw_attr_val
.val_entry
= NULL
;
4922 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4923 add_dwarf_attr (die
, &attr
);
4926 /* Add a section offset attribute value to a DIE, an offset into the
4927 debug_macinfo section. */
4930 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4935 attr
.dw_attr
= attr_kind
;
4936 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4937 attr
.dw_attr_val
.val_entry
= NULL
;
4938 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4939 add_dwarf_attr (die
, &attr
);
4942 /* Add an offset attribute value to a DIE. */
4945 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4946 unsigned HOST_WIDE_INT offset
)
4950 attr
.dw_attr
= attr_kind
;
4951 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4952 attr
.dw_attr_val
.val_entry
= NULL
;
4953 attr
.dw_attr_val
.v
.val_offset
= offset
;
4954 add_dwarf_attr (die
, &attr
);
4957 /* Add a range_list attribute value to a DIE. When using
4958 dwarf_split_debug_info, address attributes in dies destined for the
4959 final executable should be direct references--setting the parameter
4960 force_direct ensures this behavior. */
4962 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4963 #define RELOCATED_OFFSET (NULL)
4966 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4967 long unsigned int offset
, bool force_direct
)
4971 attr
.dw_attr
= attr_kind
;
4972 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4973 /* For the range_list attribute, use val_entry to store whether the
4974 offset should follow split-debug-info or normal semantics. This
4975 value is read in output_range_list_offset. */
4976 if (dwarf_split_debug_info
&& !force_direct
)
4977 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4979 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4980 attr
.dw_attr_val
.v
.val_offset
= offset
;
4981 add_dwarf_attr (die
, &attr
);
4984 /* Return the start label of a delta attribute. */
4986 static inline const char *
4987 AT_vms_delta1 (dw_attr_node
*a
)
4989 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4990 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4993 /* Return the end label of a delta attribute. */
4995 static inline const char *
4996 AT_vms_delta2 (dw_attr_node
*a
)
4998 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4999 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
5002 static inline const char *
5003 AT_lbl (dw_attr_node
*a
)
5005 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
5006 || AT_class (a
) == dw_val_class_lineptr
5007 || AT_class (a
) == dw_val_class_macptr
5008 || AT_class (a
) == dw_val_class_loclistsptr
5009 || AT_class (a
) == dw_val_class_high_pc
));
5010 return a
->dw_attr_val
.v
.val_lbl_id
;
5013 /* Get the attribute of type attr_kind. */
5015 static dw_attr_node
*
5016 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5020 dw_die_ref spec
= NULL
;
5025 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5026 if (a
->dw_attr
== attr_kind
)
5028 else if (a
->dw_attr
== DW_AT_specification
5029 || a
->dw_attr
== DW_AT_abstract_origin
)
5033 return get_AT (spec
, attr_kind
);
5038 /* Returns the parent of the declaration of DIE. */
5041 get_die_parent (dw_die_ref die
)
5048 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
5049 || (t
= get_AT_ref (die
, DW_AT_specification
)))
5052 return die
->die_parent
;
5055 /* Return the "low pc" attribute value, typically associated with a subprogram
5056 DIE. Return null if the "low pc" attribute is either not present, or if it
5057 cannot be represented as an assembler label identifier. */
5059 static inline const char *
5060 get_AT_low_pc (dw_die_ref die
)
5062 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
5064 return a
? AT_lbl (a
) : NULL
;
5067 /* Return the "high pc" attribute value, typically associated with a subprogram
5068 DIE. Return null if the "high pc" attribute is either not present, or if it
5069 cannot be represented as an assembler label identifier. */
5071 static inline const char *
5072 get_AT_hi_pc (dw_die_ref die
)
5074 dw_attr_node
*a
= get_AT (die
, DW_AT_high_pc
);
5076 return a
? AT_lbl (a
) : NULL
;
5079 /* Return the value of the string attribute designated by ATTR_KIND, or
5080 NULL if it is not present. */
5082 static inline const char *
5083 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5085 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5087 return a
? AT_string (a
) : NULL
;
5090 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5091 if it is not present. */
5094 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5096 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5098 return a
? AT_flag (a
) : 0;
5101 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5102 if it is not present. */
5104 static inline unsigned
5105 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5107 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5109 return a
? AT_unsigned (a
) : 0;
5112 static inline dw_die_ref
5113 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5115 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5117 return a
? AT_ref (a
) : NULL
;
5120 static inline struct dwarf_file_data
*
5121 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5123 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5125 return a
? AT_file (a
) : NULL
;
5128 /* Return TRUE if the language is C++. */
5133 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5135 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
5136 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
5139 /* Return TRUE if DECL was created by the C++ frontend. */
5142 is_cxx (const_tree decl
)
5146 const_tree context
= get_ultimate_context (decl
);
5147 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5148 return strncmp (TRANSLATION_UNIT_LANGUAGE (context
), "GNU C++", 7) == 0;
5153 /* Return TRUE if the language is Fortran. */
5158 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5160 return (lang
== DW_LANG_Fortran77
5161 || lang
== DW_LANG_Fortran90
5162 || lang
== DW_LANG_Fortran95
5163 || lang
== DW_LANG_Fortran03
5164 || lang
== DW_LANG_Fortran08
);
5168 is_fortran (const_tree decl
)
5172 const_tree context
= get_ultimate_context (decl
);
5173 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5174 return (strncmp (TRANSLATION_UNIT_LANGUAGE (context
),
5175 "GNU Fortran", 11) == 0
5176 || strcmp (TRANSLATION_UNIT_LANGUAGE (context
),
5179 return is_fortran ();
5182 /* Return TRUE if the language is Ada. */
5187 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5189 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5192 /* Remove the specified attribute if present. Return TRUE if removal
5196 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5204 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5205 if (a
->dw_attr
== attr_kind
)
5207 if (AT_class (a
) == dw_val_class_str
)
5208 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5209 a
->dw_attr_val
.v
.val_str
->refcount
--;
5211 /* vec::ordered_remove should help reduce the number of abbrevs
5213 die
->die_attr
->ordered_remove (ix
);
5219 /* Remove CHILD from its parent. PREV must have the property that
5220 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5223 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5225 gcc_assert (child
->die_parent
== prev
->die_parent
);
5226 gcc_assert (prev
->die_sib
== child
);
5229 gcc_assert (child
->die_parent
->die_child
== child
);
5233 prev
->die_sib
= child
->die_sib
;
5234 if (child
->die_parent
->die_child
== child
)
5235 child
->die_parent
->die_child
= prev
;
5236 child
->die_sib
= NULL
;
5239 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5240 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5243 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
5245 dw_die_ref parent
= old_child
->die_parent
;
5247 gcc_assert (parent
== prev
->die_parent
);
5248 gcc_assert (prev
->die_sib
== old_child
);
5250 new_child
->die_parent
= parent
;
5251 if (prev
== old_child
)
5253 gcc_assert (parent
->die_child
== old_child
);
5254 new_child
->die_sib
= new_child
;
5258 prev
->die_sib
= new_child
;
5259 new_child
->die_sib
= old_child
->die_sib
;
5261 if (old_child
->die_parent
->die_child
== old_child
)
5262 old_child
->die_parent
->die_child
= new_child
;
5263 old_child
->die_sib
= NULL
;
5266 /* Move all children from OLD_PARENT to NEW_PARENT. */
5269 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
5272 new_parent
->die_child
= old_parent
->die_child
;
5273 old_parent
->die_child
= NULL
;
5274 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
5277 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5281 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5287 dw_die_ref prev
= c
;
5289 while (c
->die_tag
== tag
)
5291 remove_child_with_prev (c
, prev
);
5292 c
->die_parent
= NULL
;
5293 /* Might have removed every child. */
5294 if (die
->die_child
== NULL
)
5298 } while (c
!= die
->die_child
);
5301 /* Add a CHILD_DIE as the last child of DIE. */
5304 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5306 /* FIXME this should probably be an assert. */
5307 if (! die
|| ! child_die
)
5309 gcc_assert (die
!= child_die
);
5311 child_die
->die_parent
= die
;
5314 child_die
->die_sib
= die
->die_child
->die_sib
;
5315 die
->die_child
->die_sib
= child_die
;
5318 child_die
->die_sib
= child_die
;
5319 die
->die_child
= child_die
;
5322 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5325 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
5326 dw_die_ref after_die
)
5332 && die
!= child_die
);
5334 child_die
->die_parent
= die
;
5335 child_die
->die_sib
= after_die
->die_sib
;
5336 after_die
->die_sib
= child_die
;
5337 if (die
->die_child
== after_die
)
5338 die
->die_child
= child_die
;
5341 /* Unassociate CHILD from its parent, and make its parent be
5345 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
5347 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5348 if (p
->die_sib
== child
)
5350 remove_child_with_prev (child
, p
);
5353 add_child_die (new_parent
, child
);
5356 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5357 is the specification, to the end of PARENT's list of children.
5358 This is done by removing and re-adding it. */
5361 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5363 /* We want the declaration DIE from inside the class, not the
5364 specification DIE at toplevel. */
5365 if (child
->die_parent
!= parent
)
5367 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5373 gcc_assert (child
->die_parent
== parent
5374 || (child
->die_parent
5375 == get_AT_ref (parent
, DW_AT_specification
)));
5377 reparent_child (child
, parent
);
5380 /* Create and return a new die with TAG_VALUE as tag. */
5382 static inline dw_die_ref
5383 new_die_raw (enum dwarf_tag tag_value
)
5385 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5386 die
->die_tag
= tag_value
;
5390 /* Create and return a new die with a parent of PARENT_DIE. If
5391 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5392 associated tree T must be supplied to determine parenthood
5395 static inline dw_die_ref
5396 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5398 dw_die_ref die
= new_die_raw (tag_value
);
5400 if (parent_die
!= NULL
)
5401 add_child_die (parent_die
, die
);
5404 limbo_die_node
*limbo_node
;
5406 /* No DIEs created after early dwarf should end up in limbo,
5407 because the limbo list should not persist past LTO
5409 if (tag_value
!= DW_TAG_compile_unit
5410 /* These are allowed because they're generated while
5411 breaking out COMDAT units late. */
5412 && tag_value
!= DW_TAG_type_unit
5413 && tag_value
!= DW_TAG_skeleton_unit
5415 /* Allow nested functions to live in limbo because they will
5416 only temporarily live there, as decls_for_scope will fix
5418 && (TREE_CODE (t
) != FUNCTION_DECL
5419 || !decl_function_context (t
))
5420 /* Same as nested functions above but for types. Types that
5421 are local to a function will be fixed in
5423 && (!RECORD_OR_UNION_TYPE_P (t
)
5424 || !TYPE_CONTEXT (t
)
5425 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5426 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5427 especially in the ltrans stage, but once we implement LTO
5428 dwarf streaming, we should remove this exception. */
5431 fprintf (stderr
, "symbol ended up in limbo too late:");
5432 debug_generic_stmt (t
);
5436 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5437 limbo_node
->die
= die
;
5438 limbo_node
->created_for
= t
;
5439 limbo_node
->next
= limbo_die_list
;
5440 limbo_die_list
= limbo_node
;
5446 /* Return the DIE associated with the given type specifier. */
5448 static inline dw_die_ref
5449 lookup_type_die (tree type
)
5451 dw_die_ref die
= TYPE_SYMTAB_DIE (type
);
5452 if (die
&& die
->removed
)
5454 TYPE_SYMTAB_DIE (type
) = NULL
;
5460 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5461 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5462 anonymous type instead the one of the naming typedef. */
5464 static inline dw_die_ref
5465 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5468 && TREE_CODE (type
) == RECORD_TYPE
5470 && type_die
->die_tag
== DW_TAG_typedef
5471 && is_naming_typedef_decl (TYPE_NAME (type
)))
5472 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5476 /* Like lookup_type_die, but if type is an anonymous type named by a
5477 typedef[1], return the DIE of the anonymous type instead the one of
5478 the naming typedef. This is because in gen_typedef_die, we did
5479 equate the anonymous struct named by the typedef with the DIE of
5480 the naming typedef. So by default, lookup_type_die on an anonymous
5481 struct yields the DIE of the naming typedef.
5483 [1]: Read the comment of is_naming_typedef_decl to learn about what
5484 a naming typedef is. */
5486 static inline dw_die_ref
5487 lookup_type_die_strip_naming_typedef (tree type
)
5489 dw_die_ref die
= lookup_type_die (type
);
5490 return strip_naming_typedef (type
, die
);
5493 /* Equate a DIE to a given type specifier. */
5496 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5498 TYPE_SYMTAB_DIE (type
) = type_die
;
5501 /* Returns a hash value for X (which really is a die_struct). */
5504 decl_die_hasher::hash (die_node
*x
)
5506 return (hashval_t
) x
->decl_id
;
5509 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5512 decl_die_hasher::equal (die_node
*x
, tree y
)
5514 return (x
->decl_id
== DECL_UID (y
));
5517 /* Return the DIE associated with a given declaration. */
5519 static inline dw_die_ref
5520 lookup_decl_die (tree decl
)
5522 dw_die_ref
*die
= decl_die_table
->find_slot_with_hash (decl
, DECL_UID (decl
),
5526 if ((*die
)->removed
)
5528 decl_die_table
->clear_slot (die
);
5535 /* For DECL which might have early dwarf output query a SYMBOL + OFFSET
5536 style reference. Return true if we found one refering to a DIE for
5537 DECL, otherwise return false. */
5540 dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
5541 unsigned HOST_WIDE_INT
*off
)
5545 if (flag_wpa
&& !decl_die_table
)
5548 if (TREE_CODE (decl
) == BLOCK
)
5549 die
= BLOCK_DIE (decl
);
5551 die
= lookup_decl_die (decl
);
5555 /* During WPA stage we currently use DIEs to store the
5556 decl <-> label + offset map. That's quite inefficient but it
5560 dw_die_ref ref
= get_AT_ref (die
, DW_AT_abstract_origin
);
5563 gcc_assert (die
== comp_unit_die ());
5566 *off
= ref
->die_offset
;
5567 *sym
= ref
->die_id
.die_symbol
;
5571 /* Similar to get_ref_die_offset_label, but using the "correct"
5573 *off
= die
->die_offset
;
5574 while (die
->die_parent
)
5575 die
= die
->die_parent
;
5576 /* For the containing CU DIE we compute a die_symbol in
5577 compute_comp_unit_symbol. */
5578 gcc_assert (die
->die_tag
== DW_TAG_compile_unit
5579 && die
->die_id
.die_symbol
!= NULL
);
5580 *sym
= die
->die_id
.die_symbol
;
5584 /* Add a reference of kind ATTR_KIND to a DIE at SYMBOL + OFFSET to DIE. */
5587 add_AT_external_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5588 const char *symbol
, HOST_WIDE_INT offset
)
5590 /* Create a fake DIE that contains the reference. Don't use
5591 new_die because we don't want to end up in the limbo list. */
5592 dw_die_ref ref
= new_die_raw (die
->die_tag
);
5593 ref
->die_id
.die_symbol
= IDENTIFIER_POINTER (get_identifier (symbol
));
5594 ref
->die_offset
= offset
;
5595 ref
->with_offset
= 1;
5596 add_AT_die_ref (die
, attr_kind
, ref
);
5599 /* Create a DIE for DECL if required and add a reference to a DIE
5600 at SYMBOL + OFFSET which contains attributes dumped early. */
5603 dwarf2out_register_external_die (tree decl
, const char *sym
,
5604 unsigned HOST_WIDE_INT off
)
5606 if (debug_info_level
== DINFO_LEVEL_NONE
)
5609 if (flag_wpa
&& !decl_die_table
)
5610 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (1000);
5613 = TREE_CODE (decl
) == BLOCK
? BLOCK_DIE (decl
) : lookup_decl_die (decl
);
5617 dw_die_ref parent
= NULL
;
5618 /* Need to lookup a DIE for the decls context - the containing
5619 function or translation unit. */
5620 if (TREE_CODE (decl
) == BLOCK
)
5622 ctx
= BLOCK_SUPERCONTEXT (decl
);
5623 /* ??? We do not output DIEs for all scopes thus skip as
5624 many DIEs as needed. */
5625 while (TREE_CODE (ctx
) == BLOCK
5626 && !BLOCK_DIE (ctx
))
5627 ctx
= BLOCK_SUPERCONTEXT (ctx
);
5630 ctx
= DECL_CONTEXT (decl
);
5631 while (ctx
&& TYPE_P (ctx
))
5632 ctx
= TYPE_CONTEXT (ctx
);
5635 if (TREE_CODE (ctx
) == BLOCK
)
5636 parent
= BLOCK_DIE (ctx
);
5637 else if (TREE_CODE (ctx
) == TRANSLATION_UNIT_DECL
5638 /* Keep the 1:1 association during WPA. */
5640 /* Otherwise all late annotations go to the main CU which
5641 imports the original CUs. */
5642 parent
= comp_unit_die ();
5643 else if (TREE_CODE (ctx
) == FUNCTION_DECL
5644 && TREE_CODE (decl
) != PARM_DECL
5645 && TREE_CODE (decl
) != BLOCK
)
5646 /* Leave function local entities parent determination to when
5647 we process scope vars. */
5650 parent
= lookup_decl_die (ctx
);
5653 /* In some cases the FEs fail to set DECL_CONTEXT properly.
5654 Handle this case gracefully by globalizing stuff. */
5655 parent
= comp_unit_die ();
5656 /* Create a DIE "stub". */
5657 switch (TREE_CODE (decl
))
5659 case TRANSLATION_UNIT_DECL
:
5662 die
= comp_unit_die ();
5663 dw_die_ref import
= new_die (DW_TAG_imported_unit
, die
, NULL_TREE
);
5664 add_AT_external_die_ref (import
, DW_AT_import
, sym
, off
);
5665 /* We re-target all CU decls to the LTRANS CU DIE, so no need
5666 to create a DIE for the original CUs. */
5669 /* Keep the 1:1 association during WPA. */
5670 die
= new_die (DW_TAG_compile_unit
, NULL
, decl
);
5672 case NAMESPACE_DECL
:
5673 if (is_fortran (decl
))
5674 die
= new_die (DW_TAG_module
, parent
, decl
);
5676 die
= new_die (DW_TAG_namespace
, parent
, decl
);
5679 die
= new_die (DW_TAG_subprogram
, parent
, decl
);
5682 die
= new_die (DW_TAG_variable
, parent
, decl
);
5685 die
= new_die (DW_TAG_variable
, parent
, decl
);
5688 die
= new_die (DW_TAG_formal_parameter
, parent
, decl
);
5691 die
= new_die (DW_TAG_constant
, parent
, decl
);
5694 die
= new_die (DW_TAG_label
, parent
, decl
);
5697 die
= new_die (DW_TAG_lexical_block
, parent
, decl
);
5702 if (TREE_CODE (decl
) == BLOCK
)
5703 BLOCK_DIE (decl
) = die
;
5705 equate_decl_number_to_die (decl
, die
);
5707 /* Add a reference to the DIE providing early debug at $sym + off. */
5708 add_AT_external_die_ref (die
, DW_AT_abstract_origin
, sym
, off
);
5711 /* Returns a hash value for X (which really is a var_loc_list). */
5714 decl_loc_hasher::hash (var_loc_list
*x
)
5716 return (hashval_t
) x
->decl_id
;
5719 /* Return nonzero if decl_id of var_loc_list X is the same as
5723 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5725 return (x
->decl_id
== DECL_UID (y
));
5728 /* Return the var_loc list associated with a given declaration. */
5730 static inline var_loc_list
*
5731 lookup_decl_loc (const_tree decl
)
5733 if (!decl_loc_table
)
5735 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5738 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5741 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5743 return (hashval_t
) x
->decl_id
;
5746 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5750 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5752 return (x
->decl_id
== DECL_UID (y
));
5755 /* Equate a DIE to a particular declaration. */
5758 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5760 unsigned int decl_id
= DECL_UID (decl
);
5762 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5763 decl_die
->decl_id
= decl_id
;
5766 /* Return how many bits covers PIECE EXPR_LIST. */
5768 static HOST_WIDE_INT
5769 decl_piece_bitsize (rtx piece
)
5771 int ret
= (int) GET_MODE (piece
);
5774 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5775 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5776 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5779 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5782 decl_piece_varloc_ptr (rtx piece
)
5784 if ((int) GET_MODE (piece
))
5785 return &XEXP (piece
, 0);
5787 return &XEXP (XEXP (piece
, 0), 1);
5790 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5791 Next is the chain of following piece nodes. */
5793 static rtx_expr_list
*
5794 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5796 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5797 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5799 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5804 /* Return rtx that should be stored into loc field for
5805 LOC_NOTE and BITPOS/BITSIZE. */
5808 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5809 HOST_WIDE_INT bitsize
)
5813 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5815 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5820 /* This function either modifies location piece list *DEST in
5821 place (if SRC and INNER is NULL), or copies location piece list
5822 *SRC to *DEST while modifying it. Location BITPOS is modified
5823 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5824 not copied and if needed some padding around it is added.
5825 When modifying in place, DEST should point to EXPR_LIST where
5826 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5827 to the start of the whole list and INNER points to the EXPR_LIST
5828 where earlier pieces cover PIECE_BITPOS bits. */
5831 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5832 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5833 HOST_WIDE_INT bitsize
, rtx loc_note
)
5836 bool copy
= inner
!= NULL
;
5840 /* First copy all nodes preceding the current bitpos. */
5841 while (src
!= inner
)
5843 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5844 decl_piece_bitsize (*src
), NULL_RTX
);
5845 dest
= &XEXP (*dest
, 1);
5846 src
= &XEXP (*src
, 1);
5849 /* Add padding if needed. */
5850 if (bitpos
!= piece_bitpos
)
5852 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5853 copy
? NULL_RTX
: *dest
);
5854 dest
= &XEXP (*dest
, 1);
5856 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5859 /* A piece with correct bitpos and bitsize already exist,
5860 just update the location for it and return. */
5861 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5864 /* Add the piece that changed. */
5865 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5866 dest
= &XEXP (*dest
, 1);
5867 /* Skip over pieces that overlap it. */
5868 diff
= bitpos
- piece_bitpos
+ bitsize
;
5871 while (diff
> 0 && *src
)
5874 diff
-= decl_piece_bitsize (piece
);
5876 src
= &XEXP (piece
, 1);
5879 *src
= XEXP (piece
, 1);
5880 free_EXPR_LIST_node (piece
);
5883 /* Add padding if needed. */
5884 if (diff
< 0 && *src
)
5888 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5889 dest
= &XEXP (*dest
, 1);
5893 /* Finally copy all nodes following it. */
5896 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5897 decl_piece_bitsize (*src
), NULL_RTX
);
5898 dest
= &XEXP (*dest
, 1);
5899 src
= &XEXP (*src
, 1);
5903 /* Add a variable location node to the linked list for DECL. */
5905 static struct var_loc_node
*
5906 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5908 unsigned int decl_id
;
5910 struct var_loc_node
*loc
= NULL
;
5911 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5913 if (VAR_P (decl
) && DECL_HAS_DEBUG_EXPR_P (decl
))
5915 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5916 if (handled_component_p (realdecl
)
5917 || (TREE_CODE (realdecl
) == MEM_REF
5918 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5920 HOST_WIDE_INT maxsize
;
5923 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
,
5925 if (!DECL_P (innerdecl
)
5926 || DECL_IGNORED_P (innerdecl
)
5927 || TREE_STATIC (innerdecl
)
5929 || bitpos
+ bitsize
> 256
5930 || bitsize
!= maxsize
)
5936 decl_id
= DECL_UID (decl
);
5938 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5941 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5942 temp
->decl_id
= decl_id
;
5948 /* For PARM_DECLs try to keep around the original incoming value,
5949 even if that means we'll emit a zero-range .debug_loc entry. */
5951 && temp
->first
== temp
->last
5952 && TREE_CODE (decl
) == PARM_DECL
5953 && NOTE_P (temp
->first
->loc
)
5954 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5955 && DECL_INCOMING_RTL (decl
)
5956 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5957 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5958 == GET_CODE (DECL_INCOMING_RTL (decl
))
5959 && prev_real_insn (as_a
<rtx_insn
*> (temp
->first
->loc
)) == NULL_RTX
5961 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5962 NOTE_VAR_LOCATION_LOC (loc_note
))
5963 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5964 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5966 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5967 temp
->first
->next
= loc
;
5969 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5971 else if (temp
->last
)
5973 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5974 rtx
*piece_loc
= NULL
, last_loc_note
;
5975 HOST_WIDE_INT piece_bitpos
= 0;
5979 gcc_assert (last
->next
== NULL
);
5981 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5983 piece_loc
= &last
->loc
;
5986 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5987 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5989 piece_bitpos
+= cur_bitsize
;
5990 piece_loc
= &XEXP (*piece_loc
, 1);
5994 /* TEMP->LAST here is either pointer to the last but one or
5995 last element in the chained list, LAST is pointer to the
5997 if (label
&& strcmp (last
->label
, label
) == 0)
5999 /* For SRA optimized variables if there weren't any real
6000 insns since last note, just modify the last node. */
6001 if (piece_loc
!= NULL
)
6003 adjust_piece_list (piece_loc
, NULL
, NULL
,
6004 bitpos
, piece_bitpos
, bitsize
, loc_note
);
6007 /* If the last note doesn't cover any instructions, remove it. */
6008 if (temp
->last
!= last
)
6010 temp
->last
->next
= NULL
;
6013 gcc_assert (strcmp (last
->label
, label
) != 0);
6017 gcc_assert (temp
->first
== temp
->last
6018 || (temp
->first
->next
== temp
->last
6019 && TREE_CODE (decl
) == PARM_DECL
));
6020 memset (temp
->last
, '\0', sizeof (*temp
->last
));
6021 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6025 if (bitsize
== -1 && NOTE_P (last
->loc
))
6026 last_loc_note
= last
->loc
;
6027 else if (piece_loc
!= NULL
6028 && *piece_loc
!= NULL_RTX
6029 && piece_bitpos
== bitpos
6030 && decl_piece_bitsize (*piece_loc
) == bitsize
)
6031 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
6033 last_loc_note
= NULL_RTX
;
6034 /* If the current location is the same as the end of the list,
6035 and either both or neither of the locations is uninitialized,
6036 we have nothing to do. */
6037 if (last_loc_note
== NULL_RTX
6038 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
6039 NOTE_VAR_LOCATION_LOC (loc_note
)))
6040 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6041 != NOTE_VAR_LOCATION_STATUS (loc_note
))
6042 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6043 == VAR_INIT_STATUS_UNINITIALIZED
)
6044 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
6045 == VAR_INIT_STATUS_UNINITIALIZED
))))
6047 /* Add LOC to the end of list and update LAST. If the last
6048 element of the list has been removed above, reuse its
6049 memory for the new node, otherwise allocate a new one. */
6053 memset (loc
, '\0', sizeof (*loc
));
6056 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6057 if (bitsize
== -1 || piece_loc
== NULL
)
6058 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6060 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
6061 bitpos
, piece_bitpos
, bitsize
, loc_note
);
6063 /* Ensure TEMP->LAST will point either to the new last but one
6064 element of the chain, or to the last element in it. */
6065 if (last
!= temp
->last
)
6073 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6076 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6081 /* Keep track of the number of spaces used to indent the
6082 output of the debugging routines that print the structure of
6083 the DIE internal representation. */
6084 static int print_indent
;
6086 /* Indent the line the number of spaces given by print_indent. */
6089 print_spaces (FILE *outfile
)
6091 fprintf (outfile
, "%*s", print_indent
, "");
6094 /* Print a type signature in hex. */
6097 print_signature (FILE *outfile
, char *sig
)
6101 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
6102 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
6106 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
6108 if (discr_value
->pos
)
6109 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
6111 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
6114 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
6116 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
6117 RECURSE, output location descriptor operations. */
6120 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
6122 switch (val
->val_class
)
6124 case dw_val_class_addr
:
6125 fprintf (outfile
, "address");
6127 case dw_val_class_offset
:
6128 fprintf (outfile
, "offset");
6130 case dw_val_class_loc
:
6131 fprintf (outfile
, "location descriptor");
6132 if (val
->v
.val_loc
== NULL
)
6133 fprintf (outfile
, " -> <null>\n");
6136 fprintf (outfile
, ":\n");
6138 print_loc_descr (val
->v
.val_loc
, outfile
);
6142 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
6144 case dw_val_class_loc_list
:
6145 fprintf (outfile
, "location list -> label:%s",
6146 val
->v
.val_loc_list
->ll_symbol
);
6148 case dw_val_class_range_list
:
6149 fprintf (outfile
, "range list");
6151 case dw_val_class_const
:
6152 case dw_val_class_const_implicit
:
6153 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
6155 case dw_val_class_unsigned_const
:
6156 case dw_val_class_unsigned_const_implicit
:
6157 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
6159 case dw_val_class_const_double
:
6160 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
6161 HOST_WIDE_INT_PRINT_UNSIGNED
")",
6162 val
->v
.val_double
.high
,
6163 val
->v
.val_double
.low
);
6165 case dw_val_class_wide_int
:
6167 int i
= val
->v
.val_wide
->get_len ();
6168 fprintf (outfile
, "constant (");
6170 if (val
->v
.val_wide
->elt (i
- 1) == 0)
6171 fprintf (outfile
, "0x");
6172 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
6173 val
->v
.val_wide
->elt (--i
));
6175 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
6176 val
->v
.val_wide
->elt (i
));
6177 fprintf (outfile
, ")");
6180 case dw_val_class_vec
:
6181 fprintf (outfile
, "floating-point or vector constant");
6183 case dw_val_class_flag
:
6184 fprintf (outfile
, "%u", val
->v
.val_flag
);
6186 case dw_val_class_die_ref
:
6187 if (val
->v
.val_die_ref
.die
!= NULL
)
6189 dw_die_ref die
= val
->v
.val_die_ref
.die
;
6191 if (die
->comdat_type_p
)
6193 fprintf (outfile
, "die -> signature: ");
6194 print_signature (outfile
,
6195 die
->die_id
.die_type_node
->signature
);
6197 else if (die
->die_id
.die_symbol
)
6199 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
6200 if (die
->with_offset
)
6201 fprintf (outfile
, " + %ld", die
->die_offset
);
6204 fprintf (outfile
, "die -> %ld", die
->die_offset
);
6205 fprintf (outfile
, " (%p)", (void *) die
);
6208 fprintf (outfile
, "die -> <null>");
6210 case dw_val_class_vms_delta
:
6211 fprintf (outfile
, "delta: @slotcount(%s-%s)",
6212 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
6214 case dw_val_class_lbl_id
:
6215 case dw_val_class_lineptr
:
6216 case dw_val_class_macptr
:
6217 case dw_val_class_loclistsptr
:
6218 case dw_val_class_high_pc
:
6219 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
6221 case dw_val_class_str
:
6222 if (val
->v
.val_str
->str
!= NULL
)
6223 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
6225 fprintf (outfile
, "<null>");
6227 case dw_val_class_file
:
6228 case dw_val_class_file_implicit
:
6229 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
6230 val
->v
.val_file
->emitted_number
);
6232 case dw_val_class_data8
:
6236 for (i
= 0; i
< 8; i
++)
6237 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
6240 case dw_val_class_discr_value
:
6241 print_discr_value (outfile
, &val
->v
.val_discr_value
);
6243 case dw_val_class_discr_list
:
6244 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
6246 node
= node
->dw_discr_next
)
6248 if (node
->dw_discr_range
)
6250 fprintf (outfile
, " .. ");
6251 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6252 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
6255 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6257 if (node
->dw_discr_next
!= NULL
)
6258 fprintf (outfile
, " | ");
6265 /* Likewise, for a DIE attribute. */
6268 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
6270 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
6274 /* Print the list of operands in the LOC location description to OUTFILE. This
6275 routine is a debugging aid only. */
6278 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
6280 dw_loc_descr_ref l
= loc
;
6284 print_spaces (outfile
);
6285 fprintf (outfile
, "<null>\n");
6289 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
6291 print_spaces (outfile
);
6292 fprintf (outfile
, "(%p) %s",
6294 dwarf_stack_op_name (l
->dw_loc_opc
));
6295 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
6297 fprintf (outfile
, " ");
6298 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
6300 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
6302 fprintf (outfile
, ", ");
6303 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
6305 fprintf (outfile
, "\n");
6309 /* Print the information associated with a given DIE, and its children.
6310 This routine is a debugging aid only. */
6313 print_die (dw_die_ref die
, FILE *outfile
)
6319 print_spaces (outfile
);
6320 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
6321 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
6323 print_spaces (outfile
);
6324 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
6325 fprintf (outfile
, " offset: %ld", die
->die_offset
);
6326 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
6328 if (die
->comdat_type_p
)
6330 print_spaces (outfile
);
6331 fprintf (outfile
, " signature: ");
6332 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
6333 fprintf (outfile
, "\n");
6336 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6338 print_spaces (outfile
);
6339 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6341 print_attribute (a
, true, outfile
);
6342 fprintf (outfile
, "\n");
6345 if (die
->die_child
!= NULL
)
6348 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6351 if (print_indent
== 0)
6352 fprintf (outfile
, "\n");
6355 /* Print the list of operations in the LOC location description. */
6358 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
6360 print_loc_descr (loc
, stderr
);
6363 /* Print the information collected for a given DIE. */
6366 debug_dwarf_die (dw_die_ref die
)
6368 print_die (die
, stderr
);
6372 debug (die_struct
&ref
)
6374 print_die (&ref
, stderr
);
6378 debug (die_struct
*ptr
)
6383 fprintf (stderr
, "<nil>\n");
6387 /* Print all DWARF information collected for the compilation unit.
6388 This routine is a debugging aid only. */
6394 print_die (comp_unit_die (), stderr
);
6397 /* Verify the DIE tree structure. */
6400 verify_die (dw_die_ref die
)
6402 gcc_assert (!die
->die_mark
);
6403 if (die
->die_parent
== NULL
6404 && die
->die_sib
== NULL
)
6406 /* Verify the die_sib list is cyclic. */
6413 while (x
&& !x
->die_mark
);
6414 gcc_assert (x
== die
);
6418 /* Verify all dies have the same parent. */
6419 gcc_assert (x
->die_parent
== die
->die_parent
);
6422 /* Verify the child has the proper parent and recurse. */
6423 gcc_assert (x
->die_child
->die_parent
== x
);
6424 verify_die (x
->die_child
);
6429 while (x
&& x
->die_mark
);
6432 /* Sanity checks on DIEs. */
6435 check_die (dw_die_ref die
)
6439 bool inline_found
= false;
6440 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
6441 int n_decl_line
= 0, n_decl_column
= 0, n_decl_file
= 0;
6442 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6447 if (a
->dw_attr_val
.v
.val_unsigned
)
6448 inline_found
= true;
6450 case DW_AT_location
:
6459 case DW_AT_artificial
:
6462 case DW_AT_decl_column
:
6465 case DW_AT_decl_line
:
6468 case DW_AT_decl_file
:
6475 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
6476 || n_decl_column
> 1 || n_decl_line
> 1 || n_decl_file
> 1)
6478 fprintf (stderr
, "Duplicate attributes in DIE:\n");
6479 debug_dwarf_die (die
);
6484 /* A debugging information entry that is a member of an abstract
6485 instance tree [that has DW_AT_inline] should not contain any
6486 attributes which describe aspects of the subroutine which vary
6487 between distinct inlined expansions or distinct out-of-line
6489 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6490 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
6491 && a
->dw_attr
!= DW_AT_high_pc
6492 && a
->dw_attr
!= DW_AT_location
6493 && a
->dw_attr
!= DW_AT_frame_base
6494 && a
->dw_attr
!= DW_AT_call_all_calls
6495 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
6499 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6500 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6501 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6503 /* Calculate the checksum of a location expression. */
6506 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6509 inchash::hash hstate
;
6512 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
6514 hash_loc_operands (loc
, hstate
);
6515 hash
= hstate
.end();
6519 /* Calculate the checksum of an attribute. */
6522 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
6524 dw_loc_descr_ref loc
;
6527 CHECKSUM (at
->dw_attr
);
6529 /* We don't care that this was compiled with a different compiler
6530 snapshot; if the output is the same, that's what matters. */
6531 if (at
->dw_attr
== DW_AT_producer
)
6534 switch (AT_class (at
))
6536 case dw_val_class_const
:
6537 case dw_val_class_const_implicit
:
6538 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
6540 case dw_val_class_unsigned_const
:
6541 case dw_val_class_unsigned_const_implicit
:
6542 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
6544 case dw_val_class_const_double
:
6545 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6547 case dw_val_class_wide_int
:
6548 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6549 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6550 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6552 case dw_val_class_vec
:
6553 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6554 (at
->dw_attr_val
.v
.val_vec
.length
6555 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6557 case dw_val_class_flag
:
6558 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
6560 case dw_val_class_str
:
6561 CHECKSUM_STRING (AT_string (at
));
6564 case dw_val_class_addr
:
6566 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6567 CHECKSUM_STRING (XSTR (r
, 0));
6570 case dw_val_class_offset
:
6571 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6574 case dw_val_class_loc
:
6575 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6576 loc_checksum (loc
, ctx
);
6579 case dw_val_class_die_ref
:
6580 die_checksum (AT_ref (at
), ctx
, mark
);
6583 case dw_val_class_fde_ref
:
6584 case dw_val_class_vms_delta
:
6585 case dw_val_class_lbl_id
:
6586 case dw_val_class_lineptr
:
6587 case dw_val_class_macptr
:
6588 case dw_val_class_loclistsptr
:
6589 case dw_val_class_high_pc
:
6592 case dw_val_class_file
:
6593 case dw_val_class_file_implicit
:
6594 CHECKSUM_STRING (AT_file (at
)->filename
);
6597 case dw_val_class_data8
:
6598 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6606 /* Calculate the checksum of a DIE. */
6609 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6615 /* To avoid infinite recursion. */
6618 CHECKSUM (die
->die_mark
);
6621 die
->die_mark
= ++(*mark
);
6623 CHECKSUM (die
->die_tag
);
6625 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6626 attr_checksum (a
, ctx
, mark
);
6628 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6632 #undef CHECKSUM_BLOCK
6633 #undef CHECKSUM_STRING
6635 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6636 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6637 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6638 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6639 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6640 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6641 #define CHECKSUM_ATTR(FOO) \
6642 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6644 /* Calculate the checksum of a number in signed LEB128 format. */
6647 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6654 byte
= (value
& 0x7f);
6656 more
= !((value
== 0 && (byte
& 0x40) == 0)
6657 || (value
== -1 && (byte
& 0x40) != 0));
6666 /* Calculate the checksum of a number in unsigned LEB128 format. */
6669 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6673 unsigned char byte
= (value
& 0x7f);
6676 /* More bytes to follow. */
6684 /* Checksum the context of the DIE. This adds the names of any
6685 surrounding namespaces or structures to the checksum. */
6688 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
6692 int tag
= die
->die_tag
;
6694 if (tag
!= DW_TAG_namespace
6695 && tag
!= DW_TAG_structure_type
6696 && tag
!= DW_TAG_class_type
)
6699 name
= get_AT_string (die
, DW_AT_name
);
6701 spec
= get_AT_ref (die
, DW_AT_specification
);
6705 if (die
->die_parent
!= NULL
)
6706 checksum_die_context (die
->die_parent
, ctx
);
6708 CHECKSUM_ULEB128 ('C');
6709 CHECKSUM_ULEB128 (tag
);
6711 CHECKSUM_STRING (name
);
6714 /* Calculate the checksum of a location expression. */
6717 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6719 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6720 were emitted as a DW_FORM_sdata instead of a location expression. */
6721 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6723 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6724 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6728 /* Otherwise, just checksum the raw location expression. */
6731 inchash::hash hstate
;
6734 CHECKSUM_ULEB128 (loc
->dtprel
);
6735 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6736 hash_loc_operands (loc
, hstate
);
6737 hash
= hstate
.end ();
6739 loc
= loc
->dw_loc_next
;
6743 /* Calculate the checksum of an attribute. */
6746 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
6747 struct md5_ctx
*ctx
, int *mark
)
6749 dw_loc_descr_ref loc
;
6752 if (AT_class (at
) == dw_val_class_die_ref
)
6754 dw_die_ref target_die
= AT_ref (at
);
6756 /* For pointer and reference types, we checksum only the (qualified)
6757 name of the target type (if there is a name). For friend entries,
6758 we checksum only the (qualified) name of the target type or function.
6759 This allows the checksum to remain the same whether the target type
6760 is complete or not. */
6761 if ((at
->dw_attr
== DW_AT_type
6762 && (tag
== DW_TAG_pointer_type
6763 || tag
== DW_TAG_reference_type
6764 || tag
== DW_TAG_rvalue_reference_type
6765 || tag
== DW_TAG_ptr_to_member_type
))
6766 || (at
->dw_attr
== DW_AT_friend
6767 && tag
== DW_TAG_friend
))
6769 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
6771 if (name_attr
!= NULL
)
6773 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6777 CHECKSUM_ULEB128 ('N');
6778 CHECKSUM_ULEB128 (at
->dw_attr
);
6779 if (decl
->die_parent
!= NULL
)
6780 checksum_die_context (decl
->die_parent
, ctx
);
6781 CHECKSUM_ULEB128 ('E');
6782 CHECKSUM_STRING (AT_string (name_attr
));
6787 /* For all other references to another DIE, we check to see if the
6788 target DIE has already been visited. If it has, we emit a
6789 backward reference; if not, we descend recursively. */
6790 if (target_die
->die_mark
> 0)
6792 CHECKSUM_ULEB128 ('R');
6793 CHECKSUM_ULEB128 (at
->dw_attr
);
6794 CHECKSUM_ULEB128 (target_die
->die_mark
);
6798 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6802 target_die
->die_mark
= ++(*mark
);
6803 CHECKSUM_ULEB128 ('T');
6804 CHECKSUM_ULEB128 (at
->dw_attr
);
6805 if (decl
->die_parent
!= NULL
)
6806 checksum_die_context (decl
->die_parent
, ctx
);
6807 die_checksum_ordered (target_die
, ctx
, mark
);
6812 CHECKSUM_ULEB128 ('A');
6813 CHECKSUM_ULEB128 (at
->dw_attr
);
6815 switch (AT_class (at
))
6817 case dw_val_class_const
:
6818 case dw_val_class_const_implicit
:
6819 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6820 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6823 case dw_val_class_unsigned_const
:
6824 case dw_val_class_unsigned_const_implicit
:
6825 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6826 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6829 case dw_val_class_const_double
:
6830 CHECKSUM_ULEB128 (DW_FORM_block
);
6831 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6832 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6835 case dw_val_class_wide_int
:
6836 CHECKSUM_ULEB128 (DW_FORM_block
);
6837 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6838 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6839 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6840 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6841 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6844 case dw_val_class_vec
:
6845 CHECKSUM_ULEB128 (DW_FORM_block
);
6846 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6847 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6848 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6849 (at
->dw_attr_val
.v
.val_vec
.length
6850 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6853 case dw_val_class_flag
:
6854 CHECKSUM_ULEB128 (DW_FORM_flag
);
6855 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6858 case dw_val_class_str
:
6859 CHECKSUM_ULEB128 (DW_FORM_string
);
6860 CHECKSUM_STRING (AT_string (at
));
6863 case dw_val_class_addr
:
6865 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6866 CHECKSUM_ULEB128 (DW_FORM_string
);
6867 CHECKSUM_STRING (XSTR (r
, 0));
6870 case dw_val_class_offset
:
6871 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6872 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6875 case dw_val_class_loc
:
6876 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6877 loc_checksum_ordered (loc
, ctx
);
6880 case dw_val_class_fde_ref
:
6881 case dw_val_class_lbl_id
:
6882 case dw_val_class_lineptr
:
6883 case dw_val_class_macptr
:
6884 case dw_val_class_loclistsptr
:
6885 case dw_val_class_high_pc
:
6888 case dw_val_class_file
:
6889 case dw_val_class_file_implicit
:
6890 CHECKSUM_ULEB128 (DW_FORM_string
);
6891 CHECKSUM_STRING (AT_file (at
)->filename
);
6894 case dw_val_class_data8
:
6895 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6903 struct checksum_attributes
6905 dw_attr_node
*at_name
;
6906 dw_attr_node
*at_type
;
6907 dw_attr_node
*at_friend
;
6908 dw_attr_node
*at_accessibility
;
6909 dw_attr_node
*at_address_class
;
6910 dw_attr_node
*at_alignment
;
6911 dw_attr_node
*at_allocated
;
6912 dw_attr_node
*at_artificial
;
6913 dw_attr_node
*at_associated
;
6914 dw_attr_node
*at_binary_scale
;
6915 dw_attr_node
*at_bit_offset
;
6916 dw_attr_node
*at_bit_size
;
6917 dw_attr_node
*at_bit_stride
;
6918 dw_attr_node
*at_byte_size
;
6919 dw_attr_node
*at_byte_stride
;
6920 dw_attr_node
*at_const_value
;
6921 dw_attr_node
*at_containing_type
;
6922 dw_attr_node
*at_count
;
6923 dw_attr_node
*at_data_location
;
6924 dw_attr_node
*at_data_member_location
;
6925 dw_attr_node
*at_decimal_scale
;
6926 dw_attr_node
*at_decimal_sign
;
6927 dw_attr_node
*at_default_value
;
6928 dw_attr_node
*at_digit_count
;
6929 dw_attr_node
*at_discr
;
6930 dw_attr_node
*at_discr_list
;
6931 dw_attr_node
*at_discr_value
;
6932 dw_attr_node
*at_encoding
;
6933 dw_attr_node
*at_endianity
;
6934 dw_attr_node
*at_explicit
;
6935 dw_attr_node
*at_is_optional
;
6936 dw_attr_node
*at_location
;
6937 dw_attr_node
*at_lower_bound
;
6938 dw_attr_node
*at_mutable
;
6939 dw_attr_node
*at_ordering
;
6940 dw_attr_node
*at_picture_string
;
6941 dw_attr_node
*at_prototyped
;
6942 dw_attr_node
*at_small
;
6943 dw_attr_node
*at_segment
;
6944 dw_attr_node
*at_string_length
;
6945 dw_attr_node
*at_string_length_bit_size
;
6946 dw_attr_node
*at_string_length_byte_size
;
6947 dw_attr_node
*at_threads_scaled
;
6948 dw_attr_node
*at_upper_bound
;
6949 dw_attr_node
*at_use_location
;
6950 dw_attr_node
*at_use_UTF8
;
6951 dw_attr_node
*at_variable_parameter
;
6952 dw_attr_node
*at_virtuality
;
6953 dw_attr_node
*at_visibility
;
6954 dw_attr_node
*at_vtable_elem_location
;
6957 /* Collect the attributes that we will want to use for the checksum. */
6960 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6965 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6976 attrs
->at_friend
= a
;
6978 case DW_AT_accessibility
:
6979 attrs
->at_accessibility
= a
;
6981 case DW_AT_address_class
:
6982 attrs
->at_address_class
= a
;
6984 case DW_AT_alignment
:
6985 attrs
->at_alignment
= a
;
6987 case DW_AT_allocated
:
6988 attrs
->at_allocated
= a
;
6990 case DW_AT_artificial
:
6991 attrs
->at_artificial
= a
;
6993 case DW_AT_associated
:
6994 attrs
->at_associated
= a
;
6996 case DW_AT_binary_scale
:
6997 attrs
->at_binary_scale
= a
;
6999 case DW_AT_bit_offset
:
7000 attrs
->at_bit_offset
= a
;
7002 case DW_AT_bit_size
:
7003 attrs
->at_bit_size
= a
;
7005 case DW_AT_bit_stride
:
7006 attrs
->at_bit_stride
= a
;
7008 case DW_AT_byte_size
:
7009 attrs
->at_byte_size
= a
;
7011 case DW_AT_byte_stride
:
7012 attrs
->at_byte_stride
= a
;
7014 case DW_AT_const_value
:
7015 attrs
->at_const_value
= a
;
7017 case DW_AT_containing_type
:
7018 attrs
->at_containing_type
= a
;
7021 attrs
->at_count
= a
;
7023 case DW_AT_data_location
:
7024 attrs
->at_data_location
= a
;
7026 case DW_AT_data_member_location
:
7027 attrs
->at_data_member_location
= a
;
7029 case DW_AT_decimal_scale
:
7030 attrs
->at_decimal_scale
= a
;
7032 case DW_AT_decimal_sign
:
7033 attrs
->at_decimal_sign
= a
;
7035 case DW_AT_default_value
:
7036 attrs
->at_default_value
= a
;
7038 case DW_AT_digit_count
:
7039 attrs
->at_digit_count
= a
;
7042 attrs
->at_discr
= a
;
7044 case DW_AT_discr_list
:
7045 attrs
->at_discr_list
= a
;
7047 case DW_AT_discr_value
:
7048 attrs
->at_discr_value
= a
;
7050 case DW_AT_encoding
:
7051 attrs
->at_encoding
= a
;
7053 case DW_AT_endianity
:
7054 attrs
->at_endianity
= a
;
7056 case DW_AT_explicit
:
7057 attrs
->at_explicit
= a
;
7059 case DW_AT_is_optional
:
7060 attrs
->at_is_optional
= a
;
7062 case DW_AT_location
:
7063 attrs
->at_location
= a
;
7065 case DW_AT_lower_bound
:
7066 attrs
->at_lower_bound
= a
;
7069 attrs
->at_mutable
= a
;
7071 case DW_AT_ordering
:
7072 attrs
->at_ordering
= a
;
7074 case DW_AT_picture_string
:
7075 attrs
->at_picture_string
= a
;
7077 case DW_AT_prototyped
:
7078 attrs
->at_prototyped
= a
;
7081 attrs
->at_small
= a
;
7084 attrs
->at_segment
= a
;
7086 case DW_AT_string_length
:
7087 attrs
->at_string_length
= a
;
7089 case DW_AT_string_length_bit_size
:
7090 attrs
->at_string_length_bit_size
= a
;
7092 case DW_AT_string_length_byte_size
:
7093 attrs
->at_string_length_byte_size
= a
;
7095 case DW_AT_threads_scaled
:
7096 attrs
->at_threads_scaled
= a
;
7098 case DW_AT_upper_bound
:
7099 attrs
->at_upper_bound
= a
;
7101 case DW_AT_use_location
:
7102 attrs
->at_use_location
= a
;
7104 case DW_AT_use_UTF8
:
7105 attrs
->at_use_UTF8
= a
;
7107 case DW_AT_variable_parameter
:
7108 attrs
->at_variable_parameter
= a
;
7110 case DW_AT_virtuality
:
7111 attrs
->at_virtuality
= a
;
7113 case DW_AT_visibility
:
7114 attrs
->at_visibility
= a
;
7116 case DW_AT_vtable_elem_location
:
7117 attrs
->at_vtable_elem_location
= a
;
7125 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
7128 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
7132 struct checksum_attributes attrs
;
7134 CHECKSUM_ULEB128 ('D');
7135 CHECKSUM_ULEB128 (die
->die_tag
);
7137 memset (&attrs
, 0, sizeof (attrs
));
7139 decl
= get_AT_ref (die
, DW_AT_specification
);
7141 collect_checksum_attributes (&attrs
, decl
);
7142 collect_checksum_attributes (&attrs
, die
);
7144 CHECKSUM_ATTR (attrs
.at_name
);
7145 CHECKSUM_ATTR (attrs
.at_accessibility
);
7146 CHECKSUM_ATTR (attrs
.at_address_class
);
7147 CHECKSUM_ATTR (attrs
.at_allocated
);
7148 CHECKSUM_ATTR (attrs
.at_artificial
);
7149 CHECKSUM_ATTR (attrs
.at_associated
);
7150 CHECKSUM_ATTR (attrs
.at_binary_scale
);
7151 CHECKSUM_ATTR (attrs
.at_bit_offset
);
7152 CHECKSUM_ATTR (attrs
.at_bit_size
);
7153 CHECKSUM_ATTR (attrs
.at_bit_stride
);
7154 CHECKSUM_ATTR (attrs
.at_byte_size
);
7155 CHECKSUM_ATTR (attrs
.at_byte_stride
);
7156 CHECKSUM_ATTR (attrs
.at_const_value
);
7157 CHECKSUM_ATTR (attrs
.at_containing_type
);
7158 CHECKSUM_ATTR (attrs
.at_count
);
7159 CHECKSUM_ATTR (attrs
.at_data_location
);
7160 CHECKSUM_ATTR (attrs
.at_data_member_location
);
7161 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
7162 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
7163 CHECKSUM_ATTR (attrs
.at_default_value
);
7164 CHECKSUM_ATTR (attrs
.at_digit_count
);
7165 CHECKSUM_ATTR (attrs
.at_discr
);
7166 CHECKSUM_ATTR (attrs
.at_discr_list
);
7167 CHECKSUM_ATTR (attrs
.at_discr_value
);
7168 CHECKSUM_ATTR (attrs
.at_encoding
);
7169 CHECKSUM_ATTR (attrs
.at_endianity
);
7170 CHECKSUM_ATTR (attrs
.at_explicit
);
7171 CHECKSUM_ATTR (attrs
.at_is_optional
);
7172 CHECKSUM_ATTR (attrs
.at_location
);
7173 CHECKSUM_ATTR (attrs
.at_lower_bound
);
7174 CHECKSUM_ATTR (attrs
.at_mutable
);
7175 CHECKSUM_ATTR (attrs
.at_ordering
);
7176 CHECKSUM_ATTR (attrs
.at_picture_string
);
7177 CHECKSUM_ATTR (attrs
.at_prototyped
);
7178 CHECKSUM_ATTR (attrs
.at_small
);
7179 CHECKSUM_ATTR (attrs
.at_segment
);
7180 CHECKSUM_ATTR (attrs
.at_string_length
);
7181 CHECKSUM_ATTR (attrs
.at_string_length_bit_size
);
7182 CHECKSUM_ATTR (attrs
.at_string_length_byte_size
);
7183 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
7184 CHECKSUM_ATTR (attrs
.at_upper_bound
);
7185 CHECKSUM_ATTR (attrs
.at_use_location
);
7186 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
7187 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
7188 CHECKSUM_ATTR (attrs
.at_virtuality
);
7189 CHECKSUM_ATTR (attrs
.at_visibility
);
7190 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
7191 CHECKSUM_ATTR (attrs
.at_type
);
7192 CHECKSUM_ATTR (attrs
.at_friend
);
7193 CHECKSUM_ATTR (attrs
.at_alignment
);
7195 /* Checksum the child DIEs. */
7198 dw_attr_node
*name_attr
;
7201 name_attr
= get_AT (c
, DW_AT_name
);
7202 if (is_template_instantiation (c
))
7204 /* Ignore instantiations of member type and function templates. */
7206 else if (name_attr
!= NULL
7207 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
7209 /* Use a shallow checksum for named nested types and member
7211 CHECKSUM_ULEB128 ('S');
7212 CHECKSUM_ULEB128 (c
->die_tag
);
7213 CHECKSUM_STRING (AT_string (name_attr
));
7217 /* Use a deep checksum for other children. */
7218 /* Mark this DIE so it gets processed when unmarking. */
7219 if (c
->die_mark
== 0)
7221 die_checksum_ordered (c
, ctx
, mark
);
7223 } while (c
!= die
->die_child
);
7225 CHECKSUM_ULEB128 (0);
7228 /* Add a type name and tag to a hash. */
7230 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
7232 CHECKSUM_ULEB128 (tag
);
7233 CHECKSUM_STRING (name
);
7237 #undef CHECKSUM_STRING
7238 #undef CHECKSUM_ATTR
7239 #undef CHECKSUM_LEB128
7240 #undef CHECKSUM_ULEB128
7242 /* Generate the type signature for DIE. This is computed by generating an
7243 MD5 checksum over the DIE's tag, its relevant attributes, and its
7244 children. Attributes that are references to other DIEs are processed
7245 by recursion, using the MARK field to prevent infinite recursion.
7246 If the DIE is nested inside a namespace or another type, we also
7247 need to include that context in the signature. The lower 64 bits
7248 of the resulting MD5 checksum comprise the signature. */
7251 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
7255 unsigned char checksum
[16];
7260 name
= get_AT_string (die
, DW_AT_name
);
7261 decl
= get_AT_ref (die
, DW_AT_specification
);
7262 parent
= get_die_parent (die
);
7264 /* First, compute a signature for just the type name (and its surrounding
7265 context, if any. This is stored in the type unit DIE for link-time
7266 ODR (one-definition rule) checking. */
7268 if (is_cxx () && name
!= NULL
)
7270 md5_init_ctx (&ctx
);
7272 /* Checksum the names of surrounding namespaces and structures. */
7274 checksum_die_context (parent
, &ctx
);
7276 /* Checksum the current DIE. */
7277 die_odr_checksum (die
->die_tag
, name
, &ctx
);
7278 md5_finish_ctx (&ctx
, checksum
);
7280 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
7283 /* Next, compute the complete type signature. */
7285 md5_init_ctx (&ctx
);
7287 die
->die_mark
= mark
;
7289 /* Checksum the names of surrounding namespaces and structures. */
7291 checksum_die_context (parent
, &ctx
);
7293 /* Checksum the DIE and its children. */
7294 die_checksum_ordered (die
, &ctx
, &mark
);
7295 unmark_all_dies (die
);
7296 md5_finish_ctx (&ctx
, checksum
);
7298 /* Store the signature in the type node and link the type DIE and the
7299 type node together. */
7300 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
7301 DWARF_TYPE_SIGNATURE_SIZE
);
7302 die
->comdat_type_p
= true;
7303 die
->die_id
.die_type_node
= type_node
;
7304 type_node
->type_die
= die
;
7306 /* If the DIE is a specification, link its declaration to the type node
7310 decl
->comdat_type_p
= true;
7311 decl
->die_id
.die_type_node
= type_node
;
7315 /* Do the location expressions look same? */
7317 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
7319 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
7320 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
7321 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
7324 /* Do the values look the same? */
7326 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
7328 dw_loc_descr_ref loc1
, loc2
;
7331 if (v1
->val_class
!= v2
->val_class
)
7334 switch (v1
->val_class
)
7336 case dw_val_class_const
:
7337 case dw_val_class_const_implicit
:
7338 return v1
->v
.val_int
== v2
->v
.val_int
;
7339 case dw_val_class_unsigned_const
:
7340 case dw_val_class_unsigned_const_implicit
:
7341 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
7342 case dw_val_class_const_double
:
7343 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
7344 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
7345 case dw_val_class_wide_int
:
7346 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
7347 case dw_val_class_vec
:
7348 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
7349 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7351 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7352 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7355 case dw_val_class_flag
:
7356 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7357 case dw_val_class_str
:
7358 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7360 case dw_val_class_addr
:
7361 r1
= v1
->v
.val_addr
;
7362 r2
= v2
->v
.val_addr
;
7363 if (GET_CODE (r1
) != GET_CODE (r2
))
7365 return !rtx_equal_p (r1
, r2
);
7367 case dw_val_class_offset
:
7368 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7370 case dw_val_class_loc
:
7371 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7373 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7374 if (!same_loc_p (loc1
, loc2
, mark
))
7376 return !loc1
&& !loc2
;
7378 case dw_val_class_die_ref
:
7379 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7381 case dw_val_class_fde_ref
:
7382 case dw_val_class_vms_delta
:
7383 case dw_val_class_lbl_id
:
7384 case dw_val_class_lineptr
:
7385 case dw_val_class_macptr
:
7386 case dw_val_class_loclistsptr
:
7387 case dw_val_class_high_pc
:
7390 case dw_val_class_file
:
7391 case dw_val_class_file_implicit
:
7392 return v1
->v
.val_file
== v2
->v
.val_file
;
7394 case dw_val_class_data8
:
7395 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
7402 /* Do the attributes look the same? */
7405 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
7407 if (at1
->dw_attr
!= at2
->dw_attr
)
7410 /* We don't care that this was compiled with a different compiler
7411 snapshot; if the output is the same, that's what matters. */
7412 if (at1
->dw_attr
== DW_AT_producer
)
7415 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7418 /* Do the dies look the same? */
7421 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7427 /* To avoid infinite recursion. */
7429 return die1
->die_mark
== die2
->die_mark
;
7430 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7432 if (die1
->die_tag
!= die2
->die_tag
)
7435 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
7438 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
7439 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
7442 c1
= die1
->die_child
;
7443 c2
= die2
->die_child
;
7452 if (!same_die_p (c1
, c2
, mark
))
7456 if (c1
== die1
->die_child
)
7458 if (c2
== die2
->die_child
)
7468 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7469 children, and set die_symbol. */
7472 compute_comp_unit_symbol (dw_die_ref unit_die
)
7474 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
7475 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
7476 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
7479 unsigned char checksum
[16];
7482 /* Compute the checksum of the DIE, then append part of it as hex digits to
7483 the name filename of the unit. */
7485 md5_init_ctx (&ctx
);
7487 die_checksum (unit_die
, &ctx
, &mark
);
7488 unmark_all_dies (unit_die
);
7489 md5_finish_ctx (&ctx
, checksum
);
7491 /* When we this for comp_unit_die () we have a DW_AT_name that might
7492 not start with a letter but with anything valid for filenames and
7493 clean_symbol_name doesn't fix that up. Prepend 'g' if the first
7494 character is not a letter. */
7495 sprintf (name
, "%s%s.", ISALPHA (*base
) ? "" : "g", base
);
7496 clean_symbol_name (name
);
7498 p
= name
+ strlen (name
);
7499 for (i
= 0; i
< 4; i
++)
7501 sprintf (p
, "%.2x", checksum
[i
]);
7505 unit_die
->die_id
.die_symbol
= xstrdup (name
);
7508 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7511 is_type_die (dw_die_ref die
)
7513 switch (die
->die_tag
)
7515 case DW_TAG_array_type
:
7516 case DW_TAG_class_type
:
7517 case DW_TAG_interface_type
:
7518 case DW_TAG_enumeration_type
:
7519 case DW_TAG_pointer_type
:
7520 case DW_TAG_reference_type
:
7521 case DW_TAG_rvalue_reference_type
:
7522 case DW_TAG_string_type
:
7523 case DW_TAG_structure_type
:
7524 case DW_TAG_subroutine_type
:
7525 case DW_TAG_union_type
:
7526 case DW_TAG_ptr_to_member_type
:
7527 case DW_TAG_set_type
:
7528 case DW_TAG_subrange_type
:
7529 case DW_TAG_base_type
:
7530 case DW_TAG_const_type
:
7531 case DW_TAG_file_type
:
7532 case DW_TAG_packed_type
:
7533 case DW_TAG_volatile_type
:
7534 case DW_TAG_typedef
:
7541 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7542 Basically, we want to choose the bits that are likely to be shared between
7543 compilations (types) and leave out the bits that are specific to individual
7544 compilations (functions). */
7547 is_comdat_die (dw_die_ref c
)
7549 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7550 we do for stabs. The advantage is a greater likelihood of sharing between
7551 objects that don't include headers in the same order (and therefore would
7552 put the base types in a different comdat). jason 8/28/00 */
7554 if (c
->die_tag
== DW_TAG_base_type
)
7557 if (c
->die_tag
== DW_TAG_pointer_type
7558 || c
->die_tag
== DW_TAG_reference_type
7559 || c
->die_tag
== DW_TAG_rvalue_reference_type
7560 || c
->die_tag
== DW_TAG_const_type
7561 || c
->die_tag
== DW_TAG_volatile_type
)
7563 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
7565 return t
? is_comdat_die (t
) : 0;
7568 return is_type_die (c
);
7571 /* Returns true iff C is a compile-unit DIE. */
7574 is_cu_die (dw_die_ref c
)
7576 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7577 || c
->die_tag
== DW_TAG_skeleton_unit
);
7580 /* Returns true iff C is a unit DIE of some sort. */
7583 is_unit_die (dw_die_ref c
)
7585 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7586 || c
->die_tag
== DW_TAG_partial_unit
7587 || c
->die_tag
== DW_TAG_type_unit
7588 || c
->die_tag
== DW_TAG_skeleton_unit
);
7591 /* Returns true iff C is a namespace DIE. */
7594 is_namespace_die (dw_die_ref c
)
7596 return c
&& c
->die_tag
== DW_TAG_namespace
;
7599 /* Returns true iff C is a class or structure DIE. */
7602 is_class_die (dw_die_ref c
)
7604 return c
&& (c
->die_tag
== DW_TAG_class_type
7605 || c
->die_tag
== DW_TAG_structure_type
);
7608 /* Return non-zero if this DIE is a template parameter. */
7611 is_template_parameter (dw_die_ref die
)
7613 switch (die
->die_tag
)
7615 case DW_TAG_template_type_param
:
7616 case DW_TAG_template_value_param
:
7617 case DW_TAG_GNU_template_template_param
:
7618 case DW_TAG_GNU_template_parameter_pack
:
7625 /* Return non-zero if this DIE represents a template instantiation. */
7628 is_template_instantiation (dw_die_ref die
)
7632 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
7634 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
7639 gen_internal_sym (const char *prefix
)
7641 char buf
[MAX_ARTIFICIAL_LABEL_BYTES
];
7643 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7644 return xstrdup (buf
);
7647 /* Return non-zero if this DIE is a declaration. */
7650 is_declaration_die (dw_die_ref die
)
7655 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7656 if (a
->dw_attr
== DW_AT_declaration
)
7662 /* Return non-zero if this DIE is nested inside a subprogram. */
7665 is_nested_in_subprogram (dw_die_ref die
)
7667 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7671 return local_scope_p (decl
);
7674 /* Return non-zero if this DIE contains a defining declaration of a
7678 contains_subprogram_definition (dw_die_ref die
)
7682 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7684 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7688 /* Return non-zero if this is a type DIE that should be moved to a
7689 COMDAT .debug_types section or .debug_info section with DW_UT_*type
7693 should_move_die_to_comdat (dw_die_ref die
)
7695 switch (die
->die_tag
)
7697 case DW_TAG_class_type
:
7698 case DW_TAG_structure_type
:
7699 case DW_TAG_enumeration_type
:
7700 case DW_TAG_union_type
:
7701 /* Don't move declarations, inlined instances, types nested in a
7702 subprogram, or types that contain subprogram definitions. */
7703 if (is_declaration_die (die
)
7704 || get_AT (die
, DW_AT_abstract_origin
)
7705 || is_nested_in_subprogram (die
)
7706 || contains_subprogram_definition (die
))
7709 case DW_TAG_array_type
:
7710 case DW_TAG_interface_type
:
7711 case DW_TAG_pointer_type
:
7712 case DW_TAG_reference_type
:
7713 case DW_TAG_rvalue_reference_type
:
7714 case DW_TAG_string_type
:
7715 case DW_TAG_subroutine_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
:
7730 /* Make a clone of DIE. */
7733 clone_die (dw_die_ref die
)
7735 dw_die_ref clone
= new_die_raw (die
->die_tag
);
7739 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7740 add_dwarf_attr (clone
, a
);
7745 /* Make a clone of the tree rooted at DIE. */
7748 clone_tree (dw_die_ref die
)
7751 dw_die_ref clone
= clone_die (die
);
7753 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7758 /* Make a clone of DIE as a declaration. */
7761 clone_as_declaration (dw_die_ref die
)
7768 /* If the DIE is already a declaration, just clone it. */
7769 if (is_declaration_die (die
))
7770 return clone_die (die
);
7772 /* If the DIE is a specification, just clone its declaration DIE. */
7773 decl
= get_AT_ref (die
, DW_AT_specification
);
7776 clone
= clone_die (decl
);
7777 if (die
->comdat_type_p
)
7778 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7782 clone
= new_die_raw (die
->die_tag
);
7784 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7786 /* We don't want to copy over all attributes.
7787 For example we don't want DW_AT_byte_size because otherwise we will no
7788 longer have a declaration and GDB will treat it as a definition. */
7792 case DW_AT_abstract_origin
:
7793 case DW_AT_artificial
:
7794 case DW_AT_containing_type
:
7795 case DW_AT_external
:
7798 case DW_AT_virtuality
:
7799 case DW_AT_linkage_name
:
7800 case DW_AT_MIPS_linkage_name
:
7801 add_dwarf_attr (clone
, a
);
7803 case DW_AT_byte_size
:
7804 case DW_AT_alignment
:
7810 if (die
->comdat_type_p
)
7811 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7813 add_AT_flag (clone
, DW_AT_declaration
, 1);
7818 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7820 struct decl_table_entry
7826 /* Helpers to manipulate hash table of copied declarations. */
7828 /* Hashtable helpers. */
7830 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7832 typedef die_struct
*compare_type
;
7833 static inline hashval_t
hash (const decl_table_entry
*);
7834 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7838 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7840 return htab_hash_pointer (entry
->orig
);
7844 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7845 const die_struct
*entry2
)
7847 return entry1
->orig
== entry2
;
7850 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7852 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7853 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7854 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7855 to check if the ancestor has already been copied into UNIT. */
7858 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7859 decl_hash_type
*decl_table
)
7861 dw_die_ref parent
= die
->die_parent
;
7862 dw_die_ref new_parent
= unit
;
7864 decl_table_entry
**slot
= NULL
;
7865 struct decl_table_entry
*entry
= NULL
;
7869 /* Check if the entry has already been copied to UNIT. */
7870 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7872 if (*slot
!= HTAB_EMPTY_ENTRY
)
7878 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7879 entry
= XCNEW (struct decl_table_entry
);
7887 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7890 if (!is_unit_die (parent
))
7891 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7894 copy
= clone_as_declaration (die
);
7895 add_child_die (new_parent
, copy
);
7899 /* Record the pointer to the copy. */
7905 /* Copy the declaration context to the new type unit DIE. This includes
7906 any surrounding namespace or type declarations. If the DIE has an
7907 AT_specification attribute, it also includes attributes and children
7908 attached to the specification, and returns a pointer to the original
7909 parent of the declaration DIE. Returns NULL otherwise. */
7912 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7915 dw_die_ref new_decl
;
7916 dw_die_ref orig_parent
= NULL
;
7918 decl
= get_AT_ref (die
, DW_AT_specification
);
7927 /* The original DIE will be changed to a declaration, and must
7928 be moved to be a child of the original declaration DIE. */
7929 orig_parent
= decl
->die_parent
;
7931 /* Copy the type node pointer from the new DIE to the original
7932 declaration DIE so we can forward references later. */
7933 decl
->comdat_type_p
= true;
7934 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7936 remove_AT (die
, DW_AT_specification
);
7938 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7940 if (a
->dw_attr
!= DW_AT_name
7941 && a
->dw_attr
!= DW_AT_declaration
7942 && a
->dw_attr
!= DW_AT_external
)
7943 add_dwarf_attr (die
, a
);
7946 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7949 if (decl
->die_parent
!= NULL
7950 && !is_unit_die (decl
->die_parent
))
7952 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7953 if (new_decl
!= NULL
)
7955 remove_AT (new_decl
, DW_AT_signature
);
7956 add_AT_specification (die
, new_decl
);
7963 /* Generate the skeleton ancestor tree for the given NODE, then clone
7964 the DIE and add the clone into the tree. */
7967 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7969 if (node
->new_die
!= NULL
)
7972 node
->new_die
= clone_as_declaration (node
->old_die
);
7974 if (node
->parent
!= NULL
)
7976 generate_skeleton_ancestor_tree (node
->parent
);
7977 add_child_die (node
->parent
->new_die
, node
->new_die
);
7981 /* Generate a skeleton tree of DIEs containing any declarations that are
7982 found in the original tree. We traverse the tree looking for declaration
7983 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7986 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7988 skeleton_chain_node node
;
7991 dw_die_ref prev
= NULL
;
7992 dw_die_ref next
= NULL
;
7994 node
.parent
= parent
;
7996 first
= c
= parent
->old_die
->die_child
;
8000 if (prev
== NULL
|| prev
->die_sib
== c
)
8003 next
= (c
== first
? NULL
: c
->die_sib
);
8005 node
.new_die
= NULL
;
8006 if (is_declaration_die (c
))
8008 if (is_template_instantiation (c
))
8010 /* Instantiated templates do not need to be cloned into the
8011 type unit. Just move the DIE and its children back to
8012 the skeleton tree (in the main CU). */
8013 remove_child_with_prev (c
, prev
);
8014 add_child_die (parent
->new_die
, c
);
8017 else if (c
->comdat_type_p
)
8019 /* This is the skeleton of earlier break_out_comdat_types
8020 type. Clone the existing DIE, but keep the children
8021 under the original (which is in the main CU). */
8022 dw_die_ref clone
= clone_die (c
);
8024 replace_child (c
, clone
, prev
);
8025 generate_skeleton_ancestor_tree (parent
);
8026 add_child_die (parent
->new_die
, c
);
8032 /* Clone the existing DIE, move the original to the skeleton
8033 tree (which is in the main CU), and put the clone, with
8034 all the original's children, where the original came from
8035 (which is about to be moved to the type unit). */
8036 dw_die_ref clone
= clone_die (c
);
8037 move_all_children (c
, clone
);
8039 /* If the original has a DW_AT_object_pointer attribute,
8040 it would now point to a child DIE just moved to the
8041 cloned tree, so we need to remove that attribute from
8043 remove_AT (c
, DW_AT_object_pointer
);
8045 replace_child (c
, clone
, prev
);
8046 generate_skeleton_ancestor_tree (parent
);
8047 add_child_die (parent
->new_die
, c
);
8048 node
.old_die
= clone
;
8053 generate_skeleton_bottom_up (&node
);
8054 } while (next
!= NULL
);
8057 /* Wrapper function for generate_skeleton_bottom_up. */
8060 generate_skeleton (dw_die_ref die
)
8062 skeleton_chain_node node
;
8065 node
.new_die
= NULL
;
8068 /* If this type definition is nested inside another type,
8069 and is not an instantiation of a template, always leave
8070 at least a declaration in its place. */
8071 if (die
->die_parent
!= NULL
8072 && is_type_die (die
->die_parent
)
8073 && !is_template_instantiation (die
))
8074 node
.new_die
= clone_as_declaration (die
);
8076 generate_skeleton_bottom_up (&node
);
8077 return node
.new_die
;
8080 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
8081 declaration. The original DIE is moved to a new compile unit so that
8082 existing references to it follow it to the new location. If any of the
8083 original DIE's descendants is a declaration, we need to replace the
8084 original DIE with a skeleton tree and move the declarations back into the
8088 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
8091 dw_die_ref skeleton
, orig_parent
;
8093 /* Copy the declaration context to the type unit DIE. If the returned
8094 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
8096 orig_parent
= copy_declaration_context (unit
, child
);
8098 skeleton
= generate_skeleton (child
);
8099 if (skeleton
== NULL
)
8100 remove_child_with_prev (child
, prev
);
8103 skeleton
->comdat_type_p
= true;
8104 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
8106 /* If the original DIE was a specification, we need to put
8107 the skeleton under the parent DIE of the declaration.
8108 This leaves the original declaration in the tree, but
8109 it will be pruned later since there are no longer any
8110 references to it. */
8111 if (orig_parent
!= NULL
)
8113 remove_child_with_prev (child
, prev
);
8114 add_child_die (orig_parent
, skeleton
);
8117 replace_child (child
, skeleton
, prev
);
8124 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8125 comdat_type_node
*type_node
,
8126 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
8128 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8129 procedure, put it under TYPE_NODE and return the copy. Continue looking for
8130 DWARF procedure references in the DW_AT_location attribute. */
8133 copy_dwarf_procedure (dw_die_ref die
,
8134 comdat_type_node
*type_node
,
8135 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8137 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
8139 /* DWARF procedures are not supposed to have children... */
8140 gcc_assert (die
->die_child
== NULL
);
8142 /* ... and they are supposed to have only one attribute: DW_AT_location. */
8143 gcc_assert (vec_safe_length (die
->die_attr
) == 1
8144 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
8146 /* Do not copy more than once DWARF procedures. */
8148 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
8152 die_copy
= clone_die (die
);
8153 add_child_die (type_node
->root_die
, die_copy
);
8154 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
8158 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8159 procedures in DIE's attributes. */
8162 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8163 comdat_type_node
*type_node
,
8164 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8169 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
8171 dw_loc_descr_ref loc
;
8173 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
8176 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
8178 switch (loc
->dw_loc_opc
)
8182 case DW_OP_call_ref
:
8183 gcc_assert (loc
->dw_loc_oprnd1
.val_class
8184 == dw_val_class_die_ref
);
8185 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
8186 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
8188 copied_dwarf_procs
);
8197 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8198 rewrite references to point to the copies.
8200 References are looked for in DIE's attributes and recursively in all its
8201 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8202 mapping from old DWARF procedures to their copy. It is used not to copy
8203 twice the same DWARF procedure under TYPE_NODE. */
8206 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
8207 comdat_type_node
*type_node
,
8208 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8212 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
8213 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
8215 copied_dwarf_procs
));
8218 /* Traverse the DIE and set up additional .debug_types or .debug_info
8219 DW_UT_*type sections for each type worthy of being placed in a COMDAT
8223 break_out_comdat_types (dw_die_ref die
)
8227 dw_die_ref prev
= NULL
;
8228 dw_die_ref next
= NULL
;
8229 dw_die_ref unit
= NULL
;
8231 first
= c
= die
->die_child
;
8235 if (prev
== NULL
|| prev
->die_sib
== c
)
8238 next
= (c
== first
? NULL
: c
->die_sib
);
8239 if (should_move_die_to_comdat (c
))
8241 dw_die_ref replacement
;
8242 comdat_type_node
*type_node
;
8244 /* Break out nested types into their own type units. */
8245 break_out_comdat_types (c
);
8247 /* Create a new type unit DIE as the root for the new tree, and
8248 add it to the list of comdat types. */
8249 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8250 add_AT_unsigned (unit
, DW_AT_language
,
8251 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
8252 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
8253 type_node
->root_die
= unit
;
8254 type_node
->next
= comdat_type_list
;
8255 comdat_type_list
= type_node
;
8257 /* Generate the type signature. */
8258 generate_type_signature (c
, type_node
);
8260 /* Copy the declaration context, attributes, and children of the
8261 declaration into the new type unit DIE, then remove this DIE
8262 from the main CU (or replace it with a skeleton if necessary). */
8263 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
8264 type_node
->skeleton_die
= replacement
;
8266 /* Add the DIE to the new compunit. */
8267 add_child_die (unit
, c
);
8269 /* Types can reference DWARF procedures for type size or data location
8270 expressions. Calls in DWARF expressions cannot target procedures
8271 that are not in the same section. So we must copy DWARF procedures
8272 along with this type and then rewrite references to them. */
8273 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
8274 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
8276 if (replacement
!= NULL
)
8279 else if (c
->die_tag
== DW_TAG_namespace
8280 || c
->die_tag
== DW_TAG_class_type
8281 || c
->die_tag
== DW_TAG_structure_type
8282 || c
->die_tag
== DW_TAG_union_type
)
8284 /* Look for nested types that can be broken out. */
8285 break_out_comdat_types (c
);
8287 } while (next
!= NULL
);
8290 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8291 Enter all the cloned children into the hash table decl_table. */
8294 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
8298 struct decl_table_entry
*entry
;
8299 decl_table_entry
**slot
;
8301 if (die
->die_tag
== DW_TAG_subprogram
)
8302 clone
= clone_as_declaration (die
);
8304 clone
= clone_die (die
);
8306 slot
= decl_table
->find_slot_with_hash (die
,
8307 htab_hash_pointer (die
), INSERT
);
8309 /* Assert that DIE isn't in the hash table yet. If it would be there
8310 before, the ancestors would be necessarily there as well, therefore
8311 clone_tree_partial wouldn't be called. */
8312 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8314 entry
= XCNEW (struct decl_table_entry
);
8316 entry
->copy
= clone
;
8319 if (die
->die_tag
!= DW_TAG_subprogram
)
8320 FOR_EACH_CHILD (die
, c
,
8321 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
8326 /* Walk the DIE and its children, looking for references to incomplete
8327 or trivial types that are unmarked (i.e., that are not in the current
8331 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
8337 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8339 if (AT_class (a
) == dw_val_class_die_ref
)
8341 dw_die_ref targ
= AT_ref (a
);
8342 decl_table_entry
**slot
;
8343 struct decl_table_entry
*entry
;
8345 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
8348 slot
= decl_table
->find_slot_with_hash (targ
,
8349 htab_hash_pointer (targ
),
8352 if (*slot
!= HTAB_EMPTY_ENTRY
)
8354 /* TARG has already been copied, so we just need to
8355 modify the reference to point to the copy. */
8357 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
8361 dw_die_ref parent
= unit
;
8362 dw_die_ref copy
= clone_die (targ
);
8364 /* Record in DECL_TABLE that TARG has been copied.
8365 Need to do this now, before the recursive call,
8366 because DECL_TABLE may be expanded and SLOT
8367 would no longer be a valid pointer. */
8368 entry
= XCNEW (struct decl_table_entry
);
8373 /* If TARG is not a declaration DIE, we need to copy its
8375 if (!is_declaration_die (targ
))
8379 add_child_die (copy
,
8380 clone_tree_partial (c
, decl_table
)));
8383 /* Make sure the cloned tree is marked as part of the
8387 /* If TARG has surrounding context, copy its ancestor tree
8388 into the new type unit. */
8389 if (targ
->die_parent
!= NULL
8390 && !is_unit_die (targ
->die_parent
))
8391 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8394 add_child_die (parent
, copy
);
8395 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8397 /* Make sure the newly-copied DIE is walked. If it was
8398 installed in a previously-added context, it won't
8399 get visited otherwise. */
8402 /* Find the highest point of the newly-added tree,
8403 mark each node along the way, and walk from there. */
8404 parent
->die_mark
= 1;
8405 while (parent
->die_parent
8406 && parent
->die_parent
->die_mark
== 0)
8408 parent
= parent
->die_parent
;
8409 parent
->die_mark
= 1;
8411 copy_decls_walk (unit
, parent
, decl_table
);
8417 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8420 /* Copy declarations for "unworthy" types into the new comdat section.
8421 Incomplete types, modified types, and certain other types aren't broken
8422 out into comdat sections of their own, so they don't have a signature,
8423 and we need to copy the declaration into the same section so that we
8424 don't have an external reference. */
8427 copy_decls_for_unworthy_types (dw_die_ref unit
)
8430 decl_hash_type
decl_table (10);
8431 copy_decls_walk (unit
, unit
, &decl_table
);
8435 /* Traverse the DIE and add a sibling attribute if it may have the
8436 effect of speeding up access to siblings. To save some space,
8437 avoid generating sibling attributes for DIE's without children. */
8440 add_sibling_attributes (dw_die_ref die
)
8444 if (! die
->die_child
)
8447 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8448 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8450 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8453 /* Output all location lists for the DIE and its children. */
8456 output_location_lists (dw_die_ref die
)
8462 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8463 if (AT_class (a
) == dw_val_class_loc_list
)
8464 output_loc_list (AT_loc_list (a
));
8466 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
8469 /* During assign_location_list_indexes and output_loclists_offset the
8470 current index, after it the number of assigned indexes (i.e. how
8471 large the .debug_loclists* offset table should be). */
8472 static unsigned int loc_list_idx
;
8474 /* Output all location list offsets for the DIE and its children. */
8477 output_loclists_offsets (dw_die_ref die
)
8483 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8484 if (AT_class (a
) == dw_val_class_loc_list
)
8486 dw_loc_list_ref l
= AT_loc_list (a
);
8487 if (l
->offset_emitted
)
8489 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l
->ll_symbol
,
8490 loc_section_label
, NULL
);
8491 gcc_assert (l
->hash
== loc_list_idx
);
8493 l
->offset_emitted
= true;
8496 FOR_EACH_CHILD (die
, c
, output_loclists_offsets (c
));
8499 /* Recursively set indexes of location lists. */
8502 assign_location_list_indexes (dw_die_ref die
)
8508 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8509 if (AT_class (a
) == dw_val_class_loc_list
)
8511 dw_loc_list_ref list
= AT_loc_list (a
);
8512 if (!list
->num_assigned
)
8514 list
->num_assigned
= true;
8515 list
->hash
= loc_list_idx
++;
8519 FOR_EACH_CHILD (die
, c
, assign_location_list_indexes (c
));
8522 /* We want to limit the number of external references, because they are
8523 larger than local references: a relocation takes multiple words, and
8524 even a sig8 reference is always eight bytes, whereas a local reference
8525 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8526 So if we encounter multiple external references to the same type DIE, we
8527 make a local typedef stub for it and redirect all references there.
8529 This is the element of the hash table for keeping track of these
8539 /* Hashtable helpers. */
8541 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
8543 static inline hashval_t
hash (const external_ref
*);
8544 static inline bool equal (const external_ref
*, const external_ref
*);
8548 external_ref_hasher::hash (const external_ref
*r
)
8550 dw_die_ref die
= r
->type
;
8553 /* We can't use the address of the DIE for hashing, because
8554 that will make the order of the stub DIEs non-deterministic. */
8555 if (! die
->comdat_type_p
)
8556 /* We have a symbol; use it to compute a hash. */
8557 h
= htab_hash_string (die
->die_id
.die_symbol
);
8560 /* We have a type signature; use a subset of the bits as the hash.
8561 The 8-byte signature is at least as large as hashval_t. */
8562 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
8563 memcpy (&h
, type_node
->signature
, sizeof (h
));
8569 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
8571 return r1
->type
== r2
->type
;
8574 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
8576 /* Return a pointer to the external_ref for references to DIE. */
8578 static struct external_ref
*
8579 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
8581 struct external_ref ref
, *ref_p
;
8582 external_ref
**slot
;
8585 slot
= map
->find_slot (&ref
, INSERT
);
8586 if (*slot
!= HTAB_EMPTY_ENTRY
)
8589 ref_p
= XCNEW (struct external_ref
);
8595 /* Subroutine of optimize_external_refs, below.
8597 If we see a type skeleton, record it as our stub. If we see external
8598 references, remember how many we've seen. */
8601 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
8606 struct external_ref
*ref_p
;
8608 if (is_type_die (die
)
8609 && (c
= get_AT_ref (die
, DW_AT_signature
)))
8611 /* This is a local skeleton; use it for local references. */
8612 ref_p
= lookup_external_ref (map
, c
);
8616 /* Scan the DIE references, and remember any that refer to DIEs from
8617 other CUs (i.e. those which are not marked). */
8618 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8619 if (AT_class (a
) == dw_val_class_die_ref
8620 && (c
= AT_ref (a
))->die_mark
== 0
8623 ref_p
= lookup_external_ref (map
, c
);
8627 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
8630 /* htab_traverse callback function for optimize_external_refs, below. SLOT
8631 points to an external_ref, DATA is the CU we're processing. If we don't
8632 already have a local stub, and we have multiple refs, build a stub. */
8635 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
8637 struct external_ref
*ref_p
= *slot
;
8639 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
8641 /* We have multiple references to this type, so build a small stub.
8642 Both of these forms are a bit dodgy from the perspective of the
8643 DWARF standard, since technically they should have names. */
8644 dw_die_ref cu
= data
;
8645 dw_die_ref type
= ref_p
->type
;
8646 dw_die_ref stub
= NULL
;
8648 if (type
->comdat_type_p
)
8650 /* If we refer to this type via sig8, use AT_signature. */
8651 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
8652 add_AT_die_ref (stub
, DW_AT_signature
, type
);
8656 /* Otherwise, use a typedef with no name. */
8657 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
8658 add_AT_die_ref (stub
, DW_AT_type
, type
);
8667 /* DIE is a unit; look through all the DIE references to see if there are
8668 any external references to types, and if so, create local stubs for
8669 them which will be applied in build_abbrev_table. This is useful because
8670 references to local DIEs are smaller. */
8672 static external_ref_hash_type
*
8673 optimize_external_refs (dw_die_ref die
)
8675 external_ref_hash_type
*map
= new external_ref_hash_type (10);
8676 optimize_external_refs_1 (die
, map
);
8677 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
8681 /* The following 3 variables are temporaries that are computed only during the
8682 build_abbrev_table call and used and released during the following
8683 optimize_abbrev_table call. */
8685 /* First abbrev_id that can be optimized based on usage. */
8686 static unsigned int abbrev_opt_start
;
8688 /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
8689 abbrev_id smaller than this, because they must be already sized
8690 during build_abbrev_table). */
8691 static unsigned int abbrev_opt_base_type_end
;
8693 /* Vector of usage counts during build_abbrev_table. Indexed by
8694 abbrev_id - abbrev_opt_start. */
8695 static vec
<unsigned int> abbrev_usage_count
;
8697 /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
8698 static vec
<dw_die_ref
> sorted_abbrev_dies
;
8700 /* The format of each DIE (and its attribute value pairs) is encoded in an
8701 abbreviation table. This routine builds the abbreviation table and assigns
8702 a unique abbreviation id for each abbreviation entry. The children of each
8703 die are visited recursively. */
8706 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
8708 unsigned int abbrev_id
= 0;
8714 /* Scan the DIE references, and replace any that refer to
8715 DIEs from other CUs (i.e. those which are not marked) with
8716 the local stubs we built in optimize_external_refs. */
8717 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8718 if (AT_class (a
) == dw_val_class_die_ref
8719 && (c
= AT_ref (a
))->die_mark
== 0)
8721 struct external_ref
*ref_p
;
8722 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8724 ref_p
= lookup_external_ref (extern_map
, c
);
8725 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8726 change_AT_die_ref (a
, ref_p
->stub
);
8728 /* We aren't changing this reference, so mark it external. */
8729 set_AT_ref_external (a
, 1);
8732 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
8734 dw_attr_node
*die_a
, *abbrev_a
;
8740 if (abbrev
->die_tag
!= die
->die_tag
)
8742 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8745 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8748 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8750 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8751 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8752 || (value_format (abbrev_a
) != value_format (die_a
)))
8762 if (abbrev_id
>= vec_safe_length (abbrev_die_table
))
8764 vec_safe_push (abbrev_die_table
, die
);
8765 if (abbrev_opt_start
)
8766 abbrev_usage_count
.safe_push (0);
8768 if (abbrev_opt_start
&& abbrev_id
>= abbrev_opt_start
)
8770 abbrev_usage_count
[abbrev_id
- abbrev_opt_start
]++;
8771 sorted_abbrev_dies
.safe_push (die
);
8774 die
->die_abbrev
= abbrev_id
;
8775 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8778 /* Callback function for sorted_abbrev_dies vector sorting. We sort
8779 by die_abbrev's usage count, from the most commonly used
8780 abbreviation to the least. */
8783 die_abbrev_cmp (const void *p1
, const void *p2
)
8785 dw_die_ref die1
= *(const dw_die_ref
*) p1
;
8786 dw_die_ref die2
= *(const dw_die_ref
*) p2
;
8788 gcc_checking_assert (die1
->die_abbrev
>= abbrev_opt_start
);
8789 gcc_checking_assert (die2
->die_abbrev
>= abbrev_opt_start
);
8791 if (die1
->die_abbrev
>= abbrev_opt_base_type_end
8792 && die2
->die_abbrev
>= abbrev_opt_base_type_end
)
8794 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8795 > abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8797 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8798 < abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8802 /* Stabilize the sort. */
8803 if (die1
->die_abbrev
< die2
->die_abbrev
)
8805 if (die1
->die_abbrev
> die2
->die_abbrev
)
8811 /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
8812 of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
8813 into dw_val_class_const_implicit or
8814 dw_val_class_unsigned_const_implicit. */
8817 optimize_implicit_const (unsigned int first_id
, unsigned int end
,
8818 vec
<bool> &implicit_consts
)
8820 /* It never makes sense if there is just one DIE using the abbreviation. */
8821 if (end
< first_id
+ 2)
8826 dw_die_ref die
= sorted_abbrev_dies
[first_id
];
8827 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8828 if (implicit_consts
[ix
])
8830 enum dw_val_class new_class
= dw_val_class_none
;
8831 switch (AT_class (a
))
8833 case dw_val_class_unsigned_const
:
8834 if ((HOST_WIDE_INT
) AT_unsigned (a
) < 0)
8837 /* The .debug_abbrev section will grow by
8838 size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
8839 in all the DIEs using that abbreviation. */
8840 if (constant_size (AT_unsigned (a
)) * (end
- first_id
)
8841 <= (unsigned) size_of_sleb128 (AT_unsigned (a
)))
8844 new_class
= dw_val_class_unsigned_const_implicit
;
8847 case dw_val_class_const
:
8848 new_class
= dw_val_class_const_implicit
;
8851 case dw_val_class_file
:
8852 new_class
= dw_val_class_file_implicit
;
8858 for (i
= first_id
; i
< end
; i
++)
8859 (*sorted_abbrev_dies
[i
]->die_attr
)[ix
].dw_attr_val
.val_class
8864 /* Attempt to optimize abbreviation table from abbrev_opt_start
8865 abbreviation above. */
8868 optimize_abbrev_table (void)
8870 if (abbrev_opt_start
8871 && vec_safe_length (abbrev_die_table
) > abbrev_opt_start
8872 && (dwarf_version
>= 5 || vec_safe_length (abbrev_die_table
) > 127))
8874 auto_vec
<bool, 32> implicit_consts
;
8875 sorted_abbrev_dies
.qsort (die_abbrev_cmp
);
8877 unsigned int abbrev_id
= abbrev_opt_start
- 1;
8878 unsigned int first_id
= ~0U;
8879 unsigned int last_abbrev_id
= 0;
8882 if (abbrev_opt_base_type_end
> abbrev_opt_start
)
8883 abbrev_id
= abbrev_opt_base_type_end
- 1;
8884 /* Reassign abbreviation ids from abbrev_opt_start above, so that
8885 most commonly used abbreviations come first. */
8886 FOR_EACH_VEC_ELT (sorted_abbrev_dies
, i
, die
)
8891 /* If calc_base_type_die_sizes has been called, the CU and
8892 base types after it can't be optimized, because we've already
8893 calculated their DIE offsets. We've sorted them first. */
8894 if (die
->die_abbrev
< abbrev_opt_base_type_end
)
8896 if (die
->die_abbrev
!= last_abbrev_id
)
8898 last_abbrev_id
= die
->die_abbrev
;
8899 if (dwarf_version
>= 5 && first_id
!= ~0U)
8900 optimize_implicit_const (first_id
, i
, implicit_consts
);
8902 (*abbrev_die_table
)[abbrev_id
] = die
;
8903 if (dwarf_version
>= 5)
8906 implicit_consts
.truncate (0);
8908 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8909 switch (AT_class (a
))
8911 case dw_val_class_const
:
8912 case dw_val_class_unsigned_const
:
8913 case dw_val_class_file
:
8914 implicit_consts
.safe_push (true);
8917 implicit_consts
.safe_push (false);
8922 else if (dwarf_version
>= 5)
8924 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8925 if (!implicit_consts
[ix
])
8929 dw_attr_node
*other_a
8930 = &(*(*abbrev_die_table
)[abbrev_id
]->die_attr
)[ix
];
8931 if (!dw_val_equal_p (&a
->dw_attr_val
,
8932 &other_a
->dw_attr_val
))
8933 implicit_consts
[ix
] = false;
8936 die
->die_abbrev
= abbrev_id
;
8938 gcc_assert (abbrev_id
== vec_safe_length (abbrev_die_table
) - 1);
8939 if (dwarf_version
>= 5 && first_id
!= ~0U)
8940 optimize_implicit_const (first_id
, i
, implicit_consts
);
8943 abbrev_opt_start
= 0;
8944 abbrev_opt_base_type_end
= 0;
8945 abbrev_usage_count
.release ();
8946 sorted_abbrev_dies
.release ();
8949 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8952 constant_size (unsigned HOST_WIDE_INT value
)
8959 log
= floor_log2 (value
);
8962 log
= 1 << (floor_log2 (log
) + 1);
8967 /* Return the size of a DIE as it is represented in the
8968 .debug_info section. */
8970 static unsigned long
8971 size_of_die (dw_die_ref die
)
8973 unsigned long size
= 0;
8976 enum dwarf_form form
;
8978 size
+= size_of_uleb128 (die
->die_abbrev
);
8979 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8981 switch (AT_class (a
))
8983 case dw_val_class_addr
:
8984 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8986 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8987 size
+= size_of_uleb128 (AT_index (a
));
8990 size
+= DWARF2_ADDR_SIZE
;
8992 case dw_val_class_offset
:
8993 size
+= DWARF_OFFSET_SIZE
;
8995 case dw_val_class_loc
:
8997 unsigned long lsize
= size_of_locs (AT_loc (a
));
9000 if (dwarf_version
>= 4)
9001 size
+= size_of_uleb128 (lsize
);
9003 size
+= constant_size (lsize
);
9007 case dw_val_class_loc_list
:
9008 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
9010 gcc_assert (AT_loc_list (a
)->num_assigned
);
9011 size
+= size_of_uleb128 (AT_loc_list (a
)->hash
);
9014 size
+= DWARF_OFFSET_SIZE
;
9016 case dw_val_class_range_list
:
9017 if (value_format (a
) == DW_FORM_rnglistx
)
9019 gcc_assert (rnglist_idx
);
9020 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9021 size
+= size_of_uleb128 (r
->idx
);
9024 size
+= DWARF_OFFSET_SIZE
;
9026 case dw_val_class_const
:
9027 size
+= size_of_sleb128 (AT_int (a
));
9029 case dw_val_class_unsigned_const
:
9031 int csize
= constant_size (AT_unsigned (a
));
9032 if (dwarf_version
== 3
9033 && a
->dw_attr
== DW_AT_data_member_location
9035 size
+= size_of_uleb128 (AT_unsigned (a
));
9040 case dw_val_class_const_implicit
:
9041 case dw_val_class_unsigned_const_implicit
:
9042 case dw_val_class_file_implicit
:
9043 /* These occupy no size in the DIE, just an extra sleb128 in
9046 case dw_val_class_const_double
:
9047 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
9048 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
9051 case dw_val_class_wide_int
:
9052 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9053 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
9054 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9055 * HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
9058 case dw_val_class_vec
:
9059 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
9060 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
9061 + a
->dw_attr_val
.v
.val_vec
.length
9062 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
9064 case dw_val_class_flag
:
9065 if (dwarf_version
>= 4)
9066 /* Currently all add_AT_flag calls pass in 1 as last argument,
9067 so DW_FORM_flag_present can be used. If that ever changes,
9068 we'll need to use DW_FORM_flag and have some optimization
9069 in build_abbrev_table that will change those to
9070 DW_FORM_flag_present if it is set to 1 in all DIEs using
9071 the same abbrev entry. */
9072 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9076 case dw_val_class_die_ref
:
9077 if (AT_ref_external (a
))
9079 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
9080 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
9081 is sized by target address length, whereas in DWARF3
9082 it's always sized as an offset. */
9083 if (use_debug_types
)
9084 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
9085 else if (dwarf_version
== 2)
9086 size
+= DWARF2_ADDR_SIZE
;
9088 size
+= DWARF_OFFSET_SIZE
;
9091 size
+= DWARF_OFFSET_SIZE
;
9093 case dw_val_class_fde_ref
:
9094 size
+= DWARF_OFFSET_SIZE
;
9096 case dw_val_class_lbl_id
:
9097 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9099 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9100 size
+= size_of_uleb128 (AT_index (a
));
9103 size
+= DWARF2_ADDR_SIZE
;
9105 case dw_val_class_lineptr
:
9106 case dw_val_class_macptr
:
9107 case dw_val_class_loclistsptr
:
9108 size
+= DWARF_OFFSET_SIZE
;
9110 case dw_val_class_str
:
9111 form
= AT_string_form (a
);
9112 if (form
== DW_FORM_strp
|| form
== DW_FORM_line_strp
)
9113 size
+= DWARF_OFFSET_SIZE
;
9114 else if (form
== DW_FORM_GNU_str_index
)
9115 size
+= size_of_uleb128 (AT_index (a
));
9117 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
9119 case dw_val_class_file
:
9120 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
9122 case dw_val_class_data8
:
9125 case dw_val_class_vms_delta
:
9126 size
+= DWARF_OFFSET_SIZE
;
9128 case dw_val_class_high_pc
:
9129 size
+= DWARF2_ADDR_SIZE
;
9131 case dw_val_class_discr_value
:
9132 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
9134 case dw_val_class_discr_list
:
9136 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
9138 /* This is a block, so we have the block length and then its
9140 size
+= constant_size (block_size
) + block_size
;
9151 /* Size the debugging information associated with a given DIE. Visits the
9152 DIE's children recursively. Updates the global variable next_die_offset, on
9153 each time through. Uses the current value of next_die_offset to update the
9154 die_offset field in each DIE. */
9157 calc_die_sizes (dw_die_ref die
)
9161 gcc_assert (die
->die_offset
== 0
9162 || (unsigned long int) die
->die_offset
== next_die_offset
);
9163 die
->die_offset
= next_die_offset
;
9164 next_die_offset
+= size_of_die (die
);
9166 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
9168 if (die
->die_child
!= NULL
)
9169 /* Count the null byte used to terminate sibling lists. */
9170 next_die_offset
+= 1;
9173 /* Size just the base type children at the start of the CU.
9174 This is needed because build_abbrev needs to size locs
9175 and sizing of type based stack ops needs to know die_offset
9176 values for the base types. */
9179 calc_base_type_die_sizes (void)
9181 unsigned long die_offset
= (dwarf_split_debug_info
9182 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9183 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
9185 dw_die_ref base_type
;
9186 #if ENABLE_ASSERT_CHECKING
9187 dw_die_ref prev
= comp_unit_die ()->die_child
;
9190 die_offset
+= size_of_die (comp_unit_die ());
9191 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
9193 #if ENABLE_ASSERT_CHECKING
9194 gcc_assert (base_type
->die_offset
== 0
9195 && prev
->die_sib
== base_type
9196 && base_type
->die_child
== NULL
9197 && base_type
->die_abbrev
);
9200 if (abbrev_opt_start
9201 && base_type
->die_abbrev
>= abbrev_opt_base_type_end
)
9202 abbrev_opt_base_type_end
= base_type
->die_abbrev
+ 1;
9203 base_type
->die_offset
= die_offset
;
9204 die_offset
+= size_of_die (base_type
);
9208 /* Set the marks for a die and its children. We do this so
9209 that we know whether or not a reference needs to use FORM_ref_addr; only
9210 DIEs in the same CU will be marked. We used to clear out the offset
9211 and use that as the flag, but ran into ordering problems. */
9214 mark_dies (dw_die_ref die
)
9218 gcc_assert (!die
->die_mark
);
9221 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
9224 /* Clear the marks for a die and its children. */
9227 unmark_dies (dw_die_ref die
)
9231 if (! use_debug_types
)
9232 gcc_assert (die
->die_mark
);
9235 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
9238 /* Clear the marks for a die, its children and referred dies. */
9241 unmark_all_dies (dw_die_ref die
)
9251 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
9253 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9254 if (AT_class (a
) == dw_val_class_die_ref
)
9255 unmark_all_dies (AT_ref (a
));
9258 /* Calculate if the entry should appear in the final output file. It may be
9259 from a pruned a type. */
9262 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
9264 /* By limiting gnu pubnames to definitions only, gold can generate a
9265 gdb index without entries for declarations, which don't include
9266 enough information to be useful. */
9267 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
9270 if (table
== pubname_table
)
9272 /* Enumerator names are part of the pubname table, but the
9273 parent DW_TAG_enumeration_type die may have been pruned.
9274 Don't output them if that is the case. */
9275 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
9276 (p
->die
->die_parent
== NULL
9277 || !p
->die
->die_parent
->die_perennial_p
))
9280 /* Everything else in the pubname table is included. */
9284 /* The pubtypes table shouldn't include types that have been
9286 return (p
->die
->die_offset
!= 0
9287 || !flag_eliminate_unused_debug_types
);
9290 /* Return the size of the .debug_pubnames or .debug_pubtypes table
9291 generated for the compilation unit. */
9293 static unsigned long
9294 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9299 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
9301 size
= DWARF_PUBNAMES_HEADER_SIZE
;
9302 FOR_EACH_VEC_ELT (*names
, i
, p
)
9303 if (include_pubname_in_output (names
, p
))
9304 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
9306 size
+= DWARF_OFFSET_SIZE
;
9310 /* Return the size of the information in the .debug_aranges section. */
9312 static unsigned long
9313 size_of_aranges (void)
9317 size
= DWARF_ARANGES_HEADER_SIZE
;
9319 /* Count the address/length pair for this compilation unit. */
9320 if (text_section_used
)
9321 size
+= 2 * DWARF2_ADDR_SIZE
;
9322 if (cold_text_section_used
)
9323 size
+= 2 * DWARF2_ADDR_SIZE
;
9324 if (have_multiple_function_sections
)
9329 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9331 if (DECL_IGNORED_P (fde
->decl
))
9333 if (!fde
->in_std_section
)
9334 size
+= 2 * DWARF2_ADDR_SIZE
;
9335 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9336 size
+= 2 * DWARF2_ADDR_SIZE
;
9340 /* Count the two zero words used to terminated the address range table. */
9341 size
+= 2 * DWARF2_ADDR_SIZE
;
9345 /* Select the encoding of an attribute value. */
9347 static enum dwarf_form
9348 value_format (dw_attr_node
*a
)
9350 switch (AT_class (a
))
9352 case dw_val_class_addr
:
9353 /* Only very few attributes allow DW_FORM_addr. */
9358 case DW_AT_entry_pc
:
9359 case DW_AT_trampoline
:
9360 return (AT_index (a
) == NOT_INDEXED
9361 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9365 switch (DWARF2_ADDR_SIZE
)
9368 return DW_FORM_data1
;
9370 return DW_FORM_data2
;
9372 return DW_FORM_data4
;
9374 return DW_FORM_data8
;
9378 case dw_val_class_loc_list
:
9379 if (dwarf_split_debug_info
9380 && dwarf_version
>= 5
9381 && AT_loc_list (a
)->num_assigned
)
9382 return DW_FORM_loclistx
;
9384 case dw_val_class_range_list
:
9385 /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9386 but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9387 care about sizes of .debug* sections in shared libraries and
9388 executables and don't take into account relocations that affect just
9389 relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9390 table in the .debug_rnglists section. */
9391 if (dwarf_split_debug_info
9392 && dwarf_version
>= 5
9393 && AT_class (a
) == dw_val_class_range_list
9395 && a
->dw_attr_val
.val_entry
!= RELOCATED_OFFSET
)
9396 return DW_FORM_rnglistx
;
9397 if (dwarf_version
>= 4)
9398 return DW_FORM_sec_offset
;
9400 case dw_val_class_vms_delta
:
9401 case dw_val_class_offset
:
9402 switch (DWARF_OFFSET_SIZE
)
9405 return DW_FORM_data4
;
9407 return DW_FORM_data8
;
9411 case dw_val_class_loc
:
9412 if (dwarf_version
>= 4)
9413 return DW_FORM_exprloc
;
9414 switch (constant_size (size_of_locs (AT_loc (a
))))
9417 return DW_FORM_block1
;
9419 return DW_FORM_block2
;
9421 return DW_FORM_block4
;
9425 case dw_val_class_const
:
9426 return DW_FORM_sdata
;
9427 case dw_val_class_unsigned_const
:
9428 switch (constant_size (AT_unsigned (a
)))
9431 return DW_FORM_data1
;
9433 return DW_FORM_data2
;
9435 /* In DWARF3 DW_AT_data_member_location with
9436 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
9437 constant, so we need to use DW_FORM_udata if we need
9438 a large constant. */
9439 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9440 return DW_FORM_udata
;
9441 return DW_FORM_data4
;
9443 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9444 return DW_FORM_udata
;
9445 return DW_FORM_data8
;
9449 case dw_val_class_const_implicit
:
9450 case dw_val_class_unsigned_const_implicit
:
9451 case dw_val_class_file_implicit
:
9452 return DW_FORM_implicit_const
;
9453 case dw_val_class_const_double
:
9454 switch (HOST_BITS_PER_WIDE_INT
)
9457 return DW_FORM_data2
;
9459 return DW_FORM_data4
;
9461 return DW_FORM_data8
;
9463 if (dwarf_version
>= 5)
9464 return DW_FORM_data16
;
9467 return DW_FORM_block1
;
9469 case dw_val_class_wide_int
:
9470 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
9473 return DW_FORM_data1
;
9475 return DW_FORM_data2
;
9477 return DW_FORM_data4
;
9479 return DW_FORM_data8
;
9481 if (dwarf_version
>= 5)
9482 return DW_FORM_data16
;
9485 return DW_FORM_block1
;
9487 case dw_val_class_vec
:
9488 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
9489 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
9492 return DW_FORM_block1
;
9494 return DW_FORM_block2
;
9496 return DW_FORM_block4
;
9500 case dw_val_class_flag
:
9501 if (dwarf_version
>= 4)
9503 /* Currently all add_AT_flag calls pass in 1 as last argument,
9504 so DW_FORM_flag_present can be used. If that ever changes,
9505 we'll need to use DW_FORM_flag and have some optimization
9506 in build_abbrev_table that will change those to
9507 DW_FORM_flag_present if it is set to 1 in all DIEs using
9508 the same abbrev entry. */
9509 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9510 return DW_FORM_flag_present
;
9512 return DW_FORM_flag
;
9513 case dw_val_class_die_ref
:
9514 if (AT_ref_external (a
))
9515 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
9518 case dw_val_class_fde_ref
:
9519 return DW_FORM_data
;
9520 case dw_val_class_lbl_id
:
9521 return (AT_index (a
) == NOT_INDEXED
9522 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9523 case dw_val_class_lineptr
:
9524 case dw_val_class_macptr
:
9525 case dw_val_class_loclistsptr
:
9526 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
9527 case dw_val_class_str
:
9528 return AT_string_form (a
);
9529 case dw_val_class_file
:
9530 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
9533 return DW_FORM_data1
;
9535 return DW_FORM_data2
;
9537 return DW_FORM_data4
;
9542 case dw_val_class_data8
:
9543 return DW_FORM_data8
;
9545 case dw_val_class_high_pc
:
9546 switch (DWARF2_ADDR_SIZE
)
9549 return DW_FORM_data1
;
9551 return DW_FORM_data2
;
9553 return DW_FORM_data4
;
9555 return DW_FORM_data8
;
9560 case dw_val_class_discr_value
:
9561 return (a
->dw_attr_val
.v
.val_discr_value
.pos
9564 case dw_val_class_discr_list
:
9565 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
9568 return DW_FORM_block1
;
9570 return DW_FORM_block2
;
9572 return DW_FORM_block4
;
9582 /* Output the encoding of an attribute value. */
9585 output_value_format (dw_attr_node
*a
)
9587 enum dwarf_form form
= value_format (a
);
9589 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
9592 /* Given a die and id, produce the appropriate abbreviations. */
9595 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
9598 dw_attr_node
*a_attr
;
9600 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
9601 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
9602 dwarf_tag_name (abbrev
->die_tag
));
9604 if (abbrev
->die_child
!= NULL
)
9605 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
9607 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
9609 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
9611 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
9612 dwarf_attr_name (a_attr
->dw_attr
));
9613 output_value_format (a_attr
);
9614 if (value_format (a_attr
) == DW_FORM_implicit_const
)
9616 if (AT_class (a_attr
) == dw_val_class_file_implicit
)
9618 int f
= maybe_emit_file (a_attr
->dw_attr_val
.v
.val_file
);
9619 const char *filename
= a_attr
->dw_attr_val
.v
.val_file
->filename
;
9620 dw2_asm_output_data_sleb128 (f
, "(%s)", filename
);
9623 dw2_asm_output_data_sleb128 (a_attr
->dw_attr_val
.v
.val_int
, NULL
);
9627 dw2_asm_output_data (1, 0, NULL
);
9628 dw2_asm_output_data (1, 0, NULL
);
9632 /* Output the .debug_abbrev section which defines the DIE abbreviation
9636 output_abbrev_section (void)
9638 unsigned int abbrev_id
;
9641 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
9643 output_die_abbrevs (abbrev_id
, abbrev
);
9645 /* Terminate the table. */
9646 dw2_asm_output_data (1, 0, NULL
);
9649 /* Return a new location list, given the begin and end range, and the
9652 static inline dw_loc_list_ref
9653 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
9654 const char *section
)
9656 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
9658 retlist
->begin
= begin
;
9659 retlist
->begin_entry
= NULL
;
9661 retlist
->expr
= expr
;
9662 retlist
->section
= section
;
9667 /* Generate a new internal symbol for this location list node, if it
9668 hasn't got one yet. */
9671 gen_llsym (dw_loc_list_ref list
)
9673 gcc_assert (!list
->ll_symbol
);
9674 list
->ll_symbol
= gen_internal_sym ("LLST");
9677 /* Output the location list given to us. */
9680 output_loc_list (dw_loc_list_ref list_head
)
9682 if (list_head
->emitted
)
9684 list_head
->emitted
= true;
9686 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
9688 dw_loc_list_ref curr
= list_head
;
9689 const char *last_section
= NULL
;
9690 const char *base_label
= NULL
;
9692 /* Walk the location list, and output each range + expression. */
9693 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
9696 /* Don't output an entry that starts and ends at the same address. */
9697 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
9699 size
= size_of_locs (curr
->expr
);
9700 /* If the expression is too large, drop it on the floor. We could
9701 perhaps put it into DW_TAG_dwarf_procedure and refer to that
9702 in the expression, but >= 64KB expressions for a single value
9703 in a single range are unlikely very useful. */
9704 if (dwarf_version
< 5 && size
> 0xffff)
9706 if (dwarf_version
>= 5)
9708 if (dwarf_split_debug_info
)
9710 /* For -gsplit-dwarf, emit DW_LLE_starx_length, which has
9711 uleb128 index into .debug_addr and uleb128 length. */
9712 dw2_asm_output_data (1, DW_LLE_startx_length
,
9713 "DW_LLE_startx_length (%s)",
9714 list_head
->ll_symbol
);
9715 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9716 "Location list range start index "
9717 "(%s)", curr
->begin
);
9718 /* FIXME: This will ICE ifndef HAVE_AS_LEB128.
9719 For that case we probably need to emit DW_LLE_startx_endx,
9720 but we'd need 2 .debug_addr entries rather than just one. */
9721 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9722 "Location list length (%s)",
9723 list_head
->ll_symbol
);
9725 else if (!have_multiple_function_sections
&& HAVE_AS_LEB128
)
9727 /* If all code is in .text section, the base address is
9728 already provided by the CU attributes. Use
9729 DW_LLE_offset_pair where both addresses are uleb128 encoded
9730 offsets against that base. */
9731 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9732 "DW_LLE_offset_pair (%s)",
9733 list_head
->ll_symbol
);
9734 dw2_asm_output_delta_uleb128 (curr
->begin
, curr
->section
,
9735 "Location list begin address (%s)",
9736 list_head
->ll_symbol
);
9737 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->section
,
9738 "Location list end address (%s)",
9739 list_head
->ll_symbol
);
9741 else if (HAVE_AS_LEB128
)
9743 /* Otherwise, find out how many consecutive entries could share
9744 the same base entry. If just one, emit DW_LLE_start_length,
9745 otherwise emit DW_LLE_base_address for the base address
9746 followed by a series of DW_LLE_offset_pair. */
9747 if (last_section
== NULL
|| curr
->section
!= last_section
)
9749 dw_loc_list_ref curr2
;
9750 for (curr2
= curr
->dw_loc_next
; curr2
!= NULL
;
9751 curr2
= curr2
->dw_loc_next
)
9753 if (strcmp (curr2
->begin
, curr2
->end
) == 0
9758 if (curr2
== NULL
|| curr
->section
!= curr2
->section
)
9759 last_section
= NULL
;
9762 last_section
= curr
->section
;
9763 base_label
= curr
->begin
;
9764 dw2_asm_output_data (1, DW_LLE_base_address
,
9765 "DW_LLE_base_address (%s)",
9766 list_head
->ll_symbol
);
9767 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, base_label
,
9768 "Base address (%s)",
9769 list_head
->ll_symbol
);
9772 /* Only one entry with the same base address. Use
9773 DW_LLE_start_length with absolute address and uleb128
9775 if (last_section
== NULL
)
9777 dw2_asm_output_data (1, DW_LLE_start_length
,
9778 "DW_LLE_start_length (%s)",
9779 list_head
->ll_symbol
);
9780 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9781 "Location list begin address (%s)",
9782 list_head
->ll_symbol
);
9783 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9784 "Location list length "
9785 "(%s)", list_head
->ll_symbol
);
9787 /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
9788 DW_LLE_base_address. */
9791 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9792 "DW_LLE_offset_pair (%s)",
9793 list_head
->ll_symbol
);
9794 dw2_asm_output_delta_uleb128 (curr
->begin
, base_label
,
9795 "Location list begin address "
9796 "(%s)", list_head
->ll_symbol
);
9797 dw2_asm_output_delta_uleb128 (curr
->end
, base_label
,
9798 "Location list end address "
9799 "(%s)", list_head
->ll_symbol
);
9802 /* The assembler does not support .uleb128 directive. Emit
9803 DW_LLE_start_end with a pair of absolute addresses. */
9806 dw2_asm_output_data (1, DW_LLE_start_end
,
9807 "DW_LLE_start_end (%s)",
9808 list_head
->ll_symbol
);
9809 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9810 "Location list begin address (%s)",
9811 list_head
->ll_symbol
);
9812 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9813 "Location list end address (%s)",
9814 list_head
->ll_symbol
);
9817 else if (dwarf_split_debug_info
)
9819 /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
9820 and 4 byte length. */
9821 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
9822 "Location list start/length entry (%s)",
9823 list_head
->ll_symbol
);
9824 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9825 "Location list range start index (%s)",
9827 /* The length field is 4 bytes. If we ever need to support
9828 an 8-byte length, we can add a new DW_LLE code or fall back
9829 to DW_LLE_GNU_start_end_entry. */
9830 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
9831 "Location list range length (%s)",
9832 list_head
->ll_symbol
);
9834 else if (!have_multiple_function_sections
)
9836 /* Pair of relative addresses against start of text section. */
9837 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
9838 "Location list begin address (%s)",
9839 list_head
->ll_symbol
);
9840 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
9841 "Location list end address (%s)",
9842 list_head
->ll_symbol
);
9846 /* Pair of absolute addresses. */
9847 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9848 "Location list begin address (%s)",
9849 list_head
->ll_symbol
);
9850 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9851 "Location list end address (%s)",
9852 list_head
->ll_symbol
);
9855 /* Output the block length for this list of location operations. */
9856 if (dwarf_version
>= 5)
9857 dw2_asm_output_data_uleb128 (size
, "Location expression size");
9860 gcc_assert (size
<= 0xffff);
9861 dw2_asm_output_data (2, size
, "Location expression size");
9864 output_loc_sequence (curr
->expr
, -1);
9867 /* And finally list termination. */
9868 if (dwarf_version
>= 5)
9869 dw2_asm_output_data (1, DW_LLE_end_of_list
,
9870 "DW_LLE_end_of_list (%s)", list_head
->ll_symbol
);
9871 else if (dwarf_split_debug_info
)
9872 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
9873 "Location list terminator (%s)",
9874 list_head
->ll_symbol
);
9877 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9878 "Location list terminator begin (%s)",
9879 list_head
->ll_symbol
);
9880 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9881 "Location list terminator end (%s)",
9882 list_head
->ll_symbol
);
9886 /* Output a range_list offset into the .debug_ranges or .debug_rnglists
9887 section. Emit a relocated reference if val_entry is NULL, otherwise,
9888 emit an indirect reference. */
9891 output_range_list_offset (dw_attr_node
*a
)
9893 const char *name
= dwarf_attr_name (a
->dw_attr
);
9895 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
9897 if (dwarf_version
>= 5)
9899 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9900 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, r
->label
,
9901 debug_ranges_section
, "%s", name
);
9905 char *p
= strchr (ranges_section_label
, '\0');
9906 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
9907 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
);
9908 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
9909 debug_ranges_section
, "%s", name
);
9913 else if (dwarf_version
>= 5)
9915 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9916 gcc_assert (rnglist_idx
);
9917 dw2_asm_output_data_uleb128 (r
->idx
, "%s", name
);
9920 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9921 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
,
9922 "%s (offset from %s)", name
, ranges_section_label
);
9925 /* Output the offset into the debug_loc section. */
9928 output_loc_list_offset (dw_attr_node
*a
)
9930 char *sym
= AT_loc_list (a
)->ll_symbol
;
9933 if (!dwarf_split_debug_info
)
9934 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
9935 "%s", dwarf_attr_name (a
->dw_attr
));
9936 else if (dwarf_version
>= 5)
9938 gcc_assert (AT_loc_list (a
)->num_assigned
);
9939 dw2_asm_output_data_uleb128 (AT_loc_list (a
)->hash
, "%s (%s)",
9940 dwarf_attr_name (a
->dw_attr
),
9944 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
9945 "%s", dwarf_attr_name (a
->dw_attr
));
9948 /* Output an attribute's index or value appropriately. */
9951 output_attr_index_or_value (dw_attr_node
*a
)
9953 const char *name
= dwarf_attr_name (a
->dw_attr
);
9955 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9957 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
9960 switch (AT_class (a
))
9962 case dw_val_class_addr
:
9963 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
9965 case dw_val_class_high_pc
:
9966 case dw_val_class_lbl_id
:
9967 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
9974 /* Output a type signature. */
9977 output_signature (const char *sig
, const char *name
)
9981 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9982 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
9985 /* Output a discriminant value. */
9988 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
9990 if (discr_value
->pos
)
9991 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
9993 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
9996 /* Output the DIE and its attributes. Called recursively to generate
9997 the definitions of each child DIE. */
10000 output_die (dw_die_ref die
)
10004 unsigned long size
;
10007 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
10008 (unsigned long)die
->die_offset
,
10009 dwarf_tag_name (die
->die_tag
));
10011 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
10013 const char *name
= dwarf_attr_name (a
->dw_attr
);
10015 switch (AT_class (a
))
10017 case dw_val_class_addr
:
10018 output_attr_index_or_value (a
);
10021 case dw_val_class_offset
:
10022 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
10026 case dw_val_class_range_list
:
10027 output_range_list_offset (a
);
10030 case dw_val_class_loc
:
10031 size
= size_of_locs (AT_loc (a
));
10033 /* Output the block length for this list of location operations. */
10034 if (dwarf_version
>= 4)
10035 dw2_asm_output_data_uleb128 (size
, "%s", name
);
10037 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
10039 output_loc_sequence (AT_loc (a
), -1);
10042 case dw_val_class_const
:
10043 /* ??? It would be slightly more efficient to use a scheme like is
10044 used for unsigned constants below, but gdb 4.x does not sign
10045 extend. Gdb 5.x does sign extend. */
10046 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
10049 case dw_val_class_unsigned_const
:
10051 int csize
= constant_size (AT_unsigned (a
));
10052 if (dwarf_version
== 3
10053 && a
->dw_attr
== DW_AT_data_member_location
10055 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
10057 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
10061 case dw_val_class_const_implicit
:
10062 if (flag_debug_asm
)
10063 fprintf (asm_out_file
, "\t\t\t%s %s ("
10064 HOST_WIDE_INT_PRINT_DEC
")\n",
10065 ASM_COMMENT_START
, name
, AT_int (a
));
10068 case dw_val_class_unsigned_const_implicit
:
10069 if (flag_debug_asm
)
10070 fprintf (asm_out_file
, "\t\t\t%s %s ("
10071 HOST_WIDE_INT_PRINT_HEX
")\n",
10072 ASM_COMMENT_START
, name
, AT_unsigned (a
));
10075 case dw_val_class_const_double
:
10077 unsigned HOST_WIDE_INT first
, second
;
10079 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
10080 dw2_asm_output_data (1,
10081 HOST_BITS_PER_DOUBLE_INT
10082 / HOST_BITS_PER_CHAR
,
10085 if (WORDS_BIG_ENDIAN
)
10087 first
= a
->dw_attr_val
.v
.val_double
.high
;
10088 second
= a
->dw_attr_val
.v
.val_double
.low
;
10092 first
= a
->dw_attr_val
.v
.val_double
.low
;
10093 second
= a
->dw_attr_val
.v
.val_double
.high
;
10096 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10097 first
, "%s", name
);
10098 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10103 case dw_val_class_wide_int
:
10106 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
10107 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10108 if (len
* HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
10109 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
)
10112 if (WORDS_BIG_ENDIAN
)
10113 for (i
= len
- 1; i
>= 0; --i
)
10115 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10120 for (i
= 0; i
< len
; ++i
)
10122 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10129 case dw_val_class_vec
:
10131 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
10132 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
10136 dw2_asm_output_data (constant_size (len
* elt_size
),
10137 len
* elt_size
, "%s", name
);
10138 if (elt_size
> sizeof (HOST_WIDE_INT
))
10143 for (i
= 0, p
= (unsigned char *) a
->dw_attr_val
.v
.val_vec
.array
;
10145 i
++, p
+= elt_size
)
10146 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
10147 "fp or vector constant word %u", i
);
10151 case dw_val_class_flag
:
10152 if (dwarf_version
>= 4)
10154 /* Currently all add_AT_flag calls pass in 1 as last argument,
10155 so DW_FORM_flag_present can be used. If that ever changes,
10156 we'll need to use DW_FORM_flag and have some optimization
10157 in build_abbrev_table that will change those to
10158 DW_FORM_flag_present if it is set to 1 in all DIEs using
10159 the same abbrev entry. */
10160 gcc_assert (AT_flag (a
) == 1);
10161 if (flag_debug_asm
)
10162 fprintf (asm_out_file
, "\t\t\t%s %s\n",
10163 ASM_COMMENT_START
, name
);
10166 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
10169 case dw_val_class_loc_list
:
10170 output_loc_list_offset (a
);
10173 case dw_val_class_die_ref
:
10174 if (AT_ref_external (a
))
10176 if (AT_ref (a
)->comdat_type_p
)
10178 comdat_type_node
*type_node
10179 = AT_ref (a
)->die_id
.die_type_node
;
10181 gcc_assert (type_node
);
10182 output_signature (type_node
->signature
, name
);
10186 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
10190 /* In DWARF2, DW_FORM_ref_addr is sized by target address
10191 length, whereas in DWARF3 it's always sized as an
10193 if (dwarf_version
== 2)
10194 size
= DWARF2_ADDR_SIZE
;
10196 size
= DWARF_OFFSET_SIZE
;
10197 /* ??? We cannot unconditionally output die_offset if
10198 non-zero - others might create references to those
10200 And we do not clear its DIE offset after outputting it
10201 (and the label refers to the actual DIEs, not the
10202 DWARF CU unit header which is when using label + offset
10203 would be the correct thing to do).
10204 ??? This is the reason for the with_offset flag. */
10205 if (AT_ref (a
)->with_offset
)
10206 dw2_asm_output_offset (size
, sym
, AT_ref (a
)->die_offset
,
10207 debug_info_section
, "%s", name
);
10209 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
10215 gcc_assert (AT_ref (a
)->die_offset
);
10216 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
10221 case dw_val_class_fde_ref
:
10223 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
10225 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
10226 a
->dw_attr_val
.v
.val_fde_index
* 2);
10227 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
10232 case dw_val_class_vms_delta
:
10233 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
10234 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
10235 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10238 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
10239 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10244 case dw_val_class_lbl_id
:
10245 output_attr_index_or_value (a
);
10248 case dw_val_class_lineptr
:
10249 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10250 debug_line_section
, "%s", name
);
10253 case dw_val_class_macptr
:
10254 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10255 debug_macinfo_section
, "%s", name
);
10258 case dw_val_class_loclistsptr
:
10259 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10260 debug_loc_section
, "%s", name
);
10263 case dw_val_class_str
:
10264 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
10265 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10266 a
->dw_attr_val
.v
.val_str
->label
,
10268 "%s: \"%s\"", name
, AT_string (a
));
10269 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_line_strp
)
10270 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10271 a
->dw_attr_val
.v
.val_str
->label
,
10272 debug_line_str_section
,
10273 "%s: \"%s\"", name
, AT_string (a
));
10274 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
10275 dw2_asm_output_data_uleb128 (AT_index (a
),
10276 "%s: \"%s\"", name
, AT_string (a
));
10278 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
10281 case dw_val_class_file
:
10283 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
10285 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
10286 a
->dw_attr_val
.v
.val_file
->filename
);
10290 case dw_val_class_file_implicit
:
10291 if (flag_debug_asm
)
10292 fprintf (asm_out_file
, "\t\t\t%s %s (%d, %s)\n",
10293 ASM_COMMENT_START
, name
,
10294 maybe_emit_file (a
->dw_attr_val
.v
.val_file
),
10295 a
->dw_attr_val
.v
.val_file
->filename
);
10298 case dw_val_class_data8
:
10302 for (i
= 0; i
< 8; i
++)
10303 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
10304 i
== 0 ? "%s" : NULL
, name
);
10308 case dw_val_class_high_pc
:
10309 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
10310 get_AT_low_pc (die
), "DW_AT_high_pc");
10313 case dw_val_class_discr_value
:
10314 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
10317 case dw_val_class_discr_list
:
10319 dw_discr_list_ref list
= AT_discr_list (a
);
10320 const int size
= size_of_discr_list (list
);
10322 /* This is a block, so output its length first. */
10323 dw2_asm_output_data (constant_size (size
), size
,
10324 "%s: block size", name
);
10326 for (; list
!= NULL
; list
= list
->dw_discr_next
)
10328 /* One byte for the discriminant value descriptor, and then as
10329 many LEB128 numbers as required. */
10330 if (list
->dw_discr_range
)
10331 dw2_asm_output_data (1, DW_DSC_range
,
10332 "%s: DW_DSC_range", name
);
10334 dw2_asm_output_data (1, DW_DSC_label
,
10335 "%s: DW_DSC_label", name
);
10337 output_discr_value (&list
->dw_discr_lower_bound
, name
);
10338 if (list
->dw_discr_range
)
10339 output_discr_value (&list
->dw_discr_upper_bound
, name
);
10345 gcc_unreachable ();
10349 FOR_EACH_CHILD (die
, c
, output_die (c
));
10351 /* Add null byte to terminate sibling list. */
10352 if (die
->die_child
!= NULL
)
10353 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
10354 (unsigned long) die
->die_offset
);
10357 /* Output the compilation unit that appears at the beginning of the
10358 .debug_info section, and precedes the DIE descriptions. */
10361 output_compilation_unit_header (enum dwarf_unit_type ut
)
10363 if (!XCOFF_DEBUGGING_INFO
)
10365 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10366 dw2_asm_output_data (4, 0xffffffff,
10367 "Initial length escape value indicating 64-bit DWARF extension");
10368 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10369 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
10370 "Length of Compilation Unit Info");
10373 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10374 if (dwarf_version
>= 5)
10379 case DW_UT_compile
: name
= "DW_UT_compile"; break;
10380 case DW_UT_type
: name
= "DW_UT_type"; break;
10381 case DW_UT_split_compile
: name
= "DW_UT_split_compile"; break;
10382 case DW_UT_split_type
: name
= "DW_UT_split_type"; break;
10383 default: gcc_unreachable ();
10385 dw2_asm_output_data (1, ut
, "%s", name
);
10386 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10388 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
10389 debug_abbrev_section
,
10390 "Offset Into Abbrev. Section");
10391 if (dwarf_version
< 5)
10392 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10395 /* Output the compilation unit DIE and its children. */
10398 output_comp_unit (dw_die_ref die
, int output_if_empty
,
10399 const unsigned char *dwo_id
)
10401 const char *secname
, *oldsym
;
10404 /* Unless we are outputting main CU, we may throw away empty ones. */
10405 if (!output_if_empty
&& die
->die_child
== NULL
)
10408 /* Even if there are no children of this DIE, we must output the information
10409 about the compilation unit. Otherwise, on an empty translation unit, we
10410 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
10411 will then complain when examining the file. First mark all the DIEs in
10412 this CU so we know which get local refs. */
10415 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
10417 /* For now, optimize only the main CU, in order to optimize the rest
10418 we'd need to see all of them earlier. Leave the rest for post-linking
10420 if (die
== comp_unit_die ())
10421 abbrev_opt_start
= vec_safe_length (abbrev_die_table
);
10423 build_abbrev_table (die
, extern_map
);
10425 optimize_abbrev_table ();
10429 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10430 next_die_offset
= (dwo_id
10431 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10432 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
10433 calc_die_sizes (die
);
10435 oldsym
= die
->die_id
.die_symbol
;
10436 if (oldsym
&& die
->comdat_type_p
)
10438 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
10440 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
10442 die
->die_id
.die_symbol
= NULL
;
10443 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10447 switch_to_section (debug_info_section
);
10448 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
10449 info_section_emitted
= true;
10452 /* For LTO cross unit DIE refs we want a symbol on the start of the
10453 debuginfo section, not on the CU DIE. */
10454 if ((flag_generate_lto
|| flag_generate_offload
) && oldsym
)
10456 /* ??? No way to get visibility assembled without a decl. */
10457 tree decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
,
10458 get_identifier (oldsym
), char_type_node
);
10459 TREE_PUBLIC (decl
) = true;
10460 TREE_STATIC (decl
) = true;
10461 DECL_ARTIFICIAL (decl
) = true;
10462 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
10463 DECL_VISIBILITY_SPECIFIED (decl
) = true;
10464 targetm
.asm_out
.assemble_visibility (decl
, VISIBILITY_HIDDEN
);
10465 #ifdef ASM_WEAKEN_LABEL
10466 /* We prefer a .weak because that handles duplicates from duplicate
10467 archive members in a graceful way. */
10468 ASM_WEAKEN_LABEL (asm_out_file
, oldsym
);
10470 targetm
.asm_out
.globalize_label (asm_out_file
, oldsym
);
10472 ASM_OUTPUT_LABEL (asm_out_file
, oldsym
);
10475 /* Output debugging information. */
10476 output_compilation_unit_header (dwo_id
10477 ? DW_UT_split_compile
: DW_UT_compile
);
10478 if (dwarf_version
>= 5)
10480 if (dwo_id
!= NULL
)
10481 for (int i
= 0; i
< 8; i
++)
10482 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10486 /* Leave the marks on the main CU, so we can check them in
10487 output_pubnames. */
10491 die
->die_id
.die_symbol
= oldsym
;
10495 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
10496 and .debug_pubtypes. This is configured per-target, but can be
10497 overridden by the -gpubnames or -gno-pubnames options. */
10500 want_pubnames (void)
10502 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10504 if (debug_generate_pub_sections
!= -1)
10505 return debug_generate_pub_sections
;
10506 return targetm
.want_debug_pub_sections
;
10509 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
10512 add_AT_pubnames (dw_die_ref die
)
10514 if (want_pubnames ())
10515 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
10518 /* Add a string attribute value to a skeleton DIE. */
10521 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
10525 struct indirect_string_node
*node
;
10527 if (! skeleton_debug_str_hash
)
10528 skeleton_debug_str_hash
10529 = hash_table
<indirect_string_hasher
>::create_ggc (10);
10531 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
10532 find_string_form (node
);
10533 if (node
->form
== DW_FORM_GNU_str_index
)
10534 node
->form
= DW_FORM_strp
;
10536 attr
.dw_attr
= attr_kind
;
10537 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
10538 attr
.dw_attr_val
.val_entry
= NULL
;
10539 attr
.dw_attr_val
.v
.val_str
= node
;
10540 add_dwarf_attr (die
, &attr
);
10543 /* Helper function to generate top-level dies for skeleton debug_info and
10547 add_top_level_skeleton_die_attrs (dw_die_ref die
)
10549 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
10550 const char *comp_dir
= comp_dir_string ();
10552 add_skeleton_AT_string (die
, dwarf_AT (DW_AT_dwo_name
), dwo_file_name
);
10553 if (comp_dir
!= NULL
)
10554 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
10555 add_AT_pubnames (die
);
10556 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
10559 /* Output skeleton debug sections that point to the dwo file. */
10562 output_skeleton_debug_sections (dw_die_ref comp_unit
,
10563 const unsigned char *dwo_id
)
10565 /* These attributes will be found in the full debug_info section. */
10566 remove_AT (comp_unit
, DW_AT_producer
);
10567 remove_AT (comp_unit
, DW_AT_language
);
10569 switch_to_section (debug_skeleton_info_section
);
10570 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
10572 /* Produce the skeleton compilation-unit header. This one differs enough from
10573 a normal CU header that it's better not to call output_compilation_unit
10575 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10576 dw2_asm_output_data (4, 0xffffffff,
10577 "Initial length escape value indicating 64-bit "
10578 "DWARF extension");
10580 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10581 DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10582 - DWARF_INITIAL_LENGTH_SIZE
10583 + size_of_die (comp_unit
),
10584 "Length of Compilation Unit Info");
10585 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10586 if (dwarf_version
>= 5)
10588 dw2_asm_output_data (1, DW_UT_skeleton
, "DW_UT_skeleton");
10589 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10591 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
10592 debug_skeleton_abbrev_section
,
10593 "Offset Into Abbrev. Section");
10594 if (dwarf_version
< 5)
10595 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10597 for (int i
= 0; i
< 8; i
++)
10598 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10600 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
10601 output_die (comp_unit
);
10603 /* Build the skeleton debug_abbrev section. */
10604 switch_to_section (debug_skeleton_abbrev_section
);
10605 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
10607 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
10609 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
10612 /* Output a comdat type unit DIE and its children. */
10615 output_comdat_type_unit (comdat_type_node
*node
)
10617 const char *secname
;
10620 #if defined (OBJECT_FORMAT_ELF)
10624 /* First mark all the DIEs in this CU so we know which get local refs. */
10625 mark_dies (node
->root_die
);
10627 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
10629 build_abbrev_table (node
->root_die
, extern_map
);
10634 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10635 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
10636 calc_die_sizes (node
->root_die
);
10638 #if defined (OBJECT_FORMAT_ELF)
10639 if (dwarf_version
>= 5)
10641 if (!dwarf_split_debug_info
)
10642 secname
= ".debug_info";
10644 secname
= ".debug_info.dwo";
10646 else if (!dwarf_split_debug_info
)
10647 secname
= ".debug_types";
10649 secname
= ".debug_types.dwo";
10651 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10652 sprintf (tmp
, dwarf_version
>= 5 ? "wi." : "wt.");
10653 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10654 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10655 comdat_key
= get_identifier (tmp
);
10656 targetm
.asm_out
.named_section (secname
,
10657 SECTION_DEBUG
| SECTION_LINKONCE
,
10660 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10661 sprintf (tmp
, (dwarf_version
>= 5
10662 ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
10663 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10664 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10666 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10669 /* Output debugging information. */
10670 output_compilation_unit_header (dwarf_split_debug_info
10671 ? DW_UT_split_type
: DW_UT_type
);
10672 output_signature (node
->signature
, "Type Signature");
10673 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
10674 "Offset to Type DIE");
10675 output_die (node
->root_die
);
10677 unmark_dies (node
->root_die
);
10680 /* Return the DWARF2/3 pubname associated with a decl. */
10682 static const char *
10683 dwarf2_name (tree decl
, int scope
)
10685 if (DECL_NAMELESS (decl
))
10687 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
10690 /* Add a new entry to .debug_pubnames if appropriate. */
10693 add_pubname_string (const char *str
, dw_die_ref die
)
10698 e
.name
= xstrdup (str
);
10699 vec_safe_push (pubname_table
, e
);
10703 add_pubname (tree decl
, dw_die_ref die
)
10705 if (!want_pubnames ())
10708 /* Don't add items to the table when we expect that the consumer will have
10709 just read the enclosing die. For example, if the consumer is looking at a
10710 class_member, it will either be inside the class already, or will have just
10711 looked up the class to find the member. Either way, searching the class is
10712 faster than searching the index. */
10713 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
10714 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10716 const char *name
= dwarf2_name (decl
, 1);
10719 add_pubname_string (name
, die
);
10723 /* Add an enumerator to the pubnames section. */
10726 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
10730 gcc_assert (scope_name
);
10731 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
10733 vec_safe_push (pubname_table
, e
);
10736 /* Add a new entry to .debug_pubtypes if appropriate. */
10739 add_pubtype (tree decl
, dw_die_ref die
)
10743 if (!want_pubnames ())
10746 if ((TREE_PUBLIC (decl
)
10747 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10748 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
10751 const char *scope_name
= "";
10752 const char *sep
= is_cxx () ? "::" : ".";
10755 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
10756 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
10758 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
10759 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
10760 scope_name
= concat (scope_name
, sep
, NULL
);
10766 name
= type_tag (decl
);
10768 name
= lang_hooks
.dwarf_name (decl
, 1);
10770 /* If we don't have a name for the type, there's no point in adding
10771 it to the table. */
10772 if (name
!= NULL
&& name
[0] != '\0')
10775 e
.name
= concat (scope_name
, name
, NULL
);
10776 vec_safe_push (pubtype_table
, e
);
10779 /* Although it might be more consistent to add the pubinfo for the
10780 enumerators as their dies are created, they should only be added if the
10781 enum type meets the criteria above. So rather than re-check the parent
10782 enum type whenever an enumerator die is created, just output them all
10783 here. This isn't protected by the name conditional because anonymous
10784 enums don't have names. */
10785 if (die
->die_tag
== DW_TAG_enumeration_type
)
10789 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
10794 /* Output a single entry in the pubnames table. */
10797 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
10799 dw_die_ref die
= entry
->die
;
10800 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
10802 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
10804 if (debug_generate_pub_sections
== 2)
10806 /* This logic follows gdb's method for determining the value of the flag
10808 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
10809 switch (die
->die_tag
)
10811 case DW_TAG_typedef
:
10812 case DW_TAG_base_type
:
10813 case DW_TAG_subrange_type
:
10814 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10815 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10817 case DW_TAG_enumerator
:
10818 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10819 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10821 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10823 case DW_TAG_subprogram
:
10824 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10825 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
10827 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10829 case DW_TAG_constant
:
10830 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10831 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10832 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10834 case DW_TAG_variable
:
10835 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10836 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10837 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10839 case DW_TAG_namespace
:
10840 case DW_TAG_imported_declaration
:
10841 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10843 case DW_TAG_class_type
:
10844 case DW_TAG_interface_type
:
10845 case DW_TAG_structure_type
:
10846 case DW_TAG_union_type
:
10847 case DW_TAG_enumeration_type
:
10848 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10850 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10853 /* An unusual tag. Leave the flag-byte empty. */
10856 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
10857 "GDB-index flags");
10860 dw2_asm_output_nstring (entry
->name
, -1, "external name");
10864 /* Output the public names table used to speed up access to externally
10865 visible names; or the public types table used to find type definitions. */
10868 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
10871 unsigned long pubnames_length
= size_of_pubnames (names
);
10872 pubname_entry
*pub
;
10874 if (!XCOFF_DEBUGGING_INFO
)
10876 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10877 dw2_asm_output_data (4, 0xffffffff,
10878 "Initial length escape value indicating 64-bit DWARF extension");
10879 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
10880 "Pub Info Length");
10883 /* Version number for pubnames/pubtypes is independent of dwarf version. */
10884 dw2_asm_output_data (2, 2, "DWARF Version");
10886 if (dwarf_split_debug_info
)
10887 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10888 debug_skeleton_info_section
,
10889 "Offset of Compilation Unit Info");
10891 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10892 debug_info_section
,
10893 "Offset of Compilation Unit Info");
10894 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
10895 "Compilation Unit Length");
10897 FOR_EACH_VEC_ELT (*names
, i
, pub
)
10899 if (include_pubname_in_output (names
, pub
))
10901 dw_offset die_offset
= pub
->die
->die_offset
;
10903 /* We shouldn't see pubnames for DIEs outside of the main CU. */
10904 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
10905 gcc_assert (pub
->die
->die_mark
);
10907 /* If we're putting types in their own .debug_types sections,
10908 the .debug_pubtypes table will still point to the compile
10909 unit (not the type unit), so we want to use the offset of
10910 the skeleton DIE (if there is one). */
10911 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
10913 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
10915 if (type_node
!= NULL
)
10916 die_offset
= (type_node
->skeleton_die
!= NULL
10917 ? type_node
->skeleton_die
->die_offset
10918 : comp_unit_die ()->die_offset
);
10921 output_pubname (die_offset
, pub
);
10925 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
10928 /* Output public names and types tables if necessary. */
10931 output_pubtables (void)
10933 if (!want_pubnames () || !info_section_emitted
)
10936 switch_to_section (debug_pubnames_section
);
10937 output_pubnames (pubname_table
);
10938 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
10939 It shouldn't hurt to emit it always, since pure DWARF2 consumers
10940 simply won't look for the section. */
10941 switch_to_section (debug_pubtypes_section
);
10942 output_pubnames (pubtype_table
);
10946 /* Output the information that goes into the .debug_aranges table.
10947 Namely, define the beginning and ending address range of the
10948 text section generated for this compilation unit. */
10951 output_aranges (void)
10954 unsigned long aranges_length
= size_of_aranges ();
10956 if (!XCOFF_DEBUGGING_INFO
)
10958 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10959 dw2_asm_output_data (4, 0xffffffff,
10960 "Initial length escape value indicating 64-bit DWARF extension");
10961 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
10962 "Length of Address Ranges Info");
10965 /* Version number for aranges is still 2, even up to DWARF5. */
10966 dw2_asm_output_data (2, 2, "DWARF Version");
10967 if (dwarf_split_debug_info
)
10968 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10969 debug_skeleton_info_section
,
10970 "Offset of Compilation Unit Info");
10972 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10973 debug_info_section
,
10974 "Offset of Compilation Unit Info");
10975 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
10976 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
10978 /* We need to align to twice the pointer size here. */
10979 if (DWARF_ARANGES_PAD_SIZE
)
10981 /* Pad using a 2 byte words so that padding is correct for any
10983 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
10984 2 * DWARF2_ADDR_SIZE
);
10985 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
10986 dw2_asm_output_data (2, 0, NULL
);
10989 /* It is necessary not to output these entries if the sections were
10990 not used; if the sections were not used, the length will be 0 and
10991 the address may end up as 0 if the section is discarded by ld
10992 --gc-sections, leaving an invalid (0, 0) entry that can be
10993 confused with the terminator. */
10994 if (text_section_used
)
10996 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
10997 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
10998 text_section_label
, "Length");
11000 if (cold_text_section_used
)
11002 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
11004 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
11005 cold_text_section_label
, "Length");
11008 if (have_multiple_function_sections
)
11013 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
11015 if (DECL_IGNORED_P (fde
->decl
))
11017 if (!fde
->in_std_section
)
11019 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
11021 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
11022 fde
->dw_fde_begin
, "Length");
11024 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
11026 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
11028 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
11029 fde
->dw_fde_second_begin
, "Length");
11034 /* Output the terminator words. */
11035 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11036 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11039 /* Add a new entry to .debug_ranges. Return its index into
11040 ranges_table vector. */
11042 static unsigned int
11043 add_ranges_num (int num
, bool maybe_new_sec
)
11045 dw_ranges r
= { NULL
, num
, 0, maybe_new_sec
};
11046 vec_safe_push (ranges_table
, r
);
11047 return vec_safe_length (ranges_table
) - 1;
11050 /* Add a new entry to .debug_ranges corresponding to a block, or a
11051 range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
11052 this entry might be in a different section from previous range. */
11054 static unsigned int
11055 add_ranges (const_tree block
, bool maybe_new_sec
)
11057 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0, maybe_new_sec
);
11060 /* Note that (*rnglist_table)[offset] is either a head of a rnglist
11061 chain, or middle entry of a chain that will be directly referred to. */
11064 note_rnglist_head (unsigned int offset
)
11066 if (dwarf_version
< 5 || (*ranges_table
)[offset
].label
)
11068 (*ranges_table
)[offset
].label
= gen_internal_sym ("LLRL");
11071 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
11072 When using dwarf_split_debug_info, address attributes in dies destined
11073 for the final executable should be direct references--setting the
11074 parameter force_direct ensures this behavior. */
11077 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11078 bool *added
, bool force_direct
)
11080 unsigned int in_use
= vec_safe_length (ranges_by_label
);
11081 unsigned int offset
;
11082 dw_ranges_by_label rbl
= { begin
, end
};
11083 vec_safe_push (ranges_by_label
, rbl
);
11084 offset
= add_ranges_num (-(int)in_use
- 1, true);
11087 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
11089 note_rnglist_head (offset
);
11093 /* Emit .debug_ranges section. */
11096 output_ranges (void)
11099 static const char *const start_fmt
= "Offset %#x";
11100 const char *fmt
= start_fmt
;
11103 switch_to_section (debug_ranges_section
);
11104 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11105 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11107 int block_num
= r
->num
;
11111 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11112 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11114 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11115 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11117 /* If all code is in the text section, then the compilation
11118 unit base address defaults to DW_AT_low_pc, which is the
11119 base of the text section. */
11120 if (!have_multiple_function_sections
)
11122 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11123 text_section_label
,
11124 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11125 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11126 text_section_label
, NULL
);
11129 /* Otherwise, the compilation unit base address is zero,
11130 which allows us to use absolute addresses, and not worry
11131 about whether the target supports cross-section
11135 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11136 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11137 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11143 /* Negative block_num stands for an index into ranges_by_label. */
11144 else if (block_num
< 0)
11146 int lab_idx
= - block_num
- 1;
11148 if (!have_multiple_function_sections
)
11150 gcc_unreachable ();
11152 /* If we ever use add_ranges_by_labels () for a single
11153 function section, all we have to do is to take out
11154 the #if 0 above. */
11155 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11156 (*ranges_by_label
)[lab_idx
].begin
,
11157 text_section_label
,
11158 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11159 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11160 (*ranges_by_label
)[lab_idx
].end
,
11161 text_section_label
, NULL
);
11166 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11167 (*ranges_by_label
)[lab_idx
].begin
,
11168 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11169 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11170 (*ranges_by_label
)[lab_idx
].end
,
11176 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11177 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11183 /* Non-zero if .debug_line_str should be used for .debug_line section
11184 strings or strings that are likely shareable with those. */
11185 #define DWARF5_USE_DEBUG_LINE_STR \
11186 (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
11187 && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
11188 /* FIXME: there is no .debug_line_str.dwo section, \
11189 for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
11190 && !dwarf_split_debug_info)
11192 /* Assign .debug_rnglists indexes. */
11195 index_rnglists (void)
11200 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11202 r
->idx
= rnglist_idx
++;
11205 /* Emit .debug_rnglists section. */
11208 output_rnglists (unsigned generation
)
11212 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
11213 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11214 char basebuf
[MAX_ARTIFICIAL_LABEL_BYTES
];
11216 switch_to_section (debug_ranges_section
);
11217 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11218 /* There are up to 4 unique ranges labels per generation.
11219 See also init_sections_and_labels. */
11220 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_RANGES_SECTION_LABEL
,
11221 2 + generation
* 4);
11222 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_RANGES_SECTION_LABEL
,
11223 3 + generation
* 4);
11224 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11225 dw2_asm_output_data (4, 0xffffffff,
11226 "Initial length escape value indicating "
11227 "64-bit DWARF extension");
11228 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11229 "Length of Range Lists");
11230 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11231 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11232 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11233 dw2_asm_output_data (1, 0, "Segment Size");
11234 /* Emit the offset table only for -gsplit-dwarf. If we don't care
11235 about relocation sizes and primarily care about the size of .debug*
11236 sections in linked shared libraries and executables, then
11237 the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
11238 into it are usually larger than just DW_FORM_sec_offset offsets
11239 into the .debug_rnglists section. */
11240 dw2_asm_output_data (4, dwarf_split_debug_info
? rnglist_idx
: 0,
11241 "Offset Entry Count");
11242 if (dwarf_split_debug_info
)
11244 ASM_OUTPUT_LABEL (asm_out_file
, ranges_base_label
);
11245 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11247 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, r
->label
,
11248 ranges_base_label
, NULL
);
11251 const char *lab
= "";
11252 unsigned int len
= vec_safe_length (ranges_table
);
11253 const char *base
= NULL
;
11254 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11256 int block_num
= r
->num
;
11260 ASM_OUTPUT_LABEL (asm_out_file
, r
->label
);
11263 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
11267 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11268 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11270 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11271 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11273 if (HAVE_AS_LEB128
)
11275 /* If all code is in the text section, then the compilation
11276 unit base address defaults to DW_AT_low_pc, which is the
11277 base of the text section. */
11278 if (!have_multiple_function_sections
)
11280 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11281 "DW_RLE_offset_pair (%s)", lab
);
11282 dw2_asm_output_delta_uleb128 (blabel
, text_section_label
,
11283 "Range begin address (%s)", lab
);
11284 dw2_asm_output_delta_uleb128 (elabel
, text_section_label
,
11285 "Range end address (%s)", lab
);
11290 dw_ranges
*r2
= NULL
;
11292 r2
= &(*ranges_table
)[i
+ 1];
11295 && r2
->label
== NULL
11296 && !r2
->maybe_new_sec
)
11298 dw2_asm_output_data (1, DW_RLE_base_address
,
11299 "DW_RLE_base_address (%s)", lab
);
11300 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11301 "Base address (%s)", lab
);
11302 strcpy (basebuf
, blabel
);
11308 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11309 "DW_RLE_offset_pair (%s)", lab
);
11310 dw2_asm_output_delta_uleb128 (blabel
, base
,
11311 "Range begin address (%s)", lab
);
11312 dw2_asm_output_delta_uleb128 (elabel
, base
,
11313 "Range end address (%s)", lab
);
11316 dw2_asm_output_data (1, DW_RLE_start_length
,
11317 "DW_RLE_start_length (%s)", lab
);
11318 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11319 "Range begin address (%s)", lab
);
11320 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11321 "Range length (%s)", lab
);
11325 dw2_asm_output_data (1, DW_RLE_start_end
,
11326 "DW_RLE_start_end (%s)", lab
);
11327 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11328 "Range begin address (%s)", lab
);
11329 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11330 "Range end address (%s)", lab
);
11334 /* Negative block_num stands for an index into ranges_by_label. */
11335 else if (block_num
< 0)
11337 int lab_idx
= - block_num
- 1;
11338 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
11339 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
11341 if (!have_multiple_function_sections
)
11342 gcc_unreachable ();
11343 if (HAVE_AS_LEB128
)
11345 dw2_asm_output_data (1, DW_RLE_start_length
,
11346 "DW_RLE_start_length (%s)", lab
);
11347 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11348 "Range begin address (%s)", lab
);
11349 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11350 "Range length (%s)", lab
);
11354 dw2_asm_output_data (1, DW_RLE_start_end
,
11355 "DW_RLE_start_end (%s)", lab
);
11356 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11357 "Range begin address (%s)", lab
);
11358 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11359 "Range end address (%s)", lab
);
11363 dw2_asm_output_data (1, DW_RLE_end_of_list
,
11364 "DW_RLE_end_of_list (%s)", lab
);
11366 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11369 /* Data structure containing information about input files. */
11372 const char *path
; /* Complete file name. */
11373 const char *fname
; /* File name part. */
11374 int length
; /* Length of entire string. */
11375 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
11376 int dir_idx
; /* Index in directory table. */
11379 /* Data structure containing information about directories with source
11383 const char *path
; /* Path including directory name. */
11384 int length
; /* Path length. */
11385 int prefix
; /* Index of directory entry which is a prefix. */
11386 int count
; /* Number of files in this directory. */
11387 int dir_idx
; /* Index of directory used as base. */
11390 /* Callback function for file_info comparison. We sort by looking at
11391 the directories in the path. */
11394 file_info_cmp (const void *p1
, const void *p2
)
11396 const struct file_info
*const s1
= (const struct file_info
*) p1
;
11397 const struct file_info
*const s2
= (const struct file_info
*) p2
;
11398 const unsigned char *cp1
;
11399 const unsigned char *cp2
;
11401 /* Take care of file names without directories. We need to make sure that
11402 we return consistent values to qsort since some will get confused if
11403 we return the same value when identical operands are passed in opposite
11404 orders. So if neither has a directory, return 0 and otherwise return
11405 1 or -1 depending on which one has the directory. */
11406 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
11407 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
11409 cp1
= (const unsigned char *) s1
->path
;
11410 cp2
= (const unsigned char *) s2
->path
;
11416 /* Reached the end of the first path? If so, handle like above. */
11417 if ((cp1
== (const unsigned char *) s1
->fname
)
11418 || (cp2
== (const unsigned char *) s2
->fname
))
11419 return ((cp2
== (const unsigned char *) s2
->fname
)
11420 - (cp1
== (const unsigned char *) s1
->fname
));
11422 /* Character of current path component the same? */
11423 else if (*cp1
!= *cp2
)
11424 return *cp1
- *cp2
;
11428 struct file_name_acquire_data
11430 struct file_info
*files
;
11435 /* Traversal function for the hash table. */
11438 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
11440 struct dwarf_file_data
*d
= *slot
;
11441 struct file_info
*fi
;
11444 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
11446 if (! d
->emitted_number
)
11449 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
11451 fi
= fnad
->files
+ fnad
->used_files
++;
11453 /* Skip all leading "./". */
11455 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
11458 /* Create a new array entry. */
11460 fi
->length
= strlen (f
);
11463 /* Search for the file name part. */
11464 f
= strrchr (f
, DIR_SEPARATOR
);
11465 #if defined (DIR_SEPARATOR_2)
11467 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
11471 if (f
== NULL
|| f
< g
)
11477 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
11481 /* Helper function for output_file_names. Emit a FORM encoded
11482 string STR, with assembly comment start ENTRY_KIND and
11486 output_line_string (enum dwarf_form form
, const char *str
,
11487 const char *entry_kind
, unsigned int idx
)
11491 case DW_FORM_string
:
11492 dw2_asm_output_nstring (str
, -1, "%s: %#x", entry_kind
, idx
);
11494 case DW_FORM_line_strp
:
11495 if (!debug_line_str_hash
)
11496 debug_line_str_hash
11497 = hash_table
<indirect_string_hasher
>::create_ggc (10);
11499 struct indirect_string_node
*node
;
11500 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
11501 set_indirect_string (node
);
11503 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
11504 debug_line_str_section
, "%s: %#x: \"%s\"",
11505 entry_kind
, 0, node
->str
);
11508 gcc_unreachable ();
11512 /* Output the directory table and the file name table. We try to minimize
11513 the total amount of memory needed. A heuristic is used to avoid large
11514 slowdowns with many input files. */
11517 output_file_names (void)
11519 struct file_name_acquire_data fnad
;
11521 struct file_info
*files
;
11522 struct dir_info
*dirs
;
11530 if (!last_emitted_file
)
11532 if (dwarf_version
>= 5)
11534 dw2_asm_output_data (1, 0, "Directory entry format count");
11535 dw2_asm_output_data_uleb128 (0, "Directories count");
11536 dw2_asm_output_data (1, 0, "File name entry format count");
11537 dw2_asm_output_data_uleb128 (0, "File names count");
11541 dw2_asm_output_data (1, 0, "End directory table");
11542 dw2_asm_output_data (1, 0, "End file name table");
11547 numfiles
= last_emitted_file
->emitted_number
;
11549 /* Allocate the various arrays we need. */
11550 files
= XALLOCAVEC (struct file_info
, numfiles
);
11551 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
11553 fnad
.files
= files
;
11554 fnad
.used_files
= 0;
11555 fnad
.max_files
= numfiles
;
11556 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
11557 gcc_assert (fnad
.used_files
== fnad
.max_files
);
11559 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
11561 /* Find all the different directories used. */
11562 dirs
[0].path
= files
[0].path
;
11563 dirs
[0].length
= files
[0].fname
- files
[0].path
;
11564 dirs
[0].prefix
= -1;
11566 dirs
[0].dir_idx
= 0;
11567 files
[0].dir_idx
= 0;
11570 for (i
= 1; i
< numfiles
; i
++)
11571 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
11572 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
11573 dirs
[ndirs
- 1].length
) == 0)
11575 /* Same directory as last entry. */
11576 files
[i
].dir_idx
= ndirs
- 1;
11577 ++dirs
[ndirs
- 1].count
;
11583 /* This is a new directory. */
11584 dirs
[ndirs
].path
= files
[i
].path
;
11585 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
11586 dirs
[ndirs
].count
= 1;
11587 dirs
[ndirs
].dir_idx
= ndirs
;
11588 files
[i
].dir_idx
= ndirs
;
11590 /* Search for a prefix. */
11591 dirs
[ndirs
].prefix
= -1;
11592 for (j
= 0; j
< ndirs
; j
++)
11593 if (dirs
[j
].length
< dirs
[ndirs
].length
11594 && dirs
[j
].length
> 1
11595 && (dirs
[ndirs
].prefix
== -1
11596 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
11597 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
11598 dirs
[ndirs
].prefix
= j
;
11603 /* Now to the actual work. We have to find a subset of the directories which
11604 allow expressing the file name using references to the directory table
11605 with the least amount of characters. We do not do an exhaustive search
11606 where we would have to check out every combination of every single
11607 possible prefix. Instead we use a heuristic which provides nearly optimal
11608 results in most cases and never is much off. */
11609 saved
= XALLOCAVEC (int, ndirs
);
11610 savehere
= XALLOCAVEC (int, ndirs
);
11612 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
11613 for (i
= 0; i
< ndirs
; i
++)
11618 /* We can always save some space for the current directory. But this
11619 does not mean it will be enough to justify adding the directory. */
11620 savehere
[i
] = dirs
[i
].length
;
11621 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
11623 for (j
= i
+ 1; j
< ndirs
; j
++)
11626 if (saved
[j
] < dirs
[i
].length
)
11628 /* Determine whether the dirs[i] path is a prefix of the
11632 k
= dirs
[j
].prefix
;
11633 while (k
!= -1 && k
!= (int) i
)
11634 k
= dirs
[k
].prefix
;
11638 /* Yes it is. We can possibly save some memory by
11639 writing the filenames in dirs[j] relative to
11641 savehere
[j
] = dirs
[i
].length
;
11642 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
11647 /* Check whether we can save enough to justify adding the dirs[i]
11649 if (total
> dirs
[i
].length
+ 1)
11651 /* It's worthwhile adding. */
11652 for (j
= i
; j
< ndirs
; j
++)
11653 if (savehere
[j
] > 0)
11655 /* Remember how much we saved for this directory so far. */
11656 saved
[j
] = savehere
[j
];
11658 /* Remember the prefix directory. */
11659 dirs
[j
].dir_idx
= i
;
11664 /* Emit the directory name table. */
11665 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
11666 enum dwarf_form str_form
= DW_FORM_string
;
11667 enum dwarf_form idx_form
= DW_FORM_udata
;
11668 if (dwarf_version
>= 5)
11670 const char *comp_dir
= comp_dir_string ();
11671 if (comp_dir
== NULL
)
11673 dw2_asm_output_data (1, 1, "Directory entry format count");
11674 if (DWARF5_USE_DEBUG_LINE_STR
)
11675 str_form
= DW_FORM_line_strp
;
11676 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11677 dw2_asm_output_data_uleb128 (str_form
, "%s",
11678 get_DW_FORM_name (str_form
));
11679 dw2_asm_output_data_uleb128 (ndirs
+ idx_offset
, "Directories count");
11680 if (str_form
== DW_FORM_string
)
11682 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
11683 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11684 dw2_asm_output_nstring (dirs
[i
].path
,
11686 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11687 "Directory Entry: %#x", i
+ idx_offset
);
11691 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
11692 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11695 = ggc_alloc_string (dirs
[i
].path
,
11697 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
);
11698 output_line_string (str_form
, str
, "Directory Entry",
11699 (unsigned) i
+ idx_offset
);
11705 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11706 dw2_asm_output_nstring (dirs
[i
].path
,
11708 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11709 "Directory Entry: %#x", i
+ idx_offset
);
11711 dw2_asm_output_data (1, 0, "End directory table");
11714 /* We have to emit them in the order of emitted_number since that's
11715 used in the debug info generation. To do this efficiently we
11716 generate a back-mapping of the indices first. */
11717 backmap
= XALLOCAVEC (int, numfiles
);
11718 for (i
= 0; i
< numfiles
; i
++)
11719 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
11721 if (dwarf_version
>= 5)
11723 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
11724 if (filename0
== NULL
)
11726 /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
11727 DW_FORM_data2. Choose one based on the number of directories
11728 and how much space would they occupy in each encoding.
11729 If we have at most 256 directories, all indexes fit into
11730 a single byte, so DW_FORM_data1 is most compact (if there
11731 are at most 128 directories, DW_FORM_udata would be as
11732 compact as that, but not shorter and slower to decode). */
11733 if (ndirs
+ idx_offset
<= 256)
11734 idx_form
= DW_FORM_data1
;
11735 /* If there are more than 65536 directories, we have to use
11736 DW_FORM_udata, DW_FORM_data2 can't refer to them.
11737 Otherwise, compute what space would occupy if all the indexes
11738 used DW_FORM_udata - sum - and compare that to how large would
11739 be DW_FORM_data2 encoding, and pick the more efficient one. */
11740 else if (ndirs
+ idx_offset
<= 65536)
11742 unsigned HOST_WIDE_INT sum
= 1;
11743 for (i
= 0; i
< numfiles
; i
++)
11745 int file_idx
= backmap
[i
];
11746 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11747 sum
+= size_of_uleb128 (dir_idx
);
11749 if (sum
>= HOST_WIDE_INT_UC (2) * (numfiles
+ 1))
11750 idx_form
= DW_FORM_data2
;
11752 #ifdef VMS_DEBUGGING_INFO
11753 dw2_asm_output_data (1, 4, "File name entry format count");
11755 dw2_asm_output_data (1, 2, "File name entry format count");
11757 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11758 dw2_asm_output_data_uleb128 (str_form
, "%s",
11759 get_DW_FORM_name (str_form
));
11760 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
11761 "DW_LNCT_directory_index");
11762 dw2_asm_output_data_uleb128 (idx_form
, "%s",
11763 get_DW_FORM_name (idx_form
));
11764 #ifdef VMS_DEBUGGING_INFO
11765 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
11766 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11767 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
11768 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11770 dw2_asm_output_data_uleb128 (numfiles
+ 1, "File names count");
11772 output_line_string (str_form
, filename0
, "File Entry", 0);
11774 /* Include directory index. */
11775 if (idx_form
!= DW_FORM_udata
)
11776 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11779 dw2_asm_output_data_uleb128 (0, NULL
);
11781 #ifdef VMS_DEBUGGING_INFO
11782 dw2_asm_output_data_uleb128 (0, NULL
);
11783 dw2_asm_output_data_uleb128 (0, NULL
);
11787 /* Now write all the file names. */
11788 for (i
= 0; i
< numfiles
; i
++)
11790 int file_idx
= backmap
[i
];
11791 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11793 #ifdef VMS_DEBUGGING_INFO
11794 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
11796 /* Setting these fields can lead to debugger miscomparisons,
11797 but VMS Debug requires them to be set correctly. */
11802 int maxfilelen
= (strlen (files
[file_idx
].path
)
11803 + dirs
[dir_idx
].length
11804 + MAX_VMS_VERSION_LEN
+ 1);
11805 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
11807 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
11808 snprintf (filebuf
, maxfilelen
, "%s;%d",
11809 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
11811 output_line_string (str_form
, filebuf
, "File Entry", (unsigned) i
+ 1);
11813 /* Include directory index. */
11814 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11815 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11816 dir_idx
+ idx_offset
, NULL
);
11818 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11820 /* Modification time. */
11821 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11822 &cdt
, 0, 0, 0) == 0)
11825 /* File length in bytes. */
11826 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11827 0, &siz
, 0, 0) == 0)
11830 output_line_string (str_form
,
11831 files
[file_idx
].path
+ dirs
[dir_idx
].length
,
11832 "File Entry", (unsigned) i
+ 1);
11834 /* Include directory index. */
11835 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11836 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11837 dir_idx
+ idx_offset
, NULL
);
11839 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11841 if (dwarf_version
>= 5)
11844 /* Modification time. */
11845 dw2_asm_output_data_uleb128 (0, NULL
);
11847 /* File length in bytes. */
11848 dw2_asm_output_data_uleb128 (0, NULL
);
11849 #endif /* VMS_DEBUGGING_INFO */
11852 if (dwarf_version
< 5)
11853 dw2_asm_output_data (1, 0, "End file name table");
11857 /* Output one line number table into the .debug_line section. */
11860 output_one_line_info_table (dw_line_info_table
*table
)
11862 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11863 unsigned int current_line
= 1;
11864 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
11865 dw_line_info_entry
*ent
;
11868 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
11870 switch (ent
->opcode
)
11872 case LI_set_address
:
11873 /* ??? Unfortunately, we have little choice here currently, and
11874 must always use the most general form. GCC does not know the
11875 address delta itself, so we can't use DW_LNS_advance_pc. Many
11876 ports do have length attributes which will give an upper bound
11877 on the address range. We could perhaps use length attributes
11878 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
11879 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
11881 /* This can handle any delta. This takes
11882 4+DWARF2_ADDR_SIZE bytes. */
11883 dw2_asm_output_data (1, 0, "set address %s", line_label
);
11884 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11885 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11886 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
11890 if (ent
->val
== current_line
)
11892 /* We still need to start a new row, so output a copy insn. */
11893 dw2_asm_output_data (1, DW_LNS_copy
,
11894 "copy line %u", current_line
);
11898 int line_offset
= ent
->val
- current_line
;
11899 int line_delta
= line_offset
- DWARF_LINE_BASE
;
11901 current_line
= ent
->val
;
11902 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
11904 /* This can handle deltas from -10 to 234, using the current
11905 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
11906 This takes 1 byte. */
11907 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
11908 "line %u", current_line
);
11912 /* This can handle any delta. This takes at least 4 bytes,
11913 depending on the value being encoded. */
11914 dw2_asm_output_data (1, DW_LNS_advance_line
,
11915 "advance to line %u", current_line
);
11916 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
11917 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
11923 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
11924 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11927 case LI_set_column
:
11928 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
11929 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11932 case LI_negate_stmt
:
11933 current_is_stmt
= !current_is_stmt
;
11934 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
11935 "is_stmt %d", current_is_stmt
);
11938 case LI_set_prologue_end
:
11939 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
11940 "set prologue end");
11943 case LI_set_epilogue_begin
:
11944 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
11945 "set epilogue begin");
11948 case LI_set_discriminator
:
11949 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
11950 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
11951 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
11952 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
11957 /* Emit debug info for the address of the end of the table. */
11958 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
11959 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11960 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11961 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
11963 dw2_asm_output_data (1, 0, "end sequence");
11964 dw2_asm_output_data_uleb128 (1, NULL
);
11965 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
11968 /* Output the source line number correspondence information. This
11969 information goes into the .debug_line section. */
11972 output_line_info (bool prologue_only
)
11974 static unsigned int generation
;
11975 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11976 char p1
[MAX_ARTIFICIAL_LABEL_BYTES
], p2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11977 bool saw_one
= false;
11980 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, generation
);
11981 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, generation
);
11982 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, generation
);
11983 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, generation
++);
11985 if (!XCOFF_DEBUGGING_INFO
)
11987 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11988 dw2_asm_output_data (4, 0xffffffff,
11989 "Initial length escape value indicating 64-bit DWARF extension");
11990 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11991 "Length of Source Line Info");
11994 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11996 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11997 if (dwarf_version
>= 5)
11999 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
12000 dw2_asm_output_data (1, 0, "Segment Size");
12002 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
12003 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
12005 /* Define the architecture-dependent minimum instruction length (in bytes).
12006 In this implementation of DWARF, this field is used for information
12007 purposes only. Since GCC generates assembly language, we have no
12008 a priori knowledge of how many instruction bytes are generated for each
12009 source line, and therefore can use only the DW_LNE_set_address and
12010 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
12011 this as '1', which is "correct enough" for all architectures,
12012 and don't let the target override. */
12013 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
12015 if (dwarf_version
>= 4)
12016 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
12017 "Maximum Operations Per Instruction");
12018 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
12019 "Default is_stmt_start flag");
12020 dw2_asm_output_data (1, DWARF_LINE_BASE
,
12021 "Line Base Value (Special Opcodes)");
12022 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
12023 "Line Range Value (Special Opcodes)");
12024 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
12025 "Special Opcode Base");
12027 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
12032 case DW_LNS_advance_pc
:
12033 case DW_LNS_advance_line
:
12034 case DW_LNS_set_file
:
12035 case DW_LNS_set_column
:
12036 case DW_LNS_fixed_advance_pc
:
12037 case DW_LNS_set_isa
:
12045 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
12049 /* Write out the information about the files we use. */
12050 output_file_names ();
12051 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
12054 /* Output the marker for the end of the line number info. */
12055 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12059 if (separate_line_info
)
12061 dw_line_info_table
*table
;
12064 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
12067 output_one_line_info_table (table
);
12071 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
12073 output_one_line_info_table (cold_text_section_line_info
);
12077 /* ??? Some Darwin linkers crash on a .debug_line section with no
12078 sequences. Further, merely a DW_LNE_end_sequence entry is not
12079 sufficient -- the address column must also be initialized.
12080 Make sure to output at least one set_address/end_sequence pair,
12081 choosing .text since that section is always present. */
12082 if (text_section_line_info
->in_use
|| !saw_one
)
12083 output_one_line_info_table (text_section_line_info
);
12085 /* Output the marker for the end of the line number info. */
12086 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12089 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
12092 need_endianity_attribute_p (bool reverse
)
12094 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
12097 /* Given a pointer to a tree node for some base type, return a pointer to
12098 a DIE that describes the given type. REVERSE is true if the type is
12099 to be interpreted in the reverse storage order wrt the target order.
12101 This routine must only be called for GCC type nodes that correspond to
12102 Dwarf base (fundamental) types. */
12105 base_type_die (tree type
, bool reverse
)
12107 dw_die_ref base_type_result
;
12108 enum dwarf_type encoding
;
12109 bool fpt_used
= false;
12110 struct fixed_point_type_info fpt_info
;
12111 tree type_bias
= NULL_TREE
;
12113 /* If this is a subtype that should not be emitted as a subrange type,
12114 use the base type. See subrange_type_for_debug_p. */
12115 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
12116 type
= TREE_TYPE (type
);
12118 switch (TREE_CODE (type
))
12121 if ((dwarf_version
>= 4 || !dwarf_strict
)
12122 && TYPE_NAME (type
)
12123 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12124 && DECL_IS_BUILTIN (TYPE_NAME (type
))
12125 && DECL_NAME (TYPE_NAME (type
)))
12127 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
12128 if (strcmp (name
, "char16_t") == 0
12129 || strcmp (name
, "char32_t") == 0)
12131 encoding
= DW_ATE_UTF
;
12135 if ((dwarf_version
>= 3 || !dwarf_strict
)
12136 && lang_hooks
.types
.get_fixed_point_type_info
)
12138 memset (&fpt_info
, 0, sizeof (fpt_info
));
12139 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
12142 encoding
= ((TYPE_UNSIGNED (type
))
12143 ? DW_ATE_unsigned_fixed
12144 : DW_ATE_signed_fixed
);
12148 if (TYPE_STRING_FLAG (type
))
12150 if (TYPE_UNSIGNED (type
))
12151 encoding
= DW_ATE_unsigned_char
;
12153 encoding
= DW_ATE_signed_char
;
12155 else if (TYPE_UNSIGNED (type
))
12156 encoding
= DW_ATE_unsigned
;
12158 encoding
= DW_ATE_signed
;
12161 && lang_hooks
.types
.get_type_bias
)
12162 type_bias
= lang_hooks
.types
.get_type_bias (type
);
12166 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
12168 if (dwarf_version
>= 3 || !dwarf_strict
)
12169 encoding
= DW_ATE_decimal_float
;
12171 encoding
= DW_ATE_lo_user
;
12174 encoding
= DW_ATE_float
;
12177 case FIXED_POINT_TYPE
:
12178 if (!(dwarf_version
>= 3 || !dwarf_strict
))
12179 encoding
= DW_ATE_lo_user
;
12180 else if (TYPE_UNSIGNED (type
))
12181 encoding
= DW_ATE_unsigned_fixed
;
12183 encoding
= DW_ATE_signed_fixed
;
12186 /* Dwarf2 doesn't know anything about complex ints, so use
12187 a user defined type for it. */
12189 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
12190 encoding
= DW_ATE_complex_float
;
12192 encoding
= DW_ATE_lo_user
;
12196 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12197 encoding
= DW_ATE_boolean
;
12201 /* No other TREE_CODEs are Dwarf fundamental types. */
12202 gcc_unreachable ();
12205 base_type_result
= new_die_raw (DW_TAG_base_type
);
12207 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
12208 int_size_in_bytes (type
));
12209 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
12211 if (need_endianity_attribute_p (reverse
))
12212 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
12213 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
12215 add_alignment_attribute (base_type_result
, type
);
12219 switch (fpt_info
.scale_factor_kind
)
12221 case fixed_point_scale_factor_binary
:
12222 add_AT_int (base_type_result
, DW_AT_binary_scale
,
12223 fpt_info
.scale_factor
.binary
);
12226 case fixed_point_scale_factor_decimal
:
12227 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
12228 fpt_info
.scale_factor
.decimal
);
12231 case fixed_point_scale_factor_arbitrary
:
12232 /* Arbitrary scale factors cannot be described in standard DWARF,
12236 /* Describe the scale factor as a rational constant. */
12237 const dw_die_ref scale_factor
12238 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
12240 add_AT_unsigned (scale_factor
, DW_AT_GNU_numerator
,
12241 fpt_info
.scale_factor
.arbitrary
.numerator
);
12242 add_AT_int (scale_factor
, DW_AT_GNU_denominator
,
12243 fpt_info
.scale_factor
.arbitrary
.denominator
);
12245 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
12250 gcc_unreachable ();
12255 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
12256 dw_scalar_form_constant
12257 | dw_scalar_form_exprloc
12258 | dw_scalar_form_reference
,
12261 return base_type_result
;
12264 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
12265 named 'auto' in its type: return true for it, false otherwise. */
12268 is_cxx_auto (tree type
)
12272 tree name
= TYPE_IDENTIFIER (type
);
12273 if (name
== get_identifier ("auto")
12274 || name
== get_identifier ("decltype(auto)"))
12280 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12281 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12284 is_base_type (tree type
)
12286 switch (TREE_CODE (type
))
12290 case FIXED_POINT_TYPE
:
12293 case POINTER_BOUNDS_TYPE
:
12300 case QUAL_UNION_TYPE
:
12301 case ENUMERAL_TYPE
:
12302 case FUNCTION_TYPE
:
12305 case REFERENCE_TYPE
:
12313 if (is_cxx_auto (type
))
12315 gcc_unreachable ();
12321 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12322 node, return the size in bits for the type if it is a constant, or else
12323 return the alignment for the type if the type's size is not constant, or
12324 else return BITS_PER_WORD if the type actually turns out to be an
12325 ERROR_MARK node. */
12327 static inline unsigned HOST_WIDE_INT
12328 simple_type_size_in_bits (const_tree type
)
12330 if (TREE_CODE (type
) == ERROR_MARK
)
12331 return BITS_PER_WORD
;
12332 else if (TYPE_SIZE (type
) == NULL_TREE
)
12334 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
12335 return tree_to_uhwi (TYPE_SIZE (type
));
12337 return TYPE_ALIGN (type
);
12340 /* Similarly, but return an offset_int instead of UHWI. */
12342 static inline offset_int
12343 offset_int_type_size_in_bits (const_tree type
)
12345 if (TREE_CODE (type
) == ERROR_MARK
)
12346 return BITS_PER_WORD
;
12347 else if (TYPE_SIZE (type
) == NULL_TREE
)
12349 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
12350 return wi::to_offset (TYPE_SIZE (type
));
12352 return TYPE_ALIGN (type
);
12355 /* Given a pointer to a tree node for a subrange type, return a pointer
12356 to a DIE that describes the given type. */
12359 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
12360 dw_die_ref context_die
)
12362 dw_die_ref subrange_die
;
12363 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
12365 if (context_die
== NULL
)
12366 context_die
= comp_unit_die ();
12368 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
12370 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
12372 /* The size of the subrange type and its base type do not match,
12373 so we need to generate a size attribute for the subrange type. */
12374 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
12377 add_alignment_attribute (subrange_die
, type
);
12380 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
12382 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
12383 if (bias
&& !dwarf_strict
)
12384 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
12385 dw_scalar_form_constant
12386 | dw_scalar_form_exprloc
12387 | dw_scalar_form_reference
,
12390 return subrange_die
;
12393 /* Returns the (const and/or volatile) cv_qualifiers associated with
12394 the decl node. This will normally be augmented with the
12395 cv_qualifiers of the underlying type in add_type_attribute. */
12398 decl_quals (const_tree decl
)
12400 return ((TREE_READONLY (decl
)
12401 /* The C++ front-end correctly marks reference-typed
12402 variables as readonly, but from a language (and debug
12403 info) standpoint they are not const-qualified. */
12404 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
12405 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
12406 | (TREE_THIS_VOLATILE (decl
)
12407 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
12410 /* Determine the TYPE whose qualifiers match the largest strict subset
12411 of the given TYPE_QUALS, and return its qualifiers. Ignore all
12412 qualifiers outside QUAL_MASK. */
12415 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
12418 int best_rank
= 0, best_qual
= 0, max_rank
;
12420 type_quals
&= qual_mask
;
12421 max_rank
= popcount_hwi (type_quals
) - 1;
12423 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
12424 t
= TYPE_NEXT_VARIANT (t
))
12426 int q
= TYPE_QUALS (t
) & qual_mask
;
12428 if ((q
& type_quals
) == q
&& q
!= type_quals
12429 && check_base_type (t
, type
))
12431 int rank
= popcount_hwi (q
);
12433 if (rank
> best_rank
)
12444 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
12445 static const dwarf_qual_info_t dwarf_qual_info
[] =
12447 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
12448 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
12449 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
12450 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
12452 static const unsigned int dwarf_qual_info_size
12453 = sizeof (dwarf_qual_info
) / sizeof (dwarf_qual_info
[0]);
12455 /* If DIE is a qualified DIE of some base DIE with the same parent,
12456 return the base DIE, otherwise return NULL. Set MASK to the
12457 qualifiers added compared to the returned DIE. */
12460 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
12463 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12464 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
12466 if (i
== dwarf_qual_info_size
)
12468 if (vec_safe_length (die
->die_attr
) != 1)
12470 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
12471 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
12473 *mask
|= dwarf_qual_info
[i
].q
;
12476 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
12483 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12484 entry that chains the modifiers specified by CV_QUALS in front of the
12485 given type. REVERSE is true if the type is to be interpreted in the
12486 reverse storage order wrt the target order. */
12489 modified_type_die (tree type
, int cv_quals
, bool reverse
,
12490 dw_die_ref context_die
)
12492 enum tree_code code
= TREE_CODE (type
);
12493 dw_die_ref mod_type_die
;
12494 dw_die_ref sub_die
= NULL
;
12495 tree item_type
= NULL
;
12496 tree qualified_type
;
12497 tree name
, low
, high
;
12498 dw_die_ref mod_scope
;
12499 /* Only these cv-qualifiers are currently handled. */
12500 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
12501 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
|
12502 ENCODE_QUAL_ADDR_SPACE(~0U));
12503 const bool reverse_base_type
12504 = need_endianity_attribute_p (reverse
) && is_base_type (type
);
12506 if (code
== ERROR_MARK
)
12509 if (lang_hooks
.types
.get_debug_type
)
12511 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
12513 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
12514 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
12517 cv_quals
&= cv_qual_mask
;
12519 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
12520 tag modifier (and not an attribute) old consumers won't be able
12522 if (dwarf_version
< 3)
12523 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
12525 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
12526 if (dwarf_version
< 5)
12527 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
12529 /* See if we already have the appropriately qualified variant of
12531 qualified_type
= get_qualified_type (type
, cv_quals
);
12533 if (qualified_type
== sizetype
)
12535 /* Try not to expose the internal sizetype type's name. */
12536 if (TYPE_NAME (qualified_type
)
12537 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
12539 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
12541 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
12542 && (TYPE_PRECISION (t
)
12543 == TYPE_PRECISION (qualified_type
))
12544 && (TYPE_UNSIGNED (t
)
12545 == TYPE_UNSIGNED (qualified_type
)));
12546 qualified_type
= t
;
12548 else if (qualified_type
== sizetype
12549 && TREE_CODE (sizetype
) == TREE_CODE (size_type_node
)
12550 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (size_type_node
)
12551 && TYPE_UNSIGNED (sizetype
) == TYPE_UNSIGNED (size_type_node
))
12552 qualified_type
= size_type_node
;
12555 /* If we do, then we can just use its DIE, if it exists. */
12556 if (qualified_type
)
12558 mod_type_die
= lookup_type_die (qualified_type
);
12560 /* DW_AT_endianity doesn't come from a qualifier on the type, so it is
12561 dealt with specially: the DIE with the attribute, if it exists, is
12562 placed immediately after the regular DIE for the same base type. */
12564 && (!reverse_base_type
12565 || ((mod_type_die
= mod_type_die
->die_sib
) != NULL
12566 && get_AT_unsigned (mod_type_die
, DW_AT_endianity
))))
12567 return mod_type_die
;
12570 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
12572 /* Handle C typedef types. */
12574 && TREE_CODE (name
) == TYPE_DECL
12575 && DECL_ORIGINAL_TYPE (name
)
12576 && !DECL_ARTIFICIAL (name
))
12578 tree dtype
= TREE_TYPE (name
);
12580 /* Skip the typedef for base types with DW_AT_endianity, no big deal. */
12581 if (qualified_type
== dtype
&& !reverse_base_type
)
12583 tree origin
= decl_ultimate_origin (name
);
12585 /* Typedef variants that have an abstract origin don't get their own
12586 type DIE (see gen_typedef_die), so fall back on the ultimate
12587 abstract origin instead. */
12588 if (origin
!= NULL
&& origin
!= name
)
12589 return modified_type_die (TREE_TYPE (origin
), cv_quals
, reverse
,
12592 /* For a named type, use the typedef. */
12593 gen_type_die (qualified_type
, context_die
);
12594 return lookup_type_die (qualified_type
);
12598 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
12599 dquals
&= cv_qual_mask
;
12600 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
12601 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
12602 /* cv-unqualified version of named type. Just use
12603 the unnamed type to which it refers. */
12604 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
12605 reverse
, context_die
);
12606 /* Else cv-qualified version of named type; fall through. */
12610 mod_scope
= scope_die_for (type
, context_die
);
12614 int sub_quals
= 0, first_quals
= 0;
12616 dw_die_ref first
= NULL
, last
= NULL
;
12618 /* Determine a lesser qualified type that most closely matches
12619 this one. Then generate DW_TAG_* entries for the remaining
12621 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
12623 if (sub_quals
&& use_debug_types
)
12625 bool needed
= false;
12626 /* If emitting type units, make sure the order of qualifiers
12627 is canonical. Thus, start from unqualified type if
12628 an earlier qualifier is missing in sub_quals, but some later
12629 one is present there. */
12630 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12631 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12633 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
12639 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
12640 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
12642 /* As not all intermediate qualified DIEs have corresponding
12643 tree types, ensure that qualified DIEs in the same scope
12644 as their DW_AT_type are emitted after their DW_AT_type,
12645 only with other qualified DIEs for the same type possibly
12646 in between them. Determine the range of such qualified
12647 DIEs now (first being the base type, last being corresponding
12648 last qualified DIE for it). */
12649 unsigned int count
= 0;
12650 first
= qualified_die_p (mod_type_die
, &first_quals
,
12651 dwarf_qual_info_size
);
12653 first
= mod_type_die
;
12654 gcc_assert ((first_quals
& ~sub_quals
) == 0);
12655 for (count
= 0, last
= first
;
12656 count
< (1U << dwarf_qual_info_size
);
12657 count
++, last
= last
->die_sib
)
12660 if (last
== mod_scope
->die_child
)
12662 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
12668 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12669 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12672 if (first
&& first
!= last
)
12674 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
12677 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
12678 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
12694 d
= new_die_raw (dwarf_qual_info
[i
].t
);
12695 add_child_die_after (mod_scope
, d
, last
);
12699 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
12701 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
12703 first_quals
|= dwarf_qual_info
[i
].q
;
12706 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
12708 dwarf_tag tag
= DW_TAG_pointer_type
;
12709 if (code
== REFERENCE_TYPE
)
12711 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
12712 tag
= DW_TAG_rvalue_reference_type
;
12714 tag
= DW_TAG_reference_type
;
12716 mod_type_die
= new_die (tag
, mod_scope
, type
);
12718 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12719 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12720 add_alignment_attribute (mod_type_die
, type
);
12721 item_type
= TREE_TYPE (type
);
12723 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
12724 if (!ADDR_SPACE_GENERIC_P (as
))
12726 int action
= targetm
.addr_space
.debug (as
);
12729 /* Positive values indicate an address_class. */
12730 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
12734 /* Negative values indicate an (inverted) segment base reg. */
12736 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
12737 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
12741 else if (code
== INTEGER_TYPE
12742 && TREE_TYPE (type
) != NULL_TREE
12743 && subrange_type_for_debug_p (type
, &low
, &high
))
12745 tree bias
= NULL_TREE
;
12746 if (lang_hooks
.types
.get_type_bias
)
12747 bias
= lang_hooks
.types
.get_type_bias (type
);
12748 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
12749 item_type
= TREE_TYPE (type
);
12751 else if (is_base_type (type
))
12753 mod_type_die
= base_type_die (type
, reverse
);
12755 /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
12756 if (reverse_base_type
)
12758 dw_die_ref after_die
12759 = modified_type_die (type
, cv_quals
, false, context_die
);
12760 add_child_die_after (comp_unit_die (), mod_type_die
, after_die
);
12763 add_child_die (comp_unit_die (), mod_type_die
);
12765 add_pubtype (type
, mod_type_die
);
12769 gen_type_die (type
, context_die
);
12771 /* We have to get the type_main_variant here (and pass that to the
12772 `lookup_type_die' routine) because the ..._TYPE node we have
12773 might simply be a *copy* of some original type node (where the
12774 copy was created to help us keep track of typedef names) and
12775 that copy might have a different TYPE_UID from the original
12777 if (TREE_CODE (type
) == FUNCTION_TYPE
12778 || TREE_CODE (type
) == METHOD_TYPE
)
12780 /* For function/method types, can't just use type_main_variant here,
12781 because that can have different ref-qualifiers for C++,
12782 but try to canonicalize. */
12783 tree main
= TYPE_MAIN_VARIANT (type
);
12784 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
12785 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
12786 && check_base_type (t
, main
)
12787 && check_lang_type (t
, type
))
12788 return lookup_type_die (t
);
12789 return lookup_type_die (type
);
12791 else if (TREE_CODE (type
) != VECTOR_TYPE
12792 && TREE_CODE (type
) != ARRAY_TYPE
)
12793 return lookup_type_die (type_main_variant (type
));
12795 /* Vectors have the debugging information in the type,
12796 not the main variant. */
12797 return lookup_type_die (type
);
12800 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12801 don't output a DW_TAG_typedef, since there isn't one in the
12802 user's program; just attach a DW_AT_name to the type.
12803 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12804 if the base type already has the same name. */
12806 && ((TREE_CODE (name
) != TYPE_DECL
12807 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
12808 || (cv_quals
== TYPE_UNQUALIFIED
)))
12809 || (TREE_CODE (name
) == TYPE_DECL
12810 && TREE_TYPE (name
) == qualified_type
12811 && DECL_NAME (name
))))
12813 if (TREE_CODE (name
) == TYPE_DECL
)
12814 /* Could just call add_name_and_src_coords_attributes here,
12815 but since this is a builtin type it doesn't have any
12816 useful source coordinates anyway. */
12817 name
= DECL_NAME (name
);
12818 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
12820 /* This probably indicates a bug. */
12821 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
12823 name
= TYPE_IDENTIFIER (type
);
12824 add_name_attribute (mod_type_die
,
12825 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
12828 if (qualified_type
&& !reverse_base_type
)
12829 equate_type_number_to_die (qualified_type
, mod_type_die
);
12832 /* We must do this after the equate_type_number_to_die call, in case
12833 this is a recursive type. This ensures that the modified_type_die
12834 recursion will terminate even if the type is recursive. Recursive
12835 types are possible in Ada. */
12836 sub_die
= modified_type_die (item_type
,
12837 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
12841 if (sub_die
!= NULL
)
12842 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
12844 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
12845 if (TYPE_ARTIFICIAL (type
))
12846 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
12848 return mod_type_die
;
12851 /* Generate DIEs for the generic parameters of T.
12852 T must be either a generic type or a generic function.
12853 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12856 gen_generic_params_dies (tree t
)
12860 dw_die_ref die
= NULL
;
12863 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
12867 die
= lookup_type_die (t
);
12868 else if (DECL_P (t
))
12869 die
= lookup_decl_die (t
);
12873 parms
= lang_hooks
.get_innermost_generic_parms (t
);
12875 /* T has no generic parameter. It means T is neither a generic type
12876 or function. End of story. */
12879 parms_num
= TREE_VEC_LENGTH (parms
);
12880 args
= lang_hooks
.get_innermost_generic_args (t
);
12881 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
12882 non_default
= int_cst_value (TREE_CHAIN (args
));
12884 non_default
= TREE_VEC_LENGTH (args
);
12885 for (i
= 0; i
< parms_num
; i
++)
12887 tree parm
, arg
, arg_pack_elems
;
12888 dw_die_ref parm_die
;
12890 parm
= TREE_VEC_ELT (parms
, i
);
12891 arg
= TREE_VEC_ELT (args
, i
);
12892 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
12893 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
12895 if (parm
&& TREE_VALUE (parm
) && arg
)
12897 /* If PARM represents a template parameter pack,
12898 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12899 by DW_TAG_template_*_parameter DIEs for the argument
12900 pack elements of ARG. Note that ARG would then be
12901 an argument pack. */
12902 if (arg_pack_elems
)
12903 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
12907 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
12908 true /* emit name */, die
);
12909 if (i
>= non_default
)
12910 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
12915 /* Create and return a DIE for PARM which should be
12916 the representation of a generic type parameter.
12917 For instance, in the C++ front end, PARM would be a template parameter.
12918 ARG is the argument to PARM.
12919 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12921 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12922 as a child node. */
12925 generic_parameter_die (tree parm
, tree arg
,
12927 dw_die_ref parent_die
)
12929 dw_die_ref tmpl_die
= NULL
;
12930 const char *name
= NULL
;
12932 if (!parm
|| !DECL_NAME (parm
) || !arg
)
12935 /* We support non-type generic parameters and arguments,
12936 type generic parameters and arguments, as well as
12937 generic generic parameters (a.k.a. template template parameters in C++)
12939 if (TREE_CODE (parm
) == PARM_DECL
)
12940 /* PARM is a nontype generic parameter */
12941 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
12942 else if (TREE_CODE (parm
) == TYPE_DECL
)
12943 /* PARM is a type generic parameter. */
12944 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
12945 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12946 /* PARM is a generic generic parameter.
12947 Its DIE is a GNU extension. It shall have a
12948 DW_AT_name attribute to represent the name of the template template
12949 parameter, and a DW_AT_GNU_template_name attribute to represent the
12950 name of the template template argument. */
12951 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
12954 gcc_unreachable ();
12960 /* If PARM is a generic parameter pack, it means we are
12961 emitting debug info for a template argument pack element.
12962 In other terms, ARG is a template argument pack element.
12963 In that case, we don't emit any DW_AT_name attribute for
12967 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
12969 add_AT_string (tmpl_die
, DW_AT_name
, name
);
12972 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12974 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
12975 TMPL_DIE should have a child DW_AT_type attribute that is set
12976 to the type of the argument to PARM, which is ARG.
12977 If PARM is a type generic parameter, TMPL_DIE should have a
12978 child DW_AT_type that is set to ARG. */
12979 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
12980 add_type_attribute (tmpl_die
, tmpl_type
,
12981 (TREE_THIS_VOLATILE (tmpl_type
)
12982 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
12983 false, parent_die
);
12987 /* So TMPL_DIE is a DIE representing a
12988 a generic generic template parameter, a.k.a template template
12989 parameter in C++ and arg is a template. */
12991 /* The DW_AT_GNU_template_name attribute of the DIE must be set
12992 to the name of the argument. */
12993 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
12995 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
12998 if (TREE_CODE (parm
) == PARM_DECL
)
12999 /* So PARM is a non-type generic parameter.
13000 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13001 attribute of TMPL_DIE which value represents the value
13003 We must be careful here:
13004 The value of ARG might reference some function decls.
13005 We might currently be emitting debug info for a generic
13006 type and types are emitted before function decls, we don't
13007 know if the function decls referenced by ARG will actually be
13008 emitted after cgraph computations.
13009 So must defer the generation of the DW_AT_const_value to
13010 after cgraph is ready. */
13011 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
13017 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13018 PARM_PACK must be a template parameter pack. The returned DIE
13019 will be child DIE of PARENT_DIE. */
13022 template_parameter_pack_die (tree parm_pack
,
13023 tree parm_pack_args
,
13024 dw_die_ref parent_die
)
13029 gcc_assert (parent_die
&& parm_pack
);
13031 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
13032 add_name_and_src_coords_attributes (die
, parm_pack
);
13033 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
13034 generic_parameter_die (parm_pack
,
13035 TREE_VEC_ELT (parm_pack_args
, j
),
13036 false /* Don't emit DW_AT_name */,
13041 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13042 an enumerated type. */
13045 type_is_enum (const_tree type
)
13047 return TREE_CODE (type
) == ENUMERAL_TYPE
;
13050 /* Return the DBX register number described by a given RTL node. */
13052 static unsigned int
13053 dbx_reg_number (const_rtx rtl
)
13055 unsigned regno
= REGNO (rtl
);
13057 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
13059 #ifdef LEAF_REG_REMAP
13060 if (crtl
->uses_only_leaf_regs
)
13062 int leaf_reg
= LEAF_REG_REMAP (regno
);
13063 if (leaf_reg
!= -1)
13064 regno
= (unsigned) leaf_reg
;
13068 regno
= DBX_REGISTER_NUMBER (regno
);
13069 gcc_assert (regno
!= INVALID_REGNUM
);
13073 /* Optionally add a DW_OP_piece term to a location description expression.
13074 DW_OP_piece is only added if the location description expression already
13075 doesn't end with DW_OP_piece. */
13078 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
13080 dw_loc_descr_ref loc
;
13082 if (*list_head
!= NULL
)
13084 /* Find the end of the chain. */
13085 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
13088 if (loc
->dw_loc_opc
!= DW_OP_piece
)
13089 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
13093 /* Return a location descriptor that designates a machine register or
13094 zero if there is none. */
13096 static dw_loc_descr_ref
13097 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
13101 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
13104 /* We only use "frame base" when we're sure we're talking about the
13105 post-prologue local stack frame. We do this by *not* running
13106 register elimination until this point, and recognizing the special
13107 argument pointer and soft frame pointer rtx's.
13108 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13109 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
13110 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
13112 dw_loc_descr_ref result
= NULL
;
13114 if (dwarf_version
>= 4 || !dwarf_strict
)
13116 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
13119 add_loc_descr (&result
,
13120 new_loc_descr (DW_OP_stack_value
, 0, 0));
13125 regs
= targetm
.dwarf_register_span (rtl
);
13127 if (REG_NREGS (rtl
) > 1 || regs
)
13128 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
13131 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
13132 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
13134 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
13138 /* Return a location descriptor that designates a machine register for
13139 a given hard register number. */
13141 static dw_loc_descr_ref
13142 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
13144 dw_loc_descr_ref reg_loc_descr
;
13148 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
13150 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
13152 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13153 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13155 return reg_loc_descr
;
13158 /* Given an RTL of a register, return a location descriptor that
13159 designates a value that spans more than one register. */
13161 static dw_loc_descr_ref
13162 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
13163 enum var_init_status initialized
)
13166 dw_loc_descr_ref loc_result
= NULL
;
13168 /* Simple, contiguous registers. */
13169 if (regs
== NULL_RTX
)
13171 unsigned reg
= REGNO (rtl
);
13174 #ifdef LEAF_REG_REMAP
13175 if (crtl
->uses_only_leaf_regs
)
13177 int leaf_reg
= LEAF_REG_REMAP (reg
);
13178 if (leaf_reg
!= -1)
13179 reg
= (unsigned) leaf_reg
;
13183 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
13184 nregs
= REG_NREGS (rtl
);
13186 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
13191 dw_loc_descr_ref t
;
13193 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
13194 VAR_INIT_STATUS_INITIALIZED
);
13195 add_loc_descr (&loc_result
, t
);
13196 add_loc_descr_op_piece (&loc_result
, size
);
13202 /* Now onto stupid register sets in non contiguous locations. */
13204 gcc_assert (GET_CODE (regs
) == PARALLEL
);
13206 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13209 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
13211 dw_loc_descr_ref t
;
13213 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
13214 VAR_INIT_STATUS_INITIALIZED
);
13215 add_loc_descr (&loc_result
, t
);
13216 add_loc_descr_op_piece (&loc_result
, size
);
13219 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13220 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13224 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
13226 /* Return a location descriptor that designates a constant i,
13227 as a compound operation from constant (i >> shift), constant shift
13230 static dw_loc_descr_ref
13231 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13233 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
13234 add_loc_descr (&ret
, int_loc_descriptor (shift
));
13235 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13239 /* Return a location descriptor that designates constant POLY_I. */
13241 static dw_loc_descr_ref
13242 int_loc_descriptor (poly_int64 poly_i
)
13244 enum dwarf_location_atom op
;
13247 if (!poly_i
.is_constant (&i
))
13249 /* Create location descriptions for the non-constant part and
13250 add any constant offset at the end. */
13251 dw_loc_descr_ref ret
= NULL
;
13252 HOST_WIDE_INT constant
= poly_i
.coeffs
[0];
13253 for (unsigned int j
= 1; j
< NUM_POLY_INT_COEFFS
; ++j
)
13255 HOST_WIDE_INT coeff
= poly_i
.coeffs
[j
];
13258 dw_loc_descr_ref start
= ret
;
13259 unsigned int factor
;
13261 unsigned int regno
= targetm
.dwarf_poly_indeterminate_value
13262 (j
, &factor
, &bias
);
13264 /* Add COEFF * ((REGNO / FACTOR) - BIAS) to the value:
13265 add COEFF * (REGNO / FACTOR) now and subtract
13266 COEFF * BIAS from the final constant part. */
13267 constant
-= coeff
* bias
;
13268 add_loc_descr (&ret
, new_reg_loc_descr (regno
, 0));
13269 if (coeff
% factor
== 0)
13273 int amount
= exact_log2 (factor
);
13274 gcc_assert (amount
>= 0);
13275 add_loc_descr (&ret
, int_loc_descriptor (amount
));
13276 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
13280 add_loc_descr (&ret
, int_loc_descriptor (coeff
));
13281 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13284 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
13287 loc_descr_plus_const (&ret
, constant
);
13291 /* Pick the smallest representation of a constant, rather than just
13292 defaulting to the LEB encoding. */
13295 int clz
= clz_hwi (i
);
13296 int ctz
= ctz_hwi (i
);
13298 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
13299 else if (i
<= 0xff)
13300 op
= DW_OP_const1u
;
13301 else if (i
<= 0xffff)
13302 op
= DW_OP_const2u
;
13303 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13304 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13305 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
13306 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
13307 while DW_OP_const4u is 5 bytes. */
13308 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
13309 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13310 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13311 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
13312 while DW_OP_const4u is 5 bytes. */
13313 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13315 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13316 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13319 /* As i >= 2**31, the double cast above will yield a negative number.
13320 Since wrapping is defined in DWARF expressions we can output big
13321 positive integers as small negative ones, regardless of the size
13324 Here, since the evaluator will handle 32-bit values and since i >=
13325 2**31, we know it's going to be interpreted as a negative literal:
13326 store it this way if we can do better than 5 bytes this way. */
13327 return int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13329 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13330 op
= DW_OP_const4u
;
13332 /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
13333 least 6 bytes: see if we can do better before falling back to it. */
13334 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13335 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13336 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
13337 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13338 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13339 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
13340 >= HOST_BITS_PER_WIDE_INT
)
13341 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
13342 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
13343 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
13344 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13345 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13346 && size_of_uleb128 (i
) > 6)
13347 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
13348 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
13355 op
= DW_OP_const1s
;
13356 else if (i
>= -0x8000)
13357 op
= DW_OP_const2s
;
13358 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13360 if (size_of_int_loc_descriptor (i
) < 5)
13362 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13363 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13366 op
= DW_OP_const4s
;
13370 if (size_of_int_loc_descriptor (i
)
13371 < (unsigned long) 1 + size_of_sleb128 (i
))
13373 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13374 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13381 return new_loc_descr (op
, i
, 0);
13384 /* Likewise, for unsigned constants. */
13386 static dw_loc_descr_ref
13387 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
13389 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
13390 const unsigned HOST_WIDE_INT max_uint
13391 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
13393 /* If possible, use the clever signed constants handling. */
13395 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
13397 /* Here, we are left with positive numbers that cannot be represented as
13398 HOST_WIDE_INT, i.e.:
13399 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
13401 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
13402 whereas may be better to output a negative integer: thanks to integer
13403 wrapping, we know that:
13404 x = x - 2 ** DWARF2_ADDR_SIZE
13405 = x - 2 * (max (HOST_WIDE_INT) + 1)
13406 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
13407 small negative integers. Let's try that in cases it will clearly improve
13408 the encoding: there is no gain turning DW_OP_const4u into
13410 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
13411 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
13412 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
13414 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
13416 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
13417 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
13418 const HOST_WIDE_INT second_shift
13419 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
13421 /* So we finally have:
13422 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
13423 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
13424 return int_loc_descriptor (second_shift
);
13427 /* Last chance: fallback to a simple constant operation. */
13428 return new_loc_descr
13429 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13435 /* Generate and return a location description that computes the unsigned
13436 comparison of the two stack top entries (a OP b where b is the top-most
13437 entry and a is the second one). The KIND of comparison can be LT_EXPR,
13438 LE_EXPR, GT_EXPR or GE_EXPR. */
13440 static dw_loc_descr_ref
13441 uint_comparison_loc_list (enum tree_code kind
)
13443 enum dwarf_location_atom op
, flip_op
;
13444 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
13461 gcc_unreachable ();
13464 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13465 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13467 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
13468 possible to perform unsigned comparisons: we just have to distinguish
13471 1. when a and b have the same sign (as signed integers); then we should
13472 return: a OP(signed) b;
13474 2. when a is a negative signed integer while b is a positive one, then a
13475 is a greater unsigned integer than b; likewise when a and b's roles
13478 So first, compare the sign of the two operands. */
13479 ret
= new_loc_descr (DW_OP_over
, 0, 0);
13480 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13481 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
13482 /* If they have different signs (i.e. they have different sign bits), then
13483 the stack top value has now the sign bit set and thus it's smaller than
13485 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
13486 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
13487 add_loc_descr (&ret
, bra_node
);
13489 /* We are in case 1. At this point, we know both operands have the same
13490 sign, to it's safe to use the built-in signed comparison. */
13491 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13492 add_loc_descr (&ret
, jmp_node
);
13494 /* We are in case 2. Here, we know both operands do not have the same sign,
13495 so we have to flip the signed comparison. */
13496 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
13497 tmp
= new_loc_descr (flip_op
, 0, 0);
13498 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13499 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13500 add_loc_descr (&ret
, tmp
);
13502 /* This dummy operation is necessary to make the two branches join. */
13503 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13504 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13505 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13506 add_loc_descr (&ret
, tmp
);
13511 /* Likewise, but takes the location description lists (might be destructive on
13512 them). Return NULL if either is NULL or if concatenation fails. */
13514 static dw_loc_list_ref
13515 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
13516 enum tree_code kind
)
13518 if (left
== NULL
|| right
== NULL
)
13521 add_loc_list (&left
, right
);
13525 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
13529 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
13530 without actually allocating it. */
13532 static unsigned long
13533 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13535 return size_of_int_loc_descriptor (i
>> shift
)
13536 + size_of_int_loc_descriptor (shift
)
13540 /* Return size_of_locs (int_loc_descriptor (i)) without
13541 actually allocating it. */
13543 static unsigned long
13544 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
13553 else if (i
<= 0xff)
13555 else if (i
<= 0xffff)
13559 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13560 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13561 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13563 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13564 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13565 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13567 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13568 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13570 return size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13571 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13573 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
13574 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13575 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13576 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13578 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13579 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
13580 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13582 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13583 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13585 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13594 else if (i
>= -0x8000)
13596 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13598 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13600 s
= size_of_int_loc_descriptor (-i
) + 1;
13608 unsigned long r
= 1 + size_of_sleb128 (i
);
13609 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13611 s
= size_of_int_loc_descriptor (-i
) + 1;
13620 /* Return loc description representing "address" of integer value.
13621 This can appear only as toplevel expression. */
13623 static dw_loc_descr_ref
13624 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
13627 dw_loc_descr_ref loc_result
= NULL
;
13629 if (!(dwarf_version
>= 4 || !dwarf_strict
))
13632 litsize
= size_of_int_loc_descriptor (i
);
13633 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13634 is more compact. For DW_OP_stack_value we need:
13635 litsize + 1 (DW_OP_stack_value)
13636 and for DW_OP_implicit_value:
13637 1 (DW_OP_implicit_value) + 1 (length) + size. */
13638 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
13640 loc_result
= int_loc_descriptor (i
);
13641 add_loc_descr (&loc_result
,
13642 new_loc_descr (DW_OP_stack_value
, 0, 0));
13646 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13648 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13649 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
13653 /* Return a location descriptor that designates a base+offset location. */
13655 static dw_loc_descr_ref
13656 based_loc_descr (rtx reg
, poly_int64 offset
,
13657 enum var_init_status initialized
)
13659 unsigned int regno
;
13660 dw_loc_descr_ref result
;
13661 dw_fde_ref fde
= cfun
->fde
;
13663 /* We only use "frame base" when we're sure we're talking about the
13664 post-prologue local stack frame. We do this by *not* running
13665 register elimination until this point, and recognizing the special
13666 argument pointer and soft frame pointer rtx's. */
13667 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
13669 rtx elim
= (ira_use_lra_p
13670 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
13671 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
13675 elim
= strip_offset_and_add (elim
, &offset
);
13676 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13677 && (elim
== hard_frame_pointer_rtx
13678 || elim
== stack_pointer_rtx
))
13679 || elim
== (frame_pointer_needed
13680 ? hard_frame_pointer_rtx
13681 : stack_pointer_rtx
));
13683 /* If drap register is used to align stack, use frame
13684 pointer + offset to access stack variables. If stack
13685 is aligned without drap, use stack pointer + offset to
13686 access stack variables. */
13687 if (crtl
->stack_realign_tried
13688 && reg
== frame_pointer_rtx
)
13691 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
13692 ? HARD_FRAME_POINTER_REGNUM
13694 return new_reg_loc_descr (base_reg
, offset
);
13697 gcc_assert (frame_pointer_fb_offset_valid
);
13698 offset
+= frame_pointer_fb_offset
;
13699 HOST_WIDE_INT const_offset
;
13700 if (offset
.is_constant (&const_offset
))
13701 return new_loc_descr (DW_OP_fbreg
, const_offset
, 0);
13704 dw_loc_descr_ref ret
= new_loc_descr (DW_OP_fbreg
, 0, 0);
13705 loc_descr_plus_const (&ret
, offset
);
13711 regno
= REGNO (reg
);
13712 #ifdef LEAF_REG_REMAP
13713 if (crtl
->uses_only_leaf_regs
)
13715 int leaf_reg
= LEAF_REG_REMAP (regno
);
13716 if (leaf_reg
!= -1)
13717 regno
= (unsigned) leaf_reg
;
13720 regno
= DWARF_FRAME_REGNUM (regno
);
13722 HOST_WIDE_INT const_offset
;
13723 if (!optimize
&& fde
13724 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
)
13725 && offset
.is_constant (&const_offset
))
13727 /* Use cfa+offset to represent the location of arguments passed
13728 on the stack when drap is used to align stack.
13729 Only do this when not optimizing, for optimized code var-tracking
13730 is supposed to track where the arguments live and the register
13731 used as vdrap or drap in some spot might be used for something
13732 else in other part of the routine. */
13733 return new_loc_descr (DW_OP_fbreg
, const_offset
, 0);
13736 result
= new_reg_loc_descr (regno
, offset
);
13738 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13739 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13744 /* Return true if this RTL expression describes a base+offset calculation. */
13747 is_based_loc (const_rtx rtl
)
13749 return (GET_CODE (rtl
) == PLUS
13750 && ((REG_P (XEXP (rtl
, 0))
13751 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
13752 && CONST_INT_P (XEXP (rtl
, 1)))));
13755 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13758 static dw_loc_descr_ref
13759 tls_mem_loc_descriptor (rtx mem
)
13762 dw_loc_descr_ref loc_result
;
13764 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
13767 base
= get_base_address (MEM_EXPR (mem
));
13770 || !DECL_THREAD_LOCAL_P (base
))
13773 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
13774 if (loc_result
== NULL
)
13777 if (maybe_ne (MEM_OFFSET (mem
), 0))
13778 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
13783 /* Output debug info about reason why we failed to expand expression as dwarf
13787 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
13789 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
13791 fprintf (dump_file
, "Failed to expand as dwarf: ");
13793 print_generic_expr (dump_file
, expr
, dump_flags
);
13796 fprintf (dump_file
, "\n");
13797 print_rtl (dump_file
, rtl
);
13799 fprintf (dump_file
, "\nReason: %s\n", reason
);
13803 /* Helper function for const_ok_for_output. */
13806 const_ok_for_output_1 (rtx rtl
)
13808 if (targetm
.const_not_ok_for_debug_p (rtl
))
13810 if (GET_CODE (rtl
) != UNSPEC
)
13812 expansion_failed (NULL_TREE
, rtl
,
13813 "Expression rejected for debug by the backend.\n");
13817 /* If delegitimize_address couldn't do anything with the UNSPEC, and
13818 the target hook doesn't explicitly allow it in debug info, assume
13819 we can't express it in the debug info. */
13820 /* Don't complain about TLS UNSPECs, those are just too hard to
13821 delegitimize. Note this could be a non-decl SYMBOL_REF such as
13822 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
13823 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
13825 && (XVECLEN (rtl
, 0) == 0
13826 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
13827 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
13828 inform (current_function_decl
13829 ? DECL_SOURCE_LOCATION (current_function_decl
)
13830 : UNKNOWN_LOCATION
,
13831 #if NUM_UNSPEC_VALUES > 0
13832 "non-delegitimized UNSPEC %s (%d) found in variable location",
13833 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
13834 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
13837 "non-delegitimized UNSPEC %d found in variable location",
13840 expansion_failed (NULL_TREE
, rtl
,
13841 "UNSPEC hasn't been delegitimized.\n");
13845 if (CONST_POLY_INT_P (rtl
))
13848 if (targetm
.const_not_ok_for_debug_p (rtl
))
13850 expansion_failed (NULL_TREE
, rtl
,
13851 "Expression rejected for debug by the backend.\n");
13855 /* FIXME: Refer to PR60655. It is possible for simplification
13856 of rtl expressions in var tracking to produce such expressions.
13857 We should really identify / validate expressions
13858 enclosed in CONST that can be handled by assemblers on various
13859 targets and only handle legitimate cases here. */
13860 switch (GET_CODE (rtl
))
13871 if (CONSTANT_POOL_ADDRESS_P (rtl
))
13874 get_pool_constant_mark (rtl
, &marked
);
13875 /* If all references to this pool constant were optimized away,
13876 it was not output and thus we can't represent it. */
13879 expansion_failed (NULL_TREE
, rtl
,
13880 "Constant was removed from constant pool.\n");
13885 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13888 /* Avoid references to external symbols in debug info, on several targets
13889 the linker might even refuse to link when linking a shared library,
13890 and in many other cases the relocations for .debug_info/.debug_loc are
13891 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13892 to be defined within the same shared library or executable are fine. */
13893 if (SYMBOL_REF_EXTERNAL_P (rtl
))
13895 tree decl
= SYMBOL_REF_DECL (rtl
);
13897 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
13899 expansion_failed (NULL_TREE
, rtl
,
13900 "Symbol not defined in current TU.\n");
13908 /* Return true if constant RTL can be emitted in DW_OP_addr or
13909 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13910 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13913 const_ok_for_output (rtx rtl
)
13915 if (GET_CODE (rtl
) == SYMBOL_REF
)
13916 return const_ok_for_output_1 (rtl
);
13918 if (GET_CODE (rtl
) == CONST
)
13920 subrtx_var_iterator::array_type array
;
13921 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
13922 if (!const_ok_for_output_1 (*iter
))
13930 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
13931 if possible, NULL otherwise. */
13934 base_type_for_mode (machine_mode mode
, bool unsignedp
)
13936 dw_die_ref type_die
;
13937 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
13941 switch (TREE_CODE (type
))
13949 type_die
= lookup_type_die (type
);
13951 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
13953 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
13958 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
13959 type matching MODE, or, if MODE is narrower than or as wide as
13960 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
13963 static dw_loc_descr_ref
13964 convert_descriptor_to_mode (scalar_int_mode mode
, dw_loc_descr_ref op
)
13966 machine_mode outer_mode
= mode
;
13967 dw_die_ref type_die
;
13968 dw_loc_descr_ref cvt
;
13970 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13972 add_loc_descr (&op
, new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
13975 type_die
= base_type_for_mode (outer_mode
, 1);
13976 if (type_die
== NULL
)
13978 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13979 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13980 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13981 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13982 add_loc_descr (&op
, cvt
);
13986 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
13988 static dw_loc_descr_ref
13989 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
13990 dw_loc_descr_ref op1
)
13992 dw_loc_descr_ref ret
= op0
;
13993 add_loc_descr (&ret
, op1
);
13994 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13995 if (STORE_FLAG_VALUE
!= 1)
13997 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
13998 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14003 /* Subroutine of scompare_loc_descriptor for the case in which we're
14004 comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
14005 and in which OP_MODE is bigger than DWARF2_ADDR_SIZE. */
14007 static dw_loc_descr_ref
14008 scompare_loc_descriptor_wide (enum dwarf_location_atom op
,
14009 scalar_int_mode op_mode
,
14010 dw_loc_descr_ref op0
, dw_loc_descr_ref op1
)
14012 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
14013 dw_loc_descr_ref cvt
;
14015 if (type_die
== NULL
)
14017 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14018 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14019 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14020 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14021 add_loc_descr (&op0
, cvt
);
14022 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14023 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14024 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14025 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14026 add_loc_descr (&op1
, cvt
);
14027 return compare_loc_descriptor (op
, op0
, op1
);
14030 /* Subroutine of scompare_loc_descriptor for the case in which we're
14031 comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
14032 and in which OP_MODE is smaller than DWARF2_ADDR_SIZE. */
14034 static dw_loc_descr_ref
14035 scompare_loc_descriptor_narrow (enum dwarf_location_atom op
, rtx rtl
,
14036 scalar_int_mode op_mode
,
14037 dw_loc_descr_ref op0
, dw_loc_descr_ref op1
)
14039 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
14040 /* For eq/ne, if the operands are known to be zero-extended,
14041 there is no need to do the fancy shifting up. */
14042 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
14044 dw_loc_descr_ref last0
, last1
;
14045 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
14047 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
14049 /* deref_size zero extends, and for constants we can check
14050 whether they are zero extended or not. */
14051 if (((last0
->dw_loc_opc
== DW_OP_deref_size
14052 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
14053 || (CONST_INT_P (XEXP (rtl
, 0))
14054 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
14055 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
14056 && ((last1
->dw_loc_opc
== DW_OP_deref_size
14057 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
14058 || (CONST_INT_P (XEXP (rtl
, 1))
14059 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
14060 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
14061 return compare_loc_descriptor (op
, op0
, op1
);
14063 /* EQ/NE comparison against constant in narrower type than
14064 DWARF2_ADDR_SIZE can be performed either as
14065 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
14068 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
14069 DW_OP_{eq,ne}. Pick whatever is shorter. */
14070 if (CONST_INT_P (XEXP (rtl
, 1))
14071 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
14072 && (size_of_int_loc_descriptor (shift
) + 1
14073 + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
)
14074 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
14075 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
14076 & GET_MODE_MASK (op_mode
))))
14078 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
14079 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14080 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
14081 & GET_MODE_MASK (op_mode
));
14082 return compare_loc_descriptor (op
, op0
, op1
);
14085 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14086 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14087 if (CONST_INT_P (XEXP (rtl
, 1)))
14088 op1
= int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
);
14091 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14092 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14094 return compare_loc_descriptor (op
, op0
, op1
);
14097 /* Return location descriptor for unsigned comparison OP RTL. */
14099 static dw_loc_descr_ref
14100 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
14101 machine_mode mem_mode
)
14103 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
14104 dw_loc_descr_ref op0
, op1
;
14106 if (op_mode
== VOIDmode
)
14107 op_mode
= GET_MODE (XEXP (rtl
, 1));
14108 if (op_mode
== VOIDmode
)
14111 scalar_int_mode int_op_mode
;
14113 && dwarf_version
< 5
14114 && (!is_a
<scalar_int_mode
> (op_mode
, &int_op_mode
)
14115 || GET_MODE_SIZE (int_op_mode
) > DWARF2_ADDR_SIZE
))
14118 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
14119 VAR_INIT_STATUS_INITIALIZED
);
14120 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
14121 VAR_INIT_STATUS_INITIALIZED
);
14123 if (op0
== NULL
|| op1
== NULL
)
14126 if (is_a
<scalar_int_mode
> (op_mode
, &int_op_mode
))
14128 if (GET_MODE_SIZE (int_op_mode
) < DWARF2_ADDR_SIZE
)
14129 return scompare_loc_descriptor_narrow (op
, rtl
, int_op_mode
, op0
, op1
);
14131 if (GET_MODE_SIZE (int_op_mode
) > DWARF2_ADDR_SIZE
)
14132 return scompare_loc_descriptor_wide (op
, int_op_mode
, op0
, op1
);
14134 return compare_loc_descriptor (op
, op0
, op1
);
14137 /* Return location descriptor for unsigned comparison OP RTL. */
14139 static dw_loc_descr_ref
14140 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
14141 machine_mode mem_mode
)
14143 dw_loc_descr_ref op0
, op1
;
14145 machine_mode test_op_mode
= GET_MODE (XEXP (rtl
, 0));
14146 if (test_op_mode
== VOIDmode
)
14147 test_op_mode
= GET_MODE (XEXP (rtl
, 1));
14149 scalar_int_mode op_mode
;
14150 if (!is_a
<scalar_int_mode
> (test_op_mode
, &op_mode
))
14154 && dwarf_version
< 5
14155 && GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
14158 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
14159 VAR_INIT_STATUS_INITIALIZED
);
14160 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
14161 VAR_INIT_STATUS_INITIALIZED
);
14163 if (op0
== NULL
|| op1
== NULL
)
14166 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
14168 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
14169 dw_loc_descr_ref last0
, last1
;
14170 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
14172 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
14174 if (CONST_INT_P (XEXP (rtl
, 0)))
14175 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
14176 /* deref_size zero extends, so no need to mask it again. */
14177 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
14178 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
14180 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14181 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14183 if (CONST_INT_P (XEXP (rtl
, 1)))
14184 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
14185 /* deref_size zero extends, so no need to mask it again. */
14186 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
14187 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
14189 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14190 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14193 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
14195 HOST_WIDE_INT bias
= 1;
14196 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14197 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14198 if (CONST_INT_P (XEXP (rtl
, 1)))
14199 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
14200 + INTVAL (XEXP (rtl
, 1)));
14202 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
14205 return compare_loc_descriptor (op
, op0
, op1
);
14208 /* Return location descriptor for {U,S}{MIN,MAX}. */
14210 static dw_loc_descr_ref
14211 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
14212 machine_mode mem_mode
)
14214 enum dwarf_location_atom op
;
14215 dw_loc_descr_ref op0
, op1
, ret
;
14216 dw_loc_descr_ref bra_node
, drop_node
;
14218 scalar_int_mode int_mode
;
14220 && dwarf_version
< 5
14221 && (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
14222 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
))
14225 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14226 VAR_INIT_STATUS_INITIALIZED
);
14227 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14228 VAR_INIT_STATUS_INITIALIZED
);
14230 if (op0
== NULL
|| op1
== NULL
)
14233 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
14234 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
14235 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
14236 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
14238 /* Checked by the caller. */
14239 int_mode
= as_a
<scalar_int_mode
> (mode
);
14240 if (GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
14242 HOST_WIDE_INT mask
= GET_MODE_MASK (int_mode
);
14243 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14244 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14245 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14246 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14248 else if (GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
)
14250 HOST_WIDE_INT bias
= 1;
14251 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14252 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14253 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14256 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
14257 && GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
14259 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (int_mode
)) * BITS_PER_UNIT
;
14260 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14261 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14262 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14263 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14265 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
14266 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
14268 dw_die_ref type_die
= base_type_for_mode (int_mode
, 0);
14269 dw_loc_descr_ref cvt
;
14270 if (type_die
== NULL
)
14272 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14273 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14274 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14275 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14276 add_loc_descr (&op0
, cvt
);
14277 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14278 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14279 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14280 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14281 add_loc_descr (&op1
, cvt
);
14284 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
14289 add_loc_descr (&ret
, op1
);
14290 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
14291 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14292 add_loc_descr (&ret
, bra_node
);
14293 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14294 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14295 add_loc_descr (&ret
, drop_node
);
14296 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14297 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14298 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
14299 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
14300 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
14301 ret
= convert_descriptor_to_mode (int_mode
, ret
);
14305 /* Helper function for mem_loc_descriptor. Perform OP binary op,
14306 but after converting arguments to type_die, afterwards
14307 convert back to unsigned. */
14309 static dw_loc_descr_ref
14310 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
14311 scalar_int_mode mode
, machine_mode mem_mode
)
14313 dw_loc_descr_ref cvt
, op0
, op1
;
14315 if (type_die
== NULL
)
14317 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14318 VAR_INIT_STATUS_INITIALIZED
);
14319 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14320 VAR_INIT_STATUS_INITIALIZED
);
14321 if (op0
== NULL
|| op1
== NULL
)
14323 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14324 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14325 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14326 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14327 add_loc_descr (&op0
, cvt
);
14328 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14329 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14330 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14331 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14332 add_loc_descr (&op1
, cvt
);
14333 add_loc_descr (&op0
, op1
);
14334 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
14335 return convert_descriptor_to_mode (mode
, op0
);
14338 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
14339 const0 is DW_OP_lit0 or corresponding typed constant,
14340 const1 is DW_OP_lit1 or corresponding typed constant
14341 and constMSB is constant with just the MSB bit set
14343 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14344 L1: const0 DW_OP_swap
14345 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
14346 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14351 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14352 L1: const0 DW_OP_swap
14353 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14354 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14359 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
14360 L1: const1 DW_OP_swap
14361 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14362 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14366 static dw_loc_descr_ref
14367 clz_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
14368 machine_mode mem_mode
)
14370 dw_loc_descr_ref op0
, ret
, tmp
;
14371 HOST_WIDE_INT valv
;
14372 dw_loc_descr_ref l1jump
, l1label
;
14373 dw_loc_descr_ref l2jump
, l2label
;
14374 dw_loc_descr_ref l3jump
, l3label
;
14375 dw_loc_descr_ref l4jump
, l4label
;
14378 if (GET_MODE (XEXP (rtl
, 0)) != mode
)
14381 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14382 VAR_INIT_STATUS_INITIALIZED
);
14386 if (GET_CODE (rtl
) == CLZ
)
14388 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14389 valv
= GET_MODE_BITSIZE (mode
);
14391 else if (GET_CODE (rtl
) == FFS
)
14393 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14394 valv
= GET_MODE_BITSIZE (mode
);
14395 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14396 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14397 add_loc_descr (&ret
, l1jump
);
14398 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14399 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
14400 VAR_INIT_STATUS_INITIALIZED
);
14403 add_loc_descr (&ret
, tmp
);
14404 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14405 add_loc_descr (&ret
, l4jump
);
14406 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
14407 ? const1_rtx
: const0_rtx
,
14409 VAR_INIT_STATUS_INITIALIZED
);
14410 if (l1label
== NULL
)
14412 add_loc_descr (&ret
, l1label
);
14413 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14414 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
14415 add_loc_descr (&ret
, l2label
);
14416 if (GET_CODE (rtl
) != CLZ
)
14418 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
14419 msb
= GEN_INT (HOST_WIDE_INT_1U
14420 << (GET_MODE_BITSIZE (mode
) - 1));
14422 msb
= immed_wide_int_const
14423 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
14424 GET_MODE_PRECISION (mode
)), mode
);
14425 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
14426 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14427 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
14428 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
14430 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
14431 VAR_INIT_STATUS_INITIALIZED
);
14434 add_loc_descr (&ret
, tmp
);
14435 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14436 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14437 add_loc_descr (&ret
, l3jump
);
14438 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14439 VAR_INIT_STATUS_INITIALIZED
);
14442 add_loc_descr (&ret
, tmp
);
14443 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
14444 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
14445 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14446 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
14447 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14448 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14449 add_loc_descr (&ret
, l2jump
);
14450 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
14451 add_loc_descr (&ret
, l3label
);
14452 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
14453 add_loc_descr (&ret
, l4label
);
14454 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14455 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14456 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14457 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14458 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14459 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
14460 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14461 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
14465 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
14466 const1 is DW_OP_lit1 or corresponding typed constant):
14468 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14469 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14473 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14474 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14477 static dw_loc_descr_ref
14478 popcount_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
14479 machine_mode mem_mode
)
14481 dw_loc_descr_ref op0
, ret
, tmp
;
14482 dw_loc_descr_ref l1jump
, l1label
;
14483 dw_loc_descr_ref l2jump
, l2label
;
14485 if (GET_MODE (XEXP (rtl
, 0)) != mode
)
14488 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14489 VAR_INIT_STATUS_INITIALIZED
);
14493 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14494 VAR_INIT_STATUS_INITIALIZED
);
14497 add_loc_descr (&ret
, tmp
);
14498 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14499 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
14500 add_loc_descr (&ret
, l1label
);
14501 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14502 add_loc_descr (&ret
, l2jump
);
14503 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14504 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14505 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14506 VAR_INIT_STATUS_INITIALIZED
);
14509 add_loc_descr (&ret
, tmp
);
14510 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14511 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
14512 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
14513 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14514 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14515 VAR_INIT_STATUS_INITIALIZED
);
14516 add_loc_descr (&ret
, tmp
);
14517 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14518 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14519 add_loc_descr (&ret
, l1jump
);
14520 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14521 add_loc_descr (&ret
, l2label
);
14522 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14523 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14524 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14525 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14529 /* BSWAP (constS is initial shift count, either 56 or 24):
14531 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
14532 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
14533 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
14534 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
14535 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
14537 static dw_loc_descr_ref
14538 bswap_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
14539 machine_mode mem_mode
)
14541 dw_loc_descr_ref op0
, ret
, tmp
;
14542 dw_loc_descr_ref l1jump
, l1label
;
14543 dw_loc_descr_ref l2jump
, l2label
;
14545 if (BITS_PER_UNIT
!= 8
14546 || (GET_MODE_BITSIZE (mode
) != 32
14547 && GET_MODE_BITSIZE (mode
) != 64))
14550 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14551 VAR_INIT_STATUS_INITIALIZED
);
14556 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14558 VAR_INIT_STATUS_INITIALIZED
);
14561 add_loc_descr (&ret
, tmp
);
14562 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14563 VAR_INIT_STATUS_INITIALIZED
);
14566 add_loc_descr (&ret
, tmp
);
14567 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
14568 add_loc_descr (&ret
, l1label
);
14569 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14571 VAR_INIT_STATUS_INITIALIZED
);
14572 add_loc_descr (&ret
, tmp
);
14573 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
14574 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14575 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14576 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
14577 VAR_INIT_STATUS_INITIALIZED
);
14580 add_loc_descr (&ret
, tmp
);
14581 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14582 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
14583 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14584 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14585 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14586 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14587 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14588 VAR_INIT_STATUS_INITIALIZED
);
14589 add_loc_descr (&ret
, tmp
);
14590 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
14591 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14592 add_loc_descr (&ret
, l2jump
);
14593 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
14594 VAR_INIT_STATUS_INITIALIZED
);
14595 add_loc_descr (&ret
, tmp
);
14596 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14597 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14598 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14599 add_loc_descr (&ret
, l1jump
);
14600 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14601 add_loc_descr (&ret
, l2label
);
14602 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14603 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14604 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14605 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14606 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14607 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14611 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
14612 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14613 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
14614 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
14616 ROTATERT is similar:
14617 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
14618 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14619 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
14621 static dw_loc_descr_ref
14622 rotate_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
14623 machine_mode mem_mode
)
14625 rtx rtlop1
= XEXP (rtl
, 1);
14626 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
14629 if (is_narrower_int_mode (GET_MODE (rtlop1
), mode
))
14630 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
14631 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14632 VAR_INIT_STATUS_INITIALIZED
);
14633 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
14634 VAR_INIT_STATUS_INITIALIZED
);
14635 if (op0
== NULL
|| op1
== NULL
)
14637 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14638 for (i
= 0; i
< 2; i
++)
14640 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
14641 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
14643 VAR_INIT_STATUS_INITIALIZED
);
14644 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
14645 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14647 : HOST_BITS_PER_WIDE_INT
== 64
14648 ? DW_OP_const8u
: DW_OP_constu
,
14649 GET_MODE_MASK (mode
), 0);
14652 if (mask
[i
] == NULL
)
14654 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
14657 add_loc_descr (&ret
, op1
);
14658 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14659 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14660 if (GET_CODE (rtl
) == ROTATERT
)
14662 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14663 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14664 GET_MODE_BITSIZE (mode
), 0));
14666 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14667 if (mask
[0] != NULL
)
14668 add_loc_descr (&ret
, mask
[0]);
14669 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14670 if (mask
[1] != NULL
)
14672 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14673 add_loc_descr (&ret
, mask
[1]);
14674 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14676 if (GET_CODE (rtl
) == ROTATE
)
14678 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14679 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14680 GET_MODE_BITSIZE (mode
), 0));
14682 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14683 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14687 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
14688 for DEBUG_PARAMETER_REF RTL. */
14690 static dw_loc_descr_ref
14691 parameter_ref_descriptor (rtx rtl
)
14693 dw_loc_descr_ref ret
;
14698 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
14699 /* With LTO during LTRANS we get the late DIE that refers to the early
14700 DIE, thus we add another indirection here. This seems to confuse
14701 gdb enough to make gcc.dg/guality/pr68860-1.c FAIL with LTO. */
14702 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
14703 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
14706 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14707 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14708 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14712 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14713 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
14718 /* The following routine converts the RTL for a variable or parameter
14719 (resident in memory) into an equivalent Dwarf representation of a
14720 mechanism for getting the address of that same variable onto the top of a
14721 hypothetical "address evaluation" stack.
14723 When creating memory location descriptors, we are effectively transforming
14724 the RTL for a memory-resident object into its Dwarf postfix expression
14725 equivalent. This routine recursively descends an RTL tree, turning
14726 it into Dwarf postfix code as it goes.
14728 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
14730 MEM_MODE is the mode of the memory reference, needed to handle some
14731 autoincrement addressing modes.
14733 Return 0 if we can't represent the location. */
14736 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
14737 machine_mode mem_mode
,
14738 enum var_init_status initialized
)
14740 dw_loc_descr_ref mem_loc_result
= NULL
;
14741 enum dwarf_location_atom op
;
14742 dw_loc_descr_ref op0
, op1
;
14743 rtx inner
= NULL_RTX
;
14746 if (mode
== VOIDmode
)
14747 mode
= GET_MODE (rtl
);
14749 /* Note that for a dynamically sized array, the location we will generate a
14750 description of here will be the lowest numbered location which is
14751 actually within the array. That's *not* necessarily the same as the
14752 zeroth element of the array. */
14754 rtl
= targetm
.delegitimize_address (rtl
);
14756 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
14759 scalar_int_mode int_mode
, inner_mode
, op1_mode
;
14760 switch (GET_CODE (rtl
))
14765 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
14768 /* The case of a subreg may arise when we have a local (register)
14769 variable or a formal (register) parameter which doesn't quite fill
14770 up an entire register. For now, just assume that it is
14771 legitimate to make the Dwarf info refer to the whole register which
14772 contains the given subreg. */
14773 if (!subreg_lowpart_p (rtl
))
14775 inner
= SUBREG_REG (rtl
);
14778 if (inner
== NULL_RTX
)
14779 inner
= XEXP (rtl
, 0);
14780 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
14781 && is_a
<scalar_int_mode
> (GET_MODE (inner
), &inner_mode
)
14782 && (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
14783 #ifdef POINTERS_EXTEND_UNSIGNED
14784 || (int_mode
== Pmode
&& mem_mode
!= VOIDmode
)
14787 && GET_MODE_SIZE (inner_mode
) <= DWARF2_ADDR_SIZE
)
14789 mem_loc_result
= mem_loc_descriptor (inner
,
14791 mem_mode
, initialized
);
14794 if (dwarf_strict
&& dwarf_version
< 5)
14796 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
14797 && is_a
<scalar_int_mode
> (GET_MODE (inner
), &inner_mode
)
14798 ? GET_MODE_SIZE (int_mode
) <= GET_MODE_SIZE (inner_mode
)
14799 : GET_MODE_SIZE (mode
) == GET_MODE_SIZE (GET_MODE (inner
)))
14801 dw_die_ref type_die
;
14802 dw_loc_descr_ref cvt
;
14804 mem_loc_result
= mem_loc_descriptor (inner
,
14806 mem_mode
, initialized
);
14807 if (mem_loc_result
== NULL
)
14809 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14810 if (type_die
== NULL
)
14812 mem_loc_result
= NULL
;
14815 if (GET_MODE_SIZE (mode
)
14816 != GET_MODE_SIZE (GET_MODE (inner
)))
14817 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14819 cvt
= new_loc_descr (dwarf_OP (DW_OP_reinterpret
), 0, 0);
14820 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14821 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14822 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14823 add_loc_descr (&mem_loc_result
, cvt
);
14824 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
14825 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
)
14827 /* Convert it to untyped afterwards. */
14828 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14829 add_loc_descr (&mem_loc_result
, cvt
);
14835 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
14836 || (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
14837 && rtl
!= arg_pointer_rtx
14838 && rtl
!= frame_pointer_rtx
14839 #ifdef POINTERS_EXTEND_UNSIGNED
14840 && (int_mode
!= Pmode
|| mem_mode
== VOIDmode
)
14844 dw_die_ref type_die
;
14845 unsigned int dbx_regnum
;
14847 if (dwarf_strict
&& dwarf_version
< 5)
14849 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
14851 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14852 if (type_die
== NULL
)
14855 dbx_regnum
= dbx_reg_number (rtl
);
14856 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14858 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_regval_type
),
14860 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14861 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14862 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14865 /* Whenever a register number forms a part of the description of the
14866 method for calculating the (dynamic) address of a memory resident
14867 object, DWARF rules require the register number be referred to as
14868 a "base register". This distinction is not based in any way upon
14869 what category of register the hardware believes the given register
14870 belongs to. This is strictly DWARF terminology we're dealing with
14871 here. Note that in cases where the location of a memory-resident
14872 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
14873 OP_CONST (0)) the actual DWARF location descriptor that we generate
14874 may just be OP_BASEREG (basereg). This may look deceptively like
14875 the object in question was allocated to a register (rather than in
14876 memory) so DWARF consumers need to be aware of the subtle
14877 distinction between OP_REG and OP_BASEREG. */
14878 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
14879 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
14880 else if (stack_realign_drap
14882 && crtl
->args
.internal_arg_pointer
== rtl
14883 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
14885 /* If RTL is internal_arg_pointer, which has been optimized
14886 out, use DRAP instead. */
14887 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
14888 VAR_INIT_STATUS_INITIALIZED
);
14894 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
14895 || !is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &inner_mode
))
14897 op0
= mem_loc_descriptor (XEXP (rtl
, 0), inner_mode
,
14898 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14901 else if (GET_CODE (rtl
) == ZERO_EXTEND
14902 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
14903 && GET_MODE_BITSIZE (inner_mode
) < HOST_BITS_PER_WIDE_INT
14904 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
14905 to expand zero extend as two shifts instead of
14907 && GET_MODE_SIZE (inner_mode
) <= 4)
14909 mem_loc_result
= op0
;
14910 add_loc_descr (&mem_loc_result
,
14911 int_loc_descriptor (GET_MODE_MASK (inner_mode
)));
14912 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
14914 else if (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
)
14916 int shift
= DWARF2_ADDR_SIZE
- GET_MODE_SIZE (inner_mode
);
14917 shift
*= BITS_PER_UNIT
;
14918 if (GET_CODE (rtl
) == SIGN_EXTEND
)
14922 mem_loc_result
= op0
;
14923 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14924 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14925 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14926 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14928 else if (!dwarf_strict
|| dwarf_version
>= 5)
14930 dw_die_ref type_die1
, type_die2
;
14931 dw_loc_descr_ref cvt
;
14933 type_die1
= base_type_for_mode (inner_mode
,
14934 GET_CODE (rtl
) == ZERO_EXTEND
);
14935 if (type_die1
== NULL
)
14937 type_die2
= base_type_for_mode (int_mode
, 1);
14938 if (type_die2
== NULL
)
14940 mem_loc_result
= op0
;
14941 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14942 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14943 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
14944 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14945 add_loc_descr (&mem_loc_result
, cvt
);
14946 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14947 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14948 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
14949 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14950 add_loc_descr (&mem_loc_result
, cvt
);
14956 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14957 if (new_rtl
!= rtl
)
14959 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
14961 if (mem_loc_result
!= NULL
)
14962 return mem_loc_result
;
14965 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
14966 get_address_mode (rtl
), mode
,
14967 VAR_INIT_STATUS_INITIALIZED
);
14968 if (mem_loc_result
== NULL
)
14969 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
14970 if (mem_loc_result
!= NULL
)
14972 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
14973 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
14975 dw_die_ref type_die
;
14976 dw_loc_descr_ref deref
;
14978 if (dwarf_strict
&& dwarf_version
< 5)
14981 = base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14982 if (type_die
== NULL
)
14984 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
),
14985 GET_MODE_SIZE (mode
), 0);
14986 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14987 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14988 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14989 add_loc_descr (&mem_loc_result
, deref
);
14991 else if (GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
)
14992 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
14994 add_loc_descr (&mem_loc_result
,
14995 new_loc_descr (DW_OP_deref_size
,
14996 GET_MODE_SIZE (int_mode
), 0));
15001 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
15004 /* Some ports can transform a symbol ref into a label ref, because
15005 the symbol ref is too far away and has to be dumped into a constant
15009 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15010 || (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
15011 #ifdef POINTERS_EXTEND_UNSIGNED
15012 && (int_mode
!= Pmode
|| mem_mode
== VOIDmode
)
15016 if (GET_CODE (rtl
) == SYMBOL_REF
15017 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
15019 dw_loc_descr_ref temp
;
15021 /* If this is not defined, we have no way to emit the data. */
15022 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
15025 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
15027 /* We check for DWARF 5 here because gdb did not implement
15028 DW_OP_form_tls_address until after 7.12. */
15029 mem_loc_result
= new_loc_descr ((dwarf_version
>= 5
15030 ? DW_OP_form_tls_address
15031 : DW_OP_GNU_push_tls_address
),
15033 add_loc_descr (&mem_loc_result
, temp
);
15038 if (!const_ok_for_output (rtl
))
15040 if (GET_CODE (rtl
) == CONST
)
15041 switch (GET_CODE (XEXP (rtl
, 0)))
15045 goto try_const_unop
;
15048 goto try_const_unop
;
15051 arg
= XEXP (XEXP (rtl
, 0), 0);
15052 if (!CONSTANT_P (arg
))
15053 arg
= gen_rtx_CONST (int_mode
, arg
);
15054 op0
= mem_loc_descriptor (arg
, int_mode
, mem_mode
,
15058 mem_loc_result
= op0
;
15059 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15063 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), int_mode
,
15064 mem_mode
, initialized
);
15071 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15072 vec_safe_push (used_rtx_array
, rtl
);
15078 case DEBUG_IMPLICIT_PTR
:
15079 expansion_failed (NULL_TREE
, rtl
,
15080 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
15084 if (dwarf_strict
&& dwarf_version
< 5)
15086 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
15088 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15089 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15090 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
15091 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15094 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
15095 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
15097 op0
= one_reg_loc_descriptor (dbx_regnum
,
15098 VAR_INIT_STATUS_INITIALIZED
);
15101 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
15102 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
15104 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
15105 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15106 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
15110 gcc_unreachable ();
15113 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_entry_value
), 0, 0);
15114 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15115 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
15118 case DEBUG_PARAMETER_REF
:
15119 mem_loc_result
= parameter_ref_descriptor (rtl
);
15123 /* Extract the PLUS expression nested inside and fall into
15124 PLUS code below. */
15125 rtl
= XEXP (rtl
, 1);
15130 /* Turn these into a PLUS expression and fall into the PLUS code
15132 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
15133 gen_int_mode (GET_CODE (rtl
) == PRE_INC
15134 ? GET_MODE_UNIT_SIZE (mem_mode
)
15135 : -GET_MODE_UNIT_SIZE (mem_mode
),
15142 if (is_based_loc (rtl
)
15143 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15144 && (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15145 || XEXP (rtl
, 0) == arg_pointer_rtx
15146 || XEXP (rtl
, 0) == frame_pointer_rtx
))
15147 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
15148 INTVAL (XEXP (rtl
, 1)),
15149 VAR_INIT_STATUS_INITIALIZED
);
15152 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15153 VAR_INIT_STATUS_INITIALIZED
);
15154 if (mem_loc_result
== 0)
15157 if (CONST_INT_P (XEXP (rtl
, 1))
15158 && (GET_MODE_SIZE (as_a
<scalar_int_mode
> (mode
))
15159 <= DWARF2_ADDR_SIZE
))
15160 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
15163 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15164 VAR_INIT_STATUS_INITIALIZED
);
15167 add_loc_descr (&mem_loc_result
, op1
);
15168 add_loc_descr (&mem_loc_result
,
15169 new_loc_descr (DW_OP_plus
, 0, 0));
15174 /* If a pseudo-reg is optimized away, it is possible for it to
15175 be replaced with a MEM containing a multiply or shift. */
15185 if ((!dwarf_strict
|| dwarf_version
>= 5)
15186 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15187 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15189 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
15190 base_type_for_mode (mode
, 0),
15191 int_mode
, mem_mode
);
15214 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
))
15216 op0
= mem_loc_descriptor (XEXP (rtl
, 0), int_mode
, mem_mode
,
15217 VAR_INIT_STATUS_INITIALIZED
);
15219 rtx rtlop1
= XEXP (rtl
, 1);
15220 if (is_a
<scalar_int_mode
> (GET_MODE (rtlop1
), &op1_mode
)
15221 && GET_MODE_BITSIZE (op1_mode
) < GET_MODE_BITSIZE (int_mode
))
15222 rtlop1
= gen_rtx_ZERO_EXTEND (int_mode
, rtlop1
);
15223 op1
= mem_loc_descriptor (rtlop1
, int_mode
, mem_mode
,
15224 VAR_INIT_STATUS_INITIALIZED
);
15227 if (op0
== 0 || op1
== 0)
15230 mem_loc_result
= op0
;
15231 add_loc_descr (&mem_loc_result
, op1
);
15232 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15248 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15249 VAR_INIT_STATUS_INITIALIZED
);
15250 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15251 VAR_INIT_STATUS_INITIALIZED
);
15253 if (op0
== 0 || op1
== 0)
15256 mem_loc_result
= op0
;
15257 add_loc_descr (&mem_loc_result
, op1
);
15258 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15262 if ((!dwarf_strict
|| dwarf_version
>= 5)
15263 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15264 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15266 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
15267 base_type_for_mode (mode
, 0),
15268 int_mode
, mem_mode
);
15272 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15273 VAR_INIT_STATUS_INITIALIZED
);
15274 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15275 VAR_INIT_STATUS_INITIALIZED
);
15277 if (op0
== 0 || op1
== 0)
15280 mem_loc_result
= op0
;
15281 add_loc_descr (&mem_loc_result
, op1
);
15282 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15283 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15284 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
15285 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
15286 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
15290 if ((!dwarf_strict
|| dwarf_version
>= 5)
15291 && is_a
<scalar_int_mode
> (mode
, &int_mode
))
15293 if (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15298 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
15299 base_type_for_mode (int_mode
, 1),
15300 int_mode
, mem_mode
);
15317 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15318 VAR_INIT_STATUS_INITIALIZED
);
15323 mem_loc_result
= op0
;
15324 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15328 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15329 || GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15330 #ifdef POINTERS_EXTEND_UNSIGNED
15331 || (int_mode
== Pmode
15332 && mem_mode
!= VOIDmode
15333 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
15337 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15340 if ((!dwarf_strict
|| dwarf_version
>= 5)
15341 && (GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_WIDE_INT
15342 || GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_DOUBLE_INT
))
15344 dw_die_ref type_die
= base_type_for_mode (int_mode
, 1);
15345 scalar_int_mode amode
;
15346 if (type_die
== NULL
)
15348 if (INTVAL (rtl
) >= 0
15349 && (int_mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
, 0)
15351 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
15352 /* const DW_OP_convert <XXX> vs.
15353 DW_OP_const_type <XXX, 1, const>. */
15354 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
15355 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (int_mode
))
15357 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15358 op0
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15359 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15360 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15361 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15362 add_loc_descr (&mem_loc_result
, op0
);
15363 return mem_loc_result
;
15365 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0,
15367 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15368 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15369 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15370 if (GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_WIDE_INT
)
15371 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15374 mem_loc_result
->dw_loc_oprnd2
.val_class
15375 = dw_val_class_const_double
;
15376 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15377 = double_int::from_shwi (INTVAL (rtl
));
15383 if (!dwarf_strict
|| dwarf_version
>= 5)
15385 dw_die_ref type_die
;
15387 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
15388 CONST_DOUBLE rtx could represent either a large integer
15389 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
15390 the value is always a floating point constant.
15392 When it is an integer, a CONST_DOUBLE is used whenever
15393 the constant requires 2 HWIs to be adequately represented.
15394 We output CONST_DOUBLEs as blocks. */
15395 if (mode
== VOIDmode
15396 || (GET_MODE (rtl
) == VOIDmode
15397 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
15399 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15400 if (type_die
== NULL
)
15402 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15403 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15404 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15405 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15406 #if TARGET_SUPPORTS_WIDE_INT == 0
15407 if (!SCALAR_FLOAT_MODE_P (mode
))
15409 mem_loc_result
->dw_loc_oprnd2
.val_class
15410 = dw_val_class_const_double
;
15411 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15412 = rtx_to_double_int (rtl
);
15417 scalar_float_mode float_mode
= as_a
<scalar_float_mode
> (mode
);
15418 unsigned int length
= GET_MODE_SIZE (float_mode
);
15419 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15421 insert_float (rtl
, array
);
15422 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15423 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15424 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15425 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15430 case CONST_WIDE_INT
:
15431 if (!dwarf_strict
|| dwarf_version
>= 5)
15433 dw_die_ref type_die
;
15435 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15436 if (type_die
== NULL
)
15438 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15439 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15440 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15441 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15442 mem_loc_result
->dw_loc_oprnd2
.val_class
15443 = dw_val_class_wide_int
;
15444 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15445 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15449 case CONST_POLY_INT
:
15450 mem_loc_result
= int_loc_descriptor (rtx_to_poly_int64 (rtl
));
15454 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
15458 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15462 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15466 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15470 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15474 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
15478 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15482 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15486 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15490 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15495 if (!SCALAR_INT_MODE_P (mode
))
15500 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
15505 if (CONST_INT_P (XEXP (rtl
, 1))
15506 && CONST_INT_P (XEXP (rtl
, 2))
15507 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15508 && is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &inner_mode
)
15509 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15510 && GET_MODE_SIZE (inner_mode
) <= DWARF2_ADDR_SIZE
15511 && ((unsigned) INTVAL (XEXP (rtl
, 1))
15512 + (unsigned) INTVAL (XEXP (rtl
, 2))
15513 <= GET_MODE_BITSIZE (int_mode
)))
15516 op0
= mem_loc_descriptor (XEXP (rtl
, 0), inner_mode
,
15517 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15520 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
15524 mem_loc_result
= op0
;
15525 size
= INTVAL (XEXP (rtl
, 1));
15526 shift
= INTVAL (XEXP (rtl
, 2));
15527 if (BITS_BIG_ENDIAN
)
15528 shift
= GET_MODE_BITSIZE (inner_mode
) - shift
- size
;
15529 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
15531 add_loc_descr (&mem_loc_result
,
15532 int_loc_descriptor (DWARF2_ADDR_SIZE
15534 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
15536 if (size
!= (int) DWARF2_ADDR_SIZE
)
15538 add_loc_descr (&mem_loc_result
,
15539 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
15540 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15547 dw_loc_descr_ref op2
, bra_node
, drop_node
;
15548 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
15549 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
15550 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
15551 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15552 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15553 VAR_INIT_STATUS_INITIALIZED
);
15554 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
15555 VAR_INIT_STATUS_INITIALIZED
);
15556 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
15559 mem_loc_result
= op1
;
15560 add_loc_descr (&mem_loc_result
, op2
);
15561 add_loc_descr (&mem_loc_result
, op0
);
15562 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15563 add_loc_descr (&mem_loc_result
, bra_node
);
15564 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
15565 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
15566 add_loc_descr (&mem_loc_result
, drop_node
);
15567 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15568 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
15573 case FLOAT_TRUNCATE
:
15575 case UNSIGNED_FLOAT
:
15578 if (!dwarf_strict
|| dwarf_version
>= 5)
15580 dw_die_ref type_die
;
15581 dw_loc_descr_ref cvt
;
15583 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
15584 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15587 if (is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &int_mode
)
15588 && (GET_CODE (rtl
) == FLOAT
15589 || GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
))
15591 type_die
= base_type_for_mode (int_mode
,
15592 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
15593 if (type_die
== NULL
)
15595 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15596 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15597 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15598 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15599 add_loc_descr (&op0
, cvt
);
15601 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
15602 if (type_die
== NULL
)
15604 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15605 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15606 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15607 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15608 add_loc_descr (&op0
, cvt
);
15609 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15610 && (GET_CODE (rtl
) == FIX
15611 || GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
))
15613 op0
= convert_descriptor_to_mode (int_mode
, op0
);
15617 mem_loc_result
= op0
;
15624 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
15625 mem_loc_result
= clz_loc_descriptor (rtl
, int_mode
, mem_mode
);
15630 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
15631 mem_loc_result
= popcount_loc_descriptor (rtl
, int_mode
, mem_mode
);
15635 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
15636 mem_loc_result
= bswap_loc_descriptor (rtl
, int_mode
, mem_mode
);
15641 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
15642 mem_loc_result
= rotate_loc_descriptor (rtl
, int_mode
, mem_mode
);
15646 /* In theory, we could implement the above. */
15647 /* DWARF cannot represent the unsigned compare operations
15672 case FRACT_CONVERT
:
15673 case UNSIGNED_FRACT_CONVERT
:
15675 case UNSIGNED_SAT_FRACT
:
15681 case VEC_DUPLICATE
:
15686 case STRICT_LOW_PART
:
15691 /* If delegitimize_address couldn't do anything with the UNSPEC, we
15692 can't express it in the debug info. This can happen e.g. with some
15697 resolve_one_addr (&rtl
);
15700 /* RTL sequences inside PARALLEL record a series of DWARF operations for
15701 the expression. An UNSPEC rtx represents a raw DWARF operation,
15702 new_loc_descr is called for it to build the operation directly.
15703 Otherwise mem_loc_descriptor is called recursively. */
15707 dw_loc_descr_ref exp_result
= NULL
;
15709 for (; index
< XVECLEN (rtl
, 0); index
++)
15711 rtx elem
= XVECEXP (rtl
, 0, index
);
15712 if (GET_CODE (elem
) == UNSPEC
)
15714 /* Each DWARF operation UNSPEC contain two operands, if
15715 one operand is not used for the operation, const0_rtx is
15717 gcc_assert (XVECLEN (elem
, 0) == 2);
15719 HOST_WIDE_INT dw_op
= XINT (elem
, 1);
15720 HOST_WIDE_INT oprnd1
= INTVAL (XVECEXP (elem
, 0, 0));
15721 HOST_WIDE_INT oprnd2
= INTVAL (XVECEXP (elem
, 0, 1));
15723 = new_loc_descr ((enum dwarf_location_atom
) dw_op
, oprnd1
,
15728 = mem_loc_descriptor (elem
, mode
, mem_mode
,
15729 VAR_INIT_STATUS_INITIALIZED
);
15731 if (!mem_loc_result
)
15732 mem_loc_result
= exp_result
;
15734 add_loc_descr (&mem_loc_result
, exp_result
);
15743 print_rtl (stderr
, rtl
);
15744 gcc_unreachable ();
15749 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15750 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15752 return mem_loc_result
;
15755 /* Return a descriptor that describes the concatenation of two locations.
15756 This is typically a complex variable. */
15758 static dw_loc_descr_ref
15759 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
15761 dw_loc_descr_ref cc_loc_result
= NULL
;
15762 dw_loc_descr_ref x0_ref
15763 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15764 dw_loc_descr_ref x1_ref
15765 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15767 if (x0_ref
== 0 || x1_ref
== 0)
15770 cc_loc_result
= x0_ref
;
15771 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
15773 add_loc_descr (&cc_loc_result
, x1_ref
);
15774 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
15776 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15777 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15779 return cc_loc_result
;
15782 /* Return a descriptor that describes the concatenation of N
15785 static dw_loc_descr_ref
15786 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
15789 dw_loc_descr_ref cc_loc_result
= NULL
;
15790 unsigned int n
= XVECLEN (concatn
, 0);
15792 for (i
= 0; i
< n
; ++i
)
15794 dw_loc_descr_ref ref
;
15795 rtx x
= XVECEXP (concatn
, 0, i
);
15797 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15801 add_loc_descr (&cc_loc_result
, ref
);
15802 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
15805 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15806 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15808 return cc_loc_result
;
15811 /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
15812 for DEBUG_IMPLICIT_PTR RTL. */
15814 static dw_loc_descr_ref
15815 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
15817 dw_loc_descr_ref ret
;
15820 if (dwarf_strict
&& dwarf_version
< 5)
15822 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
15823 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
15824 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
15825 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
15826 ret
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
15827 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15830 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15831 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
15832 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15836 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
15837 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
15842 /* Output a proper Dwarf location descriptor for a variable or parameter
15843 which is either allocated in a register or in a memory location. For a
15844 register, we just generate an OP_REG and the register number. For a
15845 memory location we provide a Dwarf postfix expression describing how to
15846 generate the (dynamic) address of the object onto the address stack.
15848 MODE is mode of the decl if this loc_descriptor is going to be used in
15849 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
15850 allowed, VOIDmode otherwise.
15852 If we don't know how to describe it, return 0. */
15854 static dw_loc_descr_ref
15855 loc_descriptor (rtx rtl
, machine_mode mode
,
15856 enum var_init_status initialized
)
15858 dw_loc_descr_ref loc_result
= NULL
;
15859 scalar_int_mode int_mode
;
15861 switch (GET_CODE (rtl
))
15864 /* The case of a subreg may arise when we have a local (register)
15865 variable or a formal (register) parameter which doesn't quite fill
15866 up an entire register. For now, just assume that it is
15867 legitimate to make the Dwarf info refer to the whole register which
15868 contains the given subreg. */
15869 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
15870 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
15871 GET_MODE (SUBREG_REG (rtl
)), initialized
);
15877 loc_result
= reg_loc_descriptor (rtl
, initialized
);
15881 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
15882 GET_MODE (rtl
), initialized
);
15883 if (loc_result
== NULL
)
15884 loc_result
= tls_mem_loc_descriptor (rtl
);
15885 if (loc_result
== NULL
)
15887 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
15888 if (new_rtl
!= rtl
)
15889 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
15894 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
15899 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
15904 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
15906 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
15907 if (GET_CODE (loc
) == EXPR_LIST
)
15908 loc
= XEXP (loc
, 0);
15909 loc_result
= loc_descriptor (loc
, mode
, initialized
);
15913 rtl
= XEXP (rtl
, 1);
15918 rtvec par_elems
= XVEC (rtl
, 0);
15919 int num_elem
= GET_NUM_ELEM (par_elems
);
15923 /* Create the first one, so we have something to add to. */
15924 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
15925 VOIDmode
, initialized
);
15926 if (loc_result
== NULL
)
15928 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
15929 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15930 for (i
= 1; i
< num_elem
; i
++)
15932 dw_loc_descr_ref temp
;
15934 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
15935 VOIDmode
, initialized
);
15938 add_loc_descr (&loc_result
, temp
);
15939 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
15940 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15946 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
15948 int_mode
= as_a
<scalar_int_mode
> (mode
);
15949 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (int_mode
),
15955 if (mode
== VOIDmode
)
15956 mode
= GET_MODE (rtl
);
15958 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15960 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15962 /* Note that a CONST_DOUBLE rtx could represent either an integer
15963 or a floating-point constant. A CONST_DOUBLE is used whenever
15964 the constant requires more than one word in order to be
15965 adequately represented. We output CONST_DOUBLEs as blocks. */
15966 scalar_mode smode
= as_a
<scalar_mode
> (mode
);
15967 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15968 GET_MODE_SIZE (smode
), 0);
15969 #if TARGET_SUPPORTS_WIDE_INT == 0
15970 if (!SCALAR_FLOAT_MODE_P (smode
))
15972 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
15973 loc_result
->dw_loc_oprnd2
.v
.val_double
15974 = rtx_to_double_int (rtl
);
15979 unsigned int length
= GET_MODE_SIZE (smode
);
15980 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15982 insert_float (rtl
, array
);
15983 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15984 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15985 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15986 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15991 case CONST_WIDE_INT
:
15992 if (mode
== VOIDmode
)
15993 mode
= GET_MODE (rtl
);
15995 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15997 int_mode
= as_a
<scalar_int_mode
> (mode
);
15998 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15999 GET_MODE_SIZE (int_mode
), 0);
16000 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
16001 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
16002 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, int_mode
);
16007 if (mode
== VOIDmode
)
16008 mode
= GET_MODE (rtl
);
16010 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
16012 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
16013 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
16014 unsigned char *array
16015 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
16018 machine_mode imode
= GET_MODE_INNER (mode
);
16020 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
16021 switch (GET_MODE_CLASS (mode
))
16023 case MODE_VECTOR_INT
:
16024 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16026 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16027 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
16031 case MODE_VECTOR_FLOAT
:
16032 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16034 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16035 insert_float (elt
, p
);
16040 gcc_unreachable ();
16043 loc_result
= new_loc_descr (DW_OP_implicit_value
,
16044 length
* elt_size
, 0);
16045 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
16046 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
16047 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
16048 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
16053 if (mode
== VOIDmode
16054 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
16055 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
16056 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
16058 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
16063 if (!const_ok_for_output (rtl
))
16067 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
16068 && GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
16069 && (dwarf_version
>= 4 || !dwarf_strict
))
16071 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
16072 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16073 vec_safe_push (used_rtx_array
, rtl
);
16077 case DEBUG_IMPLICIT_PTR
:
16078 loc_result
= implicit_ptr_descriptor (rtl
, 0);
16082 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
16083 && CONST_INT_P (XEXP (rtl
, 1)))
16086 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
16092 if ((is_a
<scalar_int_mode
> (mode
, &int_mode
)
16093 && GET_MODE (rtl
) == int_mode
16094 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16095 && dwarf_version
>= 4)
16096 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
16098 /* Value expression. */
16099 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
16101 add_loc_descr (&loc_result
,
16102 new_loc_descr (DW_OP_stack_value
, 0, 0));
16110 /* We need to figure out what section we should use as the base for the
16111 address ranges where a given location is valid.
16112 1. If this particular DECL has a section associated with it, use that.
16113 2. If this function has a section associated with it, use that.
16114 3. Otherwise, use the text section.
16115 XXX: If you split a variable across multiple sections, we won't notice. */
16117 static const char *
16118 secname_for_decl (const_tree decl
)
16120 const char *secname
;
16122 if (VAR_OR_FUNCTION_DECL_P (decl
)
16123 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
16124 && DECL_SECTION_NAME (decl
))
16125 secname
= DECL_SECTION_NAME (decl
);
16126 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
16127 secname
= DECL_SECTION_NAME (current_function_decl
);
16128 else if (cfun
&& in_cold_section_p
)
16129 secname
= crtl
->subsections
.cold_section_label
;
16131 secname
= text_section_label
;
16136 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
16139 decl_by_reference_p (tree decl
)
16141 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
16143 && DECL_BY_REFERENCE (decl
));
16146 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
16149 static dw_loc_descr_ref
16150 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
16151 enum var_init_status initialized
)
16153 int have_address
= 0;
16154 dw_loc_descr_ref descr
;
16157 if (want_address
!= 2)
16159 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
16161 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
16163 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
16164 if (GET_CODE (varloc
) == EXPR_LIST
)
16165 varloc
= XEXP (varloc
, 0);
16166 mode
= GET_MODE (varloc
);
16167 if (MEM_P (varloc
))
16169 rtx addr
= XEXP (varloc
, 0);
16170 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
16171 mode
, initialized
);
16176 rtx x
= avoid_constant_pool_reference (varloc
);
16178 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
16183 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
16190 if (GET_CODE (varloc
) == VAR_LOCATION
)
16191 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
16193 mode
= DECL_MODE (loc
);
16194 descr
= loc_descriptor (varloc
, mode
, initialized
);
16201 if (want_address
== 2 && !have_address
16202 && (dwarf_version
>= 4 || !dwarf_strict
))
16204 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
16206 expansion_failed (loc
, NULL_RTX
,
16207 "DWARF address size mismatch");
16210 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16213 /* Show if we can't fill the request for an address. */
16214 if (want_address
&& !have_address
)
16216 expansion_failed (loc
, NULL_RTX
,
16217 "Want address and only have value");
16221 /* If we've got an address and don't want one, dereference. */
16222 if (!want_address
&& have_address
)
16224 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
16225 enum dwarf_location_atom op
;
16227 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
16229 expansion_failed (loc
, NULL_RTX
,
16230 "DWARF address size mismatch");
16233 else if (size
== DWARF2_ADDR_SIZE
)
16236 op
= DW_OP_deref_size
;
16238 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
16244 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
16245 if it is not possible. */
16247 static dw_loc_descr_ref
16248 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
16250 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
16251 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
16252 else if (dwarf_version
>= 3 || !dwarf_strict
)
16253 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
16258 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
16259 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
16261 static dw_loc_descr_ref
16262 dw_sra_loc_expr (tree decl
, rtx loc
)
16265 unsigned HOST_WIDE_INT padsize
= 0;
16266 dw_loc_descr_ref descr
, *descr_tail
;
16267 unsigned HOST_WIDE_INT decl_size
;
16269 enum var_init_status initialized
;
16271 if (DECL_SIZE (decl
) == NULL
16272 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
16275 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
16277 descr_tail
= &descr
;
16279 for (p
= loc
; p
; p
= XEXP (p
, 1))
16281 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
16282 rtx loc_note
= *decl_piece_varloc_ptr (p
);
16283 dw_loc_descr_ref cur_descr
;
16284 dw_loc_descr_ref
*tail
, last
= NULL
;
16285 unsigned HOST_WIDE_INT opsize
= 0;
16287 if (loc_note
== NULL_RTX
16288 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
16290 padsize
+= bitsize
;
16293 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
16294 varloc
= NOTE_VAR_LOCATION (loc_note
);
16295 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
16296 if (cur_descr
== NULL
)
16298 padsize
+= bitsize
;
16302 /* Check that cur_descr either doesn't use
16303 DW_OP_*piece operations, or their sum is equal
16304 to bitsize. Otherwise we can't embed it. */
16305 for (tail
= &cur_descr
; *tail
!= NULL
;
16306 tail
= &(*tail
)->dw_loc_next
)
16307 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
16309 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
16313 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
16315 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
16319 if (last
!= NULL
&& opsize
!= bitsize
)
16321 padsize
+= bitsize
;
16322 /* Discard the current piece of the descriptor and release any
16323 addr_table entries it uses. */
16324 remove_loc_list_addr_table_entries (cur_descr
);
16328 /* If there is a hole, add DW_OP_*piece after empty DWARF
16329 expression, which means that those bits are optimized out. */
16332 if (padsize
> decl_size
)
16334 remove_loc_list_addr_table_entries (cur_descr
);
16335 goto discard_descr
;
16337 decl_size
-= padsize
;
16338 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
16339 if (*descr_tail
== NULL
)
16341 remove_loc_list_addr_table_entries (cur_descr
);
16342 goto discard_descr
;
16344 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16347 *descr_tail
= cur_descr
;
16349 if (bitsize
> decl_size
)
16350 goto discard_descr
;
16351 decl_size
-= bitsize
;
16354 HOST_WIDE_INT offset
= 0;
16355 if (GET_CODE (varloc
) == VAR_LOCATION
16356 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
16358 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
16359 if (GET_CODE (varloc
) == EXPR_LIST
)
16360 varloc
= XEXP (varloc
, 0);
16364 if (GET_CODE (varloc
) == CONST
16365 || GET_CODE (varloc
) == SIGN_EXTEND
16366 || GET_CODE (varloc
) == ZERO_EXTEND
)
16367 varloc
= XEXP (varloc
, 0);
16368 else if (GET_CODE (varloc
) == SUBREG
)
16369 varloc
= SUBREG_REG (varloc
);
16374 /* DW_OP_bit_size offset should be zero for register
16375 or implicit location descriptions and empty location
16376 descriptions, but for memory addresses needs big endian
16378 if (MEM_P (varloc
))
16380 unsigned HOST_WIDE_INT memsize
;
16381 if (!poly_uint64 (MEM_SIZE (varloc
)).is_constant (&memsize
))
16382 goto discard_descr
;
16383 memsize
*= BITS_PER_UNIT
;
16384 if (memsize
!= bitsize
)
16386 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
16387 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
16388 goto discard_descr
;
16389 if (memsize
< bitsize
)
16390 goto discard_descr
;
16391 if (BITS_BIG_ENDIAN
)
16392 offset
= memsize
- bitsize
;
16396 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
16397 if (*descr_tail
== NULL
)
16398 goto discard_descr
;
16399 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16403 /* If there were any non-empty expressions, add padding till the end of
16405 if (descr
!= NULL
&& decl_size
!= 0)
16407 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
16408 if (*descr_tail
== NULL
)
16409 goto discard_descr
;
16414 /* Discard the descriptor and release any addr_table entries it uses. */
16415 remove_loc_list_addr_table_entries (descr
);
16419 /* Return the dwarf representation of the location list LOC_LIST of
16420 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
16423 static dw_loc_list_ref
16424 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
16426 const char *endname
, *secname
;
16428 enum var_init_status initialized
;
16429 struct var_loc_node
*node
;
16430 dw_loc_descr_ref descr
;
16431 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
16432 dw_loc_list_ref list
= NULL
;
16433 dw_loc_list_ref
*listp
= &list
;
16435 /* Now that we know what section we are using for a base,
16436 actually construct the list of locations.
16437 The first location information is what is passed to the
16438 function that creates the location list, and the remaining
16439 locations just get added on to that list.
16440 Note that we only know the start address for a location
16441 (IE location changes), so to build the range, we use
16442 the range [current location start, next location start].
16443 This means we have to special case the last node, and generate
16444 a range of [last location start, end of function label]. */
16446 if (cfun
&& crtl
->has_bb_partition
)
16448 bool save_in_cold_section_p
= in_cold_section_p
;
16449 in_cold_section_p
= first_function_block_is_cold
;
16450 if (loc_list
->last_before_switch
== NULL
)
16451 in_cold_section_p
= !in_cold_section_p
;
16452 secname
= secname_for_decl (decl
);
16453 in_cold_section_p
= save_in_cold_section_p
;
16456 secname
= secname_for_decl (decl
);
16458 for (node
= loc_list
->first
; node
; node
= node
->next
)
16460 bool range_across_switch
= false;
16461 if (GET_CODE (node
->loc
) == EXPR_LIST
16462 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
16464 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16467 /* This requires DW_OP_{,bit_}piece, which is not usable
16468 inside DWARF expressions. */
16469 if (want_address
== 2)
16470 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16474 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16475 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16476 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
16480 /* If section switch happens in between node->label
16481 and node->next->label (or end of function) and
16482 we can't emit it as a single entry list,
16483 emit two ranges, first one ending at the end
16484 of first partition and second one starting at the
16485 beginning of second partition. */
16486 if (node
== loc_list
->last_before_switch
16487 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
16488 && current_function_decl
)
16490 endname
= cfun
->fde
->dw_fde_end
;
16491 range_across_switch
= true;
16493 /* The variable has a location between NODE->LABEL and
16494 NODE->NEXT->LABEL. */
16495 else if (node
->next
)
16496 endname
= node
->next
->label
;
16497 /* If the variable has a location at the last label
16498 it keeps its location until the end of function. */
16499 else if (!current_function_decl
)
16500 endname
= text_end_label
;
16503 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
16504 current_function_funcdef_no
);
16505 endname
= ggc_strdup (label_id
);
16508 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
16509 if (TREE_CODE (decl
) == PARM_DECL
16510 && node
== loc_list
->first
16511 && NOTE_P (node
->loc
)
16512 && strcmp (node
->label
, endname
) == 0)
16513 (*listp
)->force
= true;
16514 listp
= &(*listp
)->dw_loc_next
;
16519 && crtl
->has_bb_partition
16520 && node
== loc_list
->last_before_switch
)
16522 bool save_in_cold_section_p
= in_cold_section_p
;
16523 in_cold_section_p
= !first_function_block_is_cold
;
16524 secname
= secname_for_decl (decl
);
16525 in_cold_section_p
= save_in_cold_section_p
;
16528 if (range_across_switch
)
16530 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16531 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16534 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16535 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16536 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
16539 gcc_assert (descr
);
16540 /* The variable has a location between NODE->LABEL and
16541 NODE->NEXT->LABEL. */
16543 endname
= node
->next
->label
;
16545 endname
= cfun
->fde
->dw_fde_second_end
;
16546 *listp
= new_loc_list (descr
, cfun
->fde
->dw_fde_second_begin
,
16548 listp
= &(*listp
)->dw_loc_next
;
16552 /* Try to avoid the overhead of a location list emitting a location
16553 expression instead, but only if we didn't have more than one
16554 location entry in the first place. If some entries were not
16555 representable, we don't want to pretend a single entry that was
16556 applies to the entire scope in which the variable is
16558 if (list
&& loc_list
->first
->next
)
16564 /* Return if the loc_list has only single element and thus can be represented
16565 as location description. */
16568 single_element_loc_list_p (dw_loc_list_ref list
)
16570 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
16571 return !list
->ll_symbol
;
16574 /* Duplicate a single element of location list. */
16576 static inline dw_loc_descr_ref
16577 copy_loc_descr (dw_loc_descr_ref ref
)
16579 dw_loc_descr_ref copy
= ggc_alloc
<dw_loc_descr_node
> ();
16580 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
16584 /* To each location in list LIST append loc descr REF. */
16587 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
16589 dw_loc_descr_ref copy
;
16590 add_loc_descr (&list
->expr
, ref
);
16591 list
= list
->dw_loc_next
;
16594 copy
= copy_loc_descr (ref
);
16595 add_loc_descr (&list
->expr
, copy
);
16596 while (copy
->dw_loc_next
)
16597 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
16598 list
= list
->dw_loc_next
;
16602 /* To each location in list LIST prepend loc descr REF. */
16605 prepend_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
16607 dw_loc_descr_ref copy
;
16608 dw_loc_descr_ref ref_end
= list
->expr
;
16609 add_loc_descr (&ref
, list
->expr
);
16611 list
= list
->dw_loc_next
;
16614 dw_loc_descr_ref end
= list
->expr
;
16615 list
->expr
= copy
= copy_loc_descr (ref
);
16616 while (copy
->dw_loc_next
!= ref_end
)
16617 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
16618 copy
->dw_loc_next
= end
;
16619 list
= list
->dw_loc_next
;
16623 /* Given two lists RET and LIST
16624 produce location list that is result of adding expression in LIST
16625 to expression in RET on each position in program.
16626 Might be destructive on both RET and LIST.
16628 TODO: We handle only simple cases of RET or LIST having at most one
16629 element. General case would involve sorting the lists in program order
16630 and merging them that will need some additional work.
16631 Adding that will improve quality of debug info especially for SRA-ed
16635 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
16644 if (!list
->dw_loc_next
)
16646 add_loc_descr_to_each (*ret
, list
->expr
);
16649 if (!(*ret
)->dw_loc_next
)
16651 prepend_loc_descr_to_each (list
, (*ret
)->expr
);
16655 expansion_failed (NULL_TREE
, NULL_RTX
,
16656 "Don't know how to merge two non-trivial"
16657 " location lists.\n");
16662 /* LOC is constant expression. Try a luck, look it up in constant
16663 pool and return its loc_descr of its address. */
16665 static dw_loc_descr_ref
16666 cst_pool_loc_descr (tree loc
)
16668 /* Get an RTL for this, if something has been emitted. */
16669 rtx rtl
= lookup_constant_def (loc
);
16671 if (!rtl
|| !MEM_P (rtl
))
16676 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
16678 /* TODO: We might get more coverage if we was actually delaying expansion
16679 of all expressions till end of compilation when constant pools are fully
16681 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
16683 expansion_failed (loc
, NULL_RTX
,
16684 "CST value in contant pool but not marked.");
16687 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
16688 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
16691 /* Return dw_loc_list representing address of addr_expr LOC
16692 by looking for inner INDIRECT_REF expression and turning
16693 it into simple arithmetics.
16695 See loc_list_from_tree for the meaning of CONTEXT. */
16697 static dw_loc_list_ref
16698 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
16699 loc_descr_context
*context
)
16702 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
16704 int unsignedp
, reversep
, volatilep
= 0;
16705 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
16707 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
16708 &bitsize
, &bitpos
, &offset
, &mode
,
16709 &unsignedp
, &reversep
, &volatilep
);
16711 if (bitpos
% BITS_PER_UNIT
)
16713 expansion_failed (loc
, NULL_RTX
, "bitfield access");
16716 if (!INDIRECT_REF_P (obj
))
16718 expansion_failed (obj
,
16719 NULL_RTX
, "no indirect ref in inner refrence");
16722 if (!offset
&& !bitpos
)
16723 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
16726 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
16727 && (dwarf_version
>= 4 || !dwarf_strict
))
16729 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
16734 /* Variable offset. */
16735 list_ret1
= loc_list_from_tree (offset
, 0, context
);
16736 if (list_ret1
== 0)
16738 add_loc_list (&list_ret
, list_ret1
);
16741 add_loc_descr_to_each (list_ret
,
16742 new_loc_descr (DW_OP_plus
, 0, 0));
16744 bytepos
= bitpos
/ BITS_PER_UNIT
;
16746 add_loc_descr_to_each (list_ret
,
16747 new_loc_descr (DW_OP_plus_uconst
,
16749 else if (bytepos
< 0)
16750 loc_list_plus_const (list_ret
, bytepos
);
16751 add_loc_descr_to_each (list_ret
,
16752 new_loc_descr (DW_OP_stack_value
, 0, 0));
16757 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
16758 all operations from LOC are nops, move to the last one. Insert in NOPS all
16759 operations that are skipped. */
16762 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
16763 hash_set
<dw_loc_descr_ref
> &nops
)
16765 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
16768 loc
= loc
->dw_loc_next
;
16772 /* Helper for loc_descr_without_nops: free the location description operation
16776 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
16782 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
16786 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
16788 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
16791 /* Set of all DW_OP_nop operations we remove. */
16792 hash_set
<dw_loc_descr_ref
> nops
;
16794 /* First, strip all prefix NOP operations in order to keep the head of the
16795 operations list. */
16796 loc_descr_to_next_no_nop (loc
, nops
);
16798 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
16800 /* For control flow operations: strip "prefix" nops in destination
16802 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
16803 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
16804 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
16805 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
16807 /* Do the same for the operations that follow, then move to the next
16809 if (cur
->dw_loc_next
!= NULL
)
16810 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
16811 cur
= cur
->dw_loc_next
;
16814 nops
.traverse
<void *, free_loc_descr
> (NULL
);
16818 struct dwarf_procedure_info
;
16820 /* Helper structure for location descriptions generation. */
16821 struct loc_descr_context
16823 /* The type that is implicitly referenced by DW_OP_push_object_address, or
16824 NULL_TREE if DW_OP_push_object_address in invalid for this location
16825 description. This is used when processing PLACEHOLDER_EXPR nodes. */
16827 /* The ..._DECL node that should be translated as a
16828 DW_OP_push_object_address operation. */
16830 /* Information about the DWARF procedure we are currently generating. NULL if
16831 we are not generating a DWARF procedure. */
16832 struct dwarf_procedure_info
*dpi
;
16833 /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
16834 by consumer. Used for DW_TAG_generic_subrange attributes. */
16835 bool placeholder_arg
;
16836 /* True if PLACEHOLDER_EXPR has been seen. */
16837 bool placeholder_seen
;
16840 /* DWARF procedures generation
16842 DWARF expressions (aka. location descriptions) are used to encode variable
16843 things such as sizes or offsets. Such computations can have redundant parts
16844 that can be factorized in order to reduce the size of the output debug
16845 information. This is the whole point of DWARF procedures.
16847 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
16848 already factorized into functions ("size functions") in order to handle very
16849 big and complex types. Such functions are quite simple: they have integral
16850 arguments, they return an integral result and their body contains only a
16851 return statement with arithmetic expressions. This is the only kind of
16852 function we are interested in translating into DWARF procedures, here.
16854 DWARF expressions and DWARF procedure are executed using a stack, so we have
16855 to define some calling convention for them to interact. Let's say that:
16857 - Before calling a DWARF procedure, DWARF expressions must push on the stack
16858 all arguments in reverse order (right-to-left) so that when the DWARF
16859 procedure execution starts, the first argument is the top of the stack.
16861 - Then, when returning, the DWARF procedure must have consumed all arguments
16862 on the stack, must have pushed the result and touched nothing else.
16864 - Each integral argument and the result are integral types can be hold in a
16867 - We call "frame offset" the number of stack slots that are "under DWARF
16868 procedure control": it includes the arguments slots, the temporaries and
16869 the result slot. Thus, it is equal to the number of arguments when the
16870 procedure execution starts and must be equal to one (the result) when it
16873 /* Helper structure used when generating operations for a DWARF procedure. */
16874 struct dwarf_procedure_info
16876 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
16877 currently translated. */
16879 /* The number of arguments FNDECL takes. */
16880 unsigned args_count
;
16883 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
16884 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
16885 equate it to this DIE. */
16888 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
16889 dw_die_ref parent_die
)
16891 dw_die_ref dwarf_proc_die
;
16893 if ((dwarf_version
< 3 && dwarf_strict
)
16894 || location
== NULL
)
16897 dwarf_proc_die
= new_die (DW_TAG_dwarf_procedure
, parent_die
, fndecl
);
16899 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
16900 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
16901 return dwarf_proc_die
;
16904 /* Return whether TYPE is a supported type as a DWARF procedure argument
16905 type or return type (we handle only scalar types and pointer types that
16906 aren't wider than the DWARF expression evaluation stack. */
16909 is_handled_procedure_type (tree type
)
16911 return ((INTEGRAL_TYPE_P (type
)
16912 || TREE_CODE (type
) == OFFSET_TYPE
16913 || TREE_CODE (type
) == POINTER_TYPE
)
16914 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
16917 /* Helper for resolve_args_picking: do the same but stop when coming across
16918 visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
16919 offset *before* evaluating the corresponding operation. */
16922 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
16923 struct dwarf_procedure_info
*dpi
,
16924 hash_map
<dw_loc_descr_ref
, unsigned> &frame_offsets
)
16926 /* The "frame_offset" identifier is already used to name a macro... */
16927 unsigned frame_offset_
= initial_frame_offset
;
16928 dw_loc_descr_ref l
;
16930 for (l
= loc
; l
!= NULL
;)
16933 unsigned &l_frame_offset
= frame_offsets
.get_or_insert (l
, &existed
);
16935 /* If we already met this node, there is nothing to compute anymore. */
16938 /* Make sure that the stack size is consistent wherever the execution
16939 flow comes from. */
16940 gcc_assert ((unsigned) l_frame_offset
== frame_offset_
);
16943 l_frame_offset
= frame_offset_
;
16945 /* If needed, relocate the picking offset with respect to the frame
16947 if (l
->frame_offset_rel
)
16949 unsigned HOST_WIDE_INT off
;
16950 switch (l
->dw_loc_opc
)
16953 off
= l
->dw_loc_oprnd1
.v
.val_unsigned
;
16962 gcc_unreachable ();
16964 /* frame_offset_ is the size of the current stack frame, including
16965 incoming arguments. Besides, the arguments are pushed
16966 right-to-left. Thus, in order to access the Nth argument from
16967 this operation node, the picking has to skip temporaries *plus*
16968 one stack slot per argument (0 for the first one, 1 for the second
16971 The targetted argument number (N) is already set as the operand,
16972 and the number of temporaries can be computed with:
16973 frame_offsets_ - dpi->args_count */
16974 off
+= frame_offset_
- dpi
->args_count
;
16976 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
16982 l
->dw_loc_opc
= DW_OP_dup
;
16983 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16987 l
->dw_loc_opc
= DW_OP_over
;
16988 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16992 l
->dw_loc_opc
= DW_OP_pick
;
16993 l
->dw_loc_oprnd1
.v
.val_unsigned
= off
;
16997 /* Update frame_offset according to the effect the current operation has
16999 switch (l
->dw_loc_opc
)
17007 case DW_OP_plus_uconst
:
17043 case DW_OP_deref_size
:
17045 case DW_OP_bit_piece
:
17046 case DW_OP_implicit_value
:
17047 case DW_OP_stack_value
:
17051 case DW_OP_const1u
:
17052 case DW_OP_const1s
:
17053 case DW_OP_const2u
:
17054 case DW_OP_const2s
:
17055 case DW_OP_const4u
:
17056 case DW_OP_const4s
:
17057 case DW_OP_const8u
:
17058 case DW_OP_const8s
:
17129 case DW_OP_push_object_address
:
17130 case DW_OP_call_frame_cfa
:
17131 case DW_OP_GNU_variable_value
:
17156 case DW_OP_xderef_size
:
17162 case DW_OP_call_ref
:
17164 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
17165 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
17167 if (stack_usage
== NULL
)
17169 frame_offset_
+= *stack_usage
;
17173 case DW_OP_implicit_pointer
:
17174 case DW_OP_entry_value
:
17175 case DW_OP_const_type
:
17176 case DW_OP_regval_type
:
17177 case DW_OP_deref_type
:
17178 case DW_OP_convert
:
17179 case DW_OP_reinterpret
:
17180 case DW_OP_form_tls_address
:
17181 case DW_OP_GNU_push_tls_address
:
17182 case DW_OP_GNU_uninit
:
17183 case DW_OP_GNU_encoded_addr
:
17184 case DW_OP_GNU_implicit_pointer
:
17185 case DW_OP_GNU_entry_value
:
17186 case DW_OP_GNU_const_type
:
17187 case DW_OP_GNU_regval_type
:
17188 case DW_OP_GNU_deref_type
:
17189 case DW_OP_GNU_convert
:
17190 case DW_OP_GNU_reinterpret
:
17191 case DW_OP_GNU_parameter_ref
:
17192 /* loc_list_from_tree will probably not output these operations for
17193 size functions, so assume they will not appear here. */
17194 /* Fall through... */
17197 gcc_unreachable ();
17200 /* Now, follow the control flow (except subroutine calls). */
17201 switch (l
->dw_loc_opc
)
17204 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
17207 /* Fall through. */
17210 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
17213 case DW_OP_stack_value
:
17217 l
= l
->dw_loc_next
;
17225 /* Make a DFS over operations reachable through LOC (i.e. follow branch
17226 operations) in order to resolve the operand of DW_OP_pick operations that
17227 target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
17228 offset *before* LOC is executed. Return if all relocations were
17232 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
17233 struct dwarf_procedure_info
*dpi
)
17235 /* Associate to all visited operations the frame offset *before* evaluating
17237 hash_map
<dw_loc_descr_ref
, unsigned> frame_offsets
;
17239 return resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
,
17243 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
17244 Return NULL if it is not possible. */
17247 function_to_dwarf_procedure (tree fndecl
)
17249 struct loc_descr_context ctx
;
17250 struct dwarf_procedure_info dpi
;
17251 dw_die_ref dwarf_proc_die
;
17252 tree tree_body
= DECL_SAVED_TREE (fndecl
);
17253 dw_loc_descr_ref loc_body
, epilogue
;
17258 /* Do not generate multiple DWARF procedures for the same function
17260 dwarf_proc_die
= lookup_decl_die (fndecl
);
17261 if (dwarf_proc_die
!= NULL
)
17262 return dwarf_proc_die
;
17264 /* DWARF procedures are available starting with the DWARFv3 standard. */
17265 if (dwarf_version
< 3 && dwarf_strict
)
17268 /* We handle only functions for which we still have a body, that return a
17269 supported type and that takes arguments with supported types. Note that
17270 there is no point translating functions that return nothing. */
17271 if (tree_body
== NULL_TREE
17272 || DECL_RESULT (fndecl
) == NULL_TREE
17273 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
17276 for (cursor
= DECL_ARGUMENTS (fndecl
);
17277 cursor
!= NULL_TREE
;
17278 cursor
= TREE_CHAIN (cursor
))
17279 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
17282 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
17283 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
17285 tree_body
= TREE_OPERAND (tree_body
, 0);
17286 if (TREE_CODE (tree_body
) != MODIFY_EXPR
17287 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
17289 tree_body
= TREE_OPERAND (tree_body
, 1);
17291 /* Try to translate the body expression itself. Note that this will probably
17292 cause an infinite recursion if its call graph has a cycle. This is very
17293 unlikely for size functions, however, so don't bother with such things at
17295 ctx
.context_type
= NULL_TREE
;
17296 ctx
.base_decl
= NULL_TREE
;
17298 ctx
.placeholder_arg
= false;
17299 ctx
.placeholder_seen
= false;
17300 dpi
.fndecl
= fndecl
;
17301 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
17302 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
17306 /* After evaluating all operands in "loc_body", we should still have on the
17307 stack all arguments plus the desired function result (top of the stack).
17308 Generate code in order to keep only the result in our stack frame. */
17310 for (i
= 0; i
< dpi
.args_count
; ++i
)
17312 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
17313 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
17314 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
17315 epilogue
= op_couple
;
17317 add_loc_descr (&loc_body
, epilogue
);
17318 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
17321 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
17322 because they are considered useful. Now there is an epilogue, they are
17323 not anymore, so give it another try. */
17324 loc_descr_without_nops (loc_body
);
17326 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
17327 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
17328 though, given that size functions do not come from source, so they should
17329 not have a dedicated DW_TAG_subprogram DIE. */
17331 = new_dwarf_proc_die (loc_body
, fndecl
,
17332 get_context_die (DECL_CONTEXT (fndecl
)));
17334 /* The called DWARF procedure consumes one stack slot per argument and
17335 returns one stack slot. */
17336 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
17338 return dwarf_proc_die
;
17342 /* Generate Dwarf location list representing LOC.
17343 If WANT_ADDRESS is false, expression computing LOC will be computed
17344 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
17345 if WANT_ADDRESS is 2, expression computing address useable in location
17346 will be returned (i.e. DW_OP_reg can be used
17347 to refer to register values).
17349 CONTEXT provides information to customize the location descriptions
17350 generation. Its context_type field specifies what type is implicitly
17351 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
17352 will not be generated.
17354 Its DPI field determines whether we are generating a DWARF expression for a
17355 DWARF procedure, so PARM_DECL references are processed specifically.
17357 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
17358 and dpi fields were null. */
17360 static dw_loc_list_ref
17361 loc_list_from_tree_1 (tree loc
, int want_address
,
17362 struct loc_descr_context
*context
)
17364 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
17365 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
17366 int have_address
= 0;
17367 enum dwarf_location_atom op
;
17369 /* ??? Most of the time we do not take proper care for sign/zero
17370 extending the values properly. Hopefully this won't be a real
17373 if (context
!= NULL
17374 && context
->base_decl
== loc
17375 && want_address
== 0)
17377 if (dwarf_version
>= 3 || !dwarf_strict
)
17378 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
17384 switch (TREE_CODE (loc
))
17387 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
17390 case PLACEHOLDER_EXPR
:
17391 /* This case involves extracting fields from an object to determine the
17392 position of other fields. It is supposed to appear only as the first
17393 operand of COMPONENT_REF nodes and to reference precisely the type
17394 that the context allows. */
17395 if (context
!= NULL
17396 && TREE_TYPE (loc
) == context
->context_type
17397 && want_address
>= 1)
17399 if (dwarf_version
>= 3 || !dwarf_strict
)
17401 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
17408 /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
17409 the single argument passed by consumer. */
17410 else if (context
!= NULL
17411 && context
->placeholder_arg
17412 && INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17413 && want_address
== 0)
17415 ret
= new_loc_descr (DW_OP_pick
, 0, 0);
17416 ret
->frame_offset_rel
= 1;
17417 context
->placeholder_seen
= true;
17421 expansion_failed (loc
, NULL_RTX
,
17422 "PLACEHOLDER_EXPR for an unexpected type");
17427 const int nargs
= call_expr_nargs (loc
);
17428 tree callee
= get_callee_fndecl (loc
);
17430 dw_die_ref dwarf_proc
;
17432 if (callee
== NULL_TREE
)
17433 goto call_expansion_failed
;
17435 /* We handle only functions that return an integer. */
17436 if (!is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
))))
17437 goto call_expansion_failed
;
17439 dwarf_proc
= function_to_dwarf_procedure (callee
);
17440 if (dwarf_proc
== NULL
)
17441 goto call_expansion_failed
;
17443 /* Evaluate arguments right-to-left so that the first argument will
17444 be the top-most one on the stack. */
17445 for (i
= nargs
- 1; i
>= 0; --i
)
17447 dw_loc_descr_ref loc_descr
17448 = loc_descriptor_from_tree (CALL_EXPR_ARG (loc
, i
), 0,
17451 if (loc_descr
== NULL
)
17452 goto call_expansion_failed
;
17454 add_loc_descr (&ret
, loc_descr
);
17457 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
17458 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17459 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
17460 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17461 add_loc_descr (&ret
, ret1
);
17464 call_expansion_failed
:
17465 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
17466 /* There are no opcodes for these operations. */
17470 case PREINCREMENT_EXPR
:
17471 case PREDECREMENT_EXPR
:
17472 case POSTINCREMENT_EXPR
:
17473 case POSTDECREMENT_EXPR
:
17474 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
17475 /* There are no opcodes for these operations. */
17479 /* If we already want an address, see if there is INDIRECT_REF inside
17480 e.g. for &this->field. */
17483 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
17484 (loc
, want_address
== 2, context
);
17487 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
17488 && (ret
= cst_pool_loc_descr (loc
)))
17491 /* Otherwise, process the argument and look for the address. */
17492 if (!list_ret
&& !ret
)
17493 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
17497 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
17503 if (DECL_THREAD_LOCAL_P (loc
))
17506 enum dwarf_location_atom tls_op
;
17507 enum dtprel_bool dtprel
= dtprel_false
;
17509 if (targetm
.have_tls
)
17511 /* If this is not defined, we have no way to emit the
17513 if (!targetm
.asm_out
.output_dwarf_dtprel
)
17516 /* The way DW_OP_GNU_push_tls_address is specified, we
17517 can only look up addresses of objects in the current
17518 module. We used DW_OP_addr as first op, but that's
17519 wrong, because DW_OP_addr is relocated by the debug
17520 info consumer, while DW_OP_GNU_push_tls_address
17521 operand shouldn't be. */
17522 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
17524 dtprel
= dtprel_true
;
17525 /* We check for DWARF 5 here because gdb did not implement
17526 DW_OP_form_tls_address until after 7.12. */
17527 tls_op
= (dwarf_version
>= 5 ? DW_OP_form_tls_address
17528 : DW_OP_GNU_push_tls_address
);
17532 if (!targetm
.emutls
.debug_form_tls_address
17533 || !(dwarf_version
>= 3 || !dwarf_strict
))
17535 /* We stuffed the control variable into the DECL_VALUE_EXPR
17536 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
17537 no longer appear in gimple code. We used the control
17538 variable in specific so that we could pick it up here. */
17539 loc
= DECL_VALUE_EXPR (loc
);
17540 tls_op
= DW_OP_form_tls_address
;
17543 rtl
= rtl_for_decl_location (loc
);
17544 if (rtl
== NULL_RTX
)
17549 rtl
= XEXP (rtl
, 0);
17550 if (! CONSTANT_P (rtl
))
17553 ret
= new_addr_loc_descr (rtl
, dtprel
);
17554 ret1
= new_loc_descr (tls_op
, 0, 0);
17555 add_loc_descr (&ret
, ret1
);
17563 if (context
!= NULL
&& context
->dpi
!= NULL
17564 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
17566 /* We are generating code for a DWARF procedure and we want to access
17567 one of its arguments: find the appropriate argument offset and let
17568 the resolve_args_picking pass compute the offset that complies
17569 with the stack frame size. */
17573 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
17574 cursor
!= NULL_TREE
&& cursor
!= loc
;
17575 cursor
= TREE_CHAIN (cursor
), ++i
)
17577 /* If we are translating a DWARF procedure, all referenced parameters
17578 must belong to the current function. */
17579 gcc_assert (cursor
!= NULL_TREE
);
17581 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
17582 ret
->frame_offset_rel
= 1;
17588 if (DECL_HAS_VALUE_EXPR_P (loc
))
17589 return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc
),
17590 want_address
, context
);
17593 case FUNCTION_DECL
:
17596 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
17598 if (loc_list
&& loc_list
->first
)
17600 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
17601 have_address
= want_address
!= 0;
17604 rtl
= rtl_for_decl_location (loc
);
17605 if (rtl
== NULL_RTX
)
17607 if (TREE_CODE (loc
) != FUNCTION_DECL
17609 && current_function_decl
17610 && want_address
!= 1
17611 && ! DECL_IGNORED_P (loc
)
17612 && (INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17613 || POINTER_TYPE_P (TREE_TYPE (loc
)))
17614 && DECL_CONTEXT (loc
) == current_function_decl
17615 && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc
)))
17616 <= DWARF2_ADDR_SIZE
))
17618 dw_die_ref ref
= lookup_decl_die (loc
);
17619 ret
= new_loc_descr (DW_OP_GNU_variable_value
, 0, 0);
17622 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17623 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
17624 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17628 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
17629 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= loc
;
17633 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
17636 else if (CONST_INT_P (rtl
))
17638 HOST_WIDE_INT val
= INTVAL (rtl
);
17639 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17640 val
&= GET_MODE_MASK (DECL_MODE (loc
));
17641 ret
= int_loc_descriptor (val
);
17643 else if (GET_CODE (rtl
) == CONST_STRING
)
17645 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
17648 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
17649 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
17652 machine_mode mode
, mem_mode
;
17654 /* Certain constructs can only be represented at top-level. */
17655 if (want_address
== 2)
17657 ret
= loc_descriptor (rtl
, VOIDmode
,
17658 VAR_INIT_STATUS_INITIALIZED
);
17663 mode
= GET_MODE (rtl
);
17664 mem_mode
= VOIDmode
;
17668 mode
= get_address_mode (rtl
);
17669 rtl
= XEXP (rtl
, 0);
17672 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
17673 VAR_INIT_STATUS_INITIALIZED
);
17676 expansion_failed (loc
, rtl
,
17677 "failed to produce loc descriptor for rtl");
17683 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
17690 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17694 case TARGET_MEM_REF
:
17696 case DEBUG_EXPR_DECL
:
17699 case COMPOUND_EXPR
:
17700 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
17704 case VIEW_CONVERT_EXPR
:
17707 case NON_LVALUE_EXPR
:
17708 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
17711 case COMPONENT_REF
:
17712 case BIT_FIELD_REF
:
17714 case ARRAY_RANGE_REF
:
17715 case REALPART_EXPR
:
17716 case IMAGPART_EXPR
:
17719 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
17721 int unsignedp
, reversep
, volatilep
= 0;
17723 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
17724 &unsignedp
, &reversep
, &volatilep
);
17726 gcc_assert (obj
!= loc
);
17728 list_ret
= loc_list_from_tree_1 (obj
,
17730 && !bitpos
&& !offset
? 2 : 1,
17732 /* TODO: We can extract value of the small expression via shifting even
17733 for nonzero bitpos. */
17736 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
17738 expansion_failed (loc
, NULL_RTX
,
17739 "bitfield access");
17743 if (offset
!= NULL_TREE
)
17745 /* Variable offset. */
17746 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
17747 if (list_ret1
== 0)
17749 add_loc_list (&list_ret
, list_ret1
);
17752 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
17755 bytepos
= bitpos
/ BITS_PER_UNIT
;
17757 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
17758 else if (bytepos
< 0)
17759 loc_list_plus_const (list_ret
, bytepos
);
17766 if ((want_address
|| !tree_fits_shwi_p (loc
))
17767 && (ret
= cst_pool_loc_descr (loc
)))
17769 else if (want_address
== 2
17770 && tree_fits_shwi_p (loc
)
17771 && (ret
= address_of_int_loc_descriptor
17772 (int_size_in_bytes (TREE_TYPE (loc
)),
17773 tree_to_shwi (loc
))))
17775 else if (tree_fits_shwi_p (loc
))
17776 ret
= int_loc_descriptor (tree_to_shwi (loc
));
17777 else if (tree_fits_uhwi_p (loc
))
17778 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
17781 expansion_failed (loc
, NULL_RTX
,
17782 "Integer operand is not host integer");
17791 if ((ret
= cst_pool_loc_descr (loc
)))
17793 else if (TREE_CODE (loc
) == CONSTRUCTOR
)
17795 tree type
= TREE_TYPE (loc
);
17796 unsigned HOST_WIDE_INT size
= int_size_in_bytes (type
);
17797 unsigned HOST_WIDE_INT offset
= 0;
17798 unsigned HOST_WIDE_INT cnt
;
17799 constructor_elt
*ce
;
17801 if (TREE_CODE (type
) == RECORD_TYPE
)
17803 /* This is very limited, but it's enough to output
17804 pointers to member functions, as long as the
17805 referenced function is defined in the current
17806 translation unit. */
17807 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc
), cnt
, ce
)
17809 tree val
= ce
->value
;
17811 tree field
= ce
->index
;
17816 if (!field
|| DECL_BIT_FIELD (field
))
17818 expansion_failed (loc
, NULL_RTX
,
17819 "bitfield in record type constructor");
17820 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17825 HOST_WIDE_INT fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
17826 unsigned HOST_WIDE_INT pos
= int_byte_position (field
);
17827 gcc_assert (pos
+ fieldsize
<= size
);
17830 expansion_failed (loc
, NULL_RTX
,
17831 "out-of-order fields in record constructor");
17832 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17838 ret1
= new_loc_descr (DW_OP_piece
, pos
- offset
, 0);
17839 add_loc_descr (&ret
, ret1
);
17842 if (val
&& fieldsize
!= 0)
17844 ret1
= loc_descriptor_from_tree (val
, want_address
, context
);
17847 expansion_failed (loc
, NULL_RTX
,
17848 "unsupported expression in field");
17849 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17853 add_loc_descr (&ret
, ret1
);
17857 ret1
= new_loc_descr (DW_OP_piece
, fieldsize
, 0);
17858 add_loc_descr (&ret
, ret1
);
17859 offset
= pos
+ fieldsize
;
17863 if (offset
!= size
)
17865 ret1
= new_loc_descr (DW_OP_piece
, size
- offset
, 0);
17866 add_loc_descr (&ret
, ret1
);
17870 have_address
= !!want_address
;
17873 expansion_failed (loc
, NULL_RTX
,
17874 "constructor of non-record type");
17877 /* We can construct small constants here using int_loc_descriptor. */
17878 expansion_failed (loc
, NULL_RTX
,
17879 "constructor or constant not in constant pool");
17882 case TRUTH_AND_EXPR
:
17883 case TRUTH_ANDIF_EXPR
:
17888 case TRUTH_XOR_EXPR
:
17893 case TRUTH_OR_EXPR
:
17894 case TRUTH_ORIF_EXPR
:
17899 case FLOOR_DIV_EXPR
:
17900 case CEIL_DIV_EXPR
:
17901 case ROUND_DIV_EXPR
:
17902 case TRUNC_DIV_EXPR
:
17903 case EXACT_DIV_EXPR
:
17904 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17913 case FLOOR_MOD_EXPR
:
17914 case CEIL_MOD_EXPR
:
17915 case ROUND_MOD_EXPR
:
17916 case TRUNC_MOD_EXPR
:
17917 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17922 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17923 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17924 if (list_ret
== 0 || list_ret1
== 0)
17927 add_loc_list (&list_ret
, list_ret1
);
17930 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17931 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17932 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
17933 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
17934 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
17946 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
17949 case POINTER_PLUS_EXPR
:
17952 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
17954 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
17955 smarter to encode their opposite. The DW_OP_plus_uconst operation
17956 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
17957 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
17958 bytes, Y being the size of the operation that pushes the opposite
17959 of the addend. So let's choose the smallest representation. */
17960 const tree tree_addend
= TREE_OPERAND (loc
, 1);
17961 offset_int wi_addend
;
17962 HOST_WIDE_INT shwi_addend
;
17963 dw_loc_descr_ref loc_naddend
;
17965 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17969 /* Try to get the literal to push. It is the opposite of the addend,
17970 so as we rely on wrapping during DWARF evaluation, first decode
17971 the literal as a "DWARF-sized" signed number. */
17972 wi_addend
= wi::to_offset (tree_addend
);
17973 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
17974 shwi_addend
= wi_addend
.to_shwi ();
17975 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
17976 ? int_loc_descriptor (-shwi_addend
)
17979 if (loc_naddend
!= NULL
17980 && ((unsigned) size_of_uleb128 (shwi_addend
)
17981 > size_of_loc_descr (loc_naddend
)))
17983 add_loc_descr_to_each (list_ret
, loc_naddend
);
17984 add_loc_descr_to_each (list_ret
,
17985 new_loc_descr (DW_OP_minus
, 0, 0));
17989 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
17991 loc_naddend
= loc_cur
;
17992 loc_cur
= loc_cur
->dw_loc_next
;
17993 ggc_free (loc_naddend
);
17995 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
18005 goto do_comp_binop
;
18009 goto do_comp_binop
;
18013 goto do_comp_binop
;
18017 goto do_comp_binop
;
18020 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
18022 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
18023 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
18024 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
18040 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
18041 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
18042 if (list_ret
== 0 || list_ret1
== 0)
18045 add_loc_list (&list_ret
, list_ret1
);
18048 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
18051 case TRUTH_NOT_EXPR
:
18065 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
18069 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
18075 const enum tree_code code
=
18076 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
18078 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
18079 build2 (code
, integer_type_node
,
18080 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
18081 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
18088 dw_loc_descr_ref lhs
18089 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
18090 dw_loc_list_ref rhs
18091 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
18092 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
18094 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
18095 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
18098 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
18099 add_loc_descr_to_each (list_ret
, bra_node
);
18101 add_loc_list (&list_ret
, rhs
);
18102 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
18103 add_loc_descr_to_each (list_ret
, jump_node
);
18105 add_loc_descr_to_each (list_ret
, lhs
);
18106 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
18107 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
18109 /* ??? Need a node to point the skip at. Use a nop. */
18110 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
18111 add_loc_descr_to_each (list_ret
, tmp
);
18112 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
18113 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
18117 case FIX_TRUNC_EXPR
:
18121 /* Leave front-end specific codes as simply unknown. This comes
18122 up, for instance, with the C STMT_EXPR. */
18123 if ((unsigned int) TREE_CODE (loc
)
18124 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
18126 expansion_failed (loc
, NULL_RTX
,
18127 "language specific tree node");
18131 /* Otherwise this is a generic code; we should just lists all of
18132 these explicitly. We forgot one. */
18134 gcc_unreachable ();
18136 /* In a release build, we want to degrade gracefully: better to
18137 generate incomplete debugging information than to crash. */
18141 if (!ret
&& !list_ret
)
18144 if (want_address
== 2 && !have_address
18145 && (dwarf_version
>= 4 || !dwarf_strict
))
18147 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
18149 expansion_failed (loc
, NULL_RTX
,
18150 "DWARF address size mismatch");
18154 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
18156 add_loc_descr_to_each (list_ret
,
18157 new_loc_descr (DW_OP_stack_value
, 0, 0));
18160 /* Show if we can't fill the request for an address. */
18161 if (want_address
&& !have_address
)
18163 expansion_failed (loc
, NULL_RTX
,
18164 "Want address and only have value");
18168 gcc_assert (!ret
|| !list_ret
);
18170 /* If we've got an address and don't want one, dereference. */
18171 if (!want_address
&& have_address
)
18173 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
18175 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
18177 expansion_failed (loc
, NULL_RTX
,
18178 "DWARF address size mismatch");
18181 else if (size
== DWARF2_ADDR_SIZE
)
18184 op
= DW_OP_deref_size
;
18187 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
18189 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
18192 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
18197 /* Likewise, but strip useless DW_OP_nop operations in the resulting
18200 static dw_loc_list_ref
18201 loc_list_from_tree (tree loc
, int want_address
,
18202 struct loc_descr_context
*context
)
18204 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
18206 for (dw_loc_list_ref loc_cur
= result
;
18207 loc_cur
!= NULL
; loc_cur
= loc_cur
->dw_loc_next
)
18208 loc_descr_without_nops (loc_cur
->expr
);
18212 /* Same as above but return only single location expression. */
18213 static dw_loc_descr_ref
18214 loc_descriptor_from_tree (tree loc
, int want_address
,
18215 struct loc_descr_context
*context
)
18217 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
18220 if (ret
->dw_loc_next
)
18222 expansion_failed (loc
, NULL_RTX
,
18223 "Location list where only loc descriptor needed");
18229 /* Given a value, round it up to the lowest multiple of `boundary'
18230 which is not less than the value itself. */
18232 static inline HOST_WIDE_INT
18233 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
18235 return (((value
+ boundary
- 1) / boundary
) * boundary
);
18238 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
18239 pointer to the declared type for the relevant field variable, or return
18240 `integer_type_node' if the given node turns out to be an
18241 ERROR_MARK node. */
18244 field_type (const_tree decl
)
18248 if (TREE_CODE (decl
) == ERROR_MARK
)
18249 return integer_type_node
;
18251 type
= DECL_BIT_FIELD_TYPE (decl
);
18252 if (type
== NULL_TREE
)
18253 type
= TREE_TYPE (decl
);
18258 /* Given a pointer to a tree node, return the alignment in bits for
18259 it, or else return BITS_PER_WORD if the node actually turns out to
18260 be an ERROR_MARK node. */
18262 static inline unsigned
18263 simple_type_align_in_bits (const_tree type
)
18265 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
18268 static inline unsigned
18269 simple_decl_align_in_bits (const_tree decl
)
18271 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
18274 /* Return the result of rounding T up to ALIGN. */
18276 static inline offset_int
18277 round_up_to_align (const offset_int
&t
, unsigned int align
)
18279 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
18282 /* Compute the size of TYPE in bytes. If possible, return NULL and store the
18283 size as an integer constant in CST_SIZE. Otherwise, if possible, return a
18284 DWARF expression that computes the size. Return NULL and set CST_SIZE to -1
18285 if we fail to return the size in one of these two forms. */
18287 static dw_loc_descr_ref
18288 type_byte_size (const_tree type
, HOST_WIDE_INT
*cst_size
)
18291 struct loc_descr_context ctx
;
18293 /* Return a constant integer in priority, if possible. */
18294 *cst_size
= int_size_in_bytes (type
);
18295 if (*cst_size
!= -1)
18298 ctx
.context_type
= const_cast<tree
> (type
);
18299 ctx
.base_decl
= NULL_TREE
;
18301 ctx
.placeholder_arg
= false;
18302 ctx
.placeholder_seen
= false;
18304 type
= TYPE_MAIN_VARIANT (type
);
18305 tree_size
= TYPE_SIZE_UNIT (type
);
18306 return ((tree_size
!= NULL_TREE
)
18307 ? loc_descriptor_from_tree (tree_size
, 0, &ctx
)
18311 /* Helper structure for RECORD_TYPE processing. */
18314 /* Root RECORD_TYPE. It is needed to generate data member location
18315 descriptions in variable-length records (VLR), but also to cope with
18316 variants, which are composed of nested structures multiplexed with
18317 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
18318 function processing a FIELD_DECL, it is required to be non null. */
18320 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
18321 QUAL_UNION_TYPE), this holds an expression that computes the offset for
18322 this variant part as part of the root record (in storage units). For
18323 regular records, it must be NULL_TREE. */
18324 tree variant_part_offset
;
18327 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
18328 addressed byte of the "containing object" for the given FIELD_DECL. If
18329 possible, return a native constant through CST_OFFSET (in which case NULL is
18330 returned); otherwise return a DWARF expression that computes the offset.
18332 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
18333 that offset is, either because the argument turns out to be a pointer to an
18334 ERROR_MARK node, or because the offset expression is too complex for us.
18336 CTX is required: see the comment for VLR_CONTEXT. */
18338 static dw_loc_descr_ref
18339 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
18340 HOST_WIDE_INT
*cst_offset
)
18343 dw_loc_list_ref loc_result
;
18347 if (TREE_CODE (decl
) == ERROR_MARK
)
18350 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
18352 /* We cannot handle variable bit offsets at the moment, so abort if it's the
18354 if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
)
18357 #ifdef PCC_BITFIELD_TYPE_MATTERS
18358 /* We used to handle only constant offsets in all cases. Now, we handle
18359 properly dynamic byte offsets only when PCC bitfield type doesn't
18361 if (PCC_BITFIELD_TYPE_MATTERS
18362 && TREE_CODE (DECL_FIELD_OFFSET (decl
)) == INTEGER_CST
)
18364 offset_int object_offset_in_bits
;
18365 offset_int object_offset_in_bytes
;
18366 offset_int bitpos_int
;
18368 tree field_size_tree
;
18369 offset_int deepest_bitpos
;
18370 offset_int field_size_in_bits
;
18371 unsigned int type_align_in_bits
;
18372 unsigned int decl_align_in_bits
;
18373 offset_int type_size_in_bits
;
18375 bitpos_int
= wi::to_offset (bit_position (decl
));
18376 type
= field_type (decl
);
18377 type_size_in_bits
= offset_int_type_size_in_bits (type
);
18378 type_align_in_bits
= simple_type_align_in_bits (type
);
18380 field_size_tree
= DECL_SIZE (decl
);
18382 /* The size could be unspecified if there was an error, or for
18383 a flexible array member. */
18384 if (!field_size_tree
)
18385 field_size_tree
= bitsize_zero_node
;
18387 /* If the size of the field is not constant, use the type size. */
18388 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
18389 field_size_in_bits
= wi::to_offset (field_size_tree
);
18391 field_size_in_bits
= type_size_in_bits
;
18393 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
18395 /* The GCC front-end doesn't make any attempt to keep track of the
18396 starting bit offset (relative to the start of the containing
18397 structure type) of the hypothetical "containing object" for a
18398 bit-field. Thus, when computing the byte offset value for the
18399 start of the "containing object" of a bit-field, we must deduce
18400 this information on our own. This can be rather tricky to do in
18401 some cases. For example, handling the following structure type
18402 definition when compiling for an i386/i486 target (which only
18403 aligns long long's to 32-bit boundaries) can be very tricky:
18405 struct S { int field1; long long field2:31; };
18407 Fortunately, there is a simple rule-of-thumb which can be used
18408 in such cases. When compiling for an i386/i486, GCC will
18409 allocate 8 bytes for the structure shown above. It decides to
18410 do this based upon one simple rule for bit-field allocation.
18411 GCC allocates each "containing object" for each bit-field at
18412 the first (i.e. lowest addressed) legitimate alignment boundary
18413 (based upon the required minimum alignment for the declared
18414 type of the field) which it can possibly use, subject to the
18415 condition that there is still enough available space remaining
18416 in the containing object (when allocated at the selected point)
18417 to fully accommodate all of the bits of the bit-field itself.
18419 This simple rule makes it obvious why GCC allocates 8 bytes for
18420 each object of the structure type shown above. When looking
18421 for a place to allocate the "containing object" for `field2',
18422 the compiler simply tries to allocate a 64-bit "containing
18423 object" at each successive 32-bit boundary (starting at zero)
18424 until it finds a place to allocate that 64- bit field such that
18425 at least 31 contiguous (and previously unallocated) bits remain
18426 within that selected 64 bit field. (As it turns out, for the
18427 example above, the compiler finds it is OK to allocate the
18428 "containing object" 64-bit field at bit-offset zero within the
18431 Here we attempt to work backwards from the limited set of facts
18432 we're given, and we try to deduce from those facts, where GCC
18433 must have believed that the containing object started (within
18434 the structure type). The value we deduce is then used (by the
18435 callers of this routine) to generate DW_AT_location and
18436 DW_AT_bit_offset attributes for fields (both bit-fields and, in
18437 the case of DW_AT_location, regular fields as well). */
18439 /* Figure out the bit-distance from the start of the structure to
18440 the "deepest" bit of the bit-field. */
18441 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
18443 /* This is the tricky part. Use some fancy footwork to deduce
18444 where the lowest addressed bit of the containing object must
18446 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18448 /* Round up to type_align by default. This works best for
18450 object_offset_in_bits
18451 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
18453 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
18455 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18457 /* Round up to decl_align instead. */
18458 object_offset_in_bits
18459 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
18462 object_offset_in_bytes
18463 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
18464 if (ctx
->variant_part_offset
== NULL_TREE
)
18466 *cst_offset
= object_offset_in_bytes
.to_shwi ();
18469 tree_result
= wide_int_to_tree (sizetype
, object_offset_in_bytes
);
18472 #endif /* PCC_BITFIELD_TYPE_MATTERS */
18473 tree_result
= byte_position (decl
);
18475 if (ctx
->variant_part_offset
!= NULL_TREE
)
18476 tree_result
= fold_build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
18477 ctx
->variant_part_offset
, tree_result
);
18479 /* If the byte offset is a constant, it's simplier to handle a native
18480 constant rather than a DWARF expression. */
18481 if (TREE_CODE (tree_result
) == INTEGER_CST
)
18483 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
18486 struct loc_descr_context loc_ctx
= {
18487 ctx
->struct_type
, /* context_type */
18488 NULL_TREE
, /* base_decl */
18490 false, /* placeholder_arg */
18491 false /* placeholder_seen */
18493 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
18495 /* We want a DWARF expression: abort if we only have a location list with
18496 multiple elements. */
18497 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
18500 return loc_result
->expr
;
18503 /* The following routines define various Dwarf attributes and any data
18504 associated with them. */
18506 /* Add a location description attribute value to a DIE.
18508 This emits location attributes suitable for whole variables and
18509 whole parameters. Note that the location attributes for struct fields are
18510 generated by the routine `data_member_location_attribute' below. */
18513 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
18514 dw_loc_list_ref descr
)
18518 if (single_element_loc_list_p (descr
))
18519 add_AT_loc (die
, attr_kind
, descr
->expr
);
18521 add_AT_loc_list (die
, attr_kind
, descr
);
18524 /* Add DW_AT_accessibility attribute to DIE if needed. */
18527 add_accessibility_attribute (dw_die_ref die
, tree decl
)
18529 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18530 children, otherwise the default is DW_ACCESS_public. In DWARF2
18531 the default has always been DW_ACCESS_public. */
18532 if (TREE_PROTECTED (decl
))
18533 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18534 else if (TREE_PRIVATE (decl
))
18536 if (dwarf_version
== 2
18537 || die
->die_parent
== NULL
18538 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
18539 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18541 else if (dwarf_version
> 2
18543 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
18544 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18547 /* Attach the specialized form of location attribute used for data members of
18548 struct and union types. In the special case of a FIELD_DECL node which
18549 represents a bit-field, the "offset" part of this special location
18550 descriptor must indicate the distance in bytes from the lowest-addressed
18551 byte of the containing struct or union type to the lowest-addressed byte of
18552 the "containing object" for the bit-field. (See the `field_byte_offset'
18555 For any given bit-field, the "containing object" is a hypothetical object
18556 (of some integral or enum type) within which the given bit-field lives. The
18557 type of this hypothetical "containing object" is always the same as the
18558 declared type of the individual bit-field itself (for GCC anyway... the
18559 DWARF spec doesn't actually mandate this). Note that it is the size (in
18560 bytes) of the hypothetical "containing object" which will be given in the
18561 DW_AT_byte_size attribute for this bit-field. (See the
18562 `byte_size_attribute' function below.) It is also used when calculating the
18563 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
18566 CTX is required: see the comment for VLR_CONTEXT. */
18569 add_data_member_location_attribute (dw_die_ref die
,
18571 struct vlr_context
*ctx
)
18573 HOST_WIDE_INT offset
;
18574 dw_loc_descr_ref loc_descr
= 0;
18576 if (TREE_CODE (decl
) == TREE_BINFO
)
18578 /* We're working on the TAG_inheritance for a base class. */
18579 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
18581 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
18582 aren't at a fixed offset from all (sub)objects of the same
18583 type. We need to extract the appropriate offset from our
18584 vtable. The following dwarf expression means
18586 BaseAddr = ObAddr + *((*ObAddr) - Offset)
18588 This is specific to the V3 ABI, of course. */
18590 dw_loc_descr_ref tmp
;
18592 /* Make a copy of the object address. */
18593 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
18594 add_loc_descr (&loc_descr
, tmp
);
18596 /* Extract the vtable address. */
18597 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18598 add_loc_descr (&loc_descr
, tmp
);
18600 /* Calculate the address of the offset. */
18601 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
18602 gcc_assert (offset
< 0);
18604 tmp
= int_loc_descriptor (-offset
);
18605 add_loc_descr (&loc_descr
, tmp
);
18606 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
18607 add_loc_descr (&loc_descr
, tmp
);
18609 /* Extract the offset. */
18610 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18611 add_loc_descr (&loc_descr
, tmp
);
18613 /* Add it to the object address. */
18614 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
18615 add_loc_descr (&loc_descr
, tmp
);
18618 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
18622 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
18624 /* If loc_descr is available then we know the field offset is dynamic.
18625 However, GDB does not handle dynamic field offsets very well at the
18627 if (loc_descr
!= NULL
&& gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
)
18633 /* Data member location evalutation starts with the base address on the
18634 stack. Compute the field offset and add it to this base address. */
18635 else if (loc_descr
!= NULL
)
18636 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
18641 /* While DW_AT_data_bit_offset has been added already in DWARF4,
18642 e.g. GDB only added support to it in November 2016. For DWARF5
18643 we need newer debug info consumers anyway. We might change this
18644 to dwarf_version >= 4 once most consumers catched up. */
18645 if (dwarf_version
>= 5
18646 && TREE_CODE (decl
) == FIELD_DECL
18647 && DECL_BIT_FIELD_TYPE (decl
))
18649 tree off
= bit_position (decl
);
18650 if (tree_fits_uhwi_p (off
) && get_AT (die
, DW_AT_bit_size
))
18652 remove_AT (die
, DW_AT_byte_size
);
18653 remove_AT (die
, DW_AT_bit_offset
);
18654 add_AT_unsigned (die
, DW_AT_data_bit_offset
, tree_to_uhwi (off
));
18658 if (dwarf_version
> 2)
18660 /* Don't need to output a location expression, just the constant. */
18662 add_AT_int (die
, DW_AT_data_member_location
, offset
);
18664 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
18669 enum dwarf_location_atom op
;
18671 /* The DWARF2 standard says that we should assume that the structure
18672 address is already on the stack, so we can specify a structure
18673 field address by using DW_OP_plus_uconst. */
18674 op
= DW_OP_plus_uconst
;
18675 loc_descr
= new_loc_descr (op
, offset
, 0);
18679 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
18682 /* Writes integer values to dw_vec_const array. */
18685 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
18689 *dest
++ = val
& 0xff;
18695 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
18697 static HOST_WIDE_INT
18698 extract_int (const unsigned char *src
, unsigned int size
)
18700 HOST_WIDE_INT val
= 0;
18706 val
|= *--src
& 0xff;
18712 /* Writes wide_int values to dw_vec_const array. */
18715 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
18719 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
18721 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
18725 /* We'd have to extend this code to support odd sizes. */
18726 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
18728 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
18730 if (WORDS_BIG_ENDIAN
)
18731 for (i
= n
- 1; i
>= 0; i
--)
18733 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18734 dest
+= sizeof (HOST_WIDE_INT
);
18737 for (i
= 0; i
< n
; i
++)
18739 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18740 dest
+= sizeof (HOST_WIDE_INT
);
18744 /* Writes floating point values to dw_vec_const array. */
18747 insert_float (const_rtx rtl
, unsigned char *array
)
18751 scalar_float_mode mode
= as_a
<scalar_float_mode
> (GET_MODE (rtl
));
18753 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), mode
);
18755 /* real_to_target puts 32-bit pieces in each long. Pack them. */
18756 for (i
= 0; i
< GET_MODE_SIZE (mode
) / 4; i
++)
18758 insert_int (val
[i
], 4, array
);
18763 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
18764 does not have a "location" either in memory or in a register. These
18765 things can arise in GNU C when a constant is passed as an actual parameter
18766 to an inlined function. They can also arise in C++ where declared
18767 constants do not necessarily get memory "homes". */
18770 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
18772 switch (GET_CODE (rtl
))
18776 HOST_WIDE_INT val
= INTVAL (rtl
);
18779 add_AT_int (die
, DW_AT_const_value
, val
);
18781 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
18785 case CONST_WIDE_INT
:
18787 wide_int w1
= rtx_mode_t (rtl
, MAX_MODE_INT
);
18788 unsigned int prec
= MIN (wi::min_precision (w1
, UNSIGNED
),
18789 (unsigned int)CONST_WIDE_INT_NUNITS (rtl
) * HOST_BITS_PER_WIDE_INT
);
18790 wide_int w
= wi::zext (w1
, prec
);
18791 add_AT_wide (die
, DW_AT_const_value
, w
);
18796 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
18797 floating-point constant. A CONST_DOUBLE is used whenever the
18798 constant requires more than one word in order to be adequately
18800 if (TARGET_SUPPORTS_WIDE_INT
== 0
18801 && !SCALAR_FLOAT_MODE_P (GET_MODE (rtl
)))
18802 add_AT_double (die
, DW_AT_const_value
,
18803 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
18806 scalar_float_mode mode
= as_a
<scalar_float_mode
> (GET_MODE (rtl
));
18807 unsigned int length
= GET_MODE_SIZE (mode
);
18808 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
18810 insert_float (rtl
, array
);
18811 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
18817 machine_mode mode
= GET_MODE (rtl
);
18818 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
18819 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
18820 unsigned char *array
18821 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
18824 machine_mode imode
= GET_MODE_INNER (mode
);
18826 switch (GET_MODE_CLASS (mode
))
18828 case MODE_VECTOR_INT
:
18829 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18831 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18832 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
18836 case MODE_VECTOR_FLOAT
:
18837 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18839 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18840 insert_float (elt
, p
);
18845 gcc_unreachable ();
18848 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
18853 if (dwarf_version
>= 4 || !dwarf_strict
)
18855 dw_loc_descr_ref loc_result
;
18856 resolve_one_addr (&rtl
);
18858 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
18859 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
18860 add_AT_loc (die
, DW_AT_location
, loc_result
);
18861 vec_safe_push (used_rtx_array
, rtl
);
18867 if (CONSTANT_P (XEXP (rtl
, 0)))
18868 return add_const_value_attribute (die
, XEXP (rtl
, 0));
18871 if (!const_ok_for_output (rtl
))
18875 if (dwarf_version
>= 4 || !dwarf_strict
)
18880 /* In cases where an inlined instance of an inline function is passed
18881 the address of an `auto' variable (which is local to the caller) we
18882 can get a situation where the DECL_RTL of the artificial local
18883 variable (for the inlining) which acts as a stand-in for the
18884 corresponding formal parameter (of the inline function) will look
18885 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
18886 exactly a compile-time constant expression, but it isn't the address
18887 of the (artificial) local variable either. Rather, it represents the
18888 *value* which the artificial local variable always has during its
18889 lifetime. We currently have no way to represent such quasi-constant
18890 values in Dwarf, so for now we just punt and generate nothing. */
18898 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
18899 && MEM_READONLY_P (rtl
)
18900 && GET_MODE (rtl
) == BLKmode
)
18902 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
18908 /* No other kinds of rtx should be possible here. */
18909 gcc_unreachable ();
18914 /* Determine whether the evaluation of EXPR references any variables
18915 or functions which aren't otherwise used (and therefore may not be
18918 reference_to_unused (tree
* tp
, int * walk_subtrees
,
18919 void * data ATTRIBUTE_UNUSED
)
18921 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
18922 *walk_subtrees
= 0;
18924 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
18925 && ! TREE_ASM_WRITTEN (*tp
))
18927 /* ??? The C++ FE emits debug information for using decls, so
18928 putting gcc_unreachable here falls over. See PR31899. For now
18929 be conservative. */
18930 else if (!symtab
->global_info_ready
&& VAR_OR_FUNCTION_DECL_P (*tp
))
18932 else if (VAR_P (*tp
))
18934 varpool_node
*node
= varpool_node::get (*tp
);
18935 if (!node
|| !node
->definition
)
18938 else if (TREE_CODE (*tp
) == FUNCTION_DECL
18939 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
18941 /* The call graph machinery must have finished analyzing,
18942 optimizing and gimplifying the CU by now.
18943 So if *TP has no call graph node associated
18944 to it, it means *TP will not be emitted. */
18945 if (!cgraph_node::get (*tp
))
18948 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
18954 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
18955 for use in a later add_const_value_attribute call. */
18958 rtl_for_decl_init (tree init
, tree type
)
18960 rtx rtl
= NULL_RTX
;
18964 /* If a variable is initialized with a string constant without embedded
18965 zeros, build CONST_STRING. */
18966 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
18968 tree enttype
= TREE_TYPE (type
);
18969 tree domain
= TYPE_DOMAIN (type
);
18970 scalar_int_mode mode
;
18972 if (is_int_mode (TYPE_MODE (enttype
), &mode
)
18973 && GET_MODE_SIZE (mode
) == 1
18975 && integer_zerop (TYPE_MIN_VALUE (domain
))
18976 && compare_tree_int (TYPE_MAX_VALUE (domain
),
18977 TREE_STRING_LENGTH (init
) - 1) == 0
18978 && ((size_t) TREE_STRING_LENGTH (init
)
18979 == strlen (TREE_STRING_POINTER (init
)) + 1))
18981 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
18982 ggc_strdup (TREE_STRING_POINTER (init
)));
18983 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
18984 MEM_READONLY_P (rtl
) = 1;
18987 /* Other aggregates, and complex values, could be represented using
18989 else if (AGGREGATE_TYPE_P (type
)
18990 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
18991 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
18992 || TREE_CODE (type
) == COMPLEX_TYPE
)
18994 /* Vectors only work if their mode is supported by the target.
18995 FIXME: generic vectors ought to work too. */
18996 else if (TREE_CODE (type
) == VECTOR_TYPE
18997 && !VECTOR_MODE_P (TYPE_MODE (type
)))
18999 /* If the initializer is something that we know will expand into an
19000 immediate RTL constant, expand it now. We must be careful not to
19001 reference variables which won't be output. */
19002 else if (initializer_constant_valid_p (init
, type
)
19003 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
19005 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
19007 if (TREE_CODE (type
) == VECTOR_TYPE
)
19008 switch (TREE_CODE (init
))
19013 if (TREE_CONSTANT (init
))
19015 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
19016 bool constant_p
= true;
19018 unsigned HOST_WIDE_INT ix
;
19020 /* Even when ctor is constant, it might contain non-*_CST
19021 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
19022 belong into VECTOR_CST nodes. */
19023 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
19024 if (!CONSTANT_CLASS_P (value
))
19026 constant_p
= false;
19032 init
= build_vector_from_ctor (type
, elts
);
19042 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
19044 /* If expand_expr returns a MEM, it wasn't immediate. */
19045 gcc_assert (!rtl
|| !MEM_P (rtl
));
19051 /* Generate RTL for the variable DECL to represent its location. */
19054 rtl_for_decl_location (tree decl
)
19058 /* Here we have to decide where we are going to say the parameter "lives"
19059 (as far as the debugger is concerned). We only have a couple of
19060 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
19062 DECL_RTL normally indicates where the parameter lives during most of the
19063 activation of the function. If optimization is enabled however, this
19064 could be either NULL or else a pseudo-reg. Both of those cases indicate
19065 that the parameter doesn't really live anywhere (as far as the code
19066 generation parts of GCC are concerned) during most of the function's
19067 activation. That will happen (for example) if the parameter is never
19068 referenced within the function.
19070 We could just generate a location descriptor here for all non-NULL
19071 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
19072 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
19073 where DECL_RTL is NULL or is a pseudo-reg.
19075 Note however that we can only get away with using DECL_INCOMING_RTL as
19076 a backup substitute for DECL_RTL in certain limited cases. In cases
19077 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
19078 we can be sure that the parameter was passed using the same type as it is
19079 declared to have within the function, and that its DECL_INCOMING_RTL
19080 points us to a place where a value of that type is passed.
19082 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
19083 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
19084 because in these cases DECL_INCOMING_RTL points us to a value of some
19085 type which is *different* from the type of the parameter itself. Thus,
19086 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
19087 such cases, the debugger would end up (for example) trying to fetch a
19088 `float' from a place which actually contains the first part of a
19089 `double'. That would lead to really incorrect and confusing
19090 output at debug-time.
19092 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
19093 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
19094 are a couple of exceptions however. On little-endian machines we can
19095 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
19096 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
19097 an integral type that is smaller than TREE_TYPE (decl). These cases arise
19098 when (on a little-endian machine) a non-prototyped function has a
19099 parameter declared to be of type `short' or `char'. In such cases,
19100 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
19101 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
19102 passed `int' value. If the debugger then uses that address to fetch
19103 a `short' or a `char' (on a little-endian machine) the result will be
19104 the correct data, so we allow for such exceptional cases below.
19106 Note that our goal here is to describe the place where the given formal
19107 parameter lives during most of the function's activation (i.e. between the
19108 end of the prologue and the start of the epilogue). We'll do that as best
19109 as we can. Note however that if the given formal parameter is modified
19110 sometime during the execution of the function, then a stack backtrace (at
19111 debug-time) will show the function as having been called with the *new*
19112 value rather than the value which was originally passed in. This happens
19113 rarely enough that it is not a major problem, but it *is* a problem, and
19114 I'd like to fix it.
19116 A future version of dwarf2out.c may generate two additional attributes for
19117 any given DW_TAG_formal_parameter DIE which will describe the "passed
19118 type" and the "passed location" for the given formal parameter in addition
19119 to the attributes we now generate to indicate the "declared type" and the
19120 "active location" for each parameter. This additional set of attributes
19121 could be used by debuggers for stack backtraces. Separately, note that
19122 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
19123 This happens (for example) for inlined-instances of inline function formal
19124 parameters which are never referenced. This really shouldn't be
19125 happening. All PARM_DECL nodes should get valid non-NULL
19126 DECL_INCOMING_RTL values. FIXME. */
19128 /* Use DECL_RTL as the "location" unless we find something better. */
19129 rtl
= DECL_RTL_IF_SET (decl
);
19131 /* When generating abstract instances, ignore everything except
19132 constants, symbols living in memory, and symbols living in
19133 fixed registers. */
19134 if (! reload_completed
)
19137 && (CONSTANT_P (rtl
)
19139 && CONSTANT_P (XEXP (rtl
, 0)))
19142 && TREE_STATIC (decl
))))
19144 rtl
= targetm
.delegitimize_address (rtl
);
19149 else if (TREE_CODE (decl
) == PARM_DECL
)
19151 if (rtl
== NULL_RTX
19152 || is_pseudo_reg (rtl
)
19154 && is_pseudo_reg (XEXP (rtl
, 0))
19155 && DECL_INCOMING_RTL (decl
)
19156 && MEM_P (DECL_INCOMING_RTL (decl
))
19157 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
19159 tree declared_type
= TREE_TYPE (decl
);
19160 tree passed_type
= DECL_ARG_TYPE (decl
);
19161 machine_mode dmode
= TYPE_MODE (declared_type
);
19162 machine_mode pmode
= TYPE_MODE (passed_type
);
19164 /* This decl represents a formal parameter which was optimized out.
19165 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
19166 all cases where (rtl == NULL_RTX) just below. */
19167 if (dmode
== pmode
)
19168 rtl
= DECL_INCOMING_RTL (decl
);
19169 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
19170 && SCALAR_INT_MODE_P (dmode
)
19171 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
19172 && DECL_INCOMING_RTL (decl
))
19174 rtx inc
= DECL_INCOMING_RTL (decl
);
19177 else if (MEM_P (inc
))
19179 if (BYTES_BIG_ENDIAN
)
19180 rtl
= adjust_address_nv (inc
, dmode
,
19181 GET_MODE_SIZE (pmode
)
19182 - GET_MODE_SIZE (dmode
));
19189 /* If the parm was passed in registers, but lives on the stack, then
19190 make a big endian correction if the mode of the type of the
19191 parameter is not the same as the mode of the rtl. */
19192 /* ??? This is the same series of checks that are made in dbxout.c before
19193 we reach the big endian correction code there. It isn't clear if all
19194 of these checks are necessary here, but keeping them all is the safe
19196 else if (MEM_P (rtl
)
19197 && XEXP (rtl
, 0) != const0_rtx
19198 && ! CONSTANT_P (XEXP (rtl
, 0))
19199 /* Not passed in memory. */
19200 && !MEM_P (DECL_INCOMING_RTL (decl
))
19201 /* Not passed by invisible reference. */
19202 && (!REG_P (XEXP (rtl
, 0))
19203 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
19204 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
19205 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
19206 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
19209 /* Big endian correction check. */
19210 && BYTES_BIG_ENDIAN
19211 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
19212 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
19215 machine_mode addr_mode
= get_address_mode (rtl
);
19216 int offset
= (UNITS_PER_WORD
19217 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
19219 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
19220 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
19223 else if (VAR_P (decl
)
19226 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
)))
19228 machine_mode addr_mode
= get_address_mode (rtl
);
19229 HOST_WIDE_INT offset
= byte_lowpart_offset (TYPE_MODE (TREE_TYPE (decl
)),
19232 /* If a variable is declared "register" yet is smaller than
19233 a register, then if we store the variable to memory, it
19234 looks like we're storing a register-sized value, when in
19235 fact we are not. We need to adjust the offset of the
19236 storage location to reflect the actual value's bytes,
19237 else gdb will not be able to display it. */
19239 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
19240 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
19243 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
19244 and will have been substituted directly into all expressions that use it.
19245 C does not have such a concept, but C++ and other languages do. */
19246 if (!rtl
&& VAR_P (decl
) && DECL_INITIAL (decl
))
19247 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
19250 rtl
= targetm
.delegitimize_address (rtl
);
19252 /* If we don't look past the constant pool, we risk emitting a
19253 reference to a constant pool entry that isn't referenced from
19254 code, and thus is not emitted. */
19256 rtl
= avoid_constant_pool_reference (rtl
);
19258 /* Try harder to get a rtl. If this symbol ends up not being emitted
19259 in the current CU, resolve_addr will remove the expression referencing
19261 if (rtl
== NULL_RTX
19263 && !DECL_EXTERNAL (decl
)
19264 && TREE_STATIC (decl
)
19265 && DECL_NAME (decl
)
19266 && !DECL_HARD_REGISTER (decl
)
19267 && DECL_MODE (decl
) != VOIDmode
)
19269 rtl
= make_decl_rtl_for_debug (decl
);
19271 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
19272 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
19279 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
19280 returned. If so, the decl for the COMMON block is returned, and the
19281 value is the offset into the common block for the symbol. */
19284 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
19286 tree val_expr
, cvar
;
19288 HOST_WIDE_INT bitsize
, bitpos
;
19290 int unsignedp
, reversep
, volatilep
= 0;
19292 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
19293 it does not have a value (the offset into the common area), or if it
19294 is thread local (as opposed to global) then it isn't common, and shouldn't
19295 be handled as such. */
19297 || !TREE_STATIC (decl
)
19298 || !DECL_HAS_VALUE_EXPR_P (decl
)
19302 val_expr
= DECL_VALUE_EXPR (decl
);
19303 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
19306 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
19307 &unsignedp
, &reversep
, &volatilep
);
19309 if (cvar
== NULL_TREE
19311 || DECL_ARTIFICIAL (cvar
)
19312 || !TREE_PUBLIC (cvar
))
19316 if (offset
!= NULL
)
19318 if (!tree_fits_shwi_p (offset
))
19320 *value
= tree_to_shwi (offset
);
19323 *value
+= bitpos
/ BITS_PER_UNIT
;
19328 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
19329 data attribute for a variable or a parameter. We generate the
19330 DW_AT_const_value attribute only in those cases where the given variable
19331 or parameter does not have a true "location" either in memory or in a
19332 register. This can happen (for example) when a constant is passed as an
19333 actual argument in a call to an inline function. (It's possible that
19334 these things can crop up in other ways also.) Note that one type of
19335 constant value which can be passed into an inlined function is a constant
19336 pointer. This can happen for example if an actual argument in an inlined
19337 function call evaluates to a compile-time constant address.
19339 CACHE_P is true if it is worth caching the location list for DECL,
19340 so that future calls can reuse it rather than regenerate it from scratch.
19341 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
19342 since we will need to refer to them each time the function is inlined. */
19345 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
19348 dw_loc_list_ref list
;
19349 var_loc_list
*loc_list
;
19350 cached_dw_loc_list
*cache
;
19355 if (TREE_CODE (decl
) == ERROR_MARK
)
19358 if (get_AT (die
, DW_AT_location
)
19359 || get_AT (die
, DW_AT_const_value
))
19362 gcc_assert (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
19363 || TREE_CODE (decl
) == RESULT_DECL
);
19365 /* Try to get some constant RTL for this decl, and use that as the value of
19368 rtl
= rtl_for_decl_location (decl
);
19369 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19370 && add_const_value_attribute (die
, rtl
))
19373 /* See if we have single element location list that is equivalent to
19374 a constant value. That way we are better to use add_const_value_attribute
19375 rather than expanding constant value equivalent. */
19376 loc_list
= lookup_decl_loc (decl
);
19379 && loc_list
->first
->next
== NULL
19380 && NOTE_P (loc_list
->first
->loc
)
19381 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
19382 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
19384 struct var_loc_node
*node
;
19386 node
= loc_list
->first
;
19387 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
19388 if (GET_CODE (rtl
) == EXPR_LIST
)
19389 rtl
= XEXP (rtl
, 0);
19390 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19391 && add_const_value_attribute (die
, rtl
))
19394 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
19395 list several times. See if we've already cached the contents. */
19397 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
19401 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
19403 list
= cache
->loc_list
;
19407 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
19409 /* It is usually worth caching this result if the decl is from
19410 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
19411 if (cache_p
&& list
&& list
->dw_loc_next
)
19413 cached_dw_loc_list
**slot
19414 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
19417 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
19418 cache
->decl_id
= DECL_UID (decl
);
19419 cache
->loc_list
= list
;
19425 add_AT_location_description (die
, DW_AT_location
, list
);
19428 /* None of that worked, so it must not really have a location;
19429 try adding a constant value attribute from the DECL_INITIAL. */
19430 return tree_add_const_value_attribute_for_decl (die
, decl
);
19433 /* Helper function for tree_add_const_value_attribute. Natively encode
19434 initializer INIT into an array. Return true if successful. */
19437 native_encode_initializer (tree init
, unsigned char *array
, int size
)
19441 if (init
== NULL_TREE
)
19445 switch (TREE_CODE (init
))
19448 type
= TREE_TYPE (init
);
19449 if (TREE_CODE (type
) == ARRAY_TYPE
)
19451 tree enttype
= TREE_TYPE (type
);
19452 scalar_int_mode mode
;
19454 if (!is_int_mode (TYPE_MODE (enttype
), &mode
)
19455 || GET_MODE_SIZE (mode
) != 1)
19457 if (int_size_in_bytes (type
) != size
)
19459 if (size
> TREE_STRING_LENGTH (init
))
19461 memcpy (array
, TREE_STRING_POINTER (init
),
19462 TREE_STRING_LENGTH (init
));
19463 memset (array
+ TREE_STRING_LENGTH (init
),
19464 '\0', size
- TREE_STRING_LENGTH (init
));
19467 memcpy (array
, TREE_STRING_POINTER (init
), size
);
19472 type
= TREE_TYPE (init
);
19473 if (int_size_in_bytes (type
) != size
)
19475 if (TREE_CODE (type
) == ARRAY_TYPE
)
19477 HOST_WIDE_INT min_index
;
19478 unsigned HOST_WIDE_INT cnt
;
19479 int curpos
= 0, fieldsize
;
19480 constructor_elt
*ce
;
19482 if (TYPE_DOMAIN (type
) == NULL_TREE
19483 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
19486 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
19487 if (fieldsize
<= 0)
19490 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
19491 memset (array
, '\0', size
);
19492 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19494 tree val
= ce
->value
;
19495 tree index
= ce
->index
;
19497 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19498 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
19501 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
19506 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
19509 curpos
= pos
+ fieldsize
;
19510 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19512 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
19513 - tree_to_shwi (TREE_OPERAND (index
, 0));
19514 while (count
-- > 0)
19517 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
19518 curpos
+= fieldsize
;
19521 gcc_assert (curpos
<= size
);
19525 else if (TREE_CODE (type
) == RECORD_TYPE
19526 || TREE_CODE (type
) == UNION_TYPE
)
19528 tree field
= NULL_TREE
;
19529 unsigned HOST_WIDE_INT cnt
;
19530 constructor_elt
*ce
;
19532 if (int_size_in_bytes (type
) != size
)
19535 if (TREE_CODE (type
) == RECORD_TYPE
)
19536 field
= TYPE_FIELDS (type
);
19538 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19540 tree val
= ce
->value
;
19541 int pos
, fieldsize
;
19543 if (ce
->index
!= 0)
19549 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
19552 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
19553 && TYPE_DOMAIN (TREE_TYPE (field
))
19554 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
19556 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
19557 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
19559 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
19560 pos
= int_byte_position (field
);
19561 gcc_assert (pos
+ fieldsize
<= size
);
19562 if (val
&& fieldsize
!= 0
19563 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
19569 case VIEW_CONVERT_EXPR
:
19570 case NON_LVALUE_EXPR
:
19571 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
19573 return native_encode_expr (init
, array
, size
) == size
;
19577 /* Attach a DW_AT_const_value attribute to DIE. The value of the
19578 attribute is the const value T. */
19581 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
19584 tree type
= TREE_TYPE (t
);
19587 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
19591 gcc_assert (!DECL_P (init
));
19593 if (TREE_CODE (init
) == INTEGER_CST
)
19595 if (tree_fits_uhwi_p (init
))
19597 add_AT_unsigned (die
, DW_AT_const_value
, tree_to_uhwi (init
));
19600 if (tree_fits_shwi_p (init
))
19602 add_AT_int (die
, DW_AT_const_value
, tree_to_shwi (init
));
19608 rtl
= rtl_for_decl_init (init
, type
);
19610 return add_const_value_attribute (die
, rtl
);
19612 /* If the host and target are sane, try harder. */
19613 if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
19614 && initializer_constant_valid_p (init
, type
))
19616 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
19617 if (size
> 0 && (int) size
== size
)
19619 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
19621 if (native_encode_initializer (init
, array
, size
))
19623 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
19632 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
19633 attribute is the const value of T, where T is an integral constant
19634 variable with static storage duration
19635 (so it can't be a PARM_DECL or a RESULT_DECL). */
19638 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
19642 || (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
19643 || (VAR_P (decl
) && !TREE_STATIC (decl
)))
19646 if (TREE_READONLY (decl
)
19647 && ! TREE_THIS_VOLATILE (decl
)
19648 && DECL_INITIAL (decl
))
19653 /* Don't add DW_AT_const_value if abstract origin already has one. */
19654 if (get_AT (var_die
, DW_AT_const_value
))
19657 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
19660 /* Convert the CFI instructions for the current function into a
19661 location list. This is used for DW_AT_frame_base when we targeting
19662 a dwarf2 consumer that does not support the dwarf3
19663 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
19666 static dw_loc_list_ref
19667 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
19671 dw_loc_list_ref list
, *list_tail
;
19673 dw_cfa_location last_cfa
, next_cfa
;
19674 const char *start_label
, *last_label
, *section
;
19675 dw_cfa_location remember
;
19678 gcc_assert (fde
!= NULL
);
19680 section
= secname_for_decl (current_function_decl
);
19684 memset (&next_cfa
, 0, sizeof (next_cfa
));
19685 next_cfa
.reg
= INVALID_REGNUM
;
19686 remember
= next_cfa
;
19688 start_label
= fde
->dw_fde_begin
;
19690 /* ??? Bald assumption that the CIE opcode list does not contain
19691 advance opcodes. */
19692 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
19693 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19695 last_cfa
= next_cfa
;
19696 last_label
= start_label
;
19698 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
19700 /* If the first partition contained no CFI adjustments, the
19701 CIE opcodes apply to the whole first partition. */
19702 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19703 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
19704 list_tail
=&(*list_tail
)->dw_loc_next
;
19705 start_label
= last_label
= fde
->dw_fde_second_begin
;
19708 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
19710 switch (cfi
->dw_cfi_opc
)
19712 case DW_CFA_set_loc
:
19713 case DW_CFA_advance_loc1
:
19714 case DW_CFA_advance_loc2
:
19715 case DW_CFA_advance_loc4
:
19716 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19718 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19719 start_label
, last_label
, section
);
19721 list_tail
= &(*list_tail
)->dw_loc_next
;
19722 last_cfa
= next_cfa
;
19723 start_label
= last_label
;
19725 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
19728 case DW_CFA_advance_loc
:
19729 /* The encoding is complex enough that we should never emit this. */
19730 gcc_unreachable ();
19733 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19736 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
19738 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19740 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19741 start_label
, last_label
, section
);
19743 list_tail
= &(*list_tail
)->dw_loc_next
;
19744 last_cfa
= next_cfa
;
19745 start_label
= last_label
;
19747 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19748 start_label
, fde
->dw_fde_end
, section
);
19749 list_tail
= &(*list_tail
)->dw_loc_next
;
19750 start_label
= last_label
= fde
->dw_fde_second_begin
;
19754 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19756 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19757 start_label
, last_label
, section
);
19758 list_tail
= &(*list_tail
)->dw_loc_next
;
19759 start_label
= last_label
;
19762 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
19764 fde
->dw_fde_second_begin
19765 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
19768 if (list
&& list
->dw_loc_next
)
19774 /* Compute a displacement from the "steady-state frame pointer" to the
19775 frame base (often the same as the CFA), and store it in
19776 frame_pointer_fb_offset. OFFSET is added to the displacement
19777 before the latter is negated. */
19780 compute_frame_pointer_to_fb_displacement (poly_int64 offset
)
19784 #ifdef FRAME_POINTER_CFA_OFFSET
19785 reg
= frame_pointer_rtx
;
19786 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
19788 reg
= arg_pointer_rtx
;
19789 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
19792 elim
= (ira_use_lra_p
19793 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
19794 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
19795 elim
= strip_offset_and_add (elim
, &offset
);
19797 frame_pointer_fb_offset
= -offset
;
19799 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
19800 in which to eliminate. This is because it's stack pointer isn't
19801 directly accessible as a register within the ISA. To work around
19802 this, assume that while we cannot provide a proper value for
19803 frame_pointer_fb_offset, we won't need one either. */
19804 frame_pointer_fb_offset_valid
19805 = ((SUPPORTS_STACK_ALIGNMENT
19806 && (elim
== hard_frame_pointer_rtx
19807 || elim
== stack_pointer_rtx
))
19808 || elim
== (frame_pointer_needed
19809 ? hard_frame_pointer_rtx
19810 : stack_pointer_rtx
));
19813 /* Generate a DW_AT_name attribute given some string value to be included as
19814 the value of the attribute. */
19817 add_name_attribute (dw_die_ref die
, const char *name_string
)
19819 if (name_string
!= NULL
&& *name_string
!= 0)
19821 if (demangle_name_func
)
19822 name_string
= (*demangle_name_func
) (name_string
);
19824 add_AT_string (die
, DW_AT_name
, name_string
);
19828 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
19829 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
19830 of TYPE accordingly.
19832 ??? This is a temporary measure until after we're able to generate
19833 regular DWARF for the complex Ada type system. */
19836 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
19837 dw_die_ref context_die
)
19840 dw_die_ref dtype_die
;
19842 if (!lang_hooks
.types
.descriptive_type
)
19845 dtype
= lang_hooks
.types
.descriptive_type (type
);
19849 dtype_die
= lookup_type_die (dtype
);
19852 gen_type_die (dtype
, context_die
);
19853 dtype_die
= lookup_type_die (dtype
);
19854 gcc_assert (dtype_die
);
19857 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
19860 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
19862 static const char *
19863 comp_dir_string (void)
19867 static const char *cached_wd
= NULL
;
19869 if (cached_wd
!= NULL
)
19872 wd
= get_src_pwd ();
19876 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
19880 wdlen
= strlen (wd
);
19881 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
19883 wd1
[wdlen
] = DIR_SEPARATOR
;
19884 wd1
[wdlen
+ 1] = 0;
19888 cached_wd
= remap_debug_filename (wd
);
19892 /* Generate a DW_AT_comp_dir attribute for DIE. */
19895 add_comp_dir_attribute (dw_die_ref die
)
19897 const char * wd
= comp_dir_string ();
19899 add_AT_string (die
, DW_AT_comp_dir
, wd
);
19902 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
19903 pointer computation, ...), output a representation for that bound according
19904 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
19905 loc_list_from_tree for the meaning of CONTEXT. */
19908 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
19909 int forms
, struct loc_descr_context
*context
)
19911 dw_die_ref context_die
, decl_die
;
19912 dw_loc_list_ref list
;
19913 bool strip_conversions
= true;
19914 bool placeholder_seen
= false;
19916 while (strip_conversions
)
19917 switch (TREE_CODE (value
))
19924 case VIEW_CONVERT_EXPR
:
19925 value
= TREE_OPERAND (value
, 0);
19929 strip_conversions
= false;
19933 /* If possible and permitted, output the attribute as a constant. */
19934 if ((forms
& dw_scalar_form_constant
) != 0
19935 && TREE_CODE (value
) == INTEGER_CST
)
19937 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
19939 /* If HOST_WIDE_INT is big enough then represent the bound as
19940 a constant value. We need to choose a form based on
19941 whether the type is signed or unsigned. We cannot just
19942 call add_AT_unsigned if the value itself is positive
19943 (add_AT_unsigned might add the unsigned value encoded as
19944 DW_FORM_data[1248]). Some DWARF consumers will lookup the
19945 bounds type and then sign extend any unsigned values found
19946 for signed types. This is needed only for
19947 DW_AT_{lower,upper}_bound, since for most other attributes,
19948 consumers will treat DW_FORM_data[1248] as unsigned values,
19949 regardless of the underlying type. */
19950 if (prec
<= HOST_BITS_PER_WIDE_INT
19951 || tree_fits_uhwi_p (value
))
19953 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
19954 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
19956 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
19959 /* Otherwise represent the bound as an unsigned value with
19960 the precision of its type. The precision and signedness
19961 of the type will be necessary to re-interpret it
19963 add_AT_wide (die
, attr
, wi::to_wide (value
));
19967 /* Otherwise, if it's possible and permitted too, output a reference to
19969 if ((forms
& dw_scalar_form_reference
) != 0)
19971 tree decl
= NULL_TREE
;
19973 /* Some type attributes reference an outer type. For instance, the upper
19974 bound of an array may reference an embedding record (this happens in
19976 if (TREE_CODE (value
) == COMPONENT_REF
19977 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
19978 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
19979 decl
= TREE_OPERAND (value
, 1);
19981 else if (VAR_P (value
)
19982 || TREE_CODE (value
) == PARM_DECL
19983 || TREE_CODE (value
) == RESULT_DECL
)
19986 if (decl
!= NULL_TREE
)
19988 dw_die_ref decl_die
= lookup_decl_die (decl
);
19990 /* ??? Can this happen, or should the variable have been bound
19991 first? Probably it can, since I imagine that we try to create
19992 the types of parameters in the order in which they exist in
19993 the list, and won't have created a forward reference to a
19994 later parameter. */
19995 if (decl_die
!= NULL
)
19997 add_AT_die_ref (die
, attr
, decl_die
);
20003 /* Last chance: try to create a stack operation procedure to evaluate the
20004 value. Do nothing if even that is not possible or permitted. */
20005 if ((forms
& dw_scalar_form_exprloc
) == 0)
20008 list
= loc_list_from_tree (value
, 2, context
);
20009 if (context
&& context
->placeholder_arg
)
20011 placeholder_seen
= context
->placeholder_seen
;
20012 context
->placeholder_seen
= false;
20014 if (list
== NULL
|| single_element_loc_list_p (list
))
20016 /* If this attribute is not a reference nor constant, it is
20017 a DWARF expression rather than location description. For that
20018 loc_list_from_tree (value, 0, &context) is needed. */
20019 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
20020 if (list2
&& single_element_loc_list_p (list2
))
20022 if (placeholder_seen
)
20024 struct dwarf_procedure_info dpi
;
20025 dpi
.fndecl
= NULL_TREE
;
20026 dpi
.args_count
= 1;
20027 if (!resolve_args_picking (list2
->expr
, 1, &dpi
))
20030 add_AT_loc (die
, attr
, list2
->expr
);
20035 /* If that failed to give a single element location list, fall back to
20036 outputting this as a reference... still if permitted. */
20038 || (forms
& dw_scalar_form_reference
) == 0
20039 || placeholder_seen
)
20042 if (current_function_decl
== 0)
20043 context_die
= comp_unit_die ();
20045 context_die
= lookup_decl_die (current_function_decl
);
20047 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
20048 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
20049 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
20051 add_AT_location_description (decl_die
, DW_AT_location
, list
);
20052 add_AT_die_ref (die
, attr
, decl_die
);
20055 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
20059 lower_bound_default (void)
20061 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
20067 case DW_LANG_C_plus_plus
:
20068 case DW_LANG_C_plus_plus_11
:
20069 case DW_LANG_C_plus_plus_14
:
20071 case DW_LANG_ObjC_plus_plus
:
20073 case DW_LANG_Fortran77
:
20074 case DW_LANG_Fortran90
:
20075 case DW_LANG_Fortran95
:
20076 case DW_LANG_Fortran03
:
20077 case DW_LANG_Fortran08
:
20081 case DW_LANG_Python
:
20082 return dwarf_version
>= 4 ? 0 : -1;
20083 case DW_LANG_Ada95
:
20084 case DW_LANG_Ada83
:
20085 case DW_LANG_Cobol74
:
20086 case DW_LANG_Cobol85
:
20087 case DW_LANG_Modula2
:
20089 return dwarf_version
>= 4 ? 1 : -1;
20095 /* Given a tree node describing an array bound (either lower or upper) output
20096 a representation for that bound. */
20099 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
20100 tree bound
, struct loc_descr_context
*context
)
20105 switch (TREE_CODE (bound
))
20107 /* Strip all conversions. */
20109 case VIEW_CONVERT_EXPR
:
20110 bound
= TREE_OPERAND (bound
, 0);
20113 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
20114 are even omitted when they are the default. */
20116 /* If the value for this bound is the default one, we can even omit the
20118 if (bound_attr
== DW_AT_lower_bound
20119 && tree_fits_shwi_p (bound
)
20120 && (dflt
= lower_bound_default ()) != -1
20121 && tree_to_shwi (bound
) == dflt
)
20127 /* Because of the complex interaction there can be with other GNAT
20128 encodings, GDB isn't ready yet to handle proper DWARF description
20129 for self-referencial subrange bounds: let GNAT encodings do the
20130 magic in such a case. */
20132 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
20133 && contains_placeholder_p (bound
))
20136 add_scalar_info (subrange_die
, bound_attr
, bound
,
20137 dw_scalar_form_constant
20138 | dw_scalar_form_exprloc
20139 | dw_scalar_form_reference
,
20145 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
20146 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
20147 Note that the block of subscript information for an array type also
20148 includes information about the element type of the given array type.
20150 This function reuses previously set type and bound information if
20154 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
20156 unsigned dimension_number
;
20158 dw_die_ref child
= type_die
->die_child
;
20160 for (dimension_number
= 0;
20161 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
20162 type
= TREE_TYPE (type
), dimension_number
++)
20164 tree domain
= TYPE_DOMAIN (type
);
20166 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
20169 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
20170 and (in GNU C only) variable bounds. Handle all three forms
20173 /* Find and reuse a previously generated DW_TAG_subrange_type if
20176 For multi-dimensional arrays, as we iterate through the
20177 various dimensions in the enclosing for loop above, we also
20178 iterate through the DIE children and pick at each
20179 DW_TAG_subrange_type previously generated (if available).
20180 Each child DW_TAG_subrange_type DIE describes the range of
20181 the current dimension. At this point we should have as many
20182 DW_TAG_subrange_type's as we have dimensions in the
20184 dw_die_ref subrange_die
= NULL
;
20188 child
= child
->die_sib
;
20189 if (child
->die_tag
== DW_TAG_subrange_type
)
20190 subrange_die
= child
;
20191 if (child
== type_die
->die_child
)
20193 /* If we wrapped around, stop looking next time. */
20197 if (child
->die_tag
== DW_TAG_subrange_type
)
20201 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
20205 /* We have an array type with specified bounds. */
20206 lower
= TYPE_MIN_VALUE (domain
);
20207 upper
= TYPE_MAX_VALUE (domain
);
20209 /* Define the index type. */
20210 if (TREE_TYPE (domain
)
20211 && !get_AT (subrange_die
, DW_AT_type
))
20213 /* ??? This is probably an Ada unnamed subrange type. Ignore the
20214 TREE_TYPE field. We can't emit debug info for this
20215 because it is an unnamed integral type. */
20216 if (TREE_CODE (domain
) == INTEGER_TYPE
20217 && TYPE_NAME (domain
) == NULL_TREE
20218 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
20219 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
20222 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
20223 TYPE_UNQUALIFIED
, false, type_die
);
20226 /* ??? If upper is NULL, the array has unspecified length,
20227 but it does have a lower bound. This happens with Fortran
20229 Since the debugger is definitely going to need to know N
20230 to produce useful results, go ahead and output the lower
20231 bound solo, and hope the debugger can cope. */
20233 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
20234 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
20235 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
20236 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
20239 /* Otherwise we have an array type with an unspecified length. The
20240 DWARF-2 spec does not say how to handle this; let's just leave out the
20245 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
20248 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
20250 dw_die_ref decl_die
;
20251 HOST_WIDE_INT size
;
20252 dw_loc_descr_ref size_expr
= NULL
;
20254 switch (TREE_CODE (tree_node
))
20259 case ENUMERAL_TYPE
:
20262 case QUAL_UNION_TYPE
:
20263 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
20264 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
20266 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
20269 size_expr
= type_byte_size (tree_node
, &size
);
20272 /* For a data member of a struct or union, the DW_AT_byte_size is
20273 generally given as the number of bytes normally allocated for an
20274 object of the *declared* type of the member itself. This is true
20275 even for bit-fields. */
20276 size
= int_size_in_bytes (field_type (tree_node
));
20279 gcc_unreachable ();
20282 /* Support for dynamically-sized objects was introduced by DWARFv3.
20283 At the moment, GDB does not handle variable byte sizes very well,
20285 if ((dwarf_version
>= 3 || !dwarf_strict
)
20286 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
20287 && size_expr
!= NULL
)
20288 add_AT_loc (die
, DW_AT_byte_size
, size_expr
);
20290 /* Note that `size' might be -1 when we get to this point. If it is, that
20291 indicates that the byte size of the entity in question is variable and
20292 that we could not generate a DWARF expression that computes it. */
20294 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
20297 /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
20301 add_alignment_attribute (dw_die_ref die
, tree tree_node
)
20303 if (dwarf_version
< 5 && dwarf_strict
)
20308 if (DECL_P (tree_node
))
20310 if (!DECL_USER_ALIGN (tree_node
))
20313 align
= DECL_ALIGN_UNIT (tree_node
);
20315 else if (TYPE_P (tree_node
))
20317 if (!TYPE_USER_ALIGN (tree_node
))
20320 align
= TYPE_ALIGN_UNIT (tree_node
);
20323 gcc_unreachable ();
20325 add_AT_unsigned (die
, DW_AT_alignment
, align
);
20328 /* For a FIELD_DECL node which represents a bit-field, output an attribute
20329 which specifies the distance in bits from the highest order bit of the
20330 "containing object" for the bit-field to the highest order bit of the
20333 For any given bit-field, the "containing object" is a hypothetical object
20334 (of some integral or enum type) within which the given bit-field lives. The
20335 type of this hypothetical "containing object" is always the same as the
20336 declared type of the individual bit-field itself. The determination of the
20337 exact location of the "containing object" for a bit-field is rather
20338 complicated. It's handled by the `field_byte_offset' function (above).
20340 CTX is required: see the comment for VLR_CONTEXT.
20342 Note that it is the size (in bytes) of the hypothetical "containing object"
20343 which will be given in the DW_AT_byte_size attribute for this bit-field.
20344 (See `byte_size_attribute' above). */
20347 add_bit_offset_attribute (dw_die_ref die
, tree decl
, struct vlr_context
*ctx
)
20349 HOST_WIDE_INT object_offset_in_bytes
;
20350 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
20351 HOST_WIDE_INT bitpos_int
;
20352 HOST_WIDE_INT highest_order_object_bit_offset
;
20353 HOST_WIDE_INT highest_order_field_bit_offset
;
20354 HOST_WIDE_INT bit_offset
;
20356 field_byte_offset (decl
, ctx
, &object_offset_in_bytes
);
20358 /* Must be a field and a bit field. */
20359 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
20361 /* We can't yet handle bit-fields whose offsets are variable, so if we
20362 encounter such things, just return without generating any attribute
20363 whatsoever. Likewise for variable or too large size. */
20364 if (! tree_fits_shwi_p (bit_position (decl
))
20365 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
20368 bitpos_int
= int_bit_position (decl
);
20370 /* Note that the bit offset is always the distance (in bits) from the
20371 highest-order bit of the "containing object" to the highest-order bit of
20372 the bit-field itself. Since the "high-order end" of any object or field
20373 is different on big-endian and little-endian machines, the computation
20374 below must take account of these differences. */
20375 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
20376 highest_order_field_bit_offset
= bitpos_int
;
20378 if (! BYTES_BIG_ENDIAN
)
20380 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
20381 highest_order_object_bit_offset
+=
20382 simple_type_size_in_bits (original_type
);
20386 = (! BYTES_BIG_ENDIAN
20387 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
20388 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
20390 if (bit_offset
< 0)
20391 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
20393 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
20396 /* For a FIELD_DECL node which represents a bit field, output an attribute
20397 which specifies the length in bits of the given field. */
20400 add_bit_size_attribute (dw_die_ref die
, tree decl
)
20402 /* Must be a field and a bit field. */
20403 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
20404 && DECL_BIT_FIELD_TYPE (decl
));
20406 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
20407 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
20410 /* If the compiled language is ANSI C, then add a 'prototyped'
20411 attribute, if arg types are given for the parameters of a function. */
20414 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
20416 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
20423 if (prototype_p (func_type
))
20424 add_AT_flag (die
, DW_AT_prototyped
, 1);
20431 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
20432 by looking in the type declaration, the object declaration equate table or
20433 the block mapping. */
20435 static inline dw_die_ref
20436 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
20438 dw_die_ref origin_die
= NULL
;
20440 if (DECL_P (origin
))
20443 origin_die
= lookup_decl_die (origin
);
20444 /* "Unwrap" the decls DIE which we put in the imported unit context.
20445 We are looking for the abstract copy here. */
20448 && (c
= get_AT_ref (origin_die
, DW_AT_abstract_origin
))
20449 /* ??? Identify this better. */
20453 else if (TYPE_P (origin
))
20454 origin_die
= lookup_type_die (origin
);
20455 else if (TREE_CODE (origin
) == BLOCK
)
20456 origin_die
= BLOCK_DIE (origin
);
20458 /* XXX: Functions that are never lowered don't always have correct block
20459 trees (in the case of java, they simply have no block tree, in some other
20460 languages). For these functions, there is nothing we can really do to
20461 output correct debug info for inlined functions in all cases. Rather
20462 than die, we'll just produce deficient debug info now, in that we will
20463 have variables without a proper abstract origin. In the future, when all
20464 functions are lowered, we should re-add a gcc_assert (origin_die)
20468 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
20472 /* We do not currently support the pure_virtual attribute. */
20475 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
20477 if (DECL_VINDEX (func_decl
))
20479 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20481 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
20482 add_AT_loc (die
, DW_AT_vtable_elem_location
,
20483 new_loc_descr (DW_OP_constu
,
20484 tree_to_shwi (DECL_VINDEX (func_decl
)),
20487 /* GNU extension: Record what type this method came from originally. */
20488 if (debug_info_level
> DINFO_LEVEL_TERSE
20489 && DECL_CONTEXT (func_decl
))
20490 add_AT_die_ref (die
, DW_AT_containing_type
,
20491 lookup_type_die (DECL_CONTEXT (func_decl
)));
20495 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
20496 given decl. This used to be a vendor extension until after DWARF 4
20497 standardized it. */
20500 add_linkage_attr (dw_die_ref die
, tree decl
)
20502 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
20504 /* Mimic what assemble_name_raw does with a leading '*'. */
20505 if (name
[0] == '*')
20508 if (dwarf_version
>= 4)
20509 add_AT_string (die
, DW_AT_linkage_name
, name
);
20511 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
20514 /* Add source coordinate attributes for the given decl. */
20517 add_src_coords_attributes (dw_die_ref die
, tree decl
)
20519 expanded_location s
;
20521 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
20523 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
20524 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
20525 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
20526 if (debug_column_info
&& s
.column
)
20527 add_AT_unsigned (die
, DW_AT_decl_column
, s
.column
);
20530 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
20533 add_linkage_name_raw (dw_die_ref die
, tree decl
)
20535 /* Defer until we have an assembler name set. */
20536 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
20538 limbo_die_node
*asm_name
;
20540 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
20541 asm_name
->die
= die
;
20542 asm_name
->created_for
= decl
;
20543 asm_name
->next
= deferred_asm_name
;
20544 deferred_asm_name
= asm_name
;
20546 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
20547 add_linkage_attr (die
, decl
);
20550 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
20553 add_linkage_name (dw_die_ref die
, tree decl
)
20555 if (debug_info_level
> DINFO_LEVEL_NONE
20556 && VAR_OR_FUNCTION_DECL_P (decl
)
20557 && TREE_PUBLIC (decl
)
20558 && !(VAR_P (decl
) && DECL_REGISTER (decl
))
20559 && die
->die_tag
!= DW_TAG_member
)
20560 add_linkage_name_raw (die
, decl
);
20563 /* Add a DW_AT_name attribute and source coordinate attribute for the
20564 given decl, but only if it actually has a name. */
20567 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
,
20568 bool no_linkage_name
)
20572 decl_name
= DECL_NAME (decl
);
20573 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
20575 const char *name
= dwarf2_name (decl
, 0);
20577 add_name_attribute (die
, name
);
20578 if (! DECL_ARTIFICIAL (decl
))
20579 add_src_coords_attributes (die
, decl
);
20581 if (!no_linkage_name
)
20582 add_linkage_name (die
, decl
);
20585 #ifdef VMS_DEBUGGING_INFO
20586 /* Get the function's name, as described by its RTL. This may be different
20587 from the DECL_NAME name used in the source file. */
20588 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
20590 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
20591 XEXP (DECL_RTL (decl
), 0), false);
20592 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
20594 #endif /* VMS_DEBUGGING_INFO */
20597 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
20600 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
20604 attr
.dw_attr
= DW_AT_discr_value
;
20605 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
20606 attr
.dw_attr_val
.val_entry
= NULL
;
20607 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
20609 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
20611 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
20612 add_dwarf_attr (die
, &attr
);
20615 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
20618 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
20622 attr
.dw_attr
= DW_AT_discr_list
;
20623 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
20624 attr
.dw_attr_val
.val_entry
= NULL
;
20625 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
20626 add_dwarf_attr (die
, &attr
);
20629 static inline dw_discr_list_ref
20630 AT_discr_list (dw_attr_node
*attr
)
20632 return attr
->dw_attr_val
.v
.val_discr_list
;
20635 #ifdef VMS_DEBUGGING_INFO
20636 /* Output the debug main pointer die for VMS */
20639 dwarf2out_vms_debug_main_pointer (void)
20641 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20644 /* Allocate the VMS debug main subprogram die. */
20645 die
= new_die_raw (DW_TAG_subprogram
);
20646 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
20647 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
20648 current_function_funcdef_no
);
20649 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
20651 /* Make it the first child of comp_unit_die (). */
20652 die
->die_parent
= comp_unit_die ();
20653 if (comp_unit_die ()->die_child
)
20655 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
20656 comp_unit_die ()->die_child
->die_sib
= die
;
20660 die
->die_sib
= die
;
20661 comp_unit_die ()->die_child
= die
;
20664 #endif /* VMS_DEBUGGING_INFO */
20666 /* Push a new declaration scope. */
20669 push_decl_scope (tree scope
)
20671 vec_safe_push (decl_scope_table
, scope
);
20674 /* Pop a declaration scope. */
20677 pop_decl_scope (void)
20679 decl_scope_table
->pop ();
20682 /* walk_tree helper function for uses_local_type, below. */
20685 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
20688 *walk_subtrees
= 0;
20691 tree name
= TYPE_NAME (*tp
);
20692 if (name
&& DECL_P (name
) && decl_function_context (name
))
20698 /* If TYPE involves a function-local type (including a local typedef to a
20699 non-local type), returns that type; otherwise returns NULL_TREE. */
20702 uses_local_type (tree type
)
20704 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
20708 /* Return the DIE for the scope that immediately contains this type.
20709 Non-named types that do not involve a function-local type get global
20710 scope. Named types nested in namespaces or other types get their
20711 containing scope. All other types (i.e. function-local named types) get
20712 the current active scope. */
20715 scope_die_for (tree t
, dw_die_ref context_die
)
20717 dw_die_ref scope_die
= NULL
;
20718 tree containing_scope
;
20720 /* Non-types always go in the current scope. */
20721 gcc_assert (TYPE_P (t
));
20723 /* Use the scope of the typedef, rather than the scope of the type
20725 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
20726 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
20728 containing_scope
= TYPE_CONTEXT (t
);
20730 /* Use the containing namespace if there is one. */
20731 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
20733 if (context_die
== lookup_decl_die (containing_scope
))
20735 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20736 context_die
= get_context_die (containing_scope
);
20738 containing_scope
= NULL_TREE
;
20741 /* Ignore function type "scopes" from the C frontend. They mean that
20742 a tagged type is local to a parmlist of a function declarator, but
20743 that isn't useful to DWARF. */
20744 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
20745 containing_scope
= NULL_TREE
;
20747 if (SCOPE_FILE_SCOPE_P (containing_scope
))
20749 /* If T uses a local type keep it local as well, to avoid references
20750 to function-local DIEs from outside the function. */
20751 if (current_function_decl
&& uses_local_type (t
))
20752 scope_die
= context_die
;
20754 scope_die
= comp_unit_die ();
20756 else if (TYPE_P (containing_scope
))
20758 /* For types, we can just look up the appropriate DIE. */
20759 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20760 scope_die
= get_context_die (containing_scope
);
20763 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
20764 if (scope_die
== NULL
)
20765 scope_die
= comp_unit_die ();
20769 scope_die
= context_die
;
20774 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
20777 local_scope_p (dw_die_ref context_die
)
20779 for (; context_die
; context_die
= context_die
->die_parent
)
20780 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
20781 || context_die
->die_tag
== DW_TAG_subprogram
)
20787 /* Returns nonzero if CONTEXT_DIE is a class. */
20790 class_scope_p (dw_die_ref context_die
)
20792 return (context_die
20793 && (context_die
->die_tag
== DW_TAG_structure_type
20794 || context_die
->die_tag
== DW_TAG_class_type
20795 || context_die
->die_tag
== DW_TAG_interface_type
20796 || context_die
->die_tag
== DW_TAG_union_type
));
20799 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
20800 whether or not to treat a DIE in this context as a declaration. */
20803 class_or_namespace_scope_p (dw_die_ref context_die
)
20805 return (class_scope_p (context_die
)
20806 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
20809 /* Many forms of DIEs require a "type description" attribute. This
20810 routine locates the proper "type descriptor" die for the type given
20811 by 'type' plus any additional qualifiers given by 'cv_quals', and
20812 adds a DW_AT_type attribute below the given die. */
20815 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
20816 bool reverse
, dw_die_ref context_die
)
20818 enum tree_code code
= TREE_CODE (type
);
20819 dw_die_ref type_die
= NULL
;
20821 /* ??? If this type is an unnamed subrange type of an integral, floating-point
20822 or fixed-point type, use the inner type. This is because we have no
20823 support for unnamed types in base_type_die. This can happen if this is
20824 an Ada subrange type. Correct solution is emit a subrange type die. */
20825 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
20826 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
20827 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
20829 if (code
== ERROR_MARK
20830 /* Handle a special case. For functions whose return type is void, we
20831 generate *no* type attribute. (Note that no object may have type
20832 `void', so this only applies to function return types). */
20833 || code
== VOID_TYPE
)
20836 type_die
= modified_type_die (type
,
20837 cv_quals
| TYPE_QUALS (type
),
20841 if (type_die
!= NULL
)
20842 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
20845 /* Given an object die, add the calling convention attribute for the
20846 function call type. */
20848 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
20850 enum dwarf_calling_convention value
= DW_CC_normal
;
20852 value
= ((enum dwarf_calling_convention
)
20853 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
20856 && id_equal (DECL_ASSEMBLER_NAME (decl
), "MAIN__"))
20858 /* DWARF 2 doesn't provide a way to identify a program's source-level
20859 entry point. DW_AT_calling_convention attributes are only meant
20860 to describe functions' calling conventions. However, lacking a
20861 better way to signal the Fortran main program, we used this for
20862 a long time, following existing custom. Now, DWARF 4 has
20863 DW_AT_main_subprogram, which we add below, but some tools still
20864 rely on the old way, which we thus keep. */
20865 value
= DW_CC_program
;
20867 if (dwarf_version
>= 4 || !dwarf_strict
)
20868 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
20871 /* Only add the attribute if the backend requests it, and
20872 is not DW_CC_normal. */
20873 if (value
&& (value
!= DW_CC_normal
))
20874 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
20877 /* Given a tree pointer to a struct, class, union, or enum type node, return
20878 a pointer to the (string) tag name for the given type, or zero if the type
20879 was declared without a tag. */
20881 static const char *
20882 type_tag (const_tree type
)
20884 const char *name
= 0;
20886 if (TYPE_NAME (type
) != 0)
20890 /* Find the IDENTIFIER_NODE for the type name. */
20891 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
20892 && !TYPE_NAMELESS (type
))
20893 t
= TYPE_NAME (type
);
20895 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
20896 a TYPE_DECL node, regardless of whether or not a `typedef' was
20898 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20899 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
20901 /* We want to be extra verbose. Don't call dwarf_name if
20902 DECL_NAME isn't set. The default hook for decl_printable_name
20903 doesn't like that, and in this context it's correct to return
20904 0, instead of "<anonymous>" or the like. */
20905 if (DECL_NAME (TYPE_NAME (type
))
20906 && !DECL_NAMELESS (TYPE_NAME (type
)))
20907 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
20910 /* Now get the name as a string, or invent one. */
20911 if (!name
&& t
!= 0)
20912 name
= IDENTIFIER_POINTER (t
);
20915 return (name
== 0 || *name
== '\0') ? 0 : name
;
20918 /* Return the type associated with a data member, make a special check
20919 for bit field types. */
20922 member_declared_type (const_tree member
)
20924 return (DECL_BIT_FIELD_TYPE (member
)
20925 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
20928 /* Get the decl's label, as described by its RTL. This may be different
20929 from the DECL_NAME name used in the source file. */
20932 static const char *
20933 decl_start_label (tree decl
)
20936 const char *fnname
;
20938 x
= DECL_RTL (decl
);
20939 gcc_assert (MEM_P (x
));
20942 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
20944 fnname
= XSTR (x
, 0);
20949 /* For variable-length arrays that have been previously generated, but
20950 may be incomplete due to missing subscript info, fill the subscript
20951 info. Return TRUE if this is one of those cases. */
20953 fill_variable_array_bounds (tree type
)
20955 if (TREE_ASM_WRITTEN (type
)
20956 && TREE_CODE (type
) == ARRAY_TYPE
20957 && variably_modified_type_p (type
, NULL
))
20959 dw_die_ref array_die
= lookup_type_die (type
);
20962 add_subscript_info (array_die
, type
, !is_ada ());
20968 /* These routines generate the internal representation of the DIE's for
20969 the compilation unit. Debugging information is collected by walking
20970 the declaration trees passed in from dwarf2out_decl(). */
20973 gen_array_type_die (tree type
, dw_die_ref context_die
)
20975 dw_die_ref array_die
;
20977 /* GNU compilers represent multidimensional array types as sequences of one
20978 dimensional array types whose element types are themselves array types.
20979 We sometimes squish that down to a single array_type DIE with multiple
20980 subscripts in the Dwarf debugging info. The draft Dwarf specification
20981 say that we are allowed to do this kind of compression in C, because
20982 there is no difference between an array of arrays and a multidimensional
20983 array. We don't do this for Ada to remain as close as possible to the
20984 actual representation, which is especially important against the language
20985 flexibilty wrt arrays of variable size. */
20987 bool collapse_nested_arrays
= !is_ada ();
20989 if (fill_variable_array_bounds (type
))
20992 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
20995 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
20996 DW_TAG_string_type doesn't have DW_AT_type attribute). */
20997 if (TYPE_STRING_FLAG (type
)
20998 && TREE_CODE (type
) == ARRAY_TYPE
21000 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
21002 HOST_WIDE_INT size
;
21004 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
21005 add_name_attribute (array_die
, type_tag (type
));
21006 equate_type_number_to_die (type
, array_die
);
21007 size
= int_size_in_bytes (type
);
21009 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
21010 /* ??? We can't annotate types late, but for LTO we may not
21011 generate a location early either (gfortran.dg/save_6.f90). */
21012 else if (! (early_dwarf
&& (flag_generate_lto
|| flag_generate_offload
))
21013 && TYPE_DOMAIN (type
) != NULL_TREE
21014 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
21016 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
21017 tree rszdecl
= szdecl
;
21019 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
21020 if (!DECL_P (szdecl
))
21022 if (TREE_CODE (szdecl
) == INDIRECT_REF
21023 && DECL_P (TREE_OPERAND (szdecl
, 0)))
21025 rszdecl
= TREE_OPERAND (szdecl
, 0);
21026 if (int_size_in_bytes (TREE_TYPE (rszdecl
))
21027 != DWARF2_ADDR_SIZE
)
21035 dw_loc_list_ref loc
21036 = loc_list_from_tree (rszdecl
, szdecl
== rszdecl
? 2 : 0,
21040 add_AT_location_description (array_die
, DW_AT_string_length
,
21042 if (size
!= DWARF2_ADDR_SIZE
)
21043 add_AT_unsigned (array_die
, dwarf_version
>= 5
21044 ? DW_AT_string_length_byte_size
21045 : DW_AT_byte_size
, size
);
21052 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
21053 add_name_attribute (array_die
, type_tag (type
));
21054 equate_type_number_to_die (type
, array_die
);
21056 if (TREE_CODE (type
) == VECTOR_TYPE
)
21057 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
21059 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
21061 && TREE_CODE (type
) == ARRAY_TYPE
21062 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
21063 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
21064 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
21067 /* We default the array ordering. Debuggers will probably do the right
21068 things even if DW_AT_ordering is not present. It's not even an issue
21069 until we start to get into multidimensional arrays anyway. If a debugger
21070 is ever caught doing the Wrong Thing for multi-dimensional arrays,
21071 then we'll have to put the DW_AT_ordering attribute back in. (But if
21072 and when we find out that we need to put these in, we will only do so
21073 for multidimensional arrays. */
21074 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
21077 if (TREE_CODE (type
) == VECTOR_TYPE
)
21079 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
21080 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
21081 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
21082 add_bound_info (subrange_die
, DW_AT_upper_bound
,
21083 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
21086 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
21088 /* Add representation of the type of the elements of this array type and
21089 emit the corresponding DIE if we haven't done it already. */
21090 element_type
= TREE_TYPE (type
);
21091 if (collapse_nested_arrays
)
21092 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
21094 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
21096 element_type
= TREE_TYPE (element_type
);
21099 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
21100 TREE_CODE (type
) == ARRAY_TYPE
21101 && TYPE_REVERSE_STORAGE_ORDER (type
),
21104 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
21105 if (TYPE_ARTIFICIAL (type
))
21106 add_AT_flag (array_die
, DW_AT_artificial
, 1);
21108 if (get_AT (array_die
, DW_AT_name
))
21109 add_pubtype (type
, array_die
);
21111 add_alignment_attribute (array_die
, type
);
21114 /* This routine generates DIE for array with hidden descriptor, details
21115 are filled into *info by a langhook. */
21118 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
21119 dw_die_ref context_die
)
21121 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
21122 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
21123 struct loc_descr_context context
= { type
, info
->base_decl
, NULL
,
21125 enum dwarf_tag subrange_tag
= DW_TAG_subrange_type
;
21128 add_name_attribute (array_die
, type_tag (type
));
21129 equate_type_number_to_die (type
, array_die
);
21131 if (info
->ndimensions
> 1)
21132 switch (info
->ordering
)
21134 case array_descr_ordering_row_major
:
21135 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
21137 case array_descr_ordering_column_major
:
21138 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
21144 if (dwarf_version
>= 3 || !dwarf_strict
)
21146 if (info
->data_location
)
21147 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
21148 dw_scalar_form_exprloc
, &context
);
21149 if (info
->associated
)
21150 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
21151 dw_scalar_form_constant
21152 | dw_scalar_form_exprloc
21153 | dw_scalar_form_reference
, &context
);
21154 if (info
->allocated
)
21155 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
21156 dw_scalar_form_constant
21157 | dw_scalar_form_exprloc
21158 | dw_scalar_form_reference
, &context
);
21161 const enum dwarf_attribute attr
21162 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
21164 = (info
->stride_in_bits
)
21165 ? dw_scalar_form_constant
21166 : (dw_scalar_form_constant
21167 | dw_scalar_form_exprloc
21168 | dw_scalar_form_reference
);
21170 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
21173 if (dwarf_version
>= 5)
21177 add_scalar_info (array_die
, DW_AT_rank
, info
->rank
,
21178 dw_scalar_form_constant
21179 | dw_scalar_form_exprloc
, &context
);
21180 subrange_tag
= DW_TAG_generic_subrange
;
21181 context
.placeholder_arg
= true;
21185 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
21187 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
21189 dw_die_ref subrange_die
= new_die (subrange_tag
, array_die
, NULL
);
21191 if (info
->dimen
[dim
].bounds_type
)
21192 add_type_attribute (subrange_die
,
21193 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
21194 false, context_die
);
21195 if (info
->dimen
[dim
].lower_bound
)
21196 add_bound_info (subrange_die
, DW_AT_lower_bound
,
21197 info
->dimen
[dim
].lower_bound
, &context
);
21198 if (info
->dimen
[dim
].upper_bound
)
21199 add_bound_info (subrange_die
, DW_AT_upper_bound
,
21200 info
->dimen
[dim
].upper_bound
, &context
);
21201 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
21202 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
21203 info
->dimen
[dim
].stride
,
21204 dw_scalar_form_constant
21205 | dw_scalar_form_exprloc
21206 | dw_scalar_form_reference
,
21210 gen_type_die (info
->element_type
, context_die
);
21211 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
21212 TREE_CODE (type
) == ARRAY_TYPE
21213 && TYPE_REVERSE_STORAGE_ORDER (type
),
21216 if (get_AT (array_die
, DW_AT_name
))
21217 add_pubtype (type
, array_die
);
21219 add_alignment_attribute (array_die
, type
);
21224 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
21226 tree origin
= decl_ultimate_origin (decl
);
21227 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
21229 if (origin
!= NULL
)
21230 add_abstract_origin_attribute (decl_die
, origin
);
21233 add_name_and_src_coords_attributes (decl_die
, decl
);
21234 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
21235 TYPE_UNQUALIFIED
, false, context_die
);
21238 if (DECL_ABSTRACT_P (decl
))
21239 equate_decl_number_to_die (decl
, decl_die
);
21241 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
21245 /* Walk through the list of incomplete types again, trying once more to
21246 emit full debugging info for them. */
21249 retry_incomplete_types (void)
21254 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
21255 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
21256 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
21257 vec_safe_truncate (incomplete_types
, 0);
21260 /* Determine what tag to use for a record type. */
21262 static enum dwarf_tag
21263 record_type_tag (tree type
)
21265 if (! lang_hooks
.types
.classify_record
)
21266 return DW_TAG_structure_type
;
21268 switch (lang_hooks
.types
.classify_record (type
))
21270 case RECORD_IS_STRUCT
:
21271 return DW_TAG_structure_type
;
21273 case RECORD_IS_CLASS
:
21274 return DW_TAG_class_type
;
21276 case RECORD_IS_INTERFACE
:
21277 if (dwarf_version
>= 3 || !dwarf_strict
)
21278 return DW_TAG_interface_type
;
21279 return DW_TAG_structure_type
;
21282 gcc_unreachable ();
21286 /* Generate a DIE to represent an enumeration type. Note that these DIEs
21287 include all of the information about the enumeration values also. Each
21288 enumerated type name/value is listed as a child of the enumerated type
21292 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
21294 dw_die_ref type_die
= lookup_type_die (type
);
21296 if (type_die
== NULL
)
21298 type_die
= new_die (DW_TAG_enumeration_type
,
21299 scope_die_for (type
, context_die
), type
);
21300 equate_type_number_to_die (type
, type_die
);
21301 add_name_attribute (type_die
, type_tag (type
));
21302 if (dwarf_version
>= 4 || !dwarf_strict
)
21304 if (ENUM_IS_SCOPED (type
))
21305 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
21306 if (ENUM_IS_OPAQUE (type
))
21307 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21310 add_AT_unsigned (type_die
, DW_AT_encoding
,
21311 TYPE_UNSIGNED (type
)
21315 else if (! TYPE_SIZE (type
))
21318 remove_AT (type_die
, DW_AT_declaration
);
21320 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
21321 given enum type is incomplete, do not generate the DW_AT_byte_size
21322 attribute or the DW_AT_element_list attribute. */
21323 if (TYPE_SIZE (type
))
21327 TREE_ASM_WRITTEN (type
) = 1;
21328 add_byte_size_attribute (type_die
, type
);
21329 add_alignment_attribute (type_die
, type
);
21330 if (dwarf_version
>= 3 || !dwarf_strict
)
21332 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
21333 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
21336 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
21338 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
21339 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
21342 /* If the first reference to this type was as the return type of an
21343 inline function, then it may not have a parent. Fix this now. */
21344 if (type_die
->die_parent
== NULL
)
21345 add_child_die (scope_die_for (type
, context_die
), type_die
);
21347 for (link
= TYPE_VALUES (type
);
21348 link
!= NULL
; link
= TREE_CHAIN (link
))
21350 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
21351 tree value
= TREE_VALUE (link
);
21353 add_name_attribute (enum_die
,
21354 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
21356 if (TREE_CODE (value
) == CONST_DECL
)
21357 value
= DECL_INITIAL (value
);
21359 if (simple_type_size_in_bits (TREE_TYPE (value
))
21360 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
21362 /* For constant forms created by add_AT_unsigned DWARF
21363 consumers (GDB, elfutils, etc.) always zero extend
21364 the value. Only when the actual value is negative
21365 do we need to use add_AT_int to generate a constant
21366 form that can represent negative values. */
21367 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
21368 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
21369 add_AT_unsigned (enum_die
, DW_AT_const_value
,
21370 (unsigned HOST_WIDE_INT
) val
);
21372 add_AT_int (enum_die
, DW_AT_const_value
, val
);
21375 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
21376 that here. TODO: This should be re-worked to use correct
21377 signed/unsigned double tags for all cases. */
21378 add_AT_wide (enum_die
, DW_AT_const_value
, wi::to_wide (value
));
21381 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
21382 if (TYPE_ARTIFICIAL (type
))
21383 add_AT_flag (type_die
, DW_AT_artificial
, 1);
21386 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21388 add_pubtype (type
, type_die
);
21393 /* Generate a DIE to represent either a real live formal parameter decl or to
21394 represent just the type of some formal parameter position in some function
21397 Note that this routine is a bit unusual because its argument may be a
21398 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
21399 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
21400 node. If it's the former then this function is being called to output a
21401 DIE to represent a formal parameter object (or some inlining thereof). If
21402 it's the latter, then this function is only being called to output a
21403 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
21404 argument type of some subprogram type.
21405 If EMIT_NAME_P is true, name and source coordinate attributes
21409 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
21410 dw_die_ref context_die
)
21412 tree node_or_origin
= node
? node
: origin
;
21413 tree ultimate_origin
;
21414 dw_die_ref parm_die
= NULL
;
21416 if (DECL_P (node_or_origin
))
21418 parm_die
= lookup_decl_die (node
);
21420 /* If the contexts differ, we may not be talking about the same
21422 ??? When in LTO the DIE parent is the "abstract" copy and the
21423 context_die is the specification "copy". But this whole block
21424 should eventually be no longer needed. */
21425 if (parm_die
&& parm_die
->die_parent
!= context_die
&& !in_lto_p
)
21427 if (!DECL_ABSTRACT_P (node
))
21429 /* This can happen when creating an inlined instance, in
21430 which case we need to create a new DIE that will get
21431 annotated with DW_AT_abstract_origin. */
21435 gcc_unreachable ();
21438 if (parm_die
&& parm_die
->die_parent
== NULL
)
21440 /* Check that parm_die already has the right attributes that
21441 we would have added below. If any attributes are
21442 missing, fall through to add them. */
21443 if (! DECL_ABSTRACT_P (node_or_origin
)
21444 && !get_AT (parm_die
, DW_AT_location
)
21445 && !get_AT (parm_die
, DW_AT_const_value
))
21446 /* We are missing location info, and are about to add it. */
21450 add_child_die (context_die
, parm_die
);
21456 /* If we have a previously generated DIE, use it, unless this is an
21457 concrete instance (origin != NULL), in which case we need a new
21458 DIE with a corresponding DW_AT_abstract_origin. */
21460 if (parm_die
&& origin
== NULL
)
21461 reusing_die
= true;
21464 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
21465 reusing_die
= false;
21468 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
21470 case tcc_declaration
:
21471 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
21472 if (node
|| ultimate_origin
)
21473 origin
= ultimate_origin
;
21478 if (origin
!= NULL
)
21479 add_abstract_origin_attribute (parm_die
, origin
);
21480 else if (emit_name_p
)
21481 add_name_and_src_coords_attributes (parm_die
, node
);
21483 || (! DECL_ABSTRACT_P (node_or_origin
)
21484 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
21485 decl_function_context
21486 (node_or_origin
))))
21488 tree type
= TREE_TYPE (node_or_origin
);
21489 if (decl_by_reference_p (node_or_origin
))
21490 add_type_attribute (parm_die
, TREE_TYPE (type
),
21492 false, context_die
);
21494 add_type_attribute (parm_die
, type
,
21495 decl_quals (node_or_origin
),
21496 false, context_die
);
21498 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
21499 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21501 if (node
&& node
!= origin
)
21502 equate_decl_number_to_die (node
, parm_die
);
21503 if (! DECL_ABSTRACT_P (node_or_origin
))
21504 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
21510 /* We were called with some kind of a ..._TYPE node. */
21511 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
21516 gcc_unreachable ();
21522 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
21523 children DW_TAG_formal_parameter DIEs representing the arguments of the
21526 PARM_PACK must be a function parameter pack.
21527 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
21528 must point to the subsequent arguments of the function PACK_ARG belongs to.
21529 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
21530 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
21531 following the last one for which a DIE was generated. */
21534 gen_formal_parameter_pack_die (tree parm_pack
,
21536 dw_die_ref subr_die
,
21540 dw_die_ref parm_pack_die
;
21542 gcc_assert (parm_pack
21543 && lang_hooks
.function_parameter_pack_p (parm_pack
)
21546 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
21547 add_src_coords_attributes (parm_pack_die
, parm_pack
);
21549 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
21551 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
21554 gen_formal_parameter_die (arg
, NULL
,
21555 false /* Don't emit name attribute. */,
21560 return parm_pack_die
;
21563 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
21564 at the end of an (ANSI prototyped) formal parameters list. */
21567 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
21569 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
21572 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
21573 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
21574 parameters as specified in some function type specification (except for
21575 those which appear as part of a function *definition*). */
21578 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
21581 tree formal_type
= NULL
;
21582 tree first_parm_type
;
21585 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
21587 arg
= DECL_ARGUMENTS (function_or_method_type
);
21588 function_or_method_type
= TREE_TYPE (function_or_method_type
);
21593 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
21595 /* Make our first pass over the list of formal parameter types and output a
21596 DW_TAG_formal_parameter DIE for each one. */
21597 for (link
= first_parm_type
; link
; )
21599 dw_die_ref parm_die
;
21601 formal_type
= TREE_VALUE (link
);
21602 if (formal_type
== void_type_node
)
21605 /* Output a (nameless) DIE to represent the formal parameter itself. */
21606 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
21608 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
21609 true /* Emit name attribute. */,
21611 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
21612 && link
== first_parm_type
)
21614 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21615 if (dwarf_version
>= 3 || !dwarf_strict
)
21616 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
21618 else if (arg
&& DECL_ARTIFICIAL (arg
))
21619 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21622 link
= TREE_CHAIN (link
);
21624 arg
= DECL_CHAIN (arg
);
21627 /* If this function type has an ellipsis, add a
21628 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
21629 if (formal_type
!= void_type_node
)
21630 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
21632 /* Make our second (and final) pass over the list of formal parameter types
21633 and output DIEs to represent those types (as necessary). */
21634 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
21635 link
&& TREE_VALUE (link
);
21636 link
= TREE_CHAIN (link
))
21637 gen_type_die (TREE_VALUE (link
), context_die
);
21640 /* We want to generate the DIE for TYPE so that we can generate the
21641 die for MEMBER, which has been defined; we will need to refer back
21642 to the member declaration nested within TYPE. If we're trying to
21643 generate minimal debug info for TYPE, processing TYPE won't do the
21644 trick; we need to attach the member declaration by hand. */
21647 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
21649 gen_type_die (type
, context_die
);
21651 /* If we're trying to avoid duplicate debug info, we may not have
21652 emitted the member decl for this function. Emit it now. */
21653 if (TYPE_STUB_DECL (type
)
21654 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
21655 && ! lookup_decl_die (member
))
21657 dw_die_ref type_die
;
21658 gcc_assert (!decl_ultimate_origin (member
));
21660 push_decl_scope (type
);
21661 type_die
= lookup_type_die_strip_naming_typedef (type
);
21662 if (TREE_CODE (member
) == FUNCTION_DECL
)
21663 gen_subprogram_die (member
, type_die
);
21664 else if (TREE_CODE (member
) == FIELD_DECL
)
21666 /* Ignore the nameless fields that are used to skip bits but handle
21667 C++ anonymous unions and structs. */
21668 if (DECL_NAME (member
) != NULL_TREE
21669 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
21670 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
21672 struct vlr_context vlr_ctx
= {
21673 DECL_CONTEXT (member
), /* struct_type */
21674 NULL_TREE
/* variant_part_offset */
21676 gen_type_die (member_declared_type (member
), type_die
);
21677 gen_field_die (member
, &vlr_ctx
, type_die
);
21681 gen_variable_die (member
, NULL_TREE
, type_die
);
21687 /* Forward declare these functions, because they are mutually recursive
21688 with their set_block_* pairing functions. */
21689 static void set_decl_origin_self (tree
);
21691 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
21692 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
21693 that it points to the node itself, thus indicating that the node is its
21694 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
21695 the given node is NULL, recursively descend the decl/block tree which
21696 it is the root of, and for each other ..._DECL or BLOCK node contained
21697 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
21698 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
21699 values to point to themselves. */
21702 set_block_origin_self (tree stmt
)
21704 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
21706 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
21711 for (local_decl
= BLOCK_VARS (stmt
);
21712 local_decl
!= NULL_TREE
;
21713 local_decl
= DECL_CHAIN (local_decl
))
21714 /* Do not recurse on nested functions since the inlining status
21715 of parent and child can be different as per the DWARF spec. */
21716 if (TREE_CODE (local_decl
) != FUNCTION_DECL
21717 && !DECL_EXTERNAL (local_decl
))
21718 set_decl_origin_self (local_decl
);
21724 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
21725 subblock
!= NULL_TREE
;
21726 subblock
= BLOCK_CHAIN (subblock
))
21727 set_block_origin_self (subblock
); /* Recurse. */
21732 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
21733 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
21734 node to so that it points to the node itself, thus indicating that the
21735 node represents its own (abstract) origin. Additionally, if the
21736 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
21737 the decl/block tree of which the given node is the root of, and for
21738 each other ..._DECL or BLOCK node contained therein whose
21739 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
21740 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
21741 point to themselves. */
21744 set_decl_origin_self (tree decl
)
21746 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
21748 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
21749 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21753 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
21754 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
21755 if (DECL_INITIAL (decl
) != NULL_TREE
21756 && DECL_INITIAL (decl
) != error_mark_node
)
21757 set_block_origin_self (DECL_INITIAL (decl
));
21762 /* Mark the early DIE for DECL as the abstract instance. */
21765 dwarf2out_abstract_function (tree decl
)
21767 dw_die_ref old_die
;
21769 /* Make sure we have the actual abstract inline, not a clone. */
21770 decl
= DECL_ORIGIN (decl
);
21772 if (DECL_IGNORED_P (decl
))
21775 old_die
= lookup_decl_die (decl
);
21776 /* With early debug we always have an old DIE unless we are in LTO
21777 and the user did not compile but only link with debug. */
21778 if (in_lto_p
&& ! old_die
)
21780 gcc_assert (old_die
!= NULL
);
21781 if (get_AT (old_die
, DW_AT_inline
)
21782 || get_AT (old_die
, DW_AT_abstract_origin
))
21783 /* We've already generated the abstract instance. */
21786 /* Go ahead and put DW_AT_inline on the DIE. */
21787 if (DECL_DECLARED_INLINE_P (decl
))
21789 if (cgraph_function_possibly_inlined_p (decl
))
21790 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_inlined
);
21792 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
21796 if (cgraph_function_possibly_inlined_p (decl
))
21797 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_inlined
);
21799 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_not_inlined
);
21802 if (DECL_DECLARED_INLINE_P (decl
)
21803 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
21804 add_AT_flag (old_die
, DW_AT_artificial
, 1);
21806 set_decl_origin_self (decl
);
21809 /* Helper function of premark_used_types() which gets called through
21812 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21813 marked as unused by prune_unused_types. */
21816 premark_used_types_helper (tree
const &type
, void *)
21820 die
= lookup_type_die (type
);
21822 die
->die_perennial_p
= 1;
21826 /* Helper function of premark_types_used_by_global_vars which gets called
21827 through htab_traverse.
21829 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21830 marked as unused by prune_unused_types. The DIE of the type is marked
21831 only if the global variable using the type will actually be emitted. */
21834 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
21837 struct types_used_by_vars_entry
*entry
;
21840 entry
= (struct types_used_by_vars_entry
*) *slot
;
21841 gcc_assert (entry
->type
!= NULL
21842 && entry
->var_decl
!= NULL
);
21843 die
= lookup_type_die (entry
->type
);
21846 /* Ask cgraph if the global variable really is to be emitted.
21847 If yes, then we'll keep the DIE of ENTRY->TYPE. */
21848 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
21849 if (node
&& node
->definition
)
21851 die
->die_perennial_p
= 1;
21852 /* Keep the parent DIEs as well. */
21853 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
21854 die
->die_perennial_p
= 1;
21860 /* Mark all members of used_types_hash as perennial. */
21863 premark_used_types (struct function
*fun
)
21865 if (fun
&& fun
->used_types_hash
)
21866 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
21869 /* Mark all members of types_used_by_vars_entry as perennial. */
21872 premark_types_used_by_global_vars (void)
21874 if (types_used_by_vars_hash
)
21875 types_used_by_vars_hash
21876 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
21879 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
21880 for CA_LOC call arg loc node. */
21883 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
21884 struct call_arg_loc_node
*ca_loc
)
21886 dw_die_ref stmt_die
= NULL
, die
;
21887 tree block
= ca_loc
->block
;
21890 && block
!= DECL_INITIAL (decl
)
21891 && TREE_CODE (block
) == BLOCK
)
21893 stmt_die
= BLOCK_DIE (block
);
21896 block
= BLOCK_SUPERCONTEXT (block
);
21898 if (stmt_die
== NULL
)
21899 stmt_die
= subr_die
;
21900 die
= new_die (dwarf_TAG (DW_TAG_call_site
), stmt_die
, NULL_TREE
);
21901 add_AT_lbl_id (die
, dwarf_AT (DW_AT_call_return_pc
), ca_loc
->label
);
21902 if (ca_loc
->tail_call_p
)
21903 add_AT_flag (die
, dwarf_AT (DW_AT_call_tail_call
), 1);
21904 if (ca_loc
->symbol_ref
)
21906 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
21908 add_AT_die_ref (die
, dwarf_AT (DW_AT_call_origin
), tdie
);
21910 add_AT_addr (die
, dwarf_AT (DW_AT_call_origin
), ca_loc
->symbol_ref
,
21916 /* Generate a DIE to represent a declared function (either file-scope or
21920 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
21922 tree origin
= decl_ultimate_origin (decl
);
21923 dw_die_ref subr_die
;
21924 dw_die_ref old_die
= lookup_decl_die (decl
);
21926 /* This function gets called multiple times for different stages of
21927 the debug process. For example, for func() in this code:
21931 void func() { ... }
21934 ...we get called 4 times. Twice in early debug and twice in
21940 1. Once while generating func() within the namespace. This is
21941 the declaration. The declaration bit below is set, as the
21942 context is the namespace.
21944 A new DIE will be generated with DW_AT_declaration set.
21946 2. Once for func() itself. This is the specification. The
21947 declaration bit below is clear as the context is the CU.
21949 We will use the cached DIE from (1) to create a new DIE with
21950 DW_AT_specification pointing to the declaration in (1).
21952 Late debug via rest_of_handle_final()
21953 -------------------------------------
21955 3. Once generating func() within the namespace. This is also the
21956 declaration, as in (1), but this time we will early exit below
21957 as we have a cached DIE and a declaration needs no additional
21958 annotations (no locations), as the source declaration line
21961 4. Once for func() itself. As in (2), this is the specification,
21962 but this time we will re-use the cached DIE, and just annotate
21963 it with the location information that should now be available.
21965 For something without namespaces, but with abstract instances, we
21966 are also called a multiple times:
21971 Base (); // constructor declaration (1)
21974 Base::Base () { } // constructor specification (2)
21979 1. Once for the Base() constructor by virtue of it being a
21980 member of the Base class. This is done via
21981 rest_of_type_compilation.
21983 This is a declaration, so a new DIE will be created with
21986 2. Once for the Base() constructor definition, but this time
21987 while generating the abstract instance of the base
21988 constructor (__base_ctor) which is being generated via early
21989 debug of reachable functions.
21991 Even though we have a cached version of the declaration (1),
21992 we will create a DW_AT_specification of the declaration DIE
21995 3. Once for the __base_ctor itself, but this time, we generate
21996 an DW_AT_abstract_origin version of the DW_AT_specification in
21999 Late debug via rest_of_handle_final
22000 -----------------------------------
22002 4. One final time for the __base_ctor (which will have a cached
22003 DIE with DW_AT_abstract_origin created in (3). This time,
22004 we will just annotate the location information now
22007 int declaration
= (current_function_decl
!= decl
22008 || class_or_namespace_scope_p (context_die
));
22010 /* Now that the C++ front end lazily declares artificial member fns, we
22011 might need to retrofit the declaration into its class. */
22012 if (!declaration
&& !origin
&& !old_die
22013 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
22014 && !class_or_namespace_scope_p (context_die
)
22015 && debug_info_level
> DINFO_LEVEL_TERSE
)
22016 old_die
= force_decl_die (decl
);
22018 /* A concrete instance, tag a new DIE with DW_AT_abstract_origin. */
22019 if (origin
!= NULL
)
22021 gcc_assert (!declaration
|| local_scope_p (context_die
));
22023 /* Fixup die_parent for the abstract instance of a nested
22024 inline function. */
22025 if (old_die
&& old_die
->die_parent
== NULL
)
22026 add_child_die (context_die
, old_die
);
22028 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
22030 /* If we have a DW_AT_abstract_origin we have a working
22032 subr_die
= old_die
;
22036 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22037 add_abstract_origin_attribute (subr_die
, origin
);
22038 /* This is where the actual code for a cloned function is.
22039 Let's emit linkage name attribute for it. This helps
22040 debuggers to e.g, set breakpoints into
22041 constructors/destructors when the user asks "break
22043 add_linkage_name (subr_die
, decl
);
22046 /* A cached copy, possibly from early dwarf generation. Reuse as
22047 much as possible. */
22050 /* A declaration that has been previously dumped needs no
22051 additional information. */
22055 if (!get_AT_flag (old_die
, DW_AT_declaration
)
22056 /* We can have a normal definition following an inline one in the
22057 case of redefinition of GNU C extern inlines.
22058 It seems reasonable to use AT_specification in this case. */
22059 && !get_AT (old_die
, DW_AT_inline
))
22061 /* Detect and ignore this case, where we are trying to output
22062 something we have already output. */
22063 if (get_AT (old_die
, DW_AT_low_pc
)
22064 || get_AT (old_die
, DW_AT_ranges
))
22067 /* If we have no location information, this must be a
22068 partially generated DIE from early dwarf generation.
22069 Fall through and generate it. */
22072 /* If the definition comes from the same place as the declaration,
22073 maybe use the old DIE. We always want the DIE for this function
22074 that has the *_pc attributes to be under comp_unit_die so the
22075 debugger can find it. We also need to do this for abstract
22076 instances of inlines, since the spec requires the out-of-line copy
22077 to have the same parent. For local class methods, this doesn't
22078 apply; we just use the old DIE. */
22079 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
22080 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
22081 if ((is_cu_die (old_die
->die_parent
)
22082 /* This condition fixes the inconsistency/ICE with the
22083 following Fortran test (or some derivative thereof) while
22084 building libgfortran:
22088 logical function funky (FLAG)
22093 || (old_die
->die_parent
22094 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
22095 || context_die
== NULL
)
22096 && (DECL_ARTIFICIAL (decl
)
22097 /* The location attributes may be in the abstract origin
22098 which in the case of LTO might be not available to
22100 || get_AT (old_die
, DW_AT_abstract_origin
)
22101 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
22102 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
22103 == (unsigned) s
.line
)
22104 && (!debug_column_info
22106 || (get_AT_unsigned (old_die
, DW_AT_decl_column
)
22107 == (unsigned) s
.column
)))))
22109 subr_die
= old_die
;
22111 /* Clear out the declaration attribute, but leave the
22112 parameters so they can be augmented with location
22113 information later. Unless this was a declaration, in
22114 which case, wipe out the nameless parameters and recreate
22115 them further down. */
22116 if (remove_AT (subr_die
, DW_AT_declaration
))
22119 remove_AT (subr_die
, DW_AT_object_pointer
);
22120 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
22123 /* Make a specification pointing to the previously built
22127 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22128 add_AT_specification (subr_die
, old_die
);
22129 add_pubname (decl
, subr_die
);
22130 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
22131 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
22132 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
22133 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
22134 if (debug_column_info
22136 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
22137 != (unsigned) s
.column
))
22138 add_AT_unsigned (subr_die
, DW_AT_decl_column
, s
.column
);
22140 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
22141 emit the real type on the definition die. */
22142 if (is_cxx () && debug_info_level
> DINFO_LEVEL_TERSE
)
22144 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
22145 if (die
== auto_die
|| die
== decltype_auto_die
)
22146 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
22147 TYPE_UNQUALIFIED
, false, context_die
);
22150 /* When we process the method declaration, we haven't seen
22151 the out-of-class defaulted definition yet, so we have to
22153 if ((dwarf_version
>= 5 || ! dwarf_strict
)
22154 && !get_AT (subr_die
, DW_AT_defaulted
))
22157 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22159 if (defaulted
!= -1)
22161 /* Other values must have been handled before. */
22162 gcc_assert (defaulted
== DW_DEFAULTED_out_of_class
);
22163 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22168 /* Create a fresh DIE for anything else. */
22171 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22173 if (TREE_PUBLIC (decl
))
22174 add_AT_flag (subr_die
, DW_AT_external
, 1);
22176 add_name_and_src_coords_attributes (subr_die
, decl
);
22177 add_pubname (decl
, subr_die
);
22178 if (debug_info_level
> DINFO_LEVEL_TERSE
)
22180 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
22181 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
22182 TYPE_UNQUALIFIED
, false, context_die
);
22185 add_pure_or_virtual_attribute (subr_die
, decl
);
22186 if (DECL_ARTIFICIAL (decl
))
22187 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
22189 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
22190 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
22192 add_alignment_attribute (subr_die
, decl
);
22194 add_accessibility_attribute (subr_die
, decl
);
22197 /* Unless we have an existing non-declaration DIE, equate the new
22199 if (!old_die
|| is_declaration_die (old_die
))
22200 equate_decl_number_to_die (decl
, subr_die
);
22204 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
22206 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
22208 /* If this is an explicit function declaration then generate
22209 a DW_AT_explicit attribute. */
22210 if ((dwarf_version
>= 3 || !dwarf_strict
)
22211 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22212 DW_AT_explicit
) == 1)
22213 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
22215 /* If this is a C++11 deleted special function member then generate
22216 a DW_AT_deleted attribute. */
22217 if ((dwarf_version
>= 5 || !dwarf_strict
)
22218 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22219 DW_AT_deleted
) == 1)
22220 add_AT_flag (subr_die
, DW_AT_deleted
, 1);
22222 /* If this is a C++11 defaulted special function member then
22223 generate a DW_AT_defaulted attribute. */
22224 if (dwarf_version
>= 5 || !dwarf_strict
)
22227 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22229 if (defaulted
!= -1)
22230 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22233 /* If this is a C++11 non-static member function with & ref-qualifier
22234 then generate a DW_AT_reference attribute. */
22235 if ((dwarf_version
>= 5 || !dwarf_strict
)
22236 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22237 DW_AT_reference
) == 1)
22238 add_AT_flag (subr_die
, DW_AT_reference
, 1);
22240 /* If this is a C++11 non-static member function with &&
22241 ref-qualifier then generate a DW_AT_reference attribute. */
22242 if ((dwarf_version
>= 5 || !dwarf_strict
)
22243 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22244 DW_AT_rvalue_reference
)
22246 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
22249 /* For non DECL_EXTERNALs, if range information is available, fill
22250 the DIE with it. */
22251 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
22253 HOST_WIDE_INT cfa_fb_offset
;
22255 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
22257 if (!crtl
->has_bb_partition
)
22259 dw_fde_ref fde
= fun
->fde
;
22260 if (fde
->dw_fde_begin
)
22262 /* We have already generated the labels. */
22263 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22264 fde
->dw_fde_end
, false);
22268 /* Create start/end labels and add the range. */
22269 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
22270 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
22271 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
22272 current_function_funcdef_no
);
22273 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
22274 current_function_funcdef_no
);
22275 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
22279 #if VMS_DEBUGGING_INFO
22280 /* HP OpenVMS Industry Standard 64: DWARF Extensions
22281 Section 2.3 Prologue and Epilogue Attributes:
22282 When a breakpoint is set on entry to a function, it is generally
22283 desirable for execution to be suspended, not on the very first
22284 instruction of the function, but rather at a point after the
22285 function's frame has been set up, after any language defined local
22286 declaration processing has been completed, and before execution of
22287 the first statement of the function begins. Debuggers generally
22288 cannot properly determine where this point is. Similarly for a
22289 breakpoint set on exit from a function. The prologue and epilogue
22290 attributes allow a compiler to communicate the location(s) to use. */
22293 if (fde
->dw_fde_vms_end_prologue
)
22294 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
22295 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
22297 if (fde
->dw_fde_vms_begin_epilogue
)
22298 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
22299 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
22306 /* Generate pubnames entries for the split function code ranges. */
22307 dw_fde_ref fde
= fun
->fde
;
22309 if (fde
->dw_fde_second_begin
)
22311 if (dwarf_version
>= 3 || !dwarf_strict
)
22313 /* We should use ranges for non-contiguous code section
22314 addresses. Use the actual code range for the initial
22315 section, since the HOT/COLD labels might precede an
22316 alignment offset. */
22317 bool range_list_added
= false;
22318 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
22319 fde
->dw_fde_end
, &range_list_added
,
22321 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
22322 fde
->dw_fde_second_end
,
22323 &range_list_added
, false);
22324 if (range_list_added
)
22329 /* There is no real support in DW2 for this .. so we make
22330 a work-around. First, emit the pub name for the segment
22331 containing the function label. Then make and emit a
22332 simplified subprogram DIE for the second segment with the
22333 name pre-fixed by __hot/cold_sect_of_. We use the same
22334 linkage name for the second die so that gdb will find both
22335 sections when given "b foo". */
22336 const char *name
= NULL
;
22337 tree decl_name
= DECL_NAME (decl
);
22338 dw_die_ref seg_die
;
22340 /* Do the 'primary' section. */
22341 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22342 fde
->dw_fde_end
, false);
22344 /* Build a minimal DIE for the secondary section. */
22345 seg_die
= new_die (DW_TAG_subprogram
,
22346 subr_die
->die_parent
, decl
);
22348 if (TREE_PUBLIC (decl
))
22349 add_AT_flag (seg_die
, DW_AT_external
, 1);
22351 if (decl_name
!= NULL
22352 && IDENTIFIER_POINTER (decl_name
) != NULL
)
22354 name
= dwarf2_name (decl
, 1);
22355 if (! DECL_ARTIFICIAL (decl
))
22356 add_src_coords_attributes (seg_die
, decl
);
22358 add_linkage_name (seg_die
, decl
);
22360 gcc_assert (name
!= NULL
);
22361 add_pure_or_virtual_attribute (seg_die
, decl
);
22362 if (DECL_ARTIFICIAL (decl
))
22363 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
22365 name
= concat ("__second_sect_of_", name
, NULL
);
22366 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
22367 fde
->dw_fde_second_end
, false);
22368 add_name_attribute (seg_die
, name
);
22369 if (want_pubnames ())
22370 add_pubname_string (name
, seg_die
);
22374 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
22378 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
22380 /* We define the "frame base" as the function's CFA. This is more
22381 convenient for several reasons: (1) It's stable across the prologue
22382 and epilogue, which makes it better than just a frame pointer,
22383 (2) With dwarf3, there exists a one-byte encoding that allows us
22384 to reference the .debug_frame data by proxy, but failing that,
22385 (3) We can at least reuse the code inspection and interpretation
22386 code that determines the CFA position at various points in the
22388 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
22390 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
22391 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
22395 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
22396 if (list
->dw_loc_next
)
22397 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
22399 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
22402 /* Compute a displacement from the "steady-state frame pointer" to
22403 the CFA. The former is what all stack slots and argument slots
22404 will reference in the rtl; the latter is what we've told the
22405 debugger about. We'll need to adjust all frame_base references
22406 by this displacement. */
22407 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
22409 if (fun
->static_chain_decl
)
22411 /* DWARF requires here a location expression that computes the
22412 address of the enclosing subprogram's frame base. The machinery
22413 in tree-nested.c is supposed to store this specific address in the
22414 last field of the FRAME record. */
22415 const tree frame_type
22416 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
22417 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
22420 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
22421 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
22422 fb_expr
, fb_decl
, NULL_TREE
);
22424 add_AT_location_description (subr_die
, DW_AT_static_link
,
22425 loc_list_from_tree (fb_expr
, 0, NULL
));
22428 resolve_variable_values ();
22431 /* Generate child dies for template paramaters. */
22432 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
22433 gen_generic_params_dies (decl
);
22435 /* Now output descriptions of the arguments for this function. This gets
22436 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
22437 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
22438 `...' at the end of the formal parameter list. In order to find out if
22439 there was a trailing ellipsis or not, we must instead look at the type
22440 associated with the FUNCTION_DECL. This will be a node of type
22441 FUNCTION_TYPE. If the chain of type nodes hanging off of this
22442 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
22443 an ellipsis at the end. */
22445 /* In the case where we are describing a mere function declaration, all we
22446 need to do here (and all we *can* do here) is to describe the *types* of
22447 its formal parameters. */
22448 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
22450 else if (declaration
)
22451 gen_formal_types_die (decl
, subr_die
);
22454 /* Generate DIEs to represent all known formal parameters. */
22455 tree parm
= DECL_ARGUMENTS (decl
);
22456 tree generic_decl
= early_dwarf
22457 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
22458 tree generic_decl_parm
= generic_decl
22459 ? DECL_ARGUMENTS (generic_decl
)
22462 /* Now we want to walk the list of parameters of the function and
22463 emit their relevant DIEs.
22465 We consider the case of DECL being an instance of a generic function
22466 as well as it being a normal function.
22468 If DECL is an instance of a generic function we walk the
22469 parameters of the generic function declaration _and_ the parameters of
22470 DECL itself. This is useful because we want to emit specific DIEs for
22471 function parameter packs and those are declared as part of the
22472 generic function declaration. In that particular case,
22473 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
22474 That DIE has children DIEs representing the set of arguments
22475 of the pack. Note that the set of pack arguments can be empty.
22476 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
22479 Otherwise, we just consider the parameters of DECL. */
22480 while (generic_decl_parm
|| parm
)
22482 if (generic_decl_parm
22483 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
22484 gen_formal_parameter_pack_die (generic_decl_parm
,
22487 else if (parm
&& !POINTER_BOUNDS_P (parm
))
22489 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
22492 && parm
== DECL_ARGUMENTS (decl
)
22493 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
22495 && (dwarf_version
>= 3 || !dwarf_strict
))
22496 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
22498 parm
= DECL_CHAIN (parm
);
22501 parm
= DECL_CHAIN (parm
);
22503 if (generic_decl_parm
)
22504 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
22507 /* Decide whether we need an unspecified_parameters DIE at the end.
22508 There are 2 more cases to do this for: 1) the ansi ... declaration -
22509 this is detectable when the end of the arg list is not a
22510 void_type_node 2) an unprototyped function declaration (not a
22511 definition). This just means that we have no info about the
22512 parameters at all. */
22515 if (prototype_p (TREE_TYPE (decl
)))
22517 /* This is the prototyped case, check for.... */
22518 if (stdarg_p (TREE_TYPE (decl
)))
22519 gen_unspecified_parameters_die (decl
, subr_die
);
22521 else if (DECL_INITIAL (decl
) == NULL_TREE
)
22522 gen_unspecified_parameters_die (decl
, subr_die
);
22526 if (subr_die
!= old_die
)
22527 /* Add the calling convention attribute if requested. */
22528 add_calling_convention_attribute (subr_die
, decl
);
22530 /* Output Dwarf info for all of the stuff within the body of the function
22531 (if it has one - it may be just a declaration).
22533 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
22534 a function. This BLOCK actually represents the outermost binding contour
22535 for the function, i.e. the contour in which the function's formal
22536 parameters and labels get declared. Curiously, it appears that the front
22537 end doesn't actually put the PARM_DECL nodes for the current function onto
22538 the BLOCK_VARS list for this outer scope, but are strung off of the
22539 DECL_ARGUMENTS list for the function instead.
22541 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
22542 the LABEL_DECL nodes for the function however, and we output DWARF info
22543 for those in decls_for_scope. Just within the `outer_scope' there will be
22544 a BLOCK node representing the function's outermost pair of curly braces,
22545 and any blocks used for the base and member initializers of a C++
22546 constructor function. */
22547 tree outer_scope
= DECL_INITIAL (decl
);
22548 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
22550 int call_site_note_count
= 0;
22551 int tail_call_site_note_count
= 0;
22553 /* Emit a DW_TAG_variable DIE for a named return value. */
22554 if (DECL_NAME (DECL_RESULT (decl
)))
22555 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
22557 /* The first time through decls_for_scope we will generate the
22558 DIEs for the locals. The second time, we fill in the
22560 decls_for_scope (outer_scope
, subr_die
);
22562 if (call_arg_locations
&& (!dwarf_strict
|| dwarf_version
>= 5))
22564 struct call_arg_loc_node
*ca_loc
;
22565 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
22567 dw_die_ref die
= NULL
;
22568 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
22571 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
22572 ? NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
)
22574 arg
; arg
= next_arg
)
22576 dw_loc_descr_ref reg
, val
;
22577 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
22578 dw_die_ref cdie
, tdie
= NULL
;
22580 next_arg
= XEXP (arg
, 1);
22581 if (REG_P (XEXP (XEXP (arg
, 0), 0))
22583 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
22584 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
22585 && REGNO (XEXP (XEXP (arg
, 0), 0))
22586 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
22587 next_arg
= XEXP (next_arg
, 1);
22588 if (mode
== VOIDmode
)
22590 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
22591 if (mode
== VOIDmode
)
22592 mode
= GET_MODE (XEXP (arg
, 0));
22594 if (mode
== VOIDmode
|| mode
== BLKmode
)
22596 /* Get dynamic information about call target only if we
22597 have no static information: we cannot generate both
22598 DW_AT_call_origin and DW_AT_call_target
22600 if (ca_loc
->symbol_ref
== NULL_RTX
)
22602 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
22604 tloc
= XEXP (XEXP (arg
, 0), 1);
22607 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
22608 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
22610 tlocc
= XEXP (XEXP (arg
, 0), 1);
22615 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
22616 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
22617 VAR_INIT_STATUS_INITIALIZED
);
22618 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
22620 rtx mem
= XEXP (XEXP (arg
, 0), 0);
22621 reg
= mem_loc_descriptor (XEXP (mem
, 0),
22622 get_address_mode (mem
),
22624 VAR_INIT_STATUS_INITIALIZED
);
22626 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
22627 == DEBUG_PARAMETER_REF
)
22630 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
22631 tdie
= lookup_decl_die (tdecl
);
22638 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
22639 != DEBUG_PARAMETER_REF
)
22641 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
22643 VAR_INIT_STATUS_INITIALIZED
);
22647 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22648 cdie
= new_die (dwarf_TAG (DW_TAG_call_site_parameter
), die
,
22651 add_AT_loc (cdie
, DW_AT_location
, reg
);
22652 else if (tdie
!= NULL
)
22653 add_AT_die_ref (cdie
, dwarf_AT (DW_AT_call_parameter
),
22655 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_value
), val
);
22656 if (next_arg
!= XEXP (arg
, 1))
22658 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
22659 if (mode
== VOIDmode
)
22660 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
22661 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
22664 VAR_INIT_STATUS_INITIALIZED
);
22666 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_data_value
),
22671 && (ca_loc
->symbol_ref
|| tloc
))
22672 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22673 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
22675 dw_loc_descr_ref tval
= NULL
;
22677 if (tloc
!= NULL_RTX
)
22678 tval
= mem_loc_descriptor (tloc
,
22679 GET_MODE (tloc
) == VOIDmode
22680 ? Pmode
: GET_MODE (tloc
),
22682 VAR_INIT_STATUS_INITIALIZED
);
22684 add_AT_loc (die
, dwarf_AT (DW_AT_call_target
), tval
);
22685 else if (tlocc
!= NULL_RTX
)
22687 tval
= mem_loc_descriptor (tlocc
,
22688 GET_MODE (tlocc
) == VOIDmode
22689 ? Pmode
: GET_MODE (tlocc
),
22691 VAR_INIT_STATUS_INITIALIZED
);
22694 dwarf_AT (DW_AT_call_target_clobbered
),
22700 call_site_note_count
++;
22701 if (ca_loc
->tail_call_p
)
22702 tail_call_site_note_count
++;
22706 call_arg_locations
= NULL
;
22707 call_arg_loc_last
= NULL
;
22708 if (tail_call_site_count
>= 0
22709 && tail_call_site_count
== tail_call_site_note_count
22710 && (!dwarf_strict
|| dwarf_version
>= 5))
22712 if (call_site_count
>= 0
22713 && call_site_count
== call_site_note_count
)
22714 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_calls
), 1);
22716 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_tail_calls
), 1);
22718 call_site_count
= -1;
22719 tail_call_site_count
= -1;
22722 /* Mark used types after we have created DIEs for the functions scopes. */
22723 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
22726 /* Returns a hash value for X (which really is a die_struct). */
22729 block_die_hasher::hash (die_struct
*d
)
22731 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
22734 /* Return nonzero if decl_id and die_parent of die_struct X is the same
22735 as decl_id and die_parent of die_struct Y. */
22738 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
22740 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
22743 /* Return TRUE if DECL, which may have been previously generated as
22744 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
22745 true if decl (or its origin) is either an extern declaration or a
22746 class/namespace scoped declaration.
22748 The declare_in_namespace support causes us to get two DIEs for one
22749 variable, both of which are declarations. We want to avoid
22750 considering one to be a specification, so we must test for
22751 DECLARATION and DW_AT_declaration. */
22753 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
22755 return (old_die
&& TREE_STATIC (decl
) && !declaration
22756 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
22759 /* Return true if DECL is a local static. */
22762 local_function_static (tree decl
)
22764 gcc_assert (VAR_P (decl
));
22765 return TREE_STATIC (decl
)
22766 && DECL_CONTEXT (decl
)
22767 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
22770 /* Generate a DIE to represent a declared data object.
22771 Either DECL or ORIGIN must be non-null. */
22774 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
22776 HOST_WIDE_INT off
= 0;
22778 tree decl_or_origin
= decl
? decl
: origin
;
22779 tree ultimate_origin
;
22780 dw_die_ref var_die
;
22781 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
22782 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
22783 || class_or_namespace_scope_p (context_die
));
22784 bool specialization_p
= false;
22785 bool no_linkage_name
= false;
22787 /* While C++ inline static data members have definitions inside of the
22788 class, force the first DIE to be a declaration, then let gen_member_die
22789 reparent it to the class context and call gen_variable_die again
22790 to create the outside of the class DIE for the definition. */
22794 && DECL_CONTEXT (decl
)
22795 && TYPE_P (DECL_CONTEXT (decl
))
22796 && lang_hooks
.decls
.decl_dwarf_attribute (decl
, DW_AT_inline
) != -1)
22798 declaration
= true;
22799 if (dwarf_version
< 5)
22800 no_linkage_name
= true;
22803 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
22804 if (decl
|| ultimate_origin
)
22805 origin
= ultimate_origin
;
22806 com_decl
= fortran_common (decl_or_origin
, &off
);
22808 /* Symbol in common gets emitted as a child of the common block, in the form
22809 of a data member. */
22812 dw_die_ref com_die
;
22813 dw_loc_list_ref loc
= NULL
;
22814 die_node com_die_arg
;
22816 var_die
= lookup_decl_die (decl_or_origin
);
22819 if (! early_dwarf
&& get_AT (var_die
, DW_AT_location
) == NULL
)
22821 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
22826 /* Optimize the common case. */
22827 if (single_element_loc_list_p (loc
)
22828 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22829 && loc
->expr
->dw_loc_next
== NULL
22830 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
22833 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22834 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22835 = plus_constant (GET_MODE (x
), x
, off
);
22838 loc_list_plus_const (loc
, off
);
22840 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22841 remove_AT (var_die
, DW_AT_declaration
);
22847 if (common_block_die_table
== NULL
)
22848 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
22850 com_die_arg
.decl_id
= DECL_UID (com_decl
);
22851 com_die_arg
.die_parent
= context_die
;
22852 com_die
= common_block_die_table
->find (&com_die_arg
);
22854 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22855 if (com_die
== NULL
)
22858 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
22861 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
22862 add_name_and_src_coords_attributes (com_die
, com_decl
);
22865 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22866 /* Avoid sharing the same loc descriptor between
22867 DW_TAG_common_block and DW_TAG_variable. */
22868 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22870 else if (DECL_EXTERNAL (decl_or_origin
))
22871 add_AT_flag (com_die
, DW_AT_declaration
, 1);
22872 if (want_pubnames ())
22873 add_pubname_string (cnam
, com_die
); /* ??? needed? */
22874 com_die
->decl_id
= DECL_UID (com_decl
);
22875 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
22878 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
22880 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22881 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22882 remove_AT (com_die
, DW_AT_declaration
);
22884 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
22885 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
22886 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
22887 decl_quals (decl_or_origin
), false,
22889 add_alignment_attribute (var_die
, decl
);
22890 add_AT_flag (var_die
, DW_AT_external
, 1);
22895 /* Optimize the common case. */
22896 if (single_element_loc_list_p (loc
)
22897 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22898 && loc
->expr
->dw_loc_next
== NULL
22899 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
22901 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22902 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22903 = plus_constant (GET_MODE (x
), x
, off
);
22906 loc_list_plus_const (loc
, off
);
22908 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22910 else if (DECL_EXTERNAL (decl_or_origin
))
22911 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22913 equate_decl_number_to_die (decl
, var_die
);
22921 /* A declaration that has been previously dumped, needs no
22922 further annotations, since it doesn't need location on
22923 the second pass. */
22926 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
22927 && !get_AT (old_die
, DW_AT_specification
))
22929 /* Fall-thru so we can make a new variable die along with a
22930 DW_AT_specification. */
22932 else if (origin
&& old_die
->die_parent
!= context_die
)
22934 /* If we will be creating an inlined instance, we need a
22935 new DIE that will get annotated with
22936 DW_AT_abstract_origin. Clear things so we can get a
22938 gcc_assert (!DECL_ABSTRACT_P (decl
));
22943 /* If a DIE was dumped early, it still needs location info.
22944 Skip to where we fill the location bits. */
22947 /* ??? In LTRANS we cannot annotate early created variably
22948 modified type DIEs without copying them and adjusting all
22949 references to them. Thus we dumped them again, also add a
22950 reference to them. */
22951 tree type
= TREE_TYPE (decl_or_origin
);
22953 && variably_modified_type_p
22954 (type
, decl_function_context (decl_or_origin
)))
22956 if (decl_by_reference_p (decl_or_origin
))
22957 add_type_attribute (var_die
, TREE_TYPE (type
),
22958 TYPE_UNQUALIFIED
, false, context_die
);
22960 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
22961 false, context_die
);
22964 goto gen_variable_die_location
;
22968 /* For static data members, the declaration in the class is supposed
22969 to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
22970 also in DWARF2; the specification should still be DW_TAG_variable
22971 referencing the DW_TAG_member DIE. */
22972 if (declaration
&& class_scope_p (context_die
) && dwarf_version
< 5)
22973 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
22975 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
22977 if (origin
!= NULL
)
22978 add_abstract_origin_attribute (var_die
, origin
);
22980 /* Loop unrolling can create multiple blocks that refer to the same
22981 static variable, so we must test for the DW_AT_declaration flag.
22983 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
22984 copy decls and set the DECL_ABSTRACT_P flag on them instead of
22987 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
22988 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
22990 /* This is a definition of a C++ class level static. */
22991 add_AT_specification (var_die
, old_die
);
22992 specialization_p
= true;
22993 if (DECL_NAME (decl
))
22995 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
22996 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
22998 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
22999 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
23001 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
23002 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
23004 if (debug_column_info
23006 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
23007 != (unsigned) s
.column
))
23008 add_AT_unsigned (var_die
, DW_AT_decl_column
, s
.column
);
23010 if (old_die
->die_tag
== DW_TAG_member
)
23011 add_linkage_name (var_die
, decl
);
23015 add_name_and_src_coords_attributes (var_die
, decl
, no_linkage_name
);
23017 if ((origin
== NULL
&& !specialization_p
)
23019 && !DECL_ABSTRACT_P (decl_or_origin
)
23020 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
23021 decl_function_context
23022 (decl_or_origin
))))
23024 tree type
= TREE_TYPE (decl_or_origin
);
23026 if (decl_by_reference_p (decl_or_origin
))
23027 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23030 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
23034 if (origin
== NULL
&& !specialization_p
)
23036 if (TREE_PUBLIC (decl
))
23037 add_AT_flag (var_die
, DW_AT_external
, 1);
23039 if (DECL_ARTIFICIAL (decl
))
23040 add_AT_flag (var_die
, DW_AT_artificial
, 1);
23042 add_alignment_attribute (var_die
, decl
);
23044 add_accessibility_attribute (var_die
, decl
);
23048 add_AT_flag (var_die
, DW_AT_declaration
, 1);
23050 if (decl
&& (DECL_ABSTRACT_P (decl
)
23051 || !old_die
|| is_declaration_die (old_die
)))
23052 equate_decl_number_to_die (decl
, var_die
);
23054 gen_variable_die_location
:
23056 && (! DECL_ABSTRACT_P (decl_or_origin
)
23057 /* Local static vars are shared between all clones/inlines,
23058 so emit DW_AT_location on the abstract DIE if DECL_RTL is
23060 || (VAR_P (decl_or_origin
)
23061 && TREE_STATIC (decl_or_origin
)
23062 && DECL_RTL_SET_P (decl_or_origin
))))
23065 add_pubname (decl_or_origin
, var_die
);
23067 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
23071 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
23073 if ((dwarf_version
>= 4 || !dwarf_strict
)
23074 && lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
23075 DW_AT_const_expr
) == 1
23076 && !get_AT (var_die
, DW_AT_const_expr
)
23077 && !specialization_p
)
23078 add_AT_flag (var_die
, DW_AT_const_expr
, 1);
23082 int inl
= lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
23085 && !get_AT (var_die
, DW_AT_inline
)
23086 && !specialization_p
)
23087 add_AT_unsigned (var_die
, DW_AT_inline
, inl
);
23091 /* Generate a DIE to represent a named constant. */
23094 gen_const_die (tree decl
, dw_die_ref context_die
)
23096 dw_die_ref const_die
;
23097 tree type
= TREE_TYPE (decl
);
23099 const_die
= lookup_decl_die (decl
);
23103 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
23104 equate_decl_number_to_die (decl
, const_die
);
23105 add_name_and_src_coords_attributes (const_die
, decl
);
23106 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
23107 if (TREE_PUBLIC (decl
))
23108 add_AT_flag (const_die
, DW_AT_external
, 1);
23109 if (DECL_ARTIFICIAL (decl
))
23110 add_AT_flag (const_die
, DW_AT_artificial
, 1);
23111 tree_add_const_value_attribute_for_decl (const_die
, decl
);
23114 /* Generate a DIE to represent a label identifier. */
23117 gen_label_die (tree decl
, dw_die_ref context_die
)
23119 tree origin
= decl_ultimate_origin (decl
);
23120 dw_die_ref lbl_die
= lookup_decl_die (decl
);
23122 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23126 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
23127 equate_decl_number_to_die (decl
, lbl_die
);
23129 if (origin
!= NULL
)
23130 add_abstract_origin_attribute (lbl_die
, origin
);
23132 add_name_and_src_coords_attributes (lbl_die
, decl
);
23135 if (DECL_ABSTRACT_P (decl
))
23136 equate_decl_number_to_die (decl
, lbl_die
);
23137 else if (! early_dwarf
)
23139 insn
= DECL_RTL_IF_SET (decl
);
23141 /* Deleted labels are programmer specified labels which have been
23142 eliminated because of various optimizations. We still emit them
23143 here so that it is possible to put breakpoints on them. */
23147 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
23149 /* When optimization is enabled (via -O) some parts of the compiler
23150 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
23151 represent source-level labels which were explicitly declared by
23152 the user. This really shouldn't be happening though, so catch
23153 it if it ever does happen. */
23154 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
23156 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
23157 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23161 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
23162 && CODE_LABEL_NUMBER (insn
) != -1)
23164 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
23165 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23170 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
23171 attributes to the DIE for a block STMT, to describe where the inlined
23172 function was called from. This is similar to add_src_coords_attributes. */
23175 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
23177 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
23179 if (dwarf_version
>= 3 || !dwarf_strict
)
23181 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
23182 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
23183 if (debug_column_info
&& s
.column
)
23184 add_AT_unsigned (die
, DW_AT_call_column
, s
.column
);
23189 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
23190 Add low_pc and high_pc attributes to the DIE for a block STMT. */
23193 add_high_low_attributes (tree stmt
, dw_die_ref die
)
23195 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23197 if (BLOCK_FRAGMENT_CHAIN (stmt
)
23198 && (dwarf_version
>= 3 || !dwarf_strict
))
23200 tree chain
, superblock
= NULL_TREE
;
23202 dw_attr_node
*attr
= NULL
;
23204 if (inlined_function_outer_scope_p (stmt
))
23206 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23207 BLOCK_NUMBER (stmt
));
23208 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
23211 /* Optimize duplicate .debug_ranges lists or even tails of
23212 lists. If this BLOCK has same ranges as its supercontext,
23213 lookup DW_AT_ranges attribute in the supercontext (and
23214 recursively so), verify that the ranges_table contains the
23215 right values and use it instead of adding a new .debug_range. */
23216 for (chain
= stmt
, pdie
= die
;
23217 BLOCK_SAME_RANGE (chain
);
23218 chain
= BLOCK_SUPERCONTEXT (chain
))
23220 dw_attr_node
*new_attr
;
23222 pdie
= pdie
->die_parent
;
23225 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
23227 new_attr
= get_AT (pdie
, DW_AT_ranges
);
23228 if (new_attr
== NULL
23229 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
23232 superblock
= BLOCK_SUPERCONTEXT (chain
);
23235 && ((*ranges_table
)[attr
->dw_attr_val
.v
.val_offset
].num
23236 == BLOCK_NUMBER (superblock
))
23237 && BLOCK_FRAGMENT_CHAIN (superblock
))
23239 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
;
23240 unsigned long supercnt
= 0, thiscnt
= 0;
23241 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
23242 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23245 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
].num
23246 == BLOCK_NUMBER (chain
));
23248 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
+ 1].num
== 0);
23249 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23250 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23252 gcc_assert (supercnt
>= thiscnt
);
23253 add_AT_range_list (die
, DW_AT_ranges
, off
+ supercnt
- thiscnt
,
23255 note_rnglist_head (off
+ supercnt
- thiscnt
);
23259 unsigned int offset
= add_ranges (stmt
, true);
23260 add_AT_range_list (die
, DW_AT_ranges
, offset
, false);
23261 note_rnglist_head (offset
);
23263 bool prev_in_cold
= BLOCK_IN_COLD_SECTION_P (stmt
);
23264 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23267 add_ranges (chain
, prev_in_cold
!= BLOCK_IN_COLD_SECTION_P (chain
));
23268 prev_in_cold
= BLOCK_IN_COLD_SECTION_P (chain
);
23269 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
23276 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
23277 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23278 BLOCK_NUMBER (stmt
));
23279 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
23280 BLOCK_NUMBER (stmt
));
23281 add_AT_low_high_pc (die
, label
, label_high
, false);
23285 /* Generate a DIE for a lexical block. */
23288 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
23290 dw_die_ref old_die
= BLOCK_DIE (stmt
);
23291 dw_die_ref stmt_die
= NULL
;
23294 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23295 BLOCK_DIE (stmt
) = stmt_die
;
23298 if (BLOCK_ABSTRACT (stmt
))
23302 /* This must have been generated early and it won't even
23303 need location information since it's a DW_AT_inline
23306 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
23307 if (c
->die_tag
== DW_TAG_inlined_subroutine
23308 || c
->die_tag
== DW_TAG_subprogram
)
23310 gcc_assert (get_AT (c
, DW_AT_inline
));
23316 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
23318 /* If this is an inlined instance, create a new lexical die for
23319 anything below to attach DW_AT_abstract_origin to. */
23322 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23323 BLOCK_DIE (stmt
) = stmt_die
;
23327 tree origin
= block_ultimate_origin (stmt
);
23328 if (origin
!= NULL_TREE
&& origin
!= stmt
)
23329 add_abstract_origin_attribute (stmt_die
, origin
);
23333 stmt_die
= old_die
;
23335 /* A non abstract block whose blocks have already been reordered
23336 should have the instruction range for this block. If so, set the
23337 high/low attributes. */
23338 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
23340 gcc_assert (stmt_die
);
23341 add_high_low_attributes (stmt
, stmt_die
);
23344 decls_for_scope (stmt
, stmt_die
);
23347 /* Generate a DIE for an inlined subprogram. */
23350 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
23354 /* The instance of function that is effectively being inlined shall not
23356 gcc_assert (! BLOCK_ABSTRACT (stmt
));
23358 decl
= block_ultimate_origin (stmt
);
23360 /* Make sure any inlined functions are known to be inlineable. */
23361 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
23362 || cgraph_function_possibly_inlined_p (decl
));
23364 if (! BLOCK_ABSTRACT (stmt
))
23366 dw_die_ref subr_die
23367 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
23369 if (call_arg_locations
)
23370 BLOCK_DIE (stmt
) = subr_die
;
23371 add_abstract_origin_attribute (subr_die
, decl
);
23372 if (TREE_ASM_WRITTEN (stmt
))
23373 add_high_low_attributes (stmt
, subr_die
);
23374 add_call_src_coords_attributes (stmt
, subr_die
);
23376 decls_for_scope (stmt
, subr_die
);
23380 /* Generate a DIE for a field in a record, or structure. CTX is required: see
23381 the comment for VLR_CONTEXT. */
23384 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
23386 dw_die_ref decl_die
;
23388 if (TREE_TYPE (decl
) == error_mark_node
)
23391 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
23392 add_name_and_src_coords_attributes (decl_die
, decl
);
23393 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
23394 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
23397 if (DECL_BIT_FIELD_TYPE (decl
))
23399 add_byte_size_attribute (decl_die
, decl
);
23400 add_bit_size_attribute (decl_die
, decl
);
23401 add_bit_offset_attribute (decl_die
, decl
, ctx
);
23404 add_alignment_attribute (decl_die
, decl
);
23406 /* If we have a variant part offset, then we are supposed to process a member
23407 of a QUAL_UNION_TYPE, which is how we represent variant parts in
23409 gcc_assert (ctx
->variant_part_offset
== NULL_TREE
23410 || TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != QUAL_UNION_TYPE
);
23411 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
23412 add_data_member_location_attribute (decl_die
, decl
, ctx
);
23414 if (DECL_ARTIFICIAL (decl
))
23415 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
23417 add_accessibility_attribute (decl_die
, decl
);
23419 /* Equate decl number to die, so that we can look up this decl later on. */
23420 equate_decl_number_to_die (decl
, decl_die
);
23423 /* Generate a DIE for a pointer to a member type. TYPE can be an
23424 OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
23425 pointer to member function. */
23428 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
23430 if (lookup_type_die (type
))
23433 dw_die_ref ptr_die
= new_die (DW_TAG_ptr_to_member_type
,
23434 scope_die_for (type
, context_die
), type
);
23436 equate_type_number_to_die (type
, ptr_die
);
23437 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
23438 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
23439 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23441 add_alignment_attribute (ptr_die
, type
);
23443 if (TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
23444 && TREE_CODE (TREE_TYPE (type
)) != METHOD_TYPE
)
23446 dw_loc_descr_ref op
= new_loc_descr (DW_OP_plus
, 0, 0);
23447 add_AT_loc (ptr_die
, DW_AT_use_location
, op
);
23451 static char *producer_string
;
23453 /* Return a heap allocated producer string including command line options
23454 if -grecord-gcc-switches. */
23457 gen_producer_string (void)
23460 auto_vec
<const char *> switches
;
23461 const char *language_string
= lang_hooks
.name
;
23462 char *producer
, *tail
;
23464 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
23465 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
23467 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
23468 switch (save_decoded_options
[j
].opt_index
)
23475 case OPT_auxbase_strip
:
23484 case OPT_SPECIAL_unknown
:
23485 case OPT_SPECIAL_ignore
:
23486 case OPT_SPECIAL_program_name
:
23487 case OPT_SPECIAL_input_file
:
23488 case OPT_grecord_gcc_switches
:
23489 case OPT__output_pch_
:
23490 case OPT_fdiagnostics_show_location_
:
23491 case OPT_fdiagnostics_show_option
:
23492 case OPT_fdiagnostics_show_caret
:
23493 case OPT_fdiagnostics_color_
:
23494 case OPT_fverbose_asm
:
23496 case OPT__sysroot_
:
23498 case OPT_nostdinc__
:
23499 case OPT_fpreprocessed
:
23500 case OPT_fltrans_output_list_
:
23501 case OPT_fresolution_
:
23502 case OPT_fdebug_prefix_map_
:
23503 case OPT_fcompare_debug
:
23504 /* Ignore these. */
23507 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
23508 & CL_NO_DWARF_RECORD
)
23510 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
23512 switch (save_decoded_options
[j
].canonical_option
[0][1])
23519 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
23526 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
23527 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
23531 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
23533 sprintf (tail
, "%s %s", language_string
, version_string
);
23536 FOR_EACH_VEC_ELT (switches
, j
, p
)
23540 memcpy (tail
+ 1, p
, len
);
23548 /* Given a C and/or C++ language/version string return the "highest".
23549 C++ is assumed to be "higher" than C in this case. Used for merging
23550 LTO translation unit languages. */
23551 static const char *
23552 highest_c_language (const char *lang1
, const char *lang2
)
23554 if (strcmp ("GNU C++17", lang1
) == 0 || strcmp ("GNU C++17", lang2
) == 0)
23555 return "GNU C++17";
23556 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
23557 return "GNU C++14";
23558 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
23559 return "GNU C++11";
23560 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
23561 return "GNU C++98";
23563 if (strcmp ("GNU C17", lang1
) == 0 || strcmp ("GNU C17", lang2
) == 0)
23565 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
23567 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
23569 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
23572 gcc_unreachable ();
23576 /* Generate the DIE for the compilation unit. */
23579 gen_compile_unit_die (const char *filename
)
23582 const char *language_string
= lang_hooks
.name
;
23585 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
23589 add_name_attribute (die
, filename
);
23590 /* Don't add cwd for <built-in>. */
23591 if (filename
[0] != '<')
23592 add_comp_dir_attribute (die
);
23595 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
23597 /* If our producer is LTO try to figure out a common language to use
23598 from the global list of translation units. */
23599 if (strcmp (language_string
, "GNU GIMPLE") == 0)
23603 const char *common_lang
= NULL
;
23605 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
23607 if (!TRANSLATION_UNIT_LANGUAGE (t
))
23610 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
23611 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
23613 else if (strncmp (common_lang
, "GNU C", 5) == 0
23614 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
23615 /* Mixing C and C++ is ok, use C++ in that case. */
23616 common_lang
= highest_c_language (common_lang
,
23617 TRANSLATION_UNIT_LANGUAGE (t
));
23620 /* Fall back to C. */
23621 common_lang
= NULL
;
23627 language_string
= common_lang
;
23630 language
= DW_LANG_C
;
23631 if (strncmp (language_string
, "GNU C", 5) == 0
23632 && ISDIGIT (language_string
[5]))
23634 language
= DW_LANG_C89
;
23635 if (dwarf_version
>= 3 || !dwarf_strict
)
23637 if (strcmp (language_string
, "GNU C89") != 0)
23638 language
= DW_LANG_C99
;
23640 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23641 if (strcmp (language_string
, "GNU C11") == 0
23642 || strcmp (language_string
, "GNU C17") == 0)
23643 language
= DW_LANG_C11
;
23646 else if (strncmp (language_string
, "GNU C++", 7) == 0)
23648 language
= DW_LANG_C_plus_plus
;
23649 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23651 if (strcmp (language_string
, "GNU C++11") == 0)
23652 language
= DW_LANG_C_plus_plus_11
;
23653 else if (strcmp (language_string
, "GNU C++14") == 0)
23654 language
= DW_LANG_C_plus_plus_14
;
23655 else if (strcmp (language_string
, "GNU C++17") == 0)
23657 language
= DW_LANG_C_plus_plus_14
;
23660 else if (strcmp (language_string
, "GNU F77") == 0)
23661 language
= DW_LANG_Fortran77
;
23662 else if (dwarf_version
>= 3 || !dwarf_strict
)
23664 if (strcmp (language_string
, "GNU Ada") == 0)
23665 language
= DW_LANG_Ada95
;
23666 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23668 language
= DW_LANG_Fortran95
;
23669 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23671 if (strcmp (language_string
, "GNU Fortran2003") == 0)
23672 language
= DW_LANG_Fortran03
;
23673 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
23674 language
= DW_LANG_Fortran08
;
23677 else if (strcmp (language_string
, "GNU Objective-C") == 0)
23678 language
= DW_LANG_ObjC
;
23679 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
23680 language
= DW_LANG_ObjC_plus_plus
;
23681 else if (dwarf_version
>= 5 || !dwarf_strict
)
23683 if (strcmp (language_string
, "GNU Go") == 0)
23684 language
= DW_LANG_Go
;
23687 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
23688 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23689 language
= DW_LANG_Fortran90
;
23691 add_AT_unsigned (die
, DW_AT_language
, language
);
23695 case DW_LANG_Fortran77
:
23696 case DW_LANG_Fortran90
:
23697 case DW_LANG_Fortran95
:
23698 case DW_LANG_Fortran03
:
23699 case DW_LANG_Fortran08
:
23700 /* Fortran has case insensitive identifiers and the front-end
23701 lowercases everything. */
23702 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
23705 /* The default DW_ID_case_sensitive doesn't need to be specified. */
23711 /* Generate the DIE for a base class. */
23714 gen_inheritance_die (tree binfo
, tree access
, tree type
,
23715 dw_die_ref context_die
)
23717 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
23718 struct vlr_context ctx
= { type
, NULL
};
23720 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
23722 add_data_member_location_attribute (die
, binfo
, &ctx
);
23724 if (BINFO_VIRTUAL_P (binfo
))
23725 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
23727 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
23728 children, otherwise the default is DW_ACCESS_public. In DWARF2
23729 the default has always been DW_ACCESS_private. */
23730 if (access
== access_public_node
)
23732 if (dwarf_version
== 2
23733 || context_die
->die_tag
== DW_TAG_class_type
)
23734 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
23736 else if (access
== access_protected_node
)
23737 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
23738 else if (dwarf_version
> 2
23739 && context_die
->die_tag
!= DW_TAG_class_type
)
23740 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
23743 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
23746 is_variant_part (tree decl
)
23748 return (TREE_CODE (decl
) == FIELD_DECL
23749 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
23752 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
23753 return the FIELD_DECL. Return NULL_TREE otherwise. */
23756 analyze_discr_in_predicate (tree operand
, tree struct_type
)
23758 bool continue_stripping
= true;
23759 while (continue_stripping
)
23760 switch (TREE_CODE (operand
))
23763 operand
= TREE_OPERAND (operand
, 0);
23766 continue_stripping
= false;
23770 /* Match field access to members of struct_type only. */
23771 if (TREE_CODE (operand
) == COMPONENT_REF
23772 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
23773 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
23774 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
23775 return TREE_OPERAND (operand
, 1);
23780 /* Check that SRC is a constant integer that can be represented as a native
23781 integer constant (either signed or unsigned). If so, store it into DEST and
23782 return true. Return false otherwise. */
23785 get_discr_value (tree src
, dw_discr_value
*dest
)
23787 tree discr_type
= TREE_TYPE (src
);
23789 if (lang_hooks
.types
.get_debug_type
)
23791 tree debug_type
= lang_hooks
.types
.get_debug_type (discr_type
);
23792 if (debug_type
!= NULL
)
23793 discr_type
= debug_type
;
23796 if (TREE_CODE (src
) != INTEGER_CST
|| !INTEGRAL_TYPE_P (discr_type
))
23799 /* Signedness can vary between the original type and the debug type. This
23800 can happen for character types in Ada for instance: the character type
23801 used for code generation can be signed, to be compatible with the C one,
23802 but from a debugger point of view, it must be unsigned. */
23803 bool is_orig_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
23804 bool is_debug_unsigned
= TYPE_UNSIGNED (discr_type
);
23806 if (is_orig_unsigned
!= is_debug_unsigned
)
23807 src
= fold_convert (discr_type
, src
);
23809 if (!(is_debug_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
23812 dest
->pos
= is_debug_unsigned
;
23813 if (is_debug_unsigned
)
23814 dest
->v
.uval
= tree_to_uhwi (src
);
23816 dest
->v
.sval
= tree_to_shwi (src
);
23821 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
23822 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
23823 store NULL_TREE in DISCR_DECL. Otherwise:
23825 - store the discriminant field in STRUCT_TYPE that controls the variant
23826 part to *DISCR_DECL
23828 - put in *DISCR_LISTS_P an array where for each variant, the item
23829 represents the corresponding matching list of discriminant values.
23831 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
23834 Note that when the array is allocated (i.e. when the analysis is
23835 successful), it is up to the caller to free the array. */
23838 analyze_variants_discr (tree variant_part_decl
,
23841 dw_discr_list_ref
**discr_lists_p
,
23842 unsigned *discr_lists_length
)
23844 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23846 dw_discr_list_ref
*discr_lists
;
23849 /* Compute how many variants there are in this variant part. */
23850 *discr_lists_length
= 0;
23851 for (variant
= TYPE_FIELDS (variant_part_type
);
23852 variant
!= NULL_TREE
;
23853 variant
= DECL_CHAIN (variant
))
23854 ++*discr_lists_length
;
23856 *discr_decl
= NULL_TREE
;
23858 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
23859 sizeof (**discr_lists_p
));
23860 discr_lists
= *discr_lists_p
;
23862 /* And then analyze all variants to extract discriminant information for all
23863 of them. This analysis is conservative: as soon as we detect something we
23864 do not support, abort everything and pretend we found nothing. */
23865 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
23866 variant
!= NULL_TREE
;
23867 variant
= DECL_CHAIN (variant
), ++i
)
23869 tree match_expr
= DECL_QUALIFIER (variant
);
23871 /* Now, try to analyze the predicate and deduce a discriminant for
23873 if (match_expr
== boolean_true_node
)
23874 /* Typically happens for the default variant: it matches all cases that
23875 previous variants rejected. Don't output any matching value for
23879 /* The following loop tries to iterate over each discriminant
23880 possibility: single values or ranges. */
23881 while (match_expr
!= NULL_TREE
)
23883 tree next_round_match_expr
;
23884 tree candidate_discr
= NULL_TREE
;
23885 dw_discr_list_ref new_node
= NULL
;
23887 /* Possibilities are matched one after the other by nested
23888 TRUTH_ORIF_EXPR expressions. Process the current possibility and
23889 continue with the rest at next iteration. */
23890 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
23892 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
23893 match_expr
= TREE_OPERAND (match_expr
, 1);
23896 next_round_match_expr
= NULL_TREE
;
23898 if (match_expr
== boolean_false_node
)
23899 /* This sub-expression matches nothing: just wait for the next
23903 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
23905 /* We are matching: <discr_field> == <integer_cst>
23906 This sub-expression matches a single value. */
23907 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
23910 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
23913 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23914 if (!get_discr_value (integer_cst
,
23915 &new_node
->dw_discr_lower_bound
))
23917 new_node
->dw_discr_range
= false;
23920 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
23922 /* We are matching:
23923 <discr_field> > <integer_cst>
23924 && <discr_field> < <integer_cst>.
23925 This sub-expression matches the range of values between the
23926 two matched integer constants. Note that comparisons can be
23927 inclusive or exclusive. */
23928 tree candidate_discr_1
, candidate_discr_2
;
23929 tree lower_cst
, upper_cst
;
23930 bool lower_cst_included
, upper_cst_included
;
23931 tree lower_op
= TREE_OPERAND (match_expr
, 0);
23932 tree upper_op
= TREE_OPERAND (match_expr
, 1);
23934 /* When the comparison is exclusive, the integer constant is not
23935 the discriminant range bound we are looking for: we will have
23936 to increment or decrement it. */
23937 if (TREE_CODE (lower_op
) == GE_EXPR
)
23938 lower_cst_included
= true;
23939 else if (TREE_CODE (lower_op
) == GT_EXPR
)
23940 lower_cst_included
= false;
23944 if (TREE_CODE (upper_op
) == LE_EXPR
)
23945 upper_cst_included
= true;
23946 else if (TREE_CODE (upper_op
) == LT_EXPR
)
23947 upper_cst_included
= false;
23951 /* Extract the discriminant from the first operand and check it
23952 is consistant with the same analysis in the second
23955 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
23958 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
23960 if (candidate_discr_1
== candidate_discr_2
)
23961 candidate_discr
= candidate_discr_1
;
23965 /* Extract bounds from both. */
23966 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23967 lower_cst
= TREE_OPERAND (lower_op
, 1);
23968 upper_cst
= TREE_OPERAND (upper_op
, 1);
23970 if (!lower_cst_included
)
23972 = fold_build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
), lower_cst
,
23973 build_int_cst (TREE_TYPE (lower_cst
), 1));
23974 if (!upper_cst_included
)
23976 = fold_build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
), upper_cst
,
23977 build_int_cst (TREE_TYPE (upper_cst
), 1));
23979 if (!get_discr_value (lower_cst
,
23980 &new_node
->dw_discr_lower_bound
)
23981 || !get_discr_value (upper_cst
,
23982 &new_node
->dw_discr_upper_bound
))
23985 new_node
->dw_discr_range
= true;
23989 /* Unsupported sub-expression: we cannot determine the set of
23990 matching discriminant values. Abort everything. */
23993 /* If the discriminant info is not consistant with what we saw so
23994 far, consider the analysis failed and abort everything. */
23995 if (candidate_discr
== NULL_TREE
23996 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
23999 *discr_decl
= candidate_discr
;
24001 if (new_node
!= NULL
)
24003 new_node
->dw_discr_next
= discr_lists
[i
];
24004 discr_lists
[i
] = new_node
;
24006 match_expr
= next_round_match_expr
;
24010 /* If we reach this point, we could match everything we were interested
24015 /* Clean all data structure and return no result. */
24016 free (*discr_lists_p
);
24017 *discr_lists_p
= NULL
;
24018 *discr_decl
= NULL_TREE
;
24021 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
24022 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
24025 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
24026 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
24027 this type, which are record types, represent the available variants and each
24028 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
24029 values are inferred from these attributes.
24031 In trees, the offsets for the fields inside these sub-records are relative
24032 to the variant part itself, whereas the corresponding DIEs should have
24033 offset attributes that are relative to the embedding record base address.
24034 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
24035 must be an expression that computes the offset of the variant part to
24036 describe in DWARF. */
24039 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
24040 dw_die_ref context_die
)
24042 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
24043 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
24044 struct loc_descr_context ctx
= {
24045 vlr_ctx
->struct_type
, /* context_type */
24046 NULL_TREE
, /* base_decl */
24048 false, /* placeholder_arg */
24049 false /* placeholder_seen */
24052 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
24053 NULL_TREE if there is no such field. */
24054 tree discr_decl
= NULL_TREE
;
24055 dw_discr_list_ref
*discr_lists
;
24056 unsigned discr_lists_length
= 0;
24059 dw_die_ref dwarf_proc_die
= NULL
;
24060 dw_die_ref variant_part_die
24061 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
24063 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
24065 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
24066 &discr_decl
, &discr_lists
, &discr_lists_length
);
24068 if (discr_decl
!= NULL_TREE
)
24070 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
24073 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
24075 /* We have no DIE for the discriminant, so just discard all
24076 discrimimant information in the output. */
24077 discr_decl
= NULL_TREE
;
24080 /* If the offset for this variant part is more complex than a constant,
24081 create a DWARF procedure for it so that we will not have to generate DWARF
24082 expressions for it for each member. */
24083 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
24084 && (dwarf_version
>= 3 || !dwarf_strict
))
24086 const tree dwarf_proc_fndecl
24087 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
24088 build_function_type (TREE_TYPE (variant_part_offset
),
24090 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
24091 const dw_loc_descr_ref dwarf_proc_body
24092 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
24094 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
24095 dwarf_proc_fndecl
, context_die
);
24096 if (dwarf_proc_die
!= NULL
)
24097 variant_part_offset
= dwarf_proc_call
;
24100 /* Output DIEs for all variants. */
24102 for (tree variant
= TYPE_FIELDS (variant_part_type
);
24103 variant
!= NULL_TREE
;
24104 variant
= DECL_CHAIN (variant
), ++i
)
24106 tree variant_type
= TREE_TYPE (variant
);
24107 dw_die_ref variant_die
;
24109 /* All variants (i.e. members of a variant part) are supposed to be
24110 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
24111 under these records. */
24112 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
24114 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
24115 equate_decl_number_to_die (variant
, variant_die
);
24117 /* Output discriminant values this variant matches, if any. */
24118 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
24119 /* In the case we have discriminant information at all, this is
24120 probably the default variant: as the standard says, don't
24121 output any discriminant value/list attribute. */
24123 else if (discr_lists
[i
]->dw_discr_next
== NULL
24124 && !discr_lists
[i
]->dw_discr_range
)
24125 /* If there is only one accepted value, don't bother outputting a
24127 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
24129 add_discr_list (variant_die
, discr_lists
[i
]);
24131 for (tree member
= TYPE_FIELDS (variant_type
);
24132 member
!= NULL_TREE
;
24133 member
= DECL_CHAIN (member
))
24135 struct vlr_context vlr_sub_ctx
= {
24136 vlr_ctx
->struct_type
, /* struct_type */
24137 NULL
/* variant_part_offset */
24139 if (is_variant_part (member
))
24141 /* All offsets for fields inside variant parts are relative to
24142 the top-level embedding RECORD_TYPE's base address. On the
24143 other hand, offsets in GCC's types are relative to the
24144 nested-most variant part. So we have to sum offsets each time
24147 vlr_sub_ctx
.variant_part_offset
24148 = fold_build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
24149 variant_part_offset
, byte_position (member
));
24150 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
24154 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
24155 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
24160 free (discr_lists
);
24163 /* Generate a DIE for a class member. */
24166 gen_member_die (tree type
, dw_die_ref context_die
)
24169 tree binfo
= TYPE_BINFO (type
);
24171 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
24173 /* If this is not an incomplete type, output descriptions of each of its
24174 members. Note that as we output the DIEs necessary to represent the
24175 members of this record or union type, we will also be trying to output
24176 DIEs to represent the *types* of those members. However the `type'
24177 function (above) will specifically avoid generating type DIEs for member
24178 types *within* the list of member DIEs for this (containing) type except
24179 for those types (of members) which are explicitly marked as also being
24180 members of this (containing) type themselves. The g++ front- end can
24181 force any given type to be treated as a member of some other (containing)
24182 type by setting the TYPE_CONTEXT of the given (member) type to point to
24183 the TREE node representing the appropriate (containing) type. */
24185 /* First output info about the base classes. */
24188 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
24192 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
24193 gen_inheritance_die (base
,
24194 (accesses
? (*accesses
)[i
] : access_public_node
),
24199 /* Now output info about the data members and type members. */
24200 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
24202 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
24203 bool static_inline_p
24204 = (TREE_STATIC (member
)
24205 && (lang_hooks
.decls
.decl_dwarf_attribute (member
, DW_AT_inline
)
24208 /* Ignore clones. */
24209 if (DECL_ABSTRACT_ORIGIN (member
))
24212 /* If we thought we were generating minimal debug info for TYPE
24213 and then changed our minds, some of the member declarations
24214 may have already been defined. Don't define them again, but
24215 do put them in the right order. */
24217 if (dw_die_ref child
= lookup_decl_die (member
))
24219 /* Handle inline static data members, which only have in-class
24221 dw_die_ref ref
= NULL
;
24222 if (child
->die_tag
== DW_TAG_variable
24223 && child
->die_parent
== comp_unit_die ())
24225 ref
= get_AT_ref (child
, DW_AT_specification
);
24226 /* For C++17 inline static data members followed by redundant
24227 out of class redeclaration, we might get here with
24228 child being the DIE created for the out of class
24229 redeclaration and with its DW_AT_specification being
24230 the DIE created for in-class definition. We want to
24231 reparent the latter, and don't want to create another
24232 DIE with DW_AT_specification in that case, because
24233 we already have one. */
24236 && ref
->die_tag
== DW_TAG_variable
24237 && ref
->die_parent
== comp_unit_die ()
24238 && get_AT (ref
, DW_AT_specification
) == NULL
)
24242 static_inline_p
= false;
24246 if (child
->die_tag
== DW_TAG_variable
24247 && child
->die_parent
== comp_unit_die ()
24250 reparent_child (child
, context_die
);
24251 if (dwarf_version
< 5)
24252 child
->die_tag
= DW_TAG_member
;
24255 splice_child_die (context_die
, child
);
24258 /* Do not generate standard DWARF for variant parts if we are generating
24259 the corresponding GNAT encodings: DIEs generated for both would
24260 conflict in our mappings. */
24261 else if (is_variant_part (member
)
24262 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
)
24264 vlr_ctx
.variant_part_offset
= byte_position (member
);
24265 gen_variant_part (member
, &vlr_ctx
, context_die
);
24269 vlr_ctx
.variant_part_offset
= NULL_TREE
;
24270 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
24273 /* For C++ inline static data members emit immediately a DW_TAG_variable
24274 DIE that will refer to that DW_TAG_member/DW_TAG_variable through
24275 DW_AT_specification. */
24276 if (static_inline_p
)
24278 int old_extern
= DECL_EXTERNAL (member
);
24279 DECL_EXTERNAL (member
) = 0;
24280 gen_decl_die (member
, NULL
, NULL
, comp_unit_die ());
24281 DECL_EXTERNAL (member
) = old_extern
;
24286 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
24287 is set, we pretend that the type was never defined, so we only get the
24288 member DIEs needed by later specification DIEs. */
24291 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
24292 enum debug_info_usage usage
)
24294 if (TREE_ASM_WRITTEN (type
))
24296 /* Fill in the bound of variable-length fields in late dwarf if
24297 still incomplete. */
24298 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
24299 for (tree member
= TYPE_FIELDS (type
);
24301 member
= DECL_CHAIN (member
))
24302 fill_variable_array_bounds (TREE_TYPE (member
));
24306 dw_die_ref type_die
= lookup_type_die (type
);
24307 dw_die_ref scope_die
= 0;
24309 int complete
= (TYPE_SIZE (type
)
24310 && (! TYPE_STUB_DECL (type
)
24311 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
24312 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
24313 complete
= complete
&& should_emit_struct_debug (type
, usage
);
24315 if (type_die
&& ! complete
)
24318 if (TYPE_CONTEXT (type
) != NULL_TREE
24319 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24320 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
24323 scope_die
= scope_die_for (type
, context_die
);
24325 /* Generate child dies for template paramaters. */
24326 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
24327 schedule_generic_params_dies_gen (type
);
24329 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
24330 /* First occurrence of type or toplevel definition of nested class. */
24332 dw_die_ref old_die
= type_die
;
24334 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
24335 ? record_type_tag (type
) : DW_TAG_union_type
,
24337 equate_type_number_to_die (type
, type_die
);
24339 add_AT_specification (type_die
, old_die
);
24341 add_name_attribute (type_die
, type_tag (type
));
24344 remove_AT (type_die
, DW_AT_declaration
);
24346 /* If this type has been completed, then give it a byte_size attribute and
24347 then give a list of members. */
24348 if (complete
&& !ns_decl
)
24350 /* Prevent infinite recursion in cases where the type of some member of
24351 this type is expressed in terms of this type itself. */
24352 TREE_ASM_WRITTEN (type
) = 1;
24353 add_byte_size_attribute (type_die
, type
);
24354 add_alignment_attribute (type_die
, type
);
24355 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
24357 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
24358 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
24361 /* If the first reference to this type was as the return type of an
24362 inline function, then it may not have a parent. Fix this now. */
24363 if (type_die
->die_parent
== NULL
)
24364 add_child_die (scope_die
, type_die
);
24366 push_decl_scope (type
);
24367 gen_member_die (type
, type_die
);
24370 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
24371 if (TYPE_ARTIFICIAL (type
))
24372 add_AT_flag (type_die
, DW_AT_artificial
, 1);
24374 /* GNU extension: Record what type our vtable lives in. */
24375 if (TYPE_VFIELD (type
))
24377 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
24379 gen_type_die (vtype
, context_die
);
24380 add_AT_die_ref (type_die
, DW_AT_containing_type
,
24381 lookup_type_die (vtype
));
24386 add_AT_flag (type_die
, DW_AT_declaration
, 1);
24388 /* We don't need to do this for function-local types. */
24389 if (TYPE_STUB_DECL (type
)
24390 && ! decl_function_context (TYPE_STUB_DECL (type
)))
24391 vec_safe_push (incomplete_types
, type
);
24394 if (get_AT (type_die
, DW_AT_name
))
24395 add_pubtype (type
, type_die
);
24398 /* Generate a DIE for a subroutine _type_. */
24401 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
24403 tree return_type
= TREE_TYPE (type
);
24404 dw_die_ref subr_die
24405 = new_die (DW_TAG_subroutine_type
,
24406 scope_die_for (type
, context_die
), type
);
24408 equate_type_number_to_die (type
, subr_die
);
24409 add_prototyped_attribute (subr_die
, type
);
24410 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
24412 add_alignment_attribute (subr_die
, type
);
24413 gen_formal_types_die (type
, subr_die
);
24415 if (get_AT (subr_die
, DW_AT_name
))
24416 add_pubtype (type
, subr_die
);
24417 if ((dwarf_version
>= 5 || !dwarf_strict
)
24418 && lang_hooks
.types
.type_dwarf_attribute (type
, DW_AT_reference
) != -1)
24419 add_AT_flag (subr_die
, DW_AT_reference
, 1);
24420 if ((dwarf_version
>= 5 || !dwarf_strict
)
24421 && lang_hooks
.types
.type_dwarf_attribute (type
,
24422 DW_AT_rvalue_reference
) != -1)
24423 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
24426 /* Generate a DIE for a type definition. */
24429 gen_typedef_die (tree decl
, dw_die_ref context_die
)
24431 dw_die_ref type_die
;
24434 if (TREE_ASM_WRITTEN (decl
))
24436 if (DECL_ORIGINAL_TYPE (decl
))
24437 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
24441 /* As we avoid creating DIEs for local typedefs (see decl_ultimate_origin
24442 checks in process_scope_var and modified_type_die), this should be called
24443 only for original types. */
24444 gcc_assert (decl_ultimate_origin (decl
) == NULL
24445 || decl_ultimate_origin (decl
) == decl
);
24447 TREE_ASM_WRITTEN (decl
) = 1;
24448 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
24450 add_name_and_src_coords_attributes (type_die
, decl
);
24451 if (DECL_ORIGINAL_TYPE (decl
))
24453 type
= DECL_ORIGINAL_TYPE (decl
);
24454 if (type
== error_mark_node
)
24457 gcc_assert (type
!= TREE_TYPE (decl
));
24458 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
24462 type
= TREE_TYPE (decl
);
24463 if (type
== error_mark_node
)
24466 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24468 /* Here, we are in the case of decl being a typedef naming
24469 an anonymous type, e.g:
24470 typedef struct {...} foo;
24471 In that case TREE_TYPE (decl) is not a typedef variant
24472 type and TYPE_NAME of the anonymous type is set to the
24473 TYPE_DECL of the typedef. This construct is emitted by
24476 TYPE is the anonymous struct named by the typedef
24477 DECL. As we need the DW_AT_type attribute of the
24478 DW_TAG_typedef to point to the DIE of TYPE, let's
24479 generate that DIE right away. add_type_attribute
24480 called below will then pick (via lookup_type_die) that
24481 anonymous struct DIE. */
24482 if (!TREE_ASM_WRITTEN (type
))
24483 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
24485 /* This is a GNU Extension. We are adding a
24486 DW_AT_linkage_name attribute to the DIE of the
24487 anonymous struct TYPE. The value of that attribute
24488 is the name of the typedef decl naming the anonymous
24489 struct. This greatly eases the work of consumers of
24490 this debug info. */
24491 add_linkage_name_raw (lookup_type_die (type
), decl
);
24495 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
24498 if (is_naming_typedef_decl (decl
))
24499 /* We want that all subsequent calls to lookup_type_die with
24500 TYPE in argument yield the DW_TAG_typedef we have just
24502 equate_type_number_to_die (type
, type_die
);
24504 add_alignment_attribute (type_die
, TREE_TYPE (decl
));
24506 add_accessibility_attribute (type_die
, decl
);
24508 if (DECL_ABSTRACT_P (decl
))
24509 equate_decl_number_to_die (decl
, type_die
);
24511 if (get_AT (type_die
, DW_AT_name
))
24512 add_pubtype (decl
, type_die
);
24515 /* Generate a DIE for a struct, class, enum or union type. */
24518 gen_tagged_type_die (tree type
,
24519 dw_die_ref context_die
,
24520 enum debug_info_usage usage
)
24524 if (type
== NULL_TREE
24525 || !is_tagged_type (type
))
24528 if (TREE_ASM_WRITTEN (type
))
24530 /* If this is a nested type whose containing class hasn't been written
24531 out yet, writing it out will cover this one, too. This does not apply
24532 to instantiations of member class templates; they need to be added to
24533 the containing class as they are generated. FIXME: This hurts the
24534 idea of combining type decls from multiple TUs, since we can't predict
24535 what set of template instantiations we'll get. */
24536 else if (TYPE_CONTEXT (type
)
24537 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24538 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
24540 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
24542 if (TREE_ASM_WRITTEN (type
))
24545 /* If that failed, attach ourselves to the stub. */
24546 push_decl_scope (TYPE_CONTEXT (type
));
24547 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
24550 else if (TYPE_CONTEXT (type
) != NULL_TREE
24551 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
24553 /* If this type is local to a function that hasn't been written
24554 out yet, use a NULL context for now; it will be fixed up in
24555 decls_for_scope. */
24556 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
24557 /* A declaration DIE doesn't count; nested types need to go in the
24559 if (context_die
&& is_declaration_die (context_die
))
24560 context_die
= NULL
;
24565 context_die
= declare_in_namespace (type
, context_die
);
24569 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
24571 /* This might have been written out by the call to
24572 declare_in_namespace. */
24573 if (!TREE_ASM_WRITTEN (type
))
24574 gen_enumeration_type_die (type
, context_die
);
24577 gen_struct_or_union_type_die (type
, context_die
, usage
);
24582 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
24583 it up if it is ever completed. gen_*_type_die will set it for us
24584 when appropriate. */
24587 /* Generate a type description DIE. */
24590 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
24591 enum debug_info_usage usage
)
24593 struct array_descr_info info
;
24595 if (type
== NULL_TREE
|| type
== error_mark_node
)
24598 if (flag_checking
&& type
)
24599 verify_type (type
);
24601 if (TYPE_NAME (type
) != NULL_TREE
24602 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
24603 && is_redundant_typedef (TYPE_NAME (type
))
24604 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
24605 /* The DECL of this type is a typedef we don't want to emit debug
24606 info for but we want debug info for its underlying typedef.
24607 This can happen for e.g, the injected-class-name of a C++
24609 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
24611 /* If TYPE is a typedef type variant, let's generate debug info
24612 for the parent typedef which TYPE is a type of. */
24613 if (typedef_variant_p (type
))
24615 if (TREE_ASM_WRITTEN (type
))
24618 tree name
= TYPE_NAME (type
);
24619 tree origin
= decl_ultimate_origin (name
);
24620 if (origin
!= NULL
&& origin
!= name
)
24622 gen_decl_die (origin
, NULL
, NULL
, context_die
);
24626 /* Prevent broken recursion; we can't hand off to the same type. */
24627 gcc_assert (DECL_ORIGINAL_TYPE (name
) != type
);
24629 /* Give typedefs the right scope. */
24630 context_die
= scope_die_for (type
, context_die
);
24632 TREE_ASM_WRITTEN (type
) = 1;
24634 gen_decl_die (name
, NULL
, NULL
, context_die
);
24638 /* If type is an anonymous tagged type named by a typedef, let's
24639 generate debug info for the typedef. */
24640 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24642 /* Use the DIE of the containing namespace as the parent DIE of
24643 the type description DIE we want to generate. */
24644 if (DECL_CONTEXT (TYPE_NAME (type
))
24645 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
24646 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
24648 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
24652 if (lang_hooks
.types
.get_debug_type
)
24654 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
24656 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
24658 gen_type_die_with_usage (debug_type
, context_die
, usage
);
24663 /* We are going to output a DIE to represent the unqualified version
24664 of this type (i.e. without any const or volatile qualifiers) so
24665 get the main variant (i.e. the unqualified version) of this type
24666 now. (Vectors and arrays are special because the debugging info is in the
24667 cloned type itself. Similarly function/method types can contain extra
24668 ref-qualification). */
24669 if (TREE_CODE (type
) == FUNCTION_TYPE
24670 || TREE_CODE (type
) == METHOD_TYPE
)
24672 /* For function/method types, can't use type_main_variant here,
24673 because that can have different ref-qualifiers for C++,
24674 but try to canonicalize. */
24675 tree main
= TYPE_MAIN_VARIANT (type
);
24676 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
24677 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
24678 && check_base_type (t
, main
)
24679 && check_lang_type (t
, type
))
24685 else if (TREE_CODE (type
) != VECTOR_TYPE
24686 && TREE_CODE (type
) != ARRAY_TYPE
)
24687 type
= type_main_variant (type
);
24689 /* If this is an array type with hidden descriptor, handle it first. */
24690 if (!TREE_ASM_WRITTEN (type
)
24691 && lang_hooks
.types
.get_array_descr_info
)
24693 memset (&info
, 0, sizeof (info
));
24694 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
24696 /* Fortran sometimes emits array types with no dimension. */
24697 gcc_assert (info
.ndimensions
>= 0
24698 && (info
.ndimensions
24699 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
24700 gen_descr_array_type_die (type
, &info
, context_die
);
24701 TREE_ASM_WRITTEN (type
) = 1;
24706 if (TREE_ASM_WRITTEN (type
))
24708 /* Variable-length types may be incomplete even if
24709 TREE_ASM_WRITTEN. For such types, fall through to
24710 gen_array_type_die() and possibly fill in
24711 DW_AT_{upper,lower}_bound attributes. */
24712 if ((TREE_CODE (type
) != ARRAY_TYPE
24713 && TREE_CODE (type
) != RECORD_TYPE
24714 && TREE_CODE (type
) != UNION_TYPE
24715 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
24716 || !variably_modified_type_p (type
, NULL
))
24720 switch (TREE_CODE (type
))
24726 case REFERENCE_TYPE
:
24727 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
24728 ensures that the gen_type_die recursion will terminate even if the
24729 type is recursive. Recursive types are possible in Ada. */
24730 /* ??? We could perhaps do this for all types before the switch
24732 TREE_ASM_WRITTEN (type
) = 1;
24734 /* For these types, all that is required is that we output a DIE (or a
24735 set of DIEs) to represent the "basis" type. */
24736 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24737 DINFO_USAGE_IND_USE
);
24741 /* This code is used for C++ pointer-to-data-member types.
24742 Output a description of the relevant class type. */
24743 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
24744 DINFO_USAGE_IND_USE
);
24746 /* Output a description of the type of the object pointed to. */
24747 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24748 DINFO_USAGE_IND_USE
);
24750 /* Now output a DIE to represent this pointer-to-data-member type
24752 gen_ptr_to_mbr_type_die (type
, context_die
);
24755 case FUNCTION_TYPE
:
24756 /* Force out return type (in case it wasn't forced out already). */
24757 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24758 DINFO_USAGE_DIR_USE
);
24759 gen_subroutine_type_die (type
, context_die
);
24763 /* Force out return type (in case it wasn't forced out already). */
24764 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24765 DINFO_USAGE_DIR_USE
);
24766 gen_subroutine_type_die (type
, context_die
);
24771 gen_array_type_die (type
, context_die
);
24774 case ENUMERAL_TYPE
:
24777 case QUAL_UNION_TYPE
:
24778 gen_tagged_type_die (type
, context_die
, usage
);
24784 case FIXED_POINT_TYPE
:
24787 case POINTER_BOUNDS_TYPE
:
24788 /* No DIEs needed for fundamental types. */
24793 /* Just use DW_TAG_unspecified_type. */
24795 dw_die_ref type_die
= lookup_type_die (type
);
24796 if (type_die
== NULL
)
24798 tree name
= TYPE_IDENTIFIER (type
);
24799 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
24801 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
24802 equate_type_number_to_die (type
, type_die
);
24808 if (is_cxx_auto (type
))
24810 tree name
= TYPE_IDENTIFIER (type
);
24811 dw_die_ref
*die
= (name
== get_identifier ("auto")
24812 ? &auto_die
: &decltype_auto_die
);
24815 *die
= new_die (DW_TAG_unspecified_type
,
24816 comp_unit_die (), NULL_TREE
);
24817 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
24819 equate_type_number_to_die (type
, *die
);
24822 gcc_unreachable ();
24825 TREE_ASM_WRITTEN (type
) = 1;
24829 gen_type_die (tree type
, dw_die_ref context_die
)
24831 if (type
!= error_mark_node
)
24833 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
24836 dw_die_ref die
= lookup_type_die (type
);
24843 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
24844 things which are local to the given block. */
24847 gen_block_die (tree stmt
, dw_die_ref context_die
)
24849 int must_output_die
= 0;
24852 /* Ignore blocks that are NULL. */
24853 if (stmt
== NULL_TREE
)
24856 inlined_func
= inlined_function_outer_scope_p (stmt
);
24858 /* If the block is one fragment of a non-contiguous block, do not
24859 process the variables, since they will have been done by the
24860 origin block. Do process subblocks. */
24861 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
24865 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
24866 gen_block_die (sub
, context_die
);
24871 /* Determine if we need to output any Dwarf DIEs at all to represent this
24874 /* The outer scopes for inlinings *must* always be represented. We
24875 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
24876 must_output_die
= 1;
24879 /* Determine if this block directly contains any "significant"
24880 local declarations which we will need to output DIEs for. */
24881 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24882 /* We are not in terse mode so *any* local declaration counts
24883 as being a "significant" one. */
24884 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
24885 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
24886 && (TREE_USED (stmt
)
24887 || TREE_ASM_WRITTEN (stmt
)
24888 || BLOCK_ABSTRACT (stmt
)));
24889 else if ((TREE_USED (stmt
)
24890 || TREE_ASM_WRITTEN (stmt
)
24891 || BLOCK_ABSTRACT (stmt
))
24892 && !dwarf2out_ignore_block (stmt
))
24893 must_output_die
= 1;
24896 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
24897 DIE for any block which contains no significant local declarations at
24898 all. Rather, in such cases we just call `decls_for_scope' so that any
24899 needed Dwarf info for any sub-blocks will get properly generated. Note
24900 that in terse mode, our definition of what constitutes a "significant"
24901 local declaration gets restricted to include only inlined function
24902 instances and local (nested) function definitions. */
24903 if (must_output_die
)
24907 /* If STMT block is abstract, that means we have been called
24908 indirectly from dwarf2out_abstract_function.
24909 That function rightfully marks the descendent blocks (of
24910 the abstract function it is dealing with) as being abstract,
24911 precisely to prevent us from emitting any
24912 DW_TAG_inlined_subroutine DIE as a descendent
24913 of an abstract function instance. So in that case, we should
24914 not call gen_inlined_subroutine_die.
24916 Later though, when cgraph asks dwarf2out to emit info
24917 for the concrete instance of the function decl into which
24918 the concrete instance of STMT got inlined, the later will lead
24919 to the generation of a DW_TAG_inlined_subroutine DIE. */
24920 if (! BLOCK_ABSTRACT (stmt
))
24921 gen_inlined_subroutine_die (stmt
, context_die
);
24924 gen_lexical_block_die (stmt
, context_die
);
24927 decls_for_scope (stmt
, context_die
);
24930 /* Process variable DECL (or variable with origin ORIGIN) within
24931 block STMT and add it to CONTEXT_DIE. */
24933 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
24936 tree decl_or_origin
= decl
? decl
: origin
;
24938 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
24939 die
= lookup_decl_die (decl_or_origin
);
24940 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
)
24942 if (TYPE_DECL_IS_STUB (decl_or_origin
))
24943 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
24945 die
= lookup_decl_die (decl_or_origin
);
24946 /* Avoid re-creating the DIE late if it was optimized as unused early. */
24947 if (! die
&& ! early_dwarf
)
24953 /* Avoid creating DIEs for local typedefs and concrete static variables that
24954 will only be pruned later. */
24955 if ((origin
|| decl_ultimate_origin (decl
))
24956 && (TREE_CODE (decl_or_origin
) == TYPE_DECL
24957 || (VAR_P (decl_or_origin
) && TREE_STATIC (decl_or_origin
))))
24959 origin
= decl_ultimate_origin (decl_or_origin
);
24960 if (decl
&& VAR_P (decl
) && die
!= NULL
)
24962 die
= lookup_decl_die (origin
);
24964 equate_decl_number_to_die (decl
, die
);
24969 if (die
!= NULL
&& die
->die_parent
== NULL
)
24970 add_child_die (context_die
, die
);
24971 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
24974 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
24975 stmt
, context_die
);
24979 if (decl
&& DECL_P (decl
))
24981 die
= lookup_decl_die (decl
);
24983 /* Early created DIEs do not have a parent as the decls refer
24984 to the function as DECL_CONTEXT rather than the BLOCK. */
24985 if (die
&& die
->die_parent
== NULL
)
24987 gcc_assert (in_lto_p
);
24988 add_child_die (context_die
, die
);
24992 gen_decl_die (decl
, origin
, NULL
, context_die
);
24996 /* Generate all of the decls declared within a given scope and (recursively)
24997 all of its sub-blocks. */
25000 decls_for_scope (tree stmt
, dw_die_ref context_die
)
25006 /* Ignore NULL blocks. */
25007 if (stmt
== NULL_TREE
)
25010 /* Output the DIEs to represent all of the data objects and typedefs
25011 declared directly within this block but not within any nested
25012 sub-blocks. Also, nested function and tag DIEs have been
25013 generated with a parent of NULL; fix that up now. We don't
25014 have to do this if we're at -g1. */
25015 if (debug_info_level
> DINFO_LEVEL_TERSE
)
25017 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
25018 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
25019 /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
25020 origin - avoid doing this twice as we have no good way to see
25021 if we've done it once already. */
25023 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
25025 decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
25026 if (decl
== current_function_decl
)
25027 /* Ignore declarations of the current function, while they
25028 are declarations, gen_subprogram_die would treat them
25029 as definitions again, because they are equal to
25030 current_function_decl and endlessly recurse. */;
25031 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
25032 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
25034 process_scope_var (stmt
, NULL_TREE
, decl
, context_die
);
25038 /* Even if we're at -g1, we need to process the subblocks in order to get
25039 inlined call information. */
25041 /* Output the DIEs to represent all sub-blocks (and the items declared
25042 therein) of this block. */
25043 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
25045 subblocks
= BLOCK_CHAIN (subblocks
))
25046 gen_block_die (subblocks
, context_die
);
25049 /* Is this a typedef we can avoid emitting? */
25052 is_redundant_typedef (const_tree decl
)
25054 if (TYPE_DECL_IS_STUB (decl
))
25057 if (DECL_ARTIFICIAL (decl
)
25058 && DECL_CONTEXT (decl
)
25059 && is_tagged_type (DECL_CONTEXT (decl
))
25060 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
25061 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
25062 /* Also ignore the artificial member typedef for the class name. */
25068 /* Return TRUE if TYPE is a typedef that names a type for linkage
25069 purposes. This kind of typedefs is produced by the C++ FE for
25072 typedef struct {...} foo;
25074 In that case, there is no typedef variant type produced for foo.
25075 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
25079 is_naming_typedef_decl (const_tree decl
)
25081 if (decl
== NULL_TREE
25082 || TREE_CODE (decl
) != TYPE_DECL
25083 || DECL_NAMELESS (decl
)
25084 || !is_tagged_type (TREE_TYPE (decl
))
25085 || DECL_IS_BUILTIN (decl
)
25086 || is_redundant_typedef (decl
)
25087 /* It looks like Ada produces TYPE_DECLs that are very similar
25088 to C++ naming typedefs but that have different
25089 semantics. Let's be specific to c++ for now. */
25093 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
25094 && TYPE_NAME (TREE_TYPE (decl
)) == decl
25095 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
25096 != TYPE_NAME (TREE_TYPE (decl
))));
25099 /* Looks up the DIE for a context. */
25101 static inline dw_die_ref
25102 lookup_context_die (tree context
)
25106 /* Find die that represents this context. */
25107 if (TYPE_P (context
))
25109 context
= TYPE_MAIN_VARIANT (context
);
25110 dw_die_ref ctx
= lookup_type_die (context
);
25113 return strip_naming_typedef (context
, ctx
);
25116 return lookup_decl_die (context
);
25118 return comp_unit_die ();
25121 /* Returns the DIE for a context. */
25123 static inline dw_die_ref
25124 get_context_die (tree context
)
25128 /* Find die that represents this context. */
25129 if (TYPE_P (context
))
25131 context
= TYPE_MAIN_VARIANT (context
);
25132 return strip_naming_typedef (context
, force_type_die (context
));
25135 return force_decl_die (context
);
25137 return comp_unit_die ();
25140 /* Returns the DIE for decl. A DIE will always be returned. */
25143 force_decl_die (tree decl
)
25145 dw_die_ref decl_die
;
25146 unsigned saved_external_flag
;
25147 tree save_fn
= NULL_TREE
;
25148 decl_die
= lookup_decl_die (decl
);
25151 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
25153 decl_die
= lookup_decl_die (decl
);
25157 switch (TREE_CODE (decl
))
25159 case FUNCTION_DECL
:
25160 /* Clear current_function_decl, so that gen_subprogram_die thinks
25161 that this is a declaration. At this point, we just want to force
25162 declaration die. */
25163 save_fn
= current_function_decl
;
25164 current_function_decl
= NULL_TREE
;
25165 gen_subprogram_die (decl
, context_die
);
25166 current_function_decl
= save_fn
;
25170 /* Set external flag to force declaration die. Restore it after
25171 gen_decl_die() call. */
25172 saved_external_flag
= DECL_EXTERNAL (decl
);
25173 DECL_EXTERNAL (decl
) = 1;
25174 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25175 DECL_EXTERNAL (decl
) = saved_external_flag
;
25178 case NAMESPACE_DECL
:
25179 if (dwarf_version
>= 3 || !dwarf_strict
)
25180 dwarf2out_decl (decl
);
25182 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
25183 decl_die
= comp_unit_die ();
25186 case TRANSLATION_UNIT_DECL
:
25187 decl_die
= comp_unit_die ();
25191 gcc_unreachable ();
25194 /* We should be able to find the DIE now. */
25196 decl_die
= lookup_decl_die (decl
);
25197 gcc_assert (decl_die
);
25203 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
25204 always returned. */
25207 force_type_die (tree type
)
25209 dw_die_ref type_die
;
25211 type_die
= lookup_type_die (type
);
25214 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
25216 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
25217 false, context_die
);
25218 gcc_assert (type_die
);
25223 /* Force out any required namespaces to be able to output DECL,
25224 and return the new context_die for it, if it's changed. */
25227 setup_namespace_context (tree thing
, dw_die_ref context_die
)
25229 tree context
= (DECL_P (thing
)
25230 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
25231 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
25232 /* Force out the namespace. */
25233 context_die
= force_decl_die (context
);
25235 return context_die
;
25238 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
25239 type) within its namespace, if appropriate.
25241 For compatibility with older debuggers, namespace DIEs only contain
25242 declarations; all definitions are emitted at CU scope, with
25243 DW_AT_specification pointing to the declaration (like with class
25247 declare_in_namespace (tree thing
, dw_die_ref context_die
)
25249 dw_die_ref ns_context
;
25251 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25252 return context_die
;
25254 /* External declarations in the local scope only need to be emitted
25255 once, not once in the namespace and once in the scope.
25257 This avoids declaring the `extern' below in the
25258 namespace DIE as well as in the innermost scope:
25271 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
25272 return context_die
;
25274 /* If this decl is from an inlined function, then don't try to emit it in its
25275 namespace, as we will get confused. It would have already been emitted
25276 when the abstract instance of the inline function was emitted anyways. */
25277 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
25278 return context_die
;
25280 ns_context
= setup_namespace_context (thing
, context_die
);
25282 if (ns_context
!= context_die
)
25286 if (DECL_P (thing
))
25287 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
25289 gen_type_die (thing
, ns_context
);
25291 return context_die
;
25294 /* Generate a DIE for a namespace or namespace alias. */
25297 gen_namespace_die (tree decl
, dw_die_ref context_die
)
25299 dw_die_ref namespace_die
;
25301 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
25302 they are an alias of. */
25303 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
25305 /* Output a real namespace or module. */
25306 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25307 namespace_die
= new_die (is_fortran ()
25308 ? DW_TAG_module
: DW_TAG_namespace
,
25309 context_die
, decl
);
25310 /* For Fortran modules defined in different CU don't add src coords. */
25311 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
25313 const char *name
= dwarf2_name (decl
, 0);
25315 add_name_attribute (namespace_die
, name
);
25318 add_name_and_src_coords_attributes (namespace_die
, decl
);
25319 if (DECL_EXTERNAL (decl
))
25320 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
25321 equate_decl_number_to_die (decl
, namespace_die
);
25325 /* Output a namespace alias. */
25327 /* Force out the namespace we are an alias of, if necessary. */
25328 dw_die_ref origin_die
25329 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
25331 if (DECL_FILE_SCOPE_P (decl
)
25332 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
25333 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25334 /* Now create the namespace alias DIE. */
25335 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
25336 add_name_and_src_coords_attributes (namespace_die
, decl
);
25337 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
25338 equate_decl_number_to_die (decl
, namespace_die
);
25340 if ((dwarf_version
>= 5 || !dwarf_strict
)
25341 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
25342 DW_AT_export_symbols
) == 1)
25343 add_AT_flag (namespace_die
, DW_AT_export_symbols
, 1);
25345 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
25346 if (want_pubnames ())
25347 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
25350 /* Generate Dwarf debug information for a decl described by DECL.
25351 The return value is currently only meaningful for PARM_DECLs,
25352 for all other decls it returns NULL.
25354 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
25355 It can be NULL otherwise. */
25358 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
25359 dw_die_ref context_die
)
25361 tree decl_or_origin
= decl
? decl
: origin
;
25362 tree class_origin
= NULL
, ultimate_origin
;
25364 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
25367 /* Ignore pointer bounds decls. */
25368 if (DECL_P (decl_or_origin
)
25369 && TREE_TYPE (decl_or_origin
)
25370 && POINTER_BOUNDS_P (decl_or_origin
))
25373 switch (TREE_CODE (decl_or_origin
))
25379 if (!is_fortran () && !is_ada ())
25381 /* The individual enumerators of an enum type get output when we output
25382 the Dwarf representation of the relevant enum type itself. */
25386 /* Emit its type. */
25387 gen_type_die (TREE_TYPE (decl
), context_die
);
25389 /* And its containing namespace. */
25390 context_die
= declare_in_namespace (decl
, context_die
);
25392 gen_const_die (decl
, context_die
);
25395 case FUNCTION_DECL
:
25398 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
25399 on local redeclarations of global functions. That seems broken. */
25400 if (current_function_decl
!= decl
)
25401 /* This is only a declaration. */;
25404 /* We should have abstract copies already and should not generate
25405 stray type DIEs in late LTO dumping. */
25409 /* If we're emitting a clone, emit info for the abstract instance. */
25410 else if (origin
|| DECL_ORIGIN (decl
) != decl
)
25411 dwarf2out_abstract_function (origin
25412 ? DECL_ORIGIN (origin
)
25413 : DECL_ABSTRACT_ORIGIN (decl
));
25415 /* If we're emitting a possibly inlined function emit it as
25416 abstract instance. */
25417 else if (cgraph_function_possibly_inlined_p (decl
)
25418 && ! DECL_ABSTRACT_P (decl
)
25419 && ! class_or_namespace_scope_p (context_die
)
25420 /* dwarf2out_abstract_function won't emit a die if this is just
25421 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
25422 that case, because that works only if we have a die. */
25423 && DECL_INITIAL (decl
) != NULL_TREE
)
25424 dwarf2out_abstract_function (decl
);
25426 /* Otherwise we're emitting the primary DIE for this decl. */
25427 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
25429 /* Before we describe the FUNCTION_DECL itself, make sure that we
25430 have its containing type. */
25432 origin
= decl_class_context (decl
);
25433 if (origin
!= NULL_TREE
)
25434 gen_type_die (origin
, context_die
);
25436 /* And its return type. */
25437 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
25439 /* And its virtual context. */
25440 if (DECL_VINDEX (decl
) != NULL_TREE
)
25441 gen_type_die (DECL_CONTEXT (decl
), context_die
);
25443 /* Make sure we have a member DIE for decl. */
25444 if (origin
!= NULL_TREE
)
25445 gen_type_die_for_member (origin
, decl
, context_die
);
25447 /* And its containing namespace. */
25448 context_die
= declare_in_namespace (decl
, context_die
);
25451 /* Now output a DIE to represent the function itself. */
25453 gen_subprogram_die (decl
, context_die
);
25457 /* If we are in terse mode, don't generate any DIEs to represent any
25458 actual typedefs. */
25459 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25462 /* In the special case of a TYPE_DECL node representing the declaration
25463 of some type tag, if the given TYPE_DECL is marked as having been
25464 instantiated from some other (original) TYPE_DECL node (e.g. one which
25465 was generated within the original definition of an inline function) we
25466 used to generate a special (abbreviated) DW_TAG_structure_type,
25467 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
25468 should be actually referencing those DIEs, as variable DIEs with that
25469 type would be emitted already in the abstract origin, so it was always
25470 removed during unused type prunning. Don't add anything in this
25472 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
25475 if (is_redundant_typedef (decl
))
25476 gen_type_die (TREE_TYPE (decl
), context_die
);
25478 /* Output a DIE to represent the typedef itself. */
25479 gen_typedef_die (decl
, context_die
);
25483 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
25484 gen_label_die (decl
, context_die
);
25489 /* If we are in terse mode, don't generate any DIEs to represent any
25490 variable declarations or definitions. */
25491 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25494 /* Avoid generating stray type DIEs during late dwarf dumping.
25495 All types have been dumped early. */
25497 /* ??? But in LTRANS we cannot annotate early created variably
25498 modified type DIEs without copying them and adjusting all
25499 references to them. Dump them again as happens for inlining
25500 which copies both the decl and the types. */
25501 /* ??? And even non-LTO needs to re-visit type DIEs to fill
25502 in VLA bound information for example. */
25503 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
25504 current_function_decl
)))
25506 /* Output any DIEs that are needed to specify the type of this data
25508 if (decl_by_reference_p (decl_or_origin
))
25509 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25511 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25516 /* And its containing type. */
25517 class_origin
= decl_class_context (decl_or_origin
);
25518 if (class_origin
!= NULL_TREE
)
25519 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
25521 /* And its containing namespace. */
25522 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
25525 /* Now output the DIE to represent the data object itself. This gets
25526 complicated because of the possibility that the VAR_DECL really
25527 represents an inlined instance of a formal parameter for an inline
25529 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
25530 if (ultimate_origin
!= NULL_TREE
25531 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
25532 gen_formal_parameter_die (decl
, origin
,
25533 true /* Emit name attribute. */,
25536 gen_variable_die (decl
, origin
, context_die
);
25540 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
25541 /* Ignore the nameless fields that are used to skip bits but handle C++
25542 anonymous unions and structs. */
25543 if (DECL_NAME (decl
) != NULL_TREE
25544 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
25545 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
25547 gen_type_die (member_declared_type (decl
), context_die
);
25548 gen_field_die (decl
, ctx
, context_die
);
25553 /* Avoid generating stray type DIEs during late dwarf dumping.
25554 All types have been dumped early. */
25556 /* ??? But in LTRANS we cannot annotate early created variably
25557 modified type DIEs without copying them and adjusting all
25558 references to them. Dump them again as happens for inlining
25559 which copies both the decl and the types. */
25560 /* ??? And even non-LTO needs to re-visit type DIEs to fill
25561 in VLA bound information for example. */
25562 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
25563 current_function_decl
)))
25565 if (DECL_BY_REFERENCE (decl_or_origin
))
25566 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25568 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25570 return gen_formal_parameter_die (decl
, origin
,
25571 true /* Emit name attribute. */,
25574 case NAMESPACE_DECL
:
25575 if (dwarf_version
>= 3 || !dwarf_strict
)
25576 gen_namespace_die (decl
, context_die
);
25579 case IMPORTED_DECL
:
25580 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
25581 DECL_CONTEXT (decl
), context_die
);
25584 case NAMELIST_DECL
:
25585 gen_namelist_decl (DECL_NAME (decl
), context_die
,
25586 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
25590 /* Probably some frontend-internal decl. Assume we don't care. */
25591 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
25598 /* Output initial debug information for global DECL. Called at the
25599 end of the parsing process.
25601 This is the initial debug generation process. As such, the DIEs
25602 generated may be incomplete. A later debug generation pass
25603 (dwarf2out_late_global_decl) will augment the information generated
25604 in this pass (e.g., with complete location info). */
25607 dwarf2out_early_global_decl (tree decl
)
25611 /* gen_decl_die() will set DECL_ABSTRACT because
25612 cgraph_function_possibly_inlined_p() returns true. This is in
25613 turn will cause DW_AT_inline attributes to be set.
25615 This happens because at early dwarf generation, there is no
25616 cgraph information, causing cgraph_function_possibly_inlined_p()
25617 to return true. Trick cgraph_function_possibly_inlined_p()
25618 while we generate dwarf early. */
25619 bool save
= symtab
->global_info_ready
;
25620 symtab
->global_info_ready
= true;
25622 /* We don't handle TYPE_DECLs. If required, they'll be reached via
25623 other DECLs and they can point to template types or other things
25624 that dwarf2out can't handle when done via dwarf2out_decl. */
25625 if (TREE_CODE (decl
) != TYPE_DECL
25626 && TREE_CODE (decl
) != PARM_DECL
)
25628 if (TREE_CODE (decl
) == FUNCTION_DECL
)
25630 tree save_fndecl
= current_function_decl
;
25632 /* For nested functions, make sure we have DIEs for the parents first
25633 so that all nested DIEs are generated at the proper scope in the
25635 tree context
= decl_function_context (decl
);
25636 if (context
!= NULL
)
25638 dw_die_ref context_die
= lookup_decl_die (context
);
25639 current_function_decl
= context
;
25641 /* Avoid emitting DIEs multiple times, but still process CONTEXT
25642 enough so that it lands in its own context. This avoids type
25643 pruning issues later on. */
25644 if (context_die
== NULL
|| is_declaration_die (context_die
))
25645 dwarf2out_decl (context
);
25648 /* Emit an abstract origin of a function first. This happens
25649 with C++ constructor clones for example and makes
25650 dwarf2out_abstract_function happy which requires the early
25651 DIE of the abstract instance to be present. */
25652 tree origin
= DECL_ABSTRACT_ORIGIN (decl
);
25653 dw_die_ref origin_die
;
25655 /* Do not emit the DIE multiple times but make sure to
25656 process it fully here in case we just saw a declaration. */
25657 && ((origin_die
= lookup_decl_die (origin
)) == NULL
25658 || is_declaration_die (origin_die
)))
25660 current_function_decl
= origin
;
25661 dwarf2out_decl (origin
);
25664 /* Emit the DIE for decl but avoid doing that multiple times. */
25665 dw_die_ref old_die
;
25666 if ((old_die
= lookup_decl_die (decl
)) == NULL
25667 || is_declaration_die (old_die
))
25669 current_function_decl
= decl
;
25670 dwarf2out_decl (decl
);
25673 current_function_decl
= save_fndecl
;
25676 dwarf2out_decl (decl
);
25678 symtab
->global_info_ready
= save
;
25681 /* Output debug information for global decl DECL. Called from
25682 toplev.c after compilation proper has finished. */
25685 dwarf2out_late_global_decl (tree decl
)
25687 /* Fill-in any location information we were unable to determine
25688 on the first pass. */
25689 if (VAR_P (decl
) && !POINTER_BOUNDS_P (decl
))
25691 dw_die_ref die
= lookup_decl_die (decl
);
25693 /* We may have to generate early debug late for LTO in case debug
25694 was not enabled at compile-time or the target doesn't support
25695 the LTO early debug scheme. */
25696 if (! die
&& in_lto_p
)
25698 dwarf2out_decl (decl
);
25699 die
= lookup_decl_die (decl
);
25704 /* We get called via the symtab code invoking late_global_decl
25705 for symbols that are optimized out. Do not add locations
25706 for those, except if they have a DECL_VALUE_EXPR, in which case
25707 they are relevant for debuggers. */
25708 varpool_node
*node
= varpool_node::get (decl
);
25709 if ((! node
|| ! node
->definition
) && ! DECL_HAS_VALUE_EXPR_P (decl
))
25710 tree_add_const_value_attribute_for_decl (die
, decl
);
25712 add_location_or_const_value_attribute (die
, decl
, false);
25717 /* Output debug information for type decl DECL. Called from toplev.c
25718 and from language front ends (to record built-in types). */
25720 dwarf2out_type_decl (tree decl
, int local
)
25725 dwarf2out_decl (decl
);
25729 /* Output debug information for imported module or decl DECL.
25730 NAME is non-NULL name in the lexical block if the decl has been renamed.
25731 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
25732 that DECL belongs to.
25733 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
25735 dwarf2out_imported_module_or_decl_1 (tree decl
,
25737 tree lexical_block
,
25738 dw_die_ref lexical_block_die
)
25740 expanded_location xloc
;
25741 dw_die_ref imported_die
= NULL
;
25742 dw_die_ref at_import_die
;
25744 if (TREE_CODE (decl
) == IMPORTED_DECL
)
25746 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
25747 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
25751 xloc
= expand_location (input_location
);
25753 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
25755 at_import_die
= force_type_die (TREE_TYPE (decl
));
25756 /* For namespace N { typedef void T; } using N::T; base_type_die
25757 returns NULL, but DW_TAG_imported_declaration requires
25758 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
25759 if (!at_import_die
)
25761 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
25762 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
25763 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
25764 gcc_assert (at_import_die
);
25769 at_import_die
= lookup_decl_die (decl
);
25770 if (!at_import_die
)
25772 /* If we're trying to avoid duplicate debug info, we may not have
25773 emitted the member decl for this field. Emit it now. */
25774 if (TREE_CODE (decl
) == FIELD_DECL
)
25776 tree type
= DECL_CONTEXT (decl
);
25778 if (TYPE_CONTEXT (type
)
25779 && TYPE_P (TYPE_CONTEXT (type
))
25780 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
25781 DINFO_USAGE_DIR_USE
))
25783 gen_type_die_for_member (type
, decl
,
25784 get_context_die (TYPE_CONTEXT (type
)));
25786 if (TREE_CODE (decl
) == NAMELIST_DECL
)
25787 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
25788 get_context_die (DECL_CONTEXT (decl
)),
25791 at_import_die
= force_decl_die (decl
);
25795 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
25797 if (dwarf_version
>= 3 || !dwarf_strict
)
25798 imported_die
= new_die (DW_TAG_imported_module
,
25805 imported_die
= new_die (DW_TAG_imported_declaration
,
25809 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
25810 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
25811 if (debug_column_info
&& xloc
.column
)
25812 add_AT_unsigned (imported_die
, DW_AT_decl_column
, xloc
.column
);
25814 add_AT_string (imported_die
, DW_AT_name
,
25815 IDENTIFIER_POINTER (name
));
25816 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
25819 /* Output debug information for imported module or decl DECL.
25820 NAME is non-NULL name in context if the decl has been renamed.
25821 CHILD is true if decl is one of the renamed decls as part of
25822 importing whole module.
25823 IMPLICIT is set if this hook is called for an implicit import
25824 such as inline namespace. */
25827 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
25828 bool child
, bool implicit
)
25830 /* dw_die_ref at_import_die; */
25831 dw_die_ref scope_die
;
25833 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25838 /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
25839 should be enough, for DWARF4 and older even if we emit as extension
25840 DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
25841 for the benefit of consumers unaware of DW_AT_export_symbols. */
25843 && dwarf_version
>= 5
25844 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
25845 DW_AT_export_symbols
) == 1)
25850 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
25851 We need decl DIE for reference and scope die. First, get DIE for the decl
25854 /* Get the scope die for decl context. Use comp_unit_die for global module
25855 or decl. If die is not found for non globals, force new die. */
25857 && TYPE_P (context
)
25858 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
25861 scope_die
= get_context_die (context
);
25865 /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
25866 there is nothing we can do, here. */
25867 if (dwarf_version
< 3 && dwarf_strict
)
25870 gcc_assert (scope_die
->die_child
);
25871 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
25872 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
25873 scope_die
= scope_die
->die_child
;
25876 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
25877 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
25880 /* Output debug information for namelists. */
25883 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
25885 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
25889 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25892 gcc_assert (scope_die
!= NULL
);
25893 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
25894 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
25896 /* If there are no item_decls, we have a nondefining namelist, e.g.
25897 with USE association; hence, set DW_AT_declaration. */
25898 if (item_decls
== NULL_TREE
)
25900 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
25904 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
25906 nml_item_ref_die
= lookup_decl_die (value
);
25907 if (!nml_item_ref_die
)
25908 nml_item_ref_die
= force_decl_die (value
);
25910 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
25911 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
25917 /* Write the debugging output for DECL and return the DIE. */
25920 dwarf2out_decl (tree decl
)
25922 dw_die_ref context_die
= comp_unit_die ();
25924 switch (TREE_CODE (decl
))
25929 case FUNCTION_DECL
:
25930 /* If we're a nested function, initially use a parent of NULL; if we're
25931 a plain function, this will be fixed up in decls_for_scope. If
25932 we're a method, it will be ignored, since we already have a DIE. */
25933 if (decl_function_context (decl
)
25934 /* But if we're in terse mode, we don't care about scope. */
25935 && debug_info_level
> DINFO_LEVEL_TERSE
)
25936 context_die
= NULL
;
25940 /* For local statics lookup proper context die. */
25941 if (local_function_static (decl
))
25942 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25944 /* If we are in terse mode, don't generate any DIEs to represent any
25945 variable declarations or definitions. */
25946 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25951 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25953 if (!is_fortran () && !is_ada ())
25955 if (TREE_STATIC (decl
) && decl_function_context (decl
))
25956 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25959 case NAMESPACE_DECL
:
25960 case IMPORTED_DECL
:
25961 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25963 if (lookup_decl_die (decl
) != NULL
)
25968 /* Don't emit stubs for types unless they are needed by other DIEs. */
25969 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
25972 /* Don't bother trying to generate any DIEs to represent any of the
25973 normal built-in types for the language we are compiling. */
25974 if (DECL_IS_BUILTIN (decl
))
25977 /* If we are in terse mode, don't generate any DIEs for types. */
25978 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25981 /* If we're a function-scope tag, initially use a parent of NULL;
25982 this will be fixed up in decls_for_scope. */
25983 if (decl_function_context (decl
))
25984 context_die
= NULL
;
25988 case NAMELIST_DECL
:
25995 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25999 dw_die_ref die
= lookup_decl_die (decl
);
26005 /* Write the debugging output for DECL. */
26008 dwarf2out_function_decl (tree decl
)
26010 dwarf2out_decl (decl
);
26011 call_arg_locations
= NULL
;
26012 call_arg_loc_last
= NULL
;
26013 call_site_count
= -1;
26014 tail_call_site_count
= -1;
26015 decl_loc_table
->empty ();
26016 cached_dw_loc_list_table
->empty ();
26019 /* Output a marker (i.e. a label) for the beginning of the generated code for
26020 a lexical block. */
26023 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
26024 unsigned int blocknum
)
26026 switch_to_section (current_function_section ());
26027 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
26030 /* Output a marker (i.e. a label) for the end of the generated code for a
26034 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
26036 switch_to_section (current_function_section ());
26037 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
26040 /* Returns nonzero if it is appropriate not to emit any debugging
26041 information for BLOCK, because it doesn't contain any instructions.
26043 Don't allow this for blocks with nested functions or local classes
26044 as we would end up with orphans, and in the presence of scheduling
26045 we may end up calling them anyway. */
26048 dwarf2out_ignore_block (const_tree block
)
26053 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
26054 if (TREE_CODE (decl
) == FUNCTION_DECL
26055 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
26057 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
26059 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
26060 if (TREE_CODE (decl
) == FUNCTION_DECL
26061 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
26068 /* Hash table routines for file_hash. */
26071 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
26073 return filename_cmp (p1
->filename
, p2
) == 0;
26077 dwarf_file_hasher::hash (dwarf_file_data
*p
)
26079 return htab_hash_string (p
->filename
);
26082 /* Lookup FILE_NAME (in the list of filenames that we know about here in
26083 dwarf2out.c) and return its "index". The index of each (known) filename is
26084 just a unique number which is associated with only that one filename. We
26085 need such numbers for the sake of generating labels (in the .debug_sfnames
26086 section) and references to those files numbers (in the .debug_srcinfo
26087 and .debug_macinfo sections). If the filename given as an argument is not
26088 found in our current list, add it to the list and assign it the next
26089 available unique index number. */
26091 static struct dwarf_file_data
*
26092 lookup_filename (const char *file_name
)
26094 struct dwarf_file_data
* created
;
26099 dwarf_file_data
**slot
26100 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
26105 created
= ggc_alloc
<dwarf_file_data
> ();
26106 created
->filename
= file_name
;
26107 created
->emitted_number
= 0;
26112 /* If the assembler will construct the file table, then translate the compiler
26113 internal file table number into the assembler file table number, and emit
26114 a .file directive if we haven't already emitted one yet. The file table
26115 numbers are different because we prune debug info for unused variables and
26116 types, which may include filenames. */
26119 maybe_emit_file (struct dwarf_file_data
* fd
)
26121 if (! fd
->emitted_number
)
26123 if (last_emitted_file
)
26124 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
26126 fd
->emitted_number
= 1;
26127 last_emitted_file
= fd
;
26129 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26131 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
26132 output_quoted_string (asm_out_file
,
26133 remap_debug_filename (fd
->filename
));
26134 fputc ('\n', asm_out_file
);
26138 return fd
->emitted_number
;
26141 /* Schedule generation of a DW_AT_const_value attribute to DIE.
26142 That generation should happen after function debug info has been
26143 generated. The value of the attribute is the constant value of ARG. */
26146 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
26148 die_arg_entry entry
;
26153 gcc_assert (early_dwarf
);
26155 if (!tmpl_value_parm_die_table
)
26156 vec_alloc (tmpl_value_parm_die_table
, 32);
26160 vec_safe_push (tmpl_value_parm_die_table
, entry
);
26163 /* Return TRUE if T is an instance of generic type, FALSE
26167 generic_type_p (tree t
)
26169 if (t
== NULL_TREE
|| !TYPE_P (t
))
26171 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
26174 /* Schedule the generation of the generic parameter dies for the
26175 instance of generic type T. The proper generation itself is later
26176 done by gen_scheduled_generic_parms_dies. */
26179 schedule_generic_params_dies_gen (tree t
)
26181 if (!generic_type_p (t
))
26184 gcc_assert (early_dwarf
);
26186 if (!generic_type_instances
)
26187 vec_alloc (generic_type_instances
, 256);
26189 vec_safe_push (generic_type_instances
, t
);
26192 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
26193 by append_entry_to_tmpl_value_parm_die_table. This function must
26194 be called after function DIEs have been generated. */
26197 gen_remaining_tmpl_value_param_die_attribute (void)
26199 if (tmpl_value_parm_die_table
)
26204 /* We do this in two phases - first get the cases we can
26205 handle during early-finish, preserving those we cannot
26206 (containing symbolic constants where we don't yet know
26207 whether we are going to output the referenced symbols).
26208 For those we try again at late-finish. */
26210 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
26212 if (!e
->die
->removed
26213 && !tree_add_const_value_attribute (e
->die
, e
->arg
))
26215 dw_loc_descr_ref loc
= NULL
;
26217 && (dwarf_version
>= 5 || !dwarf_strict
))
26218 loc
= loc_descriptor_from_tree (e
->arg
, 2, NULL
);
26220 add_AT_loc (e
->die
, DW_AT_location
, loc
);
26222 (*tmpl_value_parm_die_table
)[j
++] = *e
;
26225 tmpl_value_parm_die_table
->truncate (j
);
26229 /* Generate generic parameters DIEs for instances of generic types
26230 that have been previously scheduled by
26231 schedule_generic_params_dies_gen. This function must be called
26232 after all the types of the CU have been laid out. */
26235 gen_scheduled_generic_parms_dies (void)
26240 if (!generic_type_instances
)
26243 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
26244 if (COMPLETE_TYPE_P (t
))
26245 gen_generic_params_dies (t
);
26247 generic_type_instances
= NULL
;
26251 /* Replace DW_AT_name for the decl with name. */
26254 dwarf2out_set_name (tree decl
, tree name
)
26257 dw_attr_node
*attr
;
26260 die
= TYPE_SYMTAB_DIE (decl
);
26264 dname
= dwarf2_name (name
, 0);
26268 attr
= get_AT (die
, DW_AT_name
);
26271 struct indirect_string_node
*node
;
26273 node
= find_AT_string (dname
);
26274 /* replace the string. */
26275 attr
->dw_attr_val
.v
.val_str
= node
;
26279 add_name_attribute (die
, dname
);
26282 /* True if before or during processing of the first function being emitted. */
26283 static bool in_first_function_p
= true;
26284 /* True if loc_note during dwarf2out_var_location call might still be
26285 before first real instruction at address equal to .Ltext0. */
26286 static bool maybe_at_text_label_p
= true;
26287 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
26288 static unsigned int first_loclabel_num_not_at_text_label
;
26290 /* Look ahead for a real insn, or for a begin stmt marker. */
26293 dwarf2out_next_real_insn (rtx_insn
*loc_note
)
26295 rtx_insn
*next_real
= NEXT_INSN (loc_note
);
26298 if (INSN_P (next_real
))
26301 next_real
= NEXT_INSN (next_real
);
26306 /* Called by the final INSN scan whenever we see a var location. We
26307 use it to drop labels in the right places, and throw the location in
26308 our lookup table. */
26311 dwarf2out_var_location (rtx_insn
*loc_note
)
26313 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
26314 struct var_loc_node
*newloc
;
26315 rtx_insn
*next_real
, *next_note
;
26316 rtx_insn
*call_insn
= NULL
;
26317 static const char *last_label
;
26318 static const char *last_postcall_label
;
26319 static bool last_in_cold_section_p
;
26320 static rtx_insn
*expected_next_loc_note
;
26324 if (!NOTE_P (loc_note
))
26326 if (CALL_P (loc_note
))
26329 if (SIBLING_CALL_P (loc_note
))
26330 tail_call_site_count
++;
26331 if (optimize
== 0 && !flag_var_tracking
)
26333 /* When the var-tracking pass is not running, there is no note
26334 for indirect calls whose target is compile-time known. In this
26335 case, process such calls specifically so that we generate call
26336 sites for them anyway. */
26337 rtx x
= PATTERN (loc_note
);
26338 if (GET_CODE (x
) == PARALLEL
)
26339 x
= XVECEXP (x
, 0, 0);
26340 if (GET_CODE (x
) == SET
)
26342 if (GET_CODE (x
) == CALL
)
26345 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
26346 || !SYMBOL_REF_DECL (XEXP (x
, 0))
26347 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
26350 call_insn
= loc_note
;
26354 next_real
= dwarf2out_next_real_insn (call_insn
);
26356 cached_next_real_insn
= NULL
;
26364 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
26365 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
26368 /* Optimize processing a large consecutive sequence of location
26369 notes so we don't spend too much time in next_real_insn. If the
26370 next insn is another location note, remember the next_real_insn
26371 calculation for next time. */
26372 next_real
= cached_next_real_insn
;
26375 if (expected_next_loc_note
!= loc_note
)
26379 next_note
= NEXT_INSN (loc_note
);
26381 || next_note
->deleted ()
26382 || ! NOTE_P (next_note
)
26383 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
26384 && NOTE_KIND (next_note
) != NOTE_INSN_BEGIN_STMT
26385 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
26389 next_real
= dwarf2out_next_real_insn (loc_note
);
26393 expected_next_loc_note
= next_note
;
26394 cached_next_real_insn
= next_real
;
26397 cached_next_real_insn
= NULL
;
26399 /* If there are no instructions which would be affected by this note,
26400 don't do anything. */
26402 && next_real
== NULL_RTX
26403 && !NOTE_DURING_CALL_P (loc_note
))
26408 if (next_real
== NULL_RTX
)
26409 next_real
= get_last_insn ();
26411 /* If there were any real insns between note we processed last time
26412 and this note (or if it is the first note), clear
26413 last_{,postcall_}label so that they are not reused this time. */
26414 if (last_var_location_insn
== NULL_RTX
26415 || last_var_location_insn
!= next_real
26416 || last_in_cold_section_p
!= in_cold_section_p
)
26419 last_postcall_label
= NULL
;
26424 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
26425 newloc
= add_var_loc_to_decl (decl
, loc_note
,
26426 NOTE_DURING_CALL_P (loc_note
)
26427 ? last_postcall_label
: last_label
);
26428 if (newloc
== NULL
)
26437 /* If there were no real insns between note we processed last time
26438 and this note, use the label we emitted last time. Otherwise
26439 create a new label and emit it. */
26440 if (last_label
== NULL
)
26442 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
26443 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
26445 last_label
= ggc_strdup (loclabel
);
26446 /* See if loclabel might be equal to .Ltext0. If yes,
26447 bump first_loclabel_num_not_at_text_label. */
26448 if (!have_multiple_function_sections
26449 && in_first_function_p
26450 && maybe_at_text_label_p
)
26452 static rtx_insn
*last_start
;
26454 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
26455 if (insn
== last_start
)
26457 else if (!NONDEBUG_INSN_P (insn
))
26461 rtx body
= PATTERN (insn
);
26462 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
26464 /* Inline asm could occupy zero bytes. */
26465 else if (GET_CODE (body
) == ASM_INPUT
26466 || asm_noperands (body
) >= 0)
26468 #ifdef HAVE_attr_length
26469 else if (get_attr_min_length (insn
) == 0)
26474 /* Assume insn has non-zero length. */
26475 maybe_at_text_label_p
= false;
26479 if (maybe_at_text_label_p
)
26481 last_start
= loc_note
;
26482 first_loclabel_num_not_at_text_label
= loclabel_num
;
26487 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
26488 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
26492 struct call_arg_loc_node
*ca_loc
26493 = ggc_cleared_alloc
<call_arg_loc_node
> ();
26495 = loc_note
!= NULL_RTX
? prev_real_insn (loc_note
) : call_insn
;
26497 ca_loc
->call_arg_loc_note
= loc_note
;
26498 ca_loc
->next
= NULL
;
26499 ca_loc
->label
= last_label
;
26502 || (NONJUMP_INSN_P (prev
)
26503 && GET_CODE (PATTERN (prev
)) == SEQUENCE
26504 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
26505 if (!CALL_P (prev
))
26506 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
26507 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
26509 /* Look for a SYMBOL_REF in the "prev" instruction. */
26510 rtx x
= get_call_rtx_from (PATTERN (prev
));
26513 /* Try to get the call symbol, if any. */
26514 if (MEM_P (XEXP (x
, 0)))
26516 /* First, look for a memory access to a symbol_ref. */
26517 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
26518 && SYMBOL_REF_DECL (XEXP (x
, 0))
26519 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
26520 ca_loc
->symbol_ref
= XEXP (x
, 0);
26521 /* Otherwise, look at a compile-time known user-level function
26525 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
26526 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
26529 ca_loc
->block
= insn_scope (prev
);
26530 if (call_arg_locations
)
26531 call_arg_loc_last
->next
= ca_loc
;
26533 call_arg_locations
= ca_loc
;
26534 call_arg_loc_last
= ca_loc
;
26536 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
26537 newloc
->label
= last_label
;
26540 if (!last_postcall_label
)
26542 sprintf (loclabel
, "%s-1", last_label
);
26543 last_postcall_label
= ggc_strdup (loclabel
);
26545 newloc
->label
= last_postcall_label
;
26548 if (var_loc_p
&& flag_debug_asm
)
26550 const char *name
= NULL
, *sep
= " => ", *patstr
= NULL
;
26551 if (decl
&& DECL_NAME (decl
))
26552 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
26553 if (NOTE_VAR_LOCATION_LOC (loc_note
))
26554 patstr
= str_pattern_slim (NOTE_VAR_LOCATION_LOC (loc_note
));
26560 fprintf (asm_out_file
, "\t%s DEBUG %s%s%s\n", ASM_COMMENT_START
,
26561 name
, sep
, patstr
);
26564 last_var_location_insn
= next_real
;
26565 last_in_cold_section_p
= in_cold_section_p
;
26568 /* Called from finalize_size_functions for size functions so that their body
26569 can be encoded in the debug info to describe the layout of variable-length
26573 dwarf2out_size_function (tree decl
)
26575 function_to_dwarf_procedure (decl
);
26578 /* Note in one location list that text section has changed. */
26581 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
26583 var_loc_list
*list
= *slot
;
26585 list
->last_before_switch
26586 = list
->last
->next
? list
->last
->next
: list
->last
;
26590 /* Note in all location lists that text section has changed. */
26593 var_location_switch_text_section (void)
26595 if (decl_loc_table
== NULL
)
26598 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
26601 /* Create a new line number table. */
26603 static dw_line_info_table
*
26604 new_line_info_table (void)
26606 dw_line_info_table
*table
;
26608 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
26609 table
->file_num
= 1;
26610 table
->line_num
= 1;
26611 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
26616 /* Lookup the "current" table into which we emit line info, so
26617 that we don't have to do it for every source line. */
26620 set_cur_line_info_table (section
*sec
)
26622 dw_line_info_table
*table
;
26624 if (sec
== text_section
)
26625 table
= text_section_line_info
;
26626 else if (sec
== cold_text_section
)
26628 table
= cold_text_section_line_info
;
26631 cold_text_section_line_info
= table
= new_line_info_table ();
26632 table
->end_label
= cold_end_label
;
26637 const char *end_label
;
26639 if (crtl
->has_bb_partition
)
26641 if (in_cold_section_p
)
26642 end_label
= crtl
->subsections
.cold_section_end_label
;
26644 end_label
= crtl
->subsections
.hot_section_end_label
;
26648 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26649 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
26650 current_function_funcdef_no
);
26651 end_label
= ggc_strdup (label
);
26654 table
= new_line_info_table ();
26655 table
->end_label
= end_label
;
26657 vec_safe_push (separate_line_info
, table
);
26660 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26661 table
->is_stmt
= (cur_line_info_table
26662 ? cur_line_info_table
->is_stmt
26663 : DWARF_LINE_DEFAULT_IS_STMT_START
);
26664 cur_line_info_table
= table
;
26668 /* We need to reset the locations at the beginning of each
26669 function. We can't do this in the end_function hook, because the
26670 declarations that use the locations won't have been output when
26671 that hook is called. Also compute have_multiple_function_sections here. */
26674 dwarf2out_begin_function (tree fun
)
26676 section
*sec
= function_section (fun
);
26678 if (sec
!= text_section
)
26679 have_multiple_function_sections
= true;
26681 if (crtl
->has_bb_partition
&& !cold_text_section
)
26683 gcc_assert (current_function_decl
== fun
);
26684 cold_text_section
= unlikely_text_section ();
26685 switch_to_section (cold_text_section
);
26686 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
26687 switch_to_section (sec
);
26690 dwarf2out_note_section_used ();
26691 call_site_count
= 0;
26692 tail_call_site_count
= 0;
26694 set_cur_line_info_table (sec
);
26697 /* Helper function of dwarf2out_end_function, called only after emitting
26698 the very first function into assembly. Check if some .debug_loc range
26699 might end with a .LVL* label that could be equal to .Ltext0.
26700 In that case we must force using absolute addresses in .debug_loc ranges,
26701 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
26702 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
26704 Set have_multiple_function_sections to true in that case and
26705 terminate htab traversal. */
26708 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
26710 var_loc_list
*entry
= *slot
;
26711 struct var_loc_node
*node
;
26713 node
= entry
->first
;
26714 if (node
&& node
->next
&& node
->next
->label
)
26717 const char *label
= node
->next
->label
;
26718 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
26720 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
26722 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
26723 if (strcmp (label
, loclabel
) == 0)
26725 have_multiple_function_sections
= true;
26733 /* Hook called after emitting a function into assembly.
26734 This does something only for the very first function emitted. */
26737 dwarf2out_end_function (unsigned int)
26739 if (in_first_function_p
26740 && !have_multiple_function_sections
26741 && first_loclabel_num_not_at_text_label
26743 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
26744 in_first_function_p
= false;
26745 maybe_at_text_label_p
= false;
26748 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
26749 front-ends register a translation unit even before dwarf2out_init is
26751 static tree main_translation_unit
= NULL_TREE
;
26753 /* Hook called by front-ends after they built their main translation unit.
26754 Associate comp_unit_die to UNIT. */
26757 dwarf2out_register_main_translation_unit (tree unit
)
26759 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
26760 && main_translation_unit
== NULL_TREE
);
26761 main_translation_unit
= unit
;
26762 /* If dwarf2out_init has not been called yet, it will perform the association
26763 itself looking at main_translation_unit. */
26764 if (decl_die_table
!= NULL
)
26765 equate_decl_number_to_die (unit
, comp_unit_die ());
26768 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
26771 push_dw_line_info_entry (dw_line_info_table
*table
,
26772 enum dw_line_info_opcode opcode
, unsigned int val
)
26774 dw_line_info_entry e
;
26777 vec_safe_push (table
->entries
, e
);
26780 /* Output a label to mark the beginning of a source code line entry
26781 and record information relating to this source line, in
26782 'line_info_table' for later output of the .debug_line section. */
26783 /* ??? The discriminator parameter ought to be unsigned. */
26786 dwarf2out_source_line (unsigned int line
, unsigned int column
,
26787 const char *filename
,
26788 int discriminator
, bool is_stmt
)
26790 unsigned int file_num
;
26791 dw_line_info_table
*table
;
26793 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
26796 /* The discriminator column was added in dwarf4. Simplify the below
26797 by simply removing it if we're not supposed to output it. */
26798 if (dwarf_version
< 4 && dwarf_strict
)
26801 if (!debug_column_info
)
26804 table
= cur_line_info_table
;
26805 file_num
= maybe_emit_file (lookup_filename (filename
));
26807 /* ??? TODO: Elide duplicate line number entries. Traditionally,
26808 the debugger has used the second (possibly duplicate) line number
26809 at the beginning of the function to mark the end of the prologue.
26810 We could eliminate any other duplicates within the function. For
26811 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
26812 that second line number entry. */
26813 /* Recall that this end-of-prologue indication is *not* the same thing
26814 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
26815 to which the hook corresponds, follows the last insn that was
26816 emitted by gen_prologue. What we need is to precede the first insn
26817 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
26818 insn that corresponds to something the user wrote. These may be
26819 very different locations once scheduling is enabled. */
26821 if (0 && file_num
== table
->file_num
26822 && line
== table
->line_num
26823 && column
== table
->column_num
26824 && discriminator
== table
->discrim_num
26825 && is_stmt
== table
->is_stmt
)
26828 switch_to_section (current_function_section ());
26830 /* If requested, emit something human-readable. */
26831 if (flag_debug_asm
)
26833 if (debug_column_info
)
26834 fprintf (asm_out_file
, "\t%s %s:%d:%d\n", ASM_COMMENT_START
,
26835 filename
, line
, column
);
26837 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
26841 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26843 /* Emit the .loc directive understood by GNU as. */
26844 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
26845 file_num, line, is_stmt, discriminator */
26846 fputs ("\t.loc ", asm_out_file
);
26847 fprint_ul (asm_out_file
, file_num
);
26848 putc (' ', asm_out_file
);
26849 fprint_ul (asm_out_file
, line
);
26850 putc (' ', asm_out_file
);
26851 fprint_ul (asm_out_file
, column
);
26853 if (is_stmt
!= table
->is_stmt
)
26855 fputs (" is_stmt ", asm_out_file
);
26856 putc (is_stmt
? '1' : '0', asm_out_file
);
26858 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
26860 gcc_assert (discriminator
> 0);
26861 fputs (" discriminator ", asm_out_file
);
26862 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
26864 putc ('\n', asm_out_file
);
26868 unsigned int label_num
= ++line_info_label_num
;
26870 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
26872 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
26873 if (file_num
!= table
->file_num
)
26874 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
26875 if (discriminator
!= table
->discrim_num
)
26876 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
26877 if (is_stmt
!= table
->is_stmt
)
26878 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
26879 push_dw_line_info_entry (table
, LI_set_line
, line
);
26880 if (debug_column_info
)
26881 push_dw_line_info_entry (table
, LI_set_column
, column
);
26884 table
->file_num
= file_num
;
26885 table
->line_num
= line
;
26886 table
->column_num
= column
;
26887 table
->discrim_num
= discriminator
;
26888 table
->is_stmt
= is_stmt
;
26889 table
->in_use
= true;
26892 /* Record the beginning of a new source file. */
26895 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
26897 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26900 e
.code
= DW_MACINFO_start_file
;
26902 e
.info
= ggc_strdup (filename
);
26903 vec_safe_push (macinfo_table
, e
);
26907 /* Record the end of a source file. */
26910 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
26912 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26915 e
.code
= DW_MACINFO_end_file
;
26918 vec_safe_push (macinfo_table
, e
);
26922 /* Called from debug_define in toplev.c. The `buffer' parameter contains
26923 the tail part of the directive line, i.e. the part which is past the
26924 initial whitespace, #, whitespace, directive-name, whitespace part. */
26927 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
26928 const char *buffer ATTRIBUTE_UNUSED
)
26930 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26933 /* Insert a dummy first entry to be able to optimize the whole
26934 predefined macro block using DW_MACRO_import. */
26935 if (macinfo_table
->is_empty () && lineno
<= 1)
26940 vec_safe_push (macinfo_table
, e
);
26942 e
.code
= DW_MACINFO_define
;
26944 e
.info
= ggc_strdup (buffer
);
26945 vec_safe_push (macinfo_table
, e
);
26949 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
26950 the tail part of the directive line, i.e. the part which is past the
26951 initial whitespace, #, whitespace, directive-name, whitespace part. */
26954 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
26955 const char *buffer ATTRIBUTE_UNUSED
)
26957 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26960 /* Insert a dummy first entry to be able to optimize the whole
26961 predefined macro block using DW_MACRO_import. */
26962 if (macinfo_table
->is_empty () && lineno
<= 1)
26967 vec_safe_push (macinfo_table
, e
);
26969 e
.code
= DW_MACINFO_undef
;
26971 e
.info
= ggc_strdup (buffer
);
26972 vec_safe_push (macinfo_table
, e
);
26976 /* Helpers to manipulate hash table of CUs. */
26978 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
26980 static inline hashval_t
hash (const macinfo_entry
*);
26981 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
26985 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
26987 return htab_hash_string (entry
->info
);
26991 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
26992 const macinfo_entry
*entry2
)
26994 return !strcmp (entry1
->info
, entry2
->info
);
26997 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
26999 /* Output a single .debug_macinfo entry. */
27002 output_macinfo_op (macinfo_entry
*ref
)
27006 struct indirect_string_node
*node
;
27007 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
27008 struct dwarf_file_data
*fd
;
27012 case DW_MACINFO_start_file
:
27013 fd
= lookup_filename (ref
->info
);
27014 file_num
= maybe_emit_file (fd
);
27015 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
27016 dw2_asm_output_data_uleb128 (ref
->lineno
,
27017 "Included from line number %lu",
27018 (unsigned long) ref
->lineno
);
27019 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
27021 case DW_MACINFO_end_file
:
27022 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
27024 case DW_MACINFO_define
:
27025 case DW_MACINFO_undef
:
27026 len
= strlen (ref
->info
) + 1;
27028 && len
> DWARF_OFFSET_SIZE
27029 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
27030 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
27032 ref
->code
= ref
->code
== DW_MACINFO_define
27033 ? DW_MACRO_define_strp
: DW_MACRO_undef_strp
;
27034 output_macinfo_op (ref
);
27037 dw2_asm_output_data (1, ref
->code
,
27038 ref
->code
== DW_MACINFO_define
27039 ? "Define macro" : "Undefine macro");
27040 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
27041 (unsigned long) ref
->lineno
);
27042 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
27044 case DW_MACRO_define_strp
:
27045 case DW_MACRO_undef_strp
:
27046 node
= find_AT_string (ref
->info
);
27048 && (node
->form
== DW_FORM_strp
27049 || node
->form
== DW_FORM_GNU_str_index
));
27050 dw2_asm_output_data (1, ref
->code
,
27051 ref
->code
== DW_MACRO_define_strp
27052 ? "Define macro strp"
27053 : "Undefine macro strp");
27054 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
27055 (unsigned long) ref
->lineno
);
27056 if (node
->form
== DW_FORM_strp
)
27057 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
27058 debug_str_section
, "The macro: \"%s\"",
27061 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
27064 case DW_MACRO_import
:
27065 dw2_asm_output_data (1, ref
->code
, "Import");
27066 ASM_GENERATE_INTERNAL_LABEL (label
,
27067 DEBUG_MACRO_SECTION_LABEL
,
27068 ref
->lineno
+ macinfo_label_base
);
27069 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
27072 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
27073 ASM_COMMENT_START
, (unsigned long) ref
->code
);
27078 /* Attempt to make a sequence of define/undef macinfo ops shareable with
27079 other compilation unit .debug_macinfo sections. IDX is the first
27080 index of a define/undef, return the number of ops that should be
27081 emitted in a comdat .debug_macinfo section and emit
27082 a DW_MACRO_import entry referencing it.
27083 If the define/undef entry should be emitted normally, return 0. */
27086 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
27087 macinfo_hash_type
**macinfo_htab
)
27089 macinfo_entry
*first
, *second
, *cur
, *inc
;
27090 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
27091 unsigned char checksum
[16];
27092 struct md5_ctx ctx
;
27093 char *grp_name
, *tail
;
27095 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
27096 macinfo_entry
**slot
;
27098 first
= &(*macinfo_table
)[idx
];
27099 second
= &(*macinfo_table
)[idx
+ 1];
27101 /* Optimize only if there are at least two consecutive define/undef ops,
27102 and either all of them are before first DW_MACINFO_start_file
27103 with lineno {0,1} (i.e. predefined macro block), or all of them are
27104 in some included header file. */
27105 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
27107 if (vec_safe_is_empty (files
))
27109 if (first
->lineno
> 1 || second
->lineno
> 1)
27112 else if (first
->lineno
== 0)
27115 /* Find the last define/undef entry that can be grouped together
27116 with first and at the same time compute md5 checksum of their
27117 codes, linenumbers and strings. */
27118 md5_init_ctx (&ctx
);
27119 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
27120 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
27122 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
27126 unsigned char code
= cur
->code
;
27127 md5_process_bytes (&code
, 1, &ctx
);
27128 checksum_uleb128 (cur
->lineno
, &ctx
);
27129 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
27131 md5_finish_ctx (&ctx
, checksum
);
27134 /* From the containing include filename (if any) pick up just
27135 usable characters from its basename. */
27136 if (vec_safe_is_empty (files
))
27139 base
= lbasename (files
->last ().info
);
27140 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
27141 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
27142 encoded_filename_len
++;
27143 /* Count . at the end. */
27144 if (encoded_filename_len
)
27145 encoded_filename_len
++;
27147 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
27148 linebuf_len
= strlen (linebuf
);
27150 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
27151 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
27153 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
27154 tail
= grp_name
+ 4;
27155 if (encoded_filename_len
)
27157 for (i
= 0; base
[i
]; i
++)
27158 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
27162 memcpy (tail
, linebuf
, linebuf_len
);
27163 tail
+= linebuf_len
;
27165 for (i
= 0; i
< 16; i
++)
27166 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
27168 /* Construct a macinfo_entry for DW_MACRO_import
27169 in the empty vector entry before the first define/undef. */
27170 inc
= &(*macinfo_table
)[idx
- 1];
27171 inc
->code
= DW_MACRO_import
;
27173 inc
->info
= ggc_strdup (grp_name
);
27174 if (!*macinfo_htab
)
27175 *macinfo_htab
= new macinfo_hash_type (10);
27176 /* Avoid emitting duplicates. */
27177 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
27182 /* If such an entry has been used before, just emit
27183 a DW_MACRO_import op. */
27185 output_macinfo_op (inc
);
27186 /* And clear all macinfo_entry in the range to avoid emitting them
27187 in the second pass. */
27188 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
27197 inc
->lineno
= (*macinfo_htab
)->elements ();
27198 output_macinfo_op (inc
);
27203 /* Save any strings needed by the macinfo table in the debug str
27204 table. All strings must be collected into the table by the time
27205 index_string is called. */
27208 save_macinfo_strings (void)
27212 macinfo_entry
*ref
;
27214 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
27218 /* Match the logic in output_macinfo_op to decide on
27219 indirect strings. */
27220 case DW_MACINFO_define
:
27221 case DW_MACINFO_undef
:
27222 len
= strlen (ref
->info
) + 1;
27224 && len
> DWARF_OFFSET_SIZE
27225 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
27226 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
27227 set_indirect_string (find_AT_string (ref
->info
));
27229 case DW_MACRO_define_strp
:
27230 case DW_MACRO_undef_strp
:
27231 set_indirect_string (find_AT_string (ref
->info
));
27239 /* Output macinfo section(s). */
27242 output_macinfo (const char *debug_line_label
, bool early_lto_debug
)
27245 unsigned long length
= vec_safe_length (macinfo_table
);
27246 macinfo_entry
*ref
;
27247 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
27248 macinfo_hash_type
*macinfo_htab
= NULL
;
27249 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
27254 /* output_macinfo* uses these interchangeably. */
27255 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_define
27256 && (int) DW_MACINFO_undef
== (int) DW_MACRO_undef
27257 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_start_file
27258 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_end_file
);
27260 /* AIX Assembler inserts the length, so adjust the reference to match the
27261 offset expected by debuggers. */
27262 strcpy (dl_section_ref
, debug_line_label
);
27263 if (XCOFF_DEBUGGING_INFO
)
27264 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
27266 /* For .debug_macro emit the section header. */
27267 if (!dwarf_strict
|| dwarf_version
>= 5)
27269 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
27270 "DWARF macro version number");
27271 if (DWARF_OFFSET_SIZE
== 8)
27272 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
27274 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
27275 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_line_label
,
27276 debug_line_section
, NULL
);
27279 /* In the first loop, it emits the primary .debug_macinfo section
27280 and after each emitted op the macinfo_entry is cleared.
27281 If a longer range of define/undef ops can be optimized using
27282 DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
27283 the vector before the first define/undef in the range and the
27284 whole range of define/undef ops is not emitted and kept. */
27285 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
27289 case DW_MACINFO_start_file
:
27290 vec_safe_push (files
, *ref
);
27292 case DW_MACINFO_end_file
:
27293 if (!vec_safe_is_empty (files
))
27296 case DW_MACINFO_define
:
27297 case DW_MACINFO_undef
:
27298 if ((!dwarf_strict
|| dwarf_version
>= 5)
27299 && HAVE_COMDAT_GROUP
27300 && vec_safe_length (files
) != 1
27303 && (*macinfo_table
)[i
- 1].code
== 0)
27305 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
27314 /* A dummy entry may be inserted at the beginning to be able
27315 to optimize the whole block of predefined macros. */
27321 output_macinfo_op (ref
);
27329 /* Save the number of transparent includes so we can adjust the
27330 label number for the fat LTO object DWARF. */
27331 unsigned macinfo_label_base_adj
= macinfo_htab
->elements ();
27333 delete macinfo_htab
;
27334 macinfo_htab
= NULL
;
27336 /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
27337 terminate the current chain and switch to a new comdat .debug_macinfo
27338 section and emit the define/undef entries within it. */
27339 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
27344 case DW_MACRO_import
:
27346 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
27347 tree comdat_key
= get_identifier (ref
->info
);
27348 /* Terminate the previous .debug_macinfo section. */
27349 dw2_asm_output_data (1, 0, "End compilation unit");
27350 targetm
.asm_out
.named_section (debug_macinfo_section_name
,
27354 ? SECTION_EXCLUDE
: 0),
27356 ASM_GENERATE_INTERNAL_LABEL (label
,
27357 DEBUG_MACRO_SECTION_LABEL
,
27358 ref
->lineno
+ macinfo_label_base
);
27359 ASM_OUTPUT_LABEL (asm_out_file
, label
);
27362 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
27363 "DWARF macro version number");
27364 if (DWARF_OFFSET_SIZE
== 8)
27365 dw2_asm_output_data (1, 1, "Flags: 64-bit");
27367 dw2_asm_output_data (1, 0, "Flags: 32-bit");
27370 case DW_MACINFO_define
:
27371 case DW_MACINFO_undef
:
27372 output_macinfo_op (ref
);
27377 gcc_unreachable ();
27380 macinfo_label_base
+= macinfo_label_base_adj
;
27383 /* Initialize the various sections and labels for dwarf output and prefix
27384 them with PREFIX if non-NULL. Returns the generation (zero based
27385 number of times function was called). */
27388 init_sections_and_labels (bool early_lto_debug
)
27390 /* As we may get called multiple times have a generation count for
27392 static unsigned generation
= 0;
27394 if (early_lto_debug
)
27396 if (!dwarf_split_debug_info
)
27398 debug_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
27399 SECTION_DEBUG
| SECTION_EXCLUDE
,
27401 debug_abbrev_section
= get_section (DEBUG_LTO_ABBREV_SECTION
,
27402 SECTION_DEBUG
| SECTION_EXCLUDE
,
27404 debug_macinfo_section_name
27405 = ((dwarf_strict
&& dwarf_version
< 5)
27406 ? DEBUG_LTO_MACINFO_SECTION
: DEBUG_LTO_MACRO_SECTION
);
27407 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27409 | SECTION_EXCLUDE
, NULL
);
27410 /* For macro info we have to refer to a debug_line section, so
27411 similar to split-dwarf emit a skeleton one for early debug. */
27412 debug_skeleton_line_section
27413 = get_section (DEBUG_LTO_LINE_SECTION
,
27414 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27415 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27416 DEBUG_SKELETON_LINE_SECTION_LABEL
,
27421 /* ??? Which of the following do we need early? */
27422 debug_info_section
= get_section (DEBUG_LTO_DWO_INFO_SECTION
,
27423 SECTION_DEBUG
| SECTION_EXCLUDE
,
27425 debug_abbrev_section
= get_section (DEBUG_LTO_DWO_ABBREV_SECTION
,
27426 SECTION_DEBUG
| SECTION_EXCLUDE
,
27428 debug_skeleton_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
27430 | SECTION_EXCLUDE
, NULL
);
27431 debug_skeleton_abbrev_section
27432 = get_section (DEBUG_LTO_ABBREV_SECTION
,
27433 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27434 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
27435 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
27438 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
27439 stay in the main .o, but the skeleton_line goes into the split
27441 debug_skeleton_line_section
27442 = get_section (DEBUG_LTO_LINE_SECTION
,
27443 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27444 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27445 DEBUG_SKELETON_LINE_SECTION_LABEL
,
27447 debug_str_offsets_section
27448 = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION
,
27449 SECTION_DEBUG
| SECTION_EXCLUDE
,
27451 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
27452 DEBUG_SKELETON_INFO_SECTION_LABEL
,
27454 debug_str_dwo_section
= get_section (DEBUG_LTO_STR_DWO_SECTION
,
27455 DEBUG_STR_DWO_SECTION_FLAGS
,
27457 debug_macinfo_section_name
27458 = ((dwarf_strict
&& dwarf_version
< 5)
27459 ? DEBUG_LTO_DWO_MACINFO_SECTION
: DEBUG_LTO_DWO_MACRO_SECTION
);
27460 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27461 SECTION_DEBUG
| SECTION_EXCLUDE
,
27464 debug_str_section
= get_section (DEBUG_LTO_STR_SECTION
,
27465 DEBUG_STR_SECTION_FLAGS
27466 | SECTION_EXCLUDE
, NULL
);
27467 if (!dwarf_split_debug_info
&& !DWARF2_ASM_LINE_DEBUG_INFO
)
27468 debug_line_str_section
27469 = get_section (DEBUG_LTO_LINE_STR_SECTION
,
27470 DEBUG_STR_SECTION_FLAGS
| SECTION_EXCLUDE
, NULL
);
27474 if (!dwarf_split_debug_info
)
27476 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
27477 SECTION_DEBUG
, NULL
);
27478 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27479 SECTION_DEBUG
, NULL
);
27480 debug_loc_section
= get_section (dwarf_version
>= 5
27481 ? DEBUG_LOCLISTS_SECTION
27482 : DEBUG_LOC_SECTION
,
27483 SECTION_DEBUG
, NULL
);
27484 debug_macinfo_section_name
27485 = ((dwarf_strict
&& dwarf_version
< 5)
27486 ? DEBUG_MACINFO_SECTION
: DEBUG_MACRO_SECTION
);
27487 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27488 SECTION_DEBUG
, NULL
);
27492 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
27493 SECTION_DEBUG
| SECTION_EXCLUDE
,
27495 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
27496 SECTION_DEBUG
| SECTION_EXCLUDE
,
27498 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
27499 SECTION_DEBUG
, NULL
);
27500 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
27501 SECTION_DEBUG
, NULL
);
27502 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27503 SECTION_DEBUG
, NULL
);
27504 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
27505 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
27508 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
27509 stay in the main .o, but the skeleton_line goes into the
27511 debug_skeleton_line_section
27512 = get_section (DEBUG_DWO_LINE_SECTION
,
27513 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27514 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27515 DEBUG_SKELETON_LINE_SECTION_LABEL
,
27517 debug_str_offsets_section
27518 = get_section (DEBUG_DWO_STR_OFFSETS_SECTION
,
27519 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27520 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
27521 DEBUG_SKELETON_INFO_SECTION_LABEL
,
27523 debug_loc_section
= get_section (dwarf_version
>= 5
27524 ? DEBUG_DWO_LOCLISTS_SECTION
27525 : DEBUG_DWO_LOC_SECTION
,
27526 SECTION_DEBUG
| SECTION_EXCLUDE
,
27528 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
27529 DEBUG_STR_DWO_SECTION_FLAGS
,
27531 debug_macinfo_section_name
27532 = ((dwarf_strict
&& dwarf_version
< 5)
27533 ? DEBUG_DWO_MACINFO_SECTION
: DEBUG_DWO_MACRO_SECTION
);
27534 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27535 SECTION_DEBUG
| SECTION_EXCLUDE
,
27538 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
27539 SECTION_DEBUG
, NULL
);
27540 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
27541 SECTION_DEBUG
, NULL
);
27542 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
27543 SECTION_DEBUG
, NULL
);
27544 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
27545 SECTION_DEBUG
, NULL
);
27546 debug_str_section
= get_section (DEBUG_STR_SECTION
,
27547 DEBUG_STR_SECTION_FLAGS
, NULL
);
27548 if (!dwarf_split_debug_info
&& !DWARF2_ASM_LINE_DEBUG_INFO
)
27549 debug_line_str_section
= get_section (DEBUG_LINE_STR_SECTION
,
27550 DEBUG_STR_SECTION_FLAGS
, NULL
);
27551 debug_ranges_section
= get_section (dwarf_version
>= 5
27552 ? DEBUG_RNGLISTS_SECTION
27553 : DEBUG_RANGES_SECTION
,
27554 SECTION_DEBUG
, NULL
);
27555 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
27556 SECTION_DEBUG
, NULL
);
27559 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
27560 DEBUG_ABBREV_SECTION_LABEL
, generation
);
27561 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
27562 DEBUG_INFO_SECTION_LABEL
, generation
);
27563 info_section_emitted
= false;
27564 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
27565 DEBUG_LINE_SECTION_LABEL
, generation
);
27566 /* There are up to 4 unique ranges labels per generation.
27567 See also output_rnglists. */
27568 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
27569 DEBUG_RANGES_SECTION_LABEL
, generation
* 4);
27570 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
27571 ASM_GENERATE_INTERNAL_LABEL (ranges_base_label
,
27572 DEBUG_RANGES_SECTION_LABEL
,
27573 1 + generation
* 4);
27574 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
27575 DEBUG_ADDR_SECTION_LABEL
, generation
);
27576 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
27577 (dwarf_strict
&& dwarf_version
< 5)
27578 ? DEBUG_MACINFO_SECTION_LABEL
27579 : DEBUG_MACRO_SECTION_LABEL
, generation
);
27580 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
,
27584 return generation
- 1;
27587 /* Set up for Dwarf output at the start of compilation. */
27590 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
27592 /* Allocate the file_table. */
27593 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
27595 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27596 /* Allocate the decl_die_table. */
27597 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
27599 /* Allocate the decl_loc_table. */
27600 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
27602 /* Allocate the cached_dw_loc_list_table. */
27603 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
27605 /* Allocate the initial hunk of the decl_scope_table. */
27606 vec_alloc (decl_scope_table
, 256);
27608 /* Allocate the initial hunk of the abbrev_die_table. */
27609 vec_alloc (abbrev_die_table
, 256);
27610 /* Zero-th entry is allocated, but unused. */
27611 abbrev_die_table
->quick_push (NULL
);
27613 /* Allocate the dwarf_proc_stack_usage_map. */
27614 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
27616 /* Allocate the pubtypes and pubnames vectors. */
27617 vec_alloc (pubname_table
, 32);
27618 vec_alloc (pubtype_table
, 32);
27620 vec_alloc (incomplete_types
, 64);
27622 vec_alloc (used_rtx_array
, 32);
27624 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
27625 vec_alloc (macinfo_table
, 64);
27628 /* If front-ends already registered a main translation unit but we were not
27629 ready to perform the association, do this now. */
27630 if (main_translation_unit
!= NULL_TREE
)
27631 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
27634 /* Called before compile () starts outputtting functions, variables
27635 and toplevel asms into assembly. */
27638 dwarf2out_assembly_start (void)
27640 if (text_section_line_info
)
27643 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27644 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
27645 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
27646 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
27647 COLD_TEXT_SECTION_LABEL
, 0);
27648 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
27650 switch_to_section (text_section
);
27651 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
27654 /* Make sure the line number table for .text always exists. */
27655 text_section_line_info
= new_line_info_table ();
27656 text_section_line_info
->end_label
= text_end_label
;
27658 #ifdef DWARF2_LINENO_DEBUGGING_INFO
27659 cur_line_info_table
= text_section_line_info
;
27662 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
27663 && dwarf2out_do_cfi_asm ()
27664 && !dwarf2out_do_eh_frame ())
27665 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
27668 /* A helper function for dwarf2out_finish called through
27669 htab_traverse. Assign a string its index. All strings must be
27670 collected into the table by the time index_string is called,
27671 because the indexing code relies on htab_traverse to traverse nodes
27672 in the same order for each run. */
27675 index_string (indirect_string_node
**h
, unsigned int *index
)
27677 indirect_string_node
*node
= *h
;
27679 find_string_form (node
);
27680 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27682 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
27683 node
->index
= *index
;
27689 /* A helper function for output_indirect_strings called through
27690 htab_traverse. Output the offset to a string and update the
27694 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
27696 indirect_string_node
*node
= *h
;
27698 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27700 /* Assert that this node has been assigned an index. */
27701 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
27702 && node
->index
!= NOT_INDEXED
);
27703 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
27704 "indexed string 0x%x: %s", node
->index
, node
->str
);
27705 *offset
+= strlen (node
->str
) + 1;
27710 /* A helper function for dwarf2out_finish called through
27711 htab_traverse. Output the indexed string. */
27714 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
27716 struct indirect_string_node
*node
= *h
;
27718 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27720 /* Assert that the strings are output in the same order as their
27721 indexes were assigned. */
27722 gcc_assert (*cur_idx
== node
->index
);
27723 assemble_string (node
->str
, strlen (node
->str
) + 1);
27729 /* A helper function for dwarf2out_finish called through
27730 htab_traverse. Emit one queued .debug_str string. */
27733 output_indirect_string (indirect_string_node
**h
, enum dwarf_form form
)
27735 struct indirect_string_node
*node
= *h
;
27737 node
->form
= find_string_form (node
);
27738 if (node
->form
== form
&& node
->refcount
> 0)
27740 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
27741 assemble_string (node
->str
, strlen (node
->str
) + 1);
27747 /* Output the indexed string table. */
27750 output_indirect_strings (void)
27752 switch_to_section (debug_str_section
);
27753 if (!dwarf_split_debug_info
)
27754 debug_str_hash
->traverse
<enum dwarf_form
,
27755 output_indirect_string
> (DW_FORM_strp
);
27758 unsigned int offset
= 0;
27759 unsigned int cur_idx
= 0;
27761 skeleton_debug_str_hash
->traverse
<enum dwarf_form
,
27762 output_indirect_string
> (DW_FORM_strp
);
27764 switch_to_section (debug_str_offsets_section
);
27765 debug_str_hash
->traverse_noresize
27766 <unsigned int *, output_index_string_offset
> (&offset
);
27767 switch_to_section (debug_str_dwo_section
);
27768 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
27773 /* Callback for htab_traverse to assign an index to an entry in the
27774 table, and to write that entry to the .debug_addr section. */
27777 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
27779 addr_table_entry
*entry
= *slot
;
27781 if (entry
->refcount
== 0)
27783 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
27784 || entry
->index
== NOT_INDEXED
);
27788 gcc_assert (entry
->index
== *cur_index
);
27791 switch (entry
->kind
)
27794 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
27795 "0x%x", entry
->index
);
27797 case ate_kind_rtx_dtprel
:
27798 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
27799 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
27802 fputc ('\n', asm_out_file
);
27804 case ate_kind_label
:
27805 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
27806 "0x%x", entry
->index
);
27809 gcc_unreachable ();
27814 /* Produce the .debug_addr section. */
27817 output_addr_table (void)
27819 unsigned int index
= 0;
27820 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
27823 switch_to_section (debug_addr_section
);
27825 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
27828 #if ENABLE_ASSERT_CHECKING
27829 /* Verify that all marks are clear. */
27832 verify_marks_clear (dw_die_ref die
)
27836 gcc_assert (! die
->die_mark
);
27837 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
27839 #endif /* ENABLE_ASSERT_CHECKING */
27841 /* Clear the marks for a die and its children.
27842 Be cool if the mark isn't set. */
27845 prune_unmark_dies (dw_die_ref die
)
27851 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
27854 /* Given LOC that is referenced by a DIE we're marking as used, find all
27855 referenced DWARF procedures it references and mark them as used. */
27858 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
27860 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
27861 switch (loc
->dw_loc_opc
)
27863 case DW_OP_implicit_pointer
:
27864 case DW_OP_convert
:
27865 case DW_OP_reinterpret
:
27866 case DW_OP_GNU_implicit_pointer
:
27867 case DW_OP_GNU_convert
:
27868 case DW_OP_GNU_reinterpret
:
27869 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
27870 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27872 case DW_OP_GNU_variable_value
:
27873 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
27876 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
27879 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
27880 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
27881 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
27886 case DW_OP_call_ref
:
27887 case DW_OP_const_type
:
27888 case DW_OP_GNU_const_type
:
27889 case DW_OP_GNU_parameter_ref
:
27890 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
27891 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27893 case DW_OP_regval_type
:
27894 case DW_OP_deref_type
:
27895 case DW_OP_GNU_regval_type
:
27896 case DW_OP_GNU_deref_type
:
27897 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
27898 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
27900 case DW_OP_entry_value
:
27901 case DW_OP_GNU_entry_value
:
27902 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
27903 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
27910 /* Given DIE that we're marking as used, find any other dies
27911 it references as attributes and mark them as used. */
27914 prune_unused_types_walk_attribs (dw_die_ref die
)
27919 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27921 switch (AT_class (a
))
27923 /* Make sure DWARF procedures referenced by location descriptions will
27925 case dw_val_class_loc
:
27926 prune_unused_types_walk_loc_descr (AT_loc (a
));
27928 case dw_val_class_loc_list
:
27929 for (dw_loc_list_ref list
= AT_loc_list (a
);
27931 list
= list
->dw_loc_next
)
27932 prune_unused_types_walk_loc_descr (list
->expr
);
27935 case dw_val_class_die_ref
:
27936 /* A reference to another DIE.
27937 Make sure that it will get emitted.
27938 If it was broken out into a comdat group, don't follow it. */
27939 if (! AT_ref (a
)->comdat_type_p
27940 || a
->dw_attr
== DW_AT_specification
)
27941 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
27944 case dw_val_class_str
:
27945 /* Set the string's refcount to 0 so that prune_unused_types_mark
27946 accounts properly for it. */
27947 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
27956 /* Mark the generic parameters and arguments children DIEs of DIE. */
27959 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
27963 if (die
== NULL
|| die
->die_child
== NULL
)
27965 c
= die
->die_child
;
27968 if (is_template_parameter (c
))
27969 prune_unused_types_mark (c
, 1);
27971 } while (c
&& c
!= die
->die_child
);
27974 /* Mark DIE as being used. If DOKIDS is true, then walk down
27975 to DIE's children. */
27978 prune_unused_types_mark (dw_die_ref die
, int dokids
)
27982 if (die
->die_mark
== 0)
27984 /* We haven't done this node yet. Mark it as used. */
27986 /* If this is the DIE of a generic type instantiation,
27987 mark the children DIEs that describe its generic parms and
27989 prune_unused_types_mark_generic_parms_dies (die
);
27991 /* We also have to mark its parents as used.
27992 (But we don't want to mark our parent's kids due to this,
27993 unless it is a class.) */
27994 if (die
->die_parent
)
27995 prune_unused_types_mark (die
->die_parent
,
27996 class_scope_p (die
->die_parent
));
27998 /* Mark any referenced nodes. */
27999 prune_unused_types_walk_attribs (die
);
28001 /* If this node is a specification,
28002 also mark the definition, if it exists. */
28003 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
28004 prune_unused_types_mark (die
->die_definition
, 1);
28007 if (dokids
&& die
->die_mark
!= 2)
28009 /* We need to walk the children, but haven't done so yet.
28010 Remember that we've walked the kids. */
28013 /* If this is an array type, we need to make sure our
28014 kids get marked, even if they're types. If we're
28015 breaking out types into comdat sections, do this
28016 for all type definitions. */
28017 if (die
->die_tag
== DW_TAG_array_type
28018 || (use_debug_types
28019 && is_type_die (die
) && ! is_declaration_die (die
)))
28020 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
28022 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
28026 /* For local classes, look if any static member functions were emitted
28027 and if so, mark them. */
28030 prune_unused_types_walk_local_classes (dw_die_ref die
)
28034 if (die
->die_mark
== 2)
28037 switch (die
->die_tag
)
28039 case DW_TAG_structure_type
:
28040 case DW_TAG_union_type
:
28041 case DW_TAG_class_type
:
28044 case DW_TAG_subprogram
:
28045 if (!get_AT_flag (die
, DW_AT_declaration
)
28046 || die
->die_definition
!= NULL
)
28047 prune_unused_types_mark (die
, 1);
28054 /* Mark children. */
28055 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
28058 /* Walk the tree DIE and mark types that we actually use. */
28061 prune_unused_types_walk (dw_die_ref die
)
28065 /* Don't do anything if this node is already marked and
28066 children have been marked as well. */
28067 if (die
->die_mark
== 2)
28070 switch (die
->die_tag
)
28072 case DW_TAG_structure_type
:
28073 case DW_TAG_union_type
:
28074 case DW_TAG_class_type
:
28075 if (die
->die_perennial_p
)
28078 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
28079 if (c
->die_tag
== DW_TAG_subprogram
)
28082 /* Finding used static member functions inside of classes
28083 is needed just for local classes, because for other classes
28084 static member function DIEs with DW_AT_specification
28085 are emitted outside of the DW_TAG_*_type. If we ever change
28086 it, we'd need to call this even for non-local classes. */
28088 prune_unused_types_walk_local_classes (die
);
28090 /* It's a type node --- don't mark it. */
28093 case DW_TAG_const_type
:
28094 case DW_TAG_packed_type
:
28095 case DW_TAG_pointer_type
:
28096 case DW_TAG_reference_type
:
28097 case DW_TAG_rvalue_reference_type
:
28098 case DW_TAG_volatile_type
:
28099 case DW_TAG_typedef
:
28100 case DW_TAG_array_type
:
28101 case DW_TAG_interface_type
:
28102 case DW_TAG_friend
:
28103 case DW_TAG_enumeration_type
:
28104 case DW_TAG_subroutine_type
:
28105 case DW_TAG_string_type
:
28106 case DW_TAG_set_type
:
28107 case DW_TAG_subrange_type
:
28108 case DW_TAG_ptr_to_member_type
:
28109 case DW_TAG_file_type
:
28110 /* Type nodes are useful only when other DIEs reference them --- don't
28114 case DW_TAG_dwarf_procedure
:
28115 /* Likewise for DWARF procedures. */
28117 if (die
->die_perennial_p
)
28123 /* Mark everything else. */
28127 if (die
->die_mark
== 0)
28131 /* Now, mark any dies referenced from here. */
28132 prune_unused_types_walk_attribs (die
);
28137 /* Mark children. */
28138 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
28141 /* Increment the string counts on strings referred to from DIE's
28145 prune_unused_types_update_strings (dw_die_ref die
)
28150 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
28151 if (AT_class (a
) == dw_val_class_str
)
28153 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
28155 /* Avoid unnecessarily putting strings that are used less than
28156 twice in the hash table. */
28158 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
28160 indirect_string_node
**slot
28161 = debug_str_hash
->find_slot_with_hash (s
->str
,
28162 htab_hash_string (s
->str
),
28164 gcc_assert (*slot
== NULL
);
28170 /* Mark DIE and its children as removed. */
28173 mark_removed (dw_die_ref die
)
28176 die
->removed
= true;
28177 FOR_EACH_CHILD (die
, c
, mark_removed (c
));
28180 /* Remove from the tree DIE any dies that aren't marked. */
28183 prune_unused_types_prune (dw_die_ref die
)
28187 gcc_assert (die
->die_mark
);
28188 prune_unused_types_update_strings (die
);
28190 if (! die
->die_child
)
28193 c
= die
->die_child
;
28195 dw_die_ref prev
= c
, next
;
28196 for (c
= c
->die_sib
; ! c
->die_mark
; c
= next
)
28197 if (c
== die
->die_child
)
28199 /* No marked children between 'prev' and the end of the list. */
28201 /* No marked children at all. */
28202 die
->die_child
= NULL
;
28205 prev
->die_sib
= c
->die_sib
;
28206 die
->die_child
= prev
;
28219 if (c
!= prev
->die_sib
)
28221 prune_unused_types_prune (c
);
28222 } while (c
!= die
->die_child
);
28225 /* Remove dies representing declarations that we never use. */
28228 prune_unused_types (void)
28231 limbo_die_node
*node
;
28232 comdat_type_node
*ctnode
;
28233 pubname_entry
*pub
;
28234 dw_die_ref base_type
;
28236 #if ENABLE_ASSERT_CHECKING
28237 /* All the marks should already be clear. */
28238 verify_marks_clear (comp_unit_die ());
28239 for (node
= limbo_die_list
; node
; node
= node
->next
)
28240 verify_marks_clear (node
->die
);
28241 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28242 verify_marks_clear (ctnode
->root_die
);
28243 #endif /* ENABLE_ASSERT_CHECKING */
28245 /* Mark types that are used in global variables. */
28246 premark_types_used_by_global_vars ();
28248 /* Set the mark on nodes that are actually used. */
28249 prune_unused_types_walk (comp_unit_die ());
28250 for (node
= limbo_die_list
; node
; node
= node
->next
)
28251 prune_unused_types_walk (node
->die
);
28252 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28254 prune_unused_types_walk (ctnode
->root_die
);
28255 prune_unused_types_mark (ctnode
->type_die
, 1);
28258 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
28259 are unusual in that they are pubnames that are the children of pubtypes.
28260 They should only be marked via their parent DW_TAG_enumeration_type die,
28261 not as roots in themselves. */
28262 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
28263 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
28264 prune_unused_types_mark (pub
->die
, 1);
28265 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
28266 prune_unused_types_mark (base_type
, 1);
28268 /* For -fvar-tracking-assignments, also set the mark on nodes that could be
28269 referenced by DW_TAG_call_site DW_AT_call_origin (i.e. direct call
28271 cgraph_node
*cnode
;
28272 FOR_EACH_FUNCTION (cnode
)
28273 if (cnode
->referred_to_p (false))
28275 dw_die_ref die
= lookup_decl_die (cnode
->decl
);
28276 if (die
== NULL
|| die
->die_mark
)
28278 for (cgraph_edge
*e
= cnode
->callers
; e
; e
= e
->next_caller
)
28279 if (e
->caller
!= cnode
28280 && opt_for_fn (e
->caller
->decl
, flag_var_tracking_assignments
))
28282 prune_unused_types_mark (die
, 1);
28287 if (debug_str_hash
)
28288 debug_str_hash
->empty ();
28289 if (skeleton_debug_str_hash
)
28290 skeleton_debug_str_hash
->empty ();
28291 prune_unused_types_prune (comp_unit_die ());
28292 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
28295 if (!node
->die
->die_mark
)
28296 *pnode
= node
->next
;
28299 prune_unused_types_prune (node
->die
);
28300 pnode
= &node
->next
;
28303 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28304 prune_unused_types_prune (ctnode
->root_die
);
28306 /* Leave the marks clear. */
28307 prune_unmark_dies (comp_unit_die ());
28308 for (node
= limbo_die_list
; node
; node
= node
->next
)
28309 prune_unmark_dies (node
->die
);
28310 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28311 prune_unmark_dies (ctnode
->root_die
);
28314 /* Helpers to manipulate hash table of comdat type units. */
28316 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
28318 static inline hashval_t
hash (const comdat_type_node
*);
28319 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
28323 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
28326 memcpy (&h
, type_node
->signature
, sizeof (h
));
28331 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
28332 const comdat_type_node
*type_node_2
)
28334 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
28335 DWARF_TYPE_SIGNATURE_SIZE
));
28338 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
28339 to the location it would have been added, should we know its
28340 DECL_ASSEMBLER_NAME when we added other attributes. This will
28341 probably improve compactness of debug info, removing equivalent
28342 abbrevs, and hide any differences caused by deferring the
28343 computation of the assembler name, triggered by e.g. PCH. */
28346 move_linkage_attr (dw_die_ref die
)
28348 unsigned ix
= vec_safe_length (die
->die_attr
);
28349 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
28351 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
28352 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
28356 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
28358 if (prev
->dw_attr
== DW_AT_decl_line
28359 || prev
->dw_attr
== DW_AT_decl_column
28360 || prev
->dw_attr
== DW_AT_name
)
28364 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
28366 die
->die_attr
->pop ();
28367 die
->die_attr
->quick_insert (ix
, linkage
);
28371 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
28372 referenced from typed stack ops and count how often they are used. */
28375 mark_base_types (dw_loc_descr_ref loc
)
28377 dw_die_ref base_type
= NULL
;
28379 for (; loc
; loc
= loc
->dw_loc_next
)
28381 switch (loc
->dw_loc_opc
)
28383 case DW_OP_regval_type
:
28384 case DW_OP_deref_type
:
28385 case DW_OP_GNU_regval_type
:
28386 case DW_OP_GNU_deref_type
:
28387 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
28389 case DW_OP_convert
:
28390 case DW_OP_reinterpret
:
28391 case DW_OP_GNU_convert
:
28392 case DW_OP_GNU_reinterpret
:
28393 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
28396 case DW_OP_const_type
:
28397 case DW_OP_GNU_const_type
:
28398 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28400 case DW_OP_entry_value
:
28401 case DW_OP_GNU_entry_value
:
28402 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
28407 gcc_assert (base_type
->die_parent
== comp_unit_die ());
28408 if (base_type
->die_mark
)
28409 base_type
->die_mark
++;
28412 base_types
.safe_push (base_type
);
28413 base_type
->die_mark
= 1;
28418 /* Comparison function for sorting marked base types. */
28421 base_type_cmp (const void *x
, const void *y
)
28423 dw_die_ref dx
= *(const dw_die_ref
*) x
;
28424 dw_die_ref dy
= *(const dw_die_ref
*) y
;
28425 unsigned int byte_size1
, byte_size2
;
28426 unsigned int encoding1
, encoding2
;
28427 unsigned int align1
, align2
;
28428 if (dx
->die_mark
> dy
->die_mark
)
28430 if (dx
->die_mark
< dy
->die_mark
)
28432 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
28433 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
28434 if (byte_size1
< byte_size2
)
28436 if (byte_size1
> byte_size2
)
28438 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
28439 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
28440 if (encoding1
< encoding2
)
28442 if (encoding1
> encoding2
)
28444 align1
= get_AT_unsigned (dx
, DW_AT_alignment
);
28445 align2
= get_AT_unsigned (dy
, DW_AT_alignment
);
28446 if (align1
< align2
)
28448 if (align1
> align2
)
28453 /* Move base types marked by mark_base_types as early as possible
28454 in the CU, sorted by decreasing usage count both to make the
28455 uleb128 references as small as possible and to make sure they
28456 will have die_offset already computed by calc_die_sizes when
28457 sizes of typed stack loc ops is computed. */
28460 move_marked_base_types (void)
28463 dw_die_ref base_type
, die
, c
;
28465 if (base_types
.is_empty ())
28468 /* Sort by decreasing usage count, they will be added again in that
28470 base_types
.qsort (base_type_cmp
);
28471 die
= comp_unit_die ();
28472 c
= die
->die_child
;
28475 dw_die_ref prev
= c
;
28477 while (c
->die_mark
)
28479 remove_child_with_prev (c
, prev
);
28480 /* As base types got marked, there must be at least
28481 one node other than DW_TAG_base_type. */
28482 gcc_assert (die
->die_child
!= NULL
);
28486 while (c
!= die
->die_child
);
28487 gcc_assert (die
->die_child
);
28488 c
= die
->die_child
;
28489 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
28491 base_type
->die_mark
= 0;
28492 base_type
->die_sib
= c
->die_sib
;
28493 c
->die_sib
= base_type
;
28498 /* Helper function for resolve_addr, attempt to resolve
28499 one CONST_STRING, return true if successful. Similarly verify that
28500 SYMBOL_REFs refer to variables emitted in the current CU. */
28503 resolve_one_addr (rtx
*addr
)
28507 if (GET_CODE (rtl
) == CONST_STRING
)
28509 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28510 tree t
= build_string (len
, XSTR (rtl
, 0));
28511 tree tlen
= size_int (len
- 1);
28513 = build_array_type (char_type_node
, build_index_type (tlen
));
28514 rtl
= lookup_constant_def (t
);
28515 if (!rtl
|| !MEM_P (rtl
))
28517 rtl
= XEXP (rtl
, 0);
28518 if (GET_CODE (rtl
) == SYMBOL_REF
28519 && SYMBOL_REF_DECL (rtl
)
28520 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28522 vec_safe_push (used_rtx_array
, rtl
);
28527 if (GET_CODE (rtl
) == SYMBOL_REF
28528 && SYMBOL_REF_DECL (rtl
))
28530 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
28532 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
28535 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28539 if (GET_CODE (rtl
) == CONST
)
28541 subrtx_ptr_iterator::array_type array
;
28542 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
28543 if (!resolve_one_addr (*iter
))
28550 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
28551 if possible, and create DW_TAG_dwarf_procedure that can be referenced
28552 from DW_OP_implicit_pointer if the string hasn't been seen yet. */
28555 string_cst_pool_decl (tree t
)
28557 rtx rtl
= output_constant_def (t
, 1);
28558 unsigned char *array
;
28559 dw_loc_descr_ref l
;
28564 if (!rtl
|| !MEM_P (rtl
))
28566 rtl
= XEXP (rtl
, 0);
28567 if (GET_CODE (rtl
) != SYMBOL_REF
28568 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
28571 decl
= SYMBOL_REF_DECL (rtl
);
28572 if (!lookup_decl_die (decl
))
28574 len
= TREE_STRING_LENGTH (t
);
28575 vec_safe_push (used_rtx_array
, rtl
);
28576 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
28577 array
= ggc_vec_alloc
<unsigned char> (len
);
28578 memcpy (array
, TREE_STRING_POINTER (t
), len
);
28579 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
28580 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
28581 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
28582 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
28583 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
28584 add_AT_loc (ref
, DW_AT_location
, l
);
28585 equate_decl_number_to_die (decl
, ref
);
28590 /* Helper function of resolve_addr_in_expr. LOC is
28591 a DW_OP_addr followed by DW_OP_stack_value, either at the start
28592 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
28593 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
28594 with DW_OP_implicit_pointer if possible
28595 and return true, if unsuccessful, return false. */
28598 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
28600 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
28601 HOST_WIDE_INT offset
= 0;
28602 dw_die_ref ref
= NULL
;
28605 if (GET_CODE (rtl
) == CONST
28606 && GET_CODE (XEXP (rtl
, 0)) == PLUS
28607 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
28609 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
28610 rtl
= XEXP (XEXP (rtl
, 0), 0);
28612 if (GET_CODE (rtl
) == CONST_STRING
)
28614 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28615 tree t
= build_string (len
, XSTR (rtl
, 0));
28616 tree tlen
= size_int (len
- 1);
28619 = build_array_type (char_type_node
, build_index_type (tlen
));
28620 rtl
= string_cst_pool_decl (t
);
28624 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
28626 decl
= SYMBOL_REF_DECL (rtl
);
28627 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
28629 ref
= lookup_decl_die (decl
);
28630 if (ref
&& (get_AT (ref
, DW_AT_location
)
28631 || get_AT (ref
, DW_AT_const_value
)))
28633 loc
->dw_loc_opc
= dwarf_OP (DW_OP_implicit_pointer
);
28634 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28635 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
28636 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28637 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28638 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28639 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
28647 /* Helper function for resolve_addr, handle one location
28648 expression, return false if at least one CONST_STRING or SYMBOL_REF in
28649 the location list couldn't be resolved. */
28652 resolve_addr_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
28654 dw_loc_descr_ref keep
= NULL
;
28655 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
28656 switch (loc
->dw_loc_opc
)
28659 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28662 || prev
->dw_loc_opc
== DW_OP_piece
28663 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
28664 && loc
->dw_loc_next
28665 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
28666 && (!dwarf_strict
|| dwarf_version
>= 5)
28667 && optimize_one_addr_into_implicit_ptr (loc
))
28672 case DW_OP_GNU_addr_index
:
28673 case DW_OP_GNU_const_index
:
28674 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
28675 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
28677 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
28678 if (!resolve_one_addr (&rtl
))
28680 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
28681 loc
->dw_loc_oprnd1
.val_entry
28682 = add_addr_table_entry (rtl
, ate_kind_rtx
);
28685 case DW_OP_const4u
:
28686 case DW_OP_const8u
:
28688 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28691 case DW_OP_plus_uconst
:
28692 if (size_of_loc_descr (loc
)
28693 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
28695 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
28697 dw_loc_descr_ref repl
28698 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
28699 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
28700 add_loc_descr (&repl
, loc
->dw_loc_next
);
28704 case DW_OP_implicit_value
:
28705 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
28706 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
28709 case DW_OP_implicit_pointer
:
28710 case DW_OP_GNU_implicit_pointer
:
28711 case DW_OP_GNU_parameter_ref
:
28712 case DW_OP_GNU_variable_value
:
28713 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28716 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
28719 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28720 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28721 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28723 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
)
28726 && loc
->dw_loc_next
== NULL
28727 && AT_class (a
) == dw_val_class_loc
)
28728 switch (a
->dw_attr
)
28730 /* Following attributes allow both exprloc and reference,
28731 so if the whole expression is DW_OP_GNU_variable_value
28732 alone we could transform it into reference. */
28733 case DW_AT_byte_size
:
28734 case DW_AT_bit_size
:
28735 case DW_AT_lower_bound
:
28736 case DW_AT_upper_bound
:
28737 case DW_AT_bit_stride
:
28739 case DW_AT_allocated
:
28740 case DW_AT_associated
:
28741 case DW_AT_byte_stride
:
28742 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
28743 a
->dw_attr_val
.val_entry
= NULL
;
28744 a
->dw_attr_val
.v
.val_die_ref
.die
28745 = loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28746 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
28755 case DW_OP_const_type
:
28756 case DW_OP_regval_type
:
28757 case DW_OP_deref_type
:
28758 case DW_OP_convert
:
28759 case DW_OP_reinterpret
:
28760 case DW_OP_GNU_const_type
:
28761 case DW_OP_GNU_regval_type
:
28762 case DW_OP_GNU_deref_type
:
28763 case DW_OP_GNU_convert
:
28764 case DW_OP_GNU_reinterpret
:
28765 while (loc
->dw_loc_next
28766 && (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_convert
28767 || loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
))
28769 dw_die_ref base1
, base2
;
28770 unsigned enc1
, enc2
, size1
, size2
;
28771 if (loc
->dw_loc_opc
== DW_OP_regval_type
28772 || loc
->dw_loc_opc
== DW_OP_deref_type
28773 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28774 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28775 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
28776 else if (loc
->dw_loc_oprnd1
.val_class
28777 == dw_val_class_unsigned_const
)
28780 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28781 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
28782 == dw_val_class_unsigned_const
)
28784 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28785 gcc_assert (base1
->die_tag
== DW_TAG_base_type
28786 && base2
->die_tag
== DW_TAG_base_type
);
28787 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
28788 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
28789 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
28790 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
28792 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
28793 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
28797 /* Optimize away next DW_OP_convert after
28798 adjusting LOC's base type die reference. */
28799 if (loc
->dw_loc_opc
== DW_OP_regval_type
28800 || loc
->dw_loc_opc
== DW_OP_deref_type
28801 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28802 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28803 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
28805 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
28806 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28809 /* Don't change integer DW_OP_convert after e.g. floating
28810 point typed stack entry. */
28811 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
28812 keep
= loc
->dw_loc_next
;
28822 /* Helper function of resolve_addr. DIE had DW_AT_location of
28823 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
28824 and DW_OP_addr couldn't be resolved. resolve_addr has already
28825 removed the DW_AT_location attribute. This function attempts to
28826 add a new DW_AT_location attribute with DW_OP_implicit_pointer
28827 to it or DW_AT_const_value attribute, if possible. */
28830 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
28833 || lookup_decl_die (decl
) != die
28834 || DECL_EXTERNAL (decl
)
28835 || !TREE_STATIC (decl
)
28836 || DECL_INITIAL (decl
) == NULL_TREE
28837 || DECL_P (DECL_INITIAL (decl
))
28838 || get_AT (die
, DW_AT_const_value
))
28841 tree init
= DECL_INITIAL (decl
);
28842 HOST_WIDE_INT offset
= 0;
28843 /* For variables that have been optimized away and thus
28844 don't have a memory location, see if we can emit
28845 DW_AT_const_value instead. */
28846 if (tree_add_const_value_attribute (die
, init
))
28848 if (dwarf_strict
&& dwarf_version
< 5)
28850 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
28851 and ADDR_EXPR refers to a decl that has DW_AT_location or
28852 DW_AT_const_value (but isn't addressable, otherwise
28853 resolving the original DW_OP_addr wouldn't fail), see if
28854 we can add DW_OP_implicit_pointer. */
28856 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
28857 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
28859 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
28860 init
= TREE_OPERAND (init
, 0);
28863 if (TREE_CODE (init
) != ADDR_EXPR
)
28865 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
28866 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
28867 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
28868 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
28869 && TREE_OPERAND (init
, 0) != decl
))
28872 dw_loc_descr_ref l
;
28874 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
28876 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
28879 decl
= SYMBOL_REF_DECL (rtl
);
28882 decl
= TREE_OPERAND (init
, 0);
28883 ref
= lookup_decl_die (decl
);
28885 || (!get_AT (ref
, DW_AT_location
)
28886 && !get_AT (ref
, DW_AT_const_value
)))
28888 l
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
28889 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28890 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28891 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28892 add_AT_loc (die
, DW_AT_location
, l
);
28896 /* Return NULL if l is a DWARF expression, or first op that is not
28897 valid DWARF expression. */
28899 static dw_loc_descr_ref
28900 non_dwarf_expression (dw_loc_descr_ref l
)
28904 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28906 switch (l
->dw_loc_opc
)
28909 case DW_OP_implicit_value
:
28910 case DW_OP_stack_value
:
28911 case DW_OP_implicit_pointer
:
28912 case DW_OP_GNU_implicit_pointer
:
28913 case DW_OP_GNU_parameter_ref
:
28915 case DW_OP_bit_piece
:
28920 l
= l
->dw_loc_next
;
28925 /* Return adjusted copy of EXPR:
28926 If it is empty DWARF expression, return it.
28927 If it is valid non-empty DWARF expression,
28928 return copy of EXPR with DW_OP_deref appended to it.
28929 If it is DWARF expression followed by DW_OP_reg{N,x}, return
28930 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
28931 If it is DWARF expression followed by DW_OP_stack_value, return
28932 copy of the DWARF expression without anything appended.
28933 Otherwise, return NULL. */
28935 static dw_loc_descr_ref
28936 copy_deref_exprloc (dw_loc_descr_ref expr
)
28938 dw_loc_descr_ref tail
= NULL
;
28943 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
28944 if (l
&& l
->dw_loc_next
)
28949 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28950 tail
= new_loc_descr ((enum dwarf_location_atom
)
28951 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
28954 switch (l
->dw_loc_opc
)
28957 tail
= new_loc_descr (DW_OP_bregx
,
28958 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
28960 case DW_OP_stack_value
:
28967 tail
= new_loc_descr (DW_OP_deref
, 0, 0);
28969 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
28972 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
28973 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
28974 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
28975 p
= &(*p
)->dw_loc_next
;
28976 expr
= expr
->dw_loc_next
;
28982 /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
28983 reference to a variable or argument, adjust it if needed and return:
28984 -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
28985 attribute if present should be removed
28986 0 keep the attribute perhaps with minor modifications, no need to rescan
28987 1 if the attribute has been successfully adjusted. */
28990 optimize_string_length (dw_attr_node
*a
)
28992 dw_loc_descr_ref l
= AT_loc (a
), lv
;
28994 if (l
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28996 tree decl
= l
->dw_loc_oprnd1
.v
.val_decl_ref
;
28997 die
= lookup_decl_die (decl
);
29000 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
29001 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= die
;
29002 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
29008 die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
29010 /* DWARF5 allows reference class, so we can then reference the DIE.
29011 Only do this for DW_OP_GNU_variable_value DW_OP_stack_value. */
29012 if (l
->dw_loc_next
!= NULL
&& dwarf_version
>= 5)
29014 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
29015 a
->dw_attr_val
.val_entry
= NULL
;
29016 a
->dw_attr_val
.v
.val_die_ref
.die
= die
;
29017 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
29021 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
29023 bool non_dwarf_expr
= false;
29026 return dwarf_strict
? -1 : 0;
29027 switch (AT_class (av
))
29029 case dw_val_class_loc_list
:
29030 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
29031 if (d
->expr
&& non_dwarf_expression (d
->expr
))
29032 non_dwarf_expr
= true;
29034 case dw_val_class_loc
:
29037 return dwarf_strict
? -1 : 0;
29038 if (non_dwarf_expression (lv
))
29039 non_dwarf_expr
= true;
29042 return dwarf_strict
? -1 : 0;
29045 /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
29046 into DW_OP_call4 or DW_OP_GNU_variable_value into
29047 DW_OP_call4 DW_OP_deref, do so. */
29048 if (!non_dwarf_expr
29049 && (l
->dw_loc_next
!= NULL
|| AT_class (av
) == dw_val_class_loc
))
29051 l
->dw_loc_opc
= DW_OP_call4
;
29052 if (l
->dw_loc_next
)
29053 l
->dw_loc_next
= NULL
;
29055 l
->dw_loc_next
= new_loc_descr (DW_OP_deref
, 0, 0);
29059 /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
29060 copy over the DW_AT_location attribute from die to a. */
29061 if (l
->dw_loc_next
!= NULL
)
29063 a
->dw_attr_val
= av
->dw_attr_val
;
29067 dw_loc_list_ref list
, *p
;
29068 switch (AT_class (av
))
29070 case dw_val_class_loc_list
:
29073 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
29075 lv
= copy_deref_exprloc (d
->expr
);
29078 *p
= new_loc_list (lv
, d
->begin
, d
->end
, d
->section
);
29079 p
= &(*p
)->dw_loc_next
;
29081 else if (!dwarf_strict
&& d
->expr
)
29085 return dwarf_strict
? -1 : 0;
29086 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
29088 *AT_loc_list_ptr (a
) = list
;
29090 case dw_val_class_loc
:
29091 lv
= copy_deref_exprloc (AT_loc (av
));
29093 return dwarf_strict
? -1 : 0;
29094 a
->dw_attr_val
.v
.val_loc
= lv
;
29097 gcc_unreachable ();
29101 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
29102 an address in .rodata section if the string literal is emitted there,
29103 or remove the containing location list or replace DW_AT_const_value
29104 with DW_AT_location and empty location expression, if it isn't found
29105 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
29106 to something that has been emitted in the current CU. */
29109 resolve_addr (dw_die_ref die
)
29113 dw_loc_list_ref
*curr
, *start
, loc
;
29115 bool remove_AT_byte_size
= false;
29117 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29118 switch (AT_class (a
))
29120 case dw_val_class_loc_list
:
29121 start
= curr
= AT_loc_list_ptr (a
);
29124 /* The same list can be referenced more than once. See if we have
29125 already recorded the result from a previous pass. */
29127 *curr
= loc
->dw_loc_next
;
29128 else if (!loc
->resolved_addr
)
29130 /* As things stand, we do not expect or allow one die to
29131 reference a suffix of another die's location list chain.
29132 References must be identical or completely separate.
29133 There is therefore no need to cache the result of this
29134 pass on any list other than the first; doing so
29135 would lead to unnecessary writes. */
29138 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
29139 if (!resolve_addr_in_expr (a
, (*curr
)->expr
))
29141 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
29142 dw_loc_descr_ref l
= (*curr
)->expr
;
29144 if (next
&& (*curr
)->ll_symbol
)
29146 gcc_assert (!next
->ll_symbol
);
29147 next
->ll_symbol
= (*curr
)->ll_symbol
;
29149 if (dwarf_split_debug_info
)
29150 remove_loc_list_addr_table_entries (l
);
29155 mark_base_types ((*curr
)->expr
);
29156 curr
= &(*curr
)->dw_loc_next
;
29160 loc
->resolved_addr
= 1;
29164 loc
->dw_loc_next
= *start
;
29169 remove_AT (die
, a
->dw_attr
);
29173 case dw_val_class_loc
:
29175 dw_loc_descr_ref l
= AT_loc (a
);
29176 /* DW_OP_GNU_variable_value DW_OP_stack_value or
29177 DW_OP_GNU_variable_value in DW_AT_string_length can be converted
29178 into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
29179 DWARF4 unlike DW_OP_GNU_variable_value. Or for DWARF5
29180 DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
29181 with DW_FORM_ref referencing the same DIE as
29182 DW_OP_GNU_variable_value used to reference. */
29183 if (a
->dw_attr
== DW_AT_string_length
29185 && l
->dw_loc_opc
== DW_OP_GNU_variable_value
29186 && (l
->dw_loc_next
== NULL
29187 || (l
->dw_loc_next
->dw_loc_next
== NULL
29188 && l
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
)))
29190 switch (optimize_string_length (a
))
29193 remove_AT (die
, a
->dw_attr
);
29195 /* If we drop DW_AT_string_length, we need to drop also
29196 DW_AT_{string_length_,}byte_size. */
29197 remove_AT_byte_size
= true;
29202 /* Even if we keep the optimized DW_AT_string_length,
29203 it might have changed AT_class, so process it again. */
29208 /* For -gdwarf-2 don't attempt to optimize
29209 DW_AT_data_member_location containing
29210 DW_OP_plus_uconst - older consumers might
29211 rely on it being that op instead of a more complex,
29212 but shorter, location description. */
29213 if ((dwarf_version
> 2
29214 || a
->dw_attr
!= DW_AT_data_member_location
29216 || l
->dw_loc_opc
!= DW_OP_plus_uconst
29217 || l
->dw_loc_next
!= NULL
)
29218 && !resolve_addr_in_expr (a
, l
))
29220 if (dwarf_split_debug_info
)
29221 remove_loc_list_addr_table_entries (l
);
29223 && l
->dw_loc_next
== NULL
29224 && l
->dw_loc_opc
== DW_OP_addr
29225 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
29226 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
29227 && a
->dw_attr
== DW_AT_location
)
29229 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
29230 remove_AT (die
, a
->dw_attr
);
29232 optimize_location_into_implicit_ptr (die
, decl
);
29235 if (a
->dw_attr
== DW_AT_string_length
)
29236 /* If we drop DW_AT_string_length, we need to drop also
29237 DW_AT_{string_length_,}byte_size. */
29238 remove_AT_byte_size
= true;
29239 remove_AT (die
, a
->dw_attr
);
29243 mark_base_types (l
);
29246 case dw_val_class_addr
:
29247 if (a
->dw_attr
== DW_AT_const_value
29248 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
29250 if (AT_index (a
) != NOT_INDEXED
)
29251 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
29252 remove_AT (die
, a
->dw_attr
);
29255 if ((die
->die_tag
== DW_TAG_call_site
29256 && a
->dw_attr
== DW_AT_call_origin
)
29257 || (die
->die_tag
== DW_TAG_GNU_call_site
29258 && a
->dw_attr
== DW_AT_abstract_origin
))
29260 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
29261 dw_die_ref tdie
= lookup_decl_die (tdecl
);
29264 && DECL_EXTERNAL (tdecl
)
29265 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
29266 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
29268 dw_die_ref pdie
= cdie
;
29269 /* Make sure we don't add these DIEs into type units.
29270 We could emit skeleton DIEs for context (namespaces,
29271 outer structs/classes) and a skeleton DIE for the
29272 innermost context with DW_AT_signature pointing to the
29273 type unit. See PR78835. */
29274 while (pdie
&& pdie
->die_tag
!= DW_TAG_type_unit
)
29275 pdie
= pdie
->die_parent
;
29278 /* Creating a full DIE for tdecl is overly expensive and
29279 at this point even wrong when in the LTO phase
29280 as it can end up generating new type DIEs we didn't
29281 output and thus optimize_external_refs will crash. */
29282 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
29283 add_AT_flag (tdie
, DW_AT_external
, 1);
29284 add_AT_flag (tdie
, DW_AT_declaration
, 1);
29285 add_linkage_attr (tdie
, tdecl
);
29286 add_name_and_src_coords_attributes (tdie
, tdecl
, true);
29287 equate_decl_number_to_die (tdecl
, tdie
);
29292 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
29293 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
29294 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
29298 if (AT_index (a
) != NOT_INDEXED
)
29299 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
29300 remove_AT (die
, a
->dw_attr
);
29309 if (remove_AT_byte_size
)
29310 remove_AT (die
, dwarf_version
>= 5
29311 ? DW_AT_string_length_byte_size
29312 : DW_AT_byte_size
);
29314 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
29317 /* Helper routines for optimize_location_lists.
29318 This pass tries to share identical local lists in .debug_loc
29321 /* Iteratively hash operands of LOC opcode into HSTATE. */
29324 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
29326 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
29327 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
29329 switch (loc
->dw_loc_opc
)
29331 case DW_OP_const4u
:
29332 case DW_OP_const8u
:
29336 case DW_OP_const1u
:
29337 case DW_OP_const1s
:
29338 case DW_OP_const2u
:
29339 case DW_OP_const2s
:
29340 case DW_OP_const4s
:
29341 case DW_OP_const8s
:
29345 case DW_OP_plus_uconst
:
29381 case DW_OP_deref_size
:
29382 case DW_OP_xderef_size
:
29383 hstate
.add_object (val1
->v
.val_int
);
29390 gcc_assert (val1
->val_class
== dw_val_class_loc
);
29391 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
29392 hstate
.add_object (offset
);
29395 case DW_OP_implicit_value
:
29396 hstate
.add_object (val1
->v
.val_unsigned
);
29397 switch (val2
->val_class
)
29399 case dw_val_class_const
:
29400 hstate
.add_object (val2
->v
.val_int
);
29402 case dw_val_class_vec
:
29404 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
29405 unsigned int len
= val2
->v
.val_vec
.length
;
29407 hstate
.add_int (elt_size
);
29408 hstate
.add_int (len
);
29409 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
29412 case dw_val_class_const_double
:
29413 hstate
.add_object (val2
->v
.val_double
.low
);
29414 hstate
.add_object (val2
->v
.val_double
.high
);
29416 case dw_val_class_wide_int
:
29417 hstate
.add (val2
->v
.val_wide
->get_val (),
29418 get_full_len (*val2
->v
.val_wide
)
29419 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
29421 case dw_val_class_addr
:
29422 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
29425 gcc_unreachable ();
29429 case DW_OP_bit_piece
:
29430 hstate
.add_object (val1
->v
.val_int
);
29431 hstate
.add_object (val2
->v
.val_int
);
29437 unsigned char dtprel
= 0xd1;
29438 hstate
.add_object (dtprel
);
29440 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
29442 case DW_OP_GNU_addr_index
:
29443 case DW_OP_GNU_const_index
:
29447 unsigned char dtprel
= 0xd1;
29448 hstate
.add_object (dtprel
);
29450 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
29453 case DW_OP_implicit_pointer
:
29454 case DW_OP_GNU_implicit_pointer
:
29455 hstate
.add_int (val2
->v
.val_int
);
29457 case DW_OP_entry_value
:
29458 case DW_OP_GNU_entry_value
:
29459 hstate
.add_object (val1
->v
.val_loc
);
29461 case DW_OP_regval_type
:
29462 case DW_OP_deref_type
:
29463 case DW_OP_GNU_regval_type
:
29464 case DW_OP_GNU_deref_type
:
29466 unsigned int byte_size
29467 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
29468 unsigned int encoding
29469 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
29470 hstate
.add_object (val1
->v
.val_int
);
29471 hstate
.add_object (byte_size
);
29472 hstate
.add_object (encoding
);
29475 case DW_OP_convert
:
29476 case DW_OP_reinterpret
:
29477 case DW_OP_GNU_convert
:
29478 case DW_OP_GNU_reinterpret
:
29479 if (val1
->val_class
== dw_val_class_unsigned_const
)
29481 hstate
.add_object (val1
->v
.val_unsigned
);
29485 case DW_OP_const_type
:
29486 case DW_OP_GNU_const_type
:
29488 unsigned int byte_size
29489 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
29490 unsigned int encoding
29491 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
29492 hstate
.add_object (byte_size
);
29493 hstate
.add_object (encoding
);
29494 if (loc
->dw_loc_opc
!= DW_OP_const_type
29495 && loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
29497 hstate
.add_object (val2
->val_class
);
29498 switch (val2
->val_class
)
29500 case dw_val_class_const
:
29501 hstate
.add_object (val2
->v
.val_int
);
29503 case dw_val_class_vec
:
29505 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
29506 unsigned int len
= val2
->v
.val_vec
.length
;
29508 hstate
.add_object (elt_size
);
29509 hstate
.add_object (len
);
29510 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
29513 case dw_val_class_const_double
:
29514 hstate
.add_object (val2
->v
.val_double
.low
);
29515 hstate
.add_object (val2
->v
.val_double
.high
);
29517 case dw_val_class_wide_int
:
29518 hstate
.add (val2
->v
.val_wide
->get_val (),
29519 get_full_len (*val2
->v
.val_wide
)
29520 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
29523 gcc_unreachable ();
29529 /* Other codes have no operands. */
29534 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
29537 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
29539 dw_loc_descr_ref l
;
29540 bool sizes_computed
= false;
29541 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
29542 size_of_locs (loc
);
29544 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
29546 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
29547 hstate
.add_object (opc
);
29548 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
29550 size_of_locs (loc
);
29551 sizes_computed
= true;
29553 hash_loc_operands (l
, hstate
);
29557 /* Compute hash of the whole location list LIST_HEAD. */
29560 hash_loc_list (dw_loc_list_ref list_head
)
29562 dw_loc_list_ref curr
= list_head
;
29563 inchash::hash hstate
;
29565 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29567 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
29568 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
29570 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
29571 hash_locs (curr
->expr
, hstate
);
29573 list_head
->hash
= hstate
.end ();
29576 /* Return true if X and Y opcodes have the same operands. */
29579 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29581 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
29582 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
29583 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
29584 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
29586 switch (x
->dw_loc_opc
)
29588 case DW_OP_const4u
:
29589 case DW_OP_const8u
:
29593 case DW_OP_const1u
:
29594 case DW_OP_const1s
:
29595 case DW_OP_const2u
:
29596 case DW_OP_const2s
:
29597 case DW_OP_const4s
:
29598 case DW_OP_const8s
:
29602 case DW_OP_plus_uconst
:
29638 case DW_OP_deref_size
:
29639 case DW_OP_xderef_size
:
29640 return valx1
->v
.val_int
== valy1
->v
.val_int
;
29643 /* If splitting debug info, the use of DW_OP_GNU_addr_index
29644 can cause irrelevant differences in dw_loc_addr. */
29645 gcc_assert (valx1
->val_class
== dw_val_class_loc
29646 && valy1
->val_class
== dw_val_class_loc
29647 && (dwarf_split_debug_info
29648 || x
->dw_loc_addr
== y
->dw_loc_addr
));
29649 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
29650 case DW_OP_implicit_value
:
29651 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
29652 || valx2
->val_class
!= valy2
->val_class
)
29654 switch (valx2
->val_class
)
29656 case dw_val_class_const
:
29657 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29658 case dw_val_class_vec
:
29659 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29660 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29661 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29662 valx2
->v
.val_vec
.elt_size
29663 * valx2
->v
.val_vec
.length
) == 0;
29664 case dw_val_class_const_double
:
29665 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29666 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29667 case dw_val_class_wide_int
:
29668 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29669 case dw_val_class_addr
:
29670 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
29672 gcc_unreachable ();
29675 case DW_OP_bit_piece
:
29676 return valx1
->v
.val_int
== valy1
->v
.val_int
29677 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29680 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
29681 case DW_OP_GNU_addr_index
:
29682 case DW_OP_GNU_const_index
:
29684 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
29685 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
29686 return rtx_equal_p (ax1
, ay1
);
29688 case DW_OP_implicit_pointer
:
29689 case DW_OP_GNU_implicit_pointer
:
29690 return valx1
->val_class
== dw_val_class_die_ref
29691 && valx1
->val_class
== valy1
->val_class
29692 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
29693 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29694 case DW_OP_entry_value
:
29695 case DW_OP_GNU_entry_value
:
29696 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
29697 case DW_OP_const_type
:
29698 case DW_OP_GNU_const_type
:
29699 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
29700 || valx2
->val_class
!= valy2
->val_class
)
29702 switch (valx2
->val_class
)
29704 case dw_val_class_const
:
29705 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29706 case dw_val_class_vec
:
29707 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29708 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29709 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29710 valx2
->v
.val_vec
.elt_size
29711 * valx2
->v
.val_vec
.length
) == 0;
29712 case dw_val_class_const_double
:
29713 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29714 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29715 case dw_val_class_wide_int
:
29716 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29718 gcc_unreachable ();
29720 case DW_OP_regval_type
:
29721 case DW_OP_deref_type
:
29722 case DW_OP_GNU_regval_type
:
29723 case DW_OP_GNU_deref_type
:
29724 return valx1
->v
.val_int
== valy1
->v
.val_int
29725 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
29726 case DW_OP_convert
:
29727 case DW_OP_reinterpret
:
29728 case DW_OP_GNU_convert
:
29729 case DW_OP_GNU_reinterpret
:
29730 if (valx1
->val_class
!= valy1
->val_class
)
29732 if (valx1
->val_class
== dw_val_class_unsigned_const
)
29733 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
29734 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29735 case DW_OP_GNU_parameter_ref
:
29736 return valx1
->val_class
== dw_val_class_die_ref
29737 && valx1
->val_class
== valy1
->val_class
29738 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29740 /* Other codes have no operands. */
29745 /* Return true if DWARF location expressions X and Y are the same. */
29748 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29750 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
29751 if (x
->dw_loc_opc
!= y
->dw_loc_opc
29752 || x
->dtprel
!= y
->dtprel
29753 || !compare_loc_operands (x
, y
))
29755 return x
== NULL
&& y
== NULL
;
29758 /* Hashtable helpers. */
29760 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
29762 static inline hashval_t
hash (const dw_loc_list_struct
*);
29763 static inline bool equal (const dw_loc_list_struct
*,
29764 const dw_loc_list_struct
*);
29767 /* Return precomputed hash of location list X. */
29770 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
29775 /* Return true if location lists A and B are the same. */
29778 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
29779 const dw_loc_list_struct
*b
)
29783 if (a
->hash
!= b
->hash
)
29785 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
29786 if (strcmp (a
->begin
, b
->begin
) != 0
29787 || strcmp (a
->end
, b
->end
) != 0
29788 || (a
->section
== NULL
) != (b
->section
== NULL
)
29789 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
29790 || !compare_locs (a
->expr
, b
->expr
))
29792 return a
== NULL
&& b
== NULL
;
29795 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
29798 /* Recursively optimize location lists referenced from DIE
29799 children and share them whenever possible. */
29802 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
29807 dw_loc_list_struct
**slot
;
29809 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29810 if (AT_class (a
) == dw_val_class_loc_list
)
29812 dw_loc_list_ref list
= AT_loc_list (a
);
29813 /* TODO: perform some optimizations here, before hashing
29814 it and storing into the hash table. */
29815 hash_loc_list (list
);
29816 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
29820 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
29823 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
29827 /* Recursively assign each location list a unique index into the debug_addr
29831 index_location_lists (dw_die_ref die
)
29837 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29838 if (AT_class (a
) == dw_val_class_loc_list
)
29840 dw_loc_list_ref list
= AT_loc_list (a
);
29841 dw_loc_list_ref curr
;
29842 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29844 /* Don't index an entry that has already been indexed
29845 or won't be output. */
29846 if (curr
->begin_entry
!= NULL
29847 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
29851 = add_addr_table_entry (xstrdup (curr
->begin
), ate_kind_label
);
29855 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
29858 /* Optimize location lists referenced from DIE
29859 children and share them whenever possible. */
29862 optimize_location_lists (dw_die_ref die
)
29864 loc_list_hash_type
htab (500);
29865 optimize_location_lists_1 (die
, &htab
);
29868 /* Traverse the limbo die list, and add parent/child links. The only
29869 dies without parents that should be here are concrete instances of
29870 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
29871 For concrete instances, we can get the parent die from the abstract
29875 flush_limbo_die_list (void)
29877 limbo_die_node
*node
;
29879 /* get_context_die calls force_decl_die, which can put new DIEs on the
29880 limbo list in LTO mode when nested functions are put in a different
29881 partition than that of their parent function. */
29882 while ((node
= limbo_die_list
))
29884 dw_die_ref die
= node
->die
;
29885 limbo_die_list
= node
->next
;
29887 if (die
->die_parent
== NULL
)
29889 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
29891 if (origin
&& origin
->die_parent
)
29892 add_child_die (origin
->die_parent
, die
);
29893 else if (is_cu_die (die
))
29895 else if (seen_error ())
29896 /* It's OK to be confused by errors in the input. */
29897 add_child_die (comp_unit_die (), die
);
29900 /* In certain situations, the lexical block containing a
29901 nested function can be optimized away, which results
29902 in the nested function die being orphaned. Likewise
29903 with the return type of that nested function. Force
29904 this to be a child of the containing function.
29906 It may happen that even the containing function got fully
29907 inlined and optimized out. In that case we are lost and
29908 assign the empty child. This should not be big issue as
29909 the function is likely unreachable too. */
29910 gcc_assert (node
->created_for
);
29912 if (DECL_P (node
->created_for
))
29913 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
29914 else if (TYPE_P (node
->created_for
))
29915 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
29917 origin
= comp_unit_die ();
29919 add_child_die (origin
, die
);
29925 /* Reset DIEs so we can output them again. */
29928 reset_dies (dw_die_ref die
)
29932 /* Remove stuff we re-generate. */
29934 die
->die_offset
= 0;
29935 die
->die_abbrev
= 0;
29936 remove_AT (die
, DW_AT_sibling
);
29938 FOR_EACH_CHILD (die
, c
, reset_dies (c
));
29941 /* Output stuff that dwarf requires at the end of every file,
29942 and generate the DWARF-2 debugging info. */
29945 dwarf2out_finish (const char *)
29947 comdat_type_node
*ctnode
;
29948 dw_die_ref main_comp_unit_die
;
29949 unsigned char checksum
[16];
29950 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
29952 /* Flush out any latecomers to the limbo party. */
29953 flush_limbo_die_list ();
29957 verify_die (comp_unit_die ());
29958 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
29959 verify_die (node
->die
);
29962 /* We shouldn't have any symbols with delayed asm names for
29963 DIEs generated after early finish. */
29964 gcc_assert (deferred_asm_name
== NULL
);
29966 gen_remaining_tmpl_value_param_die_attribute ();
29968 if (flag_generate_lto
|| flag_generate_offload
)
29970 gcc_assert (flag_fat_lto_objects
|| flag_generate_offload
);
29972 /* Prune stuff so that dwarf2out_finish runs successfully
29973 for the fat part of the object. */
29974 reset_dies (comp_unit_die ());
29975 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
29976 reset_dies (node
->die
);
29978 hash_table
<comdat_type_hasher
> comdat_type_table (100);
29979 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29981 comdat_type_node
**slot
29982 = comdat_type_table
.find_slot (ctnode
, INSERT
);
29984 /* Don't reset types twice. */
29985 if (*slot
!= HTAB_EMPTY_ENTRY
)
29988 /* Add a pointer to the line table for the main compilation unit
29989 so that the debugger can make sense of DW_AT_decl_file
29991 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29992 reset_dies (ctnode
->root_die
);
29997 /* Reset die CU symbol so we don't output it twice. */
29998 comp_unit_die ()->die_id
.die_symbol
= NULL
;
30000 /* Remove DW_AT_macro from the early output. */
30002 remove_AT (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
);
30004 /* Remove indirect string decisions. */
30005 debug_str_hash
->traverse
<void *, reset_indirect_string
> (NULL
);
30008 #if ENABLE_ASSERT_CHECKING
30010 dw_die_ref die
= comp_unit_die (), c
;
30011 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
30014 resolve_addr (comp_unit_die ());
30015 move_marked_base_types ();
30017 /* Initialize sections and labels used for actual assembler output. */
30018 unsigned generation
= init_sections_and_labels (false);
30020 /* Traverse the DIE's and add sibling attributes to those DIE's that
30022 add_sibling_attributes (comp_unit_die ());
30023 limbo_die_node
*node
;
30024 for (node
= cu_die_list
; node
; node
= node
->next
)
30025 add_sibling_attributes (node
->die
);
30026 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
30027 add_sibling_attributes (ctnode
->root_die
);
30029 /* When splitting DWARF info, we put some attributes in the
30030 skeleton compile_unit DIE that remains in the .o, while
30031 most attributes go in the DWO compile_unit_die. */
30032 if (dwarf_split_debug_info
)
30034 limbo_die_node
*cu
;
30035 main_comp_unit_die
= gen_compile_unit_die (NULL
);
30036 if (dwarf_version
>= 5)
30037 main_comp_unit_die
->die_tag
= DW_TAG_skeleton_unit
;
30038 cu
= limbo_die_list
;
30039 gcc_assert (cu
->die
== main_comp_unit_die
);
30040 limbo_die_list
= limbo_die_list
->next
;
30041 cu
->next
= cu_die_list
;
30045 main_comp_unit_die
= comp_unit_die ();
30047 /* Output a terminator label for the .text section. */
30048 switch_to_section (text_section
);
30049 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
30050 if (cold_text_section
)
30052 switch_to_section (cold_text_section
);
30053 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
30056 /* We can only use the low/high_pc attributes if all of the code was
30058 if (!have_multiple_function_sections
30059 || (dwarf_version
< 3 && dwarf_strict
))
30061 /* Don't add if the CU has no associated code. */
30062 if (text_section_used
)
30063 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
30064 text_end_label
, true);
30070 bool range_list_added
= false;
30072 if (text_section_used
)
30073 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
30074 text_end_label
, &range_list_added
, true);
30075 if (cold_text_section_used
)
30076 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
30077 cold_end_label
, &range_list_added
, true);
30079 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
30081 if (DECL_IGNORED_P (fde
->decl
))
30083 if (!fde
->in_std_section
)
30084 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
30085 fde
->dw_fde_end
, &range_list_added
,
30087 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
30088 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
30089 fde
->dw_fde_second_end
, &range_list_added
,
30093 if (range_list_added
)
30095 /* We need to give .debug_loc and .debug_ranges an appropriate
30096 "base address". Use zero so that these addresses become
30097 absolute. Historically, we've emitted the unexpected
30098 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
30099 Emit both to give time for other tools to adapt. */
30100 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
30101 if (! dwarf_strict
&& dwarf_version
< 4)
30102 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
30108 /* AIX Assembler inserts the length, so adjust the reference to match the
30109 offset expected by debuggers. */
30110 strcpy (dl_section_ref
, debug_line_section_label
);
30111 if (XCOFF_DEBUGGING_INFO
)
30112 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
30114 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
30115 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
30119 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
30120 macinfo_section_label
);
30122 if (dwarf_split_debug_info
)
30124 if (have_location_lists
)
30126 if (dwarf_version
>= 5)
30127 add_AT_loclistsptr (comp_unit_die (), DW_AT_loclists_base
,
30128 loc_section_label
);
30129 /* optimize_location_lists calculates the size of the lists,
30130 so index them first, and assign indices to the entries.
30131 Although optimize_location_lists will remove entries from
30132 the table, it only does so for duplicates, and therefore
30133 only reduces ref_counts to 1. */
30134 index_location_lists (comp_unit_die ());
30137 if (addr_index_table
!= NULL
)
30139 unsigned int index
= 0;
30141 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
30147 if (have_location_lists
)
30149 optimize_location_lists (comp_unit_die ());
30150 /* And finally assign indexes to the entries for -gsplit-dwarf. */
30151 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
30152 assign_location_list_indexes (comp_unit_die ());
30155 save_macinfo_strings ();
30157 if (dwarf_split_debug_info
)
30159 unsigned int index
= 0;
30161 /* Add attributes common to skeleton compile_units and
30162 type_units. Because these attributes include strings, it
30163 must be done before freezing the string table. Top-level
30164 skeleton die attrs are added when the skeleton type unit is
30165 created, so ensure it is created by this point. */
30166 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
30167 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
30170 /* Output all of the compilation units. We put the main one last so that
30171 the offsets are available to output_pubnames. */
30172 for (node
= cu_die_list
; node
; node
= node
->next
)
30173 output_comp_unit (node
->die
, 0, NULL
);
30175 hash_table
<comdat_type_hasher
> comdat_type_table (100);
30176 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
30178 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
30180 /* Don't output duplicate types. */
30181 if (*slot
!= HTAB_EMPTY_ENTRY
)
30184 /* Add a pointer to the line table for the main compilation unit
30185 so that the debugger can make sense of DW_AT_decl_file
30187 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
30188 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
30189 (!dwarf_split_debug_info
30191 : debug_skeleton_line_section_label
));
30193 output_comdat_type_unit (ctnode
);
30197 if (dwarf_split_debug_info
)
30200 struct md5_ctx ctx
;
30202 if (dwarf_version
>= 5 && !vec_safe_is_empty (ranges_table
))
30205 /* Compute a checksum of the comp_unit to use as the dwo_id. */
30206 md5_init_ctx (&ctx
);
30208 die_checksum (comp_unit_die (), &ctx
, &mark
);
30209 unmark_all_dies (comp_unit_die ());
30210 md5_finish_ctx (&ctx
, checksum
);
30212 if (dwarf_version
< 5)
30214 /* Use the first 8 bytes of the checksum as the dwo_id,
30215 and add it to both comp-unit DIEs. */
30216 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
30217 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
30220 /* Add the base offset of the ranges table to the skeleton
30222 if (!vec_safe_is_empty (ranges_table
))
30224 if (dwarf_version
>= 5)
30225 add_AT_lineptr (main_comp_unit_die
, DW_AT_rnglists_base
,
30226 ranges_base_label
);
30228 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
30229 ranges_section_label
);
30232 switch_to_section (debug_addr_section
);
30233 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
30234 output_addr_table ();
30237 /* Output the main compilation unit if non-empty or if .debug_macinfo
30238 or .debug_macro will be emitted. */
30239 output_comp_unit (comp_unit_die (), have_macinfo
,
30240 dwarf_split_debug_info
? checksum
: NULL
);
30242 if (dwarf_split_debug_info
&& info_section_emitted
)
30243 output_skeleton_debug_sections (main_comp_unit_die
, checksum
);
30245 /* Output the abbreviation table. */
30246 if (vec_safe_length (abbrev_die_table
) != 1)
30248 switch_to_section (debug_abbrev_section
);
30249 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
30250 output_abbrev_section ();
30253 /* Output location list section if necessary. */
30254 if (have_location_lists
)
30256 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
30257 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
30258 /* Output the location lists info. */
30259 switch_to_section (debug_loc_section
);
30260 if (dwarf_version
>= 5)
30262 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_LOC_SECTION_LABEL
, 1);
30263 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_LOC_SECTION_LABEL
, 2);
30264 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
30265 dw2_asm_output_data (4, 0xffffffff,
30266 "Initial length escape value indicating "
30267 "64-bit DWARF extension");
30268 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
30269 "Length of Location Lists");
30270 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
30271 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
30272 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
30273 dw2_asm_output_data (1, 0, "Segment Size");
30274 dw2_asm_output_data (4, dwarf_split_debug_info
? loc_list_idx
: 0,
30275 "Offset Entry Count");
30277 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
30278 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
30280 unsigned int save_loc_list_idx
= loc_list_idx
;
30282 output_loclists_offsets (comp_unit_die ());
30283 gcc_assert (save_loc_list_idx
== loc_list_idx
);
30285 output_location_lists (comp_unit_die ());
30286 if (dwarf_version
>= 5)
30287 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
30290 output_pubtables ();
30292 /* Output the address range information if a CU (.debug_info section)
30293 was emitted. We output an empty table even if we had no functions
30294 to put in it. This because the consumer has no way to tell the
30295 difference between an empty table that we omitted and failure to
30296 generate a table that would have contained data. */
30297 if (info_section_emitted
)
30299 switch_to_section (debug_aranges_section
);
30303 /* Output ranges section if necessary. */
30304 if (!vec_safe_is_empty (ranges_table
))
30306 if (dwarf_version
>= 5)
30307 output_rnglists (generation
);
30312 /* Have to end the macro section. */
30315 switch_to_section (debug_macinfo_section
);
30316 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
30317 output_macinfo (!dwarf_split_debug_info
? debug_line_section_label
30318 : debug_skeleton_line_section_label
, false);
30319 dw2_asm_output_data (1, 0, "End compilation unit");
30322 /* Output the source line correspondence table. We must do this
30323 even if there is no line information. Otherwise, on an empty
30324 translation unit, we will generate a present, but empty,
30325 .debug_info section. IRIX 6.5 `nm' will then complain when
30326 examining the file. This is done late so that any filenames
30327 used by the debug_info section are marked as 'used'. */
30328 switch_to_section (debug_line_section
);
30329 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
30330 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
30331 output_line_info (false);
30333 if (dwarf_split_debug_info
&& info_section_emitted
)
30335 switch_to_section (debug_skeleton_line_section
);
30336 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
30337 output_line_info (true);
30340 /* If we emitted any indirect strings, output the string table too. */
30341 if (debug_str_hash
|| skeleton_debug_str_hash
)
30342 output_indirect_strings ();
30343 if (debug_line_str_hash
)
30345 switch_to_section (debug_line_str_section
);
30346 const enum dwarf_form form
= DW_FORM_line_strp
;
30347 debug_line_str_hash
->traverse
<enum dwarf_form
,
30348 output_indirect_string
> (form
);
30352 /* Returns a hash value for X (which really is a variable_value_struct). */
30355 variable_value_hasher::hash (variable_value_struct
*x
)
30357 return (hashval_t
) x
->decl_id
;
30360 /* Return nonzero if decl_id of variable_value_struct X is the same as
30364 variable_value_hasher::equal (variable_value_struct
*x
, tree y
)
30366 return x
->decl_id
== DECL_UID (y
);
30369 /* Helper function for resolve_variable_value, handle
30370 DW_OP_GNU_variable_value in one location expression.
30371 Return true if exprloc has been changed into loclist. */
30374 resolve_variable_value_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
30376 dw_loc_descr_ref next
;
30377 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= next
)
30379 next
= loc
->dw_loc_next
;
30380 if (loc
->dw_loc_opc
!= DW_OP_GNU_variable_value
30381 || loc
->dw_loc_oprnd1
.val_class
!= dw_val_class_decl_ref
)
30384 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
30385 if (DECL_CONTEXT (decl
) != current_function_decl
)
30388 dw_die_ref ref
= lookup_decl_die (decl
);
30391 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30392 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30393 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30396 dw_loc_list_ref l
= loc_list_from_tree (decl
, 0, NULL
);
30399 if (l
->dw_loc_next
)
30401 if (AT_class (a
) != dw_val_class_loc
)
30403 switch (a
->dw_attr
)
30405 /* Following attributes allow both exprloc and loclist
30406 classes, so we can change them into a loclist. */
30407 case DW_AT_location
:
30408 case DW_AT_string_length
:
30409 case DW_AT_return_addr
:
30410 case DW_AT_data_member_location
:
30411 case DW_AT_frame_base
:
30412 case DW_AT_segment
:
30413 case DW_AT_static_link
:
30414 case DW_AT_use_location
:
30415 case DW_AT_vtable_elem_location
:
30418 prev
->dw_loc_next
= NULL
;
30419 prepend_loc_descr_to_each (l
, AT_loc (a
));
30422 add_loc_descr_to_each (l
, next
);
30423 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
30424 a
->dw_attr_val
.val_entry
= NULL
;
30425 a
->dw_attr_val
.v
.val_loc_list
= l
;
30426 have_location_lists
= true;
30428 /* Following attributes allow both exprloc and reference,
30429 so if the whole expression is DW_OP_GNU_variable_value alone
30430 we could transform it into reference. */
30431 case DW_AT_byte_size
:
30432 case DW_AT_bit_size
:
30433 case DW_AT_lower_bound
:
30434 case DW_AT_upper_bound
:
30435 case DW_AT_bit_stride
:
30437 case DW_AT_allocated
:
30438 case DW_AT_associated
:
30439 case DW_AT_byte_stride
:
30440 if (prev
== NULL
&& next
== NULL
)
30448 /* Create DW_TAG_variable that we can refer to. */
30449 gen_decl_die (decl
, NULL_TREE
, NULL
,
30450 lookup_decl_die (current_function_decl
));
30451 ref
= lookup_decl_die (decl
);
30454 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30455 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30456 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30462 prev
->dw_loc_next
= l
->expr
;
30463 add_loc_descr (&prev
->dw_loc_next
, next
);
30464 free_loc_descr (loc
, NULL
);
30465 next
= prev
->dw_loc_next
;
30469 memcpy (loc
, l
->expr
, sizeof (dw_loc_descr_node
));
30470 add_loc_descr (&loc
, next
);
30478 /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree. */
30481 resolve_variable_value (dw_die_ref die
)
30484 dw_loc_list_ref loc
;
30487 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30488 switch (AT_class (a
))
30490 case dw_val_class_loc
:
30491 if (!resolve_variable_value_in_expr (a
, AT_loc (a
)))
30494 case dw_val_class_loc_list
:
30495 loc
= AT_loc_list (a
);
30497 for (; loc
; loc
= loc
->dw_loc_next
)
30498 resolve_variable_value_in_expr (a
, loc
->expr
);
30505 /* Attempt to optimize DW_OP_GNU_variable_value refering to
30506 temporaries in the current function. */
30509 resolve_variable_values (void)
30511 if (!variable_value_hash
|| !current_function_decl
)
30514 struct variable_value_struct
*node
30515 = variable_value_hash
->find_with_hash (current_function_decl
,
30516 DECL_UID (current_function_decl
));
30523 FOR_EACH_VEC_SAFE_ELT (node
->dies
, i
, die
)
30524 resolve_variable_value (die
);
30527 /* Helper function for note_variable_value, handle one location
30531 note_variable_value_in_expr (dw_die_ref die
, dw_loc_descr_ref loc
)
30533 for (; loc
; loc
= loc
->dw_loc_next
)
30534 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
30535 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
30537 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
30538 dw_die_ref ref
= lookup_decl_die (decl
);
30539 if (! ref
&& (flag_generate_lto
|| flag_generate_offload
))
30541 /* ??? This is somewhat a hack because we do not create DIEs
30542 for variables not in BLOCK trees early but when generating
30543 early LTO output we need the dw_val_class_decl_ref to be
30544 fully resolved. For fat LTO objects we'd also like to
30545 undo this after LTO dwarf output. */
30546 gcc_assert (DECL_CONTEXT (decl
));
30547 dw_die_ref ctx
= lookup_decl_die (DECL_CONTEXT (decl
));
30548 gcc_assert (ctx
!= NULL
);
30549 gen_decl_die (decl
, NULL_TREE
, NULL
, ctx
);
30550 ref
= lookup_decl_die (decl
);
30551 gcc_assert (ref
!= NULL
);
30555 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30556 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30557 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30561 && DECL_CONTEXT (decl
)
30562 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
30563 && lookup_decl_die (DECL_CONTEXT (decl
)))
30565 if (!variable_value_hash
)
30566 variable_value_hash
30567 = hash_table
<variable_value_hasher
>::create_ggc (10);
30569 tree fndecl
= DECL_CONTEXT (decl
);
30570 struct variable_value_struct
*node
;
30571 struct variable_value_struct
**slot
30572 = variable_value_hash
->find_slot_with_hash (fndecl
,
30577 node
= ggc_cleared_alloc
<variable_value_struct
> ();
30578 node
->decl_id
= DECL_UID (fndecl
);
30584 vec_safe_push (node
->dies
, die
);
30589 /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
30590 with dw_val_class_decl_ref operand. */
30593 note_variable_value (dw_die_ref die
)
30597 dw_loc_list_ref loc
;
30600 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30601 switch (AT_class (a
))
30603 case dw_val_class_loc_list
:
30604 loc
= AT_loc_list (a
);
30606 if (!loc
->noted_variable_value
)
30608 loc
->noted_variable_value
= 1;
30609 for (; loc
; loc
= loc
->dw_loc_next
)
30610 note_variable_value_in_expr (die
, loc
->expr
);
30613 case dw_val_class_loc
:
30614 note_variable_value_in_expr (die
, AT_loc (a
));
30620 /* Mark children. */
30621 FOR_EACH_CHILD (die
, c
, note_variable_value (c
));
30624 /* Perform any cleanups needed after the early debug generation pass
30628 dwarf2out_early_finish (const char *filename
)
30632 /* PCH might result in DW_AT_producer string being restored from the
30633 header compilation, so always fill it with empty string initially
30634 and overwrite only here. */
30635 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
30636 producer_string
= gen_producer_string ();
30637 producer
->dw_attr_val
.v
.val_str
->refcount
--;
30638 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
30640 /* Add the name for the main input file now. We delayed this from
30641 dwarf2out_init to avoid complications with PCH. */
30642 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
30643 add_comp_dir_attribute (comp_unit_die ());
30645 /* When emitting DWARF5 .debug_line_str, move DW_AT_name and
30646 DW_AT_comp_dir into .debug_line_str section. */
30647 if (!DWARF2_ASM_LINE_DEBUG_INFO
30648 && dwarf_version
>= 5
30649 && DWARF5_USE_DEBUG_LINE_STR
)
30651 for (int i
= 0; i
< 2; i
++)
30653 dw_attr_node
*a
= get_AT (comp_unit_die (),
30654 i
? DW_AT_comp_dir
: DW_AT_name
);
30656 || AT_class (a
) != dw_val_class_str
30657 || strlen (AT_string (a
)) + 1 <= DWARF_OFFSET_SIZE
)
30660 if (! debug_line_str_hash
)
30661 debug_line_str_hash
30662 = hash_table
<indirect_string_hasher
>::create_ggc (10);
30664 struct indirect_string_node
*node
30665 = find_AT_string_in_table (AT_string (a
), debug_line_str_hash
);
30666 set_indirect_string (node
);
30667 node
->form
= DW_FORM_line_strp
;
30668 a
->dw_attr_val
.v
.val_str
->refcount
--;
30669 a
->dw_attr_val
.v
.val_str
= node
;
30673 /* With LTO early dwarf was really finished at compile-time, so make
30674 sure to adjust the phase after annotating the LTRANS CU DIE. */
30677 early_dwarf_finished
= true;
30681 /* Walk through the list of incomplete types again, trying once more to
30682 emit full debugging info for them. */
30683 retry_incomplete_types ();
30685 /* The point here is to flush out the limbo list so that it is empty
30686 and we don't need to stream it for LTO. */
30687 flush_limbo_die_list ();
30689 gen_scheduled_generic_parms_dies ();
30690 gen_remaining_tmpl_value_param_die_attribute ();
30692 /* Add DW_AT_linkage_name for all deferred DIEs. */
30693 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
30695 tree decl
= node
->created_for
;
30696 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
30697 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
30698 ended up in deferred_asm_name before we knew it was
30699 constant and never written to disk. */
30700 && DECL_ASSEMBLER_NAME (decl
))
30702 add_linkage_attr (node
->die
, decl
);
30703 move_linkage_attr (node
->die
);
30706 deferred_asm_name
= NULL
;
30708 if (flag_eliminate_unused_debug_types
)
30709 prune_unused_types ();
30711 /* Generate separate COMDAT sections for type DIEs. */
30712 if (use_debug_types
)
30714 break_out_comdat_types (comp_unit_die ());
30716 /* Each new type_unit DIE was added to the limbo die list when created.
30717 Since these have all been added to comdat_type_list, clear the
30719 limbo_die_list
= NULL
;
30721 /* For each new comdat type unit, copy declarations for incomplete
30722 types to make the new unit self-contained (i.e., no direct
30723 references to the main compile unit). */
30724 for (comdat_type_node
*ctnode
= comdat_type_list
;
30725 ctnode
!= NULL
; ctnode
= ctnode
->next
)
30726 copy_decls_for_unworthy_types (ctnode
->root_die
);
30727 copy_decls_for_unworthy_types (comp_unit_die ());
30729 /* In the process of copying declarations from one unit to another,
30730 we may have left some declarations behind that are no longer
30731 referenced. Prune them. */
30732 prune_unused_types ();
30735 /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
30736 with dw_val_class_decl_ref operand. */
30737 note_variable_value (comp_unit_die ());
30738 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
30739 note_variable_value (node
->die
);
30740 for (comdat_type_node
*ctnode
= comdat_type_list
; ctnode
!= NULL
;
30741 ctnode
= ctnode
->next
)
30742 note_variable_value (ctnode
->root_die
);
30743 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
30744 note_variable_value (node
->die
);
30746 /* The AT_pubnames attribute needs to go in all skeleton dies, including
30747 both the main_cu and all skeleton TUs. Making this call unconditional
30748 would end up either adding a second copy of the AT_pubnames attribute, or
30749 requiring a special case in add_top_level_skeleton_die_attrs. */
30750 if (!dwarf_split_debug_info
)
30751 add_AT_pubnames (comp_unit_die ());
30753 /* The early debug phase is now finished. */
30754 early_dwarf_finished
= true;
30756 /* Do not generate DWARF assembler now when not producing LTO bytecode. */
30757 if (!flag_generate_lto
&& !flag_generate_offload
)
30760 /* Now as we are going to output for LTO initialize sections and labels
30761 to the LTO variants. We don't need a random-seed postfix as other
30762 LTO sections as linking the LTO debug sections into one in a partial
30764 init_sections_and_labels (true);
30766 /* The output below is modeled after dwarf2out_finish with all
30767 location related output removed and some LTO specific changes.
30768 Some refactoring might make both smaller and easier to match up. */
30770 /* Traverse the DIE's and add add sibling attributes to those DIE's
30771 that have children. */
30772 add_sibling_attributes (comp_unit_die ());
30773 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
30774 add_sibling_attributes (node
->die
);
30775 for (comdat_type_node
*ctnode
= comdat_type_list
;
30776 ctnode
!= NULL
; ctnode
= ctnode
->next
)
30777 add_sibling_attributes (ctnode
->root_die
);
30780 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
30781 macinfo_section_label
);
30783 save_macinfo_strings ();
30785 /* Output all of the compilation units. We put the main one last so that
30786 the offsets are available to output_pubnames. */
30787 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
30788 output_comp_unit (node
->die
, 0, NULL
);
30790 hash_table
<comdat_type_hasher
> comdat_type_table (100);
30791 for (comdat_type_node
*ctnode
= comdat_type_list
;
30792 ctnode
!= NULL
; ctnode
= ctnode
->next
)
30794 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
30796 /* Don't output duplicate types. */
30797 if (*slot
!= HTAB_EMPTY_ENTRY
)
30800 /* Add a pointer to the line table for the main compilation unit
30801 so that the debugger can make sense of DW_AT_decl_file
30803 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
30804 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
30805 (!dwarf_split_debug_info
30806 ? debug_line_section_label
30807 : debug_skeleton_line_section_label
));
30809 output_comdat_type_unit (ctnode
);
30813 /* Stick a unique symbol to the main debuginfo section. */
30814 compute_comp_unit_symbol (comp_unit_die ());
30816 /* Output the main compilation unit. We always need it if only for
30818 output_comp_unit (comp_unit_die (), true, NULL
);
30820 /* Output the abbreviation table. */
30821 if (vec_safe_length (abbrev_die_table
) != 1)
30823 switch_to_section (debug_abbrev_section
);
30824 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
30825 output_abbrev_section ();
30828 /* Have to end the macro section. */
30831 /* We have to save macinfo state if we need to output it again
30832 for the FAT part of the object. */
30833 vec
<macinfo_entry
, va_gc
> *saved_macinfo_table
= macinfo_table
;
30834 if (flag_fat_lto_objects
)
30835 macinfo_table
= macinfo_table
->copy ();
30837 switch_to_section (debug_macinfo_section
);
30838 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
30839 output_macinfo (debug_skeleton_line_section_label
, true);
30840 dw2_asm_output_data (1, 0, "End compilation unit");
30842 /* Emit a skeleton debug_line section. */
30843 switch_to_section (debug_skeleton_line_section
);
30844 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
30845 output_line_info (true);
30847 if (flag_fat_lto_objects
)
30849 vec_free (macinfo_table
);
30850 macinfo_table
= saved_macinfo_table
;
30855 /* If we emitted any indirect strings, output the string table too. */
30856 if (debug_str_hash
|| skeleton_debug_str_hash
)
30857 output_indirect_strings ();
30859 /* Switch back to the text section. */
30860 switch_to_section (text_section
);
30863 /* Reset all state within dwarf2out.c so that we can rerun the compiler
30864 within the same process. For use by toplev::finalize. */
30867 dwarf2out_c_finalize (void)
30869 last_var_location_insn
= NULL
;
30870 cached_next_real_insn
= NULL
;
30871 used_rtx_array
= NULL
;
30872 incomplete_types
= NULL
;
30873 decl_scope_table
= NULL
;
30874 debug_info_section
= NULL
;
30875 debug_skeleton_info_section
= NULL
;
30876 debug_abbrev_section
= NULL
;
30877 debug_skeleton_abbrev_section
= NULL
;
30878 debug_aranges_section
= NULL
;
30879 debug_addr_section
= NULL
;
30880 debug_macinfo_section
= NULL
;
30881 debug_line_section
= NULL
;
30882 debug_skeleton_line_section
= NULL
;
30883 debug_loc_section
= NULL
;
30884 debug_pubnames_section
= NULL
;
30885 debug_pubtypes_section
= NULL
;
30886 debug_str_section
= NULL
;
30887 debug_line_str_section
= NULL
;
30888 debug_str_dwo_section
= NULL
;
30889 debug_str_offsets_section
= NULL
;
30890 debug_ranges_section
= NULL
;
30891 debug_frame_section
= NULL
;
30893 debug_str_hash
= NULL
;
30894 debug_line_str_hash
= NULL
;
30895 skeleton_debug_str_hash
= NULL
;
30896 dw2_string_counter
= 0;
30897 have_multiple_function_sections
= false;
30898 text_section_used
= false;
30899 cold_text_section_used
= false;
30900 cold_text_section
= NULL
;
30901 current_unit_personality
= NULL
;
30903 early_dwarf
= false;
30904 early_dwarf_finished
= false;
30906 next_die_offset
= 0;
30907 single_comp_unit_die
= NULL
;
30908 comdat_type_list
= NULL
;
30909 limbo_die_list
= NULL
;
30911 decl_die_table
= NULL
;
30912 common_block_die_table
= NULL
;
30913 decl_loc_table
= NULL
;
30914 call_arg_locations
= NULL
;
30915 call_arg_loc_last
= NULL
;
30916 call_site_count
= -1;
30917 tail_call_site_count
= -1;
30918 cached_dw_loc_list_table
= NULL
;
30919 abbrev_die_table
= NULL
;
30920 delete dwarf_proc_stack_usage_map
;
30921 dwarf_proc_stack_usage_map
= NULL
;
30922 line_info_label_num
= 0;
30923 cur_line_info_table
= NULL
;
30924 text_section_line_info
= NULL
;
30925 cold_text_section_line_info
= NULL
;
30926 separate_line_info
= NULL
;
30927 info_section_emitted
= false;
30928 pubname_table
= NULL
;
30929 pubtype_table
= NULL
;
30930 macinfo_table
= NULL
;
30931 ranges_table
= NULL
;
30932 ranges_by_label
= NULL
;
30934 have_location_lists
= false;
30937 last_emitted_file
= NULL
;
30939 tmpl_value_parm_die_table
= NULL
;
30940 generic_type_instances
= NULL
;
30941 frame_pointer_fb_offset
= 0;
30942 frame_pointer_fb_offset_valid
= false;
30943 base_types
.release ();
30944 XDELETEVEC (producer_string
);
30945 producer_string
= NULL
;
30948 #include "gt-dwarf2out.h"