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, const char *, int, bool);
97 static rtx_insn
*last_var_location_insn
;
98 static rtx_insn
*cached_next_real_insn
;
99 static void dwarf2out_decl (tree
);
101 #ifndef XCOFF_DEBUGGING_INFO
102 #define XCOFF_DEBUGGING_INFO 0
105 #ifndef HAVE_XCOFF_DWARF_EXTRAS
106 #define HAVE_XCOFF_DWARF_EXTRAS 0
109 #ifdef VMS_DEBUGGING_INFO
110 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
112 /* Define this macro to be a nonzero value if the directory specifications
113 which are output in the debug info should end with a separator. */
114 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
115 /* Define this macro to evaluate to a nonzero value if GCC should refrain
116 from generating indirect strings in DWARF2 debug information, for instance
117 if your target is stuck with an old version of GDB that is unable to
118 process them properly or uses VMS Debug. */
119 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
121 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
122 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
125 /* ??? Poison these here until it can be done generically. They've been
126 totally replaced in this file; make sure it stays that way. */
127 #undef DWARF2_UNWIND_INFO
128 #undef DWARF2_FRAME_INFO
129 #if (GCC_VERSION >= 3000)
130 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
133 /* The size of the target's pointer type. */
135 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
138 /* Array of RTXes referenced by the debugging information, which therefore
139 must be kept around forever. */
140 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
142 /* A pointer to the base of a list of incomplete types which might be
143 completed at some later time. incomplete_types_list needs to be a
144 vec<tree, va_gc> *because we want to tell the garbage collector about
146 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
148 /* A pointer to the base of a table of references to declaration
149 scopes. This table is a display which tracks the nesting
150 of declaration scopes at the current scope and containing
151 scopes. This table is used to find the proper place to
152 define type declaration DIE's. */
153 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
155 /* Pointers to various DWARF2 sections. */
156 static GTY(()) section
*debug_info_section
;
157 static GTY(()) section
*debug_skeleton_info_section
;
158 static GTY(()) section
*debug_abbrev_section
;
159 static GTY(()) section
*debug_skeleton_abbrev_section
;
160 static GTY(()) section
*debug_aranges_section
;
161 static GTY(()) section
*debug_addr_section
;
162 static GTY(()) section
*debug_macinfo_section
;
163 static const char *debug_macinfo_section_name
;
164 static GTY(()) section
*debug_line_section
;
165 static GTY(()) section
*debug_skeleton_line_section
;
166 static GTY(()) section
*debug_loc_section
;
167 static GTY(()) section
*debug_pubnames_section
;
168 static GTY(()) section
*debug_pubtypes_section
;
169 static GTY(()) section
*debug_str_section
;
170 static GTY(()) section
*debug_line_str_section
;
171 static GTY(()) section
*debug_str_dwo_section
;
172 static GTY(()) section
*debug_str_offsets_section
;
173 static GTY(()) section
*debug_ranges_section
;
174 static GTY(()) section
*debug_frame_section
;
176 /* Maximum size (in bytes) of an artificially generated label. */
177 #define MAX_ARTIFICIAL_LABEL_BYTES 30
179 /* According to the (draft) DWARF 3 specification, the initial length
180 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
181 bytes are 0xffffffff, followed by the length stored in the next 8
184 However, the SGI/MIPS ABI uses an initial length which is equal to
185 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
187 #ifndef DWARF_INITIAL_LENGTH_SIZE
188 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
191 /* Round SIZE up to the nearest BOUNDARY. */
192 #define DWARF_ROUND(SIZE,BOUNDARY) \
193 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
195 /* CIE identifier. */
196 #if HOST_BITS_PER_WIDE_INT >= 64
197 #define DWARF_CIE_ID \
198 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
200 #define DWARF_CIE_ID DW_CIE_ID
204 /* A vector for a table that contains frame description
205 information for each routine. */
206 #define NOT_INDEXED (-1U)
207 #define NO_INDEX_ASSIGNED (-2U)
209 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
211 struct GTY((for_user
)) indirect_string_node
{
213 unsigned int refcount
;
214 enum dwarf_form form
;
219 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
221 typedef const char *compare_type
;
223 static hashval_t
hash (indirect_string_node
*);
224 static bool equal (indirect_string_node
*, const char *);
227 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
229 static GTY (()) hash_table
<indirect_string_hasher
> *debug_line_str_hash
;
231 /* With split_debug_info, both the comp_dir and dwo_name go in the
232 main object file, rather than the dwo, similar to the force_direct
233 parameter elsewhere but with additional complications:
235 1) The string is needed in both the main object file and the dwo.
236 That is, the comp_dir and dwo_name will appear in both places.
238 2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
239 DW_FORM_line_strp or DW_FORM_GNU_str_index.
241 3) GCC chooses the form to use late, depending on the size and
244 Rather than forcing the all debug string handling functions and
245 callers to deal with these complications, simply use a separate,
246 special-cased string table for any attribute that should go in the
247 main object file. This limits the complexity to just the places
250 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
252 static GTY(()) int dw2_string_counter
;
254 /* True if the compilation unit places functions in more than one section. */
255 static GTY(()) bool have_multiple_function_sections
= false;
257 /* Whether the default text and cold text sections have been used at all. */
259 static GTY(()) bool text_section_used
= false;
260 static GTY(()) bool cold_text_section_used
= false;
262 /* The default cold text section. */
263 static GTY(()) section
*cold_text_section
;
265 /* The DIE for C++14 'auto' in a function return type. */
266 static GTY(()) dw_die_ref auto_die
;
268 /* The DIE for C++14 'decltype(auto)' in a function return type. */
269 static GTY(()) dw_die_ref decltype_auto_die
;
271 /* Forward declarations for functions defined in this file. */
273 static void output_call_frame_info (int);
274 static void dwarf2out_note_section_used (void);
276 /* Personality decl of current unit. Used only when assembler does not support
278 static GTY(()) rtx current_unit_personality
;
280 /* .debug_rnglists next index. */
281 static unsigned int rnglist_idx
;
283 /* Data and reference forms for relocatable data. */
284 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
285 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
287 #ifndef DEBUG_FRAME_SECTION
288 #define DEBUG_FRAME_SECTION ".debug_frame"
291 #ifndef FUNC_BEGIN_LABEL
292 #define FUNC_BEGIN_LABEL "LFB"
295 #ifndef FUNC_END_LABEL
296 #define FUNC_END_LABEL "LFE"
299 #ifndef PROLOGUE_END_LABEL
300 #define PROLOGUE_END_LABEL "LPE"
303 #ifndef EPILOGUE_BEGIN_LABEL
304 #define EPILOGUE_BEGIN_LABEL "LEB"
307 #ifndef FRAME_BEGIN_LABEL
308 #define FRAME_BEGIN_LABEL "Lframe"
310 #define CIE_AFTER_SIZE_LABEL "LSCIE"
311 #define CIE_END_LABEL "LECIE"
312 #define FDE_LABEL "LSFDE"
313 #define FDE_AFTER_SIZE_LABEL "LASFDE"
314 #define FDE_END_LABEL "LEFDE"
315 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
316 #define LINE_NUMBER_END_LABEL "LELT"
317 #define LN_PROLOG_AS_LABEL "LASLTP"
318 #define LN_PROLOG_END_LABEL "LELTP"
319 #define DIE_LABEL_PREFIX "DW"
321 /* Match the base name of a file to the base name of a compilation unit. */
324 matches_main_base (const char *path
)
326 /* Cache the last query. */
327 static const char *last_path
= NULL
;
328 static int last_match
= 0;
329 if (path
!= last_path
)
332 int length
= base_of_path (path
, &base
);
334 last_match
= (length
== main_input_baselength
335 && memcmp (base
, main_input_basename
, length
) == 0);
340 #ifdef DEBUG_DEBUG_STRUCT
343 dump_struct_debug (tree type
, enum debug_info_usage usage
,
344 enum debug_struct_file criterion
, int generic
,
345 int matches
, int result
)
347 /* Find the type name. */
348 tree type_decl
= TYPE_STUB_DECL (type
);
350 const char *name
= 0;
351 if (TREE_CODE (t
) == TYPE_DECL
)
354 name
= IDENTIFIER_POINTER (t
);
356 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
358 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
359 matches
? "bas" : "hdr",
360 generic
? "gen" : "ord",
361 usage
== DINFO_USAGE_DFN
? ";" :
362 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
364 (void*) type_decl
, name
);
367 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
368 dump_struct_debug (type, usage, criterion, generic, matches, result)
372 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
377 /* Get the number of HOST_WIDE_INTs needed to represent the precision
378 of the number. Some constants have a large uniform precision, so
379 we get the precision needed for the actual value of the number. */
382 get_full_len (const wide_int
&op
)
384 int prec
= wi::min_precision (op
, UNSIGNED
);
385 return ((prec
+ HOST_BITS_PER_WIDE_INT
- 1)
386 / HOST_BITS_PER_WIDE_INT
);
390 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
392 enum debug_struct_file criterion
;
394 bool generic
= lang_hooks
.types
.generic_p (type
);
397 criterion
= debug_struct_generic
[usage
];
399 criterion
= debug_struct_ordinary
[usage
];
401 if (criterion
== DINFO_STRUCT_FILE_NONE
)
402 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
403 if (criterion
== DINFO_STRUCT_FILE_ANY
)
404 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
406 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
408 if (type_decl
!= NULL
)
410 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
411 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
413 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
414 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
417 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
420 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
421 switch to the data section instead, and write out a synthetic start label
422 for collect2 the first time around. */
425 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
427 if (eh_frame_section
== 0)
431 if (EH_TABLES_CAN_BE_READ_ONLY
)
437 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
439 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
441 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
444 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
445 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
446 && (per_encoding
& 0x70) != DW_EH_PE_absptr
447 && (per_encoding
& 0x70) != DW_EH_PE_aligned
448 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
449 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
450 ? 0 : SECTION_WRITE
);
453 flags
= SECTION_WRITE
;
455 #ifdef EH_FRAME_SECTION_NAME
456 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
458 eh_frame_section
= ((flags
== SECTION_WRITE
)
459 ? data_section
: readonly_data_section
);
460 #endif /* EH_FRAME_SECTION_NAME */
463 switch_to_section (eh_frame_section
);
465 #ifdef EH_FRAME_THROUGH_COLLECT2
466 /* We have no special eh_frame section. Emit special labels to guide
470 tree label
= get_file_function_name ("F");
471 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
472 targetm
.asm_out
.globalize_label (asm_out_file
,
473 IDENTIFIER_POINTER (label
));
474 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
479 /* Switch [BACK] to the eh or debug frame table section, depending on
483 switch_to_frame_table_section (int for_eh
, bool back
)
486 switch_to_eh_frame_section (back
);
489 if (!debug_frame_section
)
490 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
491 SECTION_DEBUG
, NULL
);
492 switch_to_section (debug_frame_section
);
496 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
498 enum dw_cfi_oprnd_type
499 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
504 case DW_CFA_GNU_window_save
:
505 case DW_CFA_remember_state
:
506 case DW_CFA_restore_state
:
507 return dw_cfi_oprnd_unused
;
510 case DW_CFA_advance_loc1
:
511 case DW_CFA_advance_loc2
:
512 case DW_CFA_advance_loc4
:
513 case DW_CFA_MIPS_advance_loc8
:
514 return dw_cfi_oprnd_addr
;
517 case DW_CFA_offset_extended
:
519 case DW_CFA_offset_extended_sf
:
520 case DW_CFA_def_cfa_sf
:
522 case DW_CFA_restore_extended
:
523 case DW_CFA_undefined
:
524 case DW_CFA_same_value
:
525 case DW_CFA_def_cfa_register
:
526 case DW_CFA_register
:
527 case DW_CFA_expression
:
528 case DW_CFA_val_expression
:
529 return dw_cfi_oprnd_reg_num
;
531 case DW_CFA_def_cfa_offset
:
532 case DW_CFA_GNU_args_size
:
533 case DW_CFA_def_cfa_offset_sf
:
534 return dw_cfi_oprnd_offset
;
536 case DW_CFA_def_cfa_expression
:
537 return dw_cfi_oprnd_loc
;
544 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
546 enum dw_cfi_oprnd_type
547 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
552 case DW_CFA_def_cfa_sf
:
554 case DW_CFA_offset_extended_sf
:
555 case DW_CFA_offset_extended
:
556 return dw_cfi_oprnd_offset
;
558 case DW_CFA_register
:
559 return dw_cfi_oprnd_reg_num
;
561 case DW_CFA_expression
:
562 case DW_CFA_val_expression
:
563 return dw_cfi_oprnd_loc
;
566 return dw_cfi_oprnd_unused
;
570 /* Output one FDE. */
573 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
574 char *section_start_label
, int fde_encoding
, char *augmentation
,
575 bool any_lsda_needed
, int lsda_encoding
)
577 const char *begin
, *end
;
578 static unsigned int j
;
579 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
581 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
583 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
585 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
586 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
587 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
589 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
590 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
591 " indicating 64-bit DWARF extension");
592 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
595 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
598 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
600 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
601 debug_frame_section
, "FDE CIE offset");
603 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
604 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
608 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
609 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
610 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
611 "FDE initial location");
612 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
613 end
, begin
, "FDE address range");
617 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
618 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
625 int size
= size_of_encoded_value (lsda_encoding
);
627 if (lsda_encoding
== DW_EH_PE_aligned
)
629 int offset
= ( 4 /* Length */
631 + 2 * size_of_encoded_value (fde_encoding
)
632 + 1 /* Augmentation size */ );
633 int pad
= -offset
& (PTR_SIZE
- 1);
636 gcc_assert (size_of_uleb128 (size
) == 1);
639 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
641 if (fde
->uses_eh_lsda
)
643 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
644 fde
->funcdef_number
);
645 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
646 gen_rtx_SYMBOL_REF (Pmode
, l1
),
648 "Language Specific Data Area");
652 if (lsda_encoding
== DW_EH_PE_aligned
)
653 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
654 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
655 "Language Specific Data Area (none)");
659 dw2_asm_output_data_uleb128 (0, "Augmentation size");
662 /* Loop through the Call Frame Instructions associated with this FDE. */
663 fde
->dw_fde_current_label
= begin
;
665 size_t from
, until
, i
;
668 until
= vec_safe_length (fde
->dw_fde_cfi
);
670 if (fde
->dw_fde_second_begin
== NULL
)
673 until
= fde
->dw_fde_switch_cfi_index
;
675 from
= fde
->dw_fde_switch_cfi_index
;
677 for (i
= from
; i
< until
; i
++)
678 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
681 /* If we are to emit a ref/link from function bodies to their frame tables,
682 do it now. This is typically performed to make sure that tables
683 associated with functions are dragged with them and not discarded in
684 garbage collecting links. We need to do this on a per function basis to
685 cope with -ffunction-sections. */
687 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
688 /* Switch to the function section, emit the ref to the tables, and
689 switch *back* into the table section. */
690 switch_to_section (function_section (fde
->decl
));
691 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
692 switch_to_frame_table_section (for_eh
, true);
695 /* Pad the FDE out to an address sized boundary. */
696 ASM_OUTPUT_ALIGN (asm_out_file
,
697 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
698 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
703 /* Return true if frame description entry FDE is needed for EH. */
706 fde_needed_for_eh_p (dw_fde_ref fde
)
708 if (flag_asynchronous_unwind_tables
)
711 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
714 if (fde
->uses_eh_lsda
)
717 /* If exceptions are enabled, we have collected nothrow info. */
718 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
724 /* Output the call frame information used to record information
725 that relates to calculating the frame pointer, and records the
726 location of saved registers. */
729 output_call_frame_info (int for_eh
)
734 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
735 char section_start_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
736 bool any_lsda_needed
= false;
737 char augmentation
[6];
738 int augmentation_size
;
739 int fde_encoding
= DW_EH_PE_absptr
;
740 int per_encoding
= DW_EH_PE_absptr
;
741 int lsda_encoding
= DW_EH_PE_absptr
;
743 rtx personality
= NULL
;
746 /* Don't emit a CIE if there won't be any FDEs. */
750 /* Nothing to do if the assembler's doing it all. */
751 if (dwarf2out_do_cfi_asm ())
754 /* If we don't have any functions we'll want to unwind out of, don't emit
755 any EH unwind information. If we make FDEs linkonce, we may have to
756 emit an empty label for an FDE that wouldn't otherwise be emitted. We
757 want to avoid having an FDE kept around when the function it refers to
758 is discarded. Example where this matters: a primary function template
759 in C++ requires EH information, an explicit specialization doesn't. */
762 bool any_eh_needed
= false;
764 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
766 if (fde
->uses_eh_lsda
)
767 any_eh_needed
= any_lsda_needed
= true;
768 else if (fde_needed_for_eh_p (fde
))
769 any_eh_needed
= true;
770 else if (TARGET_USES_WEAK_UNWIND_INFO
)
771 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
778 /* We're going to be generating comments, so turn on app. */
782 /* Switch to the proper frame section, first time. */
783 switch_to_frame_table_section (for_eh
, false);
785 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
786 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
788 /* Output the CIE. */
789 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
790 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
791 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
793 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
794 dw2_asm_output_data (4, 0xffffffff,
795 "Initial length escape value indicating 64-bit DWARF extension");
796 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
797 "Length of Common Information Entry");
799 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
801 /* Now that the CIE pointer is PC-relative for EH,
802 use 0 to identify the CIE. */
803 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
804 (for_eh
? 0 : DWARF_CIE_ID
),
805 "CIE Identifier Tag");
807 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
808 use CIE version 1, unless that would produce incorrect results
809 due to overflowing the return register column. */
810 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
812 if (return_reg
>= 256 || dwarf_version
> 2)
814 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
817 augmentation_size
= 0;
819 personality
= current_unit_personality
;
825 z Indicates that a uleb128 is present to size the
826 augmentation section.
827 L Indicates the encoding (and thus presence) of
828 an LSDA pointer in the FDE augmentation.
829 R Indicates a non-default pointer encoding for
831 P Indicates the presence of an encoding + language
832 personality routine in the CIE augmentation. */
834 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
835 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
836 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
838 p
= augmentation
+ 1;
842 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
843 assemble_external_libcall (personality
);
848 augmentation_size
+= 1;
850 if (fde_encoding
!= DW_EH_PE_absptr
)
853 augmentation_size
+= 1;
855 if (p
> augmentation
+ 1)
857 augmentation
[0] = 'z';
861 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
862 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
864 int offset
= ( 4 /* Length */
866 + 1 /* CIE version */
867 + strlen (augmentation
) + 1 /* Augmentation */
868 + size_of_uleb128 (1) /* Code alignment */
869 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
871 + 1 /* Augmentation size */
872 + 1 /* Personality encoding */ );
873 int pad
= -offset
& (PTR_SIZE
- 1);
875 augmentation_size
+= pad
;
877 /* Augmentations should be small, so there's scarce need to
878 iterate for a solution. Die if we exceed one uleb128 byte. */
879 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
883 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
884 if (dw_cie_version
>= 4)
886 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
887 dw2_asm_output_data (1, 0, "CIE Segment Size");
889 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
890 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
891 "CIE Data Alignment Factor");
893 if (dw_cie_version
== 1)
894 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
896 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
900 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
903 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
904 eh_data_format_name (per_encoding
));
905 dw2_asm_output_encoded_addr_rtx (per_encoding
,
911 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
912 eh_data_format_name (lsda_encoding
));
914 if (fde_encoding
!= DW_EH_PE_absptr
)
915 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
916 eh_data_format_name (fde_encoding
));
919 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
920 output_cfi (cfi
, NULL
, for_eh
);
922 /* Pad the CIE out to an address sized boundary. */
923 ASM_OUTPUT_ALIGN (asm_out_file
,
924 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
925 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
927 /* Loop through all of the FDE's. */
928 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
932 /* Don't emit EH unwind info for leaf functions that don't need it. */
933 if (for_eh
&& !fde_needed_for_eh_p (fde
))
936 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
937 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
938 augmentation
, any_lsda_needed
, lsda_encoding
);
941 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
942 dw2_asm_output_data (4, 0, "End of Table");
944 /* Turn off app to make assembly quicker. */
949 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
952 dwarf2out_do_cfi_startproc (bool second
)
956 rtx personality
= get_personality_function (current_function_decl
);
958 fprintf (asm_out_file
, "\t.cfi_startproc\n");
962 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
965 /* ??? The GAS support isn't entirely consistent. We have to
966 handle indirect support ourselves, but PC-relative is done
967 in the assembler. Further, the assembler can't handle any
968 of the weirder relocation types. */
969 if (enc
& DW_EH_PE_indirect
)
970 ref
= dw2_force_const_mem (ref
, true);
972 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
973 output_addr_const (asm_out_file
, ref
);
974 fputc ('\n', asm_out_file
);
977 if (crtl
->uses_eh_lsda
)
979 char lab
[MAX_ARTIFICIAL_LABEL_BYTES
];
981 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
982 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
983 current_function_funcdef_no
);
984 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
985 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
987 if (enc
& DW_EH_PE_indirect
)
988 ref
= dw2_force_const_mem (ref
, true);
990 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
991 output_addr_const (asm_out_file
, ref
);
992 fputc ('\n', asm_out_file
);
996 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
997 this allocation may be done before pass_final. */
1000 dwarf2out_alloc_current_fde (void)
1004 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1005 fde
->decl
= current_function_decl
;
1006 fde
->funcdef_number
= current_function_funcdef_no
;
1007 fde
->fde_index
= vec_safe_length (fde_vec
);
1008 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1009 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1010 fde
->nothrow
= crtl
->nothrow
;
1011 fde
->drap_reg
= INVALID_REGNUM
;
1012 fde
->vdrap_reg
= INVALID_REGNUM
;
1014 /* Record the FDE associated with this function. */
1016 vec_safe_push (fde_vec
, fde
);
1021 /* Output a marker (i.e. a label) for the beginning of a function, before
1025 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1026 const char *file ATTRIBUTE_UNUSED
)
1028 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1034 current_function_func_begin_label
= NULL
;
1036 do_frame
= dwarf2out_do_frame ();
1038 /* ??? current_function_func_begin_label is also used by except.c for
1039 call-site information. We must emit this label if it might be used. */
1041 && (!flag_exceptions
1042 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1045 fnsec
= function_section (current_function_decl
);
1046 switch_to_section (fnsec
);
1047 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1048 current_function_funcdef_no
);
1049 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1050 current_function_funcdef_no
);
1051 dup_label
= xstrdup (label
);
1052 current_function_func_begin_label
= dup_label
;
1054 /* We can elide the fde allocation if we're not emitting debug info. */
1058 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1059 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1060 would include pass_dwarf2_frame. If we've not created the FDE yet,
1064 fde
= dwarf2out_alloc_current_fde ();
1066 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1067 fde
->dw_fde_begin
= dup_label
;
1068 fde
->dw_fde_current_label
= dup_label
;
1069 fde
->in_std_section
= (fnsec
== text_section
1070 || (cold_text_section
&& fnsec
== cold_text_section
));
1072 /* We only want to output line number information for the genuine dwarf2
1073 prologue case, not the eh frame case. */
1074 #ifdef DWARF2_DEBUGGING_INFO
1076 dwarf2out_source_line (line
, file
, 0, true);
1079 if (dwarf2out_do_cfi_asm ())
1080 dwarf2out_do_cfi_startproc (false);
1083 rtx personality
= get_personality_function (current_function_decl
);
1084 if (!current_unit_personality
)
1085 current_unit_personality
= personality
;
1087 /* We cannot keep a current personality per function as without CFI
1088 asm, at the point where we emit the CFI data, there is no current
1089 function anymore. */
1090 if (personality
&& current_unit_personality
!= personality
)
1091 sorry ("multiple EH personalities are supported only with assemblers "
1092 "supporting .cfi_personality directive");
1096 /* Output a marker (i.e. a label) for the end of the generated code
1097 for a function prologue. This gets called *after* the prologue code has
1101 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1102 const char *file ATTRIBUTE_UNUSED
)
1104 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1106 /* Output a label to mark the endpoint of the code generated for this
1108 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1109 current_function_funcdef_no
);
1110 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1111 current_function_funcdef_no
);
1112 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1115 /* Output a marker (i.e. a label) for the beginning of the generated code
1116 for a function epilogue. This gets called *before* the prologue code has
1120 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1121 const char *file ATTRIBUTE_UNUSED
)
1123 dw_fde_ref fde
= cfun
->fde
;
1124 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1126 if (fde
->dw_fde_vms_begin_epilogue
)
1129 /* Output a label to mark the endpoint of the code generated for this
1131 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1132 current_function_funcdef_no
);
1133 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1134 current_function_funcdef_no
);
1135 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1138 /* Output a marker (i.e. a label) for the absolute end of the generated code
1139 for a function definition. This gets called *after* the epilogue code has
1143 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1144 const char *file ATTRIBUTE_UNUSED
)
1147 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1149 last_var_location_insn
= NULL
;
1150 cached_next_real_insn
= NULL
;
1152 if (dwarf2out_do_cfi_asm ())
1153 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1155 /* Output a label to mark the endpoint of the code generated for this
1157 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1158 current_function_funcdef_no
);
1159 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1161 gcc_assert (fde
!= NULL
);
1162 if (fde
->dw_fde_second_begin
== NULL
)
1163 fde
->dw_fde_end
= xstrdup (label
);
1167 dwarf2out_frame_finish (void)
1169 /* Output call frame information. */
1170 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1171 output_call_frame_info (0);
1173 /* Output another copy for the unwinder. */
1174 if ((flag_unwind_tables
|| flag_exceptions
)
1175 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1176 output_call_frame_info (1);
1179 /* Note that the current function section is being used for code. */
1182 dwarf2out_note_section_used (void)
1184 section
*sec
= current_function_section ();
1185 if (sec
== text_section
)
1186 text_section_used
= true;
1187 else if (sec
== cold_text_section
)
1188 cold_text_section_used
= true;
1191 static void var_location_switch_text_section (void);
1192 static void set_cur_line_info_table (section
*);
1195 dwarf2out_switch_text_section (void)
1198 dw_fde_ref fde
= cfun
->fde
;
1200 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1202 if (!in_cold_section_p
)
1204 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1205 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1206 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1210 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1211 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1212 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1214 have_multiple_function_sections
= true;
1216 /* There is no need to mark used sections when not debugging. */
1217 if (cold_text_section
!= NULL
)
1218 dwarf2out_note_section_used ();
1220 if (dwarf2out_do_cfi_asm ())
1221 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1223 /* Now do the real section switch. */
1224 sect
= current_function_section ();
1225 switch_to_section (sect
);
1227 fde
->second_in_std_section
1228 = (sect
== text_section
1229 || (cold_text_section
&& sect
== cold_text_section
));
1231 if (dwarf2out_do_cfi_asm ())
1232 dwarf2out_do_cfi_startproc (true);
1234 var_location_switch_text_section ();
1236 if (cold_text_section
!= NULL
)
1237 set_cur_line_info_table (sect
);
1240 /* And now, the subset of the debugging information support code necessary
1241 for emitting location expressions. */
1243 /* Data about a single source file. */
1244 struct GTY((for_user
)) dwarf_file_data
{
1245 const char * filename
;
1249 /* Describe an entry into the .debug_addr section. */
1253 ate_kind_rtx_dtprel
,
1257 struct GTY((for_user
)) addr_table_entry
{
1259 unsigned int refcount
;
1261 union addr_table_entry_struct_union
1263 rtx
GTY ((tag ("0"))) rtl
;
1264 char * GTY ((tag ("1"))) label
;
1266 GTY ((desc ("%1.kind"))) addr
;
1269 /* Location lists are ranges + location descriptions for that range,
1270 so you can track variables that are in different places over
1271 their entire life. */
1272 typedef struct GTY(()) dw_loc_list_struct
{
1273 dw_loc_list_ref dw_loc_next
;
1274 const char *begin
; /* Label and addr_entry for start of range */
1275 addr_table_entry
*begin_entry
;
1276 const char *end
; /* Label for end of range */
1277 char *ll_symbol
; /* Label for beginning of location list.
1278 Only on head of list */
1279 const char *section
; /* Section this loclist is relative to */
1280 dw_loc_descr_ref expr
;
1282 /* True if all addresses in this and subsequent lists are known to be
1285 /* True if this list has been replaced by dw_loc_next. */
1287 /* True if it has been emitted into .debug_loc* / .debug_loclists*
1289 unsigned char emitted
: 1;
1290 /* True if hash field is index rather than hash value. */
1291 unsigned char num_assigned
: 1;
1292 /* True if .debug_loclists.dwo offset has been emitted for it already. */
1293 unsigned char offset_emitted
: 1;
1294 /* True if the range should be emitted even if begin and end
1299 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1300 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1302 /* Convert a DWARF stack opcode into its string name. */
1305 dwarf_stack_op_name (unsigned int op
)
1307 const char *name
= get_DW_OP_name (op
);
1312 return "OP_<unknown>";
1315 /* Return a pointer to a newly allocated location description. Location
1316 descriptions are simple expression terms that can be strung
1317 together to form more complicated location (address) descriptions. */
1319 static inline dw_loc_descr_ref
1320 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1321 unsigned HOST_WIDE_INT oprnd2
)
1323 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1325 descr
->dw_loc_opc
= op
;
1326 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1327 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1328 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1329 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1330 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1331 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1336 /* Return a pointer to a newly allocated location description for
1339 static inline dw_loc_descr_ref
1340 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1343 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1346 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1349 /* Add a location description term to a location description expression. */
1352 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1354 dw_loc_descr_ref
*d
;
1356 /* Find the end of the chain. */
1357 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1363 /* Compare two location operands for exact equality. */
1366 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1368 if (a
->val_class
!= b
->val_class
)
1370 switch (a
->val_class
)
1372 case dw_val_class_none
:
1374 case dw_val_class_addr
:
1375 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1377 case dw_val_class_offset
:
1378 case dw_val_class_unsigned_const
:
1379 case dw_val_class_const
:
1380 case dw_val_class_unsigned_const_implicit
:
1381 case dw_val_class_const_implicit
:
1382 case dw_val_class_range_list
:
1383 /* These are all HOST_WIDE_INT, signed or unsigned. */
1384 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1386 case dw_val_class_loc
:
1387 return a
->v
.val_loc
== b
->v
.val_loc
;
1388 case dw_val_class_loc_list
:
1389 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1390 case dw_val_class_die_ref
:
1391 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1392 case dw_val_class_fde_ref
:
1393 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1394 case dw_val_class_lbl_id
:
1395 case dw_val_class_lineptr
:
1396 case dw_val_class_macptr
:
1397 case dw_val_class_loclistsptr
:
1398 case dw_val_class_high_pc
:
1399 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1400 case dw_val_class_str
:
1401 return a
->v
.val_str
== b
->v
.val_str
;
1402 case dw_val_class_flag
:
1403 return a
->v
.val_flag
== b
->v
.val_flag
;
1404 case dw_val_class_file
:
1405 case dw_val_class_file_implicit
:
1406 return a
->v
.val_file
== b
->v
.val_file
;
1407 case dw_val_class_decl_ref
:
1408 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1410 case dw_val_class_const_double
:
1411 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1412 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1414 case dw_val_class_wide_int
:
1415 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1417 case dw_val_class_vec
:
1419 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1420 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1422 return (a_len
== b_len
1423 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1426 case dw_val_class_data8
:
1427 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1429 case dw_val_class_vms_delta
:
1430 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1431 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1433 case dw_val_class_discr_value
:
1434 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1435 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1436 case dw_val_class_discr_list
:
1437 /* It makes no sense comparing two discriminant value lists. */
1443 /* Compare two location atoms for exact equality. */
1446 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1448 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1451 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1452 address size, but since we always allocate cleared storage it
1453 should be zero for other types of locations. */
1454 if (a
->dtprel
!= b
->dtprel
)
1457 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1458 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1461 /* Compare two complete location expressions for exact equality. */
1464 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1470 if (a
== NULL
|| b
== NULL
)
1472 if (!loc_descr_equal_p_1 (a
, b
))
1481 /* Add a constant OFFSET to a location expression. */
1484 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1486 dw_loc_descr_ref loc
;
1489 gcc_assert (*list_head
!= NULL
);
1494 /* Find the end of the chain. */
1495 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1499 if (loc
->dw_loc_opc
== DW_OP_fbreg
1500 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1501 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1502 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1503 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1505 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1506 offset. Don't optimize if an signed integer overflow would happen. */
1508 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1509 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1512 else if (offset
> 0)
1513 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1518 = uint_loc_descriptor (-(unsigned HOST_WIDE_INT
) offset
);
1519 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1523 /* Add a constant OFFSET to a location list. */
1526 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1529 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1530 loc_descr_plus_const (&d
->expr
, offset
);
1533 #define DWARF_REF_SIZE \
1534 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1536 /* The number of bits that can be encoded by largest DW_FORM_dataN.
1537 In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
1538 DW_FORM_data16 with 128 bits. */
1539 #define DWARF_LARGEST_DATA_FORM_BITS \
1540 (dwarf_version >= 5 ? 128 : 64)
1542 /* Utility inline function for construction of ops that were GNU extension
1544 static inline enum dwarf_location_atom
1545 dwarf_OP (enum dwarf_location_atom op
)
1549 case DW_OP_implicit_pointer
:
1550 if (dwarf_version
< 5)
1551 return DW_OP_GNU_implicit_pointer
;
1554 case DW_OP_entry_value
:
1555 if (dwarf_version
< 5)
1556 return DW_OP_GNU_entry_value
;
1559 case DW_OP_const_type
:
1560 if (dwarf_version
< 5)
1561 return DW_OP_GNU_const_type
;
1564 case DW_OP_regval_type
:
1565 if (dwarf_version
< 5)
1566 return DW_OP_GNU_regval_type
;
1569 case DW_OP_deref_type
:
1570 if (dwarf_version
< 5)
1571 return DW_OP_GNU_deref_type
;
1575 if (dwarf_version
< 5)
1576 return DW_OP_GNU_convert
;
1579 case DW_OP_reinterpret
:
1580 if (dwarf_version
< 5)
1581 return DW_OP_GNU_reinterpret
;
1590 /* Similarly for attributes. */
1591 static inline enum dwarf_attribute
1592 dwarf_AT (enum dwarf_attribute at
)
1596 case DW_AT_call_return_pc
:
1597 if (dwarf_version
< 5)
1598 return DW_AT_low_pc
;
1601 case DW_AT_call_tail_call
:
1602 if (dwarf_version
< 5)
1603 return DW_AT_GNU_tail_call
;
1606 case DW_AT_call_origin
:
1607 if (dwarf_version
< 5)
1608 return DW_AT_abstract_origin
;
1611 case DW_AT_call_target
:
1612 if (dwarf_version
< 5)
1613 return DW_AT_GNU_call_site_target
;
1616 case DW_AT_call_target_clobbered
:
1617 if (dwarf_version
< 5)
1618 return DW_AT_GNU_call_site_target_clobbered
;
1621 case DW_AT_call_parameter
:
1622 if (dwarf_version
< 5)
1623 return DW_AT_abstract_origin
;
1626 case DW_AT_call_value
:
1627 if (dwarf_version
< 5)
1628 return DW_AT_GNU_call_site_value
;
1631 case DW_AT_call_data_value
:
1632 if (dwarf_version
< 5)
1633 return DW_AT_GNU_call_site_data_value
;
1636 case DW_AT_call_all_calls
:
1637 if (dwarf_version
< 5)
1638 return DW_AT_GNU_all_call_sites
;
1641 case DW_AT_call_all_tail_calls
:
1642 if (dwarf_version
< 5)
1643 return DW_AT_GNU_all_tail_call_sites
;
1646 case DW_AT_dwo_name
:
1647 if (dwarf_version
< 5)
1648 return DW_AT_GNU_dwo_name
;
1657 /* And similarly for tags. */
1658 static inline enum dwarf_tag
1659 dwarf_TAG (enum dwarf_tag tag
)
1663 case DW_TAG_call_site
:
1664 if (dwarf_version
< 5)
1665 return DW_TAG_GNU_call_site
;
1668 case DW_TAG_call_site_parameter
:
1669 if (dwarf_version
< 5)
1670 return DW_TAG_GNU_call_site_parameter
;
1679 static unsigned long int get_base_type_offset (dw_die_ref
);
1681 /* Return the size of a location descriptor. */
1683 static unsigned long
1684 size_of_loc_descr (dw_loc_descr_ref loc
)
1686 unsigned long size
= 1;
1688 switch (loc
->dw_loc_opc
)
1691 size
+= DWARF2_ADDR_SIZE
;
1693 case DW_OP_GNU_addr_index
:
1694 case DW_OP_GNU_const_index
:
1695 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1696 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1715 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1718 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1723 case DW_OP_plus_uconst
:
1724 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1762 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1765 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1768 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1771 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1772 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1775 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1777 case DW_OP_bit_piece
:
1778 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1779 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1781 case DW_OP_deref_size
:
1782 case DW_OP_xderef_size
:
1791 case DW_OP_call_ref
:
1792 size
+= DWARF_REF_SIZE
;
1794 case DW_OP_implicit_value
:
1795 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1796 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1798 case DW_OP_implicit_pointer
:
1799 case DW_OP_GNU_implicit_pointer
:
1800 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1802 case DW_OP_entry_value
:
1803 case DW_OP_GNU_entry_value
:
1805 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1806 size
+= size_of_uleb128 (op_size
) + op_size
;
1809 case DW_OP_const_type
:
1810 case DW_OP_GNU_const_type
:
1813 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1814 size
+= size_of_uleb128 (o
) + 1;
1815 switch (loc
->dw_loc_oprnd2
.val_class
)
1817 case dw_val_class_vec
:
1818 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1819 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1821 case dw_val_class_const
:
1822 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1824 case dw_val_class_const_double
:
1825 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1827 case dw_val_class_wide_int
:
1828 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1829 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1836 case DW_OP_regval_type
:
1837 case DW_OP_GNU_regval_type
:
1840 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1841 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1842 + size_of_uleb128 (o
);
1845 case DW_OP_deref_type
:
1846 case DW_OP_GNU_deref_type
:
1849 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1850 size
+= 1 + size_of_uleb128 (o
);
1854 case DW_OP_reinterpret
:
1855 case DW_OP_GNU_convert
:
1856 case DW_OP_GNU_reinterpret
:
1857 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1858 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1862 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1863 size
+= size_of_uleb128 (o
);
1866 case DW_OP_GNU_parameter_ref
:
1876 /* Return the size of a series of location descriptors. */
1879 size_of_locs (dw_loc_descr_ref loc
)
1884 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1885 field, to avoid writing to a PCH file. */
1886 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1888 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1890 size
+= size_of_loc_descr (l
);
1895 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1897 l
->dw_loc_addr
= size
;
1898 size
+= size_of_loc_descr (l
);
1904 /* Return the size of the value in a DW_AT_discr_value attribute. */
1907 size_of_discr_value (dw_discr_value
*discr_value
)
1909 if (discr_value
->pos
)
1910 return size_of_uleb128 (discr_value
->v
.uval
);
1912 return size_of_sleb128 (discr_value
->v
.sval
);
1915 /* Return the size of the value in a DW_AT_discr_list attribute. */
1918 size_of_discr_list (dw_discr_list_ref discr_list
)
1922 for (dw_discr_list_ref list
= discr_list
;
1924 list
= list
->dw_discr_next
)
1926 /* One byte for the discriminant value descriptor, and then one or two
1927 LEB128 numbers, depending on whether it's a single case label or a
1930 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
1931 if (list
->dw_discr_range
!= 0)
1932 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
1937 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1938 static void get_ref_die_offset_label (char *, dw_die_ref
);
1939 static unsigned long int get_ref_die_offset (dw_die_ref
);
1941 /* Output location description stack opcode's operands (if any).
1942 The for_eh_or_skip parameter controls whether register numbers are
1943 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1944 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1945 info). This should be suppressed for the cases that have not been converted
1946 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1949 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1951 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1952 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1954 switch (loc
->dw_loc_opc
)
1956 #ifdef DWARF2_DEBUGGING_INFO
1959 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1964 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1965 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1967 fputc ('\n', asm_out_file
);
1972 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1977 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1978 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1980 fputc ('\n', asm_out_file
);
1985 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1986 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1993 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1994 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1996 dw2_asm_output_data (2, offset
, NULL
);
1999 case DW_OP_implicit_value
:
2000 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2001 switch (val2
->val_class
)
2003 case dw_val_class_const
:
2004 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2006 case dw_val_class_vec
:
2008 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2009 unsigned int len
= val2
->v
.val_vec
.length
;
2013 if (elt_size
> sizeof (HOST_WIDE_INT
))
2018 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2021 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2022 "fp or vector constant word %u", i
);
2025 case dw_val_class_const_double
:
2027 unsigned HOST_WIDE_INT first
, second
;
2029 if (WORDS_BIG_ENDIAN
)
2031 first
= val2
->v
.val_double
.high
;
2032 second
= val2
->v
.val_double
.low
;
2036 first
= val2
->v
.val_double
.low
;
2037 second
= val2
->v
.val_double
.high
;
2039 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2041 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2045 case dw_val_class_wide_int
:
2048 int len
= get_full_len (*val2
->v
.val_wide
);
2049 if (WORDS_BIG_ENDIAN
)
2050 for (i
= len
- 1; i
>= 0; --i
)
2051 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2052 val2
->v
.val_wide
->elt (i
), NULL
);
2054 for (i
= 0; i
< len
; ++i
)
2055 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2056 val2
->v
.val_wide
->elt (i
), NULL
);
2059 case dw_val_class_addr
:
2060 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2061 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2076 case DW_OP_implicit_value
:
2077 /* We currently don't make any attempt to make sure these are
2078 aligned properly like we do for the main unwind info, so
2079 don't support emitting things larger than a byte if we're
2080 only doing unwinding. */
2085 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2088 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2091 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2094 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2096 case DW_OP_plus_uconst
:
2097 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2131 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2135 unsigned r
= val1
->v
.val_unsigned
;
2136 if (for_eh_or_skip
>= 0)
2137 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2138 gcc_assert (size_of_uleb128 (r
)
2139 == size_of_uleb128 (val1
->v
.val_unsigned
));
2140 dw2_asm_output_data_uleb128 (r
, NULL
);
2144 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2148 unsigned r
= val1
->v
.val_unsigned
;
2149 if (for_eh_or_skip
>= 0)
2150 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2151 gcc_assert (size_of_uleb128 (r
)
2152 == size_of_uleb128 (val1
->v
.val_unsigned
));
2153 dw2_asm_output_data_uleb128 (r
, NULL
);
2154 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2158 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2160 case DW_OP_bit_piece
:
2161 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2162 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2164 case DW_OP_deref_size
:
2165 case DW_OP_xderef_size
:
2166 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2172 if (targetm
.asm_out
.output_dwarf_dtprel
)
2174 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2177 fputc ('\n', asm_out_file
);
2184 #ifdef DWARF2_DEBUGGING_INFO
2185 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2192 case DW_OP_GNU_addr_index
:
2193 case DW_OP_GNU_const_index
:
2194 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2195 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2196 "(index into .debug_addr)");
2202 unsigned long die_offset
2203 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2204 /* Make sure the offset has been computed and that we can encode it as
2206 gcc_assert (die_offset
> 0
2207 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
2210 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2215 case DW_OP_implicit_pointer
:
2216 case DW_OP_GNU_implicit_pointer
:
2218 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2219 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2220 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2221 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2222 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2223 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2227 case DW_OP_entry_value
:
2228 case DW_OP_GNU_entry_value
:
2229 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2230 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2233 case DW_OP_const_type
:
2234 case DW_OP_GNU_const_type
:
2236 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2238 dw2_asm_output_data_uleb128 (o
, NULL
);
2239 switch (val2
->val_class
)
2241 case dw_val_class_const
:
2242 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2243 dw2_asm_output_data (1, l
, NULL
);
2244 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2246 case dw_val_class_vec
:
2248 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2249 unsigned int len
= val2
->v
.val_vec
.length
;
2254 dw2_asm_output_data (1, l
, NULL
);
2255 if (elt_size
> sizeof (HOST_WIDE_INT
))
2260 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2263 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2264 "fp or vector constant word %u", i
);
2267 case dw_val_class_const_double
:
2269 unsigned HOST_WIDE_INT first
, second
;
2270 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2272 dw2_asm_output_data (1, 2 * l
, NULL
);
2273 if (WORDS_BIG_ENDIAN
)
2275 first
= val2
->v
.val_double
.high
;
2276 second
= val2
->v
.val_double
.low
;
2280 first
= val2
->v
.val_double
.low
;
2281 second
= val2
->v
.val_double
.high
;
2283 dw2_asm_output_data (l
, first
, NULL
);
2284 dw2_asm_output_data (l
, second
, NULL
);
2287 case dw_val_class_wide_int
:
2290 int len
= get_full_len (*val2
->v
.val_wide
);
2291 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2293 dw2_asm_output_data (1, len
* l
, NULL
);
2294 if (WORDS_BIG_ENDIAN
)
2295 for (i
= len
- 1; i
>= 0; --i
)
2296 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2298 for (i
= 0; i
< len
; ++i
)
2299 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2307 case DW_OP_regval_type
:
2308 case DW_OP_GNU_regval_type
:
2310 unsigned r
= val1
->v
.val_unsigned
;
2311 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2313 if (for_eh_or_skip
>= 0)
2315 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2316 gcc_assert (size_of_uleb128 (r
)
2317 == size_of_uleb128 (val1
->v
.val_unsigned
));
2319 dw2_asm_output_data_uleb128 (r
, NULL
);
2320 dw2_asm_output_data_uleb128 (o
, NULL
);
2323 case DW_OP_deref_type
:
2324 case DW_OP_GNU_deref_type
:
2326 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2328 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2329 dw2_asm_output_data_uleb128 (o
, NULL
);
2333 case DW_OP_reinterpret
:
2334 case DW_OP_GNU_convert
:
2335 case DW_OP_GNU_reinterpret
:
2336 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2337 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2340 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2342 dw2_asm_output_data_uleb128 (o
, NULL
);
2346 case DW_OP_GNU_parameter_ref
:
2349 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2350 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2351 dw2_asm_output_data (4, o
, NULL
);
2356 /* Other codes have no operands. */
2361 /* Output a sequence of location operations.
2362 The for_eh_or_skip parameter controls whether register numbers are
2363 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2364 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2365 info). This should be suppressed for the cases that have not been converted
2366 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2369 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2371 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2373 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2374 /* Output the opcode. */
2375 if (for_eh_or_skip
>= 0
2376 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2378 unsigned r
= (opc
- DW_OP_breg0
);
2379 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2380 gcc_assert (r
<= 31);
2381 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2383 else if (for_eh_or_skip
>= 0
2384 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2386 unsigned r
= (opc
- DW_OP_reg0
);
2387 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2388 gcc_assert (r
<= 31);
2389 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2392 dw2_asm_output_data (1, opc
,
2393 "%s", dwarf_stack_op_name (opc
));
2395 /* Output the operand(s) (if any). */
2396 output_loc_operands (loc
, for_eh_or_skip
);
2400 /* Output location description stack opcode's operands (if any).
2401 The output is single bytes on a line, suitable for .cfi_escape. */
2404 output_loc_operands_raw (dw_loc_descr_ref loc
)
2406 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2407 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2409 switch (loc
->dw_loc_opc
)
2412 case DW_OP_GNU_addr_index
:
2413 case DW_OP_GNU_const_index
:
2414 case DW_OP_implicit_value
:
2415 /* We cannot output addresses in .cfi_escape, only bytes. */
2421 case DW_OP_deref_size
:
2422 case DW_OP_xderef_size
:
2423 fputc (',', asm_out_file
);
2424 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2429 fputc (',', asm_out_file
);
2430 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2435 fputc (',', asm_out_file
);
2436 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2441 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2442 fputc (',', asm_out_file
);
2443 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2451 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2452 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2454 fputc (',', asm_out_file
);
2455 dw2_asm_output_data_raw (2, offset
);
2461 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2462 gcc_assert (size_of_uleb128 (r
)
2463 == size_of_uleb128 (val1
->v
.val_unsigned
));
2464 fputc (',', asm_out_file
);
2465 dw2_asm_output_data_uleb128_raw (r
);
2470 case DW_OP_plus_uconst
:
2472 fputc (',', asm_out_file
);
2473 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2476 case DW_OP_bit_piece
:
2477 fputc (',', asm_out_file
);
2478 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2479 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2516 fputc (',', asm_out_file
);
2517 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2522 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2523 gcc_assert (size_of_uleb128 (r
)
2524 == size_of_uleb128 (val1
->v
.val_unsigned
));
2525 fputc (',', asm_out_file
);
2526 dw2_asm_output_data_uleb128_raw (r
);
2527 fputc (',', asm_out_file
);
2528 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2532 case DW_OP_implicit_pointer
:
2533 case DW_OP_entry_value
:
2534 case DW_OP_const_type
:
2535 case DW_OP_regval_type
:
2536 case DW_OP_deref_type
:
2538 case DW_OP_reinterpret
:
2539 case DW_OP_GNU_implicit_pointer
:
2540 case DW_OP_GNU_entry_value
:
2541 case DW_OP_GNU_const_type
:
2542 case DW_OP_GNU_regval_type
:
2543 case DW_OP_GNU_deref_type
:
2544 case DW_OP_GNU_convert
:
2545 case DW_OP_GNU_reinterpret
:
2546 case DW_OP_GNU_parameter_ref
:
2551 /* Other codes have no operands. */
2557 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2561 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2562 /* Output the opcode. */
2563 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2565 unsigned r
= (opc
- DW_OP_breg0
);
2566 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2567 gcc_assert (r
<= 31);
2568 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2570 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2572 unsigned r
= (opc
- DW_OP_reg0
);
2573 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2574 gcc_assert (r
<= 31);
2575 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2577 /* Output the opcode. */
2578 fprintf (asm_out_file
, "%#x", opc
);
2579 output_loc_operands_raw (loc
);
2581 if (!loc
->dw_loc_next
)
2583 loc
= loc
->dw_loc_next
;
2585 fputc (',', asm_out_file
);
2589 /* This function builds a dwarf location descriptor sequence from a
2590 dw_cfa_location, adding the given OFFSET to the result of the
2593 struct dw_loc_descr_node
*
2594 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2596 struct dw_loc_descr_node
*head
, *tmp
;
2598 offset
+= cfa
->offset
;
2602 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2603 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2604 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2605 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2606 add_loc_descr (&head
, tmp
);
2609 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2610 add_loc_descr (&head
, tmp
);
2614 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2619 /* This function builds a dwarf location descriptor sequence for
2620 the address at OFFSET from the CFA when stack is aligned to
2623 struct dw_loc_descr_node
*
2624 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2625 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2627 struct dw_loc_descr_node
*head
;
2628 unsigned int dwarf_fp
2629 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2631 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2632 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2634 head
= new_reg_loc_descr (dwarf_fp
, 0);
2635 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2636 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2637 loc_descr_plus_const (&head
, offset
);
2640 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2644 /* And now, the support for symbolic debugging information. */
2646 /* .debug_str support. */
2648 static void dwarf2out_init (const char *);
2649 static void dwarf2out_finish (const char *);
2650 static void dwarf2out_early_finish (const char *);
2651 static void dwarf2out_assembly_start (void);
2652 static void dwarf2out_define (unsigned int, const char *);
2653 static void dwarf2out_undef (unsigned int, const char *);
2654 static void dwarf2out_start_source_file (unsigned, const char *);
2655 static void dwarf2out_end_source_file (unsigned);
2656 static void dwarf2out_function_decl (tree
);
2657 static void dwarf2out_begin_block (unsigned, unsigned);
2658 static void dwarf2out_end_block (unsigned, unsigned);
2659 static bool dwarf2out_ignore_block (const_tree
);
2660 static void dwarf2out_early_global_decl (tree
);
2661 static void dwarf2out_late_global_decl (tree
);
2662 static void dwarf2out_type_decl (tree
, int);
2663 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2664 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2666 static void dwarf2out_abstract_function (tree
);
2667 static void dwarf2out_var_location (rtx_insn
*);
2668 static void dwarf2out_size_function (tree
);
2669 static void dwarf2out_begin_function (tree
);
2670 static void dwarf2out_end_function (unsigned int);
2671 static void dwarf2out_register_main_translation_unit (tree unit
);
2672 static void dwarf2out_set_name (tree
, tree
);
2674 /* The debug hooks structure. */
2676 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2680 dwarf2out_early_finish
,
2681 dwarf2out_assembly_start
,
2684 dwarf2out_start_source_file
,
2685 dwarf2out_end_source_file
,
2686 dwarf2out_begin_block
,
2687 dwarf2out_end_block
,
2688 dwarf2out_ignore_block
,
2689 dwarf2out_source_line
,
2690 dwarf2out_begin_prologue
,
2691 #if VMS_DEBUGGING_INFO
2692 dwarf2out_vms_end_prologue
,
2693 dwarf2out_vms_begin_epilogue
,
2695 debug_nothing_int_charstar
,
2696 debug_nothing_int_charstar
,
2698 dwarf2out_end_epilogue
,
2699 dwarf2out_begin_function
,
2700 dwarf2out_end_function
, /* end_function */
2701 dwarf2out_register_main_translation_unit
,
2702 dwarf2out_function_decl
, /* function_decl */
2703 dwarf2out_early_global_decl
,
2704 dwarf2out_late_global_decl
,
2705 dwarf2out_type_decl
, /* type_decl */
2706 dwarf2out_imported_module_or_decl
,
2707 debug_nothing_tree
, /* deferred_inline_function */
2708 /* The DWARF 2 backend tries to reduce debugging bloat by not
2709 emitting the abstract description of inline functions until
2710 something tries to reference them. */
2711 dwarf2out_abstract_function
, /* outlining_inline_function */
2712 debug_nothing_rtx_code_label
, /* label */
2713 debug_nothing_int
, /* handle_pch */
2714 dwarf2out_var_location
,
2715 dwarf2out_size_function
, /* size_function */
2716 dwarf2out_switch_text_section
,
2718 1, /* start_end_main_source_file */
2719 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2722 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2725 debug_nothing_charstar
,
2726 debug_nothing_charstar
,
2727 dwarf2out_assembly_start
,
2728 debug_nothing_int_charstar
,
2729 debug_nothing_int_charstar
,
2730 debug_nothing_int_charstar
,
2732 debug_nothing_int_int
, /* begin_block */
2733 debug_nothing_int_int
, /* end_block */
2734 debug_true_const_tree
, /* ignore_block */
2735 dwarf2out_source_line
, /* source_line */
2736 debug_nothing_int_charstar
, /* begin_prologue */
2737 debug_nothing_int_charstar
, /* end_prologue */
2738 debug_nothing_int_charstar
, /* begin_epilogue */
2739 debug_nothing_int_charstar
, /* end_epilogue */
2740 debug_nothing_tree
, /* begin_function */
2741 debug_nothing_int
, /* end_function */
2742 debug_nothing_tree
, /* register_main_translation_unit */
2743 debug_nothing_tree
, /* function_decl */
2744 debug_nothing_tree
, /* early_global_decl */
2745 debug_nothing_tree
, /* late_global_decl */
2746 debug_nothing_tree_int
, /* type_decl */
2747 debug_nothing_tree_tree_tree_bool
, /* imported_module_or_decl */
2748 debug_nothing_tree
, /* deferred_inline_function */
2749 debug_nothing_tree
, /* outlining_inline_function */
2750 debug_nothing_rtx_code_label
, /* label */
2751 debug_nothing_int
, /* handle_pch */
2752 debug_nothing_rtx_insn
, /* var_location */
2753 debug_nothing_tree
, /* size_function */
2754 debug_nothing_void
, /* switch_text_section */
2755 debug_nothing_tree_tree
, /* set_name */
2756 0, /* start_end_main_source_file */
2757 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2760 /* NOTE: In the comments in this file, many references are made to
2761 "Debugging Information Entries". This term is abbreviated as `DIE'
2762 throughout the remainder of this file. */
2764 /* An internal representation of the DWARF output is built, and then
2765 walked to generate the DWARF debugging info. The walk of the internal
2766 representation is done after the entire program has been compiled.
2767 The types below are used to describe the internal representation. */
2769 /* Whether to put type DIEs into their own section .debug_types instead
2770 of making them part of the .debug_info section. Only supported for
2771 Dwarf V4 or higher and the user didn't disable them through
2772 -fno-debug-types-section. It is more efficient to put them in a
2773 separate comdat sections since the linker will then be able to
2774 remove duplicates. But not all tools support .debug_types sections
2775 yet. For Dwarf V5 or higher .debug_types doesn't exist any more,
2776 it is DW_UT_type unit type in .debug_info section. */
2778 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2780 /* Various DIE's use offsets relative to the beginning of the
2781 .debug_info section to refer to each other. */
2783 typedef long int dw_offset
;
2785 struct comdat_type_node
;
2787 /* The entries in the line_info table more-or-less mirror the opcodes
2788 that are used in the real dwarf line table. Arrays of these entries
2789 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2792 enum dw_line_info_opcode
{
2793 /* Emit DW_LNE_set_address; the operand is the label index. */
2796 /* Emit a row to the matrix with the given line. This may be done
2797 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2801 /* Emit a DW_LNS_set_file. */
2804 /* Emit a DW_LNS_set_column. */
2807 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2810 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2811 LI_set_prologue_end
,
2812 LI_set_epilogue_begin
,
2814 /* Emit a DW_LNE_set_discriminator. */
2815 LI_set_discriminator
2818 typedef struct GTY(()) dw_line_info_struct
{
2819 enum dw_line_info_opcode opcode
;
2821 } dw_line_info_entry
;
2824 struct GTY(()) dw_line_info_table
{
2825 /* The label that marks the end of this section. */
2826 const char *end_label
;
2828 /* The values for the last row of the matrix, as collected in the table.
2829 These are used to minimize the changes to the next row. */
2830 unsigned int file_num
;
2831 unsigned int line_num
;
2832 unsigned int column_num
;
2837 vec
<dw_line_info_entry
, va_gc
> *entries
;
2841 /* Each DIE attribute has a field specifying the attribute kind,
2842 a link to the next attribute in the chain, and an attribute value.
2843 Attributes are typically linked below the DIE they modify. */
2845 typedef struct GTY(()) dw_attr_struct
{
2846 enum dwarf_attribute dw_attr
;
2847 dw_val_node dw_attr_val
;
2852 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2853 The children of each node form a circular list linked by
2854 die_sib. die_child points to the node *before* the "first" child node. */
2856 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2857 union die_symbol_or_type_node
2859 const char * GTY ((tag ("0"))) die_symbol
;
2860 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
2862 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2863 vec
<dw_attr_node
, va_gc
> *die_attr
;
2864 dw_die_ref die_parent
;
2865 dw_die_ref die_child
;
2867 dw_die_ref die_definition
; /* ref from a specification to its definition */
2868 dw_offset die_offset
;
2869 unsigned long die_abbrev
;
2871 unsigned int decl_id
;
2872 enum dwarf_tag die_tag
;
2873 /* Die is used and must not be pruned as unused. */
2874 BOOL_BITFIELD die_perennial_p
: 1;
2875 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2876 /* Whether this DIE was removed from the DIE tree, for example via
2877 prune_unused_types. We don't consider those present from the
2878 DIE lookup routines. */
2879 BOOL_BITFIELD removed
: 1;
2880 /* Lots of spare bits. */
2884 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2885 static bool early_dwarf
;
2886 static bool early_dwarf_finished
;
2887 struct set_early_dwarf
{
2889 set_early_dwarf () : saved(early_dwarf
)
2891 gcc_assert (! early_dwarf_finished
);
2894 ~set_early_dwarf () { early_dwarf
= saved
; }
2897 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2898 #define FOR_EACH_CHILD(die, c, expr) do { \
2899 c = die->die_child; \
2903 } while (c != die->die_child); \
2906 /* The pubname structure */
2908 typedef struct GTY(()) pubname_struct
{
2915 struct GTY(()) dw_ranges
{
2917 /* If this is positive, it's a block number, otherwise it's a
2918 bitwise-negated index into dw_ranges_by_label. */
2920 /* Index for the range list for DW_FORM_rnglistx. */
2921 unsigned int idx
: 31;
2922 /* True if this range might be possibly in a different section
2923 from previous entry. */
2924 unsigned int maybe_new_sec
: 1;
2927 /* A structure to hold a macinfo entry. */
2929 typedef struct GTY(()) macinfo_struct
{
2931 unsigned HOST_WIDE_INT lineno
;
2937 struct GTY(()) dw_ranges_by_label
{
2942 /* The comdat type node structure. */
2943 struct GTY(()) comdat_type_node
2945 dw_die_ref root_die
;
2946 dw_die_ref type_die
;
2947 dw_die_ref skeleton_die
;
2948 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2949 comdat_type_node
*next
;
2952 /* A list of DIEs for which we can't determine ancestry (parent_die
2953 field) just yet. Later in dwarf2out_finish we will fill in the
2955 typedef struct GTY(()) limbo_die_struct
{
2957 /* The tree for which this DIE was created. We use this to
2958 determine ancestry later. */
2960 struct limbo_die_struct
*next
;
2964 typedef struct skeleton_chain_struct
2968 struct skeleton_chain_struct
*parent
;
2970 skeleton_chain_node
;
2972 /* Define a macro which returns nonzero for a TYPE_DECL which was
2973 implicitly generated for a type.
2975 Note that, unlike the C front-end (which generates a NULL named
2976 TYPE_DECL node for each complete tagged type, each array type,
2977 and each function type node created) the C++ front-end generates
2978 a _named_ TYPE_DECL node for each tagged type node created.
2979 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2980 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2981 front-end, but for each type, tagged or not. */
2983 #define TYPE_DECL_IS_STUB(decl) \
2984 (DECL_NAME (decl) == NULL_TREE \
2985 || (DECL_ARTIFICIAL (decl) \
2986 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2987 /* This is necessary for stub decls that \
2988 appear in nested inline functions. */ \
2989 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2990 && (decl_ultimate_origin (decl) \
2991 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2993 /* Information concerning the compilation unit's programming
2994 language, and compiler version. */
2996 /* Fixed size portion of the DWARF compilation unit header. */
2997 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2998 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE \
2999 + (dwarf_version >= 5 ? 4 : 3))
3001 /* Fixed size portion of the DWARF comdat type unit header. */
3002 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3003 (DWARF_COMPILE_UNIT_HEADER_SIZE \
3004 + DWARF_TYPE_SIGNATURE_SIZE + DWARF_OFFSET_SIZE)
3006 /* Fixed size portion of the DWARF skeleton compilation unit header. */
3007 #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
3008 (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
3010 /* Fixed size portion of public names info. */
3011 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3013 /* Fixed size portion of the address range info. */
3014 #define DWARF_ARANGES_HEADER_SIZE \
3015 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3016 DWARF2_ADDR_SIZE * 2) \
3017 - DWARF_INITIAL_LENGTH_SIZE)
3019 /* Size of padding portion in the address range info. It must be
3020 aligned to twice the pointer size. */
3021 #define DWARF_ARANGES_PAD_SIZE \
3022 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3023 DWARF2_ADDR_SIZE * 2) \
3024 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3026 /* Use assembler line directives if available. */
3027 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3028 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3029 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3031 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3035 /* Minimum line offset in a special line info. opcode.
3036 This value was chosen to give a reasonable range of values. */
3037 #define DWARF_LINE_BASE -10
3039 /* First special line opcode - leave room for the standard opcodes. */
3040 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3042 /* Range of line offsets in a special line info. opcode. */
3043 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3045 /* Flag that indicates the initial value of the is_stmt_start flag.
3046 In the present implementation, we do not mark any lines as
3047 the beginning of a source statement, because that information
3048 is not made available by the GCC front-end. */
3049 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3051 /* Maximum number of operations per instruction bundle. */
3052 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3053 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3056 /* This location is used by calc_die_sizes() to keep track
3057 the offset of each DIE within the .debug_info section. */
3058 static unsigned long next_die_offset
;
3060 /* Record the root of the DIE's built for the current compilation unit. */
3061 static GTY(()) dw_die_ref single_comp_unit_die
;
3063 /* A list of type DIEs that have been separated into comdat sections. */
3064 static GTY(()) comdat_type_node
*comdat_type_list
;
3066 /* A list of CU DIEs that have been separated. */
3067 static GTY(()) limbo_die_node
*cu_die_list
;
3069 /* A list of DIEs with a NULL parent waiting to be relocated. */
3070 static GTY(()) limbo_die_node
*limbo_die_list
;
3072 /* A list of DIEs for which we may have to generate
3073 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3074 static GTY(()) limbo_die_node
*deferred_asm_name
;
3076 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
3078 typedef const char *compare_type
;
3080 static hashval_t
hash (dwarf_file_data
*);
3081 static bool equal (dwarf_file_data
*, const char *);
3084 /* Filenames referenced by this compilation unit. */
3085 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
3087 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
3089 typedef tree compare_type
;
3091 static hashval_t
hash (die_node
*);
3092 static bool equal (die_node
*, tree
);
3094 /* A hash table of references to DIE's that describe declarations.
3095 The key is a DECL_UID() which is a unique number identifying each decl. */
3096 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
3098 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
3100 static hashval_t
hash (die_struct
*);
3101 static bool equal (die_struct
*, die_struct
*);
3104 /* A hash table of references to DIE's that describe COMMON blocks.
3105 The key is DECL_UID() ^ die_parent. */
3106 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
3108 typedef struct GTY(()) die_arg_entry_struct
{
3114 /* Node of the variable location list. */
3115 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3116 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3117 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3118 in mode of the EXPR_LIST node and first EXPR_LIST operand
3119 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3120 location or NULL for padding. For larger bitsizes,
3121 mode is 0 and first operand is a CONCAT with bitsize
3122 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3123 NULL as second operand. */
3125 const char * GTY (()) label
;
3126 struct var_loc_node
* GTY (()) next
;
3129 /* Variable location list. */
3130 struct GTY ((for_user
)) var_loc_list_def
{
3131 struct var_loc_node
* GTY (()) first
;
3133 /* Pointer to the last but one or last element of the
3134 chained list. If the list is empty, both first and
3135 last are NULL, if the list contains just one node
3136 or the last node certainly is not redundant, it points
3137 to the last node, otherwise points to the last but one.
3138 Do not mark it for GC because it is marked through the chain. */
3139 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3141 /* Pointer to the last element before section switch,
3142 if NULL, either sections weren't switched or first
3143 is after section switch. */
3144 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3146 /* DECL_UID of the variable decl. */
3147 unsigned int decl_id
;
3149 typedef struct var_loc_list_def var_loc_list
;
3151 /* Call argument location list. */
3152 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3153 rtx
GTY (()) call_arg_loc_note
;
3154 const char * GTY (()) label
;
3155 tree
GTY (()) block
;
3157 rtx
GTY (()) symbol_ref
;
3158 struct call_arg_loc_node
* GTY (()) next
;
3162 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
3164 typedef const_tree compare_type
;
3166 static hashval_t
hash (var_loc_list
*);
3167 static bool equal (var_loc_list
*, const_tree
);
3170 /* Table of decl location linked lists. */
3171 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
3173 /* Head and tail of call_arg_loc chain. */
3174 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3175 static struct call_arg_loc_node
*call_arg_loc_last
;
3177 /* Number of call sites in the current function. */
3178 static int call_site_count
= -1;
3179 /* Number of tail call sites in the current function. */
3180 static int tail_call_site_count
= -1;
3182 /* A cached location list. */
3183 struct GTY ((for_user
)) cached_dw_loc_list_def
{
3184 /* The DECL_UID of the decl that this entry describes. */
3185 unsigned int decl_id
;
3187 /* The cached location list. */
3188 dw_loc_list_ref loc_list
;
3190 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3192 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3195 typedef const_tree compare_type
;
3197 static hashval_t
hash (cached_dw_loc_list
*);
3198 static bool equal (cached_dw_loc_list
*, const_tree
);
3201 /* Table of cached location lists. */
3202 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3204 /* A vector of references to DIE's that are uniquely identified by their tag,
3205 presence/absence of children DIE's, and list of attribute/value pairs. */
3206 static GTY(()) vec
<dw_die_ref
, va_gc
> *abbrev_die_table
;
3208 /* A hash map to remember the stack usage for DWARF procedures. The value
3209 stored is the stack size difference between before the DWARF procedure
3210 invokation and after it returned. In other words, for a DWARF procedure
3211 that consumes N stack slots and that pushes M ones, this stores M - N. */
3212 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3214 /* A global counter for generating labels for line number data. */
3215 static unsigned int line_info_label_num
;
3217 /* The current table to which we should emit line number information
3218 for the current function. This will be set up at the beginning of
3219 assembly for the function. */
3220 static GTY(()) dw_line_info_table
*cur_line_info_table
;
3222 /* The two default tables of line number info. */
3223 static GTY(()) dw_line_info_table
*text_section_line_info
;
3224 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3226 /* The set of all non-default tables of line number info. */
3227 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3229 /* A flag to tell pubnames/types export if there is an info section to
3231 static bool info_section_emitted
;
3233 /* A pointer to the base of a table that contains a list of publicly
3234 accessible names. */
3235 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3237 /* A pointer to the base of a table that contains a list of publicly
3238 accessible types. */
3239 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3241 /* A pointer to the base of a table that contains a list of macro
3242 defines/undefines (and file start/end markers). */
3243 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3245 /* True if .debug_macinfo or .debug_macros section is going to be
3247 #define have_macinfo \
3248 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3249 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3250 && !macinfo_table->is_empty ())
3252 /* Vector of dies for which we should generate .debug_ranges info. */
3253 static GTY (()) vec
<dw_ranges
, va_gc
> *ranges_table
;
3255 /* Vector of pairs of labels referenced in ranges_table. */
3256 static GTY (()) vec
<dw_ranges_by_label
, va_gc
> *ranges_by_label
;
3258 /* Whether we have location lists that need outputting */
3259 static GTY(()) bool have_location_lists
;
3261 /* Unique label counter. */
3262 static GTY(()) unsigned int loclabel_num
;
3264 /* Unique label counter for point-of-call tables. */
3265 static GTY(()) unsigned int poc_label_num
;
3267 /* The last file entry emitted by maybe_emit_file(). */
3268 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3270 /* Number of internal labels generated by gen_internal_sym(). */
3271 static GTY(()) int label_num
;
3273 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3275 /* Instances of generic types for which we need to generate debug
3276 info that describe their generic parameters and arguments. That
3277 generation needs to happen once all types are properly laid out so
3278 we do it at the end of compilation. */
3279 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3281 /* Offset from the "steady-state frame pointer" to the frame base,
3282 within the current function. */
3283 static HOST_WIDE_INT frame_pointer_fb_offset
;
3284 static bool frame_pointer_fb_offset_valid
;
3286 static vec
<dw_die_ref
> base_types
;
3288 /* Pointer to vector of DW_TAG_string_type DIEs that need finalization
3289 once all arguments are parsed. */
3290 static vec
<dw_die_ref
> *string_types
;
3292 /* Flags to represent a set of attribute classes for attributes that represent
3293 a scalar value (bounds, pointers, ...). */
3296 dw_scalar_form_constant
= 0x01,
3297 dw_scalar_form_exprloc
= 0x02,
3298 dw_scalar_form_reference
= 0x04
3301 /* Forward declarations for functions defined in this file. */
3303 static int is_pseudo_reg (const_rtx
);
3304 static tree
type_main_variant (tree
);
3305 static int is_tagged_type (const_tree
);
3306 static const char *dwarf_tag_name (unsigned);
3307 static const char *dwarf_attr_name (unsigned);
3308 static const char *dwarf_form_name (unsigned);
3309 static tree
decl_ultimate_origin (const_tree
);
3310 static tree
decl_class_context (tree
);
3311 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3312 static inline enum dw_val_class
AT_class (dw_attr_node
*);
3313 static inline unsigned int AT_index (dw_attr_node
*);
3314 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3315 static inline unsigned AT_flag (dw_attr_node
*);
3316 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3317 static inline HOST_WIDE_INT
AT_int (dw_attr_node
*);
3318 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3319 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_node
*);
3320 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3321 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3322 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3323 unsigned int, unsigned char *);
3324 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3325 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3326 static inline const char *AT_string (dw_attr_node
*);
3327 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3328 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3329 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3330 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3331 static inline int AT_ref_external (dw_attr_node
*);
3332 static inline void set_AT_ref_external (dw_attr_node
*, int);
3333 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3334 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3335 static inline dw_loc_descr_ref
AT_loc (dw_attr_node
*);
3336 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3338 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3339 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3340 static void remove_addr_table_entry (addr_table_entry
*);
3341 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3342 static inline rtx
AT_addr (dw_attr_node
*);
3343 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3344 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3345 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3346 static void add_AT_loclistsptr (dw_die_ref
, enum dwarf_attribute
,
3348 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3349 unsigned HOST_WIDE_INT
);
3350 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3351 unsigned long, bool);
3352 static inline const char *AT_lbl (dw_attr_node
*);
3353 static dw_attr_node
*get_AT (dw_die_ref
, enum dwarf_attribute
);
3354 static const char *get_AT_low_pc (dw_die_ref
);
3355 static const char *get_AT_hi_pc (dw_die_ref
);
3356 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3357 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3358 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3359 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3360 static bool is_cxx (void);
3361 static bool is_cxx (const_tree
);
3362 static bool is_fortran (void);
3363 static bool is_ada (void);
3364 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3365 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3366 static void add_child_die (dw_die_ref
, dw_die_ref
);
3367 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3368 static dw_die_ref
lookup_type_die (tree
);
3369 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3370 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3371 static void equate_type_number_to_die (tree
, dw_die_ref
);
3372 static dw_die_ref
lookup_decl_die (tree
);
3373 static var_loc_list
*lookup_decl_loc (const_tree
);
3374 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3375 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3376 static void print_spaces (FILE *);
3377 static void print_die (dw_die_ref
, FILE *);
3378 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3379 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3380 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3381 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3382 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3383 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3384 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3385 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3386 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3387 struct md5_ctx
*, int *);
3388 struct checksum_attributes
;
3389 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3390 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3391 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3392 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3393 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3394 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3395 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3396 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3397 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3398 static void compute_section_prefix (dw_die_ref
);
3399 static int is_type_die (dw_die_ref
);
3400 static int is_comdat_die (dw_die_ref
);
3401 static int is_symbol_die (dw_die_ref
);
3402 static inline bool is_template_instantiation (dw_die_ref
);
3403 static void assign_symbol_names (dw_die_ref
);
3404 static void break_out_includes (dw_die_ref
);
3405 static int is_declaration_die (dw_die_ref
);
3406 static int should_move_die_to_comdat (dw_die_ref
);
3407 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3408 static dw_die_ref
clone_die (dw_die_ref
);
3409 static dw_die_ref
clone_tree (dw_die_ref
);
3410 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3411 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3412 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3413 static dw_die_ref
generate_skeleton (dw_die_ref
);
3414 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3417 static void break_out_comdat_types (dw_die_ref
);
3418 static void copy_decls_for_unworthy_types (dw_die_ref
);
3420 static void add_sibling_attributes (dw_die_ref
);
3421 static void output_location_lists (dw_die_ref
);
3422 static int constant_size (unsigned HOST_WIDE_INT
);
3423 static unsigned long size_of_die (dw_die_ref
);
3424 static void calc_die_sizes (dw_die_ref
);
3425 static void calc_base_type_die_sizes (void);
3426 static void mark_dies (dw_die_ref
);
3427 static void unmark_dies (dw_die_ref
);
3428 static void unmark_all_dies (dw_die_ref
);
3429 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3430 static unsigned long size_of_aranges (void);
3431 static enum dwarf_form
value_format (dw_attr_node
*);
3432 static void output_value_format (dw_attr_node
*);
3433 static void output_abbrev_section (void);
3434 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3435 static void output_die_symbol (dw_die_ref
);
3436 static void output_die (dw_die_ref
);
3437 static void output_compilation_unit_header (enum dwarf_unit_type
);
3438 static void output_comp_unit (dw_die_ref
, int, const unsigned char *);
3439 static void output_comdat_type_unit (comdat_type_node
*);
3440 static const char *dwarf2_name (tree
, int);
3441 static void add_pubname (tree
, dw_die_ref
);
3442 static void add_enumerator_pubname (const char *, dw_die_ref
);
3443 static void add_pubname_string (const char *, dw_die_ref
);
3444 static void add_pubtype (tree
, dw_die_ref
);
3445 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3446 static void output_aranges (void);
3447 static unsigned int add_ranges (const_tree
, bool = false);
3448 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3450 static void output_ranges (void);
3451 static dw_line_info_table
*new_line_info_table (void);
3452 static void output_line_info (bool);
3453 static void output_file_names (void);
3454 static dw_die_ref
base_type_die (tree
, bool);
3455 static int is_base_type (tree
);
3456 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3457 static int decl_quals (const_tree
);
3458 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3459 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3460 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3461 static int type_is_enum (const_tree
);
3462 static unsigned int dbx_reg_number (const_rtx
);
3463 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3464 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3465 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3466 enum var_init_status
);
3467 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3468 enum var_init_status
);
3469 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3470 enum var_init_status
);
3471 static int is_based_loc (const_rtx
);
3472 static bool resolve_one_addr (rtx
*);
3473 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3474 enum var_init_status
);
3475 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3476 enum var_init_status
);
3477 struct loc_descr_context
;
3478 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3479 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3480 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3481 struct loc_descr_context
*);
3482 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3483 struct loc_descr_context
*);
3484 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3485 static tree
field_type (const_tree
);
3486 static unsigned int simple_type_align_in_bits (const_tree
);
3487 static unsigned int simple_decl_align_in_bits (const_tree
);
3488 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3490 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3492 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3494 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3495 struct vlr_context
*);
3496 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3497 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3498 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3499 static void insert_float (const_rtx
, unsigned char *);
3500 static rtx
rtl_for_decl_location (tree
);
3501 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3502 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3503 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3504 static void add_name_attribute (dw_die_ref
, const char *);
3505 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3506 static void add_comp_dir_attribute (dw_die_ref
);
3507 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3508 struct loc_descr_context
*);
3509 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3510 struct loc_descr_context
*);
3511 static void add_subscript_info (dw_die_ref
, tree
, bool);
3512 static void add_byte_size_attribute (dw_die_ref
, tree
);
3513 static void add_alignment_attribute (dw_die_ref
, tree
);
3514 static inline void add_bit_offset_attribute (dw_die_ref
, tree
,
3515 struct vlr_context
*);
3516 static void add_bit_size_attribute (dw_die_ref
, tree
);
3517 static void add_prototyped_attribute (dw_die_ref
, tree
);
3518 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3519 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3520 static void add_src_coords_attributes (dw_die_ref
, tree
);
3521 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
, bool = false);
3522 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3523 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3524 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3525 static void push_decl_scope (tree
);
3526 static void pop_decl_scope (void);
3527 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3528 static inline int local_scope_p (dw_die_ref
);
3529 static inline int class_scope_p (dw_die_ref
);
3530 static inline int class_or_namespace_scope_p (dw_die_ref
);
3531 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3532 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3533 static const char *type_tag (const_tree
);
3534 static tree
member_declared_type (const_tree
);
3536 static const char *decl_start_label (tree
);
3538 static void gen_array_type_die (tree
, dw_die_ref
);
3539 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3541 static void gen_entry_point_die (tree
, dw_die_ref
);
3543 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3544 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3545 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3546 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3547 static void gen_formal_types_die (tree
, dw_die_ref
);
3548 static void gen_subprogram_die (tree
, dw_die_ref
);
3549 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3550 static void gen_const_die (tree
, dw_die_ref
);
3551 static void gen_label_die (tree
, dw_die_ref
);
3552 static void gen_lexical_block_die (tree
, dw_die_ref
);
3553 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3554 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3555 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3556 static dw_die_ref
gen_compile_unit_die (const char *);
3557 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3558 static void gen_member_die (tree
, dw_die_ref
);
3559 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3560 enum debug_info_usage
);
3561 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3562 static void gen_typedef_die (tree
, dw_die_ref
);
3563 static void gen_type_die (tree
, dw_die_ref
);
3564 static void gen_block_die (tree
, dw_die_ref
);
3565 static void decls_for_scope (tree
, dw_die_ref
);
3566 static bool is_naming_typedef_decl (const_tree
);
3567 static inline dw_die_ref
get_context_die (tree
);
3568 static void gen_namespace_die (tree
, dw_die_ref
);
3569 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3570 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3571 static dw_die_ref
force_decl_die (tree
);
3572 static dw_die_ref
force_type_die (tree
);
3573 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3574 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3575 static struct dwarf_file_data
* lookup_filename (const char *);
3576 static void retry_incomplete_types (void);
3577 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3578 static void gen_generic_params_dies (tree
);
3579 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3580 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3581 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3582 static int file_info_cmp (const void *, const void *);
3583 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3584 const char *, const char *);
3585 static void output_loc_list (dw_loc_list_ref
);
3586 static char *gen_internal_sym (const char *);
3587 static bool want_pubnames (void);
3589 static void prune_unmark_dies (dw_die_ref
);
3590 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3591 static void prune_unused_types_mark (dw_die_ref
, int);
3592 static void prune_unused_types_walk (dw_die_ref
);
3593 static void prune_unused_types_walk_attribs (dw_die_ref
);
3594 static void prune_unused_types_prune (dw_die_ref
);
3595 static void prune_unused_types (void);
3596 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3597 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3598 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3599 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3600 const char *, const char *);
3601 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3602 static void gen_remaining_tmpl_value_param_die_attribute (void);
3603 static bool generic_type_p (tree
);
3604 static void schedule_generic_params_dies_gen (tree t
);
3605 static void gen_scheduled_generic_parms_dies (void);
3607 static const char *comp_dir_string (void);
3609 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3611 /* enum for tracking thread-local variables whose address is really an offset
3612 relative to the TLS pointer, which will need link-time relocation, but will
3613 not need relocation by the DWARF consumer. */
3621 /* Return the operator to use for an address of a variable. For dtprel_true, we
3622 use DW_OP_const*. For regular variables, which need both link-time
3623 relocation and consumer-level relocation (e.g., to account for shared objects
3624 loaded at a random address), we use DW_OP_addr*. */
3626 static inline enum dwarf_location_atom
3627 dw_addr_op (enum dtprel_bool dtprel
)
3629 if (dtprel
== dtprel_true
)
3630 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3631 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3633 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3636 /* Return a pointer to a newly allocated address location description. If
3637 dwarf_split_debug_info is true, then record the address with the appropriate
3639 static inline dw_loc_descr_ref
3640 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3642 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3644 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3645 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3646 ref
->dtprel
= dtprel
;
3647 if (dwarf_split_debug_info
)
3648 ref
->dw_loc_oprnd1
.val_entry
3649 = add_addr_table_entry (addr
,
3650 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3652 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3657 /* Section names used to hold DWARF debugging information. */
3659 #ifndef DEBUG_INFO_SECTION
3660 #define DEBUG_INFO_SECTION ".debug_info"
3662 #ifndef DEBUG_DWO_INFO_SECTION
3663 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3665 #ifndef DEBUG_ABBREV_SECTION
3666 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3668 #ifndef DEBUG_DWO_ABBREV_SECTION
3669 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3671 #ifndef DEBUG_ARANGES_SECTION
3672 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3674 #ifndef DEBUG_ADDR_SECTION
3675 #define DEBUG_ADDR_SECTION ".debug_addr"
3677 #ifndef DEBUG_MACINFO_SECTION
3678 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3680 #ifndef DEBUG_DWO_MACINFO_SECTION
3681 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3683 #ifndef DEBUG_DWO_MACRO_SECTION
3684 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3686 #ifndef DEBUG_MACRO_SECTION
3687 #define DEBUG_MACRO_SECTION ".debug_macro"
3689 #ifndef DEBUG_LINE_SECTION
3690 #define DEBUG_LINE_SECTION ".debug_line"
3692 #ifndef DEBUG_DWO_LINE_SECTION
3693 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3695 #ifndef DEBUG_LOC_SECTION
3696 #define DEBUG_LOC_SECTION ".debug_loc"
3698 #ifndef DEBUG_DWO_LOC_SECTION
3699 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3701 #ifndef DEBUG_LOCLISTS_SECTION
3702 #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
3704 #ifndef DEBUG_DWO_LOCLISTS_SECTION
3705 #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
3707 #ifndef DEBUG_PUBNAMES_SECTION
3708 #define DEBUG_PUBNAMES_SECTION \
3709 ((debug_generate_pub_sections == 2) \
3710 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3712 #ifndef DEBUG_PUBTYPES_SECTION
3713 #define DEBUG_PUBTYPES_SECTION \
3714 ((debug_generate_pub_sections == 2) \
3715 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3717 #ifndef DEBUG_STR_OFFSETS_SECTION
3718 #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
3720 #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
3721 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3723 #ifndef DEBUG_STR_DWO_SECTION
3724 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3726 #ifndef DEBUG_STR_SECTION
3727 #define DEBUG_STR_SECTION ".debug_str"
3729 #ifndef DEBUG_RANGES_SECTION
3730 #define DEBUG_RANGES_SECTION ".debug_ranges"
3732 #ifndef DEBUG_RNGLISTS_SECTION
3733 #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
3735 #ifndef DEBUG_LINE_STR_SECTION
3736 #define DEBUG_LINE_STR_SECTION ".debug_line_str"
3739 /* Standard ELF section names for compiled code and data. */
3740 #ifndef TEXT_SECTION_NAME
3741 #define TEXT_SECTION_NAME ".text"
3744 /* Section flags for .debug_str section. */
3745 #define DEBUG_STR_SECTION_FLAGS \
3746 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3747 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3750 /* Section flags for .debug_str.dwo section. */
3751 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3753 /* Labels we insert at beginning sections we can reference instead of
3754 the section names themselves. */
3756 #ifndef TEXT_SECTION_LABEL
3757 #define TEXT_SECTION_LABEL "Ltext"
3759 #ifndef COLD_TEXT_SECTION_LABEL
3760 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3762 #ifndef DEBUG_LINE_SECTION_LABEL
3763 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3765 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3766 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3768 #ifndef DEBUG_INFO_SECTION_LABEL
3769 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3771 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3772 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3774 #ifndef DEBUG_ABBREV_SECTION_LABEL
3775 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3777 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3778 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3780 #ifndef DEBUG_ADDR_SECTION_LABEL
3781 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3783 #ifndef DEBUG_LOC_SECTION_LABEL
3784 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3786 #ifndef DEBUG_RANGES_SECTION_LABEL
3787 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3789 #ifndef DEBUG_MACINFO_SECTION_LABEL
3790 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3792 #ifndef DEBUG_MACRO_SECTION_LABEL
3793 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3795 #define SKELETON_COMP_DIE_ABBREV 1
3796 #define SKELETON_TYPE_DIE_ABBREV 2
3798 /* Definitions of defaults for formats and names of various special
3799 (artificial) labels which may be generated within this file (when the -g
3800 options is used and DWARF2_DEBUGGING_INFO is in effect.
3801 If necessary, these may be overridden from within the tm.h file, but
3802 typically, overriding these defaults is unnecessary. */
3804 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3805 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3806 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3807 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3808 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3809 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3810 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3811 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3812 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3813 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3814 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3815 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3816 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3817 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3818 static char ranges_base_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3820 #ifndef TEXT_END_LABEL
3821 #define TEXT_END_LABEL "Letext"
3823 #ifndef COLD_END_LABEL
3824 #define COLD_END_LABEL "Letext_cold"
3826 #ifndef BLOCK_BEGIN_LABEL
3827 #define BLOCK_BEGIN_LABEL "LBB"
3829 #ifndef BLOCK_END_LABEL
3830 #define BLOCK_END_LABEL "LBE"
3832 #ifndef LINE_CODE_LABEL
3833 #define LINE_CODE_LABEL "LM"
3837 /* Return the root of the DIE's built for the current compilation unit. */
3839 comp_unit_die (void)
3841 if (!single_comp_unit_die
)
3842 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3843 return single_comp_unit_die
;
3846 /* We allow a language front-end to designate a function that is to be
3847 called to "demangle" any name before it is put into a DIE. */
3849 static const char *(*demangle_name_func
) (const char *);
3852 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3854 demangle_name_func
= func
;
3857 /* Test if rtl node points to a pseudo register. */
3860 is_pseudo_reg (const_rtx rtl
)
3862 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3863 || (GET_CODE (rtl
) == SUBREG
3864 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3867 /* Return a reference to a type, with its const and volatile qualifiers
3871 type_main_variant (tree type
)
3873 type
= TYPE_MAIN_VARIANT (type
);
3875 /* ??? There really should be only one main variant among any group of
3876 variants of a given type (and all of the MAIN_VARIANT values for all
3877 members of the group should point to that one type) but sometimes the C
3878 front-end messes this up for array types, so we work around that bug
3880 if (TREE_CODE (type
) == ARRAY_TYPE
)
3881 while (type
!= TYPE_MAIN_VARIANT (type
))
3882 type
= TYPE_MAIN_VARIANT (type
);
3887 /* Return nonzero if the given type node represents a tagged type. */
3890 is_tagged_type (const_tree type
)
3892 enum tree_code code
= TREE_CODE (type
);
3894 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3895 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3898 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3901 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3903 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3906 /* Return die_offset of a DIE reference to a base type. */
3908 static unsigned long int
3909 get_base_type_offset (dw_die_ref ref
)
3911 if (ref
->die_offset
)
3912 return ref
->die_offset
;
3913 if (comp_unit_die ()->die_abbrev
)
3915 calc_base_type_die_sizes ();
3916 gcc_assert (ref
->die_offset
);
3918 return ref
->die_offset
;
3921 /* Return die_offset of a DIE reference other than base type. */
3923 static unsigned long int
3924 get_ref_die_offset (dw_die_ref ref
)
3926 gcc_assert (ref
->die_offset
);
3927 return ref
->die_offset
;
3930 /* Convert a DIE tag into its string name. */
3933 dwarf_tag_name (unsigned int tag
)
3935 const char *name
= get_DW_TAG_name (tag
);
3940 return "DW_TAG_<unknown>";
3943 /* Convert a DWARF attribute code into its string name. */
3946 dwarf_attr_name (unsigned int attr
)
3952 #if VMS_DEBUGGING_INFO
3953 case DW_AT_HP_prologue
:
3954 return "DW_AT_HP_prologue";
3956 case DW_AT_MIPS_loop_unroll_factor
:
3957 return "DW_AT_MIPS_loop_unroll_factor";
3960 #if VMS_DEBUGGING_INFO
3961 case DW_AT_HP_epilogue
:
3962 return "DW_AT_HP_epilogue";
3964 case DW_AT_MIPS_stride
:
3965 return "DW_AT_MIPS_stride";
3969 name
= get_DW_AT_name (attr
);
3974 return "DW_AT_<unknown>";
3977 /* Convert a DWARF value form code into its string name. */
3980 dwarf_form_name (unsigned int form
)
3982 const char *name
= get_DW_FORM_name (form
);
3987 return "DW_FORM_<unknown>";
3990 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3991 instance of an inlined instance of a decl which is local to an inline
3992 function, so we have to trace all of the way back through the origin chain
3993 to find out what sort of node actually served as the original seed for the
3997 decl_ultimate_origin (const_tree decl
)
3999 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4002 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4003 we're trying to output the abstract instance of this function. */
4004 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4007 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4008 most distant ancestor, this should never happen. */
4009 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4011 return DECL_ABSTRACT_ORIGIN (decl
);
4014 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4015 of a virtual function may refer to a base class, so we check the 'this'
4019 decl_class_context (tree decl
)
4021 tree context
= NULL_TREE
;
4023 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4024 context
= DECL_CONTEXT (decl
);
4026 context
= TYPE_MAIN_VARIANT
4027 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4029 if (context
&& !TYPE_P (context
))
4030 context
= NULL_TREE
;
4035 /* Add an attribute/value pair to a DIE. */
4038 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
4040 /* Maybe this should be an assert? */
4044 vec_safe_reserve (die
->die_attr
, 1);
4045 vec_safe_push (die
->die_attr
, *attr
);
4048 static inline enum dw_val_class
4049 AT_class (dw_attr_node
*a
)
4051 return a
->dw_attr_val
.val_class
;
4054 /* Return the index for any attribute that will be referenced with a
4055 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
4056 are stored in dw_attr_val.v.val_str for reference counting
4059 static inline unsigned int
4060 AT_index (dw_attr_node
*a
)
4062 if (AT_class (a
) == dw_val_class_str
)
4063 return a
->dw_attr_val
.v
.val_str
->index
;
4064 else if (a
->dw_attr_val
.val_entry
!= NULL
)
4065 return a
->dw_attr_val
.val_entry
->index
;
4069 /* Add a flag value attribute to a DIE. */
4072 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4076 attr
.dw_attr
= attr_kind
;
4077 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4078 attr
.dw_attr_val
.val_entry
= NULL
;
4079 attr
.dw_attr_val
.v
.val_flag
= flag
;
4080 add_dwarf_attr (die
, &attr
);
4083 static inline unsigned
4084 AT_flag (dw_attr_node
*a
)
4086 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4087 return a
->dw_attr_val
.v
.val_flag
;
4090 /* Add a signed integer attribute value to a DIE. */
4093 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4097 attr
.dw_attr
= attr_kind
;
4098 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4099 attr
.dw_attr_val
.val_entry
= NULL
;
4100 attr
.dw_attr_val
.v
.val_int
= int_val
;
4101 add_dwarf_attr (die
, &attr
);
4104 static inline HOST_WIDE_INT
4105 AT_int (dw_attr_node
*a
)
4107 gcc_assert (a
&& (AT_class (a
) == dw_val_class_const
4108 || AT_class (a
) == dw_val_class_const_implicit
));
4109 return a
->dw_attr_val
.v
.val_int
;
4112 /* Add an unsigned integer attribute value to a DIE. */
4115 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4116 unsigned HOST_WIDE_INT unsigned_val
)
4120 attr
.dw_attr
= attr_kind
;
4121 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4122 attr
.dw_attr_val
.val_entry
= NULL
;
4123 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4124 add_dwarf_attr (die
, &attr
);
4127 static inline unsigned HOST_WIDE_INT
4128 AT_unsigned (dw_attr_node
*a
)
4130 gcc_assert (a
&& (AT_class (a
) == dw_val_class_unsigned_const
4131 || AT_class (a
) == dw_val_class_unsigned_const_implicit
));
4132 return a
->dw_attr_val
.v
.val_unsigned
;
4135 /* Add an unsigned wide integer attribute value to a DIE. */
4138 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4143 attr
.dw_attr
= attr_kind
;
4144 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
4145 attr
.dw_attr_val
.val_entry
= NULL
;
4146 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
4147 *attr
.dw_attr_val
.v
.val_wide
= w
;
4148 add_dwarf_attr (die
, &attr
);
4151 /* Add an unsigned double integer attribute value to a DIE. */
4154 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4155 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4159 attr
.dw_attr
= attr_kind
;
4160 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4161 attr
.dw_attr_val
.val_entry
= NULL
;
4162 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4163 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4164 add_dwarf_attr (die
, &attr
);
4167 /* Add a floating point attribute value to a DIE and return it. */
4170 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4171 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4175 attr
.dw_attr
= attr_kind
;
4176 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4177 attr
.dw_attr_val
.val_entry
= NULL
;
4178 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4179 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4180 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4181 add_dwarf_attr (die
, &attr
);
4184 /* Add an 8-byte data attribute value to a DIE. */
4187 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4188 unsigned char data8
[8])
4192 attr
.dw_attr
= attr_kind
;
4193 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4194 attr
.dw_attr_val
.val_entry
= NULL
;
4195 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4196 add_dwarf_attr (die
, &attr
);
4199 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4200 dwarf_split_debug_info, address attributes in dies destined for the
4201 final executable have force_direct set to avoid using indexed
4205 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4211 lbl_id
= xstrdup (lbl_low
);
4212 attr
.dw_attr
= DW_AT_low_pc
;
4213 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4214 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4215 if (dwarf_split_debug_info
&& !force_direct
)
4216 attr
.dw_attr_val
.val_entry
4217 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4219 attr
.dw_attr_val
.val_entry
= NULL
;
4220 add_dwarf_attr (die
, &attr
);
4222 attr
.dw_attr
= DW_AT_high_pc
;
4223 if (dwarf_version
< 4)
4224 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4226 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4227 lbl_id
= xstrdup (lbl_high
);
4228 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4229 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4230 && dwarf_split_debug_info
&& !force_direct
)
4231 attr
.dw_attr_val
.val_entry
4232 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4234 attr
.dw_attr_val
.val_entry
= NULL
;
4235 add_dwarf_attr (die
, &attr
);
4238 /* Hash and equality functions for debug_str_hash. */
4241 indirect_string_hasher::hash (indirect_string_node
*x
)
4243 return htab_hash_string (x
->str
);
4247 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4249 return strcmp (x1
->str
, x2
) == 0;
4252 /* Add STR to the given string hash table. */
4254 static struct indirect_string_node
*
4255 find_AT_string_in_table (const char *str
,
4256 hash_table
<indirect_string_hasher
> *table
)
4258 struct indirect_string_node
*node
;
4260 indirect_string_node
**slot
4261 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
4264 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4265 node
->str
= ggc_strdup (str
);
4275 /* Add STR to the indirect string hash table. */
4277 static struct indirect_string_node
*
4278 find_AT_string (const char *str
)
4280 if (! debug_str_hash
)
4281 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4283 return find_AT_string_in_table (str
, debug_str_hash
);
4286 /* Add a string attribute value to a DIE. */
4289 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4292 struct indirect_string_node
*node
;
4294 node
= find_AT_string (str
);
4296 attr
.dw_attr
= attr_kind
;
4297 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4298 attr
.dw_attr_val
.val_entry
= NULL
;
4299 attr
.dw_attr_val
.v
.val_str
= node
;
4300 add_dwarf_attr (die
, &attr
);
4303 static inline const char *
4304 AT_string (dw_attr_node
*a
)
4306 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4307 return a
->dw_attr_val
.v
.val_str
->str
;
4310 /* Call this function directly to bypass AT_string_form's logic to put
4311 the string inline in the die. */
4314 set_indirect_string (struct indirect_string_node
*node
)
4316 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4317 /* Already indirect is a no op. */
4318 if (node
->form
== DW_FORM_strp
4319 || node
->form
== DW_FORM_line_strp
4320 || node
->form
== DW_FORM_GNU_str_index
)
4322 gcc_assert (node
->label
);
4325 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4326 ++dw2_string_counter
;
4327 node
->label
= xstrdup (label
);
4329 if (!dwarf_split_debug_info
)
4331 node
->form
= DW_FORM_strp
;
4332 node
->index
= NOT_INDEXED
;
4336 node
->form
= DW_FORM_GNU_str_index
;
4337 node
->index
= NO_INDEX_ASSIGNED
;
4341 /* Find out whether a string should be output inline in DIE
4342 or out-of-line in .debug_str section. */
4344 static enum dwarf_form
4345 find_string_form (struct indirect_string_node
*node
)
4352 len
= strlen (node
->str
) + 1;
4354 /* If the string is shorter or equal to the size of the reference, it is
4355 always better to put it inline. */
4356 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4357 return node
->form
= DW_FORM_string
;
4359 /* If we cannot expect the linker to merge strings in .debug_str
4360 section, only put it into .debug_str if it is worth even in this
4362 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4363 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4364 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4365 return node
->form
= DW_FORM_string
;
4367 set_indirect_string (node
);
4372 /* Find out whether the string referenced from the attribute should be
4373 output inline in DIE or out-of-line in .debug_str section. */
4375 static enum dwarf_form
4376 AT_string_form (dw_attr_node
*a
)
4378 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4379 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4382 /* Add a DIE reference attribute value to a DIE. */
4385 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4388 gcc_checking_assert (targ_die
!= NULL
);
4390 /* With LTO we can end up trying to reference something we didn't create
4391 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4392 if (targ_die
== NULL
)
4395 attr
.dw_attr
= attr_kind
;
4396 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4397 attr
.dw_attr_val
.val_entry
= NULL
;
4398 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4399 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4400 add_dwarf_attr (die
, &attr
);
4403 /* Change DIE reference REF to point to NEW_DIE instead. */
4406 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4408 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4409 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4410 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4413 /* Add an AT_specification attribute to a DIE, and also make the back
4414 pointer from the specification to the definition. */
4417 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4419 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4420 gcc_assert (!targ_die
->die_definition
);
4421 targ_die
->die_definition
= die
;
4424 static inline dw_die_ref
4425 AT_ref (dw_attr_node
*a
)
4427 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4428 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4432 AT_ref_external (dw_attr_node
*a
)
4434 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4435 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4441 set_AT_ref_external (dw_attr_node
*a
, int i
)
4443 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4444 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4447 /* Add an FDE reference attribute value to a DIE. */
4450 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4454 attr
.dw_attr
= attr_kind
;
4455 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4456 attr
.dw_attr_val
.val_entry
= NULL
;
4457 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4458 add_dwarf_attr (die
, &attr
);
4461 /* Add a location description attribute value to a DIE. */
4464 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4468 attr
.dw_attr
= attr_kind
;
4469 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4470 attr
.dw_attr_val
.val_entry
= NULL
;
4471 attr
.dw_attr_val
.v
.val_loc
= loc
;
4472 add_dwarf_attr (die
, &attr
);
4475 static inline dw_loc_descr_ref
4476 AT_loc (dw_attr_node
*a
)
4478 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4479 return a
->dw_attr_val
.v
.val_loc
;
4483 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4487 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4490 attr
.dw_attr
= attr_kind
;
4491 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4492 attr
.dw_attr_val
.val_entry
= NULL
;
4493 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4494 add_dwarf_attr (die
, &attr
);
4495 have_location_lists
= true;
4498 static inline dw_loc_list_ref
4499 AT_loc_list (dw_attr_node
*a
)
4501 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4502 return a
->dw_attr_val
.v
.val_loc_list
;
4505 static inline dw_loc_list_ref
*
4506 AT_loc_list_ptr (dw_attr_node
*a
)
4508 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4509 return &a
->dw_attr_val
.v
.val_loc_list
;
4512 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4514 static hashval_t
hash (addr_table_entry
*);
4515 static bool equal (addr_table_entry
*, addr_table_entry
*);
4518 /* Table of entries into the .debug_addr section. */
4520 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4522 /* Hash an address_table_entry. */
4525 addr_hasher::hash (addr_table_entry
*a
)
4527 inchash::hash hstate
;
4533 case ate_kind_rtx_dtprel
:
4536 case ate_kind_label
:
4537 return htab_hash_string (a
->addr
.label
);
4541 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4542 return hstate
.end ();
4545 /* Determine equality for two address_table_entries. */
4548 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4550 if (a1
->kind
!= a2
->kind
)
4555 case ate_kind_rtx_dtprel
:
4556 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4557 case ate_kind_label
:
4558 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4564 /* Initialize an addr_table_entry. */
4567 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4573 case ate_kind_rtx_dtprel
:
4574 e
->addr
.rtl
= (rtx
) addr
;
4576 case ate_kind_label
:
4577 e
->addr
.label
= (char *) addr
;
4581 e
->index
= NO_INDEX_ASSIGNED
;
4584 /* Add attr to the address table entry to the table. Defer setting an
4585 index until output time. */
4587 static addr_table_entry
*
4588 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4590 addr_table_entry
*node
;
4591 addr_table_entry finder
;
4593 gcc_assert (dwarf_split_debug_info
);
4594 if (! addr_index_table
)
4595 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4596 init_addr_table_entry (&finder
, kind
, addr
);
4597 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4599 if (*slot
== HTAB_EMPTY_ENTRY
)
4601 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4602 init_addr_table_entry (node
, kind
, addr
);
4612 /* Remove an entry from the addr table by decrementing its refcount.
4613 Strictly, decrementing the refcount would be enough, but the
4614 assertion that the entry is actually in the table has found
4618 remove_addr_table_entry (addr_table_entry
*entry
)
4620 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4621 /* After an index is assigned, the table is frozen. */
4622 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4626 /* Given a location list, remove all addresses it refers to from the
4630 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4632 for (; descr
; descr
= descr
->dw_loc_next
)
4633 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4635 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4636 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4640 /* A helper function for dwarf2out_finish called through
4641 htab_traverse. Assign an addr_table_entry its index. All entries
4642 must be collected into the table when this function is called,
4643 because the indexing code relies on htab_traverse to traverse nodes
4644 in the same order for each run. */
4647 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4649 addr_table_entry
*node
= *h
;
4651 /* Don't index unreferenced nodes. */
4652 if (node
->refcount
== 0)
4655 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4656 node
->index
= *index
;
4662 /* Add an address constant attribute value to a DIE. When using
4663 dwarf_split_debug_info, address attributes in dies destined for the
4664 final executable should be direct references--setting the parameter
4665 force_direct ensures this behavior. */
4668 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4673 attr
.dw_attr
= attr_kind
;
4674 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4675 attr
.dw_attr_val
.v
.val_addr
= addr
;
4676 if (dwarf_split_debug_info
&& !force_direct
)
4677 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4679 attr
.dw_attr_val
.val_entry
= NULL
;
4680 add_dwarf_attr (die
, &attr
);
4683 /* Get the RTX from to an address DIE attribute. */
4686 AT_addr (dw_attr_node
*a
)
4688 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4689 return a
->dw_attr_val
.v
.val_addr
;
4692 /* Add a file attribute value to a DIE. */
4695 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4696 struct dwarf_file_data
*fd
)
4700 attr
.dw_attr
= attr_kind
;
4701 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4702 attr
.dw_attr_val
.val_entry
= NULL
;
4703 attr
.dw_attr_val
.v
.val_file
= fd
;
4704 add_dwarf_attr (die
, &attr
);
4707 /* Get the dwarf_file_data from a file DIE attribute. */
4709 static inline struct dwarf_file_data
*
4710 AT_file (dw_attr_node
*a
)
4712 gcc_assert (a
&& (AT_class (a
) == dw_val_class_file
4713 || AT_class (a
) == dw_val_class_file_implicit
));
4714 return a
->dw_attr_val
.v
.val_file
;
4717 /* Add a vms delta attribute value to a DIE. */
4720 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4721 const char *lbl1
, const char *lbl2
)
4725 attr
.dw_attr
= attr_kind
;
4726 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4727 attr
.dw_attr_val
.val_entry
= NULL
;
4728 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4729 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4730 add_dwarf_attr (die
, &attr
);
4733 /* Add a label identifier attribute value to a DIE. */
4736 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4741 attr
.dw_attr
= attr_kind
;
4742 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4743 attr
.dw_attr_val
.val_entry
= NULL
;
4744 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4745 if (dwarf_split_debug_info
)
4746 attr
.dw_attr_val
.val_entry
4747 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4749 add_dwarf_attr (die
, &attr
);
4752 /* Add a section offset attribute value to a DIE, an offset into the
4753 debug_line section. */
4756 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4761 attr
.dw_attr
= attr_kind
;
4762 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4763 attr
.dw_attr_val
.val_entry
= NULL
;
4764 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4765 add_dwarf_attr (die
, &attr
);
4768 /* Add a section offset attribute value to a DIE, an offset into the
4769 debug_loclists section. */
4772 add_AT_loclistsptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4777 attr
.dw_attr
= attr_kind
;
4778 attr
.dw_attr_val
.val_class
= dw_val_class_loclistsptr
;
4779 attr
.dw_attr_val
.val_entry
= NULL
;
4780 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4781 add_dwarf_attr (die
, &attr
);
4784 /* Add a section offset attribute value to a DIE, an offset into the
4785 debug_macinfo section. */
4788 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4793 attr
.dw_attr
= attr_kind
;
4794 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4795 attr
.dw_attr_val
.val_entry
= NULL
;
4796 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4797 add_dwarf_attr (die
, &attr
);
4800 /* Add an offset attribute value to a DIE. */
4803 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4804 unsigned HOST_WIDE_INT offset
)
4808 attr
.dw_attr
= attr_kind
;
4809 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4810 attr
.dw_attr_val
.val_entry
= NULL
;
4811 attr
.dw_attr_val
.v
.val_offset
= offset
;
4812 add_dwarf_attr (die
, &attr
);
4815 /* Add a range_list attribute value to a DIE. When using
4816 dwarf_split_debug_info, address attributes in dies destined for the
4817 final executable should be direct references--setting the parameter
4818 force_direct ensures this behavior. */
4820 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4821 #define RELOCATED_OFFSET (NULL)
4824 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4825 long unsigned int offset
, bool force_direct
)
4829 attr
.dw_attr
= attr_kind
;
4830 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4831 /* For the range_list attribute, use val_entry to store whether the
4832 offset should follow split-debug-info or normal semantics. This
4833 value is read in output_range_list_offset. */
4834 if (dwarf_split_debug_info
&& !force_direct
)
4835 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4837 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4838 attr
.dw_attr_val
.v
.val_offset
= offset
;
4839 add_dwarf_attr (die
, &attr
);
4842 /* Return the start label of a delta attribute. */
4844 static inline const char *
4845 AT_vms_delta1 (dw_attr_node
*a
)
4847 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4848 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4851 /* Return the end label of a delta attribute. */
4853 static inline const char *
4854 AT_vms_delta2 (dw_attr_node
*a
)
4856 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4857 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4860 static inline const char *
4861 AT_lbl (dw_attr_node
*a
)
4863 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4864 || AT_class (a
) == dw_val_class_lineptr
4865 || AT_class (a
) == dw_val_class_macptr
4866 || AT_class (a
) == dw_val_class_loclistsptr
4867 || AT_class (a
) == dw_val_class_high_pc
));
4868 return a
->dw_attr_val
.v
.val_lbl_id
;
4871 /* Get the attribute of type attr_kind. */
4873 static dw_attr_node
*
4874 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4878 dw_die_ref spec
= NULL
;
4883 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4884 if (a
->dw_attr
== attr_kind
)
4886 else if (a
->dw_attr
== DW_AT_specification
4887 || a
->dw_attr
== DW_AT_abstract_origin
)
4891 return get_AT (spec
, attr_kind
);
4896 /* Returns the parent of the declaration of DIE. */
4899 get_die_parent (dw_die_ref die
)
4906 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4907 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4910 return die
->die_parent
;
4913 /* Return the "low pc" attribute value, typically associated with a subprogram
4914 DIE. Return null if the "low pc" attribute is either not present, or if it
4915 cannot be represented as an assembler label identifier. */
4917 static inline const char *
4918 get_AT_low_pc (dw_die_ref die
)
4920 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
4922 return a
? AT_lbl (a
) : NULL
;
4925 /* Return the "high pc" attribute value, typically associated with a subprogram
4926 DIE. Return null if the "high pc" attribute is either not present, or if it
4927 cannot be represented as an assembler label identifier. */
4929 static inline const char *
4930 get_AT_hi_pc (dw_die_ref die
)
4932 dw_attr_node
*a
= get_AT (die
, DW_AT_high_pc
);
4934 return a
? AT_lbl (a
) : NULL
;
4937 /* Return the value of the string attribute designated by ATTR_KIND, or
4938 NULL if it is not present. */
4940 static inline const char *
4941 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4943 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4945 return a
? AT_string (a
) : NULL
;
4948 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4949 if it is not present. */
4952 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4954 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4956 return a
? AT_flag (a
) : 0;
4959 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4960 if it is not present. */
4962 static inline unsigned
4963 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4965 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4967 return a
? AT_unsigned (a
) : 0;
4970 static inline dw_die_ref
4971 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4973 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4975 return a
? AT_ref (a
) : NULL
;
4978 static inline struct dwarf_file_data
*
4979 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4981 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4983 return a
? AT_file (a
) : NULL
;
4986 /* Return TRUE if the language is C++. */
4991 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4993 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
4994 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
4997 /* Return TRUE if DECL was created by the C++ frontend. */
5000 is_cxx (const_tree decl
)
5004 const_tree context
= decl
;
5005 while (context
&& TREE_CODE (context
) != TRANSLATION_UNIT_DECL
)
5007 if (TREE_CODE (context
) == BLOCK
)
5008 context
= BLOCK_SUPERCONTEXT (context
);
5010 context
= get_containing_scope (context
);
5012 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5013 return strncmp (TRANSLATION_UNIT_LANGUAGE (context
), "GNU C++", 7) == 0;
5018 /* Return TRUE if the language is Java. */
5023 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5025 return lang
== DW_LANG_Java
;
5028 /* Return TRUE if the language is Fortran. */
5033 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5035 return (lang
== DW_LANG_Fortran77
5036 || lang
== DW_LANG_Fortran90
5037 || lang
== DW_LANG_Fortran95
5038 || lang
== DW_LANG_Fortran03
5039 || lang
== DW_LANG_Fortran08
);
5042 /* Return TRUE if the language is Ada. */
5047 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5049 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5052 /* Remove the specified attribute if present. Return TRUE if removal
5056 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5064 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5065 if (a
->dw_attr
== attr_kind
)
5067 if (AT_class (a
) == dw_val_class_str
)
5068 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5069 a
->dw_attr_val
.v
.val_str
->refcount
--;
5071 /* vec::ordered_remove should help reduce the number of abbrevs
5073 die
->die_attr
->ordered_remove (ix
);
5079 /* Remove CHILD from its parent. PREV must have the property that
5080 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5083 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5085 gcc_assert (child
->die_parent
== prev
->die_parent
);
5086 gcc_assert (prev
->die_sib
== child
);
5089 gcc_assert (child
->die_parent
->die_child
== child
);
5093 prev
->die_sib
= child
->die_sib
;
5094 if (child
->die_parent
->die_child
== child
)
5095 child
->die_parent
->die_child
= prev
;
5096 child
->die_sib
= NULL
;
5099 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5100 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5103 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
5105 dw_die_ref parent
= old_child
->die_parent
;
5107 gcc_assert (parent
== prev
->die_parent
);
5108 gcc_assert (prev
->die_sib
== old_child
);
5110 new_child
->die_parent
= parent
;
5111 if (prev
== old_child
)
5113 gcc_assert (parent
->die_child
== old_child
);
5114 new_child
->die_sib
= new_child
;
5118 prev
->die_sib
= new_child
;
5119 new_child
->die_sib
= old_child
->die_sib
;
5121 if (old_child
->die_parent
->die_child
== old_child
)
5122 old_child
->die_parent
->die_child
= new_child
;
5123 old_child
->die_sib
= NULL
;
5126 /* Move all children from OLD_PARENT to NEW_PARENT. */
5129 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
5132 new_parent
->die_child
= old_parent
->die_child
;
5133 old_parent
->die_child
= NULL
;
5134 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
5137 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5141 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5147 dw_die_ref prev
= c
;
5149 while (c
->die_tag
== tag
)
5151 remove_child_with_prev (c
, prev
);
5152 c
->die_parent
= NULL
;
5153 /* Might have removed every child. */
5154 if (die
->die_child
== NULL
)
5158 } while (c
!= die
->die_child
);
5161 /* Add a CHILD_DIE as the last child of DIE. */
5164 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5166 /* FIXME this should probably be an assert. */
5167 if (! die
|| ! child_die
)
5169 gcc_assert (die
!= child_die
);
5171 child_die
->die_parent
= die
;
5174 child_die
->die_sib
= die
->die_child
->die_sib
;
5175 die
->die_child
->die_sib
= child_die
;
5178 child_die
->die_sib
= child_die
;
5179 die
->die_child
= child_die
;
5182 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5185 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
5186 dw_die_ref after_die
)
5192 && die
!= child_die
);
5194 child_die
->die_parent
= die
;
5195 child_die
->die_sib
= after_die
->die_sib
;
5196 after_die
->die_sib
= child_die
;
5197 if (die
->die_child
== after_die
)
5198 die
->die_child
= child_die
;
5201 /* Unassociate CHILD from its parent, and make its parent be
5205 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
5207 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5208 if (p
->die_sib
== child
)
5210 remove_child_with_prev (child
, p
);
5213 add_child_die (new_parent
, child
);
5216 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5217 is the specification, to the end of PARENT's list of children.
5218 This is done by removing and re-adding it. */
5221 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5223 /* We want the declaration DIE from inside the class, not the
5224 specification DIE at toplevel. */
5225 if (child
->die_parent
!= parent
)
5227 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5233 gcc_assert (child
->die_parent
== parent
5234 || (child
->die_parent
5235 == get_AT_ref (parent
, DW_AT_specification
)));
5237 reparent_child (child
, parent
);
5240 /* Create and return a new die with a parent of PARENT_DIE. If
5241 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5242 associated tree T must be supplied to determine parenthood
5245 static inline dw_die_ref
5246 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5248 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5250 die
->die_tag
= tag_value
;
5252 if (parent_die
!= NULL
)
5253 add_child_die (parent_die
, die
);
5256 limbo_die_node
*limbo_node
;
5258 /* No DIEs created after early dwarf should end up in limbo,
5259 because the limbo list should not persist past LTO
5261 if (tag_value
!= DW_TAG_compile_unit
5262 /* These are allowed because they're generated while
5263 breaking out COMDAT units late. */
5264 && tag_value
!= DW_TAG_type_unit
5265 && tag_value
!= DW_TAG_skeleton_unit
5267 /* Allow nested functions to live in limbo because they will
5268 only temporarily live there, as decls_for_scope will fix
5270 && (TREE_CODE (t
) != FUNCTION_DECL
5271 || !decl_function_context (t
))
5272 /* Same as nested functions above but for types. Types that
5273 are local to a function will be fixed in
5275 && (!RECORD_OR_UNION_TYPE_P (t
)
5276 || !TYPE_CONTEXT (t
)
5277 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5278 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5279 especially in the ltrans stage, but once we implement LTO
5280 dwarf streaming, we should remove this exception. */
5283 fprintf (stderr
, "symbol ended up in limbo too late:");
5284 debug_generic_stmt (t
);
5288 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5289 limbo_node
->die
= die
;
5290 limbo_node
->created_for
= t
;
5291 limbo_node
->next
= limbo_die_list
;
5292 limbo_die_list
= limbo_node
;
5298 /* Return the DIE associated with the given type specifier. */
5300 static inline dw_die_ref
5301 lookup_type_die (tree type
)
5303 dw_die_ref die
= TYPE_SYMTAB_DIE (type
);
5304 if (die
&& die
->removed
)
5306 TYPE_SYMTAB_DIE (type
) = NULL
;
5312 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5313 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5314 anonymous type instead the one of the naming typedef. */
5316 static inline dw_die_ref
5317 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5320 && TREE_CODE (type
) == RECORD_TYPE
5322 && type_die
->die_tag
== DW_TAG_typedef
5323 && is_naming_typedef_decl (TYPE_NAME (type
)))
5324 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5328 /* Like lookup_type_die, but if type is an anonymous type named by a
5329 typedef[1], return the DIE of the anonymous type instead the one of
5330 the naming typedef. This is because in gen_typedef_die, we did
5331 equate the anonymous struct named by the typedef with the DIE of
5332 the naming typedef. So by default, lookup_type_die on an anonymous
5333 struct yields the DIE of the naming typedef.
5335 [1]: Read the comment of is_naming_typedef_decl to learn about what
5336 a naming typedef is. */
5338 static inline dw_die_ref
5339 lookup_type_die_strip_naming_typedef (tree type
)
5341 dw_die_ref die
= lookup_type_die (type
);
5342 return strip_naming_typedef (type
, die
);
5345 /* Equate a DIE to a given type specifier. */
5348 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5350 TYPE_SYMTAB_DIE (type
) = type_die
;
5353 /* Returns a hash value for X (which really is a die_struct). */
5356 decl_die_hasher::hash (die_node
*x
)
5358 return (hashval_t
) x
->decl_id
;
5361 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5364 decl_die_hasher::equal (die_node
*x
, tree y
)
5366 return (x
->decl_id
== DECL_UID (y
));
5369 /* Return the DIE associated with a given declaration. */
5371 static inline dw_die_ref
5372 lookup_decl_die (tree decl
)
5374 dw_die_ref
*die
= decl_die_table
->find_slot_with_hash (decl
, DECL_UID (decl
),
5378 if ((*die
)->removed
)
5380 decl_die_table
->clear_slot (die
);
5386 /* Returns a hash value for X (which really is a var_loc_list). */
5389 decl_loc_hasher::hash (var_loc_list
*x
)
5391 return (hashval_t
) x
->decl_id
;
5394 /* Return nonzero if decl_id of var_loc_list X is the same as
5398 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5400 return (x
->decl_id
== DECL_UID (y
));
5403 /* Return the var_loc list associated with a given declaration. */
5405 static inline var_loc_list
*
5406 lookup_decl_loc (const_tree decl
)
5408 if (!decl_loc_table
)
5410 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5413 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5416 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5418 return (hashval_t
) x
->decl_id
;
5421 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5425 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5427 return (x
->decl_id
== DECL_UID (y
));
5430 /* Equate a DIE to a particular declaration. */
5433 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5435 unsigned int decl_id
= DECL_UID (decl
);
5437 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5438 decl_die
->decl_id
= decl_id
;
5441 /* Return how many bits covers PIECE EXPR_LIST. */
5443 static HOST_WIDE_INT
5444 decl_piece_bitsize (rtx piece
)
5446 int ret
= (int) GET_MODE (piece
);
5449 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5450 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5451 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5454 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5457 decl_piece_varloc_ptr (rtx piece
)
5459 if ((int) GET_MODE (piece
))
5460 return &XEXP (piece
, 0);
5462 return &XEXP (XEXP (piece
, 0), 1);
5465 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5466 Next is the chain of following piece nodes. */
5468 static rtx_expr_list
*
5469 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5471 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5472 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5474 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5479 /* Return rtx that should be stored into loc field for
5480 LOC_NOTE and BITPOS/BITSIZE. */
5483 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5484 HOST_WIDE_INT bitsize
)
5488 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5490 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5495 /* This function either modifies location piece list *DEST in
5496 place (if SRC and INNER is NULL), or copies location piece list
5497 *SRC to *DEST while modifying it. Location BITPOS is modified
5498 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5499 not copied and if needed some padding around it is added.
5500 When modifying in place, DEST should point to EXPR_LIST where
5501 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5502 to the start of the whole list and INNER points to the EXPR_LIST
5503 where earlier pieces cover PIECE_BITPOS bits. */
5506 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5507 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5508 HOST_WIDE_INT bitsize
, rtx loc_note
)
5511 bool copy
= inner
!= NULL
;
5515 /* First copy all nodes preceding the current bitpos. */
5516 while (src
!= inner
)
5518 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5519 decl_piece_bitsize (*src
), NULL_RTX
);
5520 dest
= &XEXP (*dest
, 1);
5521 src
= &XEXP (*src
, 1);
5524 /* Add padding if needed. */
5525 if (bitpos
!= piece_bitpos
)
5527 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5528 copy
? NULL_RTX
: *dest
);
5529 dest
= &XEXP (*dest
, 1);
5531 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5534 /* A piece with correct bitpos and bitsize already exist,
5535 just update the location for it and return. */
5536 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5539 /* Add the piece that changed. */
5540 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5541 dest
= &XEXP (*dest
, 1);
5542 /* Skip over pieces that overlap it. */
5543 diff
= bitpos
- piece_bitpos
+ bitsize
;
5546 while (diff
> 0 && *src
)
5549 diff
-= decl_piece_bitsize (piece
);
5551 src
= &XEXP (piece
, 1);
5554 *src
= XEXP (piece
, 1);
5555 free_EXPR_LIST_node (piece
);
5558 /* Add padding if needed. */
5559 if (diff
< 0 && *src
)
5563 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5564 dest
= &XEXP (*dest
, 1);
5568 /* Finally copy all nodes following it. */
5571 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5572 decl_piece_bitsize (*src
), NULL_RTX
);
5573 dest
= &XEXP (*dest
, 1);
5574 src
= &XEXP (*src
, 1);
5578 /* Add a variable location node to the linked list for DECL. */
5580 static struct var_loc_node
*
5581 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5583 unsigned int decl_id
;
5585 struct var_loc_node
*loc
= NULL
;
5586 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5588 if (VAR_P (decl
) && DECL_HAS_DEBUG_EXPR_P (decl
))
5590 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5591 if (handled_component_p (realdecl
)
5592 || (TREE_CODE (realdecl
) == MEM_REF
5593 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5595 HOST_WIDE_INT maxsize
;
5598 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
,
5600 if (!DECL_P (innerdecl
)
5601 || DECL_IGNORED_P (innerdecl
)
5602 || TREE_STATIC (innerdecl
)
5604 || bitpos
+ bitsize
> 256
5605 || bitsize
!= maxsize
)
5611 decl_id
= DECL_UID (decl
);
5613 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5616 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5617 temp
->decl_id
= decl_id
;
5623 /* For PARM_DECLs try to keep around the original incoming value,
5624 even if that means we'll emit a zero-range .debug_loc entry. */
5626 && temp
->first
== temp
->last
5627 && TREE_CODE (decl
) == PARM_DECL
5628 && NOTE_P (temp
->first
->loc
)
5629 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5630 && DECL_INCOMING_RTL (decl
)
5631 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5632 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5633 == GET_CODE (DECL_INCOMING_RTL (decl
))
5634 && prev_real_insn (as_a
<rtx_insn
*> (temp
->first
->loc
)) == NULL_RTX
5636 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5637 NOTE_VAR_LOCATION_LOC (loc_note
))
5638 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5639 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5641 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5642 temp
->first
->next
= loc
;
5644 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5646 else if (temp
->last
)
5648 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5649 rtx
*piece_loc
= NULL
, last_loc_note
;
5650 HOST_WIDE_INT piece_bitpos
= 0;
5654 gcc_assert (last
->next
== NULL
);
5656 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5658 piece_loc
= &last
->loc
;
5661 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5662 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5664 piece_bitpos
+= cur_bitsize
;
5665 piece_loc
= &XEXP (*piece_loc
, 1);
5669 /* TEMP->LAST here is either pointer to the last but one or
5670 last element in the chained list, LAST is pointer to the
5672 if (label
&& strcmp (last
->label
, label
) == 0)
5674 /* For SRA optimized variables if there weren't any real
5675 insns since last note, just modify the last node. */
5676 if (piece_loc
!= NULL
)
5678 adjust_piece_list (piece_loc
, NULL
, NULL
,
5679 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5682 /* If the last note doesn't cover any instructions, remove it. */
5683 if (temp
->last
!= last
)
5685 temp
->last
->next
= NULL
;
5688 gcc_assert (strcmp (last
->label
, label
) != 0);
5692 gcc_assert (temp
->first
== temp
->last
5693 || (temp
->first
->next
== temp
->last
5694 && TREE_CODE (decl
) == PARM_DECL
));
5695 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5696 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5700 if (bitsize
== -1 && NOTE_P (last
->loc
))
5701 last_loc_note
= last
->loc
;
5702 else if (piece_loc
!= NULL
5703 && *piece_loc
!= NULL_RTX
5704 && piece_bitpos
== bitpos
5705 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5706 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5708 last_loc_note
= NULL_RTX
;
5709 /* If the current location is the same as the end of the list,
5710 and either both or neither of the locations is uninitialized,
5711 we have nothing to do. */
5712 if (last_loc_note
== NULL_RTX
5713 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5714 NOTE_VAR_LOCATION_LOC (loc_note
)))
5715 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5716 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5717 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5718 == VAR_INIT_STATUS_UNINITIALIZED
)
5719 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5720 == VAR_INIT_STATUS_UNINITIALIZED
))))
5722 /* Add LOC to the end of list and update LAST. If the last
5723 element of the list has been removed above, reuse its
5724 memory for the new node, otherwise allocate a new one. */
5728 memset (loc
, '\0', sizeof (*loc
));
5731 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5732 if (bitsize
== -1 || piece_loc
== NULL
)
5733 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5735 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5736 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5738 /* Ensure TEMP->LAST will point either to the new last but one
5739 element of the chain, or to the last element in it. */
5740 if (last
!= temp
->last
)
5748 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5751 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5756 /* Keep track of the number of spaces used to indent the
5757 output of the debugging routines that print the structure of
5758 the DIE internal representation. */
5759 static int print_indent
;
5761 /* Indent the line the number of spaces given by print_indent. */
5764 print_spaces (FILE *outfile
)
5766 fprintf (outfile
, "%*s", print_indent
, "");
5769 /* Print a type signature in hex. */
5772 print_signature (FILE *outfile
, char *sig
)
5776 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5777 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5781 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
5783 if (discr_value
->pos
)
5784 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
5786 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
5789 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
5791 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5792 RECURSE, output location descriptor operations. */
5795 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
5797 switch (val
->val_class
)
5799 case dw_val_class_addr
:
5800 fprintf (outfile
, "address");
5802 case dw_val_class_offset
:
5803 fprintf (outfile
, "offset");
5805 case dw_val_class_loc
:
5806 fprintf (outfile
, "location descriptor");
5807 if (val
->v
.val_loc
== NULL
)
5808 fprintf (outfile
, " -> <null>\n");
5811 fprintf (outfile
, ":\n");
5813 print_loc_descr (val
->v
.val_loc
, outfile
);
5817 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
5819 case dw_val_class_loc_list
:
5820 fprintf (outfile
, "location list -> label:%s",
5821 val
->v
.val_loc_list
->ll_symbol
);
5823 case dw_val_class_range_list
:
5824 fprintf (outfile
, "range list");
5826 case dw_val_class_const
:
5827 case dw_val_class_const_implicit
:
5828 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
5830 case dw_val_class_unsigned_const
:
5831 case dw_val_class_unsigned_const_implicit
:
5832 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
5834 case dw_val_class_const_double
:
5835 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
5836 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5837 val
->v
.val_double
.high
,
5838 val
->v
.val_double
.low
);
5840 case dw_val_class_wide_int
:
5842 int i
= val
->v
.val_wide
->get_len ();
5843 fprintf (outfile
, "constant (");
5845 if (val
->v
.val_wide
->elt (i
- 1) == 0)
5846 fprintf (outfile
, "0x");
5847 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5848 val
->v
.val_wide
->elt (--i
));
5850 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5851 val
->v
.val_wide
->elt (i
));
5852 fprintf (outfile
, ")");
5855 case dw_val_class_vec
:
5856 fprintf (outfile
, "floating-point or vector constant");
5858 case dw_val_class_flag
:
5859 fprintf (outfile
, "%u", val
->v
.val_flag
);
5861 case dw_val_class_die_ref
:
5862 if (val
->v
.val_die_ref
.die
!= NULL
)
5864 dw_die_ref die
= val
->v
.val_die_ref
.die
;
5866 if (die
->comdat_type_p
)
5868 fprintf (outfile
, "die -> signature: ");
5869 print_signature (outfile
,
5870 die
->die_id
.die_type_node
->signature
);
5872 else if (die
->die_id
.die_symbol
)
5873 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
5875 fprintf (outfile
, "die -> %ld", die
->die_offset
);
5876 fprintf (outfile
, " (%p)", (void *) die
);
5879 fprintf (outfile
, "die -> <null>");
5881 case dw_val_class_vms_delta
:
5882 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5883 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
5885 case dw_val_class_lbl_id
:
5886 case dw_val_class_lineptr
:
5887 case dw_val_class_macptr
:
5888 case dw_val_class_loclistsptr
:
5889 case dw_val_class_high_pc
:
5890 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
5892 case dw_val_class_str
:
5893 if (val
->v
.val_str
->str
!= NULL
)
5894 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
5896 fprintf (outfile
, "<null>");
5898 case dw_val_class_file
:
5899 case dw_val_class_file_implicit
:
5900 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
5901 val
->v
.val_file
->emitted_number
);
5903 case dw_val_class_data8
:
5907 for (i
= 0; i
< 8; i
++)
5908 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
5911 case dw_val_class_discr_value
:
5912 print_discr_value (outfile
, &val
->v
.val_discr_value
);
5914 case dw_val_class_discr_list
:
5915 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
5917 node
= node
->dw_discr_next
)
5919 if (node
->dw_discr_range
)
5921 fprintf (outfile
, " .. ");
5922 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5923 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
5926 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5928 if (node
->dw_discr_next
!= NULL
)
5929 fprintf (outfile
, " | ");
5936 /* Likewise, for a DIE attribute. */
5939 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
5941 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
5945 /* Print the list of operands in the LOC location description to OUTFILE. This
5946 routine is a debugging aid only. */
5949 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
5951 dw_loc_descr_ref l
= loc
;
5955 print_spaces (outfile
);
5956 fprintf (outfile
, "<null>\n");
5960 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5962 print_spaces (outfile
);
5963 fprintf (outfile
, "(%p) %s",
5965 dwarf_stack_op_name (l
->dw_loc_opc
));
5966 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
5968 fprintf (outfile
, " ");
5969 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
5971 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
5973 fprintf (outfile
, ", ");
5974 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
5976 fprintf (outfile
, "\n");
5980 /* Print the information associated with a given DIE, and its children.
5981 This routine is a debugging aid only. */
5984 print_die (dw_die_ref die
, FILE *outfile
)
5990 print_spaces (outfile
);
5991 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5992 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5994 print_spaces (outfile
);
5995 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5996 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5997 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5999 if (die
->comdat_type_p
)
6001 print_spaces (outfile
);
6002 fprintf (outfile
, " signature: ");
6003 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
6004 fprintf (outfile
, "\n");
6007 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6009 print_spaces (outfile
);
6010 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6012 print_attribute (a
, true, outfile
);
6013 fprintf (outfile
, "\n");
6016 if (die
->die_child
!= NULL
)
6019 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6022 if (print_indent
== 0)
6023 fprintf (outfile
, "\n");
6026 /* Print the list of operations in the LOC location description. */
6029 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
6031 print_loc_descr (loc
, stderr
);
6034 /* Print the information collected for a given DIE. */
6037 debug_dwarf_die (dw_die_ref die
)
6039 print_die (die
, stderr
);
6043 debug (die_struct
&ref
)
6045 print_die (&ref
, stderr
);
6049 debug (die_struct
*ptr
)
6054 fprintf (stderr
, "<nil>\n");
6058 /* Print all DWARF information collected for the compilation unit.
6059 This routine is a debugging aid only. */
6065 print_die (comp_unit_die (), stderr
);
6068 /* Verify the DIE tree structure. */
6071 verify_die (dw_die_ref die
)
6073 gcc_assert (!die
->die_mark
);
6074 if (die
->die_parent
== NULL
6075 && die
->die_sib
== NULL
)
6077 /* Verify the die_sib list is cyclic. */
6084 while (x
&& !x
->die_mark
);
6085 gcc_assert (x
== die
);
6089 /* Verify all dies have the same parent. */
6090 gcc_assert (x
->die_parent
== die
->die_parent
);
6093 /* Verify the child has the proper parent and recurse. */
6094 gcc_assert (x
->die_child
->die_parent
== x
);
6095 verify_die (x
->die_child
);
6100 while (x
&& x
->die_mark
);
6103 /* Sanity checks on DIEs. */
6106 check_die (dw_die_ref die
)
6110 bool inline_found
= false;
6111 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
6112 int n_decl_line
= 0, n_decl_file
= 0;
6113 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6118 if (a
->dw_attr_val
.v
.val_unsigned
)
6119 inline_found
= true;
6121 case DW_AT_location
:
6130 case DW_AT_artificial
:
6133 case DW_AT_decl_line
:
6136 case DW_AT_decl_file
:
6143 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
6144 || n_decl_line
> 1 || n_decl_file
> 1)
6146 fprintf (stderr
, "Duplicate attributes in DIE:\n");
6147 debug_dwarf_die (die
);
6152 /* A debugging information entry that is a member of an abstract
6153 instance tree [that has DW_AT_inline] should not contain any
6154 attributes which describe aspects of the subroutine which vary
6155 between distinct inlined expansions or distinct out-of-line
6157 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6158 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
6159 && a
->dw_attr
!= DW_AT_high_pc
6160 && a
->dw_attr
!= DW_AT_location
6161 && a
->dw_attr
!= DW_AT_frame_base
6162 && a
->dw_attr
!= DW_AT_call_all_calls
6163 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
6167 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6168 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6169 DIE that marks the start of the DIEs for this include file. */
6172 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
6174 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
6175 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
6177 new_unit
->die_sib
= old_unit
;
6181 /* Close an include-file CU and reopen the enclosing one. */
6184 pop_compile_unit (dw_die_ref old_unit
)
6186 dw_die_ref new_unit
= old_unit
->die_sib
;
6188 old_unit
->die_sib
= NULL
;
6192 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6193 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6194 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6196 /* Calculate the checksum of a location expression. */
6199 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6202 inchash::hash hstate
;
6205 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
6207 hash_loc_operands (loc
, hstate
);
6208 hash
= hstate
.end();
6212 /* Calculate the checksum of an attribute. */
6215 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
6217 dw_loc_descr_ref loc
;
6220 CHECKSUM (at
->dw_attr
);
6222 /* We don't care that this was compiled with a different compiler
6223 snapshot; if the output is the same, that's what matters. */
6224 if (at
->dw_attr
== DW_AT_producer
)
6227 switch (AT_class (at
))
6229 case dw_val_class_const
:
6230 case dw_val_class_const_implicit
:
6231 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
6233 case dw_val_class_unsigned_const
:
6234 case dw_val_class_unsigned_const_implicit
:
6235 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
6237 case dw_val_class_const_double
:
6238 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6240 case dw_val_class_wide_int
:
6241 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6242 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6243 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6245 case dw_val_class_vec
:
6246 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6247 (at
->dw_attr_val
.v
.val_vec
.length
6248 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6250 case dw_val_class_flag
:
6251 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
6253 case dw_val_class_str
:
6254 CHECKSUM_STRING (AT_string (at
));
6257 case dw_val_class_addr
:
6259 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6260 CHECKSUM_STRING (XSTR (r
, 0));
6263 case dw_val_class_offset
:
6264 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6267 case dw_val_class_loc
:
6268 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6269 loc_checksum (loc
, ctx
);
6272 case dw_val_class_die_ref
:
6273 die_checksum (AT_ref (at
), ctx
, mark
);
6276 case dw_val_class_fde_ref
:
6277 case dw_val_class_vms_delta
:
6278 case dw_val_class_lbl_id
:
6279 case dw_val_class_lineptr
:
6280 case dw_val_class_macptr
:
6281 case dw_val_class_loclistsptr
:
6282 case dw_val_class_high_pc
:
6285 case dw_val_class_file
:
6286 case dw_val_class_file_implicit
:
6287 CHECKSUM_STRING (AT_file (at
)->filename
);
6290 case dw_val_class_data8
:
6291 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6299 /* Calculate the checksum of a DIE. */
6302 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6308 /* To avoid infinite recursion. */
6311 CHECKSUM (die
->die_mark
);
6314 die
->die_mark
= ++(*mark
);
6316 CHECKSUM (die
->die_tag
);
6318 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6319 attr_checksum (a
, ctx
, mark
);
6321 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6325 #undef CHECKSUM_BLOCK
6326 #undef CHECKSUM_STRING
6328 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6329 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6330 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6331 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6332 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6333 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6334 #define CHECKSUM_ATTR(FOO) \
6335 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6337 /* Calculate the checksum of a number in signed LEB128 format. */
6340 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6347 byte
= (value
& 0x7f);
6349 more
= !((value
== 0 && (byte
& 0x40) == 0)
6350 || (value
== -1 && (byte
& 0x40) != 0));
6359 /* Calculate the checksum of a number in unsigned LEB128 format. */
6362 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6366 unsigned char byte
= (value
& 0x7f);
6369 /* More bytes to follow. */
6377 /* Checksum the context of the DIE. This adds the names of any
6378 surrounding namespaces or structures to the checksum. */
6381 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
6385 int tag
= die
->die_tag
;
6387 if (tag
!= DW_TAG_namespace
6388 && tag
!= DW_TAG_structure_type
6389 && tag
!= DW_TAG_class_type
)
6392 name
= get_AT_string (die
, DW_AT_name
);
6394 spec
= get_AT_ref (die
, DW_AT_specification
);
6398 if (die
->die_parent
!= NULL
)
6399 checksum_die_context (die
->die_parent
, ctx
);
6401 CHECKSUM_ULEB128 ('C');
6402 CHECKSUM_ULEB128 (tag
);
6404 CHECKSUM_STRING (name
);
6407 /* Calculate the checksum of a location expression. */
6410 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6412 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6413 were emitted as a DW_FORM_sdata instead of a location expression. */
6414 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6416 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6417 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6421 /* Otherwise, just checksum the raw location expression. */
6424 inchash::hash hstate
;
6427 CHECKSUM_ULEB128 (loc
->dtprel
);
6428 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6429 hash_loc_operands (loc
, hstate
);
6430 hash
= hstate
.end ();
6432 loc
= loc
->dw_loc_next
;
6436 /* Calculate the checksum of an attribute. */
6439 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
6440 struct md5_ctx
*ctx
, int *mark
)
6442 dw_loc_descr_ref loc
;
6445 if (AT_class (at
) == dw_val_class_die_ref
)
6447 dw_die_ref target_die
= AT_ref (at
);
6449 /* For pointer and reference types, we checksum only the (qualified)
6450 name of the target type (if there is a name). For friend entries,
6451 we checksum only the (qualified) name of the target type or function.
6452 This allows the checksum to remain the same whether the target type
6453 is complete or not. */
6454 if ((at
->dw_attr
== DW_AT_type
6455 && (tag
== DW_TAG_pointer_type
6456 || tag
== DW_TAG_reference_type
6457 || tag
== DW_TAG_rvalue_reference_type
6458 || tag
== DW_TAG_ptr_to_member_type
))
6459 || (at
->dw_attr
== DW_AT_friend
6460 && tag
== DW_TAG_friend
))
6462 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
6464 if (name_attr
!= NULL
)
6466 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6470 CHECKSUM_ULEB128 ('N');
6471 CHECKSUM_ULEB128 (at
->dw_attr
);
6472 if (decl
->die_parent
!= NULL
)
6473 checksum_die_context (decl
->die_parent
, ctx
);
6474 CHECKSUM_ULEB128 ('E');
6475 CHECKSUM_STRING (AT_string (name_attr
));
6480 /* For all other references to another DIE, we check to see if the
6481 target DIE has already been visited. If it has, we emit a
6482 backward reference; if not, we descend recursively. */
6483 if (target_die
->die_mark
> 0)
6485 CHECKSUM_ULEB128 ('R');
6486 CHECKSUM_ULEB128 (at
->dw_attr
);
6487 CHECKSUM_ULEB128 (target_die
->die_mark
);
6491 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6495 target_die
->die_mark
= ++(*mark
);
6496 CHECKSUM_ULEB128 ('T');
6497 CHECKSUM_ULEB128 (at
->dw_attr
);
6498 if (decl
->die_parent
!= NULL
)
6499 checksum_die_context (decl
->die_parent
, ctx
);
6500 die_checksum_ordered (target_die
, ctx
, mark
);
6505 CHECKSUM_ULEB128 ('A');
6506 CHECKSUM_ULEB128 (at
->dw_attr
);
6508 switch (AT_class (at
))
6510 case dw_val_class_const
:
6511 case dw_val_class_const_implicit
:
6512 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6513 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6516 case dw_val_class_unsigned_const
:
6517 case dw_val_class_unsigned_const_implicit
:
6518 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6519 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6522 case dw_val_class_const_double
:
6523 CHECKSUM_ULEB128 (DW_FORM_block
);
6524 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6525 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6528 case dw_val_class_wide_int
:
6529 CHECKSUM_ULEB128 (DW_FORM_block
);
6530 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6531 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6532 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6533 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6534 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6537 case dw_val_class_vec
:
6538 CHECKSUM_ULEB128 (DW_FORM_block
);
6539 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6540 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6541 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6542 (at
->dw_attr_val
.v
.val_vec
.length
6543 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6546 case dw_val_class_flag
:
6547 CHECKSUM_ULEB128 (DW_FORM_flag
);
6548 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6551 case dw_val_class_str
:
6552 CHECKSUM_ULEB128 (DW_FORM_string
);
6553 CHECKSUM_STRING (AT_string (at
));
6556 case dw_val_class_addr
:
6558 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6559 CHECKSUM_ULEB128 (DW_FORM_string
);
6560 CHECKSUM_STRING (XSTR (r
, 0));
6563 case dw_val_class_offset
:
6564 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6565 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6568 case dw_val_class_loc
:
6569 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6570 loc_checksum_ordered (loc
, ctx
);
6573 case dw_val_class_fde_ref
:
6574 case dw_val_class_lbl_id
:
6575 case dw_val_class_lineptr
:
6576 case dw_val_class_macptr
:
6577 case dw_val_class_loclistsptr
:
6578 case dw_val_class_high_pc
:
6581 case dw_val_class_file
:
6582 case dw_val_class_file_implicit
:
6583 CHECKSUM_ULEB128 (DW_FORM_string
);
6584 CHECKSUM_STRING (AT_file (at
)->filename
);
6587 case dw_val_class_data8
:
6588 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6596 struct checksum_attributes
6598 dw_attr_node
*at_name
;
6599 dw_attr_node
*at_type
;
6600 dw_attr_node
*at_friend
;
6601 dw_attr_node
*at_accessibility
;
6602 dw_attr_node
*at_address_class
;
6603 dw_attr_node
*at_allocated
;
6604 dw_attr_node
*at_artificial
;
6605 dw_attr_node
*at_associated
;
6606 dw_attr_node
*at_binary_scale
;
6607 dw_attr_node
*at_bit_offset
;
6608 dw_attr_node
*at_bit_size
;
6609 dw_attr_node
*at_bit_stride
;
6610 dw_attr_node
*at_byte_size
;
6611 dw_attr_node
*at_byte_stride
;
6612 dw_attr_node
*at_const_value
;
6613 dw_attr_node
*at_containing_type
;
6614 dw_attr_node
*at_count
;
6615 dw_attr_node
*at_data_location
;
6616 dw_attr_node
*at_data_member_location
;
6617 dw_attr_node
*at_decimal_scale
;
6618 dw_attr_node
*at_decimal_sign
;
6619 dw_attr_node
*at_default_value
;
6620 dw_attr_node
*at_digit_count
;
6621 dw_attr_node
*at_discr
;
6622 dw_attr_node
*at_discr_list
;
6623 dw_attr_node
*at_discr_value
;
6624 dw_attr_node
*at_encoding
;
6625 dw_attr_node
*at_endianity
;
6626 dw_attr_node
*at_explicit
;
6627 dw_attr_node
*at_is_optional
;
6628 dw_attr_node
*at_location
;
6629 dw_attr_node
*at_lower_bound
;
6630 dw_attr_node
*at_mutable
;
6631 dw_attr_node
*at_ordering
;
6632 dw_attr_node
*at_picture_string
;
6633 dw_attr_node
*at_prototyped
;
6634 dw_attr_node
*at_small
;
6635 dw_attr_node
*at_segment
;
6636 dw_attr_node
*at_string_length
;
6637 dw_attr_node
*at_string_length_bit_size
;
6638 dw_attr_node
*at_string_length_byte_size
;
6639 dw_attr_node
*at_threads_scaled
;
6640 dw_attr_node
*at_upper_bound
;
6641 dw_attr_node
*at_use_location
;
6642 dw_attr_node
*at_use_UTF8
;
6643 dw_attr_node
*at_variable_parameter
;
6644 dw_attr_node
*at_virtuality
;
6645 dw_attr_node
*at_visibility
;
6646 dw_attr_node
*at_vtable_elem_location
;
6649 /* Collect the attributes that we will want to use for the checksum. */
6652 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6657 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6668 attrs
->at_friend
= a
;
6670 case DW_AT_accessibility
:
6671 attrs
->at_accessibility
= a
;
6673 case DW_AT_address_class
:
6674 attrs
->at_address_class
= a
;
6676 case DW_AT_allocated
:
6677 attrs
->at_allocated
= a
;
6679 case DW_AT_artificial
:
6680 attrs
->at_artificial
= a
;
6682 case DW_AT_associated
:
6683 attrs
->at_associated
= a
;
6685 case DW_AT_binary_scale
:
6686 attrs
->at_binary_scale
= a
;
6688 case DW_AT_bit_offset
:
6689 attrs
->at_bit_offset
= a
;
6691 case DW_AT_bit_size
:
6692 attrs
->at_bit_size
= a
;
6694 case DW_AT_bit_stride
:
6695 attrs
->at_bit_stride
= a
;
6697 case DW_AT_byte_size
:
6698 attrs
->at_byte_size
= a
;
6700 case DW_AT_byte_stride
:
6701 attrs
->at_byte_stride
= a
;
6703 case DW_AT_const_value
:
6704 attrs
->at_const_value
= a
;
6706 case DW_AT_containing_type
:
6707 attrs
->at_containing_type
= a
;
6710 attrs
->at_count
= a
;
6712 case DW_AT_data_location
:
6713 attrs
->at_data_location
= a
;
6715 case DW_AT_data_member_location
:
6716 attrs
->at_data_member_location
= a
;
6718 case DW_AT_decimal_scale
:
6719 attrs
->at_decimal_scale
= a
;
6721 case DW_AT_decimal_sign
:
6722 attrs
->at_decimal_sign
= a
;
6724 case DW_AT_default_value
:
6725 attrs
->at_default_value
= a
;
6727 case DW_AT_digit_count
:
6728 attrs
->at_digit_count
= a
;
6731 attrs
->at_discr
= a
;
6733 case DW_AT_discr_list
:
6734 attrs
->at_discr_list
= a
;
6736 case DW_AT_discr_value
:
6737 attrs
->at_discr_value
= a
;
6739 case DW_AT_encoding
:
6740 attrs
->at_encoding
= a
;
6742 case DW_AT_endianity
:
6743 attrs
->at_endianity
= a
;
6745 case DW_AT_explicit
:
6746 attrs
->at_explicit
= a
;
6748 case DW_AT_is_optional
:
6749 attrs
->at_is_optional
= a
;
6751 case DW_AT_location
:
6752 attrs
->at_location
= a
;
6754 case DW_AT_lower_bound
:
6755 attrs
->at_lower_bound
= a
;
6758 attrs
->at_mutable
= a
;
6760 case DW_AT_ordering
:
6761 attrs
->at_ordering
= a
;
6763 case DW_AT_picture_string
:
6764 attrs
->at_picture_string
= a
;
6766 case DW_AT_prototyped
:
6767 attrs
->at_prototyped
= a
;
6770 attrs
->at_small
= a
;
6773 attrs
->at_segment
= a
;
6775 case DW_AT_string_length
:
6776 attrs
->at_string_length
= a
;
6778 case DW_AT_string_length_bit_size
:
6779 attrs
->at_string_length_bit_size
= a
;
6781 case DW_AT_string_length_byte_size
:
6782 attrs
->at_string_length_byte_size
= a
;
6784 case DW_AT_threads_scaled
:
6785 attrs
->at_threads_scaled
= a
;
6787 case DW_AT_upper_bound
:
6788 attrs
->at_upper_bound
= a
;
6790 case DW_AT_use_location
:
6791 attrs
->at_use_location
= a
;
6793 case DW_AT_use_UTF8
:
6794 attrs
->at_use_UTF8
= a
;
6796 case DW_AT_variable_parameter
:
6797 attrs
->at_variable_parameter
= a
;
6799 case DW_AT_virtuality
:
6800 attrs
->at_virtuality
= a
;
6802 case DW_AT_visibility
:
6803 attrs
->at_visibility
= a
;
6805 case DW_AT_vtable_elem_location
:
6806 attrs
->at_vtable_elem_location
= a
;
6814 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6817 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6821 struct checksum_attributes attrs
;
6823 CHECKSUM_ULEB128 ('D');
6824 CHECKSUM_ULEB128 (die
->die_tag
);
6826 memset (&attrs
, 0, sizeof (attrs
));
6828 decl
= get_AT_ref (die
, DW_AT_specification
);
6830 collect_checksum_attributes (&attrs
, decl
);
6831 collect_checksum_attributes (&attrs
, die
);
6833 CHECKSUM_ATTR (attrs
.at_name
);
6834 CHECKSUM_ATTR (attrs
.at_accessibility
);
6835 CHECKSUM_ATTR (attrs
.at_address_class
);
6836 CHECKSUM_ATTR (attrs
.at_allocated
);
6837 CHECKSUM_ATTR (attrs
.at_artificial
);
6838 CHECKSUM_ATTR (attrs
.at_associated
);
6839 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6840 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6841 CHECKSUM_ATTR (attrs
.at_bit_size
);
6842 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6843 CHECKSUM_ATTR (attrs
.at_byte_size
);
6844 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6845 CHECKSUM_ATTR (attrs
.at_const_value
);
6846 CHECKSUM_ATTR (attrs
.at_containing_type
);
6847 CHECKSUM_ATTR (attrs
.at_count
);
6848 CHECKSUM_ATTR (attrs
.at_data_location
);
6849 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6850 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6851 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6852 CHECKSUM_ATTR (attrs
.at_default_value
);
6853 CHECKSUM_ATTR (attrs
.at_digit_count
);
6854 CHECKSUM_ATTR (attrs
.at_discr
);
6855 CHECKSUM_ATTR (attrs
.at_discr_list
);
6856 CHECKSUM_ATTR (attrs
.at_discr_value
);
6857 CHECKSUM_ATTR (attrs
.at_encoding
);
6858 CHECKSUM_ATTR (attrs
.at_endianity
);
6859 CHECKSUM_ATTR (attrs
.at_explicit
);
6860 CHECKSUM_ATTR (attrs
.at_is_optional
);
6861 CHECKSUM_ATTR (attrs
.at_location
);
6862 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6863 CHECKSUM_ATTR (attrs
.at_mutable
);
6864 CHECKSUM_ATTR (attrs
.at_ordering
);
6865 CHECKSUM_ATTR (attrs
.at_picture_string
);
6866 CHECKSUM_ATTR (attrs
.at_prototyped
);
6867 CHECKSUM_ATTR (attrs
.at_small
);
6868 CHECKSUM_ATTR (attrs
.at_segment
);
6869 CHECKSUM_ATTR (attrs
.at_string_length
);
6870 CHECKSUM_ATTR (attrs
.at_string_length_bit_size
);
6871 CHECKSUM_ATTR (attrs
.at_string_length_byte_size
);
6872 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6873 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6874 CHECKSUM_ATTR (attrs
.at_use_location
);
6875 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6876 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6877 CHECKSUM_ATTR (attrs
.at_virtuality
);
6878 CHECKSUM_ATTR (attrs
.at_visibility
);
6879 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6880 CHECKSUM_ATTR (attrs
.at_type
);
6881 CHECKSUM_ATTR (attrs
.at_friend
);
6883 /* Checksum the child DIEs. */
6886 dw_attr_node
*name_attr
;
6889 name_attr
= get_AT (c
, DW_AT_name
);
6890 if (is_template_instantiation (c
))
6892 /* Ignore instantiations of member type and function templates. */
6894 else if (name_attr
!= NULL
6895 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6897 /* Use a shallow checksum for named nested types and member
6899 CHECKSUM_ULEB128 ('S');
6900 CHECKSUM_ULEB128 (c
->die_tag
);
6901 CHECKSUM_STRING (AT_string (name_attr
));
6905 /* Use a deep checksum for other children. */
6906 /* Mark this DIE so it gets processed when unmarking. */
6907 if (c
->die_mark
== 0)
6909 die_checksum_ordered (c
, ctx
, mark
);
6911 } while (c
!= die
->die_child
);
6913 CHECKSUM_ULEB128 (0);
6916 /* Add a type name and tag to a hash. */
6918 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6920 CHECKSUM_ULEB128 (tag
);
6921 CHECKSUM_STRING (name
);
6925 #undef CHECKSUM_STRING
6926 #undef CHECKSUM_ATTR
6927 #undef CHECKSUM_LEB128
6928 #undef CHECKSUM_ULEB128
6930 /* Generate the type signature for DIE. This is computed by generating an
6931 MD5 checksum over the DIE's tag, its relevant attributes, and its
6932 children. Attributes that are references to other DIEs are processed
6933 by recursion, using the MARK field to prevent infinite recursion.
6934 If the DIE is nested inside a namespace or another type, we also
6935 need to include that context in the signature. The lower 64 bits
6936 of the resulting MD5 checksum comprise the signature. */
6939 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6943 unsigned char checksum
[16];
6948 name
= get_AT_string (die
, DW_AT_name
);
6949 decl
= get_AT_ref (die
, DW_AT_specification
);
6950 parent
= get_die_parent (die
);
6952 /* First, compute a signature for just the type name (and its surrounding
6953 context, if any. This is stored in the type unit DIE for link-time
6954 ODR (one-definition rule) checking. */
6956 if (is_cxx () && name
!= NULL
)
6958 md5_init_ctx (&ctx
);
6960 /* Checksum the names of surrounding namespaces and structures. */
6962 checksum_die_context (parent
, &ctx
);
6964 /* Checksum the current DIE. */
6965 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6966 md5_finish_ctx (&ctx
, checksum
);
6968 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6971 /* Next, compute the complete type signature. */
6973 md5_init_ctx (&ctx
);
6975 die
->die_mark
= mark
;
6977 /* Checksum the names of surrounding namespaces and structures. */
6979 checksum_die_context (parent
, &ctx
);
6981 /* Checksum the DIE and its children. */
6982 die_checksum_ordered (die
, &ctx
, &mark
);
6983 unmark_all_dies (die
);
6984 md5_finish_ctx (&ctx
, checksum
);
6986 /* Store the signature in the type node and link the type DIE and the
6987 type node together. */
6988 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6989 DWARF_TYPE_SIGNATURE_SIZE
);
6990 die
->comdat_type_p
= true;
6991 die
->die_id
.die_type_node
= type_node
;
6992 type_node
->type_die
= die
;
6994 /* If the DIE is a specification, link its declaration to the type node
6998 decl
->comdat_type_p
= true;
6999 decl
->die_id
.die_type_node
= type_node
;
7003 /* Do the location expressions look same? */
7005 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
7007 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
7008 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
7009 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
7012 /* Do the values look the same? */
7014 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
7016 dw_loc_descr_ref loc1
, loc2
;
7019 if (v1
->val_class
!= v2
->val_class
)
7022 switch (v1
->val_class
)
7024 case dw_val_class_const
:
7025 case dw_val_class_const_implicit
:
7026 return v1
->v
.val_int
== v2
->v
.val_int
;
7027 case dw_val_class_unsigned_const
:
7028 case dw_val_class_unsigned_const_implicit
:
7029 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
7030 case dw_val_class_const_double
:
7031 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
7032 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
7033 case dw_val_class_wide_int
:
7034 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
7035 case dw_val_class_vec
:
7036 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
7037 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7039 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7040 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7043 case dw_val_class_flag
:
7044 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7045 case dw_val_class_str
:
7046 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7048 case dw_val_class_addr
:
7049 r1
= v1
->v
.val_addr
;
7050 r2
= v2
->v
.val_addr
;
7051 if (GET_CODE (r1
) != GET_CODE (r2
))
7053 return !rtx_equal_p (r1
, r2
);
7055 case dw_val_class_offset
:
7056 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7058 case dw_val_class_loc
:
7059 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7061 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7062 if (!same_loc_p (loc1
, loc2
, mark
))
7064 return !loc1
&& !loc2
;
7066 case dw_val_class_die_ref
:
7067 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7069 case dw_val_class_fde_ref
:
7070 case dw_val_class_vms_delta
:
7071 case dw_val_class_lbl_id
:
7072 case dw_val_class_lineptr
:
7073 case dw_val_class_macptr
:
7074 case dw_val_class_loclistsptr
:
7075 case dw_val_class_high_pc
:
7078 case dw_val_class_file
:
7079 case dw_val_class_file_implicit
:
7080 return v1
->v
.val_file
== v2
->v
.val_file
;
7082 case dw_val_class_data8
:
7083 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
7090 /* Do the attributes look the same? */
7093 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
7095 if (at1
->dw_attr
!= at2
->dw_attr
)
7098 /* We don't care that this was compiled with a different compiler
7099 snapshot; if the output is the same, that's what matters. */
7100 if (at1
->dw_attr
== DW_AT_producer
)
7103 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7106 /* Do the dies look the same? */
7109 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7115 /* To avoid infinite recursion. */
7117 return die1
->die_mark
== die2
->die_mark
;
7118 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7120 if (die1
->die_tag
!= die2
->die_tag
)
7123 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
7126 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
7127 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
7130 c1
= die1
->die_child
;
7131 c2
= die2
->die_child
;
7140 if (!same_die_p (c1
, c2
, mark
))
7144 if (c1
== die1
->die_child
)
7146 if (c2
== die2
->die_child
)
7156 /* Do the dies look the same? Wrapper around same_die_p. */
7159 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
7162 int ret
= same_die_p (die1
, die2
, &mark
);
7164 unmark_all_dies (die1
);
7165 unmark_all_dies (die2
);
7170 /* The prefix to attach to symbols on DIEs in the current comdat debug
7172 static const char *comdat_symbol_id
;
7174 /* The index of the current symbol within the current comdat CU. */
7175 static unsigned int comdat_symbol_number
;
7177 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7178 children, and set comdat_symbol_id accordingly. */
7181 compute_section_prefix (dw_die_ref unit_die
)
7183 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
7184 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
7185 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
7188 unsigned char checksum
[16];
7191 /* Compute the checksum of the DIE, then append part of it as hex digits to
7192 the name filename of the unit. */
7194 md5_init_ctx (&ctx
);
7196 die_checksum (unit_die
, &ctx
, &mark
);
7197 unmark_all_dies (unit_die
);
7198 md5_finish_ctx (&ctx
, checksum
);
7200 sprintf (name
, "%s.", base
);
7201 clean_symbol_name (name
);
7203 p
= name
+ strlen (name
);
7204 for (i
= 0; i
< 4; i
++)
7206 sprintf (p
, "%.2x", checksum
[i
]);
7210 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
7211 comdat_symbol_number
= 0;
7214 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7217 is_type_die (dw_die_ref die
)
7219 switch (die
->die_tag
)
7221 case DW_TAG_array_type
:
7222 case DW_TAG_class_type
:
7223 case DW_TAG_interface_type
:
7224 case DW_TAG_enumeration_type
:
7225 case DW_TAG_pointer_type
:
7226 case DW_TAG_reference_type
:
7227 case DW_TAG_rvalue_reference_type
:
7228 case DW_TAG_string_type
:
7229 case DW_TAG_structure_type
:
7230 case DW_TAG_subroutine_type
:
7231 case DW_TAG_union_type
:
7232 case DW_TAG_ptr_to_member_type
:
7233 case DW_TAG_set_type
:
7234 case DW_TAG_subrange_type
:
7235 case DW_TAG_base_type
:
7236 case DW_TAG_const_type
:
7237 case DW_TAG_file_type
:
7238 case DW_TAG_packed_type
:
7239 case DW_TAG_volatile_type
:
7240 case DW_TAG_typedef
:
7247 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7248 Basically, we want to choose the bits that are likely to be shared between
7249 compilations (types) and leave out the bits that are specific to individual
7250 compilations (functions). */
7253 is_comdat_die (dw_die_ref c
)
7255 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7256 we do for stabs. The advantage is a greater likelihood of sharing between
7257 objects that don't include headers in the same order (and therefore would
7258 put the base types in a different comdat). jason 8/28/00 */
7260 if (c
->die_tag
== DW_TAG_base_type
)
7263 if (c
->die_tag
== DW_TAG_pointer_type
7264 || c
->die_tag
== DW_TAG_reference_type
7265 || c
->die_tag
== DW_TAG_rvalue_reference_type
7266 || c
->die_tag
== DW_TAG_const_type
7267 || c
->die_tag
== DW_TAG_volatile_type
)
7269 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
7271 return t
? is_comdat_die (t
) : 0;
7274 return is_type_die (c
);
7277 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7278 compilation unit. */
7281 is_symbol_die (dw_die_ref c
)
7283 return (is_type_die (c
)
7284 || is_declaration_die (c
)
7285 || c
->die_tag
== DW_TAG_namespace
7286 || c
->die_tag
== DW_TAG_module
);
7289 /* Returns true iff C is a compile-unit DIE. */
7292 is_cu_die (dw_die_ref c
)
7294 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7295 || c
->die_tag
== DW_TAG_skeleton_unit
);
7298 /* Returns true iff C is a unit DIE of some sort. */
7301 is_unit_die (dw_die_ref c
)
7303 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7304 || c
->die_tag
== DW_TAG_partial_unit
7305 || c
->die_tag
== DW_TAG_type_unit
7306 || c
->die_tag
== DW_TAG_skeleton_unit
);
7309 /* Returns true iff C is a namespace DIE. */
7312 is_namespace_die (dw_die_ref c
)
7314 return c
&& c
->die_tag
== DW_TAG_namespace
;
7317 /* Returns true iff C is a class or structure DIE. */
7320 is_class_die (dw_die_ref c
)
7322 return c
&& (c
->die_tag
== DW_TAG_class_type
7323 || c
->die_tag
== DW_TAG_structure_type
);
7326 /* Return non-zero if this DIE is a template parameter. */
7329 is_template_parameter (dw_die_ref die
)
7331 switch (die
->die_tag
)
7333 case DW_TAG_template_type_param
:
7334 case DW_TAG_template_value_param
:
7335 case DW_TAG_GNU_template_template_param
:
7336 case DW_TAG_GNU_template_parameter_pack
:
7343 /* Return non-zero if this DIE represents a template instantiation. */
7346 is_template_instantiation (dw_die_ref die
)
7350 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
7352 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
7357 gen_internal_sym (const char *prefix
)
7359 char buf
[MAX_ARTIFICIAL_LABEL_BYTES
];
7361 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7362 return xstrdup (buf
);
7365 /* Assign symbols to all worthy DIEs under DIE. */
7368 assign_symbol_names (dw_die_ref die
)
7372 if (is_symbol_die (die
) && !die
->comdat_type_p
)
7374 if (comdat_symbol_id
)
7376 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
7378 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
7379 comdat_symbol_id
, comdat_symbol_number
++);
7380 die
->die_id
.die_symbol
= xstrdup (p
);
7383 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
7386 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
7389 struct cu_hash_table_entry
7392 unsigned min_comdat_num
, max_comdat_num
;
7393 struct cu_hash_table_entry
*next
;
7396 /* Helpers to manipulate hash table of CUs. */
7398 struct cu_hash_table_entry_hasher
: pointer_hash
<cu_hash_table_entry
>
7400 typedef die_struct
*compare_type
;
7401 static inline hashval_t
hash (const cu_hash_table_entry
*);
7402 static inline bool equal (const cu_hash_table_entry
*, const die_struct
*);
7403 static inline void remove (cu_hash_table_entry
*);
7407 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry
*entry
)
7409 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
7413 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry
*entry1
,
7414 const die_struct
*entry2
)
7416 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
7420 cu_hash_table_entry_hasher::remove (cu_hash_table_entry
*entry
)
7422 struct cu_hash_table_entry
*next
;
7432 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
7434 /* Check whether we have already seen this CU and set up SYM_NUM
7437 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
7439 struct cu_hash_table_entry dummy
;
7440 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7442 dummy
.max_comdat_num
= 0;
7444 slot
= htable
->find_slot_with_hash (cu
,
7445 htab_hash_string (cu
->die_id
.die_symbol
),
7449 for (; entry
; last
= entry
, entry
= entry
->next
)
7451 if (same_die_p_wrap (cu
, entry
->cu
))
7457 *sym_num
= entry
->min_comdat_num
;
7461 entry
= XCNEW (struct cu_hash_table_entry
);
7463 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7464 entry
->next
= *slot
;
7470 /* Record SYM_NUM to record of CU in HTABLE. */
7472 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
7473 unsigned int sym_num
)
7475 struct cu_hash_table_entry
**slot
, *entry
;
7477 slot
= htable
->find_slot_with_hash (cu
,
7478 htab_hash_string (cu
->die_id
.die_symbol
),
7482 entry
->max_comdat_num
= sym_num
;
7485 /* Traverse the DIE (which is always comp_unit_die), and set up
7486 additional compilation units for each of the include files we see
7487 bracketed by BINCL/EINCL. */
7490 break_out_includes (dw_die_ref die
)
7493 dw_die_ref unit
= NULL
;
7494 limbo_die_node
*node
, **pnode
;
7498 dw_die_ref prev
= c
;
7500 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7501 || (unit
&& is_comdat_die (c
)))
7503 dw_die_ref next
= c
->die_sib
;
7505 /* This DIE is for a secondary CU; remove it from the main one. */
7506 remove_child_with_prev (c
, prev
);
7508 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7509 unit
= push_new_compile_unit (unit
, c
);
7510 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7511 unit
= pop_compile_unit (unit
);
7513 add_child_die (unit
, c
);
7515 if (c
== die
->die_child
)
7518 } while (c
!= die
->die_child
);
7521 /* We can only use this in debugging, since the frontend doesn't check
7522 to make sure that we leave every include file we enter. */
7526 assign_symbol_names (die
);
7527 cu_hash_type
cu_hash_table (10);
7528 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7534 compute_section_prefix (node
->die
);
7535 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
7536 &comdat_symbol_number
);
7537 assign_symbol_names (node
->die
);
7539 *pnode
= node
->next
;
7542 pnode
= &node
->next
;
7543 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
7544 comdat_symbol_number
);
7549 /* Return non-zero if this DIE is a declaration. */
7552 is_declaration_die (dw_die_ref die
)
7557 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7558 if (a
->dw_attr
== DW_AT_declaration
)
7564 /* Return non-zero if this DIE is nested inside a subprogram. */
7567 is_nested_in_subprogram (dw_die_ref die
)
7569 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7573 return local_scope_p (decl
);
7576 /* Return non-zero if this DIE contains a defining declaration of a
7580 contains_subprogram_definition (dw_die_ref die
)
7584 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7586 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7590 /* Return non-zero if this is a type DIE that should be moved to a
7591 COMDAT .debug_types section or .debug_info section with DW_UT_*type
7595 should_move_die_to_comdat (dw_die_ref die
)
7597 switch (die
->die_tag
)
7599 case DW_TAG_class_type
:
7600 case DW_TAG_structure_type
:
7601 case DW_TAG_enumeration_type
:
7602 case DW_TAG_union_type
:
7603 /* Don't move declarations, inlined instances, types nested in a
7604 subprogram, or types that contain subprogram definitions. */
7605 if (is_declaration_die (die
)
7606 || get_AT (die
, DW_AT_abstract_origin
)
7607 || is_nested_in_subprogram (die
)
7608 || contains_subprogram_definition (die
))
7611 case DW_TAG_array_type
:
7612 case DW_TAG_interface_type
:
7613 case DW_TAG_pointer_type
:
7614 case DW_TAG_reference_type
:
7615 case DW_TAG_rvalue_reference_type
:
7616 case DW_TAG_string_type
:
7617 case DW_TAG_subroutine_type
:
7618 case DW_TAG_ptr_to_member_type
:
7619 case DW_TAG_set_type
:
7620 case DW_TAG_subrange_type
:
7621 case DW_TAG_base_type
:
7622 case DW_TAG_const_type
:
7623 case DW_TAG_file_type
:
7624 case DW_TAG_packed_type
:
7625 case DW_TAG_volatile_type
:
7626 case DW_TAG_typedef
:
7632 /* Make a clone of DIE. */
7635 clone_die (dw_die_ref die
)
7641 clone
= ggc_cleared_alloc
<die_node
> ();
7642 clone
->die_tag
= die
->die_tag
;
7644 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7645 add_dwarf_attr (clone
, a
);
7650 /* Make a clone of the tree rooted at DIE. */
7653 clone_tree (dw_die_ref die
)
7656 dw_die_ref clone
= clone_die (die
);
7658 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7663 /* Make a clone of DIE as a declaration. */
7666 clone_as_declaration (dw_die_ref die
)
7673 /* If the DIE is already a declaration, just clone it. */
7674 if (is_declaration_die (die
))
7675 return clone_die (die
);
7677 /* If the DIE is a specification, just clone its declaration DIE. */
7678 decl
= get_AT_ref (die
, DW_AT_specification
);
7681 clone
= clone_die (decl
);
7682 if (die
->comdat_type_p
)
7683 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7687 clone
= ggc_cleared_alloc
<die_node
> ();
7688 clone
->die_tag
= die
->die_tag
;
7690 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7692 /* We don't want to copy over all attributes.
7693 For example we don't want DW_AT_byte_size because otherwise we will no
7694 longer have a declaration and GDB will treat it as a definition. */
7698 case DW_AT_abstract_origin
:
7699 case DW_AT_artificial
:
7700 case DW_AT_containing_type
:
7701 case DW_AT_external
:
7704 case DW_AT_virtuality
:
7705 case DW_AT_linkage_name
:
7706 case DW_AT_MIPS_linkage_name
:
7707 add_dwarf_attr (clone
, a
);
7709 case DW_AT_byte_size
:
7710 case DW_AT_alignment
:
7716 if (die
->comdat_type_p
)
7717 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7719 add_AT_flag (clone
, DW_AT_declaration
, 1);
7724 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7726 struct decl_table_entry
7732 /* Helpers to manipulate hash table of copied declarations. */
7734 /* Hashtable helpers. */
7736 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7738 typedef die_struct
*compare_type
;
7739 static inline hashval_t
hash (const decl_table_entry
*);
7740 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7744 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7746 return htab_hash_pointer (entry
->orig
);
7750 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7751 const die_struct
*entry2
)
7753 return entry1
->orig
== entry2
;
7756 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7758 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7759 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7760 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7761 to check if the ancestor has already been copied into UNIT. */
7764 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7765 decl_hash_type
*decl_table
)
7767 dw_die_ref parent
= die
->die_parent
;
7768 dw_die_ref new_parent
= unit
;
7770 decl_table_entry
**slot
= NULL
;
7771 struct decl_table_entry
*entry
= NULL
;
7775 /* Check if the entry has already been copied to UNIT. */
7776 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7778 if (*slot
!= HTAB_EMPTY_ENTRY
)
7784 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7785 entry
= XCNEW (struct decl_table_entry
);
7793 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7796 if (!is_unit_die (parent
))
7797 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7800 copy
= clone_as_declaration (die
);
7801 add_child_die (new_parent
, copy
);
7805 /* Record the pointer to the copy. */
7811 /* Copy the declaration context to the new type unit DIE. This includes
7812 any surrounding namespace or type declarations. If the DIE has an
7813 AT_specification attribute, it also includes attributes and children
7814 attached to the specification, and returns a pointer to the original
7815 parent of the declaration DIE. Returns NULL otherwise. */
7818 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7821 dw_die_ref new_decl
;
7822 dw_die_ref orig_parent
= NULL
;
7824 decl
= get_AT_ref (die
, DW_AT_specification
);
7833 /* The original DIE will be changed to a declaration, and must
7834 be moved to be a child of the original declaration DIE. */
7835 orig_parent
= decl
->die_parent
;
7837 /* Copy the type node pointer from the new DIE to the original
7838 declaration DIE so we can forward references later. */
7839 decl
->comdat_type_p
= true;
7840 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7842 remove_AT (die
, DW_AT_specification
);
7844 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7846 if (a
->dw_attr
!= DW_AT_name
7847 && a
->dw_attr
!= DW_AT_declaration
7848 && a
->dw_attr
!= DW_AT_external
)
7849 add_dwarf_attr (die
, a
);
7852 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7855 if (decl
->die_parent
!= NULL
7856 && !is_unit_die (decl
->die_parent
))
7858 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7859 if (new_decl
!= NULL
)
7861 remove_AT (new_decl
, DW_AT_signature
);
7862 add_AT_specification (die
, new_decl
);
7869 /* Generate the skeleton ancestor tree for the given NODE, then clone
7870 the DIE and add the clone into the tree. */
7873 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7875 if (node
->new_die
!= NULL
)
7878 node
->new_die
= clone_as_declaration (node
->old_die
);
7880 if (node
->parent
!= NULL
)
7882 generate_skeleton_ancestor_tree (node
->parent
);
7883 add_child_die (node
->parent
->new_die
, node
->new_die
);
7887 /* Generate a skeleton tree of DIEs containing any declarations that are
7888 found in the original tree. We traverse the tree looking for declaration
7889 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7892 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7894 skeleton_chain_node node
;
7897 dw_die_ref prev
= NULL
;
7898 dw_die_ref next
= NULL
;
7900 node
.parent
= parent
;
7902 first
= c
= parent
->old_die
->die_child
;
7906 if (prev
== NULL
|| prev
->die_sib
== c
)
7909 next
= (c
== first
? NULL
: c
->die_sib
);
7911 node
.new_die
= NULL
;
7912 if (is_declaration_die (c
))
7914 if (is_template_instantiation (c
))
7916 /* Instantiated templates do not need to be cloned into the
7917 type unit. Just move the DIE and its children back to
7918 the skeleton tree (in the main CU). */
7919 remove_child_with_prev (c
, prev
);
7920 add_child_die (parent
->new_die
, c
);
7923 else if (c
->comdat_type_p
)
7925 /* This is the skeleton of earlier break_out_comdat_types
7926 type. Clone the existing DIE, but keep the children
7927 under the original (which is in the main CU). */
7928 dw_die_ref clone
= clone_die (c
);
7930 replace_child (c
, clone
, prev
);
7931 generate_skeleton_ancestor_tree (parent
);
7932 add_child_die (parent
->new_die
, c
);
7938 /* Clone the existing DIE, move the original to the skeleton
7939 tree (which is in the main CU), and put the clone, with
7940 all the original's children, where the original came from
7941 (which is about to be moved to the type unit). */
7942 dw_die_ref clone
= clone_die (c
);
7943 move_all_children (c
, clone
);
7945 /* If the original has a DW_AT_object_pointer attribute,
7946 it would now point to a child DIE just moved to the
7947 cloned tree, so we need to remove that attribute from
7949 remove_AT (c
, DW_AT_object_pointer
);
7951 replace_child (c
, clone
, prev
);
7952 generate_skeleton_ancestor_tree (parent
);
7953 add_child_die (parent
->new_die
, c
);
7954 node
.old_die
= clone
;
7959 generate_skeleton_bottom_up (&node
);
7960 } while (next
!= NULL
);
7963 /* Wrapper function for generate_skeleton_bottom_up. */
7966 generate_skeleton (dw_die_ref die
)
7968 skeleton_chain_node node
;
7971 node
.new_die
= NULL
;
7974 /* If this type definition is nested inside another type,
7975 and is not an instantiation of a template, always leave
7976 at least a declaration in its place. */
7977 if (die
->die_parent
!= NULL
7978 && is_type_die (die
->die_parent
)
7979 && !is_template_instantiation (die
))
7980 node
.new_die
= clone_as_declaration (die
);
7982 generate_skeleton_bottom_up (&node
);
7983 return node
.new_die
;
7986 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7987 declaration. The original DIE is moved to a new compile unit so that
7988 existing references to it follow it to the new location. If any of the
7989 original DIE's descendants is a declaration, we need to replace the
7990 original DIE with a skeleton tree and move the declarations back into the
7994 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7997 dw_die_ref skeleton
, orig_parent
;
7999 /* Copy the declaration context to the type unit DIE. If the returned
8000 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
8002 orig_parent
= copy_declaration_context (unit
, child
);
8004 skeleton
= generate_skeleton (child
);
8005 if (skeleton
== NULL
)
8006 remove_child_with_prev (child
, prev
);
8009 skeleton
->comdat_type_p
= true;
8010 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
8012 /* If the original DIE was a specification, we need to put
8013 the skeleton under the parent DIE of the declaration.
8014 This leaves the original declaration in the tree, but
8015 it will be pruned later since there are no longer any
8016 references to it. */
8017 if (orig_parent
!= NULL
)
8019 remove_child_with_prev (child
, prev
);
8020 add_child_die (orig_parent
, skeleton
);
8023 replace_child (child
, skeleton
, prev
);
8030 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8031 comdat_type_node
*type_node
,
8032 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
8034 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8035 procedure, put it under TYPE_NODE and return the copy. Continue looking for
8036 DWARF procedure references in the DW_AT_location attribute. */
8039 copy_dwarf_procedure (dw_die_ref die
,
8040 comdat_type_node
*type_node
,
8041 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8043 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
8045 /* DWARF procedures are not supposed to have children... */
8046 gcc_assert (die
->die_child
== NULL
);
8048 /* ... and they are supposed to have only one attribute: DW_AT_location. */
8049 gcc_assert (vec_safe_length (die
->die_attr
) == 1
8050 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
8052 /* Do not copy more than once DWARF procedures. */
8054 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
8058 die_copy
= clone_die (die
);
8059 add_child_die (type_node
->root_die
, die_copy
);
8060 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
8064 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8065 procedures in DIE's attributes. */
8068 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8069 comdat_type_node
*type_node
,
8070 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8075 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
8077 dw_loc_descr_ref loc
;
8079 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
8082 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
8084 switch (loc
->dw_loc_opc
)
8088 case DW_OP_call_ref
:
8089 gcc_assert (loc
->dw_loc_oprnd1
.val_class
8090 == dw_val_class_die_ref
);
8091 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
8092 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
8094 copied_dwarf_procs
);
8103 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8104 rewrite references to point to the copies.
8106 References are looked for in DIE's attributes and recursively in all its
8107 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8108 mapping from old DWARF procedures to their copy. It is used not to copy
8109 twice the same DWARF procedure under TYPE_NODE. */
8112 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
8113 comdat_type_node
*type_node
,
8114 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8118 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
8119 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
8121 copied_dwarf_procs
));
8124 /* Traverse the DIE and set up additional .debug_types or .debug_info
8125 DW_UT_*type sections for each type worthy of being placed in a COMDAT
8129 break_out_comdat_types (dw_die_ref die
)
8133 dw_die_ref prev
= NULL
;
8134 dw_die_ref next
= NULL
;
8135 dw_die_ref unit
= NULL
;
8137 first
= c
= die
->die_child
;
8141 if (prev
== NULL
|| prev
->die_sib
== c
)
8144 next
= (c
== first
? NULL
: c
->die_sib
);
8145 if (should_move_die_to_comdat (c
))
8147 dw_die_ref replacement
;
8148 comdat_type_node
*type_node
;
8150 /* Break out nested types into their own type units. */
8151 break_out_comdat_types (c
);
8153 /* Create a new type unit DIE as the root for the new tree, and
8154 add it to the list of comdat types. */
8155 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8156 add_AT_unsigned (unit
, DW_AT_language
,
8157 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
8158 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
8159 type_node
->root_die
= unit
;
8160 type_node
->next
= comdat_type_list
;
8161 comdat_type_list
= type_node
;
8163 /* Generate the type signature. */
8164 generate_type_signature (c
, type_node
);
8166 /* Copy the declaration context, attributes, and children of the
8167 declaration into the new type unit DIE, then remove this DIE
8168 from the main CU (or replace it with a skeleton if necessary). */
8169 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
8170 type_node
->skeleton_die
= replacement
;
8172 /* Add the DIE to the new compunit. */
8173 add_child_die (unit
, c
);
8175 /* Types can reference DWARF procedures for type size or data location
8176 expressions. Calls in DWARF expressions cannot target procedures
8177 that are not in the same section. So we must copy DWARF procedures
8178 along with this type and then rewrite references to them. */
8179 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
8180 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
8182 if (replacement
!= NULL
)
8185 else if (c
->die_tag
== DW_TAG_namespace
8186 || c
->die_tag
== DW_TAG_class_type
8187 || c
->die_tag
== DW_TAG_structure_type
8188 || c
->die_tag
== DW_TAG_union_type
)
8190 /* Look for nested types that can be broken out. */
8191 break_out_comdat_types (c
);
8193 } while (next
!= NULL
);
8196 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8197 Enter all the cloned children into the hash table decl_table. */
8200 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
8204 struct decl_table_entry
*entry
;
8205 decl_table_entry
**slot
;
8207 if (die
->die_tag
== DW_TAG_subprogram
)
8208 clone
= clone_as_declaration (die
);
8210 clone
= clone_die (die
);
8212 slot
= decl_table
->find_slot_with_hash (die
,
8213 htab_hash_pointer (die
), INSERT
);
8215 /* Assert that DIE isn't in the hash table yet. If it would be there
8216 before, the ancestors would be necessarily there as well, therefore
8217 clone_tree_partial wouldn't be called. */
8218 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8220 entry
= XCNEW (struct decl_table_entry
);
8222 entry
->copy
= clone
;
8225 if (die
->die_tag
!= DW_TAG_subprogram
)
8226 FOR_EACH_CHILD (die
, c
,
8227 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
8232 /* Walk the DIE and its children, looking for references to incomplete
8233 or trivial types that are unmarked (i.e., that are not in the current
8237 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
8243 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8245 if (AT_class (a
) == dw_val_class_die_ref
)
8247 dw_die_ref targ
= AT_ref (a
);
8248 decl_table_entry
**slot
;
8249 struct decl_table_entry
*entry
;
8251 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
8254 slot
= decl_table
->find_slot_with_hash (targ
,
8255 htab_hash_pointer (targ
),
8258 if (*slot
!= HTAB_EMPTY_ENTRY
)
8260 /* TARG has already been copied, so we just need to
8261 modify the reference to point to the copy. */
8263 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
8267 dw_die_ref parent
= unit
;
8268 dw_die_ref copy
= clone_die (targ
);
8270 /* Record in DECL_TABLE that TARG has been copied.
8271 Need to do this now, before the recursive call,
8272 because DECL_TABLE may be expanded and SLOT
8273 would no longer be a valid pointer. */
8274 entry
= XCNEW (struct decl_table_entry
);
8279 /* If TARG is not a declaration DIE, we need to copy its
8281 if (!is_declaration_die (targ
))
8285 add_child_die (copy
,
8286 clone_tree_partial (c
, decl_table
)));
8289 /* Make sure the cloned tree is marked as part of the
8293 /* If TARG has surrounding context, copy its ancestor tree
8294 into the new type unit. */
8295 if (targ
->die_parent
!= NULL
8296 && !is_unit_die (targ
->die_parent
))
8297 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8300 add_child_die (parent
, copy
);
8301 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8303 /* Make sure the newly-copied DIE is walked. If it was
8304 installed in a previously-added context, it won't
8305 get visited otherwise. */
8308 /* Find the highest point of the newly-added tree,
8309 mark each node along the way, and walk from there. */
8310 parent
->die_mark
= 1;
8311 while (parent
->die_parent
8312 && parent
->die_parent
->die_mark
== 0)
8314 parent
= parent
->die_parent
;
8315 parent
->die_mark
= 1;
8317 copy_decls_walk (unit
, parent
, decl_table
);
8323 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8326 /* Copy declarations for "unworthy" types into the new comdat section.
8327 Incomplete types, modified types, and certain other types aren't broken
8328 out into comdat sections of their own, so they don't have a signature,
8329 and we need to copy the declaration into the same section so that we
8330 don't have an external reference. */
8333 copy_decls_for_unworthy_types (dw_die_ref unit
)
8336 decl_hash_type
decl_table (10);
8337 copy_decls_walk (unit
, unit
, &decl_table
);
8341 /* Traverse the DIE and add a sibling attribute if it may have the
8342 effect of speeding up access to siblings. To save some space,
8343 avoid generating sibling attributes for DIE's without children. */
8346 add_sibling_attributes (dw_die_ref die
)
8350 if (! die
->die_child
)
8353 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8354 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8356 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8359 /* Output all location lists for the DIE and its children. */
8362 output_location_lists (dw_die_ref die
)
8368 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8369 if (AT_class (a
) == dw_val_class_loc_list
)
8370 output_loc_list (AT_loc_list (a
));
8372 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
8375 /* During assign_location_list_indexes and output_loclists_offset the
8376 current index, after it the number of assigned indexes (i.e. how
8377 large the .debug_loclists* offset table should be). */
8378 static unsigned int loc_list_idx
;
8380 /* Output all location list offsets for the DIE and its children. */
8383 output_loclists_offsets (dw_die_ref die
)
8389 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8390 if (AT_class (a
) == dw_val_class_loc_list
)
8392 dw_loc_list_ref l
= AT_loc_list (a
);
8393 if (l
->offset_emitted
)
8395 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l
->ll_symbol
,
8396 loc_section_label
, NULL
);
8397 gcc_assert (l
->hash
== loc_list_idx
);
8399 l
->offset_emitted
= true;
8402 FOR_EACH_CHILD (die
, c
, output_loclists_offsets (c
));
8405 /* Recursively set indexes of location lists. */
8408 assign_location_list_indexes (dw_die_ref die
)
8414 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8415 if (AT_class (a
) == dw_val_class_loc_list
)
8417 dw_loc_list_ref list
= AT_loc_list (a
);
8418 if (!list
->num_assigned
)
8420 list
->num_assigned
= true;
8421 list
->hash
= loc_list_idx
++;
8425 FOR_EACH_CHILD (die
, c
, assign_location_list_indexes (c
));
8428 /* We want to limit the number of external references, because they are
8429 larger than local references: a relocation takes multiple words, and
8430 even a sig8 reference is always eight bytes, whereas a local reference
8431 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8432 So if we encounter multiple external references to the same type DIE, we
8433 make a local typedef stub for it and redirect all references there.
8435 This is the element of the hash table for keeping track of these
8445 /* Hashtable helpers. */
8447 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
8449 static inline hashval_t
hash (const external_ref
*);
8450 static inline bool equal (const external_ref
*, const external_ref
*);
8454 external_ref_hasher::hash (const external_ref
*r
)
8456 dw_die_ref die
= r
->type
;
8459 /* We can't use the address of the DIE for hashing, because
8460 that will make the order of the stub DIEs non-deterministic. */
8461 if (! die
->comdat_type_p
)
8462 /* We have a symbol; use it to compute a hash. */
8463 h
= htab_hash_string (die
->die_id
.die_symbol
);
8466 /* We have a type signature; use a subset of the bits as the hash.
8467 The 8-byte signature is at least as large as hashval_t. */
8468 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
8469 memcpy (&h
, type_node
->signature
, sizeof (h
));
8475 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
8477 return r1
->type
== r2
->type
;
8480 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
8482 /* Return a pointer to the external_ref for references to DIE. */
8484 static struct external_ref
*
8485 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
8487 struct external_ref ref
, *ref_p
;
8488 external_ref
**slot
;
8491 slot
= map
->find_slot (&ref
, INSERT
);
8492 if (*slot
!= HTAB_EMPTY_ENTRY
)
8495 ref_p
= XCNEW (struct external_ref
);
8501 /* Subroutine of optimize_external_refs, below.
8503 If we see a type skeleton, record it as our stub. If we see external
8504 references, remember how many we've seen. */
8507 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
8512 struct external_ref
*ref_p
;
8514 if (is_type_die (die
)
8515 && (c
= get_AT_ref (die
, DW_AT_signature
)))
8517 /* This is a local skeleton; use it for local references. */
8518 ref_p
= lookup_external_ref (map
, c
);
8522 /* Scan the DIE references, and remember any that refer to DIEs from
8523 other CUs (i.e. those which are not marked). */
8524 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8525 if (AT_class (a
) == dw_val_class_die_ref
8526 && (c
= AT_ref (a
))->die_mark
== 0
8529 ref_p
= lookup_external_ref (map
, c
);
8533 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
8536 /* htab_traverse callback function for optimize_external_refs, below. SLOT
8537 points to an external_ref, DATA is the CU we're processing. If we don't
8538 already have a local stub, and we have multiple refs, build a stub. */
8541 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
8543 struct external_ref
*ref_p
= *slot
;
8545 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
8547 /* We have multiple references to this type, so build a small stub.
8548 Both of these forms are a bit dodgy from the perspective of the
8549 DWARF standard, since technically they should have names. */
8550 dw_die_ref cu
= data
;
8551 dw_die_ref type
= ref_p
->type
;
8552 dw_die_ref stub
= NULL
;
8554 if (type
->comdat_type_p
)
8556 /* If we refer to this type via sig8, use AT_signature. */
8557 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
8558 add_AT_die_ref (stub
, DW_AT_signature
, type
);
8562 /* Otherwise, use a typedef with no name. */
8563 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
8564 add_AT_die_ref (stub
, DW_AT_type
, type
);
8573 /* DIE is a unit; look through all the DIE references to see if there are
8574 any external references to types, and if so, create local stubs for
8575 them which will be applied in build_abbrev_table. This is useful because
8576 references to local DIEs are smaller. */
8578 static external_ref_hash_type
*
8579 optimize_external_refs (dw_die_ref die
)
8581 external_ref_hash_type
*map
= new external_ref_hash_type (10);
8582 optimize_external_refs_1 (die
, map
);
8583 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
8587 /* The following 3 variables are temporaries that are computed only during the
8588 build_abbrev_table call and used and released during the following
8589 optimize_abbrev_table call. */
8591 /* First abbrev_id that can be optimized based on usage. */
8592 static unsigned int abbrev_opt_start
;
8594 /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
8595 abbrev_id smaller than this, because they must be already sized
8596 during build_abbrev_table). */
8597 static unsigned int abbrev_opt_base_type_end
;
8599 /* Vector of usage counts during build_abbrev_table. Indexed by
8600 abbrev_id - abbrev_opt_start. */
8601 static vec
<unsigned int> abbrev_usage_count
;
8603 /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
8604 static vec
<dw_die_ref
> sorted_abbrev_dies
;
8606 /* The format of each DIE (and its attribute value pairs) is encoded in an
8607 abbreviation table. This routine builds the abbreviation table and assigns
8608 a unique abbreviation id for each abbreviation entry. The children of each
8609 die are visited recursively. */
8612 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
8614 unsigned int abbrev_id
= 0;
8620 /* Scan the DIE references, and replace any that refer to
8621 DIEs from other CUs (i.e. those which are not marked) with
8622 the local stubs we built in optimize_external_refs. */
8623 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8624 if (AT_class (a
) == dw_val_class_die_ref
8625 && (c
= AT_ref (a
))->die_mark
== 0)
8627 struct external_ref
*ref_p
;
8628 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8630 ref_p
= lookup_external_ref (extern_map
, c
);
8631 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8632 change_AT_die_ref (a
, ref_p
->stub
);
8634 /* We aren't changing this reference, so mark it external. */
8635 set_AT_ref_external (a
, 1);
8638 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
8640 dw_attr_node
*die_a
, *abbrev_a
;
8646 if (abbrev
->die_tag
!= die
->die_tag
)
8648 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8651 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8654 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8656 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8657 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8658 || (value_format (abbrev_a
) != value_format (die_a
)))
8668 if (abbrev_id
>= vec_safe_length (abbrev_die_table
))
8670 vec_safe_push (abbrev_die_table
, die
);
8671 if (abbrev_opt_start
)
8672 abbrev_usage_count
.safe_push (0);
8674 if (abbrev_opt_start
&& abbrev_id
>= abbrev_opt_start
)
8676 abbrev_usage_count
[abbrev_id
- abbrev_opt_start
]++;
8677 sorted_abbrev_dies
.safe_push (die
);
8680 die
->die_abbrev
= abbrev_id
;
8681 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8684 /* Callback function for sorted_abbrev_dies vector sorting. We sort
8685 by die_abbrev's usage count, from the most commonly used
8686 abbreviation to the least. */
8689 die_abbrev_cmp (const void *p1
, const void *p2
)
8691 dw_die_ref die1
= *(const dw_die_ref
*) p1
;
8692 dw_die_ref die2
= *(const dw_die_ref
*) p2
;
8694 gcc_checking_assert (die1
->die_abbrev
>= abbrev_opt_start
);
8695 gcc_checking_assert (die2
->die_abbrev
>= abbrev_opt_start
);
8697 if (die1
->die_abbrev
>= abbrev_opt_base_type_end
8698 && die2
->die_abbrev
>= abbrev_opt_base_type_end
)
8700 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8701 > abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8703 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8704 < abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8708 /* Stabilize the sort. */
8709 if (die1
->die_abbrev
< die2
->die_abbrev
)
8711 if (die1
->die_abbrev
> die2
->die_abbrev
)
8717 /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
8718 of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
8719 into dw_val_class_const_implicit or
8720 dw_val_class_unsigned_const_implicit. */
8723 optimize_implicit_const (unsigned int first_id
, unsigned int end
,
8724 vec
<bool> &implicit_consts
)
8726 /* It never makes sense if there is just one DIE using the abbreviation. */
8727 if (end
< first_id
+ 2)
8732 dw_die_ref die
= sorted_abbrev_dies
[first_id
];
8733 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8734 if (implicit_consts
[ix
])
8736 enum dw_val_class new_class
= dw_val_class_none
;
8737 switch (AT_class (a
))
8739 case dw_val_class_unsigned_const
:
8740 if ((HOST_WIDE_INT
) AT_unsigned (a
) < 0)
8743 /* The .debug_abbrev section will grow by
8744 size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
8745 in all the DIEs using that abbreviation. */
8746 if (constant_size (AT_unsigned (a
)) * (end
- first_id
)
8747 <= (unsigned) size_of_sleb128 (AT_unsigned (a
)))
8750 new_class
= dw_val_class_unsigned_const_implicit
;
8753 case dw_val_class_const
:
8754 new_class
= dw_val_class_const_implicit
;
8757 case dw_val_class_file
:
8758 new_class
= dw_val_class_file_implicit
;
8764 for (i
= first_id
; i
< end
; i
++)
8765 (*sorted_abbrev_dies
[i
]->die_attr
)[ix
].dw_attr_val
.val_class
8770 /* Attempt to optimize abbreviation table from abbrev_opt_start
8771 abbreviation above. */
8774 optimize_abbrev_table (void)
8776 if (abbrev_opt_start
8777 && vec_safe_length (abbrev_die_table
) > abbrev_opt_start
8778 && (dwarf_version
>= 5 || vec_safe_length (abbrev_die_table
) > 127))
8780 auto_vec
<bool, 32> implicit_consts
;
8781 sorted_abbrev_dies
.qsort (die_abbrev_cmp
);
8783 unsigned int abbrev_id
= abbrev_opt_start
- 1;
8784 unsigned int first_id
= ~0U;
8785 unsigned int last_abbrev_id
= 0;
8788 if (abbrev_opt_base_type_end
> abbrev_opt_start
)
8789 abbrev_id
= abbrev_opt_base_type_end
- 1;
8790 /* Reassign abbreviation ids from abbrev_opt_start above, so that
8791 most commonly used abbreviations come first. */
8792 FOR_EACH_VEC_ELT (sorted_abbrev_dies
, i
, die
)
8797 /* If calc_base_type_die_sizes has been called, the CU and
8798 base types after it can't be optimized, because we've already
8799 calculated their DIE offsets. We've sorted them first. */
8800 if (die
->die_abbrev
< abbrev_opt_base_type_end
)
8802 if (die
->die_abbrev
!= last_abbrev_id
)
8804 last_abbrev_id
= die
->die_abbrev
;
8805 if (dwarf_version
>= 5 && first_id
!= ~0U)
8806 optimize_implicit_const (first_id
, i
, implicit_consts
);
8808 (*abbrev_die_table
)[abbrev_id
] = die
;
8809 if (dwarf_version
>= 5)
8812 implicit_consts
.truncate (0);
8814 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8815 switch (AT_class (a
))
8817 case dw_val_class_const
:
8818 case dw_val_class_unsigned_const
:
8819 case dw_val_class_file
:
8820 implicit_consts
.safe_push (true);
8823 implicit_consts
.safe_push (false);
8828 else if (dwarf_version
>= 5)
8830 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8831 if (!implicit_consts
[ix
])
8835 dw_attr_node
*other_a
8836 = &(*(*abbrev_die_table
)[abbrev_id
]->die_attr
)[ix
];
8837 if (!dw_val_equal_p (&a
->dw_attr_val
,
8838 &other_a
->dw_attr_val
))
8839 implicit_consts
[ix
] = false;
8842 die
->die_abbrev
= abbrev_id
;
8844 gcc_assert (abbrev_id
== vec_safe_length (abbrev_die_table
) - 1);
8845 if (dwarf_version
>= 5 && first_id
!= ~0U)
8846 optimize_implicit_const (first_id
, i
, implicit_consts
);
8849 abbrev_opt_start
= 0;
8850 abbrev_opt_base_type_end
= 0;
8851 abbrev_usage_count
.release ();
8852 sorted_abbrev_dies
.release ();
8855 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8858 constant_size (unsigned HOST_WIDE_INT value
)
8865 log
= floor_log2 (value
);
8868 log
= 1 << (floor_log2 (log
) + 1);
8873 /* Return the size of a DIE as it is represented in the
8874 .debug_info section. */
8876 static unsigned long
8877 size_of_die (dw_die_ref die
)
8879 unsigned long size
= 0;
8882 enum dwarf_form form
;
8884 size
+= size_of_uleb128 (die
->die_abbrev
);
8885 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8887 switch (AT_class (a
))
8889 case dw_val_class_addr
:
8890 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8892 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8893 size
+= size_of_uleb128 (AT_index (a
));
8896 size
+= DWARF2_ADDR_SIZE
;
8898 case dw_val_class_offset
:
8899 size
+= DWARF_OFFSET_SIZE
;
8901 case dw_val_class_loc
:
8903 unsigned long lsize
= size_of_locs (AT_loc (a
));
8906 if (dwarf_version
>= 4)
8907 size
+= size_of_uleb128 (lsize
);
8909 size
+= constant_size (lsize
);
8913 case dw_val_class_loc_list
:
8914 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
8916 gcc_assert (AT_loc_list (a
)->num_assigned
);
8917 size
+= size_of_uleb128 (AT_loc_list (a
)->hash
);
8920 size
+= DWARF_OFFSET_SIZE
;
8922 case dw_val_class_range_list
:
8923 if (value_format (a
) == DW_FORM_rnglistx
)
8925 gcc_assert (rnglist_idx
);
8926 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
8927 size
+= size_of_uleb128 (r
->idx
);
8930 size
+= DWARF_OFFSET_SIZE
;
8932 case dw_val_class_const
:
8933 size
+= size_of_sleb128 (AT_int (a
));
8935 case dw_val_class_unsigned_const
:
8937 int csize
= constant_size (AT_unsigned (a
));
8938 if (dwarf_version
== 3
8939 && a
->dw_attr
== DW_AT_data_member_location
8941 size
+= size_of_uleb128 (AT_unsigned (a
));
8946 case dw_val_class_const_implicit
:
8947 case dw_val_class_unsigned_const_implicit
:
8948 case dw_val_class_file_implicit
:
8949 /* These occupy no size in the DIE, just an extra sleb128 in
8952 case dw_val_class_const_double
:
8953 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
8954 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
8957 case dw_val_class_wide_int
:
8958 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8959 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
8960 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8961 * HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
8964 case dw_val_class_vec
:
8965 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
8966 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
8967 + a
->dw_attr_val
.v
.val_vec
.length
8968 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
8970 case dw_val_class_flag
:
8971 if (dwarf_version
>= 4)
8972 /* Currently all add_AT_flag calls pass in 1 as last argument,
8973 so DW_FORM_flag_present can be used. If that ever changes,
8974 we'll need to use DW_FORM_flag and have some optimization
8975 in build_abbrev_table that will change those to
8976 DW_FORM_flag_present if it is set to 1 in all DIEs using
8977 the same abbrev entry. */
8978 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8982 case dw_val_class_die_ref
:
8983 if (AT_ref_external (a
))
8985 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8986 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8987 is sized by target address length, whereas in DWARF3
8988 it's always sized as an offset. */
8989 if (use_debug_types
)
8990 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
8991 else if (dwarf_version
== 2)
8992 size
+= DWARF2_ADDR_SIZE
;
8994 size
+= DWARF_OFFSET_SIZE
;
8997 size
+= DWARF_OFFSET_SIZE
;
8999 case dw_val_class_fde_ref
:
9000 size
+= DWARF_OFFSET_SIZE
;
9002 case dw_val_class_lbl_id
:
9003 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9005 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9006 size
+= size_of_uleb128 (AT_index (a
));
9009 size
+= DWARF2_ADDR_SIZE
;
9011 case dw_val_class_lineptr
:
9012 case dw_val_class_macptr
:
9013 case dw_val_class_loclistsptr
:
9014 size
+= DWARF_OFFSET_SIZE
;
9016 case dw_val_class_str
:
9017 form
= AT_string_form (a
);
9018 if (form
== DW_FORM_strp
|| form
== DW_FORM_line_strp
)
9019 size
+= DWARF_OFFSET_SIZE
;
9020 else if (form
== DW_FORM_GNU_str_index
)
9021 size
+= size_of_uleb128 (AT_index (a
));
9023 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
9025 case dw_val_class_file
:
9026 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
9028 case dw_val_class_data8
:
9031 case dw_val_class_vms_delta
:
9032 size
+= DWARF_OFFSET_SIZE
;
9034 case dw_val_class_high_pc
:
9035 size
+= DWARF2_ADDR_SIZE
;
9037 case dw_val_class_discr_value
:
9038 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
9040 case dw_val_class_discr_list
:
9042 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
9044 /* This is a block, so we have the block length and then its
9046 size
+= constant_size (block_size
) + block_size
;
9057 /* Size the debugging information associated with a given DIE. Visits the
9058 DIE's children recursively. Updates the global variable next_die_offset, on
9059 each time through. Uses the current value of next_die_offset to update the
9060 die_offset field in each DIE. */
9063 calc_die_sizes (dw_die_ref die
)
9067 gcc_assert (die
->die_offset
== 0
9068 || (unsigned long int) die
->die_offset
== next_die_offset
);
9069 die
->die_offset
= next_die_offset
;
9070 next_die_offset
+= size_of_die (die
);
9072 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
9074 if (die
->die_child
!= NULL
)
9075 /* Count the null byte used to terminate sibling lists. */
9076 next_die_offset
+= 1;
9079 /* Size just the base type children at the start of the CU.
9080 This is needed because build_abbrev needs to size locs
9081 and sizing of type based stack ops needs to know die_offset
9082 values for the base types. */
9085 calc_base_type_die_sizes (void)
9087 unsigned long die_offset
= (dwarf_split_debug_info
9088 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9089 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
9091 dw_die_ref base_type
;
9092 #if ENABLE_ASSERT_CHECKING
9093 dw_die_ref prev
= comp_unit_die ()->die_child
;
9096 die_offset
+= size_of_die (comp_unit_die ());
9097 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
9099 #if ENABLE_ASSERT_CHECKING
9100 gcc_assert (base_type
->die_offset
== 0
9101 && prev
->die_sib
== base_type
9102 && base_type
->die_child
== NULL
9103 && base_type
->die_abbrev
);
9106 if (abbrev_opt_start
9107 && base_type
->die_abbrev
>= abbrev_opt_base_type_end
)
9108 abbrev_opt_base_type_end
= base_type
->die_abbrev
+ 1;
9109 base_type
->die_offset
= die_offset
;
9110 die_offset
+= size_of_die (base_type
);
9114 /* Set the marks for a die and its children. We do this so
9115 that we know whether or not a reference needs to use FORM_ref_addr; only
9116 DIEs in the same CU will be marked. We used to clear out the offset
9117 and use that as the flag, but ran into ordering problems. */
9120 mark_dies (dw_die_ref die
)
9124 gcc_assert (!die
->die_mark
);
9127 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
9130 /* Clear the marks for a die and its children. */
9133 unmark_dies (dw_die_ref die
)
9137 if (! use_debug_types
)
9138 gcc_assert (die
->die_mark
);
9141 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
9144 /* Clear the marks for a die, its children and referred dies. */
9147 unmark_all_dies (dw_die_ref die
)
9157 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
9159 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9160 if (AT_class (a
) == dw_val_class_die_ref
)
9161 unmark_all_dies (AT_ref (a
));
9164 /* Calculate if the entry should appear in the final output file. It may be
9165 from a pruned a type. */
9168 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
9170 /* By limiting gnu pubnames to definitions only, gold can generate a
9171 gdb index without entries for declarations, which don't include
9172 enough information to be useful. */
9173 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
9176 if (table
== pubname_table
)
9178 /* Enumerator names are part of the pubname table, but the
9179 parent DW_TAG_enumeration_type die may have been pruned.
9180 Don't output them if that is the case. */
9181 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
9182 (p
->die
->die_parent
== NULL
9183 || !p
->die
->die_parent
->die_perennial_p
))
9186 /* Everything else in the pubname table is included. */
9190 /* The pubtypes table shouldn't include types that have been
9192 return (p
->die
->die_offset
!= 0
9193 || !flag_eliminate_unused_debug_types
);
9196 /* Return the size of the .debug_pubnames or .debug_pubtypes table
9197 generated for the compilation unit. */
9199 static unsigned long
9200 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9205 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
9207 size
= DWARF_PUBNAMES_HEADER_SIZE
;
9208 FOR_EACH_VEC_ELT (*names
, i
, p
)
9209 if (include_pubname_in_output (names
, p
))
9210 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
9212 size
+= DWARF_OFFSET_SIZE
;
9216 /* Return the size of the information in the .debug_aranges section. */
9218 static unsigned long
9219 size_of_aranges (void)
9223 size
= DWARF_ARANGES_HEADER_SIZE
;
9225 /* Count the address/length pair for this compilation unit. */
9226 if (text_section_used
)
9227 size
+= 2 * DWARF2_ADDR_SIZE
;
9228 if (cold_text_section_used
)
9229 size
+= 2 * DWARF2_ADDR_SIZE
;
9230 if (have_multiple_function_sections
)
9235 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9237 if (DECL_IGNORED_P (fde
->decl
))
9239 if (!fde
->in_std_section
)
9240 size
+= 2 * DWARF2_ADDR_SIZE
;
9241 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9242 size
+= 2 * DWARF2_ADDR_SIZE
;
9246 /* Count the two zero words used to terminated the address range table. */
9247 size
+= 2 * DWARF2_ADDR_SIZE
;
9251 /* Select the encoding of an attribute value. */
9253 static enum dwarf_form
9254 value_format (dw_attr_node
*a
)
9256 switch (AT_class (a
))
9258 case dw_val_class_addr
:
9259 /* Only very few attributes allow DW_FORM_addr. */
9264 case DW_AT_entry_pc
:
9265 case DW_AT_trampoline
:
9266 return (AT_index (a
) == NOT_INDEXED
9267 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9271 switch (DWARF2_ADDR_SIZE
)
9274 return DW_FORM_data1
;
9276 return DW_FORM_data2
;
9278 return DW_FORM_data4
;
9280 return DW_FORM_data8
;
9284 case dw_val_class_loc_list
:
9285 if (dwarf_split_debug_info
9286 && dwarf_version
>= 5
9287 && AT_loc_list (a
)->num_assigned
)
9288 return DW_FORM_loclistx
;
9290 case dw_val_class_range_list
:
9291 /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9292 but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9293 care about sizes of .debug* sections in shared libraries and
9294 executables and don't take into account relocations that affect just
9295 relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9296 table in the .debug_rnglists section. */
9297 if (dwarf_split_debug_info
9298 && dwarf_version
>= 5
9299 && AT_class (a
) == dw_val_class_range_list
9301 && a
->dw_attr_val
.val_entry
!= RELOCATED_OFFSET
)
9302 return DW_FORM_rnglistx
;
9303 if (dwarf_version
>= 4)
9304 return DW_FORM_sec_offset
;
9306 case dw_val_class_vms_delta
:
9307 case dw_val_class_offset
:
9308 switch (DWARF_OFFSET_SIZE
)
9311 return DW_FORM_data4
;
9313 return DW_FORM_data8
;
9317 case dw_val_class_loc
:
9318 if (dwarf_version
>= 4)
9319 return DW_FORM_exprloc
;
9320 switch (constant_size (size_of_locs (AT_loc (a
))))
9323 return DW_FORM_block1
;
9325 return DW_FORM_block2
;
9327 return DW_FORM_block4
;
9331 case dw_val_class_const
:
9332 return DW_FORM_sdata
;
9333 case dw_val_class_unsigned_const
:
9334 switch (constant_size (AT_unsigned (a
)))
9337 return DW_FORM_data1
;
9339 return DW_FORM_data2
;
9341 /* In DWARF3 DW_AT_data_member_location with
9342 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
9343 constant, so we need to use DW_FORM_udata if we need
9344 a large constant. */
9345 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9346 return DW_FORM_udata
;
9347 return DW_FORM_data4
;
9349 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9350 return DW_FORM_udata
;
9351 return DW_FORM_data8
;
9355 case dw_val_class_const_implicit
:
9356 case dw_val_class_unsigned_const_implicit
:
9357 case dw_val_class_file_implicit
:
9358 return DW_FORM_implicit_const
;
9359 case dw_val_class_const_double
:
9360 switch (HOST_BITS_PER_WIDE_INT
)
9363 return DW_FORM_data2
;
9365 return DW_FORM_data4
;
9367 return DW_FORM_data8
;
9369 if (dwarf_version
>= 5)
9370 return DW_FORM_data16
;
9373 return DW_FORM_block1
;
9375 case dw_val_class_wide_int
:
9376 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
9379 return DW_FORM_data1
;
9381 return DW_FORM_data2
;
9383 return DW_FORM_data4
;
9385 return DW_FORM_data8
;
9387 if (dwarf_version
>= 5)
9388 return DW_FORM_data16
;
9391 return DW_FORM_block1
;
9393 case dw_val_class_vec
:
9394 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
9395 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
9398 return DW_FORM_block1
;
9400 return DW_FORM_block2
;
9402 return DW_FORM_block4
;
9406 case dw_val_class_flag
:
9407 if (dwarf_version
>= 4)
9409 /* Currently all add_AT_flag calls pass in 1 as last argument,
9410 so DW_FORM_flag_present can be used. If that ever changes,
9411 we'll need to use DW_FORM_flag and have some optimization
9412 in build_abbrev_table that will change those to
9413 DW_FORM_flag_present if it is set to 1 in all DIEs using
9414 the same abbrev entry. */
9415 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9416 return DW_FORM_flag_present
;
9418 return DW_FORM_flag
;
9419 case dw_val_class_die_ref
:
9420 if (AT_ref_external (a
))
9421 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
9424 case dw_val_class_fde_ref
:
9425 return DW_FORM_data
;
9426 case dw_val_class_lbl_id
:
9427 return (AT_index (a
) == NOT_INDEXED
9428 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9429 case dw_val_class_lineptr
:
9430 case dw_val_class_macptr
:
9431 case dw_val_class_loclistsptr
:
9432 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
9433 case dw_val_class_str
:
9434 return AT_string_form (a
);
9435 case dw_val_class_file
:
9436 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
9439 return DW_FORM_data1
;
9441 return DW_FORM_data2
;
9443 return DW_FORM_data4
;
9448 case dw_val_class_data8
:
9449 return DW_FORM_data8
;
9451 case dw_val_class_high_pc
:
9452 switch (DWARF2_ADDR_SIZE
)
9455 return DW_FORM_data1
;
9457 return DW_FORM_data2
;
9459 return DW_FORM_data4
;
9461 return DW_FORM_data8
;
9466 case dw_val_class_discr_value
:
9467 return (a
->dw_attr_val
.v
.val_discr_value
.pos
9470 case dw_val_class_discr_list
:
9471 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
9474 return DW_FORM_block1
;
9476 return DW_FORM_block2
;
9478 return DW_FORM_block4
;
9488 /* Output the encoding of an attribute value. */
9491 output_value_format (dw_attr_node
*a
)
9493 enum dwarf_form form
= value_format (a
);
9495 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
9498 /* Given a die and id, produce the appropriate abbreviations. */
9501 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
9504 dw_attr_node
*a_attr
;
9506 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
9507 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
9508 dwarf_tag_name (abbrev
->die_tag
));
9510 if (abbrev
->die_child
!= NULL
)
9511 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
9513 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
9515 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
9517 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
9518 dwarf_attr_name (a_attr
->dw_attr
));
9519 output_value_format (a_attr
);
9520 if (value_format (a_attr
) == DW_FORM_implicit_const
)
9522 if (AT_class (a_attr
) == dw_val_class_file_implicit
)
9524 int f
= maybe_emit_file (a_attr
->dw_attr_val
.v
.val_file
);
9525 const char *filename
= a_attr
->dw_attr_val
.v
.val_file
->filename
;
9526 dw2_asm_output_data_sleb128 (f
, "(%s)", filename
);
9529 dw2_asm_output_data_sleb128 (a_attr
->dw_attr_val
.v
.val_int
, NULL
);
9533 dw2_asm_output_data (1, 0, NULL
);
9534 dw2_asm_output_data (1, 0, NULL
);
9538 /* Output the .debug_abbrev section which defines the DIE abbreviation
9542 output_abbrev_section (void)
9544 unsigned int abbrev_id
;
9547 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
9549 output_die_abbrevs (abbrev_id
, abbrev
);
9551 /* Terminate the table. */
9552 dw2_asm_output_data (1, 0, NULL
);
9555 /* Output a symbol we can use to refer to this DIE from another CU. */
9558 output_die_symbol (dw_die_ref die
)
9560 const char *sym
= die
->die_id
.die_symbol
;
9562 gcc_assert (!die
->comdat_type_p
);
9567 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
9568 /* We make these global, not weak; if the target doesn't support
9569 .linkonce, it doesn't support combining the sections, so debugging
9571 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
9573 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
9576 /* Return a new location list, given the begin and end range, and the
9579 static inline dw_loc_list_ref
9580 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
9581 const char *section
)
9583 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
9585 retlist
->begin
= begin
;
9586 retlist
->begin_entry
= NULL
;
9588 retlist
->expr
= expr
;
9589 retlist
->section
= section
;
9594 /* Generate a new internal symbol for this location list node, if it
9595 hasn't got one yet. */
9598 gen_llsym (dw_loc_list_ref list
)
9600 gcc_assert (!list
->ll_symbol
);
9601 list
->ll_symbol
= gen_internal_sym ("LLST");
9604 /* Output the location list given to us. */
9607 output_loc_list (dw_loc_list_ref list_head
)
9609 if (list_head
->emitted
)
9611 list_head
->emitted
= true;
9613 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
9615 dw_loc_list_ref curr
= list_head
;
9616 const char *last_section
= NULL
;
9617 const char *base_label
= NULL
;
9619 /* Walk the location list, and output each range + expression. */
9620 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
9623 /* Don't output an entry that starts and ends at the same address. */
9624 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
9626 size
= size_of_locs (curr
->expr
);
9627 /* If the expression is too large, drop it on the floor. We could
9628 perhaps put it into DW_TAG_dwarf_procedure and refer to that
9629 in the expression, but >= 64KB expressions for a single value
9630 in a single range are unlikely very useful. */
9631 if (dwarf_version
< 5 && size
> 0xffff)
9633 if (dwarf_version
>= 5)
9635 if (dwarf_split_debug_info
)
9637 /* For -gsplit-dwarf, emit DW_LLE_starx_length, which has
9638 uleb128 index into .debug_addr and uleb128 length. */
9639 dw2_asm_output_data (1, DW_LLE_startx_length
,
9640 "DW_LLE_startx_length (%s)",
9641 list_head
->ll_symbol
);
9642 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9643 "Location list range start index "
9644 "(%s)", curr
->begin
);
9645 /* FIXME: This will ICE ifndef HAVE_AS_LEB128.
9646 For that case we probably need to emit DW_LLE_startx_endx,
9647 but we'd need 2 .debug_addr entries rather than just one. */
9648 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9649 "Location list length (%s)",
9650 list_head
->ll_symbol
);
9652 else if (!have_multiple_function_sections
&& HAVE_AS_LEB128
)
9654 /* If all code is in .text section, the base address is
9655 already provided by the CU attributes. Use
9656 DW_LLE_offset_pair where both addresses are uleb128 encoded
9657 offsets against that base. */
9658 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9659 "DW_LLE_offset_pair (%s)",
9660 list_head
->ll_symbol
);
9661 dw2_asm_output_delta_uleb128 (curr
->begin
, curr
->section
,
9662 "Location list begin address (%s)",
9663 list_head
->ll_symbol
);
9664 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->section
,
9665 "Location list end address (%s)",
9666 list_head
->ll_symbol
);
9668 else if (HAVE_AS_LEB128
)
9670 /* Otherwise, find out how many consecutive entries could share
9671 the same base entry. If just one, emit DW_LLE_start_length,
9672 otherwise emit DW_LLE_base_address for the base address
9673 followed by a series of DW_LLE_offset_pair. */
9674 if (last_section
== NULL
|| curr
->section
!= last_section
)
9676 dw_loc_list_ref curr2
;
9677 for (curr2
= curr
->dw_loc_next
; curr2
!= NULL
;
9678 curr2
= curr2
->dw_loc_next
)
9680 if (strcmp (curr2
->begin
, curr2
->end
) == 0
9685 if (curr2
== NULL
|| curr
->section
!= curr2
->section
)
9686 last_section
= NULL
;
9689 last_section
= curr
->section
;
9690 base_label
= curr
->begin
;
9691 dw2_asm_output_data (1, DW_LLE_base_address
,
9692 "DW_LLE_base_address (%s)",
9693 list_head
->ll_symbol
);
9694 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, base_label
,
9695 "Base address (%s)",
9696 list_head
->ll_symbol
);
9699 /* Only one entry with the same base address. Use
9700 DW_LLE_start_length with absolute address and uleb128
9702 if (last_section
== NULL
)
9704 dw2_asm_output_data (1, DW_LLE_start_length
,
9705 "DW_LLE_start_length (%s)",
9706 list_head
->ll_symbol
);
9707 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9708 "Location list begin address (%s)",
9709 list_head
->ll_symbol
);
9710 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9711 "Location list length "
9712 "(%s)", list_head
->ll_symbol
);
9714 /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
9715 DW_LLE_base_address. */
9718 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9719 "DW_LLE_offset_pair (%s)",
9720 list_head
->ll_symbol
);
9721 dw2_asm_output_delta_uleb128 (curr
->begin
, base_label
,
9722 "Location list begin address "
9723 "(%s)", list_head
->ll_symbol
);
9724 dw2_asm_output_delta_uleb128 (curr
->end
, base_label
,
9725 "Location list end address "
9726 "(%s)", list_head
->ll_symbol
);
9729 /* The assembler does not support .uleb128 directive. Emit
9730 DW_LLE_start_end with a pair of absolute addresses. */
9733 dw2_asm_output_data (1, DW_LLE_start_end
,
9734 "DW_LLE_start_end (%s)",
9735 list_head
->ll_symbol
);
9736 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9737 "Location list begin address (%s)",
9738 list_head
->ll_symbol
);
9739 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9740 "Location list end address (%s)",
9741 list_head
->ll_symbol
);
9744 else if (dwarf_split_debug_info
)
9746 /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
9747 and 4 byte length. */
9748 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
9749 "Location list start/length entry (%s)",
9750 list_head
->ll_symbol
);
9751 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9752 "Location list range start index (%s)",
9754 /* The length field is 4 bytes. If we ever need to support
9755 an 8-byte length, we can add a new DW_LLE code or fall back
9756 to DW_LLE_GNU_start_end_entry. */
9757 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
9758 "Location list range length (%s)",
9759 list_head
->ll_symbol
);
9761 else if (!have_multiple_function_sections
)
9763 /* Pair of relative addresses against start of text section. */
9764 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
9765 "Location list begin address (%s)",
9766 list_head
->ll_symbol
);
9767 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
9768 "Location list end address (%s)",
9769 list_head
->ll_symbol
);
9773 /* Pair of absolute addresses. */
9774 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9775 "Location list begin address (%s)",
9776 list_head
->ll_symbol
);
9777 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9778 "Location list end address (%s)",
9779 list_head
->ll_symbol
);
9782 /* Output the block length for this list of location operations. */
9783 if (dwarf_version
>= 5)
9784 dw2_asm_output_data_uleb128 (size
, "Location expression size");
9787 gcc_assert (size
<= 0xffff);
9788 dw2_asm_output_data (2, size
, "Location expression size");
9791 output_loc_sequence (curr
->expr
, -1);
9794 /* And finally list termination. */
9795 if (dwarf_version
>= 5)
9796 dw2_asm_output_data (1, DW_LLE_end_of_list
,
9797 "DW_LLE_end_of_list (%s)", list_head
->ll_symbol
);
9798 else if (dwarf_split_debug_info
)
9799 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
9800 "Location list terminator (%s)",
9801 list_head
->ll_symbol
);
9804 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9805 "Location list terminator begin (%s)",
9806 list_head
->ll_symbol
);
9807 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9808 "Location list terminator end (%s)",
9809 list_head
->ll_symbol
);
9813 /* Output a range_list offset into the .debug_ranges or .debug_rnglists
9814 section. Emit a relocated reference if val_entry is NULL, otherwise,
9815 emit an indirect reference. */
9818 output_range_list_offset (dw_attr_node
*a
)
9820 const char *name
= dwarf_attr_name (a
->dw_attr
);
9822 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
9824 if (dwarf_version
>= 5)
9826 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9827 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, r
->label
,
9828 debug_ranges_section
, "%s", name
);
9832 char *p
= strchr (ranges_section_label
, '\0');
9833 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
9834 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
);
9835 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
9836 debug_ranges_section
, "%s", name
);
9840 else if (dwarf_version
>= 5)
9842 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9843 gcc_assert (rnglist_idx
);
9844 dw2_asm_output_data_uleb128 (r
->idx
, "%s", name
);
9847 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9848 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
,
9849 "%s (offset from %s)", name
, ranges_section_label
);
9852 /* Output the offset into the debug_loc section. */
9855 output_loc_list_offset (dw_attr_node
*a
)
9857 char *sym
= AT_loc_list (a
)->ll_symbol
;
9860 if (!dwarf_split_debug_info
)
9861 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
9862 "%s", dwarf_attr_name (a
->dw_attr
));
9863 else if (dwarf_version
>= 5)
9865 gcc_assert (AT_loc_list (a
)->num_assigned
);
9866 dw2_asm_output_data_uleb128 (AT_loc_list (a
)->hash
, "%s (%s)",
9867 dwarf_attr_name (a
->dw_attr
),
9871 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
9872 "%s", dwarf_attr_name (a
->dw_attr
));
9875 /* Output an attribute's index or value appropriately. */
9878 output_attr_index_or_value (dw_attr_node
*a
)
9880 const char *name
= dwarf_attr_name (a
->dw_attr
);
9882 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9884 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
9887 switch (AT_class (a
))
9889 case dw_val_class_addr
:
9890 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
9892 case dw_val_class_high_pc
:
9893 case dw_val_class_lbl_id
:
9894 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
9901 /* Output a type signature. */
9904 output_signature (const char *sig
, const char *name
)
9908 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9909 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
9912 /* Output a discriminant value. */
9915 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
9917 if (discr_value
->pos
)
9918 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
9920 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
9923 /* Output the DIE and its attributes. Called recursively to generate
9924 the definitions of each child DIE. */
9927 output_die (dw_die_ref die
)
9934 /* If someone in another CU might refer to us, set up a symbol for
9935 them to point to. */
9936 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
9937 output_die_symbol (die
);
9939 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
9940 (unsigned long)die
->die_offset
,
9941 dwarf_tag_name (die
->die_tag
));
9943 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9945 const char *name
= dwarf_attr_name (a
->dw_attr
);
9947 switch (AT_class (a
))
9949 case dw_val_class_addr
:
9950 output_attr_index_or_value (a
);
9953 case dw_val_class_offset
:
9954 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
9958 case dw_val_class_range_list
:
9959 output_range_list_offset (a
);
9962 case dw_val_class_loc
:
9963 size
= size_of_locs (AT_loc (a
));
9965 /* Output the block length for this list of location operations. */
9966 if (dwarf_version
>= 4)
9967 dw2_asm_output_data_uleb128 (size
, "%s", name
);
9969 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
9971 output_loc_sequence (AT_loc (a
), -1);
9974 case dw_val_class_const
:
9975 /* ??? It would be slightly more efficient to use a scheme like is
9976 used for unsigned constants below, but gdb 4.x does not sign
9977 extend. Gdb 5.x does sign extend. */
9978 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
9981 case dw_val_class_unsigned_const
:
9983 int csize
= constant_size (AT_unsigned (a
));
9984 if (dwarf_version
== 3
9985 && a
->dw_attr
== DW_AT_data_member_location
9987 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
9989 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
9993 case dw_val_class_const_implicit
:
9995 fprintf (asm_out_file
, "\t\t\t%s %s ("
9996 HOST_WIDE_INT_PRINT_DEC
")\n",
9997 ASM_COMMENT_START
, name
, AT_int (a
));
10000 case dw_val_class_unsigned_const_implicit
:
10001 if (flag_debug_asm
)
10002 fprintf (asm_out_file
, "\t\t\t%s %s ("
10003 HOST_WIDE_INT_PRINT_HEX
")\n",
10004 ASM_COMMENT_START
, name
, AT_unsigned (a
));
10007 case dw_val_class_const_double
:
10009 unsigned HOST_WIDE_INT first
, second
;
10011 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
10012 dw2_asm_output_data (1,
10013 HOST_BITS_PER_DOUBLE_INT
10014 / HOST_BITS_PER_CHAR
,
10017 if (WORDS_BIG_ENDIAN
)
10019 first
= a
->dw_attr_val
.v
.val_double
.high
;
10020 second
= a
->dw_attr_val
.v
.val_double
.low
;
10024 first
= a
->dw_attr_val
.v
.val_double
.low
;
10025 second
= a
->dw_attr_val
.v
.val_double
.high
;
10028 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10029 first
, "%s", name
);
10030 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10035 case dw_val_class_wide_int
:
10038 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
10039 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10040 if (len
* HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
10041 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
)
10044 if (WORDS_BIG_ENDIAN
)
10045 for (i
= len
- 1; i
>= 0; --i
)
10047 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10052 for (i
= 0; i
< len
; ++i
)
10054 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10061 case dw_val_class_vec
:
10063 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
10064 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
10068 dw2_asm_output_data (constant_size (len
* elt_size
),
10069 len
* elt_size
, "%s", name
);
10070 if (elt_size
> sizeof (HOST_WIDE_INT
))
10075 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
10077 i
++, p
+= elt_size
)
10078 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
10079 "fp or vector constant word %u", i
);
10083 case dw_val_class_flag
:
10084 if (dwarf_version
>= 4)
10086 /* Currently all add_AT_flag calls pass in 1 as last argument,
10087 so DW_FORM_flag_present can be used. If that ever changes,
10088 we'll need to use DW_FORM_flag and have some optimization
10089 in build_abbrev_table that will change those to
10090 DW_FORM_flag_present if it is set to 1 in all DIEs using
10091 the same abbrev entry. */
10092 gcc_assert (AT_flag (a
) == 1);
10093 if (flag_debug_asm
)
10094 fprintf (asm_out_file
, "\t\t\t%s %s\n",
10095 ASM_COMMENT_START
, name
);
10098 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
10101 case dw_val_class_loc_list
:
10102 output_loc_list_offset (a
);
10105 case dw_val_class_die_ref
:
10106 if (AT_ref_external (a
))
10108 if (AT_ref (a
)->comdat_type_p
)
10110 comdat_type_node
*type_node
10111 = AT_ref (a
)->die_id
.die_type_node
;
10113 gcc_assert (type_node
);
10114 output_signature (type_node
->signature
, name
);
10118 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
10122 /* In DWARF2, DW_FORM_ref_addr is sized by target address
10123 length, whereas in DWARF3 it's always sized as an
10125 if (dwarf_version
== 2)
10126 size
= DWARF2_ADDR_SIZE
;
10128 size
= DWARF_OFFSET_SIZE
;
10129 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
10135 gcc_assert (AT_ref (a
)->die_offset
);
10136 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
10141 case dw_val_class_fde_ref
:
10143 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
10145 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
10146 a
->dw_attr_val
.v
.val_fde_index
* 2);
10147 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
10152 case dw_val_class_vms_delta
:
10153 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
10154 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
10155 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10158 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
10159 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10164 case dw_val_class_lbl_id
:
10165 output_attr_index_or_value (a
);
10168 case dw_val_class_lineptr
:
10169 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10170 debug_line_section
, "%s", name
);
10173 case dw_val_class_macptr
:
10174 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10175 debug_macinfo_section
, "%s", name
);
10178 case dw_val_class_loclistsptr
:
10179 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10180 debug_loc_section
, "%s", name
);
10183 case dw_val_class_str
:
10184 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
10185 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10186 a
->dw_attr_val
.v
.val_str
->label
,
10188 "%s: \"%s\"", name
, AT_string (a
));
10189 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_line_strp
)
10190 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10191 a
->dw_attr_val
.v
.val_str
->label
,
10192 debug_line_str_section
,
10193 "%s: \"%s\"", name
, AT_string (a
));
10194 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
10195 dw2_asm_output_data_uleb128 (AT_index (a
),
10196 "%s: \"%s\"", name
, AT_string (a
));
10198 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
10201 case dw_val_class_file
:
10203 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
10205 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
10206 a
->dw_attr_val
.v
.val_file
->filename
);
10210 case dw_val_class_file_implicit
:
10211 if (flag_debug_asm
)
10212 fprintf (asm_out_file
, "\t\t\t%s %s (%d, %s)\n",
10213 ASM_COMMENT_START
, name
,
10214 maybe_emit_file (a
->dw_attr_val
.v
.val_file
),
10215 a
->dw_attr_val
.v
.val_file
->filename
);
10218 case dw_val_class_data8
:
10222 for (i
= 0; i
< 8; i
++)
10223 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
10224 i
== 0 ? "%s" : NULL
, name
);
10228 case dw_val_class_high_pc
:
10229 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
10230 get_AT_low_pc (die
), "DW_AT_high_pc");
10233 case dw_val_class_discr_value
:
10234 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
10237 case dw_val_class_discr_list
:
10239 dw_discr_list_ref list
= AT_discr_list (a
);
10240 const int size
= size_of_discr_list (list
);
10242 /* This is a block, so output its length first. */
10243 dw2_asm_output_data (constant_size (size
), size
,
10244 "%s: block size", name
);
10246 for (; list
!= NULL
; list
= list
->dw_discr_next
)
10248 /* One byte for the discriminant value descriptor, and then as
10249 many LEB128 numbers as required. */
10250 if (list
->dw_discr_range
)
10251 dw2_asm_output_data (1, DW_DSC_range
,
10252 "%s: DW_DSC_range", name
);
10254 dw2_asm_output_data (1, DW_DSC_label
,
10255 "%s: DW_DSC_label", name
);
10257 output_discr_value (&list
->dw_discr_lower_bound
, name
);
10258 if (list
->dw_discr_range
)
10259 output_discr_value (&list
->dw_discr_upper_bound
, name
);
10265 gcc_unreachable ();
10269 FOR_EACH_CHILD (die
, c
, output_die (c
));
10271 /* Add null byte to terminate sibling list. */
10272 if (die
->die_child
!= NULL
)
10273 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
10274 (unsigned long) die
->die_offset
);
10277 /* Output the compilation unit that appears at the beginning of the
10278 .debug_info section, and precedes the DIE descriptions. */
10281 output_compilation_unit_header (enum dwarf_unit_type ut
)
10283 if (!XCOFF_DEBUGGING_INFO
)
10285 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10286 dw2_asm_output_data (4, 0xffffffff,
10287 "Initial length escape value indicating 64-bit DWARF extension");
10288 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10289 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
10290 "Length of Compilation Unit Info");
10293 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10294 if (dwarf_version
>= 5)
10299 case DW_UT_compile
: name
= "DW_UT_compile"; break;
10300 case DW_UT_type
: name
= "DW_UT_type"; break;
10301 case DW_UT_split_compile
: name
= "DW_UT_split_compile"; break;
10302 case DW_UT_split_type
: name
= "DW_UT_split_type"; break;
10303 default: gcc_unreachable ();
10305 dw2_asm_output_data (1, ut
, "%s", name
);
10306 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10308 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
10309 debug_abbrev_section
,
10310 "Offset Into Abbrev. Section");
10311 if (dwarf_version
< 5)
10312 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10315 /* Output the compilation unit DIE and its children. */
10318 output_comp_unit (dw_die_ref die
, int output_if_empty
,
10319 const unsigned char *dwo_id
)
10321 const char *secname
, *oldsym
;
10324 /* Unless we are outputting main CU, we may throw away empty ones. */
10325 if (!output_if_empty
&& die
->die_child
== NULL
)
10328 /* Even if there are no children of this DIE, we must output the information
10329 about the compilation unit. Otherwise, on an empty translation unit, we
10330 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
10331 will then complain when examining the file. First mark all the DIEs in
10332 this CU so we know which get local refs. */
10335 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
10337 /* For now, optimize only the main CU, in order to optimize the rest
10338 we'd need to see all of them earlier. Leave the rest for post-linking
10340 if (die
== comp_unit_die ())
10341 abbrev_opt_start
= vec_safe_length (abbrev_die_table
);
10343 build_abbrev_table (die
, extern_map
);
10345 optimize_abbrev_table ();
10349 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10350 next_die_offset
= (dwo_id
10351 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10352 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
10353 calc_die_sizes (die
);
10355 oldsym
= die
->die_id
.die_symbol
;
10358 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
10360 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
10362 die
->die_id
.die_symbol
= NULL
;
10363 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10367 switch_to_section (debug_info_section
);
10368 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
10369 info_section_emitted
= true;
10372 /* Output debugging information. */
10373 output_compilation_unit_header (dwo_id
10374 ? DW_UT_split_compile
: DW_UT_compile
);
10375 if (dwarf_version
>= 5)
10377 if (dwo_id
!= NULL
)
10378 for (int i
= 0; i
< 8; i
++)
10379 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10383 /* Leave the marks on the main CU, so we can check them in
10384 output_pubnames. */
10388 die
->die_id
.die_symbol
= oldsym
;
10392 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
10393 and .debug_pubtypes. This is configured per-target, but can be
10394 overridden by the -gpubnames or -gno-pubnames options. */
10397 want_pubnames (void)
10399 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10401 if (debug_generate_pub_sections
!= -1)
10402 return debug_generate_pub_sections
;
10403 return targetm
.want_debug_pub_sections
;
10406 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
10409 add_AT_pubnames (dw_die_ref die
)
10411 if (want_pubnames ())
10412 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
10415 /* Add a string attribute value to a skeleton DIE. */
10418 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
10422 struct indirect_string_node
*node
;
10424 if (! skeleton_debug_str_hash
)
10425 skeleton_debug_str_hash
10426 = hash_table
<indirect_string_hasher
>::create_ggc (10);
10428 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
10429 find_string_form (node
);
10430 if (node
->form
== DW_FORM_GNU_str_index
)
10431 node
->form
= DW_FORM_strp
;
10433 attr
.dw_attr
= attr_kind
;
10434 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
10435 attr
.dw_attr_val
.val_entry
= NULL
;
10436 attr
.dw_attr_val
.v
.val_str
= node
;
10437 add_dwarf_attr (die
, &attr
);
10440 /* Helper function to generate top-level dies for skeleton debug_info and
10444 add_top_level_skeleton_die_attrs (dw_die_ref die
)
10446 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
10447 const char *comp_dir
= comp_dir_string ();
10449 add_skeleton_AT_string (die
, dwarf_AT (DW_AT_dwo_name
), dwo_file_name
);
10450 if (comp_dir
!= NULL
)
10451 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
10452 add_AT_pubnames (die
);
10453 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
10456 /* Output skeleton debug sections that point to the dwo file. */
10459 output_skeleton_debug_sections (dw_die_ref comp_unit
,
10460 const unsigned char *dwo_id
)
10462 /* These attributes will be found in the full debug_info section. */
10463 remove_AT (comp_unit
, DW_AT_producer
);
10464 remove_AT (comp_unit
, DW_AT_language
);
10466 switch_to_section (debug_skeleton_info_section
);
10467 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
10469 /* Produce the skeleton compilation-unit header. This one differs enough from
10470 a normal CU header that it's better not to call output_compilation_unit
10472 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10473 dw2_asm_output_data (4, 0xffffffff,
10474 "Initial length escape value indicating 64-bit "
10475 "DWARF extension");
10477 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10478 DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10479 - DWARF_INITIAL_LENGTH_SIZE
10480 + size_of_die (comp_unit
),
10481 "Length of Compilation Unit Info");
10482 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10483 if (dwarf_version
>= 5)
10485 dw2_asm_output_data (1, DW_UT_skeleton
, "DW_UT_skeleton");
10486 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10488 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
10489 debug_skeleton_abbrev_section
,
10490 "Offset Into Abbrev. Section");
10491 if (dwarf_version
< 5)
10492 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10494 for (int i
= 0; i
< 8; i
++)
10495 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10497 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
10498 output_die (comp_unit
);
10500 /* Build the skeleton debug_abbrev section. */
10501 switch_to_section (debug_skeleton_abbrev_section
);
10502 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
10504 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
10506 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
10509 /* Output a comdat type unit DIE and its children. */
10512 output_comdat_type_unit (comdat_type_node
*node
)
10514 const char *secname
;
10517 #if defined (OBJECT_FORMAT_ELF)
10521 /* First mark all the DIEs in this CU so we know which get local refs. */
10522 mark_dies (node
->root_die
);
10524 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
10526 build_abbrev_table (node
->root_die
, extern_map
);
10531 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10532 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
10533 calc_die_sizes (node
->root_die
);
10535 #if defined (OBJECT_FORMAT_ELF)
10536 if (dwarf_version
>= 5)
10538 if (!dwarf_split_debug_info
)
10539 secname
= ".debug_info";
10541 secname
= ".debug_info.dwo";
10543 else if (!dwarf_split_debug_info
)
10544 secname
= ".debug_types";
10546 secname
= ".debug_types.dwo";
10548 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10549 sprintf (tmp
, dwarf_version
>= 5 ? "wi." : "wt.");
10550 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10551 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10552 comdat_key
= get_identifier (tmp
);
10553 targetm
.asm_out
.named_section (secname
,
10554 SECTION_DEBUG
| SECTION_LINKONCE
,
10557 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10558 sprintf (tmp
, (dwarf_version
>= 5
10559 ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
10560 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10561 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10563 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10566 /* Output debugging information. */
10567 output_compilation_unit_header (dwarf_split_debug_info
10568 ? DW_UT_split_type
: DW_UT_type
);
10569 output_signature (node
->signature
, "Type Signature");
10570 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
10571 "Offset to Type DIE");
10572 output_die (node
->root_die
);
10574 unmark_dies (node
->root_die
);
10577 /* Return the DWARF2/3 pubname associated with a decl. */
10579 static const char *
10580 dwarf2_name (tree decl
, int scope
)
10582 if (DECL_NAMELESS (decl
))
10584 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
10587 /* Add a new entry to .debug_pubnames if appropriate. */
10590 add_pubname_string (const char *str
, dw_die_ref die
)
10595 e
.name
= xstrdup (str
);
10596 vec_safe_push (pubname_table
, e
);
10600 add_pubname (tree decl
, dw_die_ref die
)
10602 if (!want_pubnames ())
10605 /* Don't add items to the table when we expect that the consumer will have
10606 just read the enclosing die. For example, if the consumer is looking at a
10607 class_member, it will either be inside the class already, or will have just
10608 looked up the class to find the member. Either way, searching the class is
10609 faster than searching the index. */
10610 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
10611 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10613 const char *name
= dwarf2_name (decl
, 1);
10616 add_pubname_string (name
, die
);
10620 /* Add an enumerator to the pubnames section. */
10623 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
10627 gcc_assert (scope_name
);
10628 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
10630 vec_safe_push (pubname_table
, e
);
10633 /* Add a new entry to .debug_pubtypes if appropriate. */
10636 add_pubtype (tree decl
, dw_die_ref die
)
10640 if (!want_pubnames ())
10643 if ((TREE_PUBLIC (decl
)
10644 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10645 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
10648 const char *scope_name
= "";
10649 const char *sep
= is_cxx () ? "::" : ".";
10652 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
10653 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
10655 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
10656 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
10657 scope_name
= concat (scope_name
, sep
, NULL
);
10663 name
= type_tag (decl
);
10665 name
= lang_hooks
.dwarf_name (decl
, 1);
10667 /* If we don't have a name for the type, there's no point in adding
10668 it to the table. */
10669 if (name
!= NULL
&& name
[0] != '\0')
10672 e
.name
= concat (scope_name
, name
, NULL
);
10673 vec_safe_push (pubtype_table
, e
);
10676 /* Although it might be more consistent to add the pubinfo for the
10677 enumerators as their dies are created, they should only be added if the
10678 enum type meets the criteria above. So rather than re-check the parent
10679 enum type whenever an enumerator die is created, just output them all
10680 here. This isn't protected by the name conditional because anonymous
10681 enums don't have names. */
10682 if (die
->die_tag
== DW_TAG_enumeration_type
)
10686 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
10691 /* Output a single entry in the pubnames table. */
10694 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
10696 dw_die_ref die
= entry
->die
;
10697 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
10699 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
10701 if (debug_generate_pub_sections
== 2)
10703 /* This logic follows gdb's method for determining the value of the flag
10705 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
10706 switch (die
->die_tag
)
10708 case DW_TAG_typedef
:
10709 case DW_TAG_base_type
:
10710 case DW_TAG_subrange_type
:
10711 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10712 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10714 case DW_TAG_enumerator
:
10715 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10716 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10717 if (!is_cxx () && !is_java ())
10718 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10720 case DW_TAG_subprogram
:
10721 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10722 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
10724 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10726 case DW_TAG_constant
:
10727 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10728 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10729 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10731 case DW_TAG_variable
:
10732 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10733 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10734 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10736 case DW_TAG_namespace
:
10737 case DW_TAG_imported_declaration
:
10738 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10740 case DW_TAG_class_type
:
10741 case DW_TAG_interface_type
:
10742 case DW_TAG_structure_type
:
10743 case DW_TAG_union_type
:
10744 case DW_TAG_enumeration_type
:
10745 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10746 if (!is_cxx () && !is_java ())
10747 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10750 /* An unusual tag. Leave the flag-byte empty. */
10753 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
10754 "GDB-index flags");
10757 dw2_asm_output_nstring (entry
->name
, -1, "external name");
10761 /* Output the public names table used to speed up access to externally
10762 visible names; or the public types table used to find type definitions. */
10765 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
10768 unsigned long pubnames_length
= size_of_pubnames (names
);
10769 pubname_entry
*pub
;
10771 if (!XCOFF_DEBUGGING_INFO
)
10773 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10774 dw2_asm_output_data (4, 0xffffffff,
10775 "Initial length escape value indicating 64-bit DWARF extension");
10776 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
10777 "Pub Info Length");
10780 /* Version number for pubnames/pubtypes is independent of dwarf version. */
10781 dw2_asm_output_data (2, 2, "DWARF Version");
10783 if (dwarf_split_debug_info
)
10784 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10785 debug_skeleton_info_section
,
10786 "Offset of Compilation Unit Info");
10788 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10789 debug_info_section
,
10790 "Offset of Compilation Unit Info");
10791 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
10792 "Compilation Unit Length");
10794 FOR_EACH_VEC_ELT (*names
, i
, pub
)
10796 if (include_pubname_in_output (names
, pub
))
10798 dw_offset die_offset
= pub
->die
->die_offset
;
10800 /* We shouldn't see pubnames for DIEs outside of the main CU. */
10801 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
10802 gcc_assert (pub
->die
->die_mark
);
10804 /* If we're putting types in their own .debug_types sections,
10805 the .debug_pubtypes table will still point to the compile
10806 unit (not the type unit), so we want to use the offset of
10807 the skeleton DIE (if there is one). */
10808 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
10810 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
10812 if (type_node
!= NULL
)
10813 die_offset
= (type_node
->skeleton_die
!= NULL
10814 ? type_node
->skeleton_die
->die_offset
10815 : comp_unit_die ()->die_offset
);
10818 output_pubname (die_offset
, pub
);
10822 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
10825 /* Output public names and types tables if necessary. */
10828 output_pubtables (void)
10830 if (!want_pubnames () || !info_section_emitted
)
10833 switch_to_section (debug_pubnames_section
);
10834 output_pubnames (pubname_table
);
10835 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
10836 It shouldn't hurt to emit it always, since pure DWARF2 consumers
10837 simply won't look for the section. */
10838 switch_to_section (debug_pubtypes_section
);
10839 output_pubnames (pubtype_table
);
10843 /* Output the information that goes into the .debug_aranges table.
10844 Namely, define the beginning and ending address range of the
10845 text section generated for this compilation unit. */
10848 output_aranges (void)
10851 unsigned long aranges_length
= size_of_aranges ();
10853 if (!XCOFF_DEBUGGING_INFO
)
10855 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10856 dw2_asm_output_data (4, 0xffffffff,
10857 "Initial length escape value indicating 64-bit DWARF extension");
10858 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
10859 "Length of Address Ranges Info");
10862 /* Version number for aranges is still 2, even up to DWARF5. */
10863 dw2_asm_output_data (2, 2, "DWARF Version");
10864 if (dwarf_split_debug_info
)
10865 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10866 debug_skeleton_info_section
,
10867 "Offset of Compilation Unit Info");
10869 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10870 debug_info_section
,
10871 "Offset of Compilation Unit Info");
10872 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
10873 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
10875 /* We need to align to twice the pointer size here. */
10876 if (DWARF_ARANGES_PAD_SIZE
)
10878 /* Pad using a 2 byte words so that padding is correct for any
10880 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
10881 2 * DWARF2_ADDR_SIZE
);
10882 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
10883 dw2_asm_output_data (2, 0, NULL
);
10886 /* It is necessary not to output these entries if the sections were
10887 not used; if the sections were not used, the length will be 0 and
10888 the address may end up as 0 if the section is discarded by ld
10889 --gc-sections, leaving an invalid (0, 0) entry that can be
10890 confused with the terminator. */
10891 if (text_section_used
)
10893 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
10894 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
10895 text_section_label
, "Length");
10897 if (cold_text_section_used
)
10899 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
10901 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
10902 cold_text_section_label
, "Length");
10905 if (have_multiple_function_sections
)
10910 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
10912 if (DECL_IGNORED_P (fde
->decl
))
10914 if (!fde
->in_std_section
)
10916 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
10918 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
10919 fde
->dw_fde_begin
, "Length");
10921 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
10923 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
10925 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
10926 fde
->dw_fde_second_begin
, "Length");
10931 /* Output the terminator words. */
10932 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10933 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10936 /* Add a new entry to .debug_ranges. Return its index into
10937 ranges_table vector. */
10939 static unsigned int
10940 add_ranges_num (int num
, bool maybe_new_sec
)
10942 dw_ranges r
= { NULL
, num
, 0, maybe_new_sec
};
10943 vec_safe_push (ranges_table
, r
);
10944 return vec_safe_length (ranges_table
) - 1;
10947 /* Add a new entry to .debug_ranges corresponding to a block, or a
10948 range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
10949 this entry might be in a different section from previous range. */
10951 static unsigned int
10952 add_ranges (const_tree block
, bool maybe_new_sec
)
10954 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0, maybe_new_sec
);
10957 /* Note that (*rnglist_table)[offset] is either a head of a rnglist
10958 chain, or middle entry of a chain that will be directly referred to. */
10961 note_rnglist_head (unsigned int offset
)
10963 if (dwarf_version
< 5 || (*ranges_table
)[offset
].label
)
10965 (*ranges_table
)[offset
].label
= gen_internal_sym ("LLRL");
10968 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
10969 When using dwarf_split_debug_info, address attributes in dies destined
10970 for the final executable should be direct references--setting the
10971 parameter force_direct ensures this behavior. */
10974 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
10975 bool *added
, bool force_direct
)
10977 unsigned int in_use
= vec_safe_length (ranges_by_label
);
10978 unsigned int offset
;
10979 dw_ranges_by_label rbl
= { begin
, end
};
10980 vec_safe_push (ranges_by_label
, rbl
);
10981 offset
= add_ranges_num (-(int)in_use
- 1, true);
10984 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
10986 note_rnglist_head (offset
);
10990 /* Emit .debug_ranges section. */
10993 output_ranges (void)
10996 static const char *const start_fmt
= "Offset %#x";
10997 const char *fmt
= start_fmt
;
11000 switch_to_section (debug_ranges_section
);
11001 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11002 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11004 int block_num
= r
->num
;
11008 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11009 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11011 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11012 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11014 /* If all code is in the text section, then the compilation
11015 unit base address defaults to DW_AT_low_pc, which is the
11016 base of the text section. */
11017 if (!have_multiple_function_sections
)
11019 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11020 text_section_label
,
11021 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11022 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11023 text_section_label
, NULL
);
11026 /* Otherwise, the compilation unit base address is zero,
11027 which allows us to use absolute addresses, and not worry
11028 about whether the target supports cross-section
11032 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11033 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11034 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11040 /* Negative block_num stands for an index into ranges_by_label. */
11041 else if (block_num
< 0)
11043 int lab_idx
= - block_num
- 1;
11045 if (!have_multiple_function_sections
)
11047 gcc_unreachable ();
11049 /* If we ever use add_ranges_by_labels () for a single
11050 function section, all we have to do is to take out
11051 the #if 0 above. */
11052 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11053 (*ranges_by_label
)[lab_idx
].begin
,
11054 text_section_label
,
11055 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11056 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11057 (*ranges_by_label
)[lab_idx
].end
,
11058 text_section_label
, NULL
);
11063 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11064 (*ranges_by_label
)[lab_idx
].begin
,
11065 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11066 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11067 (*ranges_by_label
)[lab_idx
].end
,
11073 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11074 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11080 /* Non-zero if .debug_line_str should be used for .debug_line section
11081 strings or strings that are likely shareable with those. */
11082 #define DWARF5_USE_DEBUG_LINE_STR \
11083 (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
11084 && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
11085 /* FIXME: there is no .debug_line_str.dwo section, \
11086 for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
11087 && !dwarf_split_debug_info)
11089 /* Assign .debug_rnglists indexes. */
11092 index_rnglists (void)
11097 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11099 r
->idx
= rnglist_idx
++;
11102 /* Emit .debug_rnglists section. */
11105 output_rnglists (void)
11109 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
11110 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11111 char basebuf
[MAX_ARTIFICIAL_LABEL_BYTES
];
11113 switch_to_section (debug_ranges_section
);
11114 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11115 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_RANGES_SECTION_LABEL
, 2);
11116 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_RANGES_SECTION_LABEL
, 3);
11117 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11118 dw2_asm_output_data (4, 0xffffffff,
11119 "Initial length escape value indicating "
11120 "64-bit DWARF extension");
11121 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11122 "Length of Range Lists");
11123 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11124 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11125 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11126 dw2_asm_output_data (1, 0, "Segment Size");
11127 /* Emit the offset table only for -gsplit-dwarf. If we don't care
11128 about relocation sizes and primarily care about the size of .debug*
11129 sections in linked shared libraries and executables, then
11130 the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
11131 into it are usually larger than just DW_FORM_sec_offset offsets
11132 into the .debug_rnglists section. */
11133 dw2_asm_output_data (4, dwarf_split_debug_info
? rnglist_idx
: 0,
11134 "Offset Entry Count");
11135 if (dwarf_split_debug_info
)
11137 ASM_OUTPUT_LABEL (asm_out_file
, ranges_base_label
);
11138 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11140 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, r
->label
,
11141 ranges_base_label
, NULL
);
11144 const char *lab
= "";
11145 unsigned int len
= vec_safe_length (ranges_table
);
11146 const char *base
= NULL
;
11147 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11149 int block_num
= r
->num
;
11153 ASM_OUTPUT_LABEL (asm_out_file
, r
->label
);
11156 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
11160 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11161 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11163 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11164 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11166 if (HAVE_AS_LEB128
)
11168 /* If all code is in the text section, then the compilation
11169 unit base address defaults to DW_AT_low_pc, which is the
11170 base of the text section. */
11171 if (!have_multiple_function_sections
)
11173 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11174 "DW_RLE_offset_pair (%s)", lab
);
11175 dw2_asm_output_delta_uleb128 (blabel
, text_section_label
,
11176 "Range begin address (%s)", lab
);
11177 dw2_asm_output_delta_uleb128 (elabel
, text_section_label
,
11178 "Range end address (%s)", lab
);
11183 dw_ranges
*r2
= NULL
;
11185 r2
= &(*ranges_table
)[i
+ 1];
11188 && r2
->label
== NULL
11189 && !r2
->maybe_new_sec
)
11191 dw2_asm_output_data (1, DW_RLE_base_address
,
11192 "DW_RLE_base_address (%s)", lab
);
11193 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11194 "Base address (%s)", lab
);
11195 strcpy (basebuf
, blabel
);
11201 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11202 "DW_RLE_offset_pair (%s)", lab
);
11203 dw2_asm_output_delta_uleb128 (blabel
, base
,
11204 "Range begin address (%s)", lab
);
11205 dw2_asm_output_delta_uleb128 (elabel
, base
,
11206 "Range end address (%s)", lab
);
11209 dw2_asm_output_data (1, DW_RLE_start_length
,
11210 "DW_RLE_start_length (%s)", lab
);
11211 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11212 "Range begin address (%s)", lab
);
11213 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11214 "Range length (%s)", lab
);
11218 dw2_asm_output_data (1, DW_RLE_start_end
,
11219 "DW_RLE_start_end (%s)", lab
);
11220 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11221 "Range begin address (%s)", lab
);
11222 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11223 "Range end address (%s)", lab
);
11227 /* Negative block_num stands for an index into ranges_by_label. */
11228 else if (block_num
< 0)
11230 int lab_idx
= - block_num
- 1;
11231 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
11232 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
11234 if (!have_multiple_function_sections
)
11235 gcc_unreachable ();
11236 if (HAVE_AS_LEB128
)
11238 dw2_asm_output_data (1, DW_RLE_start_length
,
11239 "DW_RLE_start_length (%s)", lab
);
11240 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11241 "Range begin address (%s)", lab
);
11242 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11243 "Range length (%s)", lab
);
11247 dw2_asm_output_data (1, DW_RLE_start_end
,
11248 "DW_RLE_start_end (%s)", lab
);
11249 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11250 "Range begin address (%s)", lab
);
11251 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11252 "Range end address (%s)", lab
);
11256 dw2_asm_output_data (1, DW_RLE_end_of_list
,
11257 "DW_RLE_end_of_list (%s)", lab
);
11259 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11262 /* Data structure containing information about input files. */
11265 const char *path
; /* Complete file name. */
11266 const char *fname
; /* File name part. */
11267 int length
; /* Length of entire string. */
11268 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
11269 int dir_idx
; /* Index in directory table. */
11272 /* Data structure containing information about directories with source
11276 const char *path
; /* Path including directory name. */
11277 int length
; /* Path length. */
11278 int prefix
; /* Index of directory entry which is a prefix. */
11279 int count
; /* Number of files in this directory. */
11280 int dir_idx
; /* Index of directory used as base. */
11283 /* Callback function for file_info comparison. We sort by looking at
11284 the directories in the path. */
11287 file_info_cmp (const void *p1
, const void *p2
)
11289 const struct file_info
*const s1
= (const struct file_info
*) p1
;
11290 const struct file_info
*const s2
= (const struct file_info
*) p2
;
11291 const unsigned char *cp1
;
11292 const unsigned char *cp2
;
11294 /* Take care of file names without directories. We need to make sure that
11295 we return consistent values to qsort since some will get confused if
11296 we return the same value when identical operands are passed in opposite
11297 orders. So if neither has a directory, return 0 and otherwise return
11298 1 or -1 depending on which one has the directory. */
11299 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
11300 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
11302 cp1
= (const unsigned char *) s1
->path
;
11303 cp2
= (const unsigned char *) s2
->path
;
11309 /* Reached the end of the first path? If so, handle like above. */
11310 if ((cp1
== (const unsigned char *) s1
->fname
)
11311 || (cp2
== (const unsigned char *) s2
->fname
))
11312 return ((cp2
== (const unsigned char *) s2
->fname
)
11313 - (cp1
== (const unsigned char *) s1
->fname
));
11315 /* Character of current path component the same? */
11316 else if (*cp1
!= *cp2
)
11317 return *cp1
- *cp2
;
11321 struct file_name_acquire_data
11323 struct file_info
*files
;
11328 /* Traversal function for the hash table. */
11331 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
11333 struct dwarf_file_data
*d
= *slot
;
11334 struct file_info
*fi
;
11337 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
11339 if (! d
->emitted_number
)
11342 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
11344 fi
= fnad
->files
+ fnad
->used_files
++;
11346 /* Skip all leading "./". */
11348 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
11351 /* Create a new array entry. */
11353 fi
->length
= strlen (f
);
11356 /* Search for the file name part. */
11357 f
= strrchr (f
, DIR_SEPARATOR
);
11358 #if defined (DIR_SEPARATOR_2)
11360 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
11364 if (f
== NULL
|| f
< g
)
11370 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
11374 /* Helper function for output_file_names. Emit a FORM encoded
11375 string STR, with assembly comment start ENTRY_KIND and
11379 output_line_string (enum dwarf_form form
, const char *str
,
11380 const char *entry_kind
, unsigned int idx
)
11384 case DW_FORM_string
:
11385 dw2_asm_output_nstring (str
, -1, "%s: %#x", entry_kind
, idx
);
11387 case DW_FORM_line_strp
:
11388 if (!debug_line_str_hash
)
11389 debug_line_str_hash
11390 = hash_table
<indirect_string_hasher
>::create_ggc (10);
11392 struct indirect_string_node
*node
;
11393 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
11394 set_indirect_string (node
);
11396 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
11397 debug_line_str_section
, "%s: %#x: \"%s\"",
11398 entry_kind
, 0, node
->str
);
11401 gcc_unreachable ();
11405 /* Output the directory table and the file name table. We try to minimize
11406 the total amount of memory needed. A heuristic is used to avoid large
11407 slowdowns with many input files. */
11410 output_file_names (void)
11412 struct file_name_acquire_data fnad
;
11414 struct file_info
*files
;
11415 struct dir_info
*dirs
;
11423 if (!last_emitted_file
)
11425 if (dwarf_version
>= 5)
11427 dw2_asm_output_data (1, 0, "Directory entry format count");
11428 dw2_asm_output_data_uleb128 (0, "Directories count");
11429 dw2_asm_output_data (1, 0, "File name entry format count");
11430 dw2_asm_output_data_uleb128 (0, "File names count");
11434 dw2_asm_output_data (1, 0, "End directory table");
11435 dw2_asm_output_data (1, 0, "End file name table");
11440 numfiles
= last_emitted_file
->emitted_number
;
11442 /* Allocate the various arrays we need. */
11443 files
= XALLOCAVEC (struct file_info
, numfiles
);
11444 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
11446 fnad
.files
= files
;
11447 fnad
.used_files
= 0;
11448 fnad
.max_files
= numfiles
;
11449 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
11450 gcc_assert (fnad
.used_files
== fnad
.max_files
);
11452 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
11454 /* Find all the different directories used. */
11455 dirs
[0].path
= files
[0].path
;
11456 dirs
[0].length
= files
[0].fname
- files
[0].path
;
11457 dirs
[0].prefix
= -1;
11459 dirs
[0].dir_idx
= 0;
11460 files
[0].dir_idx
= 0;
11463 for (i
= 1; i
< numfiles
; i
++)
11464 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
11465 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
11466 dirs
[ndirs
- 1].length
) == 0)
11468 /* Same directory as last entry. */
11469 files
[i
].dir_idx
= ndirs
- 1;
11470 ++dirs
[ndirs
- 1].count
;
11476 /* This is a new directory. */
11477 dirs
[ndirs
].path
= files
[i
].path
;
11478 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
11479 dirs
[ndirs
].count
= 1;
11480 dirs
[ndirs
].dir_idx
= ndirs
;
11481 files
[i
].dir_idx
= ndirs
;
11483 /* Search for a prefix. */
11484 dirs
[ndirs
].prefix
= -1;
11485 for (j
= 0; j
< ndirs
; j
++)
11486 if (dirs
[j
].length
< dirs
[ndirs
].length
11487 && dirs
[j
].length
> 1
11488 && (dirs
[ndirs
].prefix
== -1
11489 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
11490 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
11491 dirs
[ndirs
].prefix
= j
;
11496 /* Now to the actual work. We have to find a subset of the directories which
11497 allow expressing the file name using references to the directory table
11498 with the least amount of characters. We do not do an exhaustive search
11499 where we would have to check out every combination of every single
11500 possible prefix. Instead we use a heuristic which provides nearly optimal
11501 results in most cases and never is much off. */
11502 saved
= XALLOCAVEC (int, ndirs
);
11503 savehere
= XALLOCAVEC (int, ndirs
);
11505 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
11506 for (i
= 0; i
< ndirs
; i
++)
11511 /* We can always save some space for the current directory. But this
11512 does not mean it will be enough to justify adding the directory. */
11513 savehere
[i
] = dirs
[i
].length
;
11514 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
11516 for (j
= i
+ 1; j
< ndirs
; j
++)
11519 if (saved
[j
] < dirs
[i
].length
)
11521 /* Determine whether the dirs[i] path is a prefix of the
11525 k
= dirs
[j
].prefix
;
11526 while (k
!= -1 && k
!= (int) i
)
11527 k
= dirs
[k
].prefix
;
11531 /* Yes it is. We can possibly save some memory by
11532 writing the filenames in dirs[j] relative to
11534 savehere
[j
] = dirs
[i
].length
;
11535 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
11540 /* Check whether we can save enough to justify adding the dirs[i]
11542 if (total
> dirs
[i
].length
+ 1)
11544 /* It's worthwhile adding. */
11545 for (j
= i
; j
< ndirs
; j
++)
11546 if (savehere
[j
] > 0)
11548 /* Remember how much we saved for this directory so far. */
11549 saved
[j
] = savehere
[j
];
11551 /* Remember the prefix directory. */
11552 dirs
[j
].dir_idx
= i
;
11557 /* Emit the directory name table. */
11558 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
11559 enum dwarf_form str_form
= DW_FORM_string
;
11560 enum dwarf_form idx_form
= DW_FORM_udata
;
11561 if (dwarf_version
>= 5)
11563 const char *comp_dir
= comp_dir_string ();
11564 if (comp_dir
== NULL
)
11566 dw2_asm_output_data (1, 1, "Directory entry format count");
11567 if (DWARF5_USE_DEBUG_LINE_STR
)
11568 str_form
= DW_FORM_line_strp
;
11569 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11570 dw2_asm_output_data_uleb128 (str_form
, "%s",
11571 get_DW_FORM_name (str_form
));
11572 dw2_asm_output_data_uleb128 (ndirs
+ idx_offset
, "Directories count");
11573 if (str_form
== DW_FORM_string
)
11575 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
11576 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11577 dw2_asm_output_nstring (dirs
[i
].path
,
11579 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11580 "Directory Entry: %#x", i
+ idx_offset
);
11584 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
11585 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11588 = ggc_alloc_string (dirs
[i
].path
,
11590 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
);
11591 output_line_string (str_form
, str
, "Directory Entry",
11592 (unsigned) i
+ idx_offset
);
11598 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11599 dw2_asm_output_nstring (dirs
[i
].path
,
11601 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11602 "Directory Entry: %#x", i
+ idx_offset
);
11604 dw2_asm_output_data (1, 0, "End directory table");
11607 /* We have to emit them in the order of emitted_number since that's
11608 used in the debug info generation. To do this efficiently we
11609 generate a back-mapping of the indices first. */
11610 backmap
= XALLOCAVEC (int, numfiles
);
11611 for (i
= 0; i
< numfiles
; i
++)
11612 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
11614 if (dwarf_version
>= 5)
11616 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
11617 if (filename0
== NULL
)
11619 /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
11620 DW_FORM_data2. Choose one based on the number of directories
11621 and how much space would they occupy in each encoding.
11622 If we have at most 256 directories, all indexes fit into
11623 a single byte, so DW_FORM_data1 is most compact (if there
11624 are at most 128 directories, DW_FORM_udata would be as
11625 compact as that, but not shorter and slower to decode). */
11626 if (ndirs
+ idx_offset
<= 256)
11627 idx_form
= DW_FORM_data1
;
11628 /* If there are more than 65536 directories, we have to use
11629 DW_FORM_udata, DW_FORM_data2 can't refer to them.
11630 Otherwise, compute what space would occupy if all the indexes
11631 used DW_FORM_udata - sum - and compare that to how large would
11632 be DW_FORM_data2 encoding, and pick the more efficient one. */
11633 else if (ndirs
+ idx_offset
<= 65536)
11635 unsigned HOST_WIDE_INT sum
= 1;
11636 for (i
= 0; i
< numfiles
; i
++)
11638 int file_idx
= backmap
[i
];
11639 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11640 sum
+= size_of_uleb128 (dir_idx
);
11642 if (sum
>= HOST_WIDE_INT_UC (2) * (numfiles
+ 1))
11643 idx_form
= DW_FORM_data2
;
11645 #ifdef VMS_DEBUGGING_INFO
11646 dw2_asm_output_data (1, 4, "File name entry format count");
11648 dw2_asm_output_data (1, 2, "File name entry format count");
11650 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11651 dw2_asm_output_data_uleb128 (str_form
, "%s",
11652 get_DW_FORM_name (str_form
));
11653 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
11654 "DW_LNCT_directory_index");
11655 dw2_asm_output_data_uleb128 (idx_form
, "%s",
11656 get_DW_FORM_name (idx_form
));
11657 #ifdef VMS_DEBUGGING_INFO
11658 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
11659 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11660 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
11661 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11663 dw2_asm_output_data_uleb128 (numfiles
+ 1, "File names count");
11665 output_line_string (str_form
, filename0
, "File Entry", 0);
11667 /* Include directory index. */
11668 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11669 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11672 dw2_asm_output_data_uleb128 (0, NULL
);
11674 #ifdef VMS_DEBUGGING_INFO
11675 dw2_asm_output_data_uleb128 (0, NULL
);
11676 dw2_asm_output_data_uleb128 (0, NULL
);
11680 /* Now write all the file names. */
11681 for (i
= 0; i
< numfiles
; i
++)
11683 int file_idx
= backmap
[i
];
11684 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11686 #ifdef VMS_DEBUGGING_INFO
11687 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
11689 /* Setting these fields can lead to debugger miscomparisons,
11690 but VMS Debug requires them to be set correctly. */
11695 int maxfilelen
= (strlen (files
[file_idx
].path
)
11696 + dirs
[dir_idx
].length
11697 + MAX_VMS_VERSION_LEN
+ 1);
11698 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
11700 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
11701 snprintf (filebuf
, maxfilelen
, "%s;%d",
11702 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
11704 output_line_string (str_form
, filebuf
, "File Entry", (unsigned) i
+ 1);
11706 /* Include directory index. */
11707 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11708 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11709 dir_idx
+ idx_offset
, NULL
);
11711 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11713 /* Modification time. */
11714 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11715 &cdt
, 0, 0, 0) == 0)
11718 /* File length in bytes. */
11719 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11720 0, &siz
, 0, 0) == 0)
11723 output_line_string (str_form
,
11724 files
[file_idx
].path
+ dirs
[dir_idx
].length
,
11725 "File Entry", (unsigned) i
+ 1);
11727 /* Include directory index. */
11728 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11729 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11730 dir_idx
+ idx_offset
, NULL
);
11732 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11734 if (dwarf_version
>= 5)
11737 /* Modification time. */
11738 dw2_asm_output_data_uleb128 (0, NULL
);
11740 /* File length in bytes. */
11741 dw2_asm_output_data_uleb128 (0, NULL
);
11742 #endif /* VMS_DEBUGGING_INFO */
11745 if (dwarf_version
< 5)
11746 dw2_asm_output_data (1, 0, "End file name table");
11750 /* Output one line number table into the .debug_line section. */
11753 output_one_line_info_table (dw_line_info_table
*table
)
11755 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11756 unsigned int current_line
= 1;
11757 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
11758 dw_line_info_entry
*ent
;
11761 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
11763 switch (ent
->opcode
)
11765 case LI_set_address
:
11766 /* ??? Unfortunately, we have little choice here currently, and
11767 must always use the most general form. GCC does not know the
11768 address delta itself, so we can't use DW_LNS_advance_pc. Many
11769 ports do have length attributes which will give an upper bound
11770 on the address range. We could perhaps use length attributes
11771 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
11772 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
11774 /* This can handle any delta. This takes
11775 4+DWARF2_ADDR_SIZE bytes. */
11776 dw2_asm_output_data (1, 0, "set address %s", line_label
);
11777 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11778 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11779 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
11783 if (ent
->val
== current_line
)
11785 /* We still need to start a new row, so output a copy insn. */
11786 dw2_asm_output_data (1, DW_LNS_copy
,
11787 "copy line %u", current_line
);
11791 int line_offset
= ent
->val
- current_line
;
11792 int line_delta
= line_offset
- DWARF_LINE_BASE
;
11794 current_line
= ent
->val
;
11795 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
11797 /* This can handle deltas from -10 to 234, using the current
11798 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
11799 This takes 1 byte. */
11800 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
11801 "line %u", current_line
);
11805 /* This can handle any delta. This takes at least 4 bytes,
11806 depending on the value being encoded. */
11807 dw2_asm_output_data (1, DW_LNS_advance_line
,
11808 "advance to line %u", current_line
);
11809 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
11810 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
11816 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
11817 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11820 case LI_set_column
:
11821 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
11822 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11825 case LI_negate_stmt
:
11826 current_is_stmt
= !current_is_stmt
;
11827 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
11828 "is_stmt %d", current_is_stmt
);
11831 case LI_set_prologue_end
:
11832 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
11833 "set prologue end");
11836 case LI_set_epilogue_begin
:
11837 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
11838 "set epilogue begin");
11841 case LI_set_discriminator
:
11842 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
11843 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
11844 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
11845 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
11850 /* Emit debug info for the address of the end of the table. */
11851 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
11852 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11853 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11854 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
11856 dw2_asm_output_data (1, 0, "end sequence");
11857 dw2_asm_output_data_uleb128 (1, NULL
);
11858 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
11861 /* Output the source line number correspondence information. This
11862 information goes into the .debug_line section. */
11865 output_line_info (bool prologue_only
)
11867 static unsigned int generation
;
11868 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11869 char p1
[MAX_ARTIFICIAL_LABEL_BYTES
], p2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11870 bool saw_one
= false;
11873 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, generation
);
11874 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, generation
);
11875 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, generation
);
11876 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, generation
++);
11878 if (!XCOFF_DEBUGGING_INFO
)
11880 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11881 dw2_asm_output_data (4, 0xffffffff,
11882 "Initial length escape value indicating 64-bit DWARF extension");
11883 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11884 "Length of Source Line Info");
11887 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11889 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11890 if (dwarf_version
>= 5)
11892 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11893 dw2_asm_output_data (1, 0, "Segment Size");
11895 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
11896 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
11898 /* Define the architecture-dependent minimum instruction length (in bytes).
11899 In this implementation of DWARF, this field is used for information
11900 purposes only. Since GCC generates assembly language, we have no
11901 a priori knowledge of how many instruction bytes are generated for each
11902 source line, and therefore can use only the DW_LNE_set_address and
11903 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
11904 this as '1', which is "correct enough" for all architectures,
11905 and don't let the target override. */
11906 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
11908 if (dwarf_version
>= 4)
11909 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
11910 "Maximum Operations Per Instruction");
11911 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
11912 "Default is_stmt_start flag");
11913 dw2_asm_output_data (1, DWARF_LINE_BASE
,
11914 "Line Base Value (Special Opcodes)");
11915 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
11916 "Line Range Value (Special Opcodes)");
11917 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
11918 "Special Opcode Base");
11920 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
11925 case DW_LNS_advance_pc
:
11926 case DW_LNS_advance_line
:
11927 case DW_LNS_set_file
:
11928 case DW_LNS_set_column
:
11929 case DW_LNS_fixed_advance_pc
:
11930 case DW_LNS_set_isa
:
11938 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
11942 /* Write out the information about the files we use. */
11943 output_file_names ();
11944 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
11947 /* Output the marker for the end of the line number info. */
11948 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11952 if (separate_line_info
)
11954 dw_line_info_table
*table
;
11957 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
11960 output_one_line_info_table (table
);
11964 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
11966 output_one_line_info_table (cold_text_section_line_info
);
11970 /* ??? Some Darwin linkers crash on a .debug_line section with no
11971 sequences. Further, merely a DW_LNE_end_sequence entry is not
11972 sufficient -- the address column must also be initialized.
11973 Make sure to output at least one set_address/end_sequence pair,
11974 choosing .text since that section is always present. */
11975 if (text_section_line_info
->in_use
|| !saw_one
)
11976 output_one_line_info_table (text_section_line_info
);
11978 /* Output the marker for the end of the line number info. */
11979 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11982 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
11985 need_endianity_attribute_p (bool reverse
)
11987 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
11990 /* Given a pointer to a tree node for some base type, return a pointer to
11991 a DIE that describes the given type. REVERSE is true if the type is
11992 to be interpreted in the reverse storage order wrt the target order.
11994 This routine must only be called for GCC type nodes that correspond to
11995 Dwarf base (fundamental) types. */
11998 base_type_die (tree type
, bool reverse
)
12000 dw_die_ref base_type_result
;
12001 enum dwarf_type encoding
;
12002 bool fpt_used
= false;
12003 struct fixed_point_type_info fpt_info
;
12004 tree type_bias
= NULL_TREE
;
12006 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
12009 /* If this is a subtype that should not be emitted as a subrange type,
12010 use the base type. See subrange_type_for_debug_p. */
12011 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
12012 type
= TREE_TYPE (type
);
12014 switch (TREE_CODE (type
))
12017 if ((dwarf_version
>= 4 || !dwarf_strict
)
12018 && TYPE_NAME (type
)
12019 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12020 && DECL_IS_BUILTIN (TYPE_NAME (type
))
12021 && DECL_NAME (TYPE_NAME (type
)))
12023 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
12024 if (strcmp (name
, "char16_t") == 0
12025 || strcmp (name
, "char32_t") == 0)
12027 encoding
= DW_ATE_UTF
;
12031 if ((dwarf_version
>= 3 || !dwarf_strict
)
12032 && lang_hooks
.types
.get_fixed_point_type_info
)
12034 memset (&fpt_info
, 0, sizeof (fpt_info
));
12035 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
12038 encoding
= ((TYPE_UNSIGNED (type
))
12039 ? DW_ATE_unsigned_fixed
12040 : DW_ATE_signed_fixed
);
12044 if (TYPE_STRING_FLAG (type
))
12046 if (TYPE_UNSIGNED (type
))
12047 encoding
= DW_ATE_unsigned_char
;
12049 encoding
= DW_ATE_signed_char
;
12051 else if (TYPE_UNSIGNED (type
))
12052 encoding
= DW_ATE_unsigned
;
12054 encoding
= DW_ATE_signed
;
12057 && lang_hooks
.types
.get_type_bias
)
12058 type_bias
= lang_hooks
.types
.get_type_bias (type
);
12062 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
12064 if (dwarf_version
>= 3 || !dwarf_strict
)
12065 encoding
= DW_ATE_decimal_float
;
12067 encoding
= DW_ATE_lo_user
;
12070 encoding
= DW_ATE_float
;
12073 case FIXED_POINT_TYPE
:
12074 if (!(dwarf_version
>= 3 || !dwarf_strict
))
12075 encoding
= DW_ATE_lo_user
;
12076 else if (TYPE_UNSIGNED (type
))
12077 encoding
= DW_ATE_unsigned_fixed
;
12079 encoding
= DW_ATE_signed_fixed
;
12082 /* Dwarf2 doesn't know anything about complex ints, so use
12083 a user defined type for it. */
12085 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
12086 encoding
= DW_ATE_complex_float
;
12088 encoding
= DW_ATE_lo_user
;
12092 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12093 encoding
= DW_ATE_boolean
;
12097 /* No other TREE_CODEs are Dwarf fundamental types. */
12098 gcc_unreachable ();
12101 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
12103 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
12104 int_size_in_bytes (type
));
12105 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
12107 if (need_endianity_attribute_p (reverse
))
12108 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
12109 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
12111 add_alignment_attribute (base_type_result
, type
);
12115 switch (fpt_info
.scale_factor_kind
)
12117 case fixed_point_scale_factor_binary
:
12118 add_AT_int (base_type_result
, DW_AT_binary_scale
,
12119 fpt_info
.scale_factor
.binary
);
12122 case fixed_point_scale_factor_decimal
:
12123 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
12124 fpt_info
.scale_factor
.decimal
);
12127 case fixed_point_scale_factor_arbitrary
:
12128 /* Arbitrary scale factors cannot be described in standard DWARF,
12132 /* Describe the scale factor as a rational constant. */
12133 const dw_die_ref scale_factor
12134 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
12136 add_AT_unsigned (scale_factor
, DW_AT_GNU_numerator
,
12137 fpt_info
.scale_factor
.arbitrary
.numerator
);
12138 add_AT_int (scale_factor
, DW_AT_GNU_denominator
,
12139 fpt_info
.scale_factor
.arbitrary
.denominator
);
12141 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
12146 gcc_unreachable ();
12151 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
12152 dw_scalar_form_constant
12153 | dw_scalar_form_exprloc
12154 | dw_scalar_form_reference
,
12157 add_pubtype (type
, base_type_result
);
12159 return base_type_result
;
12162 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
12163 named 'auto' in its type: return true for it, false otherwise. */
12166 is_cxx_auto (tree type
)
12170 tree name
= TYPE_IDENTIFIER (type
);
12171 if (name
== get_identifier ("auto")
12172 || name
== get_identifier ("decltype(auto)"))
12178 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12179 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12182 is_base_type (tree type
)
12184 switch (TREE_CODE (type
))
12190 case FIXED_POINT_TYPE
:
12193 case POINTER_BOUNDS_TYPE
:
12199 case QUAL_UNION_TYPE
:
12200 case ENUMERAL_TYPE
:
12201 case FUNCTION_TYPE
:
12204 case REFERENCE_TYPE
:
12212 if (is_cxx_auto (type
))
12214 gcc_unreachable ();
12220 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12221 node, return the size in bits for the type if it is a constant, or else
12222 return the alignment for the type if the type's size is not constant, or
12223 else return BITS_PER_WORD if the type actually turns out to be an
12224 ERROR_MARK node. */
12226 static inline unsigned HOST_WIDE_INT
12227 simple_type_size_in_bits (const_tree type
)
12229 if (TREE_CODE (type
) == ERROR_MARK
)
12230 return BITS_PER_WORD
;
12231 else if (TYPE_SIZE (type
) == NULL_TREE
)
12233 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
12234 return tree_to_uhwi (TYPE_SIZE (type
));
12236 return TYPE_ALIGN (type
);
12239 /* Similarly, but return an offset_int instead of UHWI. */
12241 static inline offset_int
12242 offset_int_type_size_in_bits (const_tree type
)
12244 if (TREE_CODE (type
) == ERROR_MARK
)
12245 return BITS_PER_WORD
;
12246 else if (TYPE_SIZE (type
) == NULL_TREE
)
12248 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
12249 return wi::to_offset (TYPE_SIZE (type
));
12251 return TYPE_ALIGN (type
);
12254 /* Given a pointer to a tree node for a subrange type, return a pointer
12255 to a DIE that describes the given type. */
12258 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
12259 dw_die_ref context_die
)
12261 dw_die_ref subrange_die
;
12262 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
12264 if (context_die
== NULL
)
12265 context_die
= comp_unit_die ();
12267 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
12269 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
12271 /* The size of the subrange type and its base type do not match,
12272 so we need to generate a size attribute for the subrange type. */
12273 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
12276 add_alignment_attribute (subrange_die
, type
);
12279 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
12281 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
12282 if (bias
&& !dwarf_strict
)
12283 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
12284 dw_scalar_form_constant
12285 | dw_scalar_form_exprloc
12286 | dw_scalar_form_reference
,
12289 return subrange_die
;
12292 /* Returns the (const and/or volatile) cv_qualifiers associated with
12293 the decl node. This will normally be augmented with the
12294 cv_qualifiers of the underlying type in add_type_attribute. */
12297 decl_quals (const_tree decl
)
12299 return ((TREE_READONLY (decl
)
12300 /* The C++ front-end correctly marks reference-typed
12301 variables as readonly, but from a language (and debug
12302 info) standpoint they are not const-qualified. */
12303 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
12304 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
12305 | (TREE_THIS_VOLATILE (decl
)
12306 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
12309 /* Determine the TYPE whose qualifiers match the largest strict subset
12310 of the given TYPE_QUALS, and return its qualifiers. Ignore all
12311 qualifiers outside QUAL_MASK. */
12314 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
12317 int best_rank
= 0, best_qual
= 0, max_rank
;
12319 type_quals
&= qual_mask
;
12320 max_rank
= popcount_hwi (type_quals
) - 1;
12322 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
12323 t
= TYPE_NEXT_VARIANT (t
))
12325 int q
= TYPE_QUALS (t
) & qual_mask
;
12327 if ((q
& type_quals
) == q
&& q
!= type_quals
12328 && check_base_type (t
, type
))
12330 int rank
= popcount_hwi (q
);
12332 if (rank
> best_rank
)
12343 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
12344 static const dwarf_qual_info_t dwarf_qual_info
[] =
12346 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
12347 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
12348 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
12349 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
12351 static const unsigned int dwarf_qual_info_size
12352 = sizeof (dwarf_qual_info
) / sizeof (dwarf_qual_info
[0]);
12354 /* If DIE is a qualified DIE of some base DIE with the same parent,
12355 return the base DIE, otherwise return NULL. Set MASK to the
12356 qualifiers added compared to the returned DIE. */
12359 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
12362 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12363 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
12365 if (i
== dwarf_qual_info_size
)
12367 if (vec_safe_length (die
->die_attr
) != 1)
12369 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
12370 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
12372 *mask
|= dwarf_qual_info
[i
].q
;
12375 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
12382 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12383 entry that chains the modifiers specified by CV_QUALS in front of the
12384 given type. REVERSE is true if the type is to be interpreted in the
12385 reverse storage order wrt the target order. */
12388 modified_type_die (tree type
, int cv_quals
, bool reverse
,
12389 dw_die_ref context_die
)
12391 enum tree_code code
= TREE_CODE (type
);
12392 dw_die_ref mod_type_die
;
12393 dw_die_ref sub_die
= NULL
;
12394 tree item_type
= NULL
;
12395 tree qualified_type
;
12396 tree name
, low
, high
;
12397 dw_die_ref mod_scope
;
12398 /* Only these cv-qualifiers are currently handled. */
12399 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
12400 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
12402 if (code
== ERROR_MARK
)
12405 if (lang_hooks
.types
.get_debug_type
)
12407 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
12409 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
12410 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
12413 cv_quals
&= cv_qual_mask
;
12415 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
12416 tag modifier (and not an attribute) old consumers won't be able
12418 if (dwarf_version
< 3)
12419 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
12421 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
12422 if (dwarf_version
< 5)
12423 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
12425 /* See if we already have the appropriately qualified variant of
12427 qualified_type
= get_qualified_type (type
, cv_quals
);
12429 if (qualified_type
== sizetype
12430 && TYPE_NAME (qualified_type
)
12431 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
12433 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
12435 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
12436 && TYPE_PRECISION (t
)
12437 == TYPE_PRECISION (qualified_type
)
12438 && TYPE_UNSIGNED (t
)
12439 == TYPE_UNSIGNED (qualified_type
));
12440 qualified_type
= t
;
12443 /* If we do, then we can just use its DIE, if it exists. */
12444 if (qualified_type
)
12446 mod_type_die
= lookup_type_die (qualified_type
);
12448 /* DW_AT_endianity doesn't come from a qualifier on the type. */
12450 && (!need_endianity_attribute_p (reverse
)
12451 || !is_base_type (type
)
12452 || get_AT_unsigned (mod_type_die
, DW_AT_endianity
)))
12453 return mod_type_die
;
12456 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
12458 /* Handle C typedef types. */
12459 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
12460 && !DECL_ARTIFICIAL (name
))
12462 tree dtype
= TREE_TYPE (name
);
12464 if (qualified_type
== dtype
)
12466 /* For a named type, use the typedef. */
12467 gen_type_die (qualified_type
, context_die
);
12468 return lookup_type_die (qualified_type
);
12472 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
12473 dquals
&= cv_qual_mask
;
12474 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
12475 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
12476 /* cv-unqualified version of named type. Just use
12477 the unnamed type to which it refers. */
12478 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
12479 reverse
, context_die
);
12480 /* Else cv-qualified version of named type; fall through. */
12484 mod_scope
= scope_die_for (type
, context_die
);
12488 int sub_quals
= 0, first_quals
= 0;
12490 dw_die_ref first
= NULL
, last
= NULL
;
12492 /* Determine a lesser qualified type that most closely matches
12493 this one. Then generate DW_TAG_* entries for the remaining
12495 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
12497 if (sub_quals
&& use_debug_types
)
12499 bool needed
= false;
12500 /* If emitting type units, make sure the order of qualifiers
12501 is canonical. Thus, start from unqualified type if
12502 an earlier qualifier is missing in sub_quals, but some later
12503 one is present there. */
12504 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12505 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12507 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
12513 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
12514 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
12516 /* As not all intermediate qualified DIEs have corresponding
12517 tree types, ensure that qualified DIEs in the same scope
12518 as their DW_AT_type are emitted after their DW_AT_type,
12519 only with other qualified DIEs for the same type possibly
12520 in between them. Determine the range of such qualified
12521 DIEs now (first being the base type, last being corresponding
12522 last qualified DIE for it). */
12523 unsigned int count
= 0;
12524 first
= qualified_die_p (mod_type_die
, &first_quals
,
12525 dwarf_qual_info_size
);
12527 first
= mod_type_die
;
12528 gcc_assert ((first_quals
& ~sub_quals
) == 0);
12529 for (count
= 0, last
= first
;
12530 count
< (1U << dwarf_qual_info_size
);
12531 count
++, last
= last
->die_sib
)
12534 if (last
== mod_scope
->die_child
)
12536 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
12542 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12543 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12546 if (first
&& first
!= last
)
12548 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
12551 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
12552 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
12568 d
= ggc_cleared_alloc
<die_node
> ();
12569 d
->die_tag
= dwarf_qual_info
[i
].t
;
12570 add_child_die_after (mod_scope
, d
, last
);
12574 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
12576 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
12578 first_quals
|= dwarf_qual_info
[i
].q
;
12581 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
12583 dwarf_tag tag
= DW_TAG_pointer_type
;
12584 if (code
== REFERENCE_TYPE
)
12586 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
12587 tag
= DW_TAG_rvalue_reference_type
;
12589 tag
= DW_TAG_reference_type
;
12591 mod_type_die
= new_die (tag
, mod_scope
, type
);
12593 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12594 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12595 add_alignment_attribute (mod_type_die
, type
);
12596 item_type
= TREE_TYPE (type
);
12598 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
12599 if (!ADDR_SPACE_GENERIC_P (as
))
12601 int action
= targetm
.addr_space
.debug (as
);
12604 /* Positive values indicate an address_class. */
12605 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
12609 /* Negative values indicate an (inverted) segment base reg. */
12611 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
12612 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
12616 else if (code
== INTEGER_TYPE
12617 && TREE_TYPE (type
) != NULL_TREE
12618 && subrange_type_for_debug_p (type
, &low
, &high
))
12620 tree bias
= NULL_TREE
;
12621 if (lang_hooks
.types
.get_type_bias
)
12622 bias
= lang_hooks
.types
.get_type_bias (type
);
12623 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
12624 item_type
= TREE_TYPE (type
);
12626 else if (is_base_type (type
))
12627 mod_type_die
= base_type_die (type
, reverse
);
12630 gen_type_die (type
, context_die
);
12632 /* We have to get the type_main_variant here (and pass that to the
12633 `lookup_type_die' routine) because the ..._TYPE node we have
12634 might simply be a *copy* of some original type node (where the
12635 copy was created to help us keep track of typedef names) and
12636 that copy might have a different TYPE_UID from the original
12638 if (TREE_CODE (type
) == FUNCTION_TYPE
12639 || TREE_CODE (type
) == METHOD_TYPE
)
12641 /* For function/method types, can't just use type_main_variant here,
12642 because that can have different ref-qualifiers for C++,
12643 but try to canonicalize. */
12644 tree main
= TYPE_MAIN_VARIANT (type
);
12645 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
12646 if (check_base_type (t
, main
) && check_lang_type (t
, type
))
12647 return lookup_type_die (t
);
12648 return lookup_type_die (type
);
12650 else if (TREE_CODE (type
) != VECTOR_TYPE
12651 && TREE_CODE (type
) != ARRAY_TYPE
)
12652 return lookup_type_die (type_main_variant (type
));
12654 /* Vectors have the debugging information in the type,
12655 not the main variant. */
12656 return lookup_type_die (type
);
12659 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12660 don't output a DW_TAG_typedef, since there isn't one in the
12661 user's program; just attach a DW_AT_name to the type.
12662 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12663 if the base type already has the same name. */
12665 && ((TREE_CODE (name
) != TYPE_DECL
12666 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
12667 || (cv_quals
== TYPE_UNQUALIFIED
)))
12668 || (TREE_CODE (name
) == TYPE_DECL
12669 && TREE_TYPE (name
) == qualified_type
12670 && DECL_NAME (name
))))
12672 if (TREE_CODE (name
) == TYPE_DECL
)
12673 /* Could just call add_name_and_src_coords_attributes here,
12674 but since this is a builtin type it doesn't have any
12675 useful source coordinates anyway. */
12676 name
= DECL_NAME (name
);
12677 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
12679 /* This probably indicates a bug. */
12680 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
12682 name
= TYPE_IDENTIFIER (type
);
12683 add_name_attribute (mod_type_die
,
12684 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
12687 if (qualified_type
)
12688 equate_type_number_to_die (qualified_type
, mod_type_die
);
12691 /* We must do this after the equate_type_number_to_die call, in case
12692 this is a recursive type. This ensures that the modified_type_die
12693 recursion will terminate even if the type is recursive. Recursive
12694 types are possible in Ada. */
12695 sub_die
= modified_type_die (item_type
,
12696 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
12700 if (sub_die
!= NULL
)
12701 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
12703 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
12704 if (TYPE_ARTIFICIAL (type
))
12705 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
12707 return mod_type_die
;
12710 /* Generate DIEs for the generic parameters of T.
12711 T must be either a generic type or a generic function.
12712 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12715 gen_generic_params_dies (tree t
)
12719 dw_die_ref die
= NULL
;
12722 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
12726 die
= lookup_type_die (t
);
12727 else if (DECL_P (t
))
12728 die
= lookup_decl_die (t
);
12732 parms
= lang_hooks
.get_innermost_generic_parms (t
);
12734 /* T has no generic parameter. It means T is neither a generic type
12735 or function. End of story. */
12738 parms_num
= TREE_VEC_LENGTH (parms
);
12739 args
= lang_hooks
.get_innermost_generic_args (t
);
12740 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
12741 non_default
= int_cst_value (TREE_CHAIN (args
));
12743 non_default
= TREE_VEC_LENGTH (args
);
12744 for (i
= 0; i
< parms_num
; i
++)
12746 tree parm
, arg
, arg_pack_elems
;
12747 dw_die_ref parm_die
;
12749 parm
= TREE_VEC_ELT (parms
, i
);
12750 arg
= TREE_VEC_ELT (args
, i
);
12751 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
12752 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
12754 if (parm
&& TREE_VALUE (parm
) && arg
)
12756 /* If PARM represents a template parameter pack,
12757 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12758 by DW_TAG_template_*_parameter DIEs for the argument
12759 pack elements of ARG. Note that ARG would then be
12760 an argument pack. */
12761 if (arg_pack_elems
)
12762 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
12766 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
12767 true /* emit name */, die
);
12768 if (i
>= non_default
)
12769 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
12774 /* Create and return a DIE for PARM which should be
12775 the representation of a generic type parameter.
12776 For instance, in the C++ front end, PARM would be a template parameter.
12777 ARG is the argument to PARM.
12778 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12780 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12781 as a child node. */
12784 generic_parameter_die (tree parm
, tree arg
,
12786 dw_die_ref parent_die
)
12788 dw_die_ref tmpl_die
= NULL
;
12789 const char *name
= NULL
;
12791 if (!parm
|| !DECL_NAME (parm
) || !arg
)
12794 /* We support non-type generic parameters and arguments,
12795 type generic parameters and arguments, as well as
12796 generic generic parameters (a.k.a. template template parameters in C++)
12798 if (TREE_CODE (parm
) == PARM_DECL
)
12799 /* PARM is a nontype generic parameter */
12800 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
12801 else if (TREE_CODE (parm
) == TYPE_DECL
)
12802 /* PARM is a type generic parameter. */
12803 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
12804 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12805 /* PARM is a generic generic parameter.
12806 Its DIE is a GNU extension. It shall have a
12807 DW_AT_name attribute to represent the name of the template template
12808 parameter, and a DW_AT_GNU_template_name attribute to represent the
12809 name of the template template argument. */
12810 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
12813 gcc_unreachable ();
12819 /* If PARM is a generic parameter pack, it means we are
12820 emitting debug info for a template argument pack element.
12821 In other terms, ARG is a template argument pack element.
12822 In that case, we don't emit any DW_AT_name attribute for
12826 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
12828 add_AT_string (tmpl_die
, DW_AT_name
, name
);
12831 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12833 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
12834 TMPL_DIE should have a child DW_AT_type attribute that is set
12835 to the type of the argument to PARM, which is ARG.
12836 If PARM is a type generic parameter, TMPL_DIE should have a
12837 child DW_AT_type that is set to ARG. */
12838 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
12839 add_type_attribute (tmpl_die
, tmpl_type
,
12840 (TREE_THIS_VOLATILE (tmpl_type
)
12841 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
12842 false, parent_die
);
12846 /* So TMPL_DIE is a DIE representing a
12847 a generic generic template parameter, a.k.a template template
12848 parameter in C++ and arg is a template. */
12850 /* The DW_AT_GNU_template_name attribute of the DIE must be set
12851 to the name of the argument. */
12852 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
12854 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
12857 if (TREE_CODE (parm
) == PARM_DECL
)
12858 /* So PARM is a non-type generic parameter.
12859 DWARF3 5.6.8 says we must set a DW_AT_const_value child
12860 attribute of TMPL_DIE which value represents the value
12862 We must be careful here:
12863 The value of ARG might reference some function decls.
12864 We might currently be emitting debug info for a generic
12865 type and types are emitted before function decls, we don't
12866 know if the function decls referenced by ARG will actually be
12867 emitted after cgraph computations.
12868 So must defer the generation of the DW_AT_const_value to
12869 after cgraph is ready. */
12870 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
12876 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
12877 PARM_PACK must be a template parameter pack. The returned DIE
12878 will be child DIE of PARENT_DIE. */
12881 template_parameter_pack_die (tree parm_pack
,
12882 tree parm_pack_args
,
12883 dw_die_ref parent_die
)
12888 gcc_assert (parent_die
&& parm_pack
);
12890 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
12891 add_name_and_src_coords_attributes (die
, parm_pack
);
12892 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
12893 generic_parameter_die (parm_pack
,
12894 TREE_VEC_ELT (parm_pack_args
, j
),
12895 false /* Don't emit DW_AT_name */,
12900 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
12901 an enumerated type. */
12904 type_is_enum (const_tree type
)
12906 return TREE_CODE (type
) == ENUMERAL_TYPE
;
12909 /* Return the DBX register number described by a given RTL node. */
12911 static unsigned int
12912 dbx_reg_number (const_rtx rtl
)
12914 unsigned regno
= REGNO (rtl
);
12916 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
12918 #ifdef LEAF_REG_REMAP
12919 if (crtl
->uses_only_leaf_regs
)
12921 int leaf_reg
= LEAF_REG_REMAP (regno
);
12922 if (leaf_reg
!= -1)
12923 regno
= (unsigned) leaf_reg
;
12927 regno
= DBX_REGISTER_NUMBER (regno
);
12928 gcc_assert (regno
!= INVALID_REGNUM
);
12932 /* Optionally add a DW_OP_piece term to a location description expression.
12933 DW_OP_piece is only added if the location description expression already
12934 doesn't end with DW_OP_piece. */
12937 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
12939 dw_loc_descr_ref loc
;
12941 if (*list_head
!= NULL
)
12943 /* Find the end of the chain. */
12944 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
12947 if (loc
->dw_loc_opc
!= DW_OP_piece
)
12948 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
12952 /* Return a location descriptor that designates a machine register or
12953 zero if there is none. */
12955 static dw_loc_descr_ref
12956 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
12960 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
12963 /* We only use "frame base" when we're sure we're talking about the
12964 post-prologue local stack frame. We do this by *not* running
12965 register elimination until this point, and recognizing the special
12966 argument pointer and soft frame pointer rtx's.
12967 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
12968 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
12969 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
12971 dw_loc_descr_ref result
= NULL
;
12973 if (dwarf_version
>= 4 || !dwarf_strict
)
12975 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
12978 add_loc_descr (&result
,
12979 new_loc_descr (DW_OP_stack_value
, 0, 0));
12984 regs
= targetm
.dwarf_register_span (rtl
);
12986 if (REG_NREGS (rtl
) > 1 || regs
)
12987 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
12990 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
12991 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12993 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
12997 /* Return a location descriptor that designates a machine register for
12998 a given hard register number. */
13000 static dw_loc_descr_ref
13001 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
13003 dw_loc_descr_ref reg_loc_descr
;
13007 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
13009 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
13011 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13012 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13014 return reg_loc_descr
;
13017 /* Given an RTL of a register, return a location descriptor that
13018 designates a value that spans more than one register. */
13020 static dw_loc_descr_ref
13021 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
13022 enum var_init_status initialized
)
13025 dw_loc_descr_ref loc_result
= NULL
;
13027 /* Simple, contiguous registers. */
13028 if (regs
== NULL_RTX
)
13030 unsigned reg
= REGNO (rtl
);
13033 #ifdef LEAF_REG_REMAP
13034 if (crtl
->uses_only_leaf_regs
)
13036 int leaf_reg
= LEAF_REG_REMAP (reg
);
13037 if (leaf_reg
!= -1)
13038 reg
= (unsigned) leaf_reg
;
13042 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
13043 nregs
= REG_NREGS (rtl
);
13045 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
13050 dw_loc_descr_ref t
;
13052 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
13053 VAR_INIT_STATUS_INITIALIZED
);
13054 add_loc_descr (&loc_result
, t
);
13055 add_loc_descr_op_piece (&loc_result
, size
);
13061 /* Now onto stupid register sets in non contiguous locations. */
13063 gcc_assert (GET_CODE (regs
) == PARALLEL
);
13065 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13068 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
13070 dw_loc_descr_ref t
;
13072 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
13073 VAR_INIT_STATUS_INITIALIZED
);
13074 add_loc_descr (&loc_result
, t
);
13075 add_loc_descr_op_piece (&loc_result
, size
);
13078 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13079 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13083 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
13085 /* Return a location descriptor that designates a constant i,
13086 as a compound operation from constant (i >> shift), constant shift
13089 static dw_loc_descr_ref
13090 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13092 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
13093 add_loc_descr (&ret
, int_loc_descriptor (shift
));
13094 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13098 /* Return a location descriptor that designates a constant. */
13100 static dw_loc_descr_ref
13101 int_loc_descriptor (HOST_WIDE_INT i
)
13103 enum dwarf_location_atom op
;
13105 /* Pick the smallest representation of a constant, rather than just
13106 defaulting to the LEB encoding. */
13109 int clz
= clz_hwi (i
);
13110 int ctz
= ctz_hwi (i
);
13112 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
13113 else if (i
<= 0xff)
13114 op
= DW_OP_const1u
;
13115 else if (i
<= 0xffff)
13116 op
= DW_OP_const2u
;
13117 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13118 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13119 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
13120 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
13121 while DW_OP_const4u is 5 bytes. */
13122 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
13123 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13124 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13125 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
13126 while DW_OP_const4u is 5 bytes. */
13127 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13129 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13130 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13133 /* As i >= 2**31, the double cast above will yield a negative number.
13134 Since wrapping is defined in DWARF expressions we can output big
13135 positive integers as small negative ones, regardless of the size
13138 Here, since the evaluator will handle 32-bit values and since i >=
13139 2**31, we know it's going to be interpreted as a negative literal:
13140 store it this way if we can do better than 5 bytes this way. */
13141 return int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13143 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13144 op
= DW_OP_const4u
;
13146 /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
13147 least 6 bytes: see if we can do better before falling back to it. */
13148 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13149 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13150 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
13151 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13152 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13153 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
13154 >= HOST_BITS_PER_WIDE_INT
)
13155 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
13156 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
13157 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
13158 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13159 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13160 && size_of_uleb128 (i
) > 6)
13161 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
13162 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
13169 op
= DW_OP_const1s
;
13170 else if (i
>= -0x8000)
13171 op
= DW_OP_const2s
;
13172 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13174 if (size_of_int_loc_descriptor (i
) < 5)
13176 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13177 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13180 op
= DW_OP_const4s
;
13184 if (size_of_int_loc_descriptor (i
)
13185 < (unsigned long) 1 + size_of_sleb128 (i
))
13187 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13188 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13195 return new_loc_descr (op
, i
, 0);
13198 /* Likewise, for unsigned constants. */
13200 static dw_loc_descr_ref
13201 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
13203 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
13204 const unsigned HOST_WIDE_INT max_uint
13205 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
13207 /* If possible, use the clever signed constants handling. */
13209 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
13211 /* Here, we are left with positive numbers that cannot be represented as
13212 HOST_WIDE_INT, i.e.:
13213 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
13215 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
13216 whereas may be better to output a negative integer: thanks to integer
13217 wrapping, we know that:
13218 x = x - 2 ** DWARF2_ADDR_SIZE
13219 = x - 2 * (max (HOST_WIDE_INT) + 1)
13220 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
13221 small negative integers. Let's try that in cases it will clearly improve
13222 the encoding: there is no gain turning DW_OP_const4u into
13224 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
13225 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
13226 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
13228 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
13230 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
13231 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
13232 const HOST_WIDE_INT second_shift
13233 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
13235 /* So we finally have:
13236 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
13237 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
13238 return int_loc_descriptor (second_shift
);
13241 /* Last chance: fallback to a simple constant operation. */
13242 return new_loc_descr
13243 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13249 /* Generate and return a location description that computes the unsigned
13250 comparison of the two stack top entries (a OP b where b is the top-most
13251 entry and a is the second one). The KIND of comparison can be LT_EXPR,
13252 LE_EXPR, GT_EXPR or GE_EXPR. */
13254 static dw_loc_descr_ref
13255 uint_comparison_loc_list (enum tree_code kind
)
13257 enum dwarf_location_atom op
, flip_op
;
13258 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
13275 gcc_unreachable ();
13278 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13279 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13281 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
13282 possible to perform unsigned comparisons: we just have to distinguish
13285 1. when a and b have the same sign (as signed integers); then we should
13286 return: a OP(signed) b;
13288 2. when a is a negative signed integer while b is a positive one, then a
13289 is a greater unsigned integer than b; likewise when a and b's roles
13292 So first, compare the sign of the two operands. */
13293 ret
= new_loc_descr (DW_OP_over
, 0, 0);
13294 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13295 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
13296 /* If they have different signs (i.e. they have different sign bits), then
13297 the stack top value has now the sign bit set and thus it's smaller than
13299 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
13300 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
13301 add_loc_descr (&ret
, bra_node
);
13303 /* We are in case 1. At this point, we know both operands have the same
13304 sign, to it's safe to use the built-in signed comparison. */
13305 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13306 add_loc_descr (&ret
, jmp_node
);
13308 /* We are in case 2. Here, we know both operands do not have the same sign,
13309 so we have to flip the signed comparison. */
13310 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
13311 tmp
= new_loc_descr (flip_op
, 0, 0);
13312 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13313 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13314 add_loc_descr (&ret
, tmp
);
13316 /* This dummy operation is necessary to make the two branches join. */
13317 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13318 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13319 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13320 add_loc_descr (&ret
, tmp
);
13325 /* Likewise, but takes the location description lists (might be destructive on
13326 them). Return NULL if either is NULL or if concatenation fails. */
13328 static dw_loc_list_ref
13329 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
13330 enum tree_code kind
)
13332 if (left
== NULL
|| right
== NULL
)
13335 add_loc_list (&left
, right
);
13339 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
13343 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
13344 without actually allocating it. */
13346 static unsigned long
13347 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13349 return size_of_int_loc_descriptor (i
>> shift
)
13350 + size_of_int_loc_descriptor (shift
)
13354 /* Return size_of_locs (int_loc_descriptor (i)) without
13355 actually allocating it. */
13357 static unsigned long
13358 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
13367 else if (i
<= 0xff)
13369 else if (i
<= 0xffff)
13373 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13374 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13375 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13377 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13378 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13379 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13381 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13382 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13384 return size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13385 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13387 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
13388 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13389 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13390 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13392 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13393 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
13394 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13396 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13397 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13399 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13408 else if (i
>= -0x8000)
13410 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13412 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13414 s
= size_of_int_loc_descriptor (-i
) + 1;
13422 unsigned long r
= 1 + size_of_sleb128 (i
);
13423 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13425 s
= size_of_int_loc_descriptor (-i
) + 1;
13434 /* Return loc description representing "address" of integer value.
13435 This can appear only as toplevel expression. */
13437 static dw_loc_descr_ref
13438 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
13441 dw_loc_descr_ref loc_result
= NULL
;
13443 if (!(dwarf_version
>= 4 || !dwarf_strict
))
13446 litsize
= size_of_int_loc_descriptor (i
);
13447 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13448 is more compact. For DW_OP_stack_value we need:
13449 litsize + 1 (DW_OP_stack_value)
13450 and for DW_OP_implicit_value:
13451 1 (DW_OP_implicit_value) + 1 (length) + size. */
13452 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
13454 loc_result
= int_loc_descriptor (i
);
13455 add_loc_descr (&loc_result
,
13456 new_loc_descr (DW_OP_stack_value
, 0, 0));
13460 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13462 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13463 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
13467 /* Return a location descriptor that designates a base+offset location. */
13469 static dw_loc_descr_ref
13470 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
13471 enum var_init_status initialized
)
13473 unsigned int regno
;
13474 dw_loc_descr_ref result
;
13475 dw_fde_ref fde
= cfun
->fde
;
13477 /* We only use "frame base" when we're sure we're talking about the
13478 post-prologue local stack frame. We do this by *not* running
13479 register elimination until this point, and recognizing the special
13480 argument pointer and soft frame pointer rtx's. */
13481 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
13483 rtx elim
= (ira_use_lra_p
13484 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
13485 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
13489 if (GET_CODE (elim
) == PLUS
)
13491 offset
+= INTVAL (XEXP (elim
, 1));
13492 elim
= XEXP (elim
, 0);
13494 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13495 && (elim
== hard_frame_pointer_rtx
13496 || elim
== stack_pointer_rtx
))
13497 || elim
== (frame_pointer_needed
13498 ? hard_frame_pointer_rtx
13499 : stack_pointer_rtx
));
13501 /* If drap register is used to align stack, use frame
13502 pointer + offset to access stack variables. If stack
13503 is aligned without drap, use stack pointer + offset to
13504 access stack variables. */
13505 if (crtl
->stack_realign_tried
13506 && reg
== frame_pointer_rtx
)
13509 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
13510 ? HARD_FRAME_POINTER_REGNUM
13512 return new_reg_loc_descr (base_reg
, offset
);
13515 gcc_assert (frame_pointer_fb_offset_valid
);
13516 offset
+= frame_pointer_fb_offset
;
13517 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13521 regno
= REGNO (reg
);
13522 #ifdef LEAF_REG_REMAP
13523 if (crtl
->uses_only_leaf_regs
)
13525 int leaf_reg
= LEAF_REG_REMAP (regno
);
13526 if (leaf_reg
!= -1)
13527 regno
= (unsigned) leaf_reg
;
13530 regno
= DWARF_FRAME_REGNUM (regno
);
13532 if (!optimize
&& fde
13533 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
13535 /* Use cfa+offset to represent the location of arguments passed
13536 on the stack when drap is used to align stack.
13537 Only do this when not optimizing, for optimized code var-tracking
13538 is supposed to track where the arguments live and the register
13539 used as vdrap or drap in some spot might be used for something
13540 else in other part of the routine. */
13541 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13545 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
13548 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
13550 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13551 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13556 /* Return true if this RTL expression describes a base+offset calculation. */
13559 is_based_loc (const_rtx rtl
)
13561 return (GET_CODE (rtl
) == PLUS
13562 && ((REG_P (XEXP (rtl
, 0))
13563 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
13564 && CONST_INT_P (XEXP (rtl
, 1)))));
13567 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13570 static dw_loc_descr_ref
13571 tls_mem_loc_descriptor (rtx mem
)
13574 dw_loc_descr_ref loc_result
;
13576 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
13579 base
= get_base_address (MEM_EXPR (mem
));
13582 || !DECL_THREAD_LOCAL_P (base
))
13585 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
13586 if (loc_result
== NULL
)
13589 if (MEM_OFFSET (mem
))
13590 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
13595 /* Output debug info about reason why we failed to expand expression as dwarf
13599 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
13601 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
13603 fprintf (dump_file
, "Failed to expand as dwarf: ");
13605 print_generic_expr (dump_file
, expr
, dump_flags
);
13608 fprintf (dump_file
, "\n");
13609 print_rtl (dump_file
, rtl
);
13611 fprintf (dump_file
, "\nReason: %s\n", reason
);
13615 /* Helper function for const_ok_for_output. */
13618 const_ok_for_output_1 (rtx rtl
)
13620 if (GET_CODE (rtl
) == UNSPEC
)
13622 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13623 we can't express it in the debug info. */
13624 /* Don't complain about TLS UNSPECs, those are just too hard to
13625 delegitimize. Note this could be a non-decl SYMBOL_REF such as
13626 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
13627 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
13629 && (XVECLEN (rtl
, 0) == 0
13630 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
13631 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
13632 inform (current_function_decl
13633 ? DECL_SOURCE_LOCATION (current_function_decl
)
13634 : UNKNOWN_LOCATION
,
13635 #if NUM_UNSPEC_VALUES > 0
13636 "non-delegitimized UNSPEC %s (%d) found in variable location",
13637 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
13638 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
13641 "non-delegitimized UNSPEC %d found in variable location",
13644 expansion_failed (NULL_TREE
, rtl
,
13645 "UNSPEC hasn't been delegitimized.\n");
13649 if (targetm
.const_not_ok_for_debug_p (rtl
))
13651 expansion_failed (NULL_TREE
, rtl
,
13652 "Expression rejected for debug by the backend.\n");
13656 /* FIXME: Refer to PR60655. It is possible for simplification
13657 of rtl expressions in var tracking to produce such expressions.
13658 We should really identify / validate expressions
13659 enclosed in CONST that can be handled by assemblers on various
13660 targets and only handle legitimate cases here. */
13661 if (GET_CODE (rtl
) != SYMBOL_REF
)
13663 if (GET_CODE (rtl
) == NOT
)
13668 if (CONSTANT_POOL_ADDRESS_P (rtl
))
13671 get_pool_constant_mark (rtl
, &marked
);
13672 /* If all references to this pool constant were optimized away,
13673 it was not output and thus we can't represent it. */
13676 expansion_failed (NULL_TREE
, rtl
,
13677 "Constant was removed from constant pool.\n");
13682 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13685 /* Avoid references to external symbols in debug info, on several targets
13686 the linker might even refuse to link when linking a shared library,
13687 and in many other cases the relocations for .debug_info/.debug_loc are
13688 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13689 to be defined within the same shared library or executable are fine. */
13690 if (SYMBOL_REF_EXTERNAL_P (rtl
))
13692 tree decl
= SYMBOL_REF_DECL (rtl
);
13694 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
13696 expansion_failed (NULL_TREE
, rtl
,
13697 "Symbol not defined in current TU.\n");
13705 /* Return true if constant RTL can be emitted in DW_OP_addr or
13706 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13707 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13710 const_ok_for_output (rtx rtl
)
13712 if (GET_CODE (rtl
) == SYMBOL_REF
)
13713 return const_ok_for_output_1 (rtl
);
13715 if (GET_CODE (rtl
) == CONST
)
13717 subrtx_var_iterator::array_type array
;
13718 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
13719 if (!const_ok_for_output_1 (*iter
))
13727 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
13728 if possible, NULL otherwise. */
13731 base_type_for_mode (machine_mode mode
, bool unsignedp
)
13733 dw_die_ref type_die
;
13734 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
13738 switch (TREE_CODE (type
))
13746 type_die
= lookup_type_die (type
);
13748 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
13750 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
13755 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
13756 type matching MODE, or, if MODE is narrower than or as wide as
13757 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
13760 static dw_loc_descr_ref
13761 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
13763 machine_mode outer_mode
= mode
;
13764 dw_die_ref type_die
;
13765 dw_loc_descr_ref cvt
;
13767 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13769 add_loc_descr (&op
, new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
13772 type_die
= base_type_for_mode (outer_mode
, 1);
13773 if (type_die
== NULL
)
13775 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13776 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13777 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13778 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13779 add_loc_descr (&op
, cvt
);
13783 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
13785 static dw_loc_descr_ref
13786 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
13787 dw_loc_descr_ref op1
)
13789 dw_loc_descr_ref ret
= op0
;
13790 add_loc_descr (&ret
, op1
);
13791 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13792 if (STORE_FLAG_VALUE
!= 1)
13794 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
13795 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13800 /* Return location descriptor for signed comparison OP RTL. */
13802 static dw_loc_descr_ref
13803 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
13804 machine_mode mem_mode
)
13806 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13807 dw_loc_descr_ref op0
, op1
;
13810 if (op_mode
== VOIDmode
)
13811 op_mode
= GET_MODE (XEXP (rtl
, 1));
13812 if (op_mode
== VOIDmode
)
13816 && dwarf_version
< 5
13817 && (!SCALAR_INT_MODE_P (op_mode
)
13818 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
13821 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
13822 VAR_INIT_STATUS_INITIALIZED
);
13823 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
13824 VAR_INIT_STATUS_INITIALIZED
);
13826 if (op0
== NULL
|| op1
== NULL
)
13829 if (!SCALAR_INT_MODE_P (op_mode
)
13830 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
13831 return compare_loc_descriptor (op
, op0
, op1
);
13833 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
13835 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
13836 dw_loc_descr_ref cvt
;
13838 if (type_die
== NULL
)
13840 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13841 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13842 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13843 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13844 add_loc_descr (&op0
, cvt
);
13845 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13846 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13847 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13848 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13849 add_loc_descr (&op1
, cvt
);
13850 return compare_loc_descriptor (op
, op0
, op1
);
13853 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
13854 /* For eq/ne, if the operands are known to be zero-extended,
13855 there is no need to do the fancy shifting up. */
13856 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
13858 dw_loc_descr_ref last0
, last1
;
13859 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
13861 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
13863 /* deref_size zero extends, and for constants we can check
13864 whether they are zero extended or not. */
13865 if (((last0
->dw_loc_opc
== DW_OP_deref_size
13866 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
13867 || (CONST_INT_P (XEXP (rtl
, 0))
13868 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
13869 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
13870 && ((last1
->dw_loc_opc
== DW_OP_deref_size
13871 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
13872 || (CONST_INT_P (XEXP (rtl
, 1))
13873 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
13874 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
13875 return compare_loc_descriptor (op
, op0
, op1
);
13877 /* EQ/NE comparison against constant in narrower type than
13878 DWARF2_ADDR_SIZE can be performed either as
13879 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
13882 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
13883 DW_OP_{eq,ne}. Pick whatever is shorter. */
13884 if (CONST_INT_P (XEXP (rtl
, 1))
13885 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
13886 && (size_of_int_loc_descriptor (shift
) + 1
13887 + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
)
13888 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
13889 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
13890 & GET_MODE_MASK (op_mode
))))
13892 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
13893 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
13894 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
13895 & GET_MODE_MASK (op_mode
));
13896 return compare_loc_descriptor (op
, op0
, op1
);
13899 add_loc_descr (&op0
, int_loc_descriptor (shift
));
13900 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
13901 if (CONST_INT_P (XEXP (rtl
, 1)))
13902 op1
= int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
);
13905 add_loc_descr (&op1
, int_loc_descriptor (shift
));
13906 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
13908 return compare_loc_descriptor (op
, op0
, op1
);
13911 /* Return location descriptor for unsigned comparison OP RTL. */
13913 static dw_loc_descr_ref
13914 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
13915 machine_mode mem_mode
)
13917 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13918 dw_loc_descr_ref op0
, op1
;
13920 if (op_mode
== VOIDmode
)
13921 op_mode
= GET_MODE (XEXP (rtl
, 1));
13922 if (op_mode
== VOIDmode
)
13924 if (!SCALAR_INT_MODE_P (op_mode
))
13928 && dwarf_version
< 5
13929 && GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
13932 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
13933 VAR_INIT_STATUS_INITIALIZED
);
13934 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
13935 VAR_INIT_STATUS_INITIALIZED
);
13937 if (op0
== NULL
|| op1
== NULL
)
13940 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
13942 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
13943 dw_loc_descr_ref last0
, last1
;
13944 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
13946 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
13948 if (CONST_INT_P (XEXP (rtl
, 0)))
13949 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
13950 /* deref_size zero extends, so no need to mask it again. */
13951 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
13952 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
13954 add_loc_descr (&op0
, int_loc_descriptor (mask
));
13955 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
13957 if (CONST_INT_P (XEXP (rtl
, 1)))
13958 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
13959 /* deref_size zero extends, so no need to mask it again. */
13960 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
13961 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
13963 add_loc_descr (&op1
, int_loc_descriptor (mask
));
13964 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
13967 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
13969 HOST_WIDE_INT bias
= 1;
13970 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
13971 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
13972 if (CONST_INT_P (XEXP (rtl
, 1)))
13973 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
13974 + INTVAL (XEXP (rtl
, 1)));
13976 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
13979 return compare_loc_descriptor (op
, op0
, op1
);
13982 /* Return location descriptor for {U,S}{MIN,MAX}. */
13984 static dw_loc_descr_ref
13985 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
13986 machine_mode mem_mode
)
13988 enum dwarf_location_atom op
;
13989 dw_loc_descr_ref op0
, op1
, ret
;
13990 dw_loc_descr_ref bra_node
, drop_node
;
13993 && dwarf_version
< 5
13994 && (!SCALAR_INT_MODE_P (mode
)
13995 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
13998 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13999 VAR_INIT_STATUS_INITIALIZED
);
14000 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14001 VAR_INIT_STATUS_INITIALIZED
);
14003 if (op0
== NULL
|| op1
== NULL
)
14006 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
14007 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
14008 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
14009 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
14011 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14013 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
14014 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14015 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14016 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14017 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14019 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
14021 HOST_WIDE_INT bias
= 1;
14022 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14023 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14024 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14027 else if (!SCALAR_INT_MODE_P (mode
)
14028 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14030 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
14031 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14032 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14033 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14034 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14036 else if (SCALAR_INT_MODE_P (mode
)
14037 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14039 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
14040 dw_loc_descr_ref cvt
;
14041 if (type_die
== NULL
)
14043 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14044 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14045 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14046 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14047 add_loc_descr (&op0
, cvt
);
14048 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14049 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14050 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14051 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14052 add_loc_descr (&op1
, cvt
);
14055 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
14060 add_loc_descr (&ret
, op1
);
14061 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
14062 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14063 add_loc_descr (&ret
, bra_node
);
14064 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14065 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14066 add_loc_descr (&ret
, drop_node
);
14067 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14068 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14069 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
14070 && SCALAR_INT_MODE_P (mode
)
14071 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14072 ret
= convert_descriptor_to_mode (mode
, ret
);
14076 /* Helper function for mem_loc_descriptor. Perform OP binary op,
14077 but after converting arguments to type_die, afterwards
14078 convert back to unsigned. */
14080 static dw_loc_descr_ref
14081 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
14082 machine_mode mode
, machine_mode mem_mode
)
14084 dw_loc_descr_ref cvt
, op0
, op1
;
14086 if (type_die
== NULL
)
14088 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14089 VAR_INIT_STATUS_INITIALIZED
);
14090 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14091 VAR_INIT_STATUS_INITIALIZED
);
14092 if (op0
== NULL
|| op1
== NULL
)
14094 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14095 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14096 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14097 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14098 add_loc_descr (&op0
, cvt
);
14099 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14100 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14101 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14102 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14103 add_loc_descr (&op1
, cvt
);
14104 add_loc_descr (&op0
, op1
);
14105 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
14106 return convert_descriptor_to_mode (mode
, op0
);
14109 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
14110 const0 is DW_OP_lit0 or corresponding typed constant,
14111 const1 is DW_OP_lit1 or corresponding typed constant
14112 and constMSB is constant with just the MSB bit set
14114 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14115 L1: const0 DW_OP_swap
14116 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
14117 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14122 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14123 L1: const0 DW_OP_swap
14124 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14125 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14130 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
14131 L1: const1 DW_OP_swap
14132 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14133 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14137 static dw_loc_descr_ref
14138 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
14139 machine_mode mem_mode
)
14141 dw_loc_descr_ref op0
, ret
, tmp
;
14142 HOST_WIDE_INT valv
;
14143 dw_loc_descr_ref l1jump
, l1label
;
14144 dw_loc_descr_ref l2jump
, l2label
;
14145 dw_loc_descr_ref l3jump
, l3label
;
14146 dw_loc_descr_ref l4jump
, l4label
;
14149 if (!SCALAR_INT_MODE_P (mode
)
14150 || GET_MODE (XEXP (rtl
, 0)) != mode
)
14153 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14154 VAR_INIT_STATUS_INITIALIZED
);
14158 if (GET_CODE (rtl
) == CLZ
)
14160 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14161 valv
= GET_MODE_BITSIZE (mode
);
14163 else if (GET_CODE (rtl
) == FFS
)
14165 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14166 valv
= GET_MODE_BITSIZE (mode
);
14167 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14168 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14169 add_loc_descr (&ret
, l1jump
);
14170 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14171 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
14172 VAR_INIT_STATUS_INITIALIZED
);
14175 add_loc_descr (&ret
, tmp
);
14176 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14177 add_loc_descr (&ret
, l4jump
);
14178 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
14179 ? const1_rtx
: const0_rtx
,
14181 VAR_INIT_STATUS_INITIALIZED
);
14182 if (l1label
== NULL
)
14184 add_loc_descr (&ret
, l1label
);
14185 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14186 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
14187 add_loc_descr (&ret
, l2label
);
14188 if (GET_CODE (rtl
) != CLZ
)
14190 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
14191 msb
= GEN_INT (HOST_WIDE_INT_1U
14192 << (GET_MODE_BITSIZE (mode
) - 1));
14194 msb
= immed_wide_int_const
14195 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
14196 GET_MODE_PRECISION (mode
)), mode
);
14197 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
14198 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14199 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
14200 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
14202 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
14203 VAR_INIT_STATUS_INITIALIZED
);
14206 add_loc_descr (&ret
, tmp
);
14207 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14208 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14209 add_loc_descr (&ret
, l3jump
);
14210 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14211 VAR_INIT_STATUS_INITIALIZED
);
14214 add_loc_descr (&ret
, tmp
);
14215 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
14216 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
14217 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14218 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
14219 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14220 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14221 add_loc_descr (&ret
, l2jump
);
14222 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
14223 add_loc_descr (&ret
, l3label
);
14224 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
14225 add_loc_descr (&ret
, l4label
);
14226 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14227 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14228 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14229 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14230 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14231 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
14232 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14233 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
14237 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
14238 const1 is DW_OP_lit1 or corresponding typed constant):
14240 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14241 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14245 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14246 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14249 static dw_loc_descr_ref
14250 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
14251 machine_mode mem_mode
)
14253 dw_loc_descr_ref op0
, ret
, tmp
;
14254 dw_loc_descr_ref l1jump
, l1label
;
14255 dw_loc_descr_ref l2jump
, l2label
;
14257 if (!SCALAR_INT_MODE_P (mode
)
14258 || GET_MODE (XEXP (rtl
, 0)) != mode
)
14261 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14262 VAR_INIT_STATUS_INITIALIZED
);
14266 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14267 VAR_INIT_STATUS_INITIALIZED
);
14270 add_loc_descr (&ret
, tmp
);
14271 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14272 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
14273 add_loc_descr (&ret
, l1label
);
14274 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14275 add_loc_descr (&ret
, l2jump
);
14276 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14277 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14278 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14279 VAR_INIT_STATUS_INITIALIZED
);
14282 add_loc_descr (&ret
, tmp
);
14283 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14284 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
14285 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
14286 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14287 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14288 VAR_INIT_STATUS_INITIALIZED
);
14289 add_loc_descr (&ret
, tmp
);
14290 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14291 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14292 add_loc_descr (&ret
, l1jump
);
14293 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14294 add_loc_descr (&ret
, l2label
);
14295 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14296 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14297 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14298 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14302 /* BSWAP (constS is initial shift count, either 56 or 24):
14304 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
14305 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
14306 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
14307 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
14308 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
14310 static dw_loc_descr_ref
14311 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
14312 machine_mode mem_mode
)
14314 dw_loc_descr_ref op0
, ret
, tmp
;
14315 dw_loc_descr_ref l1jump
, l1label
;
14316 dw_loc_descr_ref l2jump
, l2label
;
14318 if (!SCALAR_INT_MODE_P (mode
)
14319 || BITS_PER_UNIT
!= 8
14320 || (GET_MODE_BITSIZE (mode
) != 32
14321 && GET_MODE_BITSIZE (mode
) != 64))
14324 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14325 VAR_INIT_STATUS_INITIALIZED
);
14330 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14332 VAR_INIT_STATUS_INITIALIZED
);
14335 add_loc_descr (&ret
, tmp
);
14336 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14337 VAR_INIT_STATUS_INITIALIZED
);
14340 add_loc_descr (&ret
, tmp
);
14341 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
14342 add_loc_descr (&ret
, l1label
);
14343 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14345 VAR_INIT_STATUS_INITIALIZED
);
14346 add_loc_descr (&ret
, tmp
);
14347 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
14348 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14349 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14350 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
14351 VAR_INIT_STATUS_INITIALIZED
);
14354 add_loc_descr (&ret
, tmp
);
14355 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14356 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
14357 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14358 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14359 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14360 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14361 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14362 VAR_INIT_STATUS_INITIALIZED
);
14363 add_loc_descr (&ret
, tmp
);
14364 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
14365 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14366 add_loc_descr (&ret
, l2jump
);
14367 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
14368 VAR_INIT_STATUS_INITIALIZED
);
14369 add_loc_descr (&ret
, tmp
);
14370 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14371 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14372 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14373 add_loc_descr (&ret
, l1jump
);
14374 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14375 add_loc_descr (&ret
, l2label
);
14376 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14377 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14378 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14379 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14380 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14381 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14385 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
14386 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14387 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
14388 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
14390 ROTATERT is similar:
14391 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
14392 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14393 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
14395 static dw_loc_descr_ref
14396 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
14397 machine_mode mem_mode
)
14399 rtx rtlop1
= XEXP (rtl
, 1);
14400 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
14403 if (!SCALAR_INT_MODE_P (mode
))
14406 if (GET_MODE (rtlop1
) != VOIDmode
14407 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
14408 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
14409 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14410 VAR_INIT_STATUS_INITIALIZED
);
14411 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
14412 VAR_INIT_STATUS_INITIALIZED
);
14413 if (op0
== NULL
|| op1
== NULL
)
14415 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14416 for (i
= 0; i
< 2; i
++)
14418 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
14419 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
14421 VAR_INIT_STATUS_INITIALIZED
);
14422 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
14423 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14425 : HOST_BITS_PER_WIDE_INT
== 64
14426 ? DW_OP_const8u
: DW_OP_constu
,
14427 GET_MODE_MASK (mode
), 0);
14430 if (mask
[i
] == NULL
)
14432 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
14435 add_loc_descr (&ret
, op1
);
14436 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14437 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14438 if (GET_CODE (rtl
) == ROTATERT
)
14440 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14441 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14442 GET_MODE_BITSIZE (mode
), 0));
14444 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14445 if (mask
[0] != NULL
)
14446 add_loc_descr (&ret
, mask
[0]);
14447 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14448 if (mask
[1] != NULL
)
14450 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14451 add_loc_descr (&ret
, mask
[1]);
14452 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14454 if (GET_CODE (rtl
) == ROTATE
)
14456 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14457 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14458 GET_MODE_BITSIZE (mode
), 0));
14460 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14461 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14465 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
14466 for DEBUG_PARAMETER_REF RTL. */
14468 static dw_loc_descr_ref
14469 parameter_ref_descriptor (rtx rtl
)
14471 dw_loc_descr_ref ret
;
14476 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
14477 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
14478 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
14481 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14482 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14483 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14487 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14488 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
14493 /* The following routine converts the RTL for a variable or parameter
14494 (resident in memory) into an equivalent Dwarf representation of a
14495 mechanism for getting the address of that same variable onto the top of a
14496 hypothetical "address evaluation" stack.
14498 When creating memory location descriptors, we are effectively transforming
14499 the RTL for a memory-resident object into its Dwarf postfix expression
14500 equivalent. This routine recursively descends an RTL tree, turning
14501 it into Dwarf postfix code as it goes.
14503 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
14505 MEM_MODE is the mode of the memory reference, needed to handle some
14506 autoincrement addressing modes.
14508 Return 0 if we can't represent the location. */
14511 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
14512 machine_mode mem_mode
,
14513 enum var_init_status initialized
)
14515 dw_loc_descr_ref mem_loc_result
= NULL
;
14516 enum dwarf_location_atom op
;
14517 dw_loc_descr_ref op0
, op1
;
14518 rtx inner
= NULL_RTX
;
14520 if (mode
== VOIDmode
)
14521 mode
= GET_MODE (rtl
);
14523 /* Note that for a dynamically sized array, the location we will generate a
14524 description of here will be the lowest numbered location which is
14525 actually within the array. That's *not* necessarily the same as the
14526 zeroth element of the array. */
14528 rtl
= targetm
.delegitimize_address (rtl
);
14530 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
14533 switch (GET_CODE (rtl
))
14538 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
14541 /* The case of a subreg may arise when we have a local (register)
14542 variable or a formal (register) parameter which doesn't quite fill
14543 up an entire register. For now, just assume that it is
14544 legitimate to make the Dwarf info refer to the whole register which
14545 contains the given subreg. */
14546 if (!subreg_lowpart_p (rtl
))
14548 inner
= SUBREG_REG (rtl
);
14551 if (inner
== NULL_RTX
)
14552 inner
= XEXP (rtl
, 0);
14553 if (SCALAR_INT_MODE_P (mode
)
14554 && SCALAR_INT_MODE_P (GET_MODE (inner
))
14555 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14556 #ifdef POINTERS_EXTEND_UNSIGNED
14557 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
14560 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
14562 mem_loc_result
= mem_loc_descriptor (inner
,
14564 mem_mode
, initialized
);
14567 if (dwarf_strict
&& dwarf_version
< 5)
14569 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
14571 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
14572 && (!SCALAR_INT_MODE_P (mode
)
14573 || !SCALAR_INT_MODE_P (GET_MODE (inner
))))
14577 dw_die_ref type_die
;
14578 dw_loc_descr_ref cvt
;
14580 mem_loc_result
= mem_loc_descriptor (inner
,
14582 mem_mode
, initialized
);
14583 if (mem_loc_result
== NULL
)
14585 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14586 if (type_die
== NULL
)
14588 mem_loc_result
= NULL
;
14591 if (GET_MODE_SIZE (mode
)
14592 != GET_MODE_SIZE (GET_MODE (inner
)))
14593 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14595 cvt
= new_loc_descr (dwarf_OP (DW_OP_reinterpret
), 0, 0);
14596 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14597 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14598 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14599 add_loc_descr (&mem_loc_result
, cvt
);
14600 if (SCALAR_INT_MODE_P (mode
)
14601 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14603 /* Convert it to untyped afterwards. */
14604 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14605 add_loc_descr (&mem_loc_result
, cvt
);
14611 if (! SCALAR_INT_MODE_P (mode
)
14612 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14613 && rtl
!= arg_pointer_rtx
14614 && rtl
!= frame_pointer_rtx
14615 #ifdef POINTERS_EXTEND_UNSIGNED
14616 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
14620 dw_die_ref type_die
;
14621 unsigned int dbx_regnum
;
14623 if (dwarf_strict
&& dwarf_version
< 5)
14625 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
14627 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14628 if (type_die
== NULL
)
14631 dbx_regnum
= dbx_reg_number (rtl
);
14632 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14634 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_regval_type
),
14636 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14637 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14638 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14641 /* Whenever a register number forms a part of the description of the
14642 method for calculating the (dynamic) address of a memory resident
14643 object, DWARF rules require the register number be referred to as
14644 a "base register". This distinction is not based in any way upon
14645 what category of register the hardware believes the given register
14646 belongs to. This is strictly DWARF terminology we're dealing with
14647 here. Note that in cases where the location of a memory-resident
14648 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
14649 OP_CONST (0)) the actual DWARF location descriptor that we generate
14650 may just be OP_BASEREG (basereg). This may look deceptively like
14651 the object in question was allocated to a register (rather than in
14652 memory) so DWARF consumers need to be aware of the subtle
14653 distinction between OP_REG and OP_BASEREG. */
14654 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
14655 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
14656 else if (stack_realign_drap
14658 && crtl
->args
.internal_arg_pointer
== rtl
14659 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
14661 /* If RTL is internal_arg_pointer, which has been optimized
14662 out, use DRAP instead. */
14663 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
14664 VAR_INIT_STATUS_INITIALIZED
);
14670 if (!SCALAR_INT_MODE_P (mode
))
14672 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
14673 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14676 else if (GET_CODE (rtl
) == ZERO_EXTEND
14677 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14678 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
14679 < HOST_BITS_PER_WIDE_INT
14680 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
14681 to expand zero extend as two shifts instead of
14683 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
14685 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
14686 mem_loc_result
= op0
;
14687 add_loc_descr (&mem_loc_result
,
14688 int_loc_descriptor (GET_MODE_MASK (imode
)));
14689 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
14691 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14693 int shift
= DWARF2_ADDR_SIZE
14694 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
14695 shift
*= BITS_PER_UNIT
;
14696 if (GET_CODE (rtl
) == SIGN_EXTEND
)
14700 mem_loc_result
= op0
;
14701 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14702 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14703 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14704 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14706 else if (!dwarf_strict
|| dwarf_version
>= 5)
14708 dw_die_ref type_die1
, type_die2
;
14709 dw_loc_descr_ref cvt
;
14711 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
14712 GET_CODE (rtl
) == ZERO_EXTEND
);
14713 if (type_die1
== NULL
)
14715 type_die2
= base_type_for_mode (mode
, 1);
14716 if (type_die2
== NULL
)
14718 mem_loc_result
= op0
;
14719 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14720 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14721 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
14722 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14723 add_loc_descr (&mem_loc_result
, cvt
);
14724 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14725 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14726 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
14727 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14728 add_loc_descr (&mem_loc_result
, cvt
);
14734 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14735 if (new_rtl
!= rtl
)
14737 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
14739 if (mem_loc_result
!= NULL
)
14740 return mem_loc_result
;
14743 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
14744 get_address_mode (rtl
), mode
,
14745 VAR_INIT_STATUS_INITIALIZED
);
14746 if (mem_loc_result
== NULL
)
14747 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
14748 if (mem_loc_result
!= NULL
)
14750 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14751 || !SCALAR_INT_MODE_P(mode
))
14753 dw_die_ref type_die
;
14754 dw_loc_descr_ref deref
;
14756 if (dwarf_strict
&& dwarf_version
< 5)
14759 = base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14760 if (type_die
== NULL
)
14762 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
),
14763 GET_MODE_SIZE (mode
), 0);
14764 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14765 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14766 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14767 add_loc_descr (&mem_loc_result
, deref
);
14769 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
14770 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
14772 add_loc_descr (&mem_loc_result
,
14773 new_loc_descr (DW_OP_deref_size
,
14774 GET_MODE_SIZE (mode
), 0));
14779 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
14782 /* Some ports can transform a symbol ref into a label ref, because
14783 the symbol ref is too far away and has to be dumped into a constant
14787 if (!SCALAR_INT_MODE_P (mode
)
14788 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14789 #ifdef POINTERS_EXTEND_UNSIGNED
14790 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
14794 if (GET_CODE (rtl
) == SYMBOL_REF
14795 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
14797 dw_loc_descr_ref temp
;
14799 /* If this is not defined, we have no way to emit the data. */
14800 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
14803 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
14805 /* We check for DWARF 5 here because gdb did not implement
14806 DW_OP_form_tls_address until after 7.12. */
14807 mem_loc_result
= new_loc_descr ((dwarf_version
>= 5
14808 ? DW_OP_form_tls_address
14809 : DW_OP_GNU_push_tls_address
),
14811 add_loc_descr (&mem_loc_result
, temp
);
14816 if (!const_ok_for_output (rtl
))
14818 if (GET_CODE (rtl
) == CONST
)
14819 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14825 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14826 vec_safe_push (used_rtx_array
, rtl
);
14832 case DEBUG_IMPLICIT_PTR
:
14833 expansion_failed (NULL_TREE
, rtl
,
14834 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
14838 if (dwarf_strict
&& dwarf_version
< 5)
14840 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
14842 if (!SCALAR_INT_MODE_P (mode
)
14843 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14844 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
14845 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14848 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
14849 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14851 op0
= one_reg_loc_descriptor (dbx_regnum
,
14852 VAR_INIT_STATUS_INITIALIZED
);
14855 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
14856 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
14858 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
14859 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14860 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
14864 gcc_unreachable ();
14867 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_entry_value
), 0, 0);
14868 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14869 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
14872 case DEBUG_PARAMETER_REF
:
14873 mem_loc_result
= parameter_ref_descriptor (rtl
);
14877 /* Extract the PLUS expression nested inside and fall into
14878 PLUS code below. */
14879 rtl
= XEXP (rtl
, 1);
14884 /* Turn these into a PLUS expression and fall into the PLUS code
14886 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
14887 gen_int_mode (GET_CODE (rtl
) == PRE_INC
14888 ? GET_MODE_UNIT_SIZE (mem_mode
)
14889 : -GET_MODE_UNIT_SIZE (mem_mode
),
14896 if (is_based_loc (rtl
)
14897 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14898 || XEXP (rtl
, 0) == arg_pointer_rtx
14899 || XEXP (rtl
, 0) == frame_pointer_rtx
)
14900 && SCALAR_INT_MODE_P (mode
))
14901 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
14902 INTVAL (XEXP (rtl
, 1)),
14903 VAR_INIT_STATUS_INITIALIZED
);
14906 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14907 VAR_INIT_STATUS_INITIALIZED
);
14908 if (mem_loc_result
== 0)
14911 if (CONST_INT_P (XEXP (rtl
, 1))
14912 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14913 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
14916 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14917 VAR_INIT_STATUS_INITIALIZED
);
14920 add_loc_descr (&mem_loc_result
, op1
);
14921 add_loc_descr (&mem_loc_result
,
14922 new_loc_descr (DW_OP_plus
, 0, 0));
14927 /* If a pseudo-reg is optimized away, it is possible for it to
14928 be replaced with a MEM containing a multiply or shift. */
14938 if ((!dwarf_strict
|| dwarf_version
>= 5)
14939 && SCALAR_INT_MODE_P (mode
)
14940 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14942 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
14943 base_type_for_mode (mode
, 0),
14967 if (!SCALAR_INT_MODE_P (mode
))
14969 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14970 VAR_INIT_STATUS_INITIALIZED
);
14972 rtx rtlop1
= XEXP (rtl
, 1);
14973 if (GET_MODE (rtlop1
) != VOIDmode
14974 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
14975 < GET_MODE_BITSIZE (mode
))
14976 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
14977 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
14978 VAR_INIT_STATUS_INITIALIZED
);
14981 if (op0
== 0 || op1
== 0)
14984 mem_loc_result
= op0
;
14985 add_loc_descr (&mem_loc_result
, op1
);
14986 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15002 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15003 VAR_INIT_STATUS_INITIALIZED
);
15004 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15005 VAR_INIT_STATUS_INITIALIZED
);
15007 if (op0
== 0 || op1
== 0)
15010 mem_loc_result
= op0
;
15011 add_loc_descr (&mem_loc_result
, op1
);
15012 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15016 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
15017 && (!dwarf_strict
|| dwarf_version
>= 5))
15019 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
15020 base_type_for_mode (mode
, 0),
15025 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15026 VAR_INIT_STATUS_INITIALIZED
);
15027 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15028 VAR_INIT_STATUS_INITIALIZED
);
15030 if (op0
== 0 || op1
== 0)
15033 mem_loc_result
= op0
;
15034 add_loc_descr (&mem_loc_result
, op1
);
15035 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15036 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15037 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
15038 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
15039 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
15043 if ((!dwarf_strict
|| dwarf_version
>= 5)
15044 && SCALAR_INT_MODE_P (mode
))
15046 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
15051 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
15052 base_type_for_mode (mode
, 1),
15070 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15071 VAR_INIT_STATUS_INITIALIZED
);
15076 mem_loc_result
= op0
;
15077 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15081 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
15082 #ifdef POINTERS_EXTEND_UNSIGNED
15084 && mem_mode
!= VOIDmode
15085 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
15089 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15092 if ((!dwarf_strict
|| dwarf_version
>= 5)
15093 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
15094 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
15096 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
15097 machine_mode amode
;
15098 if (type_die
== NULL
)
15100 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
15102 if (INTVAL (rtl
) >= 0
15103 && amode
!= BLKmode
15104 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
15105 /* const DW_OP_convert <XXX> vs.
15106 DW_OP_const_type <XXX, 1, const>. */
15107 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
15108 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
15110 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15111 op0
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15112 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15113 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15114 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15115 add_loc_descr (&mem_loc_result
, op0
);
15116 return mem_loc_result
;
15118 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0,
15120 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15121 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15122 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15123 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
15124 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15127 mem_loc_result
->dw_loc_oprnd2
.val_class
15128 = dw_val_class_const_double
;
15129 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15130 = double_int::from_shwi (INTVAL (rtl
));
15136 if (!dwarf_strict
|| dwarf_version
>= 5)
15138 dw_die_ref type_die
;
15140 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
15141 CONST_DOUBLE rtx could represent either a large integer
15142 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
15143 the value is always a floating point constant.
15145 When it is an integer, a CONST_DOUBLE is used whenever
15146 the constant requires 2 HWIs to be adequately represented.
15147 We output CONST_DOUBLEs as blocks. */
15148 if (mode
== VOIDmode
15149 || (GET_MODE (rtl
) == VOIDmode
15150 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
15152 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15153 if (type_die
== NULL
)
15155 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15156 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15157 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15158 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15159 #if TARGET_SUPPORTS_WIDE_INT == 0
15160 if (!SCALAR_FLOAT_MODE_P (mode
))
15162 mem_loc_result
->dw_loc_oprnd2
.val_class
15163 = dw_val_class_const_double
;
15164 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15165 = rtx_to_double_int (rtl
);
15170 unsigned int length
= GET_MODE_SIZE (mode
);
15171 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15173 insert_float (rtl
, array
);
15174 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15175 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15176 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15177 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15182 case CONST_WIDE_INT
:
15183 if (!dwarf_strict
|| dwarf_version
>= 5)
15185 dw_die_ref type_die
;
15187 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15188 if (type_die
== NULL
)
15190 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15191 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15192 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15193 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15194 mem_loc_result
->dw_loc_oprnd2
.val_class
15195 = dw_val_class_wide_int
;
15196 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15197 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15202 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
15206 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15210 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15214 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15218 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15222 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
15226 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15230 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15234 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15238 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15243 if (!SCALAR_INT_MODE_P (mode
))
15248 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
15253 if (CONST_INT_P (XEXP (rtl
, 1))
15254 && CONST_INT_P (XEXP (rtl
, 2))
15255 && ((unsigned) INTVAL (XEXP (rtl
, 1))
15256 + (unsigned) INTVAL (XEXP (rtl
, 2))
15257 <= GET_MODE_BITSIZE (mode
))
15258 && SCALAR_INT_MODE_P (mode
)
15259 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
15260 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
15263 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
15264 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15267 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
15271 mem_loc_result
= op0
;
15272 size
= INTVAL (XEXP (rtl
, 1));
15273 shift
= INTVAL (XEXP (rtl
, 2));
15274 if (BITS_BIG_ENDIAN
)
15275 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
15277 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
15279 add_loc_descr (&mem_loc_result
,
15280 int_loc_descriptor (DWARF2_ADDR_SIZE
15282 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
15284 if (size
!= (int) DWARF2_ADDR_SIZE
)
15286 add_loc_descr (&mem_loc_result
,
15287 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
15288 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15295 dw_loc_descr_ref op2
, bra_node
, drop_node
;
15296 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
15297 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
15298 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
15299 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15300 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15301 VAR_INIT_STATUS_INITIALIZED
);
15302 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
15303 VAR_INIT_STATUS_INITIALIZED
);
15304 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
15307 mem_loc_result
= op1
;
15308 add_loc_descr (&mem_loc_result
, op2
);
15309 add_loc_descr (&mem_loc_result
, op0
);
15310 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15311 add_loc_descr (&mem_loc_result
, bra_node
);
15312 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
15313 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
15314 add_loc_descr (&mem_loc_result
, drop_node
);
15315 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15316 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
15321 case FLOAT_TRUNCATE
:
15323 case UNSIGNED_FLOAT
:
15326 if (!dwarf_strict
|| dwarf_version
>= 5)
15328 dw_die_ref type_die
;
15329 dw_loc_descr_ref cvt
;
15331 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
15332 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15335 if (SCALAR_INT_MODE_P (GET_MODE (XEXP (rtl
, 0)))
15336 && (GET_CODE (rtl
) == FLOAT
15337 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
15338 <= DWARF2_ADDR_SIZE
))
15340 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
15341 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
15342 if (type_die
== NULL
)
15344 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15345 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15346 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15347 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15348 add_loc_descr (&op0
, cvt
);
15350 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
15351 if (type_die
== NULL
)
15353 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15354 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15355 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15356 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15357 add_loc_descr (&op0
, cvt
);
15358 if (SCALAR_INT_MODE_P (mode
)
15359 && (GET_CODE (rtl
) == FIX
15360 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
15362 op0
= convert_descriptor_to_mode (mode
, op0
);
15366 mem_loc_result
= op0
;
15373 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
15378 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
15382 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
15387 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
15391 /* In theory, we could implement the above. */
15392 /* DWARF cannot represent the unsigned compare operations
15417 case FRACT_CONVERT
:
15418 case UNSIGNED_FRACT_CONVERT
:
15420 case UNSIGNED_SAT_FRACT
:
15426 case VEC_DUPLICATE
:
15430 case STRICT_LOW_PART
:
15435 /* If delegitimize_address couldn't do anything with the UNSPEC, we
15436 can't express it in the debug info. This can happen e.g. with some
15441 resolve_one_addr (&rtl
);
15444 /* RTL sequences inside PARALLEL record a series of DWARF operations for
15445 the expression. An UNSPEC rtx represents a raw DWARF operation,
15446 new_loc_descr is called for it to build the operation directly.
15447 Otherwise mem_loc_descriptor is called recursively. */
15451 dw_loc_descr_ref exp_result
= NULL
;
15453 for (; index
< XVECLEN (rtl
, 0); index
++)
15455 rtx elem
= XVECEXP (rtl
, 0, index
);
15456 if (GET_CODE (elem
) == UNSPEC
)
15458 /* Each DWARF operation UNSPEC contain two operands, if
15459 one operand is not used for the operation, const0_rtx is
15461 gcc_assert (XVECLEN (elem
, 0) == 2);
15463 HOST_WIDE_INT dw_op
= XINT (elem
, 1);
15464 HOST_WIDE_INT oprnd1
= INTVAL (XVECEXP (elem
, 0, 0));
15465 HOST_WIDE_INT oprnd2
= INTVAL (XVECEXP (elem
, 0, 1));
15467 = new_loc_descr ((enum dwarf_location_atom
) dw_op
, oprnd1
,
15472 = mem_loc_descriptor (elem
, mode
, mem_mode
,
15473 VAR_INIT_STATUS_INITIALIZED
);
15475 if (!mem_loc_result
)
15476 mem_loc_result
= exp_result
;
15478 add_loc_descr (&mem_loc_result
, exp_result
);
15487 print_rtl (stderr
, rtl
);
15488 gcc_unreachable ();
15493 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15494 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15496 return mem_loc_result
;
15499 /* Return a descriptor that describes the concatenation of two locations.
15500 This is typically a complex variable. */
15502 static dw_loc_descr_ref
15503 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
15505 dw_loc_descr_ref cc_loc_result
= NULL
;
15506 dw_loc_descr_ref x0_ref
15507 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15508 dw_loc_descr_ref x1_ref
15509 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15511 if (x0_ref
== 0 || x1_ref
== 0)
15514 cc_loc_result
= x0_ref
;
15515 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
15517 add_loc_descr (&cc_loc_result
, x1_ref
);
15518 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
15520 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15521 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15523 return cc_loc_result
;
15526 /* Return a descriptor that describes the concatenation of N
15529 static dw_loc_descr_ref
15530 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
15533 dw_loc_descr_ref cc_loc_result
= NULL
;
15534 unsigned int n
= XVECLEN (concatn
, 0);
15536 for (i
= 0; i
< n
; ++i
)
15538 dw_loc_descr_ref ref
;
15539 rtx x
= XVECEXP (concatn
, 0, i
);
15541 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15545 add_loc_descr (&cc_loc_result
, ref
);
15546 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
15549 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15550 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15552 return cc_loc_result
;
15555 /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
15556 for DEBUG_IMPLICIT_PTR RTL. */
15558 static dw_loc_descr_ref
15559 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
15561 dw_loc_descr_ref ret
;
15564 if (dwarf_strict
&& dwarf_version
< 5)
15566 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
15567 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
15568 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
15569 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
15570 ret
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
15571 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15574 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15575 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
15576 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15580 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
15581 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
15586 /* Output a proper Dwarf location descriptor for a variable or parameter
15587 which is either allocated in a register or in a memory location. For a
15588 register, we just generate an OP_REG and the register number. For a
15589 memory location we provide a Dwarf postfix expression describing how to
15590 generate the (dynamic) address of the object onto the address stack.
15592 MODE is mode of the decl if this loc_descriptor is going to be used in
15593 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
15594 allowed, VOIDmode otherwise.
15596 If we don't know how to describe it, return 0. */
15598 static dw_loc_descr_ref
15599 loc_descriptor (rtx rtl
, machine_mode mode
,
15600 enum var_init_status initialized
)
15602 dw_loc_descr_ref loc_result
= NULL
;
15604 switch (GET_CODE (rtl
))
15607 /* The case of a subreg may arise when we have a local (register)
15608 variable or a formal (register) parameter which doesn't quite fill
15609 up an entire register. For now, just assume that it is
15610 legitimate to make the Dwarf info refer to the whole register which
15611 contains the given subreg. */
15612 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
15613 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
15614 GET_MODE (SUBREG_REG (rtl
)), initialized
);
15620 loc_result
= reg_loc_descriptor (rtl
, initialized
);
15624 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
15625 GET_MODE (rtl
), initialized
);
15626 if (loc_result
== NULL
)
15627 loc_result
= tls_mem_loc_descriptor (rtl
);
15628 if (loc_result
== NULL
)
15630 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
15631 if (new_rtl
!= rtl
)
15632 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
15637 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
15642 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
15647 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
15649 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
15650 if (GET_CODE (loc
) == EXPR_LIST
)
15651 loc
= XEXP (loc
, 0);
15652 loc_result
= loc_descriptor (loc
, mode
, initialized
);
15656 rtl
= XEXP (rtl
, 1);
15661 rtvec par_elems
= XVEC (rtl
, 0);
15662 int num_elem
= GET_NUM_ELEM (par_elems
);
15666 /* Create the first one, so we have something to add to. */
15667 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
15668 VOIDmode
, initialized
);
15669 if (loc_result
== NULL
)
15671 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
15672 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15673 for (i
= 1; i
< num_elem
; i
++)
15675 dw_loc_descr_ref temp
;
15677 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
15678 VOIDmode
, initialized
);
15681 add_loc_descr (&loc_result
, temp
);
15682 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
15683 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15689 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
15690 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
15695 if (mode
== VOIDmode
)
15696 mode
= GET_MODE (rtl
);
15698 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15700 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15702 /* Note that a CONST_DOUBLE rtx could represent either an integer
15703 or a floating-point constant. A CONST_DOUBLE is used whenever
15704 the constant requires more than one word in order to be
15705 adequately represented. We output CONST_DOUBLEs as blocks. */
15706 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15707 GET_MODE_SIZE (mode
), 0);
15708 #if TARGET_SUPPORTS_WIDE_INT == 0
15709 if (!SCALAR_FLOAT_MODE_P (mode
))
15711 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
15712 loc_result
->dw_loc_oprnd2
.v
.val_double
15713 = rtx_to_double_int (rtl
);
15718 unsigned int length
= GET_MODE_SIZE (mode
);
15719 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15721 insert_float (rtl
, array
);
15722 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15723 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15724 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15725 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15730 case CONST_WIDE_INT
:
15731 if (mode
== VOIDmode
)
15732 mode
= GET_MODE (rtl
);
15734 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15736 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15737 GET_MODE_SIZE (mode
), 0);
15738 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
15739 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15740 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15745 if (mode
== VOIDmode
)
15746 mode
= GET_MODE (rtl
);
15748 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15750 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
15751 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15752 unsigned char *array
15753 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15756 machine_mode imode
= GET_MODE_INNER (mode
);
15758 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15759 switch (GET_MODE_CLASS (mode
))
15761 case MODE_VECTOR_INT
:
15762 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15764 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15765 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
15769 case MODE_VECTOR_FLOAT
:
15770 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15772 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15773 insert_float (elt
, p
);
15778 gcc_unreachable ();
15781 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15782 length
* elt_size
, 0);
15783 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15784 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
15785 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
15786 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15791 if (mode
== VOIDmode
15792 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
15793 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
15794 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
15796 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
15801 if (!const_ok_for_output (rtl
))
15805 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
15806 && (dwarf_version
>= 4 || !dwarf_strict
))
15808 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15809 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15810 vec_safe_push (used_rtx_array
, rtl
);
15814 case DEBUG_IMPLICIT_PTR
:
15815 loc_result
= implicit_ptr_descriptor (rtl
, 0);
15819 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
15820 && CONST_INT_P (XEXP (rtl
, 1)))
15823 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
15829 if ((SCALAR_INT_MODE_P (mode
)
15830 && GET_MODE (rtl
) == mode
15831 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
15832 && dwarf_version
>= 4)
15833 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
15835 /* Value expression. */
15836 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
15838 add_loc_descr (&loc_result
,
15839 new_loc_descr (DW_OP_stack_value
, 0, 0));
15847 /* We need to figure out what section we should use as the base for the
15848 address ranges where a given location is valid.
15849 1. If this particular DECL has a section associated with it, use that.
15850 2. If this function has a section associated with it, use that.
15851 3. Otherwise, use the text section.
15852 XXX: If you split a variable across multiple sections, we won't notice. */
15854 static const char *
15855 secname_for_decl (const_tree decl
)
15857 const char *secname
;
15859 if (VAR_OR_FUNCTION_DECL_P (decl
)
15860 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
15861 && DECL_SECTION_NAME (decl
))
15862 secname
= DECL_SECTION_NAME (decl
);
15863 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
15864 secname
= DECL_SECTION_NAME (current_function_decl
);
15865 else if (cfun
&& in_cold_section_p
)
15866 secname
= crtl
->subsections
.cold_section_label
;
15868 secname
= text_section_label
;
15873 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
15876 decl_by_reference_p (tree decl
)
15878 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
15880 && DECL_BY_REFERENCE (decl
));
15883 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15886 static dw_loc_descr_ref
15887 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
15888 enum var_init_status initialized
)
15890 int have_address
= 0;
15891 dw_loc_descr_ref descr
;
15894 if (want_address
!= 2)
15896 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
15898 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
15900 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
15901 if (GET_CODE (varloc
) == EXPR_LIST
)
15902 varloc
= XEXP (varloc
, 0);
15903 mode
= GET_MODE (varloc
);
15904 if (MEM_P (varloc
))
15906 rtx addr
= XEXP (varloc
, 0);
15907 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
15908 mode
, initialized
);
15913 rtx x
= avoid_constant_pool_reference (varloc
);
15915 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
15920 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
15927 if (GET_CODE (varloc
) == VAR_LOCATION
)
15928 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
15930 mode
= DECL_MODE (loc
);
15931 descr
= loc_descriptor (varloc
, mode
, initialized
);
15938 if (want_address
== 2 && !have_address
15939 && (dwarf_version
>= 4 || !dwarf_strict
))
15941 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15943 expansion_failed (loc
, NULL_RTX
,
15944 "DWARF address size mismatch");
15947 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15950 /* Show if we can't fill the request for an address. */
15951 if (want_address
&& !have_address
)
15953 expansion_failed (loc
, NULL_RTX
,
15954 "Want address and only have value");
15958 /* If we've got an address and don't want one, dereference. */
15959 if (!want_address
&& have_address
)
15961 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
15962 enum dwarf_location_atom op
;
15964 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
15966 expansion_failed (loc
, NULL_RTX
,
15967 "DWARF address size mismatch");
15970 else if (size
== DWARF2_ADDR_SIZE
)
15973 op
= DW_OP_deref_size
;
15975 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
15981 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
15982 if it is not possible. */
15984 static dw_loc_descr_ref
15985 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
15987 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
15988 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
15989 else if (dwarf_version
>= 3 || !dwarf_strict
)
15990 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
15995 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15996 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
15998 static dw_loc_descr_ref
15999 dw_sra_loc_expr (tree decl
, rtx loc
)
16002 unsigned HOST_WIDE_INT padsize
= 0;
16003 dw_loc_descr_ref descr
, *descr_tail
;
16004 unsigned HOST_WIDE_INT decl_size
;
16006 enum var_init_status initialized
;
16008 if (DECL_SIZE (decl
) == NULL
16009 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
16012 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
16014 descr_tail
= &descr
;
16016 for (p
= loc
; p
; p
= XEXP (p
, 1))
16018 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
16019 rtx loc_note
= *decl_piece_varloc_ptr (p
);
16020 dw_loc_descr_ref cur_descr
;
16021 dw_loc_descr_ref
*tail
, last
= NULL
;
16022 unsigned HOST_WIDE_INT opsize
= 0;
16024 if (loc_note
== NULL_RTX
16025 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
16027 padsize
+= bitsize
;
16030 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
16031 varloc
= NOTE_VAR_LOCATION (loc_note
);
16032 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
16033 if (cur_descr
== NULL
)
16035 padsize
+= bitsize
;
16039 /* Check that cur_descr either doesn't use
16040 DW_OP_*piece operations, or their sum is equal
16041 to bitsize. Otherwise we can't embed it. */
16042 for (tail
= &cur_descr
; *tail
!= NULL
;
16043 tail
= &(*tail
)->dw_loc_next
)
16044 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
16046 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
16050 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
16052 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
16056 if (last
!= NULL
&& opsize
!= bitsize
)
16058 padsize
+= bitsize
;
16059 /* Discard the current piece of the descriptor and release any
16060 addr_table entries it uses. */
16061 remove_loc_list_addr_table_entries (cur_descr
);
16065 /* If there is a hole, add DW_OP_*piece after empty DWARF
16066 expression, which means that those bits are optimized out. */
16069 if (padsize
> decl_size
)
16071 remove_loc_list_addr_table_entries (cur_descr
);
16072 goto discard_descr
;
16074 decl_size
-= padsize
;
16075 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
16076 if (*descr_tail
== NULL
)
16078 remove_loc_list_addr_table_entries (cur_descr
);
16079 goto discard_descr
;
16081 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16084 *descr_tail
= cur_descr
;
16086 if (bitsize
> decl_size
)
16087 goto discard_descr
;
16088 decl_size
-= bitsize
;
16091 HOST_WIDE_INT offset
= 0;
16092 if (GET_CODE (varloc
) == VAR_LOCATION
16093 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
16095 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
16096 if (GET_CODE (varloc
) == EXPR_LIST
)
16097 varloc
= XEXP (varloc
, 0);
16101 if (GET_CODE (varloc
) == CONST
16102 || GET_CODE (varloc
) == SIGN_EXTEND
16103 || GET_CODE (varloc
) == ZERO_EXTEND
)
16104 varloc
= XEXP (varloc
, 0);
16105 else if (GET_CODE (varloc
) == SUBREG
)
16106 varloc
= SUBREG_REG (varloc
);
16111 /* DW_OP_bit_size offset should be zero for register
16112 or implicit location descriptions and empty location
16113 descriptions, but for memory addresses needs big endian
16115 if (MEM_P (varloc
))
16117 unsigned HOST_WIDE_INT memsize
16118 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
16119 if (memsize
!= bitsize
)
16121 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
16122 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
16123 goto discard_descr
;
16124 if (memsize
< bitsize
)
16125 goto discard_descr
;
16126 if (BITS_BIG_ENDIAN
)
16127 offset
= memsize
- bitsize
;
16131 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
16132 if (*descr_tail
== NULL
)
16133 goto discard_descr
;
16134 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16138 /* If there were any non-empty expressions, add padding till the end of
16140 if (descr
!= NULL
&& decl_size
!= 0)
16142 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
16143 if (*descr_tail
== NULL
)
16144 goto discard_descr
;
16149 /* Discard the descriptor and release any addr_table entries it uses. */
16150 remove_loc_list_addr_table_entries (descr
);
16154 /* Return the dwarf representation of the location list LOC_LIST of
16155 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
16158 static dw_loc_list_ref
16159 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
16161 const char *endname
, *secname
;
16163 enum var_init_status initialized
;
16164 struct var_loc_node
*node
;
16165 dw_loc_descr_ref descr
;
16166 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
16167 dw_loc_list_ref list
= NULL
;
16168 dw_loc_list_ref
*listp
= &list
;
16170 /* Now that we know what section we are using for a base,
16171 actually construct the list of locations.
16172 The first location information is what is passed to the
16173 function that creates the location list, and the remaining
16174 locations just get added on to that list.
16175 Note that we only know the start address for a location
16176 (IE location changes), so to build the range, we use
16177 the range [current location start, next location start].
16178 This means we have to special case the last node, and generate
16179 a range of [last location start, end of function label]. */
16181 secname
= secname_for_decl (decl
);
16183 for (node
= loc_list
->first
; node
; node
= node
->next
)
16184 if (GET_CODE (node
->loc
) == EXPR_LIST
16185 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
16187 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16189 /* This requires DW_OP_{,bit_}piece, which is not usable
16190 inside DWARF expressions. */
16191 if (want_address
!= 2)
16193 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16199 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16200 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16201 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
16205 bool range_across_switch
= false;
16206 /* If section switch happens in between node->label
16207 and node->next->label (or end of function) and
16208 we can't emit it as a single entry list,
16209 emit two ranges, first one ending at the end
16210 of first partition and second one starting at the
16211 beginning of second partition. */
16212 if (node
== loc_list
->last_before_switch
16213 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
16214 && current_function_decl
)
16216 endname
= cfun
->fde
->dw_fde_end
;
16217 range_across_switch
= true;
16219 /* The variable has a location between NODE->LABEL and
16220 NODE->NEXT->LABEL. */
16221 else if (node
->next
)
16222 endname
= node
->next
->label
;
16223 /* If the variable has a location at the last label
16224 it keeps its location until the end of function. */
16225 else if (!current_function_decl
)
16226 endname
= text_end_label
;
16229 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
16230 current_function_funcdef_no
);
16231 endname
= ggc_strdup (label_id
);
16234 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
16235 if (TREE_CODE (decl
) == PARM_DECL
16236 && node
== loc_list
->first
16237 && NOTE_P (node
->loc
)
16238 && strcmp (node
->label
, endname
) == 0)
16239 (*listp
)->force
= true;
16240 listp
= &(*listp
)->dw_loc_next
;
16242 if (range_across_switch
)
16244 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16245 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16248 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16249 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16250 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
16253 gcc_assert (descr
);
16254 /* The variable has a location between NODE->LABEL and
16255 NODE->NEXT->LABEL. */
16257 endname
= node
->next
->label
;
16259 endname
= cfun
->fde
->dw_fde_second_end
;
16260 *listp
= new_loc_list (descr
,
16261 cfun
->fde
->dw_fde_second_begin
,
16263 listp
= &(*listp
)->dw_loc_next
;
16268 /* Try to avoid the overhead of a location list emitting a location
16269 expression instead, but only if we didn't have more than one
16270 location entry in the first place. If some entries were not
16271 representable, we don't want to pretend a single entry that was
16272 applies to the entire scope in which the variable is
16274 if (list
&& loc_list
->first
->next
)
16280 /* Return if the loc_list has only single element and thus can be represented
16281 as location description. */
16284 single_element_loc_list_p (dw_loc_list_ref list
)
16286 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
16287 return !list
->ll_symbol
;
16290 /* To each location in list LIST add loc descr REF. */
16293 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
16295 dw_loc_descr_ref copy
;
16296 add_loc_descr (&list
->expr
, ref
);
16297 list
= list
->dw_loc_next
;
16300 copy
= ggc_alloc
<dw_loc_descr_node
> ();
16301 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
16302 add_loc_descr (&list
->expr
, copy
);
16303 while (copy
->dw_loc_next
)
16305 dw_loc_descr_ref new_copy
= ggc_alloc
<dw_loc_descr_node
> ();
16306 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
16307 copy
->dw_loc_next
= new_copy
;
16310 list
= list
->dw_loc_next
;
16314 /* Given two lists RET and LIST
16315 produce location list that is result of adding expression in LIST
16316 to expression in RET on each position in program.
16317 Might be destructive on both RET and LIST.
16319 TODO: We handle only simple cases of RET or LIST having at most one
16320 element. General case would inolve sorting the lists in program order
16321 and merging them that will need some additional work.
16322 Adding that will improve quality of debug info especially for SRA-ed
16326 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
16335 if (!list
->dw_loc_next
)
16337 add_loc_descr_to_each (*ret
, list
->expr
);
16340 if (!(*ret
)->dw_loc_next
)
16342 add_loc_descr_to_each (list
, (*ret
)->expr
);
16346 expansion_failed (NULL_TREE
, NULL_RTX
,
16347 "Don't know how to merge two non-trivial"
16348 " location lists.\n");
16353 /* LOC is constant expression. Try a luck, look it up in constant
16354 pool and return its loc_descr of its address. */
16356 static dw_loc_descr_ref
16357 cst_pool_loc_descr (tree loc
)
16359 /* Get an RTL for this, if something has been emitted. */
16360 rtx rtl
= lookup_constant_def (loc
);
16362 if (!rtl
|| !MEM_P (rtl
))
16367 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
16369 /* TODO: We might get more coverage if we was actually delaying expansion
16370 of all expressions till end of compilation when constant pools are fully
16372 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
16374 expansion_failed (loc
, NULL_RTX
,
16375 "CST value in contant pool but not marked.");
16378 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
16379 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
16382 /* Return dw_loc_list representing address of addr_expr LOC
16383 by looking for inner INDIRECT_REF expression and turning
16384 it into simple arithmetics.
16386 See loc_list_from_tree for the meaning of CONTEXT. */
16388 static dw_loc_list_ref
16389 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
16390 loc_descr_context
*context
)
16393 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
16395 int unsignedp
, reversep
, volatilep
= 0;
16396 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
16398 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
16399 &bitsize
, &bitpos
, &offset
, &mode
,
16400 &unsignedp
, &reversep
, &volatilep
);
16402 if (bitpos
% BITS_PER_UNIT
)
16404 expansion_failed (loc
, NULL_RTX
, "bitfield access");
16407 if (!INDIRECT_REF_P (obj
))
16409 expansion_failed (obj
,
16410 NULL_RTX
, "no indirect ref in inner refrence");
16413 if (!offset
&& !bitpos
)
16414 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
16417 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
16418 && (dwarf_version
>= 4 || !dwarf_strict
))
16420 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
16425 /* Variable offset. */
16426 list_ret1
= loc_list_from_tree (offset
, 0, context
);
16427 if (list_ret1
== 0)
16429 add_loc_list (&list_ret
, list_ret1
);
16432 add_loc_descr_to_each (list_ret
,
16433 new_loc_descr (DW_OP_plus
, 0, 0));
16435 bytepos
= bitpos
/ BITS_PER_UNIT
;
16437 add_loc_descr_to_each (list_ret
,
16438 new_loc_descr (DW_OP_plus_uconst
,
16440 else if (bytepos
< 0)
16441 loc_list_plus_const (list_ret
, bytepos
);
16442 add_loc_descr_to_each (list_ret
,
16443 new_loc_descr (DW_OP_stack_value
, 0, 0));
16448 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
16449 all operations from LOC are nops, move to the last one. Insert in NOPS all
16450 operations that are skipped. */
16453 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
16454 hash_set
<dw_loc_descr_ref
> &nops
)
16456 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
16459 loc
= loc
->dw_loc_next
;
16463 /* Helper for loc_descr_without_nops: free the location description operation
16467 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
16473 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
16477 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
16479 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
16482 /* Set of all DW_OP_nop operations we remove. */
16483 hash_set
<dw_loc_descr_ref
> nops
;
16485 /* First, strip all prefix NOP operations in order to keep the head of the
16486 operations list. */
16487 loc_descr_to_next_no_nop (loc
, nops
);
16489 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
16491 /* For control flow operations: strip "prefix" nops in destination
16493 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
16494 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
16495 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
16496 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
16498 /* Do the same for the operations that follow, then move to the next
16500 if (cur
->dw_loc_next
!= NULL
)
16501 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
16502 cur
= cur
->dw_loc_next
;
16505 nops
.traverse
<void *, free_loc_descr
> (NULL
);
16509 struct dwarf_procedure_info
;
16511 /* Helper structure for location descriptions generation. */
16512 struct loc_descr_context
16514 /* The type that is implicitly referenced by DW_OP_push_object_address, or
16515 NULL_TREE if DW_OP_push_object_address in invalid for this location
16516 description. This is used when processing PLACEHOLDER_EXPR nodes. */
16518 /* The ..._DECL node that should be translated as a
16519 DW_OP_push_object_address operation. */
16521 /* Information about the DWARF procedure we are currently generating. NULL if
16522 we are not generating a DWARF procedure. */
16523 struct dwarf_procedure_info
*dpi
;
16524 /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
16525 by consumer. Used for DW_TAG_generic_subrange attributes. */
16526 bool placeholder_arg
;
16527 /* True if PLACEHOLDER_EXPR has been seen. */
16528 bool placeholder_seen
;
16531 /* DWARF procedures generation
16533 DWARF expressions (aka. location descriptions) are used to encode variable
16534 things such as sizes or offsets. Such computations can have redundant parts
16535 that can be factorized in order to reduce the size of the output debug
16536 information. This is the whole point of DWARF procedures.
16538 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
16539 already factorized into functions ("size functions") in order to handle very
16540 big and complex types. Such functions are quite simple: they have integral
16541 arguments, they return an integral result and their body contains only a
16542 return statement with arithmetic expressions. This is the only kind of
16543 function we are interested in translating into DWARF procedures, here.
16545 DWARF expressions and DWARF procedure are executed using a stack, so we have
16546 to define some calling convention for them to interact. Let's say that:
16548 - Before calling a DWARF procedure, DWARF expressions must push on the stack
16549 all arguments in reverse order (right-to-left) so that when the DWARF
16550 procedure execution starts, the first argument is the top of the stack.
16552 - Then, when returning, the DWARF procedure must have consumed all arguments
16553 on the stack, must have pushed the result and touched nothing else.
16555 - Each integral argument and the result are integral types can be hold in a
16558 - We call "frame offset" the number of stack slots that are "under DWARF
16559 procedure control": it includes the arguments slots, the temporaries and
16560 the result slot. Thus, it is equal to the number of arguments when the
16561 procedure execution starts and must be equal to one (the result) when it
16564 /* Helper structure used when generating operations for a DWARF procedure. */
16565 struct dwarf_procedure_info
16567 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
16568 currently translated. */
16570 /* The number of arguments FNDECL takes. */
16571 unsigned args_count
;
16574 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
16575 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
16576 equate it to this DIE. */
16579 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
16580 dw_die_ref parent_die
)
16582 dw_die_ref dwarf_proc_die
;
16584 if ((dwarf_version
< 3 && dwarf_strict
)
16585 || location
== NULL
)
16588 dwarf_proc_die
= new_die (DW_TAG_dwarf_procedure
, parent_die
, fndecl
);
16590 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
16591 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
16592 return dwarf_proc_die
;
16595 /* Return whether TYPE is a supported type as a DWARF procedure argument
16596 type or return type (we handle only scalar types and pointer types that
16597 aren't wider than the DWARF expression evaluation stack. */
16600 is_handled_procedure_type (tree type
)
16602 return ((INTEGRAL_TYPE_P (type
)
16603 || TREE_CODE (type
) == OFFSET_TYPE
16604 || TREE_CODE (type
) == POINTER_TYPE
)
16605 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
16608 /* Helper for resolve_args_picking: do the same but stop when coming across
16609 visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
16610 offset *before* evaluating the corresponding operation. */
16613 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
16614 struct dwarf_procedure_info
*dpi
,
16615 hash_map
<dw_loc_descr_ref
, unsigned> &frame_offsets
)
16617 /* The "frame_offset" identifier is already used to name a macro... */
16618 unsigned frame_offset_
= initial_frame_offset
;
16619 dw_loc_descr_ref l
;
16621 for (l
= loc
; l
!= NULL
;)
16624 unsigned &l_frame_offset
= frame_offsets
.get_or_insert (l
, &existed
);
16626 /* If we already met this node, there is nothing to compute anymore. */
16629 /* Make sure that the stack size is consistent wherever the execution
16630 flow comes from. */
16631 gcc_assert ((unsigned) l_frame_offset
== frame_offset_
);
16634 l_frame_offset
= frame_offset_
;
16636 /* If needed, relocate the picking offset with respect to the frame
16638 if (l
->frame_offset_rel
)
16640 unsigned HOST_WIDE_INT off
;
16641 switch (l
->dw_loc_opc
)
16644 off
= l
->dw_loc_oprnd1
.v
.val_unsigned
;
16653 gcc_unreachable ();
16655 /* frame_offset_ is the size of the current stack frame, including
16656 incoming arguments. Besides, the arguments are pushed
16657 right-to-left. Thus, in order to access the Nth argument from
16658 this operation node, the picking has to skip temporaries *plus*
16659 one stack slot per argument (0 for the first one, 1 for the second
16662 The targetted argument number (N) is already set as the operand,
16663 and the number of temporaries can be computed with:
16664 frame_offsets_ - dpi->args_count */
16665 off
+= frame_offset_
- dpi
->args_count
;
16667 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
16673 l
->dw_loc_opc
= DW_OP_dup
;
16674 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16678 l
->dw_loc_opc
= DW_OP_over
;
16679 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16683 l
->dw_loc_opc
= DW_OP_pick
;
16684 l
->dw_loc_oprnd1
.v
.val_unsigned
= off
;
16688 /* Update frame_offset according to the effect the current operation has
16690 switch (l
->dw_loc_opc
)
16698 case DW_OP_plus_uconst
:
16734 case DW_OP_deref_size
:
16736 case DW_OP_bit_piece
:
16737 case DW_OP_implicit_value
:
16738 case DW_OP_stack_value
:
16742 case DW_OP_const1u
:
16743 case DW_OP_const1s
:
16744 case DW_OP_const2u
:
16745 case DW_OP_const2s
:
16746 case DW_OP_const4u
:
16747 case DW_OP_const4s
:
16748 case DW_OP_const8u
:
16749 case DW_OP_const8s
:
16820 case DW_OP_push_object_address
:
16821 case DW_OP_call_frame_cfa
:
16846 case DW_OP_xderef_size
:
16852 case DW_OP_call_ref
:
16854 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
16855 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
16857 if (stack_usage
== NULL
)
16859 frame_offset_
+= *stack_usage
;
16863 case DW_OP_implicit_pointer
:
16864 case DW_OP_entry_value
:
16865 case DW_OP_const_type
:
16866 case DW_OP_regval_type
:
16867 case DW_OP_deref_type
:
16868 case DW_OP_convert
:
16869 case DW_OP_reinterpret
:
16870 case DW_OP_form_tls_address
:
16871 case DW_OP_GNU_push_tls_address
:
16872 case DW_OP_GNU_uninit
:
16873 case DW_OP_GNU_encoded_addr
:
16874 case DW_OP_GNU_implicit_pointer
:
16875 case DW_OP_GNU_entry_value
:
16876 case DW_OP_GNU_const_type
:
16877 case DW_OP_GNU_regval_type
:
16878 case DW_OP_GNU_deref_type
:
16879 case DW_OP_GNU_convert
:
16880 case DW_OP_GNU_reinterpret
:
16881 case DW_OP_GNU_parameter_ref
:
16882 /* loc_list_from_tree will probably not output these operations for
16883 size functions, so assume they will not appear here. */
16884 /* Fall through... */
16887 gcc_unreachable ();
16890 /* Now, follow the control flow (except subroutine calls). */
16891 switch (l
->dw_loc_opc
)
16894 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
16897 /* Fall through. */
16900 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
16903 case DW_OP_stack_value
:
16907 l
= l
->dw_loc_next
;
16915 /* Make a DFS over operations reachable through LOC (i.e. follow branch
16916 operations) in order to resolve the operand of DW_OP_pick operations that
16917 target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
16918 offset *before* LOC is executed. Return if all relocations were
16922 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
16923 struct dwarf_procedure_info
*dpi
)
16925 /* Associate to all visited operations the frame offset *before* evaluating
16927 hash_map
<dw_loc_descr_ref
, unsigned> frame_offsets
;
16929 return resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
,
16933 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
16934 Return NULL if it is not possible. */
16937 function_to_dwarf_procedure (tree fndecl
)
16939 struct loc_descr_context ctx
;
16940 struct dwarf_procedure_info dpi
;
16941 dw_die_ref dwarf_proc_die
;
16942 tree tree_body
= DECL_SAVED_TREE (fndecl
);
16943 dw_loc_descr_ref loc_body
, epilogue
;
16948 /* Do not generate multiple DWARF procedures for the same function
16950 dwarf_proc_die
= lookup_decl_die (fndecl
);
16951 if (dwarf_proc_die
!= NULL
)
16952 return dwarf_proc_die
;
16954 /* DWARF procedures are available starting with the DWARFv3 standard. */
16955 if (dwarf_version
< 3 && dwarf_strict
)
16958 /* We handle only functions for which we still have a body, that return a
16959 supported type and that takes arguments with supported types. Note that
16960 there is no point translating functions that return nothing. */
16961 if (tree_body
== NULL_TREE
16962 || DECL_RESULT (fndecl
) == NULL_TREE
16963 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
16966 for (cursor
= DECL_ARGUMENTS (fndecl
);
16967 cursor
!= NULL_TREE
;
16968 cursor
= TREE_CHAIN (cursor
))
16969 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
16972 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
16973 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
16975 tree_body
= TREE_OPERAND (tree_body
, 0);
16976 if (TREE_CODE (tree_body
) != MODIFY_EXPR
16977 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
16979 tree_body
= TREE_OPERAND (tree_body
, 1);
16981 /* Try to translate the body expression itself. Note that this will probably
16982 cause an infinite recursion if its call graph has a cycle. This is very
16983 unlikely for size functions, however, so don't bother with such things at
16985 ctx
.context_type
= NULL_TREE
;
16986 ctx
.base_decl
= NULL_TREE
;
16988 ctx
.placeholder_arg
= false;
16989 ctx
.placeholder_seen
= false;
16990 dpi
.fndecl
= fndecl
;
16991 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
16992 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
16996 /* After evaluating all operands in "loc_body", we should still have on the
16997 stack all arguments plus the desired function result (top of the stack).
16998 Generate code in order to keep only the result in our stack frame. */
17000 for (i
= 0; i
< dpi
.args_count
; ++i
)
17002 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
17003 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
17004 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
17005 epilogue
= op_couple
;
17007 add_loc_descr (&loc_body
, epilogue
);
17008 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
17011 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
17012 because they are considered useful. Now there is an epilogue, they are
17013 not anymore, so give it another try. */
17014 loc_descr_without_nops (loc_body
);
17016 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
17017 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
17018 though, given that size functions do not come from source, so they should
17019 not have a dedicated DW_TAG_subprogram DIE. */
17021 = new_dwarf_proc_die (loc_body
, fndecl
,
17022 get_context_die (DECL_CONTEXT (fndecl
)));
17024 /* The called DWARF procedure consumes one stack slot per argument and
17025 returns one stack slot. */
17026 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
17028 return dwarf_proc_die
;
17032 /* Generate Dwarf location list representing LOC.
17033 If WANT_ADDRESS is false, expression computing LOC will be computed
17034 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
17035 if WANT_ADDRESS is 2, expression computing address useable in location
17036 will be returned (i.e. DW_OP_reg can be used
17037 to refer to register values).
17039 CONTEXT provides information to customize the location descriptions
17040 generation. Its context_type field specifies what type is implicitly
17041 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
17042 will not be generated.
17044 Its DPI field determines whether we are generating a DWARF expression for a
17045 DWARF procedure, so PARM_DECL references are processed specifically.
17047 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
17048 and dpi fields were null. */
17050 static dw_loc_list_ref
17051 loc_list_from_tree_1 (tree loc
, int want_address
,
17052 struct loc_descr_context
*context
)
17054 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
17055 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
17056 int have_address
= 0;
17057 enum dwarf_location_atom op
;
17059 /* ??? Most of the time we do not take proper care for sign/zero
17060 extending the values properly. Hopefully this won't be a real
17063 if (context
!= NULL
17064 && context
->base_decl
== loc
17065 && want_address
== 0)
17067 if (dwarf_version
>= 3 || !dwarf_strict
)
17068 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
17074 switch (TREE_CODE (loc
))
17077 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
17080 case PLACEHOLDER_EXPR
:
17081 /* This case involves extracting fields from an object to determine the
17082 position of other fields. It is supposed to appear only as the first
17083 operand of COMPONENT_REF nodes and to reference precisely the type
17084 that the context allows. */
17085 if (context
!= NULL
17086 && TREE_TYPE (loc
) == context
->context_type
17087 && want_address
>= 1)
17089 if (dwarf_version
>= 3 || !dwarf_strict
)
17091 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
17098 /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
17099 the single argument passed by consumer. */
17100 else if (context
!= NULL
17101 && context
->placeholder_arg
17102 && INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17103 && want_address
== 0)
17105 ret
= new_loc_descr (DW_OP_pick
, 0, 0);
17106 ret
->frame_offset_rel
= 1;
17107 context
->placeholder_seen
= true;
17111 expansion_failed (loc
, NULL_RTX
,
17112 "PLACEHOLDER_EXPR for an unexpected type");
17117 const int nargs
= call_expr_nargs (loc
);
17118 tree callee
= get_callee_fndecl (loc
);
17120 dw_die_ref dwarf_proc
;
17122 if (callee
== NULL_TREE
)
17123 goto call_expansion_failed
;
17125 /* We handle only functions that return an integer. */
17126 if (!is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
))))
17127 goto call_expansion_failed
;
17129 dwarf_proc
= function_to_dwarf_procedure (callee
);
17130 if (dwarf_proc
== NULL
)
17131 goto call_expansion_failed
;
17133 /* Evaluate arguments right-to-left so that the first argument will
17134 be the top-most one on the stack. */
17135 for (i
= nargs
- 1; i
>= 0; --i
)
17137 dw_loc_descr_ref loc_descr
17138 = loc_descriptor_from_tree (CALL_EXPR_ARG (loc
, i
), 0,
17141 if (loc_descr
== NULL
)
17142 goto call_expansion_failed
;
17144 add_loc_descr (&ret
, loc_descr
);
17147 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
17148 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17149 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
17150 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17151 add_loc_descr (&ret
, ret1
);
17154 call_expansion_failed
:
17155 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
17156 /* There are no opcodes for these operations. */
17160 case PREINCREMENT_EXPR
:
17161 case PREDECREMENT_EXPR
:
17162 case POSTINCREMENT_EXPR
:
17163 case POSTDECREMENT_EXPR
:
17164 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
17165 /* There are no opcodes for these operations. */
17169 /* If we already want an address, see if there is INDIRECT_REF inside
17170 e.g. for &this->field. */
17173 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
17174 (loc
, want_address
== 2, context
);
17177 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
17178 && (ret
= cst_pool_loc_descr (loc
)))
17181 /* Otherwise, process the argument and look for the address. */
17182 if (!list_ret
&& !ret
)
17183 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
17187 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
17193 if (DECL_THREAD_LOCAL_P (loc
))
17196 enum dwarf_location_atom tls_op
;
17197 enum dtprel_bool dtprel
= dtprel_false
;
17199 if (targetm
.have_tls
)
17201 /* If this is not defined, we have no way to emit the
17203 if (!targetm
.asm_out
.output_dwarf_dtprel
)
17206 /* The way DW_OP_GNU_push_tls_address is specified, we
17207 can only look up addresses of objects in the current
17208 module. We used DW_OP_addr as first op, but that's
17209 wrong, because DW_OP_addr is relocated by the debug
17210 info consumer, while DW_OP_GNU_push_tls_address
17211 operand shouldn't be. */
17212 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
17214 dtprel
= dtprel_true
;
17215 /* We check for DWARF 5 here because gdb did not implement
17216 DW_OP_form_tls_address until after 7.12. */
17217 tls_op
= (dwarf_version
>= 5 ? DW_OP_form_tls_address
17218 : DW_OP_GNU_push_tls_address
);
17222 if (!targetm
.emutls
.debug_form_tls_address
17223 || !(dwarf_version
>= 3 || !dwarf_strict
))
17225 /* We stuffed the control variable into the DECL_VALUE_EXPR
17226 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
17227 no longer appear in gimple code. We used the control
17228 variable in specific so that we could pick it up here. */
17229 loc
= DECL_VALUE_EXPR (loc
);
17230 tls_op
= DW_OP_form_tls_address
;
17233 rtl
= rtl_for_decl_location (loc
);
17234 if (rtl
== NULL_RTX
)
17239 rtl
= XEXP (rtl
, 0);
17240 if (! CONSTANT_P (rtl
))
17243 ret
= new_addr_loc_descr (rtl
, dtprel
);
17244 ret1
= new_loc_descr (tls_op
, 0, 0);
17245 add_loc_descr (&ret
, ret1
);
17253 if (context
!= NULL
&& context
->dpi
!= NULL
17254 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
17256 /* We are generating code for a DWARF procedure and we want to access
17257 one of its arguments: find the appropriate argument offset and let
17258 the resolve_args_picking pass compute the offset that complies
17259 with the stack frame size. */
17263 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
17264 cursor
!= NULL_TREE
&& cursor
!= loc
;
17265 cursor
= TREE_CHAIN (cursor
), ++i
)
17267 /* If we are translating a DWARF procedure, all referenced parameters
17268 must belong to the current function. */
17269 gcc_assert (cursor
!= NULL_TREE
);
17271 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
17272 ret
->frame_offset_rel
= 1;
17278 if (DECL_HAS_VALUE_EXPR_P (loc
))
17279 return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc
),
17280 want_address
, context
);
17283 case FUNCTION_DECL
:
17286 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
17288 if (loc_list
&& loc_list
->first
)
17290 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
17291 have_address
= want_address
!= 0;
17294 rtl
= rtl_for_decl_location (loc
);
17295 if (rtl
== NULL_RTX
)
17297 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
17300 else if (CONST_INT_P (rtl
))
17302 HOST_WIDE_INT val
= INTVAL (rtl
);
17303 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17304 val
&= GET_MODE_MASK (DECL_MODE (loc
));
17305 ret
= int_loc_descriptor (val
);
17307 else if (GET_CODE (rtl
) == CONST_STRING
)
17309 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
17312 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
17313 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
17316 machine_mode mode
, mem_mode
;
17318 /* Certain constructs can only be represented at top-level. */
17319 if (want_address
== 2)
17321 ret
= loc_descriptor (rtl
, VOIDmode
,
17322 VAR_INIT_STATUS_INITIALIZED
);
17327 mode
= GET_MODE (rtl
);
17328 mem_mode
= VOIDmode
;
17332 mode
= get_address_mode (rtl
);
17333 rtl
= XEXP (rtl
, 0);
17336 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
17337 VAR_INIT_STATUS_INITIALIZED
);
17340 expansion_failed (loc
, rtl
,
17341 "failed to produce loc descriptor for rtl");
17347 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
17354 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17358 case TARGET_MEM_REF
:
17360 case DEBUG_EXPR_DECL
:
17363 case COMPOUND_EXPR
:
17364 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
17368 case VIEW_CONVERT_EXPR
:
17371 case NON_LVALUE_EXPR
:
17372 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
17375 case COMPONENT_REF
:
17376 case BIT_FIELD_REF
:
17378 case ARRAY_RANGE_REF
:
17379 case REALPART_EXPR
:
17380 case IMAGPART_EXPR
:
17383 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
17385 int unsignedp
, reversep
, volatilep
= 0;
17387 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
17388 &unsignedp
, &reversep
, &volatilep
);
17390 gcc_assert (obj
!= loc
);
17392 list_ret
= loc_list_from_tree_1 (obj
,
17394 && !bitpos
&& !offset
? 2 : 1,
17396 /* TODO: We can extract value of the small expression via shifting even
17397 for nonzero bitpos. */
17400 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
17402 expansion_failed (loc
, NULL_RTX
,
17403 "bitfield access");
17407 if (offset
!= NULL_TREE
)
17409 /* Variable offset. */
17410 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
17411 if (list_ret1
== 0)
17413 add_loc_list (&list_ret
, list_ret1
);
17416 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
17419 bytepos
= bitpos
/ BITS_PER_UNIT
;
17421 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
17422 else if (bytepos
< 0)
17423 loc_list_plus_const (list_ret
, bytepos
);
17430 if ((want_address
|| !tree_fits_shwi_p (loc
))
17431 && (ret
= cst_pool_loc_descr (loc
)))
17433 else if (want_address
== 2
17434 && tree_fits_shwi_p (loc
)
17435 && (ret
= address_of_int_loc_descriptor
17436 (int_size_in_bytes (TREE_TYPE (loc
)),
17437 tree_to_shwi (loc
))))
17439 else if (tree_fits_shwi_p (loc
))
17440 ret
= int_loc_descriptor (tree_to_shwi (loc
));
17441 else if (tree_fits_uhwi_p (loc
))
17442 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
17445 expansion_failed (loc
, NULL_RTX
,
17446 "Integer operand is not host integer");
17455 if ((ret
= cst_pool_loc_descr (loc
)))
17457 else if (TREE_CODE (loc
) == CONSTRUCTOR
)
17459 tree type
= TREE_TYPE (loc
);
17460 unsigned HOST_WIDE_INT size
= int_size_in_bytes (type
);
17461 unsigned HOST_WIDE_INT offset
= 0;
17462 unsigned HOST_WIDE_INT cnt
;
17463 constructor_elt
*ce
;
17465 if (TREE_CODE (type
) == RECORD_TYPE
)
17467 /* This is very limited, but it's enough to output
17468 pointers to member functions, as long as the
17469 referenced function is defined in the current
17470 translation unit. */
17471 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc
), cnt
, ce
)
17473 tree val
= ce
->value
;
17475 tree field
= ce
->index
;
17480 if (!field
|| DECL_BIT_FIELD (field
))
17482 expansion_failed (loc
, NULL_RTX
,
17483 "bitfield in record type constructor");
17484 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17489 HOST_WIDE_INT fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
17490 unsigned HOST_WIDE_INT pos
= int_byte_position (field
);
17491 gcc_assert (pos
+ fieldsize
<= size
);
17494 expansion_failed (loc
, NULL_RTX
,
17495 "out-of-order fields in record constructor");
17496 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17502 ret1
= new_loc_descr (DW_OP_piece
, pos
- offset
, 0);
17503 add_loc_descr (&ret
, ret1
);
17506 if (val
&& fieldsize
!= 0)
17508 ret1
= loc_descriptor_from_tree (val
, want_address
, context
);
17511 expansion_failed (loc
, NULL_RTX
,
17512 "unsupported expression in field");
17513 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17517 add_loc_descr (&ret
, ret1
);
17521 ret1
= new_loc_descr (DW_OP_piece
, fieldsize
, 0);
17522 add_loc_descr (&ret
, ret1
);
17523 offset
= pos
+ fieldsize
;
17527 if (offset
!= size
)
17529 ret1
= new_loc_descr (DW_OP_piece
, size
- offset
, 0);
17530 add_loc_descr (&ret
, ret1
);
17534 have_address
= !!want_address
;
17537 expansion_failed (loc
, NULL_RTX
,
17538 "constructor of non-record type");
17541 /* We can construct small constants here using int_loc_descriptor. */
17542 expansion_failed (loc
, NULL_RTX
,
17543 "constructor or constant not in constant pool");
17546 case TRUTH_AND_EXPR
:
17547 case TRUTH_ANDIF_EXPR
:
17552 case TRUTH_XOR_EXPR
:
17557 case TRUTH_OR_EXPR
:
17558 case TRUTH_ORIF_EXPR
:
17563 case FLOOR_DIV_EXPR
:
17564 case CEIL_DIV_EXPR
:
17565 case ROUND_DIV_EXPR
:
17566 case TRUNC_DIV_EXPR
:
17567 case EXACT_DIV_EXPR
:
17568 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17577 case FLOOR_MOD_EXPR
:
17578 case CEIL_MOD_EXPR
:
17579 case ROUND_MOD_EXPR
:
17580 case TRUNC_MOD_EXPR
:
17581 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17586 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17587 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17588 if (list_ret
== 0 || list_ret1
== 0)
17591 add_loc_list (&list_ret
, list_ret1
);
17594 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17595 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17596 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
17597 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
17598 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
17610 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
17613 case POINTER_PLUS_EXPR
:
17616 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
17618 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
17619 smarter to encode their opposite. The DW_OP_plus_uconst operation
17620 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
17621 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
17622 bytes, Y being the size of the operation that pushes the opposite
17623 of the addend. So let's choose the smallest representation. */
17624 const tree tree_addend
= TREE_OPERAND (loc
, 1);
17625 offset_int wi_addend
;
17626 HOST_WIDE_INT shwi_addend
;
17627 dw_loc_descr_ref loc_naddend
;
17629 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17633 /* Try to get the literal to push. It is the opposite of the addend,
17634 so as we rely on wrapping during DWARF evaluation, first decode
17635 the literal as a "DWARF-sized" signed number. */
17636 wi_addend
= wi::to_offset (tree_addend
);
17637 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
17638 shwi_addend
= wi_addend
.to_shwi ();
17639 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
17640 ? int_loc_descriptor (-shwi_addend
)
17643 if (loc_naddend
!= NULL
17644 && ((unsigned) size_of_uleb128 (shwi_addend
)
17645 > size_of_loc_descr (loc_naddend
)))
17647 add_loc_descr_to_each (list_ret
, loc_naddend
);
17648 add_loc_descr_to_each (list_ret
,
17649 new_loc_descr (DW_OP_minus
, 0, 0));
17653 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
17655 loc_naddend
= loc_cur
;
17656 loc_cur
= loc_cur
->dw_loc_next
;
17657 ggc_free (loc_naddend
);
17659 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
17669 goto do_comp_binop
;
17673 goto do_comp_binop
;
17677 goto do_comp_binop
;
17681 goto do_comp_binop
;
17684 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
17686 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
17687 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
17688 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
17704 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17705 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17706 if (list_ret
== 0 || list_ret1
== 0)
17709 add_loc_list (&list_ret
, list_ret1
);
17712 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
17715 case TRUTH_NOT_EXPR
:
17729 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17733 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
17739 const enum tree_code code
=
17740 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
17742 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
17743 build2 (code
, integer_type_node
,
17744 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
17745 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
17752 dw_loc_descr_ref lhs
17753 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
17754 dw_loc_list_ref rhs
17755 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
17756 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
17758 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17759 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
17762 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
17763 add_loc_descr_to_each (list_ret
, bra_node
);
17765 add_loc_list (&list_ret
, rhs
);
17766 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
17767 add_loc_descr_to_each (list_ret
, jump_node
);
17769 add_loc_descr_to_each (list_ret
, lhs
);
17770 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
17771 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
17773 /* ??? Need a node to point the skip at. Use a nop. */
17774 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
17775 add_loc_descr_to_each (list_ret
, tmp
);
17776 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
17777 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
17781 case FIX_TRUNC_EXPR
:
17785 /* Leave front-end specific codes as simply unknown. This comes
17786 up, for instance, with the C STMT_EXPR. */
17787 if ((unsigned int) TREE_CODE (loc
)
17788 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
17790 expansion_failed (loc
, NULL_RTX
,
17791 "language specific tree node");
17795 /* Otherwise this is a generic code; we should just lists all of
17796 these explicitly. We forgot one. */
17798 gcc_unreachable ();
17800 /* In a release build, we want to degrade gracefully: better to
17801 generate incomplete debugging information than to crash. */
17805 if (!ret
&& !list_ret
)
17808 if (want_address
== 2 && !have_address
17809 && (dwarf_version
>= 4 || !dwarf_strict
))
17811 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
17813 expansion_failed (loc
, NULL_RTX
,
17814 "DWARF address size mismatch");
17818 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17820 add_loc_descr_to_each (list_ret
,
17821 new_loc_descr (DW_OP_stack_value
, 0, 0));
17824 /* Show if we can't fill the request for an address. */
17825 if (want_address
&& !have_address
)
17827 expansion_failed (loc
, NULL_RTX
,
17828 "Want address and only have value");
17832 gcc_assert (!ret
|| !list_ret
);
17834 /* If we've got an address and don't want one, dereference. */
17835 if (!want_address
&& have_address
)
17837 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
17839 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
17841 expansion_failed (loc
, NULL_RTX
,
17842 "DWARF address size mismatch");
17845 else if (size
== DWARF2_ADDR_SIZE
)
17848 op
= DW_OP_deref_size
;
17851 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
17853 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
17856 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
17861 /* Likewise, but strip useless DW_OP_nop operations in the resulting
17864 static dw_loc_list_ref
17865 loc_list_from_tree (tree loc
, int want_address
,
17866 struct loc_descr_context
*context
)
17868 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
17870 for (dw_loc_list_ref loc_cur
= result
;
17871 loc_cur
!= NULL
; loc_cur
=
17872 loc_cur
->dw_loc_next
)
17873 loc_descr_without_nops (loc_cur
->expr
);
17877 /* Same as above but return only single location expression. */
17878 static dw_loc_descr_ref
17879 loc_descriptor_from_tree (tree loc
, int want_address
,
17880 struct loc_descr_context
*context
)
17882 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
17885 if (ret
->dw_loc_next
)
17887 expansion_failed (loc
, NULL_RTX
,
17888 "Location list where only loc descriptor needed");
17894 /* Given a value, round it up to the lowest multiple of `boundary'
17895 which is not less than the value itself. */
17897 static inline HOST_WIDE_INT
17898 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
17900 return (((value
+ boundary
- 1) / boundary
) * boundary
);
17903 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
17904 pointer to the declared type for the relevant field variable, or return
17905 `integer_type_node' if the given node turns out to be an
17906 ERROR_MARK node. */
17909 field_type (const_tree decl
)
17913 if (TREE_CODE (decl
) == ERROR_MARK
)
17914 return integer_type_node
;
17916 type
= DECL_BIT_FIELD_TYPE (decl
);
17917 if (type
== NULL_TREE
)
17918 type
= TREE_TYPE (decl
);
17923 /* Given a pointer to a tree node, return the alignment in bits for
17924 it, or else return BITS_PER_WORD if the node actually turns out to
17925 be an ERROR_MARK node. */
17927 static inline unsigned
17928 simple_type_align_in_bits (const_tree type
)
17930 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
17933 static inline unsigned
17934 simple_decl_align_in_bits (const_tree decl
)
17936 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
17939 /* Return the result of rounding T up to ALIGN. */
17941 static inline offset_int
17942 round_up_to_align (const offset_int
&t
, unsigned int align
)
17944 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
17947 /* Compute the size of TYPE in bytes. If possible, return NULL and store the
17948 size as an integer constant in CST_SIZE. Otherwise, if possible, return a
17949 DWARF expression that computes the size. Return NULL and set CST_SIZE to -1
17950 if we fail to return the size in one of these two forms. */
17952 static dw_loc_descr_ref
17953 type_byte_size (const_tree type
, HOST_WIDE_INT
*cst_size
)
17956 struct loc_descr_context ctx
;
17958 /* Return a constant integer in priority, if possible. */
17959 *cst_size
= int_size_in_bytes (type
);
17960 if (*cst_size
!= -1)
17963 ctx
.context_type
= const_cast<tree
> (type
);
17964 ctx
.base_decl
= NULL_TREE
;
17966 ctx
.placeholder_arg
= false;
17967 ctx
.placeholder_seen
= false;
17969 type
= TYPE_MAIN_VARIANT (type
);
17970 tree_size
= TYPE_SIZE_UNIT (type
);
17971 return ((tree_size
!= NULL_TREE
)
17972 ? loc_descriptor_from_tree (tree_size
, 0, &ctx
)
17976 /* Helper structure for RECORD_TYPE processing. */
17979 /* Root RECORD_TYPE. It is needed to generate data member location
17980 descriptions in variable-length records (VLR), but also to cope with
17981 variants, which are composed of nested structures multiplexed with
17982 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
17983 function processing a FIELD_DECL, it is required to be non null. */
17985 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
17986 QUAL_UNION_TYPE), this holds an expression that computes the offset for
17987 this variant part as part of the root record (in storage units). For
17988 regular records, it must be NULL_TREE. */
17989 tree variant_part_offset
;
17992 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
17993 addressed byte of the "containing object" for the given FIELD_DECL. If
17994 possible, return a native constant through CST_OFFSET (in which case NULL is
17995 returned); otherwise return a DWARF expression that computes the offset.
17997 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
17998 that offset is, either because the argument turns out to be a pointer to an
17999 ERROR_MARK node, or because the offset expression is too complex for us.
18001 CTX is required: see the comment for VLR_CONTEXT. */
18003 static dw_loc_descr_ref
18004 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
18005 HOST_WIDE_INT
*cst_offset
)
18008 dw_loc_list_ref loc_result
;
18012 if (TREE_CODE (decl
) == ERROR_MARK
)
18015 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
18017 /* We cannot handle variable bit offsets at the moment, so abort if it's the
18019 if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
)
18022 #ifdef PCC_BITFIELD_TYPE_MATTERS
18023 /* We used to handle only constant offsets in all cases. Now, we handle
18024 properly dynamic byte offsets only when PCC bitfield type doesn't
18026 if (PCC_BITFIELD_TYPE_MATTERS
18027 && TREE_CODE (DECL_FIELD_OFFSET (decl
)) == INTEGER_CST
)
18029 offset_int object_offset_in_bits
;
18030 offset_int object_offset_in_bytes
;
18031 offset_int bitpos_int
;
18033 tree field_size_tree
;
18034 offset_int deepest_bitpos
;
18035 offset_int field_size_in_bits
;
18036 unsigned int type_align_in_bits
;
18037 unsigned int decl_align_in_bits
;
18038 offset_int type_size_in_bits
;
18040 bitpos_int
= wi::to_offset (bit_position (decl
));
18041 type
= field_type (decl
);
18042 type_size_in_bits
= offset_int_type_size_in_bits (type
);
18043 type_align_in_bits
= simple_type_align_in_bits (type
);
18045 field_size_tree
= DECL_SIZE (decl
);
18047 /* The size could be unspecified if there was an error, or for
18048 a flexible array member. */
18049 if (!field_size_tree
)
18050 field_size_tree
= bitsize_zero_node
;
18052 /* If the size of the field is not constant, use the type size. */
18053 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
18054 field_size_in_bits
= wi::to_offset (field_size_tree
);
18056 field_size_in_bits
= type_size_in_bits
;
18058 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
18060 /* The GCC front-end doesn't make any attempt to keep track of the
18061 starting bit offset (relative to the start of the containing
18062 structure type) of the hypothetical "containing object" for a
18063 bit-field. Thus, when computing the byte offset value for the
18064 start of the "containing object" of a bit-field, we must deduce
18065 this information on our own. This can be rather tricky to do in
18066 some cases. For example, handling the following structure type
18067 definition when compiling for an i386/i486 target (which only
18068 aligns long long's to 32-bit boundaries) can be very tricky:
18070 struct S { int field1; long long field2:31; };
18072 Fortunately, there is a simple rule-of-thumb which can be used
18073 in such cases. When compiling for an i386/i486, GCC will
18074 allocate 8 bytes for the structure shown above. It decides to
18075 do this based upon one simple rule for bit-field allocation.
18076 GCC allocates each "containing object" for each bit-field at
18077 the first (i.e. lowest addressed) legitimate alignment boundary
18078 (based upon the required minimum alignment for the declared
18079 type of the field) which it can possibly use, subject to the
18080 condition that there is still enough available space remaining
18081 in the containing object (when allocated at the selected point)
18082 to fully accommodate all of the bits of the bit-field itself.
18084 This simple rule makes it obvious why GCC allocates 8 bytes for
18085 each object of the structure type shown above. When looking
18086 for a place to allocate the "containing object" for `field2',
18087 the compiler simply tries to allocate a 64-bit "containing
18088 object" at each successive 32-bit boundary (starting at zero)
18089 until it finds a place to allocate that 64- bit field such that
18090 at least 31 contiguous (and previously unallocated) bits remain
18091 within that selected 64 bit field. (As it turns out, for the
18092 example above, the compiler finds it is OK to allocate the
18093 "containing object" 64-bit field at bit-offset zero within the
18096 Here we attempt to work backwards from the limited set of facts
18097 we're given, and we try to deduce from those facts, where GCC
18098 must have believed that the containing object started (within
18099 the structure type). The value we deduce is then used (by the
18100 callers of this routine) to generate DW_AT_location and
18101 DW_AT_bit_offset attributes for fields (both bit-fields and, in
18102 the case of DW_AT_location, regular fields as well). */
18104 /* Figure out the bit-distance from the start of the structure to
18105 the "deepest" bit of the bit-field. */
18106 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
18108 /* This is the tricky part. Use some fancy footwork to deduce
18109 where the lowest addressed bit of the containing object must
18111 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18113 /* Round up to type_align by default. This works best for
18115 object_offset_in_bits
18116 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
18118 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
18120 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18122 /* Round up to decl_align instead. */
18123 object_offset_in_bits
18124 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
18127 object_offset_in_bytes
18128 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
18129 if (ctx
->variant_part_offset
== NULL_TREE
)
18131 *cst_offset
= object_offset_in_bytes
.to_shwi ();
18134 tree_result
= wide_int_to_tree (sizetype
, object_offset_in_bytes
);
18137 #endif /* PCC_BITFIELD_TYPE_MATTERS */
18138 tree_result
= byte_position (decl
);
18140 if (ctx
->variant_part_offset
!= NULL_TREE
)
18141 tree_result
= fold_build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
18142 ctx
->variant_part_offset
, tree_result
);
18144 /* If the byte offset is a constant, it's simplier to handle a native
18145 constant rather than a DWARF expression. */
18146 if (TREE_CODE (tree_result
) == INTEGER_CST
)
18148 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
18151 struct loc_descr_context loc_ctx
= {
18152 ctx
->struct_type
, /* context_type */
18153 NULL_TREE
, /* base_decl */
18155 false, /* placeholder_arg */
18156 false /* placeholder_seen */
18158 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
18160 /* We want a DWARF expression: abort if we only have a location list with
18161 multiple elements. */
18162 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
18165 return loc_result
->expr
;
18168 /* The following routines define various Dwarf attributes and any data
18169 associated with them. */
18171 /* Add a location description attribute value to a DIE.
18173 This emits location attributes suitable for whole variables and
18174 whole parameters. Note that the location attributes for struct fields are
18175 generated by the routine `data_member_location_attribute' below. */
18178 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
18179 dw_loc_list_ref descr
)
18183 if (single_element_loc_list_p (descr
))
18184 add_AT_loc (die
, attr_kind
, descr
->expr
);
18186 add_AT_loc_list (die
, attr_kind
, descr
);
18189 /* Add DW_AT_accessibility attribute to DIE if needed. */
18192 add_accessibility_attribute (dw_die_ref die
, tree decl
)
18194 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18195 children, otherwise the default is DW_ACCESS_public. In DWARF2
18196 the default has always been DW_ACCESS_public. */
18197 if (TREE_PROTECTED (decl
))
18198 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18199 else if (TREE_PRIVATE (decl
))
18201 if (dwarf_version
== 2
18202 || die
->die_parent
== NULL
18203 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
18204 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18206 else if (dwarf_version
> 2
18208 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
18209 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18212 /* Attach the specialized form of location attribute used for data members of
18213 struct and union types. In the special case of a FIELD_DECL node which
18214 represents a bit-field, the "offset" part of this special location
18215 descriptor must indicate the distance in bytes from the lowest-addressed
18216 byte of the containing struct or union type to the lowest-addressed byte of
18217 the "containing object" for the bit-field. (See the `field_byte_offset'
18220 For any given bit-field, the "containing object" is a hypothetical object
18221 (of some integral or enum type) within which the given bit-field lives. The
18222 type of this hypothetical "containing object" is always the same as the
18223 declared type of the individual bit-field itself (for GCC anyway... the
18224 DWARF spec doesn't actually mandate this). Note that it is the size (in
18225 bytes) of the hypothetical "containing object" which will be given in the
18226 DW_AT_byte_size attribute for this bit-field. (See the
18227 `byte_size_attribute' function below.) It is also used when calculating the
18228 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
18231 CTX is required: see the comment for VLR_CONTEXT. */
18234 add_data_member_location_attribute (dw_die_ref die
,
18236 struct vlr_context
*ctx
)
18238 HOST_WIDE_INT offset
;
18239 dw_loc_descr_ref loc_descr
= 0;
18241 if (TREE_CODE (decl
) == TREE_BINFO
)
18243 /* We're working on the TAG_inheritance for a base class. */
18244 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
18246 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
18247 aren't at a fixed offset from all (sub)objects of the same
18248 type. We need to extract the appropriate offset from our
18249 vtable. The following dwarf expression means
18251 BaseAddr = ObAddr + *((*ObAddr) - Offset)
18253 This is specific to the V3 ABI, of course. */
18255 dw_loc_descr_ref tmp
;
18257 /* Make a copy of the object address. */
18258 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
18259 add_loc_descr (&loc_descr
, tmp
);
18261 /* Extract the vtable address. */
18262 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18263 add_loc_descr (&loc_descr
, tmp
);
18265 /* Calculate the address of the offset. */
18266 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
18267 gcc_assert (offset
< 0);
18269 tmp
= int_loc_descriptor (-offset
);
18270 add_loc_descr (&loc_descr
, tmp
);
18271 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
18272 add_loc_descr (&loc_descr
, tmp
);
18274 /* Extract the offset. */
18275 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18276 add_loc_descr (&loc_descr
, tmp
);
18278 /* Add it to the object address. */
18279 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
18280 add_loc_descr (&loc_descr
, tmp
);
18283 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
18287 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
18289 /* If loc_descr is available then we know the field offset is dynamic.
18290 However, GDB does not handle dynamic field offsets very well at the
18292 if (loc_descr
!= NULL
&& gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
)
18298 /* Data member location evalutation starts with the base address on the
18299 stack. Compute the field offset and add it to this base address. */
18300 else if (loc_descr
!= NULL
)
18301 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
18306 /* While DW_AT_data_bit_offset has been added already in DWARF4,
18307 e.g. GDB only added support to it in November 2016. For DWARF5
18308 we need newer debug info consumers anyway. We might change this
18309 to dwarf_version >= 4 once most consumers catched up. */
18310 if (dwarf_version
>= 5
18311 && TREE_CODE (decl
) == FIELD_DECL
18312 && DECL_BIT_FIELD_TYPE (decl
))
18314 tree off
= bit_position (decl
);
18315 if (tree_fits_uhwi_p (off
) && get_AT (die
, DW_AT_bit_size
))
18317 remove_AT (die
, DW_AT_byte_size
);
18318 remove_AT (die
, DW_AT_bit_offset
);
18319 add_AT_unsigned (die
, DW_AT_data_bit_offset
, tree_to_uhwi (off
));
18323 if (dwarf_version
> 2)
18325 /* Don't need to output a location expression, just the constant. */
18327 add_AT_int (die
, DW_AT_data_member_location
, offset
);
18329 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
18334 enum dwarf_location_atom op
;
18336 /* The DWARF2 standard says that we should assume that the structure
18337 address is already on the stack, so we can specify a structure
18338 field address by using DW_OP_plus_uconst. */
18339 op
= DW_OP_plus_uconst
;
18340 loc_descr
= new_loc_descr (op
, offset
, 0);
18344 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
18347 /* Writes integer values to dw_vec_const array. */
18350 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
18354 *dest
++ = val
& 0xff;
18360 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
18362 static HOST_WIDE_INT
18363 extract_int (const unsigned char *src
, unsigned int size
)
18365 HOST_WIDE_INT val
= 0;
18371 val
|= *--src
& 0xff;
18377 /* Writes wide_int values to dw_vec_const array. */
18380 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
18384 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
18386 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
18390 /* We'd have to extend this code to support odd sizes. */
18391 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
18393 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
18395 if (WORDS_BIG_ENDIAN
)
18396 for (i
= n
- 1; i
>= 0; i
--)
18398 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18399 dest
+= sizeof (HOST_WIDE_INT
);
18402 for (i
= 0; i
< n
; i
++)
18404 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18405 dest
+= sizeof (HOST_WIDE_INT
);
18409 /* Writes floating point values to dw_vec_const array. */
18412 insert_float (const_rtx rtl
, unsigned char *array
)
18417 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), GET_MODE (rtl
));
18419 /* real_to_target puts 32-bit pieces in each long. Pack them. */
18420 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
18422 insert_int (val
[i
], 4, array
);
18427 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
18428 does not have a "location" either in memory or in a register. These
18429 things can arise in GNU C when a constant is passed as an actual parameter
18430 to an inlined function. They can also arise in C++ where declared
18431 constants do not necessarily get memory "homes". */
18434 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
18436 switch (GET_CODE (rtl
))
18440 HOST_WIDE_INT val
= INTVAL (rtl
);
18443 add_AT_int (die
, DW_AT_const_value
, val
);
18445 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
18449 case CONST_WIDE_INT
:
18451 wide_int w1
= rtx_mode_t (rtl
, MAX_MODE_INT
);
18452 unsigned int prec
= MIN (wi::min_precision (w1
, UNSIGNED
),
18453 (unsigned int)CONST_WIDE_INT_NUNITS (rtl
) * HOST_BITS_PER_WIDE_INT
);
18454 wide_int w
= wi::zext (w1
, prec
);
18455 add_AT_wide (die
, DW_AT_const_value
, w
);
18460 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
18461 floating-point constant. A CONST_DOUBLE is used whenever the
18462 constant requires more than one word in order to be adequately
18465 machine_mode mode
= GET_MODE (rtl
);
18467 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
18468 add_AT_double (die
, DW_AT_const_value
,
18469 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
18472 unsigned int length
= GET_MODE_SIZE (mode
);
18473 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
18475 insert_float (rtl
, array
);
18476 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
18483 machine_mode mode
= GET_MODE (rtl
);
18484 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
18485 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
18486 unsigned char *array
18487 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
18490 machine_mode imode
= GET_MODE_INNER (mode
);
18492 switch (GET_MODE_CLASS (mode
))
18494 case MODE_VECTOR_INT
:
18495 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18497 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18498 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
18502 case MODE_VECTOR_FLOAT
:
18503 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18505 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18506 insert_float (elt
, p
);
18511 gcc_unreachable ();
18514 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
18519 if (dwarf_version
>= 4 || !dwarf_strict
)
18521 dw_loc_descr_ref loc_result
;
18522 resolve_one_addr (&rtl
);
18524 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
18525 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
18526 add_AT_loc (die
, DW_AT_location
, loc_result
);
18527 vec_safe_push (used_rtx_array
, rtl
);
18533 if (CONSTANT_P (XEXP (rtl
, 0)))
18534 return add_const_value_attribute (die
, XEXP (rtl
, 0));
18537 if (!const_ok_for_output (rtl
))
18541 if (dwarf_version
>= 4 || !dwarf_strict
)
18546 /* In cases where an inlined instance of an inline function is passed
18547 the address of an `auto' variable (which is local to the caller) we
18548 can get a situation where the DECL_RTL of the artificial local
18549 variable (for the inlining) which acts as a stand-in for the
18550 corresponding formal parameter (of the inline function) will look
18551 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
18552 exactly a compile-time constant expression, but it isn't the address
18553 of the (artificial) local variable either. Rather, it represents the
18554 *value* which the artificial local variable always has during its
18555 lifetime. We currently have no way to represent such quasi-constant
18556 values in Dwarf, so for now we just punt and generate nothing. */
18564 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
18565 && MEM_READONLY_P (rtl
)
18566 && GET_MODE (rtl
) == BLKmode
)
18568 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
18574 /* No other kinds of rtx should be possible here. */
18575 gcc_unreachable ();
18580 /* Determine whether the evaluation of EXPR references any variables
18581 or functions which aren't otherwise used (and therefore may not be
18584 reference_to_unused (tree
* tp
, int * walk_subtrees
,
18585 void * data ATTRIBUTE_UNUSED
)
18587 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
18588 *walk_subtrees
= 0;
18590 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
18591 && ! TREE_ASM_WRITTEN (*tp
))
18593 /* ??? The C++ FE emits debug information for using decls, so
18594 putting gcc_unreachable here falls over. See PR31899. For now
18595 be conservative. */
18596 else if (!symtab
->global_info_ready
&& VAR_OR_FUNCTION_DECL_P (*tp
))
18598 else if (VAR_P (*tp
))
18600 varpool_node
*node
= varpool_node::get (*tp
);
18601 if (!node
|| !node
->definition
)
18604 else if (TREE_CODE (*tp
) == FUNCTION_DECL
18605 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
18607 /* The call graph machinery must have finished analyzing,
18608 optimizing and gimplifying the CU by now.
18609 So if *TP has no call graph node associated
18610 to it, it means *TP will not be emitted. */
18611 if (!cgraph_node::get (*tp
))
18614 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
18620 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
18621 for use in a later add_const_value_attribute call. */
18624 rtl_for_decl_init (tree init
, tree type
)
18626 rtx rtl
= NULL_RTX
;
18630 /* If a variable is initialized with a string constant without embedded
18631 zeros, build CONST_STRING. */
18632 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
18634 tree enttype
= TREE_TYPE (type
);
18635 tree domain
= TYPE_DOMAIN (type
);
18636 machine_mode mode
= TYPE_MODE (enttype
);
18638 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
18640 && integer_zerop (TYPE_MIN_VALUE (domain
))
18641 && compare_tree_int (TYPE_MAX_VALUE (domain
),
18642 TREE_STRING_LENGTH (init
) - 1) == 0
18643 && ((size_t) TREE_STRING_LENGTH (init
)
18644 == strlen (TREE_STRING_POINTER (init
)) + 1))
18646 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
18647 ggc_strdup (TREE_STRING_POINTER (init
)));
18648 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
18649 MEM_READONLY_P (rtl
) = 1;
18652 /* Other aggregates, and complex values, could be represented using
18654 else if (AGGREGATE_TYPE_P (type
)
18655 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
18656 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
18657 || TREE_CODE (type
) == COMPLEX_TYPE
)
18659 /* Vectors only work if their mode is supported by the target.
18660 FIXME: generic vectors ought to work too. */
18661 else if (TREE_CODE (type
) == VECTOR_TYPE
18662 && !VECTOR_MODE_P (TYPE_MODE (type
)))
18664 /* If the initializer is something that we know will expand into an
18665 immediate RTL constant, expand it now. We must be careful not to
18666 reference variables which won't be output. */
18667 else if (initializer_constant_valid_p (init
, type
)
18668 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
18670 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
18672 if (TREE_CODE (type
) == VECTOR_TYPE
)
18673 switch (TREE_CODE (init
))
18678 if (TREE_CONSTANT (init
))
18680 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
18681 bool constant_p
= true;
18683 unsigned HOST_WIDE_INT ix
;
18685 /* Even when ctor is constant, it might contain non-*_CST
18686 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
18687 belong into VECTOR_CST nodes. */
18688 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
18689 if (!CONSTANT_CLASS_P (value
))
18691 constant_p
= false;
18697 init
= build_vector_from_ctor (type
, elts
);
18707 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
18709 /* If expand_expr returns a MEM, it wasn't immediate. */
18710 gcc_assert (!rtl
|| !MEM_P (rtl
));
18716 /* Generate RTL for the variable DECL to represent its location. */
18719 rtl_for_decl_location (tree decl
)
18723 /* Here we have to decide where we are going to say the parameter "lives"
18724 (as far as the debugger is concerned). We only have a couple of
18725 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
18727 DECL_RTL normally indicates where the parameter lives during most of the
18728 activation of the function. If optimization is enabled however, this
18729 could be either NULL or else a pseudo-reg. Both of those cases indicate
18730 that the parameter doesn't really live anywhere (as far as the code
18731 generation parts of GCC are concerned) during most of the function's
18732 activation. That will happen (for example) if the parameter is never
18733 referenced within the function.
18735 We could just generate a location descriptor here for all non-NULL
18736 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
18737 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
18738 where DECL_RTL is NULL or is a pseudo-reg.
18740 Note however that we can only get away with using DECL_INCOMING_RTL as
18741 a backup substitute for DECL_RTL in certain limited cases. In cases
18742 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
18743 we can be sure that the parameter was passed using the same type as it is
18744 declared to have within the function, and that its DECL_INCOMING_RTL
18745 points us to a place where a value of that type is passed.
18747 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
18748 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
18749 because in these cases DECL_INCOMING_RTL points us to a value of some
18750 type which is *different* from the type of the parameter itself. Thus,
18751 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
18752 such cases, the debugger would end up (for example) trying to fetch a
18753 `float' from a place which actually contains the first part of a
18754 `double'. That would lead to really incorrect and confusing
18755 output at debug-time.
18757 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
18758 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
18759 are a couple of exceptions however. On little-endian machines we can
18760 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
18761 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
18762 an integral type that is smaller than TREE_TYPE (decl). These cases arise
18763 when (on a little-endian machine) a non-prototyped function has a
18764 parameter declared to be of type `short' or `char'. In such cases,
18765 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
18766 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
18767 passed `int' value. If the debugger then uses that address to fetch
18768 a `short' or a `char' (on a little-endian machine) the result will be
18769 the correct data, so we allow for such exceptional cases below.
18771 Note that our goal here is to describe the place where the given formal
18772 parameter lives during most of the function's activation (i.e. between the
18773 end of the prologue and the start of the epilogue). We'll do that as best
18774 as we can. Note however that if the given formal parameter is modified
18775 sometime during the execution of the function, then a stack backtrace (at
18776 debug-time) will show the function as having been called with the *new*
18777 value rather than the value which was originally passed in. This happens
18778 rarely enough that it is not a major problem, but it *is* a problem, and
18779 I'd like to fix it.
18781 A future version of dwarf2out.c may generate two additional attributes for
18782 any given DW_TAG_formal_parameter DIE which will describe the "passed
18783 type" and the "passed location" for the given formal parameter in addition
18784 to the attributes we now generate to indicate the "declared type" and the
18785 "active location" for each parameter. This additional set of attributes
18786 could be used by debuggers for stack backtraces. Separately, note that
18787 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
18788 This happens (for example) for inlined-instances of inline function formal
18789 parameters which are never referenced. This really shouldn't be
18790 happening. All PARM_DECL nodes should get valid non-NULL
18791 DECL_INCOMING_RTL values. FIXME. */
18793 /* Use DECL_RTL as the "location" unless we find something better. */
18794 rtl
= DECL_RTL_IF_SET (decl
);
18796 /* When generating abstract instances, ignore everything except
18797 constants, symbols living in memory, and symbols living in
18798 fixed registers. */
18799 if (! reload_completed
)
18802 && (CONSTANT_P (rtl
)
18804 && CONSTANT_P (XEXP (rtl
, 0)))
18807 && TREE_STATIC (decl
))))
18809 rtl
= targetm
.delegitimize_address (rtl
);
18814 else if (TREE_CODE (decl
) == PARM_DECL
)
18816 if (rtl
== NULL_RTX
18817 || is_pseudo_reg (rtl
)
18819 && is_pseudo_reg (XEXP (rtl
, 0))
18820 && DECL_INCOMING_RTL (decl
)
18821 && MEM_P (DECL_INCOMING_RTL (decl
))
18822 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
18824 tree declared_type
= TREE_TYPE (decl
);
18825 tree passed_type
= DECL_ARG_TYPE (decl
);
18826 machine_mode dmode
= TYPE_MODE (declared_type
);
18827 machine_mode pmode
= TYPE_MODE (passed_type
);
18829 /* This decl represents a formal parameter which was optimized out.
18830 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
18831 all cases where (rtl == NULL_RTX) just below. */
18832 if (dmode
== pmode
)
18833 rtl
= DECL_INCOMING_RTL (decl
);
18834 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
18835 && SCALAR_INT_MODE_P (dmode
)
18836 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
18837 && DECL_INCOMING_RTL (decl
))
18839 rtx inc
= DECL_INCOMING_RTL (decl
);
18842 else if (MEM_P (inc
))
18844 if (BYTES_BIG_ENDIAN
)
18845 rtl
= adjust_address_nv (inc
, dmode
,
18846 GET_MODE_SIZE (pmode
)
18847 - GET_MODE_SIZE (dmode
));
18854 /* If the parm was passed in registers, but lives on the stack, then
18855 make a big endian correction if the mode of the type of the
18856 parameter is not the same as the mode of the rtl. */
18857 /* ??? This is the same series of checks that are made in dbxout.c before
18858 we reach the big endian correction code there. It isn't clear if all
18859 of these checks are necessary here, but keeping them all is the safe
18861 else if (MEM_P (rtl
)
18862 && XEXP (rtl
, 0) != const0_rtx
18863 && ! CONSTANT_P (XEXP (rtl
, 0))
18864 /* Not passed in memory. */
18865 && !MEM_P (DECL_INCOMING_RTL (decl
))
18866 /* Not passed by invisible reference. */
18867 && (!REG_P (XEXP (rtl
, 0))
18868 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
18869 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
18870 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
18871 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
18874 /* Big endian correction check. */
18875 && BYTES_BIG_ENDIAN
18876 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
18877 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
18880 machine_mode addr_mode
= get_address_mode (rtl
);
18881 int offset
= (UNITS_PER_WORD
18882 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
18884 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
18885 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
18888 else if (VAR_P (decl
)
18891 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
18892 && BYTES_BIG_ENDIAN
)
18894 machine_mode addr_mode
= get_address_mode (rtl
);
18895 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
18896 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
18898 /* If a variable is declared "register" yet is smaller than
18899 a register, then if we store the variable to memory, it
18900 looks like we're storing a register-sized value, when in
18901 fact we are not. We need to adjust the offset of the
18902 storage location to reflect the actual value's bytes,
18903 else gdb will not be able to display it. */
18905 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
18906 plus_constant (addr_mode
, XEXP (rtl
, 0),
18910 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
18911 and will have been substituted directly into all expressions that use it.
18912 C does not have such a concept, but C++ and other languages do. */
18913 if (!rtl
&& VAR_P (decl
) && DECL_INITIAL (decl
))
18914 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
18917 rtl
= targetm
.delegitimize_address (rtl
);
18919 /* If we don't look past the constant pool, we risk emitting a
18920 reference to a constant pool entry that isn't referenced from
18921 code, and thus is not emitted. */
18923 rtl
= avoid_constant_pool_reference (rtl
);
18925 /* Try harder to get a rtl. If this symbol ends up not being emitted
18926 in the current CU, resolve_addr will remove the expression referencing
18928 if (rtl
== NULL_RTX
18930 && !DECL_EXTERNAL (decl
)
18931 && TREE_STATIC (decl
)
18932 && DECL_NAME (decl
)
18933 && !DECL_HARD_REGISTER (decl
)
18934 && DECL_MODE (decl
) != VOIDmode
)
18936 rtl
= make_decl_rtl_for_debug (decl
);
18938 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
18939 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
18946 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
18947 returned. If so, the decl for the COMMON block is returned, and the
18948 value is the offset into the common block for the symbol. */
18951 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
18953 tree val_expr
, cvar
;
18955 HOST_WIDE_INT bitsize
, bitpos
;
18957 int unsignedp
, reversep
, volatilep
= 0;
18959 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
18960 it does not have a value (the offset into the common area), or if it
18961 is thread local (as opposed to global) then it isn't common, and shouldn't
18962 be handled as such. */
18964 || !TREE_STATIC (decl
)
18965 || !DECL_HAS_VALUE_EXPR_P (decl
)
18969 val_expr
= DECL_VALUE_EXPR (decl
);
18970 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
18973 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
18974 &unsignedp
, &reversep
, &volatilep
);
18976 if (cvar
== NULL_TREE
18978 || DECL_ARTIFICIAL (cvar
)
18979 || !TREE_PUBLIC (cvar
))
18983 if (offset
!= NULL
)
18985 if (!tree_fits_shwi_p (offset
))
18987 *value
= tree_to_shwi (offset
);
18990 *value
+= bitpos
/ BITS_PER_UNIT
;
18995 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
18996 data attribute for a variable or a parameter. We generate the
18997 DW_AT_const_value attribute only in those cases where the given variable
18998 or parameter does not have a true "location" either in memory or in a
18999 register. This can happen (for example) when a constant is passed as an
19000 actual argument in a call to an inline function. (It's possible that
19001 these things can crop up in other ways also.) Note that one type of
19002 constant value which can be passed into an inlined function is a constant
19003 pointer. This can happen for example if an actual argument in an inlined
19004 function call evaluates to a compile-time constant address.
19006 CACHE_P is true if it is worth caching the location list for DECL,
19007 so that future calls can reuse it rather than regenerate it from scratch.
19008 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
19009 since we will need to refer to them each time the function is inlined. */
19012 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
19015 dw_loc_list_ref list
;
19016 var_loc_list
*loc_list
;
19017 cached_dw_loc_list
*cache
;
19022 if (TREE_CODE (decl
) == ERROR_MARK
)
19025 if (get_AT (die
, DW_AT_location
)
19026 || get_AT (die
, DW_AT_const_value
))
19029 gcc_assert (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
19030 || TREE_CODE (decl
) == RESULT_DECL
);
19032 /* Try to get some constant RTL for this decl, and use that as the value of
19035 rtl
= rtl_for_decl_location (decl
);
19036 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19037 && add_const_value_attribute (die
, rtl
))
19040 /* See if we have single element location list that is equivalent to
19041 a constant value. That way we are better to use add_const_value_attribute
19042 rather than expanding constant value equivalent. */
19043 loc_list
= lookup_decl_loc (decl
);
19046 && loc_list
->first
->next
== NULL
19047 && NOTE_P (loc_list
->first
->loc
)
19048 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
19049 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
19051 struct var_loc_node
*node
;
19053 node
= loc_list
->first
;
19054 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
19055 if (GET_CODE (rtl
) == EXPR_LIST
)
19056 rtl
= XEXP (rtl
, 0);
19057 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19058 && add_const_value_attribute (die
, rtl
))
19061 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
19062 list several times. See if we've already cached the contents. */
19064 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
19068 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
19070 list
= cache
->loc_list
;
19074 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
19076 /* It is usually worth caching this result if the decl is from
19077 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
19078 if (cache_p
&& list
&& list
->dw_loc_next
)
19080 cached_dw_loc_list
**slot
19081 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
19084 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
19085 cache
->decl_id
= DECL_UID (decl
);
19086 cache
->loc_list
= list
;
19092 add_AT_location_description (die
, DW_AT_location
, list
);
19095 /* None of that worked, so it must not really have a location;
19096 try adding a constant value attribute from the DECL_INITIAL. */
19097 return tree_add_const_value_attribute_for_decl (die
, decl
);
19100 /* Helper function for tree_add_const_value_attribute. Natively encode
19101 initializer INIT into an array. Return true if successful. */
19104 native_encode_initializer (tree init
, unsigned char *array
, int size
)
19108 if (init
== NULL_TREE
)
19112 switch (TREE_CODE (init
))
19115 type
= TREE_TYPE (init
);
19116 if (TREE_CODE (type
) == ARRAY_TYPE
)
19118 tree enttype
= TREE_TYPE (type
);
19119 machine_mode mode
= TYPE_MODE (enttype
);
19121 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
19123 if (int_size_in_bytes (type
) != size
)
19125 if (size
> TREE_STRING_LENGTH (init
))
19127 memcpy (array
, TREE_STRING_POINTER (init
),
19128 TREE_STRING_LENGTH (init
));
19129 memset (array
+ TREE_STRING_LENGTH (init
),
19130 '\0', size
- TREE_STRING_LENGTH (init
));
19133 memcpy (array
, TREE_STRING_POINTER (init
), size
);
19138 type
= TREE_TYPE (init
);
19139 if (int_size_in_bytes (type
) != size
)
19141 if (TREE_CODE (type
) == ARRAY_TYPE
)
19143 HOST_WIDE_INT min_index
;
19144 unsigned HOST_WIDE_INT cnt
;
19145 int curpos
= 0, fieldsize
;
19146 constructor_elt
*ce
;
19148 if (TYPE_DOMAIN (type
) == NULL_TREE
19149 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
19152 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
19153 if (fieldsize
<= 0)
19156 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
19157 memset (array
, '\0', size
);
19158 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19160 tree val
= ce
->value
;
19161 tree index
= ce
->index
;
19163 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19164 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
19167 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
19172 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
19175 curpos
= pos
+ fieldsize
;
19176 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19178 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
19179 - tree_to_shwi (TREE_OPERAND (index
, 0));
19180 while (count
-- > 0)
19183 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
19184 curpos
+= fieldsize
;
19187 gcc_assert (curpos
<= size
);
19191 else if (TREE_CODE (type
) == RECORD_TYPE
19192 || TREE_CODE (type
) == UNION_TYPE
)
19194 tree field
= NULL_TREE
;
19195 unsigned HOST_WIDE_INT cnt
;
19196 constructor_elt
*ce
;
19198 if (int_size_in_bytes (type
) != size
)
19201 if (TREE_CODE (type
) == RECORD_TYPE
)
19202 field
= TYPE_FIELDS (type
);
19204 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19206 tree val
= ce
->value
;
19207 int pos
, fieldsize
;
19209 if (ce
->index
!= 0)
19215 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
19218 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
19219 && TYPE_DOMAIN (TREE_TYPE (field
))
19220 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
19222 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
19223 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
19225 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
19226 pos
= int_byte_position (field
);
19227 gcc_assert (pos
+ fieldsize
<= size
);
19228 if (val
&& fieldsize
!= 0
19229 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
19235 case VIEW_CONVERT_EXPR
:
19236 case NON_LVALUE_EXPR
:
19237 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
19239 return native_encode_expr (init
, array
, size
) == size
;
19243 /* Attach a DW_AT_const_value attribute to DIE. The value of the
19244 attribute is the const value T. */
19247 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
19250 tree type
= TREE_TYPE (t
);
19253 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
19257 gcc_assert (!DECL_P (init
));
19261 rtl
= rtl_for_decl_init (init
, type
);
19263 return add_const_value_attribute (die
, rtl
);
19265 /* If the host and target are sane, try harder. */
19266 if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
19267 && initializer_constant_valid_p (init
, type
))
19269 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
19270 if (size
> 0 && (int) size
== size
)
19272 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
19274 if (native_encode_initializer (init
, array
, size
))
19276 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
19285 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
19286 attribute is the const value of T, where T is an integral constant
19287 variable with static storage duration
19288 (so it can't be a PARM_DECL or a RESULT_DECL). */
19291 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
19295 || (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
19296 || (VAR_P (decl
) && !TREE_STATIC (decl
)))
19299 if (TREE_READONLY (decl
)
19300 && ! TREE_THIS_VOLATILE (decl
)
19301 && DECL_INITIAL (decl
))
19306 /* Don't add DW_AT_const_value if abstract origin already has one. */
19307 if (get_AT (var_die
, DW_AT_const_value
))
19310 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
19313 /* Convert the CFI instructions for the current function into a
19314 location list. This is used for DW_AT_frame_base when we targeting
19315 a dwarf2 consumer that does not support the dwarf3
19316 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
19319 static dw_loc_list_ref
19320 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
19324 dw_loc_list_ref list
, *list_tail
;
19326 dw_cfa_location last_cfa
, next_cfa
;
19327 const char *start_label
, *last_label
, *section
;
19328 dw_cfa_location remember
;
19331 gcc_assert (fde
!= NULL
);
19333 section
= secname_for_decl (current_function_decl
);
19337 memset (&next_cfa
, 0, sizeof (next_cfa
));
19338 next_cfa
.reg
= INVALID_REGNUM
;
19339 remember
= next_cfa
;
19341 start_label
= fde
->dw_fde_begin
;
19343 /* ??? Bald assumption that the CIE opcode list does not contain
19344 advance opcodes. */
19345 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
19346 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19348 last_cfa
= next_cfa
;
19349 last_label
= start_label
;
19351 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
19353 /* If the first partition contained no CFI adjustments, the
19354 CIE opcodes apply to the whole first partition. */
19355 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19356 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
19357 list_tail
=&(*list_tail
)->dw_loc_next
;
19358 start_label
= last_label
= fde
->dw_fde_second_begin
;
19361 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
19363 switch (cfi
->dw_cfi_opc
)
19365 case DW_CFA_set_loc
:
19366 case DW_CFA_advance_loc1
:
19367 case DW_CFA_advance_loc2
:
19368 case DW_CFA_advance_loc4
:
19369 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19371 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19372 start_label
, last_label
, section
);
19374 list_tail
= &(*list_tail
)->dw_loc_next
;
19375 last_cfa
= next_cfa
;
19376 start_label
= last_label
;
19378 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
19381 case DW_CFA_advance_loc
:
19382 /* The encoding is complex enough that we should never emit this. */
19383 gcc_unreachable ();
19386 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19389 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
19391 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19393 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19394 start_label
, last_label
, section
);
19396 list_tail
= &(*list_tail
)->dw_loc_next
;
19397 last_cfa
= next_cfa
;
19398 start_label
= last_label
;
19400 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19401 start_label
, fde
->dw_fde_end
, section
);
19402 list_tail
= &(*list_tail
)->dw_loc_next
;
19403 start_label
= last_label
= fde
->dw_fde_second_begin
;
19407 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19409 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19410 start_label
, last_label
, section
);
19411 list_tail
= &(*list_tail
)->dw_loc_next
;
19412 start_label
= last_label
;
19415 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
19417 fde
->dw_fde_second_begin
19418 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
19421 if (list
&& list
->dw_loc_next
)
19427 /* Compute a displacement from the "steady-state frame pointer" to the
19428 frame base (often the same as the CFA), and store it in
19429 frame_pointer_fb_offset. OFFSET is added to the displacement
19430 before the latter is negated. */
19433 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
19437 #ifdef FRAME_POINTER_CFA_OFFSET
19438 reg
= frame_pointer_rtx
;
19439 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
19441 reg
= arg_pointer_rtx
;
19442 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
19445 elim
= (ira_use_lra_p
19446 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
19447 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
19448 if (GET_CODE (elim
) == PLUS
)
19450 offset
+= INTVAL (XEXP (elim
, 1));
19451 elim
= XEXP (elim
, 0);
19454 frame_pointer_fb_offset
= -offset
;
19456 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
19457 in which to eliminate. This is because it's stack pointer isn't
19458 directly accessible as a register within the ISA. To work around
19459 this, assume that while we cannot provide a proper value for
19460 frame_pointer_fb_offset, we won't need one either. */
19461 frame_pointer_fb_offset_valid
19462 = ((SUPPORTS_STACK_ALIGNMENT
19463 && (elim
== hard_frame_pointer_rtx
19464 || elim
== stack_pointer_rtx
))
19465 || elim
== (frame_pointer_needed
19466 ? hard_frame_pointer_rtx
19467 : stack_pointer_rtx
));
19470 /* Generate a DW_AT_name attribute given some string value to be included as
19471 the value of the attribute. */
19474 add_name_attribute (dw_die_ref die
, const char *name_string
)
19476 if (name_string
!= NULL
&& *name_string
!= 0)
19478 if (demangle_name_func
)
19479 name_string
= (*demangle_name_func
) (name_string
);
19481 add_AT_string (die
, DW_AT_name
, name_string
);
19485 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
19486 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
19487 of TYPE accordingly.
19489 ??? This is a temporary measure until after we're able to generate
19490 regular DWARF for the complex Ada type system. */
19493 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
19494 dw_die_ref context_die
)
19497 dw_die_ref dtype_die
;
19499 if (!lang_hooks
.types
.descriptive_type
)
19502 dtype
= lang_hooks
.types
.descriptive_type (type
);
19506 dtype_die
= lookup_type_die (dtype
);
19509 gen_type_die (dtype
, context_die
);
19510 dtype_die
= lookup_type_die (dtype
);
19511 gcc_assert (dtype_die
);
19514 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
19517 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
19519 static const char *
19520 comp_dir_string (void)
19524 static const char *cached_wd
= NULL
;
19526 if (cached_wd
!= NULL
)
19529 wd
= get_src_pwd ();
19533 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
19537 wdlen
= strlen (wd
);
19538 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
19540 wd1
[wdlen
] = DIR_SEPARATOR
;
19541 wd1
[wdlen
+ 1] = 0;
19545 cached_wd
= remap_debug_filename (wd
);
19549 /* Generate a DW_AT_comp_dir attribute for DIE. */
19552 add_comp_dir_attribute (dw_die_ref die
)
19554 const char * wd
= comp_dir_string ();
19556 add_AT_string (die
, DW_AT_comp_dir
, wd
);
19559 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
19560 pointer computation, ...), output a representation for that bound according
19561 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
19562 loc_list_from_tree for the meaning of CONTEXT. */
19565 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
19566 int forms
, struct loc_descr_context
*context
)
19568 dw_die_ref context_die
, decl_die
;
19569 dw_loc_list_ref list
;
19570 bool strip_conversions
= true;
19571 bool placeholder_seen
= false;
19573 while (strip_conversions
)
19574 switch (TREE_CODE (value
))
19581 case VIEW_CONVERT_EXPR
:
19582 value
= TREE_OPERAND (value
, 0);
19586 strip_conversions
= false;
19590 /* If possible and permitted, output the attribute as a constant. */
19591 if ((forms
& dw_scalar_form_constant
) != 0
19592 && TREE_CODE (value
) == INTEGER_CST
)
19594 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
19596 /* If HOST_WIDE_INT is big enough then represent the bound as
19597 a constant value. We need to choose a form based on
19598 whether the type is signed or unsigned. We cannot just
19599 call add_AT_unsigned if the value itself is positive
19600 (add_AT_unsigned might add the unsigned value encoded as
19601 DW_FORM_data[1248]). Some DWARF consumers will lookup the
19602 bounds type and then sign extend any unsigned values found
19603 for signed types. This is needed only for
19604 DW_AT_{lower,upper}_bound, since for most other attributes,
19605 consumers will treat DW_FORM_data[1248] as unsigned values,
19606 regardless of the underlying type. */
19607 if (prec
<= HOST_BITS_PER_WIDE_INT
19608 || tree_fits_uhwi_p (value
))
19610 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
19611 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
19613 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
19616 /* Otherwise represent the bound as an unsigned value with
19617 the precision of its type. The precision and signedness
19618 of the type will be necessary to re-interpret it
19620 add_AT_wide (die
, attr
, value
);
19624 /* Otherwise, if it's possible and permitted too, output a reference to
19626 if ((forms
& dw_scalar_form_reference
) != 0)
19628 tree decl
= NULL_TREE
;
19630 /* Some type attributes reference an outer type. For instance, the upper
19631 bound of an array may reference an embedding record (this happens in
19633 if (TREE_CODE (value
) == COMPONENT_REF
19634 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
19635 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
19636 decl
= TREE_OPERAND (value
, 1);
19638 else if (VAR_P (value
)
19639 || TREE_CODE (value
) == PARM_DECL
19640 || TREE_CODE (value
) == RESULT_DECL
)
19643 if (decl
!= NULL_TREE
)
19645 dw_die_ref decl_die
= lookup_decl_die (decl
);
19647 /* ??? Can this happen, or should the variable have been bound
19648 first? Probably it can, since I imagine that we try to create
19649 the types of parameters in the order in which they exist in
19650 the list, and won't have created a forward reference to a
19651 later parameter. */
19652 if (decl_die
!= NULL
)
19654 add_AT_die_ref (die
, attr
, decl_die
);
19660 /* Last chance: try to create a stack operation procedure to evaluate the
19661 value. Do nothing if even that is not possible or permitted. */
19662 if ((forms
& dw_scalar_form_exprloc
) == 0)
19665 list
= loc_list_from_tree (value
, 2, context
);
19666 if (context
&& context
->placeholder_arg
)
19668 placeholder_seen
= context
->placeholder_seen
;
19669 context
->placeholder_seen
= false;
19671 if (list
== NULL
|| single_element_loc_list_p (list
))
19673 /* If this attribute is not a reference nor constant, it is
19674 a DWARF expression rather than location description. For that
19675 loc_list_from_tree (value, 0, &context) is needed. */
19676 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
19677 if (list2
&& single_element_loc_list_p (list2
))
19679 if (placeholder_seen
)
19681 struct dwarf_procedure_info dpi
;
19682 dpi
.fndecl
= NULL_TREE
;
19683 dpi
.args_count
= 1;
19684 if (!resolve_args_picking (list2
->expr
, 1, &dpi
))
19687 add_AT_loc (die
, attr
, list2
->expr
);
19692 /* If that failed to give a single element location list, fall back to
19693 outputting this as a reference... still if permitted. */
19695 || (forms
& dw_scalar_form_reference
) == 0
19696 || placeholder_seen
)
19699 if (current_function_decl
== 0)
19700 context_die
= comp_unit_die ();
19702 context_die
= lookup_decl_die (current_function_decl
);
19704 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
19705 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19706 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
19708 add_AT_location_description (decl_die
, DW_AT_location
, list
);
19709 add_AT_die_ref (die
, attr
, decl_die
);
19712 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
19716 lower_bound_default (void)
19718 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
19724 case DW_LANG_C_plus_plus
:
19725 case DW_LANG_C_plus_plus_11
:
19726 case DW_LANG_C_plus_plus_14
:
19728 case DW_LANG_ObjC_plus_plus
:
19731 case DW_LANG_Fortran77
:
19732 case DW_LANG_Fortran90
:
19733 case DW_LANG_Fortran95
:
19734 case DW_LANG_Fortran03
:
19735 case DW_LANG_Fortran08
:
19739 case DW_LANG_Python
:
19740 return dwarf_version
>= 4 ? 0 : -1;
19741 case DW_LANG_Ada95
:
19742 case DW_LANG_Ada83
:
19743 case DW_LANG_Cobol74
:
19744 case DW_LANG_Cobol85
:
19745 case DW_LANG_Pascal83
:
19746 case DW_LANG_Modula2
:
19748 return dwarf_version
>= 4 ? 1 : -1;
19754 /* Given a tree node describing an array bound (either lower or upper) output
19755 a representation for that bound. */
19758 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
19759 tree bound
, struct loc_descr_context
*context
)
19764 switch (TREE_CODE (bound
))
19766 /* Strip all conversions. */
19768 case VIEW_CONVERT_EXPR
:
19769 bound
= TREE_OPERAND (bound
, 0);
19772 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
19773 are even omitted when they are the default. */
19775 /* If the value for this bound is the default one, we can even omit the
19777 if (bound_attr
== DW_AT_lower_bound
19778 && tree_fits_shwi_p (bound
)
19779 && (dflt
= lower_bound_default ()) != -1
19780 && tree_to_shwi (bound
) == dflt
)
19786 /* Because of the complex interaction there can be with other GNAT
19787 encodings, GDB isn't ready yet to handle proper DWARF description
19788 for self-referencial subrange bounds: let GNAT encodings do the
19789 magic in such a case. */
19791 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
19792 && contains_placeholder_p (bound
))
19795 add_scalar_info (subrange_die
, bound_attr
, bound
,
19796 dw_scalar_form_constant
19797 | dw_scalar_form_exprloc
19798 | dw_scalar_form_reference
,
19804 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
19805 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
19806 Note that the block of subscript information for an array type also
19807 includes information about the element type of the given array type.
19809 This function reuses previously set type and bound information if
19813 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
19815 unsigned dimension_number
;
19817 dw_die_ref child
= type_die
->die_child
;
19819 for (dimension_number
= 0;
19820 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
19821 type
= TREE_TYPE (type
), dimension_number
++)
19823 tree domain
= TYPE_DOMAIN (type
);
19825 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
19828 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
19829 and (in GNU C only) variable bounds. Handle all three forms
19832 /* Find and reuse a previously generated DW_TAG_subrange_type if
19835 For multi-dimensional arrays, as we iterate through the
19836 various dimensions in the enclosing for loop above, we also
19837 iterate through the DIE children and pick at each
19838 DW_TAG_subrange_type previously generated (if available).
19839 Each child DW_TAG_subrange_type DIE describes the range of
19840 the current dimension. At this point we should have as many
19841 DW_TAG_subrange_type's as we have dimensions in the
19843 dw_die_ref subrange_die
= NULL
;
19847 child
= child
->die_sib
;
19848 if (child
->die_tag
== DW_TAG_subrange_type
)
19849 subrange_die
= child
;
19850 if (child
== type_die
->die_child
)
19852 /* If we wrapped around, stop looking next time. */
19856 if (child
->die_tag
== DW_TAG_subrange_type
)
19860 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
19864 /* We have an array type with specified bounds. */
19865 lower
= TYPE_MIN_VALUE (domain
);
19866 upper
= TYPE_MAX_VALUE (domain
);
19868 /* Define the index type. */
19869 if (TREE_TYPE (domain
)
19870 && !get_AT (subrange_die
, DW_AT_type
))
19872 /* ??? This is probably an Ada unnamed subrange type. Ignore the
19873 TREE_TYPE field. We can't emit debug info for this
19874 because it is an unnamed integral type. */
19875 if (TREE_CODE (domain
) == INTEGER_TYPE
19876 && TYPE_NAME (domain
) == NULL_TREE
19877 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
19878 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
19881 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
19882 TYPE_UNQUALIFIED
, false, type_die
);
19885 /* ??? If upper is NULL, the array has unspecified length,
19886 but it does have a lower bound. This happens with Fortran
19888 Since the debugger is definitely going to need to know N
19889 to produce useful results, go ahead and output the lower
19890 bound solo, and hope the debugger can cope. */
19892 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
19893 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
19894 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
19895 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
19898 /* Otherwise we have an array type with an unspecified length. The
19899 DWARF-2 spec does not say how to handle this; let's just leave out the
19904 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
19907 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
19909 dw_die_ref decl_die
;
19910 HOST_WIDE_INT size
;
19911 dw_loc_descr_ref size_expr
= NULL
;
19913 switch (TREE_CODE (tree_node
))
19918 case ENUMERAL_TYPE
:
19921 case QUAL_UNION_TYPE
:
19922 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
19923 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
19925 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
19928 size_expr
= type_byte_size (tree_node
, &size
);
19931 /* For a data member of a struct or union, the DW_AT_byte_size is
19932 generally given as the number of bytes normally allocated for an
19933 object of the *declared* type of the member itself. This is true
19934 even for bit-fields. */
19935 size
= int_size_in_bytes (field_type (tree_node
));
19938 gcc_unreachable ();
19941 /* Support for dynamically-sized objects was introduced by DWARFv3.
19942 At the moment, GDB does not handle variable byte sizes very well,
19944 if ((dwarf_version
>= 3 || !dwarf_strict
)
19945 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
19946 && size_expr
!= NULL
)
19947 add_AT_loc (die
, DW_AT_byte_size
, size_expr
);
19949 /* Note that `size' might be -1 when we get to this point. If it is, that
19950 indicates that the byte size of the entity in question is variable and
19951 that we could not generate a DWARF expression that computes it. */
19953 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
19956 /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
19960 add_alignment_attribute (dw_die_ref die
, tree tree_node
)
19962 if (dwarf_version
< 5 && dwarf_strict
)
19967 if (DECL_P (tree_node
))
19969 if (!DECL_USER_ALIGN (tree_node
))
19972 align
= DECL_ALIGN_UNIT (tree_node
);
19974 else if (TYPE_P (tree_node
))
19976 if (!TYPE_USER_ALIGN (tree_node
))
19979 align
= TYPE_ALIGN_UNIT (tree_node
);
19982 gcc_unreachable ();
19984 add_AT_unsigned (die
, DW_AT_alignment
, align
);
19987 /* For a FIELD_DECL node which represents a bit-field, output an attribute
19988 which specifies the distance in bits from the highest order bit of the
19989 "containing object" for the bit-field to the highest order bit of the
19992 For any given bit-field, the "containing object" is a hypothetical object
19993 (of some integral or enum type) within which the given bit-field lives. The
19994 type of this hypothetical "containing object" is always the same as the
19995 declared type of the individual bit-field itself. The determination of the
19996 exact location of the "containing object" for a bit-field is rather
19997 complicated. It's handled by the `field_byte_offset' function (above).
19999 CTX is required: see the comment for VLR_CONTEXT.
20001 Note that it is the size (in bytes) of the hypothetical "containing object"
20002 which will be given in the DW_AT_byte_size attribute for this bit-field.
20003 (See `byte_size_attribute' above). */
20006 add_bit_offset_attribute (dw_die_ref die
, tree decl
, struct vlr_context
*ctx
)
20008 HOST_WIDE_INT object_offset_in_bytes
;
20009 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
20010 HOST_WIDE_INT bitpos_int
;
20011 HOST_WIDE_INT highest_order_object_bit_offset
;
20012 HOST_WIDE_INT highest_order_field_bit_offset
;
20013 HOST_WIDE_INT bit_offset
;
20015 field_byte_offset (decl
, ctx
, &object_offset_in_bytes
);
20017 /* Must be a field and a bit field. */
20018 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
20020 /* We can't yet handle bit-fields whose offsets are variable, so if we
20021 encounter such things, just return without generating any attribute
20022 whatsoever. Likewise for variable or too large size. */
20023 if (! tree_fits_shwi_p (bit_position (decl
))
20024 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
20027 bitpos_int
= int_bit_position (decl
);
20029 /* Note that the bit offset is always the distance (in bits) from the
20030 highest-order bit of the "containing object" to the highest-order bit of
20031 the bit-field itself. Since the "high-order end" of any object or field
20032 is different on big-endian and little-endian machines, the computation
20033 below must take account of these differences. */
20034 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
20035 highest_order_field_bit_offset
= bitpos_int
;
20037 if (! BYTES_BIG_ENDIAN
)
20039 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
20040 highest_order_object_bit_offset
+=
20041 simple_type_size_in_bits (original_type
);
20045 = (! BYTES_BIG_ENDIAN
20046 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
20047 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
20049 if (bit_offset
< 0)
20050 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
20052 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
20055 /* For a FIELD_DECL node which represents a bit field, output an attribute
20056 which specifies the length in bits of the given field. */
20059 add_bit_size_attribute (dw_die_ref die
, tree decl
)
20061 /* Must be a field and a bit field. */
20062 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
20063 && DECL_BIT_FIELD_TYPE (decl
));
20065 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
20066 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
20069 /* If the compiled language is ANSI C, then add a 'prototyped'
20070 attribute, if arg types are given for the parameters of a function. */
20073 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
20075 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
20082 if (prototype_p (func_type
))
20083 add_AT_flag (die
, DW_AT_prototyped
, 1);
20090 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
20091 by looking in the type declaration, the object declaration equate table or
20092 the block mapping. */
20094 static inline dw_die_ref
20095 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
20097 dw_die_ref origin_die
= NULL
;
20099 if (TREE_CODE (origin
) != FUNCTION_DECL
20100 && TREE_CODE (origin
) != BLOCK
)
20102 /* We may have gotten separated from the block for the inlined
20103 function, if we're in an exception handler or some such; make
20104 sure that the abstract function has been written out.
20106 Doing this for nested functions is wrong, however; functions are
20107 distinct units, and our context might not even be inline. */
20111 fn
= TYPE_STUB_DECL (fn
);
20113 fn
= decl_function_context (fn
);
20115 dwarf2out_abstract_function (fn
);
20118 if (DECL_P (origin
))
20119 origin_die
= lookup_decl_die (origin
);
20120 else if (TYPE_P (origin
))
20121 origin_die
= lookup_type_die (origin
);
20122 else if (TREE_CODE (origin
) == BLOCK
)
20123 origin_die
= BLOCK_DIE (origin
);
20125 /* XXX: Functions that are never lowered don't always have correct block
20126 trees (in the case of java, they simply have no block tree, in some other
20127 languages). For these functions, there is nothing we can really do to
20128 output correct debug info for inlined functions in all cases. Rather
20129 than die, we'll just produce deficient debug info now, in that we will
20130 have variables without a proper abstract origin. In the future, when all
20131 functions are lowered, we should re-add a gcc_assert (origin_die)
20135 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
20139 /* We do not currently support the pure_virtual attribute. */
20142 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
20144 if (DECL_VINDEX (func_decl
))
20146 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20148 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
20149 add_AT_loc (die
, DW_AT_vtable_elem_location
,
20150 new_loc_descr (DW_OP_constu
,
20151 tree_to_shwi (DECL_VINDEX (func_decl
)),
20154 /* GNU extension: Record what type this method came from originally. */
20155 if (debug_info_level
> DINFO_LEVEL_TERSE
20156 && DECL_CONTEXT (func_decl
))
20157 add_AT_die_ref (die
, DW_AT_containing_type
,
20158 lookup_type_die (DECL_CONTEXT (func_decl
)));
20162 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
20163 given decl. This used to be a vendor extension until after DWARF 4
20164 standardized it. */
20167 add_linkage_attr (dw_die_ref die
, tree decl
)
20169 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
20171 /* Mimic what assemble_name_raw does with a leading '*'. */
20172 if (name
[0] == '*')
20175 if (dwarf_version
>= 4)
20176 add_AT_string (die
, DW_AT_linkage_name
, name
);
20178 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
20181 /* Add source coordinate attributes for the given decl. */
20184 add_src_coords_attributes (dw_die_ref die
, tree decl
)
20186 expanded_location s
;
20188 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
20190 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
20191 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
20192 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
20195 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
20198 add_linkage_name_raw (dw_die_ref die
, tree decl
)
20200 /* Defer until we have an assembler name set. */
20201 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
20203 limbo_die_node
*asm_name
;
20205 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
20206 asm_name
->die
= die
;
20207 asm_name
->created_for
= decl
;
20208 asm_name
->next
= deferred_asm_name
;
20209 deferred_asm_name
= asm_name
;
20211 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
20212 add_linkage_attr (die
, decl
);
20215 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
20218 add_linkage_name (dw_die_ref die
, tree decl
)
20220 if (debug_info_level
> DINFO_LEVEL_NONE
20221 && VAR_OR_FUNCTION_DECL_P (decl
)
20222 && TREE_PUBLIC (decl
)
20223 && !(VAR_P (decl
) && DECL_REGISTER (decl
))
20224 && die
->die_tag
!= DW_TAG_member
)
20225 add_linkage_name_raw (die
, decl
);
20228 /* Add a DW_AT_name attribute and source coordinate attribute for the
20229 given decl, but only if it actually has a name. */
20232 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
,
20233 bool no_linkage_name
)
20237 decl_name
= DECL_NAME (decl
);
20238 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
20240 const char *name
= dwarf2_name (decl
, 0);
20242 add_name_attribute (die
, name
);
20243 if (! DECL_ARTIFICIAL (decl
))
20244 add_src_coords_attributes (die
, decl
);
20246 if (!no_linkage_name
)
20247 add_linkage_name (die
, decl
);
20250 #ifdef VMS_DEBUGGING_INFO
20251 /* Get the function's name, as described by its RTL. This may be different
20252 from the DECL_NAME name used in the source file. */
20253 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
20255 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
20256 XEXP (DECL_RTL (decl
), 0), false);
20257 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
20259 #endif /* VMS_DEBUGGING_INFO */
20262 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
20265 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
20269 attr
.dw_attr
= DW_AT_discr_value
;
20270 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
20271 attr
.dw_attr_val
.val_entry
= NULL
;
20272 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
20274 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
20276 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
20277 add_dwarf_attr (die
, &attr
);
20280 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
20283 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
20287 attr
.dw_attr
= DW_AT_discr_list
;
20288 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
20289 attr
.dw_attr_val
.val_entry
= NULL
;
20290 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
20291 add_dwarf_attr (die
, &attr
);
20294 static inline dw_discr_list_ref
20295 AT_discr_list (dw_attr_node
*attr
)
20297 return attr
->dw_attr_val
.v
.val_discr_list
;
20300 #ifdef VMS_DEBUGGING_INFO
20301 /* Output the debug main pointer die for VMS */
20304 dwarf2out_vms_debug_main_pointer (void)
20306 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20309 /* Allocate the VMS debug main subprogram die. */
20310 die
= ggc_cleared_alloc
<die_node
> ();
20311 die
->die_tag
= DW_TAG_subprogram
;
20312 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
20313 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
20314 current_function_funcdef_no
);
20315 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
20317 /* Make it the first child of comp_unit_die (). */
20318 die
->die_parent
= comp_unit_die ();
20319 if (comp_unit_die ()->die_child
)
20321 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
20322 comp_unit_die ()->die_child
->die_sib
= die
;
20326 die
->die_sib
= die
;
20327 comp_unit_die ()->die_child
= die
;
20330 #endif /* VMS_DEBUGGING_INFO */
20332 /* Push a new declaration scope. */
20335 push_decl_scope (tree scope
)
20337 vec_safe_push (decl_scope_table
, scope
);
20340 /* Pop a declaration scope. */
20343 pop_decl_scope (void)
20345 decl_scope_table
->pop ();
20348 /* walk_tree helper function for uses_local_type, below. */
20351 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
20354 *walk_subtrees
= 0;
20357 tree name
= TYPE_NAME (*tp
);
20358 if (name
&& DECL_P (name
) && decl_function_context (name
))
20364 /* If TYPE involves a function-local type (including a local typedef to a
20365 non-local type), returns that type; otherwise returns NULL_TREE. */
20368 uses_local_type (tree type
)
20370 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
20374 /* Return the DIE for the scope that immediately contains this type.
20375 Non-named types that do not involve a function-local type get global
20376 scope. Named types nested in namespaces or other types get their
20377 containing scope. All other types (i.e. function-local named types) get
20378 the current active scope. */
20381 scope_die_for (tree t
, dw_die_ref context_die
)
20383 dw_die_ref scope_die
= NULL
;
20384 tree containing_scope
;
20386 /* Non-types always go in the current scope. */
20387 gcc_assert (TYPE_P (t
));
20389 /* Use the scope of the typedef, rather than the scope of the type
20391 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
20392 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
20394 containing_scope
= TYPE_CONTEXT (t
);
20396 /* Use the containing namespace if there is one. */
20397 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
20399 if (context_die
== lookup_decl_die (containing_scope
))
20401 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20402 context_die
= get_context_die (containing_scope
);
20404 containing_scope
= NULL_TREE
;
20407 /* Ignore function type "scopes" from the C frontend. They mean that
20408 a tagged type is local to a parmlist of a function declarator, but
20409 that isn't useful to DWARF. */
20410 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
20411 containing_scope
= NULL_TREE
;
20413 if (SCOPE_FILE_SCOPE_P (containing_scope
))
20415 /* If T uses a local type keep it local as well, to avoid references
20416 to function-local DIEs from outside the function. */
20417 if (current_function_decl
&& uses_local_type (t
))
20418 scope_die
= context_die
;
20420 scope_die
= comp_unit_die ();
20422 else if (TYPE_P (containing_scope
))
20424 /* For types, we can just look up the appropriate DIE. */
20425 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20426 scope_die
= get_context_die (containing_scope
);
20429 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
20430 if (scope_die
== NULL
)
20431 scope_die
= comp_unit_die ();
20435 scope_die
= context_die
;
20440 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
20443 local_scope_p (dw_die_ref context_die
)
20445 for (; context_die
; context_die
= context_die
->die_parent
)
20446 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
20447 || context_die
->die_tag
== DW_TAG_subprogram
)
20453 /* Returns nonzero if CONTEXT_DIE is a class. */
20456 class_scope_p (dw_die_ref context_die
)
20458 return (context_die
20459 && (context_die
->die_tag
== DW_TAG_structure_type
20460 || context_die
->die_tag
== DW_TAG_class_type
20461 || context_die
->die_tag
== DW_TAG_interface_type
20462 || context_die
->die_tag
== DW_TAG_union_type
));
20465 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
20466 whether or not to treat a DIE in this context as a declaration. */
20469 class_or_namespace_scope_p (dw_die_ref context_die
)
20471 return (class_scope_p (context_die
)
20472 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
20475 /* Many forms of DIEs require a "type description" attribute. This
20476 routine locates the proper "type descriptor" die for the type given
20477 by 'type' plus any additional qualifiers given by 'cv_quals', and
20478 adds a DW_AT_type attribute below the given die. */
20481 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
20482 bool reverse
, dw_die_ref context_die
)
20484 enum tree_code code
= TREE_CODE (type
);
20485 dw_die_ref type_die
= NULL
;
20487 /* ??? If this type is an unnamed subrange type of an integral, floating-point
20488 or fixed-point type, use the inner type. This is because we have no
20489 support for unnamed types in base_type_die. This can happen if this is
20490 an Ada subrange type. Correct solution is emit a subrange type die. */
20491 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
20492 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
20493 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
20495 if (code
== ERROR_MARK
20496 /* Handle a special case. For functions whose return type is void, we
20497 generate *no* type attribute. (Note that no object may have type
20498 `void', so this only applies to function return types). */
20499 || code
== VOID_TYPE
)
20502 type_die
= modified_type_die (type
,
20503 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
20507 if (type_die
!= NULL
)
20508 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
20511 /* Given an object die, add the calling convention attribute for the
20512 function call type. */
20514 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
20516 enum dwarf_calling_convention value
= DW_CC_normal
;
20518 value
= ((enum dwarf_calling_convention
)
20519 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
20522 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
20524 /* DWARF 2 doesn't provide a way to identify a program's source-level
20525 entry point. DW_AT_calling_convention attributes are only meant
20526 to describe functions' calling conventions. However, lacking a
20527 better way to signal the Fortran main program, we used this for
20528 a long time, following existing custom. Now, DWARF 4 has
20529 DW_AT_main_subprogram, which we add below, but some tools still
20530 rely on the old way, which we thus keep. */
20531 value
= DW_CC_program
;
20533 if (dwarf_version
>= 4 || !dwarf_strict
)
20534 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
20537 /* Only add the attribute if the backend requests it, and
20538 is not DW_CC_normal. */
20539 if (value
&& (value
!= DW_CC_normal
))
20540 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
20543 /* Given a tree pointer to a struct, class, union, or enum type node, return
20544 a pointer to the (string) tag name for the given type, or zero if the type
20545 was declared without a tag. */
20547 static const char *
20548 type_tag (const_tree type
)
20550 const char *name
= 0;
20552 if (TYPE_NAME (type
) != 0)
20556 /* Find the IDENTIFIER_NODE for the type name. */
20557 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
20558 && !TYPE_NAMELESS (type
))
20559 t
= TYPE_NAME (type
);
20561 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
20562 a TYPE_DECL node, regardless of whether or not a `typedef' was
20564 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20565 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
20567 /* We want to be extra verbose. Don't call dwarf_name if
20568 DECL_NAME isn't set. The default hook for decl_printable_name
20569 doesn't like that, and in this context it's correct to return
20570 0, instead of "<anonymous>" or the like. */
20571 if (DECL_NAME (TYPE_NAME (type
))
20572 && !DECL_NAMELESS (TYPE_NAME (type
)))
20573 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
20576 /* Now get the name as a string, or invent one. */
20577 if (!name
&& t
!= 0)
20578 name
= IDENTIFIER_POINTER (t
);
20581 return (name
== 0 || *name
== '\0') ? 0 : name
;
20584 /* Return the type associated with a data member, make a special check
20585 for bit field types. */
20588 member_declared_type (const_tree member
)
20590 return (DECL_BIT_FIELD_TYPE (member
)
20591 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
20594 /* Get the decl's label, as described by its RTL. This may be different
20595 from the DECL_NAME name used in the source file. */
20598 static const char *
20599 decl_start_label (tree decl
)
20602 const char *fnname
;
20604 x
= DECL_RTL (decl
);
20605 gcc_assert (MEM_P (x
));
20608 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
20610 fnname
= XSTR (x
, 0);
20615 /* For variable-length arrays that have been previously generated, but
20616 may be incomplete due to missing subscript info, fill the subscript
20617 info. Return TRUE if this is one of those cases. */
20619 fill_variable_array_bounds (tree type
)
20621 if (TREE_ASM_WRITTEN (type
)
20622 && TREE_CODE (type
) == ARRAY_TYPE
20623 && variably_modified_type_p (type
, NULL
))
20625 dw_die_ref array_die
= lookup_type_die (type
);
20628 add_subscript_info (array_die
, type
, !is_ada ());
20634 /* These routines generate the internal representation of the DIE's for
20635 the compilation unit. Debugging information is collected by walking
20636 the declaration trees passed in from dwarf2out_decl(). */
20639 gen_array_type_die (tree type
, dw_die_ref context_die
)
20641 dw_die_ref array_die
;
20643 /* GNU compilers represent multidimensional array types as sequences of one
20644 dimensional array types whose element types are themselves array types.
20645 We sometimes squish that down to a single array_type DIE with multiple
20646 subscripts in the Dwarf debugging info. The draft Dwarf specification
20647 say that we are allowed to do this kind of compression in C, because
20648 there is no difference between an array of arrays and a multidimensional
20649 array. We don't do this for Ada to remain as close as possible to the
20650 actual representation, which is especially important against the language
20651 flexibilty wrt arrays of variable size. */
20653 bool collapse_nested_arrays
= !is_ada ();
20655 if (fill_variable_array_bounds (type
))
20658 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
20661 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
20662 DW_TAG_string_type doesn't have DW_AT_type attribute). */
20663 if (TYPE_STRING_FLAG (type
)
20664 && TREE_CODE (type
) == ARRAY_TYPE
20666 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
20668 HOST_WIDE_INT size
;
20670 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
20671 add_name_attribute (array_die
, type_tag (type
));
20672 equate_type_number_to_die (type
, array_die
);
20673 size
= int_size_in_bytes (type
);
20675 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
20676 else if (TYPE_DOMAIN (type
) != NULL_TREE
20677 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
20679 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
20680 tree rszdecl
= szdecl
;
20681 HOST_WIDE_INT rsize
= 0;
20683 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
20684 if (!DECL_P (szdecl
))
20686 if (TREE_CODE (szdecl
) == INDIRECT_REF
20687 && DECL_P (TREE_OPERAND (szdecl
, 0)))
20689 rszdecl
= TREE_OPERAND (szdecl
, 0);
20690 rsize
= int_size_in_bytes (TREE_TYPE (rszdecl
));
20699 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2, NULL
);
20702 && current_function_decl
20703 && DECL_CONTEXT (rszdecl
) == current_function_decl
)
20705 dw_die_ref ref
= lookup_decl_die (rszdecl
);
20706 dw_loc_descr_ref l
= NULL
;
20709 l
= new_loc_descr (DW_OP_call4
, 0, 0);
20710 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
20711 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
20712 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
20714 else if (TREE_CODE (rszdecl
) == PARM_DECL
20717 l
= new_loc_descr (DW_OP_call4
, 0, 0);
20718 l
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
20719 l
->dw_loc_oprnd1
.v
.val_decl_ref
= rszdecl
;
20720 string_types
->safe_push (array_die
);
20722 if (l
&& rszdecl
!= szdecl
)
20724 if (rsize
== DWARF2_ADDR_SIZE
)
20725 add_loc_descr (&l
, new_loc_descr (DW_OP_deref
,
20728 add_loc_descr (&l
, new_loc_descr (DW_OP_deref_size
,
20732 loc
= new_loc_list (l
, NULL
, NULL
, NULL
);
20736 add_AT_location_description (array_die
, DW_AT_string_length
,
20738 if (size
!= DWARF2_ADDR_SIZE
)
20739 add_AT_unsigned (array_die
, dwarf_version
>= 5
20740 ? DW_AT_string_length_byte_size
20741 : DW_AT_byte_size
, size
);
20748 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
20749 add_name_attribute (array_die
, type_tag (type
));
20750 equate_type_number_to_die (type
, array_die
);
20752 if (TREE_CODE (type
) == VECTOR_TYPE
)
20753 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
20755 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
20757 && TREE_CODE (type
) == ARRAY_TYPE
20758 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
20759 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
20760 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
20763 /* We default the array ordering. SDB will probably do
20764 the right things even if DW_AT_ordering is not present. It's not even
20765 an issue until we start to get into multidimensional arrays anyway. If
20766 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
20767 then we'll have to put the DW_AT_ordering attribute back in. (But if
20768 and when we find out that we need to put these in, we will only do so
20769 for multidimensional arrays. */
20770 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
20773 if (TREE_CODE (type
) == VECTOR_TYPE
)
20775 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
20776 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
20777 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
20778 add_bound_info (subrange_die
, DW_AT_upper_bound
,
20779 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
20782 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
20784 /* Add representation of the type of the elements of this array type and
20785 emit the corresponding DIE if we haven't done it already. */
20786 element_type
= TREE_TYPE (type
);
20787 if (collapse_nested_arrays
)
20788 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
20790 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
20792 element_type
= TREE_TYPE (element_type
);
20795 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
20796 TREE_CODE (type
) == ARRAY_TYPE
20797 && TYPE_REVERSE_STORAGE_ORDER (type
),
20800 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
20801 if (TYPE_ARTIFICIAL (type
))
20802 add_AT_flag (array_die
, DW_AT_artificial
, 1);
20804 if (get_AT (array_die
, DW_AT_name
))
20805 add_pubtype (type
, array_die
);
20807 add_alignment_attribute (array_die
, type
);
20810 /* After all arguments are created, adjust any DW_TAG_string_type
20811 DIEs DW_AT_string_length attributes. */
20814 adjust_string_types (void)
20816 dw_die_ref array_die
;
20818 FOR_EACH_VEC_ELT (*string_types
, i
, array_die
)
20820 dw_attr_node
*a
= get_AT (array_die
, DW_AT_string_length
);
20823 dw_loc_descr_ref loc
= AT_loc (a
);
20824 gcc_assert (loc
->dw_loc_opc
== DW_OP_call4
20825 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
);
20826 dw_die_ref ref
= lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
20829 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
20830 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
20831 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
20835 remove_AT (array_die
, DW_AT_string_length
);
20836 remove_AT (array_die
, dwarf_version
>= 5
20837 ? DW_AT_string_length_byte_size
20838 : DW_AT_byte_size
);
20843 /* This routine generates DIE for array with hidden descriptor, details
20844 are filled into *info by a langhook. */
20847 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
20848 dw_die_ref context_die
)
20850 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
20851 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
20852 struct loc_descr_context context
= { type
, info
->base_decl
, NULL
,
20854 enum dwarf_tag subrange_tag
= DW_TAG_subrange_type
;
20857 add_name_attribute (array_die
, type_tag (type
));
20858 equate_type_number_to_die (type
, array_die
);
20860 if (info
->ndimensions
> 1)
20861 switch (info
->ordering
)
20863 case array_descr_ordering_row_major
:
20864 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
20866 case array_descr_ordering_column_major
:
20867 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
20873 if (dwarf_version
>= 3 || !dwarf_strict
)
20875 if (info
->data_location
)
20876 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
20877 dw_scalar_form_exprloc
, &context
);
20878 if (info
->associated
)
20879 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
20880 dw_scalar_form_constant
20881 | dw_scalar_form_exprloc
20882 | dw_scalar_form_reference
, &context
);
20883 if (info
->allocated
)
20884 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
20885 dw_scalar_form_constant
20886 | dw_scalar_form_exprloc
20887 | dw_scalar_form_reference
, &context
);
20890 const enum dwarf_attribute attr
20891 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
20893 = (info
->stride_in_bits
)
20894 ? dw_scalar_form_constant
20895 : (dw_scalar_form_constant
20896 | dw_scalar_form_exprloc
20897 | dw_scalar_form_reference
);
20899 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
20902 if (dwarf_version
>= 5)
20906 add_scalar_info (array_die
, DW_AT_rank
, info
->rank
,
20907 dw_scalar_form_constant
20908 | dw_scalar_form_exprloc
, &context
);
20909 subrange_tag
= DW_TAG_generic_subrange
;
20910 context
.placeholder_arg
= true;
20914 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
20916 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
20918 dw_die_ref subrange_die
= new_die (subrange_tag
, array_die
, NULL
);
20920 if (info
->dimen
[dim
].bounds_type
)
20921 add_type_attribute (subrange_die
,
20922 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
20923 false, context_die
);
20924 if (info
->dimen
[dim
].lower_bound
)
20925 add_bound_info (subrange_die
, DW_AT_lower_bound
,
20926 info
->dimen
[dim
].lower_bound
, &context
);
20927 if (info
->dimen
[dim
].upper_bound
)
20928 add_bound_info (subrange_die
, DW_AT_upper_bound
,
20929 info
->dimen
[dim
].upper_bound
, &context
);
20930 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
20931 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
20932 info
->dimen
[dim
].stride
,
20933 dw_scalar_form_constant
20934 | dw_scalar_form_exprloc
20935 | dw_scalar_form_reference
,
20939 gen_type_die (info
->element_type
, context_die
);
20940 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
20941 TREE_CODE (type
) == ARRAY_TYPE
20942 && TYPE_REVERSE_STORAGE_ORDER (type
),
20945 if (get_AT (array_die
, DW_AT_name
))
20946 add_pubtype (type
, array_die
);
20948 add_alignment_attribute (array_die
, type
);
20953 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
20955 tree origin
= decl_ultimate_origin (decl
);
20956 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
20958 if (origin
!= NULL
)
20959 add_abstract_origin_attribute (decl_die
, origin
);
20962 add_name_and_src_coords_attributes (decl_die
, decl
);
20963 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
20964 TYPE_UNQUALIFIED
, false, context_die
);
20967 if (DECL_ABSTRACT_P (decl
))
20968 equate_decl_number_to_die (decl
, decl_die
);
20970 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
20974 /* Walk through the list of incomplete types again, trying once more to
20975 emit full debugging info for them. */
20978 retry_incomplete_types (void)
20983 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
20984 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
20985 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
20986 vec_safe_truncate (incomplete_types
, 0);
20989 /* Determine what tag to use for a record type. */
20991 static enum dwarf_tag
20992 record_type_tag (tree type
)
20994 if (! lang_hooks
.types
.classify_record
)
20995 return DW_TAG_structure_type
;
20997 switch (lang_hooks
.types
.classify_record (type
))
20999 case RECORD_IS_STRUCT
:
21000 return DW_TAG_structure_type
;
21002 case RECORD_IS_CLASS
:
21003 return DW_TAG_class_type
;
21005 case RECORD_IS_INTERFACE
:
21006 if (dwarf_version
>= 3 || !dwarf_strict
)
21007 return DW_TAG_interface_type
;
21008 return DW_TAG_structure_type
;
21011 gcc_unreachable ();
21015 /* Generate a DIE to represent an enumeration type. Note that these DIEs
21016 include all of the information about the enumeration values also. Each
21017 enumerated type name/value is listed as a child of the enumerated type
21021 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
21023 dw_die_ref type_die
= lookup_type_die (type
);
21025 if (type_die
== NULL
)
21027 type_die
= new_die (DW_TAG_enumeration_type
,
21028 scope_die_for (type
, context_die
), type
);
21029 equate_type_number_to_die (type
, type_die
);
21030 add_name_attribute (type_die
, type_tag (type
));
21031 if (dwarf_version
>= 4 || !dwarf_strict
)
21033 if (ENUM_IS_SCOPED (type
))
21034 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
21035 if (ENUM_IS_OPAQUE (type
))
21036 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21039 add_AT_unsigned (type_die
, DW_AT_encoding
,
21040 TYPE_UNSIGNED (type
)
21044 else if (! TYPE_SIZE (type
))
21047 remove_AT (type_die
, DW_AT_declaration
);
21049 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
21050 given enum type is incomplete, do not generate the DW_AT_byte_size
21051 attribute or the DW_AT_element_list attribute. */
21052 if (TYPE_SIZE (type
))
21056 TREE_ASM_WRITTEN (type
) = 1;
21057 add_byte_size_attribute (type_die
, type
);
21058 add_alignment_attribute (type_die
, type
);
21059 if (dwarf_version
>= 3 || !dwarf_strict
)
21061 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
21062 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
21065 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
21067 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
21068 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
21071 /* If the first reference to this type was as the return type of an
21072 inline function, then it may not have a parent. Fix this now. */
21073 if (type_die
->die_parent
== NULL
)
21074 add_child_die (scope_die_for (type
, context_die
), type_die
);
21076 for (link
= TYPE_VALUES (type
);
21077 link
!= NULL
; link
= TREE_CHAIN (link
))
21079 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
21080 tree value
= TREE_VALUE (link
);
21082 add_name_attribute (enum_die
,
21083 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
21085 if (TREE_CODE (value
) == CONST_DECL
)
21086 value
= DECL_INITIAL (value
);
21088 if (simple_type_size_in_bits (TREE_TYPE (value
))
21089 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
21091 /* For constant forms created by add_AT_unsigned DWARF
21092 consumers (GDB, elfutils, etc.) always zero extend
21093 the value. Only when the actual value is negative
21094 do we need to use add_AT_int to generate a constant
21095 form that can represent negative values. */
21096 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
21097 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
21098 add_AT_unsigned (enum_die
, DW_AT_const_value
,
21099 (unsigned HOST_WIDE_INT
) val
);
21101 add_AT_int (enum_die
, DW_AT_const_value
, val
);
21104 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
21105 that here. TODO: This should be re-worked to use correct
21106 signed/unsigned double tags for all cases. */
21107 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
21110 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
21111 if (TYPE_ARTIFICIAL (type
))
21112 add_AT_flag (type_die
, DW_AT_artificial
, 1);
21115 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21117 add_alignment_attribute (type_die
, type
);
21119 add_pubtype (type
, type_die
);
21124 /* Generate a DIE to represent either a real live formal parameter decl or to
21125 represent just the type of some formal parameter position in some function
21128 Note that this routine is a bit unusual because its argument may be a
21129 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
21130 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
21131 node. If it's the former then this function is being called to output a
21132 DIE to represent a formal parameter object (or some inlining thereof). If
21133 it's the latter, then this function is only being called to output a
21134 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
21135 argument type of some subprogram type.
21136 If EMIT_NAME_P is true, name and source coordinate attributes
21140 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
21141 dw_die_ref context_die
)
21143 tree node_or_origin
= node
? node
: origin
;
21144 tree ultimate_origin
;
21145 dw_die_ref parm_die
= NULL
;
21147 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
21149 parm_die
= lookup_decl_die (node
);
21151 /* If the contexts differ, we may not be talking about the same
21153 if (parm_die
&& parm_die
->die_parent
!= context_die
)
21155 if (!DECL_ABSTRACT_P (node
))
21157 /* This can happen when creating an inlined instance, in
21158 which case we need to create a new DIE that will get
21159 annotated with DW_AT_abstract_origin. */
21164 /* FIXME: Reuse DIE even with a differing context.
21166 This can happen when calling
21167 dwarf2out_abstract_function to build debug info for
21168 the abstract instance of a function for which we have
21169 already generated a DIE in
21170 dwarf2out_early_global_decl.
21172 Once we remove dwarf2out_abstract_function, we should
21173 have a call to gcc_unreachable here. */
21177 if (parm_die
&& parm_die
->die_parent
== NULL
)
21179 /* Check that parm_die already has the right attributes that
21180 we would have added below. If any attributes are
21181 missing, fall through to add them. */
21182 if (! DECL_ABSTRACT_P (node_or_origin
)
21183 && !get_AT (parm_die
, DW_AT_location
)
21184 && !get_AT (parm_die
, DW_AT_const_value
))
21185 /* We are missing location info, and are about to add it. */
21189 add_child_die (context_die
, parm_die
);
21195 /* If we have a previously generated DIE, use it, unless this is an
21196 concrete instance (origin != NULL), in which case we need a new
21197 DIE with a corresponding DW_AT_abstract_origin. */
21199 if (parm_die
&& origin
== NULL
)
21200 reusing_die
= true;
21203 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
21204 reusing_die
= false;
21207 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
21209 case tcc_declaration
:
21210 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
21211 if (node
|| ultimate_origin
)
21212 origin
= ultimate_origin
;
21217 if (origin
!= NULL
)
21218 add_abstract_origin_attribute (parm_die
, origin
);
21219 else if (emit_name_p
)
21220 add_name_and_src_coords_attributes (parm_die
, node
);
21222 || (! DECL_ABSTRACT_P (node_or_origin
)
21223 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
21224 decl_function_context
21225 (node_or_origin
))))
21227 tree type
= TREE_TYPE (node_or_origin
);
21228 if (decl_by_reference_p (node_or_origin
))
21229 add_type_attribute (parm_die
, TREE_TYPE (type
),
21231 false, context_die
);
21233 add_type_attribute (parm_die
, type
,
21234 decl_quals (node_or_origin
),
21235 false, context_die
);
21237 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
21238 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21240 if (node
&& node
!= origin
)
21241 equate_decl_number_to_die (node
, parm_die
);
21242 if (! DECL_ABSTRACT_P (node_or_origin
))
21243 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
21249 /* We were called with some kind of a ..._TYPE node. */
21250 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
21255 gcc_unreachable ();
21261 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
21262 children DW_TAG_formal_parameter DIEs representing the arguments of the
21265 PARM_PACK must be a function parameter pack.
21266 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
21267 must point to the subsequent arguments of the function PACK_ARG belongs to.
21268 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
21269 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
21270 following the last one for which a DIE was generated. */
21273 gen_formal_parameter_pack_die (tree parm_pack
,
21275 dw_die_ref subr_die
,
21279 dw_die_ref parm_pack_die
;
21281 gcc_assert (parm_pack
21282 && lang_hooks
.function_parameter_pack_p (parm_pack
)
21285 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
21286 add_src_coords_attributes (parm_pack_die
, parm_pack
);
21288 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
21290 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
21293 gen_formal_parameter_die (arg
, NULL
,
21294 false /* Don't emit name attribute. */,
21299 return parm_pack_die
;
21302 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
21303 at the end of an (ANSI prototyped) formal parameters list. */
21306 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
21308 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
21311 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
21312 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
21313 parameters as specified in some function type specification (except for
21314 those which appear as part of a function *definition*). */
21317 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
21320 tree formal_type
= NULL
;
21321 tree first_parm_type
;
21324 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
21326 arg
= DECL_ARGUMENTS (function_or_method_type
);
21327 function_or_method_type
= TREE_TYPE (function_or_method_type
);
21332 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
21334 /* Make our first pass over the list of formal parameter types and output a
21335 DW_TAG_formal_parameter DIE for each one. */
21336 for (link
= first_parm_type
; link
; )
21338 dw_die_ref parm_die
;
21340 formal_type
= TREE_VALUE (link
);
21341 if (formal_type
== void_type_node
)
21344 /* Output a (nameless) DIE to represent the formal parameter itself. */
21345 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
21347 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
21348 true /* Emit name attribute. */,
21350 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
21351 && link
== first_parm_type
)
21353 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21354 if (dwarf_version
>= 3 || !dwarf_strict
)
21355 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
21357 else if (arg
&& DECL_ARTIFICIAL (arg
))
21358 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21361 link
= TREE_CHAIN (link
);
21363 arg
= DECL_CHAIN (arg
);
21366 /* If this function type has an ellipsis, add a
21367 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
21368 if (formal_type
!= void_type_node
)
21369 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
21371 /* Make our second (and final) pass over the list of formal parameter types
21372 and output DIEs to represent those types (as necessary). */
21373 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
21374 link
&& TREE_VALUE (link
);
21375 link
= TREE_CHAIN (link
))
21376 gen_type_die (TREE_VALUE (link
), context_die
);
21379 /* We want to generate the DIE for TYPE so that we can generate the
21380 die for MEMBER, which has been defined; we will need to refer back
21381 to the member declaration nested within TYPE. If we're trying to
21382 generate minimal debug info for TYPE, processing TYPE won't do the
21383 trick; we need to attach the member declaration by hand. */
21386 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
21388 gen_type_die (type
, context_die
);
21390 /* If we're trying to avoid duplicate debug info, we may not have
21391 emitted the member decl for this function. Emit it now. */
21392 if (TYPE_STUB_DECL (type
)
21393 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
21394 && ! lookup_decl_die (member
))
21396 dw_die_ref type_die
;
21397 gcc_assert (!decl_ultimate_origin (member
));
21399 push_decl_scope (type
);
21400 type_die
= lookup_type_die_strip_naming_typedef (type
);
21401 if (TREE_CODE (member
) == FUNCTION_DECL
)
21402 gen_subprogram_die (member
, type_die
);
21403 else if (TREE_CODE (member
) == FIELD_DECL
)
21405 /* Ignore the nameless fields that are used to skip bits but handle
21406 C++ anonymous unions and structs. */
21407 if (DECL_NAME (member
) != NULL_TREE
21408 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
21409 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
21411 struct vlr_context vlr_ctx
= {
21412 DECL_CONTEXT (member
), /* struct_type */
21413 NULL_TREE
/* variant_part_offset */
21415 gen_type_die (member_declared_type (member
), type_die
);
21416 gen_field_die (member
, &vlr_ctx
, type_die
);
21420 gen_variable_die (member
, NULL_TREE
, type_die
);
21426 /* Forward declare these functions, because they are mutually recursive
21427 with their set_block_* pairing functions. */
21428 static void set_decl_origin_self (tree
);
21429 static void set_decl_abstract_flags (tree
, vec
<tree
> &);
21431 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
21432 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
21433 that it points to the node itself, thus indicating that the node is its
21434 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
21435 the given node is NULL, recursively descend the decl/block tree which
21436 it is the root of, and for each other ..._DECL or BLOCK node contained
21437 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
21438 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
21439 values to point to themselves. */
21442 set_block_origin_self (tree stmt
)
21444 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
21446 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
21451 for (local_decl
= BLOCK_VARS (stmt
);
21452 local_decl
!= NULL_TREE
;
21453 local_decl
= DECL_CHAIN (local_decl
))
21454 /* Do not recurse on nested functions since the inlining status
21455 of parent and child can be different as per the DWARF spec. */
21456 if (TREE_CODE (local_decl
) != FUNCTION_DECL
21457 && !DECL_EXTERNAL (local_decl
))
21458 set_decl_origin_self (local_decl
);
21464 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
21465 subblock
!= NULL_TREE
;
21466 subblock
= BLOCK_CHAIN (subblock
))
21467 set_block_origin_self (subblock
); /* Recurse. */
21472 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
21473 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
21474 node to so that it points to the node itself, thus indicating that the
21475 node represents its own (abstract) origin. Additionally, if the
21476 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
21477 the decl/block tree of which the given node is the root of, and for
21478 each other ..._DECL or BLOCK node contained therein whose
21479 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
21480 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
21481 point to themselves. */
21484 set_decl_origin_self (tree decl
)
21486 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
21488 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
21489 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21493 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
21494 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
21495 if (DECL_INITIAL (decl
) != NULL_TREE
21496 && DECL_INITIAL (decl
) != error_mark_node
)
21497 set_block_origin_self (DECL_INITIAL (decl
));
21502 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
21503 and if it wasn't 1 before, push it to abstract_vec vector.
21504 For all local decls and all local sub-blocks (recursively) do it
21508 set_block_abstract_flags (tree stmt
, vec
<tree
> &abstract_vec
)
21514 if (!BLOCK_ABSTRACT (stmt
))
21516 abstract_vec
.safe_push (stmt
);
21517 BLOCK_ABSTRACT (stmt
) = 1;
21520 for (local_decl
= BLOCK_VARS (stmt
);
21521 local_decl
!= NULL_TREE
;
21522 local_decl
= DECL_CHAIN (local_decl
))
21523 if (! DECL_EXTERNAL (local_decl
))
21524 set_decl_abstract_flags (local_decl
, abstract_vec
);
21526 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
21528 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
21529 if ((VAR_P (local_decl
) && !TREE_STATIC (local_decl
))
21530 || TREE_CODE (local_decl
) == PARM_DECL
)
21531 set_decl_abstract_flags (local_decl
, abstract_vec
);
21534 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
21535 subblock
!= NULL_TREE
;
21536 subblock
= BLOCK_CHAIN (subblock
))
21537 set_block_abstract_flags (subblock
, abstract_vec
);
21540 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
21541 to 1 and if it wasn't 1 before, push to abstract_vec vector.
21542 In the case where the decl is a FUNCTION_DECL also set the abstract
21543 flags for all of the parameters, local vars, local
21544 blocks and sub-blocks (recursively). */
21547 set_decl_abstract_flags (tree decl
, vec
<tree
> &abstract_vec
)
21549 if (!DECL_ABSTRACT_P (decl
))
21551 abstract_vec
.safe_push (decl
);
21552 DECL_ABSTRACT_P (decl
) = 1;
21555 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21559 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
21560 if (!DECL_ABSTRACT_P (arg
))
21562 abstract_vec
.safe_push (arg
);
21563 DECL_ABSTRACT_P (arg
) = 1;
21565 if (DECL_INITIAL (decl
) != NULL_TREE
21566 && DECL_INITIAL (decl
) != error_mark_node
)
21567 set_block_abstract_flags (DECL_INITIAL (decl
), abstract_vec
);
21571 /* Generate the DWARF2 info for the "abstract" instance of a function which we
21572 may later generate inlined and/or out-of-line instances of.
21574 FIXME: In the early-dwarf world, this function, and most of the
21575 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
21576 the abstract instance. All we would need to do is annotate
21577 the early DIE with the appropriate DW_AT_inline in late
21578 dwarf (perhaps in gen_inlined_subroutine_die).
21580 However, we can't do this yet, because LTO streaming of DIEs
21581 has not been implemented yet. */
21584 dwarf2out_abstract_function (tree decl
)
21586 dw_die_ref old_die
;
21589 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
21590 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
21591 int old_call_site_count
, old_tail_call_site_count
;
21592 struct call_arg_loc_node
*old_call_arg_locations
;
21594 /* Make sure we have the actual abstract inline, not a clone. */
21595 decl
= DECL_ORIGIN (decl
);
21597 old_die
= lookup_decl_die (decl
);
21598 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
21599 /* We've already generated the abstract instance. */
21602 /* We can be called while recursively when seeing block defining inlined subroutine
21603 DIE. Be sure to not clobber the outer location table nor use it or we would
21604 get locations in abstract instantces. */
21605 old_decl_loc_table
= decl_loc_table
;
21606 decl_loc_table
= NULL
;
21607 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
21608 cached_dw_loc_list_table
= NULL
;
21609 old_call_arg_locations
= call_arg_locations
;
21610 call_arg_locations
= NULL
;
21611 old_call_site_count
= call_site_count
;
21612 call_site_count
= -1;
21613 old_tail_call_site_count
= tail_call_site_count
;
21614 tail_call_site_count
= -1;
21616 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
21617 we don't get confused by DECL_ABSTRACT_P. */
21618 if (debug_info_level
> DINFO_LEVEL_TERSE
)
21620 context
= decl_class_context (decl
);
21622 gen_type_die_for_member
21623 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
21626 /* Pretend we've just finished compiling this function. */
21627 save_fn
= current_function_decl
;
21628 current_function_decl
= decl
;
21630 auto_vec
<tree
, 64> abstract_vec
;
21631 set_decl_abstract_flags (decl
, abstract_vec
);
21632 dwarf2out_decl (decl
);
21635 FOR_EACH_VEC_ELT (abstract_vec
, i
, t
)
21636 if (TREE_CODE (t
) == BLOCK
)
21637 BLOCK_ABSTRACT (t
) = 0;
21639 DECL_ABSTRACT_P (t
) = 0;
21641 current_function_decl
= save_fn
;
21642 decl_loc_table
= old_decl_loc_table
;
21643 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
21644 call_arg_locations
= old_call_arg_locations
;
21645 call_site_count
= old_call_site_count
;
21646 tail_call_site_count
= old_tail_call_site_count
;
21649 /* Helper function of premark_used_types() which gets called through
21652 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21653 marked as unused by prune_unused_types. */
21656 premark_used_types_helper (tree
const &type
, void *)
21660 die
= lookup_type_die (type
);
21662 die
->die_perennial_p
= 1;
21666 /* Helper function of premark_types_used_by_global_vars which gets called
21667 through htab_traverse.
21669 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21670 marked as unused by prune_unused_types. The DIE of the type is marked
21671 only if the global variable using the type will actually be emitted. */
21674 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
21677 struct types_used_by_vars_entry
*entry
;
21680 entry
= (struct types_used_by_vars_entry
*) *slot
;
21681 gcc_assert (entry
->type
!= NULL
21682 && entry
->var_decl
!= NULL
);
21683 die
= lookup_type_die (entry
->type
);
21686 /* Ask cgraph if the global variable really is to be emitted.
21687 If yes, then we'll keep the DIE of ENTRY->TYPE. */
21688 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
21689 if (node
&& node
->definition
)
21691 die
->die_perennial_p
= 1;
21692 /* Keep the parent DIEs as well. */
21693 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
21694 die
->die_perennial_p
= 1;
21700 /* Mark all members of used_types_hash as perennial. */
21703 premark_used_types (struct function
*fun
)
21705 if (fun
&& fun
->used_types_hash
)
21706 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
21709 /* Mark all members of types_used_by_vars_entry as perennial. */
21712 premark_types_used_by_global_vars (void)
21714 if (types_used_by_vars_hash
)
21715 types_used_by_vars_hash
21716 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
21719 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
21720 for CA_LOC call arg loc node. */
21723 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
21724 struct call_arg_loc_node
*ca_loc
)
21726 dw_die_ref stmt_die
= NULL
, die
;
21727 tree block
= ca_loc
->block
;
21730 && block
!= DECL_INITIAL (decl
)
21731 && TREE_CODE (block
) == BLOCK
)
21733 stmt_die
= BLOCK_DIE (block
);
21736 block
= BLOCK_SUPERCONTEXT (block
);
21738 if (stmt_die
== NULL
)
21739 stmt_die
= subr_die
;
21740 die
= new_die (dwarf_TAG (DW_TAG_call_site
), stmt_die
, NULL_TREE
);
21741 add_AT_lbl_id (die
, dwarf_AT (DW_AT_call_return_pc
), ca_loc
->label
);
21742 if (ca_loc
->tail_call_p
)
21743 add_AT_flag (die
, dwarf_AT (DW_AT_call_tail_call
), 1);
21744 if (ca_loc
->symbol_ref
)
21746 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
21748 add_AT_die_ref (die
, dwarf_AT (DW_AT_call_origin
), tdie
);
21750 add_AT_addr (die
, dwarf_AT (DW_AT_call_origin
), ca_loc
->symbol_ref
,
21756 /* Generate a DIE to represent a declared function (either file-scope or
21760 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
21762 tree origin
= decl_ultimate_origin (decl
);
21763 dw_die_ref subr_die
;
21764 dw_die_ref old_die
= lookup_decl_die (decl
);
21766 /* This function gets called multiple times for different stages of
21767 the debug process. For example, for func() in this code:
21771 void func() { ... }
21774 ...we get called 4 times. Twice in early debug and twice in
21780 1. Once while generating func() within the namespace. This is
21781 the declaration. The declaration bit below is set, as the
21782 context is the namespace.
21784 A new DIE will be generated with DW_AT_declaration set.
21786 2. Once for func() itself. This is the specification. The
21787 declaration bit below is clear as the context is the CU.
21789 We will use the cached DIE from (1) to create a new DIE with
21790 DW_AT_specification pointing to the declaration in (1).
21792 Late debug via rest_of_handle_final()
21793 -------------------------------------
21795 3. Once generating func() within the namespace. This is also the
21796 declaration, as in (1), but this time we will early exit below
21797 as we have a cached DIE and a declaration needs no additional
21798 annotations (no locations), as the source declaration line
21801 4. Once for func() itself. As in (2), this is the specification,
21802 but this time we will re-use the cached DIE, and just annotate
21803 it with the location information that should now be available.
21805 For something without namespaces, but with abstract instances, we
21806 are also called a multiple times:
21811 Base (); // constructor declaration (1)
21814 Base::Base () { } // constructor specification (2)
21819 1. Once for the Base() constructor by virtue of it being a
21820 member of the Base class. This is done via
21821 rest_of_type_compilation.
21823 This is a declaration, so a new DIE will be created with
21826 2. Once for the Base() constructor definition, but this time
21827 while generating the abstract instance of the base
21828 constructor (__base_ctor) which is being generated via early
21829 debug of reachable functions.
21831 Even though we have a cached version of the declaration (1),
21832 we will create a DW_AT_specification of the declaration DIE
21835 3. Once for the __base_ctor itself, but this time, we generate
21836 an DW_AT_abstract_origin version of the DW_AT_specification in
21839 Late debug via rest_of_handle_final
21840 -----------------------------------
21842 4. One final time for the __base_ctor (which will have a cached
21843 DIE with DW_AT_abstract_origin created in (3). This time,
21844 we will just annotate the location information now
21847 int declaration
= (current_function_decl
!= decl
21848 || class_or_namespace_scope_p (context_die
));
21850 /* Now that the C++ front end lazily declares artificial member fns, we
21851 might need to retrofit the declaration into its class. */
21852 if (!declaration
&& !origin
&& !old_die
21853 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
21854 && !class_or_namespace_scope_p (context_die
)
21855 && debug_info_level
> DINFO_LEVEL_TERSE
)
21856 old_die
= force_decl_die (decl
);
21858 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
21859 if (origin
!= NULL
)
21861 gcc_assert (!declaration
|| local_scope_p (context_die
));
21863 /* Fixup die_parent for the abstract instance of a nested
21864 inline function. */
21865 if (old_die
&& old_die
->die_parent
== NULL
)
21866 add_child_die (context_die
, old_die
);
21868 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
21870 /* If we have a DW_AT_abstract_origin we have a working
21872 subr_die
= old_die
;
21876 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
21877 add_abstract_origin_attribute (subr_die
, origin
);
21878 /* This is where the actual code for a cloned function is.
21879 Let's emit linkage name attribute for it. This helps
21880 debuggers to e.g, set breakpoints into
21881 constructors/destructors when the user asks "break
21883 add_linkage_name (subr_die
, decl
);
21886 /* A cached copy, possibly from early dwarf generation. Reuse as
21887 much as possible. */
21890 /* A declaration that has been previously dumped needs no
21891 additional information. */
21895 if (!get_AT_flag (old_die
, DW_AT_declaration
)
21896 /* We can have a normal definition following an inline one in the
21897 case of redefinition of GNU C extern inlines.
21898 It seems reasonable to use AT_specification in this case. */
21899 && !get_AT (old_die
, DW_AT_inline
))
21901 /* Detect and ignore this case, where we are trying to output
21902 something we have already output. */
21903 if (get_AT (old_die
, DW_AT_low_pc
)
21904 || get_AT (old_die
, DW_AT_ranges
))
21907 /* If we have no location information, this must be a
21908 partially generated DIE from early dwarf generation.
21909 Fall through and generate it. */
21912 /* If the definition comes from the same place as the declaration,
21913 maybe use the old DIE. We always want the DIE for this function
21914 that has the *_pc attributes to be under comp_unit_die so the
21915 debugger can find it. We also need to do this for abstract
21916 instances of inlines, since the spec requires the out-of-line copy
21917 to have the same parent. For local class methods, this doesn't
21918 apply; we just use the old DIE. */
21919 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
21920 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
21921 if ((is_cu_die (old_die
->die_parent
)
21922 /* This condition fixes the inconsistency/ICE with the
21923 following Fortran test (or some derivative thereof) while
21924 building libgfortran:
21928 logical function funky (FLAG)
21933 || (old_die
->die_parent
21934 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
21935 || context_die
== NULL
)
21936 && (DECL_ARTIFICIAL (decl
)
21937 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
21938 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
21939 == (unsigned) s
.line
))))
21941 subr_die
= old_die
;
21943 /* Clear out the declaration attribute, but leave the
21944 parameters so they can be augmented with location
21945 information later. Unless this was a declaration, in
21946 which case, wipe out the nameless parameters and recreate
21947 them further down. */
21948 if (remove_AT (subr_die
, DW_AT_declaration
))
21951 remove_AT (subr_die
, DW_AT_object_pointer
);
21952 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
21955 /* Make a specification pointing to the previously built
21959 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
21960 add_AT_specification (subr_die
, old_die
);
21961 add_pubname (decl
, subr_die
);
21962 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
21963 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
21964 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
21965 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
21967 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
21968 emit the real type on the definition die. */
21969 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
21971 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
21972 if (die
== auto_die
|| die
== decltype_auto_die
)
21973 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
21974 TYPE_UNQUALIFIED
, false, context_die
);
21977 /* When we process the method declaration, we haven't seen
21978 the out-of-class defaulted definition yet, so we have to
21980 if ((dwarf_version
>= 5 || ! dwarf_strict
)
21981 && !get_AT (subr_die
, DW_AT_defaulted
))
21984 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
21986 if (defaulted
!= -1)
21988 /* Other values must have been handled before. */
21989 gcc_assert (defaulted
== DW_DEFAULTED_out_of_class
);
21990 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
21995 /* Create a fresh DIE for anything else. */
21998 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22000 if (TREE_PUBLIC (decl
))
22001 add_AT_flag (subr_die
, DW_AT_external
, 1);
22003 add_name_and_src_coords_attributes (subr_die
, decl
);
22004 add_pubname (decl
, subr_die
);
22005 if (debug_info_level
> DINFO_LEVEL_TERSE
)
22007 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
22008 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
22009 TYPE_UNQUALIFIED
, false, context_die
);
22012 add_pure_or_virtual_attribute (subr_die
, decl
);
22013 if (DECL_ARTIFICIAL (decl
))
22014 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
22016 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
22017 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
22019 add_alignment_attribute (subr_die
, decl
);
22021 add_accessibility_attribute (subr_die
, decl
);
22024 /* Unless we have an existing non-declaration DIE, equate the new
22026 if (!old_die
|| is_declaration_die (old_die
))
22027 equate_decl_number_to_die (decl
, subr_die
);
22031 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
22033 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
22035 /* If this is an explicit function declaration then generate
22036 a DW_AT_explicit attribute. */
22037 if ((dwarf_version
>= 3 || !dwarf_strict
)
22038 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22039 DW_AT_explicit
) == 1)
22040 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
22042 /* If this is a C++11 deleted special function member then generate
22043 a DW_AT_deleted attribute. */
22044 if ((dwarf_version
>= 5 || !dwarf_strict
)
22045 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22046 DW_AT_deleted
) == 1)
22047 add_AT_flag (subr_die
, DW_AT_deleted
, 1);
22049 /* If this is a C++11 defaulted special function member then
22050 generate a DW_AT_defaulted attribute. */
22051 if (dwarf_version
>= 5 || !dwarf_strict
)
22054 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22056 if (defaulted
!= -1)
22057 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22060 /* If this is a C++11 non-static member function with & ref-qualifier
22061 then generate a DW_AT_reference attribute. */
22062 if ((dwarf_version
>= 5 || !dwarf_strict
)
22063 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22064 DW_AT_reference
) == 1)
22065 add_AT_flag (subr_die
, DW_AT_reference
, 1);
22067 /* If this is a C++11 non-static member function with &&
22068 ref-qualifier then generate a DW_AT_reference attribute. */
22069 if ((dwarf_version
>= 5 || !dwarf_strict
)
22070 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22071 DW_AT_rvalue_reference
)
22073 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
22076 /* Tag abstract instances with DW_AT_inline. */
22077 else if (DECL_ABSTRACT_P (decl
))
22079 if (DECL_DECLARED_INLINE_P (decl
))
22081 if (cgraph_function_possibly_inlined_p (decl
))
22082 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
22084 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
22088 if (cgraph_function_possibly_inlined_p (decl
))
22089 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
22091 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
22094 if (DECL_DECLARED_INLINE_P (decl
)
22095 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
22096 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
22098 /* For non DECL_EXTERNALs, if range information is available, fill
22099 the DIE with it. */
22100 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
22102 HOST_WIDE_INT cfa_fb_offset
;
22104 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
22106 if (!flag_reorder_blocks_and_partition
)
22108 dw_fde_ref fde
= fun
->fde
;
22109 if (fde
->dw_fde_begin
)
22111 /* We have already generated the labels. */
22112 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22113 fde
->dw_fde_end
, false);
22117 /* Create start/end labels and add the range. */
22118 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
22119 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
22120 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
22121 current_function_funcdef_no
);
22122 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
22123 current_function_funcdef_no
);
22124 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
22128 #if VMS_DEBUGGING_INFO
22129 /* HP OpenVMS Industry Standard 64: DWARF Extensions
22130 Section 2.3 Prologue and Epilogue Attributes:
22131 When a breakpoint is set on entry to a function, it is generally
22132 desirable for execution to be suspended, not on the very first
22133 instruction of the function, but rather at a point after the
22134 function's frame has been set up, after any language defined local
22135 declaration processing has been completed, and before execution of
22136 the first statement of the function begins. Debuggers generally
22137 cannot properly determine where this point is. Similarly for a
22138 breakpoint set on exit from a function. The prologue and epilogue
22139 attributes allow a compiler to communicate the location(s) to use. */
22142 if (fde
->dw_fde_vms_end_prologue
)
22143 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
22144 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
22146 if (fde
->dw_fde_vms_begin_epilogue
)
22147 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
22148 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
22155 /* Generate pubnames entries for the split function code ranges. */
22156 dw_fde_ref fde
= fun
->fde
;
22158 if (fde
->dw_fde_second_begin
)
22160 if (dwarf_version
>= 3 || !dwarf_strict
)
22162 /* We should use ranges for non-contiguous code section
22163 addresses. Use the actual code range for the initial
22164 section, since the HOT/COLD labels might precede an
22165 alignment offset. */
22166 bool range_list_added
= false;
22167 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
22168 fde
->dw_fde_end
, &range_list_added
,
22170 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
22171 fde
->dw_fde_second_end
,
22172 &range_list_added
, false);
22173 if (range_list_added
)
22178 /* There is no real support in DW2 for this .. so we make
22179 a work-around. First, emit the pub name for the segment
22180 containing the function label. Then make and emit a
22181 simplified subprogram DIE for the second segment with the
22182 name pre-fixed by __hot/cold_sect_of_. We use the same
22183 linkage name for the second die so that gdb will find both
22184 sections when given "b foo". */
22185 const char *name
= NULL
;
22186 tree decl_name
= DECL_NAME (decl
);
22187 dw_die_ref seg_die
;
22189 /* Do the 'primary' section. */
22190 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22191 fde
->dw_fde_end
, false);
22193 /* Build a minimal DIE for the secondary section. */
22194 seg_die
= new_die (DW_TAG_subprogram
,
22195 subr_die
->die_parent
, decl
);
22197 if (TREE_PUBLIC (decl
))
22198 add_AT_flag (seg_die
, DW_AT_external
, 1);
22200 if (decl_name
!= NULL
22201 && IDENTIFIER_POINTER (decl_name
) != NULL
)
22203 name
= dwarf2_name (decl
, 1);
22204 if (! DECL_ARTIFICIAL (decl
))
22205 add_src_coords_attributes (seg_die
, decl
);
22207 add_linkage_name (seg_die
, decl
);
22209 gcc_assert (name
!= NULL
);
22210 add_pure_or_virtual_attribute (seg_die
, decl
);
22211 if (DECL_ARTIFICIAL (decl
))
22212 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
22214 name
= concat ("__second_sect_of_", name
, NULL
);
22215 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
22216 fde
->dw_fde_second_end
, false);
22217 add_name_attribute (seg_die
, name
);
22218 if (want_pubnames ())
22219 add_pubname_string (name
, seg_die
);
22223 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
22227 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
22229 /* We define the "frame base" as the function's CFA. This is more
22230 convenient for several reasons: (1) It's stable across the prologue
22231 and epilogue, which makes it better than just a frame pointer,
22232 (2) With dwarf3, there exists a one-byte encoding that allows us
22233 to reference the .debug_frame data by proxy, but failing that,
22234 (3) We can at least reuse the code inspection and interpretation
22235 code that determines the CFA position at various points in the
22237 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
22239 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
22240 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
22244 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
22245 if (list
->dw_loc_next
)
22246 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
22248 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
22251 /* Compute a displacement from the "steady-state frame pointer" to
22252 the CFA. The former is what all stack slots and argument slots
22253 will reference in the rtl; the latter is what we've told the
22254 debugger about. We'll need to adjust all frame_base references
22255 by this displacement. */
22256 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
22258 if (fun
->static_chain_decl
)
22260 /* DWARF requires here a location expression that computes the
22261 address of the enclosing subprogram's frame base. The machinery
22262 in tree-nested.c is supposed to store this specific address in the
22263 last field of the FRAME record. */
22264 const tree frame_type
22265 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
22266 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
22269 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
22270 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
22271 fb_expr
, fb_decl
, NULL_TREE
);
22273 add_AT_location_description (subr_die
, DW_AT_static_link
,
22274 loc_list_from_tree (fb_expr
, 0, NULL
));
22278 /* Generate child dies for template paramaters. */
22279 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
22280 gen_generic_params_dies (decl
);
22282 /* Now output descriptions of the arguments for this function. This gets
22283 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
22284 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
22285 `...' at the end of the formal parameter list. In order to find out if
22286 there was a trailing ellipsis or not, we must instead look at the type
22287 associated with the FUNCTION_DECL. This will be a node of type
22288 FUNCTION_TYPE. If the chain of type nodes hanging off of this
22289 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
22290 an ellipsis at the end. */
22292 /* In the case where we are describing a mere function declaration, all we
22293 need to do here (and all we *can* do here) is to describe the *types* of
22294 its formal parameters. */
22295 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
22297 else if (declaration
)
22298 gen_formal_types_die (decl
, subr_die
);
22301 /* Generate DIEs to represent all known formal parameters. */
22302 tree parm
= DECL_ARGUMENTS (decl
);
22303 tree generic_decl
= early_dwarf
22304 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
22305 tree generic_decl_parm
= generic_decl
22306 ? DECL_ARGUMENTS (generic_decl
)
22308 auto_vec
<dw_die_ref
> string_types_vec
;
22309 if (string_types
== NULL
)
22310 string_types
= &string_types_vec
;
22312 /* Now we want to walk the list of parameters of the function and
22313 emit their relevant DIEs.
22315 We consider the case of DECL being an instance of a generic function
22316 as well as it being a normal function.
22318 If DECL is an instance of a generic function we walk the
22319 parameters of the generic function declaration _and_ the parameters of
22320 DECL itself. This is useful because we want to emit specific DIEs for
22321 function parameter packs and those are declared as part of the
22322 generic function declaration. In that particular case,
22323 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
22324 That DIE has children DIEs representing the set of arguments
22325 of the pack. Note that the set of pack arguments can be empty.
22326 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
22329 Otherwise, we just consider the parameters of DECL. */
22330 while (generic_decl_parm
|| parm
)
22332 if (generic_decl_parm
22333 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
22334 gen_formal_parameter_pack_die (generic_decl_parm
,
22337 else if (parm
&& !POINTER_BOUNDS_P (parm
))
22339 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
22341 if (parm
== DECL_ARGUMENTS (decl
)
22342 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
22344 && (dwarf_version
>= 3 || !dwarf_strict
))
22345 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
22347 parm
= DECL_CHAIN (parm
);
22350 parm
= DECL_CHAIN (parm
);
22352 if (generic_decl_parm
)
22353 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
22356 /* Decide whether we need an unspecified_parameters DIE at the end.
22357 There are 2 more cases to do this for: 1) the ansi ... declaration -
22358 this is detectable when the end of the arg list is not a
22359 void_type_node 2) an unprototyped function declaration (not a
22360 definition). This just means that we have no info about the
22361 parameters at all. */
22364 if (prototype_p (TREE_TYPE (decl
)))
22366 /* This is the prototyped case, check for.... */
22367 if (stdarg_p (TREE_TYPE (decl
)))
22368 gen_unspecified_parameters_die (decl
, subr_die
);
22370 else if (DECL_INITIAL (decl
) == NULL_TREE
)
22371 gen_unspecified_parameters_die (decl
, subr_die
);
22374 /* Adjust DW_TAG_string_type DIEs if needed, now that all arguments
22376 if (string_types
== &string_types_vec
)
22378 adjust_string_types ();
22379 string_types
= NULL
;
22383 if (subr_die
!= old_die
)
22384 /* Add the calling convention attribute if requested. */
22385 add_calling_convention_attribute (subr_die
, decl
);
22387 /* Output Dwarf info for all of the stuff within the body of the function
22388 (if it has one - it may be just a declaration).
22390 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
22391 a function. This BLOCK actually represents the outermost binding contour
22392 for the function, i.e. the contour in which the function's formal
22393 parameters and labels get declared. Curiously, it appears that the front
22394 end doesn't actually put the PARM_DECL nodes for the current function onto
22395 the BLOCK_VARS list for this outer scope, but are strung off of the
22396 DECL_ARGUMENTS list for the function instead.
22398 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
22399 the LABEL_DECL nodes for the function however, and we output DWARF info
22400 for those in decls_for_scope. Just within the `outer_scope' there will be
22401 a BLOCK node representing the function's outermost pair of curly braces,
22402 and any blocks used for the base and member initializers of a C++
22403 constructor function. */
22404 tree outer_scope
= DECL_INITIAL (decl
);
22405 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
22407 int call_site_note_count
= 0;
22408 int tail_call_site_note_count
= 0;
22410 /* Emit a DW_TAG_variable DIE for a named return value. */
22411 if (DECL_NAME (DECL_RESULT (decl
)))
22412 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
22414 /* The first time through decls_for_scope we will generate the
22415 DIEs for the locals. The second time, we fill in the
22417 decls_for_scope (outer_scope
, subr_die
);
22419 if (call_arg_locations
&& (!dwarf_strict
|| dwarf_version
>= 5))
22421 struct call_arg_loc_node
*ca_loc
;
22422 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
22424 dw_die_ref die
= NULL
;
22425 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
22428 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
22429 ? NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
)
22431 arg
; arg
= next_arg
)
22433 dw_loc_descr_ref reg
, val
;
22434 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
22435 dw_die_ref cdie
, tdie
= NULL
;
22437 next_arg
= XEXP (arg
, 1);
22438 if (REG_P (XEXP (XEXP (arg
, 0), 0))
22440 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
22441 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
22442 && REGNO (XEXP (XEXP (arg
, 0), 0))
22443 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
22444 next_arg
= XEXP (next_arg
, 1);
22445 if (mode
== VOIDmode
)
22447 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
22448 if (mode
== VOIDmode
)
22449 mode
= GET_MODE (XEXP (arg
, 0));
22451 if (mode
== VOIDmode
|| mode
== BLKmode
)
22453 /* Get dynamic information about call target only if we
22454 have no static information: we cannot generate both
22455 DW_AT_call_origin and DW_AT_call_target
22457 if (ca_loc
->symbol_ref
== NULL_RTX
)
22459 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
22461 tloc
= XEXP (XEXP (arg
, 0), 1);
22464 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
22465 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
22467 tlocc
= XEXP (XEXP (arg
, 0), 1);
22472 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
22473 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
22474 VAR_INIT_STATUS_INITIALIZED
);
22475 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
22477 rtx mem
= XEXP (XEXP (arg
, 0), 0);
22478 reg
= mem_loc_descriptor (XEXP (mem
, 0),
22479 get_address_mode (mem
),
22481 VAR_INIT_STATUS_INITIALIZED
);
22483 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
22484 == DEBUG_PARAMETER_REF
)
22487 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
22488 tdie
= lookup_decl_die (tdecl
);
22495 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
22496 != DEBUG_PARAMETER_REF
)
22498 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
22500 VAR_INIT_STATUS_INITIALIZED
);
22504 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22505 cdie
= new_die (dwarf_TAG (DW_TAG_call_site_parameter
), die
,
22508 add_AT_loc (cdie
, DW_AT_location
, reg
);
22509 else if (tdie
!= NULL
)
22510 add_AT_die_ref (cdie
, dwarf_AT (DW_AT_call_parameter
),
22512 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_value
), val
);
22513 if (next_arg
!= XEXP (arg
, 1))
22515 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
22516 if (mode
== VOIDmode
)
22517 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
22518 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
22521 VAR_INIT_STATUS_INITIALIZED
);
22523 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_data_value
),
22528 && (ca_loc
->symbol_ref
|| tloc
))
22529 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22530 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
22532 dw_loc_descr_ref tval
= NULL
;
22534 if (tloc
!= NULL_RTX
)
22535 tval
= mem_loc_descriptor (tloc
,
22536 GET_MODE (tloc
) == VOIDmode
22537 ? Pmode
: GET_MODE (tloc
),
22539 VAR_INIT_STATUS_INITIALIZED
);
22541 add_AT_loc (die
, dwarf_AT (DW_AT_call_target
), tval
);
22542 else if (tlocc
!= NULL_RTX
)
22544 tval
= mem_loc_descriptor (tlocc
,
22545 GET_MODE (tlocc
) == VOIDmode
22546 ? Pmode
: GET_MODE (tlocc
),
22548 VAR_INIT_STATUS_INITIALIZED
);
22551 dwarf_AT (DW_AT_call_target_clobbered
),
22557 call_site_note_count
++;
22558 if (ca_loc
->tail_call_p
)
22559 tail_call_site_note_count
++;
22563 call_arg_locations
= NULL
;
22564 call_arg_loc_last
= NULL
;
22565 if (tail_call_site_count
>= 0
22566 && tail_call_site_count
== tail_call_site_note_count
22567 && (!dwarf_strict
|| dwarf_version
>= 5))
22569 if (call_site_count
>= 0
22570 && call_site_count
== call_site_note_count
)
22571 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_calls
), 1);
22573 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_tail_calls
), 1);
22575 call_site_count
= -1;
22576 tail_call_site_count
= -1;
22579 /* Mark used types after we have created DIEs for the functions scopes. */
22580 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
22583 /* Returns a hash value for X (which really is a die_struct). */
22586 block_die_hasher::hash (die_struct
*d
)
22588 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
22591 /* Return nonzero if decl_id and die_parent of die_struct X is the same
22592 as decl_id and die_parent of die_struct Y. */
22595 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
22597 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
22600 /* Return TRUE if DECL, which may have been previously generated as
22601 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
22602 true if decl (or its origin) is either an extern declaration or a
22603 class/namespace scoped declaration.
22605 The declare_in_namespace support causes us to get two DIEs for one
22606 variable, both of which are declarations. We want to avoid
22607 considering one to be a specification, so we must test for
22608 DECLARATION and DW_AT_declaration. */
22610 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
22612 return (old_die
&& TREE_STATIC (decl
) && !declaration
22613 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
22616 /* Return true if DECL is a local static. */
22619 local_function_static (tree decl
)
22621 gcc_assert (VAR_P (decl
));
22622 return TREE_STATIC (decl
)
22623 && DECL_CONTEXT (decl
)
22624 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
22627 /* Generate a DIE to represent a declared data object.
22628 Either DECL or ORIGIN must be non-null. */
22631 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
22633 HOST_WIDE_INT off
= 0;
22635 tree decl_or_origin
= decl
? decl
: origin
;
22636 tree ultimate_origin
;
22637 dw_die_ref var_die
;
22638 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
22639 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
22640 || class_or_namespace_scope_p (context_die
));
22641 bool specialization_p
= false;
22642 bool no_linkage_name
= false;
22644 /* While C++ inline static data members have definitions inside of the
22645 class, force the first DIE to be a declaration, then let gen_member_die
22646 reparent it to the class context and call gen_variable_die again
22647 to create the outside of the class DIE for the definition. */
22651 && DECL_CONTEXT (decl
)
22652 && TYPE_P (DECL_CONTEXT (decl
))
22653 && lang_hooks
.decls
.decl_dwarf_attribute (decl
, DW_AT_inline
) != -1)
22655 declaration
= true;
22656 no_linkage_name
= true;
22659 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
22660 if (decl
|| ultimate_origin
)
22661 origin
= ultimate_origin
;
22662 com_decl
= fortran_common (decl_or_origin
, &off
);
22664 /* Symbol in common gets emitted as a child of the common block, in the form
22665 of a data member. */
22668 dw_die_ref com_die
;
22669 dw_loc_list_ref loc
= NULL
;
22670 die_node com_die_arg
;
22672 var_die
= lookup_decl_die (decl_or_origin
);
22675 if (! early_dwarf
&& get_AT (var_die
, DW_AT_location
) == NULL
)
22677 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
22682 /* Optimize the common case. */
22683 if (single_element_loc_list_p (loc
)
22684 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22685 && loc
->expr
->dw_loc_next
== NULL
22686 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
22689 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22690 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22691 = plus_constant (GET_MODE (x
), x
, off
);
22694 loc_list_plus_const (loc
, off
);
22696 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22697 remove_AT (var_die
, DW_AT_declaration
);
22703 if (common_block_die_table
== NULL
)
22704 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
22706 com_die_arg
.decl_id
= DECL_UID (com_decl
);
22707 com_die_arg
.die_parent
= context_die
;
22708 com_die
= common_block_die_table
->find (&com_die_arg
);
22710 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22711 if (com_die
== NULL
)
22714 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
22717 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
22718 add_name_and_src_coords_attributes (com_die
, com_decl
);
22721 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22722 /* Avoid sharing the same loc descriptor between
22723 DW_TAG_common_block and DW_TAG_variable. */
22724 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22726 else if (DECL_EXTERNAL (decl_or_origin
))
22727 add_AT_flag (com_die
, DW_AT_declaration
, 1);
22728 if (want_pubnames ())
22729 add_pubname_string (cnam
, com_die
); /* ??? needed? */
22730 com_die
->decl_id
= DECL_UID (com_decl
);
22731 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
22734 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
22736 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22737 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22738 remove_AT (com_die
, DW_AT_declaration
);
22740 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
22741 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
22742 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
22743 decl_quals (decl_or_origin
), false,
22745 add_alignment_attribute (var_die
, decl
);
22746 add_AT_flag (var_die
, DW_AT_external
, 1);
22751 /* Optimize the common case. */
22752 if (single_element_loc_list_p (loc
)
22753 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22754 && loc
->expr
->dw_loc_next
== NULL
22755 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
22757 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22758 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22759 = plus_constant (GET_MODE (x
), x
, off
);
22762 loc_list_plus_const (loc
, off
);
22764 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22766 else if (DECL_EXTERNAL (decl_or_origin
))
22767 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22769 equate_decl_number_to_die (decl
, var_die
);
22777 /* A declaration that has been previously dumped, needs no
22778 further annotations, since it doesn't need location on
22779 the second pass. */
22782 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
22783 && !get_AT (old_die
, DW_AT_specification
))
22785 /* Fall-thru so we can make a new variable die along with a
22786 DW_AT_specification. */
22788 else if (origin
&& old_die
->die_parent
!= context_die
)
22790 /* If we will be creating an inlined instance, we need a
22791 new DIE that will get annotated with
22792 DW_AT_abstract_origin. Clear things so we can get a
22794 gcc_assert (!DECL_ABSTRACT_P (decl
));
22799 /* If a DIE was dumped early, it still needs location info.
22800 Skip to where we fill the location bits. */
22802 goto gen_variable_die_location
;
22806 /* For static data members, the declaration in the class is supposed
22807 to have DW_TAG_member tag; the specification should still be
22808 DW_TAG_variable referencing the DW_TAG_member DIE. */
22809 if (declaration
&& class_scope_p (context_die
))
22810 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
22812 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
22814 if (origin
!= NULL
)
22815 add_abstract_origin_attribute (var_die
, origin
);
22817 /* Loop unrolling can create multiple blocks that refer to the same
22818 static variable, so we must test for the DW_AT_declaration flag.
22820 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
22821 copy decls and set the DECL_ABSTRACT_P flag on them instead of
22824 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
22825 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
22827 /* This is a definition of a C++ class level static. */
22828 add_AT_specification (var_die
, old_die
);
22829 specialization_p
= true;
22830 if (DECL_NAME (decl
))
22832 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
22833 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
22835 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
22836 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
22838 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
22839 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
22841 if (old_die
->die_tag
== DW_TAG_member
)
22842 add_linkage_name (var_die
, decl
);
22846 add_name_and_src_coords_attributes (var_die
, decl
, no_linkage_name
);
22848 if ((origin
== NULL
&& !specialization_p
)
22850 && !DECL_ABSTRACT_P (decl_or_origin
)
22851 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
22852 decl_function_context
22853 (decl_or_origin
))))
22855 tree type
= TREE_TYPE (decl_or_origin
);
22857 if (decl_by_reference_p (decl_or_origin
))
22858 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
22861 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
22865 if (origin
== NULL
&& !specialization_p
)
22867 if (TREE_PUBLIC (decl
))
22868 add_AT_flag (var_die
, DW_AT_external
, 1);
22870 if (DECL_ARTIFICIAL (decl
))
22871 add_AT_flag (var_die
, DW_AT_artificial
, 1);
22873 add_alignment_attribute (var_die
, decl
);
22875 add_accessibility_attribute (var_die
, decl
);
22879 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22881 if (decl
&& (DECL_ABSTRACT_P (decl
)
22882 || !old_die
|| is_declaration_die (old_die
)))
22883 equate_decl_number_to_die (decl
, var_die
);
22885 gen_variable_die_location
:
22887 && (! DECL_ABSTRACT_P (decl_or_origin
)
22888 /* Local static vars are shared between all clones/inlines,
22889 so emit DW_AT_location on the abstract DIE if DECL_RTL is
22891 || (VAR_P (decl_or_origin
)
22892 && TREE_STATIC (decl_or_origin
)
22893 && DECL_RTL_SET_P (decl_or_origin
))))
22896 add_pubname (decl_or_origin
, var_die
);
22898 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
22902 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
22904 if ((dwarf_version
>= 4 || !dwarf_strict
)
22905 && lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
22906 DW_AT_const_expr
) == 1
22907 && !get_AT (var_die
, DW_AT_const_expr
)
22908 && !specialization_p
)
22909 add_AT_flag (var_die
, DW_AT_const_expr
, 1);
22913 int inl
= lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
22916 && !get_AT (var_die
, DW_AT_inline
)
22917 && !specialization_p
)
22918 add_AT_unsigned (var_die
, DW_AT_inline
, inl
);
22922 /* Generate a DIE to represent a named constant. */
22925 gen_const_die (tree decl
, dw_die_ref context_die
)
22927 dw_die_ref const_die
;
22928 tree type
= TREE_TYPE (decl
);
22930 const_die
= lookup_decl_die (decl
);
22934 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
22935 equate_decl_number_to_die (decl
, const_die
);
22936 add_name_and_src_coords_attributes (const_die
, decl
);
22937 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
22938 if (TREE_PUBLIC (decl
))
22939 add_AT_flag (const_die
, DW_AT_external
, 1);
22940 if (DECL_ARTIFICIAL (decl
))
22941 add_AT_flag (const_die
, DW_AT_artificial
, 1);
22942 tree_add_const_value_attribute_for_decl (const_die
, decl
);
22945 /* Generate a DIE to represent a label identifier. */
22948 gen_label_die (tree decl
, dw_die_ref context_die
)
22950 tree origin
= decl_ultimate_origin (decl
);
22951 dw_die_ref lbl_die
= lookup_decl_die (decl
);
22953 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22957 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
22958 equate_decl_number_to_die (decl
, lbl_die
);
22960 if (origin
!= NULL
)
22961 add_abstract_origin_attribute (lbl_die
, origin
);
22963 add_name_and_src_coords_attributes (lbl_die
, decl
);
22966 if (DECL_ABSTRACT_P (decl
))
22967 equate_decl_number_to_die (decl
, lbl_die
);
22968 else if (! early_dwarf
)
22970 insn
= DECL_RTL_IF_SET (decl
);
22972 /* Deleted labels are programmer specified labels which have been
22973 eliminated because of various optimizations. We still emit them
22974 here so that it is possible to put breakpoints on them. */
22978 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
22980 /* When optimization is enabled (via -O) some parts of the compiler
22981 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
22982 represent source-level labels which were explicitly declared by
22983 the user. This really shouldn't be happening though, so catch
22984 it if it ever does happen. */
22985 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
22987 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
22988 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
22992 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
22993 && CODE_LABEL_NUMBER (insn
) != -1)
22995 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
22996 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23001 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
23002 attributes to the DIE for a block STMT, to describe where the inlined
23003 function was called from. This is similar to add_src_coords_attributes. */
23006 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
23008 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
23010 if (dwarf_version
>= 3 || !dwarf_strict
)
23012 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
23013 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
23018 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
23019 Add low_pc and high_pc attributes to the DIE for a block STMT. */
23022 add_high_low_attributes (tree stmt
, dw_die_ref die
)
23024 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23026 if (BLOCK_FRAGMENT_CHAIN (stmt
)
23027 && (dwarf_version
>= 3 || !dwarf_strict
))
23029 tree chain
, superblock
= NULL_TREE
;
23031 dw_attr_node
*attr
= NULL
;
23033 if (inlined_function_outer_scope_p (stmt
))
23035 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23036 BLOCK_NUMBER (stmt
));
23037 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
23040 /* Optimize duplicate .debug_ranges lists or even tails of
23041 lists. If this BLOCK has same ranges as its supercontext,
23042 lookup DW_AT_ranges attribute in the supercontext (and
23043 recursively so), verify that the ranges_table contains the
23044 right values and use it instead of adding a new .debug_range. */
23045 for (chain
= stmt
, pdie
= die
;
23046 BLOCK_SAME_RANGE (chain
);
23047 chain
= BLOCK_SUPERCONTEXT (chain
))
23049 dw_attr_node
*new_attr
;
23051 pdie
= pdie
->die_parent
;
23054 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
23056 new_attr
= get_AT (pdie
, DW_AT_ranges
);
23057 if (new_attr
== NULL
23058 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
23061 superblock
= BLOCK_SUPERCONTEXT (chain
);
23064 && ((*ranges_table
)[attr
->dw_attr_val
.v
.val_offset
].num
23065 == BLOCK_NUMBER (superblock
))
23066 && BLOCK_FRAGMENT_CHAIN (superblock
))
23068 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
;
23069 unsigned long supercnt
= 0, thiscnt
= 0;
23070 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
23071 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23074 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
].num
23075 == BLOCK_NUMBER (chain
));
23077 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
+ 1].num
== 0);
23078 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23079 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23081 gcc_assert (supercnt
>= thiscnt
);
23082 add_AT_range_list (die
, DW_AT_ranges
, off
+ supercnt
- thiscnt
,
23084 note_rnglist_head (off
+ supercnt
- thiscnt
);
23088 unsigned int offset
= add_ranges (stmt
, true);
23089 add_AT_range_list (die
, DW_AT_ranges
, offset
, false);
23090 note_rnglist_head (offset
);
23092 bool prev_in_cold
= BLOCK_IN_COLD_SECTION_P (stmt
);
23093 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23096 add_ranges (chain
, prev_in_cold
!= BLOCK_IN_COLD_SECTION_P (chain
));
23097 prev_in_cold
= BLOCK_IN_COLD_SECTION_P (chain
);
23098 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
23105 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
23106 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23107 BLOCK_NUMBER (stmt
));
23108 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
23109 BLOCK_NUMBER (stmt
));
23110 add_AT_low_high_pc (die
, label
, label_high
, false);
23114 /* Generate a DIE for a lexical block. */
23117 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
23119 dw_die_ref old_die
= BLOCK_DIE (stmt
);
23120 dw_die_ref stmt_die
= NULL
;
23123 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23124 BLOCK_DIE (stmt
) = stmt_die
;
23127 if (BLOCK_ABSTRACT (stmt
))
23131 /* This must have been generated early and it won't even
23132 need location information since it's a DW_AT_inline
23135 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
23136 if (c
->die_tag
== DW_TAG_inlined_subroutine
23137 || c
->die_tag
== DW_TAG_subprogram
)
23139 gcc_assert (get_AT (c
, DW_AT_inline
));
23145 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
23147 /* If this is an inlined instance, create a new lexical die for
23148 anything below to attach DW_AT_abstract_origin to. */
23151 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23152 BLOCK_DIE (stmt
) = stmt_die
;
23156 tree origin
= block_ultimate_origin (stmt
);
23157 if (origin
!= NULL_TREE
&& origin
!= stmt
)
23158 add_abstract_origin_attribute (stmt_die
, origin
);
23162 stmt_die
= old_die
;
23164 /* A non abstract block whose blocks have already been reordered
23165 should have the instruction range for this block. If so, set the
23166 high/low attributes. */
23167 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
23169 gcc_assert (stmt_die
);
23170 add_high_low_attributes (stmt
, stmt_die
);
23173 decls_for_scope (stmt
, stmt_die
);
23176 /* Generate a DIE for an inlined subprogram. */
23179 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
23183 /* The instance of function that is effectively being inlined shall not
23185 gcc_assert (! BLOCK_ABSTRACT (stmt
));
23187 decl
= block_ultimate_origin (stmt
);
23189 /* Make sure any inlined functions are known to be inlineable. */
23190 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
23191 || cgraph_function_possibly_inlined_p (decl
));
23193 /* Emit info for the abstract instance first, if we haven't yet. We
23194 must emit this even if the block is abstract, otherwise when we
23195 emit the block below (or elsewhere), we may end up trying to emit
23196 a die whose origin die hasn't been emitted, and crashing. */
23197 dwarf2out_abstract_function (decl
);
23199 if (! BLOCK_ABSTRACT (stmt
))
23201 dw_die_ref subr_die
23202 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
23204 if (call_arg_locations
)
23205 BLOCK_DIE (stmt
) = subr_die
;
23206 add_abstract_origin_attribute (subr_die
, decl
);
23207 if (TREE_ASM_WRITTEN (stmt
))
23208 add_high_low_attributes (stmt
, subr_die
);
23209 add_call_src_coords_attributes (stmt
, subr_die
);
23211 decls_for_scope (stmt
, subr_die
);
23215 /* Generate a DIE for a field in a record, or structure. CTX is required: see
23216 the comment for VLR_CONTEXT. */
23219 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
23221 dw_die_ref decl_die
;
23223 if (TREE_TYPE (decl
) == error_mark_node
)
23226 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
23227 add_name_and_src_coords_attributes (decl_die
, decl
);
23228 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
23229 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
23232 if (DECL_BIT_FIELD_TYPE (decl
))
23234 add_byte_size_attribute (decl_die
, decl
);
23235 add_bit_size_attribute (decl_die
, decl
);
23236 add_bit_offset_attribute (decl_die
, decl
, ctx
);
23239 add_alignment_attribute (decl_die
, decl
);
23241 /* If we have a variant part offset, then we are supposed to process a member
23242 of a QUAL_UNION_TYPE, which is how we represent variant parts in
23244 gcc_assert (ctx
->variant_part_offset
== NULL_TREE
23245 || TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != QUAL_UNION_TYPE
);
23246 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
23247 add_data_member_location_attribute (decl_die
, decl
, ctx
);
23249 if (DECL_ARTIFICIAL (decl
))
23250 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
23252 add_accessibility_attribute (decl_die
, decl
);
23254 /* Equate decl number to die, so that we can look up this decl later on. */
23255 equate_decl_number_to_die (decl
, decl_die
);
23259 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
23260 Use modified_type_die instead.
23261 We keep this code here just in case these types of DIEs may be needed to
23262 represent certain things in other languages (e.g. Pascal) someday. */
23265 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
23268 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
23270 equate_type_number_to_die (type
, ptr_die
);
23271 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23273 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
23276 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
23277 Use modified_type_die instead.
23278 We keep this code here just in case these types of DIEs may be needed to
23279 represent certain things in other languages (e.g. Pascal) someday. */
23282 gen_reference_type_die (tree type
, dw_die_ref context_die
)
23284 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
23286 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
23287 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
23289 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
23291 equate_type_number_to_die (type
, ref_die
);
23292 add_type_attribute (ref_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23294 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
23298 /* Generate a DIE for a pointer to a member type. TYPE can be an
23299 OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
23300 pointer to member function. */
23303 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
23305 if (lookup_type_die (type
))
23308 dw_die_ref ptr_die
= new_die (DW_TAG_ptr_to_member_type
,
23309 scope_die_for (type
, context_die
), type
);
23311 equate_type_number_to_die (type
, ptr_die
);
23312 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
23313 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
23314 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23316 add_alignment_attribute (ptr_die
, type
);
23318 if (TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
23319 && TREE_CODE (TREE_TYPE (type
)) != METHOD_TYPE
)
23321 dw_loc_descr_ref op
= new_loc_descr (DW_OP_plus
, 0, 0);
23322 add_AT_loc (ptr_die
, DW_AT_use_location
, op
);
23326 static char *producer_string
;
23328 /* Return a heap allocated producer string including command line options
23329 if -grecord-gcc-switches. */
23332 gen_producer_string (void)
23335 auto_vec
<const char *> switches
;
23336 const char *language_string
= lang_hooks
.name
;
23337 char *producer
, *tail
;
23339 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
23340 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
23342 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
23343 switch (save_decoded_options
[j
].opt_index
)
23350 case OPT_auxbase_strip
:
23359 case OPT_SPECIAL_unknown
:
23360 case OPT_SPECIAL_ignore
:
23361 case OPT_SPECIAL_program_name
:
23362 case OPT_SPECIAL_input_file
:
23363 case OPT_grecord_gcc_switches
:
23364 case OPT_gno_record_gcc_switches
:
23365 case OPT__output_pch_
:
23366 case OPT_fdiagnostics_show_location_
:
23367 case OPT_fdiagnostics_show_option
:
23368 case OPT_fdiagnostics_show_caret
:
23369 case OPT_fdiagnostics_color_
:
23370 case OPT_fverbose_asm
:
23372 case OPT__sysroot_
:
23374 case OPT_nostdinc__
:
23375 case OPT_fpreprocessed
:
23376 case OPT_fltrans_output_list_
:
23377 case OPT_fresolution_
:
23378 case OPT_fdebug_prefix_map_
:
23379 /* Ignore these. */
23382 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
23383 & CL_NO_DWARF_RECORD
)
23385 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
23387 switch (save_decoded_options
[j
].canonical_option
[0][1])
23394 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
23401 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
23402 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
23406 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
23408 sprintf (tail
, "%s %s", language_string
, version_string
);
23411 FOR_EACH_VEC_ELT (switches
, j
, p
)
23415 memcpy (tail
+ 1, p
, len
);
23423 /* Given a C and/or C++ language/version string return the "highest".
23424 C++ is assumed to be "higher" than C in this case. Used for merging
23425 LTO translation unit languages. */
23426 static const char *
23427 highest_c_language (const char *lang1
, const char *lang2
)
23429 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
23430 return "GNU C++14";
23431 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
23432 return "GNU C++11";
23433 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
23434 return "GNU C++98";
23436 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
23438 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
23440 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
23443 gcc_unreachable ();
23447 /* Generate the DIE for the compilation unit. */
23450 gen_compile_unit_die (const char *filename
)
23453 const char *language_string
= lang_hooks
.name
;
23456 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
23460 add_name_attribute (die
, filename
);
23461 /* Don't add cwd for <built-in>. */
23462 if (filename
[0] != '<')
23463 add_comp_dir_attribute (die
);
23466 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
23468 /* If our producer is LTO try to figure out a common language to use
23469 from the global list of translation units. */
23470 if (strcmp (language_string
, "GNU GIMPLE") == 0)
23474 const char *common_lang
= NULL
;
23476 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
23478 if (!TRANSLATION_UNIT_LANGUAGE (t
))
23481 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
23482 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
23484 else if (strncmp (common_lang
, "GNU C", 5) == 0
23485 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
23486 /* Mixing C and C++ is ok, use C++ in that case. */
23487 common_lang
= highest_c_language (common_lang
,
23488 TRANSLATION_UNIT_LANGUAGE (t
));
23491 /* Fall back to C. */
23492 common_lang
= NULL
;
23498 language_string
= common_lang
;
23501 language
= DW_LANG_C
;
23502 if (strncmp (language_string
, "GNU C", 5) == 0
23503 && ISDIGIT (language_string
[5]))
23505 language
= DW_LANG_C89
;
23506 if (dwarf_version
>= 3 || !dwarf_strict
)
23508 if (strcmp (language_string
, "GNU C89") != 0)
23509 language
= DW_LANG_C99
;
23511 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23512 if (strcmp (language_string
, "GNU C11") == 0)
23513 language
= DW_LANG_C11
;
23516 else if (strncmp (language_string
, "GNU C++", 7) == 0)
23518 language
= DW_LANG_C_plus_plus
;
23519 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23521 if (strcmp (language_string
, "GNU C++11") == 0)
23522 language
= DW_LANG_C_plus_plus_11
;
23523 else if (strcmp (language_string
, "GNU C++14") == 0)
23524 language
= DW_LANG_C_plus_plus_14
;
23527 else if (strcmp (language_string
, "GNU F77") == 0)
23528 language
= DW_LANG_Fortran77
;
23529 else if (strcmp (language_string
, "GNU Pascal") == 0)
23530 language
= DW_LANG_Pascal83
;
23531 else if (dwarf_version
>= 3 || !dwarf_strict
)
23533 if (strcmp (language_string
, "GNU Ada") == 0)
23534 language
= DW_LANG_Ada95
;
23535 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23537 language
= DW_LANG_Fortran95
;
23538 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23540 if (strcmp (language_string
, "GNU Fortran2003") == 0)
23541 language
= DW_LANG_Fortran03
;
23542 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
23543 language
= DW_LANG_Fortran08
;
23546 else if (strcmp (language_string
, "GNU Java") == 0)
23547 language
= DW_LANG_Java
;
23548 else if (strcmp (language_string
, "GNU Objective-C") == 0)
23549 language
= DW_LANG_ObjC
;
23550 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
23551 language
= DW_LANG_ObjC_plus_plus
;
23552 else if (dwarf_version
>= 5 || !dwarf_strict
)
23554 if (strcmp (language_string
, "GNU Go") == 0)
23555 language
= DW_LANG_Go
;
23558 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
23559 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23560 language
= DW_LANG_Fortran90
;
23562 add_AT_unsigned (die
, DW_AT_language
, language
);
23566 case DW_LANG_Fortran77
:
23567 case DW_LANG_Fortran90
:
23568 case DW_LANG_Fortran95
:
23569 case DW_LANG_Fortran03
:
23570 case DW_LANG_Fortran08
:
23571 /* Fortran has case insensitive identifiers and the front-end
23572 lowercases everything. */
23573 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
23576 /* The default DW_ID_case_sensitive doesn't need to be specified. */
23582 /* Generate the DIE for a base class. */
23585 gen_inheritance_die (tree binfo
, tree access
, tree type
,
23586 dw_die_ref context_die
)
23588 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
23589 struct vlr_context ctx
= { type
, NULL
};
23591 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
23593 add_data_member_location_attribute (die
, binfo
, &ctx
);
23595 if (BINFO_VIRTUAL_P (binfo
))
23596 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
23598 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
23599 children, otherwise the default is DW_ACCESS_public. In DWARF2
23600 the default has always been DW_ACCESS_private. */
23601 if (access
== access_public_node
)
23603 if (dwarf_version
== 2
23604 || context_die
->die_tag
== DW_TAG_class_type
)
23605 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
23607 else if (access
== access_protected_node
)
23608 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
23609 else if (dwarf_version
> 2
23610 && context_die
->die_tag
!= DW_TAG_class_type
)
23611 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
23614 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
23617 is_variant_part (tree decl
)
23619 return (TREE_CODE (decl
) == FIELD_DECL
23620 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
23623 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
23624 return the FIELD_DECL. Return NULL_TREE otherwise. */
23627 analyze_discr_in_predicate (tree operand
, tree struct_type
)
23629 bool continue_stripping
= true;
23630 while (continue_stripping
)
23631 switch (TREE_CODE (operand
))
23634 operand
= TREE_OPERAND (operand
, 0);
23637 continue_stripping
= false;
23641 /* Match field access to members of struct_type only. */
23642 if (TREE_CODE (operand
) == COMPONENT_REF
23643 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
23644 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
23645 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
23646 return TREE_OPERAND (operand
, 1);
23651 /* Check that SRC is a constant integer that can be represented as a native
23652 integer constant (either signed or unsigned). If so, store it into DEST and
23653 return true. Return false otherwise. */
23656 get_discr_value (tree src
, dw_discr_value
*dest
)
23658 bool is_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
23660 if (TREE_CODE (src
) != INTEGER_CST
23661 || !(is_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
23664 dest
->pos
= is_unsigned
;
23666 dest
->v
.uval
= tree_to_uhwi (src
);
23668 dest
->v
.sval
= tree_to_shwi (src
);
23673 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
23674 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
23675 store NULL_TREE in DISCR_DECL. Otherwise:
23677 - store the discriminant field in STRUCT_TYPE that controls the variant
23678 part to *DISCR_DECL
23680 - put in *DISCR_LISTS_P an array where for each variant, the item
23681 represents the corresponding matching list of discriminant values.
23683 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
23686 Note that when the array is allocated (i.e. when the analysis is
23687 successful), it is up to the caller to free the array. */
23690 analyze_variants_discr (tree variant_part_decl
,
23693 dw_discr_list_ref
**discr_lists_p
,
23694 unsigned *discr_lists_length
)
23696 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23698 dw_discr_list_ref
*discr_lists
;
23701 /* Compute how many variants there are in this variant part. */
23702 *discr_lists_length
= 0;
23703 for (variant
= TYPE_FIELDS (variant_part_type
);
23704 variant
!= NULL_TREE
;
23705 variant
= DECL_CHAIN (variant
))
23706 ++*discr_lists_length
;
23708 *discr_decl
= NULL_TREE
;
23710 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
23711 sizeof (**discr_lists_p
));
23712 discr_lists
= *discr_lists_p
;
23714 /* And then analyze all variants to extract discriminant information for all
23715 of them. This analysis is conservative: as soon as we detect something we
23716 do not support, abort everything and pretend we found nothing. */
23717 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
23718 variant
!= NULL_TREE
;
23719 variant
= DECL_CHAIN (variant
), ++i
)
23721 tree match_expr
= DECL_QUALIFIER (variant
);
23723 /* Now, try to analyze the predicate and deduce a discriminant for
23725 if (match_expr
== boolean_true_node
)
23726 /* Typically happens for the default variant: it matches all cases that
23727 previous variants rejected. Don't output any matching value for
23731 /* The following loop tries to iterate over each discriminant
23732 possibility: single values or ranges. */
23733 while (match_expr
!= NULL_TREE
)
23735 tree next_round_match_expr
;
23736 tree candidate_discr
= NULL_TREE
;
23737 dw_discr_list_ref new_node
= NULL
;
23739 /* Possibilities are matched one after the other by nested
23740 TRUTH_ORIF_EXPR expressions. Process the current possibility and
23741 continue with the rest at next iteration. */
23742 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
23744 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
23745 match_expr
= TREE_OPERAND (match_expr
, 1);
23748 next_round_match_expr
= NULL_TREE
;
23750 if (match_expr
== boolean_false_node
)
23751 /* This sub-expression matches nothing: just wait for the next
23755 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
23757 /* We are matching: <discr_field> == <integer_cst>
23758 This sub-expression matches a single value. */
23759 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
23762 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
23765 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23766 if (!get_discr_value (integer_cst
,
23767 &new_node
->dw_discr_lower_bound
))
23769 new_node
->dw_discr_range
= false;
23772 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
23774 /* We are matching:
23775 <discr_field> > <integer_cst>
23776 && <discr_field> < <integer_cst>.
23777 This sub-expression matches the range of values between the
23778 two matched integer constants. Note that comparisons can be
23779 inclusive or exclusive. */
23780 tree candidate_discr_1
, candidate_discr_2
;
23781 tree lower_cst
, upper_cst
;
23782 bool lower_cst_included
, upper_cst_included
;
23783 tree lower_op
= TREE_OPERAND (match_expr
, 0);
23784 tree upper_op
= TREE_OPERAND (match_expr
, 1);
23786 /* When the comparison is exclusive, the integer constant is not
23787 the discriminant range bound we are looking for: we will have
23788 to increment or decrement it. */
23789 if (TREE_CODE (lower_op
) == GE_EXPR
)
23790 lower_cst_included
= true;
23791 else if (TREE_CODE (lower_op
) == GT_EXPR
)
23792 lower_cst_included
= false;
23796 if (TREE_CODE (upper_op
) == LE_EXPR
)
23797 upper_cst_included
= true;
23798 else if (TREE_CODE (upper_op
) == LT_EXPR
)
23799 upper_cst_included
= false;
23803 /* Extract the discriminant from the first operand and check it
23804 is consistant with the same analysis in the second
23807 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
23810 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
23812 if (candidate_discr_1
== candidate_discr_2
)
23813 candidate_discr
= candidate_discr_1
;
23817 /* Extract bounds from both. */
23818 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23819 lower_cst
= TREE_OPERAND (lower_op
, 1);
23820 upper_cst
= TREE_OPERAND (upper_op
, 1);
23822 if (!lower_cst_included
)
23824 = fold_build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
), lower_cst
,
23825 build_int_cst (TREE_TYPE (lower_cst
), 1));
23826 if (!upper_cst_included
)
23828 = fold_build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
), upper_cst
,
23829 build_int_cst (TREE_TYPE (upper_cst
), 1));
23831 if (!get_discr_value (lower_cst
,
23832 &new_node
->dw_discr_lower_bound
)
23833 || !get_discr_value (upper_cst
,
23834 &new_node
->dw_discr_upper_bound
))
23837 new_node
->dw_discr_range
= true;
23841 /* Unsupported sub-expression: we cannot determine the set of
23842 matching discriminant values. Abort everything. */
23845 /* If the discriminant info is not consistant with what we saw so
23846 far, consider the analysis failed and abort everything. */
23847 if (candidate_discr
== NULL_TREE
23848 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
23851 *discr_decl
= candidate_discr
;
23853 if (new_node
!= NULL
)
23855 new_node
->dw_discr_next
= discr_lists
[i
];
23856 discr_lists
[i
] = new_node
;
23858 match_expr
= next_round_match_expr
;
23862 /* If we reach this point, we could match everything we were interested
23867 /* Clean all data structure and return no result. */
23868 free (*discr_lists_p
);
23869 *discr_lists_p
= NULL
;
23870 *discr_decl
= NULL_TREE
;
23873 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
23874 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
23877 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
23878 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
23879 this type, which are record types, represent the available variants and each
23880 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
23881 values are inferred from these attributes.
23883 In trees, the offsets for the fields inside these sub-records are relative
23884 to the variant part itself, whereas the corresponding DIEs should have
23885 offset attributes that are relative to the embedding record base address.
23886 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
23887 must be an expression that computes the offset of the variant part to
23888 describe in DWARF. */
23891 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
23892 dw_die_ref context_die
)
23894 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23895 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
23896 struct loc_descr_context ctx
= {
23897 vlr_ctx
->struct_type
, /* context_type */
23898 NULL_TREE
, /* base_decl */
23900 false, /* placeholder_arg */
23901 false /* placeholder_seen */
23904 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
23905 NULL_TREE if there is no such field. */
23906 tree discr_decl
= NULL_TREE
;
23907 dw_discr_list_ref
*discr_lists
;
23908 unsigned discr_lists_length
= 0;
23911 dw_die_ref dwarf_proc_die
= NULL
;
23912 dw_die_ref variant_part_die
23913 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
23915 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
23917 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
23918 &discr_decl
, &discr_lists
, &discr_lists_length
);
23920 if (discr_decl
!= NULL_TREE
)
23922 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
23925 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
23927 /* We have no DIE for the discriminant, so just discard all
23928 discrimimant information in the output. */
23929 discr_decl
= NULL_TREE
;
23932 /* If the offset for this variant part is more complex than a constant,
23933 create a DWARF procedure for it so that we will not have to generate DWARF
23934 expressions for it for each member. */
23935 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
23936 && (dwarf_version
>= 3 || !dwarf_strict
))
23938 const tree dwarf_proc_fndecl
23939 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
23940 build_function_type (TREE_TYPE (variant_part_offset
),
23942 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
23943 const dw_loc_descr_ref dwarf_proc_body
23944 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
23946 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
23947 dwarf_proc_fndecl
, context_die
);
23948 if (dwarf_proc_die
!= NULL
)
23949 variant_part_offset
= dwarf_proc_call
;
23952 /* Output DIEs for all variants. */
23954 for (tree variant
= TYPE_FIELDS (variant_part_type
);
23955 variant
!= NULL_TREE
;
23956 variant
= DECL_CHAIN (variant
), ++i
)
23958 tree variant_type
= TREE_TYPE (variant
);
23959 dw_die_ref variant_die
;
23961 /* All variants (i.e. members of a variant part) are supposed to be
23962 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
23963 under these records. */
23964 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
23966 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
23967 equate_decl_number_to_die (variant
, variant_die
);
23969 /* Output discriminant values this variant matches, if any. */
23970 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
23971 /* In the case we have discriminant information at all, this is
23972 probably the default variant: as the standard says, don't
23973 output any discriminant value/list attribute. */
23975 else if (discr_lists
[i
]->dw_discr_next
== NULL
23976 && !discr_lists
[i
]->dw_discr_range
)
23977 /* If there is only one accepted value, don't bother outputting a
23979 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
23981 add_discr_list (variant_die
, discr_lists
[i
]);
23983 for (tree member
= TYPE_FIELDS (variant_type
);
23984 member
!= NULL_TREE
;
23985 member
= DECL_CHAIN (member
))
23987 struct vlr_context vlr_sub_ctx
= {
23988 vlr_ctx
->struct_type
, /* struct_type */
23989 NULL
/* variant_part_offset */
23991 if (is_variant_part (member
))
23993 /* All offsets for fields inside variant parts are relative to
23994 the top-level embedding RECORD_TYPE's base address. On the
23995 other hand, offsets in GCC's types are relative to the
23996 nested-most variant part. So we have to sum offsets each time
23999 vlr_sub_ctx
.variant_part_offset
24000 = fold_build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
24001 variant_part_offset
, byte_position (member
));
24002 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
24006 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
24007 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
24012 free (discr_lists
);
24015 /* Generate a DIE for a class member. */
24018 gen_member_die (tree type
, dw_die_ref context_die
)
24021 tree binfo
= TYPE_BINFO (type
);
24024 /* If this is not an incomplete type, output descriptions of each of its
24025 members. Note that as we output the DIEs necessary to represent the
24026 members of this record or union type, we will also be trying to output
24027 DIEs to represent the *types* of those members. However the `type'
24028 function (above) will specifically avoid generating type DIEs for member
24029 types *within* the list of member DIEs for this (containing) type except
24030 for those types (of members) which are explicitly marked as also being
24031 members of this (containing) type themselves. The g++ front- end can
24032 force any given type to be treated as a member of some other (containing)
24033 type by setting the TYPE_CONTEXT of the given (member) type to point to
24034 the TREE node representing the appropriate (containing) type. */
24036 /* First output info about the base classes. */
24039 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
24043 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
24044 gen_inheritance_die (base
,
24045 (accesses
? (*accesses
)[i
] : access_public_node
),
24050 /* Now output info about the data members and type members. */
24051 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
24053 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
24055 /* If we thought we were generating minimal debug info for TYPE
24056 and then changed our minds, some of the member declarations
24057 may have already been defined. Don't define them again, but
24058 do put them in the right order. */
24060 child
= lookup_decl_die (member
);
24063 /* Handle inline static data members, which only have in-class
24065 if (child
->die_tag
== DW_TAG_variable
24066 && child
->die_parent
== comp_unit_die ()
24067 && get_AT (child
, DW_AT_specification
) == NULL
)
24069 reparent_child (child
, context_die
);
24070 child
->die_tag
= DW_TAG_member
;
24073 splice_child_die (context_die
, child
);
24076 /* Do not generate standard DWARF for variant parts if we are generating
24077 the corresponding GNAT encodings: DIEs generated for both would
24078 conflict in our mappings. */
24079 else if (is_variant_part (member
)
24080 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
)
24082 vlr_ctx
.variant_part_offset
= byte_position (member
);
24083 gen_variant_part (member
, &vlr_ctx
, context_die
);
24087 vlr_ctx
.variant_part_offset
= NULL_TREE
;
24088 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
24091 /* For C++ inline static data members emit immediately a DW_TAG_variable
24092 DIE that will refer to that DW_TAG_member through
24093 DW_AT_specification. */
24094 if (TREE_STATIC (member
)
24095 && (lang_hooks
.decls
.decl_dwarf_attribute (member
, DW_AT_inline
)
24098 int old_extern
= DECL_EXTERNAL (member
);
24099 DECL_EXTERNAL (member
) = 0;
24100 gen_decl_die (member
, NULL
, NULL
, comp_unit_die ());
24101 DECL_EXTERNAL (member
) = old_extern
;
24105 /* We do not keep type methods in type variants. */
24106 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
24107 /* Now output info about the function members (if any). */
24108 if (TYPE_METHODS (type
) != error_mark_node
)
24109 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
24111 /* Don't include clones in the member list. */
24112 if (DECL_ABSTRACT_ORIGIN (member
))
24114 /* Nor constructors for anonymous classes. */
24115 if (DECL_ARTIFICIAL (member
)
24116 && dwarf2_name (member
, 0) == NULL
)
24119 child
= lookup_decl_die (member
);
24121 splice_child_die (context_die
, child
);
24123 gen_decl_die (member
, NULL
, NULL
, context_die
);
24127 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
24128 is set, we pretend that the type was never defined, so we only get the
24129 member DIEs needed by later specification DIEs. */
24132 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
24133 enum debug_info_usage usage
)
24135 if (TREE_ASM_WRITTEN (type
))
24137 /* Fill in the bound of variable-length fields in late dwarf if
24138 still incomplete. */
24139 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
24140 for (tree member
= TYPE_FIELDS (type
);
24142 member
= DECL_CHAIN (member
))
24143 fill_variable_array_bounds (TREE_TYPE (member
));
24147 dw_die_ref type_die
= lookup_type_die (type
);
24148 dw_die_ref scope_die
= 0;
24150 int complete
= (TYPE_SIZE (type
)
24151 && (! TYPE_STUB_DECL (type
)
24152 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
24153 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
24154 complete
= complete
&& should_emit_struct_debug (type
, usage
);
24156 if (type_die
&& ! complete
)
24159 if (TYPE_CONTEXT (type
) != NULL_TREE
24160 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24161 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
24164 scope_die
= scope_die_for (type
, context_die
);
24166 /* Generate child dies for template paramaters. */
24167 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
24168 schedule_generic_params_dies_gen (type
);
24170 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
24171 /* First occurrence of type or toplevel definition of nested class. */
24173 dw_die_ref old_die
= type_die
;
24175 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
24176 ? record_type_tag (type
) : DW_TAG_union_type
,
24178 equate_type_number_to_die (type
, type_die
);
24180 add_AT_specification (type_die
, old_die
);
24182 add_name_attribute (type_die
, type_tag (type
));
24185 remove_AT (type_die
, DW_AT_declaration
);
24187 /* If this type has been completed, then give it a byte_size attribute and
24188 then give a list of members. */
24189 if (complete
&& !ns_decl
)
24191 /* Prevent infinite recursion in cases where the type of some member of
24192 this type is expressed in terms of this type itself. */
24193 TREE_ASM_WRITTEN (type
) = 1;
24194 add_byte_size_attribute (type_die
, type
);
24195 add_alignment_attribute (type_die
, type
);
24196 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
24198 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
24199 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
24202 /* If the first reference to this type was as the return type of an
24203 inline function, then it may not have a parent. Fix this now. */
24204 if (type_die
->die_parent
== NULL
)
24205 add_child_die (scope_die
, type_die
);
24207 push_decl_scope (type
);
24208 gen_member_die (type
, type_die
);
24211 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
24212 if (TYPE_ARTIFICIAL (type
))
24213 add_AT_flag (type_die
, DW_AT_artificial
, 1);
24215 /* GNU extension: Record what type our vtable lives in. */
24216 if (TYPE_VFIELD (type
))
24218 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
24220 gen_type_die (vtype
, context_die
);
24221 add_AT_die_ref (type_die
, DW_AT_containing_type
,
24222 lookup_type_die (vtype
));
24227 add_AT_flag (type_die
, DW_AT_declaration
, 1);
24229 /* We don't need to do this for function-local types. */
24230 if (TYPE_STUB_DECL (type
)
24231 && ! decl_function_context (TYPE_STUB_DECL (type
)))
24232 vec_safe_push (incomplete_types
, type
);
24235 if (get_AT (type_die
, DW_AT_name
))
24236 add_pubtype (type
, type_die
);
24239 /* Generate a DIE for a subroutine _type_. */
24242 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
24244 tree return_type
= TREE_TYPE (type
);
24245 dw_die_ref subr_die
24246 = new_die (DW_TAG_subroutine_type
,
24247 scope_die_for (type
, context_die
), type
);
24249 equate_type_number_to_die (type
, subr_die
);
24250 add_prototyped_attribute (subr_die
, type
);
24251 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
24253 add_alignment_attribute (subr_die
, type
);
24254 gen_formal_types_die (type
, subr_die
);
24256 if (get_AT (subr_die
, DW_AT_name
))
24257 add_pubtype (type
, subr_die
);
24258 if ((dwarf_version
>= 5 || !dwarf_strict
)
24259 && lang_hooks
.types
.type_dwarf_attribute (type
, DW_AT_reference
) != -1)
24260 add_AT_flag (subr_die
, DW_AT_reference
, 1);
24261 if ((dwarf_version
>= 5 || !dwarf_strict
)
24262 && lang_hooks
.types
.type_dwarf_attribute (type
,
24263 DW_AT_rvalue_reference
) != -1)
24264 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
24267 /* Generate a DIE for a type definition. */
24270 gen_typedef_die (tree decl
, dw_die_ref context_die
)
24272 dw_die_ref type_die
;
24275 if (TREE_ASM_WRITTEN (decl
))
24277 if (DECL_ORIGINAL_TYPE (decl
))
24278 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
24282 TREE_ASM_WRITTEN (decl
) = 1;
24283 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
24284 origin
= decl_ultimate_origin (decl
);
24285 if (origin
!= NULL
)
24286 add_abstract_origin_attribute (type_die
, origin
);
24289 tree type
= TREE_TYPE (decl
);
24291 if (type
== error_mark_node
)
24294 add_name_and_src_coords_attributes (type_die
, decl
);
24295 if (DECL_ORIGINAL_TYPE (decl
))
24297 type
= DECL_ORIGINAL_TYPE (decl
);
24299 if (type
== error_mark_node
)
24302 gcc_assert (type
!= TREE_TYPE (decl
));
24303 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
24307 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24309 /* Here, we are in the case of decl being a typedef naming
24310 an anonymous type, e.g:
24311 typedef struct {...} foo;
24312 In that case TREE_TYPE (decl) is not a typedef variant
24313 type and TYPE_NAME of the anonymous type is set to the
24314 TYPE_DECL of the typedef. This construct is emitted by
24317 TYPE is the anonymous struct named by the typedef
24318 DECL. As we need the DW_AT_type attribute of the
24319 DW_TAG_typedef to point to the DIE of TYPE, let's
24320 generate that DIE right away. add_type_attribute
24321 called below will then pick (via lookup_type_die) that
24322 anonymous struct DIE. */
24323 if (!TREE_ASM_WRITTEN (type
))
24324 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
24326 /* This is a GNU Extension. We are adding a
24327 DW_AT_linkage_name attribute to the DIE of the
24328 anonymous struct TYPE. The value of that attribute
24329 is the name of the typedef decl naming the anonymous
24330 struct. This greatly eases the work of consumers of
24331 this debug info. */
24332 add_linkage_name_raw (lookup_type_die (type
), decl
);
24336 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
24339 if (is_naming_typedef_decl (decl
))
24340 /* We want that all subsequent calls to lookup_type_die with
24341 TYPE in argument yield the DW_TAG_typedef we have just
24343 equate_type_number_to_die (type
, type_die
);
24345 type
= TREE_TYPE (decl
);
24347 add_alignment_attribute (type_die
, type
);
24349 add_accessibility_attribute (type_die
, decl
);
24352 if (DECL_ABSTRACT_P (decl
))
24353 equate_decl_number_to_die (decl
, type_die
);
24355 if (get_AT (type_die
, DW_AT_name
))
24356 add_pubtype (decl
, type_die
);
24359 /* Generate a DIE for a struct, class, enum or union type. */
24362 gen_tagged_type_die (tree type
,
24363 dw_die_ref context_die
,
24364 enum debug_info_usage usage
)
24368 if (type
== NULL_TREE
24369 || !is_tagged_type (type
))
24372 if (TREE_ASM_WRITTEN (type
))
24374 /* If this is a nested type whose containing class hasn't been written
24375 out yet, writing it out will cover this one, too. This does not apply
24376 to instantiations of member class templates; they need to be added to
24377 the containing class as they are generated. FIXME: This hurts the
24378 idea of combining type decls from multiple TUs, since we can't predict
24379 what set of template instantiations we'll get. */
24380 else if (TYPE_CONTEXT (type
)
24381 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24382 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
24384 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
24386 if (TREE_ASM_WRITTEN (type
))
24389 /* If that failed, attach ourselves to the stub. */
24390 push_decl_scope (TYPE_CONTEXT (type
));
24391 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
24394 else if (TYPE_CONTEXT (type
) != NULL_TREE
24395 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
24397 /* If this type is local to a function that hasn't been written
24398 out yet, use a NULL context for now; it will be fixed up in
24399 decls_for_scope. */
24400 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
24401 /* A declaration DIE doesn't count; nested types need to go in the
24403 if (context_die
&& is_declaration_die (context_die
))
24404 context_die
= NULL
;
24409 context_die
= declare_in_namespace (type
, context_die
);
24413 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
24415 /* This might have been written out by the call to
24416 declare_in_namespace. */
24417 if (!TREE_ASM_WRITTEN (type
))
24418 gen_enumeration_type_die (type
, context_die
);
24421 gen_struct_or_union_type_die (type
, context_die
, usage
);
24426 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
24427 it up if it is ever completed. gen_*_type_die will set it for us
24428 when appropriate. */
24431 /* Generate a type description DIE. */
24434 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
24435 enum debug_info_usage usage
)
24437 struct array_descr_info info
;
24439 if (type
== NULL_TREE
|| type
== error_mark_node
)
24442 if (flag_checking
&& type
)
24443 verify_type (type
);
24445 if (TYPE_NAME (type
) != NULL_TREE
24446 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
24447 && is_redundant_typedef (TYPE_NAME (type
))
24448 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
24449 /* The DECL of this type is a typedef we don't want to emit debug
24450 info for but we want debug info for its underlying typedef.
24451 This can happen for e.g, the injected-class-name of a C++
24453 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
24455 /* If TYPE is a typedef type variant, let's generate debug info
24456 for the parent typedef which TYPE is a type of. */
24457 if (typedef_variant_p (type
))
24459 if (TREE_ASM_WRITTEN (type
))
24462 /* Prevent broken recursion; we can't hand off to the same type. */
24463 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
24465 /* Give typedefs the right scope. */
24466 context_die
= scope_die_for (type
, context_die
);
24468 TREE_ASM_WRITTEN (type
) = 1;
24470 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
24474 /* If type is an anonymous tagged type named by a typedef, let's
24475 generate debug info for the typedef. */
24476 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24478 /* Use the DIE of the containing namespace as the parent DIE of
24479 the type description DIE we want to generate. */
24480 if (DECL_CONTEXT (TYPE_NAME (type
))
24481 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
24482 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
24484 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
24488 if (lang_hooks
.types
.get_debug_type
)
24490 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
24492 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
24494 gen_type_die_with_usage (debug_type
, context_die
, usage
);
24499 /* We are going to output a DIE to represent the unqualified version
24500 of this type (i.e. without any const or volatile qualifiers) so
24501 get the main variant (i.e. the unqualified version) of this type
24502 now. (Vectors and arrays are special because the debugging info is in the
24503 cloned type itself. Similarly function/method types can contain extra
24504 ref-qualification). */
24505 if (TREE_CODE (type
) == FUNCTION_TYPE
24506 || TREE_CODE (type
) == METHOD_TYPE
)
24508 /* For function/method types, can't use type_main_variant here,
24509 because that can have different ref-qualifiers for C++,
24510 but try to canonicalize. */
24511 tree main
= TYPE_MAIN_VARIANT (type
);
24512 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
24514 if (check_base_type (t
, main
) && check_lang_type (t
, type
))
24521 else if (TREE_CODE (type
) != VECTOR_TYPE
24522 && TREE_CODE (type
) != ARRAY_TYPE
)
24523 type
= type_main_variant (type
);
24525 /* If this is an array type with hidden descriptor, handle it first. */
24526 if (!TREE_ASM_WRITTEN (type
)
24527 && lang_hooks
.types
.get_array_descr_info
)
24529 memset (&info
, 0, sizeof (info
));
24530 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
24532 /* Fortran sometimes emits array types with no dimension. */
24533 gcc_assert (info
.ndimensions
>= 0
24534 && (info
.ndimensions
24535 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
24536 gen_descr_array_type_die (type
, &info
, context_die
);
24537 TREE_ASM_WRITTEN (type
) = 1;
24542 if (TREE_ASM_WRITTEN (type
))
24544 /* Variable-length types may be incomplete even if
24545 TREE_ASM_WRITTEN. For such types, fall through to
24546 gen_array_type_die() and possibly fill in
24547 DW_AT_{upper,lower}_bound attributes. */
24548 if ((TREE_CODE (type
) != ARRAY_TYPE
24549 && TREE_CODE (type
) != RECORD_TYPE
24550 && TREE_CODE (type
) != UNION_TYPE
24551 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
24552 || !variably_modified_type_p (type
, NULL
))
24556 switch (TREE_CODE (type
))
24562 case REFERENCE_TYPE
:
24563 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
24564 ensures that the gen_type_die recursion will terminate even if the
24565 type is recursive. Recursive types are possible in Ada. */
24566 /* ??? We could perhaps do this for all types before the switch
24568 TREE_ASM_WRITTEN (type
) = 1;
24570 /* For these types, all that is required is that we output a DIE (or a
24571 set of DIEs) to represent the "basis" type. */
24572 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24573 DINFO_USAGE_IND_USE
);
24577 /* This code is used for C++ pointer-to-data-member types.
24578 Output a description of the relevant class type. */
24579 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
24580 DINFO_USAGE_IND_USE
);
24582 /* Output a description of the type of the object pointed to. */
24583 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24584 DINFO_USAGE_IND_USE
);
24586 /* Now output a DIE to represent this pointer-to-data-member type
24588 gen_ptr_to_mbr_type_die (type
, context_die
);
24591 case FUNCTION_TYPE
:
24592 /* Force out return type (in case it wasn't forced out already). */
24593 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24594 DINFO_USAGE_DIR_USE
);
24595 gen_subroutine_type_die (type
, context_die
);
24599 /* Force out return type (in case it wasn't forced out already). */
24600 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24601 DINFO_USAGE_DIR_USE
);
24602 gen_subroutine_type_die (type
, context_die
);
24607 gen_array_type_die (type
, context_die
);
24610 case ENUMERAL_TYPE
:
24613 case QUAL_UNION_TYPE
:
24614 gen_tagged_type_die (type
, context_die
, usage
);
24620 case FIXED_POINT_TYPE
:
24623 case POINTER_BOUNDS_TYPE
:
24624 /* No DIEs needed for fundamental types. */
24629 /* Just use DW_TAG_unspecified_type. */
24631 dw_die_ref type_die
= lookup_type_die (type
);
24632 if (type_die
== NULL
)
24634 tree name
= TYPE_IDENTIFIER (type
);
24635 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
24637 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
24638 equate_type_number_to_die (type
, type_die
);
24644 if (is_cxx_auto (type
))
24646 tree name
= TYPE_IDENTIFIER (type
);
24647 dw_die_ref
*die
= (name
== get_identifier ("auto")
24648 ? &auto_die
: &decltype_auto_die
);
24651 *die
= new_die (DW_TAG_unspecified_type
,
24652 comp_unit_die (), NULL_TREE
);
24653 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
24655 equate_type_number_to_die (type
, *die
);
24658 gcc_unreachable ();
24661 TREE_ASM_WRITTEN (type
) = 1;
24665 gen_type_die (tree type
, dw_die_ref context_die
)
24667 if (type
!= error_mark_node
)
24669 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
24672 dw_die_ref die
= lookup_type_die (type
);
24679 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
24680 things which are local to the given block. */
24683 gen_block_die (tree stmt
, dw_die_ref context_die
)
24685 int must_output_die
= 0;
24688 /* Ignore blocks that are NULL. */
24689 if (stmt
== NULL_TREE
)
24692 inlined_func
= inlined_function_outer_scope_p (stmt
);
24694 /* If the block is one fragment of a non-contiguous block, do not
24695 process the variables, since they will have been done by the
24696 origin block. Do process subblocks. */
24697 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
24701 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
24702 gen_block_die (sub
, context_die
);
24707 /* Determine if we need to output any Dwarf DIEs at all to represent this
24710 /* The outer scopes for inlinings *must* always be represented. We
24711 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
24712 must_output_die
= 1;
24715 /* Determine if this block directly contains any "significant"
24716 local declarations which we will need to output DIEs for. */
24717 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24718 /* We are not in terse mode so *any* local declaration counts
24719 as being a "significant" one. */
24720 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
24721 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
24722 && (TREE_USED (stmt
)
24723 || TREE_ASM_WRITTEN (stmt
)
24724 || BLOCK_ABSTRACT (stmt
)));
24725 else if ((TREE_USED (stmt
)
24726 || TREE_ASM_WRITTEN (stmt
)
24727 || BLOCK_ABSTRACT (stmt
))
24728 && !dwarf2out_ignore_block (stmt
))
24729 must_output_die
= 1;
24732 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
24733 DIE for any block which contains no significant local declarations at
24734 all. Rather, in such cases we just call `decls_for_scope' so that any
24735 needed Dwarf info for any sub-blocks will get properly generated. Note
24736 that in terse mode, our definition of what constitutes a "significant"
24737 local declaration gets restricted to include only inlined function
24738 instances and local (nested) function definitions. */
24739 if (must_output_die
)
24743 /* If STMT block is abstract, that means we have been called
24744 indirectly from dwarf2out_abstract_function.
24745 That function rightfully marks the descendent blocks (of
24746 the abstract function it is dealing with) as being abstract,
24747 precisely to prevent us from emitting any
24748 DW_TAG_inlined_subroutine DIE as a descendent
24749 of an abstract function instance. So in that case, we should
24750 not call gen_inlined_subroutine_die.
24752 Later though, when cgraph asks dwarf2out to emit info
24753 for the concrete instance of the function decl into which
24754 the concrete instance of STMT got inlined, the later will lead
24755 to the generation of a DW_TAG_inlined_subroutine DIE. */
24756 if (! BLOCK_ABSTRACT (stmt
))
24757 gen_inlined_subroutine_die (stmt
, context_die
);
24760 gen_lexical_block_die (stmt
, context_die
);
24763 decls_for_scope (stmt
, context_die
);
24766 /* Process variable DECL (or variable with origin ORIGIN) within
24767 block STMT and add it to CONTEXT_DIE. */
24769 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
24772 tree decl_or_origin
= decl
? decl
: origin
;
24774 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
24775 die
= lookup_decl_die (decl_or_origin
);
24776 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
)
24778 if (TYPE_DECL_IS_STUB (decl_or_origin
))
24779 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
24781 die
= lookup_decl_die (decl_or_origin
);
24782 /* Avoid re-creating the DIE late if it was optimized as unused early. */
24783 if (! die
&& ! early_dwarf
)
24789 if (die
!= NULL
&& die
->die_parent
== NULL
)
24790 add_child_die (context_die
, die
);
24791 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
24794 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
24795 stmt
, context_die
);
24798 gen_decl_die (decl
, origin
, NULL
, context_die
);
24801 /* Generate all of the decls declared within a given scope and (recursively)
24802 all of its sub-blocks. */
24805 decls_for_scope (tree stmt
, dw_die_ref context_die
)
24811 /* Ignore NULL blocks. */
24812 if (stmt
== NULL_TREE
)
24815 /* Output the DIEs to represent all of the data objects and typedefs
24816 declared directly within this block but not within any nested
24817 sub-blocks. Also, nested function and tag DIEs have been
24818 generated with a parent of NULL; fix that up now. We don't
24819 have to do this if we're at -g1. */
24820 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24822 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
24823 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
24824 /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
24825 origin - avoid doing this twice as we have no good way to see
24826 if we've done it once already. */
24828 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
24829 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
24833 /* Even if we're at -g1, we need to process the subblocks in order to get
24834 inlined call information. */
24836 /* Output the DIEs to represent all sub-blocks (and the items declared
24837 therein) of this block. */
24838 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
24840 subblocks
= BLOCK_CHAIN (subblocks
))
24841 gen_block_die (subblocks
, context_die
);
24844 /* Is this a typedef we can avoid emitting? */
24847 is_redundant_typedef (const_tree decl
)
24849 if (TYPE_DECL_IS_STUB (decl
))
24852 if (DECL_ARTIFICIAL (decl
)
24853 && DECL_CONTEXT (decl
)
24854 && is_tagged_type (DECL_CONTEXT (decl
))
24855 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
24856 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
24857 /* Also ignore the artificial member typedef for the class name. */
24863 /* Return TRUE if TYPE is a typedef that names a type for linkage
24864 purposes. This kind of typedefs is produced by the C++ FE for
24867 typedef struct {...} foo;
24869 In that case, there is no typedef variant type produced for foo.
24870 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
24874 is_naming_typedef_decl (const_tree decl
)
24876 if (decl
== NULL_TREE
24877 || TREE_CODE (decl
) != TYPE_DECL
24878 || DECL_NAMELESS (decl
)
24879 || !is_tagged_type (TREE_TYPE (decl
))
24880 || DECL_IS_BUILTIN (decl
)
24881 || is_redundant_typedef (decl
)
24882 /* It looks like Ada produces TYPE_DECLs that are very similar
24883 to C++ naming typedefs but that have different
24884 semantics. Let's be specific to c++ for now. */
24888 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
24889 && TYPE_NAME (TREE_TYPE (decl
)) == decl
24890 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
24891 != TYPE_NAME (TREE_TYPE (decl
))));
24894 /* Looks up the DIE for a context. */
24896 static inline dw_die_ref
24897 lookup_context_die (tree context
)
24901 /* Find die that represents this context. */
24902 if (TYPE_P (context
))
24904 context
= TYPE_MAIN_VARIANT (context
);
24905 dw_die_ref ctx
= lookup_type_die (context
);
24908 return strip_naming_typedef (context
, ctx
);
24911 return lookup_decl_die (context
);
24913 return comp_unit_die ();
24916 /* Returns the DIE for a context. */
24918 static inline dw_die_ref
24919 get_context_die (tree context
)
24923 /* Find die that represents this context. */
24924 if (TYPE_P (context
))
24926 context
= TYPE_MAIN_VARIANT (context
);
24927 return strip_naming_typedef (context
, force_type_die (context
));
24930 return force_decl_die (context
);
24932 return comp_unit_die ();
24935 /* Returns the DIE for decl. A DIE will always be returned. */
24938 force_decl_die (tree decl
)
24940 dw_die_ref decl_die
;
24941 unsigned saved_external_flag
;
24942 tree save_fn
= NULL_TREE
;
24943 decl_die
= lookup_decl_die (decl
);
24946 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
24948 decl_die
= lookup_decl_die (decl
);
24952 switch (TREE_CODE (decl
))
24954 case FUNCTION_DECL
:
24955 /* Clear current_function_decl, so that gen_subprogram_die thinks
24956 that this is a declaration. At this point, we just want to force
24957 declaration die. */
24958 save_fn
= current_function_decl
;
24959 current_function_decl
= NULL_TREE
;
24960 gen_subprogram_die (decl
, context_die
);
24961 current_function_decl
= save_fn
;
24965 /* Set external flag to force declaration die. Restore it after
24966 gen_decl_die() call. */
24967 saved_external_flag
= DECL_EXTERNAL (decl
);
24968 DECL_EXTERNAL (decl
) = 1;
24969 gen_decl_die (decl
, NULL
, NULL
, context_die
);
24970 DECL_EXTERNAL (decl
) = saved_external_flag
;
24973 case NAMESPACE_DECL
:
24974 if (dwarf_version
>= 3 || !dwarf_strict
)
24975 dwarf2out_decl (decl
);
24977 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
24978 decl_die
= comp_unit_die ();
24981 case TRANSLATION_UNIT_DECL
:
24982 decl_die
= comp_unit_die ();
24986 gcc_unreachable ();
24989 /* We should be able to find the DIE now. */
24991 decl_die
= lookup_decl_die (decl
);
24992 gcc_assert (decl_die
);
24998 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
24999 always returned. */
25002 force_type_die (tree type
)
25004 dw_die_ref type_die
;
25006 type_die
= lookup_type_die (type
);
25009 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
25011 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
25012 false, context_die
);
25013 gcc_assert (type_die
);
25018 /* Force out any required namespaces to be able to output DECL,
25019 and return the new context_die for it, if it's changed. */
25022 setup_namespace_context (tree thing
, dw_die_ref context_die
)
25024 tree context
= (DECL_P (thing
)
25025 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
25026 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
25027 /* Force out the namespace. */
25028 context_die
= force_decl_die (context
);
25030 return context_die
;
25033 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
25034 type) within its namespace, if appropriate.
25036 For compatibility with older debuggers, namespace DIEs only contain
25037 declarations; all definitions are emitted at CU scope, with
25038 DW_AT_specification pointing to the declaration (like with class
25042 declare_in_namespace (tree thing
, dw_die_ref context_die
)
25044 dw_die_ref ns_context
;
25046 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25047 return context_die
;
25049 /* External declarations in the local scope only need to be emitted
25050 once, not once in the namespace and once in the scope.
25052 This avoids declaring the `extern' below in the
25053 namespace DIE as well as in the innermost scope:
25066 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
25067 return context_die
;
25069 /* If this decl is from an inlined function, then don't try to emit it in its
25070 namespace, as we will get confused. It would have already been emitted
25071 when the abstract instance of the inline function was emitted anyways. */
25072 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
25073 return context_die
;
25075 ns_context
= setup_namespace_context (thing
, context_die
);
25077 if (ns_context
!= context_die
)
25081 if (DECL_P (thing
))
25082 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
25084 gen_type_die (thing
, ns_context
);
25086 return context_die
;
25089 /* Generate a DIE for a namespace or namespace alias. */
25092 gen_namespace_die (tree decl
, dw_die_ref context_die
)
25094 dw_die_ref namespace_die
;
25096 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
25097 they are an alias of. */
25098 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
25100 /* Output a real namespace or module. */
25101 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25102 namespace_die
= new_die (is_fortran ()
25103 ? DW_TAG_module
: DW_TAG_namespace
,
25104 context_die
, decl
);
25105 /* For Fortran modules defined in different CU don't add src coords. */
25106 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
25108 const char *name
= dwarf2_name (decl
, 0);
25110 add_name_attribute (namespace_die
, name
);
25113 add_name_and_src_coords_attributes (namespace_die
, decl
);
25114 if (DECL_EXTERNAL (decl
))
25115 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
25116 equate_decl_number_to_die (decl
, namespace_die
);
25120 /* Output a namespace alias. */
25122 /* Force out the namespace we are an alias of, if necessary. */
25123 dw_die_ref origin_die
25124 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
25126 if (DECL_FILE_SCOPE_P (decl
)
25127 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
25128 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25129 /* Now create the namespace alias DIE. */
25130 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
25131 add_name_and_src_coords_attributes (namespace_die
, decl
);
25132 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
25133 equate_decl_number_to_die (decl
, namespace_die
);
25135 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
25136 if (want_pubnames ())
25137 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
25140 /* Generate Dwarf debug information for a decl described by DECL.
25141 The return value is currently only meaningful for PARM_DECLs,
25142 for all other decls it returns NULL.
25144 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
25145 It can be NULL otherwise. */
25148 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
25149 dw_die_ref context_die
)
25151 tree decl_or_origin
= decl
? decl
: origin
;
25152 tree class_origin
= NULL
, ultimate_origin
;
25154 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
25157 /* Ignore pointer bounds decls. */
25158 if (DECL_P (decl_or_origin
)
25159 && TREE_TYPE (decl_or_origin
)
25160 && POINTER_BOUNDS_P (decl_or_origin
))
25163 switch (TREE_CODE (decl_or_origin
))
25169 if (!is_fortran () && !is_ada ())
25171 /* The individual enumerators of an enum type get output when we output
25172 the Dwarf representation of the relevant enum type itself. */
25176 /* Emit its type. */
25177 gen_type_die (TREE_TYPE (decl
), context_die
);
25179 /* And its containing namespace. */
25180 context_die
= declare_in_namespace (decl
, context_die
);
25182 gen_const_die (decl
, context_die
);
25185 case FUNCTION_DECL
:
25186 /* Don't output any DIEs to represent mere function declarations,
25187 unless they are class members or explicit block externs. */
25188 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
25189 && DECL_FILE_SCOPE_P (decl_or_origin
)
25190 && (current_function_decl
== NULL_TREE
25191 || DECL_ARTIFICIAL (decl_or_origin
)))
25196 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
25197 on local redeclarations of global functions. That seems broken. */
25198 if (current_function_decl
!= decl
)
25199 /* This is only a declaration. */;
25202 /* If we're emitting a clone, emit info for the abstract instance. */
25203 if (origin
|| DECL_ORIGIN (decl
) != decl
)
25204 dwarf2out_abstract_function (origin
25205 ? DECL_ORIGIN (origin
)
25206 : DECL_ABSTRACT_ORIGIN (decl
));
25208 /* If we're emitting an out-of-line copy of an inline function,
25209 emit info for the abstract instance and set up to refer to it. */
25210 else if (cgraph_function_possibly_inlined_p (decl
)
25211 && ! DECL_ABSTRACT_P (decl
)
25212 && ! class_or_namespace_scope_p (context_die
)
25213 /* dwarf2out_abstract_function won't emit a die if this is just
25214 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
25215 that case, because that works only if we have a die. */
25216 && DECL_INITIAL (decl
) != NULL_TREE
)
25218 dwarf2out_abstract_function (decl
);
25219 set_decl_origin_self (decl
);
25222 /* Otherwise we're emitting the primary DIE for this decl. */
25223 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
25225 /* Before we describe the FUNCTION_DECL itself, make sure that we
25226 have its containing type. */
25228 origin
= decl_class_context (decl
);
25229 if (origin
!= NULL_TREE
)
25230 gen_type_die (origin
, context_die
);
25232 /* And its return type. */
25233 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
25235 /* And its virtual context. */
25236 if (DECL_VINDEX (decl
) != NULL_TREE
)
25237 gen_type_die (DECL_CONTEXT (decl
), context_die
);
25239 /* Make sure we have a member DIE for decl. */
25240 if (origin
!= NULL_TREE
)
25241 gen_type_die_for_member (origin
, decl
, context_die
);
25243 /* And its containing namespace. */
25244 context_die
= declare_in_namespace (decl
, context_die
);
25247 /* Now output a DIE to represent the function itself. */
25249 gen_subprogram_die (decl
, context_die
);
25253 /* If we are in terse mode, don't generate any DIEs to represent any
25254 actual typedefs. */
25255 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25258 /* In the special case of a TYPE_DECL node representing the declaration
25259 of some type tag, if the given TYPE_DECL is marked as having been
25260 instantiated from some other (original) TYPE_DECL node (e.g. one which
25261 was generated within the original definition of an inline function) we
25262 used to generate a special (abbreviated) DW_TAG_structure_type,
25263 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
25264 should be actually referencing those DIEs, as variable DIEs with that
25265 type would be emitted already in the abstract origin, so it was always
25266 removed during unused type prunning. Don't add anything in this
25268 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
25271 if (is_redundant_typedef (decl
))
25272 gen_type_die (TREE_TYPE (decl
), context_die
);
25274 /* Output a DIE to represent the typedef itself. */
25275 gen_typedef_die (decl
, context_die
);
25279 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
25280 gen_label_die (decl
, context_die
);
25285 /* If we are in terse mode, don't generate any DIEs to represent any
25286 variable declarations or definitions. */
25287 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25290 /* Output any DIEs that are needed to specify the type of this data
25292 if (decl_by_reference_p (decl_or_origin
))
25293 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25295 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25297 /* And its containing type. */
25298 class_origin
= decl_class_context (decl_or_origin
);
25299 if (class_origin
!= NULL_TREE
)
25300 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
25302 /* And its containing namespace. */
25303 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
25305 /* Now output the DIE to represent the data object itself. This gets
25306 complicated because of the possibility that the VAR_DECL really
25307 represents an inlined instance of a formal parameter for an inline
25309 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
25310 if (ultimate_origin
!= NULL_TREE
25311 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
25312 gen_formal_parameter_die (decl
, origin
,
25313 true /* Emit name attribute. */,
25316 gen_variable_die (decl
, origin
, context_die
);
25320 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
25321 /* Ignore the nameless fields that are used to skip bits but handle C++
25322 anonymous unions and structs. */
25323 if (DECL_NAME (decl
) != NULL_TREE
25324 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
25325 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
25327 gen_type_die (member_declared_type (decl
), context_die
);
25328 gen_field_die (decl
, ctx
, context_die
);
25333 if (DECL_BY_REFERENCE (decl_or_origin
))
25334 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25336 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25337 return gen_formal_parameter_die (decl
, origin
,
25338 true /* Emit name attribute. */,
25341 case NAMESPACE_DECL
:
25342 if (dwarf_version
>= 3 || !dwarf_strict
)
25343 gen_namespace_die (decl
, context_die
);
25346 case IMPORTED_DECL
:
25347 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
25348 DECL_CONTEXT (decl
), context_die
);
25351 case NAMELIST_DECL
:
25352 gen_namelist_decl (DECL_NAME (decl
), context_die
,
25353 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
25357 /* Probably some frontend-internal decl. Assume we don't care. */
25358 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
25365 /* Output initial debug information for global DECL. Called at the
25366 end of the parsing process.
25368 This is the initial debug generation process. As such, the DIEs
25369 generated may be incomplete. A later debug generation pass
25370 (dwarf2out_late_global_decl) will augment the information generated
25371 in this pass (e.g., with complete location info). */
25374 dwarf2out_early_global_decl (tree decl
)
25378 /* gen_decl_die() will set DECL_ABSTRACT because
25379 cgraph_function_possibly_inlined_p() returns true. This is in
25380 turn will cause DW_AT_inline attributes to be set.
25382 This happens because at early dwarf generation, there is no
25383 cgraph information, causing cgraph_function_possibly_inlined_p()
25384 to return true. Trick cgraph_function_possibly_inlined_p()
25385 while we generate dwarf early. */
25386 bool save
= symtab
->global_info_ready
;
25387 symtab
->global_info_ready
= true;
25389 /* We don't handle TYPE_DECLs. If required, they'll be reached via
25390 other DECLs and they can point to template types or other things
25391 that dwarf2out can't handle when done via dwarf2out_decl. */
25392 if (TREE_CODE (decl
) != TYPE_DECL
25393 && TREE_CODE (decl
) != PARM_DECL
)
25395 tree save_fndecl
= current_function_decl
;
25396 if (TREE_CODE (decl
) == FUNCTION_DECL
)
25398 /* No cfun means the symbol has no body, so there's nothing
25400 if (!DECL_STRUCT_FUNCTION (decl
))
25401 goto early_decl_exit
;
25403 /* For nested functions, make sure we have DIEs for the parents first
25404 so that all nested DIEs are generated at the proper scope in the
25406 tree context
= decl_function_context (decl
);
25407 if (context
!= NULL
&& lookup_decl_die (context
) == NULL
)
25409 current_function_decl
= context
;
25410 dwarf2out_decl (context
);
25413 current_function_decl
= decl
;
25415 dwarf2out_decl (decl
);
25416 if (TREE_CODE (decl
) == FUNCTION_DECL
)
25417 current_function_decl
= save_fndecl
;
25420 symtab
->global_info_ready
= save
;
25423 /* Output debug information for global decl DECL. Called from
25424 toplev.c after compilation proper has finished. */
25427 dwarf2out_late_global_decl (tree decl
)
25429 /* Fill-in any location information we were unable to determine
25430 on the first pass. */
25431 if (VAR_P (decl
) && !POINTER_BOUNDS_P (decl
))
25433 dw_die_ref die
= lookup_decl_die (decl
);
25435 /* We have to generate early debug late for LTO. */
25436 if (! die
&& in_lto_p
)
25438 dwarf2out_decl (decl
);
25439 die
= lookup_decl_die (decl
);
25444 /* We get called via the symtab code invoking late_global_decl
25445 for symbols that are optimized out. Do not add locations
25447 varpool_node
*node
= varpool_node::get (decl
);
25448 if (! node
|| ! node
->definition
)
25449 tree_add_const_value_attribute_for_decl (die
, decl
);
25451 add_location_or_const_value_attribute (die
, decl
, false);
25456 /* Output debug information for type decl DECL. Called from toplev.c
25457 and from language front ends (to record built-in types). */
25459 dwarf2out_type_decl (tree decl
, int local
)
25464 dwarf2out_decl (decl
);
25468 /* Output debug information for imported module or decl DECL.
25469 NAME is non-NULL name in the lexical block if the decl has been renamed.
25470 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
25471 that DECL belongs to.
25472 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
25474 dwarf2out_imported_module_or_decl_1 (tree decl
,
25476 tree lexical_block
,
25477 dw_die_ref lexical_block_die
)
25479 expanded_location xloc
;
25480 dw_die_ref imported_die
= NULL
;
25481 dw_die_ref at_import_die
;
25483 if (TREE_CODE (decl
) == IMPORTED_DECL
)
25485 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
25486 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
25490 xloc
= expand_location (input_location
);
25492 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
25494 at_import_die
= force_type_die (TREE_TYPE (decl
));
25495 /* For namespace N { typedef void T; } using N::T; base_type_die
25496 returns NULL, but DW_TAG_imported_declaration requires
25497 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
25498 if (!at_import_die
)
25500 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
25501 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
25502 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
25503 gcc_assert (at_import_die
);
25508 at_import_die
= lookup_decl_die (decl
);
25509 if (!at_import_die
)
25511 /* If we're trying to avoid duplicate debug info, we may not have
25512 emitted the member decl for this field. Emit it now. */
25513 if (TREE_CODE (decl
) == FIELD_DECL
)
25515 tree type
= DECL_CONTEXT (decl
);
25517 if (TYPE_CONTEXT (type
)
25518 && TYPE_P (TYPE_CONTEXT (type
))
25519 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
25520 DINFO_USAGE_DIR_USE
))
25522 gen_type_die_for_member (type
, decl
,
25523 get_context_die (TYPE_CONTEXT (type
)));
25525 if (TREE_CODE (decl
) == NAMELIST_DECL
)
25526 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
25527 get_context_die (DECL_CONTEXT (decl
)),
25530 at_import_die
= force_decl_die (decl
);
25534 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
25536 if (dwarf_version
>= 3 || !dwarf_strict
)
25537 imported_die
= new_die (DW_TAG_imported_module
,
25544 imported_die
= new_die (DW_TAG_imported_declaration
,
25548 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
25549 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
25551 add_AT_string (imported_die
, DW_AT_name
,
25552 IDENTIFIER_POINTER (name
));
25553 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
25556 /* Output debug information for imported module or decl DECL.
25557 NAME is non-NULL name in context if the decl has been renamed.
25558 CHILD is true if decl is one of the renamed decls as part of
25559 importing whole module. */
25562 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
25565 /* dw_die_ref at_import_die; */
25566 dw_die_ref scope_die
;
25568 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25575 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
25576 We need decl DIE for reference and scope die. First, get DIE for the decl
25579 /* Get the scope die for decl context. Use comp_unit_die for global module
25580 or decl. If die is not found for non globals, force new die. */
25582 && TYPE_P (context
)
25583 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
25586 scope_die
= get_context_die (context
);
25590 /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
25591 there is nothing we can do, here. */
25592 if (dwarf_version
< 3 && dwarf_strict
)
25595 gcc_assert (scope_die
->die_child
);
25596 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
25597 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
25598 scope_die
= scope_die
->die_child
;
25601 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
25602 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
25605 /* Output debug information for namelists. */
25608 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
25610 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
25614 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25617 gcc_assert (scope_die
!= NULL
);
25618 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
25619 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
25621 /* If there are no item_decls, we have a nondefining namelist, e.g.
25622 with USE association; hence, set DW_AT_declaration. */
25623 if (item_decls
== NULL_TREE
)
25625 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
25629 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
25631 nml_item_ref_die
= lookup_decl_die (value
);
25632 if (!nml_item_ref_die
)
25633 nml_item_ref_die
= force_decl_die (value
);
25635 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
25636 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
25642 /* Write the debugging output for DECL and return the DIE. */
25645 dwarf2out_decl (tree decl
)
25647 dw_die_ref context_die
= comp_unit_die ();
25649 switch (TREE_CODE (decl
))
25654 case FUNCTION_DECL
:
25655 /* What we would really like to do here is to filter out all mere
25656 file-scope declarations of file-scope functions which are never
25657 referenced later within this translation unit (and keep all of ones
25658 that *are* referenced later on) but we aren't clairvoyant, so we have
25659 no idea which functions will be referenced in the future (i.e. later
25660 on within the current translation unit). So here we just ignore all
25661 file-scope function declarations which are not also definitions. If
25662 and when the debugger needs to know something about these functions,
25663 it will have to hunt around and find the DWARF information associated
25664 with the definition of the function.
25666 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
25667 nodes represent definitions and which ones represent mere
25668 declarations. We have to check DECL_INITIAL instead. That's because
25669 the C front-end supports some weird semantics for "extern inline"
25670 function definitions. These can get inlined within the current
25671 translation unit (and thus, we need to generate Dwarf info for their
25672 abstract instances so that the Dwarf info for the concrete inlined
25673 instances can have something to refer to) but the compiler never
25674 generates any out-of-lines instances of such things (despite the fact
25675 that they *are* definitions).
25677 The important point is that the C front-end marks these "extern
25678 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
25679 them anyway. Note that the C++ front-end also plays some similar games
25680 for inline function definitions appearing within include files which
25681 also contain `#pragma interface' pragmas.
25683 If we are called from dwarf2out_abstract_function output a DIE
25684 anyway. We can end up here this way with early inlining and LTO
25685 where the inlined function is output in a different LTRANS unit
25687 if (DECL_INITIAL (decl
) == NULL_TREE
25688 && ! DECL_ABSTRACT_P (decl
))
25691 /* If we're a nested function, initially use a parent of NULL; if we're
25692 a plain function, this will be fixed up in decls_for_scope. If
25693 we're a method, it will be ignored, since we already have a DIE. */
25694 if (decl_function_context (decl
)
25695 /* But if we're in terse mode, we don't care about scope. */
25696 && debug_info_level
> DINFO_LEVEL_TERSE
)
25697 context_die
= NULL
;
25701 /* For local statics lookup proper context die. */
25702 if (local_function_static (decl
))
25703 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25705 /* If we are in terse mode, don't generate any DIEs to represent any
25706 variable declarations or definitions. */
25707 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25712 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25714 if (!is_fortran () && !is_ada ())
25716 if (TREE_STATIC (decl
) && decl_function_context (decl
))
25717 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25720 case NAMESPACE_DECL
:
25721 case IMPORTED_DECL
:
25722 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25724 if (lookup_decl_die (decl
) != NULL
)
25729 /* Don't emit stubs for types unless they are needed by other DIEs. */
25730 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
25733 /* Don't bother trying to generate any DIEs to represent any of the
25734 normal built-in types for the language we are compiling. */
25735 if (DECL_IS_BUILTIN (decl
))
25738 /* If we are in terse mode, don't generate any DIEs for types. */
25739 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25742 /* If we're a function-scope tag, initially use a parent of NULL;
25743 this will be fixed up in decls_for_scope. */
25744 if (decl_function_context (decl
))
25745 context_die
= NULL
;
25749 case NAMELIST_DECL
:
25756 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25760 dw_die_ref die
= lookup_decl_die (decl
);
25766 /* Write the debugging output for DECL. */
25769 dwarf2out_function_decl (tree decl
)
25771 dwarf2out_decl (decl
);
25772 call_arg_locations
= NULL
;
25773 call_arg_loc_last
= NULL
;
25774 call_site_count
= -1;
25775 tail_call_site_count
= -1;
25776 decl_loc_table
->empty ();
25777 cached_dw_loc_list_table
->empty ();
25780 /* Output a marker (i.e. a label) for the beginning of the generated code for
25781 a lexical block. */
25784 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
25785 unsigned int blocknum
)
25787 switch_to_section (current_function_section ());
25788 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
25791 /* Output a marker (i.e. a label) for the end of the generated code for a
25795 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
25797 switch_to_section (current_function_section ());
25798 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
25801 /* Returns nonzero if it is appropriate not to emit any debugging
25802 information for BLOCK, because it doesn't contain any instructions.
25804 Don't allow this for blocks with nested functions or local classes
25805 as we would end up with orphans, and in the presence of scheduling
25806 we may end up calling them anyway. */
25809 dwarf2out_ignore_block (const_tree block
)
25814 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
25815 if (TREE_CODE (decl
) == FUNCTION_DECL
25816 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
25818 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
25820 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
25821 if (TREE_CODE (decl
) == FUNCTION_DECL
25822 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
25829 /* Hash table routines for file_hash. */
25832 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
25834 return filename_cmp (p1
->filename
, p2
) == 0;
25838 dwarf_file_hasher::hash (dwarf_file_data
*p
)
25840 return htab_hash_string (p
->filename
);
25843 /* Lookup FILE_NAME (in the list of filenames that we know about here in
25844 dwarf2out.c) and return its "index". The index of each (known) filename is
25845 just a unique number which is associated with only that one filename. We
25846 need such numbers for the sake of generating labels (in the .debug_sfnames
25847 section) and references to those files numbers (in the .debug_srcinfo
25848 and .debug_macinfo sections). If the filename given as an argument is not
25849 found in our current list, add it to the list and assign it the next
25850 available unique index number. */
25852 static struct dwarf_file_data
*
25853 lookup_filename (const char *file_name
)
25855 struct dwarf_file_data
* created
;
25860 dwarf_file_data
**slot
25861 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
25866 created
= ggc_alloc
<dwarf_file_data
> ();
25867 created
->filename
= file_name
;
25868 created
->emitted_number
= 0;
25873 /* If the assembler will construct the file table, then translate the compiler
25874 internal file table number into the assembler file table number, and emit
25875 a .file directive if we haven't already emitted one yet. The file table
25876 numbers are different because we prune debug info for unused variables and
25877 types, which may include filenames. */
25880 maybe_emit_file (struct dwarf_file_data
* fd
)
25882 if (! fd
->emitted_number
)
25884 if (last_emitted_file
)
25885 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
25887 fd
->emitted_number
= 1;
25888 last_emitted_file
= fd
;
25890 if (DWARF2_ASM_LINE_DEBUG_INFO
)
25892 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
25893 output_quoted_string (asm_out_file
,
25894 remap_debug_filename (fd
->filename
));
25895 fputc ('\n', asm_out_file
);
25899 return fd
->emitted_number
;
25902 /* Schedule generation of a DW_AT_const_value attribute to DIE.
25903 That generation should happen after function debug info has been
25904 generated. The value of the attribute is the constant value of ARG. */
25907 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
25909 die_arg_entry entry
;
25914 gcc_assert (early_dwarf
);
25916 if (!tmpl_value_parm_die_table
)
25917 vec_alloc (tmpl_value_parm_die_table
, 32);
25921 vec_safe_push (tmpl_value_parm_die_table
, entry
);
25924 /* Return TRUE if T is an instance of generic type, FALSE
25928 generic_type_p (tree t
)
25930 if (t
== NULL_TREE
|| !TYPE_P (t
))
25932 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
25935 /* Schedule the generation of the generic parameter dies for the
25936 instance of generic type T. The proper generation itself is later
25937 done by gen_scheduled_generic_parms_dies. */
25940 schedule_generic_params_dies_gen (tree t
)
25942 if (!generic_type_p (t
))
25945 gcc_assert (early_dwarf
);
25947 if (!generic_type_instances
)
25948 vec_alloc (generic_type_instances
, 256);
25950 vec_safe_push (generic_type_instances
, t
);
25953 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
25954 by append_entry_to_tmpl_value_parm_die_table. This function must
25955 be called after function DIEs have been generated. */
25958 gen_remaining_tmpl_value_param_die_attribute (void)
25960 if (tmpl_value_parm_die_table
)
25965 /* We do this in two phases - first get the cases we can
25966 handle during early-finish, preserving those we cannot
25967 (containing symbolic constants where we don't yet know
25968 whether we are going to output the referenced symbols).
25969 For those we try again at late-finish. */
25971 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
25973 if (!tree_add_const_value_attribute (e
->die
, e
->arg
))
25975 dw_loc_descr_ref loc
= NULL
;
25977 && (dwarf_version
>= 5 || !dwarf_strict
))
25978 loc
= loc_descriptor_from_tree (e
->arg
, 2, NULL
);
25980 add_AT_loc (e
->die
, DW_AT_location
, loc
);
25982 (*tmpl_value_parm_die_table
)[j
++] = *e
;
25985 tmpl_value_parm_die_table
->truncate (j
);
25989 /* Generate generic parameters DIEs for instances of generic types
25990 that have been previously scheduled by
25991 schedule_generic_params_dies_gen. This function must be called
25992 after all the types of the CU have been laid out. */
25995 gen_scheduled_generic_parms_dies (void)
26000 if (!generic_type_instances
)
26003 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
26004 if (COMPLETE_TYPE_P (t
))
26005 gen_generic_params_dies (t
);
26007 generic_type_instances
= NULL
;
26011 /* Replace DW_AT_name for the decl with name. */
26014 dwarf2out_set_name (tree decl
, tree name
)
26017 dw_attr_node
*attr
;
26020 die
= TYPE_SYMTAB_DIE (decl
);
26024 dname
= dwarf2_name (name
, 0);
26028 attr
= get_AT (die
, DW_AT_name
);
26031 struct indirect_string_node
*node
;
26033 node
= find_AT_string (dname
);
26034 /* replace the string. */
26035 attr
->dw_attr_val
.v
.val_str
= node
;
26039 add_name_attribute (die
, dname
);
26042 /* True if before or during processing of the first function being emitted. */
26043 static bool in_first_function_p
= true;
26044 /* True if loc_note during dwarf2out_var_location call might still be
26045 before first real instruction at address equal to .Ltext0. */
26046 static bool maybe_at_text_label_p
= true;
26047 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
26048 static unsigned int first_loclabel_num_not_at_text_label
;
26050 /* Called by the final INSN scan whenever we see a var location. We
26051 use it to drop labels in the right places, and throw the location in
26052 our lookup table. */
26055 dwarf2out_var_location (rtx_insn
*loc_note
)
26057 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
26058 struct var_loc_node
*newloc
;
26059 rtx_insn
*next_real
, *next_note
;
26060 rtx_insn
*call_insn
= NULL
;
26061 static const char *last_label
;
26062 static const char *last_postcall_label
;
26063 static bool last_in_cold_section_p
;
26064 static rtx_insn
*expected_next_loc_note
;
26068 if (!NOTE_P (loc_note
))
26070 if (CALL_P (loc_note
))
26073 if (SIBLING_CALL_P (loc_note
))
26074 tail_call_site_count
++;
26075 if (optimize
== 0 && !flag_var_tracking
)
26077 /* When the var-tracking pass is not running, there is no note
26078 for indirect calls whose target is compile-time known. In this
26079 case, process such calls specifically so that we generate call
26080 sites for them anyway. */
26081 rtx x
= PATTERN (loc_note
);
26082 if (GET_CODE (x
) == PARALLEL
)
26083 x
= XVECEXP (x
, 0, 0);
26084 if (GET_CODE (x
) == SET
)
26086 if (GET_CODE (x
) == CALL
)
26089 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
26090 || !SYMBOL_REF_DECL (XEXP (x
, 0))
26091 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
26094 call_insn
= loc_note
;
26098 next_real
= next_real_insn (call_insn
);
26100 cached_next_real_insn
= NULL
;
26108 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
26109 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
26112 /* Optimize processing a large consecutive sequence of location
26113 notes so we don't spend too much time in next_real_insn. If the
26114 next insn is another location note, remember the next_real_insn
26115 calculation for next time. */
26116 next_real
= cached_next_real_insn
;
26119 if (expected_next_loc_note
!= loc_note
)
26123 next_note
= NEXT_INSN (loc_note
);
26125 || next_note
->deleted ()
26126 || ! NOTE_P (next_note
)
26127 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
26128 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
26132 next_real
= next_real_insn (loc_note
);
26136 expected_next_loc_note
= next_note
;
26137 cached_next_real_insn
= next_real
;
26140 cached_next_real_insn
= NULL
;
26142 /* If there are no instructions which would be affected by this note,
26143 don't do anything. */
26145 && next_real
== NULL_RTX
26146 && !NOTE_DURING_CALL_P (loc_note
))
26151 if (next_real
== NULL_RTX
)
26152 next_real
= get_last_insn ();
26154 /* If there were any real insns between note we processed last time
26155 and this note (or if it is the first note), clear
26156 last_{,postcall_}label so that they are not reused this time. */
26157 if (last_var_location_insn
== NULL_RTX
26158 || last_var_location_insn
!= next_real
26159 || last_in_cold_section_p
!= in_cold_section_p
)
26162 last_postcall_label
= NULL
;
26167 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
26168 newloc
= add_var_loc_to_decl (decl
, loc_note
,
26169 NOTE_DURING_CALL_P (loc_note
)
26170 ? last_postcall_label
: last_label
);
26171 if (newloc
== NULL
)
26180 /* If there were no real insns between note we processed last time
26181 and this note, use the label we emitted last time. Otherwise
26182 create a new label and emit it. */
26183 if (last_label
== NULL
)
26185 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
26186 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
26188 last_label
= ggc_strdup (loclabel
);
26189 /* See if loclabel might be equal to .Ltext0. If yes,
26190 bump first_loclabel_num_not_at_text_label. */
26191 if (!have_multiple_function_sections
26192 && in_first_function_p
26193 && maybe_at_text_label_p
)
26195 static rtx_insn
*last_start
;
26197 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
26198 if (insn
== last_start
)
26200 else if (!NONDEBUG_INSN_P (insn
))
26204 rtx body
= PATTERN (insn
);
26205 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
26207 /* Inline asm could occupy zero bytes. */
26208 else if (GET_CODE (body
) == ASM_INPUT
26209 || asm_noperands (body
) >= 0)
26211 #ifdef HAVE_attr_length
26212 else if (get_attr_min_length (insn
) == 0)
26217 /* Assume insn has non-zero length. */
26218 maybe_at_text_label_p
= false;
26222 if (maybe_at_text_label_p
)
26224 last_start
= loc_note
;
26225 first_loclabel_num_not_at_text_label
= loclabel_num
;
26230 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
26231 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
26235 struct call_arg_loc_node
*ca_loc
26236 = ggc_cleared_alloc
<call_arg_loc_node
> ();
26238 = loc_note
!= NULL_RTX
? prev_real_insn (loc_note
) : call_insn
;
26240 ca_loc
->call_arg_loc_note
= loc_note
;
26241 ca_loc
->next
= NULL
;
26242 ca_loc
->label
= last_label
;
26245 || (NONJUMP_INSN_P (prev
)
26246 && GET_CODE (PATTERN (prev
)) == SEQUENCE
26247 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
26248 if (!CALL_P (prev
))
26249 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
26250 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
26252 /* Look for a SYMBOL_REF in the "prev" instruction. */
26253 rtx x
= get_call_rtx_from (PATTERN (prev
));
26256 /* Try to get the call symbol, if any. */
26257 if (MEM_P (XEXP (x
, 0)))
26259 /* First, look for a memory access to a symbol_ref. */
26260 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
26261 && SYMBOL_REF_DECL (XEXP (x
, 0))
26262 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
26263 ca_loc
->symbol_ref
= XEXP (x
, 0);
26264 /* Otherwise, look at a compile-time known user-level function
26268 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
26269 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
26272 ca_loc
->block
= insn_scope (prev
);
26273 if (call_arg_locations
)
26274 call_arg_loc_last
->next
= ca_loc
;
26276 call_arg_locations
= ca_loc
;
26277 call_arg_loc_last
= ca_loc
;
26279 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
26280 newloc
->label
= last_label
;
26283 if (!last_postcall_label
)
26285 sprintf (loclabel
, "%s-1", last_label
);
26286 last_postcall_label
= ggc_strdup (loclabel
);
26288 newloc
->label
= last_postcall_label
;
26291 last_var_location_insn
= next_real
;
26292 last_in_cold_section_p
= in_cold_section_p
;
26295 /* Called from finalize_size_functions for size functions so that their body
26296 can be encoded in the debug info to describe the layout of variable-length
26300 dwarf2out_size_function (tree decl
)
26302 function_to_dwarf_procedure (decl
);
26305 /* Note in one location list that text section has changed. */
26308 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
26310 var_loc_list
*list
= *slot
;
26312 list
->last_before_switch
26313 = list
->last
->next
? list
->last
->next
: list
->last
;
26317 /* Note in all location lists that text section has changed. */
26320 var_location_switch_text_section (void)
26322 if (decl_loc_table
== NULL
)
26325 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
26328 /* Create a new line number table. */
26330 static dw_line_info_table
*
26331 new_line_info_table (void)
26333 dw_line_info_table
*table
;
26335 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
26336 table
->file_num
= 1;
26337 table
->line_num
= 1;
26338 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
26343 /* Lookup the "current" table into which we emit line info, so
26344 that we don't have to do it for every source line. */
26347 set_cur_line_info_table (section
*sec
)
26349 dw_line_info_table
*table
;
26351 if (sec
== text_section
)
26352 table
= text_section_line_info
;
26353 else if (sec
== cold_text_section
)
26355 table
= cold_text_section_line_info
;
26358 cold_text_section_line_info
= table
= new_line_info_table ();
26359 table
->end_label
= cold_end_label
;
26364 const char *end_label
;
26366 if (flag_reorder_blocks_and_partition
)
26368 if (in_cold_section_p
)
26369 end_label
= crtl
->subsections
.cold_section_end_label
;
26371 end_label
= crtl
->subsections
.hot_section_end_label
;
26375 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26376 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
26377 current_function_funcdef_no
);
26378 end_label
= ggc_strdup (label
);
26381 table
= new_line_info_table ();
26382 table
->end_label
= end_label
;
26384 vec_safe_push (separate_line_info
, table
);
26387 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26388 table
->is_stmt
= (cur_line_info_table
26389 ? cur_line_info_table
->is_stmt
26390 : DWARF_LINE_DEFAULT_IS_STMT_START
);
26391 cur_line_info_table
= table
;
26395 /* We need to reset the locations at the beginning of each
26396 function. We can't do this in the end_function hook, because the
26397 declarations that use the locations won't have been output when
26398 that hook is called. Also compute have_multiple_function_sections here. */
26401 dwarf2out_begin_function (tree fun
)
26403 section
*sec
= function_section (fun
);
26405 if (sec
!= text_section
)
26406 have_multiple_function_sections
= true;
26408 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
26410 gcc_assert (current_function_decl
== fun
);
26411 cold_text_section
= unlikely_text_section ();
26412 switch_to_section (cold_text_section
);
26413 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
26414 switch_to_section (sec
);
26417 dwarf2out_note_section_used ();
26418 call_site_count
= 0;
26419 tail_call_site_count
= 0;
26421 set_cur_line_info_table (sec
);
26424 /* Helper function of dwarf2out_end_function, called only after emitting
26425 the very first function into assembly. Check if some .debug_loc range
26426 might end with a .LVL* label that could be equal to .Ltext0.
26427 In that case we must force using absolute addresses in .debug_loc ranges,
26428 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
26429 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
26431 Set have_multiple_function_sections to true in that case and
26432 terminate htab traversal. */
26435 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
26437 var_loc_list
*entry
= *slot
;
26438 struct var_loc_node
*node
;
26440 node
= entry
->first
;
26441 if (node
&& node
->next
&& node
->next
->label
)
26444 const char *label
= node
->next
->label
;
26445 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
26447 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
26449 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
26450 if (strcmp (label
, loclabel
) == 0)
26452 have_multiple_function_sections
= true;
26460 /* Hook called after emitting a function into assembly.
26461 This does something only for the very first function emitted. */
26464 dwarf2out_end_function (unsigned int)
26466 if (in_first_function_p
26467 && !have_multiple_function_sections
26468 && first_loclabel_num_not_at_text_label
26470 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
26471 in_first_function_p
= false;
26472 maybe_at_text_label_p
= false;
26475 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
26476 front-ends register a translation unit even before dwarf2out_init is
26478 static tree main_translation_unit
= NULL_TREE
;
26480 /* Hook called by front-ends after they built their main translation unit.
26481 Associate comp_unit_die to UNIT. */
26484 dwarf2out_register_main_translation_unit (tree unit
)
26486 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
26487 && main_translation_unit
== NULL_TREE
);
26488 main_translation_unit
= unit
;
26489 /* If dwarf2out_init has not been called yet, it will perform the association
26490 itself looking at main_translation_unit. */
26491 if (decl_die_table
!= NULL
)
26492 equate_decl_number_to_die (unit
, comp_unit_die ());
26495 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
26498 push_dw_line_info_entry (dw_line_info_table
*table
,
26499 enum dw_line_info_opcode opcode
, unsigned int val
)
26501 dw_line_info_entry e
;
26504 vec_safe_push (table
->entries
, e
);
26507 /* Output a label to mark the beginning of a source code line entry
26508 and record information relating to this source line, in
26509 'line_info_table' for later output of the .debug_line section. */
26510 /* ??? The discriminator parameter ought to be unsigned. */
26513 dwarf2out_source_line (unsigned int line
, const char *filename
,
26514 int discriminator
, bool is_stmt
)
26516 unsigned int file_num
;
26517 dw_line_info_table
*table
;
26519 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
26522 /* The discriminator column was added in dwarf4. Simplify the below
26523 by simply removing it if we're not supposed to output it. */
26524 if (dwarf_version
< 4 && dwarf_strict
)
26527 table
= cur_line_info_table
;
26528 file_num
= maybe_emit_file (lookup_filename (filename
));
26530 /* ??? TODO: Elide duplicate line number entries. Traditionally,
26531 the debugger has used the second (possibly duplicate) line number
26532 at the beginning of the function to mark the end of the prologue.
26533 We could eliminate any other duplicates within the function. For
26534 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
26535 that second line number entry. */
26536 /* Recall that this end-of-prologue indication is *not* the same thing
26537 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
26538 to which the hook corresponds, follows the last insn that was
26539 emitted by gen_prologue. What we need is to precede the first insn
26540 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
26541 insn that corresponds to something the user wrote. These may be
26542 very different locations once scheduling is enabled. */
26544 if (0 && file_num
== table
->file_num
26545 && line
== table
->line_num
26546 && discriminator
== table
->discrim_num
26547 && is_stmt
== table
->is_stmt
)
26550 switch_to_section (current_function_section ());
26552 /* If requested, emit something human-readable. */
26553 if (flag_debug_asm
)
26554 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
26556 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26558 /* Emit the .loc directive understood by GNU as. */
26559 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
26560 file_num, line, is_stmt, discriminator */
26561 fputs ("\t.loc ", asm_out_file
);
26562 fprint_ul (asm_out_file
, file_num
);
26563 putc (' ', asm_out_file
);
26564 fprint_ul (asm_out_file
, line
);
26565 putc (' ', asm_out_file
);
26566 putc ('0', asm_out_file
);
26568 if (is_stmt
!= table
->is_stmt
)
26570 fputs (" is_stmt ", asm_out_file
);
26571 putc (is_stmt
? '1' : '0', asm_out_file
);
26573 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
26575 gcc_assert (discriminator
> 0);
26576 fputs (" discriminator ", asm_out_file
);
26577 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
26579 putc ('\n', asm_out_file
);
26583 unsigned int label_num
= ++line_info_label_num
;
26585 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
26587 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
26588 if (file_num
!= table
->file_num
)
26589 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
26590 if (discriminator
!= table
->discrim_num
)
26591 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
26592 if (is_stmt
!= table
->is_stmt
)
26593 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
26594 push_dw_line_info_entry (table
, LI_set_line
, line
);
26597 table
->file_num
= file_num
;
26598 table
->line_num
= line
;
26599 table
->discrim_num
= discriminator
;
26600 table
->is_stmt
= is_stmt
;
26601 table
->in_use
= true;
26604 /* Record the beginning of a new source file. */
26607 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
26609 if (flag_eliminate_dwarf2_dups
)
26611 /* Record the beginning of the file for break_out_includes. */
26612 dw_die_ref bincl_die
;
26614 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
26615 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
26618 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26621 e
.code
= DW_MACINFO_start_file
;
26623 e
.info
= ggc_strdup (filename
);
26624 vec_safe_push (macinfo_table
, e
);
26628 /* Record the end of a source file. */
26631 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
26633 if (flag_eliminate_dwarf2_dups
)
26634 /* Record the end of the file for break_out_includes. */
26635 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
26637 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26640 e
.code
= DW_MACINFO_end_file
;
26643 vec_safe_push (macinfo_table
, e
);
26647 /* Called from debug_define in toplev.c. The `buffer' parameter contains
26648 the tail part of the directive line, i.e. the part which is past the
26649 initial whitespace, #, whitespace, directive-name, whitespace part. */
26652 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
26653 const char *buffer ATTRIBUTE_UNUSED
)
26655 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26658 /* Insert a dummy first entry to be able to optimize the whole
26659 predefined macro block using DW_MACRO_import. */
26660 if (macinfo_table
->is_empty () && lineno
<= 1)
26665 vec_safe_push (macinfo_table
, e
);
26667 e
.code
= DW_MACINFO_define
;
26669 e
.info
= ggc_strdup (buffer
);
26670 vec_safe_push (macinfo_table
, e
);
26674 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
26675 the tail part of the directive line, i.e. the part which is past the
26676 initial whitespace, #, whitespace, directive-name, whitespace part. */
26679 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
26680 const char *buffer ATTRIBUTE_UNUSED
)
26682 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26685 /* Insert a dummy first entry to be able to optimize the whole
26686 predefined macro block using DW_MACRO_import. */
26687 if (macinfo_table
->is_empty () && lineno
<= 1)
26692 vec_safe_push (macinfo_table
, e
);
26694 e
.code
= DW_MACINFO_undef
;
26696 e
.info
= ggc_strdup (buffer
);
26697 vec_safe_push (macinfo_table
, e
);
26701 /* Helpers to manipulate hash table of CUs. */
26703 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
26705 static inline hashval_t
hash (const macinfo_entry
*);
26706 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
26710 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
26712 return htab_hash_string (entry
->info
);
26716 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
26717 const macinfo_entry
*entry2
)
26719 return !strcmp (entry1
->info
, entry2
->info
);
26722 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
26724 /* Output a single .debug_macinfo entry. */
26727 output_macinfo_op (macinfo_entry
*ref
)
26731 struct indirect_string_node
*node
;
26732 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26733 struct dwarf_file_data
*fd
;
26737 case DW_MACINFO_start_file
:
26738 fd
= lookup_filename (ref
->info
);
26739 file_num
= maybe_emit_file (fd
);
26740 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
26741 dw2_asm_output_data_uleb128 (ref
->lineno
,
26742 "Included from line number %lu",
26743 (unsigned long) ref
->lineno
);
26744 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
26746 case DW_MACINFO_end_file
:
26747 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
26749 case DW_MACINFO_define
:
26750 case DW_MACINFO_undef
:
26751 len
= strlen (ref
->info
) + 1;
26753 && len
> DWARF_OFFSET_SIZE
26754 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
26755 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
26757 ref
->code
= ref
->code
== DW_MACINFO_define
26758 ? DW_MACRO_define_strp
: DW_MACRO_undef_strp
;
26759 output_macinfo_op (ref
);
26762 dw2_asm_output_data (1, ref
->code
,
26763 ref
->code
== DW_MACINFO_define
26764 ? "Define macro" : "Undefine macro");
26765 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
26766 (unsigned long) ref
->lineno
);
26767 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
26769 case DW_MACRO_define_strp
:
26770 case DW_MACRO_undef_strp
:
26771 node
= find_AT_string (ref
->info
);
26773 && (node
->form
== DW_FORM_strp
26774 || node
->form
== DW_FORM_GNU_str_index
));
26775 dw2_asm_output_data (1, ref
->code
,
26776 ref
->code
== DW_MACRO_define_strp
26777 ? "Define macro strp"
26778 : "Undefine macro strp");
26779 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
26780 (unsigned long) ref
->lineno
);
26781 if (node
->form
== DW_FORM_strp
)
26782 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
26783 debug_str_section
, "The macro: \"%s\"",
26786 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
26789 case DW_MACRO_import
:
26790 dw2_asm_output_data (1, ref
->code
, "Import");
26791 ASM_GENERATE_INTERNAL_LABEL (label
,
26792 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
26793 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
26796 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
26797 ASM_COMMENT_START
, (unsigned long) ref
->code
);
26802 /* Attempt to make a sequence of define/undef macinfo ops shareable with
26803 other compilation unit .debug_macinfo sections. IDX is the first
26804 index of a define/undef, return the number of ops that should be
26805 emitted in a comdat .debug_macinfo section and emit
26806 a DW_MACRO_import entry referencing it.
26807 If the define/undef entry should be emitted normally, return 0. */
26810 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
26811 macinfo_hash_type
**macinfo_htab
)
26813 macinfo_entry
*first
, *second
, *cur
, *inc
;
26814 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
26815 unsigned char checksum
[16];
26816 struct md5_ctx ctx
;
26817 char *grp_name
, *tail
;
26819 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
26820 macinfo_entry
**slot
;
26822 first
= &(*macinfo_table
)[idx
];
26823 second
= &(*macinfo_table
)[idx
+ 1];
26825 /* Optimize only if there are at least two consecutive define/undef ops,
26826 and either all of them are before first DW_MACINFO_start_file
26827 with lineno {0,1} (i.e. predefined macro block), or all of them are
26828 in some included header file. */
26829 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
26831 if (vec_safe_is_empty (files
))
26833 if (first
->lineno
> 1 || second
->lineno
> 1)
26836 else if (first
->lineno
== 0)
26839 /* Find the last define/undef entry that can be grouped together
26840 with first and at the same time compute md5 checksum of their
26841 codes, linenumbers and strings. */
26842 md5_init_ctx (&ctx
);
26843 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
26844 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
26846 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
26850 unsigned char code
= cur
->code
;
26851 md5_process_bytes (&code
, 1, &ctx
);
26852 checksum_uleb128 (cur
->lineno
, &ctx
);
26853 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
26855 md5_finish_ctx (&ctx
, checksum
);
26858 /* From the containing include filename (if any) pick up just
26859 usable characters from its basename. */
26860 if (vec_safe_is_empty (files
))
26863 base
= lbasename (files
->last ().info
);
26864 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
26865 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
26866 encoded_filename_len
++;
26867 /* Count . at the end. */
26868 if (encoded_filename_len
)
26869 encoded_filename_len
++;
26871 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
26872 linebuf_len
= strlen (linebuf
);
26874 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
26875 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
26877 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
26878 tail
= grp_name
+ 4;
26879 if (encoded_filename_len
)
26881 for (i
= 0; base
[i
]; i
++)
26882 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
26886 memcpy (tail
, linebuf
, linebuf_len
);
26887 tail
+= linebuf_len
;
26889 for (i
= 0; i
< 16; i
++)
26890 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
26892 /* Construct a macinfo_entry for DW_MACRO_import
26893 in the empty vector entry before the first define/undef. */
26894 inc
= &(*macinfo_table
)[idx
- 1];
26895 inc
->code
= DW_MACRO_import
;
26897 inc
->info
= ggc_strdup (grp_name
);
26898 if (!*macinfo_htab
)
26899 *macinfo_htab
= new macinfo_hash_type (10);
26900 /* Avoid emitting duplicates. */
26901 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
26906 /* If such an entry has been used before, just emit
26907 a DW_MACRO_import op. */
26909 output_macinfo_op (inc
);
26910 /* And clear all macinfo_entry in the range to avoid emitting them
26911 in the second pass. */
26912 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
26921 inc
->lineno
= (*macinfo_htab
)->elements ();
26922 output_macinfo_op (inc
);
26927 /* Save any strings needed by the macinfo table in the debug str
26928 table. All strings must be collected into the table by the time
26929 index_string is called. */
26932 save_macinfo_strings (void)
26936 macinfo_entry
*ref
;
26938 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
26942 /* Match the logic in output_macinfo_op to decide on
26943 indirect strings. */
26944 case DW_MACINFO_define
:
26945 case DW_MACINFO_undef
:
26946 len
= strlen (ref
->info
) + 1;
26948 && len
> DWARF_OFFSET_SIZE
26949 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
26950 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
26951 set_indirect_string (find_AT_string (ref
->info
));
26953 case DW_MACRO_define_strp
:
26954 case DW_MACRO_undef_strp
:
26955 set_indirect_string (find_AT_string (ref
->info
));
26963 /* Output macinfo section(s). */
26966 output_macinfo (void)
26969 unsigned long length
= vec_safe_length (macinfo_table
);
26970 macinfo_entry
*ref
;
26971 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
26972 macinfo_hash_type
*macinfo_htab
= NULL
;
26977 /* output_macinfo* uses these interchangeably. */
26978 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_define
26979 && (int) DW_MACINFO_undef
== (int) DW_MACRO_undef
26980 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_start_file
26981 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_end_file
);
26983 /* For .debug_macro emit the section header. */
26984 if (!dwarf_strict
|| dwarf_version
>= 5)
26986 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
26987 "DWARF macro version number");
26988 if (DWARF_OFFSET_SIZE
== 8)
26989 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
26991 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
26992 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
26993 (!dwarf_split_debug_info
? debug_line_section_label
26994 : debug_skeleton_line_section_label
),
26995 debug_line_section
, NULL
);
26998 /* In the first loop, it emits the primary .debug_macinfo section
26999 and after each emitted op the macinfo_entry is cleared.
27000 If a longer range of define/undef ops can be optimized using
27001 DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
27002 the vector before the first define/undef in the range and the
27003 whole range of define/undef ops is not emitted and kept. */
27004 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
27008 case DW_MACINFO_start_file
:
27009 vec_safe_push (files
, *ref
);
27011 case DW_MACINFO_end_file
:
27012 if (!vec_safe_is_empty (files
))
27015 case DW_MACINFO_define
:
27016 case DW_MACINFO_undef
:
27017 if ((!dwarf_strict
|| dwarf_version
>= 5)
27018 && HAVE_COMDAT_GROUP
27019 && vec_safe_length (files
) != 1
27022 && (*macinfo_table
)[i
- 1].code
== 0)
27024 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
27033 /* A dummy entry may be inserted at the beginning to be able
27034 to optimize the whole block of predefined macros. */
27040 output_macinfo_op (ref
);
27048 delete macinfo_htab
;
27049 macinfo_htab
= NULL
;
27051 /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
27052 terminate the current chain and switch to a new comdat .debug_macinfo
27053 section and emit the define/undef entries within it. */
27054 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
27059 case DW_MACRO_import
:
27061 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
27062 tree comdat_key
= get_identifier (ref
->info
);
27063 /* Terminate the previous .debug_macinfo section. */
27064 dw2_asm_output_data (1, 0, "End compilation unit");
27065 targetm
.asm_out
.named_section (debug_macinfo_section_name
,
27067 | SECTION_LINKONCE
,
27069 ASM_GENERATE_INTERNAL_LABEL (label
,
27070 DEBUG_MACRO_SECTION_LABEL
,
27072 ASM_OUTPUT_LABEL (asm_out_file
, label
);
27075 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
27076 "DWARF macro version number");
27077 if (DWARF_OFFSET_SIZE
== 8)
27078 dw2_asm_output_data (1, 1, "Flags: 64-bit");
27080 dw2_asm_output_data (1, 0, "Flags: 32-bit");
27083 case DW_MACINFO_define
:
27084 case DW_MACINFO_undef
:
27085 output_macinfo_op (ref
);
27090 gcc_unreachable ();
27094 /* Initialize the various sections and labels for dwarf output. */
27097 init_sections_and_labels (void)
27099 if (!dwarf_split_debug_info
)
27101 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
27102 SECTION_DEBUG
, NULL
);
27103 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27104 SECTION_DEBUG
, NULL
);
27105 debug_loc_section
= get_section (dwarf_version
>= 5
27106 ? DEBUG_LOCLISTS_SECTION
27107 : DEBUG_LOC_SECTION
,
27108 SECTION_DEBUG
, NULL
);
27109 debug_macinfo_section_name
27110 = (dwarf_strict
&& dwarf_version
< 5)
27111 ? DEBUG_MACINFO_SECTION
: DEBUG_MACRO_SECTION
;
27112 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27113 SECTION_DEBUG
, NULL
);
27117 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
27118 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27119 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
27120 SECTION_DEBUG
| SECTION_EXCLUDE
,
27122 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
27123 SECTION_DEBUG
, NULL
);
27124 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
27125 SECTION_DEBUG
, NULL
);
27126 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27127 SECTION_DEBUG
, NULL
);
27128 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
27129 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
27131 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
27132 the main .o, but the skeleton_line goes into the split off dwo. */
27133 debug_skeleton_line_section
27134 = get_section (DEBUG_DWO_LINE_SECTION
,
27135 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27136 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27137 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
27138 debug_str_offsets_section
= get_section (DEBUG_DWO_STR_OFFSETS_SECTION
,
27139 SECTION_DEBUG
| SECTION_EXCLUDE
,
27141 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
27142 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
27143 debug_loc_section
= get_section (dwarf_version
>= 5
27144 ? DEBUG_DWO_LOCLISTS_SECTION
27145 : DEBUG_DWO_LOC_SECTION
,
27146 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27147 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
27148 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
27149 debug_macinfo_section_name
27150 = (dwarf_strict
&& dwarf_version
< 5)
27151 ? DEBUG_DWO_MACINFO_SECTION
: DEBUG_DWO_MACRO_SECTION
;
27152 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27153 SECTION_DEBUG
| SECTION_EXCLUDE
,
27156 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
27157 SECTION_DEBUG
, NULL
);
27158 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
27159 SECTION_DEBUG
, NULL
);
27160 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
27161 SECTION_DEBUG
, NULL
);
27162 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
27163 SECTION_DEBUG
, NULL
);
27164 debug_str_section
= get_section (DEBUG_STR_SECTION
,
27165 DEBUG_STR_SECTION_FLAGS
, NULL
);
27166 if (!dwarf_split_debug_info
&& !DWARF2_ASM_LINE_DEBUG_INFO
)
27167 debug_line_str_section
= get_section (DEBUG_LINE_STR_SECTION
,
27168 DEBUG_STR_SECTION_FLAGS
, NULL
);
27170 debug_ranges_section
= get_section (dwarf_version
>= 5
27171 ? DEBUG_RNGLISTS_SECTION
27172 : DEBUG_RANGES_SECTION
,
27173 SECTION_DEBUG
, NULL
);
27174 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
27175 SECTION_DEBUG
, NULL
);
27177 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
27178 DEBUG_ABBREV_SECTION_LABEL
, 0);
27179 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
27180 DEBUG_INFO_SECTION_LABEL
, 0);
27181 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
27182 DEBUG_LINE_SECTION_LABEL
, 0);
27183 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
27184 DEBUG_RANGES_SECTION_LABEL
, 0);
27185 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
27186 ASM_GENERATE_INTERNAL_LABEL (ranges_base_label
,
27187 DEBUG_RANGES_SECTION_LABEL
, 1);
27188 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
27189 DEBUG_ADDR_SECTION_LABEL
, 0);
27190 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
27191 (dwarf_strict
&& dwarf_version
< 5)
27192 ? DEBUG_MACINFO_SECTION_LABEL
27193 : DEBUG_MACRO_SECTION_LABEL
, 0);
27194 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
27197 /* Set up for Dwarf output at the start of compilation. */
27200 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
27202 /* This option is currently broken, see (PR53118 and PR46102). */
27203 if (flag_eliminate_dwarf2_dups
27204 && strstr (lang_hooks
.name
, "C++"))
27206 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
27207 flag_eliminate_dwarf2_dups
= 0;
27210 /* Allocate the file_table. */
27211 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
27213 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27214 /* Allocate the decl_die_table. */
27215 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
27217 /* Allocate the decl_loc_table. */
27218 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
27220 /* Allocate the cached_dw_loc_list_table. */
27221 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
27223 /* Allocate the initial hunk of the decl_scope_table. */
27224 vec_alloc (decl_scope_table
, 256);
27226 /* Allocate the initial hunk of the abbrev_die_table. */
27227 vec_alloc (abbrev_die_table
, 256);
27228 /* Zero-th entry is allocated, but unused. */
27229 abbrev_die_table
->quick_push (NULL
);
27231 /* Allocate the dwarf_proc_stack_usage_map. */
27232 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
27234 /* Allocate the pubtypes and pubnames vectors. */
27235 vec_alloc (pubname_table
, 32);
27236 vec_alloc (pubtype_table
, 32);
27238 vec_alloc (incomplete_types
, 64);
27240 vec_alloc (used_rtx_array
, 32);
27242 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
27243 vec_alloc (macinfo_table
, 64);
27246 /* If front-ends already registered a main translation unit but we were not
27247 ready to perform the association, do this now. */
27248 if (main_translation_unit
!= NULL_TREE
)
27249 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
27252 /* Called before compile () starts outputtting functions, variables
27253 and toplevel asms into assembly. */
27256 dwarf2out_assembly_start (void)
27258 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27259 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
27260 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
27261 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
27262 COLD_TEXT_SECTION_LABEL
, 0);
27263 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
27265 switch_to_section (text_section
);
27266 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
27269 /* Make sure the line number table for .text always exists. */
27270 text_section_line_info
= new_line_info_table ();
27271 text_section_line_info
->end_label
= text_end_label
;
27273 #ifdef DWARF2_LINENO_DEBUGGING_INFO
27274 cur_line_info_table
= text_section_line_info
;
27277 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
27278 && dwarf2out_do_cfi_asm ()
27279 && (!(flag_unwind_tables
|| flag_exceptions
)
27280 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
27281 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
27284 /* A helper function for dwarf2out_finish called through
27285 htab_traverse. Assign a string its index. All strings must be
27286 collected into the table by the time index_string is called,
27287 because the indexing code relies on htab_traverse to traverse nodes
27288 in the same order for each run. */
27291 index_string (indirect_string_node
**h
, unsigned int *index
)
27293 indirect_string_node
*node
= *h
;
27295 find_string_form (node
);
27296 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27298 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
27299 node
->index
= *index
;
27305 /* A helper function for output_indirect_strings called through
27306 htab_traverse. Output the offset to a string and update the
27310 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
27312 indirect_string_node
*node
= *h
;
27314 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27316 /* Assert that this node has been assigned an index. */
27317 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
27318 && node
->index
!= NOT_INDEXED
);
27319 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
27320 "indexed string 0x%x: %s", node
->index
, node
->str
);
27321 *offset
+= strlen (node
->str
) + 1;
27326 /* A helper function for dwarf2out_finish called through
27327 htab_traverse. Output the indexed string. */
27330 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
27332 struct indirect_string_node
*node
= *h
;
27334 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27336 /* Assert that the strings are output in the same order as their
27337 indexes were assigned. */
27338 gcc_assert (*cur_idx
== node
->index
);
27339 assemble_string (node
->str
, strlen (node
->str
) + 1);
27345 /* A helper function for dwarf2out_finish called through
27346 htab_traverse. Emit one queued .debug_str string. */
27349 output_indirect_string (indirect_string_node
**h
, enum dwarf_form form
)
27351 struct indirect_string_node
*node
= *h
;
27353 node
->form
= find_string_form (node
);
27354 if (node
->form
== form
&& node
->refcount
> 0)
27356 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
27357 assemble_string (node
->str
, strlen (node
->str
) + 1);
27363 /* Output the indexed string table. */
27366 output_indirect_strings (void)
27368 switch_to_section (debug_str_section
);
27369 if (!dwarf_split_debug_info
)
27370 debug_str_hash
->traverse
<enum dwarf_form
,
27371 output_indirect_string
> (DW_FORM_strp
);
27374 unsigned int offset
= 0;
27375 unsigned int cur_idx
= 0;
27377 skeleton_debug_str_hash
->traverse
<enum dwarf_form
,
27378 output_indirect_string
> (DW_FORM_strp
);
27380 switch_to_section (debug_str_offsets_section
);
27381 debug_str_hash
->traverse_noresize
27382 <unsigned int *, output_index_string_offset
> (&offset
);
27383 switch_to_section (debug_str_dwo_section
);
27384 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
27389 /* Callback for htab_traverse to assign an index to an entry in the
27390 table, and to write that entry to the .debug_addr section. */
27393 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
27395 addr_table_entry
*entry
= *slot
;
27397 if (entry
->refcount
== 0)
27399 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
27400 || entry
->index
== NOT_INDEXED
);
27404 gcc_assert (entry
->index
== *cur_index
);
27407 switch (entry
->kind
)
27410 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
27411 "0x%x", entry
->index
);
27413 case ate_kind_rtx_dtprel
:
27414 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
27415 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
27418 fputc ('\n', asm_out_file
);
27420 case ate_kind_label
:
27421 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
27422 "0x%x", entry
->index
);
27425 gcc_unreachable ();
27430 /* Produce the .debug_addr section. */
27433 output_addr_table (void)
27435 unsigned int index
= 0;
27436 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
27439 switch_to_section (debug_addr_section
);
27441 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
27444 #if ENABLE_ASSERT_CHECKING
27445 /* Verify that all marks are clear. */
27448 verify_marks_clear (dw_die_ref die
)
27452 gcc_assert (! die
->die_mark
);
27453 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
27455 #endif /* ENABLE_ASSERT_CHECKING */
27457 /* Clear the marks for a die and its children.
27458 Be cool if the mark isn't set. */
27461 prune_unmark_dies (dw_die_ref die
)
27467 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
27470 /* Given LOC that is referenced by a DIE we're marking as used, find all
27471 referenced DWARF procedures it references and mark them as used. */
27474 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
27476 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
27477 switch (loc
->dw_loc_opc
)
27479 case DW_OP_implicit_pointer
:
27480 case DW_OP_convert
:
27481 case DW_OP_reinterpret
:
27482 case DW_OP_GNU_implicit_pointer
:
27483 case DW_OP_GNU_convert
:
27484 case DW_OP_GNU_reinterpret
:
27485 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
27486 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27490 case DW_OP_call_ref
:
27491 case DW_OP_const_type
:
27492 case DW_OP_GNU_const_type
:
27493 case DW_OP_GNU_parameter_ref
:
27494 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
27495 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27497 case DW_OP_regval_type
:
27498 case DW_OP_deref_type
:
27499 case DW_OP_GNU_regval_type
:
27500 case DW_OP_GNU_deref_type
:
27501 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
27502 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
27504 case DW_OP_entry_value
:
27505 case DW_OP_GNU_entry_value
:
27506 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
27507 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
27514 /* Given DIE that we're marking as used, find any other dies
27515 it references as attributes and mark them as used. */
27518 prune_unused_types_walk_attribs (dw_die_ref die
)
27523 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27525 switch (AT_class (a
))
27527 /* Make sure DWARF procedures referenced by location descriptions will
27529 case dw_val_class_loc
:
27530 prune_unused_types_walk_loc_descr (AT_loc (a
));
27532 case dw_val_class_loc_list
:
27533 for (dw_loc_list_ref list
= AT_loc_list (a
);
27535 list
= list
->dw_loc_next
)
27536 prune_unused_types_walk_loc_descr (list
->expr
);
27539 case dw_val_class_die_ref
:
27540 /* A reference to another DIE.
27541 Make sure that it will get emitted.
27542 If it was broken out into a comdat group, don't follow it. */
27543 if (! AT_ref (a
)->comdat_type_p
27544 || a
->dw_attr
== DW_AT_specification
)
27545 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
27548 case dw_val_class_str
:
27549 /* Set the string's refcount to 0 so that prune_unused_types_mark
27550 accounts properly for it. */
27551 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
27560 /* Mark the generic parameters and arguments children DIEs of DIE. */
27563 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
27567 if (die
== NULL
|| die
->die_child
== NULL
)
27569 c
= die
->die_child
;
27572 if (is_template_parameter (c
))
27573 prune_unused_types_mark (c
, 1);
27575 } while (c
&& c
!= die
->die_child
);
27578 /* Mark DIE as being used. If DOKIDS is true, then walk down
27579 to DIE's children. */
27582 prune_unused_types_mark (dw_die_ref die
, int dokids
)
27586 if (die
->die_mark
== 0)
27588 /* We haven't done this node yet. Mark it as used. */
27590 /* If this is the DIE of a generic type instantiation,
27591 mark the children DIEs that describe its generic parms and
27593 prune_unused_types_mark_generic_parms_dies (die
);
27595 /* We also have to mark its parents as used.
27596 (But we don't want to mark our parent's kids due to this,
27597 unless it is a class.) */
27598 if (die
->die_parent
)
27599 prune_unused_types_mark (die
->die_parent
,
27600 class_scope_p (die
->die_parent
));
27602 /* Mark any referenced nodes. */
27603 prune_unused_types_walk_attribs (die
);
27605 /* If this node is a specification,
27606 also mark the definition, if it exists. */
27607 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
27608 prune_unused_types_mark (die
->die_definition
, 1);
27611 if (dokids
&& die
->die_mark
!= 2)
27613 /* We need to walk the children, but haven't done so yet.
27614 Remember that we've walked the kids. */
27617 /* If this is an array type, we need to make sure our
27618 kids get marked, even if they're types. If we're
27619 breaking out types into comdat sections, do this
27620 for all type definitions. */
27621 if (die
->die_tag
== DW_TAG_array_type
27622 || (use_debug_types
27623 && is_type_die (die
) && ! is_declaration_die (die
)))
27624 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
27626 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
27630 /* For local classes, look if any static member functions were emitted
27631 and if so, mark them. */
27634 prune_unused_types_walk_local_classes (dw_die_ref die
)
27638 if (die
->die_mark
== 2)
27641 switch (die
->die_tag
)
27643 case DW_TAG_structure_type
:
27644 case DW_TAG_union_type
:
27645 case DW_TAG_class_type
:
27648 case DW_TAG_subprogram
:
27649 if (!get_AT_flag (die
, DW_AT_declaration
)
27650 || die
->die_definition
!= NULL
)
27651 prune_unused_types_mark (die
, 1);
27658 /* Mark children. */
27659 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
27662 /* Walk the tree DIE and mark types that we actually use. */
27665 prune_unused_types_walk (dw_die_ref die
)
27669 /* Don't do anything if this node is already marked and
27670 children have been marked as well. */
27671 if (die
->die_mark
== 2)
27674 switch (die
->die_tag
)
27676 case DW_TAG_structure_type
:
27677 case DW_TAG_union_type
:
27678 case DW_TAG_class_type
:
27679 if (die
->die_perennial_p
)
27682 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
27683 if (c
->die_tag
== DW_TAG_subprogram
)
27686 /* Finding used static member functions inside of classes
27687 is needed just for local classes, because for other classes
27688 static member function DIEs with DW_AT_specification
27689 are emitted outside of the DW_TAG_*_type. If we ever change
27690 it, we'd need to call this even for non-local classes. */
27692 prune_unused_types_walk_local_classes (die
);
27694 /* It's a type node --- don't mark it. */
27697 case DW_TAG_const_type
:
27698 case DW_TAG_packed_type
:
27699 case DW_TAG_pointer_type
:
27700 case DW_TAG_reference_type
:
27701 case DW_TAG_rvalue_reference_type
:
27702 case DW_TAG_volatile_type
:
27703 case DW_TAG_typedef
:
27704 case DW_TAG_array_type
:
27705 case DW_TAG_interface_type
:
27706 case DW_TAG_friend
:
27707 case DW_TAG_enumeration_type
:
27708 case DW_TAG_subroutine_type
:
27709 case DW_TAG_string_type
:
27710 case DW_TAG_set_type
:
27711 case DW_TAG_subrange_type
:
27712 case DW_TAG_ptr_to_member_type
:
27713 case DW_TAG_file_type
:
27714 /* Type nodes are useful only when other DIEs reference them --- don't
27718 case DW_TAG_dwarf_procedure
:
27719 /* Likewise for DWARF procedures. */
27721 if (die
->die_perennial_p
)
27727 /* Mark everything else. */
27731 if (die
->die_mark
== 0)
27735 /* Now, mark any dies referenced from here. */
27736 prune_unused_types_walk_attribs (die
);
27741 /* Mark children. */
27742 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
27745 /* Increment the string counts on strings referred to from DIE's
27749 prune_unused_types_update_strings (dw_die_ref die
)
27754 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27755 if (AT_class (a
) == dw_val_class_str
)
27757 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
27759 /* Avoid unnecessarily putting strings that are used less than
27760 twice in the hash table. */
27762 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
27764 indirect_string_node
**slot
27765 = debug_str_hash
->find_slot_with_hash (s
->str
,
27766 htab_hash_string (s
->str
),
27768 gcc_assert (*slot
== NULL
);
27774 /* Mark DIE and its children as removed. */
27777 mark_removed (dw_die_ref die
)
27780 die
->removed
= true;
27781 FOR_EACH_CHILD (die
, c
, mark_removed (c
));
27784 /* Remove from the tree DIE any dies that aren't marked. */
27787 prune_unused_types_prune (dw_die_ref die
)
27791 gcc_assert (die
->die_mark
);
27792 prune_unused_types_update_strings (die
);
27794 if (! die
->die_child
)
27797 c
= die
->die_child
;
27799 dw_die_ref prev
= c
, next
;
27800 for (c
= c
->die_sib
; ! c
->die_mark
; c
= next
)
27801 if (c
== die
->die_child
)
27803 /* No marked children between 'prev' and the end of the list. */
27805 /* No marked children at all. */
27806 die
->die_child
= NULL
;
27809 prev
->die_sib
= c
->die_sib
;
27810 die
->die_child
= prev
;
27823 if (c
!= prev
->die_sib
)
27825 prune_unused_types_prune (c
);
27826 } while (c
!= die
->die_child
);
27829 /* Remove dies representing declarations that we never use. */
27832 prune_unused_types (void)
27835 limbo_die_node
*node
;
27836 comdat_type_node
*ctnode
;
27837 pubname_entry
*pub
;
27838 dw_die_ref base_type
;
27840 #if ENABLE_ASSERT_CHECKING
27841 /* All the marks should already be clear. */
27842 verify_marks_clear (comp_unit_die ());
27843 for (node
= limbo_die_list
; node
; node
= node
->next
)
27844 verify_marks_clear (node
->die
);
27845 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27846 verify_marks_clear (ctnode
->root_die
);
27847 #endif /* ENABLE_ASSERT_CHECKING */
27849 /* Mark types that are used in global variables. */
27850 premark_types_used_by_global_vars ();
27852 /* Set the mark on nodes that are actually used. */
27853 prune_unused_types_walk (comp_unit_die ());
27854 for (node
= limbo_die_list
; node
; node
= node
->next
)
27855 prune_unused_types_walk (node
->die
);
27856 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27858 prune_unused_types_walk (ctnode
->root_die
);
27859 prune_unused_types_mark (ctnode
->type_die
, 1);
27862 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
27863 are unusual in that they are pubnames that are the children of pubtypes.
27864 They should only be marked via their parent DW_TAG_enumeration_type die,
27865 not as roots in themselves. */
27866 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
27867 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
27868 prune_unused_types_mark (pub
->die
, 1);
27869 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
27870 prune_unused_types_mark (base_type
, 1);
27872 /* For -fvar-tracking-assignments, also set the mark on nodes that could be
27873 referenced by DW_TAG_call_site DW_AT_call_origin (i.e. direct call
27875 cgraph_node
*cnode
;
27876 FOR_EACH_FUNCTION (cnode
)
27877 if (cnode
->referred_to_p (false))
27879 dw_die_ref die
= lookup_decl_die (cnode
->decl
);
27880 if (die
== NULL
|| die
->die_mark
)
27882 for (cgraph_edge
*e
= cnode
->callers
; e
; e
= e
->next_caller
)
27883 if (e
->caller
!= cnode
27884 && opt_for_fn (e
->caller
->decl
, flag_var_tracking_assignments
))
27886 prune_unused_types_mark (die
, 1);
27891 if (debug_str_hash
)
27892 debug_str_hash
->empty ();
27893 if (skeleton_debug_str_hash
)
27894 skeleton_debug_str_hash
->empty ();
27895 prune_unused_types_prune (comp_unit_die ());
27896 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
27899 if (!node
->die
->die_mark
)
27900 *pnode
= node
->next
;
27903 prune_unused_types_prune (node
->die
);
27904 pnode
= &node
->next
;
27907 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27908 prune_unused_types_prune (ctnode
->root_die
);
27910 /* Leave the marks clear. */
27911 prune_unmark_dies (comp_unit_die ());
27912 for (node
= limbo_die_list
; node
; node
= node
->next
)
27913 prune_unmark_dies (node
->die
);
27914 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27915 prune_unmark_dies (ctnode
->root_die
);
27918 /* Helpers to manipulate hash table of comdat type units. */
27920 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
27922 static inline hashval_t
hash (const comdat_type_node
*);
27923 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
27927 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
27930 memcpy (&h
, type_node
->signature
, sizeof (h
));
27935 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
27936 const comdat_type_node
*type_node_2
)
27938 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
27939 DWARF_TYPE_SIGNATURE_SIZE
));
27942 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
27943 to the location it would have been added, should we know its
27944 DECL_ASSEMBLER_NAME when we added other attributes. This will
27945 probably improve compactness of debug info, removing equivalent
27946 abbrevs, and hide any differences caused by deferring the
27947 computation of the assembler name, triggered by e.g. PCH. */
27950 move_linkage_attr (dw_die_ref die
)
27952 unsigned ix
= vec_safe_length (die
->die_attr
);
27953 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
27955 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
27956 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
27960 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
27962 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
27966 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
27968 die
->die_attr
->pop ();
27969 die
->die_attr
->quick_insert (ix
, linkage
);
27973 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
27974 referenced from typed stack ops and count how often they are used. */
27977 mark_base_types (dw_loc_descr_ref loc
)
27979 dw_die_ref base_type
= NULL
;
27981 for (; loc
; loc
= loc
->dw_loc_next
)
27983 switch (loc
->dw_loc_opc
)
27985 case DW_OP_regval_type
:
27986 case DW_OP_deref_type
:
27987 case DW_OP_GNU_regval_type
:
27988 case DW_OP_GNU_deref_type
:
27989 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
27991 case DW_OP_convert
:
27992 case DW_OP_reinterpret
:
27993 case DW_OP_GNU_convert
:
27994 case DW_OP_GNU_reinterpret
:
27995 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
27998 case DW_OP_const_type
:
27999 case DW_OP_GNU_const_type
:
28000 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28002 case DW_OP_entry_value
:
28003 case DW_OP_GNU_entry_value
:
28004 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
28009 gcc_assert (base_type
->die_parent
== comp_unit_die ());
28010 if (base_type
->die_mark
)
28011 base_type
->die_mark
++;
28014 base_types
.safe_push (base_type
);
28015 base_type
->die_mark
= 1;
28020 /* Comparison function for sorting marked base types. */
28023 base_type_cmp (const void *x
, const void *y
)
28025 dw_die_ref dx
= *(const dw_die_ref
*) x
;
28026 dw_die_ref dy
= *(const dw_die_ref
*) y
;
28027 unsigned int byte_size1
, byte_size2
;
28028 unsigned int encoding1
, encoding2
;
28029 unsigned int align1
, align2
;
28030 if (dx
->die_mark
> dy
->die_mark
)
28032 if (dx
->die_mark
< dy
->die_mark
)
28034 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
28035 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
28036 if (byte_size1
< byte_size2
)
28038 if (byte_size1
> byte_size2
)
28040 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
28041 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
28042 if (encoding1
< encoding2
)
28044 if (encoding1
> encoding2
)
28046 align1
= get_AT_unsigned (dx
, DW_AT_alignment
);
28047 align2
= get_AT_unsigned (dy
, DW_AT_alignment
);
28048 if (align1
< align2
)
28050 if (align1
> align2
)
28055 /* Move base types marked by mark_base_types as early as possible
28056 in the CU, sorted by decreasing usage count both to make the
28057 uleb128 references as small as possible and to make sure they
28058 will have die_offset already computed by calc_die_sizes when
28059 sizes of typed stack loc ops is computed. */
28062 move_marked_base_types (void)
28065 dw_die_ref base_type
, die
, c
;
28067 if (base_types
.is_empty ())
28070 /* Sort by decreasing usage count, they will be added again in that
28072 base_types
.qsort (base_type_cmp
);
28073 die
= comp_unit_die ();
28074 c
= die
->die_child
;
28077 dw_die_ref prev
= c
;
28079 while (c
->die_mark
)
28081 remove_child_with_prev (c
, prev
);
28082 /* As base types got marked, there must be at least
28083 one node other than DW_TAG_base_type. */
28084 gcc_assert (die
->die_child
!= NULL
);
28088 while (c
!= die
->die_child
);
28089 gcc_assert (die
->die_child
);
28090 c
= die
->die_child
;
28091 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
28093 base_type
->die_mark
= 0;
28094 base_type
->die_sib
= c
->die_sib
;
28095 c
->die_sib
= base_type
;
28100 /* Helper function for resolve_addr, attempt to resolve
28101 one CONST_STRING, return true if successful. Similarly verify that
28102 SYMBOL_REFs refer to variables emitted in the current CU. */
28105 resolve_one_addr (rtx
*addr
)
28109 if (GET_CODE (rtl
) == CONST_STRING
)
28111 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28112 tree t
= build_string (len
, XSTR (rtl
, 0));
28113 tree tlen
= size_int (len
- 1);
28115 = build_array_type (char_type_node
, build_index_type (tlen
));
28116 rtl
= lookup_constant_def (t
);
28117 if (!rtl
|| !MEM_P (rtl
))
28119 rtl
= XEXP (rtl
, 0);
28120 if (GET_CODE (rtl
) == SYMBOL_REF
28121 && SYMBOL_REF_DECL (rtl
)
28122 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28124 vec_safe_push (used_rtx_array
, rtl
);
28129 if (GET_CODE (rtl
) == SYMBOL_REF
28130 && SYMBOL_REF_DECL (rtl
))
28132 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
28134 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
28137 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28141 if (GET_CODE (rtl
) == CONST
)
28143 subrtx_ptr_iterator::array_type array
;
28144 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
28145 if (!resolve_one_addr (*iter
))
28152 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
28153 if possible, and create DW_TAG_dwarf_procedure that can be referenced
28154 from DW_OP_implicit_pointer if the string hasn't been seen yet. */
28157 string_cst_pool_decl (tree t
)
28159 rtx rtl
= output_constant_def (t
, 1);
28160 unsigned char *array
;
28161 dw_loc_descr_ref l
;
28166 if (!rtl
|| !MEM_P (rtl
))
28168 rtl
= XEXP (rtl
, 0);
28169 if (GET_CODE (rtl
) != SYMBOL_REF
28170 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
28173 decl
= SYMBOL_REF_DECL (rtl
);
28174 if (!lookup_decl_die (decl
))
28176 len
= TREE_STRING_LENGTH (t
);
28177 vec_safe_push (used_rtx_array
, rtl
);
28178 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
28179 array
= ggc_vec_alloc
<unsigned char> (len
);
28180 memcpy (array
, TREE_STRING_POINTER (t
), len
);
28181 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
28182 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
28183 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
28184 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
28185 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
28186 add_AT_loc (ref
, DW_AT_location
, l
);
28187 equate_decl_number_to_die (decl
, ref
);
28192 /* Helper function of resolve_addr_in_expr. LOC is
28193 a DW_OP_addr followed by DW_OP_stack_value, either at the start
28194 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
28195 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
28196 with DW_OP_implicit_pointer if possible
28197 and return true, if unsuccessful, return false. */
28200 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
28202 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
28203 HOST_WIDE_INT offset
= 0;
28204 dw_die_ref ref
= NULL
;
28207 if (GET_CODE (rtl
) == CONST
28208 && GET_CODE (XEXP (rtl
, 0)) == PLUS
28209 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
28211 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
28212 rtl
= XEXP (XEXP (rtl
, 0), 0);
28214 if (GET_CODE (rtl
) == CONST_STRING
)
28216 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28217 tree t
= build_string (len
, XSTR (rtl
, 0));
28218 tree tlen
= size_int (len
- 1);
28221 = build_array_type (char_type_node
, build_index_type (tlen
));
28222 rtl
= string_cst_pool_decl (t
);
28226 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
28228 decl
= SYMBOL_REF_DECL (rtl
);
28229 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
28231 ref
= lookup_decl_die (decl
);
28232 if (ref
&& (get_AT (ref
, DW_AT_location
)
28233 || get_AT (ref
, DW_AT_const_value
)))
28235 loc
->dw_loc_opc
= dwarf_OP (DW_OP_implicit_pointer
);
28236 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28237 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
28238 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28239 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28240 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28241 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
28249 /* Helper function for resolve_addr, handle one location
28250 expression, return false if at least one CONST_STRING or SYMBOL_REF in
28251 the location list couldn't be resolved. */
28254 resolve_addr_in_expr (dw_loc_descr_ref loc
)
28256 dw_loc_descr_ref keep
= NULL
;
28257 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
28258 switch (loc
->dw_loc_opc
)
28261 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28264 || prev
->dw_loc_opc
== DW_OP_piece
28265 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
28266 && loc
->dw_loc_next
28267 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
28268 && (!dwarf_strict
|| dwarf_version
>= 5)
28269 && optimize_one_addr_into_implicit_ptr (loc
))
28274 case DW_OP_GNU_addr_index
:
28275 case DW_OP_GNU_const_index
:
28276 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
28277 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
28279 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
28280 if (!resolve_one_addr (&rtl
))
28282 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
28283 loc
->dw_loc_oprnd1
.val_entry
28284 = add_addr_table_entry (rtl
, ate_kind_rtx
);
28287 case DW_OP_const4u
:
28288 case DW_OP_const8u
:
28290 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28293 case DW_OP_plus_uconst
:
28294 if (size_of_loc_descr (loc
)
28295 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
28297 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
28299 dw_loc_descr_ref repl
28300 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
28301 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
28302 add_loc_descr (&repl
, loc
->dw_loc_next
);
28306 case DW_OP_implicit_value
:
28307 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
28308 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
28311 case DW_OP_implicit_pointer
:
28312 case DW_OP_GNU_implicit_pointer
:
28313 case DW_OP_GNU_parameter_ref
:
28314 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28317 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
28320 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28321 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28322 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28325 case DW_OP_const_type
:
28326 case DW_OP_regval_type
:
28327 case DW_OP_deref_type
:
28328 case DW_OP_convert
:
28329 case DW_OP_reinterpret
:
28330 case DW_OP_GNU_const_type
:
28331 case DW_OP_GNU_regval_type
:
28332 case DW_OP_GNU_deref_type
:
28333 case DW_OP_GNU_convert
:
28334 case DW_OP_GNU_reinterpret
:
28335 while (loc
->dw_loc_next
28336 && (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_convert
28337 || loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
))
28339 dw_die_ref base1
, base2
;
28340 unsigned enc1
, enc2
, size1
, size2
;
28341 if (loc
->dw_loc_opc
== DW_OP_regval_type
28342 || loc
->dw_loc_opc
== DW_OP_deref_type
28343 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28344 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28345 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
28346 else if (loc
->dw_loc_oprnd1
.val_class
28347 == dw_val_class_unsigned_const
)
28350 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28351 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
28352 == dw_val_class_unsigned_const
)
28354 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28355 gcc_assert (base1
->die_tag
== DW_TAG_base_type
28356 && base2
->die_tag
== DW_TAG_base_type
);
28357 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
28358 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
28359 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
28360 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
28362 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
28363 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
28367 /* Optimize away next DW_OP_convert after
28368 adjusting LOC's base type die reference. */
28369 if (loc
->dw_loc_opc
== DW_OP_regval_type
28370 || loc
->dw_loc_opc
== DW_OP_deref_type
28371 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28372 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28373 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
28375 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
28376 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28379 /* Don't change integer DW_OP_convert after e.g. floating
28380 point typed stack entry. */
28381 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
28382 keep
= loc
->dw_loc_next
;
28392 /* Helper function of resolve_addr. DIE had DW_AT_location of
28393 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
28394 and DW_OP_addr couldn't be resolved. resolve_addr has already
28395 removed the DW_AT_location attribute. This function attempts to
28396 add a new DW_AT_location attribute with DW_OP_implicit_pointer
28397 to it or DW_AT_const_value attribute, if possible. */
28400 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
28403 || lookup_decl_die (decl
) != die
28404 || DECL_EXTERNAL (decl
)
28405 || !TREE_STATIC (decl
)
28406 || DECL_INITIAL (decl
) == NULL_TREE
28407 || DECL_P (DECL_INITIAL (decl
))
28408 || get_AT (die
, DW_AT_const_value
))
28411 tree init
= DECL_INITIAL (decl
);
28412 HOST_WIDE_INT offset
= 0;
28413 /* For variables that have been optimized away and thus
28414 don't have a memory location, see if we can emit
28415 DW_AT_const_value instead. */
28416 if (tree_add_const_value_attribute (die
, init
))
28418 if (dwarf_strict
&& dwarf_version
< 5)
28420 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
28421 and ADDR_EXPR refers to a decl that has DW_AT_location or
28422 DW_AT_const_value (but isn't addressable, otherwise
28423 resolving the original DW_OP_addr wouldn't fail), see if
28424 we can add DW_OP_implicit_pointer. */
28426 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
28427 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
28429 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
28430 init
= TREE_OPERAND (init
, 0);
28433 if (TREE_CODE (init
) != ADDR_EXPR
)
28435 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
28436 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
28437 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
28438 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
28439 && TREE_OPERAND (init
, 0) != decl
))
28442 dw_loc_descr_ref l
;
28444 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
28446 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
28449 decl
= SYMBOL_REF_DECL (rtl
);
28452 decl
= TREE_OPERAND (init
, 0);
28453 ref
= lookup_decl_die (decl
);
28455 || (!get_AT (ref
, DW_AT_location
)
28456 && !get_AT (ref
, DW_AT_const_value
)))
28458 l
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
28459 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28460 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28461 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28462 add_AT_loc (die
, DW_AT_location
, l
);
28466 /* Return NULL if l is a DWARF expression, or first op that is not
28467 valid DWARF expression. */
28469 static dw_loc_descr_ref
28470 non_dwarf_expression (dw_loc_descr_ref l
)
28474 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28476 switch (l
->dw_loc_opc
)
28479 case DW_OP_implicit_value
:
28480 case DW_OP_stack_value
:
28481 case DW_OP_implicit_pointer
:
28482 case DW_OP_GNU_implicit_pointer
:
28483 case DW_OP_GNU_parameter_ref
:
28485 case DW_OP_bit_piece
:
28490 l
= l
->dw_loc_next
;
28495 /* Return adjusted copy of EXPR:
28496 If it is empty DWARF expression, return it.
28497 If it is valid non-empty DWARF expression,
28498 return copy of EXPR with copy of DEREF appended to it.
28499 If it is DWARF expression followed by DW_OP_reg{N,x}, return
28500 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended
28502 If it is DWARF expression followed by DW_OP_stack_value, return
28503 copy of the DWARF expression without anything appended.
28504 Otherwise, return NULL. */
28506 static dw_loc_descr_ref
28507 copy_deref_exprloc (dw_loc_descr_ref expr
, dw_loc_descr_ref deref
)
28513 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
28514 if (l
&& l
->dw_loc_next
)
28519 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28520 deref
= new_loc_descr ((enum dwarf_location_atom
)
28521 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
28524 switch (l
->dw_loc_opc
)
28527 deref
= new_loc_descr (DW_OP_bregx
,
28528 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
28530 case DW_OP_stack_value
:
28538 deref
= new_loc_descr (deref
->dw_loc_opc
,
28539 deref
->dw_loc_oprnd1
.v
.val_int
, 0);
28541 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
28544 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
28545 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
28546 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
28547 p
= &(*p
)->dw_loc_next
;
28548 expr
= expr
->dw_loc_next
;
28554 /* For DW_AT_string_length attribute with DW_OP_call4 reference to a variable
28555 or argument, adjust it if needed and return:
28556 -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
28557 attribute if present should be removed
28558 0 keep the attribute as is if the referenced var or argument has
28559 only DWARF expression that covers all ranges
28560 1 if the attribute has been successfully adjusted. */
28563 optimize_string_length (dw_attr_node
*a
)
28565 dw_loc_descr_ref l
= AT_loc (a
), lv
;
28566 dw_die_ref die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28567 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
28569 bool non_dwarf_expr
= false;
28573 switch (AT_class (av
))
28575 case dw_val_class_loc_list
:
28576 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
28577 if (d
->expr
&& non_dwarf_expression (d
->expr
))
28578 non_dwarf_expr
= true;
28580 case dw_val_class_loc
:
28584 if (non_dwarf_expression (lv
))
28585 non_dwarf_expr
= true;
28591 /* If it is safe to keep DW_OP_call4 in, keep it. */
28592 if (!non_dwarf_expr
28593 && (l
->dw_loc_next
== NULL
|| AT_class (av
) == dw_val_class_loc
))
28596 /* If not dereferencing the DW_OP_call4 afterwards, we can just
28597 copy over the DW_AT_location attribute from die to a. */
28598 if (l
->dw_loc_next
== NULL
)
28600 a
->dw_attr_val
= av
->dw_attr_val
;
28604 dw_loc_list_ref list
, *p
;
28605 switch (AT_class (av
))
28607 case dw_val_class_loc_list
:
28610 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
28612 lv
= copy_deref_exprloc (d
->expr
, l
->dw_loc_next
);
28615 *p
= new_loc_list (lv
, d
->begin
, d
->end
, d
->section
);
28616 p
= &(*p
)->dw_loc_next
;
28621 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
28623 *AT_loc_list_ptr (a
) = list
;
28625 case dw_val_class_loc
:
28626 lv
= copy_deref_exprloc (AT_loc (av
), l
->dw_loc_next
);
28629 a
->dw_attr_val
.v
.val_loc
= lv
;
28632 gcc_unreachable ();
28636 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
28637 an address in .rodata section if the string literal is emitted there,
28638 or remove the containing location list or replace DW_AT_const_value
28639 with DW_AT_location and empty location expression, if it isn't found
28640 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
28641 to something that has been emitted in the current CU. */
28644 resolve_addr (dw_die_ref die
)
28648 dw_loc_list_ref
*curr
, *start
, loc
;
28650 bool remove_AT_byte_size
= false;
28652 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
28653 switch (AT_class (a
))
28655 case dw_val_class_loc_list
:
28656 start
= curr
= AT_loc_list_ptr (a
);
28659 /* The same list can be referenced more than once. See if we have
28660 already recorded the result from a previous pass. */
28662 *curr
= loc
->dw_loc_next
;
28663 else if (!loc
->resolved_addr
)
28665 /* As things stand, we do not expect or allow one die to
28666 reference a suffix of another die's location list chain.
28667 References must be identical or completely separate.
28668 There is therefore no need to cache the result of this
28669 pass on any list other than the first; doing so
28670 would lead to unnecessary writes. */
28673 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
28674 if (!resolve_addr_in_expr ((*curr
)->expr
))
28676 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
28677 dw_loc_descr_ref l
= (*curr
)->expr
;
28679 if (next
&& (*curr
)->ll_symbol
)
28681 gcc_assert (!next
->ll_symbol
);
28682 next
->ll_symbol
= (*curr
)->ll_symbol
;
28684 if (dwarf_split_debug_info
)
28685 remove_loc_list_addr_table_entries (l
);
28690 mark_base_types ((*curr
)->expr
);
28691 curr
= &(*curr
)->dw_loc_next
;
28695 loc
->resolved_addr
= 1;
28699 loc
->dw_loc_next
= *start
;
28704 remove_AT (die
, a
->dw_attr
);
28708 case dw_val_class_loc
:
28710 dw_loc_descr_ref l
= AT_loc (a
);
28711 /* Using DW_OP_call4 or DW_OP_call4 DW_OP_deref in
28712 DW_AT_string_length is only a rough approximation; unfortunately
28713 DW_AT_string_length can't be a reference to a DIE. DW_OP_call4
28714 needs a DWARF expression, while DW_AT_location of the referenced
28715 variable or argument might be any location description. */
28716 if (a
->dw_attr
== DW_AT_string_length
28718 && l
->dw_loc_opc
== DW_OP_call4
28719 && l
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
28720 && (l
->dw_loc_next
== NULL
28721 || (l
->dw_loc_next
->dw_loc_next
== NULL
28722 && (l
->dw_loc_next
->dw_loc_opc
== DW_OP_deref
28723 || l
->dw_loc_next
->dw_loc_opc
!= DW_OP_deref_size
))))
28725 switch (optimize_string_length (a
))
28728 remove_AT (die
, a
->dw_attr
);
28730 /* If we drop DW_AT_string_length, we need to drop also
28731 DW_AT_{string_length_,}byte_size. */
28732 remove_AT_byte_size
= true;
28737 /* Even if we keep the optimized DW_AT_string_length,
28738 it might have changed AT_class, so process it again. */
28743 /* For -gdwarf-2 don't attempt to optimize
28744 DW_AT_data_member_location containing
28745 DW_OP_plus_uconst - older consumers might
28746 rely on it being that op instead of a more complex,
28747 but shorter, location description. */
28748 if ((dwarf_version
> 2
28749 || a
->dw_attr
!= DW_AT_data_member_location
28751 || l
->dw_loc_opc
!= DW_OP_plus_uconst
28752 || l
->dw_loc_next
!= NULL
)
28753 && !resolve_addr_in_expr (l
))
28755 if (dwarf_split_debug_info
)
28756 remove_loc_list_addr_table_entries (l
);
28758 && l
->dw_loc_next
== NULL
28759 && l
->dw_loc_opc
== DW_OP_addr
28760 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
28761 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
28762 && a
->dw_attr
== DW_AT_location
)
28764 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
28765 remove_AT (die
, a
->dw_attr
);
28767 optimize_location_into_implicit_ptr (die
, decl
);
28770 remove_AT (die
, a
->dw_attr
);
28774 mark_base_types (l
);
28777 case dw_val_class_addr
:
28778 if (a
->dw_attr
== DW_AT_const_value
28779 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
28781 if (AT_index (a
) != NOT_INDEXED
)
28782 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
28783 remove_AT (die
, a
->dw_attr
);
28786 if ((die
->die_tag
== DW_TAG_call_site
28787 && a
->dw_attr
== DW_AT_call_origin
)
28788 || (die
->die_tag
== DW_TAG_GNU_call_site
28789 && a
->dw_attr
== DW_AT_abstract_origin
))
28791 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
28792 dw_die_ref tdie
= lookup_decl_die (tdecl
);
28795 && DECL_EXTERNAL (tdecl
)
28796 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
28797 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
28799 dw_die_ref pdie
= cdie
;
28800 /* Make sure we don't add these DIEs into type units.
28801 We could emit skeleton DIEs for context (namespaces,
28802 outer structs/classes) and a skeleton DIE for the
28803 innermost context with DW_AT_signature pointing to the
28804 type unit. See PR78835. */
28805 while (pdie
&& pdie
->die_tag
!= DW_TAG_type_unit
)
28806 pdie
= pdie
->die_parent
;
28809 /* Creating a full DIE for tdecl is overly expensive and
28810 at this point even wrong when in the LTO phase
28811 as it can end up generating new type DIEs we didn't
28812 output and thus optimize_external_refs will crash. */
28813 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
28814 add_AT_flag (tdie
, DW_AT_external
, 1);
28815 add_AT_flag (tdie
, DW_AT_declaration
, 1);
28816 add_linkage_attr (tdie
, tdecl
);
28817 add_name_and_src_coords_attributes (tdie
, tdecl
);
28818 equate_decl_number_to_die (tdecl
, tdie
);
28823 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
28824 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
28825 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
28829 if (AT_index (a
) != NOT_INDEXED
)
28830 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
28831 remove_AT (die
, a
->dw_attr
);
28840 if (remove_AT_byte_size
)
28841 remove_AT (die
, dwarf_version
>= 5
28842 ? DW_AT_string_length_byte_size
28843 : DW_AT_byte_size
);
28845 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
28848 /* Helper routines for optimize_location_lists.
28849 This pass tries to share identical local lists in .debug_loc
28852 /* Iteratively hash operands of LOC opcode into HSTATE. */
28855 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
28857 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
28858 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
28860 switch (loc
->dw_loc_opc
)
28862 case DW_OP_const4u
:
28863 case DW_OP_const8u
:
28867 case DW_OP_const1u
:
28868 case DW_OP_const1s
:
28869 case DW_OP_const2u
:
28870 case DW_OP_const2s
:
28871 case DW_OP_const4s
:
28872 case DW_OP_const8s
:
28876 case DW_OP_plus_uconst
:
28912 case DW_OP_deref_size
:
28913 case DW_OP_xderef_size
:
28914 hstate
.add_object (val1
->v
.val_int
);
28921 gcc_assert (val1
->val_class
== dw_val_class_loc
);
28922 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
28923 hstate
.add_object (offset
);
28926 case DW_OP_implicit_value
:
28927 hstate
.add_object (val1
->v
.val_unsigned
);
28928 switch (val2
->val_class
)
28930 case dw_val_class_const
:
28931 hstate
.add_object (val2
->v
.val_int
);
28933 case dw_val_class_vec
:
28935 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
28936 unsigned int len
= val2
->v
.val_vec
.length
;
28938 hstate
.add_int (elt_size
);
28939 hstate
.add_int (len
);
28940 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
28943 case dw_val_class_const_double
:
28944 hstate
.add_object (val2
->v
.val_double
.low
);
28945 hstate
.add_object (val2
->v
.val_double
.high
);
28947 case dw_val_class_wide_int
:
28948 hstate
.add (val2
->v
.val_wide
->get_val (),
28949 get_full_len (*val2
->v
.val_wide
)
28950 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
28952 case dw_val_class_addr
:
28953 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
28956 gcc_unreachable ();
28960 case DW_OP_bit_piece
:
28961 hstate
.add_object (val1
->v
.val_int
);
28962 hstate
.add_object (val2
->v
.val_int
);
28968 unsigned char dtprel
= 0xd1;
28969 hstate
.add_object (dtprel
);
28971 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
28973 case DW_OP_GNU_addr_index
:
28974 case DW_OP_GNU_const_index
:
28978 unsigned char dtprel
= 0xd1;
28979 hstate
.add_object (dtprel
);
28981 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
28984 case DW_OP_implicit_pointer
:
28985 case DW_OP_GNU_implicit_pointer
:
28986 hstate
.add_int (val2
->v
.val_int
);
28988 case DW_OP_entry_value
:
28989 case DW_OP_GNU_entry_value
:
28990 hstate
.add_object (val1
->v
.val_loc
);
28992 case DW_OP_regval_type
:
28993 case DW_OP_deref_type
:
28994 case DW_OP_GNU_regval_type
:
28995 case DW_OP_GNU_deref_type
:
28997 unsigned int byte_size
28998 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
28999 unsigned int encoding
29000 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
29001 hstate
.add_object (val1
->v
.val_int
);
29002 hstate
.add_object (byte_size
);
29003 hstate
.add_object (encoding
);
29006 case DW_OP_convert
:
29007 case DW_OP_reinterpret
:
29008 case DW_OP_GNU_convert
:
29009 case DW_OP_GNU_reinterpret
:
29010 if (val1
->val_class
== dw_val_class_unsigned_const
)
29012 hstate
.add_object (val1
->v
.val_unsigned
);
29016 case DW_OP_const_type
:
29017 case DW_OP_GNU_const_type
:
29019 unsigned int byte_size
29020 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
29021 unsigned int encoding
29022 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
29023 hstate
.add_object (byte_size
);
29024 hstate
.add_object (encoding
);
29025 if (loc
->dw_loc_opc
!= DW_OP_const_type
29026 && loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
29028 hstate
.add_object (val2
->val_class
);
29029 switch (val2
->val_class
)
29031 case dw_val_class_const
:
29032 hstate
.add_object (val2
->v
.val_int
);
29034 case dw_val_class_vec
:
29036 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
29037 unsigned int len
= val2
->v
.val_vec
.length
;
29039 hstate
.add_object (elt_size
);
29040 hstate
.add_object (len
);
29041 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
29044 case dw_val_class_const_double
:
29045 hstate
.add_object (val2
->v
.val_double
.low
);
29046 hstate
.add_object (val2
->v
.val_double
.high
);
29048 case dw_val_class_wide_int
:
29049 hstate
.add (val2
->v
.val_wide
->get_val (),
29050 get_full_len (*val2
->v
.val_wide
)
29051 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
29054 gcc_unreachable ();
29060 /* Other codes have no operands. */
29065 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
29068 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
29070 dw_loc_descr_ref l
;
29071 bool sizes_computed
= false;
29072 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
29073 size_of_locs (loc
);
29075 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
29077 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
29078 hstate
.add_object (opc
);
29079 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
29081 size_of_locs (loc
);
29082 sizes_computed
= true;
29084 hash_loc_operands (l
, hstate
);
29088 /* Compute hash of the whole location list LIST_HEAD. */
29091 hash_loc_list (dw_loc_list_ref list_head
)
29093 dw_loc_list_ref curr
= list_head
;
29094 inchash::hash hstate
;
29096 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29098 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
29099 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
29101 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
29102 hash_locs (curr
->expr
, hstate
);
29104 list_head
->hash
= hstate
.end ();
29107 /* Return true if X and Y opcodes have the same operands. */
29110 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29112 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
29113 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
29114 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
29115 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
29117 switch (x
->dw_loc_opc
)
29119 case DW_OP_const4u
:
29120 case DW_OP_const8u
:
29124 case DW_OP_const1u
:
29125 case DW_OP_const1s
:
29126 case DW_OP_const2u
:
29127 case DW_OP_const2s
:
29128 case DW_OP_const4s
:
29129 case DW_OP_const8s
:
29133 case DW_OP_plus_uconst
:
29169 case DW_OP_deref_size
:
29170 case DW_OP_xderef_size
:
29171 return valx1
->v
.val_int
== valy1
->v
.val_int
;
29174 /* If splitting debug info, the use of DW_OP_GNU_addr_index
29175 can cause irrelevant differences in dw_loc_addr. */
29176 gcc_assert (valx1
->val_class
== dw_val_class_loc
29177 && valy1
->val_class
== dw_val_class_loc
29178 && (dwarf_split_debug_info
29179 || x
->dw_loc_addr
== y
->dw_loc_addr
));
29180 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
29181 case DW_OP_implicit_value
:
29182 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
29183 || valx2
->val_class
!= valy2
->val_class
)
29185 switch (valx2
->val_class
)
29187 case dw_val_class_const
:
29188 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29189 case dw_val_class_vec
:
29190 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29191 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29192 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29193 valx2
->v
.val_vec
.elt_size
29194 * valx2
->v
.val_vec
.length
) == 0;
29195 case dw_val_class_const_double
:
29196 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29197 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29198 case dw_val_class_wide_int
:
29199 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29200 case dw_val_class_addr
:
29201 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
29203 gcc_unreachable ();
29206 case DW_OP_bit_piece
:
29207 return valx1
->v
.val_int
== valy1
->v
.val_int
29208 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29211 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
29212 case DW_OP_GNU_addr_index
:
29213 case DW_OP_GNU_const_index
:
29215 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
29216 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
29217 return rtx_equal_p (ax1
, ay1
);
29219 case DW_OP_implicit_pointer
:
29220 case DW_OP_GNU_implicit_pointer
:
29221 return valx1
->val_class
== dw_val_class_die_ref
29222 && valx1
->val_class
== valy1
->val_class
29223 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
29224 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29225 case DW_OP_entry_value
:
29226 case DW_OP_GNU_entry_value
:
29227 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
29228 case DW_OP_const_type
:
29229 case DW_OP_GNU_const_type
:
29230 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
29231 || valx2
->val_class
!= valy2
->val_class
)
29233 switch (valx2
->val_class
)
29235 case dw_val_class_const
:
29236 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29237 case dw_val_class_vec
:
29238 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29239 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29240 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29241 valx2
->v
.val_vec
.elt_size
29242 * valx2
->v
.val_vec
.length
) == 0;
29243 case dw_val_class_const_double
:
29244 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29245 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29246 case dw_val_class_wide_int
:
29247 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29249 gcc_unreachable ();
29251 case DW_OP_regval_type
:
29252 case DW_OP_deref_type
:
29253 case DW_OP_GNU_regval_type
:
29254 case DW_OP_GNU_deref_type
:
29255 return valx1
->v
.val_int
== valy1
->v
.val_int
29256 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
29257 case DW_OP_convert
:
29258 case DW_OP_reinterpret
:
29259 case DW_OP_GNU_convert
:
29260 case DW_OP_GNU_reinterpret
:
29261 if (valx1
->val_class
!= valy1
->val_class
)
29263 if (valx1
->val_class
== dw_val_class_unsigned_const
)
29264 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
29265 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29266 case DW_OP_GNU_parameter_ref
:
29267 return valx1
->val_class
== dw_val_class_die_ref
29268 && valx1
->val_class
== valy1
->val_class
29269 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29271 /* Other codes have no operands. */
29276 /* Return true if DWARF location expressions X and Y are the same. */
29279 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29281 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
29282 if (x
->dw_loc_opc
!= y
->dw_loc_opc
29283 || x
->dtprel
!= y
->dtprel
29284 || !compare_loc_operands (x
, y
))
29286 return x
== NULL
&& y
== NULL
;
29289 /* Hashtable helpers. */
29291 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
29293 static inline hashval_t
hash (const dw_loc_list_struct
*);
29294 static inline bool equal (const dw_loc_list_struct
*,
29295 const dw_loc_list_struct
*);
29298 /* Return precomputed hash of location list X. */
29301 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
29306 /* Return true if location lists A and B are the same. */
29309 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
29310 const dw_loc_list_struct
*b
)
29314 if (a
->hash
!= b
->hash
)
29316 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
29317 if (strcmp (a
->begin
, b
->begin
) != 0
29318 || strcmp (a
->end
, b
->end
) != 0
29319 || (a
->section
== NULL
) != (b
->section
== NULL
)
29320 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
29321 || !compare_locs (a
->expr
, b
->expr
))
29323 return a
== NULL
&& b
== NULL
;
29326 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
29329 /* Recursively optimize location lists referenced from DIE
29330 children and share them whenever possible. */
29333 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
29338 dw_loc_list_struct
**slot
;
29340 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29341 if (AT_class (a
) == dw_val_class_loc_list
)
29343 dw_loc_list_ref list
= AT_loc_list (a
);
29344 /* TODO: perform some optimizations here, before hashing
29345 it and storing into the hash table. */
29346 hash_loc_list (list
);
29347 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
29351 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
29354 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
29358 /* Recursively assign each location list a unique index into the debug_addr
29362 index_location_lists (dw_die_ref die
)
29368 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29369 if (AT_class (a
) == dw_val_class_loc_list
)
29371 dw_loc_list_ref list
= AT_loc_list (a
);
29372 dw_loc_list_ref curr
;
29373 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29375 /* Don't index an entry that has already been indexed
29376 or won't be output. */
29377 if (curr
->begin_entry
!= NULL
29378 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
29382 = add_addr_table_entry (xstrdup (curr
->begin
), ate_kind_label
);
29386 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
29389 /* Optimize location lists referenced from DIE
29390 children and share them whenever possible. */
29393 optimize_location_lists (dw_die_ref die
)
29395 loc_list_hash_type
htab (500);
29396 optimize_location_lists_1 (die
, &htab
);
29399 /* Traverse the limbo die list, and add parent/child links. The only
29400 dies without parents that should be here are concrete instances of
29401 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
29402 For concrete instances, we can get the parent die from the abstract
29406 flush_limbo_die_list (void)
29408 limbo_die_node
*node
;
29410 /* get_context_die calls force_decl_die, which can put new DIEs on the
29411 limbo list in LTO mode when nested functions are put in a different
29412 partition than that of their parent function. */
29413 while ((node
= limbo_die_list
))
29415 dw_die_ref die
= node
->die
;
29416 limbo_die_list
= node
->next
;
29418 if (die
->die_parent
== NULL
)
29420 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
29422 if (origin
&& origin
->die_parent
)
29423 add_child_die (origin
->die_parent
, die
);
29424 else if (is_cu_die (die
))
29426 else if (seen_error ())
29427 /* It's OK to be confused by errors in the input. */
29428 add_child_die (comp_unit_die (), die
);
29431 /* In certain situations, the lexical block containing a
29432 nested function can be optimized away, which results
29433 in the nested function die being orphaned. Likewise
29434 with the return type of that nested function. Force
29435 this to be a child of the containing function.
29437 It may happen that even the containing function got fully
29438 inlined and optimized out. In that case we are lost and
29439 assign the empty child. This should not be big issue as
29440 the function is likely unreachable too. */
29441 gcc_assert (node
->created_for
);
29443 if (DECL_P (node
->created_for
))
29444 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
29445 else if (TYPE_P (node
->created_for
))
29446 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
29448 origin
= comp_unit_die ();
29450 add_child_die (origin
, die
);
29456 /* Output stuff that dwarf requires at the end of every file,
29457 and generate the DWARF-2 debugging info. */
29460 dwarf2out_finish (const char *)
29462 comdat_type_node
*ctnode
;
29463 dw_die_ref main_comp_unit_die
;
29464 unsigned char checksum
[16];
29466 /* Flush out any latecomers to the limbo party. */
29467 flush_limbo_die_list ();
29471 verify_die (comp_unit_die ());
29472 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
29473 verify_die (node
->die
);
29476 /* We shouldn't have any symbols with delayed asm names for
29477 DIEs generated after early finish. */
29478 gcc_assert (deferred_asm_name
== NULL
);
29480 gen_remaining_tmpl_value_param_die_attribute ();
29482 #if ENABLE_ASSERT_CHECKING
29484 dw_die_ref die
= comp_unit_die (), c
;
29485 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
29488 resolve_addr (comp_unit_die ());
29489 move_marked_base_types ();
29491 /* Initialize sections and labels used for actual assembler output. */
29492 init_sections_and_labels ();
29494 /* Traverse the DIE's and add sibling attributes to those DIE's that
29496 add_sibling_attributes (comp_unit_die ());
29497 limbo_die_node
*node
;
29498 for (node
= cu_die_list
; node
; node
= node
->next
)
29499 add_sibling_attributes (node
->die
);
29500 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29501 add_sibling_attributes (ctnode
->root_die
);
29503 /* When splitting DWARF info, we put some attributes in the
29504 skeleton compile_unit DIE that remains in the .o, while
29505 most attributes go in the DWO compile_unit_die. */
29506 if (dwarf_split_debug_info
)
29508 limbo_die_node
*cu
;
29509 main_comp_unit_die
= gen_compile_unit_die (NULL
);
29510 if (dwarf_version
>= 5)
29511 main_comp_unit_die
->die_tag
= DW_TAG_skeleton_unit
;
29512 cu
= limbo_die_list
;
29513 gcc_assert (cu
->die
== main_comp_unit_die
);
29514 limbo_die_list
= limbo_die_list
->next
;
29515 cu
->next
= cu_die_list
;
29519 main_comp_unit_die
= comp_unit_die ();
29521 /* Output a terminator label for the .text section. */
29522 switch_to_section (text_section
);
29523 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
29524 if (cold_text_section
)
29526 switch_to_section (cold_text_section
);
29527 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
29530 /* We can only use the low/high_pc attributes if all of the code was
29532 if (!have_multiple_function_sections
29533 || (dwarf_version
< 3 && dwarf_strict
))
29535 /* Don't add if the CU has no associated code. */
29536 if (text_section_used
)
29537 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
29538 text_end_label
, true);
29544 bool range_list_added
= false;
29546 if (text_section_used
)
29547 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
29548 text_end_label
, &range_list_added
, true);
29549 if (cold_text_section_used
)
29550 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
29551 cold_end_label
, &range_list_added
, true);
29553 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
29555 if (DECL_IGNORED_P (fde
->decl
))
29557 if (!fde
->in_std_section
)
29558 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
29559 fde
->dw_fde_end
, &range_list_added
,
29561 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
29562 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
29563 fde
->dw_fde_second_end
, &range_list_added
,
29567 if (range_list_added
)
29569 /* We need to give .debug_loc and .debug_ranges an appropriate
29570 "base address". Use zero so that these addresses become
29571 absolute. Historically, we've emitted the unexpected
29572 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
29573 Emit both to give time for other tools to adapt. */
29574 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
29575 if (! dwarf_strict
&& dwarf_version
< 4)
29576 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
29582 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29583 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
29584 debug_line_section_label
);
29587 add_AT_macptr (comp_unit_die (),
29588 dwarf_version
>= 5 ? DW_AT_macros
29589 : dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
29590 macinfo_section_label
);
29592 if (dwarf_split_debug_info
)
29594 if (have_location_lists
)
29596 if (dwarf_version
>= 5)
29597 add_AT_loclistsptr (comp_unit_die (), DW_AT_loclists_base
,
29598 loc_section_label
);
29599 /* optimize_location_lists calculates the size of the lists,
29600 so index them first, and assign indices to the entries.
29601 Although optimize_location_lists will remove entries from
29602 the table, it only does so for duplicates, and therefore
29603 only reduces ref_counts to 1. */
29604 index_location_lists (comp_unit_die ());
29607 if (addr_index_table
!= NULL
)
29609 unsigned int index
= 0;
29611 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
29617 if (have_location_lists
)
29619 optimize_location_lists (comp_unit_die ());
29620 /* And finally assign indexes to the entries for -gsplit-dwarf. */
29621 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
29622 assign_location_list_indexes (comp_unit_die ());
29625 save_macinfo_strings ();
29627 if (dwarf_split_debug_info
)
29629 unsigned int index
= 0;
29631 /* Add attributes common to skeleton compile_units and
29632 type_units. Because these attributes include strings, it
29633 must be done before freezing the string table. Top-level
29634 skeleton die attrs are added when the skeleton type unit is
29635 created, so ensure it is created by this point. */
29636 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
29637 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
29640 /* Output all of the compilation units. We put the main one last so that
29641 the offsets are available to output_pubnames. */
29642 for (node
= cu_die_list
; node
; node
= node
->next
)
29643 output_comp_unit (node
->die
, 0, NULL
);
29645 hash_table
<comdat_type_hasher
> comdat_type_table (100);
29646 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29648 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
29650 /* Don't output duplicate types. */
29651 if (*slot
!= HTAB_EMPTY_ENTRY
)
29654 /* Add a pointer to the line table for the main compilation unit
29655 so that the debugger can make sense of DW_AT_decl_file
29657 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29658 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
29659 (!dwarf_split_debug_info
29660 ? debug_line_section_label
29661 : debug_skeleton_line_section_label
));
29663 output_comdat_type_unit (ctnode
);
29667 /* The AT_pubnames attribute needs to go in all skeleton dies, including
29668 both the main_cu and all skeleton TUs. Making this call unconditional
29669 would end up either adding a second copy of the AT_pubnames attribute, or
29670 requiring a special case in add_top_level_skeleton_die_attrs. */
29671 if (!dwarf_split_debug_info
)
29672 add_AT_pubnames (comp_unit_die ());
29674 if (dwarf_split_debug_info
)
29677 struct md5_ctx ctx
;
29679 if (dwarf_version
>= 5 && !vec_safe_is_empty (ranges_table
))
29682 /* Compute a checksum of the comp_unit to use as the dwo_id. */
29683 md5_init_ctx (&ctx
);
29685 die_checksum (comp_unit_die (), &ctx
, &mark
);
29686 unmark_all_dies (comp_unit_die ());
29687 md5_finish_ctx (&ctx
, checksum
);
29689 if (dwarf_version
< 5)
29691 /* Use the first 8 bytes of the checksum as the dwo_id,
29692 and add it to both comp-unit DIEs. */
29693 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
29694 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
29697 /* Add the base offset of the ranges table to the skeleton
29699 if (!vec_safe_is_empty (ranges_table
))
29701 if (dwarf_version
>= 5)
29702 add_AT_lineptr (main_comp_unit_die
, DW_AT_rnglists_base
,
29703 ranges_base_label
);
29705 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
29706 ranges_section_label
);
29709 switch_to_section (debug_addr_section
);
29710 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
29711 output_addr_table ();
29714 /* Output the main compilation unit if non-empty or if .debug_macinfo
29715 or .debug_macro will be emitted. */
29716 output_comp_unit (comp_unit_die (), have_macinfo
,
29717 dwarf_split_debug_info
? checksum
: NULL
);
29719 if (dwarf_split_debug_info
&& info_section_emitted
)
29720 output_skeleton_debug_sections (main_comp_unit_die
, checksum
);
29722 /* Output the abbreviation table. */
29723 if (vec_safe_length (abbrev_die_table
) != 1)
29725 switch_to_section (debug_abbrev_section
);
29726 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
29727 output_abbrev_section ();
29730 /* Output location list section if necessary. */
29731 if (have_location_lists
)
29733 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
29734 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
29735 /* Output the location lists info. */
29736 switch_to_section (debug_loc_section
);
29737 if (dwarf_version
>= 5)
29739 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_LOC_SECTION_LABEL
, 1);
29740 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_LOC_SECTION_LABEL
, 2);
29741 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
29742 dw2_asm_output_data (4, 0xffffffff,
29743 "Initial length escape value indicating "
29744 "64-bit DWARF extension");
29745 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
29746 "Length of Location Lists");
29747 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
29748 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
29749 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
29750 dw2_asm_output_data (1, 0, "Segment Size");
29751 dw2_asm_output_data (4, dwarf_split_debug_info
? loc_list_idx
: 0,
29752 "Offset Entry Count");
29754 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
29755 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
29757 unsigned int save_loc_list_idx
= loc_list_idx
;
29759 output_loclists_offsets (comp_unit_die ());
29760 gcc_assert (save_loc_list_idx
== loc_list_idx
);
29762 output_location_lists (comp_unit_die ());
29763 if (dwarf_version
>= 5)
29764 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
29767 output_pubtables ();
29769 /* Output the address range information if a CU (.debug_info section)
29770 was emitted. We output an empty table even if we had no functions
29771 to put in it. This because the consumer has no way to tell the
29772 difference between an empty table that we omitted and failure to
29773 generate a table that would have contained data. */
29774 if (info_section_emitted
)
29776 switch_to_section (debug_aranges_section
);
29780 /* Output ranges section if necessary. */
29781 if (!vec_safe_is_empty (ranges_table
))
29783 if (dwarf_version
>= 5)
29784 output_rnglists ();
29789 /* Have to end the macro section. */
29792 switch_to_section (debug_macinfo_section
);
29793 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
29795 dw2_asm_output_data (1, 0, "End compilation unit");
29798 /* Output the source line correspondence table. We must do this
29799 even if there is no line information. Otherwise, on an empty
29800 translation unit, we will generate a present, but empty,
29801 .debug_info section. IRIX 6.5 `nm' will then complain when
29802 examining the file. This is done late so that any filenames
29803 used by the debug_info section are marked as 'used'. */
29804 switch_to_section (debug_line_section
);
29805 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
29806 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
29807 output_line_info (false);
29809 if (dwarf_split_debug_info
&& info_section_emitted
)
29811 switch_to_section (debug_skeleton_line_section
);
29812 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
29813 output_line_info (true);
29816 /* If we emitted any indirect strings, output the string table too. */
29817 if (debug_str_hash
|| skeleton_debug_str_hash
)
29818 output_indirect_strings ();
29819 if (debug_line_str_hash
)
29821 switch_to_section (debug_line_str_section
);
29822 const enum dwarf_form form
= DW_FORM_line_strp
;
29823 debug_line_str_hash
->traverse
<enum dwarf_form
,
29824 output_indirect_string
> (form
);
29828 /* Perform any cleanups needed after the early debug generation pass
29832 dwarf2out_early_finish (const char *filename
)
29836 /* PCH might result in DW_AT_producer string being restored from the
29837 header compilation, so always fill it with empty string initially
29838 and overwrite only here. */
29839 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
29840 producer_string
= gen_producer_string ();
29841 producer
->dw_attr_val
.v
.val_str
->refcount
--;
29842 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
29844 /* Add the name for the main input file now. We delayed this from
29845 dwarf2out_init to avoid complications with PCH. */
29846 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
29847 add_comp_dir_attribute (comp_unit_die ());
29849 /* When emitting DWARF5 .debug_line_str, move DW_AT_name and
29850 DW_AT_comp_dir into .debug_line_str section. */
29851 if (!DWARF2_ASM_LINE_DEBUG_INFO
29852 && dwarf_version
>= 5
29853 && DWARF5_USE_DEBUG_LINE_STR
)
29855 for (int i
= 0; i
< 2; i
++)
29857 dw_attr_node
*a
= get_AT (comp_unit_die (),
29858 i
? DW_AT_comp_dir
: DW_AT_name
);
29860 || AT_class (a
) != dw_val_class_str
29861 || strlen (AT_string (a
)) + 1 <= DWARF_OFFSET_SIZE
)
29864 if (! debug_line_str_hash
)
29865 debug_line_str_hash
29866 = hash_table
<indirect_string_hasher
>::create_ggc (10);
29868 struct indirect_string_node
*node
29869 = find_AT_string_in_table (AT_string (a
), debug_line_str_hash
);
29870 set_indirect_string (node
);
29871 node
->form
= DW_FORM_line_strp
;
29872 a
->dw_attr_val
.v
.val_str
->refcount
--;
29873 a
->dw_attr_val
.v
.val_str
= node
;
29877 /* With LTO early dwarf was really finished at compile-time, so make
29878 sure to adjust the phase after annotating the LTRANS CU DIE. */
29881 early_dwarf_finished
= true;
29885 /* Walk through the list of incomplete types again, trying once more to
29886 emit full debugging info for them. */
29887 retry_incomplete_types ();
29889 /* The point here is to flush out the limbo list so that it is empty
29890 and we don't need to stream it for LTO. */
29891 flush_limbo_die_list ();
29893 gen_scheduled_generic_parms_dies ();
29894 gen_remaining_tmpl_value_param_die_attribute ();
29896 /* Add DW_AT_linkage_name for all deferred DIEs. */
29897 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
29899 tree decl
= node
->created_for
;
29900 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
29901 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
29902 ended up in deferred_asm_name before we knew it was
29903 constant and never written to disk. */
29904 && DECL_ASSEMBLER_NAME (decl
))
29906 add_linkage_attr (node
->die
, decl
);
29907 move_linkage_attr (node
->die
);
29910 deferred_asm_name
= NULL
;
29912 if (flag_eliminate_unused_debug_types
)
29913 prune_unused_types ();
29915 /* Generate separate COMDAT sections for type DIEs. */
29916 if (use_debug_types
)
29918 break_out_comdat_types (comp_unit_die ());
29920 /* Each new type_unit DIE was added to the limbo die list when created.
29921 Since these have all been added to comdat_type_list, clear the
29923 limbo_die_list
= NULL
;
29925 /* For each new comdat type unit, copy declarations for incomplete
29926 types to make the new unit self-contained (i.e., no direct
29927 references to the main compile unit). */
29928 for (comdat_type_node
*ctnode
= comdat_type_list
;
29929 ctnode
!= NULL
; ctnode
= ctnode
->next
)
29930 copy_decls_for_unworthy_types (ctnode
->root_die
);
29931 copy_decls_for_unworthy_types (comp_unit_die ());
29933 /* In the process of copying declarations from one unit to another,
29934 we may have left some declarations behind that are no longer
29935 referenced. Prune them. */
29936 prune_unused_types ();
29939 /* Generate separate CUs for each of the include files we've seen.
29940 They will go into limbo_die_list and from there to cu_die_list. */
29941 if (flag_eliminate_dwarf2_dups
)
29943 gcc_assert (limbo_die_list
== NULL
);
29944 break_out_includes (comp_unit_die ());
29945 limbo_die_node
*cu
;
29946 while ((cu
= limbo_die_list
))
29948 limbo_die_list
= cu
->next
;
29949 cu
->next
= cu_die_list
;
29954 /* The early debug phase is now finished. */
29955 early_dwarf_finished
= true;
29958 /* Reset all state within dwarf2out.c so that we can rerun the compiler
29959 within the same process. For use by toplev::finalize. */
29962 dwarf2out_c_finalize (void)
29964 last_var_location_insn
= NULL
;
29965 cached_next_real_insn
= NULL
;
29966 used_rtx_array
= NULL
;
29967 incomplete_types
= NULL
;
29968 decl_scope_table
= NULL
;
29969 debug_info_section
= NULL
;
29970 debug_skeleton_info_section
= NULL
;
29971 debug_abbrev_section
= NULL
;
29972 debug_skeleton_abbrev_section
= NULL
;
29973 debug_aranges_section
= NULL
;
29974 debug_addr_section
= NULL
;
29975 debug_macinfo_section
= NULL
;
29976 debug_line_section
= NULL
;
29977 debug_skeleton_line_section
= NULL
;
29978 debug_loc_section
= NULL
;
29979 debug_pubnames_section
= NULL
;
29980 debug_pubtypes_section
= NULL
;
29981 debug_str_section
= NULL
;
29982 debug_line_str_section
= NULL
;
29983 debug_str_dwo_section
= NULL
;
29984 debug_str_offsets_section
= NULL
;
29985 debug_ranges_section
= NULL
;
29986 debug_frame_section
= NULL
;
29988 debug_str_hash
= NULL
;
29989 debug_line_str_hash
= NULL
;
29990 skeleton_debug_str_hash
= NULL
;
29991 dw2_string_counter
= 0;
29992 have_multiple_function_sections
= false;
29993 text_section_used
= false;
29994 cold_text_section_used
= false;
29995 cold_text_section
= NULL
;
29996 current_unit_personality
= NULL
;
29998 early_dwarf
= false;
29999 early_dwarf_finished
= false;
30001 next_die_offset
= 0;
30002 single_comp_unit_die
= NULL
;
30003 comdat_type_list
= NULL
;
30004 limbo_die_list
= NULL
;
30006 decl_die_table
= NULL
;
30007 common_block_die_table
= NULL
;
30008 decl_loc_table
= NULL
;
30009 call_arg_locations
= NULL
;
30010 call_arg_loc_last
= NULL
;
30011 call_site_count
= -1;
30012 tail_call_site_count
= -1;
30013 cached_dw_loc_list_table
= NULL
;
30014 abbrev_die_table
= NULL
;
30015 delete dwarf_proc_stack_usage_map
;
30016 dwarf_proc_stack_usage_map
= NULL
;
30017 line_info_label_num
= 0;
30018 cur_line_info_table
= NULL
;
30019 text_section_line_info
= NULL
;
30020 cold_text_section_line_info
= NULL
;
30021 separate_line_info
= NULL
;
30022 info_section_emitted
= false;
30023 pubname_table
= NULL
;
30024 pubtype_table
= NULL
;
30025 macinfo_table
= NULL
;
30026 ranges_table
= NULL
;
30027 ranges_by_label
= NULL
;
30029 have_location_lists
= false;
30032 last_emitted_file
= NULL
;
30034 tmpl_value_parm_die_table
= NULL
;
30035 generic_type_instances
= NULL
;
30036 frame_pointer_fb_offset
= 0;
30037 frame_pointer_fb_offset_valid
= false;
30038 base_types
.release ();
30039 XDELETEVEC (producer_string
);
30040 producer_string
= NULL
;
30043 #include "gt-dwarf2out.h"