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"
87 #include "common/common-target.h"
88 #include "langhooks.h"
93 #include "gdb/gdb-index.h"
96 static void dwarf2out_source_line (unsigned int, unsigned int, const char *,
98 static rtx_insn
*last_var_location_insn
;
99 static rtx_insn
*cached_next_real_insn
;
100 static void dwarf2out_decl (tree
);
102 #ifndef XCOFF_DEBUGGING_INFO
103 #define XCOFF_DEBUGGING_INFO 0
106 #ifndef HAVE_XCOFF_DWARF_EXTRAS
107 #define HAVE_XCOFF_DWARF_EXTRAS 0
110 #ifdef VMS_DEBUGGING_INFO
111 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
113 /* Define this macro to be a nonzero value if the directory specifications
114 which are output in the debug info should end with a separator. */
115 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
116 /* Define this macro to evaluate to a nonzero value if GCC should refrain
117 from generating indirect strings in DWARF2 debug information, for instance
118 if your target is stuck with an old version of GDB that is unable to
119 process them properly or uses VMS Debug. */
120 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
122 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
123 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
126 /* ??? Poison these here until it can be done generically. They've been
127 totally replaced in this file; make sure it stays that way. */
128 #undef DWARF2_UNWIND_INFO
129 #undef DWARF2_FRAME_INFO
130 #if (GCC_VERSION >= 3000)
131 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
134 /* The size of the target's pointer type. */
136 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
139 /* Array of RTXes referenced by the debugging information, which therefore
140 must be kept around forever. */
141 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
143 /* A pointer to the base of a list of incomplete types which might be
144 completed at some later time. incomplete_types_list needs to be a
145 vec<tree, va_gc> *because we want to tell the garbage collector about
147 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
149 /* A pointer to the base of a table of references to declaration
150 scopes. This table is a display which tracks the nesting
151 of declaration scopes at the current scope and containing
152 scopes. This table is used to find the proper place to
153 define type declaration DIE's. */
154 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
156 /* Pointers to various DWARF2 sections. */
157 static GTY(()) section
*debug_info_section
;
158 static GTY(()) section
*debug_skeleton_info_section
;
159 static GTY(()) section
*debug_abbrev_section
;
160 static GTY(()) section
*debug_skeleton_abbrev_section
;
161 static GTY(()) section
*debug_aranges_section
;
162 static GTY(()) section
*debug_addr_section
;
163 static GTY(()) section
*debug_macinfo_section
;
164 static const char *debug_macinfo_section_name
;
165 static GTY(()) section
*debug_line_section
;
166 static GTY(()) section
*debug_skeleton_line_section
;
167 static GTY(()) section
*debug_loc_section
;
168 static GTY(()) section
*debug_pubnames_section
;
169 static GTY(()) section
*debug_pubtypes_section
;
170 static GTY(()) section
*debug_str_section
;
171 static GTY(()) section
*debug_line_str_section
;
172 static GTY(()) section
*debug_str_dwo_section
;
173 static GTY(()) section
*debug_str_offsets_section
;
174 static GTY(()) section
*debug_ranges_section
;
175 static GTY(()) section
*debug_frame_section
;
177 /* Maximum size (in bytes) of an artificially generated label. */
178 #define MAX_ARTIFICIAL_LABEL_BYTES 30
180 /* According to the (draft) DWARF 3 specification, the initial length
181 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
182 bytes are 0xffffffff, followed by the length stored in the next 8
185 However, the SGI/MIPS ABI uses an initial length which is equal to
186 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
188 #ifndef DWARF_INITIAL_LENGTH_SIZE
189 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
192 #ifndef DWARF_INITIAL_LENGTH_SIZE_STR
193 #define DWARF_INITIAL_LENGTH_SIZE_STR (DWARF_OFFSET_SIZE == 4 ? "-4" : "-12")
196 /* Round SIZE up to the nearest BOUNDARY. */
197 #define DWARF_ROUND(SIZE,BOUNDARY) \
198 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
200 /* CIE identifier. */
201 #if HOST_BITS_PER_WIDE_INT >= 64
202 #define DWARF_CIE_ID \
203 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
205 #define DWARF_CIE_ID DW_CIE_ID
209 /* A vector for a table that contains frame description
210 information for each routine. */
211 #define NOT_INDEXED (-1U)
212 #define NO_INDEX_ASSIGNED (-2U)
214 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
216 struct GTY((for_user
)) indirect_string_node
{
218 unsigned int refcount
;
219 enum dwarf_form form
;
224 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
226 typedef const char *compare_type
;
228 static hashval_t
hash (indirect_string_node
*);
229 static bool equal (indirect_string_node
*, const char *);
232 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
234 static GTY (()) hash_table
<indirect_string_hasher
> *debug_line_str_hash
;
236 /* With split_debug_info, both the comp_dir and dwo_name go in the
237 main object file, rather than the dwo, similar to the force_direct
238 parameter elsewhere but with additional complications:
240 1) The string is needed in both the main object file and the dwo.
241 That is, the comp_dir and dwo_name will appear in both places.
243 2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
244 DW_FORM_line_strp or DW_FORM_GNU_str_index.
246 3) GCC chooses the form to use late, depending on the size and
249 Rather than forcing the all debug string handling functions and
250 callers to deal with these complications, simply use a separate,
251 special-cased string table for any attribute that should go in the
252 main object file. This limits the complexity to just the places
255 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
257 static GTY(()) int dw2_string_counter
;
259 /* True if the compilation unit places functions in more than one section. */
260 static GTY(()) bool have_multiple_function_sections
= false;
262 /* Whether the default text and cold text sections have been used at all. */
264 static GTY(()) bool text_section_used
= false;
265 static GTY(()) bool cold_text_section_used
= false;
267 /* The default cold text section. */
268 static GTY(()) section
*cold_text_section
;
270 /* The DIE for C++14 'auto' in a function return type. */
271 static GTY(()) dw_die_ref auto_die
;
273 /* The DIE for C++14 'decltype(auto)' in a function return type. */
274 static GTY(()) dw_die_ref decltype_auto_die
;
276 /* Forward declarations for functions defined in this file. */
278 static void output_call_frame_info (int);
279 static void dwarf2out_note_section_used (void);
281 /* Personality decl of current unit. Used only when assembler does not support
283 static GTY(()) rtx current_unit_personality
;
285 /* .debug_rnglists next index. */
286 static unsigned int rnglist_idx
;
288 /* Data and reference forms for relocatable data. */
289 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
290 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
292 #ifndef DEBUG_FRAME_SECTION
293 #define DEBUG_FRAME_SECTION ".debug_frame"
296 #ifndef FUNC_BEGIN_LABEL
297 #define FUNC_BEGIN_LABEL "LFB"
300 #ifndef FUNC_END_LABEL
301 #define FUNC_END_LABEL "LFE"
304 #ifndef PROLOGUE_END_LABEL
305 #define PROLOGUE_END_LABEL "LPE"
308 #ifndef EPILOGUE_BEGIN_LABEL
309 #define EPILOGUE_BEGIN_LABEL "LEB"
312 #ifndef FRAME_BEGIN_LABEL
313 #define FRAME_BEGIN_LABEL "Lframe"
315 #define CIE_AFTER_SIZE_LABEL "LSCIE"
316 #define CIE_END_LABEL "LECIE"
317 #define FDE_LABEL "LSFDE"
318 #define FDE_AFTER_SIZE_LABEL "LASFDE"
319 #define FDE_END_LABEL "LEFDE"
320 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
321 #define LINE_NUMBER_END_LABEL "LELT"
322 #define LN_PROLOG_AS_LABEL "LASLTP"
323 #define LN_PROLOG_END_LABEL "LELTP"
324 #define DIE_LABEL_PREFIX "DW"
326 /* Match the base name of a file to the base name of a compilation unit. */
329 matches_main_base (const char *path
)
331 /* Cache the last query. */
332 static const char *last_path
= NULL
;
333 static int last_match
= 0;
334 if (path
!= last_path
)
337 int length
= base_of_path (path
, &base
);
339 last_match
= (length
== main_input_baselength
340 && memcmp (base
, main_input_basename
, length
) == 0);
345 #ifdef DEBUG_DEBUG_STRUCT
348 dump_struct_debug (tree type
, enum debug_info_usage usage
,
349 enum debug_struct_file criterion
, int generic
,
350 int matches
, int result
)
352 /* Find the type name. */
353 tree type_decl
= TYPE_STUB_DECL (type
);
355 const char *name
= 0;
356 if (TREE_CODE (t
) == TYPE_DECL
)
359 name
= IDENTIFIER_POINTER (t
);
361 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
363 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
364 matches
? "bas" : "hdr",
365 generic
? "gen" : "ord",
366 usage
== DINFO_USAGE_DFN
? ";" :
367 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
369 (void*) type_decl
, name
);
372 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
373 dump_struct_debug (type, usage, criterion, generic, matches, result)
377 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
382 /* Get the number of HOST_WIDE_INTs needed to represent the precision
383 of the number. Some constants have a large uniform precision, so
384 we get the precision needed for the actual value of the number. */
387 get_full_len (const wide_int
&op
)
389 int prec
= wi::min_precision (op
, UNSIGNED
);
390 return ((prec
+ HOST_BITS_PER_WIDE_INT
- 1)
391 / HOST_BITS_PER_WIDE_INT
);
395 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
397 enum debug_struct_file criterion
;
399 bool generic
= lang_hooks
.types
.generic_p (type
);
402 criterion
= debug_struct_generic
[usage
];
404 criterion
= debug_struct_ordinary
[usage
];
406 if (criterion
== DINFO_STRUCT_FILE_NONE
)
407 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
408 if (criterion
== DINFO_STRUCT_FILE_ANY
)
409 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
411 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
413 if (type_decl
!= NULL
)
415 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
416 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
418 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
419 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
422 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
425 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
426 switch to the data section instead, and write out a synthetic start label
427 for collect2 the first time around. */
430 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
432 if (eh_frame_section
== 0)
436 if (EH_TABLES_CAN_BE_READ_ONLY
)
442 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
444 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
446 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
449 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
450 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
451 && (per_encoding
& 0x70) != DW_EH_PE_absptr
452 && (per_encoding
& 0x70) != DW_EH_PE_aligned
453 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
454 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
455 ? 0 : SECTION_WRITE
);
458 flags
= SECTION_WRITE
;
460 #ifdef EH_FRAME_SECTION_NAME
461 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
463 eh_frame_section
= ((flags
== SECTION_WRITE
)
464 ? data_section
: readonly_data_section
);
465 #endif /* EH_FRAME_SECTION_NAME */
468 switch_to_section (eh_frame_section
);
470 #ifdef EH_FRAME_THROUGH_COLLECT2
471 /* We have no special eh_frame section. Emit special labels to guide
475 tree label
= get_file_function_name ("F");
476 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
477 targetm
.asm_out
.globalize_label (asm_out_file
,
478 IDENTIFIER_POINTER (label
));
479 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
484 /* Switch [BACK] to the eh or debug frame table section, depending on
488 switch_to_frame_table_section (int for_eh
, bool back
)
491 switch_to_eh_frame_section (back
);
494 if (!debug_frame_section
)
495 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
496 SECTION_DEBUG
, NULL
);
497 switch_to_section (debug_frame_section
);
501 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
503 enum dw_cfi_oprnd_type
504 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
509 case DW_CFA_GNU_window_save
:
510 case DW_CFA_remember_state
:
511 case DW_CFA_restore_state
:
512 return dw_cfi_oprnd_unused
;
515 case DW_CFA_advance_loc1
:
516 case DW_CFA_advance_loc2
:
517 case DW_CFA_advance_loc4
:
518 case DW_CFA_MIPS_advance_loc8
:
519 return dw_cfi_oprnd_addr
;
522 case DW_CFA_offset_extended
:
524 case DW_CFA_offset_extended_sf
:
525 case DW_CFA_def_cfa_sf
:
527 case DW_CFA_restore_extended
:
528 case DW_CFA_undefined
:
529 case DW_CFA_same_value
:
530 case DW_CFA_def_cfa_register
:
531 case DW_CFA_register
:
532 case DW_CFA_expression
:
533 case DW_CFA_val_expression
:
534 return dw_cfi_oprnd_reg_num
;
536 case DW_CFA_def_cfa_offset
:
537 case DW_CFA_GNU_args_size
:
538 case DW_CFA_def_cfa_offset_sf
:
539 return dw_cfi_oprnd_offset
;
541 case DW_CFA_def_cfa_expression
:
542 return dw_cfi_oprnd_loc
;
549 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
551 enum dw_cfi_oprnd_type
552 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
557 case DW_CFA_def_cfa_sf
:
559 case DW_CFA_offset_extended_sf
:
560 case DW_CFA_offset_extended
:
561 return dw_cfi_oprnd_offset
;
563 case DW_CFA_register
:
564 return dw_cfi_oprnd_reg_num
;
566 case DW_CFA_expression
:
567 case DW_CFA_val_expression
:
568 return dw_cfi_oprnd_loc
;
571 return dw_cfi_oprnd_unused
;
575 /* Output one FDE. */
578 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
579 char *section_start_label
, int fde_encoding
, char *augmentation
,
580 bool any_lsda_needed
, int lsda_encoding
)
582 const char *begin
, *end
;
583 static unsigned int j
;
584 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
586 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
588 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
590 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
591 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
592 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
594 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
595 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
596 " indicating 64-bit DWARF extension");
597 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
600 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
603 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
605 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
606 debug_frame_section
, "FDE CIE offset");
608 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
609 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
613 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
614 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
615 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
616 "FDE initial location");
617 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
618 end
, begin
, "FDE address range");
622 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
623 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
630 int size
= size_of_encoded_value (lsda_encoding
);
632 if (lsda_encoding
== DW_EH_PE_aligned
)
634 int offset
= ( 4 /* Length */
636 + 2 * size_of_encoded_value (fde_encoding
)
637 + 1 /* Augmentation size */ );
638 int pad
= -offset
& (PTR_SIZE
- 1);
641 gcc_assert (size_of_uleb128 (size
) == 1);
644 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
646 if (fde
->uses_eh_lsda
)
648 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
649 fde
->funcdef_number
);
650 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
651 gen_rtx_SYMBOL_REF (Pmode
, l1
),
653 "Language Specific Data Area");
657 if (lsda_encoding
== DW_EH_PE_aligned
)
658 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
659 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
660 "Language Specific Data Area (none)");
664 dw2_asm_output_data_uleb128 (0, "Augmentation size");
667 /* Loop through the Call Frame Instructions associated with this FDE. */
668 fde
->dw_fde_current_label
= begin
;
670 size_t from
, until
, i
;
673 until
= vec_safe_length (fde
->dw_fde_cfi
);
675 if (fde
->dw_fde_second_begin
== NULL
)
678 until
= fde
->dw_fde_switch_cfi_index
;
680 from
= fde
->dw_fde_switch_cfi_index
;
682 for (i
= from
; i
< until
; i
++)
683 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
686 /* If we are to emit a ref/link from function bodies to their frame tables,
687 do it now. This is typically performed to make sure that tables
688 associated with functions are dragged with them and not discarded in
689 garbage collecting links. We need to do this on a per function basis to
690 cope with -ffunction-sections. */
692 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
693 /* Switch to the function section, emit the ref to the tables, and
694 switch *back* into the table section. */
695 switch_to_section (function_section (fde
->decl
));
696 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
697 switch_to_frame_table_section (for_eh
, true);
700 /* Pad the FDE out to an address sized boundary. */
701 ASM_OUTPUT_ALIGN (asm_out_file
,
702 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
703 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
708 /* Return true if frame description entry FDE is needed for EH. */
711 fde_needed_for_eh_p (dw_fde_ref fde
)
713 if (flag_asynchronous_unwind_tables
)
716 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
719 if (fde
->uses_eh_lsda
)
722 /* If exceptions are enabled, we have collected nothrow info. */
723 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
729 /* Output the call frame information used to record information
730 that relates to calculating the frame pointer, and records the
731 location of saved registers. */
734 output_call_frame_info (int for_eh
)
739 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
740 char section_start_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
741 bool any_lsda_needed
= false;
742 char augmentation
[6];
743 int augmentation_size
;
744 int fde_encoding
= DW_EH_PE_absptr
;
745 int per_encoding
= DW_EH_PE_absptr
;
746 int lsda_encoding
= DW_EH_PE_absptr
;
748 rtx personality
= NULL
;
751 /* Don't emit a CIE if there won't be any FDEs. */
755 /* Nothing to do if the assembler's doing it all. */
756 if (dwarf2out_do_cfi_asm ())
759 /* If we don't have any functions we'll want to unwind out of, don't emit
760 any EH unwind information. If we make FDEs linkonce, we may have to
761 emit an empty label for an FDE that wouldn't otherwise be emitted. We
762 want to avoid having an FDE kept around when the function it refers to
763 is discarded. Example where this matters: a primary function template
764 in C++ requires EH information, an explicit specialization doesn't. */
767 bool any_eh_needed
= false;
769 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
771 if (fde
->uses_eh_lsda
)
772 any_eh_needed
= any_lsda_needed
= true;
773 else if (fde_needed_for_eh_p (fde
))
774 any_eh_needed
= true;
775 else if (TARGET_USES_WEAK_UNWIND_INFO
)
776 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
783 /* We're going to be generating comments, so turn on app. */
787 /* Switch to the proper frame section, first time. */
788 switch_to_frame_table_section (for_eh
, false);
790 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
791 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
793 /* Output the CIE. */
794 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
795 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
796 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
798 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
799 dw2_asm_output_data (4, 0xffffffff,
800 "Initial length escape value indicating 64-bit DWARF extension");
801 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
802 "Length of Common Information Entry");
804 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
806 /* Now that the CIE pointer is PC-relative for EH,
807 use 0 to identify the CIE. */
808 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
809 (for_eh
? 0 : DWARF_CIE_ID
),
810 "CIE Identifier Tag");
812 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
813 use CIE version 1, unless that would produce incorrect results
814 due to overflowing the return register column. */
815 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
817 if (return_reg
>= 256 || dwarf_version
> 2)
819 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
822 augmentation_size
= 0;
824 personality
= current_unit_personality
;
830 z Indicates that a uleb128 is present to size the
831 augmentation section.
832 L Indicates the encoding (and thus presence) of
833 an LSDA pointer in the FDE augmentation.
834 R Indicates a non-default pointer encoding for
836 P Indicates the presence of an encoding + language
837 personality routine in the CIE augmentation. */
839 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
840 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
841 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
843 p
= augmentation
+ 1;
847 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
848 assemble_external_libcall (personality
);
853 augmentation_size
+= 1;
855 if (fde_encoding
!= DW_EH_PE_absptr
)
858 augmentation_size
+= 1;
860 if (p
> augmentation
+ 1)
862 augmentation
[0] = 'z';
866 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
867 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
869 int offset
= ( 4 /* Length */
871 + 1 /* CIE version */
872 + strlen (augmentation
) + 1 /* Augmentation */
873 + size_of_uleb128 (1) /* Code alignment */
874 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
876 + 1 /* Augmentation size */
877 + 1 /* Personality encoding */ );
878 int pad
= -offset
& (PTR_SIZE
- 1);
880 augmentation_size
+= pad
;
882 /* Augmentations should be small, so there's scarce need to
883 iterate for a solution. Die if we exceed one uleb128 byte. */
884 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
888 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
889 if (dw_cie_version
>= 4)
891 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
892 dw2_asm_output_data (1, 0, "CIE Segment Size");
894 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
895 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
896 "CIE Data Alignment Factor");
898 if (dw_cie_version
== 1)
899 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
901 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
905 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
908 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
909 eh_data_format_name (per_encoding
));
910 dw2_asm_output_encoded_addr_rtx (per_encoding
,
916 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
917 eh_data_format_name (lsda_encoding
));
919 if (fde_encoding
!= DW_EH_PE_absptr
)
920 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
921 eh_data_format_name (fde_encoding
));
924 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
925 output_cfi (cfi
, NULL
, for_eh
);
927 /* Pad the CIE out to an address sized boundary. */
928 ASM_OUTPUT_ALIGN (asm_out_file
,
929 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
930 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
932 /* Loop through all of the FDE's. */
933 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
937 /* Don't emit EH unwind info for leaf functions that don't need it. */
938 if (for_eh
&& !fde_needed_for_eh_p (fde
))
941 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
942 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
943 augmentation
, any_lsda_needed
, lsda_encoding
);
946 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
947 dw2_asm_output_data (4, 0, "End of Table");
949 /* Turn off app to make assembly quicker. */
954 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
957 dwarf2out_do_cfi_startproc (bool second
)
961 rtx personality
= get_personality_function (current_function_decl
);
963 fprintf (asm_out_file
, "\t.cfi_startproc\n");
967 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
970 /* ??? The GAS support isn't entirely consistent. We have to
971 handle indirect support ourselves, but PC-relative is done
972 in the assembler. Further, the assembler can't handle any
973 of the weirder relocation types. */
974 if (enc
& DW_EH_PE_indirect
)
975 ref
= dw2_force_const_mem (ref
, true);
977 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
978 output_addr_const (asm_out_file
, ref
);
979 fputc ('\n', asm_out_file
);
982 if (crtl
->uses_eh_lsda
)
984 char lab
[MAX_ARTIFICIAL_LABEL_BYTES
];
986 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
987 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
988 current_function_funcdef_no
);
989 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
990 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
992 if (enc
& DW_EH_PE_indirect
)
993 ref
= dw2_force_const_mem (ref
, true);
995 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
996 output_addr_const (asm_out_file
, ref
);
997 fputc ('\n', asm_out_file
);
1001 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1002 this allocation may be done before pass_final. */
1005 dwarf2out_alloc_current_fde (void)
1009 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1010 fde
->decl
= current_function_decl
;
1011 fde
->funcdef_number
= current_function_funcdef_no
;
1012 fde
->fde_index
= vec_safe_length (fde_vec
);
1013 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1014 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1015 fde
->nothrow
= crtl
->nothrow
;
1016 fde
->drap_reg
= INVALID_REGNUM
;
1017 fde
->vdrap_reg
= INVALID_REGNUM
;
1019 /* Record the FDE associated with this function. */
1021 vec_safe_push (fde_vec
, fde
);
1026 /* Output a marker (i.e. a label) for the beginning of a function, before
1030 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1031 unsigned int column ATTRIBUTE_UNUSED
,
1032 const char *file ATTRIBUTE_UNUSED
)
1034 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1040 current_function_func_begin_label
= NULL
;
1042 do_frame
= dwarf2out_do_frame ();
1044 /* ??? current_function_func_begin_label is also used by except.c for
1045 call-site information. We must emit this label if it might be used. */
1047 && (!flag_exceptions
1048 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1051 fnsec
= function_section (current_function_decl
);
1052 switch_to_section (fnsec
);
1053 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1054 current_function_funcdef_no
);
1055 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1056 current_function_funcdef_no
);
1057 dup_label
= xstrdup (label
);
1058 current_function_func_begin_label
= dup_label
;
1060 /* We can elide the fde allocation if we're not emitting debug info. */
1064 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1065 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1066 would include pass_dwarf2_frame. If we've not created the FDE yet,
1070 fde
= dwarf2out_alloc_current_fde ();
1072 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1073 fde
->dw_fde_begin
= dup_label
;
1074 fde
->dw_fde_current_label
= dup_label
;
1075 fde
->in_std_section
= (fnsec
== text_section
1076 || (cold_text_section
&& fnsec
== cold_text_section
));
1078 /* We only want to output line number information for the genuine dwarf2
1079 prologue case, not the eh frame case. */
1080 #ifdef DWARF2_DEBUGGING_INFO
1082 dwarf2out_source_line (line
, column
, file
, 0, true);
1085 if (dwarf2out_do_cfi_asm ())
1086 dwarf2out_do_cfi_startproc (false);
1089 rtx personality
= get_personality_function (current_function_decl
);
1090 if (!current_unit_personality
)
1091 current_unit_personality
= personality
;
1093 /* We cannot keep a current personality per function as without CFI
1094 asm, at the point where we emit the CFI data, there is no current
1095 function anymore. */
1096 if (personality
&& current_unit_personality
!= personality
)
1097 sorry ("multiple EH personalities are supported only with assemblers "
1098 "supporting .cfi_personality directive");
1102 /* Output a marker (i.e. a label) for the end of the generated code
1103 for a function prologue. This gets called *after* the prologue code has
1107 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1108 const char *file ATTRIBUTE_UNUSED
)
1110 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1112 /* Output a label to mark the endpoint of the code generated for this
1114 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1115 current_function_funcdef_no
);
1116 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1117 current_function_funcdef_no
);
1118 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1121 /* Output a marker (i.e. a label) for the beginning of the generated code
1122 for a function epilogue. This gets called *before* the prologue code has
1126 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1127 const char *file ATTRIBUTE_UNUSED
)
1129 dw_fde_ref fde
= cfun
->fde
;
1130 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1132 if (fde
->dw_fde_vms_begin_epilogue
)
1135 /* Output a label to mark the endpoint of the code generated for this
1137 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1138 current_function_funcdef_no
);
1139 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1140 current_function_funcdef_no
);
1141 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1144 /* Output a marker (i.e. a label) for the absolute end of the generated code
1145 for a function definition. This gets called *after* the epilogue code has
1149 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1150 const char *file ATTRIBUTE_UNUSED
)
1153 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1155 last_var_location_insn
= NULL
;
1156 cached_next_real_insn
= NULL
;
1158 if (dwarf2out_do_cfi_asm ())
1159 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1161 /* Output a label to mark the endpoint of the code generated for this
1163 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1164 current_function_funcdef_no
);
1165 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1167 gcc_assert (fde
!= NULL
);
1168 if (fde
->dw_fde_second_begin
== NULL
)
1169 fde
->dw_fde_end
= xstrdup (label
);
1173 dwarf2out_frame_finish (void)
1175 /* Output call frame information. */
1176 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1177 output_call_frame_info (0);
1179 /* Output another copy for the unwinder. */
1180 if ((flag_unwind_tables
|| flag_exceptions
)
1181 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1182 output_call_frame_info (1);
1185 /* Note that the current function section is being used for code. */
1188 dwarf2out_note_section_used (void)
1190 section
*sec
= current_function_section ();
1191 if (sec
== text_section
)
1192 text_section_used
= true;
1193 else if (sec
== cold_text_section
)
1194 cold_text_section_used
= true;
1197 static void var_location_switch_text_section (void);
1198 static void set_cur_line_info_table (section
*);
1201 dwarf2out_switch_text_section (void)
1204 dw_fde_ref fde
= cfun
->fde
;
1206 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1208 if (!in_cold_section_p
)
1210 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1211 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1212 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1216 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1217 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1218 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1220 have_multiple_function_sections
= true;
1222 /* There is no need to mark used sections when not debugging. */
1223 if (cold_text_section
!= NULL
)
1224 dwarf2out_note_section_used ();
1226 if (dwarf2out_do_cfi_asm ())
1227 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1229 /* Now do the real section switch. */
1230 sect
= current_function_section ();
1231 switch_to_section (sect
);
1233 fde
->second_in_std_section
1234 = (sect
== text_section
1235 || (cold_text_section
&& sect
== cold_text_section
));
1237 if (dwarf2out_do_cfi_asm ())
1238 dwarf2out_do_cfi_startproc (true);
1240 var_location_switch_text_section ();
1242 if (cold_text_section
!= NULL
)
1243 set_cur_line_info_table (sect
);
1246 /* And now, the subset of the debugging information support code necessary
1247 for emitting location expressions. */
1249 /* Data about a single source file. */
1250 struct GTY((for_user
)) dwarf_file_data
{
1251 const char * filename
;
1255 /* Describe an entry into the .debug_addr section. */
1259 ate_kind_rtx_dtprel
,
1263 struct GTY((for_user
)) addr_table_entry
{
1265 unsigned int refcount
;
1267 union addr_table_entry_struct_union
1269 rtx
GTY ((tag ("0"))) rtl
;
1270 char * GTY ((tag ("1"))) label
;
1272 GTY ((desc ("%1.kind"))) addr
;
1275 /* Location lists are ranges + location descriptions for that range,
1276 so you can track variables that are in different places over
1277 their entire life. */
1278 typedef struct GTY(()) dw_loc_list_struct
{
1279 dw_loc_list_ref dw_loc_next
;
1280 const char *begin
; /* Label and addr_entry for start of range */
1281 addr_table_entry
*begin_entry
;
1282 const char *end
; /* Label for end of range */
1283 char *ll_symbol
; /* Label for beginning of location list.
1284 Only on head of list */
1285 const char *section
; /* Section this loclist is relative to */
1286 dw_loc_descr_ref expr
;
1288 /* True if all addresses in this and subsequent lists are known to be
1291 /* True if this list has been replaced by dw_loc_next. */
1293 /* True if it has been emitted into .debug_loc* / .debug_loclists*
1295 unsigned char emitted
: 1;
1296 /* True if hash field is index rather than hash value. */
1297 unsigned char num_assigned
: 1;
1298 /* True if .debug_loclists.dwo offset has been emitted for it already. */
1299 unsigned char offset_emitted
: 1;
1300 /* True if note_variable_value_in_expr has been called on it. */
1301 unsigned char noted_variable_value
: 1;
1302 /* True if the range should be emitted even if begin and end
1307 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1308 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1310 /* Convert a DWARF stack opcode into its string name. */
1313 dwarf_stack_op_name (unsigned int op
)
1315 const char *name
= get_DW_OP_name (op
);
1320 return "OP_<unknown>";
1323 /* Return a pointer to a newly allocated location description. Location
1324 descriptions are simple expression terms that can be strung
1325 together to form more complicated location (address) descriptions. */
1327 static inline dw_loc_descr_ref
1328 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1329 unsigned HOST_WIDE_INT oprnd2
)
1331 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1333 descr
->dw_loc_opc
= op
;
1334 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1335 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1336 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1337 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1338 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1339 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1344 /* Return a pointer to a newly allocated location description for
1347 static inline dw_loc_descr_ref
1348 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1351 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1354 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1357 /* Add a location description term to a location description expression. */
1360 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1362 dw_loc_descr_ref
*d
;
1364 /* Find the end of the chain. */
1365 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1371 /* Compare two location operands for exact equality. */
1374 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1376 if (a
->val_class
!= b
->val_class
)
1378 switch (a
->val_class
)
1380 case dw_val_class_none
:
1382 case dw_val_class_addr
:
1383 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1385 case dw_val_class_offset
:
1386 case dw_val_class_unsigned_const
:
1387 case dw_val_class_const
:
1388 case dw_val_class_unsigned_const_implicit
:
1389 case dw_val_class_const_implicit
:
1390 case dw_val_class_range_list
:
1391 /* These are all HOST_WIDE_INT, signed or unsigned. */
1392 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1394 case dw_val_class_loc
:
1395 return a
->v
.val_loc
== b
->v
.val_loc
;
1396 case dw_val_class_loc_list
:
1397 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1398 case dw_val_class_die_ref
:
1399 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1400 case dw_val_class_fde_ref
:
1401 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1402 case dw_val_class_lbl_id
:
1403 case dw_val_class_lineptr
:
1404 case dw_val_class_macptr
:
1405 case dw_val_class_loclistsptr
:
1406 case dw_val_class_high_pc
:
1407 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1408 case dw_val_class_str
:
1409 return a
->v
.val_str
== b
->v
.val_str
;
1410 case dw_val_class_flag
:
1411 return a
->v
.val_flag
== b
->v
.val_flag
;
1412 case dw_val_class_file
:
1413 case dw_val_class_file_implicit
:
1414 return a
->v
.val_file
== b
->v
.val_file
;
1415 case dw_val_class_decl_ref
:
1416 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1418 case dw_val_class_const_double
:
1419 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1420 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1422 case dw_val_class_wide_int
:
1423 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1425 case dw_val_class_vec
:
1427 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1428 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1430 return (a_len
== b_len
1431 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1434 case dw_val_class_data8
:
1435 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1437 case dw_val_class_vms_delta
:
1438 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1439 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1441 case dw_val_class_discr_value
:
1442 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1443 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1444 case dw_val_class_discr_list
:
1445 /* It makes no sense comparing two discriminant value lists. */
1451 /* Compare two location atoms for exact equality. */
1454 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1456 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1459 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1460 address size, but since we always allocate cleared storage it
1461 should be zero for other types of locations. */
1462 if (a
->dtprel
!= b
->dtprel
)
1465 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1466 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1469 /* Compare two complete location expressions for exact equality. */
1472 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1478 if (a
== NULL
|| b
== NULL
)
1480 if (!loc_descr_equal_p_1 (a
, b
))
1489 /* Add a constant OFFSET to a location expression. */
1492 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1494 dw_loc_descr_ref loc
;
1497 gcc_assert (*list_head
!= NULL
);
1502 /* Find the end of the chain. */
1503 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1507 if (loc
->dw_loc_opc
== DW_OP_fbreg
1508 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1509 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1510 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1511 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1513 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1514 offset. Don't optimize if an signed integer overflow would happen. */
1516 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1517 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1520 else if (offset
> 0)
1521 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1526 = uint_loc_descriptor (-(unsigned HOST_WIDE_INT
) offset
);
1527 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1531 /* Add a constant OFFSET to a location list. */
1534 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1537 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1538 loc_descr_plus_const (&d
->expr
, offset
);
1541 #define DWARF_REF_SIZE \
1542 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1544 /* The number of bits that can be encoded by largest DW_FORM_dataN.
1545 In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
1546 DW_FORM_data16 with 128 bits. */
1547 #define DWARF_LARGEST_DATA_FORM_BITS \
1548 (dwarf_version >= 5 ? 128 : 64)
1550 /* Utility inline function for construction of ops that were GNU extension
1552 static inline enum dwarf_location_atom
1553 dwarf_OP (enum dwarf_location_atom op
)
1557 case DW_OP_implicit_pointer
:
1558 if (dwarf_version
< 5)
1559 return DW_OP_GNU_implicit_pointer
;
1562 case DW_OP_entry_value
:
1563 if (dwarf_version
< 5)
1564 return DW_OP_GNU_entry_value
;
1567 case DW_OP_const_type
:
1568 if (dwarf_version
< 5)
1569 return DW_OP_GNU_const_type
;
1572 case DW_OP_regval_type
:
1573 if (dwarf_version
< 5)
1574 return DW_OP_GNU_regval_type
;
1577 case DW_OP_deref_type
:
1578 if (dwarf_version
< 5)
1579 return DW_OP_GNU_deref_type
;
1583 if (dwarf_version
< 5)
1584 return DW_OP_GNU_convert
;
1587 case DW_OP_reinterpret
:
1588 if (dwarf_version
< 5)
1589 return DW_OP_GNU_reinterpret
;
1598 /* Similarly for attributes. */
1599 static inline enum dwarf_attribute
1600 dwarf_AT (enum dwarf_attribute at
)
1604 case DW_AT_call_return_pc
:
1605 if (dwarf_version
< 5)
1606 return DW_AT_low_pc
;
1609 case DW_AT_call_tail_call
:
1610 if (dwarf_version
< 5)
1611 return DW_AT_GNU_tail_call
;
1614 case DW_AT_call_origin
:
1615 if (dwarf_version
< 5)
1616 return DW_AT_abstract_origin
;
1619 case DW_AT_call_target
:
1620 if (dwarf_version
< 5)
1621 return DW_AT_GNU_call_site_target
;
1624 case DW_AT_call_target_clobbered
:
1625 if (dwarf_version
< 5)
1626 return DW_AT_GNU_call_site_target_clobbered
;
1629 case DW_AT_call_parameter
:
1630 if (dwarf_version
< 5)
1631 return DW_AT_abstract_origin
;
1634 case DW_AT_call_value
:
1635 if (dwarf_version
< 5)
1636 return DW_AT_GNU_call_site_value
;
1639 case DW_AT_call_data_value
:
1640 if (dwarf_version
< 5)
1641 return DW_AT_GNU_call_site_data_value
;
1644 case DW_AT_call_all_calls
:
1645 if (dwarf_version
< 5)
1646 return DW_AT_GNU_all_call_sites
;
1649 case DW_AT_call_all_tail_calls
:
1650 if (dwarf_version
< 5)
1651 return DW_AT_GNU_all_tail_call_sites
;
1654 case DW_AT_dwo_name
:
1655 if (dwarf_version
< 5)
1656 return DW_AT_GNU_dwo_name
;
1665 /* And similarly for tags. */
1666 static inline enum dwarf_tag
1667 dwarf_TAG (enum dwarf_tag tag
)
1671 case DW_TAG_call_site
:
1672 if (dwarf_version
< 5)
1673 return DW_TAG_GNU_call_site
;
1676 case DW_TAG_call_site_parameter
:
1677 if (dwarf_version
< 5)
1678 return DW_TAG_GNU_call_site_parameter
;
1687 static unsigned long int get_base_type_offset (dw_die_ref
);
1689 /* Return the size of a location descriptor. */
1691 static unsigned long
1692 size_of_loc_descr (dw_loc_descr_ref loc
)
1694 unsigned long size
= 1;
1696 switch (loc
->dw_loc_opc
)
1699 size
+= DWARF2_ADDR_SIZE
;
1701 case DW_OP_GNU_addr_index
:
1702 case DW_OP_GNU_const_index
:
1703 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1704 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1723 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1726 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1731 case DW_OP_plus_uconst
:
1732 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1770 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1773 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1776 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1779 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1780 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1783 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1785 case DW_OP_bit_piece
:
1786 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1787 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1789 case DW_OP_deref_size
:
1790 case DW_OP_xderef_size
:
1799 case DW_OP_call_ref
:
1800 case DW_OP_GNU_variable_value
:
1801 size
+= DWARF_REF_SIZE
;
1803 case DW_OP_implicit_value
:
1804 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1805 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1807 case DW_OP_implicit_pointer
:
1808 case DW_OP_GNU_implicit_pointer
:
1809 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1811 case DW_OP_entry_value
:
1812 case DW_OP_GNU_entry_value
:
1814 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1815 size
+= size_of_uleb128 (op_size
) + op_size
;
1818 case DW_OP_const_type
:
1819 case DW_OP_GNU_const_type
:
1822 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1823 size
+= size_of_uleb128 (o
) + 1;
1824 switch (loc
->dw_loc_oprnd2
.val_class
)
1826 case dw_val_class_vec
:
1827 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1828 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1830 case dw_val_class_const
:
1831 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1833 case dw_val_class_const_double
:
1834 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1836 case dw_val_class_wide_int
:
1837 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1838 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1845 case DW_OP_regval_type
:
1846 case DW_OP_GNU_regval_type
:
1849 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1850 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1851 + size_of_uleb128 (o
);
1854 case DW_OP_deref_type
:
1855 case DW_OP_GNU_deref_type
:
1858 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1859 size
+= 1 + size_of_uleb128 (o
);
1863 case DW_OP_reinterpret
:
1864 case DW_OP_GNU_convert
:
1865 case DW_OP_GNU_reinterpret
:
1866 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1867 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1871 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1872 size
+= size_of_uleb128 (o
);
1875 case DW_OP_GNU_parameter_ref
:
1885 /* Return the size of a series of location descriptors. */
1888 size_of_locs (dw_loc_descr_ref loc
)
1893 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1894 field, to avoid writing to a PCH file. */
1895 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1897 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1899 size
+= size_of_loc_descr (l
);
1904 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1906 l
->dw_loc_addr
= size
;
1907 size
+= size_of_loc_descr (l
);
1913 /* Return the size of the value in a DW_AT_discr_value attribute. */
1916 size_of_discr_value (dw_discr_value
*discr_value
)
1918 if (discr_value
->pos
)
1919 return size_of_uleb128 (discr_value
->v
.uval
);
1921 return size_of_sleb128 (discr_value
->v
.sval
);
1924 /* Return the size of the value in a DW_AT_discr_list attribute. */
1927 size_of_discr_list (dw_discr_list_ref discr_list
)
1931 for (dw_discr_list_ref list
= discr_list
;
1933 list
= list
->dw_discr_next
)
1935 /* One byte for the discriminant value descriptor, and then one or two
1936 LEB128 numbers, depending on whether it's a single case label or a
1939 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
1940 if (list
->dw_discr_range
!= 0)
1941 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
1946 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1947 static void get_ref_die_offset_label (char *, dw_die_ref
);
1948 static unsigned long int get_ref_die_offset (dw_die_ref
);
1950 /* Output location description stack opcode's operands (if any).
1951 The for_eh_or_skip parameter controls whether register numbers are
1952 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1953 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1954 info). This should be suppressed for the cases that have not been converted
1955 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1958 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1960 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1961 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1963 switch (loc
->dw_loc_opc
)
1965 #ifdef DWARF2_DEBUGGING_INFO
1968 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1973 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1974 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1976 fputc ('\n', asm_out_file
);
1981 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1986 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1987 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1989 fputc ('\n', asm_out_file
);
1994 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1995 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2002 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2003 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2005 dw2_asm_output_data (2, offset
, NULL
);
2008 case DW_OP_implicit_value
:
2009 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2010 switch (val2
->val_class
)
2012 case dw_val_class_const
:
2013 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2015 case dw_val_class_vec
:
2017 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2018 unsigned int len
= val2
->v
.val_vec
.length
;
2022 if (elt_size
> sizeof (HOST_WIDE_INT
))
2027 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2030 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2031 "fp or vector constant word %u", i
);
2034 case dw_val_class_const_double
:
2036 unsigned HOST_WIDE_INT first
, second
;
2038 if (WORDS_BIG_ENDIAN
)
2040 first
= val2
->v
.val_double
.high
;
2041 second
= val2
->v
.val_double
.low
;
2045 first
= val2
->v
.val_double
.low
;
2046 second
= val2
->v
.val_double
.high
;
2048 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2050 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2054 case dw_val_class_wide_int
:
2057 int len
= get_full_len (*val2
->v
.val_wide
);
2058 if (WORDS_BIG_ENDIAN
)
2059 for (i
= len
- 1; i
>= 0; --i
)
2060 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2061 val2
->v
.val_wide
->elt (i
), NULL
);
2063 for (i
= 0; i
< len
; ++i
)
2064 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2065 val2
->v
.val_wide
->elt (i
), NULL
);
2068 case dw_val_class_addr
:
2069 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2070 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2085 case DW_OP_implicit_value
:
2086 /* We currently don't make any attempt to make sure these are
2087 aligned properly like we do for the main unwind info, so
2088 don't support emitting things larger than a byte if we're
2089 only doing unwinding. */
2094 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2097 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2100 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2103 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2105 case DW_OP_plus_uconst
:
2106 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2140 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2144 unsigned r
= val1
->v
.val_unsigned
;
2145 if (for_eh_or_skip
>= 0)
2146 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2147 gcc_assert (size_of_uleb128 (r
)
2148 == size_of_uleb128 (val1
->v
.val_unsigned
));
2149 dw2_asm_output_data_uleb128 (r
, NULL
);
2153 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2157 unsigned r
= val1
->v
.val_unsigned
;
2158 if (for_eh_or_skip
>= 0)
2159 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2160 gcc_assert (size_of_uleb128 (r
)
2161 == size_of_uleb128 (val1
->v
.val_unsigned
));
2162 dw2_asm_output_data_uleb128 (r
, NULL
);
2163 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2167 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2169 case DW_OP_bit_piece
:
2170 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2171 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2173 case DW_OP_deref_size
:
2174 case DW_OP_xderef_size
:
2175 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2181 if (targetm
.asm_out
.output_dwarf_dtprel
)
2183 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2186 fputc ('\n', asm_out_file
);
2193 #ifdef DWARF2_DEBUGGING_INFO
2194 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2201 case DW_OP_GNU_addr_index
:
2202 case DW_OP_GNU_const_index
:
2203 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2204 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2205 "(index into .debug_addr)");
2211 unsigned long die_offset
2212 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2213 /* Make sure the offset has been computed and that we can encode it as
2215 gcc_assert (die_offset
> 0
2216 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
2219 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2224 case DW_OP_call_ref
:
2225 case DW_OP_GNU_variable_value
:
2227 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2228 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2229 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2230 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2231 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2235 case DW_OP_implicit_pointer
:
2236 case DW_OP_GNU_implicit_pointer
:
2238 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2239 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2240 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2241 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2242 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2243 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2247 case DW_OP_entry_value
:
2248 case DW_OP_GNU_entry_value
:
2249 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2250 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2253 case DW_OP_const_type
:
2254 case DW_OP_GNU_const_type
:
2256 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2258 dw2_asm_output_data_uleb128 (o
, NULL
);
2259 switch (val2
->val_class
)
2261 case dw_val_class_const
:
2262 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2263 dw2_asm_output_data (1, l
, NULL
);
2264 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2266 case dw_val_class_vec
:
2268 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2269 unsigned int len
= val2
->v
.val_vec
.length
;
2274 dw2_asm_output_data (1, l
, NULL
);
2275 if (elt_size
> sizeof (HOST_WIDE_INT
))
2280 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2283 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2284 "fp or vector constant word %u", i
);
2287 case dw_val_class_const_double
:
2289 unsigned HOST_WIDE_INT first
, second
;
2290 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2292 dw2_asm_output_data (1, 2 * l
, NULL
);
2293 if (WORDS_BIG_ENDIAN
)
2295 first
= val2
->v
.val_double
.high
;
2296 second
= val2
->v
.val_double
.low
;
2300 first
= val2
->v
.val_double
.low
;
2301 second
= val2
->v
.val_double
.high
;
2303 dw2_asm_output_data (l
, first
, NULL
);
2304 dw2_asm_output_data (l
, second
, NULL
);
2307 case dw_val_class_wide_int
:
2310 int len
= get_full_len (*val2
->v
.val_wide
);
2311 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2313 dw2_asm_output_data (1, len
* l
, NULL
);
2314 if (WORDS_BIG_ENDIAN
)
2315 for (i
= len
- 1; i
>= 0; --i
)
2316 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2318 for (i
= 0; i
< len
; ++i
)
2319 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2327 case DW_OP_regval_type
:
2328 case DW_OP_GNU_regval_type
:
2330 unsigned r
= val1
->v
.val_unsigned
;
2331 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2333 if (for_eh_or_skip
>= 0)
2335 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2336 gcc_assert (size_of_uleb128 (r
)
2337 == size_of_uleb128 (val1
->v
.val_unsigned
));
2339 dw2_asm_output_data_uleb128 (r
, NULL
);
2340 dw2_asm_output_data_uleb128 (o
, NULL
);
2343 case DW_OP_deref_type
:
2344 case DW_OP_GNU_deref_type
:
2346 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2348 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2349 dw2_asm_output_data_uleb128 (o
, NULL
);
2353 case DW_OP_reinterpret
:
2354 case DW_OP_GNU_convert
:
2355 case DW_OP_GNU_reinterpret
:
2356 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2357 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2360 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2362 dw2_asm_output_data_uleb128 (o
, NULL
);
2366 case DW_OP_GNU_parameter_ref
:
2369 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2370 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2371 dw2_asm_output_data (4, o
, NULL
);
2376 /* Other codes have no operands. */
2381 /* Output a sequence of location operations.
2382 The for_eh_or_skip parameter controls whether register numbers are
2383 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2384 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2385 info). This should be suppressed for the cases that have not been converted
2386 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2389 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2391 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2393 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2394 /* Output the opcode. */
2395 if (for_eh_or_skip
>= 0
2396 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2398 unsigned r
= (opc
- DW_OP_breg0
);
2399 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2400 gcc_assert (r
<= 31);
2401 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2403 else if (for_eh_or_skip
>= 0
2404 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2406 unsigned r
= (opc
- DW_OP_reg0
);
2407 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2408 gcc_assert (r
<= 31);
2409 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2412 dw2_asm_output_data (1, opc
,
2413 "%s", dwarf_stack_op_name (opc
));
2415 /* Output the operand(s) (if any). */
2416 output_loc_operands (loc
, for_eh_or_skip
);
2420 /* Output location description stack opcode's operands (if any).
2421 The output is single bytes on a line, suitable for .cfi_escape. */
2424 output_loc_operands_raw (dw_loc_descr_ref loc
)
2426 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2427 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2429 switch (loc
->dw_loc_opc
)
2432 case DW_OP_GNU_addr_index
:
2433 case DW_OP_GNU_const_index
:
2434 case DW_OP_implicit_value
:
2435 /* We cannot output addresses in .cfi_escape, only bytes. */
2441 case DW_OP_deref_size
:
2442 case DW_OP_xderef_size
:
2443 fputc (',', asm_out_file
);
2444 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2449 fputc (',', asm_out_file
);
2450 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2455 fputc (',', asm_out_file
);
2456 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2461 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2462 fputc (',', asm_out_file
);
2463 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2471 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2472 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2474 fputc (',', asm_out_file
);
2475 dw2_asm_output_data_raw (2, offset
);
2481 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2482 gcc_assert (size_of_uleb128 (r
)
2483 == size_of_uleb128 (val1
->v
.val_unsigned
));
2484 fputc (',', asm_out_file
);
2485 dw2_asm_output_data_uleb128_raw (r
);
2490 case DW_OP_plus_uconst
:
2492 fputc (',', asm_out_file
);
2493 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2496 case DW_OP_bit_piece
:
2497 fputc (',', asm_out_file
);
2498 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2499 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2536 fputc (',', asm_out_file
);
2537 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2542 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2543 gcc_assert (size_of_uleb128 (r
)
2544 == size_of_uleb128 (val1
->v
.val_unsigned
));
2545 fputc (',', asm_out_file
);
2546 dw2_asm_output_data_uleb128_raw (r
);
2547 fputc (',', asm_out_file
);
2548 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2552 case DW_OP_implicit_pointer
:
2553 case DW_OP_entry_value
:
2554 case DW_OP_const_type
:
2555 case DW_OP_regval_type
:
2556 case DW_OP_deref_type
:
2558 case DW_OP_reinterpret
:
2559 case DW_OP_GNU_implicit_pointer
:
2560 case DW_OP_GNU_entry_value
:
2561 case DW_OP_GNU_const_type
:
2562 case DW_OP_GNU_regval_type
:
2563 case DW_OP_GNU_deref_type
:
2564 case DW_OP_GNU_convert
:
2565 case DW_OP_GNU_reinterpret
:
2566 case DW_OP_GNU_parameter_ref
:
2571 /* Other codes have no operands. */
2577 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2581 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2582 /* Output the opcode. */
2583 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2585 unsigned r
= (opc
- DW_OP_breg0
);
2586 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2587 gcc_assert (r
<= 31);
2588 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2590 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2592 unsigned r
= (opc
- DW_OP_reg0
);
2593 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2594 gcc_assert (r
<= 31);
2595 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2597 /* Output the opcode. */
2598 fprintf (asm_out_file
, "%#x", opc
);
2599 output_loc_operands_raw (loc
);
2601 if (!loc
->dw_loc_next
)
2603 loc
= loc
->dw_loc_next
;
2605 fputc (',', asm_out_file
);
2609 /* This function builds a dwarf location descriptor sequence from a
2610 dw_cfa_location, adding the given OFFSET to the result of the
2613 struct dw_loc_descr_node
*
2614 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2616 struct dw_loc_descr_node
*head
, *tmp
;
2618 offset
+= cfa
->offset
;
2622 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2623 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2624 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2625 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2626 add_loc_descr (&head
, tmp
);
2629 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2630 add_loc_descr (&head
, tmp
);
2634 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2639 /* This function builds a dwarf location descriptor sequence for
2640 the address at OFFSET from the CFA when stack is aligned to
2643 struct dw_loc_descr_node
*
2644 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2645 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2647 struct dw_loc_descr_node
*head
;
2648 unsigned int dwarf_fp
2649 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2651 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2652 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2654 head
= new_reg_loc_descr (dwarf_fp
, 0);
2655 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2656 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2657 loc_descr_plus_const (&head
, offset
);
2660 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2664 /* And now, the support for symbolic debugging information. */
2666 /* .debug_str support. */
2668 static void dwarf2out_init (const char *);
2669 static void dwarf2out_finish (const char *);
2670 static void dwarf2out_early_finish (const char *);
2671 static void dwarf2out_assembly_start (void);
2672 static void dwarf2out_define (unsigned int, const char *);
2673 static void dwarf2out_undef (unsigned int, const char *);
2674 static void dwarf2out_start_source_file (unsigned, const char *);
2675 static void dwarf2out_end_source_file (unsigned);
2676 static void dwarf2out_function_decl (tree
);
2677 static void dwarf2out_begin_block (unsigned, unsigned);
2678 static void dwarf2out_end_block (unsigned, unsigned);
2679 static bool dwarf2out_ignore_block (const_tree
);
2680 static void dwarf2out_early_global_decl (tree
);
2681 static void dwarf2out_late_global_decl (tree
);
2682 static void dwarf2out_type_decl (tree
, int);
2683 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2684 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2686 static void dwarf2out_abstract_function (tree
);
2687 static void dwarf2out_var_location (rtx_insn
*);
2688 static void dwarf2out_size_function (tree
);
2689 static void dwarf2out_begin_function (tree
);
2690 static void dwarf2out_end_function (unsigned int);
2691 static void dwarf2out_register_main_translation_unit (tree unit
);
2692 static void dwarf2out_set_name (tree
, tree
);
2694 /* The debug hooks structure. */
2696 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2700 dwarf2out_early_finish
,
2701 dwarf2out_assembly_start
,
2704 dwarf2out_start_source_file
,
2705 dwarf2out_end_source_file
,
2706 dwarf2out_begin_block
,
2707 dwarf2out_end_block
,
2708 dwarf2out_ignore_block
,
2709 dwarf2out_source_line
,
2710 dwarf2out_begin_prologue
,
2711 #if VMS_DEBUGGING_INFO
2712 dwarf2out_vms_end_prologue
,
2713 dwarf2out_vms_begin_epilogue
,
2715 debug_nothing_int_charstar
,
2716 debug_nothing_int_charstar
,
2718 dwarf2out_end_epilogue
,
2719 dwarf2out_begin_function
,
2720 dwarf2out_end_function
, /* end_function */
2721 dwarf2out_register_main_translation_unit
,
2722 dwarf2out_function_decl
, /* function_decl */
2723 dwarf2out_early_global_decl
,
2724 dwarf2out_late_global_decl
,
2725 dwarf2out_type_decl
, /* type_decl */
2726 dwarf2out_imported_module_or_decl
,
2727 debug_nothing_tree
, /* deferred_inline_function */
2728 /* The DWARF 2 backend tries to reduce debugging bloat by not
2729 emitting the abstract description of inline functions until
2730 something tries to reference them. */
2731 dwarf2out_abstract_function
, /* outlining_inline_function */
2732 debug_nothing_rtx_code_label
, /* label */
2733 debug_nothing_int
, /* handle_pch */
2734 dwarf2out_var_location
,
2735 dwarf2out_size_function
, /* size_function */
2736 dwarf2out_switch_text_section
,
2738 1, /* start_end_main_source_file */
2739 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2742 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2745 debug_nothing_charstar
,
2746 debug_nothing_charstar
,
2747 dwarf2out_assembly_start
,
2748 debug_nothing_int_charstar
,
2749 debug_nothing_int_charstar
,
2750 debug_nothing_int_charstar
,
2752 debug_nothing_int_int
, /* begin_block */
2753 debug_nothing_int_int
, /* end_block */
2754 debug_true_const_tree
, /* ignore_block */
2755 dwarf2out_source_line
, /* source_line */
2756 debug_nothing_int_int_charstar
, /* begin_prologue */
2757 debug_nothing_int_charstar
, /* end_prologue */
2758 debug_nothing_int_charstar
, /* begin_epilogue */
2759 debug_nothing_int_charstar
, /* end_epilogue */
2760 debug_nothing_tree
, /* begin_function */
2761 debug_nothing_int
, /* end_function */
2762 debug_nothing_tree
, /* register_main_translation_unit */
2763 debug_nothing_tree
, /* function_decl */
2764 debug_nothing_tree
, /* early_global_decl */
2765 debug_nothing_tree
, /* late_global_decl */
2766 debug_nothing_tree_int
, /* type_decl */
2767 debug_nothing_tree_tree_tree_bool
, /* imported_module_or_decl */
2768 debug_nothing_tree
, /* deferred_inline_function */
2769 debug_nothing_tree
, /* outlining_inline_function */
2770 debug_nothing_rtx_code_label
, /* label */
2771 debug_nothing_int
, /* handle_pch */
2772 debug_nothing_rtx_insn
, /* var_location */
2773 debug_nothing_tree
, /* size_function */
2774 debug_nothing_void
, /* switch_text_section */
2775 debug_nothing_tree_tree
, /* set_name */
2776 0, /* start_end_main_source_file */
2777 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2780 /* NOTE: In the comments in this file, many references are made to
2781 "Debugging Information Entries". This term is abbreviated as `DIE'
2782 throughout the remainder of this file. */
2784 /* An internal representation of the DWARF output is built, and then
2785 walked to generate the DWARF debugging info. The walk of the internal
2786 representation is done after the entire program has been compiled.
2787 The types below are used to describe the internal representation. */
2789 /* Whether to put type DIEs into their own section .debug_types instead
2790 of making them part of the .debug_info section. Only supported for
2791 Dwarf V4 or higher and the user didn't disable them through
2792 -fno-debug-types-section. It is more efficient to put them in a
2793 separate comdat sections since the linker will then be able to
2794 remove duplicates. But not all tools support .debug_types sections
2795 yet. For Dwarf V5 or higher .debug_types doesn't exist any more,
2796 it is DW_UT_type unit type in .debug_info section. */
2798 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2800 /* Various DIE's use offsets relative to the beginning of the
2801 .debug_info section to refer to each other. */
2803 typedef long int dw_offset
;
2805 struct comdat_type_node
;
2807 /* The entries in the line_info table more-or-less mirror the opcodes
2808 that are used in the real dwarf line table. Arrays of these entries
2809 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2812 enum dw_line_info_opcode
{
2813 /* Emit DW_LNE_set_address; the operand is the label index. */
2816 /* Emit a row to the matrix with the given line. This may be done
2817 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2821 /* Emit a DW_LNS_set_file. */
2824 /* Emit a DW_LNS_set_column. */
2827 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2830 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2831 LI_set_prologue_end
,
2832 LI_set_epilogue_begin
,
2834 /* Emit a DW_LNE_set_discriminator. */
2835 LI_set_discriminator
2838 typedef struct GTY(()) dw_line_info_struct
{
2839 enum dw_line_info_opcode opcode
;
2841 } dw_line_info_entry
;
2844 struct GTY(()) dw_line_info_table
{
2845 /* The label that marks the end of this section. */
2846 const char *end_label
;
2848 /* The values for the last row of the matrix, as collected in the table.
2849 These are used to minimize the changes to the next row. */
2850 unsigned int file_num
;
2851 unsigned int line_num
;
2852 unsigned int column_num
;
2857 vec
<dw_line_info_entry
, va_gc
> *entries
;
2861 /* Each DIE attribute has a field specifying the attribute kind,
2862 a link to the next attribute in the chain, and an attribute value.
2863 Attributes are typically linked below the DIE they modify. */
2865 typedef struct GTY(()) dw_attr_struct
{
2866 enum dwarf_attribute dw_attr
;
2867 dw_val_node dw_attr_val
;
2872 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2873 The children of each node form a circular list linked by
2874 die_sib. die_child points to the node *before* the "first" child node. */
2876 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2877 union die_symbol_or_type_node
2879 const char * GTY ((tag ("0"))) die_symbol
;
2880 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
2882 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2883 vec
<dw_attr_node
, va_gc
> *die_attr
;
2884 dw_die_ref die_parent
;
2885 dw_die_ref die_child
;
2887 dw_die_ref die_definition
; /* ref from a specification to its definition */
2888 dw_offset die_offset
;
2889 unsigned long die_abbrev
;
2891 unsigned int decl_id
;
2892 enum dwarf_tag die_tag
;
2893 /* Die is used and must not be pruned as unused. */
2894 BOOL_BITFIELD die_perennial_p
: 1;
2895 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2896 /* Whether this DIE was removed from the DIE tree, for example via
2897 prune_unused_types. We don't consider those present from the
2898 DIE lookup routines. */
2899 BOOL_BITFIELD removed
: 1;
2900 /* Lots of spare bits. */
2904 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2905 static bool early_dwarf
;
2906 static bool early_dwarf_finished
;
2907 struct set_early_dwarf
{
2909 set_early_dwarf () : saved(early_dwarf
)
2911 gcc_assert (! early_dwarf_finished
);
2914 ~set_early_dwarf () { early_dwarf
= saved
; }
2917 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2918 #define FOR_EACH_CHILD(die, c, expr) do { \
2919 c = die->die_child; \
2923 } while (c != die->die_child); \
2926 /* The pubname structure */
2928 typedef struct GTY(()) pubname_struct
{
2935 struct GTY(()) dw_ranges
{
2937 /* If this is positive, it's a block number, otherwise it's a
2938 bitwise-negated index into dw_ranges_by_label. */
2940 /* Index for the range list for DW_FORM_rnglistx. */
2941 unsigned int idx
: 31;
2942 /* True if this range might be possibly in a different section
2943 from previous entry. */
2944 unsigned int maybe_new_sec
: 1;
2947 /* A structure to hold a macinfo entry. */
2949 typedef struct GTY(()) macinfo_struct
{
2951 unsigned HOST_WIDE_INT lineno
;
2957 struct GTY(()) dw_ranges_by_label
{
2962 /* The comdat type node structure. */
2963 struct GTY(()) comdat_type_node
2965 dw_die_ref root_die
;
2966 dw_die_ref type_die
;
2967 dw_die_ref skeleton_die
;
2968 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2969 comdat_type_node
*next
;
2972 /* A list of DIEs for which we can't determine ancestry (parent_die
2973 field) just yet. Later in dwarf2out_finish we will fill in the
2975 typedef struct GTY(()) limbo_die_struct
{
2977 /* The tree for which this DIE was created. We use this to
2978 determine ancestry later. */
2980 struct limbo_die_struct
*next
;
2984 typedef struct skeleton_chain_struct
2988 struct skeleton_chain_struct
*parent
;
2990 skeleton_chain_node
;
2992 /* Define a macro which returns nonzero for a TYPE_DECL which was
2993 implicitly generated for a type.
2995 Note that, unlike the C front-end (which generates a NULL named
2996 TYPE_DECL node for each complete tagged type, each array type,
2997 and each function type node created) the C++ front-end generates
2998 a _named_ TYPE_DECL node for each tagged type node created.
2999 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3000 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
3001 front-end, but for each type, tagged or not. */
3003 #define TYPE_DECL_IS_STUB(decl) \
3004 (DECL_NAME (decl) == NULL_TREE \
3005 || (DECL_ARTIFICIAL (decl) \
3006 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3007 /* This is necessary for stub decls that \
3008 appear in nested inline functions. */ \
3009 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3010 && (decl_ultimate_origin (decl) \
3011 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3013 /* Information concerning the compilation unit's programming
3014 language, and compiler version. */
3016 /* Fixed size portion of the DWARF compilation unit header. */
3017 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3018 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE \
3019 + (dwarf_version >= 5 ? 4 : 3))
3021 /* Fixed size portion of the DWARF comdat type unit header. */
3022 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3023 (DWARF_COMPILE_UNIT_HEADER_SIZE \
3024 + DWARF_TYPE_SIGNATURE_SIZE + DWARF_OFFSET_SIZE)
3026 /* Fixed size portion of the DWARF skeleton compilation unit header. */
3027 #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
3028 (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
3030 /* Fixed size portion of public names info. */
3031 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3033 /* Fixed size portion of the address range info. */
3034 #define DWARF_ARANGES_HEADER_SIZE \
3035 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3036 DWARF2_ADDR_SIZE * 2) \
3037 - DWARF_INITIAL_LENGTH_SIZE)
3039 /* Size of padding portion in the address range info. It must be
3040 aligned to twice the pointer size. */
3041 #define DWARF_ARANGES_PAD_SIZE \
3042 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3043 DWARF2_ADDR_SIZE * 2) \
3044 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3046 /* Use assembler line directives if available. */
3047 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3048 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3049 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3051 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3055 /* Minimum line offset in a special line info. opcode.
3056 This value was chosen to give a reasonable range of values. */
3057 #define DWARF_LINE_BASE -10
3059 /* First special line opcode - leave room for the standard opcodes. */
3060 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3062 /* Range of line offsets in a special line info. opcode. */
3063 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3065 /* Flag that indicates the initial value of the is_stmt_start flag.
3066 In the present implementation, we do not mark any lines as
3067 the beginning of a source statement, because that information
3068 is not made available by the GCC front-end. */
3069 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3071 /* Maximum number of operations per instruction bundle. */
3072 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3073 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3076 /* This location is used by calc_die_sizes() to keep track
3077 the offset of each DIE within the .debug_info section. */
3078 static unsigned long next_die_offset
;
3080 /* Record the root of the DIE's built for the current compilation unit. */
3081 static GTY(()) dw_die_ref single_comp_unit_die
;
3083 /* A list of type DIEs that have been separated into comdat sections. */
3084 static GTY(()) comdat_type_node
*comdat_type_list
;
3086 /* A list of CU DIEs that have been separated. */
3087 static GTY(()) limbo_die_node
*cu_die_list
;
3089 /* A list of DIEs with a NULL parent waiting to be relocated. */
3090 static GTY(()) limbo_die_node
*limbo_die_list
;
3092 /* A list of DIEs for which we may have to generate
3093 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3094 static GTY(()) limbo_die_node
*deferred_asm_name
;
3096 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
3098 typedef const char *compare_type
;
3100 static hashval_t
hash (dwarf_file_data
*);
3101 static bool equal (dwarf_file_data
*, const char *);
3104 /* Filenames referenced by this compilation unit. */
3105 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
3107 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
3109 typedef tree compare_type
;
3111 static hashval_t
hash (die_node
*);
3112 static bool equal (die_node
*, tree
);
3114 /* A hash table of references to DIE's that describe declarations.
3115 The key is a DECL_UID() which is a unique number identifying each decl. */
3116 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
3118 struct GTY ((for_user
)) variable_value_struct
{
3119 unsigned int decl_id
;
3120 vec
<dw_die_ref
, va_gc
> *dies
;
3123 struct variable_value_hasher
: ggc_ptr_hash
<variable_value_struct
>
3125 typedef tree compare_type
;
3127 static hashval_t
hash (variable_value_struct
*);
3128 static bool equal (variable_value_struct
*, tree
);
3130 /* A hash table of DIEs that contain DW_OP_GNU_variable_value with
3131 dw_val_class_decl_ref class, indexed by FUNCTION_DECLs which is
3132 DECL_CONTEXT of the referenced VAR_DECLs. */
3133 static GTY (()) hash_table
<variable_value_hasher
> *variable_value_hash
;
3135 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
3137 static hashval_t
hash (die_struct
*);
3138 static bool equal (die_struct
*, die_struct
*);
3141 /* A hash table of references to DIE's that describe COMMON blocks.
3142 The key is DECL_UID() ^ die_parent. */
3143 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
3145 typedef struct GTY(()) die_arg_entry_struct
{
3151 /* Node of the variable location list. */
3152 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3153 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3154 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3155 in mode of the EXPR_LIST node and first EXPR_LIST operand
3156 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3157 location or NULL for padding. For larger bitsizes,
3158 mode is 0 and first operand is a CONCAT with bitsize
3159 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3160 NULL as second operand. */
3162 const char * GTY (()) label
;
3163 struct var_loc_node
* GTY (()) next
;
3166 /* Variable location list. */
3167 struct GTY ((for_user
)) var_loc_list_def
{
3168 struct var_loc_node
* GTY (()) first
;
3170 /* Pointer to the last but one or last element of the
3171 chained list. If the list is empty, both first and
3172 last are NULL, if the list contains just one node
3173 or the last node certainly is not redundant, it points
3174 to the last node, otherwise points to the last but one.
3175 Do not mark it for GC because it is marked through the chain. */
3176 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3178 /* Pointer to the last element before section switch,
3179 if NULL, either sections weren't switched or first
3180 is after section switch. */
3181 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3183 /* DECL_UID of the variable decl. */
3184 unsigned int decl_id
;
3186 typedef struct var_loc_list_def var_loc_list
;
3188 /* Call argument location list. */
3189 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3190 rtx
GTY (()) call_arg_loc_note
;
3191 const char * GTY (()) label
;
3192 tree
GTY (()) block
;
3194 rtx
GTY (()) symbol_ref
;
3195 struct call_arg_loc_node
* GTY (()) next
;
3199 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
3201 typedef const_tree compare_type
;
3203 static hashval_t
hash (var_loc_list
*);
3204 static bool equal (var_loc_list
*, const_tree
);
3207 /* Table of decl location linked lists. */
3208 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
3210 /* Head and tail of call_arg_loc chain. */
3211 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3212 static struct call_arg_loc_node
*call_arg_loc_last
;
3214 /* Number of call sites in the current function. */
3215 static int call_site_count
= -1;
3216 /* Number of tail call sites in the current function. */
3217 static int tail_call_site_count
= -1;
3219 /* A cached location list. */
3220 struct GTY ((for_user
)) cached_dw_loc_list_def
{
3221 /* The DECL_UID of the decl that this entry describes. */
3222 unsigned int decl_id
;
3224 /* The cached location list. */
3225 dw_loc_list_ref loc_list
;
3227 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3229 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3232 typedef const_tree compare_type
;
3234 static hashval_t
hash (cached_dw_loc_list
*);
3235 static bool equal (cached_dw_loc_list
*, const_tree
);
3238 /* Table of cached location lists. */
3239 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3241 /* A vector of references to DIE's that are uniquely identified by their tag,
3242 presence/absence of children DIE's, and list of attribute/value pairs. */
3243 static GTY(()) vec
<dw_die_ref
, va_gc
> *abbrev_die_table
;
3245 /* A hash map to remember the stack usage for DWARF procedures. The value
3246 stored is the stack size difference between before the DWARF procedure
3247 invokation and after it returned. In other words, for a DWARF procedure
3248 that consumes N stack slots and that pushes M ones, this stores M - N. */
3249 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3251 /* A global counter for generating labels for line number data. */
3252 static unsigned int line_info_label_num
;
3254 /* The current table to which we should emit line number information
3255 for the current function. This will be set up at the beginning of
3256 assembly for the function. */
3257 static GTY(()) dw_line_info_table
*cur_line_info_table
;
3259 /* The two default tables of line number info. */
3260 static GTY(()) dw_line_info_table
*text_section_line_info
;
3261 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3263 /* The set of all non-default tables of line number info. */
3264 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3266 /* A flag to tell pubnames/types export if there is an info section to
3268 static bool info_section_emitted
;
3270 /* A pointer to the base of a table that contains a list of publicly
3271 accessible names. */
3272 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3274 /* A pointer to the base of a table that contains a list of publicly
3275 accessible types. */
3276 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3278 /* A pointer to the base of a table that contains a list of macro
3279 defines/undefines (and file start/end markers). */
3280 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3282 /* True if .debug_macinfo or .debug_macros section is going to be
3284 #define have_macinfo \
3285 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3286 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3287 && !macinfo_table->is_empty ())
3289 /* Vector of dies for which we should generate .debug_ranges info. */
3290 static GTY (()) vec
<dw_ranges
, va_gc
> *ranges_table
;
3292 /* Vector of pairs of labels referenced in ranges_table. */
3293 static GTY (()) vec
<dw_ranges_by_label
, va_gc
> *ranges_by_label
;
3295 /* Whether we have location lists that need outputting */
3296 static GTY(()) bool have_location_lists
;
3298 /* Unique label counter. */
3299 static GTY(()) unsigned int loclabel_num
;
3301 /* Unique label counter for point-of-call tables. */
3302 static GTY(()) unsigned int poc_label_num
;
3304 /* The last file entry emitted by maybe_emit_file(). */
3305 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3307 /* Number of internal labels generated by gen_internal_sym(). */
3308 static GTY(()) int label_num
;
3310 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3312 /* Instances of generic types for which we need to generate debug
3313 info that describe their generic parameters and arguments. That
3314 generation needs to happen once all types are properly laid out so
3315 we do it at the end of compilation. */
3316 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3318 /* Offset from the "steady-state frame pointer" to the frame base,
3319 within the current function. */
3320 static HOST_WIDE_INT frame_pointer_fb_offset
;
3321 static bool frame_pointer_fb_offset_valid
;
3323 static vec
<dw_die_ref
> base_types
;
3325 /* Flags to represent a set of attribute classes for attributes that represent
3326 a scalar value (bounds, pointers, ...). */
3329 dw_scalar_form_constant
= 0x01,
3330 dw_scalar_form_exprloc
= 0x02,
3331 dw_scalar_form_reference
= 0x04
3334 /* Forward declarations for functions defined in this file. */
3336 static int is_pseudo_reg (const_rtx
);
3337 static tree
type_main_variant (tree
);
3338 static int is_tagged_type (const_tree
);
3339 static const char *dwarf_tag_name (unsigned);
3340 static const char *dwarf_attr_name (unsigned);
3341 static const char *dwarf_form_name (unsigned);
3342 static tree
decl_ultimate_origin (const_tree
);
3343 static tree
decl_class_context (tree
);
3344 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3345 static inline enum dw_val_class
AT_class (dw_attr_node
*);
3346 static inline unsigned int AT_index (dw_attr_node
*);
3347 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3348 static inline unsigned AT_flag (dw_attr_node
*);
3349 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3350 static inline HOST_WIDE_INT
AT_int (dw_attr_node
*);
3351 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3352 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_node
*);
3353 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3354 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3355 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3356 unsigned int, unsigned char *);
3357 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3358 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3359 static inline const char *AT_string (dw_attr_node
*);
3360 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3361 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3362 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3363 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3364 static inline int AT_ref_external (dw_attr_node
*);
3365 static inline void set_AT_ref_external (dw_attr_node
*, int);
3366 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3367 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3368 static inline dw_loc_descr_ref
AT_loc (dw_attr_node
*);
3369 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3371 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3372 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3373 static void remove_addr_table_entry (addr_table_entry
*);
3374 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3375 static inline rtx
AT_addr (dw_attr_node
*);
3376 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3377 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3378 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3379 static void add_AT_loclistsptr (dw_die_ref
, enum dwarf_attribute
,
3381 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3382 unsigned HOST_WIDE_INT
);
3383 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3384 unsigned long, bool);
3385 static inline const char *AT_lbl (dw_attr_node
*);
3386 static dw_attr_node
*get_AT (dw_die_ref
, enum dwarf_attribute
);
3387 static const char *get_AT_low_pc (dw_die_ref
);
3388 static const char *get_AT_hi_pc (dw_die_ref
);
3389 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3390 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3391 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3392 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3393 static bool is_cxx (void);
3394 static bool is_cxx (const_tree
);
3395 static bool is_fortran (void);
3396 static bool is_ada (void);
3397 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3398 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3399 static void add_child_die (dw_die_ref
, dw_die_ref
);
3400 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3401 static dw_die_ref
lookup_type_die (tree
);
3402 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3403 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3404 static void equate_type_number_to_die (tree
, dw_die_ref
);
3405 static dw_die_ref
lookup_decl_die (tree
);
3406 static var_loc_list
*lookup_decl_loc (const_tree
);
3407 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3408 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3409 static void print_spaces (FILE *);
3410 static void print_die (dw_die_ref
, FILE *);
3411 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3412 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3413 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3414 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3415 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3416 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3417 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3418 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3419 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3420 struct md5_ctx
*, int *);
3421 struct checksum_attributes
;
3422 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3423 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3424 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3425 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3426 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3427 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3428 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3429 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3430 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3431 static void compute_section_prefix (dw_die_ref
);
3432 static int is_type_die (dw_die_ref
);
3433 static int is_comdat_die (dw_die_ref
);
3434 static int is_symbol_die (dw_die_ref
);
3435 static inline bool is_template_instantiation (dw_die_ref
);
3436 static void assign_symbol_names (dw_die_ref
);
3437 static void break_out_includes (dw_die_ref
);
3438 static int is_declaration_die (dw_die_ref
);
3439 static int should_move_die_to_comdat (dw_die_ref
);
3440 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3441 static dw_die_ref
clone_die (dw_die_ref
);
3442 static dw_die_ref
clone_tree (dw_die_ref
);
3443 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3444 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3445 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3446 static dw_die_ref
generate_skeleton (dw_die_ref
);
3447 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3450 static void break_out_comdat_types (dw_die_ref
);
3451 static void copy_decls_for_unworthy_types (dw_die_ref
);
3453 static void add_sibling_attributes (dw_die_ref
);
3454 static void output_location_lists (dw_die_ref
);
3455 static int constant_size (unsigned HOST_WIDE_INT
);
3456 static unsigned long size_of_die (dw_die_ref
);
3457 static void calc_die_sizes (dw_die_ref
);
3458 static void calc_base_type_die_sizes (void);
3459 static void mark_dies (dw_die_ref
);
3460 static void unmark_dies (dw_die_ref
);
3461 static void unmark_all_dies (dw_die_ref
);
3462 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3463 static unsigned long size_of_aranges (void);
3464 static enum dwarf_form
value_format (dw_attr_node
*);
3465 static void output_value_format (dw_attr_node
*);
3466 static void output_abbrev_section (void);
3467 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3468 static void output_die_symbol (dw_die_ref
);
3469 static void output_die (dw_die_ref
);
3470 static void output_compilation_unit_header (enum dwarf_unit_type
);
3471 static void output_comp_unit (dw_die_ref
, int, const unsigned char *);
3472 static void output_comdat_type_unit (comdat_type_node
*);
3473 static const char *dwarf2_name (tree
, int);
3474 static void add_pubname (tree
, dw_die_ref
);
3475 static void add_enumerator_pubname (const char *, dw_die_ref
);
3476 static void add_pubname_string (const char *, dw_die_ref
);
3477 static void add_pubtype (tree
, dw_die_ref
);
3478 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3479 static void output_aranges (void);
3480 static unsigned int add_ranges (const_tree
, bool = false);
3481 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3483 static void output_ranges (void);
3484 static dw_line_info_table
*new_line_info_table (void);
3485 static void output_line_info (bool);
3486 static void output_file_names (void);
3487 static dw_die_ref
base_type_die (tree
, bool);
3488 static int is_base_type (tree
);
3489 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3490 static int decl_quals (const_tree
);
3491 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3492 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3493 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3494 static int type_is_enum (const_tree
);
3495 static unsigned int dbx_reg_number (const_rtx
);
3496 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3497 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3498 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3499 enum var_init_status
);
3500 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3501 enum var_init_status
);
3502 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3503 enum var_init_status
);
3504 static int is_based_loc (const_rtx
);
3505 static bool resolve_one_addr (rtx
*);
3506 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3507 enum var_init_status
);
3508 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3509 enum var_init_status
);
3510 struct loc_descr_context
;
3511 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3512 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3513 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3514 struct loc_descr_context
*);
3515 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3516 struct loc_descr_context
*);
3517 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3518 static tree
field_type (const_tree
);
3519 static unsigned int simple_type_align_in_bits (const_tree
);
3520 static unsigned int simple_decl_align_in_bits (const_tree
);
3521 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3523 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3525 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3527 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3528 struct vlr_context
*);
3529 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3530 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3531 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3532 static void insert_float (const_rtx
, unsigned char *);
3533 static rtx
rtl_for_decl_location (tree
);
3534 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3535 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3536 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3537 static void add_name_attribute (dw_die_ref
, const char *);
3538 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3539 static void add_comp_dir_attribute (dw_die_ref
);
3540 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3541 struct loc_descr_context
*);
3542 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3543 struct loc_descr_context
*);
3544 static void add_subscript_info (dw_die_ref
, tree
, bool);
3545 static void add_byte_size_attribute (dw_die_ref
, tree
);
3546 static void add_alignment_attribute (dw_die_ref
, tree
);
3547 static inline void add_bit_offset_attribute (dw_die_ref
, tree
,
3548 struct vlr_context
*);
3549 static void add_bit_size_attribute (dw_die_ref
, tree
);
3550 static void add_prototyped_attribute (dw_die_ref
, tree
);
3551 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3552 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3553 static void add_src_coords_attributes (dw_die_ref
, tree
);
3554 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
, bool = false);
3555 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3556 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3557 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3558 static void push_decl_scope (tree
);
3559 static void pop_decl_scope (void);
3560 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3561 static inline int local_scope_p (dw_die_ref
);
3562 static inline int class_scope_p (dw_die_ref
);
3563 static inline int class_or_namespace_scope_p (dw_die_ref
);
3564 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3565 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3566 static const char *type_tag (const_tree
);
3567 static tree
member_declared_type (const_tree
);
3569 static const char *decl_start_label (tree
);
3571 static void gen_array_type_die (tree
, dw_die_ref
);
3572 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3574 static void gen_entry_point_die (tree
, dw_die_ref
);
3576 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3577 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3578 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3579 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3580 static void gen_formal_types_die (tree
, dw_die_ref
);
3581 static void gen_subprogram_die (tree
, dw_die_ref
);
3582 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3583 static void gen_const_die (tree
, dw_die_ref
);
3584 static void gen_label_die (tree
, dw_die_ref
);
3585 static void gen_lexical_block_die (tree
, dw_die_ref
);
3586 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3587 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3588 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3589 static dw_die_ref
gen_compile_unit_die (const char *);
3590 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3591 static void gen_member_die (tree
, dw_die_ref
);
3592 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3593 enum debug_info_usage
);
3594 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3595 static void gen_typedef_die (tree
, dw_die_ref
);
3596 static void gen_type_die (tree
, dw_die_ref
);
3597 static void gen_block_die (tree
, dw_die_ref
);
3598 static void decls_for_scope (tree
, dw_die_ref
);
3599 static bool is_naming_typedef_decl (const_tree
);
3600 static inline dw_die_ref
get_context_die (tree
);
3601 static void gen_namespace_die (tree
, dw_die_ref
);
3602 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3603 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3604 static dw_die_ref
force_decl_die (tree
);
3605 static dw_die_ref
force_type_die (tree
);
3606 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3607 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3608 static struct dwarf_file_data
* lookup_filename (const char *);
3609 static void retry_incomplete_types (void);
3610 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3611 static void gen_generic_params_dies (tree
);
3612 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3613 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3614 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3615 static int file_info_cmp (const void *, const void *);
3616 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3617 const char *, const char *);
3618 static void output_loc_list (dw_loc_list_ref
);
3619 static char *gen_internal_sym (const char *);
3620 static bool want_pubnames (void);
3622 static void prune_unmark_dies (dw_die_ref
);
3623 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3624 static void prune_unused_types_mark (dw_die_ref
, int);
3625 static void prune_unused_types_walk (dw_die_ref
);
3626 static void prune_unused_types_walk_attribs (dw_die_ref
);
3627 static void prune_unused_types_prune (dw_die_ref
);
3628 static void prune_unused_types (void);
3629 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3630 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3631 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3632 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3633 const char *, const char *);
3634 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3635 static void gen_remaining_tmpl_value_param_die_attribute (void);
3636 static bool generic_type_p (tree
);
3637 static void schedule_generic_params_dies_gen (tree t
);
3638 static void gen_scheduled_generic_parms_dies (void);
3639 static void resolve_variable_values (void);
3641 static const char *comp_dir_string (void);
3643 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3645 /* enum for tracking thread-local variables whose address is really an offset
3646 relative to the TLS pointer, which will need link-time relocation, but will
3647 not need relocation by the DWARF consumer. */
3655 /* Return the operator to use for an address of a variable. For dtprel_true, we
3656 use DW_OP_const*. For regular variables, which need both link-time
3657 relocation and consumer-level relocation (e.g., to account for shared objects
3658 loaded at a random address), we use DW_OP_addr*. */
3660 static inline enum dwarf_location_atom
3661 dw_addr_op (enum dtprel_bool dtprel
)
3663 if (dtprel
== dtprel_true
)
3664 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3665 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3667 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3670 /* Return a pointer to a newly allocated address location description. If
3671 dwarf_split_debug_info is true, then record the address with the appropriate
3673 static inline dw_loc_descr_ref
3674 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3676 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3678 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3679 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3680 ref
->dtprel
= dtprel
;
3681 if (dwarf_split_debug_info
)
3682 ref
->dw_loc_oprnd1
.val_entry
3683 = add_addr_table_entry (addr
,
3684 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3686 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3691 /* Section names used to hold DWARF debugging information. */
3693 #ifndef DEBUG_INFO_SECTION
3694 #define DEBUG_INFO_SECTION ".debug_info"
3696 #ifndef DEBUG_DWO_INFO_SECTION
3697 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3699 #ifndef DEBUG_ABBREV_SECTION
3700 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3702 #ifndef DEBUG_DWO_ABBREV_SECTION
3703 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3705 #ifndef DEBUG_ARANGES_SECTION
3706 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3708 #ifndef DEBUG_ADDR_SECTION
3709 #define DEBUG_ADDR_SECTION ".debug_addr"
3711 #ifndef DEBUG_MACINFO_SECTION
3712 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3714 #ifndef DEBUG_DWO_MACINFO_SECTION
3715 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3717 #ifndef DEBUG_DWO_MACRO_SECTION
3718 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3720 #ifndef DEBUG_MACRO_SECTION
3721 #define DEBUG_MACRO_SECTION ".debug_macro"
3723 #ifndef DEBUG_LINE_SECTION
3724 #define DEBUG_LINE_SECTION ".debug_line"
3726 #ifndef DEBUG_DWO_LINE_SECTION
3727 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3729 #ifndef DEBUG_LOC_SECTION
3730 #define DEBUG_LOC_SECTION ".debug_loc"
3732 #ifndef DEBUG_DWO_LOC_SECTION
3733 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3735 #ifndef DEBUG_LOCLISTS_SECTION
3736 #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
3738 #ifndef DEBUG_DWO_LOCLISTS_SECTION
3739 #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
3741 #ifndef DEBUG_PUBNAMES_SECTION
3742 #define DEBUG_PUBNAMES_SECTION \
3743 ((debug_generate_pub_sections == 2) \
3744 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3746 #ifndef DEBUG_PUBTYPES_SECTION
3747 #define DEBUG_PUBTYPES_SECTION \
3748 ((debug_generate_pub_sections == 2) \
3749 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3751 #ifndef DEBUG_STR_OFFSETS_SECTION
3752 #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
3754 #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
3755 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3757 #ifndef DEBUG_STR_DWO_SECTION
3758 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3760 #ifndef DEBUG_STR_SECTION
3761 #define DEBUG_STR_SECTION ".debug_str"
3763 #ifndef DEBUG_RANGES_SECTION
3764 #define DEBUG_RANGES_SECTION ".debug_ranges"
3766 #ifndef DEBUG_RNGLISTS_SECTION
3767 #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
3769 #ifndef DEBUG_LINE_STR_SECTION
3770 #define DEBUG_LINE_STR_SECTION ".debug_line_str"
3773 /* Standard ELF section names for compiled code and data. */
3774 #ifndef TEXT_SECTION_NAME
3775 #define TEXT_SECTION_NAME ".text"
3778 /* Section flags for .debug_str section. */
3779 #define DEBUG_STR_SECTION_FLAGS \
3780 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3781 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3784 /* Section flags for .debug_str.dwo section. */
3785 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3787 /* Labels we insert at beginning sections we can reference instead of
3788 the section names themselves. */
3790 #ifndef TEXT_SECTION_LABEL
3791 #define TEXT_SECTION_LABEL "Ltext"
3793 #ifndef COLD_TEXT_SECTION_LABEL
3794 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3796 #ifndef DEBUG_LINE_SECTION_LABEL
3797 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3799 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3800 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3802 #ifndef DEBUG_INFO_SECTION_LABEL
3803 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3805 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3806 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3808 #ifndef DEBUG_ABBREV_SECTION_LABEL
3809 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3811 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3812 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3814 #ifndef DEBUG_ADDR_SECTION_LABEL
3815 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3817 #ifndef DEBUG_LOC_SECTION_LABEL
3818 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3820 #ifndef DEBUG_RANGES_SECTION_LABEL
3821 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3823 #ifndef DEBUG_MACINFO_SECTION_LABEL
3824 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3826 #ifndef DEBUG_MACRO_SECTION_LABEL
3827 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3829 #define SKELETON_COMP_DIE_ABBREV 1
3830 #define SKELETON_TYPE_DIE_ABBREV 2
3832 /* Definitions of defaults for formats and names of various special
3833 (artificial) labels which may be generated within this file (when the -g
3834 options is used and DWARF2_DEBUGGING_INFO is in effect.
3835 If necessary, these may be overridden from within the tm.h file, but
3836 typically, overriding these defaults is unnecessary. */
3838 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3839 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3840 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3841 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3842 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3843 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3844 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3845 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3846 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3847 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3848 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3849 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3850 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3851 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3852 static char ranges_base_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3854 #ifndef TEXT_END_LABEL
3855 #define TEXT_END_LABEL "Letext"
3857 #ifndef COLD_END_LABEL
3858 #define COLD_END_LABEL "Letext_cold"
3860 #ifndef BLOCK_BEGIN_LABEL
3861 #define BLOCK_BEGIN_LABEL "LBB"
3863 #ifndef BLOCK_END_LABEL
3864 #define BLOCK_END_LABEL "LBE"
3866 #ifndef LINE_CODE_LABEL
3867 #define LINE_CODE_LABEL "LM"
3871 /* Return the root of the DIE's built for the current compilation unit. */
3873 comp_unit_die (void)
3875 if (!single_comp_unit_die
)
3876 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3877 return single_comp_unit_die
;
3880 /* We allow a language front-end to designate a function that is to be
3881 called to "demangle" any name before it is put into a DIE. */
3883 static const char *(*demangle_name_func
) (const char *);
3886 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3888 demangle_name_func
= func
;
3891 /* Test if rtl node points to a pseudo register. */
3894 is_pseudo_reg (const_rtx rtl
)
3896 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3897 || (GET_CODE (rtl
) == SUBREG
3898 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3901 /* Return a reference to a type, with its const and volatile qualifiers
3905 type_main_variant (tree type
)
3907 type
= TYPE_MAIN_VARIANT (type
);
3909 /* ??? There really should be only one main variant among any group of
3910 variants of a given type (and all of the MAIN_VARIANT values for all
3911 members of the group should point to that one type) but sometimes the C
3912 front-end messes this up for array types, so we work around that bug
3914 if (TREE_CODE (type
) == ARRAY_TYPE
)
3915 while (type
!= TYPE_MAIN_VARIANT (type
))
3916 type
= TYPE_MAIN_VARIANT (type
);
3921 /* Return nonzero if the given type node represents a tagged type. */
3924 is_tagged_type (const_tree type
)
3926 enum tree_code code
= TREE_CODE (type
);
3928 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3929 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3932 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3935 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3937 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3940 /* Return die_offset of a DIE reference to a base type. */
3942 static unsigned long int
3943 get_base_type_offset (dw_die_ref ref
)
3945 if (ref
->die_offset
)
3946 return ref
->die_offset
;
3947 if (comp_unit_die ()->die_abbrev
)
3949 calc_base_type_die_sizes ();
3950 gcc_assert (ref
->die_offset
);
3952 return ref
->die_offset
;
3955 /* Return die_offset of a DIE reference other than base type. */
3957 static unsigned long int
3958 get_ref_die_offset (dw_die_ref ref
)
3960 gcc_assert (ref
->die_offset
);
3961 return ref
->die_offset
;
3964 /* Convert a DIE tag into its string name. */
3967 dwarf_tag_name (unsigned int tag
)
3969 const char *name
= get_DW_TAG_name (tag
);
3974 return "DW_TAG_<unknown>";
3977 /* Convert a DWARF attribute code into its string name. */
3980 dwarf_attr_name (unsigned int attr
)
3986 #if VMS_DEBUGGING_INFO
3987 case DW_AT_HP_prologue
:
3988 return "DW_AT_HP_prologue";
3990 case DW_AT_MIPS_loop_unroll_factor
:
3991 return "DW_AT_MIPS_loop_unroll_factor";
3994 #if VMS_DEBUGGING_INFO
3995 case DW_AT_HP_epilogue
:
3996 return "DW_AT_HP_epilogue";
3998 case DW_AT_MIPS_stride
:
3999 return "DW_AT_MIPS_stride";
4003 name
= get_DW_AT_name (attr
);
4008 return "DW_AT_<unknown>";
4011 /* Convert a DWARF value form code into its string name. */
4014 dwarf_form_name (unsigned int form
)
4016 const char *name
= get_DW_FORM_name (form
);
4021 return "DW_FORM_<unknown>";
4024 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4025 instance of an inlined instance of a decl which is local to an inline
4026 function, so we have to trace all of the way back through the origin chain
4027 to find out what sort of node actually served as the original seed for the
4031 decl_ultimate_origin (const_tree decl
)
4033 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4036 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4037 we're trying to output the abstract instance of this function. */
4038 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4041 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4042 most distant ancestor, this should never happen. */
4043 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4045 return DECL_ABSTRACT_ORIGIN (decl
);
4048 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4049 of a virtual function may refer to a base class, so we check the 'this'
4053 decl_class_context (tree decl
)
4055 tree context
= NULL_TREE
;
4057 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4058 context
= DECL_CONTEXT (decl
);
4060 context
= TYPE_MAIN_VARIANT
4061 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4063 if (context
&& !TYPE_P (context
))
4064 context
= NULL_TREE
;
4069 /* Add an attribute/value pair to a DIE. */
4072 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
4074 /* Maybe this should be an assert? */
4078 vec_safe_reserve (die
->die_attr
, 1);
4079 vec_safe_push (die
->die_attr
, *attr
);
4082 static inline enum dw_val_class
4083 AT_class (dw_attr_node
*a
)
4085 return a
->dw_attr_val
.val_class
;
4088 /* Return the index for any attribute that will be referenced with a
4089 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
4090 are stored in dw_attr_val.v.val_str for reference counting
4093 static inline unsigned int
4094 AT_index (dw_attr_node
*a
)
4096 if (AT_class (a
) == dw_val_class_str
)
4097 return a
->dw_attr_val
.v
.val_str
->index
;
4098 else if (a
->dw_attr_val
.val_entry
!= NULL
)
4099 return a
->dw_attr_val
.val_entry
->index
;
4103 /* Add a flag value attribute to a DIE. */
4106 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4110 attr
.dw_attr
= attr_kind
;
4111 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4112 attr
.dw_attr_val
.val_entry
= NULL
;
4113 attr
.dw_attr_val
.v
.val_flag
= flag
;
4114 add_dwarf_attr (die
, &attr
);
4117 static inline unsigned
4118 AT_flag (dw_attr_node
*a
)
4120 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4121 return a
->dw_attr_val
.v
.val_flag
;
4124 /* Add a signed integer attribute value to a DIE. */
4127 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4131 attr
.dw_attr
= attr_kind
;
4132 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4133 attr
.dw_attr_val
.val_entry
= NULL
;
4134 attr
.dw_attr_val
.v
.val_int
= int_val
;
4135 add_dwarf_attr (die
, &attr
);
4138 static inline HOST_WIDE_INT
4139 AT_int (dw_attr_node
*a
)
4141 gcc_assert (a
&& (AT_class (a
) == dw_val_class_const
4142 || AT_class (a
) == dw_val_class_const_implicit
));
4143 return a
->dw_attr_val
.v
.val_int
;
4146 /* Add an unsigned integer attribute value to a DIE. */
4149 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4150 unsigned HOST_WIDE_INT unsigned_val
)
4154 attr
.dw_attr
= attr_kind
;
4155 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4156 attr
.dw_attr_val
.val_entry
= NULL
;
4157 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4158 add_dwarf_attr (die
, &attr
);
4161 static inline unsigned HOST_WIDE_INT
4162 AT_unsigned (dw_attr_node
*a
)
4164 gcc_assert (a
&& (AT_class (a
) == dw_val_class_unsigned_const
4165 || AT_class (a
) == dw_val_class_unsigned_const_implicit
));
4166 return a
->dw_attr_val
.v
.val_unsigned
;
4169 /* Add an unsigned wide integer attribute value to a DIE. */
4172 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4177 attr
.dw_attr
= attr_kind
;
4178 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
4179 attr
.dw_attr_val
.val_entry
= NULL
;
4180 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
4181 *attr
.dw_attr_val
.v
.val_wide
= w
;
4182 add_dwarf_attr (die
, &attr
);
4185 /* Add an unsigned double integer attribute value to a DIE. */
4188 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4189 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4193 attr
.dw_attr
= attr_kind
;
4194 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4195 attr
.dw_attr_val
.val_entry
= NULL
;
4196 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4197 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4198 add_dwarf_attr (die
, &attr
);
4201 /* Add a floating point attribute value to a DIE and return it. */
4204 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4205 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4209 attr
.dw_attr
= attr_kind
;
4210 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4211 attr
.dw_attr_val
.val_entry
= NULL
;
4212 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4213 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4214 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4215 add_dwarf_attr (die
, &attr
);
4218 /* Add an 8-byte data attribute value to a DIE. */
4221 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4222 unsigned char data8
[8])
4226 attr
.dw_attr
= attr_kind
;
4227 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4228 attr
.dw_attr_val
.val_entry
= NULL
;
4229 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4230 add_dwarf_attr (die
, &attr
);
4233 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4234 dwarf_split_debug_info, address attributes in dies destined for the
4235 final executable have force_direct set to avoid using indexed
4239 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4245 lbl_id
= xstrdup (lbl_low
);
4246 attr
.dw_attr
= DW_AT_low_pc
;
4247 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4248 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4249 if (dwarf_split_debug_info
&& !force_direct
)
4250 attr
.dw_attr_val
.val_entry
4251 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4253 attr
.dw_attr_val
.val_entry
= NULL
;
4254 add_dwarf_attr (die
, &attr
);
4256 attr
.dw_attr
= DW_AT_high_pc
;
4257 if (dwarf_version
< 4)
4258 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4260 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4261 lbl_id
= xstrdup (lbl_high
);
4262 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4263 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4264 && dwarf_split_debug_info
&& !force_direct
)
4265 attr
.dw_attr_val
.val_entry
4266 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4268 attr
.dw_attr_val
.val_entry
= NULL
;
4269 add_dwarf_attr (die
, &attr
);
4272 /* Hash and equality functions for debug_str_hash. */
4275 indirect_string_hasher::hash (indirect_string_node
*x
)
4277 return htab_hash_string (x
->str
);
4281 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4283 return strcmp (x1
->str
, x2
) == 0;
4286 /* Add STR to the given string hash table. */
4288 static struct indirect_string_node
*
4289 find_AT_string_in_table (const char *str
,
4290 hash_table
<indirect_string_hasher
> *table
)
4292 struct indirect_string_node
*node
;
4294 indirect_string_node
**slot
4295 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
4298 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4299 node
->str
= ggc_strdup (str
);
4309 /* Add STR to the indirect string hash table. */
4311 static struct indirect_string_node
*
4312 find_AT_string (const char *str
)
4314 if (! debug_str_hash
)
4315 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4317 return find_AT_string_in_table (str
, debug_str_hash
);
4320 /* Add a string attribute value to a DIE. */
4323 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4326 struct indirect_string_node
*node
;
4328 node
= find_AT_string (str
);
4330 attr
.dw_attr
= attr_kind
;
4331 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4332 attr
.dw_attr_val
.val_entry
= NULL
;
4333 attr
.dw_attr_val
.v
.val_str
= node
;
4334 add_dwarf_attr (die
, &attr
);
4337 static inline const char *
4338 AT_string (dw_attr_node
*a
)
4340 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4341 return a
->dw_attr_val
.v
.val_str
->str
;
4344 /* Call this function directly to bypass AT_string_form's logic to put
4345 the string inline in the die. */
4348 set_indirect_string (struct indirect_string_node
*node
)
4350 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4351 /* Already indirect is a no op. */
4352 if (node
->form
== DW_FORM_strp
4353 || node
->form
== DW_FORM_line_strp
4354 || node
->form
== DW_FORM_GNU_str_index
)
4356 gcc_assert (node
->label
);
4359 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4360 ++dw2_string_counter
;
4361 node
->label
= xstrdup (label
);
4363 if (!dwarf_split_debug_info
)
4365 node
->form
= DW_FORM_strp
;
4366 node
->index
= NOT_INDEXED
;
4370 node
->form
= DW_FORM_GNU_str_index
;
4371 node
->index
= NO_INDEX_ASSIGNED
;
4375 /* Find out whether a string should be output inline in DIE
4376 or out-of-line in .debug_str section. */
4378 static enum dwarf_form
4379 find_string_form (struct indirect_string_node
*node
)
4386 len
= strlen (node
->str
) + 1;
4388 /* If the string is shorter or equal to the size of the reference, it is
4389 always better to put it inline. */
4390 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4391 return node
->form
= DW_FORM_string
;
4393 /* If we cannot expect the linker to merge strings in .debug_str
4394 section, only put it into .debug_str if it is worth even in this
4396 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4397 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4398 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4399 return node
->form
= DW_FORM_string
;
4401 set_indirect_string (node
);
4406 /* Find out whether the string referenced from the attribute should be
4407 output inline in DIE or out-of-line in .debug_str section. */
4409 static enum dwarf_form
4410 AT_string_form (dw_attr_node
*a
)
4412 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4413 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4416 /* Add a DIE reference attribute value to a DIE. */
4419 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4422 gcc_checking_assert (targ_die
!= NULL
);
4424 /* With LTO we can end up trying to reference something we didn't create
4425 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4426 if (targ_die
== NULL
)
4429 attr
.dw_attr
= attr_kind
;
4430 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4431 attr
.dw_attr_val
.val_entry
= NULL
;
4432 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4433 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4434 add_dwarf_attr (die
, &attr
);
4437 /* Change DIE reference REF to point to NEW_DIE instead. */
4440 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4442 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4443 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4444 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4447 /* Add an AT_specification attribute to a DIE, and also make the back
4448 pointer from the specification to the definition. */
4451 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4453 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4454 gcc_assert (!targ_die
->die_definition
);
4455 targ_die
->die_definition
= die
;
4458 static inline dw_die_ref
4459 AT_ref (dw_attr_node
*a
)
4461 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4462 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4466 AT_ref_external (dw_attr_node
*a
)
4468 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4469 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4475 set_AT_ref_external (dw_attr_node
*a
, int i
)
4477 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4478 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4481 /* Add an FDE reference attribute value to a DIE. */
4484 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4488 attr
.dw_attr
= attr_kind
;
4489 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4490 attr
.dw_attr_val
.val_entry
= NULL
;
4491 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4492 add_dwarf_attr (die
, &attr
);
4495 /* Add a location description attribute value to a DIE. */
4498 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4502 attr
.dw_attr
= attr_kind
;
4503 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4504 attr
.dw_attr_val
.val_entry
= NULL
;
4505 attr
.dw_attr_val
.v
.val_loc
= loc
;
4506 add_dwarf_attr (die
, &attr
);
4509 static inline dw_loc_descr_ref
4510 AT_loc (dw_attr_node
*a
)
4512 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4513 return a
->dw_attr_val
.v
.val_loc
;
4517 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4521 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4524 attr
.dw_attr
= attr_kind
;
4525 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4526 attr
.dw_attr_val
.val_entry
= NULL
;
4527 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4528 add_dwarf_attr (die
, &attr
);
4529 have_location_lists
= true;
4532 static inline dw_loc_list_ref
4533 AT_loc_list (dw_attr_node
*a
)
4535 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4536 return a
->dw_attr_val
.v
.val_loc_list
;
4539 static inline dw_loc_list_ref
*
4540 AT_loc_list_ptr (dw_attr_node
*a
)
4542 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4543 return &a
->dw_attr_val
.v
.val_loc_list
;
4546 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4548 static hashval_t
hash (addr_table_entry
*);
4549 static bool equal (addr_table_entry
*, addr_table_entry
*);
4552 /* Table of entries into the .debug_addr section. */
4554 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4556 /* Hash an address_table_entry. */
4559 addr_hasher::hash (addr_table_entry
*a
)
4561 inchash::hash hstate
;
4567 case ate_kind_rtx_dtprel
:
4570 case ate_kind_label
:
4571 return htab_hash_string (a
->addr
.label
);
4575 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4576 return hstate
.end ();
4579 /* Determine equality for two address_table_entries. */
4582 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4584 if (a1
->kind
!= a2
->kind
)
4589 case ate_kind_rtx_dtprel
:
4590 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4591 case ate_kind_label
:
4592 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4598 /* Initialize an addr_table_entry. */
4601 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4607 case ate_kind_rtx_dtprel
:
4608 e
->addr
.rtl
= (rtx
) addr
;
4610 case ate_kind_label
:
4611 e
->addr
.label
= (char *) addr
;
4615 e
->index
= NO_INDEX_ASSIGNED
;
4618 /* Add attr to the address table entry to the table. Defer setting an
4619 index until output time. */
4621 static addr_table_entry
*
4622 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4624 addr_table_entry
*node
;
4625 addr_table_entry finder
;
4627 gcc_assert (dwarf_split_debug_info
);
4628 if (! addr_index_table
)
4629 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4630 init_addr_table_entry (&finder
, kind
, addr
);
4631 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4633 if (*slot
== HTAB_EMPTY_ENTRY
)
4635 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4636 init_addr_table_entry (node
, kind
, addr
);
4646 /* Remove an entry from the addr table by decrementing its refcount.
4647 Strictly, decrementing the refcount would be enough, but the
4648 assertion that the entry is actually in the table has found
4652 remove_addr_table_entry (addr_table_entry
*entry
)
4654 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4655 /* After an index is assigned, the table is frozen. */
4656 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4660 /* Given a location list, remove all addresses it refers to from the
4664 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4666 for (; descr
; descr
= descr
->dw_loc_next
)
4667 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4669 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4670 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4674 /* A helper function for dwarf2out_finish called through
4675 htab_traverse. Assign an addr_table_entry its index. All entries
4676 must be collected into the table when this function is called,
4677 because the indexing code relies on htab_traverse to traverse nodes
4678 in the same order for each run. */
4681 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4683 addr_table_entry
*node
= *h
;
4685 /* Don't index unreferenced nodes. */
4686 if (node
->refcount
== 0)
4689 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4690 node
->index
= *index
;
4696 /* Add an address constant attribute value to a DIE. When using
4697 dwarf_split_debug_info, address attributes in dies destined for the
4698 final executable should be direct references--setting the parameter
4699 force_direct ensures this behavior. */
4702 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4707 attr
.dw_attr
= attr_kind
;
4708 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4709 attr
.dw_attr_val
.v
.val_addr
= addr
;
4710 if (dwarf_split_debug_info
&& !force_direct
)
4711 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4713 attr
.dw_attr_val
.val_entry
= NULL
;
4714 add_dwarf_attr (die
, &attr
);
4717 /* Get the RTX from to an address DIE attribute. */
4720 AT_addr (dw_attr_node
*a
)
4722 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4723 return a
->dw_attr_val
.v
.val_addr
;
4726 /* Add a file attribute value to a DIE. */
4729 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4730 struct dwarf_file_data
*fd
)
4734 attr
.dw_attr
= attr_kind
;
4735 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4736 attr
.dw_attr_val
.val_entry
= NULL
;
4737 attr
.dw_attr_val
.v
.val_file
= fd
;
4738 add_dwarf_attr (die
, &attr
);
4741 /* Get the dwarf_file_data from a file DIE attribute. */
4743 static inline struct dwarf_file_data
*
4744 AT_file (dw_attr_node
*a
)
4746 gcc_assert (a
&& (AT_class (a
) == dw_val_class_file
4747 || AT_class (a
) == dw_val_class_file_implicit
));
4748 return a
->dw_attr_val
.v
.val_file
;
4751 /* Add a vms delta attribute value to a DIE. */
4754 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4755 const char *lbl1
, const char *lbl2
)
4759 attr
.dw_attr
= attr_kind
;
4760 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4761 attr
.dw_attr_val
.val_entry
= NULL
;
4762 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4763 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4764 add_dwarf_attr (die
, &attr
);
4767 /* Add a label identifier attribute value to a DIE. */
4770 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4775 attr
.dw_attr
= attr_kind
;
4776 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4777 attr
.dw_attr_val
.val_entry
= NULL
;
4778 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4779 if (dwarf_split_debug_info
)
4780 attr
.dw_attr_val
.val_entry
4781 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4783 add_dwarf_attr (die
, &attr
);
4786 /* Add a section offset attribute value to a DIE, an offset into the
4787 debug_line section. */
4790 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4795 attr
.dw_attr
= attr_kind
;
4796 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4797 attr
.dw_attr_val
.val_entry
= NULL
;
4798 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4799 add_dwarf_attr (die
, &attr
);
4802 /* Add a section offset attribute value to a DIE, an offset into the
4803 debug_loclists section. */
4806 add_AT_loclistsptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4811 attr
.dw_attr
= attr_kind
;
4812 attr
.dw_attr_val
.val_class
= dw_val_class_loclistsptr
;
4813 attr
.dw_attr_val
.val_entry
= NULL
;
4814 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4815 add_dwarf_attr (die
, &attr
);
4818 /* Add a section offset attribute value to a DIE, an offset into the
4819 debug_macinfo section. */
4822 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4827 attr
.dw_attr
= attr_kind
;
4828 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4829 attr
.dw_attr_val
.val_entry
= NULL
;
4830 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4831 add_dwarf_attr (die
, &attr
);
4834 /* Add an offset attribute value to a DIE. */
4837 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4838 unsigned HOST_WIDE_INT offset
)
4842 attr
.dw_attr
= attr_kind
;
4843 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4844 attr
.dw_attr_val
.val_entry
= NULL
;
4845 attr
.dw_attr_val
.v
.val_offset
= offset
;
4846 add_dwarf_attr (die
, &attr
);
4849 /* Add a range_list attribute value to a DIE. When using
4850 dwarf_split_debug_info, address attributes in dies destined for the
4851 final executable should be direct references--setting the parameter
4852 force_direct ensures this behavior. */
4854 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4855 #define RELOCATED_OFFSET (NULL)
4858 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4859 long unsigned int offset
, bool force_direct
)
4863 attr
.dw_attr
= attr_kind
;
4864 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4865 /* For the range_list attribute, use val_entry to store whether the
4866 offset should follow split-debug-info or normal semantics. This
4867 value is read in output_range_list_offset. */
4868 if (dwarf_split_debug_info
&& !force_direct
)
4869 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4871 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4872 attr
.dw_attr_val
.v
.val_offset
= offset
;
4873 add_dwarf_attr (die
, &attr
);
4876 /* Return the start label of a delta attribute. */
4878 static inline const char *
4879 AT_vms_delta1 (dw_attr_node
*a
)
4881 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4882 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4885 /* Return the end label of a delta attribute. */
4887 static inline const char *
4888 AT_vms_delta2 (dw_attr_node
*a
)
4890 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4891 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4894 static inline const char *
4895 AT_lbl (dw_attr_node
*a
)
4897 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4898 || AT_class (a
) == dw_val_class_lineptr
4899 || AT_class (a
) == dw_val_class_macptr
4900 || AT_class (a
) == dw_val_class_loclistsptr
4901 || AT_class (a
) == dw_val_class_high_pc
));
4902 return a
->dw_attr_val
.v
.val_lbl_id
;
4905 /* Get the attribute of type attr_kind. */
4907 static dw_attr_node
*
4908 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4912 dw_die_ref spec
= NULL
;
4917 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4918 if (a
->dw_attr
== attr_kind
)
4920 else if (a
->dw_attr
== DW_AT_specification
4921 || a
->dw_attr
== DW_AT_abstract_origin
)
4925 return get_AT (spec
, attr_kind
);
4930 /* Returns the parent of the declaration of DIE. */
4933 get_die_parent (dw_die_ref die
)
4940 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4941 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4944 return die
->die_parent
;
4947 /* Return the "low pc" attribute value, typically associated with a subprogram
4948 DIE. Return null if the "low pc" attribute is either not present, or if it
4949 cannot be represented as an assembler label identifier. */
4951 static inline const char *
4952 get_AT_low_pc (dw_die_ref die
)
4954 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
4956 return a
? AT_lbl (a
) : NULL
;
4959 /* Return the "high pc" attribute value, typically associated with a subprogram
4960 DIE. Return null if the "high pc" attribute is either not present, or if it
4961 cannot be represented as an assembler label identifier. */
4963 static inline const char *
4964 get_AT_hi_pc (dw_die_ref die
)
4966 dw_attr_node
*a
= get_AT (die
, DW_AT_high_pc
);
4968 return a
? AT_lbl (a
) : NULL
;
4971 /* Return the value of the string attribute designated by ATTR_KIND, or
4972 NULL if it is not present. */
4974 static inline const char *
4975 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4977 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4979 return a
? AT_string (a
) : NULL
;
4982 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4983 if it is not present. */
4986 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4988 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4990 return a
? AT_flag (a
) : 0;
4993 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4994 if it is not present. */
4996 static inline unsigned
4997 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4999 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5001 return a
? AT_unsigned (a
) : 0;
5004 static inline dw_die_ref
5005 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5007 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5009 return a
? AT_ref (a
) : NULL
;
5012 static inline struct dwarf_file_data
*
5013 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5015 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5017 return a
? AT_file (a
) : NULL
;
5020 /* Return TRUE if the language is C++. */
5025 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5027 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
5028 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
5031 /* Return TRUE if DECL was created by the C++ frontend. */
5034 is_cxx (const_tree decl
)
5038 const_tree context
= decl
;
5039 while (context
&& TREE_CODE (context
) != TRANSLATION_UNIT_DECL
)
5041 if (TREE_CODE (context
) == BLOCK
)
5042 context
= BLOCK_SUPERCONTEXT (context
);
5044 context
= get_containing_scope (context
);
5046 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5047 return strncmp (TRANSLATION_UNIT_LANGUAGE (context
), "GNU C++", 7) == 0;
5052 /* Return TRUE if the language is Java. */
5057 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5059 return lang
== DW_LANG_Java
;
5062 /* Return TRUE if the language is Fortran. */
5067 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5069 return (lang
== DW_LANG_Fortran77
5070 || lang
== DW_LANG_Fortran90
5071 || lang
== DW_LANG_Fortran95
5072 || lang
== DW_LANG_Fortran03
5073 || lang
== DW_LANG_Fortran08
);
5076 /* Return TRUE if the language is Ada. */
5081 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5083 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5086 /* Remove the specified attribute if present. Return TRUE if removal
5090 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5098 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5099 if (a
->dw_attr
== attr_kind
)
5101 if (AT_class (a
) == dw_val_class_str
)
5102 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5103 a
->dw_attr_val
.v
.val_str
->refcount
--;
5105 /* vec::ordered_remove should help reduce the number of abbrevs
5107 die
->die_attr
->ordered_remove (ix
);
5113 /* Remove CHILD from its parent. PREV must have the property that
5114 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5117 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5119 gcc_assert (child
->die_parent
== prev
->die_parent
);
5120 gcc_assert (prev
->die_sib
== child
);
5123 gcc_assert (child
->die_parent
->die_child
== child
);
5127 prev
->die_sib
= child
->die_sib
;
5128 if (child
->die_parent
->die_child
== child
)
5129 child
->die_parent
->die_child
= prev
;
5130 child
->die_sib
= NULL
;
5133 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5134 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5137 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
5139 dw_die_ref parent
= old_child
->die_parent
;
5141 gcc_assert (parent
== prev
->die_parent
);
5142 gcc_assert (prev
->die_sib
== old_child
);
5144 new_child
->die_parent
= parent
;
5145 if (prev
== old_child
)
5147 gcc_assert (parent
->die_child
== old_child
);
5148 new_child
->die_sib
= new_child
;
5152 prev
->die_sib
= new_child
;
5153 new_child
->die_sib
= old_child
->die_sib
;
5155 if (old_child
->die_parent
->die_child
== old_child
)
5156 old_child
->die_parent
->die_child
= new_child
;
5157 old_child
->die_sib
= NULL
;
5160 /* Move all children from OLD_PARENT to NEW_PARENT. */
5163 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
5166 new_parent
->die_child
= old_parent
->die_child
;
5167 old_parent
->die_child
= NULL
;
5168 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
5171 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5175 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5181 dw_die_ref prev
= c
;
5183 while (c
->die_tag
== tag
)
5185 remove_child_with_prev (c
, prev
);
5186 c
->die_parent
= NULL
;
5187 /* Might have removed every child. */
5188 if (die
->die_child
== NULL
)
5192 } while (c
!= die
->die_child
);
5195 /* Add a CHILD_DIE as the last child of DIE. */
5198 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5200 /* FIXME this should probably be an assert. */
5201 if (! die
|| ! child_die
)
5203 gcc_assert (die
!= child_die
);
5205 child_die
->die_parent
= die
;
5208 child_die
->die_sib
= die
->die_child
->die_sib
;
5209 die
->die_child
->die_sib
= child_die
;
5212 child_die
->die_sib
= child_die
;
5213 die
->die_child
= child_die
;
5216 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5219 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
5220 dw_die_ref after_die
)
5226 && die
!= child_die
);
5228 child_die
->die_parent
= die
;
5229 child_die
->die_sib
= after_die
->die_sib
;
5230 after_die
->die_sib
= child_die
;
5231 if (die
->die_child
== after_die
)
5232 die
->die_child
= child_die
;
5235 /* Unassociate CHILD from its parent, and make its parent be
5239 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
5241 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5242 if (p
->die_sib
== child
)
5244 remove_child_with_prev (child
, p
);
5247 add_child_die (new_parent
, child
);
5250 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5251 is the specification, to the end of PARENT's list of children.
5252 This is done by removing and re-adding it. */
5255 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5257 /* We want the declaration DIE from inside the class, not the
5258 specification DIE at toplevel. */
5259 if (child
->die_parent
!= parent
)
5261 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5267 gcc_assert (child
->die_parent
== parent
5268 || (child
->die_parent
5269 == get_AT_ref (parent
, DW_AT_specification
)));
5271 reparent_child (child
, parent
);
5274 /* Create and return a new die with a parent of PARENT_DIE. If
5275 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5276 associated tree T must be supplied to determine parenthood
5279 static inline dw_die_ref
5280 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5282 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5284 die
->die_tag
= tag_value
;
5286 if (parent_die
!= NULL
)
5287 add_child_die (parent_die
, die
);
5290 limbo_die_node
*limbo_node
;
5292 /* No DIEs created after early dwarf should end up in limbo,
5293 because the limbo list should not persist past LTO
5295 if (tag_value
!= DW_TAG_compile_unit
5296 /* These are allowed because they're generated while
5297 breaking out COMDAT units late. */
5298 && tag_value
!= DW_TAG_type_unit
5299 && tag_value
!= DW_TAG_skeleton_unit
5301 /* Allow nested functions to live in limbo because they will
5302 only temporarily live there, as decls_for_scope will fix
5304 && (TREE_CODE (t
) != FUNCTION_DECL
5305 || !decl_function_context (t
))
5306 /* Same as nested functions above but for types. Types that
5307 are local to a function will be fixed in
5309 && (!RECORD_OR_UNION_TYPE_P (t
)
5310 || !TYPE_CONTEXT (t
)
5311 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5312 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5313 especially in the ltrans stage, but once we implement LTO
5314 dwarf streaming, we should remove this exception. */
5317 fprintf (stderr
, "symbol ended up in limbo too late:");
5318 debug_generic_stmt (t
);
5322 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5323 limbo_node
->die
= die
;
5324 limbo_node
->created_for
= t
;
5325 limbo_node
->next
= limbo_die_list
;
5326 limbo_die_list
= limbo_node
;
5332 /* Return the DIE associated with the given type specifier. */
5334 static inline dw_die_ref
5335 lookup_type_die (tree type
)
5337 dw_die_ref die
= TYPE_SYMTAB_DIE (type
);
5338 if (die
&& die
->removed
)
5340 TYPE_SYMTAB_DIE (type
) = NULL
;
5346 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5347 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5348 anonymous type instead the one of the naming typedef. */
5350 static inline dw_die_ref
5351 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5354 && TREE_CODE (type
) == RECORD_TYPE
5356 && type_die
->die_tag
== DW_TAG_typedef
5357 && is_naming_typedef_decl (TYPE_NAME (type
)))
5358 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5362 /* Like lookup_type_die, but if type is an anonymous type named by a
5363 typedef[1], return the DIE of the anonymous type instead the one of
5364 the naming typedef. This is because in gen_typedef_die, we did
5365 equate the anonymous struct named by the typedef with the DIE of
5366 the naming typedef. So by default, lookup_type_die on an anonymous
5367 struct yields the DIE of the naming typedef.
5369 [1]: Read the comment of is_naming_typedef_decl to learn about what
5370 a naming typedef is. */
5372 static inline dw_die_ref
5373 lookup_type_die_strip_naming_typedef (tree type
)
5375 dw_die_ref die
= lookup_type_die (type
);
5376 return strip_naming_typedef (type
, die
);
5379 /* Equate a DIE to a given type specifier. */
5382 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5384 TYPE_SYMTAB_DIE (type
) = type_die
;
5387 /* Returns a hash value for X (which really is a die_struct). */
5390 decl_die_hasher::hash (die_node
*x
)
5392 return (hashval_t
) x
->decl_id
;
5395 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5398 decl_die_hasher::equal (die_node
*x
, tree y
)
5400 return (x
->decl_id
== DECL_UID (y
));
5403 /* Return the DIE associated with a given declaration. */
5405 static inline dw_die_ref
5406 lookup_decl_die (tree decl
)
5408 dw_die_ref
*die
= decl_die_table
->find_slot_with_hash (decl
, DECL_UID (decl
),
5412 if ((*die
)->removed
)
5414 decl_die_table
->clear_slot (die
);
5420 /* Returns a hash value for X (which really is a var_loc_list). */
5423 decl_loc_hasher::hash (var_loc_list
*x
)
5425 return (hashval_t
) x
->decl_id
;
5428 /* Return nonzero if decl_id of var_loc_list X is the same as
5432 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5434 return (x
->decl_id
== DECL_UID (y
));
5437 /* Return the var_loc list associated with a given declaration. */
5439 static inline var_loc_list
*
5440 lookup_decl_loc (const_tree decl
)
5442 if (!decl_loc_table
)
5444 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5447 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5450 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5452 return (hashval_t
) x
->decl_id
;
5455 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5459 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5461 return (x
->decl_id
== DECL_UID (y
));
5464 /* Equate a DIE to a particular declaration. */
5467 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5469 unsigned int decl_id
= DECL_UID (decl
);
5471 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5472 decl_die
->decl_id
= decl_id
;
5475 /* Return how many bits covers PIECE EXPR_LIST. */
5477 static HOST_WIDE_INT
5478 decl_piece_bitsize (rtx piece
)
5480 int ret
= (int) GET_MODE (piece
);
5483 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5484 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5485 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5488 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5491 decl_piece_varloc_ptr (rtx piece
)
5493 if ((int) GET_MODE (piece
))
5494 return &XEXP (piece
, 0);
5496 return &XEXP (XEXP (piece
, 0), 1);
5499 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5500 Next is the chain of following piece nodes. */
5502 static rtx_expr_list
*
5503 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5505 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5506 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5508 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5513 /* Return rtx that should be stored into loc field for
5514 LOC_NOTE and BITPOS/BITSIZE. */
5517 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5518 HOST_WIDE_INT bitsize
)
5522 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5524 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5529 /* This function either modifies location piece list *DEST in
5530 place (if SRC and INNER is NULL), or copies location piece list
5531 *SRC to *DEST while modifying it. Location BITPOS is modified
5532 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5533 not copied and if needed some padding around it is added.
5534 When modifying in place, DEST should point to EXPR_LIST where
5535 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5536 to the start of the whole list and INNER points to the EXPR_LIST
5537 where earlier pieces cover PIECE_BITPOS bits. */
5540 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5541 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5542 HOST_WIDE_INT bitsize
, rtx loc_note
)
5545 bool copy
= inner
!= NULL
;
5549 /* First copy all nodes preceding the current bitpos. */
5550 while (src
!= inner
)
5552 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5553 decl_piece_bitsize (*src
), NULL_RTX
);
5554 dest
= &XEXP (*dest
, 1);
5555 src
= &XEXP (*src
, 1);
5558 /* Add padding if needed. */
5559 if (bitpos
!= piece_bitpos
)
5561 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5562 copy
? NULL_RTX
: *dest
);
5563 dest
= &XEXP (*dest
, 1);
5565 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5568 /* A piece with correct bitpos and bitsize already exist,
5569 just update the location for it and return. */
5570 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5573 /* Add the piece that changed. */
5574 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5575 dest
= &XEXP (*dest
, 1);
5576 /* Skip over pieces that overlap it. */
5577 diff
= bitpos
- piece_bitpos
+ bitsize
;
5580 while (diff
> 0 && *src
)
5583 diff
-= decl_piece_bitsize (piece
);
5585 src
= &XEXP (piece
, 1);
5588 *src
= XEXP (piece
, 1);
5589 free_EXPR_LIST_node (piece
);
5592 /* Add padding if needed. */
5593 if (diff
< 0 && *src
)
5597 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5598 dest
= &XEXP (*dest
, 1);
5602 /* Finally copy all nodes following it. */
5605 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5606 decl_piece_bitsize (*src
), NULL_RTX
);
5607 dest
= &XEXP (*dest
, 1);
5608 src
= &XEXP (*src
, 1);
5612 /* Add a variable location node to the linked list for DECL. */
5614 static struct var_loc_node
*
5615 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5617 unsigned int decl_id
;
5619 struct var_loc_node
*loc
= NULL
;
5620 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5622 if (VAR_P (decl
) && DECL_HAS_DEBUG_EXPR_P (decl
))
5624 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5625 if (handled_component_p (realdecl
)
5626 || (TREE_CODE (realdecl
) == MEM_REF
5627 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5629 HOST_WIDE_INT maxsize
;
5632 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
,
5634 if (!DECL_P (innerdecl
)
5635 || DECL_IGNORED_P (innerdecl
)
5636 || TREE_STATIC (innerdecl
)
5638 || bitpos
+ bitsize
> 256
5639 || bitsize
!= maxsize
)
5645 decl_id
= DECL_UID (decl
);
5647 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5650 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5651 temp
->decl_id
= decl_id
;
5657 /* For PARM_DECLs try to keep around the original incoming value,
5658 even if that means we'll emit a zero-range .debug_loc entry. */
5660 && temp
->first
== temp
->last
5661 && TREE_CODE (decl
) == PARM_DECL
5662 && NOTE_P (temp
->first
->loc
)
5663 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5664 && DECL_INCOMING_RTL (decl
)
5665 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5666 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5667 == GET_CODE (DECL_INCOMING_RTL (decl
))
5668 && prev_real_insn (as_a
<rtx_insn
*> (temp
->first
->loc
)) == NULL_RTX
5670 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5671 NOTE_VAR_LOCATION_LOC (loc_note
))
5672 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5673 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5675 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5676 temp
->first
->next
= loc
;
5678 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5680 else if (temp
->last
)
5682 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5683 rtx
*piece_loc
= NULL
, last_loc_note
;
5684 HOST_WIDE_INT piece_bitpos
= 0;
5688 gcc_assert (last
->next
== NULL
);
5690 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5692 piece_loc
= &last
->loc
;
5695 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5696 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5698 piece_bitpos
+= cur_bitsize
;
5699 piece_loc
= &XEXP (*piece_loc
, 1);
5703 /* TEMP->LAST here is either pointer to the last but one or
5704 last element in the chained list, LAST is pointer to the
5706 if (label
&& strcmp (last
->label
, label
) == 0)
5708 /* For SRA optimized variables if there weren't any real
5709 insns since last note, just modify the last node. */
5710 if (piece_loc
!= NULL
)
5712 adjust_piece_list (piece_loc
, NULL
, NULL
,
5713 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5716 /* If the last note doesn't cover any instructions, remove it. */
5717 if (temp
->last
!= last
)
5719 temp
->last
->next
= NULL
;
5722 gcc_assert (strcmp (last
->label
, label
) != 0);
5726 gcc_assert (temp
->first
== temp
->last
5727 || (temp
->first
->next
== temp
->last
5728 && TREE_CODE (decl
) == PARM_DECL
));
5729 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5730 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5734 if (bitsize
== -1 && NOTE_P (last
->loc
))
5735 last_loc_note
= last
->loc
;
5736 else if (piece_loc
!= NULL
5737 && *piece_loc
!= NULL_RTX
5738 && piece_bitpos
== bitpos
5739 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5740 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5742 last_loc_note
= NULL_RTX
;
5743 /* If the current location is the same as the end of the list,
5744 and either both or neither of the locations is uninitialized,
5745 we have nothing to do. */
5746 if (last_loc_note
== NULL_RTX
5747 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5748 NOTE_VAR_LOCATION_LOC (loc_note
)))
5749 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5750 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5751 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5752 == VAR_INIT_STATUS_UNINITIALIZED
)
5753 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5754 == VAR_INIT_STATUS_UNINITIALIZED
))))
5756 /* Add LOC to the end of list and update LAST. If the last
5757 element of the list has been removed above, reuse its
5758 memory for the new node, otherwise allocate a new one. */
5762 memset (loc
, '\0', sizeof (*loc
));
5765 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5766 if (bitsize
== -1 || piece_loc
== NULL
)
5767 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5769 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5770 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5772 /* Ensure TEMP->LAST will point either to the new last but one
5773 element of the chain, or to the last element in it. */
5774 if (last
!= temp
->last
)
5782 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5785 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5790 /* Keep track of the number of spaces used to indent the
5791 output of the debugging routines that print the structure of
5792 the DIE internal representation. */
5793 static int print_indent
;
5795 /* Indent the line the number of spaces given by print_indent. */
5798 print_spaces (FILE *outfile
)
5800 fprintf (outfile
, "%*s", print_indent
, "");
5803 /* Print a type signature in hex. */
5806 print_signature (FILE *outfile
, char *sig
)
5810 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5811 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5815 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
5817 if (discr_value
->pos
)
5818 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
5820 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
5823 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
5825 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5826 RECURSE, output location descriptor operations. */
5829 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
5831 switch (val
->val_class
)
5833 case dw_val_class_addr
:
5834 fprintf (outfile
, "address");
5836 case dw_val_class_offset
:
5837 fprintf (outfile
, "offset");
5839 case dw_val_class_loc
:
5840 fprintf (outfile
, "location descriptor");
5841 if (val
->v
.val_loc
== NULL
)
5842 fprintf (outfile
, " -> <null>\n");
5845 fprintf (outfile
, ":\n");
5847 print_loc_descr (val
->v
.val_loc
, outfile
);
5851 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
5853 case dw_val_class_loc_list
:
5854 fprintf (outfile
, "location list -> label:%s",
5855 val
->v
.val_loc_list
->ll_symbol
);
5857 case dw_val_class_range_list
:
5858 fprintf (outfile
, "range list");
5860 case dw_val_class_const
:
5861 case dw_val_class_const_implicit
:
5862 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
5864 case dw_val_class_unsigned_const
:
5865 case dw_val_class_unsigned_const_implicit
:
5866 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
5868 case dw_val_class_const_double
:
5869 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
5870 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5871 val
->v
.val_double
.high
,
5872 val
->v
.val_double
.low
);
5874 case dw_val_class_wide_int
:
5876 int i
= val
->v
.val_wide
->get_len ();
5877 fprintf (outfile
, "constant (");
5879 if (val
->v
.val_wide
->elt (i
- 1) == 0)
5880 fprintf (outfile
, "0x");
5881 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5882 val
->v
.val_wide
->elt (--i
));
5884 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5885 val
->v
.val_wide
->elt (i
));
5886 fprintf (outfile
, ")");
5889 case dw_val_class_vec
:
5890 fprintf (outfile
, "floating-point or vector constant");
5892 case dw_val_class_flag
:
5893 fprintf (outfile
, "%u", val
->v
.val_flag
);
5895 case dw_val_class_die_ref
:
5896 if (val
->v
.val_die_ref
.die
!= NULL
)
5898 dw_die_ref die
= val
->v
.val_die_ref
.die
;
5900 if (die
->comdat_type_p
)
5902 fprintf (outfile
, "die -> signature: ");
5903 print_signature (outfile
,
5904 die
->die_id
.die_type_node
->signature
);
5906 else if (die
->die_id
.die_symbol
)
5907 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
5909 fprintf (outfile
, "die -> %ld", die
->die_offset
);
5910 fprintf (outfile
, " (%p)", (void *) die
);
5913 fprintf (outfile
, "die -> <null>");
5915 case dw_val_class_vms_delta
:
5916 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5917 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
5919 case dw_val_class_lbl_id
:
5920 case dw_val_class_lineptr
:
5921 case dw_val_class_macptr
:
5922 case dw_val_class_loclistsptr
:
5923 case dw_val_class_high_pc
:
5924 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
5926 case dw_val_class_str
:
5927 if (val
->v
.val_str
->str
!= NULL
)
5928 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
5930 fprintf (outfile
, "<null>");
5932 case dw_val_class_file
:
5933 case dw_val_class_file_implicit
:
5934 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
5935 val
->v
.val_file
->emitted_number
);
5937 case dw_val_class_data8
:
5941 for (i
= 0; i
< 8; i
++)
5942 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
5945 case dw_val_class_discr_value
:
5946 print_discr_value (outfile
, &val
->v
.val_discr_value
);
5948 case dw_val_class_discr_list
:
5949 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
5951 node
= node
->dw_discr_next
)
5953 if (node
->dw_discr_range
)
5955 fprintf (outfile
, " .. ");
5956 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5957 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
5960 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5962 if (node
->dw_discr_next
!= NULL
)
5963 fprintf (outfile
, " | ");
5970 /* Likewise, for a DIE attribute. */
5973 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
5975 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
5979 /* Print the list of operands in the LOC location description to OUTFILE. This
5980 routine is a debugging aid only. */
5983 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
5985 dw_loc_descr_ref l
= loc
;
5989 print_spaces (outfile
);
5990 fprintf (outfile
, "<null>\n");
5994 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5996 print_spaces (outfile
);
5997 fprintf (outfile
, "(%p) %s",
5999 dwarf_stack_op_name (l
->dw_loc_opc
));
6000 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
6002 fprintf (outfile
, " ");
6003 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
6005 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
6007 fprintf (outfile
, ", ");
6008 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
6010 fprintf (outfile
, "\n");
6014 /* Print the information associated with a given DIE, and its children.
6015 This routine is a debugging aid only. */
6018 print_die (dw_die_ref die
, FILE *outfile
)
6024 print_spaces (outfile
);
6025 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
6026 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
6028 print_spaces (outfile
);
6029 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
6030 fprintf (outfile
, " offset: %ld", die
->die_offset
);
6031 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
6033 if (die
->comdat_type_p
)
6035 print_spaces (outfile
);
6036 fprintf (outfile
, " signature: ");
6037 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
6038 fprintf (outfile
, "\n");
6041 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6043 print_spaces (outfile
);
6044 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6046 print_attribute (a
, true, outfile
);
6047 fprintf (outfile
, "\n");
6050 if (die
->die_child
!= NULL
)
6053 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6056 if (print_indent
== 0)
6057 fprintf (outfile
, "\n");
6060 /* Print the list of operations in the LOC location description. */
6063 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
6065 print_loc_descr (loc
, stderr
);
6068 /* Print the information collected for a given DIE. */
6071 debug_dwarf_die (dw_die_ref die
)
6073 print_die (die
, stderr
);
6077 debug (die_struct
&ref
)
6079 print_die (&ref
, stderr
);
6083 debug (die_struct
*ptr
)
6088 fprintf (stderr
, "<nil>\n");
6092 /* Print all DWARF information collected for the compilation unit.
6093 This routine is a debugging aid only. */
6099 print_die (comp_unit_die (), stderr
);
6102 /* Verify the DIE tree structure. */
6105 verify_die (dw_die_ref die
)
6107 gcc_assert (!die
->die_mark
);
6108 if (die
->die_parent
== NULL
6109 && die
->die_sib
== NULL
)
6111 /* Verify the die_sib list is cyclic. */
6118 while (x
&& !x
->die_mark
);
6119 gcc_assert (x
== die
);
6123 /* Verify all dies have the same parent. */
6124 gcc_assert (x
->die_parent
== die
->die_parent
);
6127 /* Verify the child has the proper parent and recurse. */
6128 gcc_assert (x
->die_child
->die_parent
== x
);
6129 verify_die (x
->die_child
);
6134 while (x
&& x
->die_mark
);
6137 /* Sanity checks on DIEs. */
6140 check_die (dw_die_ref die
)
6144 bool inline_found
= false;
6145 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
6146 int n_decl_line
= 0, n_decl_column
= 0, n_decl_file
= 0;
6147 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6152 if (a
->dw_attr_val
.v
.val_unsigned
)
6153 inline_found
= true;
6155 case DW_AT_location
:
6164 case DW_AT_artificial
:
6167 case DW_AT_decl_column
:
6170 case DW_AT_decl_line
:
6173 case DW_AT_decl_file
:
6180 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
6181 || n_decl_column
> 1 || n_decl_line
> 1 || n_decl_file
> 1)
6183 fprintf (stderr
, "Duplicate attributes in DIE:\n");
6184 debug_dwarf_die (die
);
6189 /* A debugging information entry that is a member of an abstract
6190 instance tree [that has DW_AT_inline] should not contain any
6191 attributes which describe aspects of the subroutine which vary
6192 between distinct inlined expansions or distinct out-of-line
6194 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6195 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
6196 && a
->dw_attr
!= DW_AT_high_pc
6197 && a
->dw_attr
!= DW_AT_location
6198 && a
->dw_attr
!= DW_AT_frame_base
6199 && a
->dw_attr
!= DW_AT_call_all_calls
6200 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
6204 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6205 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6206 DIE that marks the start of the DIEs for this include file. */
6209 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
6211 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
6212 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
6214 new_unit
->die_sib
= old_unit
;
6218 /* Close an include-file CU and reopen the enclosing one. */
6221 pop_compile_unit (dw_die_ref old_unit
)
6223 dw_die_ref new_unit
= old_unit
->die_sib
;
6225 old_unit
->die_sib
= NULL
;
6229 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6230 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6231 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6233 /* Calculate the checksum of a location expression. */
6236 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6239 inchash::hash hstate
;
6242 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
6244 hash_loc_operands (loc
, hstate
);
6245 hash
= hstate
.end();
6249 /* Calculate the checksum of an attribute. */
6252 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
6254 dw_loc_descr_ref loc
;
6257 CHECKSUM (at
->dw_attr
);
6259 /* We don't care that this was compiled with a different compiler
6260 snapshot; if the output is the same, that's what matters. */
6261 if (at
->dw_attr
== DW_AT_producer
)
6264 switch (AT_class (at
))
6266 case dw_val_class_const
:
6267 case dw_val_class_const_implicit
:
6268 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
6270 case dw_val_class_unsigned_const
:
6271 case dw_val_class_unsigned_const_implicit
:
6272 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
6274 case dw_val_class_const_double
:
6275 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6277 case dw_val_class_wide_int
:
6278 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6279 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6280 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6282 case dw_val_class_vec
:
6283 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6284 (at
->dw_attr_val
.v
.val_vec
.length
6285 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6287 case dw_val_class_flag
:
6288 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
6290 case dw_val_class_str
:
6291 CHECKSUM_STRING (AT_string (at
));
6294 case dw_val_class_addr
:
6296 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6297 CHECKSUM_STRING (XSTR (r
, 0));
6300 case dw_val_class_offset
:
6301 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6304 case dw_val_class_loc
:
6305 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6306 loc_checksum (loc
, ctx
);
6309 case dw_val_class_die_ref
:
6310 die_checksum (AT_ref (at
), ctx
, mark
);
6313 case dw_val_class_fde_ref
:
6314 case dw_val_class_vms_delta
:
6315 case dw_val_class_lbl_id
:
6316 case dw_val_class_lineptr
:
6317 case dw_val_class_macptr
:
6318 case dw_val_class_loclistsptr
:
6319 case dw_val_class_high_pc
:
6322 case dw_val_class_file
:
6323 case dw_val_class_file_implicit
:
6324 CHECKSUM_STRING (AT_file (at
)->filename
);
6327 case dw_val_class_data8
:
6328 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6336 /* Calculate the checksum of a DIE. */
6339 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6345 /* To avoid infinite recursion. */
6348 CHECKSUM (die
->die_mark
);
6351 die
->die_mark
= ++(*mark
);
6353 CHECKSUM (die
->die_tag
);
6355 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6356 attr_checksum (a
, ctx
, mark
);
6358 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6362 #undef CHECKSUM_BLOCK
6363 #undef CHECKSUM_STRING
6365 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6366 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6367 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6368 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6369 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6370 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6371 #define CHECKSUM_ATTR(FOO) \
6372 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6374 /* Calculate the checksum of a number in signed LEB128 format. */
6377 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6384 byte
= (value
& 0x7f);
6386 more
= !((value
== 0 && (byte
& 0x40) == 0)
6387 || (value
== -1 && (byte
& 0x40) != 0));
6396 /* Calculate the checksum of a number in unsigned LEB128 format. */
6399 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6403 unsigned char byte
= (value
& 0x7f);
6406 /* More bytes to follow. */
6414 /* Checksum the context of the DIE. This adds the names of any
6415 surrounding namespaces or structures to the checksum. */
6418 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
6422 int tag
= die
->die_tag
;
6424 if (tag
!= DW_TAG_namespace
6425 && tag
!= DW_TAG_structure_type
6426 && tag
!= DW_TAG_class_type
)
6429 name
= get_AT_string (die
, DW_AT_name
);
6431 spec
= get_AT_ref (die
, DW_AT_specification
);
6435 if (die
->die_parent
!= NULL
)
6436 checksum_die_context (die
->die_parent
, ctx
);
6438 CHECKSUM_ULEB128 ('C');
6439 CHECKSUM_ULEB128 (tag
);
6441 CHECKSUM_STRING (name
);
6444 /* Calculate the checksum of a location expression. */
6447 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6449 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6450 were emitted as a DW_FORM_sdata instead of a location expression. */
6451 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6453 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6454 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6458 /* Otherwise, just checksum the raw location expression. */
6461 inchash::hash hstate
;
6464 CHECKSUM_ULEB128 (loc
->dtprel
);
6465 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6466 hash_loc_operands (loc
, hstate
);
6467 hash
= hstate
.end ();
6469 loc
= loc
->dw_loc_next
;
6473 /* Calculate the checksum of an attribute. */
6476 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
6477 struct md5_ctx
*ctx
, int *mark
)
6479 dw_loc_descr_ref loc
;
6482 if (AT_class (at
) == dw_val_class_die_ref
)
6484 dw_die_ref target_die
= AT_ref (at
);
6486 /* For pointer and reference types, we checksum only the (qualified)
6487 name of the target type (if there is a name). For friend entries,
6488 we checksum only the (qualified) name of the target type or function.
6489 This allows the checksum to remain the same whether the target type
6490 is complete or not. */
6491 if ((at
->dw_attr
== DW_AT_type
6492 && (tag
== DW_TAG_pointer_type
6493 || tag
== DW_TAG_reference_type
6494 || tag
== DW_TAG_rvalue_reference_type
6495 || tag
== DW_TAG_ptr_to_member_type
))
6496 || (at
->dw_attr
== DW_AT_friend
6497 && tag
== DW_TAG_friend
))
6499 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
6501 if (name_attr
!= NULL
)
6503 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6507 CHECKSUM_ULEB128 ('N');
6508 CHECKSUM_ULEB128 (at
->dw_attr
);
6509 if (decl
->die_parent
!= NULL
)
6510 checksum_die_context (decl
->die_parent
, ctx
);
6511 CHECKSUM_ULEB128 ('E');
6512 CHECKSUM_STRING (AT_string (name_attr
));
6517 /* For all other references to another DIE, we check to see if the
6518 target DIE has already been visited. If it has, we emit a
6519 backward reference; if not, we descend recursively. */
6520 if (target_die
->die_mark
> 0)
6522 CHECKSUM_ULEB128 ('R');
6523 CHECKSUM_ULEB128 (at
->dw_attr
);
6524 CHECKSUM_ULEB128 (target_die
->die_mark
);
6528 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6532 target_die
->die_mark
= ++(*mark
);
6533 CHECKSUM_ULEB128 ('T');
6534 CHECKSUM_ULEB128 (at
->dw_attr
);
6535 if (decl
->die_parent
!= NULL
)
6536 checksum_die_context (decl
->die_parent
, ctx
);
6537 die_checksum_ordered (target_die
, ctx
, mark
);
6542 CHECKSUM_ULEB128 ('A');
6543 CHECKSUM_ULEB128 (at
->dw_attr
);
6545 switch (AT_class (at
))
6547 case dw_val_class_const
:
6548 case dw_val_class_const_implicit
:
6549 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6550 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6553 case dw_val_class_unsigned_const
:
6554 case dw_val_class_unsigned_const_implicit
:
6555 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6556 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6559 case dw_val_class_const_double
:
6560 CHECKSUM_ULEB128 (DW_FORM_block
);
6561 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6562 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6565 case dw_val_class_wide_int
:
6566 CHECKSUM_ULEB128 (DW_FORM_block
);
6567 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6568 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6569 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6570 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6571 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6574 case dw_val_class_vec
:
6575 CHECKSUM_ULEB128 (DW_FORM_block
);
6576 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6577 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6578 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6579 (at
->dw_attr_val
.v
.val_vec
.length
6580 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6583 case dw_val_class_flag
:
6584 CHECKSUM_ULEB128 (DW_FORM_flag
);
6585 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6588 case dw_val_class_str
:
6589 CHECKSUM_ULEB128 (DW_FORM_string
);
6590 CHECKSUM_STRING (AT_string (at
));
6593 case dw_val_class_addr
:
6595 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6596 CHECKSUM_ULEB128 (DW_FORM_string
);
6597 CHECKSUM_STRING (XSTR (r
, 0));
6600 case dw_val_class_offset
:
6601 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6602 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6605 case dw_val_class_loc
:
6606 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6607 loc_checksum_ordered (loc
, ctx
);
6610 case dw_val_class_fde_ref
:
6611 case dw_val_class_lbl_id
:
6612 case dw_val_class_lineptr
:
6613 case dw_val_class_macptr
:
6614 case dw_val_class_loclistsptr
:
6615 case dw_val_class_high_pc
:
6618 case dw_val_class_file
:
6619 case dw_val_class_file_implicit
:
6620 CHECKSUM_ULEB128 (DW_FORM_string
);
6621 CHECKSUM_STRING (AT_file (at
)->filename
);
6624 case dw_val_class_data8
:
6625 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6633 struct checksum_attributes
6635 dw_attr_node
*at_name
;
6636 dw_attr_node
*at_type
;
6637 dw_attr_node
*at_friend
;
6638 dw_attr_node
*at_accessibility
;
6639 dw_attr_node
*at_address_class
;
6640 dw_attr_node
*at_alignment
;
6641 dw_attr_node
*at_allocated
;
6642 dw_attr_node
*at_artificial
;
6643 dw_attr_node
*at_associated
;
6644 dw_attr_node
*at_binary_scale
;
6645 dw_attr_node
*at_bit_offset
;
6646 dw_attr_node
*at_bit_size
;
6647 dw_attr_node
*at_bit_stride
;
6648 dw_attr_node
*at_byte_size
;
6649 dw_attr_node
*at_byte_stride
;
6650 dw_attr_node
*at_const_value
;
6651 dw_attr_node
*at_containing_type
;
6652 dw_attr_node
*at_count
;
6653 dw_attr_node
*at_data_location
;
6654 dw_attr_node
*at_data_member_location
;
6655 dw_attr_node
*at_decimal_scale
;
6656 dw_attr_node
*at_decimal_sign
;
6657 dw_attr_node
*at_default_value
;
6658 dw_attr_node
*at_digit_count
;
6659 dw_attr_node
*at_discr
;
6660 dw_attr_node
*at_discr_list
;
6661 dw_attr_node
*at_discr_value
;
6662 dw_attr_node
*at_encoding
;
6663 dw_attr_node
*at_endianity
;
6664 dw_attr_node
*at_explicit
;
6665 dw_attr_node
*at_is_optional
;
6666 dw_attr_node
*at_location
;
6667 dw_attr_node
*at_lower_bound
;
6668 dw_attr_node
*at_mutable
;
6669 dw_attr_node
*at_ordering
;
6670 dw_attr_node
*at_picture_string
;
6671 dw_attr_node
*at_prototyped
;
6672 dw_attr_node
*at_small
;
6673 dw_attr_node
*at_segment
;
6674 dw_attr_node
*at_string_length
;
6675 dw_attr_node
*at_string_length_bit_size
;
6676 dw_attr_node
*at_string_length_byte_size
;
6677 dw_attr_node
*at_threads_scaled
;
6678 dw_attr_node
*at_upper_bound
;
6679 dw_attr_node
*at_use_location
;
6680 dw_attr_node
*at_use_UTF8
;
6681 dw_attr_node
*at_variable_parameter
;
6682 dw_attr_node
*at_virtuality
;
6683 dw_attr_node
*at_visibility
;
6684 dw_attr_node
*at_vtable_elem_location
;
6687 /* Collect the attributes that we will want to use for the checksum. */
6690 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6695 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6706 attrs
->at_friend
= a
;
6708 case DW_AT_accessibility
:
6709 attrs
->at_accessibility
= a
;
6711 case DW_AT_address_class
:
6712 attrs
->at_address_class
= a
;
6714 case DW_AT_alignment
:
6715 attrs
->at_alignment
= a
;
6717 case DW_AT_allocated
:
6718 attrs
->at_allocated
= a
;
6720 case DW_AT_artificial
:
6721 attrs
->at_artificial
= a
;
6723 case DW_AT_associated
:
6724 attrs
->at_associated
= a
;
6726 case DW_AT_binary_scale
:
6727 attrs
->at_binary_scale
= a
;
6729 case DW_AT_bit_offset
:
6730 attrs
->at_bit_offset
= a
;
6732 case DW_AT_bit_size
:
6733 attrs
->at_bit_size
= a
;
6735 case DW_AT_bit_stride
:
6736 attrs
->at_bit_stride
= a
;
6738 case DW_AT_byte_size
:
6739 attrs
->at_byte_size
= a
;
6741 case DW_AT_byte_stride
:
6742 attrs
->at_byte_stride
= a
;
6744 case DW_AT_const_value
:
6745 attrs
->at_const_value
= a
;
6747 case DW_AT_containing_type
:
6748 attrs
->at_containing_type
= a
;
6751 attrs
->at_count
= a
;
6753 case DW_AT_data_location
:
6754 attrs
->at_data_location
= a
;
6756 case DW_AT_data_member_location
:
6757 attrs
->at_data_member_location
= a
;
6759 case DW_AT_decimal_scale
:
6760 attrs
->at_decimal_scale
= a
;
6762 case DW_AT_decimal_sign
:
6763 attrs
->at_decimal_sign
= a
;
6765 case DW_AT_default_value
:
6766 attrs
->at_default_value
= a
;
6768 case DW_AT_digit_count
:
6769 attrs
->at_digit_count
= a
;
6772 attrs
->at_discr
= a
;
6774 case DW_AT_discr_list
:
6775 attrs
->at_discr_list
= a
;
6777 case DW_AT_discr_value
:
6778 attrs
->at_discr_value
= a
;
6780 case DW_AT_encoding
:
6781 attrs
->at_encoding
= a
;
6783 case DW_AT_endianity
:
6784 attrs
->at_endianity
= a
;
6786 case DW_AT_explicit
:
6787 attrs
->at_explicit
= a
;
6789 case DW_AT_is_optional
:
6790 attrs
->at_is_optional
= a
;
6792 case DW_AT_location
:
6793 attrs
->at_location
= a
;
6795 case DW_AT_lower_bound
:
6796 attrs
->at_lower_bound
= a
;
6799 attrs
->at_mutable
= a
;
6801 case DW_AT_ordering
:
6802 attrs
->at_ordering
= a
;
6804 case DW_AT_picture_string
:
6805 attrs
->at_picture_string
= a
;
6807 case DW_AT_prototyped
:
6808 attrs
->at_prototyped
= a
;
6811 attrs
->at_small
= a
;
6814 attrs
->at_segment
= a
;
6816 case DW_AT_string_length
:
6817 attrs
->at_string_length
= a
;
6819 case DW_AT_string_length_bit_size
:
6820 attrs
->at_string_length_bit_size
= a
;
6822 case DW_AT_string_length_byte_size
:
6823 attrs
->at_string_length_byte_size
= a
;
6825 case DW_AT_threads_scaled
:
6826 attrs
->at_threads_scaled
= a
;
6828 case DW_AT_upper_bound
:
6829 attrs
->at_upper_bound
= a
;
6831 case DW_AT_use_location
:
6832 attrs
->at_use_location
= a
;
6834 case DW_AT_use_UTF8
:
6835 attrs
->at_use_UTF8
= a
;
6837 case DW_AT_variable_parameter
:
6838 attrs
->at_variable_parameter
= a
;
6840 case DW_AT_virtuality
:
6841 attrs
->at_virtuality
= a
;
6843 case DW_AT_visibility
:
6844 attrs
->at_visibility
= a
;
6846 case DW_AT_vtable_elem_location
:
6847 attrs
->at_vtable_elem_location
= a
;
6855 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6858 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6862 struct checksum_attributes attrs
;
6864 CHECKSUM_ULEB128 ('D');
6865 CHECKSUM_ULEB128 (die
->die_tag
);
6867 memset (&attrs
, 0, sizeof (attrs
));
6869 decl
= get_AT_ref (die
, DW_AT_specification
);
6871 collect_checksum_attributes (&attrs
, decl
);
6872 collect_checksum_attributes (&attrs
, die
);
6874 CHECKSUM_ATTR (attrs
.at_name
);
6875 CHECKSUM_ATTR (attrs
.at_accessibility
);
6876 CHECKSUM_ATTR (attrs
.at_address_class
);
6877 CHECKSUM_ATTR (attrs
.at_allocated
);
6878 CHECKSUM_ATTR (attrs
.at_artificial
);
6879 CHECKSUM_ATTR (attrs
.at_associated
);
6880 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6881 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6882 CHECKSUM_ATTR (attrs
.at_bit_size
);
6883 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6884 CHECKSUM_ATTR (attrs
.at_byte_size
);
6885 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6886 CHECKSUM_ATTR (attrs
.at_const_value
);
6887 CHECKSUM_ATTR (attrs
.at_containing_type
);
6888 CHECKSUM_ATTR (attrs
.at_count
);
6889 CHECKSUM_ATTR (attrs
.at_data_location
);
6890 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6891 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6892 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6893 CHECKSUM_ATTR (attrs
.at_default_value
);
6894 CHECKSUM_ATTR (attrs
.at_digit_count
);
6895 CHECKSUM_ATTR (attrs
.at_discr
);
6896 CHECKSUM_ATTR (attrs
.at_discr_list
);
6897 CHECKSUM_ATTR (attrs
.at_discr_value
);
6898 CHECKSUM_ATTR (attrs
.at_encoding
);
6899 CHECKSUM_ATTR (attrs
.at_endianity
);
6900 CHECKSUM_ATTR (attrs
.at_explicit
);
6901 CHECKSUM_ATTR (attrs
.at_is_optional
);
6902 CHECKSUM_ATTR (attrs
.at_location
);
6903 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6904 CHECKSUM_ATTR (attrs
.at_mutable
);
6905 CHECKSUM_ATTR (attrs
.at_ordering
);
6906 CHECKSUM_ATTR (attrs
.at_picture_string
);
6907 CHECKSUM_ATTR (attrs
.at_prototyped
);
6908 CHECKSUM_ATTR (attrs
.at_small
);
6909 CHECKSUM_ATTR (attrs
.at_segment
);
6910 CHECKSUM_ATTR (attrs
.at_string_length
);
6911 CHECKSUM_ATTR (attrs
.at_string_length_bit_size
);
6912 CHECKSUM_ATTR (attrs
.at_string_length_byte_size
);
6913 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6914 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6915 CHECKSUM_ATTR (attrs
.at_use_location
);
6916 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6917 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6918 CHECKSUM_ATTR (attrs
.at_virtuality
);
6919 CHECKSUM_ATTR (attrs
.at_visibility
);
6920 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6921 CHECKSUM_ATTR (attrs
.at_type
);
6922 CHECKSUM_ATTR (attrs
.at_friend
);
6923 CHECKSUM_ATTR (attrs
.at_alignment
);
6925 /* Checksum the child DIEs. */
6928 dw_attr_node
*name_attr
;
6931 name_attr
= get_AT (c
, DW_AT_name
);
6932 if (is_template_instantiation (c
))
6934 /* Ignore instantiations of member type and function templates. */
6936 else if (name_attr
!= NULL
6937 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6939 /* Use a shallow checksum for named nested types and member
6941 CHECKSUM_ULEB128 ('S');
6942 CHECKSUM_ULEB128 (c
->die_tag
);
6943 CHECKSUM_STRING (AT_string (name_attr
));
6947 /* Use a deep checksum for other children. */
6948 /* Mark this DIE so it gets processed when unmarking. */
6949 if (c
->die_mark
== 0)
6951 die_checksum_ordered (c
, ctx
, mark
);
6953 } while (c
!= die
->die_child
);
6955 CHECKSUM_ULEB128 (0);
6958 /* Add a type name and tag to a hash. */
6960 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6962 CHECKSUM_ULEB128 (tag
);
6963 CHECKSUM_STRING (name
);
6967 #undef CHECKSUM_STRING
6968 #undef CHECKSUM_ATTR
6969 #undef CHECKSUM_LEB128
6970 #undef CHECKSUM_ULEB128
6972 /* Generate the type signature for DIE. This is computed by generating an
6973 MD5 checksum over the DIE's tag, its relevant attributes, and its
6974 children. Attributes that are references to other DIEs are processed
6975 by recursion, using the MARK field to prevent infinite recursion.
6976 If the DIE is nested inside a namespace or another type, we also
6977 need to include that context in the signature. The lower 64 bits
6978 of the resulting MD5 checksum comprise the signature. */
6981 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6985 unsigned char checksum
[16];
6990 name
= get_AT_string (die
, DW_AT_name
);
6991 decl
= get_AT_ref (die
, DW_AT_specification
);
6992 parent
= get_die_parent (die
);
6994 /* First, compute a signature for just the type name (and its surrounding
6995 context, if any. This is stored in the type unit DIE for link-time
6996 ODR (one-definition rule) checking. */
6998 if (is_cxx () && name
!= NULL
)
7000 md5_init_ctx (&ctx
);
7002 /* Checksum the names of surrounding namespaces and structures. */
7004 checksum_die_context (parent
, &ctx
);
7006 /* Checksum the current DIE. */
7007 die_odr_checksum (die
->die_tag
, name
, &ctx
);
7008 md5_finish_ctx (&ctx
, checksum
);
7010 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
7013 /* Next, compute the complete type signature. */
7015 md5_init_ctx (&ctx
);
7017 die
->die_mark
= mark
;
7019 /* Checksum the names of surrounding namespaces and structures. */
7021 checksum_die_context (parent
, &ctx
);
7023 /* Checksum the DIE and its children. */
7024 die_checksum_ordered (die
, &ctx
, &mark
);
7025 unmark_all_dies (die
);
7026 md5_finish_ctx (&ctx
, checksum
);
7028 /* Store the signature in the type node and link the type DIE and the
7029 type node together. */
7030 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
7031 DWARF_TYPE_SIGNATURE_SIZE
);
7032 die
->comdat_type_p
= true;
7033 die
->die_id
.die_type_node
= type_node
;
7034 type_node
->type_die
= die
;
7036 /* If the DIE is a specification, link its declaration to the type node
7040 decl
->comdat_type_p
= true;
7041 decl
->die_id
.die_type_node
= type_node
;
7045 /* Do the location expressions look same? */
7047 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
7049 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
7050 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
7051 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
7054 /* Do the values look the same? */
7056 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
7058 dw_loc_descr_ref loc1
, loc2
;
7061 if (v1
->val_class
!= v2
->val_class
)
7064 switch (v1
->val_class
)
7066 case dw_val_class_const
:
7067 case dw_val_class_const_implicit
:
7068 return v1
->v
.val_int
== v2
->v
.val_int
;
7069 case dw_val_class_unsigned_const
:
7070 case dw_val_class_unsigned_const_implicit
:
7071 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
7072 case dw_val_class_const_double
:
7073 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
7074 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
7075 case dw_val_class_wide_int
:
7076 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
7077 case dw_val_class_vec
:
7078 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
7079 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7081 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7082 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7085 case dw_val_class_flag
:
7086 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7087 case dw_val_class_str
:
7088 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7090 case dw_val_class_addr
:
7091 r1
= v1
->v
.val_addr
;
7092 r2
= v2
->v
.val_addr
;
7093 if (GET_CODE (r1
) != GET_CODE (r2
))
7095 return !rtx_equal_p (r1
, r2
);
7097 case dw_val_class_offset
:
7098 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7100 case dw_val_class_loc
:
7101 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7103 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7104 if (!same_loc_p (loc1
, loc2
, mark
))
7106 return !loc1
&& !loc2
;
7108 case dw_val_class_die_ref
:
7109 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7111 case dw_val_class_fde_ref
:
7112 case dw_val_class_vms_delta
:
7113 case dw_val_class_lbl_id
:
7114 case dw_val_class_lineptr
:
7115 case dw_val_class_macptr
:
7116 case dw_val_class_loclistsptr
:
7117 case dw_val_class_high_pc
:
7120 case dw_val_class_file
:
7121 case dw_val_class_file_implicit
:
7122 return v1
->v
.val_file
== v2
->v
.val_file
;
7124 case dw_val_class_data8
:
7125 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
7132 /* Do the attributes look the same? */
7135 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
7137 if (at1
->dw_attr
!= at2
->dw_attr
)
7140 /* We don't care that this was compiled with a different compiler
7141 snapshot; if the output is the same, that's what matters. */
7142 if (at1
->dw_attr
== DW_AT_producer
)
7145 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7148 /* Do the dies look the same? */
7151 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7157 /* To avoid infinite recursion. */
7159 return die1
->die_mark
== die2
->die_mark
;
7160 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7162 if (die1
->die_tag
!= die2
->die_tag
)
7165 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
7168 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
7169 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
7172 c1
= die1
->die_child
;
7173 c2
= die2
->die_child
;
7182 if (!same_die_p (c1
, c2
, mark
))
7186 if (c1
== die1
->die_child
)
7188 if (c2
== die2
->die_child
)
7198 /* Do the dies look the same? Wrapper around same_die_p. */
7201 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
7204 int ret
= same_die_p (die1
, die2
, &mark
);
7206 unmark_all_dies (die1
);
7207 unmark_all_dies (die2
);
7212 /* The prefix to attach to symbols on DIEs in the current comdat debug
7214 static const char *comdat_symbol_id
;
7216 /* The index of the current symbol within the current comdat CU. */
7217 static unsigned int comdat_symbol_number
;
7219 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7220 children, and set comdat_symbol_id accordingly. */
7223 compute_section_prefix (dw_die_ref unit_die
)
7225 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
7226 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
7227 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
7230 unsigned char checksum
[16];
7233 /* Compute the checksum of the DIE, then append part of it as hex digits to
7234 the name filename of the unit. */
7236 md5_init_ctx (&ctx
);
7238 die_checksum (unit_die
, &ctx
, &mark
);
7239 unmark_all_dies (unit_die
);
7240 md5_finish_ctx (&ctx
, checksum
);
7242 sprintf (name
, "%s.", base
);
7243 clean_symbol_name (name
);
7245 p
= name
+ strlen (name
);
7246 for (i
= 0; i
< 4; i
++)
7248 sprintf (p
, "%.2x", checksum
[i
]);
7252 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
7253 comdat_symbol_number
= 0;
7256 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7259 is_type_die (dw_die_ref die
)
7261 switch (die
->die_tag
)
7263 case DW_TAG_array_type
:
7264 case DW_TAG_class_type
:
7265 case DW_TAG_interface_type
:
7266 case DW_TAG_enumeration_type
:
7267 case DW_TAG_pointer_type
:
7268 case DW_TAG_reference_type
:
7269 case DW_TAG_rvalue_reference_type
:
7270 case DW_TAG_string_type
:
7271 case DW_TAG_structure_type
:
7272 case DW_TAG_subroutine_type
:
7273 case DW_TAG_union_type
:
7274 case DW_TAG_ptr_to_member_type
:
7275 case DW_TAG_set_type
:
7276 case DW_TAG_subrange_type
:
7277 case DW_TAG_base_type
:
7278 case DW_TAG_const_type
:
7279 case DW_TAG_file_type
:
7280 case DW_TAG_packed_type
:
7281 case DW_TAG_volatile_type
:
7282 case DW_TAG_typedef
:
7289 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7290 Basically, we want to choose the bits that are likely to be shared between
7291 compilations (types) and leave out the bits that are specific to individual
7292 compilations (functions). */
7295 is_comdat_die (dw_die_ref c
)
7297 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7298 we do for stabs. The advantage is a greater likelihood of sharing between
7299 objects that don't include headers in the same order (and therefore would
7300 put the base types in a different comdat). jason 8/28/00 */
7302 if (c
->die_tag
== DW_TAG_base_type
)
7305 if (c
->die_tag
== DW_TAG_pointer_type
7306 || c
->die_tag
== DW_TAG_reference_type
7307 || c
->die_tag
== DW_TAG_rvalue_reference_type
7308 || c
->die_tag
== DW_TAG_const_type
7309 || c
->die_tag
== DW_TAG_volatile_type
)
7311 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
7313 return t
? is_comdat_die (t
) : 0;
7316 return is_type_die (c
);
7319 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7320 compilation unit. */
7323 is_symbol_die (dw_die_ref c
)
7325 return (is_type_die (c
)
7326 || is_declaration_die (c
)
7327 || c
->die_tag
== DW_TAG_namespace
7328 || c
->die_tag
== DW_TAG_module
);
7331 /* Returns true iff C is a compile-unit DIE. */
7334 is_cu_die (dw_die_ref c
)
7336 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7337 || c
->die_tag
== DW_TAG_skeleton_unit
);
7340 /* Returns true iff C is a unit DIE of some sort. */
7343 is_unit_die (dw_die_ref c
)
7345 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7346 || c
->die_tag
== DW_TAG_partial_unit
7347 || c
->die_tag
== DW_TAG_type_unit
7348 || c
->die_tag
== DW_TAG_skeleton_unit
);
7351 /* Returns true iff C is a namespace DIE. */
7354 is_namespace_die (dw_die_ref c
)
7356 return c
&& c
->die_tag
== DW_TAG_namespace
;
7359 /* Returns true iff C is a class or structure DIE. */
7362 is_class_die (dw_die_ref c
)
7364 return c
&& (c
->die_tag
== DW_TAG_class_type
7365 || c
->die_tag
== DW_TAG_structure_type
);
7368 /* Return non-zero if this DIE is a template parameter. */
7371 is_template_parameter (dw_die_ref die
)
7373 switch (die
->die_tag
)
7375 case DW_TAG_template_type_param
:
7376 case DW_TAG_template_value_param
:
7377 case DW_TAG_GNU_template_template_param
:
7378 case DW_TAG_GNU_template_parameter_pack
:
7385 /* Return non-zero if this DIE represents a template instantiation. */
7388 is_template_instantiation (dw_die_ref die
)
7392 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
7394 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
7399 gen_internal_sym (const char *prefix
)
7401 char buf
[MAX_ARTIFICIAL_LABEL_BYTES
];
7403 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7404 return xstrdup (buf
);
7407 /* Assign symbols to all worthy DIEs under DIE. */
7410 assign_symbol_names (dw_die_ref die
)
7414 if (is_symbol_die (die
) && !die
->comdat_type_p
)
7416 if (comdat_symbol_id
)
7418 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
7420 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
7421 comdat_symbol_id
, comdat_symbol_number
++);
7422 die
->die_id
.die_symbol
= xstrdup (p
);
7425 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
7428 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
7431 struct cu_hash_table_entry
7434 unsigned min_comdat_num
, max_comdat_num
;
7435 struct cu_hash_table_entry
*next
;
7438 /* Helpers to manipulate hash table of CUs. */
7440 struct cu_hash_table_entry_hasher
: pointer_hash
<cu_hash_table_entry
>
7442 typedef die_struct
*compare_type
;
7443 static inline hashval_t
hash (const cu_hash_table_entry
*);
7444 static inline bool equal (const cu_hash_table_entry
*, const die_struct
*);
7445 static inline void remove (cu_hash_table_entry
*);
7449 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry
*entry
)
7451 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
7455 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry
*entry1
,
7456 const die_struct
*entry2
)
7458 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
7462 cu_hash_table_entry_hasher::remove (cu_hash_table_entry
*entry
)
7464 struct cu_hash_table_entry
*next
;
7474 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
7476 /* Check whether we have already seen this CU and set up SYM_NUM
7479 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
7481 struct cu_hash_table_entry dummy
;
7482 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7484 dummy
.max_comdat_num
= 0;
7486 slot
= htable
->find_slot_with_hash (cu
,
7487 htab_hash_string (cu
->die_id
.die_symbol
),
7491 for (; entry
; last
= entry
, entry
= entry
->next
)
7493 if (same_die_p_wrap (cu
, entry
->cu
))
7499 *sym_num
= entry
->min_comdat_num
;
7503 entry
= XCNEW (struct cu_hash_table_entry
);
7505 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7506 entry
->next
= *slot
;
7512 /* Record SYM_NUM to record of CU in HTABLE. */
7514 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
7515 unsigned int sym_num
)
7517 struct cu_hash_table_entry
**slot
, *entry
;
7519 slot
= htable
->find_slot_with_hash (cu
,
7520 htab_hash_string (cu
->die_id
.die_symbol
),
7524 entry
->max_comdat_num
= sym_num
;
7527 /* Traverse the DIE (which is always comp_unit_die), and set up
7528 additional compilation units for each of the include files we see
7529 bracketed by BINCL/EINCL. */
7532 break_out_includes (dw_die_ref die
)
7535 dw_die_ref unit
= NULL
;
7536 limbo_die_node
*node
, **pnode
;
7540 dw_die_ref prev
= c
;
7542 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7543 || (unit
&& is_comdat_die (c
)))
7545 dw_die_ref next
= c
->die_sib
;
7547 /* This DIE is for a secondary CU; remove it from the main one. */
7548 remove_child_with_prev (c
, prev
);
7550 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7551 unit
= push_new_compile_unit (unit
, c
);
7552 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7553 unit
= pop_compile_unit (unit
);
7555 add_child_die (unit
, c
);
7557 if (c
== die
->die_child
)
7560 } while (c
!= die
->die_child
);
7563 /* We can only use this in debugging, since the frontend doesn't check
7564 to make sure that we leave every include file we enter. */
7568 assign_symbol_names (die
);
7569 cu_hash_type
cu_hash_table (10);
7570 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7576 compute_section_prefix (node
->die
);
7577 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
7578 &comdat_symbol_number
);
7579 assign_symbol_names (node
->die
);
7581 *pnode
= node
->next
;
7584 pnode
= &node
->next
;
7585 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
7586 comdat_symbol_number
);
7591 /* Return non-zero if this DIE is a declaration. */
7594 is_declaration_die (dw_die_ref die
)
7599 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7600 if (a
->dw_attr
== DW_AT_declaration
)
7606 /* Return non-zero if this DIE is nested inside a subprogram. */
7609 is_nested_in_subprogram (dw_die_ref die
)
7611 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7615 return local_scope_p (decl
);
7618 /* Return non-zero if this DIE contains a defining declaration of a
7622 contains_subprogram_definition (dw_die_ref die
)
7626 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7628 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7632 /* Return non-zero if this is a type DIE that should be moved to a
7633 COMDAT .debug_types section or .debug_info section with DW_UT_*type
7637 should_move_die_to_comdat (dw_die_ref die
)
7639 switch (die
->die_tag
)
7641 case DW_TAG_class_type
:
7642 case DW_TAG_structure_type
:
7643 case DW_TAG_enumeration_type
:
7644 case DW_TAG_union_type
:
7645 /* Don't move declarations, inlined instances, types nested in a
7646 subprogram, or types that contain subprogram definitions. */
7647 if (is_declaration_die (die
)
7648 || get_AT (die
, DW_AT_abstract_origin
)
7649 || is_nested_in_subprogram (die
)
7650 || contains_subprogram_definition (die
))
7653 case DW_TAG_array_type
:
7654 case DW_TAG_interface_type
:
7655 case DW_TAG_pointer_type
:
7656 case DW_TAG_reference_type
:
7657 case DW_TAG_rvalue_reference_type
:
7658 case DW_TAG_string_type
:
7659 case DW_TAG_subroutine_type
:
7660 case DW_TAG_ptr_to_member_type
:
7661 case DW_TAG_set_type
:
7662 case DW_TAG_subrange_type
:
7663 case DW_TAG_base_type
:
7664 case DW_TAG_const_type
:
7665 case DW_TAG_file_type
:
7666 case DW_TAG_packed_type
:
7667 case DW_TAG_volatile_type
:
7668 case DW_TAG_typedef
:
7674 /* Make a clone of DIE. */
7677 clone_die (dw_die_ref die
)
7683 clone
= ggc_cleared_alloc
<die_node
> ();
7684 clone
->die_tag
= die
->die_tag
;
7686 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7687 add_dwarf_attr (clone
, a
);
7692 /* Make a clone of the tree rooted at DIE. */
7695 clone_tree (dw_die_ref die
)
7698 dw_die_ref clone
= clone_die (die
);
7700 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7705 /* Make a clone of DIE as a declaration. */
7708 clone_as_declaration (dw_die_ref die
)
7715 /* If the DIE is already a declaration, just clone it. */
7716 if (is_declaration_die (die
))
7717 return clone_die (die
);
7719 /* If the DIE is a specification, just clone its declaration DIE. */
7720 decl
= get_AT_ref (die
, DW_AT_specification
);
7723 clone
= clone_die (decl
);
7724 if (die
->comdat_type_p
)
7725 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7729 clone
= ggc_cleared_alloc
<die_node
> ();
7730 clone
->die_tag
= die
->die_tag
;
7732 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7734 /* We don't want to copy over all attributes.
7735 For example we don't want DW_AT_byte_size because otherwise we will no
7736 longer have a declaration and GDB will treat it as a definition. */
7740 case DW_AT_abstract_origin
:
7741 case DW_AT_artificial
:
7742 case DW_AT_containing_type
:
7743 case DW_AT_external
:
7746 case DW_AT_virtuality
:
7747 case DW_AT_linkage_name
:
7748 case DW_AT_MIPS_linkage_name
:
7749 add_dwarf_attr (clone
, a
);
7751 case DW_AT_byte_size
:
7752 case DW_AT_alignment
:
7758 if (die
->comdat_type_p
)
7759 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7761 add_AT_flag (clone
, DW_AT_declaration
, 1);
7766 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7768 struct decl_table_entry
7774 /* Helpers to manipulate hash table of copied declarations. */
7776 /* Hashtable helpers. */
7778 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7780 typedef die_struct
*compare_type
;
7781 static inline hashval_t
hash (const decl_table_entry
*);
7782 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7786 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7788 return htab_hash_pointer (entry
->orig
);
7792 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7793 const die_struct
*entry2
)
7795 return entry1
->orig
== entry2
;
7798 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7800 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7801 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7802 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7803 to check if the ancestor has already been copied into UNIT. */
7806 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7807 decl_hash_type
*decl_table
)
7809 dw_die_ref parent
= die
->die_parent
;
7810 dw_die_ref new_parent
= unit
;
7812 decl_table_entry
**slot
= NULL
;
7813 struct decl_table_entry
*entry
= NULL
;
7817 /* Check if the entry has already been copied to UNIT. */
7818 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7820 if (*slot
!= HTAB_EMPTY_ENTRY
)
7826 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7827 entry
= XCNEW (struct decl_table_entry
);
7835 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7838 if (!is_unit_die (parent
))
7839 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7842 copy
= clone_as_declaration (die
);
7843 add_child_die (new_parent
, copy
);
7847 /* Record the pointer to the copy. */
7853 /* Copy the declaration context to the new type unit DIE. This includes
7854 any surrounding namespace or type declarations. If the DIE has an
7855 AT_specification attribute, it also includes attributes and children
7856 attached to the specification, and returns a pointer to the original
7857 parent of the declaration DIE. Returns NULL otherwise. */
7860 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7863 dw_die_ref new_decl
;
7864 dw_die_ref orig_parent
= NULL
;
7866 decl
= get_AT_ref (die
, DW_AT_specification
);
7875 /* The original DIE will be changed to a declaration, and must
7876 be moved to be a child of the original declaration DIE. */
7877 orig_parent
= decl
->die_parent
;
7879 /* Copy the type node pointer from the new DIE to the original
7880 declaration DIE so we can forward references later. */
7881 decl
->comdat_type_p
= true;
7882 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7884 remove_AT (die
, DW_AT_specification
);
7886 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7888 if (a
->dw_attr
!= DW_AT_name
7889 && a
->dw_attr
!= DW_AT_declaration
7890 && a
->dw_attr
!= DW_AT_external
)
7891 add_dwarf_attr (die
, a
);
7894 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7897 if (decl
->die_parent
!= NULL
7898 && !is_unit_die (decl
->die_parent
))
7900 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7901 if (new_decl
!= NULL
)
7903 remove_AT (new_decl
, DW_AT_signature
);
7904 add_AT_specification (die
, new_decl
);
7911 /* Generate the skeleton ancestor tree for the given NODE, then clone
7912 the DIE and add the clone into the tree. */
7915 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7917 if (node
->new_die
!= NULL
)
7920 node
->new_die
= clone_as_declaration (node
->old_die
);
7922 if (node
->parent
!= NULL
)
7924 generate_skeleton_ancestor_tree (node
->parent
);
7925 add_child_die (node
->parent
->new_die
, node
->new_die
);
7929 /* Generate a skeleton tree of DIEs containing any declarations that are
7930 found in the original tree. We traverse the tree looking for declaration
7931 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7934 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7936 skeleton_chain_node node
;
7939 dw_die_ref prev
= NULL
;
7940 dw_die_ref next
= NULL
;
7942 node
.parent
= parent
;
7944 first
= c
= parent
->old_die
->die_child
;
7948 if (prev
== NULL
|| prev
->die_sib
== c
)
7951 next
= (c
== first
? NULL
: c
->die_sib
);
7953 node
.new_die
= NULL
;
7954 if (is_declaration_die (c
))
7956 if (is_template_instantiation (c
))
7958 /* Instantiated templates do not need to be cloned into the
7959 type unit. Just move the DIE and its children back to
7960 the skeleton tree (in the main CU). */
7961 remove_child_with_prev (c
, prev
);
7962 add_child_die (parent
->new_die
, c
);
7965 else if (c
->comdat_type_p
)
7967 /* This is the skeleton of earlier break_out_comdat_types
7968 type. Clone the existing DIE, but keep the children
7969 under the original (which is in the main CU). */
7970 dw_die_ref clone
= clone_die (c
);
7972 replace_child (c
, clone
, prev
);
7973 generate_skeleton_ancestor_tree (parent
);
7974 add_child_die (parent
->new_die
, c
);
7980 /* Clone the existing DIE, move the original to the skeleton
7981 tree (which is in the main CU), and put the clone, with
7982 all the original's children, where the original came from
7983 (which is about to be moved to the type unit). */
7984 dw_die_ref clone
= clone_die (c
);
7985 move_all_children (c
, clone
);
7987 /* If the original has a DW_AT_object_pointer attribute,
7988 it would now point to a child DIE just moved to the
7989 cloned tree, so we need to remove that attribute from
7991 remove_AT (c
, DW_AT_object_pointer
);
7993 replace_child (c
, clone
, prev
);
7994 generate_skeleton_ancestor_tree (parent
);
7995 add_child_die (parent
->new_die
, c
);
7996 node
.old_die
= clone
;
8001 generate_skeleton_bottom_up (&node
);
8002 } while (next
!= NULL
);
8005 /* Wrapper function for generate_skeleton_bottom_up. */
8008 generate_skeleton (dw_die_ref die
)
8010 skeleton_chain_node node
;
8013 node
.new_die
= NULL
;
8016 /* If this type definition is nested inside another type,
8017 and is not an instantiation of a template, always leave
8018 at least a declaration in its place. */
8019 if (die
->die_parent
!= NULL
8020 && is_type_die (die
->die_parent
)
8021 && !is_template_instantiation (die
))
8022 node
.new_die
= clone_as_declaration (die
);
8024 generate_skeleton_bottom_up (&node
);
8025 return node
.new_die
;
8028 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
8029 declaration. The original DIE is moved to a new compile unit so that
8030 existing references to it follow it to the new location. If any of the
8031 original DIE's descendants is a declaration, we need to replace the
8032 original DIE with a skeleton tree and move the declarations back into the
8036 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
8039 dw_die_ref skeleton
, orig_parent
;
8041 /* Copy the declaration context to the type unit DIE. If the returned
8042 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
8044 orig_parent
= copy_declaration_context (unit
, child
);
8046 skeleton
= generate_skeleton (child
);
8047 if (skeleton
== NULL
)
8048 remove_child_with_prev (child
, prev
);
8051 skeleton
->comdat_type_p
= true;
8052 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
8054 /* If the original DIE was a specification, we need to put
8055 the skeleton under the parent DIE of the declaration.
8056 This leaves the original declaration in the tree, but
8057 it will be pruned later since there are no longer any
8058 references to it. */
8059 if (orig_parent
!= NULL
)
8061 remove_child_with_prev (child
, prev
);
8062 add_child_die (orig_parent
, skeleton
);
8065 replace_child (child
, skeleton
, prev
);
8072 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8073 comdat_type_node
*type_node
,
8074 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
8076 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8077 procedure, put it under TYPE_NODE and return the copy. Continue looking for
8078 DWARF procedure references in the DW_AT_location attribute. */
8081 copy_dwarf_procedure (dw_die_ref die
,
8082 comdat_type_node
*type_node
,
8083 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8085 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
8087 /* DWARF procedures are not supposed to have children... */
8088 gcc_assert (die
->die_child
== NULL
);
8090 /* ... and they are supposed to have only one attribute: DW_AT_location. */
8091 gcc_assert (vec_safe_length (die
->die_attr
) == 1
8092 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
8094 /* Do not copy more than once DWARF procedures. */
8096 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
8100 die_copy
= clone_die (die
);
8101 add_child_die (type_node
->root_die
, die_copy
);
8102 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
8106 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8107 procedures in DIE's attributes. */
8110 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8111 comdat_type_node
*type_node
,
8112 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8117 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
8119 dw_loc_descr_ref loc
;
8121 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
8124 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
8126 switch (loc
->dw_loc_opc
)
8130 case DW_OP_call_ref
:
8131 gcc_assert (loc
->dw_loc_oprnd1
.val_class
8132 == dw_val_class_die_ref
);
8133 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
8134 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
8136 copied_dwarf_procs
);
8145 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8146 rewrite references to point to the copies.
8148 References are looked for in DIE's attributes and recursively in all its
8149 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8150 mapping from old DWARF procedures to their copy. It is used not to copy
8151 twice the same DWARF procedure under TYPE_NODE. */
8154 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
8155 comdat_type_node
*type_node
,
8156 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8160 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
8161 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
8163 copied_dwarf_procs
));
8166 /* Traverse the DIE and set up additional .debug_types or .debug_info
8167 DW_UT_*type sections for each type worthy of being placed in a COMDAT
8171 break_out_comdat_types (dw_die_ref die
)
8175 dw_die_ref prev
= NULL
;
8176 dw_die_ref next
= NULL
;
8177 dw_die_ref unit
= NULL
;
8179 first
= c
= die
->die_child
;
8183 if (prev
== NULL
|| prev
->die_sib
== c
)
8186 next
= (c
== first
? NULL
: c
->die_sib
);
8187 if (should_move_die_to_comdat (c
))
8189 dw_die_ref replacement
;
8190 comdat_type_node
*type_node
;
8192 /* Break out nested types into their own type units. */
8193 break_out_comdat_types (c
);
8195 /* Create a new type unit DIE as the root for the new tree, and
8196 add it to the list of comdat types. */
8197 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8198 add_AT_unsigned (unit
, DW_AT_language
,
8199 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
8200 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
8201 type_node
->root_die
= unit
;
8202 type_node
->next
= comdat_type_list
;
8203 comdat_type_list
= type_node
;
8205 /* Generate the type signature. */
8206 generate_type_signature (c
, type_node
);
8208 /* Copy the declaration context, attributes, and children of the
8209 declaration into the new type unit DIE, then remove this DIE
8210 from the main CU (or replace it with a skeleton if necessary). */
8211 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
8212 type_node
->skeleton_die
= replacement
;
8214 /* Add the DIE to the new compunit. */
8215 add_child_die (unit
, c
);
8217 /* Types can reference DWARF procedures for type size or data location
8218 expressions. Calls in DWARF expressions cannot target procedures
8219 that are not in the same section. So we must copy DWARF procedures
8220 along with this type and then rewrite references to them. */
8221 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
8222 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
8224 if (replacement
!= NULL
)
8227 else if (c
->die_tag
== DW_TAG_namespace
8228 || c
->die_tag
== DW_TAG_class_type
8229 || c
->die_tag
== DW_TAG_structure_type
8230 || c
->die_tag
== DW_TAG_union_type
)
8232 /* Look for nested types that can be broken out. */
8233 break_out_comdat_types (c
);
8235 } while (next
!= NULL
);
8238 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8239 Enter all the cloned children into the hash table decl_table. */
8242 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
8246 struct decl_table_entry
*entry
;
8247 decl_table_entry
**slot
;
8249 if (die
->die_tag
== DW_TAG_subprogram
)
8250 clone
= clone_as_declaration (die
);
8252 clone
= clone_die (die
);
8254 slot
= decl_table
->find_slot_with_hash (die
,
8255 htab_hash_pointer (die
), INSERT
);
8257 /* Assert that DIE isn't in the hash table yet. If it would be there
8258 before, the ancestors would be necessarily there as well, therefore
8259 clone_tree_partial wouldn't be called. */
8260 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8262 entry
= XCNEW (struct decl_table_entry
);
8264 entry
->copy
= clone
;
8267 if (die
->die_tag
!= DW_TAG_subprogram
)
8268 FOR_EACH_CHILD (die
, c
,
8269 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
8274 /* Walk the DIE and its children, looking for references to incomplete
8275 or trivial types that are unmarked (i.e., that are not in the current
8279 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
8285 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8287 if (AT_class (a
) == dw_val_class_die_ref
)
8289 dw_die_ref targ
= AT_ref (a
);
8290 decl_table_entry
**slot
;
8291 struct decl_table_entry
*entry
;
8293 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
8296 slot
= decl_table
->find_slot_with_hash (targ
,
8297 htab_hash_pointer (targ
),
8300 if (*slot
!= HTAB_EMPTY_ENTRY
)
8302 /* TARG has already been copied, so we just need to
8303 modify the reference to point to the copy. */
8305 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
8309 dw_die_ref parent
= unit
;
8310 dw_die_ref copy
= clone_die (targ
);
8312 /* Record in DECL_TABLE that TARG has been copied.
8313 Need to do this now, before the recursive call,
8314 because DECL_TABLE may be expanded and SLOT
8315 would no longer be a valid pointer. */
8316 entry
= XCNEW (struct decl_table_entry
);
8321 /* If TARG is not a declaration DIE, we need to copy its
8323 if (!is_declaration_die (targ
))
8327 add_child_die (copy
,
8328 clone_tree_partial (c
, decl_table
)));
8331 /* Make sure the cloned tree is marked as part of the
8335 /* If TARG has surrounding context, copy its ancestor tree
8336 into the new type unit. */
8337 if (targ
->die_parent
!= NULL
8338 && !is_unit_die (targ
->die_parent
))
8339 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8342 add_child_die (parent
, copy
);
8343 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8345 /* Make sure the newly-copied DIE is walked. If it was
8346 installed in a previously-added context, it won't
8347 get visited otherwise. */
8350 /* Find the highest point of the newly-added tree,
8351 mark each node along the way, and walk from there. */
8352 parent
->die_mark
= 1;
8353 while (parent
->die_parent
8354 && parent
->die_parent
->die_mark
== 0)
8356 parent
= parent
->die_parent
;
8357 parent
->die_mark
= 1;
8359 copy_decls_walk (unit
, parent
, decl_table
);
8365 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8368 /* Copy declarations for "unworthy" types into the new comdat section.
8369 Incomplete types, modified types, and certain other types aren't broken
8370 out into comdat sections of their own, so they don't have a signature,
8371 and we need to copy the declaration into the same section so that we
8372 don't have an external reference. */
8375 copy_decls_for_unworthy_types (dw_die_ref unit
)
8378 decl_hash_type
decl_table (10);
8379 copy_decls_walk (unit
, unit
, &decl_table
);
8383 /* Traverse the DIE and add a sibling attribute if it may have the
8384 effect of speeding up access to siblings. To save some space,
8385 avoid generating sibling attributes for DIE's without children. */
8388 add_sibling_attributes (dw_die_ref die
)
8392 if (! die
->die_child
)
8395 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8396 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8398 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8401 /* Output all location lists for the DIE and its children. */
8404 output_location_lists (dw_die_ref die
)
8410 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8411 if (AT_class (a
) == dw_val_class_loc_list
)
8412 output_loc_list (AT_loc_list (a
));
8414 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
8417 /* During assign_location_list_indexes and output_loclists_offset the
8418 current index, after it the number of assigned indexes (i.e. how
8419 large the .debug_loclists* offset table should be). */
8420 static unsigned int loc_list_idx
;
8422 /* Output all location list offsets for the DIE and its children. */
8425 output_loclists_offsets (dw_die_ref die
)
8431 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8432 if (AT_class (a
) == dw_val_class_loc_list
)
8434 dw_loc_list_ref l
= AT_loc_list (a
);
8435 if (l
->offset_emitted
)
8437 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l
->ll_symbol
,
8438 loc_section_label
, NULL
);
8439 gcc_assert (l
->hash
== loc_list_idx
);
8441 l
->offset_emitted
= true;
8444 FOR_EACH_CHILD (die
, c
, output_loclists_offsets (c
));
8447 /* Recursively set indexes of location lists. */
8450 assign_location_list_indexes (dw_die_ref die
)
8456 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8457 if (AT_class (a
) == dw_val_class_loc_list
)
8459 dw_loc_list_ref list
= AT_loc_list (a
);
8460 if (!list
->num_assigned
)
8462 list
->num_assigned
= true;
8463 list
->hash
= loc_list_idx
++;
8467 FOR_EACH_CHILD (die
, c
, assign_location_list_indexes (c
));
8470 /* We want to limit the number of external references, because they are
8471 larger than local references: a relocation takes multiple words, and
8472 even a sig8 reference is always eight bytes, whereas a local reference
8473 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8474 So if we encounter multiple external references to the same type DIE, we
8475 make a local typedef stub for it and redirect all references there.
8477 This is the element of the hash table for keeping track of these
8487 /* Hashtable helpers. */
8489 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
8491 static inline hashval_t
hash (const external_ref
*);
8492 static inline bool equal (const external_ref
*, const external_ref
*);
8496 external_ref_hasher::hash (const external_ref
*r
)
8498 dw_die_ref die
= r
->type
;
8501 /* We can't use the address of the DIE for hashing, because
8502 that will make the order of the stub DIEs non-deterministic. */
8503 if (! die
->comdat_type_p
)
8504 /* We have a symbol; use it to compute a hash. */
8505 h
= htab_hash_string (die
->die_id
.die_symbol
);
8508 /* We have a type signature; use a subset of the bits as the hash.
8509 The 8-byte signature is at least as large as hashval_t. */
8510 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
8511 memcpy (&h
, type_node
->signature
, sizeof (h
));
8517 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
8519 return r1
->type
== r2
->type
;
8522 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
8524 /* Return a pointer to the external_ref for references to DIE. */
8526 static struct external_ref
*
8527 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
8529 struct external_ref ref
, *ref_p
;
8530 external_ref
**slot
;
8533 slot
= map
->find_slot (&ref
, INSERT
);
8534 if (*slot
!= HTAB_EMPTY_ENTRY
)
8537 ref_p
= XCNEW (struct external_ref
);
8543 /* Subroutine of optimize_external_refs, below.
8545 If we see a type skeleton, record it as our stub. If we see external
8546 references, remember how many we've seen. */
8549 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
8554 struct external_ref
*ref_p
;
8556 if (is_type_die (die
)
8557 && (c
= get_AT_ref (die
, DW_AT_signature
)))
8559 /* This is a local skeleton; use it for local references. */
8560 ref_p
= lookup_external_ref (map
, c
);
8564 /* Scan the DIE references, and remember any that refer to DIEs from
8565 other CUs (i.e. those which are not marked). */
8566 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8567 if (AT_class (a
) == dw_val_class_die_ref
8568 && (c
= AT_ref (a
))->die_mark
== 0
8571 ref_p
= lookup_external_ref (map
, c
);
8575 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
8578 /* htab_traverse callback function for optimize_external_refs, below. SLOT
8579 points to an external_ref, DATA is the CU we're processing. If we don't
8580 already have a local stub, and we have multiple refs, build a stub. */
8583 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
8585 struct external_ref
*ref_p
= *slot
;
8587 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
8589 /* We have multiple references to this type, so build a small stub.
8590 Both of these forms are a bit dodgy from the perspective of the
8591 DWARF standard, since technically they should have names. */
8592 dw_die_ref cu
= data
;
8593 dw_die_ref type
= ref_p
->type
;
8594 dw_die_ref stub
= NULL
;
8596 if (type
->comdat_type_p
)
8598 /* If we refer to this type via sig8, use AT_signature. */
8599 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
8600 add_AT_die_ref (stub
, DW_AT_signature
, type
);
8604 /* Otherwise, use a typedef with no name. */
8605 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
8606 add_AT_die_ref (stub
, DW_AT_type
, type
);
8615 /* DIE is a unit; look through all the DIE references to see if there are
8616 any external references to types, and if so, create local stubs for
8617 them which will be applied in build_abbrev_table. This is useful because
8618 references to local DIEs are smaller. */
8620 static external_ref_hash_type
*
8621 optimize_external_refs (dw_die_ref die
)
8623 external_ref_hash_type
*map
= new external_ref_hash_type (10);
8624 optimize_external_refs_1 (die
, map
);
8625 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
8629 /* The following 3 variables are temporaries that are computed only during the
8630 build_abbrev_table call and used and released during the following
8631 optimize_abbrev_table call. */
8633 /* First abbrev_id that can be optimized based on usage. */
8634 static unsigned int abbrev_opt_start
;
8636 /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
8637 abbrev_id smaller than this, because they must be already sized
8638 during build_abbrev_table). */
8639 static unsigned int abbrev_opt_base_type_end
;
8641 /* Vector of usage counts during build_abbrev_table. Indexed by
8642 abbrev_id - abbrev_opt_start. */
8643 static vec
<unsigned int> abbrev_usage_count
;
8645 /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
8646 static vec
<dw_die_ref
> sorted_abbrev_dies
;
8648 /* The format of each DIE (and its attribute value pairs) is encoded in an
8649 abbreviation table. This routine builds the abbreviation table and assigns
8650 a unique abbreviation id for each abbreviation entry. The children of each
8651 die are visited recursively. */
8654 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
8656 unsigned int abbrev_id
= 0;
8662 /* Scan the DIE references, and replace any that refer to
8663 DIEs from other CUs (i.e. those which are not marked) with
8664 the local stubs we built in optimize_external_refs. */
8665 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8666 if (AT_class (a
) == dw_val_class_die_ref
8667 && (c
= AT_ref (a
))->die_mark
== 0)
8669 struct external_ref
*ref_p
;
8670 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8672 ref_p
= lookup_external_ref (extern_map
, c
);
8673 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8674 change_AT_die_ref (a
, ref_p
->stub
);
8676 /* We aren't changing this reference, so mark it external. */
8677 set_AT_ref_external (a
, 1);
8680 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
8682 dw_attr_node
*die_a
, *abbrev_a
;
8688 if (abbrev
->die_tag
!= die
->die_tag
)
8690 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8693 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8696 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8698 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8699 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8700 || (value_format (abbrev_a
) != value_format (die_a
)))
8710 if (abbrev_id
>= vec_safe_length (abbrev_die_table
))
8712 vec_safe_push (abbrev_die_table
, die
);
8713 if (abbrev_opt_start
)
8714 abbrev_usage_count
.safe_push (0);
8716 if (abbrev_opt_start
&& abbrev_id
>= abbrev_opt_start
)
8718 abbrev_usage_count
[abbrev_id
- abbrev_opt_start
]++;
8719 sorted_abbrev_dies
.safe_push (die
);
8722 die
->die_abbrev
= abbrev_id
;
8723 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8726 /* Callback function for sorted_abbrev_dies vector sorting. We sort
8727 by die_abbrev's usage count, from the most commonly used
8728 abbreviation to the least. */
8731 die_abbrev_cmp (const void *p1
, const void *p2
)
8733 dw_die_ref die1
= *(const dw_die_ref
*) p1
;
8734 dw_die_ref die2
= *(const dw_die_ref
*) p2
;
8736 gcc_checking_assert (die1
->die_abbrev
>= abbrev_opt_start
);
8737 gcc_checking_assert (die2
->die_abbrev
>= abbrev_opt_start
);
8739 if (die1
->die_abbrev
>= abbrev_opt_base_type_end
8740 && die2
->die_abbrev
>= abbrev_opt_base_type_end
)
8742 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8743 > abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8745 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8746 < abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8750 /* Stabilize the sort. */
8751 if (die1
->die_abbrev
< die2
->die_abbrev
)
8753 if (die1
->die_abbrev
> die2
->die_abbrev
)
8759 /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
8760 of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
8761 into dw_val_class_const_implicit or
8762 dw_val_class_unsigned_const_implicit. */
8765 optimize_implicit_const (unsigned int first_id
, unsigned int end
,
8766 vec
<bool> &implicit_consts
)
8768 /* It never makes sense if there is just one DIE using the abbreviation. */
8769 if (end
< first_id
+ 2)
8774 dw_die_ref die
= sorted_abbrev_dies
[first_id
];
8775 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8776 if (implicit_consts
[ix
])
8778 enum dw_val_class new_class
= dw_val_class_none
;
8779 switch (AT_class (a
))
8781 case dw_val_class_unsigned_const
:
8782 if ((HOST_WIDE_INT
) AT_unsigned (a
) < 0)
8785 /* The .debug_abbrev section will grow by
8786 size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
8787 in all the DIEs using that abbreviation. */
8788 if (constant_size (AT_unsigned (a
)) * (end
- first_id
)
8789 <= (unsigned) size_of_sleb128 (AT_unsigned (a
)))
8792 new_class
= dw_val_class_unsigned_const_implicit
;
8795 case dw_val_class_const
:
8796 new_class
= dw_val_class_const_implicit
;
8799 case dw_val_class_file
:
8800 new_class
= dw_val_class_file_implicit
;
8806 for (i
= first_id
; i
< end
; i
++)
8807 (*sorted_abbrev_dies
[i
]->die_attr
)[ix
].dw_attr_val
.val_class
8812 /* Attempt to optimize abbreviation table from abbrev_opt_start
8813 abbreviation above. */
8816 optimize_abbrev_table (void)
8818 if (abbrev_opt_start
8819 && vec_safe_length (abbrev_die_table
) > abbrev_opt_start
8820 && (dwarf_version
>= 5 || vec_safe_length (abbrev_die_table
) > 127))
8822 auto_vec
<bool, 32> implicit_consts
;
8823 sorted_abbrev_dies
.qsort (die_abbrev_cmp
);
8825 unsigned int abbrev_id
= abbrev_opt_start
- 1;
8826 unsigned int first_id
= ~0U;
8827 unsigned int last_abbrev_id
= 0;
8830 if (abbrev_opt_base_type_end
> abbrev_opt_start
)
8831 abbrev_id
= abbrev_opt_base_type_end
- 1;
8832 /* Reassign abbreviation ids from abbrev_opt_start above, so that
8833 most commonly used abbreviations come first. */
8834 FOR_EACH_VEC_ELT (sorted_abbrev_dies
, i
, die
)
8839 /* If calc_base_type_die_sizes has been called, the CU and
8840 base types after it can't be optimized, because we've already
8841 calculated their DIE offsets. We've sorted them first. */
8842 if (die
->die_abbrev
< abbrev_opt_base_type_end
)
8844 if (die
->die_abbrev
!= last_abbrev_id
)
8846 last_abbrev_id
= die
->die_abbrev
;
8847 if (dwarf_version
>= 5 && first_id
!= ~0U)
8848 optimize_implicit_const (first_id
, i
, implicit_consts
);
8850 (*abbrev_die_table
)[abbrev_id
] = die
;
8851 if (dwarf_version
>= 5)
8854 implicit_consts
.truncate (0);
8856 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8857 switch (AT_class (a
))
8859 case dw_val_class_const
:
8860 case dw_val_class_unsigned_const
:
8861 case dw_val_class_file
:
8862 implicit_consts
.safe_push (true);
8865 implicit_consts
.safe_push (false);
8870 else if (dwarf_version
>= 5)
8872 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8873 if (!implicit_consts
[ix
])
8877 dw_attr_node
*other_a
8878 = &(*(*abbrev_die_table
)[abbrev_id
]->die_attr
)[ix
];
8879 if (!dw_val_equal_p (&a
->dw_attr_val
,
8880 &other_a
->dw_attr_val
))
8881 implicit_consts
[ix
] = false;
8884 die
->die_abbrev
= abbrev_id
;
8886 gcc_assert (abbrev_id
== vec_safe_length (abbrev_die_table
) - 1);
8887 if (dwarf_version
>= 5 && first_id
!= ~0U)
8888 optimize_implicit_const (first_id
, i
, implicit_consts
);
8891 abbrev_opt_start
= 0;
8892 abbrev_opt_base_type_end
= 0;
8893 abbrev_usage_count
.release ();
8894 sorted_abbrev_dies
.release ();
8897 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8900 constant_size (unsigned HOST_WIDE_INT value
)
8907 log
= floor_log2 (value
);
8910 log
= 1 << (floor_log2 (log
) + 1);
8915 /* Return the size of a DIE as it is represented in the
8916 .debug_info section. */
8918 static unsigned long
8919 size_of_die (dw_die_ref die
)
8921 unsigned long size
= 0;
8924 enum dwarf_form form
;
8926 size
+= size_of_uleb128 (die
->die_abbrev
);
8927 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8929 switch (AT_class (a
))
8931 case dw_val_class_addr
:
8932 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8934 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8935 size
+= size_of_uleb128 (AT_index (a
));
8938 size
+= DWARF2_ADDR_SIZE
;
8940 case dw_val_class_offset
:
8941 size
+= DWARF_OFFSET_SIZE
;
8943 case dw_val_class_loc
:
8945 unsigned long lsize
= size_of_locs (AT_loc (a
));
8948 if (dwarf_version
>= 4)
8949 size
+= size_of_uleb128 (lsize
);
8951 size
+= constant_size (lsize
);
8955 case dw_val_class_loc_list
:
8956 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
8958 gcc_assert (AT_loc_list (a
)->num_assigned
);
8959 size
+= size_of_uleb128 (AT_loc_list (a
)->hash
);
8962 size
+= DWARF_OFFSET_SIZE
;
8964 case dw_val_class_range_list
:
8965 if (value_format (a
) == DW_FORM_rnglistx
)
8967 gcc_assert (rnglist_idx
);
8968 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
8969 size
+= size_of_uleb128 (r
->idx
);
8972 size
+= DWARF_OFFSET_SIZE
;
8974 case dw_val_class_const
:
8975 size
+= size_of_sleb128 (AT_int (a
));
8977 case dw_val_class_unsigned_const
:
8979 int csize
= constant_size (AT_unsigned (a
));
8980 if (dwarf_version
== 3
8981 && a
->dw_attr
== DW_AT_data_member_location
8983 size
+= size_of_uleb128 (AT_unsigned (a
));
8988 case dw_val_class_const_implicit
:
8989 case dw_val_class_unsigned_const_implicit
:
8990 case dw_val_class_file_implicit
:
8991 /* These occupy no size in the DIE, just an extra sleb128 in
8994 case dw_val_class_const_double
:
8995 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
8996 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
8999 case dw_val_class_wide_int
:
9000 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9001 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
9002 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9003 * HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
9006 case dw_val_class_vec
:
9007 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
9008 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
9009 + a
->dw_attr_val
.v
.val_vec
.length
9010 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
9012 case dw_val_class_flag
:
9013 if (dwarf_version
>= 4)
9014 /* Currently all add_AT_flag calls pass in 1 as last argument,
9015 so DW_FORM_flag_present can be used. If that ever changes,
9016 we'll need to use DW_FORM_flag and have some optimization
9017 in build_abbrev_table that will change those to
9018 DW_FORM_flag_present if it is set to 1 in all DIEs using
9019 the same abbrev entry. */
9020 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9024 case dw_val_class_die_ref
:
9025 if (AT_ref_external (a
))
9027 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
9028 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
9029 is sized by target address length, whereas in DWARF3
9030 it's always sized as an offset. */
9031 if (use_debug_types
)
9032 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
9033 else if (dwarf_version
== 2)
9034 size
+= DWARF2_ADDR_SIZE
;
9036 size
+= DWARF_OFFSET_SIZE
;
9039 size
+= DWARF_OFFSET_SIZE
;
9041 case dw_val_class_fde_ref
:
9042 size
+= DWARF_OFFSET_SIZE
;
9044 case dw_val_class_lbl_id
:
9045 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9047 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9048 size
+= size_of_uleb128 (AT_index (a
));
9051 size
+= DWARF2_ADDR_SIZE
;
9053 case dw_val_class_lineptr
:
9054 case dw_val_class_macptr
:
9055 case dw_val_class_loclistsptr
:
9056 size
+= DWARF_OFFSET_SIZE
;
9058 case dw_val_class_str
:
9059 form
= AT_string_form (a
);
9060 if (form
== DW_FORM_strp
|| form
== DW_FORM_line_strp
)
9061 size
+= DWARF_OFFSET_SIZE
;
9062 else if (form
== DW_FORM_GNU_str_index
)
9063 size
+= size_of_uleb128 (AT_index (a
));
9065 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
9067 case dw_val_class_file
:
9068 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
9070 case dw_val_class_data8
:
9073 case dw_val_class_vms_delta
:
9074 size
+= DWARF_OFFSET_SIZE
;
9076 case dw_val_class_high_pc
:
9077 size
+= DWARF2_ADDR_SIZE
;
9079 case dw_val_class_discr_value
:
9080 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
9082 case dw_val_class_discr_list
:
9084 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
9086 /* This is a block, so we have the block length and then its
9088 size
+= constant_size (block_size
) + block_size
;
9099 /* Size the debugging information associated with a given DIE. Visits the
9100 DIE's children recursively. Updates the global variable next_die_offset, on
9101 each time through. Uses the current value of next_die_offset to update the
9102 die_offset field in each DIE. */
9105 calc_die_sizes (dw_die_ref die
)
9109 gcc_assert (die
->die_offset
== 0
9110 || (unsigned long int) die
->die_offset
== next_die_offset
);
9111 die
->die_offset
= next_die_offset
;
9112 next_die_offset
+= size_of_die (die
);
9114 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
9116 if (die
->die_child
!= NULL
)
9117 /* Count the null byte used to terminate sibling lists. */
9118 next_die_offset
+= 1;
9121 /* Size just the base type children at the start of the CU.
9122 This is needed because build_abbrev needs to size locs
9123 and sizing of type based stack ops needs to know die_offset
9124 values for the base types. */
9127 calc_base_type_die_sizes (void)
9129 unsigned long die_offset
= (dwarf_split_debug_info
9130 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9131 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
9133 dw_die_ref base_type
;
9134 #if ENABLE_ASSERT_CHECKING
9135 dw_die_ref prev
= comp_unit_die ()->die_child
;
9138 die_offset
+= size_of_die (comp_unit_die ());
9139 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
9141 #if ENABLE_ASSERT_CHECKING
9142 gcc_assert (base_type
->die_offset
== 0
9143 && prev
->die_sib
== base_type
9144 && base_type
->die_child
== NULL
9145 && base_type
->die_abbrev
);
9148 if (abbrev_opt_start
9149 && base_type
->die_abbrev
>= abbrev_opt_base_type_end
)
9150 abbrev_opt_base_type_end
= base_type
->die_abbrev
+ 1;
9151 base_type
->die_offset
= die_offset
;
9152 die_offset
+= size_of_die (base_type
);
9156 /* Set the marks for a die and its children. We do this so
9157 that we know whether or not a reference needs to use FORM_ref_addr; only
9158 DIEs in the same CU will be marked. We used to clear out the offset
9159 and use that as the flag, but ran into ordering problems. */
9162 mark_dies (dw_die_ref die
)
9166 gcc_assert (!die
->die_mark
);
9169 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
9172 /* Clear the marks for a die and its children. */
9175 unmark_dies (dw_die_ref die
)
9179 if (! use_debug_types
)
9180 gcc_assert (die
->die_mark
);
9183 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
9186 /* Clear the marks for a die, its children and referred dies. */
9189 unmark_all_dies (dw_die_ref die
)
9199 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
9201 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9202 if (AT_class (a
) == dw_val_class_die_ref
)
9203 unmark_all_dies (AT_ref (a
));
9206 /* Calculate if the entry should appear in the final output file. It may be
9207 from a pruned a type. */
9210 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
9212 /* By limiting gnu pubnames to definitions only, gold can generate a
9213 gdb index without entries for declarations, which don't include
9214 enough information to be useful. */
9215 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
9218 if (table
== pubname_table
)
9220 /* Enumerator names are part of the pubname table, but the
9221 parent DW_TAG_enumeration_type die may have been pruned.
9222 Don't output them if that is the case. */
9223 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
9224 (p
->die
->die_parent
== NULL
9225 || !p
->die
->die_parent
->die_perennial_p
))
9228 /* Everything else in the pubname table is included. */
9232 /* The pubtypes table shouldn't include types that have been
9234 return (p
->die
->die_offset
!= 0
9235 || !flag_eliminate_unused_debug_types
);
9238 /* Return the size of the .debug_pubnames or .debug_pubtypes table
9239 generated for the compilation unit. */
9241 static unsigned long
9242 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9247 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
9249 size
= DWARF_PUBNAMES_HEADER_SIZE
;
9250 FOR_EACH_VEC_ELT (*names
, i
, p
)
9251 if (include_pubname_in_output (names
, p
))
9252 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
9254 size
+= DWARF_OFFSET_SIZE
;
9258 /* Return the size of the information in the .debug_aranges section. */
9260 static unsigned long
9261 size_of_aranges (void)
9265 size
= DWARF_ARANGES_HEADER_SIZE
;
9267 /* Count the address/length pair for this compilation unit. */
9268 if (text_section_used
)
9269 size
+= 2 * DWARF2_ADDR_SIZE
;
9270 if (cold_text_section_used
)
9271 size
+= 2 * DWARF2_ADDR_SIZE
;
9272 if (have_multiple_function_sections
)
9277 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9279 if (DECL_IGNORED_P (fde
->decl
))
9281 if (!fde
->in_std_section
)
9282 size
+= 2 * DWARF2_ADDR_SIZE
;
9283 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9284 size
+= 2 * DWARF2_ADDR_SIZE
;
9288 /* Count the two zero words used to terminated the address range table. */
9289 size
+= 2 * DWARF2_ADDR_SIZE
;
9293 /* Select the encoding of an attribute value. */
9295 static enum dwarf_form
9296 value_format (dw_attr_node
*a
)
9298 switch (AT_class (a
))
9300 case dw_val_class_addr
:
9301 /* Only very few attributes allow DW_FORM_addr. */
9306 case DW_AT_entry_pc
:
9307 case DW_AT_trampoline
:
9308 return (AT_index (a
) == NOT_INDEXED
9309 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9313 switch (DWARF2_ADDR_SIZE
)
9316 return DW_FORM_data1
;
9318 return DW_FORM_data2
;
9320 return DW_FORM_data4
;
9322 return DW_FORM_data8
;
9326 case dw_val_class_loc_list
:
9327 if (dwarf_split_debug_info
9328 && dwarf_version
>= 5
9329 && AT_loc_list (a
)->num_assigned
)
9330 return DW_FORM_loclistx
;
9332 case dw_val_class_range_list
:
9333 /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9334 but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9335 care about sizes of .debug* sections in shared libraries and
9336 executables and don't take into account relocations that affect just
9337 relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9338 table in the .debug_rnglists section. */
9339 if (dwarf_split_debug_info
9340 && dwarf_version
>= 5
9341 && AT_class (a
) == dw_val_class_range_list
9343 && a
->dw_attr_val
.val_entry
!= RELOCATED_OFFSET
)
9344 return DW_FORM_rnglistx
;
9345 if (dwarf_version
>= 4)
9346 return DW_FORM_sec_offset
;
9348 case dw_val_class_vms_delta
:
9349 case dw_val_class_offset
:
9350 switch (DWARF_OFFSET_SIZE
)
9353 return DW_FORM_data4
;
9355 return DW_FORM_data8
;
9359 case dw_val_class_loc
:
9360 if (dwarf_version
>= 4)
9361 return DW_FORM_exprloc
;
9362 switch (constant_size (size_of_locs (AT_loc (a
))))
9365 return DW_FORM_block1
;
9367 return DW_FORM_block2
;
9369 return DW_FORM_block4
;
9373 case dw_val_class_const
:
9374 return DW_FORM_sdata
;
9375 case dw_val_class_unsigned_const
:
9376 switch (constant_size (AT_unsigned (a
)))
9379 return DW_FORM_data1
;
9381 return DW_FORM_data2
;
9383 /* In DWARF3 DW_AT_data_member_location with
9384 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
9385 constant, so we need to use DW_FORM_udata if we need
9386 a large constant. */
9387 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9388 return DW_FORM_udata
;
9389 return DW_FORM_data4
;
9391 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9392 return DW_FORM_udata
;
9393 return DW_FORM_data8
;
9397 case dw_val_class_const_implicit
:
9398 case dw_val_class_unsigned_const_implicit
:
9399 case dw_val_class_file_implicit
:
9400 return DW_FORM_implicit_const
;
9401 case dw_val_class_const_double
:
9402 switch (HOST_BITS_PER_WIDE_INT
)
9405 return DW_FORM_data2
;
9407 return DW_FORM_data4
;
9409 return DW_FORM_data8
;
9411 if (dwarf_version
>= 5)
9412 return DW_FORM_data16
;
9415 return DW_FORM_block1
;
9417 case dw_val_class_wide_int
:
9418 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
9421 return DW_FORM_data1
;
9423 return DW_FORM_data2
;
9425 return DW_FORM_data4
;
9427 return DW_FORM_data8
;
9429 if (dwarf_version
>= 5)
9430 return DW_FORM_data16
;
9433 return DW_FORM_block1
;
9435 case dw_val_class_vec
:
9436 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
9437 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
9440 return DW_FORM_block1
;
9442 return DW_FORM_block2
;
9444 return DW_FORM_block4
;
9448 case dw_val_class_flag
:
9449 if (dwarf_version
>= 4)
9451 /* Currently all add_AT_flag calls pass in 1 as last argument,
9452 so DW_FORM_flag_present can be used. If that ever changes,
9453 we'll need to use DW_FORM_flag and have some optimization
9454 in build_abbrev_table that will change those to
9455 DW_FORM_flag_present if it is set to 1 in all DIEs using
9456 the same abbrev entry. */
9457 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9458 return DW_FORM_flag_present
;
9460 return DW_FORM_flag
;
9461 case dw_val_class_die_ref
:
9462 if (AT_ref_external (a
))
9463 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
9466 case dw_val_class_fde_ref
:
9467 return DW_FORM_data
;
9468 case dw_val_class_lbl_id
:
9469 return (AT_index (a
) == NOT_INDEXED
9470 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9471 case dw_val_class_lineptr
:
9472 case dw_val_class_macptr
:
9473 case dw_val_class_loclistsptr
:
9474 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
9475 case dw_val_class_str
:
9476 return AT_string_form (a
);
9477 case dw_val_class_file
:
9478 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
9481 return DW_FORM_data1
;
9483 return DW_FORM_data2
;
9485 return DW_FORM_data4
;
9490 case dw_val_class_data8
:
9491 return DW_FORM_data8
;
9493 case dw_val_class_high_pc
:
9494 switch (DWARF2_ADDR_SIZE
)
9497 return DW_FORM_data1
;
9499 return DW_FORM_data2
;
9501 return DW_FORM_data4
;
9503 return DW_FORM_data8
;
9508 case dw_val_class_discr_value
:
9509 return (a
->dw_attr_val
.v
.val_discr_value
.pos
9512 case dw_val_class_discr_list
:
9513 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
9516 return DW_FORM_block1
;
9518 return DW_FORM_block2
;
9520 return DW_FORM_block4
;
9530 /* Output the encoding of an attribute value. */
9533 output_value_format (dw_attr_node
*a
)
9535 enum dwarf_form form
= value_format (a
);
9537 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
9540 /* Given a die and id, produce the appropriate abbreviations. */
9543 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
9546 dw_attr_node
*a_attr
;
9548 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
9549 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
9550 dwarf_tag_name (abbrev
->die_tag
));
9552 if (abbrev
->die_child
!= NULL
)
9553 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
9555 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
9557 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
9559 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
9560 dwarf_attr_name (a_attr
->dw_attr
));
9561 output_value_format (a_attr
);
9562 if (value_format (a_attr
) == DW_FORM_implicit_const
)
9564 if (AT_class (a_attr
) == dw_val_class_file_implicit
)
9566 int f
= maybe_emit_file (a_attr
->dw_attr_val
.v
.val_file
);
9567 const char *filename
= a_attr
->dw_attr_val
.v
.val_file
->filename
;
9568 dw2_asm_output_data_sleb128 (f
, "(%s)", filename
);
9571 dw2_asm_output_data_sleb128 (a_attr
->dw_attr_val
.v
.val_int
, NULL
);
9575 dw2_asm_output_data (1, 0, NULL
);
9576 dw2_asm_output_data (1, 0, NULL
);
9580 /* Output the .debug_abbrev section which defines the DIE abbreviation
9584 output_abbrev_section (void)
9586 unsigned int abbrev_id
;
9589 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
9591 output_die_abbrevs (abbrev_id
, abbrev
);
9593 /* Terminate the table. */
9594 dw2_asm_output_data (1, 0, NULL
);
9597 /* Output a symbol we can use to refer to this DIE from another CU. */
9600 output_die_symbol (dw_die_ref die
)
9602 const char *sym
= die
->die_id
.die_symbol
;
9604 gcc_assert (!die
->comdat_type_p
);
9609 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
9610 /* We make these global, not weak; if the target doesn't support
9611 .linkonce, it doesn't support combining the sections, so debugging
9613 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
9615 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
9618 /* Return a new location list, given the begin and end range, and the
9621 static inline dw_loc_list_ref
9622 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
9623 const char *section
)
9625 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
9627 retlist
->begin
= begin
;
9628 retlist
->begin_entry
= NULL
;
9630 retlist
->expr
= expr
;
9631 retlist
->section
= section
;
9636 /* Generate a new internal symbol for this location list node, if it
9637 hasn't got one yet. */
9640 gen_llsym (dw_loc_list_ref list
)
9642 gcc_assert (!list
->ll_symbol
);
9643 list
->ll_symbol
= gen_internal_sym ("LLST");
9646 /* Output the location list given to us. */
9649 output_loc_list (dw_loc_list_ref list_head
)
9651 if (list_head
->emitted
)
9653 list_head
->emitted
= true;
9655 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
9657 dw_loc_list_ref curr
= list_head
;
9658 const char *last_section
= NULL
;
9659 const char *base_label
= NULL
;
9661 /* Walk the location list, and output each range + expression. */
9662 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
9665 /* Don't output an entry that starts and ends at the same address. */
9666 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
9668 size
= size_of_locs (curr
->expr
);
9669 /* If the expression is too large, drop it on the floor. We could
9670 perhaps put it into DW_TAG_dwarf_procedure and refer to that
9671 in the expression, but >= 64KB expressions for a single value
9672 in a single range are unlikely very useful. */
9673 if (dwarf_version
< 5 && size
> 0xffff)
9675 if (dwarf_version
>= 5)
9677 if (dwarf_split_debug_info
)
9679 /* For -gsplit-dwarf, emit DW_LLE_starx_length, which has
9680 uleb128 index into .debug_addr and uleb128 length. */
9681 dw2_asm_output_data (1, DW_LLE_startx_length
,
9682 "DW_LLE_startx_length (%s)",
9683 list_head
->ll_symbol
);
9684 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9685 "Location list range start index "
9686 "(%s)", curr
->begin
);
9687 /* FIXME: This will ICE ifndef HAVE_AS_LEB128.
9688 For that case we probably need to emit DW_LLE_startx_endx,
9689 but we'd need 2 .debug_addr entries rather than just one. */
9690 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9691 "Location list length (%s)",
9692 list_head
->ll_symbol
);
9694 else if (!have_multiple_function_sections
&& HAVE_AS_LEB128
)
9696 /* If all code is in .text section, the base address is
9697 already provided by the CU attributes. Use
9698 DW_LLE_offset_pair where both addresses are uleb128 encoded
9699 offsets against that base. */
9700 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9701 "DW_LLE_offset_pair (%s)",
9702 list_head
->ll_symbol
);
9703 dw2_asm_output_delta_uleb128 (curr
->begin
, curr
->section
,
9704 "Location list begin address (%s)",
9705 list_head
->ll_symbol
);
9706 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->section
,
9707 "Location list end address (%s)",
9708 list_head
->ll_symbol
);
9710 else if (HAVE_AS_LEB128
)
9712 /* Otherwise, find out how many consecutive entries could share
9713 the same base entry. If just one, emit DW_LLE_start_length,
9714 otherwise emit DW_LLE_base_address for the base address
9715 followed by a series of DW_LLE_offset_pair. */
9716 if (last_section
== NULL
|| curr
->section
!= last_section
)
9718 dw_loc_list_ref curr2
;
9719 for (curr2
= curr
->dw_loc_next
; curr2
!= NULL
;
9720 curr2
= curr2
->dw_loc_next
)
9722 if (strcmp (curr2
->begin
, curr2
->end
) == 0
9727 if (curr2
== NULL
|| curr
->section
!= curr2
->section
)
9728 last_section
= NULL
;
9731 last_section
= curr
->section
;
9732 base_label
= curr
->begin
;
9733 dw2_asm_output_data (1, DW_LLE_base_address
,
9734 "DW_LLE_base_address (%s)",
9735 list_head
->ll_symbol
);
9736 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, base_label
,
9737 "Base address (%s)",
9738 list_head
->ll_symbol
);
9741 /* Only one entry with the same base address. Use
9742 DW_LLE_start_length with absolute address and uleb128
9744 if (last_section
== NULL
)
9746 dw2_asm_output_data (1, DW_LLE_start_length
,
9747 "DW_LLE_start_length (%s)",
9748 list_head
->ll_symbol
);
9749 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9750 "Location list begin address (%s)",
9751 list_head
->ll_symbol
);
9752 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9753 "Location list length "
9754 "(%s)", list_head
->ll_symbol
);
9756 /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
9757 DW_LLE_base_address. */
9760 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9761 "DW_LLE_offset_pair (%s)",
9762 list_head
->ll_symbol
);
9763 dw2_asm_output_delta_uleb128 (curr
->begin
, base_label
,
9764 "Location list begin address "
9765 "(%s)", list_head
->ll_symbol
);
9766 dw2_asm_output_delta_uleb128 (curr
->end
, base_label
,
9767 "Location list end address "
9768 "(%s)", list_head
->ll_symbol
);
9771 /* The assembler does not support .uleb128 directive. Emit
9772 DW_LLE_start_end with a pair of absolute addresses. */
9775 dw2_asm_output_data (1, DW_LLE_start_end
,
9776 "DW_LLE_start_end (%s)",
9777 list_head
->ll_symbol
);
9778 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9779 "Location list begin address (%s)",
9780 list_head
->ll_symbol
);
9781 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9782 "Location list end address (%s)",
9783 list_head
->ll_symbol
);
9786 else if (dwarf_split_debug_info
)
9788 /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
9789 and 4 byte length. */
9790 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
9791 "Location list start/length entry (%s)",
9792 list_head
->ll_symbol
);
9793 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9794 "Location list range start index (%s)",
9796 /* The length field is 4 bytes. If we ever need to support
9797 an 8-byte length, we can add a new DW_LLE code or fall back
9798 to DW_LLE_GNU_start_end_entry. */
9799 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
9800 "Location list range length (%s)",
9801 list_head
->ll_symbol
);
9803 else if (!have_multiple_function_sections
)
9805 /* Pair of relative addresses against start of text section. */
9806 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
9807 "Location list begin address (%s)",
9808 list_head
->ll_symbol
);
9809 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
9810 "Location list end address (%s)",
9811 list_head
->ll_symbol
);
9815 /* Pair of absolute addresses. */
9816 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9817 "Location list begin address (%s)",
9818 list_head
->ll_symbol
);
9819 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9820 "Location list end address (%s)",
9821 list_head
->ll_symbol
);
9824 /* Output the block length for this list of location operations. */
9825 if (dwarf_version
>= 5)
9826 dw2_asm_output_data_uleb128 (size
, "Location expression size");
9829 gcc_assert (size
<= 0xffff);
9830 dw2_asm_output_data (2, size
, "Location expression size");
9833 output_loc_sequence (curr
->expr
, -1);
9836 /* And finally list termination. */
9837 if (dwarf_version
>= 5)
9838 dw2_asm_output_data (1, DW_LLE_end_of_list
,
9839 "DW_LLE_end_of_list (%s)", list_head
->ll_symbol
);
9840 else if (dwarf_split_debug_info
)
9841 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
9842 "Location list terminator (%s)",
9843 list_head
->ll_symbol
);
9846 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9847 "Location list terminator begin (%s)",
9848 list_head
->ll_symbol
);
9849 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9850 "Location list terminator end (%s)",
9851 list_head
->ll_symbol
);
9855 /* Output a range_list offset into the .debug_ranges or .debug_rnglists
9856 section. Emit a relocated reference if val_entry is NULL, otherwise,
9857 emit an indirect reference. */
9860 output_range_list_offset (dw_attr_node
*a
)
9862 const char *name
= dwarf_attr_name (a
->dw_attr
);
9864 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
9866 if (dwarf_version
>= 5)
9868 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9869 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, r
->label
,
9870 debug_ranges_section
, "%s", name
);
9874 char *p
= strchr (ranges_section_label
, '\0');
9875 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
9876 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
);
9877 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
9878 debug_ranges_section
, "%s", name
);
9882 else if (dwarf_version
>= 5)
9884 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9885 gcc_assert (rnglist_idx
);
9886 dw2_asm_output_data_uleb128 (r
->idx
, "%s", name
);
9889 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9890 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
,
9891 "%s (offset from %s)", name
, ranges_section_label
);
9894 /* Output the offset into the debug_loc section. */
9897 output_loc_list_offset (dw_attr_node
*a
)
9899 char *sym
= AT_loc_list (a
)->ll_symbol
;
9902 if (!dwarf_split_debug_info
)
9903 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
9904 "%s", dwarf_attr_name (a
->dw_attr
));
9905 else if (dwarf_version
>= 5)
9907 gcc_assert (AT_loc_list (a
)->num_assigned
);
9908 dw2_asm_output_data_uleb128 (AT_loc_list (a
)->hash
, "%s (%s)",
9909 dwarf_attr_name (a
->dw_attr
),
9913 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
9914 "%s", dwarf_attr_name (a
->dw_attr
));
9917 /* Output an attribute's index or value appropriately. */
9920 output_attr_index_or_value (dw_attr_node
*a
)
9922 const char *name
= dwarf_attr_name (a
->dw_attr
);
9924 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9926 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
9929 switch (AT_class (a
))
9931 case dw_val_class_addr
:
9932 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
9934 case dw_val_class_high_pc
:
9935 case dw_val_class_lbl_id
:
9936 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
9943 /* Output a type signature. */
9946 output_signature (const char *sig
, const char *name
)
9950 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9951 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
9954 /* Output a discriminant value. */
9957 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
9959 if (discr_value
->pos
)
9960 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
9962 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
9965 /* Output the DIE and its attributes. Called recursively to generate
9966 the definitions of each child DIE. */
9969 output_die (dw_die_ref die
)
9976 /* If someone in another CU might refer to us, set up a symbol for
9977 them to point to. */
9978 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
9979 output_die_symbol (die
);
9981 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
9982 (unsigned long)die
->die_offset
,
9983 dwarf_tag_name (die
->die_tag
));
9985 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9987 const char *name
= dwarf_attr_name (a
->dw_attr
);
9989 switch (AT_class (a
))
9991 case dw_val_class_addr
:
9992 output_attr_index_or_value (a
);
9995 case dw_val_class_offset
:
9996 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
10000 case dw_val_class_range_list
:
10001 output_range_list_offset (a
);
10004 case dw_val_class_loc
:
10005 size
= size_of_locs (AT_loc (a
));
10007 /* Output the block length for this list of location operations. */
10008 if (dwarf_version
>= 4)
10009 dw2_asm_output_data_uleb128 (size
, "%s", name
);
10011 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
10013 output_loc_sequence (AT_loc (a
), -1);
10016 case dw_val_class_const
:
10017 /* ??? It would be slightly more efficient to use a scheme like is
10018 used for unsigned constants below, but gdb 4.x does not sign
10019 extend. Gdb 5.x does sign extend. */
10020 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
10023 case dw_val_class_unsigned_const
:
10025 int csize
= constant_size (AT_unsigned (a
));
10026 if (dwarf_version
== 3
10027 && a
->dw_attr
== DW_AT_data_member_location
10029 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
10031 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
10035 case dw_val_class_const_implicit
:
10036 if (flag_debug_asm
)
10037 fprintf (asm_out_file
, "\t\t\t%s %s ("
10038 HOST_WIDE_INT_PRINT_DEC
")\n",
10039 ASM_COMMENT_START
, name
, AT_int (a
));
10042 case dw_val_class_unsigned_const_implicit
:
10043 if (flag_debug_asm
)
10044 fprintf (asm_out_file
, "\t\t\t%s %s ("
10045 HOST_WIDE_INT_PRINT_HEX
")\n",
10046 ASM_COMMENT_START
, name
, AT_unsigned (a
));
10049 case dw_val_class_const_double
:
10051 unsigned HOST_WIDE_INT first
, second
;
10053 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
10054 dw2_asm_output_data (1,
10055 HOST_BITS_PER_DOUBLE_INT
10056 / HOST_BITS_PER_CHAR
,
10059 if (WORDS_BIG_ENDIAN
)
10061 first
= a
->dw_attr_val
.v
.val_double
.high
;
10062 second
= a
->dw_attr_val
.v
.val_double
.low
;
10066 first
= a
->dw_attr_val
.v
.val_double
.low
;
10067 second
= a
->dw_attr_val
.v
.val_double
.high
;
10070 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10071 first
, "%s", name
);
10072 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10077 case dw_val_class_wide_int
:
10080 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
10081 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10082 if (len
* HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
10083 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
)
10086 if (WORDS_BIG_ENDIAN
)
10087 for (i
= len
- 1; i
>= 0; --i
)
10089 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10094 for (i
= 0; i
< len
; ++i
)
10096 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10103 case dw_val_class_vec
:
10105 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
10106 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
10110 dw2_asm_output_data (constant_size (len
* elt_size
),
10111 len
* elt_size
, "%s", name
);
10112 if (elt_size
> sizeof (HOST_WIDE_INT
))
10117 for (i
= 0, p
= (unsigned char *) a
->dw_attr_val
.v
.val_vec
.array
;
10119 i
++, p
+= elt_size
)
10120 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
10121 "fp or vector constant word %u", i
);
10125 case dw_val_class_flag
:
10126 if (dwarf_version
>= 4)
10128 /* Currently all add_AT_flag calls pass in 1 as last argument,
10129 so DW_FORM_flag_present can be used. If that ever changes,
10130 we'll need to use DW_FORM_flag and have some optimization
10131 in build_abbrev_table that will change those to
10132 DW_FORM_flag_present if it is set to 1 in all DIEs using
10133 the same abbrev entry. */
10134 gcc_assert (AT_flag (a
) == 1);
10135 if (flag_debug_asm
)
10136 fprintf (asm_out_file
, "\t\t\t%s %s\n",
10137 ASM_COMMENT_START
, name
);
10140 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
10143 case dw_val_class_loc_list
:
10144 output_loc_list_offset (a
);
10147 case dw_val_class_die_ref
:
10148 if (AT_ref_external (a
))
10150 if (AT_ref (a
)->comdat_type_p
)
10152 comdat_type_node
*type_node
10153 = AT_ref (a
)->die_id
.die_type_node
;
10155 gcc_assert (type_node
);
10156 output_signature (type_node
->signature
, name
);
10160 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
10164 /* In DWARF2, DW_FORM_ref_addr is sized by target address
10165 length, whereas in DWARF3 it's always sized as an
10167 if (dwarf_version
== 2)
10168 size
= DWARF2_ADDR_SIZE
;
10170 size
= DWARF_OFFSET_SIZE
;
10171 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
10177 gcc_assert (AT_ref (a
)->die_offset
);
10178 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
10183 case dw_val_class_fde_ref
:
10185 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
10187 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
10188 a
->dw_attr_val
.v
.val_fde_index
* 2);
10189 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
10194 case dw_val_class_vms_delta
:
10195 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
10196 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
10197 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10200 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
10201 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10206 case dw_val_class_lbl_id
:
10207 output_attr_index_or_value (a
);
10210 case dw_val_class_lineptr
:
10211 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10212 debug_line_section
, "%s", name
);
10215 case dw_val_class_macptr
:
10216 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10217 debug_macinfo_section
, "%s", name
);
10220 case dw_val_class_loclistsptr
:
10221 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10222 debug_loc_section
, "%s", name
);
10225 case dw_val_class_str
:
10226 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
10227 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10228 a
->dw_attr_val
.v
.val_str
->label
,
10230 "%s: \"%s\"", name
, AT_string (a
));
10231 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_line_strp
)
10232 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10233 a
->dw_attr_val
.v
.val_str
->label
,
10234 debug_line_str_section
,
10235 "%s: \"%s\"", name
, AT_string (a
));
10236 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
10237 dw2_asm_output_data_uleb128 (AT_index (a
),
10238 "%s: \"%s\"", name
, AT_string (a
));
10240 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
10243 case dw_val_class_file
:
10245 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
10247 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
10248 a
->dw_attr_val
.v
.val_file
->filename
);
10252 case dw_val_class_file_implicit
:
10253 if (flag_debug_asm
)
10254 fprintf (asm_out_file
, "\t\t\t%s %s (%d, %s)\n",
10255 ASM_COMMENT_START
, name
,
10256 maybe_emit_file (a
->dw_attr_val
.v
.val_file
),
10257 a
->dw_attr_val
.v
.val_file
->filename
);
10260 case dw_val_class_data8
:
10264 for (i
= 0; i
< 8; i
++)
10265 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
10266 i
== 0 ? "%s" : NULL
, name
);
10270 case dw_val_class_high_pc
:
10271 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
10272 get_AT_low_pc (die
), "DW_AT_high_pc");
10275 case dw_val_class_discr_value
:
10276 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
10279 case dw_val_class_discr_list
:
10281 dw_discr_list_ref list
= AT_discr_list (a
);
10282 const int size
= size_of_discr_list (list
);
10284 /* This is a block, so output its length first. */
10285 dw2_asm_output_data (constant_size (size
), size
,
10286 "%s: block size", name
);
10288 for (; list
!= NULL
; list
= list
->dw_discr_next
)
10290 /* One byte for the discriminant value descriptor, and then as
10291 many LEB128 numbers as required. */
10292 if (list
->dw_discr_range
)
10293 dw2_asm_output_data (1, DW_DSC_range
,
10294 "%s: DW_DSC_range", name
);
10296 dw2_asm_output_data (1, DW_DSC_label
,
10297 "%s: DW_DSC_label", name
);
10299 output_discr_value (&list
->dw_discr_lower_bound
, name
);
10300 if (list
->dw_discr_range
)
10301 output_discr_value (&list
->dw_discr_upper_bound
, name
);
10307 gcc_unreachable ();
10311 FOR_EACH_CHILD (die
, c
, output_die (c
));
10313 /* Add null byte to terminate sibling list. */
10314 if (die
->die_child
!= NULL
)
10315 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
10316 (unsigned long) die
->die_offset
);
10319 /* Output the compilation unit that appears at the beginning of the
10320 .debug_info section, and precedes the DIE descriptions. */
10323 output_compilation_unit_header (enum dwarf_unit_type ut
)
10325 if (!XCOFF_DEBUGGING_INFO
)
10327 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10328 dw2_asm_output_data (4, 0xffffffff,
10329 "Initial length escape value indicating 64-bit DWARF extension");
10330 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10331 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
10332 "Length of Compilation Unit Info");
10335 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10336 if (dwarf_version
>= 5)
10341 case DW_UT_compile
: name
= "DW_UT_compile"; break;
10342 case DW_UT_type
: name
= "DW_UT_type"; break;
10343 case DW_UT_split_compile
: name
= "DW_UT_split_compile"; break;
10344 case DW_UT_split_type
: name
= "DW_UT_split_type"; break;
10345 default: gcc_unreachable ();
10347 dw2_asm_output_data (1, ut
, "%s", name
);
10348 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10350 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
10351 debug_abbrev_section
,
10352 "Offset Into Abbrev. Section");
10353 if (dwarf_version
< 5)
10354 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10357 /* Output the compilation unit DIE and its children. */
10360 output_comp_unit (dw_die_ref die
, int output_if_empty
,
10361 const unsigned char *dwo_id
)
10363 const char *secname
, *oldsym
;
10366 /* Unless we are outputting main CU, we may throw away empty ones. */
10367 if (!output_if_empty
&& die
->die_child
== NULL
)
10370 /* Even if there are no children of this DIE, we must output the information
10371 about the compilation unit. Otherwise, on an empty translation unit, we
10372 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
10373 will then complain when examining the file. First mark all the DIEs in
10374 this CU so we know which get local refs. */
10377 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
10379 /* For now, optimize only the main CU, in order to optimize the rest
10380 we'd need to see all of them earlier. Leave the rest for post-linking
10382 if (die
== comp_unit_die ())
10383 abbrev_opt_start
= vec_safe_length (abbrev_die_table
);
10385 build_abbrev_table (die
, extern_map
);
10387 optimize_abbrev_table ();
10391 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10392 next_die_offset
= (dwo_id
10393 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10394 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
10395 calc_die_sizes (die
);
10397 oldsym
= die
->die_id
.die_symbol
;
10400 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
10402 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
10404 die
->die_id
.die_symbol
= NULL
;
10405 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10409 switch_to_section (debug_info_section
);
10410 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
10411 info_section_emitted
= true;
10414 /* Output debugging information. */
10415 output_compilation_unit_header (dwo_id
10416 ? DW_UT_split_compile
: DW_UT_compile
);
10417 if (dwarf_version
>= 5)
10419 if (dwo_id
!= NULL
)
10420 for (int i
= 0; i
< 8; i
++)
10421 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10425 /* Leave the marks on the main CU, so we can check them in
10426 output_pubnames. */
10430 die
->die_id
.die_symbol
= oldsym
;
10434 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
10435 and .debug_pubtypes. This is configured per-target, but can be
10436 overridden by the -gpubnames or -gno-pubnames options. */
10439 want_pubnames (void)
10441 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10443 if (debug_generate_pub_sections
!= -1)
10444 return debug_generate_pub_sections
;
10445 return targetm
.want_debug_pub_sections
;
10448 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
10451 add_AT_pubnames (dw_die_ref die
)
10453 if (want_pubnames ())
10454 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
10457 /* Add a string attribute value to a skeleton DIE. */
10460 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
10464 struct indirect_string_node
*node
;
10466 if (! skeleton_debug_str_hash
)
10467 skeleton_debug_str_hash
10468 = hash_table
<indirect_string_hasher
>::create_ggc (10);
10470 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
10471 find_string_form (node
);
10472 if (node
->form
== DW_FORM_GNU_str_index
)
10473 node
->form
= DW_FORM_strp
;
10475 attr
.dw_attr
= attr_kind
;
10476 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
10477 attr
.dw_attr_val
.val_entry
= NULL
;
10478 attr
.dw_attr_val
.v
.val_str
= node
;
10479 add_dwarf_attr (die
, &attr
);
10482 /* Helper function to generate top-level dies for skeleton debug_info and
10486 add_top_level_skeleton_die_attrs (dw_die_ref die
)
10488 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
10489 const char *comp_dir
= comp_dir_string ();
10491 add_skeleton_AT_string (die
, dwarf_AT (DW_AT_dwo_name
), dwo_file_name
);
10492 if (comp_dir
!= NULL
)
10493 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
10494 add_AT_pubnames (die
);
10495 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
10498 /* Output skeleton debug sections that point to the dwo file. */
10501 output_skeleton_debug_sections (dw_die_ref comp_unit
,
10502 const unsigned char *dwo_id
)
10504 /* These attributes will be found in the full debug_info section. */
10505 remove_AT (comp_unit
, DW_AT_producer
);
10506 remove_AT (comp_unit
, DW_AT_language
);
10508 switch_to_section (debug_skeleton_info_section
);
10509 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
10511 /* Produce the skeleton compilation-unit header. This one differs enough from
10512 a normal CU header that it's better not to call output_compilation_unit
10514 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10515 dw2_asm_output_data (4, 0xffffffff,
10516 "Initial length escape value indicating 64-bit "
10517 "DWARF extension");
10519 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10520 DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10521 - DWARF_INITIAL_LENGTH_SIZE
10522 + size_of_die (comp_unit
),
10523 "Length of Compilation Unit Info");
10524 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10525 if (dwarf_version
>= 5)
10527 dw2_asm_output_data (1, DW_UT_skeleton
, "DW_UT_skeleton");
10528 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10530 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
10531 debug_skeleton_abbrev_section
,
10532 "Offset Into Abbrev. Section");
10533 if (dwarf_version
< 5)
10534 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10536 for (int i
= 0; i
< 8; i
++)
10537 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10539 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
10540 output_die (comp_unit
);
10542 /* Build the skeleton debug_abbrev section. */
10543 switch_to_section (debug_skeleton_abbrev_section
);
10544 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
10546 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
10548 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
10551 /* Output a comdat type unit DIE and its children. */
10554 output_comdat_type_unit (comdat_type_node
*node
)
10556 const char *secname
;
10559 #if defined (OBJECT_FORMAT_ELF)
10563 /* First mark all the DIEs in this CU so we know which get local refs. */
10564 mark_dies (node
->root_die
);
10566 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
10568 build_abbrev_table (node
->root_die
, extern_map
);
10573 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10574 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
10575 calc_die_sizes (node
->root_die
);
10577 #if defined (OBJECT_FORMAT_ELF)
10578 if (dwarf_version
>= 5)
10580 if (!dwarf_split_debug_info
)
10581 secname
= ".debug_info";
10583 secname
= ".debug_info.dwo";
10585 else if (!dwarf_split_debug_info
)
10586 secname
= ".debug_types";
10588 secname
= ".debug_types.dwo";
10590 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10591 sprintf (tmp
, dwarf_version
>= 5 ? "wi." : "wt.");
10592 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10593 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10594 comdat_key
= get_identifier (tmp
);
10595 targetm
.asm_out
.named_section (secname
,
10596 SECTION_DEBUG
| SECTION_LINKONCE
,
10599 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10600 sprintf (tmp
, (dwarf_version
>= 5
10601 ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
10602 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10603 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10605 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10608 /* Output debugging information. */
10609 output_compilation_unit_header (dwarf_split_debug_info
10610 ? DW_UT_split_type
: DW_UT_type
);
10611 output_signature (node
->signature
, "Type Signature");
10612 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
10613 "Offset to Type DIE");
10614 output_die (node
->root_die
);
10616 unmark_dies (node
->root_die
);
10619 /* Return the DWARF2/3 pubname associated with a decl. */
10621 static const char *
10622 dwarf2_name (tree decl
, int scope
)
10624 if (DECL_NAMELESS (decl
))
10626 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
10629 /* Add a new entry to .debug_pubnames if appropriate. */
10632 add_pubname_string (const char *str
, dw_die_ref die
)
10637 e
.name
= xstrdup (str
);
10638 vec_safe_push (pubname_table
, e
);
10642 add_pubname (tree decl
, dw_die_ref die
)
10644 if (!want_pubnames ())
10647 /* Don't add items to the table when we expect that the consumer will have
10648 just read the enclosing die. For example, if the consumer is looking at a
10649 class_member, it will either be inside the class already, or will have just
10650 looked up the class to find the member. Either way, searching the class is
10651 faster than searching the index. */
10652 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
10653 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10655 const char *name
= dwarf2_name (decl
, 1);
10658 add_pubname_string (name
, die
);
10662 /* Add an enumerator to the pubnames section. */
10665 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
10669 gcc_assert (scope_name
);
10670 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
10672 vec_safe_push (pubname_table
, e
);
10675 /* Add a new entry to .debug_pubtypes if appropriate. */
10678 add_pubtype (tree decl
, dw_die_ref die
)
10682 if (!want_pubnames ())
10685 if ((TREE_PUBLIC (decl
)
10686 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10687 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
10690 const char *scope_name
= "";
10691 const char *sep
= is_cxx () ? "::" : ".";
10694 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
10695 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
10697 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
10698 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
10699 scope_name
= concat (scope_name
, sep
, NULL
);
10705 name
= type_tag (decl
);
10707 name
= lang_hooks
.dwarf_name (decl
, 1);
10709 /* If we don't have a name for the type, there's no point in adding
10710 it to the table. */
10711 if (name
!= NULL
&& name
[0] != '\0')
10714 e
.name
= concat (scope_name
, name
, NULL
);
10715 vec_safe_push (pubtype_table
, e
);
10718 /* Although it might be more consistent to add the pubinfo for the
10719 enumerators as their dies are created, they should only be added if the
10720 enum type meets the criteria above. So rather than re-check the parent
10721 enum type whenever an enumerator die is created, just output them all
10722 here. This isn't protected by the name conditional because anonymous
10723 enums don't have names. */
10724 if (die
->die_tag
== DW_TAG_enumeration_type
)
10728 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
10733 /* Output a single entry in the pubnames table. */
10736 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
10738 dw_die_ref die
= entry
->die
;
10739 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
10741 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
10743 if (debug_generate_pub_sections
== 2)
10745 /* This logic follows gdb's method for determining the value of the flag
10747 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
10748 switch (die
->die_tag
)
10750 case DW_TAG_typedef
:
10751 case DW_TAG_base_type
:
10752 case DW_TAG_subrange_type
:
10753 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10754 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10756 case DW_TAG_enumerator
:
10757 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10758 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10759 if (!is_cxx () && !is_java ())
10760 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10762 case DW_TAG_subprogram
:
10763 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10764 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
10766 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10768 case DW_TAG_constant
:
10769 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10770 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10771 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10773 case DW_TAG_variable
:
10774 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10775 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10776 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10778 case DW_TAG_namespace
:
10779 case DW_TAG_imported_declaration
:
10780 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10782 case DW_TAG_class_type
:
10783 case DW_TAG_interface_type
:
10784 case DW_TAG_structure_type
:
10785 case DW_TAG_union_type
:
10786 case DW_TAG_enumeration_type
:
10787 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10788 if (!is_cxx () && !is_java ())
10789 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10792 /* An unusual tag. Leave the flag-byte empty. */
10795 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
10796 "GDB-index flags");
10799 dw2_asm_output_nstring (entry
->name
, -1, "external name");
10803 /* Output the public names table used to speed up access to externally
10804 visible names; or the public types table used to find type definitions. */
10807 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
10810 unsigned long pubnames_length
= size_of_pubnames (names
);
10811 pubname_entry
*pub
;
10813 if (!XCOFF_DEBUGGING_INFO
)
10815 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10816 dw2_asm_output_data (4, 0xffffffff,
10817 "Initial length escape value indicating 64-bit DWARF extension");
10818 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
10819 "Pub Info Length");
10822 /* Version number for pubnames/pubtypes is independent of dwarf version. */
10823 dw2_asm_output_data (2, 2, "DWARF Version");
10825 if (dwarf_split_debug_info
)
10826 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10827 debug_skeleton_info_section
,
10828 "Offset of Compilation Unit Info");
10830 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10831 debug_info_section
,
10832 "Offset of Compilation Unit Info");
10833 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
10834 "Compilation Unit Length");
10836 FOR_EACH_VEC_ELT (*names
, i
, pub
)
10838 if (include_pubname_in_output (names
, pub
))
10840 dw_offset die_offset
= pub
->die
->die_offset
;
10842 /* We shouldn't see pubnames for DIEs outside of the main CU. */
10843 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
10844 gcc_assert (pub
->die
->die_mark
);
10846 /* If we're putting types in their own .debug_types sections,
10847 the .debug_pubtypes table will still point to the compile
10848 unit (not the type unit), so we want to use the offset of
10849 the skeleton DIE (if there is one). */
10850 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
10852 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
10854 if (type_node
!= NULL
)
10855 die_offset
= (type_node
->skeleton_die
!= NULL
10856 ? type_node
->skeleton_die
->die_offset
10857 : comp_unit_die ()->die_offset
);
10860 output_pubname (die_offset
, pub
);
10864 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
10867 /* Output public names and types tables if necessary. */
10870 output_pubtables (void)
10872 if (!want_pubnames () || !info_section_emitted
)
10875 switch_to_section (debug_pubnames_section
);
10876 output_pubnames (pubname_table
);
10877 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
10878 It shouldn't hurt to emit it always, since pure DWARF2 consumers
10879 simply won't look for the section. */
10880 switch_to_section (debug_pubtypes_section
);
10881 output_pubnames (pubtype_table
);
10885 /* Output the information that goes into the .debug_aranges table.
10886 Namely, define the beginning and ending address range of the
10887 text section generated for this compilation unit. */
10890 output_aranges (void)
10893 unsigned long aranges_length
= size_of_aranges ();
10895 if (!XCOFF_DEBUGGING_INFO
)
10897 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10898 dw2_asm_output_data (4, 0xffffffff,
10899 "Initial length escape value indicating 64-bit DWARF extension");
10900 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
10901 "Length of Address Ranges Info");
10904 /* Version number for aranges is still 2, even up to DWARF5. */
10905 dw2_asm_output_data (2, 2, "DWARF Version");
10906 if (dwarf_split_debug_info
)
10907 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10908 debug_skeleton_info_section
,
10909 "Offset of Compilation Unit Info");
10911 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10912 debug_info_section
,
10913 "Offset of Compilation Unit Info");
10914 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
10915 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
10917 /* We need to align to twice the pointer size here. */
10918 if (DWARF_ARANGES_PAD_SIZE
)
10920 /* Pad using a 2 byte words so that padding is correct for any
10922 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
10923 2 * DWARF2_ADDR_SIZE
);
10924 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
10925 dw2_asm_output_data (2, 0, NULL
);
10928 /* It is necessary not to output these entries if the sections were
10929 not used; if the sections were not used, the length will be 0 and
10930 the address may end up as 0 if the section is discarded by ld
10931 --gc-sections, leaving an invalid (0, 0) entry that can be
10932 confused with the terminator. */
10933 if (text_section_used
)
10935 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
10936 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
10937 text_section_label
, "Length");
10939 if (cold_text_section_used
)
10941 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
10943 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
10944 cold_text_section_label
, "Length");
10947 if (have_multiple_function_sections
)
10952 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
10954 if (DECL_IGNORED_P (fde
->decl
))
10956 if (!fde
->in_std_section
)
10958 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
10960 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
10961 fde
->dw_fde_begin
, "Length");
10963 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
10965 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
10967 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
10968 fde
->dw_fde_second_begin
, "Length");
10973 /* Output the terminator words. */
10974 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10975 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10978 /* Add a new entry to .debug_ranges. Return its index into
10979 ranges_table vector. */
10981 static unsigned int
10982 add_ranges_num (int num
, bool maybe_new_sec
)
10984 dw_ranges r
= { NULL
, num
, 0, maybe_new_sec
};
10985 vec_safe_push (ranges_table
, r
);
10986 return vec_safe_length (ranges_table
) - 1;
10989 /* Add a new entry to .debug_ranges corresponding to a block, or a
10990 range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
10991 this entry might be in a different section from previous range. */
10993 static unsigned int
10994 add_ranges (const_tree block
, bool maybe_new_sec
)
10996 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0, maybe_new_sec
);
10999 /* Note that (*rnglist_table)[offset] is either a head of a rnglist
11000 chain, or middle entry of a chain that will be directly referred to. */
11003 note_rnglist_head (unsigned int offset
)
11005 if (dwarf_version
< 5 || (*ranges_table
)[offset
].label
)
11007 (*ranges_table
)[offset
].label
= gen_internal_sym ("LLRL");
11010 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
11011 When using dwarf_split_debug_info, address attributes in dies destined
11012 for the final executable should be direct references--setting the
11013 parameter force_direct ensures this behavior. */
11016 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11017 bool *added
, bool force_direct
)
11019 unsigned int in_use
= vec_safe_length (ranges_by_label
);
11020 unsigned int offset
;
11021 dw_ranges_by_label rbl
= { begin
, end
};
11022 vec_safe_push (ranges_by_label
, rbl
);
11023 offset
= add_ranges_num (-(int)in_use
- 1, true);
11026 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
11028 note_rnglist_head (offset
);
11032 /* Emit .debug_ranges section. */
11035 output_ranges (void)
11038 static const char *const start_fmt
= "Offset %#x";
11039 const char *fmt
= start_fmt
;
11042 switch_to_section (debug_ranges_section
);
11043 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11044 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11046 int block_num
= r
->num
;
11050 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11051 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11053 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11054 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11056 /* If all code is in the text section, then the compilation
11057 unit base address defaults to DW_AT_low_pc, which is the
11058 base of the text section. */
11059 if (!have_multiple_function_sections
)
11061 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11062 text_section_label
,
11063 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11064 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11065 text_section_label
, NULL
);
11068 /* Otherwise, the compilation unit base address is zero,
11069 which allows us to use absolute addresses, and not worry
11070 about whether the target supports cross-section
11074 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11075 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11076 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11082 /* Negative block_num stands for an index into ranges_by_label. */
11083 else if (block_num
< 0)
11085 int lab_idx
= - block_num
- 1;
11087 if (!have_multiple_function_sections
)
11089 gcc_unreachable ();
11091 /* If we ever use add_ranges_by_labels () for a single
11092 function section, all we have to do is to take out
11093 the #if 0 above. */
11094 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11095 (*ranges_by_label
)[lab_idx
].begin
,
11096 text_section_label
,
11097 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11098 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11099 (*ranges_by_label
)[lab_idx
].end
,
11100 text_section_label
, NULL
);
11105 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11106 (*ranges_by_label
)[lab_idx
].begin
,
11107 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11108 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11109 (*ranges_by_label
)[lab_idx
].end
,
11115 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11116 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11122 /* Non-zero if .debug_line_str should be used for .debug_line section
11123 strings or strings that are likely shareable with those. */
11124 #define DWARF5_USE_DEBUG_LINE_STR \
11125 (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
11126 && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
11127 /* FIXME: there is no .debug_line_str.dwo section, \
11128 for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
11129 && !dwarf_split_debug_info)
11131 /* Assign .debug_rnglists indexes. */
11134 index_rnglists (void)
11139 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11141 r
->idx
= rnglist_idx
++;
11144 /* Emit .debug_rnglists section. */
11147 output_rnglists (void)
11151 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
11152 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11153 char basebuf
[MAX_ARTIFICIAL_LABEL_BYTES
];
11155 switch_to_section (debug_ranges_section
);
11156 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11157 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_RANGES_SECTION_LABEL
, 2);
11158 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_RANGES_SECTION_LABEL
, 3);
11159 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11160 dw2_asm_output_data (4, 0xffffffff,
11161 "Initial length escape value indicating "
11162 "64-bit DWARF extension");
11163 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11164 "Length of Range Lists");
11165 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11166 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11167 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11168 dw2_asm_output_data (1, 0, "Segment Size");
11169 /* Emit the offset table only for -gsplit-dwarf. If we don't care
11170 about relocation sizes and primarily care about the size of .debug*
11171 sections in linked shared libraries and executables, then
11172 the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
11173 into it are usually larger than just DW_FORM_sec_offset offsets
11174 into the .debug_rnglists section. */
11175 dw2_asm_output_data (4, dwarf_split_debug_info
? rnglist_idx
: 0,
11176 "Offset Entry Count");
11177 if (dwarf_split_debug_info
)
11179 ASM_OUTPUT_LABEL (asm_out_file
, ranges_base_label
);
11180 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11182 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, r
->label
,
11183 ranges_base_label
, NULL
);
11186 const char *lab
= "";
11187 unsigned int len
= vec_safe_length (ranges_table
);
11188 const char *base
= NULL
;
11189 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11191 int block_num
= r
->num
;
11195 ASM_OUTPUT_LABEL (asm_out_file
, r
->label
);
11198 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
11202 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11203 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11205 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11206 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11208 if (HAVE_AS_LEB128
)
11210 /* If all code is in the text section, then the compilation
11211 unit base address defaults to DW_AT_low_pc, which is the
11212 base of the text section. */
11213 if (!have_multiple_function_sections
)
11215 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11216 "DW_RLE_offset_pair (%s)", lab
);
11217 dw2_asm_output_delta_uleb128 (blabel
, text_section_label
,
11218 "Range begin address (%s)", lab
);
11219 dw2_asm_output_delta_uleb128 (elabel
, text_section_label
,
11220 "Range end address (%s)", lab
);
11225 dw_ranges
*r2
= NULL
;
11227 r2
= &(*ranges_table
)[i
+ 1];
11230 && r2
->label
== NULL
11231 && !r2
->maybe_new_sec
)
11233 dw2_asm_output_data (1, DW_RLE_base_address
,
11234 "DW_RLE_base_address (%s)", lab
);
11235 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11236 "Base address (%s)", lab
);
11237 strcpy (basebuf
, blabel
);
11243 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11244 "DW_RLE_offset_pair (%s)", lab
);
11245 dw2_asm_output_delta_uleb128 (blabel
, base
,
11246 "Range begin address (%s)", lab
);
11247 dw2_asm_output_delta_uleb128 (elabel
, base
,
11248 "Range end address (%s)", lab
);
11251 dw2_asm_output_data (1, DW_RLE_start_length
,
11252 "DW_RLE_start_length (%s)", lab
);
11253 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11254 "Range begin address (%s)", lab
);
11255 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11256 "Range length (%s)", lab
);
11260 dw2_asm_output_data (1, DW_RLE_start_end
,
11261 "DW_RLE_start_end (%s)", lab
);
11262 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11263 "Range begin address (%s)", lab
);
11264 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11265 "Range end address (%s)", lab
);
11269 /* Negative block_num stands for an index into ranges_by_label. */
11270 else if (block_num
< 0)
11272 int lab_idx
= - block_num
- 1;
11273 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
11274 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
11276 if (!have_multiple_function_sections
)
11277 gcc_unreachable ();
11278 if (HAVE_AS_LEB128
)
11280 dw2_asm_output_data (1, DW_RLE_start_length
,
11281 "DW_RLE_start_length (%s)", lab
);
11282 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11283 "Range begin address (%s)", lab
);
11284 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11285 "Range length (%s)", lab
);
11289 dw2_asm_output_data (1, DW_RLE_start_end
,
11290 "DW_RLE_start_end (%s)", lab
);
11291 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11292 "Range begin address (%s)", lab
);
11293 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11294 "Range end address (%s)", lab
);
11298 dw2_asm_output_data (1, DW_RLE_end_of_list
,
11299 "DW_RLE_end_of_list (%s)", lab
);
11301 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11304 /* Data structure containing information about input files. */
11307 const char *path
; /* Complete file name. */
11308 const char *fname
; /* File name part. */
11309 int length
; /* Length of entire string. */
11310 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
11311 int dir_idx
; /* Index in directory table. */
11314 /* Data structure containing information about directories with source
11318 const char *path
; /* Path including directory name. */
11319 int length
; /* Path length. */
11320 int prefix
; /* Index of directory entry which is a prefix. */
11321 int count
; /* Number of files in this directory. */
11322 int dir_idx
; /* Index of directory used as base. */
11325 /* Callback function for file_info comparison. We sort by looking at
11326 the directories in the path. */
11329 file_info_cmp (const void *p1
, const void *p2
)
11331 const struct file_info
*const s1
= (const struct file_info
*) p1
;
11332 const struct file_info
*const s2
= (const struct file_info
*) p2
;
11333 const unsigned char *cp1
;
11334 const unsigned char *cp2
;
11336 /* Take care of file names without directories. We need to make sure that
11337 we return consistent values to qsort since some will get confused if
11338 we return the same value when identical operands are passed in opposite
11339 orders. So if neither has a directory, return 0 and otherwise return
11340 1 or -1 depending on which one has the directory. */
11341 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
11342 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
11344 cp1
= (const unsigned char *) s1
->path
;
11345 cp2
= (const unsigned char *) s2
->path
;
11351 /* Reached the end of the first path? If so, handle like above. */
11352 if ((cp1
== (const unsigned char *) s1
->fname
)
11353 || (cp2
== (const unsigned char *) s2
->fname
))
11354 return ((cp2
== (const unsigned char *) s2
->fname
)
11355 - (cp1
== (const unsigned char *) s1
->fname
));
11357 /* Character of current path component the same? */
11358 else if (*cp1
!= *cp2
)
11359 return *cp1
- *cp2
;
11363 struct file_name_acquire_data
11365 struct file_info
*files
;
11370 /* Traversal function for the hash table. */
11373 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
11375 struct dwarf_file_data
*d
= *slot
;
11376 struct file_info
*fi
;
11379 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
11381 if (! d
->emitted_number
)
11384 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
11386 fi
= fnad
->files
+ fnad
->used_files
++;
11388 /* Skip all leading "./". */
11390 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
11393 /* Create a new array entry. */
11395 fi
->length
= strlen (f
);
11398 /* Search for the file name part. */
11399 f
= strrchr (f
, DIR_SEPARATOR
);
11400 #if defined (DIR_SEPARATOR_2)
11402 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
11406 if (f
== NULL
|| f
< g
)
11412 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
11416 /* Helper function for output_file_names. Emit a FORM encoded
11417 string STR, with assembly comment start ENTRY_KIND and
11421 output_line_string (enum dwarf_form form
, const char *str
,
11422 const char *entry_kind
, unsigned int idx
)
11426 case DW_FORM_string
:
11427 dw2_asm_output_nstring (str
, -1, "%s: %#x", entry_kind
, idx
);
11429 case DW_FORM_line_strp
:
11430 if (!debug_line_str_hash
)
11431 debug_line_str_hash
11432 = hash_table
<indirect_string_hasher
>::create_ggc (10);
11434 struct indirect_string_node
*node
;
11435 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
11436 set_indirect_string (node
);
11438 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
11439 debug_line_str_section
, "%s: %#x: \"%s\"",
11440 entry_kind
, 0, node
->str
);
11443 gcc_unreachable ();
11447 /* Output the directory table and the file name table. We try to minimize
11448 the total amount of memory needed. A heuristic is used to avoid large
11449 slowdowns with many input files. */
11452 output_file_names (void)
11454 struct file_name_acquire_data fnad
;
11456 struct file_info
*files
;
11457 struct dir_info
*dirs
;
11465 if (!last_emitted_file
)
11467 if (dwarf_version
>= 5)
11469 dw2_asm_output_data (1, 0, "Directory entry format count");
11470 dw2_asm_output_data_uleb128 (0, "Directories count");
11471 dw2_asm_output_data (1, 0, "File name entry format count");
11472 dw2_asm_output_data_uleb128 (0, "File names count");
11476 dw2_asm_output_data (1, 0, "End directory table");
11477 dw2_asm_output_data (1, 0, "End file name table");
11482 numfiles
= last_emitted_file
->emitted_number
;
11484 /* Allocate the various arrays we need. */
11485 files
= XALLOCAVEC (struct file_info
, numfiles
);
11486 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
11488 fnad
.files
= files
;
11489 fnad
.used_files
= 0;
11490 fnad
.max_files
= numfiles
;
11491 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
11492 gcc_assert (fnad
.used_files
== fnad
.max_files
);
11494 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
11496 /* Find all the different directories used. */
11497 dirs
[0].path
= files
[0].path
;
11498 dirs
[0].length
= files
[0].fname
- files
[0].path
;
11499 dirs
[0].prefix
= -1;
11501 dirs
[0].dir_idx
= 0;
11502 files
[0].dir_idx
= 0;
11505 for (i
= 1; i
< numfiles
; i
++)
11506 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
11507 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
11508 dirs
[ndirs
- 1].length
) == 0)
11510 /* Same directory as last entry. */
11511 files
[i
].dir_idx
= ndirs
- 1;
11512 ++dirs
[ndirs
- 1].count
;
11518 /* This is a new directory. */
11519 dirs
[ndirs
].path
= files
[i
].path
;
11520 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
11521 dirs
[ndirs
].count
= 1;
11522 dirs
[ndirs
].dir_idx
= ndirs
;
11523 files
[i
].dir_idx
= ndirs
;
11525 /* Search for a prefix. */
11526 dirs
[ndirs
].prefix
= -1;
11527 for (j
= 0; j
< ndirs
; j
++)
11528 if (dirs
[j
].length
< dirs
[ndirs
].length
11529 && dirs
[j
].length
> 1
11530 && (dirs
[ndirs
].prefix
== -1
11531 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
11532 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
11533 dirs
[ndirs
].prefix
= j
;
11538 /* Now to the actual work. We have to find a subset of the directories which
11539 allow expressing the file name using references to the directory table
11540 with the least amount of characters. We do not do an exhaustive search
11541 where we would have to check out every combination of every single
11542 possible prefix. Instead we use a heuristic which provides nearly optimal
11543 results in most cases and never is much off. */
11544 saved
= XALLOCAVEC (int, ndirs
);
11545 savehere
= XALLOCAVEC (int, ndirs
);
11547 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
11548 for (i
= 0; i
< ndirs
; i
++)
11553 /* We can always save some space for the current directory. But this
11554 does not mean it will be enough to justify adding the directory. */
11555 savehere
[i
] = dirs
[i
].length
;
11556 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
11558 for (j
= i
+ 1; j
< ndirs
; j
++)
11561 if (saved
[j
] < dirs
[i
].length
)
11563 /* Determine whether the dirs[i] path is a prefix of the
11567 k
= dirs
[j
].prefix
;
11568 while (k
!= -1 && k
!= (int) i
)
11569 k
= dirs
[k
].prefix
;
11573 /* Yes it is. We can possibly save some memory by
11574 writing the filenames in dirs[j] relative to
11576 savehere
[j
] = dirs
[i
].length
;
11577 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
11582 /* Check whether we can save enough to justify adding the dirs[i]
11584 if (total
> dirs
[i
].length
+ 1)
11586 /* It's worthwhile adding. */
11587 for (j
= i
; j
< ndirs
; j
++)
11588 if (savehere
[j
] > 0)
11590 /* Remember how much we saved for this directory so far. */
11591 saved
[j
] = savehere
[j
];
11593 /* Remember the prefix directory. */
11594 dirs
[j
].dir_idx
= i
;
11599 /* Emit the directory name table. */
11600 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
11601 enum dwarf_form str_form
= DW_FORM_string
;
11602 enum dwarf_form idx_form
= DW_FORM_udata
;
11603 if (dwarf_version
>= 5)
11605 const char *comp_dir
= comp_dir_string ();
11606 if (comp_dir
== NULL
)
11608 dw2_asm_output_data (1, 1, "Directory entry format count");
11609 if (DWARF5_USE_DEBUG_LINE_STR
)
11610 str_form
= DW_FORM_line_strp
;
11611 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11612 dw2_asm_output_data_uleb128 (str_form
, "%s",
11613 get_DW_FORM_name (str_form
));
11614 dw2_asm_output_data_uleb128 (ndirs
+ idx_offset
, "Directories count");
11615 if (str_form
== DW_FORM_string
)
11617 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
11618 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11619 dw2_asm_output_nstring (dirs
[i
].path
,
11621 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11622 "Directory Entry: %#x", i
+ idx_offset
);
11626 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
11627 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11630 = ggc_alloc_string (dirs
[i
].path
,
11632 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
);
11633 output_line_string (str_form
, str
, "Directory Entry",
11634 (unsigned) i
+ idx_offset
);
11640 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11641 dw2_asm_output_nstring (dirs
[i
].path
,
11643 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11644 "Directory Entry: %#x", i
+ idx_offset
);
11646 dw2_asm_output_data (1, 0, "End directory table");
11649 /* We have to emit them in the order of emitted_number since that's
11650 used in the debug info generation. To do this efficiently we
11651 generate a back-mapping of the indices first. */
11652 backmap
= XALLOCAVEC (int, numfiles
);
11653 for (i
= 0; i
< numfiles
; i
++)
11654 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
11656 if (dwarf_version
>= 5)
11658 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
11659 if (filename0
== NULL
)
11661 /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
11662 DW_FORM_data2. Choose one based on the number of directories
11663 and how much space would they occupy in each encoding.
11664 If we have at most 256 directories, all indexes fit into
11665 a single byte, so DW_FORM_data1 is most compact (if there
11666 are at most 128 directories, DW_FORM_udata would be as
11667 compact as that, but not shorter and slower to decode). */
11668 if (ndirs
+ idx_offset
<= 256)
11669 idx_form
= DW_FORM_data1
;
11670 /* If there are more than 65536 directories, we have to use
11671 DW_FORM_udata, DW_FORM_data2 can't refer to them.
11672 Otherwise, compute what space would occupy if all the indexes
11673 used DW_FORM_udata - sum - and compare that to how large would
11674 be DW_FORM_data2 encoding, and pick the more efficient one. */
11675 else if (ndirs
+ idx_offset
<= 65536)
11677 unsigned HOST_WIDE_INT sum
= 1;
11678 for (i
= 0; i
< numfiles
; i
++)
11680 int file_idx
= backmap
[i
];
11681 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11682 sum
+= size_of_uleb128 (dir_idx
);
11684 if (sum
>= HOST_WIDE_INT_UC (2) * (numfiles
+ 1))
11685 idx_form
= DW_FORM_data2
;
11687 #ifdef VMS_DEBUGGING_INFO
11688 dw2_asm_output_data (1, 4, "File name entry format count");
11690 dw2_asm_output_data (1, 2, "File name entry format count");
11692 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11693 dw2_asm_output_data_uleb128 (str_form
, "%s",
11694 get_DW_FORM_name (str_form
));
11695 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
11696 "DW_LNCT_directory_index");
11697 dw2_asm_output_data_uleb128 (idx_form
, "%s",
11698 get_DW_FORM_name (idx_form
));
11699 #ifdef VMS_DEBUGGING_INFO
11700 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
11701 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11702 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
11703 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11705 dw2_asm_output_data_uleb128 (numfiles
+ 1, "File names count");
11707 output_line_string (str_form
, filename0
, "File Entry", 0);
11709 /* Include directory index. */
11710 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11711 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11714 dw2_asm_output_data_uleb128 (0, NULL
);
11716 #ifdef VMS_DEBUGGING_INFO
11717 dw2_asm_output_data_uleb128 (0, NULL
);
11718 dw2_asm_output_data_uleb128 (0, NULL
);
11722 /* Now write all the file names. */
11723 for (i
= 0; i
< numfiles
; i
++)
11725 int file_idx
= backmap
[i
];
11726 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11728 #ifdef VMS_DEBUGGING_INFO
11729 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
11731 /* Setting these fields can lead to debugger miscomparisons,
11732 but VMS Debug requires them to be set correctly. */
11737 int maxfilelen
= (strlen (files
[file_idx
].path
)
11738 + dirs
[dir_idx
].length
11739 + MAX_VMS_VERSION_LEN
+ 1);
11740 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
11742 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
11743 snprintf (filebuf
, maxfilelen
, "%s;%d",
11744 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
11746 output_line_string (str_form
, filebuf
, "File Entry", (unsigned) i
+ 1);
11748 /* Include directory index. */
11749 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11750 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11751 dir_idx
+ idx_offset
, NULL
);
11753 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11755 /* Modification time. */
11756 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11757 &cdt
, 0, 0, 0) == 0)
11760 /* File length in bytes. */
11761 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11762 0, &siz
, 0, 0) == 0)
11765 output_line_string (str_form
,
11766 files
[file_idx
].path
+ dirs
[dir_idx
].length
,
11767 "File Entry", (unsigned) i
+ 1);
11769 /* Include directory index. */
11770 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11771 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11772 dir_idx
+ idx_offset
, NULL
);
11774 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11776 if (dwarf_version
>= 5)
11779 /* Modification time. */
11780 dw2_asm_output_data_uleb128 (0, NULL
);
11782 /* File length in bytes. */
11783 dw2_asm_output_data_uleb128 (0, NULL
);
11784 #endif /* VMS_DEBUGGING_INFO */
11787 if (dwarf_version
< 5)
11788 dw2_asm_output_data (1, 0, "End file name table");
11792 /* Output one line number table into the .debug_line section. */
11795 output_one_line_info_table (dw_line_info_table
*table
)
11797 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11798 unsigned int current_line
= 1;
11799 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
11800 dw_line_info_entry
*ent
;
11803 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
11805 switch (ent
->opcode
)
11807 case LI_set_address
:
11808 /* ??? Unfortunately, we have little choice here currently, and
11809 must always use the most general form. GCC does not know the
11810 address delta itself, so we can't use DW_LNS_advance_pc. Many
11811 ports do have length attributes which will give an upper bound
11812 on the address range. We could perhaps use length attributes
11813 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
11814 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
11816 /* This can handle any delta. This takes
11817 4+DWARF2_ADDR_SIZE bytes. */
11818 dw2_asm_output_data (1, 0, "set address %s", line_label
);
11819 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11820 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11821 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
11825 if (ent
->val
== current_line
)
11827 /* We still need to start a new row, so output a copy insn. */
11828 dw2_asm_output_data (1, DW_LNS_copy
,
11829 "copy line %u", current_line
);
11833 int line_offset
= ent
->val
- current_line
;
11834 int line_delta
= line_offset
- DWARF_LINE_BASE
;
11836 current_line
= ent
->val
;
11837 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
11839 /* This can handle deltas from -10 to 234, using the current
11840 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
11841 This takes 1 byte. */
11842 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
11843 "line %u", current_line
);
11847 /* This can handle any delta. This takes at least 4 bytes,
11848 depending on the value being encoded. */
11849 dw2_asm_output_data (1, DW_LNS_advance_line
,
11850 "advance to line %u", current_line
);
11851 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
11852 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
11858 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
11859 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11862 case LI_set_column
:
11863 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
11864 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11867 case LI_negate_stmt
:
11868 current_is_stmt
= !current_is_stmt
;
11869 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
11870 "is_stmt %d", current_is_stmt
);
11873 case LI_set_prologue_end
:
11874 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
11875 "set prologue end");
11878 case LI_set_epilogue_begin
:
11879 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
11880 "set epilogue begin");
11883 case LI_set_discriminator
:
11884 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
11885 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
11886 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
11887 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
11892 /* Emit debug info for the address of the end of the table. */
11893 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
11894 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11895 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11896 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
11898 dw2_asm_output_data (1, 0, "end sequence");
11899 dw2_asm_output_data_uleb128 (1, NULL
);
11900 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
11903 /* Output the source line number correspondence information. This
11904 information goes into the .debug_line section. */
11907 output_line_info (bool prologue_only
)
11909 static unsigned int generation
;
11910 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11911 char p1
[MAX_ARTIFICIAL_LABEL_BYTES
], p2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11912 bool saw_one
= false;
11915 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, generation
);
11916 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, generation
);
11917 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, generation
);
11918 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, generation
++);
11920 if (!XCOFF_DEBUGGING_INFO
)
11922 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11923 dw2_asm_output_data (4, 0xffffffff,
11924 "Initial length escape value indicating 64-bit DWARF extension");
11925 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11926 "Length of Source Line Info");
11929 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11931 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11932 if (dwarf_version
>= 5)
11934 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11935 dw2_asm_output_data (1, 0, "Segment Size");
11937 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
11938 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
11940 /* Define the architecture-dependent minimum instruction length (in bytes).
11941 In this implementation of DWARF, this field is used for information
11942 purposes only. Since GCC generates assembly language, we have no
11943 a priori knowledge of how many instruction bytes are generated for each
11944 source line, and therefore can use only the DW_LNE_set_address and
11945 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
11946 this as '1', which is "correct enough" for all architectures,
11947 and don't let the target override. */
11948 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
11950 if (dwarf_version
>= 4)
11951 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
11952 "Maximum Operations Per Instruction");
11953 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
11954 "Default is_stmt_start flag");
11955 dw2_asm_output_data (1, DWARF_LINE_BASE
,
11956 "Line Base Value (Special Opcodes)");
11957 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
11958 "Line Range Value (Special Opcodes)");
11959 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
11960 "Special Opcode Base");
11962 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
11967 case DW_LNS_advance_pc
:
11968 case DW_LNS_advance_line
:
11969 case DW_LNS_set_file
:
11970 case DW_LNS_set_column
:
11971 case DW_LNS_fixed_advance_pc
:
11972 case DW_LNS_set_isa
:
11980 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
11984 /* Write out the information about the files we use. */
11985 output_file_names ();
11986 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
11989 /* Output the marker for the end of the line number info. */
11990 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11994 if (separate_line_info
)
11996 dw_line_info_table
*table
;
11999 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
12002 output_one_line_info_table (table
);
12006 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
12008 output_one_line_info_table (cold_text_section_line_info
);
12012 /* ??? Some Darwin linkers crash on a .debug_line section with no
12013 sequences. Further, merely a DW_LNE_end_sequence entry is not
12014 sufficient -- the address column must also be initialized.
12015 Make sure to output at least one set_address/end_sequence pair,
12016 choosing .text since that section is always present. */
12017 if (text_section_line_info
->in_use
|| !saw_one
)
12018 output_one_line_info_table (text_section_line_info
);
12020 /* Output the marker for the end of the line number info. */
12021 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12024 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
12027 need_endianity_attribute_p (bool reverse
)
12029 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
12032 /* Given a pointer to a tree node for some base type, return a pointer to
12033 a DIE that describes the given type. REVERSE is true if the type is
12034 to be interpreted in the reverse storage order wrt the target order.
12036 This routine must only be called for GCC type nodes that correspond to
12037 Dwarf base (fundamental) types. */
12040 base_type_die (tree type
, bool reverse
)
12042 dw_die_ref base_type_result
;
12043 enum dwarf_type encoding
;
12044 bool fpt_used
= false;
12045 struct fixed_point_type_info fpt_info
;
12046 tree type_bias
= NULL_TREE
;
12048 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
12051 /* If this is a subtype that should not be emitted as a subrange type,
12052 use the base type. See subrange_type_for_debug_p. */
12053 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
12054 type
= TREE_TYPE (type
);
12056 switch (TREE_CODE (type
))
12059 if ((dwarf_version
>= 4 || !dwarf_strict
)
12060 && TYPE_NAME (type
)
12061 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12062 && DECL_IS_BUILTIN (TYPE_NAME (type
))
12063 && DECL_NAME (TYPE_NAME (type
)))
12065 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
12066 if (strcmp (name
, "char16_t") == 0
12067 || strcmp (name
, "char32_t") == 0)
12069 encoding
= DW_ATE_UTF
;
12073 if ((dwarf_version
>= 3 || !dwarf_strict
)
12074 && lang_hooks
.types
.get_fixed_point_type_info
)
12076 memset (&fpt_info
, 0, sizeof (fpt_info
));
12077 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
12080 encoding
= ((TYPE_UNSIGNED (type
))
12081 ? DW_ATE_unsigned_fixed
12082 : DW_ATE_signed_fixed
);
12086 if (TYPE_STRING_FLAG (type
))
12088 if (TYPE_UNSIGNED (type
))
12089 encoding
= DW_ATE_unsigned_char
;
12091 encoding
= DW_ATE_signed_char
;
12093 else if (TYPE_UNSIGNED (type
))
12094 encoding
= DW_ATE_unsigned
;
12096 encoding
= DW_ATE_signed
;
12099 && lang_hooks
.types
.get_type_bias
)
12100 type_bias
= lang_hooks
.types
.get_type_bias (type
);
12104 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
12106 if (dwarf_version
>= 3 || !dwarf_strict
)
12107 encoding
= DW_ATE_decimal_float
;
12109 encoding
= DW_ATE_lo_user
;
12112 encoding
= DW_ATE_float
;
12115 case FIXED_POINT_TYPE
:
12116 if (!(dwarf_version
>= 3 || !dwarf_strict
))
12117 encoding
= DW_ATE_lo_user
;
12118 else if (TYPE_UNSIGNED (type
))
12119 encoding
= DW_ATE_unsigned_fixed
;
12121 encoding
= DW_ATE_signed_fixed
;
12124 /* Dwarf2 doesn't know anything about complex ints, so use
12125 a user defined type for it. */
12127 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
12128 encoding
= DW_ATE_complex_float
;
12130 encoding
= DW_ATE_lo_user
;
12134 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12135 encoding
= DW_ATE_boolean
;
12139 /* No other TREE_CODEs are Dwarf fundamental types. */
12140 gcc_unreachable ();
12143 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
12145 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
12146 int_size_in_bytes (type
));
12147 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
12149 if (need_endianity_attribute_p (reverse
))
12150 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
12151 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
12153 add_alignment_attribute (base_type_result
, type
);
12157 switch (fpt_info
.scale_factor_kind
)
12159 case fixed_point_scale_factor_binary
:
12160 add_AT_int (base_type_result
, DW_AT_binary_scale
,
12161 fpt_info
.scale_factor
.binary
);
12164 case fixed_point_scale_factor_decimal
:
12165 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
12166 fpt_info
.scale_factor
.decimal
);
12169 case fixed_point_scale_factor_arbitrary
:
12170 /* Arbitrary scale factors cannot be described in standard DWARF,
12174 /* Describe the scale factor as a rational constant. */
12175 const dw_die_ref scale_factor
12176 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
12178 add_AT_unsigned (scale_factor
, DW_AT_GNU_numerator
,
12179 fpt_info
.scale_factor
.arbitrary
.numerator
);
12180 add_AT_int (scale_factor
, DW_AT_GNU_denominator
,
12181 fpt_info
.scale_factor
.arbitrary
.denominator
);
12183 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
12188 gcc_unreachable ();
12193 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
12194 dw_scalar_form_constant
12195 | dw_scalar_form_exprloc
12196 | dw_scalar_form_reference
,
12199 add_pubtype (type
, base_type_result
);
12201 return base_type_result
;
12204 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
12205 named 'auto' in its type: return true for it, false otherwise. */
12208 is_cxx_auto (tree type
)
12212 tree name
= TYPE_IDENTIFIER (type
);
12213 if (name
== get_identifier ("auto")
12214 || name
== get_identifier ("decltype(auto)"))
12220 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12221 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12224 is_base_type (tree type
)
12226 switch (TREE_CODE (type
))
12232 case FIXED_POINT_TYPE
:
12235 case POINTER_BOUNDS_TYPE
:
12241 case QUAL_UNION_TYPE
:
12242 case ENUMERAL_TYPE
:
12243 case FUNCTION_TYPE
:
12246 case REFERENCE_TYPE
:
12254 if (is_cxx_auto (type
))
12256 gcc_unreachable ();
12262 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12263 node, return the size in bits for the type if it is a constant, or else
12264 return the alignment for the type if the type's size is not constant, or
12265 else return BITS_PER_WORD if the type actually turns out to be an
12266 ERROR_MARK node. */
12268 static inline unsigned HOST_WIDE_INT
12269 simple_type_size_in_bits (const_tree type
)
12271 if (TREE_CODE (type
) == ERROR_MARK
)
12272 return BITS_PER_WORD
;
12273 else if (TYPE_SIZE (type
) == NULL_TREE
)
12275 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
12276 return tree_to_uhwi (TYPE_SIZE (type
));
12278 return TYPE_ALIGN (type
);
12281 /* Similarly, but return an offset_int instead of UHWI. */
12283 static inline offset_int
12284 offset_int_type_size_in_bits (const_tree type
)
12286 if (TREE_CODE (type
) == ERROR_MARK
)
12287 return BITS_PER_WORD
;
12288 else if (TYPE_SIZE (type
) == NULL_TREE
)
12290 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
12291 return wi::to_offset (TYPE_SIZE (type
));
12293 return TYPE_ALIGN (type
);
12296 /* Given a pointer to a tree node for a subrange type, return a pointer
12297 to a DIE that describes the given type. */
12300 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
12301 dw_die_ref context_die
)
12303 dw_die_ref subrange_die
;
12304 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
12306 if (context_die
== NULL
)
12307 context_die
= comp_unit_die ();
12309 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
12311 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
12313 /* The size of the subrange type and its base type do not match,
12314 so we need to generate a size attribute for the subrange type. */
12315 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
12318 add_alignment_attribute (subrange_die
, type
);
12321 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
12323 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
12324 if (bias
&& !dwarf_strict
)
12325 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
12326 dw_scalar_form_constant
12327 | dw_scalar_form_exprloc
12328 | dw_scalar_form_reference
,
12331 return subrange_die
;
12334 /* Returns the (const and/or volatile) cv_qualifiers associated with
12335 the decl node. This will normally be augmented with the
12336 cv_qualifiers of the underlying type in add_type_attribute. */
12339 decl_quals (const_tree decl
)
12341 return ((TREE_READONLY (decl
)
12342 /* The C++ front-end correctly marks reference-typed
12343 variables as readonly, but from a language (and debug
12344 info) standpoint they are not const-qualified. */
12345 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
12346 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
12347 | (TREE_THIS_VOLATILE (decl
)
12348 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
12351 /* Determine the TYPE whose qualifiers match the largest strict subset
12352 of the given TYPE_QUALS, and return its qualifiers. Ignore all
12353 qualifiers outside QUAL_MASK. */
12356 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
12359 int best_rank
= 0, best_qual
= 0, max_rank
;
12361 type_quals
&= qual_mask
;
12362 max_rank
= popcount_hwi (type_quals
) - 1;
12364 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
12365 t
= TYPE_NEXT_VARIANT (t
))
12367 int q
= TYPE_QUALS (t
) & qual_mask
;
12369 if ((q
& type_quals
) == q
&& q
!= type_quals
12370 && check_base_type (t
, type
))
12372 int rank
= popcount_hwi (q
);
12374 if (rank
> best_rank
)
12385 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
12386 static const dwarf_qual_info_t dwarf_qual_info
[] =
12388 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
12389 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
12390 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
12391 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
12393 static const unsigned int dwarf_qual_info_size
12394 = sizeof (dwarf_qual_info
) / sizeof (dwarf_qual_info
[0]);
12396 /* If DIE is a qualified DIE of some base DIE with the same parent,
12397 return the base DIE, otherwise return NULL. Set MASK to the
12398 qualifiers added compared to the returned DIE. */
12401 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
12404 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12405 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
12407 if (i
== dwarf_qual_info_size
)
12409 if (vec_safe_length (die
->die_attr
) != 1)
12411 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
12412 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
12414 *mask
|= dwarf_qual_info
[i
].q
;
12417 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
12424 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12425 entry that chains the modifiers specified by CV_QUALS in front of the
12426 given type. REVERSE is true if the type is to be interpreted in the
12427 reverse storage order wrt the target order. */
12430 modified_type_die (tree type
, int cv_quals
, bool reverse
,
12431 dw_die_ref context_die
)
12433 enum tree_code code
= TREE_CODE (type
);
12434 dw_die_ref mod_type_die
;
12435 dw_die_ref sub_die
= NULL
;
12436 tree item_type
= NULL
;
12437 tree qualified_type
;
12438 tree name
, low
, high
;
12439 dw_die_ref mod_scope
;
12440 /* Only these cv-qualifiers are currently handled. */
12441 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
12442 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
12444 if (code
== ERROR_MARK
)
12447 if (lang_hooks
.types
.get_debug_type
)
12449 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
12451 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
12452 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
12455 cv_quals
&= cv_qual_mask
;
12457 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
12458 tag modifier (and not an attribute) old consumers won't be able
12460 if (dwarf_version
< 3)
12461 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
12463 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
12464 if (dwarf_version
< 5)
12465 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
12467 /* See if we already have the appropriately qualified variant of
12469 qualified_type
= get_qualified_type (type
, cv_quals
);
12471 if (qualified_type
== sizetype
)
12473 /* Try not to expose the internal sizetype type's name. */
12474 if (TYPE_NAME (qualified_type
)
12475 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
12477 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
12479 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
12480 && (TYPE_PRECISION (t
)
12481 == TYPE_PRECISION (qualified_type
))
12482 && (TYPE_UNSIGNED (t
)
12483 == TYPE_UNSIGNED (qualified_type
)));
12484 qualified_type
= t
;
12486 else if (qualified_type
== sizetype
12487 && TREE_CODE (sizetype
) == TREE_CODE (size_type_node
)
12488 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (size_type_node
)
12489 && TYPE_UNSIGNED (sizetype
) == TYPE_UNSIGNED (size_type_node
))
12490 qualified_type
= size_type_node
;
12494 /* If we do, then we can just use its DIE, if it exists. */
12495 if (qualified_type
)
12497 mod_type_die
= lookup_type_die (qualified_type
);
12499 /* DW_AT_endianity doesn't come from a qualifier on the type. */
12501 && (!need_endianity_attribute_p (reverse
)
12502 || !is_base_type (type
)
12503 || get_AT_unsigned (mod_type_die
, DW_AT_endianity
)))
12504 return mod_type_die
;
12507 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
12509 /* Handle C typedef types. */
12510 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
12511 && !DECL_ARTIFICIAL (name
))
12513 tree dtype
= TREE_TYPE (name
);
12515 if (qualified_type
== dtype
)
12517 /* For a named type, use the typedef. */
12518 gen_type_die (qualified_type
, context_die
);
12519 return lookup_type_die (qualified_type
);
12523 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
12524 dquals
&= cv_qual_mask
;
12525 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
12526 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
12527 /* cv-unqualified version of named type. Just use
12528 the unnamed type to which it refers. */
12529 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
12530 reverse
, context_die
);
12531 /* Else cv-qualified version of named type; fall through. */
12535 mod_scope
= scope_die_for (type
, context_die
);
12539 int sub_quals
= 0, first_quals
= 0;
12541 dw_die_ref first
= NULL
, last
= NULL
;
12543 /* Determine a lesser qualified type that most closely matches
12544 this one. Then generate DW_TAG_* entries for the remaining
12546 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
12548 if (sub_quals
&& use_debug_types
)
12550 bool needed
= false;
12551 /* If emitting type units, make sure the order of qualifiers
12552 is canonical. Thus, start from unqualified type if
12553 an earlier qualifier is missing in sub_quals, but some later
12554 one is present there. */
12555 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12556 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12558 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
12564 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
12565 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
12567 /* As not all intermediate qualified DIEs have corresponding
12568 tree types, ensure that qualified DIEs in the same scope
12569 as their DW_AT_type are emitted after their DW_AT_type,
12570 only with other qualified DIEs for the same type possibly
12571 in between them. Determine the range of such qualified
12572 DIEs now (first being the base type, last being corresponding
12573 last qualified DIE for it). */
12574 unsigned int count
= 0;
12575 first
= qualified_die_p (mod_type_die
, &first_quals
,
12576 dwarf_qual_info_size
);
12578 first
= mod_type_die
;
12579 gcc_assert ((first_quals
& ~sub_quals
) == 0);
12580 for (count
= 0, last
= first
;
12581 count
< (1U << dwarf_qual_info_size
);
12582 count
++, last
= last
->die_sib
)
12585 if (last
== mod_scope
->die_child
)
12587 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
12593 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12594 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12597 if (first
&& first
!= last
)
12599 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
12602 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
12603 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
12619 d
= ggc_cleared_alloc
<die_node
> ();
12620 d
->die_tag
= dwarf_qual_info
[i
].t
;
12621 add_child_die_after (mod_scope
, d
, last
);
12625 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
12627 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
12629 first_quals
|= dwarf_qual_info
[i
].q
;
12632 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
12634 dwarf_tag tag
= DW_TAG_pointer_type
;
12635 if (code
== REFERENCE_TYPE
)
12637 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
12638 tag
= DW_TAG_rvalue_reference_type
;
12640 tag
= DW_TAG_reference_type
;
12642 mod_type_die
= new_die (tag
, mod_scope
, type
);
12644 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12645 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12646 add_alignment_attribute (mod_type_die
, type
);
12647 item_type
= TREE_TYPE (type
);
12649 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
12650 if (!ADDR_SPACE_GENERIC_P (as
))
12652 int action
= targetm
.addr_space
.debug (as
);
12655 /* Positive values indicate an address_class. */
12656 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
12660 /* Negative values indicate an (inverted) segment base reg. */
12662 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
12663 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
12667 else if (code
== INTEGER_TYPE
12668 && TREE_TYPE (type
) != NULL_TREE
12669 && subrange_type_for_debug_p (type
, &low
, &high
))
12671 tree bias
= NULL_TREE
;
12672 if (lang_hooks
.types
.get_type_bias
)
12673 bias
= lang_hooks
.types
.get_type_bias (type
);
12674 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
12675 item_type
= TREE_TYPE (type
);
12677 else if (is_base_type (type
))
12678 mod_type_die
= base_type_die (type
, reverse
);
12681 gen_type_die (type
, context_die
);
12683 /* We have to get the type_main_variant here (and pass that to the
12684 `lookup_type_die' routine) because the ..._TYPE node we have
12685 might simply be a *copy* of some original type node (where the
12686 copy was created to help us keep track of typedef names) and
12687 that copy might have a different TYPE_UID from the original
12689 if (TREE_CODE (type
) == FUNCTION_TYPE
12690 || TREE_CODE (type
) == METHOD_TYPE
)
12692 /* For function/method types, can't just use type_main_variant here,
12693 because that can have different ref-qualifiers for C++,
12694 but try to canonicalize. */
12695 tree main
= TYPE_MAIN_VARIANT (type
);
12696 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
12697 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
12698 && check_base_type (t
, main
)
12699 && check_lang_type (t
, type
))
12700 return lookup_type_die (t
);
12701 return lookup_type_die (type
);
12703 else if (TREE_CODE (type
) != VECTOR_TYPE
12704 && TREE_CODE (type
) != ARRAY_TYPE
)
12705 return lookup_type_die (type_main_variant (type
));
12707 /* Vectors have the debugging information in the type,
12708 not the main variant. */
12709 return lookup_type_die (type
);
12712 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12713 don't output a DW_TAG_typedef, since there isn't one in the
12714 user's program; just attach a DW_AT_name to the type.
12715 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12716 if the base type already has the same name. */
12718 && ((TREE_CODE (name
) != TYPE_DECL
12719 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
12720 || (cv_quals
== TYPE_UNQUALIFIED
)))
12721 || (TREE_CODE (name
) == TYPE_DECL
12722 && TREE_TYPE (name
) == qualified_type
12723 && DECL_NAME (name
))))
12725 if (TREE_CODE (name
) == TYPE_DECL
)
12726 /* Could just call add_name_and_src_coords_attributes here,
12727 but since this is a builtin type it doesn't have any
12728 useful source coordinates anyway. */
12729 name
= DECL_NAME (name
);
12730 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
12732 /* This probably indicates a bug. */
12733 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
12735 name
= TYPE_IDENTIFIER (type
);
12736 add_name_attribute (mod_type_die
,
12737 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
12740 if (qualified_type
)
12741 equate_type_number_to_die (qualified_type
, mod_type_die
);
12744 /* We must do this after the equate_type_number_to_die call, in case
12745 this is a recursive type. This ensures that the modified_type_die
12746 recursion will terminate even if the type is recursive. Recursive
12747 types are possible in Ada. */
12748 sub_die
= modified_type_die (item_type
,
12749 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
12753 if (sub_die
!= NULL
)
12754 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
12756 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
12757 if (TYPE_ARTIFICIAL (type
))
12758 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
12760 return mod_type_die
;
12763 /* Generate DIEs for the generic parameters of T.
12764 T must be either a generic type or a generic function.
12765 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12768 gen_generic_params_dies (tree t
)
12772 dw_die_ref die
= NULL
;
12775 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
12779 die
= lookup_type_die (t
);
12780 else if (DECL_P (t
))
12781 die
= lookup_decl_die (t
);
12785 parms
= lang_hooks
.get_innermost_generic_parms (t
);
12787 /* T has no generic parameter. It means T is neither a generic type
12788 or function. End of story. */
12791 parms_num
= TREE_VEC_LENGTH (parms
);
12792 args
= lang_hooks
.get_innermost_generic_args (t
);
12793 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
12794 non_default
= int_cst_value (TREE_CHAIN (args
));
12796 non_default
= TREE_VEC_LENGTH (args
);
12797 for (i
= 0; i
< parms_num
; i
++)
12799 tree parm
, arg
, arg_pack_elems
;
12800 dw_die_ref parm_die
;
12802 parm
= TREE_VEC_ELT (parms
, i
);
12803 arg
= TREE_VEC_ELT (args
, i
);
12804 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
12805 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
12807 if (parm
&& TREE_VALUE (parm
) && arg
)
12809 /* If PARM represents a template parameter pack,
12810 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12811 by DW_TAG_template_*_parameter DIEs for the argument
12812 pack elements of ARG. Note that ARG would then be
12813 an argument pack. */
12814 if (arg_pack_elems
)
12815 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
12819 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
12820 true /* emit name */, die
);
12821 if (i
>= non_default
)
12822 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
12827 /* Create and return a DIE for PARM which should be
12828 the representation of a generic type parameter.
12829 For instance, in the C++ front end, PARM would be a template parameter.
12830 ARG is the argument to PARM.
12831 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12833 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12834 as a child node. */
12837 generic_parameter_die (tree parm
, tree arg
,
12839 dw_die_ref parent_die
)
12841 dw_die_ref tmpl_die
= NULL
;
12842 const char *name
= NULL
;
12844 if (!parm
|| !DECL_NAME (parm
) || !arg
)
12847 /* We support non-type generic parameters and arguments,
12848 type generic parameters and arguments, as well as
12849 generic generic parameters (a.k.a. template template parameters in C++)
12851 if (TREE_CODE (parm
) == PARM_DECL
)
12852 /* PARM is a nontype generic parameter */
12853 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
12854 else if (TREE_CODE (parm
) == TYPE_DECL
)
12855 /* PARM is a type generic parameter. */
12856 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
12857 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12858 /* PARM is a generic generic parameter.
12859 Its DIE is a GNU extension. It shall have a
12860 DW_AT_name attribute to represent the name of the template template
12861 parameter, and a DW_AT_GNU_template_name attribute to represent the
12862 name of the template template argument. */
12863 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
12866 gcc_unreachable ();
12872 /* If PARM is a generic parameter pack, it means we are
12873 emitting debug info for a template argument pack element.
12874 In other terms, ARG is a template argument pack element.
12875 In that case, we don't emit any DW_AT_name attribute for
12879 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
12881 add_AT_string (tmpl_die
, DW_AT_name
, name
);
12884 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12886 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
12887 TMPL_DIE should have a child DW_AT_type attribute that is set
12888 to the type of the argument to PARM, which is ARG.
12889 If PARM is a type generic parameter, TMPL_DIE should have a
12890 child DW_AT_type that is set to ARG. */
12891 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
12892 add_type_attribute (tmpl_die
, tmpl_type
,
12893 (TREE_THIS_VOLATILE (tmpl_type
)
12894 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
12895 false, parent_die
);
12899 /* So TMPL_DIE is a DIE representing a
12900 a generic generic template parameter, a.k.a template template
12901 parameter in C++ and arg is a template. */
12903 /* The DW_AT_GNU_template_name attribute of the DIE must be set
12904 to the name of the argument. */
12905 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
12907 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
12910 if (TREE_CODE (parm
) == PARM_DECL
)
12911 /* So PARM is a non-type generic parameter.
12912 DWARF3 5.6.8 says we must set a DW_AT_const_value child
12913 attribute of TMPL_DIE which value represents the value
12915 We must be careful here:
12916 The value of ARG might reference some function decls.
12917 We might currently be emitting debug info for a generic
12918 type and types are emitted before function decls, we don't
12919 know if the function decls referenced by ARG will actually be
12920 emitted after cgraph computations.
12921 So must defer the generation of the DW_AT_const_value to
12922 after cgraph is ready. */
12923 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
12929 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
12930 PARM_PACK must be a template parameter pack. The returned DIE
12931 will be child DIE of PARENT_DIE. */
12934 template_parameter_pack_die (tree parm_pack
,
12935 tree parm_pack_args
,
12936 dw_die_ref parent_die
)
12941 gcc_assert (parent_die
&& parm_pack
);
12943 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
12944 add_name_and_src_coords_attributes (die
, parm_pack
);
12945 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
12946 generic_parameter_die (parm_pack
,
12947 TREE_VEC_ELT (parm_pack_args
, j
),
12948 false /* Don't emit DW_AT_name */,
12953 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
12954 an enumerated type. */
12957 type_is_enum (const_tree type
)
12959 return TREE_CODE (type
) == ENUMERAL_TYPE
;
12962 /* Return the DBX register number described by a given RTL node. */
12964 static unsigned int
12965 dbx_reg_number (const_rtx rtl
)
12967 unsigned regno
= REGNO (rtl
);
12969 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
12971 #ifdef LEAF_REG_REMAP
12972 if (crtl
->uses_only_leaf_regs
)
12974 int leaf_reg
= LEAF_REG_REMAP (regno
);
12975 if (leaf_reg
!= -1)
12976 regno
= (unsigned) leaf_reg
;
12980 regno
= DBX_REGISTER_NUMBER (regno
);
12981 gcc_assert (regno
!= INVALID_REGNUM
);
12985 /* Optionally add a DW_OP_piece term to a location description expression.
12986 DW_OP_piece is only added if the location description expression already
12987 doesn't end with DW_OP_piece. */
12990 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
12992 dw_loc_descr_ref loc
;
12994 if (*list_head
!= NULL
)
12996 /* Find the end of the chain. */
12997 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
13000 if (loc
->dw_loc_opc
!= DW_OP_piece
)
13001 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
13005 /* Return a location descriptor that designates a machine register or
13006 zero if there is none. */
13008 static dw_loc_descr_ref
13009 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
13013 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
13016 /* We only use "frame base" when we're sure we're talking about the
13017 post-prologue local stack frame. We do this by *not* running
13018 register elimination until this point, and recognizing the special
13019 argument pointer and soft frame pointer rtx's.
13020 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13021 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
13022 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
13024 dw_loc_descr_ref result
= NULL
;
13026 if (dwarf_version
>= 4 || !dwarf_strict
)
13028 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
13031 add_loc_descr (&result
,
13032 new_loc_descr (DW_OP_stack_value
, 0, 0));
13037 regs
= targetm
.dwarf_register_span (rtl
);
13039 if (REG_NREGS (rtl
) > 1 || regs
)
13040 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
13043 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
13044 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
13046 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
13050 /* Return a location descriptor that designates a machine register for
13051 a given hard register number. */
13053 static dw_loc_descr_ref
13054 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
13056 dw_loc_descr_ref reg_loc_descr
;
13060 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
13062 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
13064 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13065 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13067 return reg_loc_descr
;
13070 /* Given an RTL of a register, return a location descriptor that
13071 designates a value that spans more than one register. */
13073 static dw_loc_descr_ref
13074 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
13075 enum var_init_status initialized
)
13078 dw_loc_descr_ref loc_result
= NULL
;
13080 /* Simple, contiguous registers. */
13081 if (regs
== NULL_RTX
)
13083 unsigned reg
= REGNO (rtl
);
13086 #ifdef LEAF_REG_REMAP
13087 if (crtl
->uses_only_leaf_regs
)
13089 int leaf_reg
= LEAF_REG_REMAP (reg
);
13090 if (leaf_reg
!= -1)
13091 reg
= (unsigned) leaf_reg
;
13095 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
13096 nregs
= REG_NREGS (rtl
);
13098 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
13103 dw_loc_descr_ref t
;
13105 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
13106 VAR_INIT_STATUS_INITIALIZED
);
13107 add_loc_descr (&loc_result
, t
);
13108 add_loc_descr_op_piece (&loc_result
, size
);
13114 /* Now onto stupid register sets in non contiguous locations. */
13116 gcc_assert (GET_CODE (regs
) == PARALLEL
);
13118 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13121 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
13123 dw_loc_descr_ref t
;
13125 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
13126 VAR_INIT_STATUS_INITIALIZED
);
13127 add_loc_descr (&loc_result
, t
);
13128 add_loc_descr_op_piece (&loc_result
, size
);
13131 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13132 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13136 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
13138 /* Return a location descriptor that designates a constant i,
13139 as a compound operation from constant (i >> shift), constant shift
13142 static dw_loc_descr_ref
13143 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13145 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
13146 add_loc_descr (&ret
, int_loc_descriptor (shift
));
13147 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13151 /* Return a location descriptor that designates a constant. */
13153 static dw_loc_descr_ref
13154 int_loc_descriptor (HOST_WIDE_INT i
)
13156 enum dwarf_location_atom op
;
13158 /* Pick the smallest representation of a constant, rather than just
13159 defaulting to the LEB encoding. */
13162 int clz
= clz_hwi (i
);
13163 int ctz
= ctz_hwi (i
);
13165 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
13166 else if (i
<= 0xff)
13167 op
= DW_OP_const1u
;
13168 else if (i
<= 0xffff)
13169 op
= DW_OP_const2u
;
13170 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13171 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13172 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
13173 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
13174 while DW_OP_const4u is 5 bytes. */
13175 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
13176 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13177 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13178 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
13179 while DW_OP_const4u is 5 bytes. */
13180 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13182 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13183 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13186 /* As i >= 2**31, the double cast above will yield a negative number.
13187 Since wrapping is defined in DWARF expressions we can output big
13188 positive integers as small negative ones, regardless of the size
13191 Here, since the evaluator will handle 32-bit values and since i >=
13192 2**31, we know it's going to be interpreted as a negative literal:
13193 store it this way if we can do better than 5 bytes this way. */
13194 return int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13196 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13197 op
= DW_OP_const4u
;
13199 /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
13200 least 6 bytes: see if we can do better before falling back to it. */
13201 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13202 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13203 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
13204 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13205 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13206 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
13207 >= HOST_BITS_PER_WIDE_INT
)
13208 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
13209 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
13210 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
13211 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13212 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13213 && size_of_uleb128 (i
) > 6)
13214 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
13215 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
13222 op
= DW_OP_const1s
;
13223 else if (i
>= -0x8000)
13224 op
= DW_OP_const2s
;
13225 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13227 if (size_of_int_loc_descriptor (i
) < 5)
13229 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13230 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13233 op
= DW_OP_const4s
;
13237 if (size_of_int_loc_descriptor (i
)
13238 < (unsigned long) 1 + size_of_sleb128 (i
))
13240 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13241 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13248 return new_loc_descr (op
, i
, 0);
13251 /* Likewise, for unsigned constants. */
13253 static dw_loc_descr_ref
13254 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
13256 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
13257 const unsigned HOST_WIDE_INT max_uint
13258 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
13260 /* If possible, use the clever signed constants handling. */
13262 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
13264 /* Here, we are left with positive numbers that cannot be represented as
13265 HOST_WIDE_INT, i.e.:
13266 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
13268 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
13269 whereas may be better to output a negative integer: thanks to integer
13270 wrapping, we know that:
13271 x = x - 2 ** DWARF2_ADDR_SIZE
13272 = x - 2 * (max (HOST_WIDE_INT) + 1)
13273 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
13274 small negative integers. Let's try that in cases it will clearly improve
13275 the encoding: there is no gain turning DW_OP_const4u into
13277 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
13278 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
13279 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
13281 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
13283 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
13284 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
13285 const HOST_WIDE_INT second_shift
13286 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
13288 /* So we finally have:
13289 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
13290 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
13291 return int_loc_descriptor (second_shift
);
13294 /* Last chance: fallback to a simple constant operation. */
13295 return new_loc_descr
13296 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13302 /* Generate and return a location description that computes the unsigned
13303 comparison of the two stack top entries (a OP b where b is the top-most
13304 entry and a is the second one). The KIND of comparison can be LT_EXPR,
13305 LE_EXPR, GT_EXPR or GE_EXPR. */
13307 static dw_loc_descr_ref
13308 uint_comparison_loc_list (enum tree_code kind
)
13310 enum dwarf_location_atom op
, flip_op
;
13311 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
13328 gcc_unreachable ();
13331 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13332 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13334 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
13335 possible to perform unsigned comparisons: we just have to distinguish
13338 1. when a and b have the same sign (as signed integers); then we should
13339 return: a OP(signed) b;
13341 2. when a is a negative signed integer while b is a positive one, then a
13342 is a greater unsigned integer than b; likewise when a and b's roles
13345 So first, compare the sign of the two operands. */
13346 ret
= new_loc_descr (DW_OP_over
, 0, 0);
13347 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13348 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
13349 /* If they have different signs (i.e. they have different sign bits), then
13350 the stack top value has now the sign bit set and thus it's smaller than
13352 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
13353 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
13354 add_loc_descr (&ret
, bra_node
);
13356 /* We are in case 1. At this point, we know both operands have the same
13357 sign, to it's safe to use the built-in signed comparison. */
13358 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13359 add_loc_descr (&ret
, jmp_node
);
13361 /* We are in case 2. Here, we know both operands do not have the same sign,
13362 so we have to flip the signed comparison. */
13363 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
13364 tmp
= new_loc_descr (flip_op
, 0, 0);
13365 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13366 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13367 add_loc_descr (&ret
, tmp
);
13369 /* This dummy operation is necessary to make the two branches join. */
13370 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13371 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13372 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13373 add_loc_descr (&ret
, tmp
);
13378 /* Likewise, but takes the location description lists (might be destructive on
13379 them). Return NULL if either is NULL or if concatenation fails. */
13381 static dw_loc_list_ref
13382 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
13383 enum tree_code kind
)
13385 if (left
== NULL
|| right
== NULL
)
13388 add_loc_list (&left
, right
);
13392 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
13396 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
13397 without actually allocating it. */
13399 static unsigned long
13400 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13402 return size_of_int_loc_descriptor (i
>> shift
)
13403 + size_of_int_loc_descriptor (shift
)
13407 /* Return size_of_locs (int_loc_descriptor (i)) without
13408 actually allocating it. */
13410 static unsigned long
13411 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
13420 else if (i
<= 0xff)
13422 else if (i
<= 0xffff)
13426 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13427 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13428 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13430 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13431 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13432 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13434 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13435 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13437 return size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13438 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13440 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
13441 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13442 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13443 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13445 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13446 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
13447 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13449 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13450 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13452 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13461 else if (i
>= -0x8000)
13463 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13465 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13467 s
= size_of_int_loc_descriptor (-i
) + 1;
13475 unsigned long r
= 1 + size_of_sleb128 (i
);
13476 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13478 s
= size_of_int_loc_descriptor (-i
) + 1;
13487 /* Return loc description representing "address" of integer value.
13488 This can appear only as toplevel expression. */
13490 static dw_loc_descr_ref
13491 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
13494 dw_loc_descr_ref loc_result
= NULL
;
13496 if (!(dwarf_version
>= 4 || !dwarf_strict
))
13499 litsize
= size_of_int_loc_descriptor (i
);
13500 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13501 is more compact. For DW_OP_stack_value we need:
13502 litsize + 1 (DW_OP_stack_value)
13503 and for DW_OP_implicit_value:
13504 1 (DW_OP_implicit_value) + 1 (length) + size. */
13505 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
13507 loc_result
= int_loc_descriptor (i
);
13508 add_loc_descr (&loc_result
,
13509 new_loc_descr (DW_OP_stack_value
, 0, 0));
13513 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13515 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13516 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
13520 /* Return a location descriptor that designates a base+offset location. */
13522 static dw_loc_descr_ref
13523 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
13524 enum var_init_status initialized
)
13526 unsigned int regno
;
13527 dw_loc_descr_ref result
;
13528 dw_fde_ref fde
= cfun
->fde
;
13530 /* We only use "frame base" when we're sure we're talking about the
13531 post-prologue local stack frame. We do this by *not* running
13532 register elimination until this point, and recognizing the special
13533 argument pointer and soft frame pointer rtx's. */
13534 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
13536 rtx elim
= (ira_use_lra_p
13537 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
13538 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
13542 if (GET_CODE (elim
) == PLUS
)
13544 offset
+= INTVAL (XEXP (elim
, 1));
13545 elim
= XEXP (elim
, 0);
13547 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13548 && (elim
== hard_frame_pointer_rtx
13549 || elim
== stack_pointer_rtx
))
13550 || elim
== (frame_pointer_needed
13551 ? hard_frame_pointer_rtx
13552 : stack_pointer_rtx
));
13554 /* If drap register is used to align stack, use frame
13555 pointer + offset to access stack variables. If stack
13556 is aligned without drap, use stack pointer + offset to
13557 access stack variables. */
13558 if (crtl
->stack_realign_tried
13559 && reg
== frame_pointer_rtx
)
13562 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
13563 ? HARD_FRAME_POINTER_REGNUM
13565 return new_reg_loc_descr (base_reg
, offset
);
13568 gcc_assert (frame_pointer_fb_offset_valid
);
13569 offset
+= frame_pointer_fb_offset
;
13570 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13574 regno
= REGNO (reg
);
13575 #ifdef LEAF_REG_REMAP
13576 if (crtl
->uses_only_leaf_regs
)
13578 int leaf_reg
= LEAF_REG_REMAP (regno
);
13579 if (leaf_reg
!= -1)
13580 regno
= (unsigned) leaf_reg
;
13583 regno
= DWARF_FRAME_REGNUM (regno
);
13585 if (!optimize
&& fde
13586 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
13588 /* Use cfa+offset to represent the location of arguments passed
13589 on the stack when drap is used to align stack.
13590 Only do this when not optimizing, for optimized code var-tracking
13591 is supposed to track where the arguments live and the register
13592 used as vdrap or drap in some spot might be used for something
13593 else in other part of the routine. */
13594 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13598 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
13601 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
13603 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13604 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13609 /* Return true if this RTL expression describes a base+offset calculation. */
13612 is_based_loc (const_rtx rtl
)
13614 return (GET_CODE (rtl
) == PLUS
13615 && ((REG_P (XEXP (rtl
, 0))
13616 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
13617 && CONST_INT_P (XEXP (rtl
, 1)))));
13620 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13623 static dw_loc_descr_ref
13624 tls_mem_loc_descriptor (rtx mem
)
13627 dw_loc_descr_ref loc_result
;
13629 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
13632 base
= get_base_address (MEM_EXPR (mem
));
13635 || !DECL_THREAD_LOCAL_P (base
))
13638 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
13639 if (loc_result
== NULL
)
13642 if (MEM_OFFSET (mem
))
13643 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
13648 /* Output debug info about reason why we failed to expand expression as dwarf
13652 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
13654 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
13656 fprintf (dump_file
, "Failed to expand as dwarf: ");
13658 print_generic_expr (dump_file
, expr
, dump_flags
);
13661 fprintf (dump_file
, "\n");
13662 print_rtl (dump_file
, rtl
);
13664 fprintf (dump_file
, "\nReason: %s\n", reason
);
13668 /* Helper function for const_ok_for_output. */
13671 const_ok_for_output_1 (rtx rtl
)
13673 if (GET_CODE (rtl
) == UNSPEC
)
13675 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13676 we can't express it in the debug info. */
13677 /* Don't complain about TLS UNSPECs, those are just too hard to
13678 delegitimize. Note this could be a non-decl SYMBOL_REF such as
13679 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
13680 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
13682 && (XVECLEN (rtl
, 0) == 0
13683 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
13684 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
13685 inform (current_function_decl
13686 ? DECL_SOURCE_LOCATION (current_function_decl
)
13687 : UNKNOWN_LOCATION
,
13688 #if NUM_UNSPEC_VALUES > 0
13689 "non-delegitimized UNSPEC %s (%d) found in variable location",
13690 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
13691 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
13694 "non-delegitimized UNSPEC %d found in variable location",
13697 expansion_failed (NULL_TREE
, rtl
,
13698 "UNSPEC hasn't been delegitimized.\n");
13702 if (targetm
.const_not_ok_for_debug_p (rtl
))
13704 expansion_failed (NULL_TREE
, rtl
,
13705 "Expression rejected for debug by the backend.\n");
13709 /* FIXME: Refer to PR60655. It is possible for simplification
13710 of rtl expressions in var tracking to produce such expressions.
13711 We should really identify / validate expressions
13712 enclosed in CONST that can be handled by assemblers on various
13713 targets and only handle legitimate cases here. */
13714 if (GET_CODE (rtl
) != SYMBOL_REF
)
13716 if (GET_CODE (rtl
) == NOT
)
13721 if (CONSTANT_POOL_ADDRESS_P (rtl
))
13724 get_pool_constant_mark (rtl
, &marked
);
13725 /* If all references to this pool constant were optimized away,
13726 it was not output and thus we can't represent it. */
13729 expansion_failed (NULL_TREE
, rtl
,
13730 "Constant was removed from constant pool.\n");
13735 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13738 /* Avoid references to external symbols in debug info, on several targets
13739 the linker might even refuse to link when linking a shared library,
13740 and in many other cases the relocations for .debug_info/.debug_loc are
13741 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13742 to be defined within the same shared library or executable are fine. */
13743 if (SYMBOL_REF_EXTERNAL_P (rtl
))
13745 tree decl
= SYMBOL_REF_DECL (rtl
);
13747 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
13749 expansion_failed (NULL_TREE
, rtl
,
13750 "Symbol not defined in current TU.\n");
13758 /* Return true if constant RTL can be emitted in DW_OP_addr or
13759 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13760 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13763 const_ok_for_output (rtx rtl
)
13765 if (GET_CODE (rtl
) == SYMBOL_REF
)
13766 return const_ok_for_output_1 (rtl
);
13768 if (GET_CODE (rtl
) == CONST
)
13770 subrtx_var_iterator::array_type array
;
13771 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
13772 if (!const_ok_for_output_1 (*iter
))
13780 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
13781 if possible, NULL otherwise. */
13784 base_type_for_mode (machine_mode mode
, bool unsignedp
)
13786 dw_die_ref type_die
;
13787 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
13791 switch (TREE_CODE (type
))
13799 type_die
= lookup_type_die (type
);
13801 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
13803 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
13808 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
13809 type matching MODE, or, if MODE is narrower than or as wide as
13810 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
13813 static dw_loc_descr_ref
13814 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
13816 machine_mode outer_mode
= mode
;
13817 dw_die_ref type_die
;
13818 dw_loc_descr_ref cvt
;
13820 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13822 add_loc_descr (&op
, new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
13825 type_die
= base_type_for_mode (outer_mode
, 1);
13826 if (type_die
== NULL
)
13828 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13829 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13830 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13831 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13832 add_loc_descr (&op
, cvt
);
13836 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
13838 static dw_loc_descr_ref
13839 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
13840 dw_loc_descr_ref op1
)
13842 dw_loc_descr_ref ret
= op0
;
13843 add_loc_descr (&ret
, op1
);
13844 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13845 if (STORE_FLAG_VALUE
!= 1)
13847 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
13848 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13853 /* Return location descriptor for signed comparison OP RTL. */
13855 static dw_loc_descr_ref
13856 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
13857 machine_mode mem_mode
)
13859 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13860 dw_loc_descr_ref op0
, op1
;
13863 if (op_mode
== VOIDmode
)
13864 op_mode
= GET_MODE (XEXP (rtl
, 1));
13865 if (op_mode
== VOIDmode
)
13869 && dwarf_version
< 5
13870 && (!SCALAR_INT_MODE_P (op_mode
)
13871 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
13874 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
13875 VAR_INIT_STATUS_INITIALIZED
);
13876 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
13877 VAR_INIT_STATUS_INITIALIZED
);
13879 if (op0
== NULL
|| op1
== NULL
)
13882 if (!SCALAR_INT_MODE_P (op_mode
)
13883 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
13884 return compare_loc_descriptor (op
, op0
, op1
);
13886 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
13888 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
13889 dw_loc_descr_ref cvt
;
13891 if (type_die
== NULL
)
13893 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13894 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13895 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13896 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13897 add_loc_descr (&op0
, cvt
);
13898 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13899 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13900 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13901 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13902 add_loc_descr (&op1
, cvt
);
13903 return compare_loc_descriptor (op
, op0
, op1
);
13906 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
13907 /* For eq/ne, if the operands are known to be zero-extended,
13908 there is no need to do the fancy shifting up. */
13909 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
13911 dw_loc_descr_ref last0
, last1
;
13912 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
13914 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
13916 /* deref_size zero extends, and for constants we can check
13917 whether they are zero extended or not. */
13918 if (((last0
->dw_loc_opc
== DW_OP_deref_size
13919 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
13920 || (CONST_INT_P (XEXP (rtl
, 0))
13921 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
13922 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
13923 && ((last1
->dw_loc_opc
== DW_OP_deref_size
13924 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
13925 || (CONST_INT_P (XEXP (rtl
, 1))
13926 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
13927 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
13928 return compare_loc_descriptor (op
, op0
, op1
);
13930 /* EQ/NE comparison against constant in narrower type than
13931 DWARF2_ADDR_SIZE can be performed either as
13932 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
13935 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
13936 DW_OP_{eq,ne}. Pick whatever is shorter. */
13937 if (CONST_INT_P (XEXP (rtl
, 1))
13938 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
13939 && (size_of_int_loc_descriptor (shift
) + 1
13940 + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
)
13941 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
13942 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
13943 & GET_MODE_MASK (op_mode
))))
13945 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
13946 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
13947 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
13948 & GET_MODE_MASK (op_mode
));
13949 return compare_loc_descriptor (op
, op0
, op1
);
13952 add_loc_descr (&op0
, int_loc_descriptor (shift
));
13953 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
13954 if (CONST_INT_P (XEXP (rtl
, 1)))
13955 op1
= int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
);
13958 add_loc_descr (&op1
, int_loc_descriptor (shift
));
13959 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
13961 return compare_loc_descriptor (op
, op0
, op1
);
13964 /* Return location descriptor for unsigned comparison OP RTL. */
13966 static dw_loc_descr_ref
13967 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
13968 machine_mode mem_mode
)
13970 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13971 dw_loc_descr_ref op0
, op1
;
13973 if (op_mode
== VOIDmode
)
13974 op_mode
= GET_MODE (XEXP (rtl
, 1));
13975 if (op_mode
== VOIDmode
)
13977 if (!SCALAR_INT_MODE_P (op_mode
))
13981 && dwarf_version
< 5
13982 && GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
13985 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
13986 VAR_INIT_STATUS_INITIALIZED
);
13987 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
13988 VAR_INIT_STATUS_INITIALIZED
);
13990 if (op0
== NULL
|| op1
== NULL
)
13993 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
13995 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
13996 dw_loc_descr_ref last0
, last1
;
13997 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
13999 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
14001 if (CONST_INT_P (XEXP (rtl
, 0)))
14002 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
14003 /* deref_size zero extends, so no need to mask it again. */
14004 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
14005 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
14007 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14008 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14010 if (CONST_INT_P (XEXP (rtl
, 1)))
14011 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
14012 /* deref_size zero extends, so no need to mask it again. */
14013 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
14014 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
14016 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14017 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14020 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
14022 HOST_WIDE_INT bias
= 1;
14023 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14024 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14025 if (CONST_INT_P (XEXP (rtl
, 1)))
14026 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
14027 + INTVAL (XEXP (rtl
, 1)));
14029 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
14032 return compare_loc_descriptor (op
, op0
, op1
);
14035 /* Return location descriptor for {U,S}{MIN,MAX}. */
14037 static dw_loc_descr_ref
14038 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
14039 machine_mode mem_mode
)
14041 enum dwarf_location_atom op
;
14042 dw_loc_descr_ref op0
, op1
, ret
;
14043 dw_loc_descr_ref bra_node
, drop_node
;
14046 && dwarf_version
< 5
14047 && (!SCALAR_INT_MODE_P (mode
)
14048 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
14051 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14052 VAR_INIT_STATUS_INITIALIZED
);
14053 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14054 VAR_INIT_STATUS_INITIALIZED
);
14056 if (op0
== NULL
|| op1
== NULL
)
14059 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
14060 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
14061 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
14062 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
14064 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14066 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
14067 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14068 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14069 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14070 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14072 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
14074 HOST_WIDE_INT bias
= 1;
14075 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14076 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14077 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14080 else if (!SCALAR_INT_MODE_P (mode
)
14081 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14083 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
14084 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14085 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14086 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14087 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14089 else if (SCALAR_INT_MODE_P (mode
)
14090 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14092 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
14093 dw_loc_descr_ref cvt
;
14094 if (type_die
== NULL
)
14096 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14097 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14098 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14099 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14100 add_loc_descr (&op0
, cvt
);
14101 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14102 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14103 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14104 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14105 add_loc_descr (&op1
, cvt
);
14108 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
14113 add_loc_descr (&ret
, op1
);
14114 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
14115 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14116 add_loc_descr (&ret
, bra_node
);
14117 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14118 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14119 add_loc_descr (&ret
, drop_node
);
14120 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14121 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14122 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
14123 && SCALAR_INT_MODE_P (mode
)
14124 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14125 ret
= convert_descriptor_to_mode (mode
, ret
);
14129 /* Helper function for mem_loc_descriptor. Perform OP binary op,
14130 but after converting arguments to type_die, afterwards
14131 convert back to unsigned. */
14133 static dw_loc_descr_ref
14134 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
14135 machine_mode mode
, machine_mode mem_mode
)
14137 dw_loc_descr_ref cvt
, op0
, op1
;
14139 if (type_die
== NULL
)
14141 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14142 VAR_INIT_STATUS_INITIALIZED
);
14143 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14144 VAR_INIT_STATUS_INITIALIZED
);
14145 if (op0
== NULL
|| op1
== NULL
)
14147 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14148 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14149 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14150 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14151 add_loc_descr (&op0
, cvt
);
14152 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14153 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14154 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14155 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14156 add_loc_descr (&op1
, cvt
);
14157 add_loc_descr (&op0
, op1
);
14158 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
14159 return convert_descriptor_to_mode (mode
, op0
);
14162 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
14163 const0 is DW_OP_lit0 or corresponding typed constant,
14164 const1 is DW_OP_lit1 or corresponding typed constant
14165 and constMSB is constant with just the MSB bit set
14167 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14168 L1: const0 DW_OP_swap
14169 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
14170 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14175 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14176 L1: const0 DW_OP_swap
14177 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14178 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14183 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
14184 L1: const1 DW_OP_swap
14185 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14186 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14190 static dw_loc_descr_ref
14191 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
14192 machine_mode mem_mode
)
14194 dw_loc_descr_ref op0
, ret
, tmp
;
14195 HOST_WIDE_INT valv
;
14196 dw_loc_descr_ref l1jump
, l1label
;
14197 dw_loc_descr_ref l2jump
, l2label
;
14198 dw_loc_descr_ref l3jump
, l3label
;
14199 dw_loc_descr_ref l4jump
, l4label
;
14202 if (!SCALAR_INT_MODE_P (mode
)
14203 || GET_MODE (XEXP (rtl
, 0)) != mode
)
14206 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14207 VAR_INIT_STATUS_INITIALIZED
);
14211 if (GET_CODE (rtl
) == CLZ
)
14213 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14214 valv
= GET_MODE_BITSIZE (mode
);
14216 else if (GET_CODE (rtl
) == FFS
)
14218 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14219 valv
= GET_MODE_BITSIZE (mode
);
14220 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14221 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14222 add_loc_descr (&ret
, l1jump
);
14223 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14224 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
14225 VAR_INIT_STATUS_INITIALIZED
);
14228 add_loc_descr (&ret
, tmp
);
14229 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14230 add_loc_descr (&ret
, l4jump
);
14231 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
14232 ? const1_rtx
: const0_rtx
,
14234 VAR_INIT_STATUS_INITIALIZED
);
14235 if (l1label
== NULL
)
14237 add_loc_descr (&ret
, l1label
);
14238 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14239 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
14240 add_loc_descr (&ret
, l2label
);
14241 if (GET_CODE (rtl
) != CLZ
)
14243 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
14244 msb
= GEN_INT (HOST_WIDE_INT_1U
14245 << (GET_MODE_BITSIZE (mode
) - 1));
14247 msb
= immed_wide_int_const
14248 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
14249 GET_MODE_PRECISION (mode
)), mode
);
14250 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
14251 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14252 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
14253 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
14255 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
14256 VAR_INIT_STATUS_INITIALIZED
);
14259 add_loc_descr (&ret
, tmp
);
14260 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14261 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14262 add_loc_descr (&ret
, l3jump
);
14263 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14264 VAR_INIT_STATUS_INITIALIZED
);
14267 add_loc_descr (&ret
, tmp
);
14268 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
14269 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
14270 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14271 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
14272 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14273 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14274 add_loc_descr (&ret
, l2jump
);
14275 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
14276 add_loc_descr (&ret
, l3label
);
14277 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
14278 add_loc_descr (&ret
, l4label
);
14279 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14280 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14281 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14282 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14283 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14284 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
14285 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14286 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
14290 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
14291 const1 is DW_OP_lit1 or corresponding typed constant):
14293 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14294 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14298 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14299 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14302 static dw_loc_descr_ref
14303 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
14304 machine_mode mem_mode
)
14306 dw_loc_descr_ref op0
, ret
, tmp
;
14307 dw_loc_descr_ref l1jump
, l1label
;
14308 dw_loc_descr_ref l2jump
, l2label
;
14310 if (!SCALAR_INT_MODE_P (mode
)
14311 || GET_MODE (XEXP (rtl
, 0)) != mode
)
14314 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14315 VAR_INIT_STATUS_INITIALIZED
);
14319 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14320 VAR_INIT_STATUS_INITIALIZED
);
14323 add_loc_descr (&ret
, tmp
);
14324 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14325 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
14326 add_loc_descr (&ret
, l1label
);
14327 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14328 add_loc_descr (&ret
, l2jump
);
14329 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14330 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14331 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14332 VAR_INIT_STATUS_INITIALIZED
);
14335 add_loc_descr (&ret
, tmp
);
14336 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14337 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
14338 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
14339 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14340 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14341 VAR_INIT_STATUS_INITIALIZED
);
14342 add_loc_descr (&ret
, tmp
);
14343 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14344 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14345 add_loc_descr (&ret
, l1jump
);
14346 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14347 add_loc_descr (&ret
, l2label
);
14348 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14349 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14350 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14351 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14355 /* BSWAP (constS is initial shift count, either 56 or 24):
14357 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
14358 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
14359 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
14360 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
14361 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
14363 static dw_loc_descr_ref
14364 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
14365 machine_mode mem_mode
)
14367 dw_loc_descr_ref op0
, ret
, tmp
;
14368 dw_loc_descr_ref l1jump
, l1label
;
14369 dw_loc_descr_ref l2jump
, l2label
;
14371 if (!SCALAR_INT_MODE_P (mode
)
14372 || BITS_PER_UNIT
!= 8
14373 || (GET_MODE_BITSIZE (mode
) != 32
14374 && GET_MODE_BITSIZE (mode
) != 64))
14377 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14378 VAR_INIT_STATUS_INITIALIZED
);
14383 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14385 VAR_INIT_STATUS_INITIALIZED
);
14388 add_loc_descr (&ret
, tmp
);
14389 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14390 VAR_INIT_STATUS_INITIALIZED
);
14393 add_loc_descr (&ret
, tmp
);
14394 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
14395 add_loc_descr (&ret
, l1label
);
14396 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14398 VAR_INIT_STATUS_INITIALIZED
);
14399 add_loc_descr (&ret
, tmp
);
14400 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
14401 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14402 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14403 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
14404 VAR_INIT_STATUS_INITIALIZED
);
14407 add_loc_descr (&ret
, tmp
);
14408 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14409 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
14410 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14411 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14412 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14413 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14414 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14415 VAR_INIT_STATUS_INITIALIZED
);
14416 add_loc_descr (&ret
, tmp
);
14417 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
14418 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14419 add_loc_descr (&ret
, l2jump
);
14420 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
14421 VAR_INIT_STATUS_INITIALIZED
);
14422 add_loc_descr (&ret
, tmp
);
14423 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14424 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14425 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14426 add_loc_descr (&ret
, l1jump
);
14427 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14428 add_loc_descr (&ret
, l2label
);
14429 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14430 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14431 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14432 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14433 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14434 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14438 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
14439 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14440 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
14441 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
14443 ROTATERT is similar:
14444 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
14445 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14446 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
14448 static dw_loc_descr_ref
14449 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
14450 machine_mode mem_mode
)
14452 rtx rtlop1
= XEXP (rtl
, 1);
14453 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
14456 if (!SCALAR_INT_MODE_P (mode
))
14459 if (GET_MODE (rtlop1
) != VOIDmode
14460 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
14461 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
14462 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14463 VAR_INIT_STATUS_INITIALIZED
);
14464 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
14465 VAR_INIT_STATUS_INITIALIZED
);
14466 if (op0
== NULL
|| op1
== NULL
)
14468 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14469 for (i
= 0; i
< 2; i
++)
14471 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
14472 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
14474 VAR_INIT_STATUS_INITIALIZED
);
14475 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
14476 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14478 : HOST_BITS_PER_WIDE_INT
== 64
14479 ? DW_OP_const8u
: DW_OP_constu
,
14480 GET_MODE_MASK (mode
), 0);
14483 if (mask
[i
] == NULL
)
14485 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
14488 add_loc_descr (&ret
, op1
);
14489 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14490 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14491 if (GET_CODE (rtl
) == ROTATERT
)
14493 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14494 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14495 GET_MODE_BITSIZE (mode
), 0));
14497 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14498 if (mask
[0] != NULL
)
14499 add_loc_descr (&ret
, mask
[0]);
14500 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14501 if (mask
[1] != NULL
)
14503 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14504 add_loc_descr (&ret
, mask
[1]);
14505 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14507 if (GET_CODE (rtl
) == ROTATE
)
14509 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14510 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14511 GET_MODE_BITSIZE (mode
), 0));
14513 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14514 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14518 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
14519 for DEBUG_PARAMETER_REF RTL. */
14521 static dw_loc_descr_ref
14522 parameter_ref_descriptor (rtx rtl
)
14524 dw_loc_descr_ref ret
;
14529 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
14530 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
14531 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
14534 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14535 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14536 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14540 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14541 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
14546 /* The following routine converts the RTL for a variable or parameter
14547 (resident in memory) into an equivalent Dwarf representation of a
14548 mechanism for getting the address of that same variable onto the top of a
14549 hypothetical "address evaluation" stack.
14551 When creating memory location descriptors, we are effectively transforming
14552 the RTL for a memory-resident object into its Dwarf postfix expression
14553 equivalent. This routine recursively descends an RTL tree, turning
14554 it into Dwarf postfix code as it goes.
14556 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
14558 MEM_MODE is the mode of the memory reference, needed to handle some
14559 autoincrement addressing modes.
14561 Return 0 if we can't represent the location. */
14564 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
14565 machine_mode mem_mode
,
14566 enum var_init_status initialized
)
14568 dw_loc_descr_ref mem_loc_result
= NULL
;
14569 enum dwarf_location_atom op
;
14570 dw_loc_descr_ref op0
, op1
;
14571 rtx inner
= NULL_RTX
;
14573 if (mode
== VOIDmode
)
14574 mode
= GET_MODE (rtl
);
14576 /* Note that for a dynamically sized array, the location we will generate a
14577 description of here will be the lowest numbered location which is
14578 actually within the array. That's *not* necessarily the same as the
14579 zeroth element of the array. */
14581 rtl
= targetm
.delegitimize_address (rtl
);
14583 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
14586 switch (GET_CODE (rtl
))
14591 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
14594 /* The case of a subreg may arise when we have a local (register)
14595 variable or a formal (register) parameter which doesn't quite fill
14596 up an entire register. For now, just assume that it is
14597 legitimate to make the Dwarf info refer to the whole register which
14598 contains the given subreg. */
14599 if (!subreg_lowpart_p (rtl
))
14601 inner
= SUBREG_REG (rtl
);
14604 if (inner
== NULL_RTX
)
14605 inner
= XEXP (rtl
, 0);
14606 if (SCALAR_INT_MODE_P (mode
)
14607 && SCALAR_INT_MODE_P (GET_MODE (inner
))
14608 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14609 #ifdef POINTERS_EXTEND_UNSIGNED
14610 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
14613 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
14615 mem_loc_result
= mem_loc_descriptor (inner
,
14617 mem_mode
, initialized
);
14620 if (dwarf_strict
&& dwarf_version
< 5)
14622 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
14624 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
14625 && (!SCALAR_INT_MODE_P (mode
)
14626 || !SCALAR_INT_MODE_P (GET_MODE (inner
))))
14630 dw_die_ref type_die
;
14631 dw_loc_descr_ref cvt
;
14633 mem_loc_result
= mem_loc_descriptor (inner
,
14635 mem_mode
, initialized
);
14636 if (mem_loc_result
== NULL
)
14638 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14639 if (type_die
== NULL
)
14641 mem_loc_result
= NULL
;
14644 if (GET_MODE_SIZE (mode
)
14645 != GET_MODE_SIZE (GET_MODE (inner
)))
14646 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14648 cvt
= new_loc_descr (dwarf_OP (DW_OP_reinterpret
), 0, 0);
14649 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14650 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14651 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14652 add_loc_descr (&mem_loc_result
, cvt
);
14653 if (SCALAR_INT_MODE_P (mode
)
14654 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14656 /* Convert it to untyped afterwards. */
14657 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14658 add_loc_descr (&mem_loc_result
, cvt
);
14664 if (! SCALAR_INT_MODE_P (mode
)
14665 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14666 && rtl
!= arg_pointer_rtx
14667 && rtl
!= frame_pointer_rtx
14668 #ifdef POINTERS_EXTEND_UNSIGNED
14669 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
14673 dw_die_ref type_die
;
14674 unsigned int dbx_regnum
;
14676 if (dwarf_strict
&& dwarf_version
< 5)
14678 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
14680 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14681 if (type_die
== NULL
)
14684 dbx_regnum
= dbx_reg_number (rtl
);
14685 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14687 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_regval_type
),
14689 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14690 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14691 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14694 /* Whenever a register number forms a part of the description of the
14695 method for calculating the (dynamic) address of a memory resident
14696 object, DWARF rules require the register number be referred to as
14697 a "base register". This distinction is not based in any way upon
14698 what category of register the hardware believes the given register
14699 belongs to. This is strictly DWARF terminology we're dealing with
14700 here. Note that in cases where the location of a memory-resident
14701 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
14702 OP_CONST (0)) the actual DWARF location descriptor that we generate
14703 may just be OP_BASEREG (basereg). This may look deceptively like
14704 the object in question was allocated to a register (rather than in
14705 memory) so DWARF consumers need to be aware of the subtle
14706 distinction between OP_REG and OP_BASEREG. */
14707 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
14708 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
14709 else if (stack_realign_drap
14711 && crtl
->args
.internal_arg_pointer
== rtl
14712 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
14714 /* If RTL is internal_arg_pointer, which has been optimized
14715 out, use DRAP instead. */
14716 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
14717 VAR_INIT_STATUS_INITIALIZED
);
14723 if (!SCALAR_INT_MODE_P (mode
))
14725 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
14726 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14729 else if (GET_CODE (rtl
) == ZERO_EXTEND
14730 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14731 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
14732 < HOST_BITS_PER_WIDE_INT
14733 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
14734 to expand zero extend as two shifts instead of
14736 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
14738 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
14739 mem_loc_result
= op0
;
14740 add_loc_descr (&mem_loc_result
,
14741 int_loc_descriptor (GET_MODE_MASK (imode
)));
14742 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
14744 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14746 int shift
= DWARF2_ADDR_SIZE
14747 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
14748 shift
*= BITS_PER_UNIT
;
14749 if (GET_CODE (rtl
) == SIGN_EXTEND
)
14753 mem_loc_result
= op0
;
14754 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14755 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14756 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14757 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14759 else if (!dwarf_strict
|| dwarf_version
>= 5)
14761 dw_die_ref type_die1
, type_die2
;
14762 dw_loc_descr_ref cvt
;
14764 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
14765 GET_CODE (rtl
) == ZERO_EXTEND
);
14766 if (type_die1
== NULL
)
14768 type_die2
= base_type_for_mode (mode
, 1);
14769 if (type_die2
== NULL
)
14771 mem_loc_result
= op0
;
14772 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14773 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14774 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
14775 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14776 add_loc_descr (&mem_loc_result
, cvt
);
14777 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14778 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14779 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
14780 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14781 add_loc_descr (&mem_loc_result
, cvt
);
14787 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14788 if (new_rtl
!= rtl
)
14790 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
14792 if (mem_loc_result
!= NULL
)
14793 return mem_loc_result
;
14796 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
14797 get_address_mode (rtl
), mode
,
14798 VAR_INIT_STATUS_INITIALIZED
);
14799 if (mem_loc_result
== NULL
)
14800 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
14801 if (mem_loc_result
!= NULL
)
14803 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14804 || !SCALAR_INT_MODE_P(mode
))
14806 dw_die_ref type_die
;
14807 dw_loc_descr_ref deref
;
14809 if (dwarf_strict
&& dwarf_version
< 5)
14812 = base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14813 if (type_die
== NULL
)
14815 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
),
14816 GET_MODE_SIZE (mode
), 0);
14817 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14818 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14819 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14820 add_loc_descr (&mem_loc_result
, deref
);
14822 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
14823 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
14825 add_loc_descr (&mem_loc_result
,
14826 new_loc_descr (DW_OP_deref_size
,
14827 GET_MODE_SIZE (mode
), 0));
14832 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
14835 /* Some ports can transform a symbol ref into a label ref, because
14836 the symbol ref is too far away and has to be dumped into a constant
14840 if (!SCALAR_INT_MODE_P (mode
)
14841 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14842 #ifdef POINTERS_EXTEND_UNSIGNED
14843 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
14847 if (GET_CODE (rtl
) == SYMBOL_REF
14848 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
14850 dw_loc_descr_ref temp
;
14852 /* If this is not defined, we have no way to emit the data. */
14853 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
14856 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
14858 /* We check for DWARF 5 here because gdb did not implement
14859 DW_OP_form_tls_address until after 7.12. */
14860 mem_loc_result
= new_loc_descr ((dwarf_version
>= 5
14861 ? DW_OP_form_tls_address
14862 : DW_OP_GNU_push_tls_address
),
14864 add_loc_descr (&mem_loc_result
, temp
);
14869 if (!const_ok_for_output (rtl
))
14871 if (GET_CODE (rtl
) == CONST
)
14872 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14878 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14879 vec_safe_push (used_rtx_array
, rtl
);
14885 case DEBUG_IMPLICIT_PTR
:
14886 expansion_failed (NULL_TREE
, rtl
,
14887 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
14891 if (dwarf_strict
&& dwarf_version
< 5)
14893 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
14895 if (!SCALAR_INT_MODE_P (mode
)
14896 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14897 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
14898 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14901 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
14902 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14904 op0
= one_reg_loc_descriptor (dbx_regnum
,
14905 VAR_INIT_STATUS_INITIALIZED
);
14908 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
14909 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
14911 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
14912 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14913 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
14917 gcc_unreachable ();
14920 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_entry_value
), 0, 0);
14921 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14922 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
14925 case DEBUG_PARAMETER_REF
:
14926 mem_loc_result
= parameter_ref_descriptor (rtl
);
14930 /* Extract the PLUS expression nested inside and fall into
14931 PLUS code below. */
14932 rtl
= XEXP (rtl
, 1);
14937 /* Turn these into a PLUS expression and fall into the PLUS code
14939 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
14940 gen_int_mode (GET_CODE (rtl
) == PRE_INC
14941 ? GET_MODE_UNIT_SIZE (mem_mode
)
14942 : -GET_MODE_UNIT_SIZE (mem_mode
),
14949 if (is_based_loc (rtl
)
14950 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14951 || XEXP (rtl
, 0) == arg_pointer_rtx
14952 || XEXP (rtl
, 0) == frame_pointer_rtx
)
14953 && SCALAR_INT_MODE_P (mode
))
14954 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
14955 INTVAL (XEXP (rtl
, 1)),
14956 VAR_INIT_STATUS_INITIALIZED
);
14959 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14960 VAR_INIT_STATUS_INITIALIZED
);
14961 if (mem_loc_result
== 0)
14964 if (CONST_INT_P (XEXP (rtl
, 1))
14965 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14966 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
14969 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14970 VAR_INIT_STATUS_INITIALIZED
);
14973 add_loc_descr (&mem_loc_result
, op1
);
14974 add_loc_descr (&mem_loc_result
,
14975 new_loc_descr (DW_OP_plus
, 0, 0));
14980 /* If a pseudo-reg is optimized away, it is possible for it to
14981 be replaced with a MEM containing a multiply or shift. */
14991 if ((!dwarf_strict
|| dwarf_version
>= 5)
14992 && SCALAR_INT_MODE_P (mode
)
14993 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14995 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
14996 base_type_for_mode (mode
, 0),
15020 if (!SCALAR_INT_MODE_P (mode
))
15022 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15023 VAR_INIT_STATUS_INITIALIZED
);
15025 rtx rtlop1
= XEXP (rtl
, 1);
15026 if (GET_MODE (rtlop1
) != VOIDmode
15027 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
15028 < GET_MODE_BITSIZE (mode
))
15029 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
15030 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
15031 VAR_INIT_STATUS_INITIALIZED
);
15034 if (op0
== 0 || op1
== 0)
15037 mem_loc_result
= op0
;
15038 add_loc_descr (&mem_loc_result
, op1
);
15039 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15055 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15056 VAR_INIT_STATUS_INITIALIZED
);
15057 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15058 VAR_INIT_STATUS_INITIALIZED
);
15060 if (op0
== 0 || op1
== 0)
15063 mem_loc_result
= op0
;
15064 add_loc_descr (&mem_loc_result
, op1
);
15065 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15069 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
15070 && (!dwarf_strict
|| dwarf_version
>= 5))
15072 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
15073 base_type_for_mode (mode
, 0),
15078 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15079 VAR_INIT_STATUS_INITIALIZED
);
15080 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15081 VAR_INIT_STATUS_INITIALIZED
);
15083 if (op0
== 0 || op1
== 0)
15086 mem_loc_result
= op0
;
15087 add_loc_descr (&mem_loc_result
, op1
);
15088 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15089 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15090 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
15091 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
15092 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
15096 if ((!dwarf_strict
|| dwarf_version
>= 5)
15097 && SCALAR_INT_MODE_P (mode
))
15099 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
15104 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
15105 base_type_for_mode (mode
, 1),
15123 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15124 VAR_INIT_STATUS_INITIALIZED
);
15129 mem_loc_result
= op0
;
15130 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15134 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
15135 #ifdef POINTERS_EXTEND_UNSIGNED
15137 && mem_mode
!= VOIDmode
15138 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
15142 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15145 if ((!dwarf_strict
|| dwarf_version
>= 5)
15146 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
15147 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
15149 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
15150 machine_mode amode
;
15151 if (type_die
== NULL
)
15153 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
15155 if (INTVAL (rtl
) >= 0
15156 && amode
!= BLKmode
15157 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
15158 /* const DW_OP_convert <XXX> vs.
15159 DW_OP_const_type <XXX, 1, const>. */
15160 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
15161 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
15163 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15164 op0
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15165 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15166 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15167 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15168 add_loc_descr (&mem_loc_result
, op0
);
15169 return mem_loc_result
;
15171 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0,
15173 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15174 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15175 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15176 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
15177 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15180 mem_loc_result
->dw_loc_oprnd2
.val_class
15181 = dw_val_class_const_double
;
15182 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15183 = double_int::from_shwi (INTVAL (rtl
));
15189 if (!dwarf_strict
|| dwarf_version
>= 5)
15191 dw_die_ref type_die
;
15193 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
15194 CONST_DOUBLE rtx could represent either a large integer
15195 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
15196 the value is always a floating point constant.
15198 When it is an integer, a CONST_DOUBLE is used whenever
15199 the constant requires 2 HWIs to be adequately represented.
15200 We output CONST_DOUBLEs as blocks. */
15201 if (mode
== VOIDmode
15202 || (GET_MODE (rtl
) == VOIDmode
15203 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
15205 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15206 if (type_die
== NULL
)
15208 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15209 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15210 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15211 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15212 #if TARGET_SUPPORTS_WIDE_INT == 0
15213 if (!SCALAR_FLOAT_MODE_P (mode
))
15215 mem_loc_result
->dw_loc_oprnd2
.val_class
15216 = dw_val_class_const_double
;
15217 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15218 = rtx_to_double_int (rtl
);
15223 unsigned int length
= GET_MODE_SIZE (mode
);
15224 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15226 insert_float (rtl
, array
);
15227 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15228 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15229 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15230 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15235 case CONST_WIDE_INT
:
15236 if (!dwarf_strict
|| dwarf_version
>= 5)
15238 dw_die_ref type_die
;
15240 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15241 if (type_die
== NULL
)
15243 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15244 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15245 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15246 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15247 mem_loc_result
->dw_loc_oprnd2
.val_class
15248 = dw_val_class_wide_int
;
15249 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15250 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15255 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
15259 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15263 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15267 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15271 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15275 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
15279 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15283 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15287 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15291 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15296 if (!SCALAR_INT_MODE_P (mode
))
15301 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
15306 if (CONST_INT_P (XEXP (rtl
, 1))
15307 && CONST_INT_P (XEXP (rtl
, 2))
15308 && ((unsigned) INTVAL (XEXP (rtl
, 1))
15309 + (unsigned) INTVAL (XEXP (rtl
, 2))
15310 <= GET_MODE_BITSIZE (mode
))
15311 && SCALAR_INT_MODE_P (mode
)
15312 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
15313 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
15316 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
15317 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15320 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
15324 mem_loc_result
= op0
;
15325 size
= INTVAL (XEXP (rtl
, 1));
15326 shift
= INTVAL (XEXP (rtl
, 2));
15327 if (BITS_BIG_ENDIAN
)
15328 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
15330 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
15332 add_loc_descr (&mem_loc_result
,
15333 int_loc_descriptor (DWARF2_ADDR_SIZE
15335 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
15337 if (size
!= (int) DWARF2_ADDR_SIZE
)
15339 add_loc_descr (&mem_loc_result
,
15340 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
15341 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15348 dw_loc_descr_ref op2
, bra_node
, drop_node
;
15349 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
15350 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
15351 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
15352 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15353 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15354 VAR_INIT_STATUS_INITIALIZED
);
15355 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
15356 VAR_INIT_STATUS_INITIALIZED
);
15357 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
15360 mem_loc_result
= op1
;
15361 add_loc_descr (&mem_loc_result
, op2
);
15362 add_loc_descr (&mem_loc_result
, op0
);
15363 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15364 add_loc_descr (&mem_loc_result
, bra_node
);
15365 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
15366 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
15367 add_loc_descr (&mem_loc_result
, drop_node
);
15368 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15369 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
15374 case FLOAT_TRUNCATE
:
15376 case UNSIGNED_FLOAT
:
15379 if (!dwarf_strict
|| dwarf_version
>= 5)
15381 dw_die_ref type_die
;
15382 dw_loc_descr_ref cvt
;
15384 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
15385 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15388 if (SCALAR_INT_MODE_P (GET_MODE (XEXP (rtl
, 0)))
15389 && (GET_CODE (rtl
) == FLOAT
15390 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
15391 <= DWARF2_ADDR_SIZE
))
15393 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
15394 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
15395 if (type_die
== NULL
)
15397 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15398 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15399 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15400 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15401 add_loc_descr (&op0
, cvt
);
15403 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
15404 if (type_die
== NULL
)
15406 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15407 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15408 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15409 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15410 add_loc_descr (&op0
, cvt
);
15411 if (SCALAR_INT_MODE_P (mode
)
15412 && (GET_CODE (rtl
) == FIX
15413 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
15415 op0
= convert_descriptor_to_mode (mode
, op0
);
15419 mem_loc_result
= op0
;
15426 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
15431 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
15435 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
15440 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
15444 /* In theory, we could implement the above. */
15445 /* DWARF cannot represent the unsigned compare operations
15470 case FRACT_CONVERT
:
15471 case UNSIGNED_FRACT_CONVERT
:
15473 case UNSIGNED_SAT_FRACT
:
15479 case VEC_DUPLICATE
:
15483 case STRICT_LOW_PART
:
15488 /* If delegitimize_address couldn't do anything with the UNSPEC, we
15489 can't express it in the debug info. This can happen e.g. with some
15494 resolve_one_addr (&rtl
);
15497 /* RTL sequences inside PARALLEL record a series of DWARF operations for
15498 the expression. An UNSPEC rtx represents a raw DWARF operation,
15499 new_loc_descr is called for it to build the operation directly.
15500 Otherwise mem_loc_descriptor is called recursively. */
15504 dw_loc_descr_ref exp_result
= NULL
;
15506 for (; index
< XVECLEN (rtl
, 0); index
++)
15508 rtx elem
= XVECEXP (rtl
, 0, index
);
15509 if (GET_CODE (elem
) == UNSPEC
)
15511 /* Each DWARF operation UNSPEC contain two operands, if
15512 one operand is not used for the operation, const0_rtx is
15514 gcc_assert (XVECLEN (elem
, 0) == 2);
15516 HOST_WIDE_INT dw_op
= XINT (elem
, 1);
15517 HOST_WIDE_INT oprnd1
= INTVAL (XVECEXP (elem
, 0, 0));
15518 HOST_WIDE_INT oprnd2
= INTVAL (XVECEXP (elem
, 0, 1));
15520 = new_loc_descr ((enum dwarf_location_atom
) dw_op
, oprnd1
,
15525 = mem_loc_descriptor (elem
, mode
, mem_mode
,
15526 VAR_INIT_STATUS_INITIALIZED
);
15528 if (!mem_loc_result
)
15529 mem_loc_result
= exp_result
;
15531 add_loc_descr (&mem_loc_result
, exp_result
);
15540 print_rtl (stderr
, rtl
);
15541 gcc_unreachable ();
15546 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15547 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15549 return mem_loc_result
;
15552 /* Return a descriptor that describes the concatenation of two locations.
15553 This is typically a complex variable. */
15555 static dw_loc_descr_ref
15556 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
15558 dw_loc_descr_ref cc_loc_result
= NULL
;
15559 dw_loc_descr_ref x0_ref
15560 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15561 dw_loc_descr_ref x1_ref
15562 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15564 if (x0_ref
== 0 || x1_ref
== 0)
15567 cc_loc_result
= x0_ref
;
15568 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
15570 add_loc_descr (&cc_loc_result
, x1_ref
);
15571 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
15573 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15574 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15576 return cc_loc_result
;
15579 /* Return a descriptor that describes the concatenation of N
15582 static dw_loc_descr_ref
15583 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
15586 dw_loc_descr_ref cc_loc_result
= NULL
;
15587 unsigned int n
= XVECLEN (concatn
, 0);
15589 for (i
= 0; i
< n
; ++i
)
15591 dw_loc_descr_ref ref
;
15592 rtx x
= XVECEXP (concatn
, 0, i
);
15594 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15598 add_loc_descr (&cc_loc_result
, ref
);
15599 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
15602 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15603 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15605 return cc_loc_result
;
15608 /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
15609 for DEBUG_IMPLICIT_PTR RTL. */
15611 static dw_loc_descr_ref
15612 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
15614 dw_loc_descr_ref ret
;
15617 if (dwarf_strict
&& dwarf_version
< 5)
15619 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
15620 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
15621 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
15622 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
15623 ret
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
15624 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15627 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15628 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
15629 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15633 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
15634 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
15639 /* Output a proper Dwarf location descriptor for a variable or parameter
15640 which is either allocated in a register or in a memory location. For a
15641 register, we just generate an OP_REG and the register number. For a
15642 memory location we provide a Dwarf postfix expression describing how to
15643 generate the (dynamic) address of the object onto the address stack.
15645 MODE is mode of the decl if this loc_descriptor is going to be used in
15646 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
15647 allowed, VOIDmode otherwise.
15649 If we don't know how to describe it, return 0. */
15651 static dw_loc_descr_ref
15652 loc_descriptor (rtx rtl
, machine_mode mode
,
15653 enum var_init_status initialized
)
15655 dw_loc_descr_ref loc_result
= NULL
;
15657 switch (GET_CODE (rtl
))
15660 /* The case of a subreg may arise when we have a local (register)
15661 variable or a formal (register) parameter which doesn't quite fill
15662 up an entire register. For now, just assume that it is
15663 legitimate to make the Dwarf info refer to the whole register which
15664 contains the given subreg. */
15665 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
15666 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
15667 GET_MODE (SUBREG_REG (rtl
)), initialized
);
15673 loc_result
= reg_loc_descriptor (rtl
, initialized
);
15677 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
15678 GET_MODE (rtl
), initialized
);
15679 if (loc_result
== NULL
)
15680 loc_result
= tls_mem_loc_descriptor (rtl
);
15681 if (loc_result
== NULL
)
15683 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
15684 if (new_rtl
!= rtl
)
15685 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
15690 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
15695 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
15700 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
15702 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
15703 if (GET_CODE (loc
) == EXPR_LIST
)
15704 loc
= XEXP (loc
, 0);
15705 loc_result
= loc_descriptor (loc
, mode
, initialized
);
15709 rtl
= XEXP (rtl
, 1);
15714 rtvec par_elems
= XVEC (rtl
, 0);
15715 int num_elem
= GET_NUM_ELEM (par_elems
);
15719 /* Create the first one, so we have something to add to. */
15720 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
15721 VOIDmode
, initialized
);
15722 if (loc_result
== NULL
)
15724 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
15725 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15726 for (i
= 1; i
< num_elem
; i
++)
15728 dw_loc_descr_ref temp
;
15730 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
15731 VOIDmode
, initialized
);
15734 add_loc_descr (&loc_result
, temp
);
15735 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
15736 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15742 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
15743 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
15748 if (mode
== VOIDmode
)
15749 mode
= GET_MODE (rtl
);
15751 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15753 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15755 /* Note that a CONST_DOUBLE rtx could represent either an integer
15756 or a floating-point constant. A CONST_DOUBLE is used whenever
15757 the constant requires more than one word in order to be
15758 adequately represented. We output CONST_DOUBLEs as blocks. */
15759 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15760 GET_MODE_SIZE (mode
), 0);
15761 #if TARGET_SUPPORTS_WIDE_INT == 0
15762 if (!SCALAR_FLOAT_MODE_P (mode
))
15764 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
15765 loc_result
->dw_loc_oprnd2
.v
.val_double
15766 = rtx_to_double_int (rtl
);
15771 unsigned int length
= GET_MODE_SIZE (mode
);
15772 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15774 insert_float (rtl
, array
);
15775 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15776 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15777 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15778 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15783 case CONST_WIDE_INT
:
15784 if (mode
== VOIDmode
)
15785 mode
= GET_MODE (rtl
);
15787 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15789 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15790 GET_MODE_SIZE (mode
), 0);
15791 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
15792 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15793 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15798 if (mode
== VOIDmode
)
15799 mode
= GET_MODE (rtl
);
15801 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15803 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
15804 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15805 unsigned char *array
15806 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15809 machine_mode imode
= GET_MODE_INNER (mode
);
15811 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15812 switch (GET_MODE_CLASS (mode
))
15814 case MODE_VECTOR_INT
:
15815 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15817 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15818 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
15822 case MODE_VECTOR_FLOAT
:
15823 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15825 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15826 insert_float (elt
, p
);
15831 gcc_unreachable ();
15834 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15835 length
* elt_size
, 0);
15836 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15837 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
15838 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
15839 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15844 if (mode
== VOIDmode
15845 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
15846 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
15847 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
15849 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
15854 if (!const_ok_for_output (rtl
))
15858 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
15859 && (dwarf_version
>= 4 || !dwarf_strict
))
15861 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15862 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15863 vec_safe_push (used_rtx_array
, rtl
);
15867 case DEBUG_IMPLICIT_PTR
:
15868 loc_result
= implicit_ptr_descriptor (rtl
, 0);
15872 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
15873 && CONST_INT_P (XEXP (rtl
, 1)))
15876 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
15882 if ((SCALAR_INT_MODE_P (mode
)
15883 && GET_MODE (rtl
) == mode
15884 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
15885 && dwarf_version
>= 4)
15886 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
15888 /* Value expression. */
15889 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
15891 add_loc_descr (&loc_result
,
15892 new_loc_descr (DW_OP_stack_value
, 0, 0));
15900 /* We need to figure out what section we should use as the base for the
15901 address ranges where a given location is valid.
15902 1. If this particular DECL has a section associated with it, use that.
15903 2. If this function has a section associated with it, use that.
15904 3. Otherwise, use the text section.
15905 XXX: If you split a variable across multiple sections, we won't notice. */
15907 static const char *
15908 secname_for_decl (const_tree decl
)
15910 const char *secname
;
15912 if (VAR_OR_FUNCTION_DECL_P (decl
)
15913 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
15914 && DECL_SECTION_NAME (decl
))
15915 secname
= DECL_SECTION_NAME (decl
);
15916 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
15917 secname
= DECL_SECTION_NAME (current_function_decl
);
15918 else if (cfun
&& in_cold_section_p
)
15919 secname
= crtl
->subsections
.cold_section_label
;
15921 secname
= text_section_label
;
15926 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
15929 decl_by_reference_p (tree decl
)
15931 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
15933 && DECL_BY_REFERENCE (decl
));
15936 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15939 static dw_loc_descr_ref
15940 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
15941 enum var_init_status initialized
)
15943 int have_address
= 0;
15944 dw_loc_descr_ref descr
;
15947 if (want_address
!= 2)
15949 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
15951 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
15953 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
15954 if (GET_CODE (varloc
) == EXPR_LIST
)
15955 varloc
= XEXP (varloc
, 0);
15956 mode
= GET_MODE (varloc
);
15957 if (MEM_P (varloc
))
15959 rtx addr
= XEXP (varloc
, 0);
15960 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
15961 mode
, initialized
);
15966 rtx x
= avoid_constant_pool_reference (varloc
);
15968 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
15973 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
15980 if (GET_CODE (varloc
) == VAR_LOCATION
)
15981 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
15983 mode
= DECL_MODE (loc
);
15984 descr
= loc_descriptor (varloc
, mode
, initialized
);
15991 if (want_address
== 2 && !have_address
15992 && (dwarf_version
>= 4 || !dwarf_strict
))
15994 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15996 expansion_failed (loc
, NULL_RTX
,
15997 "DWARF address size mismatch");
16000 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16003 /* Show if we can't fill the request for an address. */
16004 if (want_address
&& !have_address
)
16006 expansion_failed (loc
, NULL_RTX
,
16007 "Want address and only have value");
16011 /* If we've got an address and don't want one, dereference. */
16012 if (!want_address
&& have_address
)
16014 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
16015 enum dwarf_location_atom op
;
16017 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
16019 expansion_failed (loc
, NULL_RTX
,
16020 "DWARF address size mismatch");
16023 else if (size
== DWARF2_ADDR_SIZE
)
16026 op
= DW_OP_deref_size
;
16028 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
16034 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
16035 if it is not possible. */
16037 static dw_loc_descr_ref
16038 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
16040 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
16041 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
16042 else if (dwarf_version
>= 3 || !dwarf_strict
)
16043 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
16048 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
16049 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
16051 static dw_loc_descr_ref
16052 dw_sra_loc_expr (tree decl
, rtx loc
)
16055 unsigned HOST_WIDE_INT padsize
= 0;
16056 dw_loc_descr_ref descr
, *descr_tail
;
16057 unsigned HOST_WIDE_INT decl_size
;
16059 enum var_init_status initialized
;
16061 if (DECL_SIZE (decl
) == NULL
16062 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
16065 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
16067 descr_tail
= &descr
;
16069 for (p
= loc
; p
; p
= XEXP (p
, 1))
16071 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
16072 rtx loc_note
= *decl_piece_varloc_ptr (p
);
16073 dw_loc_descr_ref cur_descr
;
16074 dw_loc_descr_ref
*tail
, last
= NULL
;
16075 unsigned HOST_WIDE_INT opsize
= 0;
16077 if (loc_note
== NULL_RTX
16078 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
16080 padsize
+= bitsize
;
16083 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
16084 varloc
= NOTE_VAR_LOCATION (loc_note
);
16085 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
16086 if (cur_descr
== NULL
)
16088 padsize
+= bitsize
;
16092 /* Check that cur_descr either doesn't use
16093 DW_OP_*piece operations, or their sum is equal
16094 to bitsize. Otherwise we can't embed it. */
16095 for (tail
= &cur_descr
; *tail
!= NULL
;
16096 tail
= &(*tail
)->dw_loc_next
)
16097 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
16099 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
16103 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
16105 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
16109 if (last
!= NULL
&& opsize
!= bitsize
)
16111 padsize
+= bitsize
;
16112 /* Discard the current piece of the descriptor and release any
16113 addr_table entries it uses. */
16114 remove_loc_list_addr_table_entries (cur_descr
);
16118 /* If there is a hole, add DW_OP_*piece after empty DWARF
16119 expression, which means that those bits are optimized out. */
16122 if (padsize
> decl_size
)
16124 remove_loc_list_addr_table_entries (cur_descr
);
16125 goto discard_descr
;
16127 decl_size
-= padsize
;
16128 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
16129 if (*descr_tail
== NULL
)
16131 remove_loc_list_addr_table_entries (cur_descr
);
16132 goto discard_descr
;
16134 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16137 *descr_tail
= cur_descr
;
16139 if (bitsize
> decl_size
)
16140 goto discard_descr
;
16141 decl_size
-= bitsize
;
16144 HOST_WIDE_INT offset
= 0;
16145 if (GET_CODE (varloc
) == VAR_LOCATION
16146 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
16148 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
16149 if (GET_CODE (varloc
) == EXPR_LIST
)
16150 varloc
= XEXP (varloc
, 0);
16154 if (GET_CODE (varloc
) == CONST
16155 || GET_CODE (varloc
) == SIGN_EXTEND
16156 || GET_CODE (varloc
) == ZERO_EXTEND
)
16157 varloc
= XEXP (varloc
, 0);
16158 else if (GET_CODE (varloc
) == SUBREG
)
16159 varloc
= SUBREG_REG (varloc
);
16164 /* DW_OP_bit_size offset should be zero for register
16165 or implicit location descriptions and empty location
16166 descriptions, but for memory addresses needs big endian
16168 if (MEM_P (varloc
))
16170 unsigned HOST_WIDE_INT memsize
16171 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
16172 if (memsize
!= bitsize
)
16174 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
16175 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
16176 goto discard_descr
;
16177 if (memsize
< bitsize
)
16178 goto discard_descr
;
16179 if (BITS_BIG_ENDIAN
)
16180 offset
= memsize
- bitsize
;
16184 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
16185 if (*descr_tail
== NULL
)
16186 goto discard_descr
;
16187 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16191 /* If there were any non-empty expressions, add padding till the end of
16193 if (descr
!= NULL
&& decl_size
!= 0)
16195 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
16196 if (*descr_tail
== NULL
)
16197 goto discard_descr
;
16202 /* Discard the descriptor and release any addr_table entries it uses. */
16203 remove_loc_list_addr_table_entries (descr
);
16207 /* Return the dwarf representation of the location list LOC_LIST of
16208 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
16211 static dw_loc_list_ref
16212 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
16214 const char *endname
, *secname
;
16216 enum var_init_status initialized
;
16217 struct var_loc_node
*node
;
16218 dw_loc_descr_ref descr
;
16219 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
16220 dw_loc_list_ref list
= NULL
;
16221 dw_loc_list_ref
*listp
= &list
;
16223 /* Now that we know what section we are using for a base,
16224 actually construct the list of locations.
16225 The first location information is what is passed to the
16226 function that creates the location list, and the remaining
16227 locations just get added on to that list.
16228 Note that we only know the start address for a location
16229 (IE location changes), so to build the range, we use
16230 the range [current location start, next location start].
16231 This means we have to special case the last node, and generate
16232 a range of [last location start, end of function label]. */
16234 secname
= secname_for_decl (decl
);
16236 for (node
= loc_list
->first
; node
; node
= node
->next
)
16237 if (GET_CODE (node
->loc
) == EXPR_LIST
16238 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
16240 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16242 /* This requires DW_OP_{,bit_}piece, which is not usable
16243 inside DWARF expressions. */
16244 if (want_address
!= 2)
16246 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16252 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16253 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16254 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
16258 bool range_across_switch
= false;
16259 /* If section switch happens in between node->label
16260 and node->next->label (or end of function) and
16261 we can't emit it as a single entry list,
16262 emit two ranges, first one ending at the end
16263 of first partition and second one starting at the
16264 beginning of second partition. */
16265 if (node
== loc_list
->last_before_switch
16266 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
16267 && current_function_decl
)
16269 endname
= cfun
->fde
->dw_fde_end
;
16270 range_across_switch
= true;
16272 /* The variable has a location between NODE->LABEL and
16273 NODE->NEXT->LABEL. */
16274 else if (node
->next
)
16275 endname
= node
->next
->label
;
16276 /* If the variable has a location at the last label
16277 it keeps its location until the end of function. */
16278 else if (!current_function_decl
)
16279 endname
= text_end_label
;
16282 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
16283 current_function_funcdef_no
);
16284 endname
= ggc_strdup (label_id
);
16287 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
16288 if (TREE_CODE (decl
) == PARM_DECL
16289 && node
== loc_list
->first
16290 && NOTE_P (node
->loc
)
16291 && strcmp (node
->label
, endname
) == 0)
16292 (*listp
)->force
= true;
16293 listp
= &(*listp
)->dw_loc_next
;
16295 if (range_across_switch
)
16297 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16298 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16301 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16302 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16303 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
16306 gcc_assert (descr
);
16307 /* The variable has a location between NODE->LABEL and
16308 NODE->NEXT->LABEL. */
16310 endname
= node
->next
->label
;
16312 endname
= cfun
->fde
->dw_fde_second_end
;
16313 *listp
= new_loc_list (descr
,
16314 cfun
->fde
->dw_fde_second_begin
,
16316 listp
= &(*listp
)->dw_loc_next
;
16321 /* Try to avoid the overhead of a location list emitting a location
16322 expression instead, but only if we didn't have more than one
16323 location entry in the first place. If some entries were not
16324 representable, we don't want to pretend a single entry that was
16325 applies to the entire scope in which the variable is
16327 if (list
&& loc_list
->first
->next
)
16333 /* Return if the loc_list has only single element and thus can be represented
16334 as location description. */
16337 single_element_loc_list_p (dw_loc_list_ref list
)
16339 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
16340 return !list
->ll_symbol
;
16343 /* Duplicate a single element of location list. */
16345 static inline dw_loc_descr_ref
16346 copy_loc_descr (dw_loc_descr_ref ref
)
16348 dw_loc_descr_ref copy
= ggc_alloc
<dw_loc_descr_node
> ();
16349 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
16353 /* To each location in list LIST append loc descr REF. */
16356 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
16358 dw_loc_descr_ref copy
;
16359 add_loc_descr (&list
->expr
, ref
);
16360 list
= list
->dw_loc_next
;
16363 copy
= copy_loc_descr (ref
);
16364 add_loc_descr (&list
->expr
, copy
);
16365 while (copy
->dw_loc_next
)
16366 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
16367 list
= list
->dw_loc_next
;
16371 /* To each location in list LIST prepend loc descr REF. */
16374 prepend_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
16376 dw_loc_descr_ref copy
;
16377 dw_loc_descr_ref ref_end
= list
->expr
;
16378 add_loc_descr (&ref
, list
->expr
);
16380 list
= list
->dw_loc_next
;
16383 dw_loc_descr_ref end
= list
->expr
;
16384 list
->expr
= copy
= copy_loc_descr (ref
);
16385 while (copy
->dw_loc_next
!= ref_end
)
16386 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
16387 copy
->dw_loc_next
= end
;
16388 list
= list
->dw_loc_next
;
16392 /* Given two lists RET and LIST
16393 produce location list that is result of adding expression in LIST
16394 to expression in RET on each position in program.
16395 Might be destructive on both RET and LIST.
16397 TODO: We handle only simple cases of RET or LIST having at most one
16398 element. General case would involve sorting the lists in program order
16399 and merging them that will need some additional work.
16400 Adding that will improve quality of debug info especially for SRA-ed
16404 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
16413 if (!list
->dw_loc_next
)
16415 add_loc_descr_to_each (*ret
, list
->expr
);
16418 if (!(*ret
)->dw_loc_next
)
16420 prepend_loc_descr_to_each (list
, (*ret
)->expr
);
16424 expansion_failed (NULL_TREE
, NULL_RTX
,
16425 "Don't know how to merge two non-trivial"
16426 " location lists.\n");
16431 /* LOC is constant expression. Try a luck, look it up in constant
16432 pool and return its loc_descr of its address. */
16434 static dw_loc_descr_ref
16435 cst_pool_loc_descr (tree loc
)
16437 /* Get an RTL for this, if something has been emitted. */
16438 rtx rtl
= lookup_constant_def (loc
);
16440 if (!rtl
|| !MEM_P (rtl
))
16445 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
16447 /* TODO: We might get more coverage if we was actually delaying expansion
16448 of all expressions till end of compilation when constant pools are fully
16450 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
16452 expansion_failed (loc
, NULL_RTX
,
16453 "CST value in contant pool but not marked.");
16456 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
16457 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
16460 /* Return dw_loc_list representing address of addr_expr LOC
16461 by looking for inner INDIRECT_REF expression and turning
16462 it into simple arithmetics.
16464 See loc_list_from_tree for the meaning of CONTEXT. */
16466 static dw_loc_list_ref
16467 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
16468 loc_descr_context
*context
)
16471 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
16473 int unsignedp
, reversep
, volatilep
= 0;
16474 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
16476 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
16477 &bitsize
, &bitpos
, &offset
, &mode
,
16478 &unsignedp
, &reversep
, &volatilep
);
16480 if (bitpos
% BITS_PER_UNIT
)
16482 expansion_failed (loc
, NULL_RTX
, "bitfield access");
16485 if (!INDIRECT_REF_P (obj
))
16487 expansion_failed (obj
,
16488 NULL_RTX
, "no indirect ref in inner refrence");
16491 if (!offset
&& !bitpos
)
16492 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
16495 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
16496 && (dwarf_version
>= 4 || !dwarf_strict
))
16498 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
16503 /* Variable offset. */
16504 list_ret1
= loc_list_from_tree (offset
, 0, context
);
16505 if (list_ret1
== 0)
16507 add_loc_list (&list_ret
, list_ret1
);
16510 add_loc_descr_to_each (list_ret
,
16511 new_loc_descr (DW_OP_plus
, 0, 0));
16513 bytepos
= bitpos
/ BITS_PER_UNIT
;
16515 add_loc_descr_to_each (list_ret
,
16516 new_loc_descr (DW_OP_plus_uconst
,
16518 else if (bytepos
< 0)
16519 loc_list_plus_const (list_ret
, bytepos
);
16520 add_loc_descr_to_each (list_ret
,
16521 new_loc_descr (DW_OP_stack_value
, 0, 0));
16526 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
16527 all operations from LOC are nops, move to the last one. Insert in NOPS all
16528 operations that are skipped. */
16531 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
16532 hash_set
<dw_loc_descr_ref
> &nops
)
16534 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
16537 loc
= loc
->dw_loc_next
;
16541 /* Helper for loc_descr_without_nops: free the location description operation
16545 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
16551 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
16555 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
16557 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
16560 /* Set of all DW_OP_nop operations we remove. */
16561 hash_set
<dw_loc_descr_ref
> nops
;
16563 /* First, strip all prefix NOP operations in order to keep the head of the
16564 operations list. */
16565 loc_descr_to_next_no_nop (loc
, nops
);
16567 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
16569 /* For control flow operations: strip "prefix" nops in destination
16571 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
16572 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
16573 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
16574 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
16576 /* Do the same for the operations that follow, then move to the next
16578 if (cur
->dw_loc_next
!= NULL
)
16579 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
16580 cur
= cur
->dw_loc_next
;
16583 nops
.traverse
<void *, free_loc_descr
> (NULL
);
16587 struct dwarf_procedure_info
;
16589 /* Helper structure for location descriptions generation. */
16590 struct loc_descr_context
16592 /* The type that is implicitly referenced by DW_OP_push_object_address, or
16593 NULL_TREE if DW_OP_push_object_address in invalid for this location
16594 description. This is used when processing PLACEHOLDER_EXPR nodes. */
16596 /* The ..._DECL node that should be translated as a
16597 DW_OP_push_object_address operation. */
16599 /* Information about the DWARF procedure we are currently generating. NULL if
16600 we are not generating a DWARF procedure. */
16601 struct dwarf_procedure_info
*dpi
;
16602 /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
16603 by consumer. Used for DW_TAG_generic_subrange attributes. */
16604 bool placeholder_arg
;
16605 /* True if PLACEHOLDER_EXPR has been seen. */
16606 bool placeholder_seen
;
16609 /* DWARF procedures generation
16611 DWARF expressions (aka. location descriptions) are used to encode variable
16612 things such as sizes or offsets. Such computations can have redundant parts
16613 that can be factorized in order to reduce the size of the output debug
16614 information. This is the whole point of DWARF procedures.
16616 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
16617 already factorized into functions ("size functions") in order to handle very
16618 big and complex types. Such functions are quite simple: they have integral
16619 arguments, they return an integral result and their body contains only a
16620 return statement with arithmetic expressions. This is the only kind of
16621 function we are interested in translating into DWARF procedures, here.
16623 DWARF expressions and DWARF procedure are executed using a stack, so we have
16624 to define some calling convention for them to interact. Let's say that:
16626 - Before calling a DWARF procedure, DWARF expressions must push on the stack
16627 all arguments in reverse order (right-to-left) so that when the DWARF
16628 procedure execution starts, the first argument is the top of the stack.
16630 - Then, when returning, the DWARF procedure must have consumed all arguments
16631 on the stack, must have pushed the result and touched nothing else.
16633 - Each integral argument and the result are integral types can be hold in a
16636 - We call "frame offset" the number of stack slots that are "under DWARF
16637 procedure control": it includes the arguments slots, the temporaries and
16638 the result slot. Thus, it is equal to the number of arguments when the
16639 procedure execution starts and must be equal to one (the result) when it
16642 /* Helper structure used when generating operations for a DWARF procedure. */
16643 struct dwarf_procedure_info
16645 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
16646 currently translated. */
16648 /* The number of arguments FNDECL takes. */
16649 unsigned args_count
;
16652 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
16653 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
16654 equate it to this DIE. */
16657 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
16658 dw_die_ref parent_die
)
16660 dw_die_ref dwarf_proc_die
;
16662 if ((dwarf_version
< 3 && dwarf_strict
)
16663 || location
== NULL
)
16666 dwarf_proc_die
= new_die (DW_TAG_dwarf_procedure
, parent_die
, fndecl
);
16668 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
16669 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
16670 return dwarf_proc_die
;
16673 /* Return whether TYPE is a supported type as a DWARF procedure argument
16674 type or return type (we handle only scalar types and pointer types that
16675 aren't wider than the DWARF expression evaluation stack. */
16678 is_handled_procedure_type (tree type
)
16680 return ((INTEGRAL_TYPE_P (type
)
16681 || TREE_CODE (type
) == OFFSET_TYPE
16682 || TREE_CODE (type
) == POINTER_TYPE
)
16683 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
16686 /* Helper for resolve_args_picking: do the same but stop when coming across
16687 visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
16688 offset *before* evaluating the corresponding operation. */
16691 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
16692 struct dwarf_procedure_info
*dpi
,
16693 hash_map
<dw_loc_descr_ref
, unsigned> &frame_offsets
)
16695 /* The "frame_offset" identifier is already used to name a macro... */
16696 unsigned frame_offset_
= initial_frame_offset
;
16697 dw_loc_descr_ref l
;
16699 for (l
= loc
; l
!= NULL
;)
16702 unsigned &l_frame_offset
= frame_offsets
.get_or_insert (l
, &existed
);
16704 /* If we already met this node, there is nothing to compute anymore. */
16707 /* Make sure that the stack size is consistent wherever the execution
16708 flow comes from. */
16709 gcc_assert ((unsigned) l_frame_offset
== frame_offset_
);
16712 l_frame_offset
= frame_offset_
;
16714 /* If needed, relocate the picking offset with respect to the frame
16716 if (l
->frame_offset_rel
)
16718 unsigned HOST_WIDE_INT off
;
16719 switch (l
->dw_loc_opc
)
16722 off
= l
->dw_loc_oprnd1
.v
.val_unsigned
;
16731 gcc_unreachable ();
16733 /* frame_offset_ is the size of the current stack frame, including
16734 incoming arguments. Besides, the arguments are pushed
16735 right-to-left. Thus, in order to access the Nth argument from
16736 this operation node, the picking has to skip temporaries *plus*
16737 one stack slot per argument (0 for the first one, 1 for the second
16740 The targetted argument number (N) is already set as the operand,
16741 and the number of temporaries can be computed with:
16742 frame_offsets_ - dpi->args_count */
16743 off
+= frame_offset_
- dpi
->args_count
;
16745 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
16751 l
->dw_loc_opc
= DW_OP_dup
;
16752 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16756 l
->dw_loc_opc
= DW_OP_over
;
16757 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16761 l
->dw_loc_opc
= DW_OP_pick
;
16762 l
->dw_loc_oprnd1
.v
.val_unsigned
= off
;
16766 /* Update frame_offset according to the effect the current operation has
16768 switch (l
->dw_loc_opc
)
16776 case DW_OP_plus_uconst
:
16812 case DW_OP_deref_size
:
16814 case DW_OP_bit_piece
:
16815 case DW_OP_implicit_value
:
16816 case DW_OP_stack_value
:
16820 case DW_OP_const1u
:
16821 case DW_OP_const1s
:
16822 case DW_OP_const2u
:
16823 case DW_OP_const2s
:
16824 case DW_OP_const4u
:
16825 case DW_OP_const4s
:
16826 case DW_OP_const8u
:
16827 case DW_OP_const8s
:
16898 case DW_OP_push_object_address
:
16899 case DW_OP_call_frame_cfa
:
16900 case DW_OP_GNU_variable_value
:
16925 case DW_OP_xderef_size
:
16931 case DW_OP_call_ref
:
16933 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
16934 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
16936 if (stack_usage
== NULL
)
16938 frame_offset_
+= *stack_usage
;
16942 case DW_OP_implicit_pointer
:
16943 case DW_OP_entry_value
:
16944 case DW_OP_const_type
:
16945 case DW_OP_regval_type
:
16946 case DW_OP_deref_type
:
16947 case DW_OP_convert
:
16948 case DW_OP_reinterpret
:
16949 case DW_OP_form_tls_address
:
16950 case DW_OP_GNU_push_tls_address
:
16951 case DW_OP_GNU_uninit
:
16952 case DW_OP_GNU_encoded_addr
:
16953 case DW_OP_GNU_implicit_pointer
:
16954 case DW_OP_GNU_entry_value
:
16955 case DW_OP_GNU_const_type
:
16956 case DW_OP_GNU_regval_type
:
16957 case DW_OP_GNU_deref_type
:
16958 case DW_OP_GNU_convert
:
16959 case DW_OP_GNU_reinterpret
:
16960 case DW_OP_GNU_parameter_ref
:
16961 /* loc_list_from_tree will probably not output these operations for
16962 size functions, so assume they will not appear here. */
16963 /* Fall through... */
16966 gcc_unreachable ();
16969 /* Now, follow the control flow (except subroutine calls). */
16970 switch (l
->dw_loc_opc
)
16973 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
16976 /* Fall through. */
16979 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
16982 case DW_OP_stack_value
:
16986 l
= l
->dw_loc_next
;
16994 /* Make a DFS over operations reachable through LOC (i.e. follow branch
16995 operations) in order to resolve the operand of DW_OP_pick operations that
16996 target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
16997 offset *before* LOC is executed. Return if all relocations were
17001 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
17002 struct dwarf_procedure_info
*dpi
)
17004 /* Associate to all visited operations the frame offset *before* evaluating
17006 hash_map
<dw_loc_descr_ref
, unsigned> frame_offsets
;
17008 return resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
,
17012 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
17013 Return NULL if it is not possible. */
17016 function_to_dwarf_procedure (tree fndecl
)
17018 struct loc_descr_context ctx
;
17019 struct dwarf_procedure_info dpi
;
17020 dw_die_ref dwarf_proc_die
;
17021 tree tree_body
= DECL_SAVED_TREE (fndecl
);
17022 dw_loc_descr_ref loc_body
, epilogue
;
17027 /* Do not generate multiple DWARF procedures for the same function
17029 dwarf_proc_die
= lookup_decl_die (fndecl
);
17030 if (dwarf_proc_die
!= NULL
)
17031 return dwarf_proc_die
;
17033 /* DWARF procedures are available starting with the DWARFv3 standard. */
17034 if (dwarf_version
< 3 && dwarf_strict
)
17037 /* We handle only functions for which we still have a body, that return a
17038 supported type and that takes arguments with supported types. Note that
17039 there is no point translating functions that return nothing. */
17040 if (tree_body
== NULL_TREE
17041 || DECL_RESULT (fndecl
) == NULL_TREE
17042 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
17045 for (cursor
= DECL_ARGUMENTS (fndecl
);
17046 cursor
!= NULL_TREE
;
17047 cursor
= TREE_CHAIN (cursor
))
17048 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
17051 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
17052 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
17054 tree_body
= TREE_OPERAND (tree_body
, 0);
17055 if (TREE_CODE (tree_body
) != MODIFY_EXPR
17056 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
17058 tree_body
= TREE_OPERAND (tree_body
, 1);
17060 /* Try to translate the body expression itself. Note that this will probably
17061 cause an infinite recursion if its call graph has a cycle. This is very
17062 unlikely for size functions, however, so don't bother with such things at
17064 ctx
.context_type
= NULL_TREE
;
17065 ctx
.base_decl
= NULL_TREE
;
17067 ctx
.placeholder_arg
= false;
17068 ctx
.placeholder_seen
= false;
17069 dpi
.fndecl
= fndecl
;
17070 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
17071 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
17075 /* After evaluating all operands in "loc_body", we should still have on the
17076 stack all arguments plus the desired function result (top of the stack).
17077 Generate code in order to keep only the result in our stack frame. */
17079 for (i
= 0; i
< dpi
.args_count
; ++i
)
17081 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
17082 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
17083 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
17084 epilogue
= op_couple
;
17086 add_loc_descr (&loc_body
, epilogue
);
17087 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
17090 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
17091 because they are considered useful. Now there is an epilogue, they are
17092 not anymore, so give it another try. */
17093 loc_descr_without_nops (loc_body
);
17095 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
17096 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
17097 though, given that size functions do not come from source, so they should
17098 not have a dedicated DW_TAG_subprogram DIE. */
17100 = new_dwarf_proc_die (loc_body
, fndecl
,
17101 get_context_die (DECL_CONTEXT (fndecl
)));
17103 /* The called DWARF procedure consumes one stack slot per argument and
17104 returns one stack slot. */
17105 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
17107 return dwarf_proc_die
;
17111 /* Generate Dwarf location list representing LOC.
17112 If WANT_ADDRESS is false, expression computing LOC will be computed
17113 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
17114 if WANT_ADDRESS is 2, expression computing address useable in location
17115 will be returned (i.e. DW_OP_reg can be used
17116 to refer to register values).
17118 CONTEXT provides information to customize the location descriptions
17119 generation. Its context_type field specifies what type is implicitly
17120 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
17121 will not be generated.
17123 Its DPI field determines whether we are generating a DWARF expression for a
17124 DWARF procedure, so PARM_DECL references are processed specifically.
17126 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
17127 and dpi fields were null. */
17129 static dw_loc_list_ref
17130 loc_list_from_tree_1 (tree loc
, int want_address
,
17131 struct loc_descr_context
*context
)
17133 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
17134 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
17135 int have_address
= 0;
17136 enum dwarf_location_atom op
;
17138 /* ??? Most of the time we do not take proper care for sign/zero
17139 extending the values properly. Hopefully this won't be a real
17142 if (context
!= NULL
17143 && context
->base_decl
== loc
17144 && want_address
== 0)
17146 if (dwarf_version
>= 3 || !dwarf_strict
)
17147 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
17153 switch (TREE_CODE (loc
))
17156 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
17159 case PLACEHOLDER_EXPR
:
17160 /* This case involves extracting fields from an object to determine the
17161 position of other fields. It is supposed to appear only as the first
17162 operand of COMPONENT_REF nodes and to reference precisely the type
17163 that the context allows. */
17164 if (context
!= NULL
17165 && TREE_TYPE (loc
) == context
->context_type
17166 && want_address
>= 1)
17168 if (dwarf_version
>= 3 || !dwarf_strict
)
17170 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
17177 /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
17178 the single argument passed by consumer. */
17179 else if (context
!= NULL
17180 && context
->placeholder_arg
17181 && INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17182 && want_address
== 0)
17184 ret
= new_loc_descr (DW_OP_pick
, 0, 0);
17185 ret
->frame_offset_rel
= 1;
17186 context
->placeholder_seen
= true;
17190 expansion_failed (loc
, NULL_RTX
,
17191 "PLACEHOLDER_EXPR for an unexpected type");
17196 const int nargs
= call_expr_nargs (loc
);
17197 tree callee
= get_callee_fndecl (loc
);
17199 dw_die_ref dwarf_proc
;
17201 if (callee
== NULL_TREE
)
17202 goto call_expansion_failed
;
17204 /* We handle only functions that return an integer. */
17205 if (!is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
))))
17206 goto call_expansion_failed
;
17208 dwarf_proc
= function_to_dwarf_procedure (callee
);
17209 if (dwarf_proc
== NULL
)
17210 goto call_expansion_failed
;
17212 /* Evaluate arguments right-to-left so that the first argument will
17213 be the top-most one on the stack. */
17214 for (i
= nargs
- 1; i
>= 0; --i
)
17216 dw_loc_descr_ref loc_descr
17217 = loc_descriptor_from_tree (CALL_EXPR_ARG (loc
, i
), 0,
17220 if (loc_descr
== NULL
)
17221 goto call_expansion_failed
;
17223 add_loc_descr (&ret
, loc_descr
);
17226 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
17227 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17228 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
17229 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17230 add_loc_descr (&ret
, ret1
);
17233 call_expansion_failed
:
17234 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
17235 /* There are no opcodes for these operations. */
17239 case PREINCREMENT_EXPR
:
17240 case PREDECREMENT_EXPR
:
17241 case POSTINCREMENT_EXPR
:
17242 case POSTDECREMENT_EXPR
:
17243 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
17244 /* There are no opcodes for these operations. */
17248 /* If we already want an address, see if there is INDIRECT_REF inside
17249 e.g. for &this->field. */
17252 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
17253 (loc
, want_address
== 2, context
);
17256 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
17257 && (ret
= cst_pool_loc_descr (loc
)))
17260 /* Otherwise, process the argument and look for the address. */
17261 if (!list_ret
&& !ret
)
17262 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
17266 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
17272 if (DECL_THREAD_LOCAL_P (loc
))
17275 enum dwarf_location_atom tls_op
;
17276 enum dtprel_bool dtprel
= dtprel_false
;
17278 if (targetm
.have_tls
)
17280 /* If this is not defined, we have no way to emit the
17282 if (!targetm
.asm_out
.output_dwarf_dtprel
)
17285 /* The way DW_OP_GNU_push_tls_address is specified, we
17286 can only look up addresses of objects in the current
17287 module. We used DW_OP_addr as first op, but that's
17288 wrong, because DW_OP_addr is relocated by the debug
17289 info consumer, while DW_OP_GNU_push_tls_address
17290 operand shouldn't be. */
17291 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
17293 dtprel
= dtprel_true
;
17294 /* We check for DWARF 5 here because gdb did not implement
17295 DW_OP_form_tls_address until after 7.12. */
17296 tls_op
= (dwarf_version
>= 5 ? DW_OP_form_tls_address
17297 : DW_OP_GNU_push_tls_address
);
17301 if (!targetm
.emutls
.debug_form_tls_address
17302 || !(dwarf_version
>= 3 || !dwarf_strict
))
17304 /* We stuffed the control variable into the DECL_VALUE_EXPR
17305 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
17306 no longer appear in gimple code. We used the control
17307 variable in specific so that we could pick it up here. */
17308 loc
= DECL_VALUE_EXPR (loc
);
17309 tls_op
= DW_OP_form_tls_address
;
17312 rtl
= rtl_for_decl_location (loc
);
17313 if (rtl
== NULL_RTX
)
17318 rtl
= XEXP (rtl
, 0);
17319 if (! CONSTANT_P (rtl
))
17322 ret
= new_addr_loc_descr (rtl
, dtprel
);
17323 ret1
= new_loc_descr (tls_op
, 0, 0);
17324 add_loc_descr (&ret
, ret1
);
17332 if (context
!= NULL
&& context
->dpi
!= NULL
17333 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
17335 /* We are generating code for a DWARF procedure and we want to access
17336 one of its arguments: find the appropriate argument offset and let
17337 the resolve_args_picking pass compute the offset that complies
17338 with the stack frame size. */
17342 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
17343 cursor
!= NULL_TREE
&& cursor
!= loc
;
17344 cursor
= TREE_CHAIN (cursor
), ++i
)
17346 /* If we are translating a DWARF procedure, all referenced parameters
17347 must belong to the current function. */
17348 gcc_assert (cursor
!= NULL_TREE
);
17350 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
17351 ret
->frame_offset_rel
= 1;
17357 if (DECL_HAS_VALUE_EXPR_P (loc
))
17358 return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc
),
17359 want_address
, context
);
17362 case FUNCTION_DECL
:
17365 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
17367 if (loc_list
&& loc_list
->first
)
17369 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
17370 have_address
= want_address
!= 0;
17373 rtl
= rtl_for_decl_location (loc
);
17374 if (rtl
== NULL_RTX
)
17376 if (TREE_CODE (loc
) != FUNCTION_DECL
17378 && current_function_decl
17379 && want_address
!= 1
17380 && ! DECL_IGNORED_P (loc
)
17381 && (INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17382 || POINTER_TYPE_P (TREE_TYPE (loc
)))
17383 && DECL_CONTEXT (loc
) == current_function_decl
17384 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc
)))
17385 <= DWARF2_ADDR_SIZE
))
17387 dw_die_ref ref
= lookup_decl_die (loc
);
17388 ret
= new_loc_descr (DW_OP_GNU_variable_value
, 0, 0);
17391 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17392 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
17393 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17397 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
17398 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= loc
;
17402 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
17405 else if (CONST_INT_P (rtl
))
17407 HOST_WIDE_INT val
= INTVAL (rtl
);
17408 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17409 val
&= GET_MODE_MASK (DECL_MODE (loc
));
17410 ret
= int_loc_descriptor (val
);
17412 else if (GET_CODE (rtl
) == CONST_STRING
)
17414 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
17417 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
17418 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
17421 machine_mode mode
, mem_mode
;
17423 /* Certain constructs can only be represented at top-level. */
17424 if (want_address
== 2)
17426 ret
= loc_descriptor (rtl
, VOIDmode
,
17427 VAR_INIT_STATUS_INITIALIZED
);
17432 mode
= GET_MODE (rtl
);
17433 mem_mode
= VOIDmode
;
17437 mode
= get_address_mode (rtl
);
17438 rtl
= XEXP (rtl
, 0);
17441 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
17442 VAR_INIT_STATUS_INITIALIZED
);
17445 expansion_failed (loc
, rtl
,
17446 "failed to produce loc descriptor for rtl");
17452 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
17459 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17463 case TARGET_MEM_REF
:
17465 case DEBUG_EXPR_DECL
:
17468 case COMPOUND_EXPR
:
17469 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
17473 case VIEW_CONVERT_EXPR
:
17476 case NON_LVALUE_EXPR
:
17477 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
17480 case COMPONENT_REF
:
17481 case BIT_FIELD_REF
:
17483 case ARRAY_RANGE_REF
:
17484 case REALPART_EXPR
:
17485 case IMAGPART_EXPR
:
17488 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
17490 int unsignedp
, reversep
, volatilep
= 0;
17492 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
17493 &unsignedp
, &reversep
, &volatilep
);
17495 gcc_assert (obj
!= loc
);
17497 list_ret
= loc_list_from_tree_1 (obj
,
17499 && !bitpos
&& !offset
? 2 : 1,
17501 /* TODO: We can extract value of the small expression via shifting even
17502 for nonzero bitpos. */
17505 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
17507 expansion_failed (loc
, NULL_RTX
,
17508 "bitfield access");
17512 if (offset
!= NULL_TREE
)
17514 /* Variable offset. */
17515 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
17516 if (list_ret1
== 0)
17518 add_loc_list (&list_ret
, list_ret1
);
17521 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
17524 bytepos
= bitpos
/ BITS_PER_UNIT
;
17526 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
17527 else if (bytepos
< 0)
17528 loc_list_plus_const (list_ret
, bytepos
);
17535 if ((want_address
|| !tree_fits_shwi_p (loc
))
17536 && (ret
= cst_pool_loc_descr (loc
)))
17538 else if (want_address
== 2
17539 && tree_fits_shwi_p (loc
)
17540 && (ret
= address_of_int_loc_descriptor
17541 (int_size_in_bytes (TREE_TYPE (loc
)),
17542 tree_to_shwi (loc
))))
17544 else if (tree_fits_shwi_p (loc
))
17545 ret
= int_loc_descriptor (tree_to_shwi (loc
));
17546 else if (tree_fits_uhwi_p (loc
))
17547 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
17550 expansion_failed (loc
, NULL_RTX
,
17551 "Integer operand is not host integer");
17560 if ((ret
= cst_pool_loc_descr (loc
)))
17562 else if (TREE_CODE (loc
) == CONSTRUCTOR
)
17564 tree type
= TREE_TYPE (loc
);
17565 unsigned HOST_WIDE_INT size
= int_size_in_bytes (type
);
17566 unsigned HOST_WIDE_INT offset
= 0;
17567 unsigned HOST_WIDE_INT cnt
;
17568 constructor_elt
*ce
;
17570 if (TREE_CODE (type
) == RECORD_TYPE
)
17572 /* This is very limited, but it's enough to output
17573 pointers to member functions, as long as the
17574 referenced function is defined in the current
17575 translation unit. */
17576 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc
), cnt
, ce
)
17578 tree val
= ce
->value
;
17580 tree field
= ce
->index
;
17585 if (!field
|| DECL_BIT_FIELD (field
))
17587 expansion_failed (loc
, NULL_RTX
,
17588 "bitfield in record type constructor");
17589 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17594 HOST_WIDE_INT fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
17595 unsigned HOST_WIDE_INT pos
= int_byte_position (field
);
17596 gcc_assert (pos
+ fieldsize
<= size
);
17599 expansion_failed (loc
, NULL_RTX
,
17600 "out-of-order fields in record constructor");
17601 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17607 ret1
= new_loc_descr (DW_OP_piece
, pos
- offset
, 0);
17608 add_loc_descr (&ret
, ret1
);
17611 if (val
&& fieldsize
!= 0)
17613 ret1
= loc_descriptor_from_tree (val
, want_address
, context
);
17616 expansion_failed (loc
, NULL_RTX
,
17617 "unsupported expression in field");
17618 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17622 add_loc_descr (&ret
, ret1
);
17626 ret1
= new_loc_descr (DW_OP_piece
, fieldsize
, 0);
17627 add_loc_descr (&ret
, ret1
);
17628 offset
= pos
+ fieldsize
;
17632 if (offset
!= size
)
17634 ret1
= new_loc_descr (DW_OP_piece
, size
- offset
, 0);
17635 add_loc_descr (&ret
, ret1
);
17639 have_address
= !!want_address
;
17642 expansion_failed (loc
, NULL_RTX
,
17643 "constructor of non-record type");
17646 /* We can construct small constants here using int_loc_descriptor. */
17647 expansion_failed (loc
, NULL_RTX
,
17648 "constructor or constant not in constant pool");
17651 case TRUTH_AND_EXPR
:
17652 case TRUTH_ANDIF_EXPR
:
17657 case TRUTH_XOR_EXPR
:
17662 case TRUTH_OR_EXPR
:
17663 case TRUTH_ORIF_EXPR
:
17668 case FLOOR_DIV_EXPR
:
17669 case CEIL_DIV_EXPR
:
17670 case ROUND_DIV_EXPR
:
17671 case TRUNC_DIV_EXPR
:
17672 case EXACT_DIV_EXPR
:
17673 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17682 case FLOOR_MOD_EXPR
:
17683 case CEIL_MOD_EXPR
:
17684 case ROUND_MOD_EXPR
:
17685 case TRUNC_MOD_EXPR
:
17686 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17691 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17692 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17693 if (list_ret
== 0 || list_ret1
== 0)
17696 add_loc_list (&list_ret
, list_ret1
);
17699 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17700 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17701 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
17702 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
17703 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
17715 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
17718 case POINTER_PLUS_EXPR
:
17721 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
17723 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
17724 smarter to encode their opposite. The DW_OP_plus_uconst operation
17725 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
17726 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
17727 bytes, Y being the size of the operation that pushes the opposite
17728 of the addend. So let's choose the smallest representation. */
17729 const tree tree_addend
= TREE_OPERAND (loc
, 1);
17730 offset_int wi_addend
;
17731 HOST_WIDE_INT shwi_addend
;
17732 dw_loc_descr_ref loc_naddend
;
17734 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17738 /* Try to get the literal to push. It is the opposite of the addend,
17739 so as we rely on wrapping during DWARF evaluation, first decode
17740 the literal as a "DWARF-sized" signed number. */
17741 wi_addend
= wi::to_offset (tree_addend
);
17742 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
17743 shwi_addend
= wi_addend
.to_shwi ();
17744 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
17745 ? int_loc_descriptor (-shwi_addend
)
17748 if (loc_naddend
!= NULL
17749 && ((unsigned) size_of_uleb128 (shwi_addend
)
17750 > size_of_loc_descr (loc_naddend
)))
17752 add_loc_descr_to_each (list_ret
, loc_naddend
);
17753 add_loc_descr_to_each (list_ret
,
17754 new_loc_descr (DW_OP_minus
, 0, 0));
17758 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
17760 loc_naddend
= loc_cur
;
17761 loc_cur
= loc_cur
->dw_loc_next
;
17762 ggc_free (loc_naddend
);
17764 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
17774 goto do_comp_binop
;
17778 goto do_comp_binop
;
17782 goto do_comp_binop
;
17786 goto do_comp_binop
;
17789 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
17791 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
17792 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
17793 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
17809 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17810 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17811 if (list_ret
== 0 || list_ret1
== 0)
17814 add_loc_list (&list_ret
, list_ret1
);
17817 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
17820 case TRUTH_NOT_EXPR
:
17834 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17838 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
17844 const enum tree_code code
=
17845 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
17847 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
17848 build2 (code
, integer_type_node
,
17849 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
17850 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
17857 dw_loc_descr_ref lhs
17858 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
17859 dw_loc_list_ref rhs
17860 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
17861 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
17863 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17864 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
17867 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
17868 add_loc_descr_to_each (list_ret
, bra_node
);
17870 add_loc_list (&list_ret
, rhs
);
17871 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
17872 add_loc_descr_to_each (list_ret
, jump_node
);
17874 add_loc_descr_to_each (list_ret
, lhs
);
17875 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
17876 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
17878 /* ??? Need a node to point the skip at. Use a nop. */
17879 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
17880 add_loc_descr_to_each (list_ret
, tmp
);
17881 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
17882 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
17886 case FIX_TRUNC_EXPR
:
17890 /* Leave front-end specific codes as simply unknown. This comes
17891 up, for instance, with the C STMT_EXPR. */
17892 if ((unsigned int) TREE_CODE (loc
)
17893 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
17895 expansion_failed (loc
, NULL_RTX
,
17896 "language specific tree node");
17900 /* Otherwise this is a generic code; we should just lists all of
17901 these explicitly. We forgot one. */
17903 gcc_unreachable ();
17905 /* In a release build, we want to degrade gracefully: better to
17906 generate incomplete debugging information than to crash. */
17910 if (!ret
&& !list_ret
)
17913 if (want_address
== 2 && !have_address
17914 && (dwarf_version
>= 4 || !dwarf_strict
))
17916 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
17918 expansion_failed (loc
, NULL_RTX
,
17919 "DWARF address size mismatch");
17923 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17925 add_loc_descr_to_each (list_ret
,
17926 new_loc_descr (DW_OP_stack_value
, 0, 0));
17929 /* Show if we can't fill the request for an address. */
17930 if (want_address
&& !have_address
)
17932 expansion_failed (loc
, NULL_RTX
,
17933 "Want address and only have value");
17937 gcc_assert (!ret
|| !list_ret
);
17939 /* If we've got an address and don't want one, dereference. */
17940 if (!want_address
&& have_address
)
17942 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
17944 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
17946 expansion_failed (loc
, NULL_RTX
,
17947 "DWARF address size mismatch");
17950 else if (size
== DWARF2_ADDR_SIZE
)
17953 op
= DW_OP_deref_size
;
17956 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
17958 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
17961 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
17966 /* Likewise, but strip useless DW_OP_nop operations in the resulting
17969 static dw_loc_list_ref
17970 loc_list_from_tree (tree loc
, int want_address
,
17971 struct loc_descr_context
*context
)
17973 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
17975 for (dw_loc_list_ref loc_cur
= result
;
17976 loc_cur
!= NULL
; loc_cur
= loc_cur
->dw_loc_next
)
17977 loc_descr_without_nops (loc_cur
->expr
);
17981 /* Same as above but return only single location expression. */
17982 static dw_loc_descr_ref
17983 loc_descriptor_from_tree (tree loc
, int want_address
,
17984 struct loc_descr_context
*context
)
17986 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
17989 if (ret
->dw_loc_next
)
17991 expansion_failed (loc
, NULL_RTX
,
17992 "Location list where only loc descriptor needed");
17998 /* Given a value, round it up to the lowest multiple of `boundary'
17999 which is not less than the value itself. */
18001 static inline HOST_WIDE_INT
18002 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
18004 return (((value
+ boundary
- 1) / boundary
) * boundary
);
18007 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
18008 pointer to the declared type for the relevant field variable, or return
18009 `integer_type_node' if the given node turns out to be an
18010 ERROR_MARK node. */
18013 field_type (const_tree decl
)
18017 if (TREE_CODE (decl
) == ERROR_MARK
)
18018 return integer_type_node
;
18020 type
= DECL_BIT_FIELD_TYPE (decl
);
18021 if (type
== NULL_TREE
)
18022 type
= TREE_TYPE (decl
);
18027 /* Given a pointer to a tree node, return the alignment in bits for
18028 it, or else return BITS_PER_WORD if the node actually turns out to
18029 be an ERROR_MARK node. */
18031 static inline unsigned
18032 simple_type_align_in_bits (const_tree type
)
18034 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
18037 static inline unsigned
18038 simple_decl_align_in_bits (const_tree decl
)
18040 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
18043 /* Return the result of rounding T up to ALIGN. */
18045 static inline offset_int
18046 round_up_to_align (const offset_int
&t
, unsigned int align
)
18048 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
18051 /* Compute the size of TYPE in bytes. If possible, return NULL and store the
18052 size as an integer constant in CST_SIZE. Otherwise, if possible, return a
18053 DWARF expression that computes the size. Return NULL and set CST_SIZE to -1
18054 if we fail to return the size in one of these two forms. */
18056 static dw_loc_descr_ref
18057 type_byte_size (const_tree type
, HOST_WIDE_INT
*cst_size
)
18060 struct loc_descr_context ctx
;
18062 /* Return a constant integer in priority, if possible. */
18063 *cst_size
= int_size_in_bytes (type
);
18064 if (*cst_size
!= -1)
18067 ctx
.context_type
= const_cast<tree
> (type
);
18068 ctx
.base_decl
= NULL_TREE
;
18070 ctx
.placeholder_arg
= false;
18071 ctx
.placeholder_seen
= false;
18073 type
= TYPE_MAIN_VARIANT (type
);
18074 tree_size
= TYPE_SIZE_UNIT (type
);
18075 return ((tree_size
!= NULL_TREE
)
18076 ? loc_descriptor_from_tree (tree_size
, 0, &ctx
)
18080 /* Helper structure for RECORD_TYPE processing. */
18083 /* Root RECORD_TYPE. It is needed to generate data member location
18084 descriptions in variable-length records (VLR), but also to cope with
18085 variants, which are composed of nested structures multiplexed with
18086 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
18087 function processing a FIELD_DECL, it is required to be non null. */
18089 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
18090 QUAL_UNION_TYPE), this holds an expression that computes the offset for
18091 this variant part as part of the root record (in storage units). For
18092 regular records, it must be NULL_TREE. */
18093 tree variant_part_offset
;
18096 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
18097 addressed byte of the "containing object" for the given FIELD_DECL. If
18098 possible, return a native constant through CST_OFFSET (in which case NULL is
18099 returned); otherwise return a DWARF expression that computes the offset.
18101 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
18102 that offset is, either because the argument turns out to be a pointer to an
18103 ERROR_MARK node, or because the offset expression is too complex for us.
18105 CTX is required: see the comment for VLR_CONTEXT. */
18107 static dw_loc_descr_ref
18108 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
18109 HOST_WIDE_INT
*cst_offset
)
18112 dw_loc_list_ref loc_result
;
18116 if (TREE_CODE (decl
) == ERROR_MARK
)
18119 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
18121 /* We cannot handle variable bit offsets at the moment, so abort if it's the
18123 if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
)
18126 #ifdef PCC_BITFIELD_TYPE_MATTERS
18127 /* We used to handle only constant offsets in all cases. Now, we handle
18128 properly dynamic byte offsets only when PCC bitfield type doesn't
18130 if (PCC_BITFIELD_TYPE_MATTERS
18131 && TREE_CODE (DECL_FIELD_OFFSET (decl
)) == INTEGER_CST
)
18133 offset_int object_offset_in_bits
;
18134 offset_int object_offset_in_bytes
;
18135 offset_int bitpos_int
;
18137 tree field_size_tree
;
18138 offset_int deepest_bitpos
;
18139 offset_int field_size_in_bits
;
18140 unsigned int type_align_in_bits
;
18141 unsigned int decl_align_in_bits
;
18142 offset_int type_size_in_bits
;
18144 bitpos_int
= wi::to_offset (bit_position (decl
));
18145 type
= field_type (decl
);
18146 type_size_in_bits
= offset_int_type_size_in_bits (type
);
18147 type_align_in_bits
= simple_type_align_in_bits (type
);
18149 field_size_tree
= DECL_SIZE (decl
);
18151 /* The size could be unspecified if there was an error, or for
18152 a flexible array member. */
18153 if (!field_size_tree
)
18154 field_size_tree
= bitsize_zero_node
;
18156 /* If the size of the field is not constant, use the type size. */
18157 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
18158 field_size_in_bits
= wi::to_offset (field_size_tree
);
18160 field_size_in_bits
= type_size_in_bits
;
18162 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
18164 /* The GCC front-end doesn't make any attempt to keep track of the
18165 starting bit offset (relative to the start of the containing
18166 structure type) of the hypothetical "containing object" for a
18167 bit-field. Thus, when computing the byte offset value for the
18168 start of the "containing object" of a bit-field, we must deduce
18169 this information on our own. This can be rather tricky to do in
18170 some cases. For example, handling the following structure type
18171 definition when compiling for an i386/i486 target (which only
18172 aligns long long's to 32-bit boundaries) can be very tricky:
18174 struct S { int field1; long long field2:31; };
18176 Fortunately, there is a simple rule-of-thumb which can be used
18177 in such cases. When compiling for an i386/i486, GCC will
18178 allocate 8 bytes for the structure shown above. It decides to
18179 do this based upon one simple rule for bit-field allocation.
18180 GCC allocates each "containing object" for each bit-field at
18181 the first (i.e. lowest addressed) legitimate alignment boundary
18182 (based upon the required minimum alignment for the declared
18183 type of the field) which it can possibly use, subject to the
18184 condition that there is still enough available space remaining
18185 in the containing object (when allocated at the selected point)
18186 to fully accommodate all of the bits of the bit-field itself.
18188 This simple rule makes it obvious why GCC allocates 8 bytes for
18189 each object of the structure type shown above. When looking
18190 for a place to allocate the "containing object" for `field2',
18191 the compiler simply tries to allocate a 64-bit "containing
18192 object" at each successive 32-bit boundary (starting at zero)
18193 until it finds a place to allocate that 64- bit field such that
18194 at least 31 contiguous (and previously unallocated) bits remain
18195 within that selected 64 bit field. (As it turns out, for the
18196 example above, the compiler finds it is OK to allocate the
18197 "containing object" 64-bit field at bit-offset zero within the
18200 Here we attempt to work backwards from the limited set of facts
18201 we're given, and we try to deduce from those facts, where GCC
18202 must have believed that the containing object started (within
18203 the structure type). The value we deduce is then used (by the
18204 callers of this routine) to generate DW_AT_location and
18205 DW_AT_bit_offset attributes for fields (both bit-fields and, in
18206 the case of DW_AT_location, regular fields as well). */
18208 /* Figure out the bit-distance from the start of the structure to
18209 the "deepest" bit of the bit-field. */
18210 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
18212 /* This is the tricky part. Use some fancy footwork to deduce
18213 where the lowest addressed bit of the containing object must
18215 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18217 /* Round up to type_align by default. This works best for
18219 object_offset_in_bits
18220 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
18222 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
18224 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18226 /* Round up to decl_align instead. */
18227 object_offset_in_bits
18228 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
18231 object_offset_in_bytes
18232 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
18233 if (ctx
->variant_part_offset
== NULL_TREE
)
18235 *cst_offset
= object_offset_in_bytes
.to_shwi ();
18238 tree_result
= wide_int_to_tree (sizetype
, object_offset_in_bytes
);
18241 #endif /* PCC_BITFIELD_TYPE_MATTERS */
18242 tree_result
= byte_position (decl
);
18244 if (ctx
->variant_part_offset
!= NULL_TREE
)
18245 tree_result
= fold_build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
18246 ctx
->variant_part_offset
, tree_result
);
18248 /* If the byte offset is a constant, it's simplier to handle a native
18249 constant rather than a DWARF expression. */
18250 if (TREE_CODE (tree_result
) == INTEGER_CST
)
18252 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
18255 struct loc_descr_context loc_ctx
= {
18256 ctx
->struct_type
, /* context_type */
18257 NULL_TREE
, /* base_decl */
18259 false, /* placeholder_arg */
18260 false /* placeholder_seen */
18262 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
18264 /* We want a DWARF expression: abort if we only have a location list with
18265 multiple elements. */
18266 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
18269 return loc_result
->expr
;
18272 /* The following routines define various Dwarf attributes and any data
18273 associated with them. */
18275 /* Add a location description attribute value to a DIE.
18277 This emits location attributes suitable for whole variables and
18278 whole parameters. Note that the location attributes for struct fields are
18279 generated by the routine `data_member_location_attribute' below. */
18282 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
18283 dw_loc_list_ref descr
)
18287 if (single_element_loc_list_p (descr
))
18288 add_AT_loc (die
, attr_kind
, descr
->expr
);
18290 add_AT_loc_list (die
, attr_kind
, descr
);
18293 /* Add DW_AT_accessibility attribute to DIE if needed. */
18296 add_accessibility_attribute (dw_die_ref die
, tree decl
)
18298 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18299 children, otherwise the default is DW_ACCESS_public. In DWARF2
18300 the default has always been DW_ACCESS_public. */
18301 if (TREE_PROTECTED (decl
))
18302 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18303 else if (TREE_PRIVATE (decl
))
18305 if (dwarf_version
== 2
18306 || die
->die_parent
== NULL
18307 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
18308 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18310 else if (dwarf_version
> 2
18312 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
18313 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18316 /* Attach the specialized form of location attribute used for data members of
18317 struct and union types. In the special case of a FIELD_DECL node which
18318 represents a bit-field, the "offset" part of this special location
18319 descriptor must indicate the distance in bytes from the lowest-addressed
18320 byte of the containing struct or union type to the lowest-addressed byte of
18321 the "containing object" for the bit-field. (See the `field_byte_offset'
18324 For any given bit-field, the "containing object" is a hypothetical object
18325 (of some integral or enum type) within which the given bit-field lives. The
18326 type of this hypothetical "containing object" is always the same as the
18327 declared type of the individual bit-field itself (for GCC anyway... the
18328 DWARF spec doesn't actually mandate this). Note that it is the size (in
18329 bytes) of the hypothetical "containing object" which will be given in the
18330 DW_AT_byte_size attribute for this bit-field. (See the
18331 `byte_size_attribute' function below.) It is also used when calculating the
18332 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
18335 CTX is required: see the comment for VLR_CONTEXT. */
18338 add_data_member_location_attribute (dw_die_ref die
,
18340 struct vlr_context
*ctx
)
18342 HOST_WIDE_INT offset
;
18343 dw_loc_descr_ref loc_descr
= 0;
18345 if (TREE_CODE (decl
) == TREE_BINFO
)
18347 /* We're working on the TAG_inheritance for a base class. */
18348 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
18350 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
18351 aren't at a fixed offset from all (sub)objects of the same
18352 type. We need to extract the appropriate offset from our
18353 vtable. The following dwarf expression means
18355 BaseAddr = ObAddr + *((*ObAddr) - Offset)
18357 This is specific to the V3 ABI, of course. */
18359 dw_loc_descr_ref tmp
;
18361 /* Make a copy of the object address. */
18362 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
18363 add_loc_descr (&loc_descr
, tmp
);
18365 /* Extract the vtable address. */
18366 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18367 add_loc_descr (&loc_descr
, tmp
);
18369 /* Calculate the address of the offset. */
18370 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
18371 gcc_assert (offset
< 0);
18373 tmp
= int_loc_descriptor (-offset
);
18374 add_loc_descr (&loc_descr
, tmp
);
18375 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
18376 add_loc_descr (&loc_descr
, tmp
);
18378 /* Extract the offset. */
18379 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18380 add_loc_descr (&loc_descr
, tmp
);
18382 /* Add it to the object address. */
18383 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
18384 add_loc_descr (&loc_descr
, tmp
);
18387 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
18391 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
18393 /* If loc_descr is available then we know the field offset is dynamic.
18394 However, GDB does not handle dynamic field offsets very well at the
18396 if (loc_descr
!= NULL
&& gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
)
18402 /* Data member location evalutation starts with the base address on the
18403 stack. Compute the field offset and add it to this base address. */
18404 else if (loc_descr
!= NULL
)
18405 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
18410 /* While DW_AT_data_bit_offset has been added already in DWARF4,
18411 e.g. GDB only added support to it in November 2016. For DWARF5
18412 we need newer debug info consumers anyway. We might change this
18413 to dwarf_version >= 4 once most consumers catched up. */
18414 if (dwarf_version
>= 5
18415 && TREE_CODE (decl
) == FIELD_DECL
18416 && DECL_BIT_FIELD_TYPE (decl
))
18418 tree off
= bit_position (decl
);
18419 if (tree_fits_uhwi_p (off
) && get_AT (die
, DW_AT_bit_size
))
18421 remove_AT (die
, DW_AT_byte_size
);
18422 remove_AT (die
, DW_AT_bit_offset
);
18423 add_AT_unsigned (die
, DW_AT_data_bit_offset
, tree_to_uhwi (off
));
18427 if (dwarf_version
> 2)
18429 /* Don't need to output a location expression, just the constant. */
18431 add_AT_int (die
, DW_AT_data_member_location
, offset
);
18433 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
18438 enum dwarf_location_atom op
;
18440 /* The DWARF2 standard says that we should assume that the structure
18441 address is already on the stack, so we can specify a structure
18442 field address by using DW_OP_plus_uconst. */
18443 op
= DW_OP_plus_uconst
;
18444 loc_descr
= new_loc_descr (op
, offset
, 0);
18448 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
18451 /* Writes integer values to dw_vec_const array. */
18454 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
18458 *dest
++ = val
& 0xff;
18464 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
18466 static HOST_WIDE_INT
18467 extract_int (const unsigned char *src
, unsigned int size
)
18469 HOST_WIDE_INT val
= 0;
18475 val
|= *--src
& 0xff;
18481 /* Writes wide_int values to dw_vec_const array. */
18484 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
18488 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
18490 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
18494 /* We'd have to extend this code to support odd sizes. */
18495 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
18497 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
18499 if (WORDS_BIG_ENDIAN
)
18500 for (i
= n
- 1; i
>= 0; i
--)
18502 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18503 dest
+= sizeof (HOST_WIDE_INT
);
18506 for (i
= 0; i
< n
; i
++)
18508 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18509 dest
+= sizeof (HOST_WIDE_INT
);
18513 /* Writes floating point values to dw_vec_const array. */
18516 insert_float (const_rtx rtl
, unsigned char *array
)
18521 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), GET_MODE (rtl
));
18523 /* real_to_target puts 32-bit pieces in each long. Pack them. */
18524 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
18526 insert_int (val
[i
], 4, array
);
18531 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
18532 does not have a "location" either in memory or in a register. These
18533 things can arise in GNU C when a constant is passed as an actual parameter
18534 to an inlined function. They can also arise in C++ where declared
18535 constants do not necessarily get memory "homes". */
18538 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
18540 switch (GET_CODE (rtl
))
18544 HOST_WIDE_INT val
= INTVAL (rtl
);
18547 add_AT_int (die
, DW_AT_const_value
, val
);
18549 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
18553 case CONST_WIDE_INT
:
18555 wide_int w1
= rtx_mode_t (rtl
, MAX_MODE_INT
);
18556 unsigned int prec
= MIN (wi::min_precision (w1
, UNSIGNED
),
18557 (unsigned int)CONST_WIDE_INT_NUNITS (rtl
) * HOST_BITS_PER_WIDE_INT
);
18558 wide_int w
= wi::zext (w1
, prec
);
18559 add_AT_wide (die
, DW_AT_const_value
, w
);
18564 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
18565 floating-point constant. A CONST_DOUBLE is used whenever the
18566 constant requires more than one word in order to be adequately
18569 machine_mode mode
= GET_MODE (rtl
);
18571 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
18572 add_AT_double (die
, DW_AT_const_value
,
18573 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
18576 unsigned int length
= GET_MODE_SIZE (mode
);
18577 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
18579 insert_float (rtl
, array
);
18580 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
18587 machine_mode mode
= GET_MODE (rtl
);
18588 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
18589 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
18590 unsigned char *array
18591 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
18594 machine_mode imode
= GET_MODE_INNER (mode
);
18596 switch (GET_MODE_CLASS (mode
))
18598 case MODE_VECTOR_INT
:
18599 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18601 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18602 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
18606 case MODE_VECTOR_FLOAT
:
18607 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18609 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18610 insert_float (elt
, p
);
18615 gcc_unreachable ();
18618 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
18623 if (dwarf_version
>= 4 || !dwarf_strict
)
18625 dw_loc_descr_ref loc_result
;
18626 resolve_one_addr (&rtl
);
18628 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
18629 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
18630 add_AT_loc (die
, DW_AT_location
, loc_result
);
18631 vec_safe_push (used_rtx_array
, rtl
);
18637 if (CONSTANT_P (XEXP (rtl
, 0)))
18638 return add_const_value_attribute (die
, XEXP (rtl
, 0));
18641 if (!const_ok_for_output (rtl
))
18645 if (dwarf_version
>= 4 || !dwarf_strict
)
18650 /* In cases where an inlined instance of an inline function is passed
18651 the address of an `auto' variable (which is local to the caller) we
18652 can get a situation where the DECL_RTL of the artificial local
18653 variable (for the inlining) which acts as a stand-in for the
18654 corresponding formal parameter (of the inline function) will look
18655 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
18656 exactly a compile-time constant expression, but it isn't the address
18657 of the (artificial) local variable either. Rather, it represents the
18658 *value* which the artificial local variable always has during its
18659 lifetime. We currently have no way to represent such quasi-constant
18660 values in Dwarf, so for now we just punt and generate nothing. */
18668 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
18669 && MEM_READONLY_P (rtl
)
18670 && GET_MODE (rtl
) == BLKmode
)
18672 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
18678 /* No other kinds of rtx should be possible here. */
18679 gcc_unreachable ();
18684 /* Determine whether the evaluation of EXPR references any variables
18685 or functions which aren't otherwise used (and therefore may not be
18688 reference_to_unused (tree
* tp
, int * walk_subtrees
,
18689 void * data ATTRIBUTE_UNUSED
)
18691 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
18692 *walk_subtrees
= 0;
18694 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
18695 && ! TREE_ASM_WRITTEN (*tp
))
18697 /* ??? The C++ FE emits debug information for using decls, so
18698 putting gcc_unreachable here falls over. See PR31899. For now
18699 be conservative. */
18700 else if (!symtab
->global_info_ready
&& VAR_OR_FUNCTION_DECL_P (*tp
))
18702 else if (VAR_P (*tp
))
18704 varpool_node
*node
= varpool_node::get (*tp
);
18705 if (!node
|| !node
->definition
)
18708 else if (TREE_CODE (*tp
) == FUNCTION_DECL
18709 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
18711 /* The call graph machinery must have finished analyzing,
18712 optimizing and gimplifying the CU by now.
18713 So if *TP has no call graph node associated
18714 to it, it means *TP will not be emitted. */
18715 if (!cgraph_node::get (*tp
))
18718 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
18724 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
18725 for use in a later add_const_value_attribute call. */
18728 rtl_for_decl_init (tree init
, tree type
)
18730 rtx rtl
= NULL_RTX
;
18734 /* If a variable is initialized with a string constant without embedded
18735 zeros, build CONST_STRING. */
18736 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
18738 tree enttype
= TREE_TYPE (type
);
18739 tree domain
= TYPE_DOMAIN (type
);
18740 machine_mode mode
= TYPE_MODE (enttype
);
18742 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
18744 && integer_zerop (TYPE_MIN_VALUE (domain
))
18745 && compare_tree_int (TYPE_MAX_VALUE (domain
),
18746 TREE_STRING_LENGTH (init
) - 1) == 0
18747 && ((size_t) TREE_STRING_LENGTH (init
)
18748 == strlen (TREE_STRING_POINTER (init
)) + 1))
18750 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
18751 ggc_strdup (TREE_STRING_POINTER (init
)));
18752 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
18753 MEM_READONLY_P (rtl
) = 1;
18756 /* Other aggregates, and complex values, could be represented using
18758 else if (AGGREGATE_TYPE_P (type
)
18759 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
18760 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
18761 || TREE_CODE (type
) == COMPLEX_TYPE
)
18763 /* Vectors only work if their mode is supported by the target.
18764 FIXME: generic vectors ought to work too. */
18765 else if (TREE_CODE (type
) == VECTOR_TYPE
18766 && !VECTOR_MODE_P (TYPE_MODE (type
)))
18768 /* If the initializer is something that we know will expand into an
18769 immediate RTL constant, expand it now. We must be careful not to
18770 reference variables which won't be output. */
18771 else if (initializer_constant_valid_p (init
, type
)
18772 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
18774 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
18776 if (TREE_CODE (type
) == VECTOR_TYPE
)
18777 switch (TREE_CODE (init
))
18782 if (TREE_CONSTANT (init
))
18784 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
18785 bool constant_p
= true;
18787 unsigned HOST_WIDE_INT ix
;
18789 /* Even when ctor is constant, it might contain non-*_CST
18790 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
18791 belong into VECTOR_CST nodes. */
18792 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
18793 if (!CONSTANT_CLASS_P (value
))
18795 constant_p
= false;
18801 init
= build_vector_from_ctor (type
, elts
);
18811 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
18813 /* If expand_expr returns a MEM, it wasn't immediate. */
18814 gcc_assert (!rtl
|| !MEM_P (rtl
));
18820 /* Generate RTL for the variable DECL to represent its location. */
18823 rtl_for_decl_location (tree decl
)
18827 /* Here we have to decide where we are going to say the parameter "lives"
18828 (as far as the debugger is concerned). We only have a couple of
18829 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
18831 DECL_RTL normally indicates where the parameter lives during most of the
18832 activation of the function. If optimization is enabled however, this
18833 could be either NULL or else a pseudo-reg. Both of those cases indicate
18834 that the parameter doesn't really live anywhere (as far as the code
18835 generation parts of GCC are concerned) during most of the function's
18836 activation. That will happen (for example) if the parameter is never
18837 referenced within the function.
18839 We could just generate a location descriptor here for all non-NULL
18840 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
18841 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
18842 where DECL_RTL is NULL or is a pseudo-reg.
18844 Note however that we can only get away with using DECL_INCOMING_RTL as
18845 a backup substitute for DECL_RTL in certain limited cases. In cases
18846 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
18847 we can be sure that the parameter was passed using the same type as it is
18848 declared to have within the function, and that its DECL_INCOMING_RTL
18849 points us to a place where a value of that type is passed.
18851 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
18852 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
18853 because in these cases DECL_INCOMING_RTL points us to a value of some
18854 type which is *different* from the type of the parameter itself. Thus,
18855 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
18856 such cases, the debugger would end up (for example) trying to fetch a
18857 `float' from a place which actually contains the first part of a
18858 `double'. That would lead to really incorrect and confusing
18859 output at debug-time.
18861 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
18862 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
18863 are a couple of exceptions however. On little-endian machines we can
18864 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
18865 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
18866 an integral type that is smaller than TREE_TYPE (decl). These cases arise
18867 when (on a little-endian machine) a non-prototyped function has a
18868 parameter declared to be of type `short' or `char'. In such cases,
18869 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
18870 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
18871 passed `int' value. If the debugger then uses that address to fetch
18872 a `short' or a `char' (on a little-endian machine) the result will be
18873 the correct data, so we allow for such exceptional cases below.
18875 Note that our goal here is to describe the place where the given formal
18876 parameter lives during most of the function's activation (i.e. between the
18877 end of the prologue and the start of the epilogue). We'll do that as best
18878 as we can. Note however that if the given formal parameter is modified
18879 sometime during the execution of the function, then a stack backtrace (at
18880 debug-time) will show the function as having been called with the *new*
18881 value rather than the value which was originally passed in. This happens
18882 rarely enough that it is not a major problem, but it *is* a problem, and
18883 I'd like to fix it.
18885 A future version of dwarf2out.c may generate two additional attributes for
18886 any given DW_TAG_formal_parameter DIE which will describe the "passed
18887 type" and the "passed location" for the given formal parameter in addition
18888 to the attributes we now generate to indicate the "declared type" and the
18889 "active location" for each parameter. This additional set of attributes
18890 could be used by debuggers for stack backtraces. Separately, note that
18891 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
18892 This happens (for example) for inlined-instances of inline function formal
18893 parameters which are never referenced. This really shouldn't be
18894 happening. All PARM_DECL nodes should get valid non-NULL
18895 DECL_INCOMING_RTL values. FIXME. */
18897 /* Use DECL_RTL as the "location" unless we find something better. */
18898 rtl
= DECL_RTL_IF_SET (decl
);
18900 /* When generating abstract instances, ignore everything except
18901 constants, symbols living in memory, and symbols living in
18902 fixed registers. */
18903 if (! reload_completed
)
18906 && (CONSTANT_P (rtl
)
18908 && CONSTANT_P (XEXP (rtl
, 0)))
18911 && TREE_STATIC (decl
))))
18913 rtl
= targetm
.delegitimize_address (rtl
);
18918 else if (TREE_CODE (decl
) == PARM_DECL
)
18920 if (rtl
== NULL_RTX
18921 || is_pseudo_reg (rtl
)
18923 && is_pseudo_reg (XEXP (rtl
, 0))
18924 && DECL_INCOMING_RTL (decl
)
18925 && MEM_P (DECL_INCOMING_RTL (decl
))
18926 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
18928 tree declared_type
= TREE_TYPE (decl
);
18929 tree passed_type
= DECL_ARG_TYPE (decl
);
18930 machine_mode dmode
= TYPE_MODE (declared_type
);
18931 machine_mode pmode
= TYPE_MODE (passed_type
);
18933 /* This decl represents a formal parameter which was optimized out.
18934 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
18935 all cases where (rtl == NULL_RTX) just below. */
18936 if (dmode
== pmode
)
18937 rtl
= DECL_INCOMING_RTL (decl
);
18938 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
18939 && SCALAR_INT_MODE_P (dmode
)
18940 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
18941 && DECL_INCOMING_RTL (decl
))
18943 rtx inc
= DECL_INCOMING_RTL (decl
);
18946 else if (MEM_P (inc
))
18948 if (BYTES_BIG_ENDIAN
)
18949 rtl
= adjust_address_nv (inc
, dmode
,
18950 GET_MODE_SIZE (pmode
)
18951 - GET_MODE_SIZE (dmode
));
18958 /* If the parm was passed in registers, but lives on the stack, then
18959 make a big endian correction if the mode of the type of the
18960 parameter is not the same as the mode of the rtl. */
18961 /* ??? This is the same series of checks that are made in dbxout.c before
18962 we reach the big endian correction code there. It isn't clear if all
18963 of these checks are necessary here, but keeping them all is the safe
18965 else if (MEM_P (rtl
)
18966 && XEXP (rtl
, 0) != const0_rtx
18967 && ! CONSTANT_P (XEXP (rtl
, 0))
18968 /* Not passed in memory. */
18969 && !MEM_P (DECL_INCOMING_RTL (decl
))
18970 /* Not passed by invisible reference. */
18971 && (!REG_P (XEXP (rtl
, 0))
18972 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
18973 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
18974 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
18975 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
18978 /* Big endian correction check. */
18979 && BYTES_BIG_ENDIAN
18980 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
18981 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
18984 machine_mode addr_mode
= get_address_mode (rtl
);
18985 int offset
= (UNITS_PER_WORD
18986 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
18988 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
18989 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
18992 else if (VAR_P (decl
)
18995 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
18996 && BYTES_BIG_ENDIAN
)
18998 machine_mode addr_mode
= get_address_mode (rtl
);
18999 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
19000 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
19002 /* If a variable is declared "register" yet is smaller than
19003 a register, then if we store the variable to memory, it
19004 looks like we're storing a register-sized value, when in
19005 fact we are not. We need to adjust the offset of the
19006 storage location to reflect the actual value's bytes,
19007 else gdb will not be able to display it. */
19009 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
19010 plus_constant (addr_mode
, XEXP (rtl
, 0),
19014 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
19015 and will have been substituted directly into all expressions that use it.
19016 C does not have such a concept, but C++ and other languages do. */
19017 if (!rtl
&& VAR_P (decl
) && DECL_INITIAL (decl
))
19018 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
19021 rtl
= targetm
.delegitimize_address (rtl
);
19023 /* If we don't look past the constant pool, we risk emitting a
19024 reference to a constant pool entry that isn't referenced from
19025 code, and thus is not emitted. */
19027 rtl
= avoid_constant_pool_reference (rtl
);
19029 /* Try harder to get a rtl. If this symbol ends up not being emitted
19030 in the current CU, resolve_addr will remove the expression referencing
19032 if (rtl
== NULL_RTX
19034 && !DECL_EXTERNAL (decl
)
19035 && TREE_STATIC (decl
)
19036 && DECL_NAME (decl
)
19037 && !DECL_HARD_REGISTER (decl
)
19038 && DECL_MODE (decl
) != VOIDmode
)
19040 rtl
= make_decl_rtl_for_debug (decl
);
19042 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
19043 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
19050 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
19051 returned. If so, the decl for the COMMON block is returned, and the
19052 value is the offset into the common block for the symbol. */
19055 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
19057 tree val_expr
, cvar
;
19059 HOST_WIDE_INT bitsize
, bitpos
;
19061 int unsignedp
, reversep
, volatilep
= 0;
19063 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
19064 it does not have a value (the offset into the common area), or if it
19065 is thread local (as opposed to global) then it isn't common, and shouldn't
19066 be handled as such. */
19068 || !TREE_STATIC (decl
)
19069 || !DECL_HAS_VALUE_EXPR_P (decl
)
19073 val_expr
= DECL_VALUE_EXPR (decl
);
19074 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
19077 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
19078 &unsignedp
, &reversep
, &volatilep
);
19080 if (cvar
== NULL_TREE
19082 || DECL_ARTIFICIAL (cvar
)
19083 || !TREE_PUBLIC (cvar
))
19087 if (offset
!= NULL
)
19089 if (!tree_fits_shwi_p (offset
))
19091 *value
= tree_to_shwi (offset
);
19094 *value
+= bitpos
/ BITS_PER_UNIT
;
19099 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
19100 data attribute for a variable or a parameter. We generate the
19101 DW_AT_const_value attribute only in those cases where the given variable
19102 or parameter does not have a true "location" either in memory or in a
19103 register. This can happen (for example) when a constant is passed as an
19104 actual argument in a call to an inline function. (It's possible that
19105 these things can crop up in other ways also.) Note that one type of
19106 constant value which can be passed into an inlined function is a constant
19107 pointer. This can happen for example if an actual argument in an inlined
19108 function call evaluates to a compile-time constant address.
19110 CACHE_P is true if it is worth caching the location list for DECL,
19111 so that future calls can reuse it rather than regenerate it from scratch.
19112 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
19113 since we will need to refer to them each time the function is inlined. */
19116 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
19119 dw_loc_list_ref list
;
19120 var_loc_list
*loc_list
;
19121 cached_dw_loc_list
*cache
;
19126 if (TREE_CODE (decl
) == ERROR_MARK
)
19129 if (get_AT (die
, DW_AT_location
)
19130 || get_AT (die
, DW_AT_const_value
))
19133 gcc_assert (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
19134 || TREE_CODE (decl
) == RESULT_DECL
);
19136 /* Try to get some constant RTL for this decl, and use that as the value of
19139 rtl
= rtl_for_decl_location (decl
);
19140 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19141 && add_const_value_attribute (die
, rtl
))
19144 /* See if we have single element location list that is equivalent to
19145 a constant value. That way we are better to use add_const_value_attribute
19146 rather than expanding constant value equivalent. */
19147 loc_list
= lookup_decl_loc (decl
);
19150 && loc_list
->first
->next
== NULL
19151 && NOTE_P (loc_list
->first
->loc
)
19152 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
19153 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
19155 struct var_loc_node
*node
;
19157 node
= loc_list
->first
;
19158 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
19159 if (GET_CODE (rtl
) == EXPR_LIST
)
19160 rtl
= XEXP (rtl
, 0);
19161 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19162 && add_const_value_attribute (die
, rtl
))
19165 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
19166 list several times. See if we've already cached the contents. */
19168 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
19172 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
19174 list
= cache
->loc_list
;
19178 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
19180 /* It is usually worth caching this result if the decl is from
19181 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
19182 if (cache_p
&& list
&& list
->dw_loc_next
)
19184 cached_dw_loc_list
**slot
19185 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
19188 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
19189 cache
->decl_id
= DECL_UID (decl
);
19190 cache
->loc_list
= list
;
19196 add_AT_location_description (die
, DW_AT_location
, list
);
19199 /* None of that worked, so it must not really have a location;
19200 try adding a constant value attribute from the DECL_INITIAL. */
19201 return tree_add_const_value_attribute_for_decl (die
, decl
);
19204 /* Helper function for tree_add_const_value_attribute. Natively encode
19205 initializer INIT into an array. Return true if successful. */
19208 native_encode_initializer (tree init
, unsigned char *array
, int size
)
19212 if (init
== NULL_TREE
)
19216 switch (TREE_CODE (init
))
19219 type
= TREE_TYPE (init
);
19220 if (TREE_CODE (type
) == ARRAY_TYPE
)
19222 tree enttype
= TREE_TYPE (type
);
19223 machine_mode mode
= TYPE_MODE (enttype
);
19225 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
19227 if (int_size_in_bytes (type
) != size
)
19229 if (size
> TREE_STRING_LENGTH (init
))
19231 memcpy (array
, TREE_STRING_POINTER (init
),
19232 TREE_STRING_LENGTH (init
));
19233 memset (array
+ TREE_STRING_LENGTH (init
),
19234 '\0', size
- TREE_STRING_LENGTH (init
));
19237 memcpy (array
, TREE_STRING_POINTER (init
), size
);
19242 type
= TREE_TYPE (init
);
19243 if (int_size_in_bytes (type
) != size
)
19245 if (TREE_CODE (type
) == ARRAY_TYPE
)
19247 HOST_WIDE_INT min_index
;
19248 unsigned HOST_WIDE_INT cnt
;
19249 int curpos
= 0, fieldsize
;
19250 constructor_elt
*ce
;
19252 if (TYPE_DOMAIN (type
) == NULL_TREE
19253 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
19256 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
19257 if (fieldsize
<= 0)
19260 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
19261 memset (array
, '\0', size
);
19262 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19264 tree val
= ce
->value
;
19265 tree index
= ce
->index
;
19267 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19268 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
19271 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
19276 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
19279 curpos
= pos
+ fieldsize
;
19280 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19282 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
19283 - tree_to_shwi (TREE_OPERAND (index
, 0));
19284 while (count
-- > 0)
19287 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
19288 curpos
+= fieldsize
;
19291 gcc_assert (curpos
<= size
);
19295 else if (TREE_CODE (type
) == RECORD_TYPE
19296 || TREE_CODE (type
) == UNION_TYPE
)
19298 tree field
= NULL_TREE
;
19299 unsigned HOST_WIDE_INT cnt
;
19300 constructor_elt
*ce
;
19302 if (int_size_in_bytes (type
) != size
)
19305 if (TREE_CODE (type
) == RECORD_TYPE
)
19306 field
= TYPE_FIELDS (type
);
19308 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19310 tree val
= ce
->value
;
19311 int pos
, fieldsize
;
19313 if (ce
->index
!= 0)
19319 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
19322 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
19323 && TYPE_DOMAIN (TREE_TYPE (field
))
19324 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
19326 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
19327 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
19329 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
19330 pos
= int_byte_position (field
);
19331 gcc_assert (pos
+ fieldsize
<= size
);
19332 if (val
&& fieldsize
!= 0
19333 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
19339 case VIEW_CONVERT_EXPR
:
19340 case NON_LVALUE_EXPR
:
19341 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
19343 return native_encode_expr (init
, array
, size
) == size
;
19347 /* Attach a DW_AT_const_value attribute to DIE. The value of the
19348 attribute is the const value T. */
19351 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
19354 tree type
= TREE_TYPE (t
);
19357 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
19361 gcc_assert (!DECL_P (init
));
19365 rtl
= rtl_for_decl_init (init
, type
);
19367 return add_const_value_attribute (die
, rtl
);
19369 /* If the host and target are sane, try harder. */
19370 if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
19371 && initializer_constant_valid_p (init
, type
))
19373 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
19374 if (size
> 0 && (int) size
== size
)
19376 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
19378 if (native_encode_initializer (init
, array
, size
))
19380 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
19389 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
19390 attribute is the const value of T, where T is an integral constant
19391 variable with static storage duration
19392 (so it can't be a PARM_DECL or a RESULT_DECL). */
19395 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
19399 || (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
19400 || (VAR_P (decl
) && !TREE_STATIC (decl
)))
19403 if (TREE_READONLY (decl
)
19404 && ! TREE_THIS_VOLATILE (decl
)
19405 && DECL_INITIAL (decl
))
19410 /* Don't add DW_AT_const_value if abstract origin already has one. */
19411 if (get_AT (var_die
, DW_AT_const_value
))
19414 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
19417 /* Convert the CFI instructions for the current function into a
19418 location list. This is used for DW_AT_frame_base when we targeting
19419 a dwarf2 consumer that does not support the dwarf3
19420 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
19423 static dw_loc_list_ref
19424 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
19428 dw_loc_list_ref list
, *list_tail
;
19430 dw_cfa_location last_cfa
, next_cfa
;
19431 const char *start_label
, *last_label
, *section
;
19432 dw_cfa_location remember
;
19435 gcc_assert (fde
!= NULL
);
19437 section
= secname_for_decl (current_function_decl
);
19441 memset (&next_cfa
, 0, sizeof (next_cfa
));
19442 next_cfa
.reg
= INVALID_REGNUM
;
19443 remember
= next_cfa
;
19445 start_label
= fde
->dw_fde_begin
;
19447 /* ??? Bald assumption that the CIE opcode list does not contain
19448 advance opcodes. */
19449 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
19450 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19452 last_cfa
= next_cfa
;
19453 last_label
= start_label
;
19455 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
19457 /* If the first partition contained no CFI adjustments, the
19458 CIE opcodes apply to the whole first partition. */
19459 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19460 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
19461 list_tail
=&(*list_tail
)->dw_loc_next
;
19462 start_label
= last_label
= fde
->dw_fde_second_begin
;
19465 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
19467 switch (cfi
->dw_cfi_opc
)
19469 case DW_CFA_set_loc
:
19470 case DW_CFA_advance_loc1
:
19471 case DW_CFA_advance_loc2
:
19472 case DW_CFA_advance_loc4
:
19473 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19475 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19476 start_label
, last_label
, section
);
19478 list_tail
= &(*list_tail
)->dw_loc_next
;
19479 last_cfa
= next_cfa
;
19480 start_label
= last_label
;
19482 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
19485 case DW_CFA_advance_loc
:
19486 /* The encoding is complex enough that we should never emit this. */
19487 gcc_unreachable ();
19490 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19493 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
19495 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19497 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19498 start_label
, last_label
, section
);
19500 list_tail
= &(*list_tail
)->dw_loc_next
;
19501 last_cfa
= next_cfa
;
19502 start_label
= last_label
;
19504 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19505 start_label
, fde
->dw_fde_end
, section
);
19506 list_tail
= &(*list_tail
)->dw_loc_next
;
19507 start_label
= last_label
= fde
->dw_fde_second_begin
;
19511 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19513 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19514 start_label
, last_label
, section
);
19515 list_tail
= &(*list_tail
)->dw_loc_next
;
19516 start_label
= last_label
;
19519 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
19521 fde
->dw_fde_second_begin
19522 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
19525 if (list
&& list
->dw_loc_next
)
19531 /* Compute a displacement from the "steady-state frame pointer" to the
19532 frame base (often the same as the CFA), and store it in
19533 frame_pointer_fb_offset. OFFSET is added to the displacement
19534 before the latter is negated. */
19537 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
19541 #ifdef FRAME_POINTER_CFA_OFFSET
19542 reg
= frame_pointer_rtx
;
19543 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
19545 reg
= arg_pointer_rtx
;
19546 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
19549 elim
= (ira_use_lra_p
19550 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
19551 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
19552 if (GET_CODE (elim
) == PLUS
)
19554 offset
+= INTVAL (XEXP (elim
, 1));
19555 elim
= XEXP (elim
, 0);
19558 frame_pointer_fb_offset
= -offset
;
19560 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
19561 in which to eliminate. This is because it's stack pointer isn't
19562 directly accessible as a register within the ISA. To work around
19563 this, assume that while we cannot provide a proper value for
19564 frame_pointer_fb_offset, we won't need one either. */
19565 frame_pointer_fb_offset_valid
19566 = ((SUPPORTS_STACK_ALIGNMENT
19567 && (elim
== hard_frame_pointer_rtx
19568 || elim
== stack_pointer_rtx
))
19569 || elim
== (frame_pointer_needed
19570 ? hard_frame_pointer_rtx
19571 : stack_pointer_rtx
));
19574 /* Generate a DW_AT_name attribute given some string value to be included as
19575 the value of the attribute. */
19578 add_name_attribute (dw_die_ref die
, const char *name_string
)
19580 if (name_string
!= NULL
&& *name_string
!= 0)
19582 if (demangle_name_func
)
19583 name_string
= (*demangle_name_func
) (name_string
);
19585 add_AT_string (die
, DW_AT_name
, name_string
);
19589 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
19590 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
19591 of TYPE accordingly.
19593 ??? This is a temporary measure until after we're able to generate
19594 regular DWARF for the complex Ada type system. */
19597 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
19598 dw_die_ref context_die
)
19601 dw_die_ref dtype_die
;
19603 if (!lang_hooks
.types
.descriptive_type
)
19606 dtype
= lang_hooks
.types
.descriptive_type (type
);
19610 dtype_die
= lookup_type_die (dtype
);
19613 gen_type_die (dtype
, context_die
);
19614 dtype_die
= lookup_type_die (dtype
);
19615 gcc_assert (dtype_die
);
19618 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
19621 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
19623 static const char *
19624 comp_dir_string (void)
19628 static const char *cached_wd
= NULL
;
19630 if (cached_wd
!= NULL
)
19633 wd
= get_src_pwd ();
19637 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
19641 wdlen
= strlen (wd
);
19642 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
19644 wd1
[wdlen
] = DIR_SEPARATOR
;
19645 wd1
[wdlen
+ 1] = 0;
19649 cached_wd
= remap_debug_filename (wd
);
19653 /* Generate a DW_AT_comp_dir attribute for DIE. */
19656 add_comp_dir_attribute (dw_die_ref die
)
19658 const char * wd
= comp_dir_string ();
19660 add_AT_string (die
, DW_AT_comp_dir
, wd
);
19663 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
19664 pointer computation, ...), output a representation for that bound according
19665 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
19666 loc_list_from_tree for the meaning of CONTEXT. */
19669 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
19670 int forms
, struct loc_descr_context
*context
)
19672 dw_die_ref context_die
, decl_die
;
19673 dw_loc_list_ref list
;
19674 bool strip_conversions
= true;
19675 bool placeholder_seen
= false;
19677 while (strip_conversions
)
19678 switch (TREE_CODE (value
))
19685 case VIEW_CONVERT_EXPR
:
19686 value
= TREE_OPERAND (value
, 0);
19690 strip_conversions
= false;
19694 /* If possible and permitted, output the attribute as a constant. */
19695 if ((forms
& dw_scalar_form_constant
) != 0
19696 && TREE_CODE (value
) == INTEGER_CST
)
19698 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
19700 /* If HOST_WIDE_INT is big enough then represent the bound as
19701 a constant value. We need to choose a form based on
19702 whether the type is signed or unsigned. We cannot just
19703 call add_AT_unsigned if the value itself is positive
19704 (add_AT_unsigned might add the unsigned value encoded as
19705 DW_FORM_data[1248]). Some DWARF consumers will lookup the
19706 bounds type and then sign extend any unsigned values found
19707 for signed types. This is needed only for
19708 DW_AT_{lower,upper}_bound, since for most other attributes,
19709 consumers will treat DW_FORM_data[1248] as unsigned values,
19710 regardless of the underlying type. */
19711 if (prec
<= HOST_BITS_PER_WIDE_INT
19712 || tree_fits_uhwi_p (value
))
19714 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
19715 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
19717 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
19720 /* Otherwise represent the bound as an unsigned value with
19721 the precision of its type. The precision and signedness
19722 of the type will be necessary to re-interpret it
19724 add_AT_wide (die
, attr
, value
);
19728 /* Otherwise, if it's possible and permitted too, output a reference to
19730 if ((forms
& dw_scalar_form_reference
) != 0)
19732 tree decl
= NULL_TREE
;
19734 /* Some type attributes reference an outer type. For instance, the upper
19735 bound of an array may reference an embedding record (this happens in
19737 if (TREE_CODE (value
) == COMPONENT_REF
19738 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
19739 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
19740 decl
= TREE_OPERAND (value
, 1);
19742 else if (VAR_P (value
)
19743 || TREE_CODE (value
) == PARM_DECL
19744 || TREE_CODE (value
) == RESULT_DECL
)
19747 if (decl
!= NULL_TREE
)
19749 dw_die_ref decl_die
= lookup_decl_die (decl
);
19751 /* ??? Can this happen, or should the variable have been bound
19752 first? Probably it can, since I imagine that we try to create
19753 the types of parameters in the order in which they exist in
19754 the list, and won't have created a forward reference to a
19755 later parameter. */
19756 if (decl_die
!= NULL
)
19758 add_AT_die_ref (die
, attr
, decl_die
);
19764 /* Last chance: try to create a stack operation procedure to evaluate the
19765 value. Do nothing if even that is not possible or permitted. */
19766 if ((forms
& dw_scalar_form_exprloc
) == 0)
19769 list
= loc_list_from_tree (value
, 2, context
);
19770 if (context
&& context
->placeholder_arg
)
19772 placeholder_seen
= context
->placeholder_seen
;
19773 context
->placeholder_seen
= false;
19775 if (list
== NULL
|| single_element_loc_list_p (list
))
19777 /* If this attribute is not a reference nor constant, it is
19778 a DWARF expression rather than location description. For that
19779 loc_list_from_tree (value, 0, &context) is needed. */
19780 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
19781 if (list2
&& single_element_loc_list_p (list2
))
19783 if (placeholder_seen
)
19785 struct dwarf_procedure_info dpi
;
19786 dpi
.fndecl
= NULL_TREE
;
19787 dpi
.args_count
= 1;
19788 if (!resolve_args_picking (list2
->expr
, 1, &dpi
))
19791 add_AT_loc (die
, attr
, list2
->expr
);
19796 /* If that failed to give a single element location list, fall back to
19797 outputting this as a reference... still if permitted. */
19799 || (forms
& dw_scalar_form_reference
) == 0
19800 || placeholder_seen
)
19803 if (current_function_decl
== 0)
19804 context_die
= comp_unit_die ();
19806 context_die
= lookup_decl_die (current_function_decl
);
19808 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
19809 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19810 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
19812 add_AT_location_description (decl_die
, DW_AT_location
, list
);
19813 add_AT_die_ref (die
, attr
, decl_die
);
19816 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
19820 lower_bound_default (void)
19822 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
19828 case DW_LANG_C_plus_plus
:
19829 case DW_LANG_C_plus_plus_11
:
19830 case DW_LANG_C_plus_plus_14
:
19832 case DW_LANG_ObjC_plus_plus
:
19835 case DW_LANG_Fortran77
:
19836 case DW_LANG_Fortran90
:
19837 case DW_LANG_Fortran95
:
19838 case DW_LANG_Fortran03
:
19839 case DW_LANG_Fortran08
:
19843 case DW_LANG_Python
:
19844 return dwarf_version
>= 4 ? 0 : -1;
19845 case DW_LANG_Ada95
:
19846 case DW_LANG_Ada83
:
19847 case DW_LANG_Cobol74
:
19848 case DW_LANG_Cobol85
:
19849 case DW_LANG_Pascal83
:
19850 case DW_LANG_Modula2
:
19852 return dwarf_version
>= 4 ? 1 : -1;
19858 /* Given a tree node describing an array bound (either lower or upper) output
19859 a representation for that bound. */
19862 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
19863 tree bound
, struct loc_descr_context
*context
)
19868 switch (TREE_CODE (bound
))
19870 /* Strip all conversions. */
19872 case VIEW_CONVERT_EXPR
:
19873 bound
= TREE_OPERAND (bound
, 0);
19876 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
19877 are even omitted when they are the default. */
19879 /* If the value for this bound is the default one, we can even omit the
19881 if (bound_attr
== DW_AT_lower_bound
19882 && tree_fits_shwi_p (bound
)
19883 && (dflt
= lower_bound_default ()) != -1
19884 && tree_to_shwi (bound
) == dflt
)
19890 /* Because of the complex interaction there can be with other GNAT
19891 encodings, GDB isn't ready yet to handle proper DWARF description
19892 for self-referencial subrange bounds: let GNAT encodings do the
19893 magic in such a case. */
19895 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
19896 && contains_placeholder_p (bound
))
19899 add_scalar_info (subrange_die
, bound_attr
, bound
,
19900 dw_scalar_form_constant
19901 | dw_scalar_form_exprloc
19902 | dw_scalar_form_reference
,
19908 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
19909 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
19910 Note that the block of subscript information for an array type also
19911 includes information about the element type of the given array type.
19913 This function reuses previously set type and bound information if
19917 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
19919 unsigned dimension_number
;
19921 dw_die_ref child
= type_die
->die_child
;
19923 for (dimension_number
= 0;
19924 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
19925 type
= TREE_TYPE (type
), dimension_number
++)
19927 tree domain
= TYPE_DOMAIN (type
);
19929 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
19932 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
19933 and (in GNU C only) variable bounds. Handle all three forms
19936 /* Find and reuse a previously generated DW_TAG_subrange_type if
19939 For multi-dimensional arrays, as we iterate through the
19940 various dimensions in the enclosing for loop above, we also
19941 iterate through the DIE children and pick at each
19942 DW_TAG_subrange_type previously generated (if available).
19943 Each child DW_TAG_subrange_type DIE describes the range of
19944 the current dimension. At this point we should have as many
19945 DW_TAG_subrange_type's as we have dimensions in the
19947 dw_die_ref subrange_die
= NULL
;
19951 child
= child
->die_sib
;
19952 if (child
->die_tag
== DW_TAG_subrange_type
)
19953 subrange_die
= child
;
19954 if (child
== type_die
->die_child
)
19956 /* If we wrapped around, stop looking next time. */
19960 if (child
->die_tag
== DW_TAG_subrange_type
)
19964 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
19968 /* We have an array type with specified bounds. */
19969 lower
= TYPE_MIN_VALUE (domain
);
19970 upper
= TYPE_MAX_VALUE (domain
);
19972 /* Define the index type. */
19973 if (TREE_TYPE (domain
)
19974 && !get_AT (subrange_die
, DW_AT_type
))
19976 /* ??? This is probably an Ada unnamed subrange type. Ignore the
19977 TREE_TYPE field. We can't emit debug info for this
19978 because it is an unnamed integral type. */
19979 if (TREE_CODE (domain
) == INTEGER_TYPE
19980 && TYPE_NAME (domain
) == NULL_TREE
19981 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
19982 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
19985 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
19986 TYPE_UNQUALIFIED
, false, type_die
);
19989 /* ??? If upper is NULL, the array has unspecified length,
19990 but it does have a lower bound. This happens with Fortran
19992 Since the debugger is definitely going to need to know N
19993 to produce useful results, go ahead and output the lower
19994 bound solo, and hope the debugger can cope. */
19996 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
19997 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
19998 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
19999 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
20002 /* Otherwise we have an array type with an unspecified length. The
20003 DWARF-2 spec does not say how to handle this; let's just leave out the
20008 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
20011 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
20013 dw_die_ref decl_die
;
20014 HOST_WIDE_INT size
;
20015 dw_loc_descr_ref size_expr
= NULL
;
20017 switch (TREE_CODE (tree_node
))
20022 case ENUMERAL_TYPE
:
20025 case QUAL_UNION_TYPE
:
20026 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
20027 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
20029 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
20032 size_expr
= type_byte_size (tree_node
, &size
);
20035 /* For a data member of a struct or union, the DW_AT_byte_size is
20036 generally given as the number of bytes normally allocated for an
20037 object of the *declared* type of the member itself. This is true
20038 even for bit-fields. */
20039 size
= int_size_in_bytes (field_type (tree_node
));
20042 gcc_unreachable ();
20045 /* Support for dynamically-sized objects was introduced by DWARFv3.
20046 At the moment, GDB does not handle variable byte sizes very well,
20048 if ((dwarf_version
>= 3 || !dwarf_strict
)
20049 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
20050 && size_expr
!= NULL
)
20051 add_AT_loc (die
, DW_AT_byte_size
, size_expr
);
20053 /* Note that `size' might be -1 when we get to this point. If it is, that
20054 indicates that the byte size of the entity in question is variable and
20055 that we could not generate a DWARF expression that computes it. */
20057 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
20060 /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
20064 add_alignment_attribute (dw_die_ref die
, tree tree_node
)
20066 if (dwarf_version
< 5 && dwarf_strict
)
20071 if (DECL_P (tree_node
))
20073 if (!DECL_USER_ALIGN (tree_node
))
20076 align
= DECL_ALIGN_UNIT (tree_node
);
20078 else if (TYPE_P (tree_node
))
20080 if (!TYPE_USER_ALIGN (tree_node
))
20083 align
= TYPE_ALIGN_UNIT (tree_node
);
20086 gcc_unreachable ();
20088 add_AT_unsigned (die
, DW_AT_alignment
, align
);
20091 /* For a FIELD_DECL node which represents a bit-field, output an attribute
20092 which specifies the distance in bits from the highest order bit of the
20093 "containing object" for the bit-field to the highest order bit of the
20096 For any given bit-field, the "containing object" is a hypothetical object
20097 (of some integral or enum type) within which the given bit-field lives. The
20098 type of this hypothetical "containing object" is always the same as the
20099 declared type of the individual bit-field itself. The determination of the
20100 exact location of the "containing object" for a bit-field is rather
20101 complicated. It's handled by the `field_byte_offset' function (above).
20103 CTX is required: see the comment for VLR_CONTEXT.
20105 Note that it is the size (in bytes) of the hypothetical "containing object"
20106 which will be given in the DW_AT_byte_size attribute for this bit-field.
20107 (See `byte_size_attribute' above). */
20110 add_bit_offset_attribute (dw_die_ref die
, tree decl
, struct vlr_context
*ctx
)
20112 HOST_WIDE_INT object_offset_in_bytes
;
20113 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
20114 HOST_WIDE_INT bitpos_int
;
20115 HOST_WIDE_INT highest_order_object_bit_offset
;
20116 HOST_WIDE_INT highest_order_field_bit_offset
;
20117 HOST_WIDE_INT bit_offset
;
20119 field_byte_offset (decl
, ctx
, &object_offset_in_bytes
);
20121 /* Must be a field and a bit field. */
20122 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
20124 /* We can't yet handle bit-fields whose offsets are variable, so if we
20125 encounter such things, just return without generating any attribute
20126 whatsoever. Likewise for variable or too large size. */
20127 if (! tree_fits_shwi_p (bit_position (decl
))
20128 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
20131 bitpos_int
= int_bit_position (decl
);
20133 /* Note that the bit offset is always the distance (in bits) from the
20134 highest-order bit of the "containing object" to the highest-order bit of
20135 the bit-field itself. Since the "high-order end" of any object or field
20136 is different on big-endian and little-endian machines, the computation
20137 below must take account of these differences. */
20138 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
20139 highest_order_field_bit_offset
= bitpos_int
;
20141 if (! BYTES_BIG_ENDIAN
)
20143 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
20144 highest_order_object_bit_offset
+=
20145 simple_type_size_in_bits (original_type
);
20149 = (! BYTES_BIG_ENDIAN
20150 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
20151 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
20153 if (bit_offset
< 0)
20154 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
20156 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
20159 /* For a FIELD_DECL node which represents a bit field, output an attribute
20160 which specifies the length in bits of the given field. */
20163 add_bit_size_attribute (dw_die_ref die
, tree decl
)
20165 /* Must be a field and a bit field. */
20166 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
20167 && DECL_BIT_FIELD_TYPE (decl
));
20169 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
20170 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
20173 /* If the compiled language is ANSI C, then add a 'prototyped'
20174 attribute, if arg types are given for the parameters of a function. */
20177 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
20179 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
20186 if (prototype_p (func_type
))
20187 add_AT_flag (die
, DW_AT_prototyped
, 1);
20194 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
20195 by looking in the type declaration, the object declaration equate table or
20196 the block mapping. */
20198 static inline dw_die_ref
20199 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
20201 dw_die_ref origin_die
= NULL
;
20203 if (TREE_CODE (origin
) != FUNCTION_DECL
20204 && TREE_CODE (origin
) != BLOCK
)
20206 /* We may have gotten separated from the block for the inlined
20207 function, if we're in an exception handler or some such; make
20208 sure that the abstract function has been written out.
20210 Doing this for nested functions is wrong, however; functions are
20211 distinct units, and our context might not even be inline. */
20215 fn
= TYPE_STUB_DECL (fn
);
20217 fn
= decl_function_context (fn
);
20219 dwarf2out_abstract_function (fn
);
20222 if (DECL_P (origin
))
20223 origin_die
= lookup_decl_die (origin
);
20224 else if (TYPE_P (origin
))
20225 origin_die
= lookup_type_die (origin
);
20226 else if (TREE_CODE (origin
) == BLOCK
)
20227 origin_die
= BLOCK_DIE (origin
);
20229 /* XXX: Functions that are never lowered don't always have correct block
20230 trees (in the case of java, they simply have no block tree, in some other
20231 languages). For these functions, there is nothing we can really do to
20232 output correct debug info for inlined functions in all cases. Rather
20233 than die, we'll just produce deficient debug info now, in that we will
20234 have variables without a proper abstract origin. In the future, when all
20235 functions are lowered, we should re-add a gcc_assert (origin_die)
20239 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
20243 /* We do not currently support the pure_virtual attribute. */
20246 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
20248 if (DECL_VINDEX (func_decl
))
20250 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20252 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
20253 add_AT_loc (die
, DW_AT_vtable_elem_location
,
20254 new_loc_descr (DW_OP_constu
,
20255 tree_to_shwi (DECL_VINDEX (func_decl
)),
20258 /* GNU extension: Record what type this method came from originally. */
20259 if (debug_info_level
> DINFO_LEVEL_TERSE
20260 && DECL_CONTEXT (func_decl
))
20261 add_AT_die_ref (die
, DW_AT_containing_type
,
20262 lookup_type_die (DECL_CONTEXT (func_decl
)));
20266 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
20267 given decl. This used to be a vendor extension until after DWARF 4
20268 standardized it. */
20271 add_linkage_attr (dw_die_ref die
, tree decl
)
20273 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
20275 /* Mimic what assemble_name_raw does with a leading '*'. */
20276 if (name
[0] == '*')
20279 if (dwarf_version
>= 4)
20280 add_AT_string (die
, DW_AT_linkage_name
, name
);
20282 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
20285 /* Add source coordinate attributes for the given decl. */
20288 add_src_coords_attributes (dw_die_ref die
, tree decl
)
20290 expanded_location s
;
20292 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
20294 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
20295 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
20296 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
20297 if (debug_column_info
&& s
.column
)
20298 add_AT_unsigned (die
, DW_AT_decl_column
, s
.column
);
20301 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
20304 add_linkage_name_raw (dw_die_ref die
, tree decl
)
20306 /* Defer until we have an assembler name set. */
20307 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
20309 limbo_die_node
*asm_name
;
20311 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
20312 asm_name
->die
= die
;
20313 asm_name
->created_for
= decl
;
20314 asm_name
->next
= deferred_asm_name
;
20315 deferred_asm_name
= asm_name
;
20317 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
20318 add_linkage_attr (die
, decl
);
20321 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
20324 add_linkage_name (dw_die_ref die
, tree decl
)
20326 if (debug_info_level
> DINFO_LEVEL_NONE
20327 && VAR_OR_FUNCTION_DECL_P (decl
)
20328 && TREE_PUBLIC (decl
)
20329 && !(VAR_P (decl
) && DECL_REGISTER (decl
))
20330 && die
->die_tag
!= DW_TAG_member
)
20331 add_linkage_name_raw (die
, decl
);
20334 /* Add a DW_AT_name attribute and source coordinate attribute for the
20335 given decl, but only if it actually has a name. */
20338 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
,
20339 bool no_linkage_name
)
20343 decl_name
= DECL_NAME (decl
);
20344 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
20346 const char *name
= dwarf2_name (decl
, 0);
20348 add_name_attribute (die
, name
);
20349 if (! DECL_ARTIFICIAL (decl
))
20350 add_src_coords_attributes (die
, decl
);
20352 if (!no_linkage_name
)
20353 add_linkage_name (die
, decl
);
20356 #ifdef VMS_DEBUGGING_INFO
20357 /* Get the function's name, as described by its RTL. This may be different
20358 from the DECL_NAME name used in the source file. */
20359 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
20361 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
20362 XEXP (DECL_RTL (decl
), 0), false);
20363 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
20365 #endif /* VMS_DEBUGGING_INFO */
20368 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
20371 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
20375 attr
.dw_attr
= DW_AT_discr_value
;
20376 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
20377 attr
.dw_attr_val
.val_entry
= NULL
;
20378 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
20380 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
20382 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
20383 add_dwarf_attr (die
, &attr
);
20386 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
20389 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
20393 attr
.dw_attr
= DW_AT_discr_list
;
20394 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
20395 attr
.dw_attr_val
.val_entry
= NULL
;
20396 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
20397 add_dwarf_attr (die
, &attr
);
20400 static inline dw_discr_list_ref
20401 AT_discr_list (dw_attr_node
*attr
)
20403 return attr
->dw_attr_val
.v
.val_discr_list
;
20406 #ifdef VMS_DEBUGGING_INFO
20407 /* Output the debug main pointer die for VMS */
20410 dwarf2out_vms_debug_main_pointer (void)
20412 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20415 /* Allocate the VMS debug main subprogram die. */
20416 die
= ggc_cleared_alloc
<die_node
> ();
20417 die
->die_tag
= DW_TAG_subprogram
;
20418 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
20419 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
20420 current_function_funcdef_no
);
20421 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
20423 /* Make it the first child of comp_unit_die (). */
20424 die
->die_parent
= comp_unit_die ();
20425 if (comp_unit_die ()->die_child
)
20427 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
20428 comp_unit_die ()->die_child
->die_sib
= die
;
20432 die
->die_sib
= die
;
20433 comp_unit_die ()->die_child
= die
;
20436 #endif /* VMS_DEBUGGING_INFO */
20438 /* Push a new declaration scope. */
20441 push_decl_scope (tree scope
)
20443 vec_safe_push (decl_scope_table
, scope
);
20446 /* Pop a declaration scope. */
20449 pop_decl_scope (void)
20451 decl_scope_table
->pop ();
20454 /* walk_tree helper function for uses_local_type, below. */
20457 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
20460 *walk_subtrees
= 0;
20463 tree name
= TYPE_NAME (*tp
);
20464 if (name
&& DECL_P (name
) && decl_function_context (name
))
20470 /* If TYPE involves a function-local type (including a local typedef to a
20471 non-local type), returns that type; otherwise returns NULL_TREE. */
20474 uses_local_type (tree type
)
20476 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
20480 /* Return the DIE for the scope that immediately contains this type.
20481 Non-named types that do not involve a function-local type get global
20482 scope. Named types nested in namespaces or other types get their
20483 containing scope. All other types (i.e. function-local named types) get
20484 the current active scope. */
20487 scope_die_for (tree t
, dw_die_ref context_die
)
20489 dw_die_ref scope_die
= NULL
;
20490 tree containing_scope
;
20492 /* Non-types always go in the current scope. */
20493 gcc_assert (TYPE_P (t
));
20495 /* Use the scope of the typedef, rather than the scope of the type
20497 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
20498 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
20500 containing_scope
= TYPE_CONTEXT (t
);
20502 /* Use the containing namespace if there is one. */
20503 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
20505 if (context_die
== lookup_decl_die (containing_scope
))
20507 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20508 context_die
= get_context_die (containing_scope
);
20510 containing_scope
= NULL_TREE
;
20513 /* Ignore function type "scopes" from the C frontend. They mean that
20514 a tagged type is local to a parmlist of a function declarator, but
20515 that isn't useful to DWARF. */
20516 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
20517 containing_scope
= NULL_TREE
;
20519 if (SCOPE_FILE_SCOPE_P (containing_scope
))
20521 /* If T uses a local type keep it local as well, to avoid references
20522 to function-local DIEs from outside the function. */
20523 if (current_function_decl
&& uses_local_type (t
))
20524 scope_die
= context_die
;
20526 scope_die
= comp_unit_die ();
20528 else if (TYPE_P (containing_scope
))
20530 /* For types, we can just look up the appropriate DIE. */
20531 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20532 scope_die
= get_context_die (containing_scope
);
20535 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
20536 if (scope_die
== NULL
)
20537 scope_die
= comp_unit_die ();
20541 scope_die
= context_die
;
20546 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
20549 local_scope_p (dw_die_ref context_die
)
20551 for (; context_die
; context_die
= context_die
->die_parent
)
20552 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
20553 || context_die
->die_tag
== DW_TAG_subprogram
)
20559 /* Returns nonzero if CONTEXT_DIE is a class. */
20562 class_scope_p (dw_die_ref context_die
)
20564 return (context_die
20565 && (context_die
->die_tag
== DW_TAG_structure_type
20566 || context_die
->die_tag
== DW_TAG_class_type
20567 || context_die
->die_tag
== DW_TAG_interface_type
20568 || context_die
->die_tag
== DW_TAG_union_type
));
20571 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
20572 whether or not to treat a DIE in this context as a declaration. */
20575 class_or_namespace_scope_p (dw_die_ref context_die
)
20577 return (class_scope_p (context_die
)
20578 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
20581 /* Many forms of DIEs require a "type description" attribute. This
20582 routine locates the proper "type descriptor" die for the type given
20583 by 'type' plus any additional qualifiers given by 'cv_quals', and
20584 adds a DW_AT_type attribute below the given die. */
20587 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
20588 bool reverse
, dw_die_ref context_die
)
20590 enum tree_code code
= TREE_CODE (type
);
20591 dw_die_ref type_die
= NULL
;
20593 /* ??? If this type is an unnamed subrange type of an integral, floating-point
20594 or fixed-point type, use the inner type. This is because we have no
20595 support for unnamed types in base_type_die. This can happen if this is
20596 an Ada subrange type. Correct solution is emit a subrange type die. */
20597 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
20598 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
20599 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
20601 if (code
== ERROR_MARK
20602 /* Handle a special case. For functions whose return type is void, we
20603 generate *no* type attribute. (Note that no object may have type
20604 `void', so this only applies to function return types). */
20605 || code
== VOID_TYPE
)
20608 type_die
= modified_type_die (type
,
20609 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
20613 if (type_die
!= NULL
)
20614 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
20617 /* Given an object die, add the calling convention attribute for the
20618 function call type. */
20620 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
20622 enum dwarf_calling_convention value
= DW_CC_normal
;
20624 value
= ((enum dwarf_calling_convention
)
20625 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
20628 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
20630 /* DWARF 2 doesn't provide a way to identify a program's source-level
20631 entry point. DW_AT_calling_convention attributes are only meant
20632 to describe functions' calling conventions. However, lacking a
20633 better way to signal the Fortran main program, we used this for
20634 a long time, following existing custom. Now, DWARF 4 has
20635 DW_AT_main_subprogram, which we add below, but some tools still
20636 rely on the old way, which we thus keep. */
20637 value
= DW_CC_program
;
20639 if (dwarf_version
>= 4 || !dwarf_strict
)
20640 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
20643 /* Only add the attribute if the backend requests it, and
20644 is not DW_CC_normal. */
20645 if (value
&& (value
!= DW_CC_normal
))
20646 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
20649 /* Given a tree pointer to a struct, class, union, or enum type node, return
20650 a pointer to the (string) tag name for the given type, or zero if the type
20651 was declared without a tag. */
20653 static const char *
20654 type_tag (const_tree type
)
20656 const char *name
= 0;
20658 if (TYPE_NAME (type
) != 0)
20662 /* Find the IDENTIFIER_NODE for the type name. */
20663 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
20664 && !TYPE_NAMELESS (type
))
20665 t
= TYPE_NAME (type
);
20667 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
20668 a TYPE_DECL node, regardless of whether or not a `typedef' was
20670 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20671 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
20673 /* We want to be extra verbose. Don't call dwarf_name if
20674 DECL_NAME isn't set. The default hook for decl_printable_name
20675 doesn't like that, and in this context it's correct to return
20676 0, instead of "<anonymous>" or the like. */
20677 if (DECL_NAME (TYPE_NAME (type
))
20678 && !DECL_NAMELESS (TYPE_NAME (type
)))
20679 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
20682 /* Now get the name as a string, or invent one. */
20683 if (!name
&& t
!= 0)
20684 name
= IDENTIFIER_POINTER (t
);
20687 return (name
== 0 || *name
== '\0') ? 0 : name
;
20690 /* Return the type associated with a data member, make a special check
20691 for bit field types. */
20694 member_declared_type (const_tree member
)
20696 return (DECL_BIT_FIELD_TYPE (member
)
20697 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
20700 /* Get the decl's label, as described by its RTL. This may be different
20701 from the DECL_NAME name used in the source file. */
20704 static const char *
20705 decl_start_label (tree decl
)
20708 const char *fnname
;
20710 x
= DECL_RTL (decl
);
20711 gcc_assert (MEM_P (x
));
20714 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
20716 fnname
= XSTR (x
, 0);
20721 /* For variable-length arrays that have been previously generated, but
20722 may be incomplete due to missing subscript info, fill the subscript
20723 info. Return TRUE if this is one of those cases. */
20725 fill_variable_array_bounds (tree type
)
20727 if (TREE_ASM_WRITTEN (type
)
20728 && TREE_CODE (type
) == ARRAY_TYPE
20729 && variably_modified_type_p (type
, NULL
))
20731 dw_die_ref array_die
= lookup_type_die (type
);
20734 add_subscript_info (array_die
, type
, !is_ada ());
20740 /* These routines generate the internal representation of the DIE's for
20741 the compilation unit. Debugging information is collected by walking
20742 the declaration trees passed in from dwarf2out_decl(). */
20745 gen_array_type_die (tree type
, dw_die_ref context_die
)
20747 dw_die_ref array_die
;
20749 /* GNU compilers represent multidimensional array types as sequences of one
20750 dimensional array types whose element types are themselves array types.
20751 We sometimes squish that down to a single array_type DIE with multiple
20752 subscripts in the Dwarf debugging info. The draft Dwarf specification
20753 say that we are allowed to do this kind of compression in C, because
20754 there is no difference between an array of arrays and a multidimensional
20755 array. We don't do this for Ada to remain as close as possible to the
20756 actual representation, which is especially important against the language
20757 flexibilty wrt arrays of variable size. */
20759 bool collapse_nested_arrays
= !is_ada ();
20761 if (fill_variable_array_bounds (type
))
20764 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
20767 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
20768 DW_TAG_string_type doesn't have DW_AT_type attribute). */
20769 if (TYPE_STRING_FLAG (type
)
20770 && TREE_CODE (type
) == ARRAY_TYPE
20772 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
20774 HOST_WIDE_INT size
;
20776 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
20777 add_name_attribute (array_die
, type_tag (type
));
20778 equate_type_number_to_die (type
, array_die
);
20779 size
= int_size_in_bytes (type
);
20781 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
20782 else if (TYPE_DOMAIN (type
) != NULL_TREE
20783 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
20785 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
20786 tree rszdecl
= szdecl
;
20788 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
20789 if (!DECL_P (szdecl
))
20791 if (TREE_CODE (szdecl
) == INDIRECT_REF
20792 && DECL_P (TREE_OPERAND (szdecl
, 0)))
20794 rszdecl
= TREE_OPERAND (szdecl
, 0);
20795 if (int_size_in_bytes (TREE_TYPE (rszdecl
))
20796 != DWARF2_ADDR_SIZE
)
20804 dw_loc_list_ref loc
20805 = loc_list_from_tree (rszdecl
, szdecl
== rszdecl
? 2 : 0,
20809 add_AT_location_description (array_die
, DW_AT_string_length
,
20811 if (size
!= DWARF2_ADDR_SIZE
)
20812 add_AT_unsigned (array_die
, dwarf_version
>= 5
20813 ? DW_AT_string_length_byte_size
20814 : DW_AT_byte_size
, size
);
20821 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
20822 add_name_attribute (array_die
, type_tag (type
));
20823 equate_type_number_to_die (type
, array_die
);
20825 if (TREE_CODE (type
) == VECTOR_TYPE
)
20826 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
20828 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
20830 && TREE_CODE (type
) == ARRAY_TYPE
20831 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
20832 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
20833 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
20836 /* We default the array ordering. SDB will probably do
20837 the right things even if DW_AT_ordering is not present. It's not even
20838 an issue until we start to get into multidimensional arrays anyway. If
20839 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
20840 then we'll have to put the DW_AT_ordering attribute back in. (But if
20841 and when we find out that we need to put these in, we will only do so
20842 for multidimensional arrays. */
20843 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
20846 if (TREE_CODE (type
) == VECTOR_TYPE
)
20848 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
20849 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
20850 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
20851 add_bound_info (subrange_die
, DW_AT_upper_bound
,
20852 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
20855 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
20857 /* Add representation of the type of the elements of this array type and
20858 emit the corresponding DIE if we haven't done it already. */
20859 element_type
= TREE_TYPE (type
);
20860 if (collapse_nested_arrays
)
20861 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
20863 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
20865 element_type
= TREE_TYPE (element_type
);
20868 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
20869 TREE_CODE (type
) == ARRAY_TYPE
20870 && TYPE_REVERSE_STORAGE_ORDER (type
),
20873 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
20874 if (TYPE_ARTIFICIAL (type
))
20875 add_AT_flag (array_die
, DW_AT_artificial
, 1);
20877 if (get_AT (array_die
, DW_AT_name
))
20878 add_pubtype (type
, array_die
);
20880 add_alignment_attribute (array_die
, type
);
20883 /* This routine generates DIE for array with hidden descriptor, details
20884 are filled into *info by a langhook. */
20887 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
20888 dw_die_ref context_die
)
20890 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
20891 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
20892 struct loc_descr_context context
= { type
, info
->base_decl
, NULL
,
20894 enum dwarf_tag subrange_tag
= DW_TAG_subrange_type
;
20897 add_name_attribute (array_die
, type_tag (type
));
20898 equate_type_number_to_die (type
, array_die
);
20900 if (info
->ndimensions
> 1)
20901 switch (info
->ordering
)
20903 case array_descr_ordering_row_major
:
20904 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
20906 case array_descr_ordering_column_major
:
20907 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
20913 if (dwarf_version
>= 3 || !dwarf_strict
)
20915 if (info
->data_location
)
20916 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
20917 dw_scalar_form_exprloc
, &context
);
20918 if (info
->associated
)
20919 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
20920 dw_scalar_form_constant
20921 | dw_scalar_form_exprloc
20922 | dw_scalar_form_reference
, &context
);
20923 if (info
->allocated
)
20924 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
20925 dw_scalar_form_constant
20926 | dw_scalar_form_exprloc
20927 | dw_scalar_form_reference
, &context
);
20930 const enum dwarf_attribute attr
20931 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
20933 = (info
->stride_in_bits
)
20934 ? dw_scalar_form_constant
20935 : (dw_scalar_form_constant
20936 | dw_scalar_form_exprloc
20937 | dw_scalar_form_reference
);
20939 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
20942 if (dwarf_version
>= 5)
20946 add_scalar_info (array_die
, DW_AT_rank
, info
->rank
,
20947 dw_scalar_form_constant
20948 | dw_scalar_form_exprloc
, &context
);
20949 subrange_tag
= DW_TAG_generic_subrange
;
20950 context
.placeholder_arg
= true;
20954 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
20956 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
20958 dw_die_ref subrange_die
= new_die (subrange_tag
, array_die
, NULL
);
20960 if (info
->dimen
[dim
].bounds_type
)
20961 add_type_attribute (subrange_die
,
20962 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
20963 false, context_die
);
20964 if (info
->dimen
[dim
].lower_bound
)
20965 add_bound_info (subrange_die
, DW_AT_lower_bound
,
20966 info
->dimen
[dim
].lower_bound
, &context
);
20967 if (info
->dimen
[dim
].upper_bound
)
20968 add_bound_info (subrange_die
, DW_AT_upper_bound
,
20969 info
->dimen
[dim
].upper_bound
, &context
);
20970 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
20971 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
20972 info
->dimen
[dim
].stride
,
20973 dw_scalar_form_constant
20974 | dw_scalar_form_exprloc
20975 | dw_scalar_form_reference
,
20979 gen_type_die (info
->element_type
, context_die
);
20980 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
20981 TREE_CODE (type
) == ARRAY_TYPE
20982 && TYPE_REVERSE_STORAGE_ORDER (type
),
20985 if (get_AT (array_die
, DW_AT_name
))
20986 add_pubtype (type
, array_die
);
20988 add_alignment_attribute (array_die
, type
);
20993 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
20995 tree origin
= decl_ultimate_origin (decl
);
20996 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
20998 if (origin
!= NULL
)
20999 add_abstract_origin_attribute (decl_die
, origin
);
21002 add_name_and_src_coords_attributes (decl_die
, decl
);
21003 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
21004 TYPE_UNQUALIFIED
, false, context_die
);
21007 if (DECL_ABSTRACT_P (decl
))
21008 equate_decl_number_to_die (decl
, decl_die
);
21010 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
21014 /* Walk through the list of incomplete types again, trying once more to
21015 emit full debugging info for them. */
21018 retry_incomplete_types (void)
21023 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
21024 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
21025 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
21026 vec_safe_truncate (incomplete_types
, 0);
21029 /* Determine what tag to use for a record type. */
21031 static enum dwarf_tag
21032 record_type_tag (tree type
)
21034 if (! lang_hooks
.types
.classify_record
)
21035 return DW_TAG_structure_type
;
21037 switch (lang_hooks
.types
.classify_record (type
))
21039 case RECORD_IS_STRUCT
:
21040 return DW_TAG_structure_type
;
21042 case RECORD_IS_CLASS
:
21043 return DW_TAG_class_type
;
21045 case RECORD_IS_INTERFACE
:
21046 if (dwarf_version
>= 3 || !dwarf_strict
)
21047 return DW_TAG_interface_type
;
21048 return DW_TAG_structure_type
;
21051 gcc_unreachable ();
21055 /* Generate a DIE to represent an enumeration type. Note that these DIEs
21056 include all of the information about the enumeration values also. Each
21057 enumerated type name/value is listed as a child of the enumerated type
21061 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
21063 dw_die_ref type_die
= lookup_type_die (type
);
21065 if (type_die
== NULL
)
21067 type_die
= new_die (DW_TAG_enumeration_type
,
21068 scope_die_for (type
, context_die
), type
);
21069 equate_type_number_to_die (type
, type_die
);
21070 add_name_attribute (type_die
, type_tag (type
));
21071 if (dwarf_version
>= 4 || !dwarf_strict
)
21073 if (ENUM_IS_SCOPED (type
))
21074 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
21075 if (ENUM_IS_OPAQUE (type
))
21076 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21079 add_AT_unsigned (type_die
, DW_AT_encoding
,
21080 TYPE_UNSIGNED (type
)
21084 else if (! TYPE_SIZE (type
))
21087 remove_AT (type_die
, DW_AT_declaration
);
21089 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
21090 given enum type is incomplete, do not generate the DW_AT_byte_size
21091 attribute or the DW_AT_element_list attribute. */
21092 if (TYPE_SIZE (type
))
21096 TREE_ASM_WRITTEN (type
) = 1;
21097 add_byte_size_attribute (type_die
, type
);
21098 add_alignment_attribute (type_die
, type
);
21099 if (dwarf_version
>= 3 || !dwarf_strict
)
21101 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
21102 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
21105 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
21107 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
21108 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
21111 /* If the first reference to this type was as the return type of an
21112 inline function, then it may not have a parent. Fix this now. */
21113 if (type_die
->die_parent
== NULL
)
21114 add_child_die (scope_die_for (type
, context_die
), type_die
);
21116 for (link
= TYPE_VALUES (type
);
21117 link
!= NULL
; link
= TREE_CHAIN (link
))
21119 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
21120 tree value
= TREE_VALUE (link
);
21122 add_name_attribute (enum_die
,
21123 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
21125 if (TREE_CODE (value
) == CONST_DECL
)
21126 value
= DECL_INITIAL (value
);
21128 if (simple_type_size_in_bits (TREE_TYPE (value
))
21129 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
21131 /* For constant forms created by add_AT_unsigned DWARF
21132 consumers (GDB, elfutils, etc.) always zero extend
21133 the value. Only when the actual value is negative
21134 do we need to use add_AT_int to generate a constant
21135 form that can represent negative values. */
21136 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
21137 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
21138 add_AT_unsigned (enum_die
, DW_AT_const_value
,
21139 (unsigned HOST_WIDE_INT
) val
);
21141 add_AT_int (enum_die
, DW_AT_const_value
, val
);
21144 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
21145 that here. TODO: This should be re-worked to use correct
21146 signed/unsigned double tags for all cases. */
21147 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
21150 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
21151 if (TYPE_ARTIFICIAL (type
))
21152 add_AT_flag (type_die
, DW_AT_artificial
, 1);
21155 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21157 add_alignment_attribute (type_die
, type
);
21159 add_pubtype (type
, type_die
);
21164 /* Generate a DIE to represent either a real live formal parameter decl or to
21165 represent just the type of some formal parameter position in some function
21168 Note that this routine is a bit unusual because its argument may be a
21169 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
21170 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
21171 node. If it's the former then this function is being called to output a
21172 DIE to represent a formal parameter object (or some inlining thereof). If
21173 it's the latter, then this function is only being called to output a
21174 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
21175 argument type of some subprogram type.
21176 If EMIT_NAME_P is true, name and source coordinate attributes
21180 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
21181 dw_die_ref context_die
)
21183 tree node_or_origin
= node
? node
: origin
;
21184 tree ultimate_origin
;
21185 dw_die_ref parm_die
= NULL
;
21187 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
21189 parm_die
= lookup_decl_die (node
);
21191 /* If the contexts differ, we may not be talking about the same
21193 if (parm_die
&& parm_die
->die_parent
!= context_die
)
21195 if (!DECL_ABSTRACT_P (node
))
21197 /* This can happen when creating an inlined instance, in
21198 which case we need to create a new DIE that will get
21199 annotated with DW_AT_abstract_origin. */
21204 /* FIXME: Reuse DIE even with a differing context.
21206 This can happen when calling
21207 dwarf2out_abstract_function to build debug info for
21208 the abstract instance of a function for which we have
21209 already generated a DIE in
21210 dwarf2out_early_global_decl.
21212 Once we remove dwarf2out_abstract_function, we should
21213 have a call to gcc_unreachable here. */
21217 if (parm_die
&& parm_die
->die_parent
== NULL
)
21219 /* Check that parm_die already has the right attributes that
21220 we would have added below. If any attributes are
21221 missing, fall through to add them. */
21222 if (! DECL_ABSTRACT_P (node_or_origin
)
21223 && !get_AT (parm_die
, DW_AT_location
)
21224 && !get_AT (parm_die
, DW_AT_const_value
))
21225 /* We are missing location info, and are about to add it. */
21229 add_child_die (context_die
, parm_die
);
21235 /* If we have a previously generated DIE, use it, unless this is an
21236 concrete instance (origin != NULL), in which case we need a new
21237 DIE with a corresponding DW_AT_abstract_origin. */
21239 if (parm_die
&& origin
== NULL
)
21240 reusing_die
= true;
21243 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
21244 reusing_die
= false;
21247 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
21249 case tcc_declaration
:
21250 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
21251 if (node
|| ultimate_origin
)
21252 origin
= ultimate_origin
;
21257 if (origin
!= NULL
)
21258 add_abstract_origin_attribute (parm_die
, origin
);
21259 else if (emit_name_p
)
21260 add_name_and_src_coords_attributes (parm_die
, node
);
21262 || (! DECL_ABSTRACT_P (node_or_origin
)
21263 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
21264 decl_function_context
21265 (node_or_origin
))))
21267 tree type
= TREE_TYPE (node_or_origin
);
21268 if (decl_by_reference_p (node_or_origin
))
21269 add_type_attribute (parm_die
, TREE_TYPE (type
),
21271 false, context_die
);
21273 add_type_attribute (parm_die
, type
,
21274 decl_quals (node_or_origin
),
21275 false, context_die
);
21277 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
21278 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21280 if (node
&& node
!= origin
)
21281 equate_decl_number_to_die (node
, parm_die
);
21282 if (! DECL_ABSTRACT_P (node_or_origin
))
21283 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
21289 /* We were called with some kind of a ..._TYPE node. */
21290 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
21295 gcc_unreachable ();
21301 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
21302 children DW_TAG_formal_parameter DIEs representing the arguments of the
21305 PARM_PACK must be a function parameter pack.
21306 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
21307 must point to the subsequent arguments of the function PACK_ARG belongs to.
21308 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
21309 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
21310 following the last one for which a DIE was generated. */
21313 gen_formal_parameter_pack_die (tree parm_pack
,
21315 dw_die_ref subr_die
,
21319 dw_die_ref parm_pack_die
;
21321 gcc_assert (parm_pack
21322 && lang_hooks
.function_parameter_pack_p (parm_pack
)
21325 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
21326 add_src_coords_attributes (parm_pack_die
, parm_pack
);
21328 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
21330 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
21333 gen_formal_parameter_die (arg
, NULL
,
21334 false /* Don't emit name attribute. */,
21339 return parm_pack_die
;
21342 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
21343 at the end of an (ANSI prototyped) formal parameters list. */
21346 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
21348 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
21351 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
21352 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
21353 parameters as specified in some function type specification (except for
21354 those which appear as part of a function *definition*). */
21357 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
21360 tree formal_type
= NULL
;
21361 tree first_parm_type
;
21364 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
21366 arg
= DECL_ARGUMENTS (function_or_method_type
);
21367 function_or_method_type
= TREE_TYPE (function_or_method_type
);
21372 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
21374 /* Make our first pass over the list of formal parameter types and output a
21375 DW_TAG_formal_parameter DIE for each one. */
21376 for (link
= first_parm_type
; link
; )
21378 dw_die_ref parm_die
;
21380 formal_type
= TREE_VALUE (link
);
21381 if (formal_type
== void_type_node
)
21384 /* Output a (nameless) DIE to represent the formal parameter itself. */
21385 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
21387 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
21388 true /* Emit name attribute. */,
21390 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
21391 && link
== first_parm_type
)
21393 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21394 if (dwarf_version
>= 3 || !dwarf_strict
)
21395 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
21397 else if (arg
&& DECL_ARTIFICIAL (arg
))
21398 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21401 link
= TREE_CHAIN (link
);
21403 arg
= DECL_CHAIN (arg
);
21406 /* If this function type has an ellipsis, add a
21407 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
21408 if (formal_type
!= void_type_node
)
21409 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
21411 /* Make our second (and final) pass over the list of formal parameter types
21412 and output DIEs to represent those types (as necessary). */
21413 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
21414 link
&& TREE_VALUE (link
);
21415 link
= TREE_CHAIN (link
))
21416 gen_type_die (TREE_VALUE (link
), context_die
);
21419 /* We want to generate the DIE for TYPE so that we can generate the
21420 die for MEMBER, which has been defined; we will need to refer back
21421 to the member declaration nested within TYPE. If we're trying to
21422 generate minimal debug info for TYPE, processing TYPE won't do the
21423 trick; we need to attach the member declaration by hand. */
21426 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
21428 gen_type_die (type
, context_die
);
21430 /* If we're trying to avoid duplicate debug info, we may not have
21431 emitted the member decl for this function. Emit it now. */
21432 if (TYPE_STUB_DECL (type
)
21433 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
21434 && ! lookup_decl_die (member
))
21436 dw_die_ref type_die
;
21437 gcc_assert (!decl_ultimate_origin (member
));
21439 push_decl_scope (type
);
21440 type_die
= lookup_type_die_strip_naming_typedef (type
);
21441 if (TREE_CODE (member
) == FUNCTION_DECL
)
21442 gen_subprogram_die (member
, type_die
);
21443 else if (TREE_CODE (member
) == FIELD_DECL
)
21445 /* Ignore the nameless fields that are used to skip bits but handle
21446 C++ anonymous unions and structs. */
21447 if (DECL_NAME (member
) != NULL_TREE
21448 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
21449 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
21451 struct vlr_context vlr_ctx
= {
21452 DECL_CONTEXT (member
), /* struct_type */
21453 NULL_TREE
/* variant_part_offset */
21455 gen_type_die (member_declared_type (member
), type_die
);
21456 gen_field_die (member
, &vlr_ctx
, type_die
);
21460 gen_variable_die (member
, NULL_TREE
, type_die
);
21466 /* Forward declare these functions, because they are mutually recursive
21467 with their set_block_* pairing functions. */
21468 static void set_decl_origin_self (tree
);
21469 static void set_decl_abstract_flags (tree
, vec
<tree
> &);
21471 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
21472 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
21473 that it points to the node itself, thus indicating that the node is its
21474 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
21475 the given node is NULL, recursively descend the decl/block tree which
21476 it is the root of, and for each other ..._DECL or BLOCK node contained
21477 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
21478 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
21479 values to point to themselves. */
21482 set_block_origin_self (tree stmt
)
21484 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
21486 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
21491 for (local_decl
= BLOCK_VARS (stmt
);
21492 local_decl
!= NULL_TREE
;
21493 local_decl
= DECL_CHAIN (local_decl
))
21494 /* Do not recurse on nested functions since the inlining status
21495 of parent and child can be different as per the DWARF spec. */
21496 if (TREE_CODE (local_decl
) != FUNCTION_DECL
21497 && !DECL_EXTERNAL (local_decl
))
21498 set_decl_origin_self (local_decl
);
21504 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
21505 subblock
!= NULL_TREE
;
21506 subblock
= BLOCK_CHAIN (subblock
))
21507 set_block_origin_self (subblock
); /* Recurse. */
21512 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
21513 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
21514 node to so that it points to the node itself, thus indicating that the
21515 node represents its own (abstract) origin. Additionally, if the
21516 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
21517 the decl/block tree of which the given node is the root of, and for
21518 each other ..._DECL or BLOCK node contained therein whose
21519 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
21520 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
21521 point to themselves. */
21524 set_decl_origin_self (tree decl
)
21526 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
21528 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
21529 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21533 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
21534 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
21535 if (DECL_INITIAL (decl
) != NULL_TREE
21536 && DECL_INITIAL (decl
) != error_mark_node
)
21537 set_block_origin_self (DECL_INITIAL (decl
));
21542 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
21543 and if it wasn't 1 before, push it to abstract_vec vector.
21544 For all local decls and all local sub-blocks (recursively) do it
21548 set_block_abstract_flags (tree stmt
, vec
<tree
> &abstract_vec
)
21554 if (!BLOCK_ABSTRACT (stmt
))
21556 abstract_vec
.safe_push (stmt
);
21557 BLOCK_ABSTRACT (stmt
) = 1;
21560 for (local_decl
= BLOCK_VARS (stmt
);
21561 local_decl
!= NULL_TREE
;
21562 local_decl
= DECL_CHAIN (local_decl
))
21563 if (! DECL_EXTERNAL (local_decl
))
21564 set_decl_abstract_flags (local_decl
, abstract_vec
);
21566 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
21568 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
21569 if ((VAR_P (local_decl
) && !TREE_STATIC (local_decl
))
21570 || TREE_CODE (local_decl
) == PARM_DECL
)
21571 set_decl_abstract_flags (local_decl
, abstract_vec
);
21574 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
21575 subblock
!= NULL_TREE
;
21576 subblock
= BLOCK_CHAIN (subblock
))
21577 set_block_abstract_flags (subblock
, abstract_vec
);
21580 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
21581 to 1 and if it wasn't 1 before, push to abstract_vec vector.
21582 In the case where the decl is a FUNCTION_DECL also set the abstract
21583 flags for all of the parameters, local vars, local
21584 blocks and sub-blocks (recursively). */
21587 set_decl_abstract_flags (tree decl
, vec
<tree
> &abstract_vec
)
21589 if (!DECL_ABSTRACT_P (decl
))
21591 abstract_vec
.safe_push (decl
);
21592 DECL_ABSTRACT_P (decl
) = 1;
21595 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21599 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
21600 if (!DECL_ABSTRACT_P (arg
))
21602 abstract_vec
.safe_push (arg
);
21603 DECL_ABSTRACT_P (arg
) = 1;
21605 if (DECL_INITIAL (decl
) != NULL_TREE
21606 && DECL_INITIAL (decl
) != error_mark_node
)
21607 set_block_abstract_flags (DECL_INITIAL (decl
), abstract_vec
);
21611 /* Generate the DWARF2 info for the "abstract" instance of a function which we
21612 may later generate inlined and/or out-of-line instances of.
21614 FIXME: In the early-dwarf world, this function, and most of the
21615 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
21616 the abstract instance. All we would need to do is annotate
21617 the early DIE with the appropriate DW_AT_inline in late
21618 dwarf (perhaps in gen_inlined_subroutine_die).
21620 However, we can't do this yet, because LTO streaming of DIEs
21621 has not been implemented yet. */
21624 dwarf2out_abstract_function (tree decl
)
21626 dw_die_ref old_die
;
21629 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
21630 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
21631 int old_call_site_count
, old_tail_call_site_count
;
21632 struct call_arg_loc_node
*old_call_arg_locations
;
21634 /* Make sure we have the actual abstract inline, not a clone. */
21635 decl
= DECL_ORIGIN (decl
);
21637 old_die
= lookup_decl_die (decl
);
21638 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
21639 /* We've already generated the abstract instance. */
21642 /* We can be called while recursively when seeing block defining inlined subroutine
21643 DIE. Be sure to not clobber the outer location table nor use it or we would
21644 get locations in abstract instantces. */
21645 old_decl_loc_table
= decl_loc_table
;
21646 decl_loc_table
= NULL
;
21647 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
21648 cached_dw_loc_list_table
= NULL
;
21649 old_call_arg_locations
= call_arg_locations
;
21650 call_arg_locations
= NULL
;
21651 old_call_site_count
= call_site_count
;
21652 call_site_count
= -1;
21653 old_tail_call_site_count
= tail_call_site_count
;
21654 tail_call_site_count
= -1;
21656 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
21657 we don't get confused by DECL_ABSTRACT_P. */
21658 if (debug_info_level
> DINFO_LEVEL_TERSE
)
21660 context
= decl_class_context (decl
);
21662 gen_type_die_for_member
21663 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
21666 /* Pretend we've just finished compiling this function. */
21667 save_fn
= current_function_decl
;
21668 current_function_decl
= decl
;
21670 auto_vec
<tree
, 64> abstract_vec
;
21671 set_decl_abstract_flags (decl
, abstract_vec
);
21672 dwarf2out_decl (decl
);
21675 FOR_EACH_VEC_ELT (abstract_vec
, i
, t
)
21676 if (TREE_CODE (t
) == BLOCK
)
21677 BLOCK_ABSTRACT (t
) = 0;
21679 DECL_ABSTRACT_P (t
) = 0;
21681 current_function_decl
= save_fn
;
21682 decl_loc_table
= old_decl_loc_table
;
21683 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
21684 call_arg_locations
= old_call_arg_locations
;
21685 call_site_count
= old_call_site_count
;
21686 tail_call_site_count
= old_tail_call_site_count
;
21689 /* Helper function of premark_used_types() which gets called through
21692 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21693 marked as unused by prune_unused_types. */
21696 premark_used_types_helper (tree
const &type
, void *)
21700 die
= lookup_type_die (type
);
21702 die
->die_perennial_p
= 1;
21706 /* Helper function of premark_types_used_by_global_vars which gets called
21707 through htab_traverse.
21709 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21710 marked as unused by prune_unused_types. The DIE of the type is marked
21711 only if the global variable using the type will actually be emitted. */
21714 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
21717 struct types_used_by_vars_entry
*entry
;
21720 entry
= (struct types_used_by_vars_entry
*) *slot
;
21721 gcc_assert (entry
->type
!= NULL
21722 && entry
->var_decl
!= NULL
);
21723 die
= lookup_type_die (entry
->type
);
21726 /* Ask cgraph if the global variable really is to be emitted.
21727 If yes, then we'll keep the DIE of ENTRY->TYPE. */
21728 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
21729 if (node
&& node
->definition
)
21731 die
->die_perennial_p
= 1;
21732 /* Keep the parent DIEs as well. */
21733 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
21734 die
->die_perennial_p
= 1;
21740 /* Mark all members of used_types_hash as perennial. */
21743 premark_used_types (struct function
*fun
)
21745 if (fun
&& fun
->used_types_hash
)
21746 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
21749 /* Mark all members of types_used_by_vars_entry as perennial. */
21752 premark_types_used_by_global_vars (void)
21754 if (types_used_by_vars_hash
)
21755 types_used_by_vars_hash
21756 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
21759 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
21760 for CA_LOC call arg loc node. */
21763 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
21764 struct call_arg_loc_node
*ca_loc
)
21766 dw_die_ref stmt_die
= NULL
, die
;
21767 tree block
= ca_loc
->block
;
21770 && block
!= DECL_INITIAL (decl
)
21771 && TREE_CODE (block
) == BLOCK
)
21773 stmt_die
= BLOCK_DIE (block
);
21776 block
= BLOCK_SUPERCONTEXT (block
);
21778 if (stmt_die
== NULL
)
21779 stmt_die
= subr_die
;
21780 die
= new_die (dwarf_TAG (DW_TAG_call_site
), stmt_die
, NULL_TREE
);
21781 add_AT_lbl_id (die
, dwarf_AT (DW_AT_call_return_pc
), ca_loc
->label
);
21782 if (ca_loc
->tail_call_p
)
21783 add_AT_flag (die
, dwarf_AT (DW_AT_call_tail_call
), 1);
21784 if (ca_loc
->symbol_ref
)
21786 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
21788 add_AT_die_ref (die
, dwarf_AT (DW_AT_call_origin
), tdie
);
21790 add_AT_addr (die
, dwarf_AT (DW_AT_call_origin
), ca_loc
->symbol_ref
,
21796 /* Generate a DIE to represent a declared function (either file-scope or
21800 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
21802 tree origin
= decl_ultimate_origin (decl
);
21803 dw_die_ref subr_die
;
21804 dw_die_ref old_die
= lookup_decl_die (decl
);
21806 /* This function gets called multiple times for different stages of
21807 the debug process. For example, for func() in this code:
21811 void func() { ... }
21814 ...we get called 4 times. Twice in early debug and twice in
21820 1. Once while generating func() within the namespace. This is
21821 the declaration. The declaration bit below is set, as the
21822 context is the namespace.
21824 A new DIE will be generated with DW_AT_declaration set.
21826 2. Once for func() itself. This is the specification. The
21827 declaration bit below is clear as the context is the CU.
21829 We will use the cached DIE from (1) to create a new DIE with
21830 DW_AT_specification pointing to the declaration in (1).
21832 Late debug via rest_of_handle_final()
21833 -------------------------------------
21835 3. Once generating func() within the namespace. This is also the
21836 declaration, as in (1), but this time we will early exit below
21837 as we have a cached DIE and a declaration needs no additional
21838 annotations (no locations), as the source declaration line
21841 4. Once for func() itself. As in (2), this is the specification,
21842 but this time we will re-use the cached DIE, and just annotate
21843 it with the location information that should now be available.
21845 For something without namespaces, but with abstract instances, we
21846 are also called a multiple times:
21851 Base (); // constructor declaration (1)
21854 Base::Base () { } // constructor specification (2)
21859 1. Once for the Base() constructor by virtue of it being a
21860 member of the Base class. This is done via
21861 rest_of_type_compilation.
21863 This is a declaration, so a new DIE will be created with
21866 2. Once for the Base() constructor definition, but this time
21867 while generating the abstract instance of the base
21868 constructor (__base_ctor) which is being generated via early
21869 debug of reachable functions.
21871 Even though we have a cached version of the declaration (1),
21872 we will create a DW_AT_specification of the declaration DIE
21875 3. Once for the __base_ctor itself, but this time, we generate
21876 an DW_AT_abstract_origin version of the DW_AT_specification in
21879 Late debug via rest_of_handle_final
21880 -----------------------------------
21882 4. One final time for the __base_ctor (which will have a cached
21883 DIE with DW_AT_abstract_origin created in (3). This time,
21884 we will just annotate the location information now
21887 int declaration
= (current_function_decl
!= decl
21888 || class_or_namespace_scope_p (context_die
));
21890 /* Now that the C++ front end lazily declares artificial member fns, we
21891 might need to retrofit the declaration into its class. */
21892 if (!declaration
&& !origin
&& !old_die
21893 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
21894 && !class_or_namespace_scope_p (context_die
)
21895 && debug_info_level
> DINFO_LEVEL_TERSE
)
21896 old_die
= force_decl_die (decl
);
21898 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
21899 if (origin
!= NULL
)
21901 gcc_assert (!declaration
|| local_scope_p (context_die
));
21903 /* Fixup die_parent for the abstract instance of a nested
21904 inline function. */
21905 if (old_die
&& old_die
->die_parent
== NULL
)
21906 add_child_die (context_die
, old_die
);
21908 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
21910 /* If we have a DW_AT_abstract_origin we have a working
21912 subr_die
= old_die
;
21916 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
21917 add_abstract_origin_attribute (subr_die
, origin
);
21918 /* This is where the actual code for a cloned function is.
21919 Let's emit linkage name attribute for it. This helps
21920 debuggers to e.g, set breakpoints into
21921 constructors/destructors when the user asks "break
21923 add_linkage_name (subr_die
, decl
);
21926 /* A cached copy, possibly from early dwarf generation. Reuse as
21927 much as possible. */
21930 /* A declaration that has been previously dumped needs no
21931 additional information. */
21935 if (!get_AT_flag (old_die
, DW_AT_declaration
)
21936 /* We can have a normal definition following an inline one in the
21937 case of redefinition of GNU C extern inlines.
21938 It seems reasonable to use AT_specification in this case. */
21939 && !get_AT (old_die
, DW_AT_inline
))
21941 /* Detect and ignore this case, where we are trying to output
21942 something we have already output. */
21943 if (get_AT (old_die
, DW_AT_low_pc
)
21944 || get_AT (old_die
, DW_AT_ranges
))
21947 /* If we have no location information, this must be a
21948 partially generated DIE from early dwarf generation.
21949 Fall through and generate it. */
21952 /* If the definition comes from the same place as the declaration,
21953 maybe use the old DIE. We always want the DIE for this function
21954 that has the *_pc attributes to be under comp_unit_die so the
21955 debugger can find it. We also need to do this for abstract
21956 instances of inlines, since the spec requires the out-of-line copy
21957 to have the same parent. For local class methods, this doesn't
21958 apply; we just use the old DIE. */
21959 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
21960 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
21961 if ((is_cu_die (old_die
->die_parent
)
21962 /* This condition fixes the inconsistency/ICE with the
21963 following Fortran test (or some derivative thereof) while
21964 building libgfortran:
21968 logical function funky (FLAG)
21973 || (old_die
->die_parent
21974 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
21975 || context_die
== NULL
)
21976 && (DECL_ARTIFICIAL (decl
)
21977 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
21978 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
21979 == (unsigned) s
.line
)
21980 && (!debug_column_info
21982 || (get_AT_unsigned (old_die
, DW_AT_decl_column
)
21983 == (unsigned) s
.column
)))))
21985 subr_die
= old_die
;
21987 /* Clear out the declaration attribute, but leave the
21988 parameters so they can be augmented with location
21989 information later. Unless this was a declaration, in
21990 which case, wipe out the nameless parameters and recreate
21991 them further down. */
21992 if (remove_AT (subr_die
, DW_AT_declaration
))
21995 remove_AT (subr_die
, DW_AT_object_pointer
);
21996 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
21999 /* Make a specification pointing to the previously built
22003 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22004 add_AT_specification (subr_die
, old_die
);
22005 add_pubname (decl
, subr_die
);
22006 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
22007 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
22008 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
22009 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
22010 if (debug_column_info
22012 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
22013 != (unsigned) s
.column
))
22014 add_AT_unsigned (subr_die
, DW_AT_decl_column
, s
.column
);
22016 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
22017 emit the real type on the definition die. */
22018 if (is_cxx () && debug_info_level
> DINFO_LEVEL_TERSE
)
22020 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
22021 if (die
== auto_die
|| die
== decltype_auto_die
)
22022 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
22023 TYPE_UNQUALIFIED
, false, context_die
);
22026 /* When we process the method declaration, we haven't seen
22027 the out-of-class defaulted definition yet, so we have to
22029 if ((dwarf_version
>= 5 || ! dwarf_strict
)
22030 && !get_AT (subr_die
, DW_AT_defaulted
))
22033 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22035 if (defaulted
!= -1)
22037 /* Other values must have been handled before. */
22038 gcc_assert (defaulted
== DW_DEFAULTED_out_of_class
);
22039 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22044 /* Create a fresh DIE for anything else. */
22047 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22049 if (TREE_PUBLIC (decl
))
22050 add_AT_flag (subr_die
, DW_AT_external
, 1);
22052 add_name_and_src_coords_attributes (subr_die
, decl
);
22053 add_pubname (decl
, subr_die
);
22054 if (debug_info_level
> DINFO_LEVEL_TERSE
)
22056 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
22057 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
22058 TYPE_UNQUALIFIED
, false, context_die
);
22061 add_pure_or_virtual_attribute (subr_die
, decl
);
22062 if (DECL_ARTIFICIAL (decl
))
22063 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
22065 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
22066 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
22068 add_alignment_attribute (subr_die
, decl
);
22070 add_accessibility_attribute (subr_die
, decl
);
22073 /* Unless we have an existing non-declaration DIE, equate the new
22075 if (!old_die
|| is_declaration_die (old_die
))
22076 equate_decl_number_to_die (decl
, subr_die
);
22080 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
22082 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
22084 /* If this is an explicit function declaration then generate
22085 a DW_AT_explicit attribute. */
22086 if ((dwarf_version
>= 3 || !dwarf_strict
)
22087 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22088 DW_AT_explicit
) == 1)
22089 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
22091 /* If this is a C++11 deleted special function member then generate
22092 a DW_AT_deleted attribute. */
22093 if ((dwarf_version
>= 5 || !dwarf_strict
)
22094 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22095 DW_AT_deleted
) == 1)
22096 add_AT_flag (subr_die
, DW_AT_deleted
, 1);
22098 /* If this is a C++11 defaulted special function member then
22099 generate a DW_AT_defaulted attribute. */
22100 if (dwarf_version
>= 5 || !dwarf_strict
)
22103 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22105 if (defaulted
!= -1)
22106 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22109 /* If this is a C++11 non-static member function with & ref-qualifier
22110 then generate a DW_AT_reference attribute. */
22111 if ((dwarf_version
>= 5 || !dwarf_strict
)
22112 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22113 DW_AT_reference
) == 1)
22114 add_AT_flag (subr_die
, DW_AT_reference
, 1);
22116 /* If this is a C++11 non-static member function with &&
22117 ref-qualifier then generate a DW_AT_reference attribute. */
22118 if ((dwarf_version
>= 5 || !dwarf_strict
)
22119 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22120 DW_AT_rvalue_reference
)
22122 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
22125 /* Tag abstract instances with DW_AT_inline. */
22126 else if (DECL_ABSTRACT_P (decl
))
22128 if (DECL_DECLARED_INLINE_P (decl
))
22130 if (cgraph_function_possibly_inlined_p (decl
))
22131 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
22133 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
22137 if (cgraph_function_possibly_inlined_p (decl
))
22138 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
22140 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
22143 if (DECL_DECLARED_INLINE_P (decl
)
22144 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
22145 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
22147 /* For non DECL_EXTERNALs, if range information is available, fill
22148 the DIE with it. */
22149 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
22151 HOST_WIDE_INT cfa_fb_offset
;
22153 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
22155 if (!flag_reorder_blocks_and_partition
)
22157 dw_fde_ref fde
= fun
->fde
;
22158 if (fde
->dw_fde_begin
)
22160 /* We have already generated the labels. */
22161 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22162 fde
->dw_fde_end
, false);
22166 /* Create start/end labels and add the range. */
22167 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
22168 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
22169 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
22170 current_function_funcdef_no
);
22171 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
22172 current_function_funcdef_no
);
22173 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
22177 #if VMS_DEBUGGING_INFO
22178 /* HP OpenVMS Industry Standard 64: DWARF Extensions
22179 Section 2.3 Prologue and Epilogue Attributes:
22180 When a breakpoint is set on entry to a function, it is generally
22181 desirable for execution to be suspended, not on the very first
22182 instruction of the function, but rather at a point after the
22183 function's frame has been set up, after any language defined local
22184 declaration processing has been completed, and before execution of
22185 the first statement of the function begins. Debuggers generally
22186 cannot properly determine where this point is. Similarly for a
22187 breakpoint set on exit from a function. The prologue and epilogue
22188 attributes allow a compiler to communicate the location(s) to use. */
22191 if (fde
->dw_fde_vms_end_prologue
)
22192 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
22193 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
22195 if (fde
->dw_fde_vms_begin_epilogue
)
22196 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
22197 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
22204 /* Generate pubnames entries for the split function code ranges. */
22205 dw_fde_ref fde
= fun
->fde
;
22207 if (fde
->dw_fde_second_begin
)
22209 if (dwarf_version
>= 3 || !dwarf_strict
)
22211 /* We should use ranges for non-contiguous code section
22212 addresses. Use the actual code range for the initial
22213 section, since the HOT/COLD labels might precede an
22214 alignment offset. */
22215 bool range_list_added
= false;
22216 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
22217 fde
->dw_fde_end
, &range_list_added
,
22219 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
22220 fde
->dw_fde_second_end
,
22221 &range_list_added
, false);
22222 if (range_list_added
)
22227 /* There is no real support in DW2 for this .. so we make
22228 a work-around. First, emit the pub name for the segment
22229 containing the function label. Then make and emit a
22230 simplified subprogram DIE for the second segment with the
22231 name pre-fixed by __hot/cold_sect_of_. We use the same
22232 linkage name for the second die so that gdb will find both
22233 sections when given "b foo". */
22234 const char *name
= NULL
;
22235 tree decl_name
= DECL_NAME (decl
);
22236 dw_die_ref seg_die
;
22238 /* Do the 'primary' section. */
22239 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22240 fde
->dw_fde_end
, false);
22242 /* Build a minimal DIE for the secondary section. */
22243 seg_die
= new_die (DW_TAG_subprogram
,
22244 subr_die
->die_parent
, decl
);
22246 if (TREE_PUBLIC (decl
))
22247 add_AT_flag (seg_die
, DW_AT_external
, 1);
22249 if (decl_name
!= NULL
22250 && IDENTIFIER_POINTER (decl_name
) != NULL
)
22252 name
= dwarf2_name (decl
, 1);
22253 if (! DECL_ARTIFICIAL (decl
))
22254 add_src_coords_attributes (seg_die
, decl
);
22256 add_linkage_name (seg_die
, decl
);
22258 gcc_assert (name
!= NULL
);
22259 add_pure_or_virtual_attribute (seg_die
, decl
);
22260 if (DECL_ARTIFICIAL (decl
))
22261 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
22263 name
= concat ("__second_sect_of_", name
, NULL
);
22264 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
22265 fde
->dw_fde_second_end
, false);
22266 add_name_attribute (seg_die
, name
);
22267 if (want_pubnames ())
22268 add_pubname_string (name
, seg_die
);
22272 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
22276 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
22278 /* We define the "frame base" as the function's CFA. This is more
22279 convenient for several reasons: (1) It's stable across the prologue
22280 and epilogue, which makes it better than just a frame pointer,
22281 (2) With dwarf3, there exists a one-byte encoding that allows us
22282 to reference the .debug_frame data by proxy, but failing that,
22283 (3) We can at least reuse the code inspection and interpretation
22284 code that determines the CFA position at various points in the
22286 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
22288 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
22289 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
22293 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
22294 if (list
->dw_loc_next
)
22295 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
22297 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
22300 /* Compute a displacement from the "steady-state frame pointer" to
22301 the CFA. The former is what all stack slots and argument slots
22302 will reference in the rtl; the latter is what we've told the
22303 debugger about. We'll need to adjust all frame_base references
22304 by this displacement. */
22305 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
22307 if (fun
->static_chain_decl
)
22309 /* DWARF requires here a location expression that computes the
22310 address of the enclosing subprogram's frame base. The machinery
22311 in tree-nested.c is supposed to store this specific address in the
22312 last field of the FRAME record. */
22313 const tree frame_type
22314 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
22315 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
22318 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
22319 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
22320 fb_expr
, fb_decl
, NULL_TREE
);
22322 add_AT_location_description (subr_die
, DW_AT_static_link
,
22323 loc_list_from_tree (fb_expr
, 0, NULL
));
22326 resolve_variable_values ();
22329 /* Generate child dies for template paramaters. */
22330 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
22331 gen_generic_params_dies (decl
);
22333 /* Now output descriptions of the arguments for this function. This gets
22334 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
22335 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
22336 `...' at the end of the formal parameter list. In order to find out if
22337 there was a trailing ellipsis or not, we must instead look at the type
22338 associated with the FUNCTION_DECL. This will be a node of type
22339 FUNCTION_TYPE. If the chain of type nodes hanging off of this
22340 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
22341 an ellipsis at the end. */
22343 /* In the case where we are describing a mere function declaration, all we
22344 need to do here (and all we *can* do here) is to describe the *types* of
22345 its formal parameters. */
22346 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
22348 else if (declaration
)
22349 gen_formal_types_die (decl
, subr_die
);
22352 /* Generate DIEs to represent all known formal parameters. */
22353 tree parm
= DECL_ARGUMENTS (decl
);
22354 tree generic_decl
= early_dwarf
22355 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
22356 tree generic_decl_parm
= generic_decl
22357 ? DECL_ARGUMENTS (generic_decl
)
22360 /* Now we want to walk the list of parameters of the function and
22361 emit their relevant DIEs.
22363 We consider the case of DECL being an instance of a generic function
22364 as well as it being a normal function.
22366 If DECL is an instance of a generic function we walk the
22367 parameters of the generic function declaration _and_ the parameters of
22368 DECL itself. This is useful because we want to emit specific DIEs for
22369 function parameter packs and those are declared as part of the
22370 generic function declaration. In that particular case,
22371 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
22372 That DIE has children DIEs representing the set of arguments
22373 of the pack. Note that the set of pack arguments can be empty.
22374 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
22377 Otherwise, we just consider the parameters of DECL. */
22378 while (generic_decl_parm
|| parm
)
22380 if (generic_decl_parm
22381 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
22382 gen_formal_parameter_pack_die (generic_decl_parm
,
22385 else if (parm
&& !POINTER_BOUNDS_P (parm
))
22387 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
22389 if (parm
== DECL_ARGUMENTS (decl
)
22390 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
22392 && (dwarf_version
>= 3 || !dwarf_strict
))
22393 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
22395 parm
= DECL_CHAIN (parm
);
22398 parm
= DECL_CHAIN (parm
);
22400 if (generic_decl_parm
)
22401 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
22404 /* Decide whether we need an unspecified_parameters DIE at the end.
22405 There are 2 more cases to do this for: 1) the ansi ... declaration -
22406 this is detectable when the end of the arg list is not a
22407 void_type_node 2) an unprototyped function declaration (not a
22408 definition). This just means that we have no info about the
22409 parameters at all. */
22412 if (prototype_p (TREE_TYPE (decl
)))
22414 /* This is the prototyped case, check for.... */
22415 if (stdarg_p (TREE_TYPE (decl
)))
22416 gen_unspecified_parameters_die (decl
, subr_die
);
22418 else if (DECL_INITIAL (decl
) == NULL_TREE
)
22419 gen_unspecified_parameters_die (decl
, subr_die
);
22423 if (subr_die
!= old_die
)
22424 /* Add the calling convention attribute if requested. */
22425 add_calling_convention_attribute (subr_die
, decl
);
22427 /* Output Dwarf info for all of the stuff within the body of the function
22428 (if it has one - it may be just a declaration).
22430 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
22431 a function. This BLOCK actually represents the outermost binding contour
22432 for the function, i.e. the contour in which the function's formal
22433 parameters and labels get declared. Curiously, it appears that the front
22434 end doesn't actually put the PARM_DECL nodes for the current function onto
22435 the BLOCK_VARS list for this outer scope, but are strung off of the
22436 DECL_ARGUMENTS list for the function instead.
22438 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
22439 the LABEL_DECL nodes for the function however, and we output DWARF info
22440 for those in decls_for_scope. Just within the `outer_scope' there will be
22441 a BLOCK node representing the function's outermost pair of curly braces,
22442 and any blocks used for the base and member initializers of a C++
22443 constructor function. */
22444 tree outer_scope
= DECL_INITIAL (decl
);
22445 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
22447 int call_site_note_count
= 0;
22448 int tail_call_site_note_count
= 0;
22450 /* Emit a DW_TAG_variable DIE for a named return value. */
22451 if (DECL_NAME (DECL_RESULT (decl
)))
22452 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
22454 /* The first time through decls_for_scope we will generate the
22455 DIEs for the locals. The second time, we fill in the
22457 decls_for_scope (outer_scope
, subr_die
);
22459 if (call_arg_locations
&& (!dwarf_strict
|| dwarf_version
>= 5))
22461 struct call_arg_loc_node
*ca_loc
;
22462 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
22464 dw_die_ref die
= NULL
;
22465 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
22468 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
22469 ? NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
)
22471 arg
; arg
= next_arg
)
22473 dw_loc_descr_ref reg
, val
;
22474 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
22475 dw_die_ref cdie
, tdie
= NULL
;
22477 next_arg
= XEXP (arg
, 1);
22478 if (REG_P (XEXP (XEXP (arg
, 0), 0))
22480 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
22481 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
22482 && REGNO (XEXP (XEXP (arg
, 0), 0))
22483 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
22484 next_arg
= XEXP (next_arg
, 1);
22485 if (mode
== VOIDmode
)
22487 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
22488 if (mode
== VOIDmode
)
22489 mode
= GET_MODE (XEXP (arg
, 0));
22491 if (mode
== VOIDmode
|| mode
== BLKmode
)
22493 /* Get dynamic information about call target only if we
22494 have no static information: we cannot generate both
22495 DW_AT_call_origin and DW_AT_call_target
22497 if (ca_loc
->symbol_ref
== NULL_RTX
)
22499 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
22501 tloc
= XEXP (XEXP (arg
, 0), 1);
22504 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
22505 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
22507 tlocc
= XEXP (XEXP (arg
, 0), 1);
22512 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
22513 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
22514 VAR_INIT_STATUS_INITIALIZED
);
22515 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
22517 rtx mem
= XEXP (XEXP (arg
, 0), 0);
22518 reg
= mem_loc_descriptor (XEXP (mem
, 0),
22519 get_address_mode (mem
),
22521 VAR_INIT_STATUS_INITIALIZED
);
22523 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
22524 == DEBUG_PARAMETER_REF
)
22527 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
22528 tdie
= lookup_decl_die (tdecl
);
22535 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
22536 != DEBUG_PARAMETER_REF
)
22538 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
22540 VAR_INIT_STATUS_INITIALIZED
);
22544 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22545 cdie
= new_die (dwarf_TAG (DW_TAG_call_site_parameter
), die
,
22548 add_AT_loc (cdie
, DW_AT_location
, reg
);
22549 else if (tdie
!= NULL
)
22550 add_AT_die_ref (cdie
, dwarf_AT (DW_AT_call_parameter
),
22552 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_value
), val
);
22553 if (next_arg
!= XEXP (arg
, 1))
22555 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
22556 if (mode
== VOIDmode
)
22557 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
22558 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
22561 VAR_INIT_STATUS_INITIALIZED
);
22563 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_data_value
),
22568 && (ca_loc
->symbol_ref
|| tloc
))
22569 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22570 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
22572 dw_loc_descr_ref tval
= NULL
;
22574 if (tloc
!= NULL_RTX
)
22575 tval
= mem_loc_descriptor (tloc
,
22576 GET_MODE (tloc
) == VOIDmode
22577 ? Pmode
: GET_MODE (tloc
),
22579 VAR_INIT_STATUS_INITIALIZED
);
22581 add_AT_loc (die
, dwarf_AT (DW_AT_call_target
), tval
);
22582 else if (tlocc
!= NULL_RTX
)
22584 tval
= mem_loc_descriptor (tlocc
,
22585 GET_MODE (tlocc
) == VOIDmode
22586 ? Pmode
: GET_MODE (tlocc
),
22588 VAR_INIT_STATUS_INITIALIZED
);
22591 dwarf_AT (DW_AT_call_target_clobbered
),
22597 call_site_note_count
++;
22598 if (ca_loc
->tail_call_p
)
22599 tail_call_site_note_count
++;
22603 call_arg_locations
= NULL
;
22604 call_arg_loc_last
= NULL
;
22605 if (tail_call_site_count
>= 0
22606 && tail_call_site_count
== tail_call_site_note_count
22607 && (!dwarf_strict
|| dwarf_version
>= 5))
22609 if (call_site_count
>= 0
22610 && call_site_count
== call_site_note_count
)
22611 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_calls
), 1);
22613 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_tail_calls
), 1);
22615 call_site_count
= -1;
22616 tail_call_site_count
= -1;
22619 /* Mark used types after we have created DIEs for the functions scopes. */
22620 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
22623 /* Returns a hash value for X (which really is a die_struct). */
22626 block_die_hasher::hash (die_struct
*d
)
22628 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
22631 /* Return nonzero if decl_id and die_parent of die_struct X is the same
22632 as decl_id and die_parent of die_struct Y. */
22635 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
22637 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
22640 /* Return TRUE if DECL, which may have been previously generated as
22641 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
22642 true if decl (or its origin) is either an extern declaration or a
22643 class/namespace scoped declaration.
22645 The declare_in_namespace support causes us to get two DIEs for one
22646 variable, both of which are declarations. We want to avoid
22647 considering one to be a specification, so we must test for
22648 DECLARATION and DW_AT_declaration. */
22650 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
22652 return (old_die
&& TREE_STATIC (decl
) && !declaration
22653 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
22656 /* Return true if DECL is a local static. */
22659 local_function_static (tree decl
)
22661 gcc_assert (VAR_P (decl
));
22662 return TREE_STATIC (decl
)
22663 && DECL_CONTEXT (decl
)
22664 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
22667 /* Generate a DIE to represent a declared data object.
22668 Either DECL or ORIGIN must be non-null. */
22671 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
22673 HOST_WIDE_INT off
= 0;
22675 tree decl_or_origin
= decl
? decl
: origin
;
22676 tree ultimate_origin
;
22677 dw_die_ref var_die
;
22678 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
22679 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
22680 || class_or_namespace_scope_p (context_die
));
22681 bool specialization_p
= false;
22682 bool no_linkage_name
= false;
22684 /* While C++ inline static data members have definitions inside of the
22685 class, force the first DIE to be a declaration, then let gen_member_die
22686 reparent it to the class context and call gen_variable_die again
22687 to create the outside of the class DIE for the definition. */
22691 && DECL_CONTEXT (decl
)
22692 && TYPE_P (DECL_CONTEXT (decl
))
22693 && lang_hooks
.decls
.decl_dwarf_attribute (decl
, DW_AT_inline
) != -1)
22695 declaration
= true;
22696 if (dwarf_version
< 5)
22697 no_linkage_name
= true;
22700 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
22701 if (decl
|| ultimate_origin
)
22702 origin
= ultimate_origin
;
22703 com_decl
= fortran_common (decl_or_origin
, &off
);
22705 /* Symbol in common gets emitted as a child of the common block, in the form
22706 of a data member. */
22709 dw_die_ref com_die
;
22710 dw_loc_list_ref loc
= NULL
;
22711 die_node com_die_arg
;
22713 var_die
= lookup_decl_die (decl_or_origin
);
22716 if (! early_dwarf
&& get_AT (var_die
, DW_AT_location
) == NULL
)
22718 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
22723 /* Optimize the common case. */
22724 if (single_element_loc_list_p (loc
)
22725 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22726 && loc
->expr
->dw_loc_next
== NULL
22727 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
22730 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22731 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22732 = plus_constant (GET_MODE (x
), x
, off
);
22735 loc_list_plus_const (loc
, off
);
22737 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22738 remove_AT (var_die
, DW_AT_declaration
);
22744 if (common_block_die_table
== NULL
)
22745 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
22747 com_die_arg
.decl_id
= DECL_UID (com_decl
);
22748 com_die_arg
.die_parent
= context_die
;
22749 com_die
= common_block_die_table
->find (&com_die_arg
);
22751 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22752 if (com_die
== NULL
)
22755 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
22758 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
22759 add_name_and_src_coords_attributes (com_die
, com_decl
);
22762 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22763 /* Avoid sharing the same loc descriptor between
22764 DW_TAG_common_block and DW_TAG_variable. */
22765 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22767 else if (DECL_EXTERNAL (decl_or_origin
))
22768 add_AT_flag (com_die
, DW_AT_declaration
, 1);
22769 if (want_pubnames ())
22770 add_pubname_string (cnam
, com_die
); /* ??? needed? */
22771 com_die
->decl_id
= DECL_UID (com_decl
);
22772 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
22775 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
22777 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22778 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22779 remove_AT (com_die
, DW_AT_declaration
);
22781 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
22782 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
22783 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
22784 decl_quals (decl_or_origin
), false,
22786 add_alignment_attribute (var_die
, decl
);
22787 add_AT_flag (var_die
, DW_AT_external
, 1);
22792 /* Optimize the common case. */
22793 if (single_element_loc_list_p (loc
)
22794 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22795 && loc
->expr
->dw_loc_next
== NULL
22796 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
22798 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22799 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22800 = plus_constant (GET_MODE (x
), x
, off
);
22803 loc_list_plus_const (loc
, off
);
22805 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22807 else if (DECL_EXTERNAL (decl_or_origin
))
22808 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22810 equate_decl_number_to_die (decl
, var_die
);
22818 /* A declaration that has been previously dumped, needs no
22819 further annotations, since it doesn't need location on
22820 the second pass. */
22823 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
22824 && !get_AT (old_die
, DW_AT_specification
))
22826 /* Fall-thru so we can make a new variable die along with a
22827 DW_AT_specification. */
22829 else if (origin
&& old_die
->die_parent
!= context_die
)
22831 /* If we will be creating an inlined instance, we need a
22832 new DIE that will get annotated with
22833 DW_AT_abstract_origin. Clear things so we can get a
22835 gcc_assert (!DECL_ABSTRACT_P (decl
));
22840 /* If a DIE was dumped early, it still needs location info.
22841 Skip to where we fill the location bits. */
22843 goto gen_variable_die_location
;
22847 /* For static data members, the declaration in the class is supposed
22848 to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
22849 also in DWARF2; the specification should still be DW_TAG_variable
22850 referencing the DW_TAG_member DIE. */
22851 if (declaration
&& class_scope_p (context_die
) && dwarf_version
< 5)
22852 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
22854 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
22856 if (origin
!= NULL
)
22857 add_abstract_origin_attribute (var_die
, origin
);
22859 /* Loop unrolling can create multiple blocks that refer to the same
22860 static variable, so we must test for the DW_AT_declaration flag.
22862 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
22863 copy decls and set the DECL_ABSTRACT_P flag on them instead of
22866 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
22867 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
22869 /* This is a definition of a C++ class level static. */
22870 add_AT_specification (var_die
, old_die
);
22871 specialization_p
= true;
22872 if (DECL_NAME (decl
))
22874 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
22875 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
22877 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
22878 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
22880 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
22881 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
22883 if (debug_column_info
22885 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
22886 != (unsigned) s
.column
))
22887 add_AT_unsigned (var_die
, DW_AT_decl_column
, s
.column
);
22889 if (old_die
->die_tag
== DW_TAG_member
)
22890 add_linkage_name (var_die
, decl
);
22894 add_name_and_src_coords_attributes (var_die
, decl
, no_linkage_name
);
22896 if ((origin
== NULL
&& !specialization_p
)
22898 && !DECL_ABSTRACT_P (decl_or_origin
)
22899 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
22900 decl_function_context
22901 (decl_or_origin
))))
22903 tree type
= TREE_TYPE (decl_or_origin
);
22905 if (decl_by_reference_p (decl_or_origin
))
22906 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
22909 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
22913 if (origin
== NULL
&& !specialization_p
)
22915 if (TREE_PUBLIC (decl
))
22916 add_AT_flag (var_die
, DW_AT_external
, 1);
22918 if (DECL_ARTIFICIAL (decl
))
22919 add_AT_flag (var_die
, DW_AT_artificial
, 1);
22921 add_alignment_attribute (var_die
, decl
);
22923 add_accessibility_attribute (var_die
, decl
);
22927 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22929 if (decl
&& (DECL_ABSTRACT_P (decl
)
22930 || !old_die
|| is_declaration_die (old_die
)))
22931 equate_decl_number_to_die (decl
, var_die
);
22933 gen_variable_die_location
:
22935 && (! DECL_ABSTRACT_P (decl_or_origin
)
22936 /* Local static vars are shared between all clones/inlines,
22937 so emit DW_AT_location on the abstract DIE if DECL_RTL is
22939 || (VAR_P (decl_or_origin
)
22940 && TREE_STATIC (decl_or_origin
)
22941 && DECL_RTL_SET_P (decl_or_origin
))))
22944 add_pubname (decl_or_origin
, var_die
);
22946 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
22950 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
22952 if ((dwarf_version
>= 4 || !dwarf_strict
)
22953 && lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
22954 DW_AT_const_expr
) == 1
22955 && !get_AT (var_die
, DW_AT_const_expr
)
22956 && !specialization_p
)
22957 add_AT_flag (var_die
, DW_AT_const_expr
, 1);
22961 int inl
= lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
22964 && !get_AT (var_die
, DW_AT_inline
)
22965 && !specialization_p
)
22966 add_AT_unsigned (var_die
, DW_AT_inline
, inl
);
22970 /* Generate a DIE to represent a named constant. */
22973 gen_const_die (tree decl
, dw_die_ref context_die
)
22975 dw_die_ref const_die
;
22976 tree type
= TREE_TYPE (decl
);
22978 const_die
= lookup_decl_die (decl
);
22982 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
22983 equate_decl_number_to_die (decl
, const_die
);
22984 add_name_and_src_coords_attributes (const_die
, decl
);
22985 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
22986 if (TREE_PUBLIC (decl
))
22987 add_AT_flag (const_die
, DW_AT_external
, 1);
22988 if (DECL_ARTIFICIAL (decl
))
22989 add_AT_flag (const_die
, DW_AT_artificial
, 1);
22990 tree_add_const_value_attribute_for_decl (const_die
, decl
);
22993 /* Generate a DIE to represent a label identifier. */
22996 gen_label_die (tree decl
, dw_die_ref context_die
)
22998 tree origin
= decl_ultimate_origin (decl
);
22999 dw_die_ref lbl_die
= lookup_decl_die (decl
);
23001 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23005 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
23006 equate_decl_number_to_die (decl
, lbl_die
);
23008 if (origin
!= NULL
)
23009 add_abstract_origin_attribute (lbl_die
, origin
);
23011 add_name_and_src_coords_attributes (lbl_die
, decl
);
23014 if (DECL_ABSTRACT_P (decl
))
23015 equate_decl_number_to_die (decl
, lbl_die
);
23016 else if (! early_dwarf
)
23018 insn
= DECL_RTL_IF_SET (decl
);
23020 /* Deleted labels are programmer specified labels which have been
23021 eliminated because of various optimizations. We still emit them
23022 here so that it is possible to put breakpoints on them. */
23026 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
23028 /* When optimization is enabled (via -O) some parts of the compiler
23029 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
23030 represent source-level labels which were explicitly declared by
23031 the user. This really shouldn't be happening though, so catch
23032 it if it ever does happen. */
23033 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
23035 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
23036 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23040 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
23041 && CODE_LABEL_NUMBER (insn
) != -1)
23043 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
23044 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23049 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
23050 attributes to the DIE for a block STMT, to describe where the inlined
23051 function was called from. This is similar to add_src_coords_attributes. */
23054 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
23056 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
23058 if (dwarf_version
>= 3 || !dwarf_strict
)
23060 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
23061 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
23062 if (debug_column_info
&& s
.column
)
23063 add_AT_unsigned (die
, DW_AT_call_column
, s
.column
);
23068 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
23069 Add low_pc and high_pc attributes to the DIE for a block STMT. */
23072 add_high_low_attributes (tree stmt
, dw_die_ref die
)
23074 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23076 if (BLOCK_FRAGMENT_CHAIN (stmt
)
23077 && (dwarf_version
>= 3 || !dwarf_strict
))
23079 tree chain
, superblock
= NULL_TREE
;
23081 dw_attr_node
*attr
= NULL
;
23083 if (inlined_function_outer_scope_p (stmt
))
23085 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23086 BLOCK_NUMBER (stmt
));
23087 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
23090 /* Optimize duplicate .debug_ranges lists or even tails of
23091 lists. If this BLOCK has same ranges as its supercontext,
23092 lookup DW_AT_ranges attribute in the supercontext (and
23093 recursively so), verify that the ranges_table contains the
23094 right values and use it instead of adding a new .debug_range. */
23095 for (chain
= stmt
, pdie
= die
;
23096 BLOCK_SAME_RANGE (chain
);
23097 chain
= BLOCK_SUPERCONTEXT (chain
))
23099 dw_attr_node
*new_attr
;
23101 pdie
= pdie
->die_parent
;
23104 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
23106 new_attr
= get_AT (pdie
, DW_AT_ranges
);
23107 if (new_attr
== NULL
23108 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
23111 superblock
= BLOCK_SUPERCONTEXT (chain
);
23114 && ((*ranges_table
)[attr
->dw_attr_val
.v
.val_offset
].num
23115 == BLOCK_NUMBER (superblock
))
23116 && BLOCK_FRAGMENT_CHAIN (superblock
))
23118 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
;
23119 unsigned long supercnt
= 0, thiscnt
= 0;
23120 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
23121 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23124 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
].num
23125 == BLOCK_NUMBER (chain
));
23127 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
+ 1].num
== 0);
23128 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23129 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23131 gcc_assert (supercnt
>= thiscnt
);
23132 add_AT_range_list (die
, DW_AT_ranges
, off
+ supercnt
- thiscnt
,
23134 note_rnglist_head (off
+ supercnt
- thiscnt
);
23138 unsigned int offset
= add_ranges (stmt
, true);
23139 add_AT_range_list (die
, DW_AT_ranges
, offset
, false);
23140 note_rnglist_head (offset
);
23142 bool prev_in_cold
= BLOCK_IN_COLD_SECTION_P (stmt
);
23143 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23146 add_ranges (chain
, prev_in_cold
!= BLOCK_IN_COLD_SECTION_P (chain
));
23147 prev_in_cold
= BLOCK_IN_COLD_SECTION_P (chain
);
23148 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
23155 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
23156 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23157 BLOCK_NUMBER (stmt
));
23158 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
23159 BLOCK_NUMBER (stmt
));
23160 add_AT_low_high_pc (die
, label
, label_high
, false);
23164 /* Generate a DIE for a lexical block. */
23167 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
23169 dw_die_ref old_die
= BLOCK_DIE (stmt
);
23170 dw_die_ref stmt_die
= NULL
;
23173 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23174 BLOCK_DIE (stmt
) = stmt_die
;
23177 if (BLOCK_ABSTRACT (stmt
))
23181 /* This must have been generated early and it won't even
23182 need location information since it's a DW_AT_inline
23185 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
23186 if (c
->die_tag
== DW_TAG_inlined_subroutine
23187 || c
->die_tag
== DW_TAG_subprogram
)
23189 gcc_assert (get_AT (c
, DW_AT_inline
));
23195 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
23197 /* If this is an inlined instance, create a new lexical die for
23198 anything below to attach DW_AT_abstract_origin to. */
23201 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23202 BLOCK_DIE (stmt
) = stmt_die
;
23206 tree origin
= block_ultimate_origin (stmt
);
23207 if (origin
!= NULL_TREE
&& origin
!= stmt
)
23208 add_abstract_origin_attribute (stmt_die
, origin
);
23212 stmt_die
= old_die
;
23214 /* A non abstract block whose blocks have already been reordered
23215 should have the instruction range for this block. If so, set the
23216 high/low attributes. */
23217 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
23219 gcc_assert (stmt_die
);
23220 add_high_low_attributes (stmt
, stmt_die
);
23223 decls_for_scope (stmt
, stmt_die
);
23226 /* Generate a DIE for an inlined subprogram. */
23229 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
23233 /* The instance of function that is effectively being inlined shall not
23235 gcc_assert (! BLOCK_ABSTRACT (stmt
));
23237 decl
= block_ultimate_origin (stmt
);
23239 /* Make sure any inlined functions are known to be inlineable. */
23240 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
23241 || cgraph_function_possibly_inlined_p (decl
));
23243 /* Emit info for the abstract instance first, if we haven't yet. We
23244 must emit this even if the block is abstract, otherwise when we
23245 emit the block below (or elsewhere), we may end up trying to emit
23246 a die whose origin die hasn't been emitted, and crashing. */
23247 dwarf2out_abstract_function (decl
);
23249 if (! BLOCK_ABSTRACT (stmt
))
23251 dw_die_ref subr_die
23252 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
23254 if (call_arg_locations
)
23255 BLOCK_DIE (stmt
) = subr_die
;
23256 add_abstract_origin_attribute (subr_die
, decl
);
23257 if (TREE_ASM_WRITTEN (stmt
))
23258 add_high_low_attributes (stmt
, subr_die
);
23259 add_call_src_coords_attributes (stmt
, subr_die
);
23261 decls_for_scope (stmt
, subr_die
);
23265 /* Generate a DIE for a field in a record, or structure. CTX is required: see
23266 the comment for VLR_CONTEXT. */
23269 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
23271 dw_die_ref decl_die
;
23273 if (TREE_TYPE (decl
) == error_mark_node
)
23276 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
23277 add_name_and_src_coords_attributes (decl_die
, decl
);
23278 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
23279 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
23282 if (DECL_BIT_FIELD_TYPE (decl
))
23284 add_byte_size_attribute (decl_die
, decl
);
23285 add_bit_size_attribute (decl_die
, decl
);
23286 add_bit_offset_attribute (decl_die
, decl
, ctx
);
23289 add_alignment_attribute (decl_die
, decl
);
23291 /* If we have a variant part offset, then we are supposed to process a member
23292 of a QUAL_UNION_TYPE, which is how we represent variant parts in
23294 gcc_assert (ctx
->variant_part_offset
== NULL_TREE
23295 || TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != QUAL_UNION_TYPE
);
23296 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
23297 add_data_member_location_attribute (decl_die
, decl
, ctx
);
23299 if (DECL_ARTIFICIAL (decl
))
23300 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
23302 add_accessibility_attribute (decl_die
, decl
);
23304 /* Equate decl number to die, so that we can look up this decl later on. */
23305 equate_decl_number_to_die (decl
, decl_die
);
23309 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
23310 Use modified_type_die instead.
23311 We keep this code here just in case these types of DIEs may be needed to
23312 represent certain things in other languages (e.g. Pascal) someday. */
23315 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
23318 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
23320 equate_type_number_to_die (type
, ptr_die
);
23321 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23323 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
23326 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
23327 Use modified_type_die instead.
23328 We keep this code here just in case these types of DIEs may be needed to
23329 represent certain things in other languages (e.g. Pascal) someday. */
23332 gen_reference_type_die (tree type
, dw_die_ref context_die
)
23334 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
23336 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
23337 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
23339 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
23341 equate_type_number_to_die (type
, ref_die
);
23342 add_type_attribute (ref_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23344 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
23348 /* Generate a DIE for a pointer to a member type. TYPE can be an
23349 OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
23350 pointer to member function. */
23353 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
23355 if (lookup_type_die (type
))
23358 dw_die_ref ptr_die
= new_die (DW_TAG_ptr_to_member_type
,
23359 scope_die_for (type
, context_die
), type
);
23361 equate_type_number_to_die (type
, ptr_die
);
23362 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
23363 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
23364 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23366 add_alignment_attribute (ptr_die
, type
);
23368 if (TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
23369 && TREE_CODE (TREE_TYPE (type
)) != METHOD_TYPE
)
23371 dw_loc_descr_ref op
= new_loc_descr (DW_OP_plus
, 0, 0);
23372 add_AT_loc (ptr_die
, DW_AT_use_location
, op
);
23376 static char *producer_string
;
23378 /* Return a heap allocated producer string including command line options
23379 if -grecord-gcc-switches. */
23382 gen_producer_string (void)
23385 auto_vec
<const char *> switches
;
23386 const char *language_string
= lang_hooks
.name
;
23387 char *producer
, *tail
;
23389 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
23390 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
23392 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
23393 switch (save_decoded_options
[j
].opt_index
)
23400 case OPT_auxbase_strip
:
23409 case OPT_SPECIAL_unknown
:
23410 case OPT_SPECIAL_ignore
:
23411 case OPT_SPECIAL_program_name
:
23412 case OPT_SPECIAL_input_file
:
23413 case OPT_grecord_gcc_switches
:
23414 case OPT_gno_record_gcc_switches
:
23415 case OPT__output_pch_
:
23416 case OPT_fdiagnostics_show_location_
:
23417 case OPT_fdiagnostics_show_option
:
23418 case OPT_fdiagnostics_show_caret
:
23419 case OPT_fdiagnostics_color_
:
23420 case OPT_fverbose_asm
:
23422 case OPT__sysroot_
:
23424 case OPT_nostdinc__
:
23425 case OPT_fpreprocessed
:
23426 case OPT_fltrans_output_list_
:
23427 case OPT_fresolution_
:
23428 case OPT_fdebug_prefix_map_
:
23429 /* Ignore these. */
23432 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
23433 & CL_NO_DWARF_RECORD
)
23435 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
23437 switch (save_decoded_options
[j
].canonical_option
[0][1])
23444 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
23451 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
23452 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
23456 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
23458 sprintf (tail
, "%s %s", language_string
, version_string
);
23461 FOR_EACH_VEC_ELT (switches
, j
, p
)
23465 memcpy (tail
+ 1, p
, len
);
23473 /* Given a C and/or C++ language/version string return the "highest".
23474 C++ is assumed to be "higher" than C in this case. Used for merging
23475 LTO translation unit languages. */
23476 static const char *
23477 highest_c_language (const char *lang1
, const char *lang2
)
23479 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
23480 return "GNU C++14";
23481 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
23482 return "GNU C++11";
23483 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
23484 return "GNU C++98";
23486 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
23488 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
23490 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
23493 gcc_unreachable ();
23497 /* Generate the DIE for the compilation unit. */
23500 gen_compile_unit_die (const char *filename
)
23503 const char *language_string
= lang_hooks
.name
;
23506 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
23510 add_name_attribute (die
, filename
);
23511 /* Don't add cwd for <built-in>. */
23512 if (filename
[0] != '<')
23513 add_comp_dir_attribute (die
);
23516 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
23518 /* If our producer is LTO try to figure out a common language to use
23519 from the global list of translation units. */
23520 if (strcmp (language_string
, "GNU GIMPLE") == 0)
23524 const char *common_lang
= NULL
;
23526 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
23528 if (!TRANSLATION_UNIT_LANGUAGE (t
))
23531 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
23532 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
23534 else if (strncmp (common_lang
, "GNU C", 5) == 0
23535 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
23536 /* Mixing C and C++ is ok, use C++ in that case. */
23537 common_lang
= highest_c_language (common_lang
,
23538 TRANSLATION_UNIT_LANGUAGE (t
));
23541 /* Fall back to C. */
23542 common_lang
= NULL
;
23548 language_string
= common_lang
;
23551 language
= DW_LANG_C
;
23552 if (strncmp (language_string
, "GNU C", 5) == 0
23553 && ISDIGIT (language_string
[5]))
23555 language
= DW_LANG_C89
;
23556 if (dwarf_version
>= 3 || !dwarf_strict
)
23558 if (strcmp (language_string
, "GNU C89") != 0)
23559 language
= DW_LANG_C99
;
23561 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23562 if (strcmp (language_string
, "GNU C11") == 0)
23563 language
= DW_LANG_C11
;
23566 else if (strncmp (language_string
, "GNU C++", 7) == 0)
23568 language
= DW_LANG_C_plus_plus
;
23569 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23571 if (strcmp (language_string
, "GNU C++11") == 0)
23572 language
= DW_LANG_C_plus_plus_11
;
23573 else if (strcmp (language_string
, "GNU C++14") == 0)
23574 language
= DW_LANG_C_plus_plus_14
;
23577 else if (strcmp (language_string
, "GNU F77") == 0)
23578 language
= DW_LANG_Fortran77
;
23579 else if (strcmp (language_string
, "GNU Pascal") == 0)
23580 language
= DW_LANG_Pascal83
;
23581 else if (dwarf_version
>= 3 || !dwarf_strict
)
23583 if (strcmp (language_string
, "GNU Ada") == 0)
23584 language
= DW_LANG_Ada95
;
23585 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23587 language
= DW_LANG_Fortran95
;
23588 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23590 if (strcmp (language_string
, "GNU Fortran2003") == 0)
23591 language
= DW_LANG_Fortran03
;
23592 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
23593 language
= DW_LANG_Fortran08
;
23596 else if (strcmp (language_string
, "GNU Java") == 0)
23597 language
= DW_LANG_Java
;
23598 else if (strcmp (language_string
, "GNU Objective-C") == 0)
23599 language
= DW_LANG_ObjC
;
23600 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
23601 language
= DW_LANG_ObjC_plus_plus
;
23602 else if (dwarf_version
>= 5 || !dwarf_strict
)
23604 if (strcmp (language_string
, "GNU Go") == 0)
23605 language
= DW_LANG_Go
;
23608 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
23609 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23610 language
= DW_LANG_Fortran90
;
23612 add_AT_unsigned (die
, DW_AT_language
, language
);
23616 case DW_LANG_Fortran77
:
23617 case DW_LANG_Fortran90
:
23618 case DW_LANG_Fortran95
:
23619 case DW_LANG_Fortran03
:
23620 case DW_LANG_Fortran08
:
23621 /* Fortran has case insensitive identifiers and the front-end
23622 lowercases everything. */
23623 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
23626 /* The default DW_ID_case_sensitive doesn't need to be specified. */
23632 /* Generate the DIE for a base class. */
23635 gen_inheritance_die (tree binfo
, tree access
, tree type
,
23636 dw_die_ref context_die
)
23638 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
23639 struct vlr_context ctx
= { type
, NULL
};
23641 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
23643 add_data_member_location_attribute (die
, binfo
, &ctx
);
23645 if (BINFO_VIRTUAL_P (binfo
))
23646 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
23648 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
23649 children, otherwise the default is DW_ACCESS_public. In DWARF2
23650 the default has always been DW_ACCESS_private. */
23651 if (access
== access_public_node
)
23653 if (dwarf_version
== 2
23654 || context_die
->die_tag
== DW_TAG_class_type
)
23655 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
23657 else if (access
== access_protected_node
)
23658 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
23659 else if (dwarf_version
> 2
23660 && context_die
->die_tag
!= DW_TAG_class_type
)
23661 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
23664 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
23667 is_variant_part (tree decl
)
23669 return (TREE_CODE (decl
) == FIELD_DECL
23670 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
23673 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
23674 return the FIELD_DECL. Return NULL_TREE otherwise. */
23677 analyze_discr_in_predicate (tree operand
, tree struct_type
)
23679 bool continue_stripping
= true;
23680 while (continue_stripping
)
23681 switch (TREE_CODE (operand
))
23684 operand
= TREE_OPERAND (operand
, 0);
23687 continue_stripping
= false;
23691 /* Match field access to members of struct_type only. */
23692 if (TREE_CODE (operand
) == COMPONENT_REF
23693 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
23694 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
23695 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
23696 return TREE_OPERAND (operand
, 1);
23701 /* Check that SRC is a constant integer that can be represented as a native
23702 integer constant (either signed or unsigned). If so, store it into DEST and
23703 return true. Return false otherwise. */
23706 get_discr_value (tree src
, dw_discr_value
*dest
)
23708 tree discr_type
= TREE_TYPE (src
);
23710 if (lang_hooks
.types
.get_debug_type
)
23712 tree debug_type
= lang_hooks
.types
.get_debug_type (discr_type
);
23713 if (debug_type
!= NULL
)
23714 discr_type
= debug_type
;
23717 if (TREE_CODE (src
) != INTEGER_CST
|| !INTEGRAL_TYPE_P (discr_type
))
23720 /* Signedness can vary between the original type and the debug type. This
23721 can happen for character types in Ada for instance: the character type
23722 used for code generation can be signed, to be compatible with the C one,
23723 but from a debugger point of view, it must be unsigned. */
23724 bool is_orig_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
23725 bool is_debug_unsigned
= TYPE_UNSIGNED (discr_type
);
23727 if (is_orig_unsigned
!= is_debug_unsigned
)
23728 src
= fold_convert (discr_type
, src
);
23730 if (!(is_debug_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
23733 dest
->pos
= is_debug_unsigned
;
23734 if (is_debug_unsigned
)
23735 dest
->v
.uval
= tree_to_uhwi (src
);
23737 dest
->v
.sval
= tree_to_shwi (src
);
23742 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
23743 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
23744 store NULL_TREE in DISCR_DECL. Otherwise:
23746 - store the discriminant field in STRUCT_TYPE that controls the variant
23747 part to *DISCR_DECL
23749 - put in *DISCR_LISTS_P an array where for each variant, the item
23750 represents the corresponding matching list of discriminant values.
23752 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
23755 Note that when the array is allocated (i.e. when the analysis is
23756 successful), it is up to the caller to free the array. */
23759 analyze_variants_discr (tree variant_part_decl
,
23762 dw_discr_list_ref
**discr_lists_p
,
23763 unsigned *discr_lists_length
)
23765 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23767 dw_discr_list_ref
*discr_lists
;
23770 /* Compute how many variants there are in this variant part. */
23771 *discr_lists_length
= 0;
23772 for (variant
= TYPE_FIELDS (variant_part_type
);
23773 variant
!= NULL_TREE
;
23774 variant
= DECL_CHAIN (variant
))
23775 ++*discr_lists_length
;
23777 *discr_decl
= NULL_TREE
;
23779 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
23780 sizeof (**discr_lists_p
));
23781 discr_lists
= *discr_lists_p
;
23783 /* And then analyze all variants to extract discriminant information for all
23784 of them. This analysis is conservative: as soon as we detect something we
23785 do not support, abort everything and pretend we found nothing. */
23786 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
23787 variant
!= NULL_TREE
;
23788 variant
= DECL_CHAIN (variant
), ++i
)
23790 tree match_expr
= DECL_QUALIFIER (variant
);
23792 /* Now, try to analyze the predicate and deduce a discriminant for
23794 if (match_expr
== boolean_true_node
)
23795 /* Typically happens for the default variant: it matches all cases that
23796 previous variants rejected. Don't output any matching value for
23800 /* The following loop tries to iterate over each discriminant
23801 possibility: single values or ranges. */
23802 while (match_expr
!= NULL_TREE
)
23804 tree next_round_match_expr
;
23805 tree candidate_discr
= NULL_TREE
;
23806 dw_discr_list_ref new_node
= NULL
;
23808 /* Possibilities are matched one after the other by nested
23809 TRUTH_ORIF_EXPR expressions. Process the current possibility and
23810 continue with the rest at next iteration. */
23811 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
23813 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
23814 match_expr
= TREE_OPERAND (match_expr
, 1);
23817 next_round_match_expr
= NULL_TREE
;
23819 if (match_expr
== boolean_false_node
)
23820 /* This sub-expression matches nothing: just wait for the next
23824 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
23826 /* We are matching: <discr_field> == <integer_cst>
23827 This sub-expression matches a single value. */
23828 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
23831 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
23834 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23835 if (!get_discr_value (integer_cst
,
23836 &new_node
->dw_discr_lower_bound
))
23838 new_node
->dw_discr_range
= false;
23841 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
23843 /* We are matching:
23844 <discr_field> > <integer_cst>
23845 && <discr_field> < <integer_cst>.
23846 This sub-expression matches the range of values between the
23847 two matched integer constants. Note that comparisons can be
23848 inclusive or exclusive. */
23849 tree candidate_discr_1
, candidate_discr_2
;
23850 tree lower_cst
, upper_cst
;
23851 bool lower_cst_included
, upper_cst_included
;
23852 tree lower_op
= TREE_OPERAND (match_expr
, 0);
23853 tree upper_op
= TREE_OPERAND (match_expr
, 1);
23855 /* When the comparison is exclusive, the integer constant is not
23856 the discriminant range bound we are looking for: we will have
23857 to increment or decrement it. */
23858 if (TREE_CODE (lower_op
) == GE_EXPR
)
23859 lower_cst_included
= true;
23860 else if (TREE_CODE (lower_op
) == GT_EXPR
)
23861 lower_cst_included
= false;
23865 if (TREE_CODE (upper_op
) == LE_EXPR
)
23866 upper_cst_included
= true;
23867 else if (TREE_CODE (upper_op
) == LT_EXPR
)
23868 upper_cst_included
= false;
23872 /* Extract the discriminant from the first operand and check it
23873 is consistant with the same analysis in the second
23876 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
23879 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
23881 if (candidate_discr_1
== candidate_discr_2
)
23882 candidate_discr
= candidate_discr_1
;
23886 /* Extract bounds from both. */
23887 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23888 lower_cst
= TREE_OPERAND (lower_op
, 1);
23889 upper_cst
= TREE_OPERAND (upper_op
, 1);
23891 if (!lower_cst_included
)
23893 = fold_build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
), lower_cst
,
23894 build_int_cst (TREE_TYPE (lower_cst
), 1));
23895 if (!upper_cst_included
)
23897 = fold_build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
), upper_cst
,
23898 build_int_cst (TREE_TYPE (upper_cst
), 1));
23900 if (!get_discr_value (lower_cst
,
23901 &new_node
->dw_discr_lower_bound
)
23902 || !get_discr_value (upper_cst
,
23903 &new_node
->dw_discr_upper_bound
))
23906 new_node
->dw_discr_range
= true;
23910 /* Unsupported sub-expression: we cannot determine the set of
23911 matching discriminant values. Abort everything. */
23914 /* If the discriminant info is not consistant with what we saw so
23915 far, consider the analysis failed and abort everything. */
23916 if (candidate_discr
== NULL_TREE
23917 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
23920 *discr_decl
= candidate_discr
;
23922 if (new_node
!= NULL
)
23924 new_node
->dw_discr_next
= discr_lists
[i
];
23925 discr_lists
[i
] = new_node
;
23927 match_expr
= next_round_match_expr
;
23931 /* If we reach this point, we could match everything we were interested
23936 /* Clean all data structure and return no result. */
23937 free (*discr_lists_p
);
23938 *discr_lists_p
= NULL
;
23939 *discr_decl
= NULL_TREE
;
23942 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
23943 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
23946 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
23947 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
23948 this type, which are record types, represent the available variants and each
23949 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
23950 values are inferred from these attributes.
23952 In trees, the offsets for the fields inside these sub-records are relative
23953 to the variant part itself, whereas the corresponding DIEs should have
23954 offset attributes that are relative to the embedding record base address.
23955 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
23956 must be an expression that computes the offset of the variant part to
23957 describe in DWARF. */
23960 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
23961 dw_die_ref context_die
)
23963 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23964 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
23965 struct loc_descr_context ctx
= {
23966 vlr_ctx
->struct_type
, /* context_type */
23967 NULL_TREE
, /* base_decl */
23969 false, /* placeholder_arg */
23970 false /* placeholder_seen */
23973 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
23974 NULL_TREE if there is no such field. */
23975 tree discr_decl
= NULL_TREE
;
23976 dw_discr_list_ref
*discr_lists
;
23977 unsigned discr_lists_length
= 0;
23980 dw_die_ref dwarf_proc_die
= NULL
;
23981 dw_die_ref variant_part_die
23982 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
23984 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
23986 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
23987 &discr_decl
, &discr_lists
, &discr_lists_length
);
23989 if (discr_decl
!= NULL_TREE
)
23991 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
23994 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
23996 /* We have no DIE for the discriminant, so just discard all
23997 discrimimant information in the output. */
23998 discr_decl
= NULL_TREE
;
24001 /* If the offset for this variant part is more complex than a constant,
24002 create a DWARF procedure for it so that we will not have to generate DWARF
24003 expressions for it for each member. */
24004 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
24005 && (dwarf_version
>= 3 || !dwarf_strict
))
24007 const tree dwarf_proc_fndecl
24008 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
24009 build_function_type (TREE_TYPE (variant_part_offset
),
24011 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
24012 const dw_loc_descr_ref dwarf_proc_body
24013 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
24015 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
24016 dwarf_proc_fndecl
, context_die
);
24017 if (dwarf_proc_die
!= NULL
)
24018 variant_part_offset
= dwarf_proc_call
;
24021 /* Output DIEs for all variants. */
24023 for (tree variant
= TYPE_FIELDS (variant_part_type
);
24024 variant
!= NULL_TREE
;
24025 variant
= DECL_CHAIN (variant
), ++i
)
24027 tree variant_type
= TREE_TYPE (variant
);
24028 dw_die_ref variant_die
;
24030 /* All variants (i.e. members of a variant part) are supposed to be
24031 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
24032 under these records. */
24033 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
24035 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
24036 equate_decl_number_to_die (variant
, variant_die
);
24038 /* Output discriminant values this variant matches, if any. */
24039 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
24040 /* In the case we have discriminant information at all, this is
24041 probably the default variant: as the standard says, don't
24042 output any discriminant value/list attribute. */
24044 else if (discr_lists
[i
]->dw_discr_next
== NULL
24045 && !discr_lists
[i
]->dw_discr_range
)
24046 /* If there is only one accepted value, don't bother outputting a
24048 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
24050 add_discr_list (variant_die
, discr_lists
[i
]);
24052 for (tree member
= TYPE_FIELDS (variant_type
);
24053 member
!= NULL_TREE
;
24054 member
= DECL_CHAIN (member
))
24056 struct vlr_context vlr_sub_ctx
= {
24057 vlr_ctx
->struct_type
, /* struct_type */
24058 NULL
/* variant_part_offset */
24060 if (is_variant_part (member
))
24062 /* All offsets for fields inside variant parts are relative to
24063 the top-level embedding RECORD_TYPE's base address. On the
24064 other hand, offsets in GCC's types are relative to the
24065 nested-most variant part. So we have to sum offsets each time
24068 vlr_sub_ctx
.variant_part_offset
24069 = fold_build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
24070 variant_part_offset
, byte_position (member
));
24071 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
24075 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
24076 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
24081 free (discr_lists
);
24084 /* Generate a DIE for a class member. */
24087 gen_member_die (tree type
, dw_die_ref context_die
)
24090 tree binfo
= TYPE_BINFO (type
);
24093 /* If this is not an incomplete type, output descriptions of each of its
24094 members. Note that as we output the DIEs necessary to represent the
24095 members of this record or union type, we will also be trying to output
24096 DIEs to represent the *types* of those members. However the `type'
24097 function (above) will specifically avoid generating type DIEs for member
24098 types *within* the list of member DIEs for this (containing) type except
24099 for those types (of members) which are explicitly marked as also being
24100 members of this (containing) type themselves. The g++ front- end can
24101 force any given type to be treated as a member of some other (containing)
24102 type by setting the TYPE_CONTEXT of the given (member) type to point to
24103 the TREE node representing the appropriate (containing) type. */
24105 /* First output info about the base classes. */
24108 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
24112 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
24113 gen_inheritance_die (base
,
24114 (accesses
? (*accesses
)[i
] : access_public_node
),
24119 /* Now output info about the data members and type members. */
24120 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
24122 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
24123 bool static_inline_p
24124 = (TREE_STATIC (member
)
24125 && (lang_hooks
.decls
.decl_dwarf_attribute (member
, DW_AT_inline
)
24128 /* If we thought we were generating minimal debug info for TYPE
24129 and then changed our minds, some of the member declarations
24130 may have already been defined. Don't define them again, but
24131 do put them in the right order. */
24133 child
= lookup_decl_die (member
);
24136 /* Handle inline static data members, which only have in-class
24138 dw_die_ref ref
= NULL
;
24139 if (child
->die_tag
== DW_TAG_variable
24140 && child
->die_parent
== comp_unit_die ())
24142 ref
= get_AT_ref (child
, DW_AT_specification
);
24143 /* For C++17 inline static data members followed by redundant
24144 out of class redeclaration, we might get here with
24145 child being the DIE created for the out of class
24146 redeclaration and with its DW_AT_specification being
24147 the DIE created for in-class definition. We want to
24148 reparent the latter, and don't want to create another
24149 DIE with DW_AT_specification in that case, because
24150 we already have one. */
24153 && ref
->die_tag
== DW_TAG_variable
24154 && ref
->die_parent
== comp_unit_die ()
24155 && get_AT (ref
, DW_AT_specification
) == NULL
)
24159 static_inline_p
= false;
24162 if (child
->die_tag
== DW_TAG_variable
24163 && child
->die_parent
== comp_unit_die ()
24166 reparent_child (child
, context_die
);
24167 if (dwarf_version
< 5)
24168 child
->die_tag
= DW_TAG_member
;
24171 splice_child_die (context_die
, child
);
24174 /* Do not generate standard DWARF for variant parts if we are generating
24175 the corresponding GNAT encodings: DIEs generated for both would
24176 conflict in our mappings. */
24177 else if (is_variant_part (member
)
24178 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
)
24180 vlr_ctx
.variant_part_offset
= byte_position (member
);
24181 gen_variant_part (member
, &vlr_ctx
, context_die
);
24185 vlr_ctx
.variant_part_offset
= NULL_TREE
;
24186 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
24189 /* For C++ inline static data members emit immediately a DW_TAG_variable
24190 DIE that will refer to that DW_TAG_member/DW_TAG_variable through
24191 DW_AT_specification. */
24192 if (static_inline_p
)
24194 int old_extern
= DECL_EXTERNAL (member
);
24195 DECL_EXTERNAL (member
) = 0;
24196 gen_decl_die (member
, NULL
, NULL
, comp_unit_die ());
24197 DECL_EXTERNAL (member
) = old_extern
;
24201 /* We do not keep type methods in type variants. */
24202 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
24203 /* Now output info about the function members (if any). */
24204 if (TYPE_METHODS (type
) != error_mark_node
)
24205 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
24207 /* Don't include clones in the member list. */
24208 if (DECL_ABSTRACT_ORIGIN (member
))
24210 /* Nor constructors for anonymous classes. */
24211 if (DECL_ARTIFICIAL (member
)
24212 && dwarf2_name (member
, 0) == NULL
)
24215 child
= lookup_decl_die (member
);
24217 splice_child_die (context_die
, child
);
24219 gen_decl_die (member
, NULL
, NULL
, context_die
);
24223 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
24224 is set, we pretend that the type was never defined, so we only get the
24225 member DIEs needed by later specification DIEs. */
24228 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
24229 enum debug_info_usage usage
)
24231 if (TREE_ASM_WRITTEN (type
))
24233 /* Fill in the bound of variable-length fields in late dwarf if
24234 still incomplete. */
24235 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
24236 for (tree member
= TYPE_FIELDS (type
);
24238 member
= DECL_CHAIN (member
))
24239 fill_variable_array_bounds (TREE_TYPE (member
));
24243 dw_die_ref type_die
= lookup_type_die (type
);
24244 dw_die_ref scope_die
= 0;
24246 int complete
= (TYPE_SIZE (type
)
24247 && (! TYPE_STUB_DECL (type
)
24248 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
24249 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
24250 complete
= complete
&& should_emit_struct_debug (type
, usage
);
24252 if (type_die
&& ! complete
)
24255 if (TYPE_CONTEXT (type
) != NULL_TREE
24256 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24257 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
24260 scope_die
= scope_die_for (type
, context_die
);
24262 /* Generate child dies for template paramaters. */
24263 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
24264 schedule_generic_params_dies_gen (type
);
24266 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
24267 /* First occurrence of type or toplevel definition of nested class. */
24269 dw_die_ref old_die
= type_die
;
24271 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
24272 ? record_type_tag (type
) : DW_TAG_union_type
,
24274 equate_type_number_to_die (type
, type_die
);
24276 add_AT_specification (type_die
, old_die
);
24278 add_name_attribute (type_die
, type_tag (type
));
24281 remove_AT (type_die
, DW_AT_declaration
);
24283 /* If this type has been completed, then give it a byte_size attribute and
24284 then give a list of members. */
24285 if (complete
&& !ns_decl
)
24287 /* Prevent infinite recursion in cases where the type of some member of
24288 this type is expressed in terms of this type itself. */
24289 TREE_ASM_WRITTEN (type
) = 1;
24290 add_byte_size_attribute (type_die
, type
);
24291 add_alignment_attribute (type_die
, type
);
24292 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
24294 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
24295 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
24298 /* If the first reference to this type was as the return type of an
24299 inline function, then it may not have a parent. Fix this now. */
24300 if (type_die
->die_parent
== NULL
)
24301 add_child_die (scope_die
, type_die
);
24303 push_decl_scope (type
);
24304 gen_member_die (type
, type_die
);
24307 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
24308 if (TYPE_ARTIFICIAL (type
))
24309 add_AT_flag (type_die
, DW_AT_artificial
, 1);
24311 /* GNU extension: Record what type our vtable lives in. */
24312 if (TYPE_VFIELD (type
))
24314 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
24316 gen_type_die (vtype
, context_die
);
24317 add_AT_die_ref (type_die
, DW_AT_containing_type
,
24318 lookup_type_die (vtype
));
24323 add_AT_flag (type_die
, DW_AT_declaration
, 1);
24325 /* We don't need to do this for function-local types. */
24326 if (TYPE_STUB_DECL (type
)
24327 && ! decl_function_context (TYPE_STUB_DECL (type
)))
24328 vec_safe_push (incomplete_types
, type
);
24331 if (get_AT (type_die
, DW_AT_name
))
24332 add_pubtype (type
, type_die
);
24335 /* Generate a DIE for a subroutine _type_. */
24338 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
24340 tree return_type
= TREE_TYPE (type
);
24341 dw_die_ref subr_die
24342 = new_die (DW_TAG_subroutine_type
,
24343 scope_die_for (type
, context_die
), type
);
24345 equate_type_number_to_die (type
, subr_die
);
24346 add_prototyped_attribute (subr_die
, type
);
24347 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
24349 add_alignment_attribute (subr_die
, type
);
24350 gen_formal_types_die (type
, subr_die
);
24352 if (get_AT (subr_die
, DW_AT_name
))
24353 add_pubtype (type
, subr_die
);
24354 if ((dwarf_version
>= 5 || !dwarf_strict
)
24355 && lang_hooks
.types
.type_dwarf_attribute (type
, DW_AT_reference
) != -1)
24356 add_AT_flag (subr_die
, DW_AT_reference
, 1);
24357 if ((dwarf_version
>= 5 || !dwarf_strict
)
24358 && lang_hooks
.types
.type_dwarf_attribute (type
,
24359 DW_AT_rvalue_reference
) != -1)
24360 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
24363 /* Generate a DIE for a type definition. */
24366 gen_typedef_die (tree decl
, dw_die_ref context_die
)
24368 dw_die_ref type_die
;
24371 if (TREE_ASM_WRITTEN (decl
))
24373 if (DECL_ORIGINAL_TYPE (decl
))
24374 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
24378 TREE_ASM_WRITTEN (decl
) = 1;
24379 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
24380 origin
= decl_ultimate_origin (decl
);
24381 if (origin
!= NULL
)
24382 add_abstract_origin_attribute (type_die
, origin
);
24385 tree type
= TREE_TYPE (decl
);
24387 if (type
== error_mark_node
)
24390 add_name_and_src_coords_attributes (type_die
, decl
);
24391 if (DECL_ORIGINAL_TYPE (decl
))
24393 type
= DECL_ORIGINAL_TYPE (decl
);
24395 if (type
== error_mark_node
)
24398 gcc_assert (type
!= TREE_TYPE (decl
));
24399 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
24403 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24405 /* Here, we are in the case of decl being a typedef naming
24406 an anonymous type, e.g:
24407 typedef struct {...} foo;
24408 In that case TREE_TYPE (decl) is not a typedef variant
24409 type and TYPE_NAME of the anonymous type is set to the
24410 TYPE_DECL of the typedef. This construct is emitted by
24413 TYPE is the anonymous struct named by the typedef
24414 DECL. As we need the DW_AT_type attribute of the
24415 DW_TAG_typedef to point to the DIE of TYPE, let's
24416 generate that DIE right away. add_type_attribute
24417 called below will then pick (via lookup_type_die) that
24418 anonymous struct DIE. */
24419 if (!TREE_ASM_WRITTEN (type
))
24420 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
24422 /* This is a GNU Extension. We are adding a
24423 DW_AT_linkage_name attribute to the DIE of the
24424 anonymous struct TYPE. The value of that attribute
24425 is the name of the typedef decl naming the anonymous
24426 struct. This greatly eases the work of consumers of
24427 this debug info. */
24428 add_linkage_name_raw (lookup_type_die (type
), decl
);
24432 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
24435 if (is_naming_typedef_decl (decl
))
24436 /* We want that all subsequent calls to lookup_type_die with
24437 TYPE in argument yield the DW_TAG_typedef we have just
24439 equate_type_number_to_die (type
, type_die
);
24441 type
= TREE_TYPE (decl
);
24443 add_alignment_attribute (type_die
, type
);
24445 add_accessibility_attribute (type_die
, decl
);
24448 if (DECL_ABSTRACT_P (decl
))
24449 equate_decl_number_to_die (decl
, type_die
);
24451 if (get_AT (type_die
, DW_AT_name
))
24452 add_pubtype (decl
, type_die
);
24455 /* Generate a DIE for a struct, class, enum or union type. */
24458 gen_tagged_type_die (tree type
,
24459 dw_die_ref context_die
,
24460 enum debug_info_usage usage
)
24464 if (type
== NULL_TREE
24465 || !is_tagged_type (type
))
24468 if (TREE_ASM_WRITTEN (type
))
24470 /* If this is a nested type whose containing class hasn't been written
24471 out yet, writing it out will cover this one, too. This does not apply
24472 to instantiations of member class templates; they need to be added to
24473 the containing class as they are generated. FIXME: This hurts the
24474 idea of combining type decls from multiple TUs, since we can't predict
24475 what set of template instantiations we'll get. */
24476 else if (TYPE_CONTEXT (type
)
24477 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24478 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
24480 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
24482 if (TREE_ASM_WRITTEN (type
))
24485 /* If that failed, attach ourselves to the stub. */
24486 push_decl_scope (TYPE_CONTEXT (type
));
24487 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
24490 else if (TYPE_CONTEXT (type
) != NULL_TREE
24491 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
24493 /* If this type is local to a function that hasn't been written
24494 out yet, use a NULL context for now; it will be fixed up in
24495 decls_for_scope. */
24496 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
24497 /* A declaration DIE doesn't count; nested types need to go in the
24499 if (context_die
&& is_declaration_die (context_die
))
24500 context_die
= NULL
;
24505 context_die
= declare_in_namespace (type
, context_die
);
24509 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
24511 /* This might have been written out by the call to
24512 declare_in_namespace. */
24513 if (!TREE_ASM_WRITTEN (type
))
24514 gen_enumeration_type_die (type
, context_die
);
24517 gen_struct_or_union_type_die (type
, context_die
, usage
);
24522 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
24523 it up if it is ever completed. gen_*_type_die will set it for us
24524 when appropriate. */
24527 /* Generate a type description DIE. */
24530 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
24531 enum debug_info_usage usage
)
24533 struct array_descr_info info
;
24535 if (type
== NULL_TREE
|| type
== error_mark_node
)
24538 if (flag_checking
&& type
)
24539 verify_type (type
);
24541 if (TYPE_NAME (type
) != NULL_TREE
24542 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
24543 && is_redundant_typedef (TYPE_NAME (type
))
24544 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
24545 /* The DECL of this type is a typedef we don't want to emit debug
24546 info for but we want debug info for its underlying typedef.
24547 This can happen for e.g, the injected-class-name of a C++
24549 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
24551 /* If TYPE is a typedef type variant, let's generate debug info
24552 for the parent typedef which TYPE is a type of. */
24553 if (typedef_variant_p (type
))
24555 if (TREE_ASM_WRITTEN (type
))
24558 /* Prevent broken recursion; we can't hand off to the same type. */
24559 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
24561 /* Give typedefs the right scope. */
24562 context_die
= scope_die_for (type
, context_die
);
24564 TREE_ASM_WRITTEN (type
) = 1;
24566 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
24570 /* If type is an anonymous tagged type named by a typedef, let's
24571 generate debug info for the typedef. */
24572 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24574 /* Use the DIE of the containing namespace as the parent DIE of
24575 the type description DIE we want to generate. */
24576 if (DECL_CONTEXT (TYPE_NAME (type
))
24577 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
24578 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
24580 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
24584 if (lang_hooks
.types
.get_debug_type
)
24586 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
24588 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
24590 gen_type_die_with_usage (debug_type
, context_die
, usage
);
24595 /* We are going to output a DIE to represent the unqualified version
24596 of this type (i.e. without any const or volatile qualifiers) so
24597 get the main variant (i.e. the unqualified version) of this type
24598 now. (Vectors and arrays are special because the debugging info is in the
24599 cloned type itself. Similarly function/method types can contain extra
24600 ref-qualification). */
24601 if (TREE_CODE (type
) == FUNCTION_TYPE
24602 || TREE_CODE (type
) == METHOD_TYPE
)
24604 /* For function/method types, can't use type_main_variant here,
24605 because that can have different ref-qualifiers for C++,
24606 but try to canonicalize. */
24607 tree main
= TYPE_MAIN_VARIANT (type
);
24608 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
24609 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
24610 && check_base_type (t
, main
)
24611 && check_lang_type (t
, type
))
24617 else if (TREE_CODE (type
) != VECTOR_TYPE
24618 && TREE_CODE (type
) != ARRAY_TYPE
)
24619 type
= type_main_variant (type
);
24621 /* If this is an array type with hidden descriptor, handle it first. */
24622 if (!TREE_ASM_WRITTEN (type
)
24623 && lang_hooks
.types
.get_array_descr_info
)
24625 memset (&info
, 0, sizeof (info
));
24626 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
24628 /* Fortran sometimes emits array types with no dimension. */
24629 gcc_assert (info
.ndimensions
>= 0
24630 && (info
.ndimensions
24631 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
24632 gen_descr_array_type_die (type
, &info
, context_die
);
24633 TREE_ASM_WRITTEN (type
) = 1;
24638 if (TREE_ASM_WRITTEN (type
))
24640 /* Variable-length types may be incomplete even if
24641 TREE_ASM_WRITTEN. For such types, fall through to
24642 gen_array_type_die() and possibly fill in
24643 DW_AT_{upper,lower}_bound attributes. */
24644 if ((TREE_CODE (type
) != ARRAY_TYPE
24645 && TREE_CODE (type
) != RECORD_TYPE
24646 && TREE_CODE (type
) != UNION_TYPE
24647 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
24648 || !variably_modified_type_p (type
, NULL
))
24652 switch (TREE_CODE (type
))
24658 case REFERENCE_TYPE
:
24659 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
24660 ensures that the gen_type_die recursion will terminate even if the
24661 type is recursive. Recursive types are possible in Ada. */
24662 /* ??? We could perhaps do this for all types before the switch
24664 TREE_ASM_WRITTEN (type
) = 1;
24666 /* For these types, all that is required is that we output a DIE (or a
24667 set of DIEs) to represent the "basis" type. */
24668 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24669 DINFO_USAGE_IND_USE
);
24673 /* This code is used for C++ pointer-to-data-member types.
24674 Output a description of the relevant class type. */
24675 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
24676 DINFO_USAGE_IND_USE
);
24678 /* Output a description of the type of the object pointed to. */
24679 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24680 DINFO_USAGE_IND_USE
);
24682 /* Now output a DIE to represent this pointer-to-data-member type
24684 gen_ptr_to_mbr_type_die (type
, context_die
);
24687 case FUNCTION_TYPE
:
24688 /* Force out return type (in case it wasn't forced out already). */
24689 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24690 DINFO_USAGE_DIR_USE
);
24691 gen_subroutine_type_die (type
, context_die
);
24695 /* Force out return type (in case it wasn't forced out already). */
24696 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24697 DINFO_USAGE_DIR_USE
);
24698 gen_subroutine_type_die (type
, context_die
);
24703 gen_array_type_die (type
, context_die
);
24706 case ENUMERAL_TYPE
:
24709 case QUAL_UNION_TYPE
:
24710 gen_tagged_type_die (type
, context_die
, usage
);
24716 case FIXED_POINT_TYPE
:
24719 case POINTER_BOUNDS_TYPE
:
24720 /* No DIEs needed for fundamental types. */
24725 /* Just use DW_TAG_unspecified_type. */
24727 dw_die_ref type_die
= lookup_type_die (type
);
24728 if (type_die
== NULL
)
24730 tree name
= TYPE_IDENTIFIER (type
);
24731 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
24733 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
24734 equate_type_number_to_die (type
, type_die
);
24740 if (is_cxx_auto (type
))
24742 tree name
= TYPE_IDENTIFIER (type
);
24743 dw_die_ref
*die
= (name
== get_identifier ("auto")
24744 ? &auto_die
: &decltype_auto_die
);
24747 *die
= new_die (DW_TAG_unspecified_type
,
24748 comp_unit_die (), NULL_TREE
);
24749 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
24751 equate_type_number_to_die (type
, *die
);
24754 gcc_unreachable ();
24757 TREE_ASM_WRITTEN (type
) = 1;
24761 gen_type_die (tree type
, dw_die_ref context_die
)
24763 if (type
!= error_mark_node
)
24765 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
24768 dw_die_ref die
= lookup_type_die (type
);
24775 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
24776 things which are local to the given block. */
24779 gen_block_die (tree stmt
, dw_die_ref context_die
)
24781 int must_output_die
= 0;
24784 /* Ignore blocks that are NULL. */
24785 if (stmt
== NULL_TREE
)
24788 inlined_func
= inlined_function_outer_scope_p (stmt
);
24790 /* If the block is one fragment of a non-contiguous block, do not
24791 process the variables, since they will have been done by the
24792 origin block. Do process subblocks. */
24793 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
24797 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
24798 gen_block_die (sub
, context_die
);
24803 /* Determine if we need to output any Dwarf DIEs at all to represent this
24806 /* The outer scopes for inlinings *must* always be represented. We
24807 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
24808 must_output_die
= 1;
24811 /* Determine if this block directly contains any "significant"
24812 local declarations which we will need to output DIEs for. */
24813 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24814 /* We are not in terse mode so *any* local declaration counts
24815 as being a "significant" one. */
24816 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
24817 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
24818 && (TREE_USED (stmt
)
24819 || TREE_ASM_WRITTEN (stmt
)
24820 || BLOCK_ABSTRACT (stmt
)));
24821 else if ((TREE_USED (stmt
)
24822 || TREE_ASM_WRITTEN (stmt
)
24823 || BLOCK_ABSTRACT (stmt
))
24824 && !dwarf2out_ignore_block (stmt
))
24825 must_output_die
= 1;
24828 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
24829 DIE for any block which contains no significant local declarations at
24830 all. Rather, in such cases we just call `decls_for_scope' so that any
24831 needed Dwarf info for any sub-blocks will get properly generated. Note
24832 that in terse mode, our definition of what constitutes a "significant"
24833 local declaration gets restricted to include only inlined function
24834 instances and local (nested) function definitions. */
24835 if (must_output_die
)
24839 /* If STMT block is abstract, that means we have been called
24840 indirectly from dwarf2out_abstract_function.
24841 That function rightfully marks the descendent blocks (of
24842 the abstract function it is dealing with) as being abstract,
24843 precisely to prevent us from emitting any
24844 DW_TAG_inlined_subroutine DIE as a descendent
24845 of an abstract function instance. So in that case, we should
24846 not call gen_inlined_subroutine_die.
24848 Later though, when cgraph asks dwarf2out to emit info
24849 for the concrete instance of the function decl into which
24850 the concrete instance of STMT got inlined, the later will lead
24851 to the generation of a DW_TAG_inlined_subroutine DIE. */
24852 if (! BLOCK_ABSTRACT (stmt
))
24853 gen_inlined_subroutine_die (stmt
, context_die
);
24856 gen_lexical_block_die (stmt
, context_die
);
24859 decls_for_scope (stmt
, context_die
);
24862 /* Process variable DECL (or variable with origin ORIGIN) within
24863 block STMT and add it to CONTEXT_DIE. */
24865 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
24868 tree decl_or_origin
= decl
? decl
: origin
;
24870 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
24871 die
= lookup_decl_die (decl_or_origin
);
24872 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
)
24874 if (TYPE_DECL_IS_STUB (decl_or_origin
))
24875 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
24877 die
= lookup_decl_die (decl_or_origin
);
24878 /* Avoid re-creating the DIE late if it was optimized as unused early. */
24879 if (! die
&& ! early_dwarf
)
24885 if (die
!= NULL
&& die
->die_parent
== NULL
)
24886 add_child_die (context_die
, die
);
24887 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
24890 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
24891 stmt
, context_die
);
24894 gen_decl_die (decl
, origin
, NULL
, context_die
);
24897 /* Generate all of the decls declared within a given scope and (recursively)
24898 all of its sub-blocks. */
24901 decls_for_scope (tree stmt
, dw_die_ref context_die
)
24907 /* Ignore NULL blocks. */
24908 if (stmt
== NULL_TREE
)
24911 /* Output the DIEs to represent all of the data objects and typedefs
24912 declared directly within this block but not within any nested
24913 sub-blocks. Also, nested function and tag DIEs have been
24914 generated with a parent of NULL; fix that up now. We don't
24915 have to do this if we're at -g1. */
24916 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24918 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
24919 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
24920 /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
24921 origin - avoid doing this twice as we have no good way to see
24922 if we've done it once already. */
24924 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
24926 decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
24927 if (decl
== current_function_decl
)
24928 /* Ignore declarations of the current function, while they
24929 are declarations, gen_subprogram_die would treat them
24930 as definitions again, because they are equal to
24931 current_function_decl and endlessly recurse. */;
24932 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
24933 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
24935 process_scope_var (stmt
, NULL_TREE
, decl
, context_die
);
24939 /* Even if we're at -g1, we need to process the subblocks in order to get
24940 inlined call information. */
24942 /* Output the DIEs to represent all sub-blocks (and the items declared
24943 therein) of this block. */
24944 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
24946 subblocks
= BLOCK_CHAIN (subblocks
))
24947 gen_block_die (subblocks
, context_die
);
24950 /* Is this a typedef we can avoid emitting? */
24953 is_redundant_typedef (const_tree decl
)
24955 if (TYPE_DECL_IS_STUB (decl
))
24958 if (DECL_ARTIFICIAL (decl
)
24959 && DECL_CONTEXT (decl
)
24960 && is_tagged_type (DECL_CONTEXT (decl
))
24961 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
24962 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
24963 /* Also ignore the artificial member typedef for the class name. */
24969 /* Return TRUE if TYPE is a typedef that names a type for linkage
24970 purposes. This kind of typedefs is produced by the C++ FE for
24973 typedef struct {...} foo;
24975 In that case, there is no typedef variant type produced for foo.
24976 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
24980 is_naming_typedef_decl (const_tree decl
)
24982 if (decl
== NULL_TREE
24983 || TREE_CODE (decl
) != TYPE_DECL
24984 || DECL_NAMELESS (decl
)
24985 || !is_tagged_type (TREE_TYPE (decl
))
24986 || DECL_IS_BUILTIN (decl
)
24987 || is_redundant_typedef (decl
)
24988 /* It looks like Ada produces TYPE_DECLs that are very similar
24989 to C++ naming typedefs but that have different
24990 semantics. Let's be specific to c++ for now. */
24994 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
24995 && TYPE_NAME (TREE_TYPE (decl
)) == decl
24996 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
24997 != TYPE_NAME (TREE_TYPE (decl
))));
25000 /* Looks up the DIE for a context. */
25002 static inline dw_die_ref
25003 lookup_context_die (tree context
)
25007 /* Find die that represents this context. */
25008 if (TYPE_P (context
))
25010 context
= TYPE_MAIN_VARIANT (context
);
25011 dw_die_ref ctx
= lookup_type_die (context
);
25014 return strip_naming_typedef (context
, ctx
);
25017 return lookup_decl_die (context
);
25019 return comp_unit_die ();
25022 /* Returns the DIE for a context. */
25024 static inline dw_die_ref
25025 get_context_die (tree context
)
25029 /* Find die that represents this context. */
25030 if (TYPE_P (context
))
25032 context
= TYPE_MAIN_VARIANT (context
);
25033 return strip_naming_typedef (context
, force_type_die (context
));
25036 return force_decl_die (context
);
25038 return comp_unit_die ();
25041 /* Returns the DIE for decl. A DIE will always be returned. */
25044 force_decl_die (tree decl
)
25046 dw_die_ref decl_die
;
25047 unsigned saved_external_flag
;
25048 tree save_fn
= NULL_TREE
;
25049 decl_die
= lookup_decl_die (decl
);
25052 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
25054 decl_die
= lookup_decl_die (decl
);
25058 switch (TREE_CODE (decl
))
25060 case FUNCTION_DECL
:
25061 /* Clear current_function_decl, so that gen_subprogram_die thinks
25062 that this is a declaration. At this point, we just want to force
25063 declaration die. */
25064 save_fn
= current_function_decl
;
25065 current_function_decl
= NULL_TREE
;
25066 gen_subprogram_die (decl
, context_die
);
25067 current_function_decl
= save_fn
;
25071 /* Set external flag to force declaration die. Restore it after
25072 gen_decl_die() call. */
25073 saved_external_flag
= DECL_EXTERNAL (decl
);
25074 DECL_EXTERNAL (decl
) = 1;
25075 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25076 DECL_EXTERNAL (decl
) = saved_external_flag
;
25079 case NAMESPACE_DECL
:
25080 if (dwarf_version
>= 3 || !dwarf_strict
)
25081 dwarf2out_decl (decl
);
25083 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
25084 decl_die
= comp_unit_die ();
25087 case TRANSLATION_UNIT_DECL
:
25088 decl_die
= comp_unit_die ();
25092 gcc_unreachable ();
25095 /* We should be able to find the DIE now. */
25097 decl_die
= lookup_decl_die (decl
);
25098 gcc_assert (decl_die
);
25104 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
25105 always returned. */
25108 force_type_die (tree type
)
25110 dw_die_ref type_die
;
25112 type_die
= lookup_type_die (type
);
25115 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
25117 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
25118 false, context_die
);
25119 gcc_assert (type_die
);
25124 /* Force out any required namespaces to be able to output DECL,
25125 and return the new context_die for it, if it's changed. */
25128 setup_namespace_context (tree thing
, dw_die_ref context_die
)
25130 tree context
= (DECL_P (thing
)
25131 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
25132 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
25133 /* Force out the namespace. */
25134 context_die
= force_decl_die (context
);
25136 return context_die
;
25139 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
25140 type) within its namespace, if appropriate.
25142 For compatibility with older debuggers, namespace DIEs only contain
25143 declarations; all definitions are emitted at CU scope, with
25144 DW_AT_specification pointing to the declaration (like with class
25148 declare_in_namespace (tree thing
, dw_die_ref context_die
)
25150 dw_die_ref ns_context
;
25152 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25153 return context_die
;
25155 /* External declarations in the local scope only need to be emitted
25156 once, not once in the namespace and once in the scope.
25158 This avoids declaring the `extern' below in the
25159 namespace DIE as well as in the innermost scope:
25172 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
25173 return context_die
;
25175 /* If this decl is from an inlined function, then don't try to emit it in its
25176 namespace, as we will get confused. It would have already been emitted
25177 when the abstract instance of the inline function was emitted anyways. */
25178 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
25179 return context_die
;
25181 ns_context
= setup_namespace_context (thing
, context_die
);
25183 if (ns_context
!= context_die
)
25187 if (DECL_P (thing
))
25188 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
25190 gen_type_die (thing
, ns_context
);
25192 return context_die
;
25195 /* Generate a DIE for a namespace or namespace alias. */
25198 gen_namespace_die (tree decl
, dw_die_ref context_die
)
25200 dw_die_ref namespace_die
;
25202 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
25203 they are an alias of. */
25204 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
25206 /* Output a real namespace or module. */
25207 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25208 namespace_die
= new_die (is_fortran ()
25209 ? DW_TAG_module
: DW_TAG_namespace
,
25210 context_die
, decl
);
25211 /* For Fortran modules defined in different CU don't add src coords. */
25212 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
25214 const char *name
= dwarf2_name (decl
, 0);
25216 add_name_attribute (namespace_die
, name
);
25219 add_name_and_src_coords_attributes (namespace_die
, decl
);
25220 if (DECL_EXTERNAL (decl
))
25221 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
25222 equate_decl_number_to_die (decl
, namespace_die
);
25226 /* Output a namespace alias. */
25228 /* Force out the namespace we are an alias of, if necessary. */
25229 dw_die_ref origin_die
25230 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
25232 if (DECL_FILE_SCOPE_P (decl
)
25233 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
25234 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25235 /* Now create the namespace alias DIE. */
25236 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
25237 add_name_and_src_coords_attributes (namespace_die
, decl
);
25238 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
25239 equate_decl_number_to_die (decl
, namespace_die
);
25241 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
25242 if (want_pubnames ())
25243 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
25246 /* Generate Dwarf debug information for a decl described by DECL.
25247 The return value is currently only meaningful for PARM_DECLs,
25248 for all other decls it returns NULL.
25250 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
25251 It can be NULL otherwise. */
25254 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
25255 dw_die_ref context_die
)
25257 tree decl_or_origin
= decl
? decl
: origin
;
25258 tree class_origin
= NULL
, ultimate_origin
;
25260 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
25263 /* Ignore pointer bounds decls. */
25264 if (DECL_P (decl_or_origin
)
25265 && TREE_TYPE (decl_or_origin
)
25266 && POINTER_BOUNDS_P (decl_or_origin
))
25269 switch (TREE_CODE (decl_or_origin
))
25275 if (!is_fortran () && !is_ada ())
25277 /* The individual enumerators of an enum type get output when we output
25278 the Dwarf representation of the relevant enum type itself. */
25282 /* Emit its type. */
25283 gen_type_die (TREE_TYPE (decl
), context_die
);
25285 /* And its containing namespace. */
25286 context_die
= declare_in_namespace (decl
, context_die
);
25288 gen_const_die (decl
, context_die
);
25291 case FUNCTION_DECL
:
25292 /* Don't output any DIEs to represent mere function declarations,
25293 unless they are class members or explicit block externs. */
25294 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
25295 && DECL_FILE_SCOPE_P (decl_or_origin
)
25296 && (current_function_decl
== NULL_TREE
25297 || DECL_ARTIFICIAL (decl_or_origin
)))
25302 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
25303 on local redeclarations of global functions. That seems broken. */
25304 if (current_function_decl
!= decl
)
25305 /* This is only a declaration. */;
25308 /* If we're emitting a clone, emit info for the abstract instance. */
25309 if (origin
|| DECL_ORIGIN (decl
) != decl
)
25310 dwarf2out_abstract_function (origin
25311 ? DECL_ORIGIN (origin
)
25312 : DECL_ABSTRACT_ORIGIN (decl
));
25314 /* If we're emitting an out-of-line copy of an inline function,
25315 emit info for the abstract instance and set up to refer to it. */
25316 else if (cgraph_function_possibly_inlined_p (decl
)
25317 && ! DECL_ABSTRACT_P (decl
)
25318 && ! class_or_namespace_scope_p (context_die
)
25319 /* dwarf2out_abstract_function won't emit a die if this is just
25320 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
25321 that case, because that works only if we have a die. */
25322 && DECL_INITIAL (decl
) != NULL_TREE
)
25324 dwarf2out_abstract_function (decl
);
25325 set_decl_origin_self (decl
);
25328 /* Otherwise we're emitting the primary DIE for this decl. */
25329 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
25331 /* Before we describe the FUNCTION_DECL itself, make sure that we
25332 have its containing type. */
25334 origin
= decl_class_context (decl
);
25335 if (origin
!= NULL_TREE
)
25336 gen_type_die (origin
, context_die
);
25338 /* And its return type. */
25339 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
25341 /* And its virtual context. */
25342 if (DECL_VINDEX (decl
) != NULL_TREE
)
25343 gen_type_die (DECL_CONTEXT (decl
), context_die
);
25345 /* Make sure we have a member DIE for decl. */
25346 if (origin
!= NULL_TREE
)
25347 gen_type_die_for_member (origin
, decl
, context_die
);
25349 /* And its containing namespace. */
25350 context_die
= declare_in_namespace (decl
, context_die
);
25353 /* Now output a DIE to represent the function itself. */
25355 gen_subprogram_die (decl
, context_die
);
25359 /* If we are in terse mode, don't generate any DIEs to represent any
25360 actual typedefs. */
25361 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25364 /* In the special case of a TYPE_DECL node representing the declaration
25365 of some type tag, if the given TYPE_DECL is marked as having been
25366 instantiated from some other (original) TYPE_DECL node (e.g. one which
25367 was generated within the original definition of an inline function) we
25368 used to generate a special (abbreviated) DW_TAG_structure_type,
25369 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
25370 should be actually referencing those DIEs, as variable DIEs with that
25371 type would be emitted already in the abstract origin, so it was always
25372 removed during unused type prunning. Don't add anything in this
25374 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
25377 if (is_redundant_typedef (decl
))
25378 gen_type_die (TREE_TYPE (decl
), context_die
);
25380 /* Output a DIE to represent the typedef itself. */
25381 gen_typedef_die (decl
, context_die
);
25385 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
25386 gen_label_die (decl
, context_die
);
25391 /* If we are in terse mode, don't generate any DIEs to represent any
25392 variable declarations or definitions. */
25393 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25396 /* Output any DIEs that are needed to specify the type of this data
25398 if (decl_by_reference_p (decl_or_origin
))
25399 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25401 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25403 /* And its containing type. */
25404 class_origin
= decl_class_context (decl_or_origin
);
25405 if (class_origin
!= NULL_TREE
)
25406 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
25408 /* And its containing namespace. */
25409 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
25411 /* Now output the DIE to represent the data object itself. This gets
25412 complicated because of the possibility that the VAR_DECL really
25413 represents an inlined instance of a formal parameter for an inline
25415 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
25416 if (ultimate_origin
!= NULL_TREE
25417 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
25418 gen_formal_parameter_die (decl
, origin
,
25419 true /* Emit name attribute. */,
25422 gen_variable_die (decl
, origin
, context_die
);
25426 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
25427 /* Ignore the nameless fields that are used to skip bits but handle C++
25428 anonymous unions and structs. */
25429 if (DECL_NAME (decl
) != NULL_TREE
25430 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
25431 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
25433 gen_type_die (member_declared_type (decl
), context_die
);
25434 gen_field_die (decl
, ctx
, context_die
);
25439 if (DECL_BY_REFERENCE (decl_or_origin
))
25440 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25442 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25443 return gen_formal_parameter_die (decl
, origin
,
25444 true /* Emit name attribute. */,
25447 case NAMESPACE_DECL
:
25448 if (dwarf_version
>= 3 || !dwarf_strict
)
25449 gen_namespace_die (decl
, context_die
);
25452 case IMPORTED_DECL
:
25453 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
25454 DECL_CONTEXT (decl
), context_die
);
25457 case NAMELIST_DECL
:
25458 gen_namelist_decl (DECL_NAME (decl
), context_die
,
25459 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
25463 /* Probably some frontend-internal decl. Assume we don't care. */
25464 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
25471 /* Output initial debug information for global DECL. Called at the
25472 end of the parsing process.
25474 This is the initial debug generation process. As such, the DIEs
25475 generated may be incomplete. A later debug generation pass
25476 (dwarf2out_late_global_decl) will augment the information generated
25477 in this pass (e.g., with complete location info). */
25480 dwarf2out_early_global_decl (tree decl
)
25484 /* gen_decl_die() will set DECL_ABSTRACT because
25485 cgraph_function_possibly_inlined_p() returns true. This is in
25486 turn will cause DW_AT_inline attributes to be set.
25488 This happens because at early dwarf generation, there is no
25489 cgraph information, causing cgraph_function_possibly_inlined_p()
25490 to return true. Trick cgraph_function_possibly_inlined_p()
25491 while we generate dwarf early. */
25492 bool save
= symtab
->global_info_ready
;
25493 symtab
->global_info_ready
= true;
25495 /* We don't handle TYPE_DECLs. If required, they'll be reached via
25496 other DECLs and they can point to template types or other things
25497 that dwarf2out can't handle when done via dwarf2out_decl. */
25498 if (TREE_CODE (decl
) != TYPE_DECL
25499 && TREE_CODE (decl
) != PARM_DECL
)
25501 tree save_fndecl
= current_function_decl
;
25502 if (TREE_CODE (decl
) == FUNCTION_DECL
)
25504 /* No cfun means the symbol has no body, so there's nothing
25506 if (!DECL_STRUCT_FUNCTION (decl
))
25507 goto early_decl_exit
;
25509 /* For nested functions, make sure we have DIEs for the parents first
25510 so that all nested DIEs are generated at the proper scope in the
25512 tree context
= decl_function_context (decl
);
25513 if (context
!= NULL
&& lookup_decl_die (context
) == NULL
)
25515 current_function_decl
= context
;
25516 dwarf2out_decl (context
);
25519 current_function_decl
= decl
;
25521 dwarf2out_decl (decl
);
25522 if (TREE_CODE (decl
) == FUNCTION_DECL
)
25523 current_function_decl
= save_fndecl
;
25526 symtab
->global_info_ready
= save
;
25529 /* Output debug information for global decl DECL. Called from
25530 toplev.c after compilation proper has finished. */
25533 dwarf2out_late_global_decl (tree decl
)
25535 /* Fill-in any location information we were unable to determine
25536 on the first pass. */
25537 if (VAR_P (decl
) && !POINTER_BOUNDS_P (decl
))
25539 dw_die_ref die
= lookup_decl_die (decl
);
25541 /* We have to generate early debug late for LTO. */
25542 if (! die
&& in_lto_p
)
25544 dwarf2out_decl (decl
);
25545 die
= lookup_decl_die (decl
);
25550 /* We get called via the symtab code invoking late_global_decl
25551 for symbols that are optimized out. Do not add locations
25552 for those, except if they have a DECL_VALUE_EXPR, in which case
25553 they are relevant for debuggers. */
25554 varpool_node
*node
= varpool_node::get (decl
);
25555 if ((! node
|| ! node
->definition
) && ! DECL_HAS_VALUE_EXPR_P (decl
))
25556 tree_add_const_value_attribute_for_decl (die
, decl
);
25558 add_location_or_const_value_attribute (die
, decl
, false);
25563 /* Output debug information for type decl DECL. Called from toplev.c
25564 and from language front ends (to record built-in types). */
25566 dwarf2out_type_decl (tree decl
, int local
)
25571 dwarf2out_decl (decl
);
25575 /* Output debug information for imported module or decl DECL.
25576 NAME is non-NULL name in the lexical block if the decl has been renamed.
25577 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
25578 that DECL belongs to.
25579 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
25581 dwarf2out_imported_module_or_decl_1 (tree decl
,
25583 tree lexical_block
,
25584 dw_die_ref lexical_block_die
)
25586 expanded_location xloc
;
25587 dw_die_ref imported_die
= NULL
;
25588 dw_die_ref at_import_die
;
25590 if (TREE_CODE (decl
) == IMPORTED_DECL
)
25592 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
25593 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
25597 xloc
= expand_location (input_location
);
25599 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
25601 at_import_die
= force_type_die (TREE_TYPE (decl
));
25602 /* For namespace N { typedef void T; } using N::T; base_type_die
25603 returns NULL, but DW_TAG_imported_declaration requires
25604 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
25605 if (!at_import_die
)
25607 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
25608 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
25609 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
25610 gcc_assert (at_import_die
);
25615 at_import_die
= lookup_decl_die (decl
);
25616 if (!at_import_die
)
25618 /* If we're trying to avoid duplicate debug info, we may not have
25619 emitted the member decl for this field. Emit it now. */
25620 if (TREE_CODE (decl
) == FIELD_DECL
)
25622 tree type
= DECL_CONTEXT (decl
);
25624 if (TYPE_CONTEXT (type
)
25625 && TYPE_P (TYPE_CONTEXT (type
))
25626 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
25627 DINFO_USAGE_DIR_USE
))
25629 gen_type_die_for_member (type
, decl
,
25630 get_context_die (TYPE_CONTEXT (type
)));
25632 if (TREE_CODE (decl
) == NAMELIST_DECL
)
25633 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
25634 get_context_die (DECL_CONTEXT (decl
)),
25637 at_import_die
= force_decl_die (decl
);
25641 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
25643 if (dwarf_version
>= 3 || !dwarf_strict
)
25644 imported_die
= new_die (DW_TAG_imported_module
,
25651 imported_die
= new_die (DW_TAG_imported_declaration
,
25655 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
25656 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
25657 if (debug_column_info
&& xloc
.column
)
25658 add_AT_unsigned (imported_die
, DW_AT_decl_column
, xloc
.column
);
25660 add_AT_string (imported_die
, DW_AT_name
,
25661 IDENTIFIER_POINTER (name
));
25662 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
25665 /* Output debug information for imported module or decl DECL.
25666 NAME is non-NULL name in context if the decl has been renamed.
25667 CHILD is true if decl is one of the renamed decls as part of
25668 importing whole module. */
25671 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
25674 /* dw_die_ref at_import_die; */
25675 dw_die_ref scope_die
;
25677 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25684 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
25685 We need decl DIE for reference and scope die. First, get DIE for the decl
25688 /* Get the scope die for decl context. Use comp_unit_die for global module
25689 or decl. If die is not found for non globals, force new die. */
25691 && TYPE_P (context
)
25692 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
25695 scope_die
= get_context_die (context
);
25699 /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
25700 there is nothing we can do, here. */
25701 if (dwarf_version
< 3 && dwarf_strict
)
25704 gcc_assert (scope_die
->die_child
);
25705 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
25706 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
25707 scope_die
= scope_die
->die_child
;
25710 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
25711 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
25714 /* Output debug information for namelists. */
25717 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
25719 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
25723 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25726 gcc_assert (scope_die
!= NULL
);
25727 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
25728 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
25730 /* If there are no item_decls, we have a nondefining namelist, e.g.
25731 with USE association; hence, set DW_AT_declaration. */
25732 if (item_decls
== NULL_TREE
)
25734 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
25738 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
25740 nml_item_ref_die
= lookup_decl_die (value
);
25741 if (!nml_item_ref_die
)
25742 nml_item_ref_die
= force_decl_die (value
);
25744 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
25745 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
25751 /* Write the debugging output for DECL and return the DIE. */
25754 dwarf2out_decl (tree decl
)
25756 dw_die_ref context_die
= comp_unit_die ();
25758 switch (TREE_CODE (decl
))
25763 case FUNCTION_DECL
:
25764 /* What we would really like to do here is to filter out all mere
25765 file-scope declarations of file-scope functions which are never
25766 referenced later within this translation unit (and keep all of ones
25767 that *are* referenced later on) but we aren't clairvoyant, so we have
25768 no idea which functions will be referenced in the future (i.e. later
25769 on within the current translation unit). So here we just ignore all
25770 file-scope function declarations which are not also definitions. If
25771 and when the debugger needs to know something about these functions,
25772 it will have to hunt around and find the DWARF information associated
25773 with the definition of the function.
25775 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
25776 nodes represent definitions and which ones represent mere
25777 declarations. We have to check DECL_INITIAL instead. That's because
25778 the C front-end supports some weird semantics for "extern inline"
25779 function definitions. These can get inlined within the current
25780 translation unit (and thus, we need to generate Dwarf info for their
25781 abstract instances so that the Dwarf info for the concrete inlined
25782 instances can have something to refer to) but the compiler never
25783 generates any out-of-lines instances of such things (despite the fact
25784 that they *are* definitions).
25786 The important point is that the C front-end marks these "extern
25787 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
25788 them anyway. Note that the C++ front-end also plays some similar games
25789 for inline function definitions appearing within include files which
25790 also contain `#pragma interface' pragmas.
25792 If we are called from dwarf2out_abstract_function output a DIE
25793 anyway. We can end up here this way with early inlining and LTO
25794 where the inlined function is output in a different LTRANS unit
25796 if (DECL_INITIAL (decl
) == NULL_TREE
25797 && ! DECL_ABSTRACT_P (decl
))
25800 /* If we're a nested function, initially use a parent of NULL; if we're
25801 a plain function, this will be fixed up in decls_for_scope. If
25802 we're a method, it will be ignored, since we already have a DIE. */
25803 if (decl_function_context (decl
)
25804 /* But if we're in terse mode, we don't care about scope. */
25805 && debug_info_level
> DINFO_LEVEL_TERSE
)
25806 context_die
= NULL
;
25810 /* For local statics lookup proper context die. */
25811 if (local_function_static (decl
))
25812 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25814 /* If we are in terse mode, don't generate any DIEs to represent any
25815 variable declarations or definitions. */
25816 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25821 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25823 if (!is_fortran () && !is_ada ())
25825 if (TREE_STATIC (decl
) && decl_function_context (decl
))
25826 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25829 case NAMESPACE_DECL
:
25830 case IMPORTED_DECL
:
25831 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25833 if (lookup_decl_die (decl
) != NULL
)
25838 /* Don't emit stubs for types unless they are needed by other DIEs. */
25839 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
25842 /* Don't bother trying to generate any DIEs to represent any of the
25843 normal built-in types for the language we are compiling. */
25844 if (DECL_IS_BUILTIN (decl
))
25847 /* If we are in terse mode, don't generate any DIEs for types. */
25848 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25851 /* If we're a function-scope tag, initially use a parent of NULL;
25852 this will be fixed up in decls_for_scope. */
25853 if (decl_function_context (decl
))
25854 context_die
= NULL
;
25858 case NAMELIST_DECL
:
25865 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25869 dw_die_ref die
= lookup_decl_die (decl
);
25875 /* Write the debugging output for DECL. */
25878 dwarf2out_function_decl (tree decl
)
25880 dwarf2out_decl (decl
);
25881 call_arg_locations
= NULL
;
25882 call_arg_loc_last
= NULL
;
25883 call_site_count
= -1;
25884 tail_call_site_count
= -1;
25885 decl_loc_table
->empty ();
25886 cached_dw_loc_list_table
->empty ();
25889 /* Output a marker (i.e. a label) for the beginning of the generated code for
25890 a lexical block. */
25893 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
25894 unsigned int blocknum
)
25896 switch_to_section (current_function_section ());
25897 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
25900 /* Output a marker (i.e. a label) for the end of the generated code for a
25904 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
25906 switch_to_section (current_function_section ());
25907 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
25910 /* Returns nonzero if it is appropriate not to emit any debugging
25911 information for BLOCK, because it doesn't contain any instructions.
25913 Don't allow this for blocks with nested functions or local classes
25914 as we would end up with orphans, and in the presence of scheduling
25915 we may end up calling them anyway. */
25918 dwarf2out_ignore_block (const_tree block
)
25923 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
25924 if (TREE_CODE (decl
) == FUNCTION_DECL
25925 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
25927 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
25929 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
25930 if (TREE_CODE (decl
) == FUNCTION_DECL
25931 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
25938 /* Hash table routines for file_hash. */
25941 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
25943 return filename_cmp (p1
->filename
, p2
) == 0;
25947 dwarf_file_hasher::hash (dwarf_file_data
*p
)
25949 return htab_hash_string (p
->filename
);
25952 /* Lookup FILE_NAME (in the list of filenames that we know about here in
25953 dwarf2out.c) and return its "index". The index of each (known) filename is
25954 just a unique number which is associated with only that one filename. We
25955 need such numbers for the sake of generating labels (in the .debug_sfnames
25956 section) and references to those files numbers (in the .debug_srcinfo
25957 and .debug_macinfo sections). If the filename given as an argument is not
25958 found in our current list, add it to the list and assign it the next
25959 available unique index number. */
25961 static struct dwarf_file_data
*
25962 lookup_filename (const char *file_name
)
25964 struct dwarf_file_data
* created
;
25969 dwarf_file_data
**slot
25970 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
25975 created
= ggc_alloc
<dwarf_file_data
> ();
25976 created
->filename
= file_name
;
25977 created
->emitted_number
= 0;
25982 /* If the assembler will construct the file table, then translate the compiler
25983 internal file table number into the assembler file table number, and emit
25984 a .file directive if we haven't already emitted one yet. The file table
25985 numbers are different because we prune debug info for unused variables and
25986 types, which may include filenames. */
25989 maybe_emit_file (struct dwarf_file_data
* fd
)
25991 if (! fd
->emitted_number
)
25993 if (last_emitted_file
)
25994 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
25996 fd
->emitted_number
= 1;
25997 last_emitted_file
= fd
;
25999 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26001 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
26002 output_quoted_string (asm_out_file
,
26003 remap_debug_filename (fd
->filename
));
26004 fputc ('\n', asm_out_file
);
26008 return fd
->emitted_number
;
26011 /* Schedule generation of a DW_AT_const_value attribute to DIE.
26012 That generation should happen after function debug info has been
26013 generated. The value of the attribute is the constant value of ARG. */
26016 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
26018 die_arg_entry entry
;
26023 gcc_assert (early_dwarf
);
26025 if (!tmpl_value_parm_die_table
)
26026 vec_alloc (tmpl_value_parm_die_table
, 32);
26030 vec_safe_push (tmpl_value_parm_die_table
, entry
);
26033 /* Return TRUE if T is an instance of generic type, FALSE
26037 generic_type_p (tree t
)
26039 if (t
== NULL_TREE
|| !TYPE_P (t
))
26041 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
26044 /* Schedule the generation of the generic parameter dies for the
26045 instance of generic type T. The proper generation itself is later
26046 done by gen_scheduled_generic_parms_dies. */
26049 schedule_generic_params_dies_gen (tree t
)
26051 if (!generic_type_p (t
))
26054 gcc_assert (early_dwarf
);
26056 if (!generic_type_instances
)
26057 vec_alloc (generic_type_instances
, 256);
26059 vec_safe_push (generic_type_instances
, t
);
26062 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
26063 by append_entry_to_tmpl_value_parm_die_table. This function must
26064 be called after function DIEs have been generated. */
26067 gen_remaining_tmpl_value_param_die_attribute (void)
26069 if (tmpl_value_parm_die_table
)
26074 /* We do this in two phases - first get the cases we can
26075 handle during early-finish, preserving those we cannot
26076 (containing symbolic constants where we don't yet know
26077 whether we are going to output the referenced symbols).
26078 For those we try again at late-finish. */
26080 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
26082 if (!tree_add_const_value_attribute (e
->die
, e
->arg
))
26084 dw_loc_descr_ref loc
= NULL
;
26086 && (dwarf_version
>= 5 || !dwarf_strict
))
26087 loc
= loc_descriptor_from_tree (e
->arg
, 2, NULL
);
26089 add_AT_loc (e
->die
, DW_AT_location
, loc
);
26091 (*tmpl_value_parm_die_table
)[j
++] = *e
;
26094 tmpl_value_parm_die_table
->truncate (j
);
26098 /* Generate generic parameters DIEs for instances of generic types
26099 that have been previously scheduled by
26100 schedule_generic_params_dies_gen. This function must be called
26101 after all the types of the CU have been laid out. */
26104 gen_scheduled_generic_parms_dies (void)
26109 if (!generic_type_instances
)
26112 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
26113 if (COMPLETE_TYPE_P (t
))
26114 gen_generic_params_dies (t
);
26116 generic_type_instances
= NULL
;
26120 /* Replace DW_AT_name for the decl with name. */
26123 dwarf2out_set_name (tree decl
, tree name
)
26126 dw_attr_node
*attr
;
26129 die
= TYPE_SYMTAB_DIE (decl
);
26133 dname
= dwarf2_name (name
, 0);
26137 attr
= get_AT (die
, DW_AT_name
);
26140 struct indirect_string_node
*node
;
26142 node
= find_AT_string (dname
);
26143 /* replace the string. */
26144 attr
->dw_attr_val
.v
.val_str
= node
;
26148 add_name_attribute (die
, dname
);
26151 /* True if before or during processing of the first function being emitted. */
26152 static bool in_first_function_p
= true;
26153 /* True if loc_note during dwarf2out_var_location call might still be
26154 before first real instruction at address equal to .Ltext0. */
26155 static bool maybe_at_text_label_p
= true;
26156 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
26157 static unsigned int first_loclabel_num_not_at_text_label
;
26159 /* Called by the final INSN scan whenever we see a var location. We
26160 use it to drop labels in the right places, and throw the location in
26161 our lookup table. */
26164 dwarf2out_var_location (rtx_insn
*loc_note
)
26166 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
26167 struct var_loc_node
*newloc
;
26168 rtx_insn
*next_real
, *next_note
;
26169 rtx_insn
*call_insn
= NULL
;
26170 static const char *last_label
;
26171 static const char *last_postcall_label
;
26172 static bool last_in_cold_section_p
;
26173 static rtx_insn
*expected_next_loc_note
;
26177 if (!NOTE_P (loc_note
))
26179 if (CALL_P (loc_note
))
26182 if (SIBLING_CALL_P (loc_note
))
26183 tail_call_site_count
++;
26184 if (optimize
== 0 && !flag_var_tracking
)
26186 /* When the var-tracking pass is not running, there is no note
26187 for indirect calls whose target is compile-time known. In this
26188 case, process such calls specifically so that we generate call
26189 sites for them anyway. */
26190 rtx x
= PATTERN (loc_note
);
26191 if (GET_CODE (x
) == PARALLEL
)
26192 x
= XVECEXP (x
, 0, 0);
26193 if (GET_CODE (x
) == SET
)
26195 if (GET_CODE (x
) == CALL
)
26198 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
26199 || !SYMBOL_REF_DECL (XEXP (x
, 0))
26200 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
26203 call_insn
= loc_note
;
26207 next_real
= next_real_insn (call_insn
);
26209 cached_next_real_insn
= NULL
;
26217 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
26218 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
26221 /* Optimize processing a large consecutive sequence of location
26222 notes so we don't spend too much time in next_real_insn. If the
26223 next insn is another location note, remember the next_real_insn
26224 calculation for next time. */
26225 next_real
= cached_next_real_insn
;
26228 if (expected_next_loc_note
!= loc_note
)
26232 next_note
= NEXT_INSN (loc_note
);
26234 || next_note
->deleted ()
26235 || ! NOTE_P (next_note
)
26236 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
26237 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
26241 next_real
= next_real_insn (loc_note
);
26245 expected_next_loc_note
= next_note
;
26246 cached_next_real_insn
= next_real
;
26249 cached_next_real_insn
= NULL
;
26251 /* If there are no instructions which would be affected by this note,
26252 don't do anything. */
26254 && next_real
== NULL_RTX
26255 && !NOTE_DURING_CALL_P (loc_note
))
26260 if (next_real
== NULL_RTX
)
26261 next_real
= get_last_insn ();
26263 /* If there were any real insns between note we processed last time
26264 and this note (or if it is the first note), clear
26265 last_{,postcall_}label so that they are not reused this time. */
26266 if (last_var_location_insn
== NULL_RTX
26267 || last_var_location_insn
!= next_real
26268 || last_in_cold_section_p
!= in_cold_section_p
)
26271 last_postcall_label
= NULL
;
26276 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
26277 newloc
= add_var_loc_to_decl (decl
, loc_note
,
26278 NOTE_DURING_CALL_P (loc_note
)
26279 ? last_postcall_label
: last_label
);
26280 if (newloc
== NULL
)
26289 /* If there were no real insns between note we processed last time
26290 and this note, use the label we emitted last time. Otherwise
26291 create a new label and emit it. */
26292 if (last_label
== NULL
)
26294 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
26295 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
26297 last_label
= ggc_strdup (loclabel
);
26298 /* See if loclabel might be equal to .Ltext0. If yes,
26299 bump first_loclabel_num_not_at_text_label. */
26300 if (!have_multiple_function_sections
26301 && in_first_function_p
26302 && maybe_at_text_label_p
)
26304 static rtx_insn
*last_start
;
26306 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
26307 if (insn
== last_start
)
26309 else if (!NONDEBUG_INSN_P (insn
))
26313 rtx body
= PATTERN (insn
);
26314 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
26316 /* Inline asm could occupy zero bytes. */
26317 else if (GET_CODE (body
) == ASM_INPUT
26318 || asm_noperands (body
) >= 0)
26320 #ifdef HAVE_attr_length
26321 else if (get_attr_min_length (insn
) == 0)
26326 /* Assume insn has non-zero length. */
26327 maybe_at_text_label_p
= false;
26331 if (maybe_at_text_label_p
)
26333 last_start
= loc_note
;
26334 first_loclabel_num_not_at_text_label
= loclabel_num
;
26339 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
26340 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
26344 struct call_arg_loc_node
*ca_loc
26345 = ggc_cleared_alloc
<call_arg_loc_node
> ();
26347 = loc_note
!= NULL_RTX
? prev_real_insn (loc_note
) : call_insn
;
26349 ca_loc
->call_arg_loc_note
= loc_note
;
26350 ca_loc
->next
= NULL
;
26351 ca_loc
->label
= last_label
;
26354 || (NONJUMP_INSN_P (prev
)
26355 && GET_CODE (PATTERN (prev
)) == SEQUENCE
26356 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
26357 if (!CALL_P (prev
))
26358 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
26359 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
26361 /* Look for a SYMBOL_REF in the "prev" instruction. */
26362 rtx x
= get_call_rtx_from (PATTERN (prev
));
26365 /* Try to get the call symbol, if any. */
26366 if (MEM_P (XEXP (x
, 0)))
26368 /* First, look for a memory access to a symbol_ref. */
26369 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
26370 && SYMBOL_REF_DECL (XEXP (x
, 0))
26371 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
26372 ca_loc
->symbol_ref
= XEXP (x
, 0);
26373 /* Otherwise, look at a compile-time known user-level function
26377 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
26378 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
26381 ca_loc
->block
= insn_scope (prev
);
26382 if (call_arg_locations
)
26383 call_arg_loc_last
->next
= ca_loc
;
26385 call_arg_locations
= ca_loc
;
26386 call_arg_loc_last
= ca_loc
;
26388 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
26389 newloc
->label
= last_label
;
26392 if (!last_postcall_label
)
26394 sprintf (loclabel
, "%s-1", last_label
);
26395 last_postcall_label
= ggc_strdup (loclabel
);
26397 newloc
->label
= last_postcall_label
;
26400 last_var_location_insn
= next_real
;
26401 last_in_cold_section_p
= in_cold_section_p
;
26404 /* Called from finalize_size_functions for size functions so that their body
26405 can be encoded in the debug info to describe the layout of variable-length
26409 dwarf2out_size_function (tree decl
)
26411 function_to_dwarf_procedure (decl
);
26414 /* Note in one location list that text section has changed. */
26417 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
26419 var_loc_list
*list
= *slot
;
26421 list
->last_before_switch
26422 = list
->last
->next
? list
->last
->next
: list
->last
;
26426 /* Note in all location lists that text section has changed. */
26429 var_location_switch_text_section (void)
26431 if (decl_loc_table
== NULL
)
26434 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
26437 /* Create a new line number table. */
26439 static dw_line_info_table
*
26440 new_line_info_table (void)
26442 dw_line_info_table
*table
;
26444 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
26445 table
->file_num
= 1;
26446 table
->line_num
= 1;
26447 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
26452 /* Lookup the "current" table into which we emit line info, so
26453 that we don't have to do it for every source line. */
26456 set_cur_line_info_table (section
*sec
)
26458 dw_line_info_table
*table
;
26460 if (sec
== text_section
)
26461 table
= text_section_line_info
;
26462 else if (sec
== cold_text_section
)
26464 table
= cold_text_section_line_info
;
26467 cold_text_section_line_info
= table
= new_line_info_table ();
26468 table
->end_label
= cold_end_label
;
26473 const char *end_label
;
26475 if (flag_reorder_blocks_and_partition
)
26477 if (in_cold_section_p
)
26478 end_label
= crtl
->subsections
.cold_section_end_label
;
26480 end_label
= crtl
->subsections
.hot_section_end_label
;
26484 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26485 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
26486 current_function_funcdef_no
);
26487 end_label
= ggc_strdup (label
);
26490 table
= new_line_info_table ();
26491 table
->end_label
= end_label
;
26493 vec_safe_push (separate_line_info
, table
);
26496 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26497 table
->is_stmt
= (cur_line_info_table
26498 ? cur_line_info_table
->is_stmt
26499 : DWARF_LINE_DEFAULT_IS_STMT_START
);
26500 cur_line_info_table
= table
;
26504 /* We need to reset the locations at the beginning of each
26505 function. We can't do this in the end_function hook, because the
26506 declarations that use the locations won't have been output when
26507 that hook is called. Also compute have_multiple_function_sections here. */
26510 dwarf2out_begin_function (tree fun
)
26512 section
*sec
= function_section (fun
);
26514 if (sec
!= text_section
)
26515 have_multiple_function_sections
= true;
26517 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
26519 gcc_assert (current_function_decl
== fun
);
26520 cold_text_section
= unlikely_text_section ();
26521 switch_to_section (cold_text_section
);
26522 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
26523 switch_to_section (sec
);
26526 dwarf2out_note_section_used ();
26527 call_site_count
= 0;
26528 tail_call_site_count
= 0;
26530 set_cur_line_info_table (sec
);
26533 /* Helper function of dwarf2out_end_function, called only after emitting
26534 the very first function into assembly. Check if some .debug_loc range
26535 might end with a .LVL* label that could be equal to .Ltext0.
26536 In that case we must force using absolute addresses in .debug_loc ranges,
26537 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
26538 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
26540 Set have_multiple_function_sections to true in that case and
26541 terminate htab traversal. */
26544 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
26546 var_loc_list
*entry
= *slot
;
26547 struct var_loc_node
*node
;
26549 node
= entry
->first
;
26550 if (node
&& node
->next
&& node
->next
->label
)
26553 const char *label
= node
->next
->label
;
26554 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
26556 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
26558 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
26559 if (strcmp (label
, loclabel
) == 0)
26561 have_multiple_function_sections
= true;
26569 /* Hook called after emitting a function into assembly.
26570 This does something only for the very first function emitted. */
26573 dwarf2out_end_function (unsigned int)
26575 if (in_first_function_p
26576 && !have_multiple_function_sections
26577 && first_loclabel_num_not_at_text_label
26579 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
26580 in_first_function_p
= false;
26581 maybe_at_text_label_p
= false;
26584 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
26585 front-ends register a translation unit even before dwarf2out_init is
26587 static tree main_translation_unit
= NULL_TREE
;
26589 /* Hook called by front-ends after they built their main translation unit.
26590 Associate comp_unit_die to UNIT. */
26593 dwarf2out_register_main_translation_unit (tree unit
)
26595 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
26596 && main_translation_unit
== NULL_TREE
);
26597 main_translation_unit
= unit
;
26598 /* If dwarf2out_init has not been called yet, it will perform the association
26599 itself looking at main_translation_unit. */
26600 if (decl_die_table
!= NULL
)
26601 equate_decl_number_to_die (unit
, comp_unit_die ());
26604 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
26607 push_dw_line_info_entry (dw_line_info_table
*table
,
26608 enum dw_line_info_opcode opcode
, unsigned int val
)
26610 dw_line_info_entry e
;
26613 vec_safe_push (table
->entries
, e
);
26616 /* Output a label to mark the beginning of a source code line entry
26617 and record information relating to this source line, in
26618 'line_info_table' for later output of the .debug_line section. */
26619 /* ??? The discriminator parameter ought to be unsigned. */
26622 dwarf2out_source_line (unsigned int line
, unsigned int column
,
26623 const char *filename
,
26624 int discriminator
, bool is_stmt
)
26626 unsigned int file_num
;
26627 dw_line_info_table
*table
;
26629 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
26632 /* The discriminator column was added in dwarf4. Simplify the below
26633 by simply removing it if we're not supposed to output it. */
26634 if (dwarf_version
< 4 && dwarf_strict
)
26637 if (!debug_column_info
)
26640 table
= cur_line_info_table
;
26641 file_num
= maybe_emit_file (lookup_filename (filename
));
26643 /* ??? TODO: Elide duplicate line number entries. Traditionally,
26644 the debugger has used the second (possibly duplicate) line number
26645 at the beginning of the function to mark the end of the prologue.
26646 We could eliminate any other duplicates within the function. For
26647 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
26648 that second line number entry. */
26649 /* Recall that this end-of-prologue indication is *not* the same thing
26650 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
26651 to which the hook corresponds, follows the last insn that was
26652 emitted by gen_prologue. What we need is to precede the first insn
26653 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
26654 insn that corresponds to something the user wrote. These may be
26655 very different locations once scheduling is enabled. */
26657 if (0 && file_num
== table
->file_num
26658 && line
== table
->line_num
26659 && column
== table
->column_num
26660 && discriminator
== table
->discrim_num
26661 && is_stmt
== table
->is_stmt
)
26664 switch_to_section (current_function_section ());
26666 /* If requested, emit something human-readable. */
26667 if (flag_debug_asm
)
26669 if (debug_column_info
)
26670 fprintf (asm_out_file
, "\t%s %s:%d:%d\n", ASM_COMMENT_START
,
26671 filename
, line
, column
);
26673 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
26677 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26679 /* Emit the .loc directive understood by GNU as. */
26680 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
26681 file_num, line, is_stmt, discriminator */
26682 fputs ("\t.loc ", asm_out_file
);
26683 fprint_ul (asm_out_file
, file_num
);
26684 putc (' ', asm_out_file
);
26685 fprint_ul (asm_out_file
, line
);
26686 putc (' ', asm_out_file
);
26687 if (debug_column_info
)
26688 fprint_ul (asm_out_file
, column
);
26690 putc ('0', asm_out_file
);
26692 if (is_stmt
!= table
->is_stmt
)
26694 fputs (" is_stmt ", asm_out_file
);
26695 putc (is_stmt
? '1' : '0', asm_out_file
);
26697 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
26699 gcc_assert (discriminator
> 0);
26700 fputs (" discriminator ", asm_out_file
);
26701 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
26703 putc ('\n', asm_out_file
);
26707 unsigned int label_num
= ++line_info_label_num
;
26709 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
26711 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
26712 if (file_num
!= table
->file_num
)
26713 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
26714 if (discriminator
!= table
->discrim_num
)
26715 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
26716 if (is_stmt
!= table
->is_stmt
)
26717 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
26718 push_dw_line_info_entry (table
, LI_set_line
, line
);
26719 if (debug_column_info
)
26720 push_dw_line_info_entry (table
, LI_set_column
, column
);
26723 table
->file_num
= file_num
;
26724 table
->line_num
= line
;
26725 table
->column_num
= column
;
26726 table
->discrim_num
= discriminator
;
26727 table
->is_stmt
= is_stmt
;
26728 table
->in_use
= true;
26731 /* Record the beginning of a new source file. */
26734 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
26736 if (flag_eliminate_dwarf2_dups
)
26738 /* Record the beginning of the file for break_out_includes. */
26739 dw_die_ref bincl_die
;
26741 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
26742 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
26745 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26748 e
.code
= DW_MACINFO_start_file
;
26750 e
.info
= ggc_strdup (filename
);
26751 vec_safe_push (macinfo_table
, e
);
26755 /* Record the end of a source file. */
26758 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
26760 if (flag_eliminate_dwarf2_dups
)
26761 /* Record the end of the file for break_out_includes. */
26762 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
26764 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26767 e
.code
= DW_MACINFO_end_file
;
26770 vec_safe_push (macinfo_table
, e
);
26774 /* Called from debug_define in toplev.c. The `buffer' parameter contains
26775 the tail part of the directive line, i.e. the part which is past the
26776 initial whitespace, #, whitespace, directive-name, whitespace part. */
26779 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
26780 const char *buffer ATTRIBUTE_UNUSED
)
26782 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26785 /* Insert a dummy first entry to be able to optimize the whole
26786 predefined macro block using DW_MACRO_import. */
26787 if (macinfo_table
->is_empty () && lineno
<= 1)
26792 vec_safe_push (macinfo_table
, e
);
26794 e
.code
= DW_MACINFO_define
;
26796 e
.info
= ggc_strdup (buffer
);
26797 vec_safe_push (macinfo_table
, e
);
26801 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
26802 the tail part of the directive line, i.e. the part which is past the
26803 initial whitespace, #, whitespace, directive-name, whitespace part. */
26806 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
26807 const char *buffer ATTRIBUTE_UNUSED
)
26809 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26812 /* Insert a dummy first entry to be able to optimize the whole
26813 predefined macro block using DW_MACRO_import. */
26814 if (macinfo_table
->is_empty () && lineno
<= 1)
26819 vec_safe_push (macinfo_table
, e
);
26821 e
.code
= DW_MACINFO_undef
;
26823 e
.info
= ggc_strdup (buffer
);
26824 vec_safe_push (macinfo_table
, e
);
26828 /* Helpers to manipulate hash table of CUs. */
26830 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
26832 static inline hashval_t
hash (const macinfo_entry
*);
26833 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
26837 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
26839 return htab_hash_string (entry
->info
);
26843 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
26844 const macinfo_entry
*entry2
)
26846 return !strcmp (entry1
->info
, entry2
->info
);
26849 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
26851 /* Output a single .debug_macinfo entry. */
26854 output_macinfo_op (macinfo_entry
*ref
)
26858 struct indirect_string_node
*node
;
26859 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26860 struct dwarf_file_data
*fd
;
26864 case DW_MACINFO_start_file
:
26865 fd
= lookup_filename (ref
->info
);
26866 file_num
= maybe_emit_file (fd
);
26867 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
26868 dw2_asm_output_data_uleb128 (ref
->lineno
,
26869 "Included from line number %lu",
26870 (unsigned long) ref
->lineno
);
26871 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
26873 case DW_MACINFO_end_file
:
26874 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
26876 case DW_MACINFO_define
:
26877 case DW_MACINFO_undef
:
26878 len
= strlen (ref
->info
) + 1;
26880 && len
> DWARF_OFFSET_SIZE
26881 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
26882 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
26884 ref
->code
= ref
->code
== DW_MACINFO_define
26885 ? DW_MACRO_define_strp
: DW_MACRO_undef_strp
;
26886 output_macinfo_op (ref
);
26889 dw2_asm_output_data (1, ref
->code
,
26890 ref
->code
== DW_MACINFO_define
26891 ? "Define macro" : "Undefine macro");
26892 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
26893 (unsigned long) ref
->lineno
);
26894 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
26896 case DW_MACRO_define_strp
:
26897 case DW_MACRO_undef_strp
:
26898 node
= find_AT_string (ref
->info
);
26900 && (node
->form
== DW_FORM_strp
26901 || node
->form
== DW_FORM_GNU_str_index
));
26902 dw2_asm_output_data (1, ref
->code
,
26903 ref
->code
== DW_MACRO_define_strp
26904 ? "Define macro strp"
26905 : "Undefine macro strp");
26906 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
26907 (unsigned long) ref
->lineno
);
26908 if (node
->form
== DW_FORM_strp
)
26909 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
26910 debug_str_section
, "The macro: \"%s\"",
26913 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
26916 case DW_MACRO_import
:
26917 dw2_asm_output_data (1, ref
->code
, "Import");
26918 ASM_GENERATE_INTERNAL_LABEL (label
,
26919 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
26920 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
26923 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
26924 ASM_COMMENT_START
, (unsigned long) ref
->code
);
26929 /* Attempt to make a sequence of define/undef macinfo ops shareable with
26930 other compilation unit .debug_macinfo sections. IDX is the first
26931 index of a define/undef, return the number of ops that should be
26932 emitted in a comdat .debug_macinfo section and emit
26933 a DW_MACRO_import entry referencing it.
26934 If the define/undef entry should be emitted normally, return 0. */
26937 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
26938 macinfo_hash_type
**macinfo_htab
)
26940 macinfo_entry
*first
, *second
, *cur
, *inc
;
26941 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
26942 unsigned char checksum
[16];
26943 struct md5_ctx ctx
;
26944 char *grp_name
, *tail
;
26946 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
26947 macinfo_entry
**slot
;
26949 first
= &(*macinfo_table
)[idx
];
26950 second
= &(*macinfo_table
)[idx
+ 1];
26952 /* Optimize only if there are at least two consecutive define/undef ops,
26953 and either all of them are before first DW_MACINFO_start_file
26954 with lineno {0,1} (i.e. predefined macro block), or all of them are
26955 in some included header file. */
26956 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
26958 if (vec_safe_is_empty (files
))
26960 if (first
->lineno
> 1 || second
->lineno
> 1)
26963 else if (first
->lineno
== 0)
26966 /* Find the last define/undef entry that can be grouped together
26967 with first and at the same time compute md5 checksum of their
26968 codes, linenumbers and strings. */
26969 md5_init_ctx (&ctx
);
26970 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
26971 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
26973 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
26977 unsigned char code
= cur
->code
;
26978 md5_process_bytes (&code
, 1, &ctx
);
26979 checksum_uleb128 (cur
->lineno
, &ctx
);
26980 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
26982 md5_finish_ctx (&ctx
, checksum
);
26985 /* From the containing include filename (if any) pick up just
26986 usable characters from its basename. */
26987 if (vec_safe_is_empty (files
))
26990 base
= lbasename (files
->last ().info
);
26991 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
26992 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
26993 encoded_filename_len
++;
26994 /* Count . at the end. */
26995 if (encoded_filename_len
)
26996 encoded_filename_len
++;
26998 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
26999 linebuf_len
= strlen (linebuf
);
27001 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
27002 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
27004 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
27005 tail
= grp_name
+ 4;
27006 if (encoded_filename_len
)
27008 for (i
= 0; base
[i
]; i
++)
27009 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
27013 memcpy (tail
, linebuf
, linebuf_len
);
27014 tail
+= linebuf_len
;
27016 for (i
= 0; i
< 16; i
++)
27017 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
27019 /* Construct a macinfo_entry for DW_MACRO_import
27020 in the empty vector entry before the first define/undef. */
27021 inc
= &(*macinfo_table
)[idx
- 1];
27022 inc
->code
= DW_MACRO_import
;
27024 inc
->info
= ggc_strdup (grp_name
);
27025 if (!*macinfo_htab
)
27026 *macinfo_htab
= new macinfo_hash_type (10);
27027 /* Avoid emitting duplicates. */
27028 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
27033 /* If such an entry has been used before, just emit
27034 a DW_MACRO_import op. */
27036 output_macinfo_op (inc
);
27037 /* And clear all macinfo_entry in the range to avoid emitting them
27038 in the second pass. */
27039 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
27048 inc
->lineno
= (*macinfo_htab
)->elements ();
27049 output_macinfo_op (inc
);
27054 /* Save any strings needed by the macinfo table in the debug str
27055 table. All strings must be collected into the table by the time
27056 index_string is called. */
27059 save_macinfo_strings (void)
27063 macinfo_entry
*ref
;
27065 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
27069 /* Match the logic in output_macinfo_op to decide on
27070 indirect strings. */
27071 case DW_MACINFO_define
:
27072 case DW_MACINFO_undef
:
27073 len
= strlen (ref
->info
) + 1;
27075 && len
> DWARF_OFFSET_SIZE
27076 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
27077 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
27078 set_indirect_string (find_AT_string (ref
->info
));
27080 case DW_MACRO_define_strp
:
27081 case DW_MACRO_undef_strp
:
27082 set_indirect_string (find_AT_string (ref
->info
));
27090 /* Output macinfo section(s). */
27093 output_macinfo (void)
27096 unsigned long length
= vec_safe_length (macinfo_table
);
27097 macinfo_entry
*ref
;
27098 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
27099 macinfo_hash_type
*macinfo_htab
= NULL
;
27104 /* output_macinfo* uses these interchangeably. */
27105 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_define
27106 && (int) DW_MACINFO_undef
== (int) DW_MACRO_undef
27107 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_start_file
27108 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_end_file
);
27110 /* For .debug_macro emit the section header. */
27111 if (!dwarf_strict
|| dwarf_version
>= 5)
27113 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
27114 "DWARF macro version number");
27115 if (DWARF_OFFSET_SIZE
== 8)
27116 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
27118 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
27119 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
27120 (!dwarf_split_debug_info
? debug_line_section_label
27121 : debug_skeleton_line_section_label
),
27122 debug_line_section
, NULL
);
27125 /* In the first loop, it emits the primary .debug_macinfo section
27126 and after each emitted op the macinfo_entry is cleared.
27127 If a longer range of define/undef ops can be optimized using
27128 DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
27129 the vector before the first define/undef in the range and the
27130 whole range of define/undef ops is not emitted and kept. */
27131 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
27135 case DW_MACINFO_start_file
:
27136 vec_safe_push (files
, *ref
);
27138 case DW_MACINFO_end_file
:
27139 if (!vec_safe_is_empty (files
))
27142 case DW_MACINFO_define
:
27143 case DW_MACINFO_undef
:
27144 if ((!dwarf_strict
|| dwarf_version
>= 5)
27145 && HAVE_COMDAT_GROUP
27146 && vec_safe_length (files
) != 1
27149 && (*macinfo_table
)[i
- 1].code
== 0)
27151 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
27160 /* A dummy entry may be inserted at the beginning to be able
27161 to optimize the whole block of predefined macros. */
27167 output_macinfo_op (ref
);
27175 delete macinfo_htab
;
27176 macinfo_htab
= NULL
;
27178 /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
27179 terminate the current chain and switch to a new comdat .debug_macinfo
27180 section and emit the define/undef entries within it. */
27181 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
27186 case DW_MACRO_import
:
27188 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
27189 tree comdat_key
= get_identifier (ref
->info
);
27190 /* Terminate the previous .debug_macinfo section. */
27191 dw2_asm_output_data (1, 0, "End compilation unit");
27192 targetm
.asm_out
.named_section (debug_macinfo_section_name
,
27194 | SECTION_LINKONCE
,
27196 ASM_GENERATE_INTERNAL_LABEL (label
,
27197 DEBUG_MACRO_SECTION_LABEL
,
27199 ASM_OUTPUT_LABEL (asm_out_file
, label
);
27202 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
27203 "DWARF macro version number");
27204 if (DWARF_OFFSET_SIZE
== 8)
27205 dw2_asm_output_data (1, 1, "Flags: 64-bit");
27207 dw2_asm_output_data (1, 0, "Flags: 32-bit");
27210 case DW_MACINFO_define
:
27211 case DW_MACINFO_undef
:
27212 output_macinfo_op (ref
);
27217 gcc_unreachable ();
27221 /* Initialize the various sections and labels for dwarf output. */
27224 init_sections_and_labels (void)
27226 if (!dwarf_split_debug_info
)
27228 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
27229 SECTION_DEBUG
, NULL
);
27230 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27231 SECTION_DEBUG
, NULL
);
27232 debug_loc_section
= get_section (dwarf_version
>= 5
27233 ? DEBUG_LOCLISTS_SECTION
27234 : DEBUG_LOC_SECTION
,
27235 SECTION_DEBUG
, NULL
);
27236 debug_macinfo_section_name
27237 = (dwarf_strict
&& dwarf_version
< 5)
27238 ? DEBUG_MACINFO_SECTION
: DEBUG_MACRO_SECTION
;
27239 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27240 SECTION_DEBUG
, NULL
);
27244 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
27245 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27246 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
27247 SECTION_DEBUG
| SECTION_EXCLUDE
,
27249 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
27250 SECTION_DEBUG
, NULL
);
27251 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
27252 SECTION_DEBUG
, NULL
);
27253 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27254 SECTION_DEBUG
, NULL
);
27255 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
27256 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
27258 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
27259 the main .o, but the skeleton_line goes into the split off dwo. */
27260 debug_skeleton_line_section
27261 = get_section (DEBUG_DWO_LINE_SECTION
,
27262 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27263 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27264 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
27265 debug_str_offsets_section
= get_section (DEBUG_DWO_STR_OFFSETS_SECTION
,
27266 SECTION_DEBUG
| SECTION_EXCLUDE
,
27268 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
27269 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
27270 debug_loc_section
= get_section (dwarf_version
>= 5
27271 ? DEBUG_DWO_LOCLISTS_SECTION
27272 : DEBUG_DWO_LOC_SECTION
,
27273 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27274 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
27275 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
27276 debug_macinfo_section_name
27277 = (dwarf_strict
&& dwarf_version
< 5)
27278 ? DEBUG_DWO_MACINFO_SECTION
: DEBUG_DWO_MACRO_SECTION
;
27279 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27280 SECTION_DEBUG
| SECTION_EXCLUDE
,
27283 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
27284 SECTION_DEBUG
, NULL
);
27285 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
27286 SECTION_DEBUG
, NULL
);
27287 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
27288 SECTION_DEBUG
, NULL
);
27289 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
27290 SECTION_DEBUG
, NULL
);
27291 debug_str_section
= get_section (DEBUG_STR_SECTION
,
27292 DEBUG_STR_SECTION_FLAGS
, NULL
);
27293 if (!dwarf_split_debug_info
&& !DWARF2_ASM_LINE_DEBUG_INFO
)
27294 debug_line_str_section
= get_section (DEBUG_LINE_STR_SECTION
,
27295 DEBUG_STR_SECTION_FLAGS
, NULL
);
27297 debug_ranges_section
= get_section (dwarf_version
>= 5
27298 ? DEBUG_RNGLISTS_SECTION
27299 : DEBUG_RANGES_SECTION
,
27300 SECTION_DEBUG
, NULL
);
27301 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
27302 SECTION_DEBUG
, NULL
);
27304 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
27305 DEBUG_ABBREV_SECTION_LABEL
, 0);
27306 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
27307 DEBUG_INFO_SECTION_LABEL
, 0);
27308 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
27309 DEBUG_LINE_SECTION_LABEL
, 0);
27310 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
27311 DEBUG_RANGES_SECTION_LABEL
, 0);
27312 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
27313 ASM_GENERATE_INTERNAL_LABEL (ranges_base_label
,
27314 DEBUG_RANGES_SECTION_LABEL
, 1);
27315 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
27316 DEBUG_ADDR_SECTION_LABEL
, 0);
27317 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
27318 (dwarf_strict
&& dwarf_version
< 5)
27319 ? DEBUG_MACINFO_SECTION_LABEL
27320 : DEBUG_MACRO_SECTION_LABEL
, 0);
27321 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
27324 /* Set up for Dwarf output at the start of compilation. */
27327 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
27329 /* This option is currently broken, see (PR53118 and PR46102). */
27330 if (flag_eliminate_dwarf2_dups
27331 && strstr (lang_hooks
.name
, "C++"))
27333 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
27334 flag_eliminate_dwarf2_dups
= 0;
27337 /* Allocate the file_table. */
27338 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
27340 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27341 /* Allocate the decl_die_table. */
27342 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
27344 /* Allocate the decl_loc_table. */
27345 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
27347 /* Allocate the cached_dw_loc_list_table. */
27348 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
27350 /* Allocate the initial hunk of the decl_scope_table. */
27351 vec_alloc (decl_scope_table
, 256);
27353 /* Allocate the initial hunk of the abbrev_die_table. */
27354 vec_alloc (abbrev_die_table
, 256);
27355 /* Zero-th entry is allocated, but unused. */
27356 abbrev_die_table
->quick_push (NULL
);
27358 /* Allocate the dwarf_proc_stack_usage_map. */
27359 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
27361 /* Allocate the pubtypes and pubnames vectors. */
27362 vec_alloc (pubname_table
, 32);
27363 vec_alloc (pubtype_table
, 32);
27365 vec_alloc (incomplete_types
, 64);
27367 vec_alloc (used_rtx_array
, 32);
27369 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
27370 vec_alloc (macinfo_table
, 64);
27373 /* If front-ends already registered a main translation unit but we were not
27374 ready to perform the association, do this now. */
27375 if (main_translation_unit
!= NULL_TREE
)
27376 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
27379 /* Called before compile () starts outputtting functions, variables
27380 and toplevel asms into assembly. */
27383 dwarf2out_assembly_start (void)
27385 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27386 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
27387 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
27388 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
27389 COLD_TEXT_SECTION_LABEL
, 0);
27390 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
27392 switch_to_section (text_section
);
27393 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
27396 /* Make sure the line number table for .text always exists. */
27397 text_section_line_info
= new_line_info_table ();
27398 text_section_line_info
->end_label
= text_end_label
;
27400 #ifdef DWARF2_LINENO_DEBUGGING_INFO
27401 cur_line_info_table
= text_section_line_info
;
27404 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
27405 && dwarf2out_do_cfi_asm ()
27406 && (!(flag_unwind_tables
|| flag_exceptions
)
27407 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
27408 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
27411 /* A helper function for dwarf2out_finish called through
27412 htab_traverse. Assign a string its index. All strings must be
27413 collected into the table by the time index_string is called,
27414 because the indexing code relies on htab_traverse to traverse nodes
27415 in the same order for each run. */
27418 index_string (indirect_string_node
**h
, unsigned int *index
)
27420 indirect_string_node
*node
= *h
;
27422 find_string_form (node
);
27423 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27425 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
27426 node
->index
= *index
;
27432 /* A helper function for output_indirect_strings called through
27433 htab_traverse. Output the offset to a string and update the
27437 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
27439 indirect_string_node
*node
= *h
;
27441 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27443 /* Assert that this node has been assigned an index. */
27444 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
27445 && node
->index
!= NOT_INDEXED
);
27446 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
27447 "indexed string 0x%x: %s", node
->index
, node
->str
);
27448 *offset
+= strlen (node
->str
) + 1;
27453 /* A helper function for dwarf2out_finish called through
27454 htab_traverse. Output the indexed string. */
27457 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
27459 struct indirect_string_node
*node
= *h
;
27461 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27463 /* Assert that the strings are output in the same order as their
27464 indexes were assigned. */
27465 gcc_assert (*cur_idx
== node
->index
);
27466 assemble_string (node
->str
, strlen (node
->str
) + 1);
27472 /* A helper function for dwarf2out_finish called through
27473 htab_traverse. Emit one queued .debug_str string. */
27476 output_indirect_string (indirect_string_node
**h
, enum dwarf_form form
)
27478 struct indirect_string_node
*node
= *h
;
27480 node
->form
= find_string_form (node
);
27481 if (node
->form
== form
&& node
->refcount
> 0)
27483 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
27484 assemble_string (node
->str
, strlen (node
->str
) + 1);
27490 /* Output the indexed string table. */
27493 output_indirect_strings (void)
27495 switch_to_section (debug_str_section
);
27496 if (!dwarf_split_debug_info
)
27497 debug_str_hash
->traverse
<enum dwarf_form
,
27498 output_indirect_string
> (DW_FORM_strp
);
27501 unsigned int offset
= 0;
27502 unsigned int cur_idx
= 0;
27504 skeleton_debug_str_hash
->traverse
<enum dwarf_form
,
27505 output_indirect_string
> (DW_FORM_strp
);
27507 switch_to_section (debug_str_offsets_section
);
27508 debug_str_hash
->traverse_noresize
27509 <unsigned int *, output_index_string_offset
> (&offset
);
27510 switch_to_section (debug_str_dwo_section
);
27511 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
27516 /* Callback for htab_traverse to assign an index to an entry in the
27517 table, and to write that entry to the .debug_addr section. */
27520 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
27522 addr_table_entry
*entry
= *slot
;
27524 if (entry
->refcount
== 0)
27526 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
27527 || entry
->index
== NOT_INDEXED
);
27531 gcc_assert (entry
->index
== *cur_index
);
27534 switch (entry
->kind
)
27537 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
27538 "0x%x", entry
->index
);
27540 case ate_kind_rtx_dtprel
:
27541 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
27542 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
27545 fputc ('\n', asm_out_file
);
27547 case ate_kind_label
:
27548 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
27549 "0x%x", entry
->index
);
27552 gcc_unreachable ();
27557 /* Produce the .debug_addr section. */
27560 output_addr_table (void)
27562 unsigned int index
= 0;
27563 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
27566 switch_to_section (debug_addr_section
);
27568 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
27571 #if ENABLE_ASSERT_CHECKING
27572 /* Verify that all marks are clear. */
27575 verify_marks_clear (dw_die_ref die
)
27579 gcc_assert (! die
->die_mark
);
27580 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
27582 #endif /* ENABLE_ASSERT_CHECKING */
27584 /* Clear the marks for a die and its children.
27585 Be cool if the mark isn't set. */
27588 prune_unmark_dies (dw_die_ref die
)
27594 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
27597 /* Given LOC that is referenced by a DIE we're marking as used, find all
27598 referenced DWARF procedures it references and mark them as used. */
27601 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
27603 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
27604 switch (loc
->dw_loc_opc
)
27606 case DW_OP_implicit_pointer
:
27607 case DW_OP_convert
:
27608 case DW_OP_reinterpret
:
27609 case DW_OP_GNU_implicit_pointer
:
27610 case DW_OP_GNU_convert
:
27611 case DW_OP_GNU_reinterpret
:
27612 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
27613 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27615 case DW_OP_GNU_variable_value
:
27616 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
27619 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
27622 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
27623 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
27624 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
27629 case DW_OP_call_ref
:
27630 case DW_OP_const_type
:
27631 case DW_OP_GNU_const_type
:
27632 case DW_OP_GNU_parameter_ref
:
27633 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
27634 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27636 case DW_OP_regval_type
:
27637 case DW_OP_deref_type
:
27638 case DW_OP_GNU_regval_type
:
27639 case DW_OP_GNU_deref_type
:
27640 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
27641 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
27643 case DW_OP_entry_value
:
27644 case DW_OP_GNU_entry_value
:
27645 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
27646 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
27653 /* Given DIE that we're marking as used, find any other dies
27654 it references as attributes and mark them as used. */
27657 prune_unused_types_walk_attribs (dw_die_ref die
)
27662 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27664 switch (AT_class (a
))
27666 /* Make sure DWARF procedures referenced by location descriptions will
27668 case dw_val_class_loc
:
27669 prune_unused_types_walk_loc_descr (AT_loc (a
));
27671 case dw_val_class_loc_list
:
27672 for (dw_loc_list_ref list
= AT_loc_list (a
);
27674 list
= list
->dw_loc_next
)
27675 prune_unused_types_walk_loc_descr (list
->expr
);
27678 case dw_val_class_die_ref
:
27679 /* A reference to another DIE.
27680 Make sure that it will get emitted.
27681 If it was broken out into a comdat group, don't follow it. */
27682 if (! AT_ref (a
)->comdat_type_p
27683 || a
->dw_attr
== DW_AT_specification
)
27684 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
27687 case dw_val_class_str
:
27688 /* Set the string's refcount to 0 so that prune_unused_types_mark
27689 accounts properly for it. */
27690 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
27699 /* Mark the generic parameters and arguments children DIEs of DIE. */
27702 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
27706 if (die
== NULL
|| die
->die_child
== NULL
)
27708 c
= die
->die_child
;
27711 if (is_template_parameter (c
))
27712 prune_unused_types_mark (c
, 1);
27714 } while (c
&& c
!= die
->die_child
);
27717 /* Mark DIE as being used. If DOKIDS is true, then walk down
27718 to DIE's children. */
27721 prune_unused_types_mark (dw_die_ref die
, int dokids
)
27725 if (die
->die_mark
== 0)
27727 /* We haven't done this node yet. Mark it as used. */
27729 /* If this is the DIE of a generic type instantiation,
27730 mark the children DIEs that describe its generic parms and
27732 prune_unused_types_mark_generic_parms_dies (die
);
27734 /* We also have to mark its parents as used.
27735 (But we don't want to mark our parent's kids due to this,
27736 unless it is a class.) */
27737 if (die
->die_parent
)
27738 prune_unused_types_mark (die
->die_parent
,
27739 class_scope_p (die
->die_parent
));
27741 /* Mark any referenced nodes. */
27742 prune_unused_types_walk_attribs (die
);
27744 /* If this node is a specification,
27745 also mark the definition, if it exists. */
27746 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
27747 prune_unused_types_mark (die
->die_definition
, 1);
27750 if (dokids
&& die
->die_mark
!= 2)
27752 /* We need to walk the children, but haven't done so yet.
27753 Remember that we've walked the kids. */
27756 /* If this is an array type, we need to make sure our
27757 kids get marked, even if they're types. If we're
27758 breaking out types into comdat sections, do this
27759 for all type definitions. */
27760 if (die
->die_tag
== DW_TAG_array_type
27761 || (use_debug_types
27762 && is_type_die (die
) && ! is_declaration_die (die
)))
27763 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
27765 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
27769 /* For local classes, look if any static member functions were emitted
27770 and if so, mark them. */
27773 prune_unused_types_walk_local_classes (dw_die_ref die
)
27777 if (die
->die_mark
== 2)
27780 switch (die
->die_tag
)
27782 case DW_TAG_structure_type
:
27783 case DW_TAG_union_type
:
27784 case DW_TAG_class_type
:
27787 case DW_TAG_subprogram
:
27788 if (!get_AT_flag (die
, DW_AT_declaration
)
27789 || die
->die_definition
!= NULL
)
27790 prune_unused_types_mark (die
, 1);
27797 /* Mark children. */
27798 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
27801 /* Walk the tree DIE and mark types that we actually use. */
27804 prune_unused_types_walk (dw_die_ref die
)
27808 /* Don't do anything if this node is already marked and
27809 children have been marked as well. */
27810 if (die
->die_mark
== 2)
27813 switch (die
->die_tag
)
27815 case DW_TAG_structure_type
:
27816 case DW_TAG_union_type
:
27817 case DW_TAG_class_type
:
27818 if (die
->die_perennial_p
)
27821 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
27822 if (c
->die_tag
== DW_TAG_subprogram
)
27825 /* Finding used static member functions inside of classes
27826 is needed just for local classes, because for other classes
27827 static member function DIEs with DW_AT_specification
27828 are emitted outside of the DW_TAG_*_type. If we ever change
27829 it, we'd need to call this even for non-local classes. */
27831 prune_unused_types_walk_local_classes (die
);
27833 /* It's a type node --- don't mark it. */
27836 case DW_TAG_const_type
:
27837 case DW_TAG_packed_type
:
27838 case DW_TAG_pointer_type
:
27839 case DW_TAG_reference_type
:
27840 case DW_TAG_rvalue_reference_type
:
27841 case DW_TAG_volatile_type
:
27842 case DW_TAG_typedef
:
27843 case DW_TAG_array_type
:
27844 case DW_TAG_interface_type
:
27845 case DW_TAG_friend
:
27846 case DW_TAG_enumeration_type
:
27847 case DW_TAG_subroutine_type
:
27848 case DW_TAG_string_type
:
27849 case DW_TAG_set_type
:
27850 case DW_TAG_subrange_type
:
27851 case DW_TAG_ptr_to_member_type
:
27852 case DW_TAG_file_type
:
27853 /* Type nodes are useful only when other DIEs reference them --- don't
27857 case DW_TAG_dwarf_procedure
:
27858 /* Likewise for DWARF procedures. */
27860 if (die
->die_perennial_p
)
27866 /* Mark everything else. */
27870 if (die
->die_mark
== 0)
27874 /* Now, mark any dies referenced from here. */
27875 prune_unused_types_walk_attribs (die
);
27880 /* Mark children. */
27881 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
27884 /* Increment the string counts on strings referred to from DIE's
27888 prune_unused_types_update_strings (dw_die_ref die
)
27893 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27894 if (AT_class (a
) == dw_val_class_str
)
27896 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
27898 /* Avoid unnecessarily putting strings that are used less than
27899 twice in the hash table. */
27901 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
27903 indirect_string_node
**slot
27904 = debug_str_hash
->find_slot_with_hash (s
->str
,
27905 htab_hash_string (s
->str
),
27907 gcc_assert (*slot
== NULL
);
27913 /* Mark DIE and its children as removed. */
27916 mark_removed (dw_die_ref die
)
27919 die
->removed
= true;
27920 FOR_EACH_CHILD (die
, c
, mark_removed (c
));
27923 /* Remove from the tree DIE any dies that aren't marked. */
27926 prune_unused_types_prune (dw_die_ref die
)
27930 gcc_assert (die
->die_mark
);
27931 prune_unused_types_update_strings (die
);
27933 if (! die
->die_child
)
27936 c
= die
->die_child
;
27938 dw_die_ref prev
= c
, next
;
27939 for (c
= c
->die_sib
; ! c
->die_mark
; c
= next
)
27940 if (c
== die
->die_child
)
27942 /* No marked children between 'prev' and the end of the list. */
27944 /* No marked children at all. */
27945 die
->die_child
= NULL
;
27948 prev
->die_sib
= c
->die_sib
;
27949 die
->die_child
= prev
;
27962 if (c
!= prev
->die_sib
)
27964 prune_unused_types_prune (c
);
27965 } while (c
!= die
->die_child
);
27968 /* Remove dies representing declarations that we never use. */
27971 prune_unused_types (void)
27974 limbo_die_node
*node
;
27975 comdat_type_node
*ctnode
;
27976 pubname_entry
*pub
;
27977 dw_die_ref base_type
;
27979 #if ENABLE_ASSERT_CHECKING
27980 /* All the marks should already be clear. */
27981 verify_marks_clear (comp_unit_die ());
27982 for (node
= limbo_die_list
; node
; node
= node
->next
)
27983 verify_marks_clear (node
->die
);
27984 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27985 verify_marks_clear (ctnode
->root_die
);
27986 #endif /* ENABLE_ASSERT_CHECKING */
27988 /* Mark types that are used in global variables. */
27989 premark_types_used_by_global_vars ();
27991 /* Set the mark on nodes that are actually used. */
27992 prune_unused_types_walk (comp_unit_die ());
27993 for (node
= limbo_die_list
; node
; node
= node
->next
)
27994 prune_unused_types_walk (node
->die
);
27995 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27997 prune_unused_types_walk (ctnode
->root_die
);
27998 prune_unused_types_mark (ctnode
->type_die
, 1);
28001 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
28002 are unusual in that they are pubnames that are the children of pubtypes.
28003 They should only be marked via their parent DW_TAG_enumeration_type die,
28004 not as roots in themselves. */
28005 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
28006 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
28007 prune_unused_types_mark (pub
->die
, 1);
28008 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
28009 prune_unused_types_mark (base_type
, 1);
28011 /* For -fvar-tracking-assignments, also set the mark on nodes that could be
28012 referenced by DW_TAG_call_site DW_AT_call_origin (i.e. direct call
28014 cgraph_node
*cnode
;
28015 FOR_EACH_FUNCTION (cnode
)
28016 if (cnode
->referred_to_p (false))
28018 dw_die_ref die
= lookup_decl_die (cnode
->decl
);
28019 if (die
== NULL
|| die
->die_mark
)
28021 for (cgraph_edge
*e
= cnode
->callers
; e
; e
= e
->next_caller
)
28022 if (e
->caller
!= cnode
28023 && opt_for_fn (e
->caller
->decl
, flag_var_tracking_assignments
))
28025 prune_unused_types_mark (die
, 1);
28030 if (debug_str_hash
)
28031 debug_str_hash
->empty ();
28032 if (skeleton_debug_str_hash
)
28033 skeleton_debug_str_hash
->empty ();
28034 prune_unused_types_prune (comp_unit_die ());
28035 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
28038 if (!node
->die
->die_mark
)
28039 *pnode
= node
->next
;
28042 prune_unused_types_prune (node
->die
);
28043 pnode
= &node
->next
;
28046 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28047 prune_unused_types_prune (ctnode
->root_die
);
28049 /* Leave the marks clear. */
28050 prune_unmark_dies (comp_unit_die ());
28051 for (node
= limbo_die_list
; node
; node
= node
->next
)
28052 prune_unmark_dies (node
->die
);
28053 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28054 prune_unmark_dies (ctnode
->root_die
);
28057 /* Helpers to manipulate hash table of comdat type units. */
28059 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
28061 static inline hashval_t
hash (const comdat_type_node
*);
28062 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
28066 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
28069 memcpy (&h
, type_node
->signature
, sizeof (h
));
28074 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
28075 const comdat_type_node
*type_node_2
)
28077 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
28078 DWARF_TYPE_SIGNATURE_SIZE
));
28081 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
28082 to the location it would have been added, should we know its
28083 DECL_ASSEMBLER_NAME when we added other attributes. This will
28084 probably improve compactness of debug info, removing equivalent
28085 abbrevs, and hide any differences caused by deferring the
28086 computation of the assembler name, triggered by e.g. PCH. */
28089 move_linkage_attr (dw_die_ref die
)
28091 unsigned ix
= vec_safe_length (die
->die_attr
);
28092 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
28094 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
28095 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
28099 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
28101 if (prev
->dw_attr
== DW_AT_decl_line
28102 || prev
->dw_attr
== DW_AT_decl_column
28103 || prev
->dw_attr
== DW_AT_name
)
28107 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
28109 die
->die_attr
->pop ();
28110 die
->die_attr
->quick_insert (ix
, linkage
);
28114 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
28115 referenced from typed stack ops and count how often they are used. */
28118 mark_base_types (dw_loc_descr_ref loc
)
28120 dw_die_ref base_type
= NULL
;
28122 for (; loc
; loc
= loc
->dw_loc_next
)
28124 switch (loc
->dw_loc_opc
)
28126 case DW_OP_regval_type
:
28127 case DW_OP_deref_type
:
28128 case DW_OP_GNU_regval_type
:
28129 case DW_OP_GNU_deref_type
:
28130 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
28132 case DW_OP_convert
:
28133 case DW_OP_reinterpret
:
28134 case DW_OP_GNU_convert
:
28135 case DW_OP_GNU_reinterpret
:
28136 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
28139 case DW_OP_const_type
:
28140 case DW_OP_GNU_const_type
:
28141 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28143 case DW_OP_entry_value
:
28144 case DW_OP_GNU_entry_value
:
28145 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
28150 gcc_assert (base_type
->die_parent
== comp_unit_die ());
28151 if (base_type
->die_mark
)
28152 base_type
->die_mark
++;
28155 base_types
.safe_push (base_type
);
28156 base_type
->die_mark
= 1;
28161 /* Comparison function for sorting marked base types. */
28164 base_type_cmp (const void *x
, const void *y
)
28166 dw_die_ref dx
= *(const dw_die_ref
*) x
;
28167 dw_die_ref dy
= *(const dw_die_ref
*) y
;
28168 unsigned int byte_size1
, byte_size2
;
28169 unsigned int encoding1
, encoding2
;
28170 unsigned int align1
, align2
;
28171 if (dx
->die_mark
> dy
->die_mark
)
28173 if (dx
->die_mark
< dy
->die_mark
)
28175 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
28176 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
28177 if (byte_size1
< byte_size2
)
28179 if (byte_size1
> byte_size2
)
28181 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
28182 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
28183 if (encoding1
< encoding2
)
28185 if (encoding1
> encoding2
)
28187 align1
= get_AT_unsigned (dx
, DW_AT_alignment
);
28188 align2
= get_AT_unsigned (dy
, DW_AT_alignment
);
28189 if (align1
< align2
)
28191 if (align1
> align2
)
28196 /* Move base types marked by mark_base_types as early as possible
28197 in the CU, sorted by decreasing usage count both to make the
28198 uleb128 references as small as possible and to make sure they
28199 will have die_offset already computed by calc_die_sizes when
28200 sizes of typed stack loc ops is computed. */
28203 move_marked_base_types (void)
28206 dw_die_ref base_type
, die
, c
;
28208 if (base_types
.is_empty ())
28211 /* Sort by decreasing usage count, they will be added again in that
28213 base_types
.qsort (base_type_cmp
);
28214 die
= comp_unit_die ();
28215 c
= die
->die_child
;
28218 dw_die_ref prev
= c
;
28220 while (c
->die_mark
)
28222 remove_child_with_prev (c
, prev
);
28223 /* As base types got marked, there must be at least
28224 one node other than DW_TAG_base_type. */
28225 gcc_assert (die
->die_child
!= NULL
);
28229 while (c
!= die
->die_child
);
28230 gcc_assert (die
->die_child
);
28231 c
= die
->die_child
;
28232 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
28234 base_type
->die_mark
= 0;
28235 base_type
->die_sib
= c
->die_sib
;
28236 c
->die_sib
= base_type
;
28241 /* Helper function for resolve_addr, attempt to resolve
28242 one CONST_STRING, return true if successful. Similarly verify that
28243 SYMBOL_REFs refer to variables emitted in the current CU. */
28246 resolve_one_addr (rtx
*addr
)
28250 if (GET_CODE (rtl
) == CONST_STRING
)
28252 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28253 tree t
= build_string (len
, XSTR (rtl
, 0));
28254 tree tlen
= size_int (len
- 1);
28256 = build_array_type (char_type_node
, build_index_type (tlen
));
28257 rtl
= lookup_constant_def (t
);
28258 if (!rtl
|| !MEM_P (rtl
))
28260 rtl
= XEXP (rtl
, 0);
28261 if (GET_CODE (rtl
) == SYMBOL_REF
28262 && SYMBOL_REF_DECL (rtl
)
28263 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28265 vec_safe_push (used_rtx_array
, rtl
);
28270 if (GET_CODE (rtl
) == SYMBOL_REF
28271 && SYMBOL_REF_DECL (rtl
))
28273 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
28275 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
28278 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28282 if (GET_CODE (rtl
) == CONST
)
28284 subrtx_ptr_iterator::array_type array
;
28285 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
28286 if (!resolve_one_addr (*iter
))
28293 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
28294 if possible, and create DW_TAG_dwarf_procedure that can be referenced
28295 from DW_OP_implicit_pointer if the string hasn't been seen yet. */
28298 string_cst_pool_decl (tree t
)
28300 rtx rtl
= output_constant_def (t
, 1);
28301 unsigned char *array
;
28302 dw_loc_descr_ref l
;
28307 if (!rtl
|| !MEM_P (rtl
))
28309 rtl
= XEXP (rtl
, 0);
28310 if (GET_CODE (rtl
) != SYMBOL_REF
28311 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
28314 decl
= SYMBOL_REF_DECL (rtl
);
28315 if (!lookup_decl_die (decl
))
28317 len
= TREE_STRING_LENGTH (t
);
28318 vec_safe_push (used_rtx_array
, rtl
);
28319 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
28320 array
= ggc_vec_alloc
<unsigned char> (len
);
28321 memcpy (array
, TREE_STRING_POINTER (t
), len
);
28322 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
28323 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
28324 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
28325 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
28326 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
28327 add_AT_loc (ref
, DW_AT_location
, l
);
28328 equate_decl_number_to_die (decl
, ref
);
28333 /* Helper function of resolve_addr_in_expr. LOC is
28334 a DW_OP_addr followed by DW_OP_stack_value, either at the start
28335 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
28336 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
28337 with DW_OP_implicit_pointer if possible
28338 and return true, if unsuccessful, return false. */
28341 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
28343 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
28344 HOST_WIDE_INT offset
= 0;
28345 dw_die_ref ref
= NULL
;
28348 if (GET_CODE (rtl
) == CONST
28349 && GET_CODE (XEXP (rtl
, 0)) == PLUS
28350 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
28352 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
28353 rtl
= XEXP (XEXP (rtl
, 0), 0);
28355 if (GET_CODE (rtl
) == CONST_STRING
)
28357 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28358 tree t
= build_string (len
, XSTR (rtl
, 0));
28359 tree tlen
= size_int (len
- 1);
28362 = build_array_type (char_type_node
, build_index_type (tlen
));
28363 rtl
= string_cst_pool_decl (t
);
28367 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
28369 decl
= SYMBOL_REF_DECL (rtl
);
28370 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
28372 ref
= lookup_decl_die (decl
);
28373 if (ref
&& (get_AT (ref
, DW_AT_location
)
28374 || get_AT (ref
, DW_AT_const_value
)))
28376 loc
->dw_loc_opc
= dwarf_OP (DW_OP_implicit_pointer
);
28377 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28378 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
28379 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28380 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28381 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28382 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
28390 /* Helper function for resolve_addr, handle one location
28391 expression, return false if at least one CONST_STRING or SYMBOL_REF in
28392 the location list couldn't be resolved. */
28395 resolve_addr_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
28397 dw_loc_descr_ref keep
= NULL
;
28398 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
28399 switch (loc
->dw_loc_opc
)
28402 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28405 || prev
->dw_loc_opc
== DW_OP_piece
28406 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
28407 && loc
->dw_loc_next
28408 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
28409 && (!dwarf_strict
|| dwarf_version
>= 5)
28410 && optimize_one_addr_into_implicit_ptr (loc
))
28415 case DW_OP_GNU_addr_index
:
28416 case DW_OP_GNU_const_index
:
28417 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
28418 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
28420 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
28421 if (!resolve_one_addr (&rtl
))
28423 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
28424 loc
->dw_loc_oprnd1
.val_entry
28425 = add_addr_table_entry (rtl
, ate_kind_rtx
);
28428 case DW_OP_const4u
:
28429 case DW_OP_const8u
:
28431 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28434 case DW_OP_plus_uconst
:
28435 if (size_of_loc_descr (loc
)
28436 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
28438 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
28440 dw_loc_descr_ref repl
28441 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
28442 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
28443 add_loc_descr (&repl
, loc
->dw_loc_next
);
28447 case DW_OP_implicit_value
:
28448 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
28449 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
28452 case DW_OP_implicit_pointer
:
28453 case DW_OP_GNU_implicit_pointer
:
28454 case DW_OP_GNU_parameter_ref
:
28455 case DW_OP_GNU_variable_value
:
28456 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28459 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
28462 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28463 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28464 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28466 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
)
28469 && loc
->dw_loc_next
== NULL
28470 && AT_class (a
) == dw_val_class_loc
)
28471 switch (a
->dw_attr
)
28473 /* Following attributes allow both exprloc and reference,
28474 so if the whole expression is DW_OP_GNU_variable_value
28475 alone we could transform it into reference. */
28476 case DW_AT_byte_size
:
28477 case DW_AT_bit_size
:
28478 case DW_AT_lower_bound
:
28479 case DW_AT_upper_bound
:
28480 case DW_AT_bit_stride
:
28482 case DW_AT_allocated
:
28483 case DW_AT_associated
:
28484 case DW_AT_byte_stride
:
28485 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
28486 a
->dw_attr_val
.val_entry
= NULL
;
28487 a
->dw_attr_val
.v
.val_die_ref
.die
28488 = loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28489 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
28498 case DW_OP_const_type
:
28499 case DW_OP_regval_type
:
28500 case DW_OP_deref_type
:
28501 case DW_OP_convert
:
28502 case DW_OP_reinterpret
:
28503 case DW_OP_GNU_const_type
:
28504 case DW_OP_GNU_regval_type
:
28505 case DW_OP_GNU_deref_type
:
28506 case DW_OP_GNU_convert
:
28507 case DW_OP_GNU_reinterpret
:
28508 while (loc
->dw_loc_next
28509 && (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_convert
28510 || loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
))
28512 dw_die_ref base1
, base2
;
28513 unsigned enc1
, enc2
, size1
, size2
;
28514 if (loc
->dw_loc_opc
== DW_OP_regval_type
28515 || loc
->dw_loc_opc
== DW_OP_deref_type
28516 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28517 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28518 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
28519 else if (loc
->dw_loc_oprnd1
.val_class
28520 == dw_val_class_unsigned_const
)
28523 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28524 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
28525 == dw_val_class_unsigned_const
)
28527 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28528 gcc_assert (base1
->die_tag
== DW_TAG_base_type
28529 && base2
->die_tag
== DW_TAG_base_type
);
28530 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
28531 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
28532 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
28533 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
28535 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
28536 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
28540 /* Optimize away next DW_OP_convert after
28541 adjusting LOC's base type die reference. */
28542 if (loc
->dw_loc_opc
== DW_OP_regval_type
28543 || loc
->dw_loc_opc
== DW_OP_deref_type
28544 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28545 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28546 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
28548 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
28549 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28552 /* Don't change integer DW_OP_convert after e.g. floating
28553 point typed stack entry. */
28554 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
28555 keep
= loc
->dw_loc_next
;
28565 /* Helper function of resolve_addr. DIE had DW_AT_location of
28566 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
28567 and DW_OP_addr couldn't be resolved. resolve_addr has already
28568 removed the DW_AT_location attribute. This function attempts to
28569 add a new DW_AT_location attribute with DW_OP_implicit_pointer
28570 to it or DW_AT_const_value attribute, if possible. */
28573 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
28576 || lookup_decl_die (decl
) != die
28577 || DECL_EXTERNAL (decl
)
28578 || !TREE_STATIC (decl
)
28579 || DECL_INITIAL (decl
) == NULL_TREE
28580 || DECL_P (DECL_INITIAL (decl
))
28581 || get_AT (die
, DW_AT_const_value
))
28584 tree init
= DECL_INITIAL (decl
);
28585 HOST_WIDE_INT offset
= 0;
28586 /* For variables that have been optimized away and thus
28587 don't have a memory location, see if we can emit
28588 DW_AT_const_value instead. */
28589 if (tree_add_const_value_attribute (die
, init
))
28591 if (dwarf_strict
&& dwarf_version
< 5)
28593 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
28594 and ADDR_EXPR refers to a decl that has DW_AT_location or
28595 DW_AT_const_value (but isn't addressable, otherwise
28596 resolving the original DW_OP_addr wouldn't fail), see if
28597 we can add DW_OP_implicit_pointer. */
28599 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
28600 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
28602 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
28603 init
= TREE_OPERAND (init
, 0);
28606 if (TREE_CODE (init
) != ADDR_EXPR
)
28608 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
28609 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
28610 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
28611 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
28612 && TREE_OPERAND (init
, 0) != decl
))
28615 dw_loc_descr_ref l
;
28617 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
28619 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
28622 decl
= SYMBOL_REF_DECL (rtl
);
28625 decl
= TREE_OPERAND (init
, 0);
28626 ref
= lookup_decl_die (decl
);
28628 || (!get_AT (ref
, DW_AT_location
)
28629 && !get_AT (ref
, DW_AT_const_value
)))
28631 l
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
28632 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28633 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28634 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28635 add_AT_loc (die
, DW_AT_location
, l
);
28639 /* Return NULL if l is a DWARF expression, or first op that is not
28640 valid DWARF expression. */
28642 static dw_loc_descr_ref
28643 non_dwarf_expression (dw_loc_descr_ref l
)
28647 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28649 switch (l
->dw_loc_opc
)
28652 case DW_OP_implicit_value
:
28653 case DW_OP_stack_value
:
28654 case DW_OP_implicit_pointer
:
28655 case DW_OP_GNU_implicit_pointer
:
28656 case DW_OP_GNU_parameter_ref
:
28658 case DW_OP_bit_piece
:
28663 l
= l
->dw_loc_next
;
28668 /* Return adjusted copy of EXPR:
28669 If it is empty DWARF expression, return it.
28670 If it is valid non-empty DWARF expression,
28671 return copy of EXPR with DW_OP_deref appended to it.
28672 If it is DWARF expression followed by DW_OP_reg{N,x}, return
28673 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
28674 If it is DWARF expression followed by DW_OP_stack_value, return
28675 copy of the DWARF expression without anything appended.
28676 Otherwise, return NULL. */
28678 static dw_loc_descr_ref
28679 copy_deref_exprloc (dw_loc_descr_ref expr
)
28681 dw_loc_descr_ref tail
= NULL
;
28686 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
28687 if (l
&& l
->dw_loc_next
)
28692 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28693 tail
= new_loc_descr ((enum dwarf_location_atom
)
28694 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
28697 switch (l
->dw_loc_opc
)
28700 tail
= new_loc_descr (DW_OP_bregx
,
28701 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
28703 case DW_OP_stack_value
:
28710 tail
= new_loc_descr (DW_OP_deref
, 0, 0);
28712 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
28715 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
28716 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
28717 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
28718 p
= &(*p
)->dw_loc_next
;
28719 expr
= expr
->dw_loc_next
;
28725 /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
28726 reference to a variable or argument, adjust it if needed and return:
28727 -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
28728 attribute if present should be removed
28729 0 keep the attribute perhaps with minor modifications, no need to rescan
28730 1 if the attribute has been successfully adjusted. */
28733 optimize_string_length (dw_attr_node
*a
)
28735 dw_loc_descr_ref l
= AT_loc (a
), lv
;
28737 if (l
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28739 tree decl
= l
->dw_loc_oprnd1
.v
.val_decl_ref
;
28740 die
= lookup_decl_die (decl
);
28743 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28744 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= die
;
28745 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28751 die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28753 /* DWARF5 allows reference class, so we can then reference the DIE.
28754 Only do this for DW_OP_GNU_variable_value DW_OP_stack_value. */
28755 if (l
->dw_loc_next
!= NULL
&& dwarf_version
>= 5)
28757 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
28758 a
->dw_attr_val
.val_entry
= NULL
;
28759 a
->dw_attr_val
.v
.val_die_ref
.die
= die
;
28760 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
28764 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
28766 bool non_dwarf_expr
= false;
28769 return dwarf_strict
? -1 : 0;
28770 switch (AT_class (av
))
28772 case dw_val_class_loc_list
:
28773 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
28774 if (d
->expr
&& non_dwarf_expression (d
->expr
))
28775 non_dwarf_expr
= true;
28777 case dw_val_class_loc
:
28780 return dwarf_strict
? -1 : 0;
28781 if (non_dwarf_expression (lv
))
28782 non_dwarf_expr
= true;
28785 return dwarf_strict
? -1 : 0;
28788 /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
28789 into DW_OP_call4 or DW_OP_GNU_variable_value into
28790 DW_OP_call4 DW_OP_deref, do so. */
28791 if (!non_dwarf_expr
28792 && (l
->dw_loc_next
!= NULL
|| AT_class (av
) == dw_val_class_loc
))
28794 l
->dw_loc_opc
= DW_OP_call4
;
28795 if (l
->dw_loc_next
)
28796 l
->dw_loc_next
= NULL
;
28798 l
->dw_loc_next
= new_loc_descr (DW_OP_deref
, 0, 0);
28802 /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
28803 copy over the DW_AT_location attribute from die to a. */
28804 if (l
->dw_loc_next
!= NULL
)
28806 a
->dw_attr_val
= av
->dw_attr_val
;
28810 dw_loc_list_ref list
, *p
;
28811 switch (AT_class (av
))
28813 case dw_val_class_loc_list
:
28816 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
28818 lv
= copy_deref_exprloc (d
->expr
);
28821 *p
= new_loc_list (lv
, d
->begin
, d
->end
, d
->section
);
28822 p
= &(*p
)->dw_loc_next
;
28824 else if (!dwarf_strict
&& d
->expr
)
28828 return dwarf_strict
? -1 : 0;
28829 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
28831 *AT_loc_list_ptr (a
) = list
;
28833 case dw_val_class_loc
:
28834 lv
= copy_deref_exprloc (AT_loc (av
));
28836 return dwarf_strict
? -1 : 0;
28837 a
->dw_attr_val
.v
.val_loc
= lv
;
28840 gcc_unreachable ();
28844 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
28845 an address in .rodata section if the string literal is emitted there,
28846 or remove the containing location list or replace DW_AT_const_value
28847 with DW_AT_location and empty location expression, if it isn't found
28848 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
28849 to something that has been emitted in the current CU. */
28852 resolve_addr (dw_die_ref die
)
28856 dw_loc_list_ref
*curr
, *start
, loc
;
28858 bool remove_AT_byte_size
= false;
28860 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
28861 switch (AT_class (a
))
28863 case dw_val_class_loc_list
:
28864 start
= curr
= AT_loc_list_ptr (a
);
28867 /* The same list can be referenced more than once. See if we have
28868 already recorded the result from a previous pass. */
28870 *curr
= loc
->dw_loc_next
;
28871 else if (!loc
->resolved_addr
)
28873 /* As things stand, we do not expect or allow one die to
28874 reference a suffix of another die's location list chain.
28875 References must be identical or completely separate.
28876 There is therefore no need to cache the result of this
28877 pass on any list other than the first; doing so
28878 would lead to unnecessary writes. */
28881 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
28882 if (!resolve_addr_in_expr (a
, (*curr
)->expr
))
28884 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
28885 dw_loc_descr_ref l
= (*curr
)->expr
;
28887 if (next
&& (*curr
)->ll_symbol
)
28889 gcc_assert (!next
->ll_symbol
);
28890 next
->ll_symbol
= (*curr
)->ll_symbol
;
28892 if (dwarf_split_debug_info
)
28893 remove_loc_list_addr_table_entries (l
);
28898 mark_base_types ((*curr
)->expr
);
28899 curr
= &(*curr
)->dw_loc_next
;
28903 loc
->resolved_addr
= 1;
28907 loc
->dw_loc_next
= *start
;
28912 remove_AT (die
, a
->dw_attr
);
28916 case dw_val_class_loc
:
28918 dw_loc_descr_ref l
= AT_loc (a
);
28919 /* DW_OP_GNU_variable_value DW_OP_stack_value or
28920 DW_OP_GNU_variable_value in DW_AT_string_length can be converted
28921 into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
28922 DWARF4 unlike DW_OP_GNU_variable_value. Or for DWARF5
28923 DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
28924 with DW_FORM_ref referencing the same DIE as
28925 DW_OP_GNU_variable_value used to reference. */
28926 if (a
->dw_attr
== DW_AT_string_length
28928 && l
->dw_loc_opc
== DW_OP_GNU_variable_value
28929 && (l
->dw_loc_next
== NULL
28930 || (l
->dw_loc_next
->dw_loc_next
== NULL
28931 && l
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
)))
28933 switch (optimize_string_length (a
))
28936 remove_AT (die
, a
->dw_attr
);
28938 /* If we drop DW_AT_string_length, we need to drop also
28939 DW_AT_{string_length_,}byte_size. */
28940 remove_AT_byte_size
= true;
28945 /* Even if we keep the optimized DW_AT_string_length,
28946 it might have changed AT_class, so process it again. */
28951 /* For -gdwarf-2 don't attempt to optimize
28952 DW_AT_data_member_location containing
28953 DW_OP_plus_uconst - older consumers might
28954 rely on it being that op instead of a more complex,
28955 but shorter, location description. */
28956 if ((dwarf_version
> 2
28957 || a
->dw_attr
!= DW_AT_data_member_location
28959 || l
->dw_loc_opc
!= DW_OP_plus_uconst
28960 || l
->dw_loc_next
!= NULL
)
28961 && !resolve_addr_in_expr (a
, l
))
28963 if (dwarf_split_debug_info
)
28964 remove_loc_list_addr_table_entries (l
);
28966 && l
->dw_loc_next
== NULL
28967 && l
->dw_loc_opc
== DW_OP_addr
28968 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
28969 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
28970 && a
->dw_attr
== DW_AT_location
)
28972 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
28973 remove_AT (die
, a
->dw_attr
);
28975 optimize_location_into_implicit_ptr (die
, decl
);
28978 if (a
->dw_attr
== DW_AT_string_length
)
28979 /* If we drop DW_AT_string_length, we need to drop also
28980 DW_AT_{string_length_,}byte_size. */
28981 remove_AT_byte_size
= true;
28982 remove_AT (die
, a
->dw_attr
);
28986 mark_base_types (l
);
28989 case dw_val_class_addr
:
28990 if (a
->dw_attr
== DW_AT_const_value
28991 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
28993 if (AT_index (a
) != NOT_INDEXED
)
28994 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
28995 remove_AT (die
, a
->dw_attr
);
28998 if ((die
->die_tag
== DW_TAG_call_site
28999 && a
->dw_attr
== DW_AT_call_origin
)
29000 || (die
->die_tag
== DW_TAG_GNU_call_site
29001 && a
->dw_attr
== DW_AT_abstract_origin
))
29003 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
29004 dw_die_ref tdie
= lookup_decl_die (tdecl
);
29007 && DECL_EXTERNAL (tdecl
)
29008 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
29009 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
29011 dw_die_ref pdie
= cdie
;
29012 /* Make sure we don't add these DIEs into type units.
29013 We could emit skeleton DIEs for context (namespaces,
29014 outer structs/classes) and a skeleton DIE for the
29015 innermost context with DW_AT_signature pointing to the
29016 type unit. See PR78835. */
29017 while (pdie
&& pdie
->die_tag
!= DW_TAG_type_unit
)
29018 pdie
= pdie
->die_parent
;
29021 /* Creating a full DIE for tdecl is overly expensive and
29022 at this point even wrong when in the LTO phase
29023 as it can end up generating new type DIEs we didn't
29024 output and thus optimize_external_refs will crash. */
29025 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
29026 add_AT_flag (tdie
, DW_AT_external
, 1);
29027 add_AT_flag (tdie
, DW_AT_declaration
, 1);
29028 add_linkage_attr (tdie
, tdecl
);
29029 add_name_and_src_coords_attributes (tdie
, tdecl
);
29030 equate_decl_number_to_die (tdecl
, tdie
);
29035 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
29036 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
29037 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
29041 if (AT_index (a
) != NOT_INDEXED
)
29042 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
29043 remove_AT (die
, a
->dw_attr
);
29052 if (remove_AT_byte_size
)
29053 remove_AT (die
, dwarf_version
>= 5
29054 ? DW_AT_string_length_byte_size
29055 : DW_AT_byte_size
);
29057 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
29060 /* Helper routines for optimize_location_lists.
29061 This pass tries to share identical local lists in .debug_loc
29064 /* Iteratively hash operands of LOC opcode into HSTATE. */
29067 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
29069 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
29070 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
29072 switch (loc
->dw_loc_opc
)
29074 case DW_OP_const4u
:
29075 case DW_OP_const8u
:
29079 case DW_OP_const1u
:
29080 case DW_OP_const1s
:
29081 case DW_OP_const2u
:
29082 case DW_OP_const2s
:
29083 case DW_OP_const4s
:
29084 case DW_OP_const8s
:
29088 case DW_OP_plus_uconst
:
29124 case DW_OP_deref_size
:
29125 case DW_OP_xderef_size
:
29126 hstate
.add_object (val1
->v
.val_int
);
29133 gcc_assert (val1
->val_class
== dw_val_class_loc
);
29134 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
29135 hstate
.add_object (offset
);
29138 case DW_OP_implicit_value
:
29139 hstate
.add_object (val1
->v
.val_unsigned
);
29140 switch (val2
->val_class
)
29142 case dw_val_class_const
:
29143 hstate
.add_object (val2
->v
.val_int
);
29145 case dw_val_class_vec
:
29147 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
29148 unsigned int len
= val2
->v
.val_vec
.length
;
29150 hstate
.add_int (elt_size
);
29151 hstate
.add_int (len
);
29152 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
29155 case dw_val_class_const_double
:
29156 hstate
.add_object (val2
->v
.val_double
.low
);
29157 hstate
.add_object (val2
->v
.val_double
.high
);
29159 case dw_val_class_wide_int
:
29160 hstate
.add (val2
->v
.val_wide
->get_val (),
29161 get_full_len (*val2
->v
.val_wide
)
29162 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
29164 case dw_val_class_addr
:
29165 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
29168 gcc_unreachable ();
29172 case DW_OP_bit_piece
:
29173 hstate
.add_object (val1
->v
.val_int
);
29174 hstate
.add_object (val2
->v
.val_int
);
29180 unsigned char dtprel
= 0xd1;
29181 hstate
.add_object (dtprel
);
29183 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
29185 case DW_OP_GNU_addr_index
:
29186 case DW_OP_GNU_const_index
:
29190 unsigned char dtprel
= 0xd1;
29191 hstate
.add_object (dtprel
);
29193 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
29196 case DW_OP_implicit_pointer
:
29197 case DW_OP_GNU_implicit_pointer
:
29198 hstate
.add_int (val2
->v
.val_int
);
29200 case DW_OP_entry_value
:
29201 case DW_OP_GNU_entry_value
:
29202 hstate
.add_object (val1
->v
.val_loc
);
29204 case DW_OP_regval_type
:
29205 case DW_OP_deref_type
:
29206 case DW_OP_GNU_regval_type
:
29207 case DW_OP_GNU_deref_type
:
29209 unsigned int byte_size
29210 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
29211 unsigned int encoding
29212 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
29213 hstate
.add_object (val1
->v
.val_int
);
29214 hstate
.add_object (byte_size
);
29215 hstate
.add_object (encoding
);
29218 case DW_OP_convert
:
29219 case DW_OP_reinterpret
:
29220 case DW_OP_GNU_convert
:
29221 case DW_OP_GNU_reinterpret
:
29222 if (val1
->val_class
== dw_val_class_unsigned_const
)
29224 hstate
.add_object (val1
->v
.val_unsigned
);
29228 case DW_OP_const_type
:
29229 case DW_OP_GNU_const_type
:
29231 unsigned int byte_size
29232 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
29233 unsigned int encoding
29234 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
29235 hstate
.add_object (byte_size
);
29236 hstate
.add_object (encoding
);
29237 if (loc
->dw_loc_opc
!= DW_OP_const_type
29238 && loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
29240 hstate
.add_object (val2
->val_class
);
29241 switch (val2
->val_class
)
29243 case dw_val_class_const
:
29244 hstate
.add_object (val2
->v
.val_int
);
29246 case dw_val_class_vec
:
29248 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
29249 unsigned int len
= val2
->v
.val_vec
.length
;
29251 hstate
.add_object (elt_size
);
29252 hstate
.add_object (len
);
29253 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
29256 case dw_val_class_const_double
:
29257 hstate
.add_object (val2
->v
.val_double
.low
);
29258 hstate
.add_object (val2
->v
.val_double
.high
);
29260 case dw_val_class_wide_int
:
29261 hstate
.add (val2
->v
.val_wide
->get_val (),
29262 get_full_len (*val2
->v
.val_wide
)
29263 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
29266 gcc_unreachable ();
29272 /* Other codes have no operands. */
29277 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
29280 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
29282 dw_loc_descr_ref l
;
29283 bool sizes_computed
= false;
29284 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
29285 size_of_locs (loc
);
29287 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
29289 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
29290 hstate
.add_object (opc
);
29291 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
29293 size_of_locs (loc
);
29294 sizes_computed
= true;
29296 hash_loc_operands (l
, hstate
);
29300 /* Compute hash of the whole location list LIST_HEAD. */
29303 hash_loc_list (dw_loc_list_ref list_head
)
29305 dw_loc_list_ref curr
= list_head
;
29306 inchash::hash hstate
;
29308 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29310 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
29311 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
29313 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
29314 hash_locs (curr
->expr
, hstate
);
29316 list_head
->hash
= hstate
.end ();
29319 /* Return true if X and Y opcodes have the same operands. */
29322 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29324 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
29325 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
29326 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
29327 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
29329 switch (x
->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 return valx1
->v
.val_int
== valy1
->v
.val_int
;
29386 /* If splitting debug info, the use of DW_OP_GNU_addr_index
29387 can cause irrelevant differences in dw_loc_addr. */
29388 gcc_assert (valx1
->val_class
== dw_val_class_loc
29389 && valy1
->val_class
== dw_val_class_loc
29390 && (dwarf_split_debug_info
29391 || x
->dw_loc_addr
== y
->dw_loc_addr
));
29392 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
29393 case DW_OP_implicit_value
:
29394 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
29395 || valx2
->val_class
!= valy2
->val_class
)
29397 switch (valx2
->val_class
)
29399 case dw_val_class_const
:
29400 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29401 case dw_val_class_vec
:
29402 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29403 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29404 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29405 valx2
->v
.val_vec
.elt_size
29406 * valx2
->v
.val_vec
.length
) == 0;
29407 case dw_val_class_const_double
:
29408 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29409 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29410 case dw_val_class_wide_int
:
29411 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29412 case dw_val_class_addr
:
29413 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
29415 gcc_unreachable ();
29418 case DW_OP_bit_piece
:
29419 return valx1
->v
.val_int
== valy1
->v
.val_int
29420 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29423 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
29424 case DW_OP_GNU_addr_index
:
29425 case DW_OP_GNU_const_index
:
29427 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
29428 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
29429 return rtx_equal_p (ax1
, ay1
);
29431 case DW_OP_implicit_pointer
:
29432 case DW_OP_GNU_implicit_pointer
:
29433 return valx1
->val_class
== dw_val_class_die_ref
29434 && valx1
->val_class
== valy1
->val_class
29435 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
29436 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29437 case DW_OP_entry_value
:
29438 case DW_OP_GNU_entry_value
:
29439 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
29440 case DW_OP_const_type
:
29441 case DW_OP_GNU_const_type
:
29442 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
29443 || valx2
->val_class
!= valy2
->val_class
)
29445 switch (valx2
->val_class
)
29447 case dw_val_class_const
:
29448 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29449 case dw_val_class_vec
:
29450 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29451 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29452 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29453 valx2
->v
.val_vec
.elt_size
29454 * valx2
->v
.val_vec
.length
) == 0;
29455 case dw_val_class_const_double
:
29456 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29457 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29458 case dw_val_class_wide_int
:
29459 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29461 gcc_unreachable ();
29463 case DW_OP_regval_type
:
29464 case DW_OP_deref_type
:
29465 case DW_OP_GNU_regval_type
:
29466 case DW_OP_GNU_deref_type
:
29467 return valx1
->v
.val_int
== valy1
->v
.val_int
29468 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
29469 case DW_OP_convert
:
29470 case DW_OP_reinterpret
:
29471 case DW_OP_GNU_convert
:
29472 case DW_OP_GNU_reinterpret
:
29473 if (valx1
->val_class
!= valy1
->val_class
)
29475 if (valx1
->val_class
== dw_val_class_unsigned_const
)
29476 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
29477 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29478 case DW_OP_GNU_parameter_ref
:
29479 return valx1
->val_class
== dw_val_class_die_ref
29480 && valx1
->val_class
== valy1
->val_class
29481 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29483 /* Other codes have no operands. */
29488 /* Return true if DWARF location expressions X and Y are the same. */
29491 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29493 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
29494 if (x
->dw_loc_opc
!= y
->dw_loc_opc
29495 || x
->dtprel
!= y
->dtprel
29496 || !compare_loc_operands (x
, y
))
29498 return x
== NULL
&& y
== NULL
;
29501 /* Hashtable helpers. */
29503 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
29505 static inline hashval_t
hash (const dw_loc_list_struct
*);
29506 static inline bool equal (const dw_loc_list_struct
*,
29507 const dw_loc_list_struct
*);
29510 /* Return precomputed hash of location list X. */
29513 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
29518 /* Return true if location lists A and B are the same. */
29521 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
29522 const dw_loc_list_struct
*b
)
29526 if (a
->hash
!= b
->hash
)
29528 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
29529 if (strcmp (a
->begin
, b
->begin
) != 0
29530 || strcmp (a
->end
, b
->end
) != 0
29531 || (a
->section
== NULL
) != (b
->section
== NULL
)
29532 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
29533 || !compare_locs (a
->expr
, b
->expr
))
29535 return a
== NULL
&& b
== NULL
;
29538 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
29541 /* Recursively optimize location lists referenced from DIE
29542 children and share them whenever possible. */
29545 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
29550 dw_loc_list_struct
**slot
;
29552 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29553 if (AT_class (a
) == dw_val_class_loc_list
)
29555 dw_loc_list_ref list
= AT_loc_list (a
);
29556 /* TODO: perform some optimizations here, before hashing
29557 it and storing into the hash table. */
29558 hash_loc_list (list
);
29559 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
29563 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
29566 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
29570 /* Recursively assign each location list a unique index into the debug_addr
29574 index_location_lists (dw_die_ref die
)
29580 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29581 if (AT_class (a
) == dw_val_class_loc_list
)
29583 dw_loc_list_ref list
= AT_loc_list (a
);
29584 dw_loc_list_ref curr
;
29585 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29587 /* Don't index an entry that has already been indexed
29588 or won't be output. */
29589 if (curr
->begin_entry
!= NULL
29590 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
29594 = add_addr_table_entry (xstrdup (curr
->begin
), ate_kind_label
);
29598 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
29601 /* Optimize location lists referenced from DIE
29602 children and share them whenever possible. */
29605 optimize_location_lists (dw_die_ref die
)
29607 loc_list_hash_type
htab (500);
29608 optimize_location_lists_1 (die
, &htab
);
29611 /* Traverse the limbo die list, and add parent/child links. The only
29612 dies without parents that should be here are concrete instances of
29613 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
29614 For concrete instances, we can get the parent die from the abstract
29618 flush_limbo_die_list (void)
29620 limbo_die_node
*node
;
29622 /* get_context_die calls force_decl_die, which can put new DIEs on the
29623 limbo list in LTO mode when nested functions are put in a different
29624 partition than that of their parent function. */
29625 while ((node
= limbo_die_list
))
29627 dw_die_ref die
= node
->die
;
29628 limbo_die_list
= node
->next
;
29630 if (die
->die_parent
== NULL
)
29632 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
29634 if (origin
&& origin
->die_parent
)
29635 add_child_die (origin
->die_parent
, die
);
29636 else if (is_cu_die (die
))
29638 else if (seen_error ())
29639 /* It's OK to be confused by errors in the input. */
29640 add_child_die (comp_unit_die (), die
);
29643 /* In certain situations, the lexical block containing a
29644 nested function can be optimized away, which results
29645 in the nested function die being orphaned. Likewise
29646 with the return type of that nested function. Force
29647 this to be a child of the containing function.
29649 It may happen that even the containing function got fully
29650 inlined and optimized out. In that case we are lost and
29651 assign the empty child. This should not be big issue as
29652 the function is likely unreachable too. */
29653 gcc_assert (node
->created_for
);
29655 if (DECL_P (node
->created_for
))
29656 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
29657 else if (TYPE_P (node
->created_for
))
29658 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
29660 origin
= comp_unit_die ();
29662 add_child_die (origin
, die
);
29668 /* Output stuff that dwarf requires at the end of every file,
29669 and generate the DWARF-2 debugging info. */
29672 dwarf2out_finish (const char *)
29674 comdat_type_node
*ctnode
;
29675 dw_die_ref main_comp_unit_die
;
29676 unsigned char checksum
[16];
29677 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
29679 /* Flush out any latecomers to the limbo party. */
29680 flush_limbo_die_list ();
29684 verify_die (comp_unit_die ());
29685 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
29686 verify_die (node
->die
);
29689 /* We shouldn't have any symbols with delayed asm names for
29690 DIEs generated after early finish. */
29691 gcc_assert (deferred_asm_name
== NULL
);
29693 gen_remaining_tmpl_value_param_die_attribute ();
29695 #if ENABLE_ASSERT_CHECKING
29697 dw_die_ref die
= comp_unit_die (), c
;
29698 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
29701 resolve_addr (comp_unit_die ());
29702 move_marked_base_types ();
29704 /* Initialize sections and labels used for actual assembler output. */
29705 init_sections_and_labels ();
29707 /* Traverse the DIE's and add sibling attributes to those DIE's that
29709 add_sibling_attributes (comp_unit_die ());
29710 limbo_die_node
*node
;
29711 for (node
= cu_die_list
; node
; node
= node
->next
)
29712 add_sibling_attributes (node
->die
);
29713 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29714 add_sibling_attributes (ctnode
->root_die
);
29716 /* When splitting DWARF info, we put some attributes in the
29717 skeleton compile_unit DIE that remains in the .o, while
29718 most attributes go in the DWO compile_unit_die. */
29719 if (dwarf_split_debug_info
)
29721 limbo_die_node
*cu
;
29722 main_comp_unit_die
= gen_compile_unit_die (NULL
);
29723 if (dwarf_version
>= 5)
29724 main_comp_unit_die
->die_tag
= DW_TAG_skeleton_unit
;
29725 cu
= limbo_die_list
;
29726 gcc_assert (cu
->die
== main_comp_unit_die
);
29727 limbo_die_list
= limbo_die_list
->next
;
29728 cu
->next
= cu_die_list
;
29732 main_comp_unit_die
= comp_unit_die ();
29734 /* Output a terminator label for the .text section. */
29735 switch_to_section (text_section
);
29736 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
29737 if (cold_text_section
)
29739 switch_to_section (cold_text_section
);
29740 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
29743 /* We can only use the low/high_pc attributes if all of the code was
29745 if (!have_multiple_function_sections
29746 || (dwarf_version
< 3 && dwarf_strict
))
29748 /* Don't add if the CU has no associated code. */
29749 if (text_section_used
)
29750 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
29751 text_end_label
, true);
29757 bool range_list_added
= false;
29759 if (text_section_used
)
29760 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
29761 text_end_label
, &range_list_added
, true);
29762 if (cold_text_section_used
)
29763 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
29764 cold_end_label
, &range_list_added
, true);
29766 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
29768 if (DECL_IGNORED_P (fde
->decl
))
29770 if (!fde
->in_std_section
)
29771 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
29772 fde
->dw_fde_end
, &range_list_added
,
29774 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
29775 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
29776 fde
->dw_fde_second_end
, &range_list_added
,
29780 if (range_list_added
)
29782 /* We need to give .debug_loc and .debug_ranges an appropriate
29783 "base address". Use zero so that these addresses become
29784 absolute. Historically, we've emitted the unexpected
29785 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
29786 Emit both to give time for other tools to adapt. */
29787 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
29788 if (! dwarf_strict
&& dwarf_version
< 4)
29789 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
29795 /* AIX Assembler inserts the length, so adjust the reference to match the
29796 offset expected by debuggers. */
29797 strcpy (dl_section_ref
, debug_line_section_label
);
29798 if (XCOFF_DEBUGGING_INFO
)
29799 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
29801 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29802 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
29806 add_AT_macptr (comp_unit_die (),
29807 dwarf_version
>= 5 ? DW_AT_macros
29808 : dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
29809 macinfo_section_label
);
29811 if (dwarf_split_debug_info
)
29813 if (have_location_lists
)
29815 if (dwarf_version
>= 5)
29816 add_AT_loclistsptr (comp_unit_die (), DW_AT_loclists_base
,
29817 loc_section_label
);
29818 /* optimize_location_lists calculates the size of the lists,
29819 so index them first, and assign indices to the entries.
29820 Although optimize_location_lists will remove entries from
29821 the table, it only does so for duplicates, and therefore
29822 only reduces ref_counts to 1. */
29823 index_location_lists (comp_unit_die ());
29826 if (addr_index_table
!= NULL
)
29828 unsigned int index
= 0;
29830 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
29836 if (have_location_lists
)
29838 optimize_location_lists (comp_unit_die ());
29839 /* And finally assign indexes to the entries for -gsplit-dwarf. */
29840 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
29841 assign_location_list_indexes (comp_unit_die ());
29844 save_macinfo_strings ();
29846 if (dwarf_split_debug_info
)
29848 unsigned int index
= 0;
29850 /* Add attributes common to skeleton compile_units and
29851 type_units. Because these attributes include strings, it
29852 must be done before freezing the string table. Top-level
29853 skeleton die attrs are added when the skeleton type unit is
29854 created, so ensure it is created by this point. */
29855 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
29856 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
29859 /* Output all of the compilation units. We put the main one last so that
29860 the offsets are available to output_pubnames. */
29861 for (node
= cu_die_list
; node
; node
= node
->next
)
29862 output_comp_unit (node
->die
, 0, NULL
);
29864 hash_table
<comdat_type_hasher
> comdat_type_table (100);
29865 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29867 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
29869 /* Don't output duplicate types. */
29870 if (*slot
!= HTAB_EMPTY_ENTRY
)
29873 /* Add a pointer to the line table for the main compilation unit
29874 so that the debugger can make sense of DW_AT_decl_file
29876 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29877 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
29878 (!dwarf_split_debug_info
29880 : debug_skeleton_line_section_label
));
29882 output_comdat_type_unit (ctnode
);
29886 /* The AT_pubnames attribute needs to go in all skeleton dies, including
29887 both the main_cu and all skeleton TUs. Making this call unconditional
29888 would end up either adding a second copy of the AT_pubnames attribute, or
29889 requiring a special case in add_top_level_skeleton_die_attrs. */
29890 if (!dwarf_split_debug_info
)
29891 add_AT_pubnames (comp_unit_die ());
29893 if (dwarf_split_debug_info
)
29896 struct md5_ctx ctx
;
29898 if (dwarf_version
>= 5 && !vec_safe_is_empty (ranges_table
))
29901 /* Compute a checksum of the comp_unit to use as the dwo_id. */
29902 md5_init_ctx (&ctx
);
29904 die_checksum (comp_unit_die (), &ctx
, &mark
);
29905 unmark_all_dies (comp_unit_die ());
29906 md5_finish_ctx (&ctx
, checksum
);
29908 if (dwarf_version
< 5)
29910 /* Use the first 8 bytes of the checksum as the dwo_id,
29911 and add it to both comp-unit DIEs. */
29912 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
29913 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
29916 /* Add the base offset of the ranges table to the skeleton
29918 if (!vec_safe_is_empty (ranges_table
))
29920 if (dwarf_version
>= 5)
29921 add_AT_lineptr (main_comp_unit_die
, DW_AT_rnglists_base
,
29922 ranges_base_label
);
29924 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
29925 ranges_section_label
);
29928 switch_to_section (debug_addr_section
);
29929 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
29930 output_addr_table ();
29933 /* Output the main compilation unit if non-empty or if .debug_macinfo
29934 or .debug_macro will be emitted. */
29935 output_comp_unit (comp_unit_die (), have_macinfo
,
29936 dwarf_split_debug_info
? checksum
: NULL
);
29938 if (dwarf_split_debug_info
&& info_section_emitted
)
29939 output_skeleton_debug_sections (main_comp_unit_die
, checksum
);
29941 /* Output the abbreviation table. */
29942 if (vec_safe_length (abbrev_die_table
) != 1)
29944 switch_to_section (debug_abbrev_section
);
29945 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
29946 output_abbrev_section ();
29949 /* Output location list section if necessary. */
29950 if (have_location_lists
)
29952 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
29953 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
29954 /* Output the location lists info. */
29955 switch_to_section (debug_loc_section
);
29956 if (dwarf_version
>= 5)
29958 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_LOC_SECTION_LABEL
, 1);
29959 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_LOC_SECTION_LABEL
, 2);
29960 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
29961 dw2_asm_output_data (4, 0xffffffff,
29962 "Initial length escape value indicating "
29963 "64-bit DWARF extension");
29964 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
29965 "Length of Location Lists");
29966 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
29967 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
29968 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
29969 dw2_asm_output_data (1, 0, "Segment Size");
29970 dw2_asm_output_data (4, dwarf_split_debug_info
? loc_list_idx
: 0,
29971 "Offset Entry Count");
29973 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
29974 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
29976 unsigned int save_loc_list_idx
= loc_list_idx
;
29978 output_loclists_offsets (comp_unit_die ());
29979 gcc_assert (save_loc_list_idx
== loc_list_idx
);
29981 output_location_lists (comp_unit_die ());
29982 if (dwarf_version
>= 5)
29983 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
29986 output_pubtables ();
29988 /* Output the address range information if a CU (.debug_info section)
29989 was emitted. We output an empty table even if we had no functions
29990 to put in it. This because the consumer has no way to tell the
29991 difference between an empty table that we omitted and failure to
29992 generate a table that would have contained data. */
29993 if (info_section_emitted
)
29995 switch_to_section (debug_aranges_section
);
29999 /* Output ranges section if necessary. */
30000 if (!vec_safe_is_empty (ranges_table
))
30002 if (dwarf_version
>= 5)
30003 output_rnglists ();
30008 /* Have to end the macro section. */
30011 switch_to_section (debug_macinfo_section
);
30012 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
30014 dw2_asm_output_data (1, 0, "End compilation unit");
30017 /* Output the source line correspondence table. We must do this
30018 even if there is no line information. Otherwise, on an empty
30019 translation unit, we will generate a present, but empty,
30020 .debug_info section. IRIX 6.5 `nm' will then complain when
30021 examining the file. This is done late so that any filenames
30022 used by the debug_info section are marked as 'used'. */
30023 switch_to_section (debug_line_section
);
30024 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
30025 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
30026 output_line_info (false);
30028 if (dwarf_split_debug_info
&& info_section_emitted
)
30030 switch_to_section (debug_skeleton_line_section
);
30031 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
30032 output_line_info (true);
30035 /* If we emitted any indirect strings, output the string table too. */
30036 if (debug_str_hash
|| skeleton_debug_str_hash
)
30037 output_indirect_strings ();
30038 if (debug_line_str_hash
)
30040 switch_to_section (debug_line_str_section
);
30041 const enum dwarf_form form
= DW_FORM_line_strp
;
30042 debug_line_str_hash
->traverse
<enum dwarf_form
,
30043 output_indirect_string
> (form
);
30047 /* Returns a hash value for X (which really is a variable_value_struct). */
30050 variable_value_hasher::hash (variable_value_struct
*x
)
30052 return (hashval_t
) x
->decl_id
;
30055 /* Return nonzero if decl_id of variable_value_struct X is the same as
30059 variable_value_hasher::equal (variable_value_struct
*x
, tree y
)
30061 return x
->decl_id
== DECL_UID (y
);
30064 /* Helper function for resolve_variable_value, handle
30065 DW_OP_GNU_variable_value in one location expression.
30066 Return true if exprloc has been changed into loclist. */
30069 resolve_variable_value_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
30071 dw_loc_descr_ref next
;
30072 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= next
)
30074 next
= loc
->dw_loc_next
;
30075 if (loc
->dw_loc_opc
!= DW_OP_GNU_variable_value
30076 || loc
->dw_loc_oprnd1
.val_class
!= dw_val_class_decl_ref
)
30079 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
30080 if (DECL_CONTEXT (decl
) != current_function_decl
)
30083 dw_die_ref ref
= lookup_decl_die (decl
);
30086 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30087 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30088 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30091 dw_loc_list_ref l
= loc_list_from_tree (decl
, 0, NULL
);
30094 if (l
->dw_loc_next
)
30096 if (AT_class (a
) != dw_val_class_loc
)
30098 switch (a
->dw_attr
)
30100 /* Following attributes allow both exprloc and loclist
30101 classes, so we can change them into a loclist. */
30102 case DW_AT_location
:
30103 case DW_AT_string_length
:
30104 case DW_AT_return_addr
:
30105 case DW_AT_data_member_location
:
30106 case DW_AT_frame_base
:
30107 case DW_AT_segment
:
30108 case DW_AT_static_link
:
30109 case DW_AT_use_location
:
30110 case DW_AT_vtable_elem_location
:
30113 prev
->dw_loc_next
= NULL
;
30114 prepend_loc_descr_to_each (l
, AT_loc (a
));
30117 add_loc_descr_to_each (l
, next
);
30118 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
30119 a
->dw_attr_val
.val_entry
= NULL
;
30120 a
->dw_attr_val
.v
.val_loc_list
= l
;
30121 have_location_lists
= true;
30123 /* Following attributes allow both exprloc and reference,
30124 so if the whole expression is DW_OP_GNU_variable_value alone
30125 we could transform it into reference. */
30126 case DW_AT_byte_size
:
30127 case DW_AT_bit_size
:
30128 case DW_AT_lower_bound
:
30129 case DW_AT_upper_bound
:
30130 case DW_AT_bit_stride
:
30132 case DW_AT_allocated
:
30133 case DW_AT_associated
:
30134 case DW_AT_byte_stride
:
30135 if (prev
== NULL
&& next
== NULL
)
30143 /* Create DW_TAG_variable that we can refer to. */
30144 gen_decl_die (decl
, NULL_TREE
, NULL
,
30145 lookup_decl_die (current_function_decl
));
30146 ref
= lookup_decl_die (decl
);
30149 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30150 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30151 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30157 prev
->dw_loc_next
= l
->expr
;
30158 add_loc_descr (&prev
->dw_loc_next
, next
);
30159 free_loc_descr (loc
, NULL
);
30160 next
= prev
->dw_loc_next
;
30164 memcpy (loc
, l
->expr
, sizeof (dw_loc_descr_node
));
30165 add_loc_descr (&loc
, next
);
30173 /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree. */
30176 resolve_variable_value (dw_die_ref die
)
30179 dw_loc_list_ref loc
;
30182 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30183 switch (AT_class (a
))
30185 case dw_val_class_loc
:
30186 if (!resolve_variable_value_in_expr (a
, AT_loc (a
)))
30189 case dw_val_class_loc_list
:
30190 loc
= AT_loc_list (a
);
30192 for (; loc
; loc
= loc
->dw_loc_next
)
30193 resolve_variable_value_in_expr (a
, loc
->expr
);
30200 /* Attempt to optimize DW_OP_GNU_variable_value refering to
30201 temporaries in the current function. */
30204 resolve_variable_values (void)
30206 if (!variable_value_hash
|| !current_function_decl
)
30209 struct variable_value_struct
*node
30210 = variable_value_hash
->find_with_hash (current_function_decl
,
30211 DECL_UID (current_function_decl
));
30218 FOR_EACH_VEC_SAFE_ELT (node
->dies
, i
, die
)
30219 resolve_variable_value (die
);
30222 /* Helper function for note_variable_value, handle one location
30226 note_variable_value_in_expr (dw_die_ref die
, dw_loc_descr_ref loc
)
30228 for (; loc
; loc
= loc
->dw_loc_next
)
30229 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
30230 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
30232 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
30233 dw_die_ref ref
= lookup_decl_die (decl
);
30236 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30237 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30238 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30242 && DECL_CONTEXT (decl
)
30243 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
30244 && lookup_decl_die (DECL_CONTEXT (decl
)))
30246 if (!variable_value_hash
)
30247 variable_value_hash
30248 = hash_table
<variable_value_hasher
>::create_ggc (10);
30250 tree fndecl
= DECL_CONTEXT (decl
);
30251 struct variable_value_struct
*node
;
30252 struct variable_value_struct
**slot
30253 = variable_value_hash
->find_slot_with_hash (fndecl
,
30258 node
= ggc_cleared_alloc
<variable_value_struct
> ();
30259 node
->decl_id
= DECL_UID (fndecl
);
30265 vec_safe_push (node
->dies
, die
);
30270 /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
30271 with dw_val_class_decl_ref operand. */
30274 note_variable_value (dw_die_ref die
)
30278 dw_loc_list_ref loc
;
30281 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30282 switch (AT_class (a
))
30284 case dw_val_class_loc_list
:
30285 loc
= AT_loc_list (a
);
30287 if (!loc
->noted_variable_value
)
30289 loc
->noted_variable_value
= 1;
30290 for (; loc
; loc
= loc
->dw_loc_next
)
30291 note_variable_value_in_expr (die
, loc
->expr
);
30294 case dw_val_class_loc
:
30295 note_variable_value_in_expr (die
, AT_loc (a
));
30301 /* Mark children. */
30302 FOR_EACH_CHILD (die
, c
, note_variable_value (c
));
30305 /* Perform any cleanups needed after the early debug generation pass
30309 dwarf2out_early_finish (const char *filename
)
30313 /* PCH might result in DW_AT_producer string being restored from the
30314 header compilation, so always fill it with empty string initially
30315 and overwrite only here. */
30316 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
30317 producer_string
= gen_producer_string ();
30318 producer
->dw_attr_val
.v
.val_str
->refcount
--;
30319 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
30321 /* Add the name for the main input file now. We delayed this from
30322 dwarf2out_init to avoid complications with PCH. */
30323 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
30324 add_comp_dir_attribute (comp_unit_die ());
30326 /* When emitting DWARF5 .debug_line_str, move DW_AT_name and
30327 DW_AT_comp_dir into .debug_line_str section. */
30328 if (!DWARF2_ASM_LINE_DEBUG_INFO
30329 && dwarf_version
>= 5
30330 && DWARF5_USE_DEBUG_LINE_STR
)
30332 for (int i
= 0; i
< 2; i
++)
30334 dw_attr_node
*a
= get_AT (comp_unit_die (),
30335 i
? DW_AT_comp_dir
: DW_AT_name
);
30337 || AT_class (a
) != dw_val_class_str
30338 || strlen (AT_string (a
)) + 1 <= DWARF_OFFSET_SIZE
)
30341 if (! debug_line_str_hash
)
30342 debug_line_str_hash
30343 = hash_table
<indirect_string_hasher
>::create_ggc (10);
30345 struct indirect_string_node
*node
30346 = find_AT_string_in_table (AT_string (a
), debug_line_str_hash
);
30347 set_indirect_string (node
);
30348 node
->form
= DW_FORM_line_strp
;
30349 a
->dw_attr_val
.v
.val_str
->refcount
--;
30350 a
->dw_attr_val
.v
.val_str
= node
;
30354 /* With LTO early dwarf was really finished at compile-time, so make
30355 sure to adjust the phase after annotating the LTRANS CU DIE. */
30358 early_dwarf_finished
= true;
30362 /* Walk through the list of incomplete types again, trying once more to
30363 emit full debugging info for them. */
30364 retry_incomplete_types ();
30366 /* The point here is to flush out the limbo list so that it is empty
30367 and we don't need to stream it for LTO. */
30368 flush_limbo_die_list ();
30370 gen_scheduled_generic_parms_dies ();
30371 gen_remaining_tmpl_value_param_die_attribute ();
30373 /* Add DW_AT_linkage_name for all deferred DIEs. */
30374 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
30376 tree decl
= node
->created_for
;
30377 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
30378 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
30379 ended up in deferred_asm_name before we knew it was
30380 constant and never written to disk. */
30381 && DECL_ASSEMBLER_NAME (decl
))
30383 add_linkage_attr (node
->die
, decl
);
30384 move_linkage_attr (node
->die
);
30387 deferred_asm_name
= NULL
;
30389 if (flag_eliminate_unused_debug_types
)
30390 prune_unused_types ();
30392 /* Generate separate COMDAT sections for type DIEs. */
30393 if (use_debug_types
)
30395 break_out_comdat_types (comp_unit_die ());
30397 /* Each new type_unit DIE was added to the limbo die list when created.
30398 Since these have all been added to comdat_type_list, clear the
30400 limbo_die_list
= NULL
;
30402 /* For each new comdat type unit, copy declarations for incomplete
30403 types to make the new unit self-contained (i.e., no direct
30404 references to the main compile unit). */
30405 for (comdat_type_node
*ctnode
= comdat_type_list
;
30406 ctnode
!= NULL
; ctnode
= ctnode
->next
)
30407 copy_decls_for_unworthy_types (ctnode
->root_die
);
30408 copy_decls_for_unworthy_types (comp_unit_die ());
30410 /* In the process of copying declarations from one unit to another,
30411 we may have left some declarations behind that are no longer
30412 referenced. Prune them. */
30413 prune_unused_types ();
30416 /* Generate separate CUs for each of the include files we've seen.
30417 They will go into limbo_die_list and from there to cu_die_list. */
30418 if (flag_eliminate_dwarf2_dups
)
30420 gcc_assert (limbo_die_list
== NULL
);
30421 break_out_includes (comp_unit_die ());
30422 limbo_die_node
*cu
;
30423 while ((cu
= limbo_die_list
))
30425 limbo_die_list
= cu
->next
;
30426 cu
->next
= cu_die_list
;
30431 /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
30432 with dw_val_class_decl_ref operand. */
30433 note_variable_value (comp_unit_die ());
30434 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
30435 note_variable_value (node
->die
);
30436 for (comdat_type_node
*ctnode
= comdat_type_list
; ctnode
!= NULL
;
30437 ctnode
= ctnode
->next
)
30438 note_variable_value (ctnode
->root_die
);
30439 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
30440 note_variable_value (node
->die
);
30442 /* The early debug phase is now finished. */
30443 early_dwarf_finished
= true;
30446 /* Reset all state within dwarf2out.c so that we can rerun the compiler
30447 within the same process. For use by toplev::finalize. */
30450 dwarf2out_c_finalize (void)
30452 last_var_location_insn
= NULL
;
30453 cached_next_real_insn
= NULL
;
30454 used_rtx_array
= NULL
;
30455 incomplete_types
= NULL
;
30456 decl_scope_table
= NULL
;
30457 debug_info_section
= NULL
;
30458 debug_skeleton_info_section
= NULL
;
30459 debug_abbrev_section
= NULL
;
30460 debug_skeleton_abbrev_section
= NULL
;
30461 debug_aranges_section
= NULL
;
30462 debug_addr_section
= NULL
;
30463 debug_macinfo_section
= NULL
;
30464 debug_line_section
= NULL
;
30465 debug_skeleton_line_section
= NULL
;
30466 debug_loc_section
= NULL
;
30467 debug_pubnames_section
= NULL
;
30468 debug_pubtypes_section
= NULL
;
30469 debug_str_section
= NULL
;
30470 debug_line_str_section
= NULL
;
30471 debug_str_dwo_section
= NULL
;
30472 debug_str_offsets_section
= NULL
;
30473 debug_ranges_section
= NULL
;
30474 debug_frame_section
= NULL
;
30476 debug_str_hash
= NULL
;
30477 debug_line_str_hash
= NULL
;
30478 skeleton_debug_str_hash
= NULL
;
30479 dw2_string_counter
= 0;
30480 have_multiple_function_sections
= false;
30481 text_section_used
= false;
30482 cold_text_section_used
= false;
30483 cold_text_section
= NULL
;
30484 current_unit_personality
= NULL
;
30486 early_dwarf
= false;
30487 early_dwarf_finished
= false;
30489 next_die_offset
= 0;
30490 single_comp_unit_die
= NULL
;
30491 comdat_type_list
= NULL
;
30492 limbo_die_list
= NULL
;
30494 decl_die_table
= NULL
;
30495 common_block_die_table
= NULL
;
30496 decl_loc_table
= NULL
;
30497 call_arg_locations
= NULL
;
30498 call_arg_loc_last
= NULL
;
30499 call_site_count
= -1;
30500 tail_call_site_count
= -1;
30501 cached_dw_loc_list_table
= NULL
;
30502 abbrev_die_table
= NULL
;
30503 delete dwarf_proc_stack_usage_map
;
30504 dwarf_proc_stack_usage_map
= NULL
;
30505 line_info_label_num
= 0;
30506 cur_line_info_table
= NULL
;
30507 text_section_line_info
= NULL
;
30508 cold_text_section_line_info
= NULL
;
30509 separate_line_info
= NULL
;
30510 info_section_emitted
= false;
30511 pubname_table
= NULL
;
30512 pubtype_table
= NULL
;
30513 macinfo_table
= NULL
;
30514 ranges_table
= NULL
;
30515 ranges_by_label
= NULL
;
30517 have_location_lists
= false;
30520 last_emitted_file
= NULL
;
30522 tmpl_value_parm_die_table
= NULL
;
30523 generic_type_instances
= NULL
;
30524 frame_pointer_fb_offset
= 0;
30525 frame_pointer_fb_offset_valid
= false;
30526 base_types
.release ();
30527 XDELETEVEC (producer_string
);
30528 producer_string
= NULL
;
30531 #include "gt-dwarf2out.h"