1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2016 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"
66 #include "stringpool.h"
67 #include "insn-config.h"
70 #include "diagnostic.h"
71 #include "fold-const.h"
72 #include "stor-layout.h"
80 #include "dwarf2out.h"
81 #include "dwarf2asm.h"
84 #include "tree-pretty-print.h"
86 #include "common/common-target.h"
87 #include "langhooks.h"
92 #include "gdb/gdb-index.h"
95 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
96 static rtx_insn
*last_var_location_insn
;
97 static rtx_insn
*cached_next_real_insn
;
98 static void dwarf2out_decl (tree
);
100 #ifndef XCOFF_DEBUGGING_INFO
101 #define XCOFF_DEBUGGING_INFO 0
104 #ifndef HAVE_XCOFF_DWARF_EXTRAS
105 #define HAVE_XCOFF_DWARF_EXTRAS 0
108 #ifdef VMS_DEBUGGING_INFO
109 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
111 /* Define this macro to be a nonzero value if the directory specifications
112 which are output in the debug info should end with a separator. */
113 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
114 /* Define this macro to evaluate to a nonzero value if GCC should refrain
115 from generating indirect strings in DWARF2 debug information, for instance
116 if your target is stuck with an old version of GDB that is unable to
117 process them properly or uses VMS Debug. */
118 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
120 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
121 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
124 /* ??? Poison these here until it can be done generically. They've been
125 totally replaced in this file; make sure it stays that way. */
126 #undef DWARF2_UNWIND_INFO
127 #undef DWARF2_FRAME_INFO
128 #if (GCC_VERSION >= 3000)
129 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
132 /* The size of the target's pointer type. */
134 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
137 /* Array of RTXes referenced by the debugging information, which therefore
138 must be kept around forever. */
139 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
141 /* A pointer to the base of a list of incomplete types which might be
142 completed at some later time. incomplete_types_list needs to be a
143 vec<tree, va_gc> *because we want to tell the garbage collector about
145 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
147 /* A pointer to the base of a table of references to declaration
148 scopes. This table is a display which tracks the nesting
149 of declaration scopes at the current scope and containing
150 scopes. This table is used to find the proper place to
151 define type declaration DIE's. */
152 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
154 /* Pointers to various DWARF2 sections. */
155 static GTY(()) section
*debug_info_section
;
156 static GTY(()) section
*debug_skeleton_info_section
;
157 static GTY(()) section
*debug_abbrev_section
;
158 static GTY(()) section
*debug_skeleton_abbrev_section
;
159 static GTY(()) section
*debug_aranges_section
;
160 static GTY(()) section
*debug_addr_section
;
161 static GTY(()) section
*debug_macinfo_section
;
162 static GTY(()) section
*debug_line_section
;
163 static GTY(()) section
*debug_skeleton_line_section
;
164 static GTY(()) section
*debug_loc_section
;
165 static GTY(()) section
*debug_pubnames_section
;
166 static GTY(()) section
*debug_pubtypes_section
;
167 static GTY(()) section
*debug_str_section
;
168 static GTY(()) section
*debug_str_dwo_section
;
169 static GTY(()) section
*debug_str_offsets_section
;
170 static GTY(()) section
*debug_ranges_section
;
171 static GTY(()) section
*debug_frame_section
;
173 /* Maximum size (in bytes) of an artificially generated label. */
174 #define MAX_ARTIFICIAL_LABEL_BYTES 30
176 /* According to the (draft) DWARF 3 specification, the initial length
177 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
178 bytes are 0xffffffff, followed by the length stored in the next 8
181 However, the SGI/MIPS ABI uses an initial length which is equal to
182 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
184 #ifndef DWARF_INITIAL_LENGTH_SIZE
185 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
188 /* Round SIZE up to the nearest BOUNDARY. */
189 #define DWARF_ROUND(SIZE,BOUNDARY) \
190 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
192 /* CIE identifier. */
193 #if HOST_BITS_PER_WIDE_INT >= 64
194 #define DWARF_CIE_ID \
195 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
197 #define DWARF_CIE_ID DW_CIE_ID
201 /* A vector for a table that contains frame description
202 information for each routine. */
203 #define NOT_INDEXED (-1U)
204 #define NO_INDEX_ASSIGNED (-2U)
206 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
208 struct GTY((for_user
)) indirect_string_node
{
210 unsigned int refcount
;
211 enum dwarf_form form
;
216 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
218 typedef const char *compare_type
;
220 static hashval_t
hash (indirect_string_node
*);
221 static bool equal (indirect_string_node
*, const char *);
224 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
226 /* With split_debug_info, both the comp_dir and dwo_name go in the
227 main object file, rather than the dwo, similar to the force_direct
228 parameter elsewhere but with additional complications:
230 1) The string is needed in both the main object file and the dwo.
231 That is, the comp_dir and dwo_name will appear in both places.
233 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
234 DW_FORM_GNU_str_index.
236 3) GCC chooses the form to use late, depending on the size and
239 Rather than forcing the all debug string handling functions and
240 callers to deal with these complications, simply use a separate,
241 special-cased string table for any attribute that should go in the
242 main object file. This limits the complexity to just the places
245 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
247 static GTY(()) int dw2_string_counter
;
249 /* True if the compilation unit places functions in more than one section. */
250 static GTY(()) bool have_multiple_function_sections
= false;
252 /* Whether the default text and cold text sections have been used at all. */
254 static GTY(()) bool text_section_used
= false;
255 static GTY(()) bool cold_text_section_used
= false;
257 /* The default cold text section. */
258 static GTY(()) section
*cold_text_section
;
260 /* The DIE for C++14 'auto' in a function return type. */
261 static GTY(()) dw_die_ref auto_die
;
263 /* The DIE for C++14 'decltype(auto)' in a function return type. */
264 static GTY(()) dw_die_ref decltype_auto_die
;
266 /* Forward declarations for functions defined in this file. */
268 static char *stripattributes (const char *);
269 static void output_call_frame_info (int);
270 static void dwarf2out_note_section_used (void);
272 /* Personality decl of current unit. Used only when assembler does not support
274 static GTY(()) rtx current_unit_personality
;
276 /* Data and reference forms for relocatable data. */
277 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
278 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
280 #ifndef DEBUG_FRAME_SECTION
281 #define DEBUG_FRAME_SECTION ".debug_frame"
284 #ifndef FUNC_BEGIN_LABEL
285 #define FUNC_BEGIN_LABEL "LFB"
288 #ifndef FUNC_END_LABEL
289 #define FUNC_END_LABEL "LFE"
292 #ifndef PROLOGUE_END_LABEL
293 #define PROLOGUE_END_LABEL "LPE"
296 #ifndef EPILOGUE_BEGIN_LABEL
297 #define EPILOGUE_BEGIN_LABEL "LEB"
300 #ifndef FRAME_BEGIN_LABEL
301 #define FRAME_BEGIN_LABEL "Lframe"
303 #define CIE_AFTER_SIZE_LABEL "LSCIE"
304 #define CIE_END_LABEL "LECIE"
305 #define FDE_LABEL "LSFDE"
306 #define FDE_AFTER_SIZE_LABEL "LASFDE"
307 #define FDE_END_LABEL "LEFDE"
308 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
309 #define LINE_NUMBER_END_LABEL "LELT"
310 #define LN_PROLOG_AS_LABEL "LASLTP"
311 #define LN_PROLOG_END_LABEL "LELTP"
312 #define DIE_LABEL_PREFIX "DW"
314 /* Match the base name of a file to the base name of a compilation unit. */
317 matches_main_base (const char *path
)
319 /* Cache the last query. */
320 static const char *last_path
= NULL
;
321 static int last_match
= 0;
322 if (path
!= last_path
)
325 int length
= base_of_path (path
, &base
);
327 last_match
= (length
== main_input_baselength
328 && memcmp (base
, main_input_basename
, length
) == 0);
333 #ifdef DEBUG_DEBUG_STRUCT
336 dump_struct_debug (tree type
, enum debug_info_usage usage
,
337 enum debug_struct_file criterion
, int generic
,
338 int matches
, int result
)
340 /* Find the type name. */
341 tree type_decl
= TYPE_STUB_DECL (type
);
343 const char *name
= 0;
344 if (TREE_CODE (t
) == TYPE_DECL
)
347 name
= IDENTIFIER_POINTER (t
);
349 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
351 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
352 matches
? "bas" : "hdr",
353 generic
? "gen" : "ord",
354 usage
== DINFO_USAGE_DFN
? ";" :
355 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
357 (void*) type_decl
, name
);
360 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
361 dump_struct_debug (type, usage, criterion, generic, matches, result)
365 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
370 /* Get the number of HOST_WIDE_INTs needed to represent the precision
371 of the number. Some constants have a large uniform precision, so
372 we get the precision needed for the actual value of the number. */
375 get_full_len (const wide_int
&op
)
377 int prec
= wi::min_precision (op
, UNSIGNED
);
378 return ((prec
+ HOST_BITS_PER_WIDE_INT
- 1)
379 / HOST_BITS_PER_WIDE_INT
);
383 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
385 enum debug_struct_file criterion
;
387 bool generic
= lang_hooks
.types
.generic_p (type
);
390 criterion
= debug_struct_generic
[usage
];
392 criterion
= debug_struct_ordinary
[usage
];
394 if (criterion
== DINFO_STRUCT_FILE_NONE
)
395 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
396 if (criterion
== DINFO_STRUCT_FILE_ANY
)
397 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
399 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
401 if (type_decl
!= NULL
)
403 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
404 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
406 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
407 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
410 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
413 /* Return a pointer to a copy of the section string name S with all
414 attributes stripped off, and an asterisk prepended (for assemble_name). */
417 stripattributes (const char *s
)
419 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
424 while (*s
&& *s
!= ',')
431 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
432 switch to the data section instead, and write out a synthetic start label
433 for collect2 the first time around. */
436 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
438 if (eh_frame_section
== 0)
442 if (EH_TABLES_CAN_BE_READ_ONLY
)
448 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
450 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
452 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
455 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
456 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
457 && (per_encoding
& 0x70) != DW_EH_PE_absptr
458 && (per_encoding
& 0x70) != DW_EH_PE_aligned
459 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
460 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
461 ? 0 : SECTION_WRITE
);
464 flags
= SECTION_WRITE
;
466 #ifdef EH_FRAME_SECTION_NAME
467 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
469 eh_frame_section
= ((flags
== SECTION_WRITE
)
470 ? data_section
: readonly_data_section
);
471 #endif /* EH_FRAME_SECTION_NAME */
474 switch_to_section (eh_frame_section
);
476 #ifdef EH_FRAME_THROUGH_COLLECT2
477 /* We have no special eh_frame section. Emit special labels to guide
481 tree label
= get_file_function_name ("F");
482 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
483 targetm
.asm_out
.globalize_label (asm_out_file
,
484 IDENTIFIER_POINTER (label
));
485 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
490 /* Switch [BACK] to the eh or debug frame table section, depending on
494 switch_to_frame_table_section (int for_eh
, bool back
)
497 switch_to_eh_frame_section (back
);
500 if (!debug_frame_section
)
501 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
502 SECTION_DEBUG
, NULL
);
503 switch_to_section (debug_frame_section
);
507 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
509 enum dw_cfi_oprnd_type
510 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
515 case DW_CFA_GNU_window_save
:
516 case DW_CFA_remember_state
:
517 case DW_CFA_restore_state
:
518 return dw_cfi_oprnd_unused
;
521 case DW_CFA_advance_loc1
:
522 case DW_CFA_advance_loc2
:
523 case DW_CFA_advance_loc4
:
524 case DW_CFA_MIPS_advance_loc8
:
525 return dw_cfi_oprnd_addr
;
528 case DW_CFA_offset_extended
:
530 case DW_CFA_offset_extended_sf
:
531 case DW_CFA_def_cfa_sf
:
533 case DW_CFA_restore_extended
:
534 case DW_CFA_undefined
:
535 case DW_CFA_same_value
:
536 case DW_CFA_def_cfa_register
:
537 case DW_CFA_register
:
538 case DW_CFA_expression
:
539 return dw_cfi_oprnd_reg_num
;
541 case DW_CFA_def_cfa_offset
:
542 case DW_CFA_GNU_args_size
:
543 case DW_CFA_def_cfa_offset_sf
:
544 return dw_cfi_oprnd_offset
;
546 case DW_CFA_def_cfa_expression
:
547 return dw_cfi_oprnd_loc
;
554 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
556 enum dw_cfi_oprnd_type
557 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
562 case DW_CFA_def_cfa_sf
:
564 case DW_CFA_offset_extended_sf
:
565 case DW_CFA_offset_extended
:
566 return dw_cfi_oprnd_offset
;
568 case DW_CFA_register
:
569 return dw_cfi_oprnd_reg_num
;
571 case DW_CFA_expression
:
572 return dw_cfi_oprnd_loc
;
575 return dw_cfi_oprnd_unused
;
579 /* Output one FDE. */
582 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
583 char *section_start_label
, int fde_encoding
, char *augmentation
,
584 bool any_lsda_needed
, int lsda_encoding
)
586 const char *begin
, *end
;
587 static unsigned int j
;
590 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
592 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
594 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
595 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
596 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
598 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
599 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
600 " indicating 64-bit DWARF extension");
601 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
604 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
607 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
609 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
610 debug_frame_section
, "FDE CIE offset");
612 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
613 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
617 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
618 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
619 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
620 "FDE initial location");
621 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
622 end
, begin
, "FDE address range");
626 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
627 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
634 int size
= size_of_encoded_value (lsda_encoding
);
636 if (lsda_encoding
== DW_EH_PE_aligned
)
638 int offset
= ( 4 /* Length */
640 + 2 * size_of_encoded_value (fde_encoding
)
641 + 1 /* Augmentation size */ );
642 int pad
= -offset
& (PTR_SIZE
- 1);
645 gcc_assert (size_of_uleb128 (size
) == 1);
648 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
650 if (fde
->uses_eh_lsda
)
652 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
653 fde
->funcdef_number
);
654 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
655 gen_rtx_SYMBOL_REF (Pmode
, l1
),
657 "Language Specific Data Area");
661 if (lsda_encoding
== DW_EH_PE_aligned
)
662 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
663 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
664 "Language Specific Data Area (none)");
668 dw2_asm_output_data_uleb128 (0, "Augmentation size");
671 /* Loop through the Call Frame Instructions associated with this FDE. */
672 fde
->dw_fde_current_label
= begin
;
674 size_t from
, until
, i
;
677 until
= vec_safe_length (fde
->dw_fde_cfi
);
679 if (fde
->dw_fde_second_begin
== NULL
)
682 until
= fde
->dw_fde_switch_cfi_index
;
684 from
= fde
->dw_fde_switch_cfi_index
;
686 for (i
= from
; i
< until
; i
++)
687 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
690 /* If we are to emit a ref/link from function bodies to their frame tables,
691 do it now. This is typically performed to make sure that tables
692 associated with functions are dragged with them and not discarded in
693 garbage collecting links. We need to do this on a per function basis to
694 cope with -ffunction-sections. */
696 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
697 /* Switch to the function section, emit the ref to the tables, and
698 switch *back* into the table section. */
699 switch_to_section (function_section (fde
->decl
));
700 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
701 switch_to_frame_table_section (for_eh
, true);
704 /* Pad the FDE out to an address sized boundary. */
705 ASM_OUTPUT_ALIGN (asm_out_file
,
706 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
707 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
712 /* Return true if frame description entry FDE is needed for EH. */
715 fde_needed_for_eh_p (dw_fde_ref fde
)
717 if (flag_asynchronous_unwind_tables
)
720 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
723 if (fde
->uses_eh_lsda
)
726 /* If exceptions are enabled, we have collected nothrow info. */
727 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
733 /* Output the call frame information used to record information
734 that relates to calculating the frame pointer, and records the
735 location of saved registers. */
738 output_call_frame_info (int for_eh
)
743 char l1
[20], l2
[20], section_start_label
[20];
744 bool any_lsda_needed
= false;
745 char augmentation
[6];
746 int augmentation_size
;
747 int fde_encoding
= DW_EH_PE_absptr
;
748 int per_encoding
= DW_EH_PE_absptr
;
749 int lsda_encoding
= DW_EH_PE_absptr
;
751 rtx personality
= NULL
;
754 /* Don't emit a CIE if there won't be any FDEs. */
758 /* Nothing to do if the assembler's doing it all. */
759 if (dwarf2out_do_cfi_asm ())
762 /* If we don't have any functions we'll want to unwind out of, don't emit
763 any EH unwind information. If we make FDEs linkonce, we may have to
764 emit an empty label for an FDE that wouldn't otherwise be emitted. We
765 want to avoid having an FDE kept around when the function it refers to
766 is discarded. Example where this matters: a primary function template
767 in C++ requires EH information, an explicit specialization doesn't. */
770 bool any_eh_needed
= false;
772 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
774 if (fde
->uses_eh_lsda
)
775 any_eh_needed
= any_lsda_needed
= true;
776 else if (fde_needed_for_eh_p (fde
))
777 any_eh_needed
= true;
778 else if (TARGET_USES_WEAK_UNWIND_INFO
)
779 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
786 /* We're going to be generating comments, so turn on app. */
790 /* Switch to the proper frame section, first time. */
791 switch_to_frame_table_section (for_eh
, false);
793 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
794 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
796 /* Output the CIE. */
797 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
798 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
799 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
801 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
802 dw2_asm_output_data (4, 0xffffffff,
803 "Initial length escape value indicating 64-bit DWARF extension");
804 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
805 "Length of Common Information Entry");
807 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
809 /* Now that the CIE pointer is PC-relative for EH,
810 use 0 to identify the CIE. */
811 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
812 (for_eh
? 0 : DWARF_CIE_ID
),
813 "CIE Identifier Tag");
815 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
816 use CIE version 1, unless that would produce incorrect results
817 due to overflowing the return register column. */
818 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
820 if (return_reg
>= 256 || dwarf_version
> 2)
822 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
825 augmentation_size
= 0;
827 personality
= current_unit_personality
;
833 z Indicates that a uleb128 is present to size the
834 augmentation section.
835 L Indicates the encoding (and thus presence) of
836 an LSDA pointer in the FDE augmentation.
837 R Indicates a non-default pointer encoding for
839 P Indicates the presence of an encoding + language
840 personality routine in the CIE augmentation. */
842 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
843 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
844 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
846 p
= augmentation
+ 1;
850 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
851 assemble_external_libcall (personality
);
856 augmentation_size
+= 1;
858 if (fde_encoding
!= DW_EH_PE_absptr
)
861 augmentation_size
+= 1;
863 if (p
> augmentation
+ 1)
865 augmentation
[0] = 'z';
869 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
870 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
872 int offset
= ( 4 /* Length */
874 + 1 /* CIE version */
875 + strlen (augmentation
) + 1 /* Augmentation */
876 + size_of_uleb128 (1) /* Code alignment */
877 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
879 + 1 /* Augmentation size */
880 + 1 /* Personality encoding */ );
881 int pad
= -offset
& (PTR_SIZE
- 1);
883 augmentation_size
+= pad
;
885 /* Augmentations should be small, so there's scarce need to
886 iterate for a solution. Die if we exceed one uleb128 byte. */
887 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
891 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
892 if (dw_cie_version
>= 4)
894 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
895 dw2_asm_output_data (1, 0, "CIE Segment Size");
897 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
898 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
899 "CIE Data Alignment Factor");
901 if (dw_cie_version
== 1)
902 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
904 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
908 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
911 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
912 eh_data_format_name (per_encoding
));
913 dw2_asm_output_encoded_addr_rtx (per_encoding
,
919 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
920 eh_data_format_name (lsda_encoding
));
922 if (fde_encoding
!= DW_EH_PE_absptr
)
923 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
924 eh_data_format_name (fde_encoding
));
927 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
928 output_cfi (cfi
, NULL
, for_eh
);
930 /* Pad the CIE out to an address sized boundary. */
931 ASM_OUTPUT_ALIGN (asm_out_file
,
932 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
933 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
935 /* Loop through all of the FDE's. */
936 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
940 /* Don't emit EH unwind info for leaf functions that don't need it. */
941 if (for_eh
&& !fde_needed_for_eh_p (fde
))
944 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
945 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
946 augmentation
, any_lsda_needed
, lsda_encoding
);
949 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
950 dw2_asm_output_data (4, 0, "End of Table");
952 /* Turn off app to make assembly quicker. */
957 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
960 dwarf2out_do_cfi_startproc (bool second
)
964 rtx personality
= get_personality_function (current_function_decl
);
966 fprintf (asm_out_file
, "\t.cfi_startproc\n");
970 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
973 /* ??? The GAS support isn't entirely consistent. We have to
974 handle indirect support ourselves, but PC-relative is done
975 in the assembler. Further, the assembler can't handle any
976 of the weirder relocation types. */
977 if (enc
& DW_EH_PE_indirect
)
978 ref
= dw2_force_const_mem (ref
, true);
980 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
981 output_addr_const (asm_out_file
, ref
);
982 fputc ('\n', asm_out_file
);
985 if (crtl
->uses_eh_lsda
)
989 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
990 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
991 current_function_funcdef_no
);
992 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
993 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
995 if (enc
& DW_EH_PE_indirect
)
996 ref
= dw2_force_const_mem (ref
, true);
998 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
999 output_addr_const (asm_out_file
, ref
);
1000 fputc ('\n', asm_out_file
);
1004 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1005 this allocation may be done before pass_final. */
1008 dwarf2out_alloc_current_fde (void)
1012 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1013 fde
->decl
= current_function_decl
;
1014 fde
->funcdef_number
= current_function_funcdef_no
;
1015 fde
->fde_index
= vec_safe_length (fde_vec
);
1016 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1017 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1018 fde
->nothrow
= crtl
->nothrow
;
1019 fde
->drap_reg
= INVALID_REGNUM
;
1020 fde
->vdrap_reg
= INVALID_REGNUM
;
1022 /* Record the FDE associated with this function. */
1024 vec_safe_push (fde_vec
, fde
);
1029 /* Output a marker (i.e. a label) for the beginning of a function, before
1033 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1034 const char *file ATTRIBUTE_UNUSED
)
1036 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1042 current_function_func_begin_label
= NULL
;
1044 do_frame
= dwarf2out_do_frame ();
1046 /* ??? current_function_func_begin_label is also used by except.c for
1047 call-site information. We must emit this label if it might be used. */
1049 && (!flag_exceptions
1050 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1053 fnsec
= function_section (current_function_decl
);
1054 switch_to_section (fnsec
);
1055 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1056 current_function_funcdef_no
);
1057 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1058 current_function_funcdef_no
);
1059 dup_label
= xstrdup (label
);
1060 current_function_func_begin_label
= dup_label
;
1062 /* We can elide the fde allocation if we're not emitting debug info. */
1066 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1067 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1068 would include pass_dwarf2_frame. If we've not created the FDE yet,
1072 fde
= dwarf2out_alloc_current_fde ();
1074 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1075 fde
->dw_fde_begin
= dup_label
;
1076 fde
->dw_fde_current_label
= dup_label
;
1077 fde
->in_std_section
= (fnsec
== text_section
1078 || (cold_text_section
&& fnsec
== cold_text_section
));
1080 /* We only want to output line number information for the genuine dwarf2
1081 prologue case, not the eh frame case. */
1082 #ifdef DWARF2_DEBUGGING_INFO
1084 dwarf2out_source_line (line
, file
, 0, true);
1087 if (dwarf2out_do_cfi_asm ())
1088 dwarf2out_do_cfi_startproc (false);
1091 rtx personality
= get_personality_function (current_function_decl
);
1092 if (!current_unit_personality
)
1093 current_unit_personality
= personality
;
1095 /* We cannot keep a current personality per function as without CFI
1096 asm, at the point where we emit the CFI data, there is no current
1097 function anymore. */
1098 if (personality
&& current_unit_personality
!= personality
)
1099 sorry ("multiple EH personalities are supported only with assemblers "
1100 "supporting .cfi_personality directive");
1104 /* Output a marker (i.e. a label) for the end of the generated code
1105 for a function prologue. This gets called *after* the prologue code has
1109 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1110 const char *file ATTRIBUTE_UNUSED
)
1112 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1114 /* Output a label to mark the endpoint of the code generated for this
1116 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1117 current_function_funcdef_no
);
1118 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1119 current_function_funcdef_no
);
1120 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1123 /* Output a marker (i.e. a label) for the beginning of the generated code
1124 for a function epilogue. This gets called *before* the prologue code has
1128 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1129 const char *file ATTRIBUTE_UNUSED
)
1131 dw_fde_ref fde
= cfun
->fde
;
1132 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1134 if (fde
->dw_fde_vms_begin_epilogue
)
1137 /* Output a label to mark the endpoint of the code generated for this
1139 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1140 current_function_funcdef_no
);
1141 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1142 current_function_funcdef_no
);
1143 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1146 /* Output a marker (i.e. a label) for the absolute end of the generated code
1147 for a function definition. This gets called *after* the epilogue code has
1151 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1152 const char *file ATTRIBUTE_UNUSED
)
1155 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1157 last_var_location_insn
= NULL
;
1158 cached_next_real_insn
= NULL
;
1160 if (dwarf2out_do_cfi_asm ())
1161 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1163 /* Output a label to mark the endpoint of the code generated for this
1165 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1166 current_function_funcdef_no
);
1167 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1169 gcc_assert (fde
!= NULL
);
1170 if (fde
->dw_fde_second_begin
== NULL
)
1171 fde
->dw_fde_end
= xstrdup (label
);
1175 dwarf2out_frame_finish (void)
1177 /* Output call frame information. */
1178 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1179 output_call_frame_info (0);
1181 /* Output another copy for the unwinder. */
1182 if ((flag_unwind_tables
|| flag_exceptions
)
1183 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1184 output_call_frame_info (1);
1187 /* Note that the current function section is being used for code. */
1190 dwarf2out_note_section_used (void)
1192 section
*sec
= current_function_section ();
1193 if (sec
== text_section
)
1194 text_section_used
= true;
1195 else if (sec
== cold_text_section
)
1196 cold_text_section_used
= true;
1199 static void var_location_switch_text_section (void);
1200 static void set_cur_line_info_table (section
*);
1203 dwarf2out_switch_text_section (void)
1206 dw_fde_ref fde
= cfun
->fde
;
1208 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1210 if (!in_cold_section_p
)
1212 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1213 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1214 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1218 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1219 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1220 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1222 have_multiple_function_sections
= true;
1224 /* There is no need to mark used sections when not debugging. */
1225 if (cold_text_section
!= NULL
)
1226 dwarf2out_note_section_used ();
1228 if (dwarf2out_do_cfi_asm ())
1229 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1231 /* Now do the real section switch. */
1232 sect
= current_function_section ();
1233 switch_to_section (sect
);
1235 fde
->second_in_std_section
1236 = (sect
== text_section
1237 || (cold_text_section
&& sect
== cold_text_section
));
1239 if (dwarf2out_do_cfi_asm ())
1240 dwarf2out_do_cfi_startproc (true);
1242 var_location_switch_text_section ();
1244 if (cold_text_section
!= NULL
)
1245 set_cur_line_info_table (sect
);
1248 /* And now, the subset of the debugging information support code necessary
1249 for emitting location expressions. */
1251 /* Data about a single source file. */
1252 struct GTY((for_user
)) dwarf_file_data
{
1253 const char * filename
;
1257 /* Describe an entry into the .debug_addr section. */
1261 ate_kind_rtx_dtprel
,
1265 struct GTY((for_user
)) addr_table_entry
{
1267 unsigned int refcount
;
1269 union addr_table_entry_struct_union
1271 rtx
GTY ((tag ("0"))) rtl
;
1272 char * GTY ((tag ("1"))) label
;
1274 GTY ((desc ("%1.kind"))) addr
;
1277 /* Location lists are ranges + location descriptions for that range,
1278 so you can track variables that are in different places over
1279 their entire life. */
1280 typedef struct GTY(()) dw_loc_list_struct
{
1281 dw_loc_list_ref dw_loc_next
;
1282 const char *begin
; /* Label and addr_entry for start of range */
1283 addr_table_entry
*begin_entry
;
1284 const char *end
; /* Label for end of range */
1285 char *ll_symbol
; /* Label for beginning of location list.
1286 Only on head of list */
1287 const char *section
; /* Section this loclist is relative to */
1288 dw_loc_descr_ref expr
;
1290 /* True if all addresses in this and subsequent lists are known to be
1293 /* True if this list has been replaced by dw_loc_next. */
1296 /* True if the range should be emitted even if begin and end
1301 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1302 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1304 /* Convert a DWARF stack opcode into its string name. */
1307 dwarf_stack_op_name (unsigned int op
)
1309 const char *name
= get_DW_OP_name (op
);
1314 return "OP_<unknown>";
1317 /* Return a pointer to a newly allocated location description. Location
1318 descriptions are simple expression terms that can be strung
1319 together to form more complicated location (address) descriptions. */
1321 static inline dw_loc_descr_ref
1322 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1323 unsigned HOST_WIDE_INT oprnd2
)
1325 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1327 descr
->dw_loc_opc
= op
;
1329 descr
->dw_loc_frame_offset
= -1;
1331 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1332 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1333 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1334 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1335 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1336 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1341 /* Return a pointer to a newly allocated location description for
1344 static inline dw_loc_descr_ref
1345 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1348 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1351 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1354 /* Add a location description term to a location description expression. */
1357 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1359 dw_loc_descr_ref
*d
;
1361 /* Find the end of the chain. */
1362 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1368 /* Compare two location operands for exact equality. */
1371 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1373 if (a
->val_class
!= b
->val_class
)
1375 switch (a
->val_class
)
1377 case dw_val_class_none
:
1379 case dw_val_class_addr
:
1380 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1382 case dw_val_class_offset
:
1383 case dw_val_class_unsigned_const
:
1384 case dw_val_class_const
:
1385 case dw_val_class_range_list
:
1386 case dw_val_class_lineptr
:
1387 case dw_val_class_macptr
:
1388 /* These are all HOST_WIDE_INT, signed or unsigned. */
1389 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1391 case dw_val_class_loc
:
1392 return a
->v
.val_loc
== b
->v
.val_loc
;
1393 case dw_val_class_loc_list
:
1394 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1395 case dw_val_class_die_ref
:
1396 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1397 case dw_val_class_fde_ref
:
1398 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1399 case dw_val_class_lbl_id
:
1400 case dw_val_class_high_pc
:
1401 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1402 case dw_val_class_str
:
1403 return a
->v
.val_str
== b
->v
.val_str
;
1404 case dw_val_class_flag
:
1405 return a
->v
.val_flag
== b
->v
.val_flag
;
1406 case dw_val_class_file
:
1407 return a
->v
.val_file
== b
->v
.val_file
;
1408 case dw_val_class_decl_ref
:
1409 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1411 case dw_val_class_const_double
:
1412 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1413 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1415 case dw_val_class_wide_int
:
1416 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1418 case dw_val_class_vec
:
1420 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1421 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1423 return (a_len
== b_len
1424 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1427 case dw_val_class_data8
:
1428 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1430 case dw_val_class_vms_delta
:
1431 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1432 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1434 case dw_val_class_discr_value
:
1435 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1436 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1437 case dw_val_class_discr_list
:
1438 /* It makes no sense comparing two discriminant value lists. */
1444 /* Compare two location atoms for exact equality. */
1447 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1449 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1452 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1453 address size, but since we always allocate cleared storage it
1454 should be zero for other types of locations. */
1455 if (a
->dtprel
!= b
->dtprel
)
1458 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1459 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1462 /* Compare two complete location expressions for exact equality. */
1465 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1471 if (a
== NULL
|| b
== NULL
)
1473 if (!loc_descr_equal_p_1 (a
, b
))
1482 /* Add a constant OFFSET to a location expression. */
1485 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1487 dw_loc_descr_ref loc
;
1490 gcc_assert (*list_head
!= NULL
);
1495 /* Find the end of the chain. */
1496 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1500 if (loc
->dw_loc_opc
== DW_OP_fbreg
1501 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1502 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1503 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1504 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1506 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1507 offset. Don't optimize if an signed integer overflow would happen. */
1509 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1510 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1513 else if (offset
> 0)
1514 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1518 loc
->dw_loc_next
= int_loc_descriptor (-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 static unsigned long int get_base_type_offset (dw_die_ref
);
1538 /* Return the size of a location descriptor. */
1540 static unsigned long
1541 size_of_loc_descr (dw_loc_descr_ref loc
)
1543 unsigned long size
= 1;
1545 switch (loc
->dw_loc_opc
)
1548 size
+= DWARF2_ADDR_SIZE
;
1550 case DW_OP_GNU_addr_index
:
1551 case DW_OP_GNU_const_index
:
1552 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1553 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1572 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1575 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1580 case DW_OP_plus_uconst
:
1581 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1619 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1622 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1625 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1628 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1629 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1632 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1634 case DW_OP_bit_piece
:
1635 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1636 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1638 case DW_OP_deref_size
:
1639 case DW_OP_xderef_size
:
1648 case DW_OP_call_ref
:
1649 size
+= DWARF_REF_SIZE
;
1651 case DW_OP_implicit_value
:
1652 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1653 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1655 case DW_OP_GNU_implicit_pointer
:
1656 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1658 case DW_OP_GNU_entry_value
:
1660 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1661 size
+= size_of_uleb128 (op_size
) + op_size
;
1664 case DW_OP_GNU_const_type
:
1667 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1668 size
+= size_of_uleb128 (o
) + 1;
1669 switch (loc
->dw_loc_oprnd2
.val_class
)
1671 case dw_val_class_vec
:
1672 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1673 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1675 case dw_val_class_const
:
1676 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1678 case dw_val_class_const_double
:
1679 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1681 case dw_val_class_wide_int
:
1682 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1683 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1690 case DW_OP_GNU_regval_type
:
1693 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1694 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1695 + size_of_uleb128 (o
);
1698 case DW_OP_GNU_deref_type
:
1701 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1702 size
+= 1 + size_of_uleb128 (o
);
1705 case DW_OP_GNU_convert
:
1706 case DW_OP_GNU_reinterpret
:
1707 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1708 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1712 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1713 size
+= size_of_uleb128 (o
);
1716 case DW_OP_GNU_parameter_ref
:
1726 /* Return the size of a series of location descriptors. */
1729 size_of_locs (dw_loc_descr_ref loc
)
1734 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1735 field, to avoid writing to a PCH file. */
1736 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1738 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1740 size
+= size_of_loc_descr (l
);
1745 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1747 l
->dw_loc_addr
= size
;
1748 size
+= size_of_loc_descr (l
);
1754 /* Return the size of the value in a DW_AT_discr_value attribute. */
1757 size_of_discr_value (dw_discr_value
*discr_value
)
1759 if (discr_value
->pos
)
1760 return size_of_uleb128 (discr_value
->v
.uval
);
1762 return size_of_sleb128 (discr_value
->v
.sval
);
1765 /* Return the size of the value in a DW_discr_list attribute. */
1768 size_of_discr_list (dw_discr_list_ref discr_list
)
1772 for (dw_discr_list_ref list
= discr_list
;
1774 list
= list
->dw_discr_next
)
1776 /* One byte for the discriminant value descriptor, and then one or two
1777 LEB128 numbers, depending on whether it's a single case label or a
1780 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
1781 if (list
->dw_discr_range
!= 0)
1782 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
1787 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1788 static void get_ref_die_offset_label (char *, dw_die_ref
);
1789 static unsigned long int get_ref_die_offset (dw_die_ref
);
1791 /* Output location description stack opcode's operands (if any).
1792 The for_eh_or_skip parameter controls whether register numbers are
1793 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1794 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1795 info). This should be suppressed for the cases that have not been converted
1796 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1799 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1801 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1802 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1804 switch (loc
->dw_loc_opc
)
1806 #ifdef DWARF2_DEBUGGING_INFO
1809 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1814 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1815 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1817 fputc ('\n', asm_out_file
);
1822 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1827 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1828 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1830 fputc ('\n', asm_out_file
);
1835 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1836 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1843 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1844 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1846 dw2_asm_output_data (2, offset
, NULL
);
1849 case DW_OP_implicit_value
:
1850 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1851 switch (val2
->val_class
)
1853 case dw_val_class_const
:
1854 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1856 case dw_val_class_vec
:
1858 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1859 unsigned int len
= val2
->v
.val_vec
.length
;
1863 if (elt_size
> sizeof (HOST_WIDE_INT
))
1868 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1871 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1872 "fp or vector constant word %u", i
);
1875 case dw_val_class_const_double
:
1877 unsigned HOST_WIDE_INT first
, second
;
1879 if (WORDS_BIG_ENDIAN
)
1881 first
= val2
->v
.val_double
.high
;
1882 second
= val2
->v
.val_double
.low
;
1886 first
= val2
->v
.val_double
.low
;
1887 second
= val2
->v
.val_double
.high
;
1889 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1891 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1895 case dw_val_class_wide_int
:
1898 int len
= get_full_len (*val2
->v
.val_wide
);
1899 if (WORDS_BIG_ENDIAN
)
1900 for (i
= len
- 1; i
>= 0; --i
)
1901 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1902 val2
->v
.val_wide
->elt (i
), NULL
);
1904 for (i
= 0; i
< len
; ++i
)
1905 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1906 val2
->v
.val_wide
->elt (i
), NULL
);
1909 case dw_val_class_addr
:
1910 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1911 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1926 case DW_OP_implicit_value
:
1927 /* We currently don't make any attempt to make sure these are
1928 aligned properly like we do for the main unwind info, so
1929 don't support emitting things larger than a byte if we're
1930 only doing unwinding. */
1935 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1938 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1941 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1944 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1946 case DW_OP_plus_uconst
:
1947 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1981 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1985 unsigned r
= val1
->v
.val_unsigned
;
1986 if (for_eh_or_skip
>= 0)
1987 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1988 gcc_assert (size_of_uleb128 (r
)
1989 == size_of_uleb128 (val1
->v
.val_unsigned
));
1990 dw2_asm_output_data_uleb128 (r
, NULL
);
1994 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1998 unsigned r
= val1
->v
.val_unsigned
;
1999 if (for_eh_or_skip
>= 0)
2000 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2001 gcc_assert (size_of_uleb128 (r
)
2002 == size_of_uleb128 (val1
->v
.val_unsigned
));
2003 dw2_asm_output_data_uleb128 (r
, NULL
);
2004 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2008 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2010 case DW_OP_bit_piece
:
2011 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2012 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2014 case DW_OP_deref_size
:
2015 case DW_OP_xderef_size
:
2016 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2022 if (targetm
.asm_out
.output_dwarf_dtprel
)
2024 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2027 fputc ('\n', asm_out_file
);
2034 #ifdef DWARF2_DEBUGGING_INFO
2035 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2042 case DW_OP_GNU_addr_index
:
2043 case DW_OP_GNU_const_index
:
2044 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2045 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2046 "(index into .debug_addr)");
2052 unsigned long die_offset
2053 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2054 /* Make sure the offset has been computed and that we can encode it as
2056 gcc_assert (die_offset
> 0
2057 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
)
2060 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2065 case DW_OP_GNU_implicit_pointer
:
2067 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2068 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2069 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2070 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2071 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2072 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2076 case DW_OP_GNU_entry_value
:
2077 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2078 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2081 case DW_OP_GNU_const_type
:
2083 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2085 dw2_asm_output_data_uleb128 (o
, NULL
);
2086 switch (val2
->val_class
)
2088 case dw_val_class_const
:
2089 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2090 dw2_asm_output_data (1, l
, NULL
);
2091 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2093 case dw_val_class_vec
:
2095 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2096 unsigned int len
= val2
->v
.val_vec
.length
;
2101 dw2_asm_output_data (1, l
, NULL
);
2102 if (elt_size
> sizeof (HOST_WIDE_INT
))
2107 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2110 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2111 "fp or vector constant word %u", i
);
2114 case dw_val_class_const_double
:
2116 unsigned HOST_WIDE_INT first
, second
;
2117 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2119 dw2_asm_output_data (1, 2 * l
, NULL
);
2120 if (WORDS_BIG_ENDIAN
)
2122 first
= val2
->v
.val_double
.high
;
2123 second
= val2
->v
.val_double
.low
;
2127 first
= val2
->v
.val_double
.low
;
2128 second
= val2
->v
.val_double
.high
;
2130 dw2_asm_output_data (l
, first
, NULL
);
2131 dw2_asm_output_data (l
, second
, NULL
);
2134 case dw_val_class_wide_int
:
2137 int len
= get_full_len (*val2
->v
.val_wide
);
2138 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2140 dw2_asm_output_data (1, len
* l
, NULL
);
2141 if (WORDS_BIG_ENDIAN
)
2142 for (i
= len
- 1; i
>= 0; --i
)
2143 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2145 for (i
= 0; i
< len
; ++i
)
2146 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2154 case DW_OP_GNU_regval_type
:
2156 unsigned r
= val1
->v
.val_unsigned
;
2157 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2159 if (for_eh_or_skip
>= 0)
2161 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2162 gcc_assert (size_of_uleb128 (r
)
2163 == size_of_uleb128 (val1
->v
.val_unsigned
));
2165 dw2_asm_output_data_uleb128 (r
, NULL
);
2166 dw2_asm_output_data_uleb128 (o
, NULL
);
2169 case DW_OP_GNU_deref_type
:
2171 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2173 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2174 dw2_asm_output_data_uleb128 (o
, NULL
);
2177 case DW_OP_GNU_convert
:
2178 case DW_OP_GNU_reinterpret
:
2179 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2180 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2183 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2185 dw2_asm_output_data_uleb128 (o
, NULL
);
2189 case DW_OP_GNU_parameter_ref
:
2192 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2193 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2194 dw2_asm_output_data (4, o
, NULL
);
2199 /* Other codes have no operands. */
2204 /* Output a sequence of location operations.
2205 The for_eh_or_skip parameter controls whether register numbers are
2206 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2207 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2208 info). This should be suppressed for the cases that have not been converted
2209 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2212 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2214 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2216 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2217 /* Output the opcode. */
2218 if (for_eh_or_skip
>= 0
2219 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2221 unsigned r
= (opc
- DW_OP_breg0
);
2222 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2223 gcc_assert (r
<= 31);
2224 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2226 else if (for_eh_or_skip
>= 0
2227 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2229 unsigned r
= (opc
- DW_OP_reg0
);
2230 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2231 gcc_assert (r
<= 31);
2232 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2235 dw2_asm_output_data (1, opc
,
2236 "%s", dwarf_stack_op_name (opc
));
2238 /* Output the operand(s) (if any). */
2239 output_loc_operands (loc
, for_eh_or_skip
);
2243 /* Output location description stack opcode's operands (if any).
2244 The output is single bytes on a line, suitable for .cfi_escape. */
2247 output_loc_operands_raw (dw_loc_descr_ref loc
)
2249 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2250 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2252 switch (loc
->dw_loc_opc
)
2255 case DW_OP_GNU_addr_index
:
2256 case DW_OP_GNU_const_index
:
2257 case DW_OP_implicit_value
:
2258 /* We cannot output addresses in .cfi_escape, only bytes. */
2264 case DW_OP_deref_size
:
2265 case DW_OP_xderef_size
:
2266 fputc (',', asm_out_file
);
2267 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2272 fputc (',', asm_out_file
);
2273 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2278 fputc (',', asm_out_file
);
2279 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2284 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2285 fputc (',', asm_out_file
);
2286 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2294 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2295 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2297 fputc (',', asm_out_file
);
2298 dw2_asm_output_data_raw (2, offset
);
2304 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2305 gcc_assert (size_of_uleb128 (r
)
2306 == size_of_uleb128 (val1
->v
.val_unsigned
));
2307 fputc (',', asm_out_file
);
2308 dw2_asm_output_data_uleb128_raw (r
);
2313 case DW_OP_plus_uconst
:
2315 fputc (',', asm_out_file
);
2316 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2319 case DW_OP_bit_piece
:
2320 fputc (',', asm_out_file
);
2321 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2322 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2359 fputc (',', asm_out_file
);
2360 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2365 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2366 gcc_assert (size_of_uleb128 (r
)
2367 == size_of_uleb128 (val1
->v
.val_unsigned
));
2368 fputc (',', asm_out_file
);
2369 dw2_asm_output_data_uleb128_raw (r
);
2370 fputc (',', asm_out_file
);
2371 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2375 case DW_OP_GNU_implicit_pointer
:
2376 case DW_OP_GNU_entry_value
:
2377 case DW_OP_GNU_const_type
:
2378 case DW_OP_GNU_regval_type
:
2379 case DW_OP_GNU_deref_type
:
2380 case DW_OP_GNU_convert
:
2381 case DW_OP_GNU_reinterpret
:
2382 case DW_OP_GNU_parameter_ref
:
2387 /* Other codes have no operands. */
2393 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2397 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2398 /* Output the opcode. */
2399 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2401 unsigned r
= (opc
- DW_OP_breg0
);
2402 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2403 gcc_assert (r
<= 31);
2404 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2406 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2408 unsigned r
= (opc
- DW_OP_reg0
);
2409 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2410 gcc_assert (r
<= 31);
2411 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2413 /* Output the opcode. */
2414 fprintf (asm_out_file
, "%#x", opc
);
2415 output_loc_operands_raw (loc
);
2417 if (!loc
->dw_loc_next
)
2419 loc
= loc
->dw_loc_next
;
2421 fputc (',', asm_out_file
);
2425 /* This function builds a dwarf location descriptor sequence from a
2426 dw_cfa_location, adding the given OFFSET to the result of the
2429 struct dw_loc_descr_node
*
2430 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2432 struct dw_loc_descr_node
*head
, *tmp
;
2434 offset
+= cfa
->offset
;
2438 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2439 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2440 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2441 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2442 add_loc_descr (&head
, tmp
);
2445 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2446 add_loc_descr (&head
, tmp
);
2450 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2455 /* This function builds a dwarf location descriptor sequence for
2456 the address at OFFSET from the CFA when stack is aligned to
2459 struct dw_loc_descr_node
*
2460 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2461 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2463 struct dw_loc_descr_node
*head
;
2464 unsigned int dwarf_fp
2465 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2467 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2468 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2470 head
= new_reg_loc_descr (dwarf_fp
, 0);
2471 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2472 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2473 loc_descr_plus_const (&head
, offset
);
2476 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2480 /* And now, the support for symbolic debugging information. */
2482 /* .debug_str support. */
2484 static void dwarf2out_init (const char *);
2485 static void dwarf2out_finish (const char *);
2486 static void dwarf2out_early_finish (void);
2487 static void dwarf2out_assembly_start (void);
2488 static void dwarf2out_define (unsigned int, const char *);
2489 static void dwarf2out_undef (unsigned int, const char *);
2490 static void dwarf2out_start_source_file (unsigned, const char *);
2491 static void dwarf2out_end_source_file (unsigned);
2492 static void dwarf2out_function_decl (tree
);
2493 static void dwarf2out_begin_block (unsigned, unsigned);
2494 static void dwarf2out_end_block (unsigned, unsigned);
2495 static bool dwarf2out_ignore_block (const_tree
);
2496 static void dwarf2out_early_global_decl (tree
);
2497 static void dwarf2out_late_global_decl (tree
);
2498 static void dwarf2out_type_decl (tree
, int);
2499 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2500 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2502 static void dwarf2out_abstract_function (tree
);
2503 static void dwarf2out_var_location (rtx_insn
*);
2504 static void dwarf2out_size_function (tree
);
2505 static void dwarf2out_begin_function (tree
);
2506 static void dwarf2out_end_function (unsigned int);
2507 static void dwarf2out_register_main_translation_unit (tree unit
);
2508 static void dwarf2out_set_name (tree
, tree
);
2510 /* The debug hooks structure. */
2512 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2516 dwarf2out_early_finish
,
2517 dwarf2out_assembly_start
,
2520 dwarf2out_start_source_file
,
2521 dwarf2out_end_source_file
,
2522 dwarf2out_begin_block
,
2523 dwarf2out_end_block
,
2524 dwarf2out_ignore_block
,
2525 dwarf2out_source_line
,
2526 dwarf2out_begin_prologue
,
2527 #if VMS_DEBUGGING_INFO
2528 dwarf2out_vms_end_prologue
,
2529 dwarf2out_vms_begin_epilogue
,
2531 debug_nothing_int_charstar
,
2532 debug_nothing_int_charstar
,
2534 dwarf2out_end_epilogue
,
2535 dwarf2out_begin_function
,
2536 dwarf2out_end_function
, /* end_function */
2537 dwarf2out_register_main_translation_unit
,
2538 dwarf2out_function_decl
, /* function_decl */
2539 dwarf2out_early_global_decl
,
2540 dwarf2out_late_global_decl
,
2541 dwarf2out_type_decl
, /* type_decl */
2542 dwarf2out_imported_module_or_decl
,
2543 debug_nothing_tree
, /* deferred_inline_function */
2544 /* The DWARF 2 backend tries to reduce debugging bloat by not
2545 emitting the abstract description of inline functions until
2546 something tries to reference them. */
2547 dwarf2out_abstract_function
, /* outlining_inline_function */
2548 debug_nothing_rtx_code_label
, /* label */
2549 debug_nothing_int
, /* handle_pch */
2550 dwarf2out_var_location
,
2551 dwarf2out_size_function
, /* size_function */
2552 dwarf2out_switch_text_section
,
2554 1, /* start_end_main_source_file */
2555 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2558 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2561 debug_nothing_charstar
,
2564 debug_nothing_int_charstar
,
2565 debug_nothing_int_charstar
,
2566 debug_nothing_int_charstar
,
2568 debug_nothing_int_int
, /* begin_block */
2569 debug_nothing_int_int
, /* end_block */
2570 debug_true_const_tree
, /* ignore_block */
2571 dwarf2out_source_line
, /* source_line */
2572 debug_nothing_int_charstar
, /* begin_prologue */
2573 debug_nothing_int_charstar
, /* end_prologue */
2574 debug_nothing_int_charstar
, /* begin_epilogue */
2575 debug_nothing_int_charstar
, /* end_epilogue */
2576 debug_nothing_tree
, /* begin_function */
2577 debug_nothing_int
, /* end_function */
2578 debug_nothing_tree
, /* register_main_translation_unit */
2579 debug_nothing_tree
, /* function_decl */
2580 debug_nothing_tree
, /* early_global_decl */
2581 debug_nothing_tree
, /* late_global_decl */
2582 debug_nothing_tree_int
, /* type_decl */
2583 debug_nothing_tree_tree_tree_bool
, /* imported_module_or_decl */
2584 debug_nothing_tree
, /* deferred_inline_function */
2585 debug_nothing_tree
, /* outlining_inline_function */
2586 debug_nothing_rtx_code_label
, /* label */
2587 debug_nothing_int
, /* handle_pch */
2588 debug_nothing_rtx_insn
, /* var_location */
2589 debug_nothing_tree
, /* size_function */
2590 debug_nothing_void
, /* switch_text_section */
2591 debug_nothing_tree_tree
, /* set_name */
2592 0, /* start_end_main_source_file */
2593 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2596 /* NOTE: In the comments in this file, many references are made to
2597 "Debugging Information Entries". This term is abbreviated as `DIE'
2598 throughout the remainder of this file. */
2600 /* An internal representation of the DWARF output is built, and then
2601 walked to generate the DWARF debugging info. The walk of the internal
2602 representation is done after the entire program has been compiled.
2603 The types below are used to describe the internal representation. */
2605 /* Whether to put type DIEs into their own section .debug_types instead
2606 of making them part of the .debug_info section. Only supported for
2607 Dwarf V4 or higher and the user didn't disable them through
2608 -fno-debug-types-section. It is more efficient to put them in a
2609 separate comdat sections since the linker will then be able to
2610 remove duplicates. But not all tools support .debug_types sections
2613 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2615 /* Various DIE's use offsets relative to the beginning of the
2616 .debug_info section to refer to each other. */
2618 typedef long int dw_offset
;
2620 struct comdat_type_node
;
2622 /* The entries in the line_info table more-or-less mirror the opcodes
2623 that are used in the real dwarf line table. Arrays of these entries
2624 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2627 enum dw_line_info_opcode
{
2628 /* Emit DW_LNE_set_address; the operand is the label index. */
2631 /* Emit a row to the matrix with the given line. This may be done
2632 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2636 /* Emit a DW_LNS_set_file. */
2639 /* Emit a DW_LNS_set_column. */
2642 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2645 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2646 LI_set_prologue_end
,
2647 LI_set_epilogue_begin
,
2649 /* Emit a DW_LNE_set_discriminator. */
2650 LI_set_discriminator
2653 typedef struct GTY(()) dw_line_info_struct
{
2654 enum dw_line_info_opcode opcode
;
2656 } dw_line_info_entry
;
2659 struct GTY(()) dw_line_info_table
{
2660 /* The label that marks the end of this section. */
2661 const char *end_label
;
2663 /* The values for the last row of the matrix, as collected in the table.
2664 These are used to minimize the changes to the next row. */
2665 unsigned int file_num
;
2666 unsigned int line_num
;
2667 unsigned int column_num
;
2672 vec
<dw_line_info_entry
, va_gc
> *entries
;
2676 /* Each DIE attribute has a field specifying the attribute kind,
2677 a link to the next attribute in the chain, and an attribute value.
2678 Attributes are typically linked below the DIE they modify. */
2680 typedef struct GTY(()) dw_attr_struct
{
2681 enum dwarf_attribute dw_attr
;
2682 dw_val_node dw_attr_val
;
2687 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2688 The children of each node form a circular list linked by
2689 die_sib. die_child points to the node *before* the "first" child node. */
2691 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2692 union die_symbol_or_type_node
2694 const char * GTY ((tag ("0"))) die_symbol
;
2695 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
2697 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2698 vec
<dw_attr_node
, va_gc
> *die_attr
;
2699 dw_die_ref die_parent
;
2700 dw_die_ref die_child
;
2702 dw_die_ref die_definition
; /* ref from a specification to its definition */
2703 dw_offset die_offset
;
2704 unsigned long die_abbrev
;
2706 unsigned int decl_id
;
2707 enum dwarf_tag die_tag
;
2708 /* Die is used and must not be pruned as unused. */
2709 BOOL_BITFIELD die_perennial_p
: 1;
2710 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2711 /* Lots of spare bits. */
2715 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2716 static bool early_dwarf
;
2717 struct set_early_dwarf
{
2719 set_early_dwarf () : saved(early_dwarf
) { early_dwarf
= true; }
2720 ~set_early_dwarf () { early_dwarf
= saved
; }
2723 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2724 #define FOR_EACH_CHILD(die, c, expr) do { \
2725 c = die->die_child; \
2729 } while (c != die->die_child); \
2732 /* The pubname structure */
2734 typedef struct GTY(()) pubname_struct
{
2741 struct GTY(()) dw_ranges
{
2742 /* If this is positive, it's a block number, otherwise it's a
2743 bitwise-negated index into dw_ranges_by_label. */
2747 /* A structure to hold a macinfo entry. */
2749 typedef struct GTY(()) macinfo_struct
{
2751 unsigned HOST_WIDE_INT lineno
;
2757 struct GTY(()) dw_ranges_by_label
{
2762 /* The comdat type node structure. */
2763 struct GTY(()) comdat_type_node
2765 dw_die_ref root_die
;
2766 dw_die_ref type_die
;
2767 dw_die_ref skeleton_die
;
2768 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2769 comdat_type_node
*next
;
2772 /* A list of DIEs for which we can't determine ancestry (parent_die
2773 field) just yet. Later in dwarf2out_finish we will fill in the
2775 typedef struct GTY(()) limbo_die_struct
{
2777 /* The tree for which this DIE was created. We use this to
2778 determine ancestry later. */
2780 struct limbo_die_struct
*next
;
2784 typedef struct skeleton_chain_struct
2788 struct skeleton_chain_struct
*parent
;
2790 skeleton_chain_node
;
2792 /* Define a macro which returns nonzero for a TYPE_DECL which was
2793 implicitly generated for a type.
2795 Note that, unlike the C front-end (which generates a NULL named
2796 TYPE_DECL node for each complete tagged type, each array type,
2797 and each function type node created) the C++ front-end generates
2798 a _named_ TYPE_DECL node for each tagged type node created.
2799 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2800 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2801 front-end, but for each type, tagged or not. */
2803 #define TYPE_DECL_IS_STUB(decl) \
2804 (DECL_NAME (decl) == NULL_TREE \
2805 || (DECL_ARTIFICIAL (decl) \
2806 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2807 /* This is necessary for stub decls that \
2808 appear in nested inline functions. */ \
2809 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2810 && (decl_ultimate_origin (decl) \
2811 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2813 /* Information concerning the compilation unit's programming
2814 language, and compiler version. */
2816 /* Fixed size portion of the DWARF compilation unit header. */
2817 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2818 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2820 /* Fixed size portion of the DWARF comdat type unit header. */
2821 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2822 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2823 + DWARF_OFFSET_SIZE)
2825 /* Fixed size portion of public names info. */
2826 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2828 /* Fixed size portion of the address range info. */
2829 #define DWARF_ARANGES_HEADER_SIZE \
2830 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2831 DWARF2_ADDR_SIZE * 2) \
2832 - DWARF_INITIAL_LENGTH_SIZE)
2834 /* Size of padding portion in the address range info. It must be
2835 aligned to twice the pointer size. */
2836 #define DWARF_ARANGES_PAD_SIZE \
2837 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2838 DWARF2_ADDR_SIZE * 2) \
2839 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2841 /* Use assembler line directives if available. */
2842 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2843 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2844 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2846 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2850 /* Minimum line offset in a special line info. opcode.
2851 This value was chosen to give a reasonable range of values. */
2852 #define DWARF_LINE_BASE -10
2854 /* First special line opcode - leave room for the standard opcodes. */
2855 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2857 /* Range of line offsets in a special line info. opcode. */
2858 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2860 /* Flag that indicates the initial value of the is_stmt_start flag.
2861 In the present implementation, we do not mark any lines as
2862 the beginning of a source statement, because that information
2863 is not made available by the GCC front-end. */
2864 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2866 /* Maximum number of operations per instruction bundle. */
2867 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2868 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2871 /* This location is used by calc_die_sizes() to keep track
2872 the offset of each DIE within the .debug_info section. */
2873 static unsigned long next_die_offset
;
2875 /* Record the root of the DIE's built for the current compilation unit. */
2876 static GTY(()) dw_die_ref single_comp_unit_die
;
2878 /* A list of type DIEs that have been separated into comdat sections. */
2879 static GTY(()) comdat_type_node
*comdat_type_list
;
2881 /* A list of DIEs with a NULL parent waiting to be relocated. */
2882 static GTY(()) limbo_die_node
*limbo_die_list
;
2884 /* A list of DIEs for which we may have to generate
2885 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2886 static GTY(()) limbo_die_node
*deferred_asm_name
;
2888 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
2890 typedef const char *compare_type
;
2892 static hashval_t
hash (dwarf_file_data
*);
2893 static bool equal (dwarf_file_data
*, const char *);
2896 /* Filenames referenced by this compilation unit. */
2897 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
2899 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
2901 typedef tree compare_type
;
2903 static hashval_t
hash (die_node
*);
2904 static bool equal (die_node
*, tree
);
2906 /* A hash table of references to DIE's that describe declarations.
2907 The key is a DECL_UID() which is a unique number identifying each decl. */
2908 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
2910 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
2912 static hashval_t
hash (die_struct
*);
2913 static bool equal (die_struct
*, die_struct
*);
2916 /* A hash table of references to DIE's that describe COMMON blocks.
2917 The key is DECL_UID() ^ die_parent. */
2918 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
2920 typedef struct GTY(()) die_arg_entry_struct
{
2926 /* Node of the variable location list. */
2927 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2928 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2929 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2930 in mode of the EXPR_LIST node and first EXPR_LIST operand
2931 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2932 location or NULL for padding. For larger bitsizes,
2933 mode is 0 and first operand is a CONCAT with bitsize
2934 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2935 NULL as second operand. */
2937 const char * GTY (()) label
;
2938 struct var_loc_node
* GTY (()) next
;
2941 /* Variable location list. */
2942 struct GTY ((for_user
)) var_loc_list_def
{
2943 struct var_loc_node
* GTY (()) first
;
2945 /* Pointer to the last but one or last element of the
2946 chained list. If the list is empty, both first and
2947 last are NULL, if the list contains just one node
2948 or the last node certainly is not redundant, it points
2949 to the last node, otherwise points to the last but one.
2950 Do not mark it for GC because it is marked through the chain. */
2951 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2953 /* Pointer to the last element before section switch,
2954 if NULL, either sections weren't switched or first
2955 is after section switch. */
2956 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2958 /* DECL_UID of the variable decl. */
2959 unsigned int decl_id
;
2961 typedef struct var_loc_list_def var_loc_list
;
2963 /* Call argument location list. */
2964 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2965 rtx
GTY (()) call_arg_loc_note
;
2966 const char * GTY (()) label
;
2967 tree
GTY (()) block
;
2969 rtx
GTY (()) symbol_ref
;
2970 struct call_arg_loc_node
* GTY (()) next
;
2974 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
2976 typedef const_tree compare_type
;
2978 static hashval_t
hash (var_loc_list
*);
2979 static bool equal (var_loc_list
*, const_tree
);
2982 /* Table of decl location linked lists. */
2983 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
2985 /* Head and tail of call_arg_loc chain. */
2986 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2987 static struct call_arg_loc_node
*call_arg_loc_last
;
2989 /* Number of call sites in the current function. */
2990 static int call_site_count
= -1;
2991 /* Number of tail call sites in the current function. */
2992 static int tail_call_site_count
= -1;
2994 /* A cached location list. */
2995 struct GTY ((for_user
)) cached_dw_loc_list_def
{
2996 /* The DECL_UID of the decl that this entry describes. */
2997 unsigned int decl_id
;
2999 /* The cached location list. */
3000 dw_loc_list_ref loc_list
;
3002 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3004 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3007 typedef const_tree compare_type
;
3009 static hashval_t
hash (cached_dw_loc_list
*);
3010 static bool equal (cached_dw_loc_list
*, const_tree
);
3013 /* Table of cached location lists. */
3014 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3016 /* A pointer to the base of a list of references to DIE's that
3017 are uniquely identified by their tag, presence/absence of
3018 children DIE's, and list of attribute/value pairs. */
3019 static GTY((length ("abbrev_die_table_allocated")))
3020 dw_die_ref
*abbrev_die_table
;
3022 /* Number of elements currently allocated for abbrev_die_table. */
3023 static GTY(()) unsigned abbrev_die_table_allocated
;
3025 /* Number of elements in abbrev_die_table currently in use. */
3026 static GTY(()) unsigned abbrev_die_table_in_use
;
3028 /* A hash map to remember the stack usage for DWARF procedures. The value
3029 stored is the stack size difference between before the DWARF procedure
3030 invokation and after it returned. In other words, for a DWARF procedure
3031 that consumes N stack slots and that pushes M ones, this stores M - N. */
3032 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3034 /* Size (in elements) of increments by which we may expand the
3035 abbrev_die_table. */
3036 #define ABBREV_DIE_TABLE_INCREMENT 256
3038 /* A global counter for generating labels for line number data. */
3039 static unsigned int line_info_label_num
;
3041 /* The current table to which we should emit line number information
3042 for the current function. This will be set up at the beginning of
3043 assembly for the function. */
3044 static dw_line_info_table
*cur_line_info_table
;
3046 /* The two default tables of line number info. */
3047 static GTY(()) dw_line_info_table
*text_section_line_info
;
3048 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3050 /* The set of all non-default tables of line number info. */
3051 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3053 /* A flag to tell pubnames/types export if there is an info section to
3055 static bool info_section_emitted
;
3057 /* A pointer to the base of a table that contains a list of publicly
3058 accessible names. */
3059 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3061 /* A pointer to the base of a table that contains a list of publicly
3062 accessible types. */
3063 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3065 /* A pointer to the base of a table that contains a list of macro
3066 defines/undefines (and file start/end markers). */
3067 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3069 /* True if .debug_macinfo or .debug_macros section is going to be
3071 #define have_macinfo \
3072 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3073 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3074 && !macinfo_table->is_empty ())
3076 /* Array of dies for which we should generate .debug_ranges info. */
3077 static GTY ((length ("ranges_table_allocated"))) dw_ranges
*ranges_table
;
3079 /* Number of elements currently allocated for ranges_table. */
3080 static GTY(()) unsigned ranges_table_allocated
;
3082 /* Number of elements in ranges_table currently in use. */
3083 static GTY(()) unsigned ranges_table_in_use
;
3085 /* Array of pairs of labels referenced in ranges_table. */
3086 static GTY ((length ("ranges_by_label_allocated")))
3087 dw_ranges_by_label
*ranges_by_label
;
3089 /* Number of elements currently allocated for ranges_by_label. */
3090 static GTY(()) unsigned ranges_by_label_allocated
;
3092 /* Number of elements in ranges_by_label currently in use. */
3093 static GTY(()) unsigned ranges_by_label_in_use
;
3095 /* Size (in elements) of increments by which we may expand the
3097 #define RANGES_TABLE_INCREMENT 64
3099 /* Whether we have location lists that need outputting */
3100 static GTY(()) bool have_location_lists
;
3102 /* Unique label counter. */
3103 static GTY(()) unsigned int loclabel_num
;
3105 /* Unique label counter for point-of-call tables. */
3106 static GTY(()) unsigned int poc_label_num
;
3108 /* The last file entry emitted by maybe_emit_file(). */
3109 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3111 /* Number of internal labels generated by gen_internal_sym(). */
3112 static GTY(()) int label_num
;
3114 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3116 /* Instances of generic types for which we need to generate debug
3117 info that describe their generic parameters and arguments. That
3118 generation needs to happen once all types are properly laid out so
3119 we do it at the end of compilation. */
3120 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3122 /* Offset from the "steady-state frame pointer" to the frame base,
3123 within the current function. */
3124 static HOST_WIDE_INT frame_pointer_fb_offset
;
3125 static bool frame_pointer_fb_offset_valid
;
3127 static vec
<dw_die_ref
> base_types
;
3129 /* Flags to represent a set of attribute classes for attributes that represent
3130 a scalar value (bounds, pointers, ...). */
3133 dw_scalar_form_constant
= 0x01,
3134 dw_scalar_form_exprloc
= 0x02,
3135 dw_scalar_form_reference
= 0x04
3138 /* Forward declarations for functions defined in this file. */
3140 static int is_pseudo_reg (const_rtx
);
3141 static tree
type_main_variant (tree
);
3142 static int is_tagged_type (const_tree
);
3143 static const char *dwarf_tag_name (unsigned);
3144 static const char *dwarf_attr_name (unsigned);
3145 static const char *dwarf_form_name (unsigned);
3146 static tree
decl_ultimate_origin (const_tree
);
3147 static tree
decl_class_context (tree
);
3148 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3149 static inline enum dw_val_class
AT_class (dw_attr_node
*);
3150 static inline unsigned int AT_index (dw_attr_node
*);
3151 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3152 static inline unsigned AT_flag (dw_attr_node
*);
3153 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3154 static inline HOST_WIDE_INT
AT_int (dw_attr_node
*);
3155 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3156 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_node
*);
3157 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3158 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3159 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3160 unsigned int, unsigned char *);
3161 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3162 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3163 static inline const char *AT_string (dw_attr_node
*);
3164 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3165 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3166 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3167 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3168 static inline int AT_ref_external (dw_attr_node
*);
3169 static inline void set_AT_ref_external (dw_attr_node
*, int);
3170 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3171 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3172 static inline dw_loc_descr_ref
AT_loc (dw_attr_node
*);
3173 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3175 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3176 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3177 static void remove_addr_table_entry (addr_table_entry
*);
3178 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3179 static inline rtx
AT_addr (dw_attr_node
*);
3180 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3181 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3182 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3183 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3184 unsigned HOST_WIDE_INT
);
3185 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3186 unsigned long, bool);
3187 static inline const char *AT_lbl (dw_attr_node
*);
3188 static dw_attr_node
*get_AT (dw_die_ref
, enum dwarf_attribute
);
3189 static const char *get_AT_low_pc (dw_die_ref
);
3190 static const char *get_AT_hi_pc (dw_die_ref
);
3191 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3192 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3193 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3194 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3195 static bool is_cxx (void);
3196 static bool is_fortran (void);
3197 static bool is_ada (void);
3198 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3199 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3200 static void add_child_die (dw_die_ref
, dw_die_ref
);
3201 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3202 static dw_die_ref
lookup_type_die (tree
);
3203 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3204 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3205 static void equate_type_number_to_die (tree
, dw_die_ref
);
3206 static dw_die_ref
lookup_decl_die (tree
);
3207 static var_loc_list
*lookup_decl_loc (const_tree
);
3208 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3209 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3210 static void print_spaces (FILE *);
3211 static void print_die (dw_die_ref
, FILE *);
3212 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3213 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3214 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3215 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3216 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3217 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3218 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3219 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3220 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3221 struct md5_ctx
*, int *);
3222 struct checksum_attributes
;
3223 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3224 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3225 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3226 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3227 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3228 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3229 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3230 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3231 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3232 static void compute_section_prefix (dw_die_ref
);
3233 static int is_type_die (dw_die_ref
);
3234 static int is_comdat_die (dw_die_ref
);
3235 static int is_symbol_die (dw_die_ref
);
3236 static inline bool is_template_instantiation (dw_die_ref
);
3237 static void assign_symbol_names (dw_die_ref
);
3238 static void break_out_includes (dw_die_ref
);
3239 static int is_declaration_die (dw_die_ref
);
3240 static int should_move_die_to_comdat (dw_die_ref
);
3241 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3242 static dw_die_ref
clone_die (dw_die_ref
);
3243 static dw_die_ref
clone_tree (dw_die_ref
);
3244 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3245 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3246 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3247 static dw_die_ref
generate_skeleton (dw_die_ref
);
3248 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3251 static void break_out_comdat_types (dw_die_ref
);
3252 static void copy_decls_for_unworthy_types (dw_die_ref
);
3254 static void add_sibling_attributes (dw_die_ref
);
3255 static void output_location_lists (dw_die_ref
);
3256 static int constant_size (unsigned HOST_WIDE_INT
);
3257 static unsigned long size_of_die (dw_die_ref
);
3258 static void calc_die_sizes (dw_die_ref
);
3259 static void calc_base_type_die_sizes (void);
3260 static void mark_dies (dw_die_ref
);
3261 static void unmark_dies (dw_die_ref
);
3262 static void unmark_all_dies (dw_die_ref
);
3263 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3264 static unsigned long size_of_aranges (void);
3265 static enum dwarf_form
value_format (dw_attr_node
*);
3266 static void output_value_format (dw_attr_node
*);
3267 static void output_abbrev_section (void);
3268 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3269 static void output_die_symbol (dw_die_ref
);
3270 static void output_die (dw_die_ref
);
3271 static void output_compilation_unit_header (void);
3272 static void output_comp_unit (dw_die_ref
, int);
3273 static void output_comdat_type_unit (comdat_type_node
*);
3274 static const char *dwarf2_name (tree
, int);
3275 static void add_pubname (tree
, dw_die_ref
);
3276 static void add_enumerator_pubname (const char *, dw_die_ref
);
3277 static void add_pubname_string (const char *, dw_die_ref
);
3278 static void add_pubtype (tree
, dw_die_ref
);
3279 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3280 static void output_aranges (void);
3281 static unsigned int add_ranges_num (int);
3282 static unsigned int add_ranges (const_tree
);
3283 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3285 static void output_ranges (void);
3286 static dw_line_info_table
*new_line_info_table (void);
3287 static void output_line_info (bool);
3288 static void output_file_names (void);
3289 static dw_die_ref
base_type_die (tree
, bool);
3290 static int is_base_type (tree
);
3291 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3292 static int decl_quals (const_tree
);
3293 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3294 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3295 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3296 static int type_is_enum (const_tree
);
3297 static unsigned int dbx_reg_number (const_rtx
);
3298 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3299 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3300 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3301 enum var_init_status
);
3302 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3303 enum var_init_status
);
3304 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3305 enum var_init_status
);
3306 static int is_based_loc (const_rtx
);
3307 static bool resolve_one_addr (rtx
*);
3308 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3309 enum var_init_status
);
3310 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3311 enum var_init_status
);
3312 struct loc_descr_context
;
3313 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3314 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3315 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3316 const struct loc_descr_context
*);
3317 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3318 const struct loc_descr_context
*);
3319 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3320 static tree
field_type (const_tree
);
3321 static unsigned int simple_type_align_in_bits (const_tree
);
3322 static unsigned int simple_decl_align_in_bits (const_tree
);
3323 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3325 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3327 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3329 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3330 struct vlr_context
*);
3331 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3332 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3333 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3334 static void insert_float (const_rtx
, unsigned char *);
3335 static rtx
rtl_for_decl_location (tree
);
3336 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3337 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3338 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3339 static void add_name_attribute (dw_die_ref
, const char *);
3340 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3341 static void add_comp_dir_attribute (dw_die_ref
);
3342 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3343 const struct loc_descr_context
*);
3344 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3345 const struct loc_descr_context
*);
3346 static void add_subscript_info (dw_die_ref
, tree
, bool);
3347 static void add_byte_size_attribute (dw_die_ref
, tree
);
3348 static inline void add_bit_offset_attribute (dw_die_ref
, tree
,
3349 struct vlr_context
*);
3350 static void add_bit_size_attribute (dw_die_ref
, tree
);
3351 static void add_prototyped_attribute (dw_die_ref
, tree
);
3352 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3353 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3354 static void add_src_coords_attributes (dw_die_ref
, tree
);
3355 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3356 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3357 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3358 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3359 static void push_decl_scope (tree
);
3360 static void pop_decl_scope (void);
3361 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3362 static inline int local_scope_p (dw_die_ref
);
3363 static inline int class_scope_p (dw_die_ref
);
3364 static inline int class_or_namespace_scope_p (dw_die_ref
);
3365 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3366 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3367 static const char *type_tag (const_tree
);
3368 static tree
member_declared_type (const_tree
);
3370 static const char *decl_start_label (tree
);
3372 static void gen_array_type_die (tree
, dw_die_ref
);
3373 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3375 static void gen_entry_point_die (tree
, dw_die_ref
);
3377 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3378 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3379 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3380 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3381 static void gen_formal_types_die (tree
, dw_die_ref
);
3382 static void gen_subprogram_die (tree
, dw_die_ref
);
3383 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3384 static void gen_const_die (tree
, dw_die_ref
);
3385 static void gen_label_die (tree
, dw_die_ref
);
3386 static void gen_lexical_block_die (tree
, dw_die_ref
);
3387 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3388 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3389 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3390 static dw_die_ref
gen_compile_unit_die (const char *);
3391 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3392 static void gen_member_die (tree
, dw_die_ref
);
3393 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3394 enum debug_info_usage
);
3395 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3396 static void gen_typedef_die (tree
, dw_die_ref
);
3397 static void gen_type_die (tree
, dw_die_ref
);
3398 static void gen_block_die (tree
, dw_die_ref
);
3399 static void decls_for_scope (tree
, dw_die_ref
);
3400 static bool is_naming_typedef_decl (const_tree
);
3401 static inline dw_die_ref
get_context_die (tree
);
3402 static void gen_namespace_die (tree
, dw_die_ref
);
3403 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3404 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3405 static dw_die_ref
force_decl_die (tree
);
3406 static dw_die_ref
force_type_die (tree
);
3407 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3408 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3409 static struct dwarf_file_data
* lookup_filename (const char *);
3410 static void retry_incomplete_types (void);
3411 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3412 static void gen_generic_params_dies (tree
);
3413 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3414 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3415 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3416 static int file_info_cmp (const void *, const void *);
3417 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3418 const char *, const char *);
3419 static void output_loc_list (dw_loc_list_ref
);
3420 static char *gen_internal_sym (const char *);
3421 static bool want_pubnames (void);
3423 static void prune_unmark_dies (dw_die_ref
);
3424 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3425 static void prune_unused_types_mark (dw_die_ref
, int);
3426 static void prune_unused_types_walk (dw_die_ref
);
3427 static void prune_unused_types_walk_attribs (dw_die_ref
);
3428 static void prune_unused_types_prune (dw_die_ref
);
3429 static void prune_unused_types (void);
3430 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3431 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3432 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3433 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3434 const char *, const char *);
3435 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3436 static void gen_remaining_tmpl_value_param_die_attribute (void);
3437 static bool generic_type_p (tree
);
3438 static void schedule_generic_params_dies_gen (tree t
);
3439 static void gen_scheduled_generic_parms_dies (void);
3441 static const char *comp_dir_string (void);
3443 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3445 /* enum for tracking thread-local variables whose address is really an offset
3446 relative to the TLS pointer, which will need link-time relocation, but will
3447 not need relocation by the DWARF consumer. */
3455 /* Return the operator to use for an address of a variable. For dtprel_true, we
3456 use DW_OP_const*. For regular variables, which need both link-time
3457 relocation and consumer-level relocation (e.g., to account for shared objects
3458 loaded at a random address), we use DW_OP_addr*. */
3460 static inline enum dwarf_location_atom
3461 dw_addr_op (enum dtprel_bool dtprel
)
3463 if (dtprel
== dtprel_true
)
3464 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3465 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3467 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3470 /* Return a pointer to a newly allocated address location description. If
3471 dwarf_split_debug_info is true, then record the address with the appropriate
3473 static inline dw_loc_descr_ref
3474 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3476 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3478 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3479 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3480 ref
->dtprel
= dtprel
;
3481 if (dwarf_split_debug_info
)
3482 ref
->dw_loc_oprnd1
.val_entry
3483 = add_addr_table_entry (addr
,
3484 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3486 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3491 /* Section names used to hold DWARF debugging information. */
3493 #ifndef DEBUG_INFO_SECTION
3494 #define DEBUG_INFO_SECTION ".debug_info"
3496 #ifndef DEBUG_DWO_INFO_SECTION
3497 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3499 #ifndef DEBUG_ABBREV_SECTION
3500 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3502 #ifndef DEBUG_DWO_ABBREV_SECTION
3503 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3505 #ifndef DEBUG_ARANGES_SECTION
3506 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3508 #ifndef DEBUG_ADDR_SECTION
3509 #define DEBUG_ADDR_SECTION ".debug_addr"
3511 #ifndef DEBUG_NORM_MACINFO_SECTION
3512 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3514 #ifndef DEBUG_DWO_MACINFO_SECTION
3515 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3517 #ifndef DEBUG_MACINFO_SECTION
3518 #define DEBUG_MACINFO_SECTION \
3519 (!dwarf_split_debug_info \
3520 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3522 #ifndef DEBUG_NORM_MACRO_SECTION
3523 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3525 #ifndef DEBUG_DWO_MACRO_SECTION
3526 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3528 #ifndef DEBUG_MACRO_SECTION
3529 #define DEBUG_MACRO_SECTION \
3530 (!dwarf_split_debug_info \
3531 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3533 #ifndef DEBUG_LINE_SECTION
3534 #define DEBUG_LINE_SECTION ".debug_line"
3536 #ifndef DEBUG_DWO_LINE_SECTION
3537 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3539 #ifndef DEBUG_LOC_SECTION
3540 #define DEBUG_LOC_SECTION ".debug_loc"
3542 #ifndef DEBUG_DWO_LOC_SECTION
3543 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3545 #ifndef DEBUG_PUBNAMES_SECTION
3546 #define DEBUG_PUBNAMES_SECTION \
3547 ((debug_generate_pub_sections == 2) \
3548 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3550 #ifndef DEBUG_PUBTYPES_SECTION
3551 #define DEBUG_PUBTYPES_SECTION \
3552 ((debug_generate_pub_sections == 2) \
3553 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3555 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3556 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3557 #ifndef DEBUG_STR_OFFSETS_SECTION
3558 #define DEBUG_STR_OFFSETS_SECTION \
3559 (!dwarf_split_debug_info \
3560 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3562 #ifndef DEBUG_STR_DWO_SECTION
3563 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3565 #ifndef DEBUG_STR_SECTION
3566 #define DEBUG_STR_SECTION ".debug_str"
3568 #ifndef DEBUG_RANGES_SECTION
3569 #define DEBUG_RANGES_SECTION ".debug_ranges"
3572 /* Standard ELF section names for compiled code and data. */
3573 #ifndef TEXT_SECTION_NAME
3574 #define TEXT_SECTION_NAME ".text"
3577 /* Section flags for .debug_macinfo/.debug_macro section. */
3578 #define DEBUG_MACRO_SECTION_FLAGS \
3579 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3581 /* Section flags for .debug_str section. */
3582 #define DEBUG_STR_SECTION_FLAGS \
3583 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3584 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3587 /* Section flags for .debug_str.dwo section. */
3588 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3590 /* Labels we insert at beginning sections we can reference instead of
3591 the section names themselves. */
3593 #ifndef TEXT_SECTION_LABEL
3594 #define TEXT_SECTION_LABEL "Ltext"
3596 #ifndef COLD_TEXT_SECTION_LABEL
3597 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3599 #ifndef DEBUG_LINE_SECTION_LABEL
3600 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3602 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3603 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3605 #ifndef DEBUG_INFO_SECTION_LABEL
3606 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3608 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3609 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3611 #ifndef DEBUG_ABBREV_SECTION_LABEL
3612 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3614 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3615 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3617 #ifndef DEBUG_ADDR_SECTION_LABEL
3618 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3620 #ifndef DEBUG_LOC_SECTION_LABEL
3621 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3623 #ifndef DEBUG_RANGES_SECTION_LABEL
3624 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3626 #ifndef DEBUG_MACINFO_SECTION_LABEL
3627 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3629 #ifndef DEBUG_MACRO_SECTION_LABEL
3630 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3632 #define SKELETON_COMP_DIE_ABBREV 1
3633 #define SKELETON_TYPE_DIE_ABBREV 2
3635 /* Definitions of defaults for formats and names of various special
3636 (artificial) labels which may be generated within this file (when the -g
3637 options is used and DWARF2_DEBUGGING_INFO is in effect.
3638 If necessary, these may be overridden from within the tm.h file, but
3639 typically, overriding these defaults is unnecessary. */
3641 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3642 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3643 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3644 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3645 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3646 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3647 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3648 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3649 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3650 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3651 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3652 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3653 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3654 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3656 #ifndef TEXT_END_LABEL
3657 #define TEXT_END_LABEL "Letext"
3659 #ifndef COLD_END_LABEL
3660 #define COLD_END_LABEL "Letext_cold"
3662 #ifndef BLOCK_BEGIN_LABEL
3663 #define BLOCK_BEGIN_LABEL "LBB"
3665 #ifndef BLOCK_END_LABEL
3666 #define BLOCK_END_LABEL "LBE"
3668 #ifndef LINE_CODE_LABEL
3669 #define LINE_CODE_LABEL "LM"
3673 /* Return the root of the DIE's built for the current compilation unit. */
3675 comp_unit_die (void)
3677 if (!single_comp_unit_die
)
3678 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3679 return single_comp_unit_die
;
3682 /* We allow a language front-end to designate a function that is to be
3683 called to "demangle" any name before it is put into a DIE. */
3685 static const char *(*demangle_name_func
) (const char *);
3688 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3690 demangle_name_func
= func
;
3693 /* Test if rtl node points to a pseudo register. */
3696 is_pseudo_reg (const_rtx rtl
)
3698 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3699 || (GET_CODE (rtl
) == SUBREG
3700 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3703 /* Return a reference to a type, with its const and volatile qualifiers
3707 type_main_variant (tree type
)
3709 type
= TYPE_MAIN_VARIANT (type
);
3711 /* ??? There really should be only one main variant among any group of
3712 variants of a given type (and all of the MAIN_VARIANT values for all
3713 members of the group should point to that one type) but sometimes the C
3714 front-end messes this up for array types, so we work around that bug
3716 if (TREE_CODE (type
) == ARRAY_TYPE
)
3717 while (type
!= TYPE_MAIN_VARIANT (type
))
3718 type
= TYPE_MAIN_VARIANT (type
);
3723 /* Return nonzero if the given type node represents a tagged type. */
3726 is_tagged_type (const_tree type
)
3728 enum tree_code code
= TREE_CODE (type
);
3730 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3731 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3734 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3737 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3739 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3742 /* Return die_offset of a DIE reference to a base type. */
3744 static unsigned long int
3745 get_base_type_offset (dw_die_ref ref
)
3747 if (ref
->die_offset
)
3748 return ref
->die_offset
;
3749 if (comp_unit_die ()->die_abbrev
)
3751 calc_base_type_die_sizes ();
3752 gcc_assert (ref
->die_offset
);
3754 return ref
->die_offset
;
3757 /* Return die_offset of a DIE reference other than base type. */
3759 static unsigned long int
3760 get_ref_die_offset (dw_die_ref ref
)
3762 gcc_assert (ref
->die_offset
);
3763 return ref
->die_offset
;
3766 /* Convert a DIE tag into its string name. */
3769 dwarf_tag_name (unsigned int tag
)
3771 const char *name
= get_DW_TAG_name (tag
);
3776 return "DW_TAG_<unknown>";
3779 /* Convert a DWARF attribute code into its string name. */
3782 dwarf_attr_name (unsigned int attr
)
3788 #if VMS_DEBUGGING_INFO
3789 case DW_AT_HP_prologue
:
3790 return "DW_AT_HP_prologue";
3792 case DW_AT_MIPS_loop_unroll_factor
:
3793 return "DW_AT_MIPS_loop_unroll_factor";
3796 #if VMS_DEBUGGING_INFO
3797 case DW_AT_HP_epilogue
:
3798 return "DW_AT_HP_epilogue";
3800 case DW_AT_MIPS_stride
:
3801 return "DW_AT_MIPS_stride";
3805 name
= get_DW_AT_name (attr
);
3810 return "DW_AT_<unknown>";
3813 /* Convert a DWARF value form code into its string name. */
3816 dwarf_form_name (unsigned int form
)
3818 const char *name
= get_DW_FORM_name (form
);
3823 return "DW_FORM_<unknown>";
3826 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3827 instance of an inlined instance of a decl which is local to an inline
3828 function, so we have to trace all of the way back through the origin chain
3829 to find out what sort of node actually served as the original seed for the
3833 decl_ultimate_origin (const_tree decl
)
3835 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3838 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3839 we're trying to output the abstract instance of this function. */
3840 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3843 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3844 most distant ancestor, this should never happen. */
3845 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3847 return DECL_ABSTRACT_ORIGIN (decl
);
3850 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3851 of a virtual function may refer to a base class, so we check the 'this'
3855 decl_class_context (tree decl
)
3857 tree context
= NULL_TREE
;
3859 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3860 context
= DECL_CONTEXT (decl
);
3862 context
= TYPE_MAIN_VARIANT
3863 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3865 if (context
&& !TYPE_P (context
))
3866 context
= NULL_TREE
;
3871 /* Add an attribute/value pair to a DIE. */
3874 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
3876 /* Maybe this should be an assert? */
3880 vec_safe_reserve (die
->die_attr
, 1);
3881 vec_safe_push (die
->die_attr
, *attr
);
3884 static inline enum dw_val_class
3885 AT_class (dw_attr_node
*a
)
3887 return a
->dw_attr_val
.val_class
;
3890 /* Return the index for any attribute that will be referenced with a
3891 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3892 are stored in dw_attr_val.v.val_str for reference counting
3895 static inline unsigned int
3896 AT_index (dw_attr_node
*a
)
3898 if (AT_class (a
) == dw_val_class_str
)
3899 return a
->dw_attr_val
.v
.val_str
->index
;
3900 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3901 return a
->dw_attr_val
.val_entry
->index
;
3905 /* Add a flag value attribute to a DIE. */
3908 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3912 attr
.dw_attr
= attr_kind
;
3913 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3914 attr
.dw_attr_val
.val_entry
= NULL
;
3915 attr
.dw_attr_val
.v
.val_flag
= flag
;
3916 add_dwarf_attr (die
, &attr
);
3919 static inline unsigned
3920 AT_flag (dw_attr_node
*a
)
3922 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3923 return a
->dw_attr_val
.v
.val_flag
;
3926 /* Add a signed integer attribute value to a DIE. */
3929 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3933 attr
.dw_attr
= attr_kind
;
3934 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3935 attr
.dw_attr_val
.val_entry
= NULL
;
3936 attr
.dw_attr_val
.v
.val_int
= int_val
;
3937 add_dwarf_attr (die
, &attr
);
3940 static inline HOST_WIDE_INT
3941 AT_int (dw_attr_node
*a
)
3943 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3944 return a
->dw_attr_val
.v
.val_int
;
3947 /* Add an unsigned integer attribute value to a DIE. */
3950 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3951 unsigned HOST_WIDE_INT unsigned_val
)
3955 attr
.dw_attr
= attr_kind
;
3956 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3957 attr
.dw_attr_val
.val_entry
= NULL
;
3958 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3959 add_dwarf_attr (die
, &attr
);
3962 static inline unsigned HOST_WIDE_INT
3963 AT_unsigned (dw_attr_node
*a
)
3965 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3966 return a
->dw_attr_val
.v
.val_unsigned
;
3969 /* Add an unsigned wide integer attribute value to a DIE. */
3972 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3977 attr
.dw_attr
= attr_kind
;
3978 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
3979 attr
.dw_attr_val
.val_entry
= NULL
;
3980 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
3981 *attr
.dw_attr_val
.v
.val_wide
= w
;
3982 add_dwarf_attr (die
, &attr
);
3985 /* Add an unsigned double integer attribute value to a DIE. */
3988 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3989 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3993 attr
.dw_attr
= attr_kind
;
3994 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3995 attr
.dw_attr_val
.val_entry
= NULL
;
3996 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3997 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3998 add_dwarf_attr (die
, &attr
);
4001 /* Add a floating point attribute value to a DIE and return it. */
4004 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4005 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4009 attr
.dw_attr
= attr_kind
;
4010 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4011 attr
.dw_attr_val
.val_entry
= NULL
;
4012 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4013 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4014 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4015 add_dwarf_attr (die
, &attr
);
4018 /* Add an 8-byte data attribute value to a DIE. */
4021 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4022 unsigned char data8
[8])
4026 attr
.dw_attr
= attr_kind
;
4027 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4028 attr
.dw_attr_val
.val_entry
= NULL
;
4029 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4030 add_dwarf_attr (die
, &attr
);
4033 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4034 dwarf_split_debug_info, address attributes in dies destined for the
4035 final executable have force_direct set to avoid using indexed
4039 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4045 lbl_id
= xstrdup (lbl_low
);
4046 attr
.dw_attr
= DW_AT_low_pc
;
4047 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4048 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4049 if (dwarf_split_debug_info
&& !force_direct
)
4050 attr
.dw_attr_val
.val_entry
4051 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4053 attr
.dw_attr_val
.val_entry
= NULL
;
4054 add_dwarf_attr (die
, &attr
);
4056 attr
.dw_attr
= DW_AT_high_pc
;
4057 if (dwarf_version
< 4)
4058 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4060 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4061 lbl_id
= xstrdup (lbl_high
);
4062 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4063 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4064 && dwarf_split_debug_info
&& !force_direct
)
4065 attr
.dw_attr_val
.val_entry
4066 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4068 attr
.dw_attr_val
.val_entry
= NULL
;
4069 add_dwarf_attr (die
, &attr
);
4072 /* Hash and equality functions for debug_str_hash. */
4075 indirect_string_hasher::hash (indirect_string_node
*x
)
4077 return htab_hash_string (x
->str
);
4081 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4083 return strcmp (x1
->str
, x2
) == 0;
4086 /* Add STR to the given string hash table. */
4088 static struct indirect_string_node
*
4089 find_AT_string_in_table (const char *str
,
4090 hash_table
<indirect_string_hasher
> *table
)
4092 struct indirect_string_node
*node
;
4094 indirect_string_node
**slot
4095 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
4098 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4099 node
->str
= ggc_strdup (str
);
4109 /* Add STR to the indirect string hash table. */
4111 static struct indirect_string_node
*
4112 find_AT_string (const char *str
)
4114 if (! debug_str_hash
)
4115 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4117 return find_AT_string_in_table (str
, debug_str_hash
);
4120 /* Add a string attribute value to a DIE. */
4123 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4126 struct indirect_string_node
*node
;
4128 node
= find_AT_string (str
);
4130 attr
.dw_attr
= attr_kind
;
4131 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4132 attr
.dw_attr_val
.val_entry
= NULL
;
4133 attr
.dw_attr_val
.v
.val_str
= node
;
4134 add_dwarf_attr (die
, &attr
);
4137 static inline const char *
4138 AT_string (dw_attr_node
*a
)
4140 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4141 return a
->dw_attr_val
.v
.val_str
->str
;
4144 /* Call this function directly to bypass AT_string_form's logic to put
4145 the string inline in the die. */
4148 set_indirect_string (struct indirect_string_node
*node
)
4151 /* Already indirect is a no op. */
4152 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4154 gcc_assert (node
->label
);
4157 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4158 ++dw2_string_counter
;
4159 node
->label
= xstrdup (label
);
4161 if (!dwarf_split_debug_info
)
4163 node
->form
= DW_FORM_strp
;
4164 node
->index
= NOT_INDEXED
;
4168 node
->form
= DW_FORM_GNU_str_index
;
4169 node
->index
= NO_INDEX_ASSIGNED
;
4173 /* Find out whether a string should be output inline in DIE
4174 or out-of-line in .debug_str section. */
4176 static enum dwarf_form
4177 find_string_form (struct indirect_string_node
*node
)
4184 len
= strlen (node
->str
) + 1;
4186 /* If the string is shorter or equal to the size of the reference, it is
4187 always better to put it inline. */
4188 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4189 return node
->form
= DW_FORM_string
;
4191 /* If we cannot expect the linker to merge strings in .debug_str
4192 section, only put it into .debug_str if it is worth even in this
4194 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4195 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4196 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4197 return node
->form
= DW_FORM_string
;
4199 set_indirect_string (node
);
4204 /* Find out whether the string referenced from the attribute should be
4205 output inline in DIE or out-of-line in .debug_str section. */
4207 static enum dwarf_form
4208 AT_string_form (dw_attr_node
*a
)
4210 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4211 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4214 /* Add a DIE reference attribute value to a DIE. */
4217 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4220 gcc_checking_assert (targ_die
!= NULL
);
4222 /* With LTO we can end up trying to reference something we didn't create
4223 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4224 if (targ_die
== NULL
)
4227 attr
.dw_attr
= attr_kind
;
4228 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4229 attr
.dw_attr_val
.val_entry
= NULL
;
4230 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4231 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4232 add_dwarf_attr (die
, &attr
);
4235 /* Change DIE reference REF to point to NEW_DIE instead. */
4238 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4240 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4241 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4242 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4245 /* Add an AT_specification attribute to a DIE, and also make the back
4246 pointer from the specification to the definition. */
4249 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4251 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4252 gcc_assert (!targ_die
->die_definition
);
4253 targ_die
->die_definition
= die
;
4256 static inline dw_die_ref
4257 AT_ref (dw_attr_node
*a
)
4259 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4260 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4264 AT_ref_external (dw_attr_node
*a
)
4266 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4267 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4273 set_AT_ref_external (dw_attr_node
*a
, int i
)
4275 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4276 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4279 /* Add an FDE reference attribute value to a DIE. */
4282 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4286 attr
.dw_attr
= attr_kind
;
4287 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4288 attr
.dw_attr_val
.val_entry
= NULL
;
4289 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4290 add_dwarf_attr (die
, &attr
);
4293 /* Add a location description attribute value to a DIE. */
4296 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4300 attr
.dw_attr
= attr_kind
;
4301 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4302 attr
.dw_attr_val
.val_entry
= NULL
;
4303 attr
.dw_attr_val
.v
.val_loc
= loc
;
4304 add_dwarf_attr (die
, &attr
);
4307 static inline dw_loc_descr_ref
4308 AT_loc (dw_attr_node
*a
)
4310 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4311 return a
->dw_attr_val
.v
.val_loc
;
4315 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4319 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4322 attr
.dw_attr
= attr_kind
;
4323 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4324 attr
.dw_attr_val
.val_entry
= NULL
;
4325 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4326 add_dwarf_attr (die
, &attr
);
4327 have_location_lists
= true;
4330 static inline dw_loc_list_ref
4331 AT_loc_list (dw_attr_node
*a
)
4333 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4334 return a
->dw_attr_val
.v
.val_loc_list
;
4337 static inline dw_loc_list_ref
*
4338 AT_loc_list_ptr (dw_attr_node
*a
)
4340 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4341 return &a
->dw_attr_val
.v
.val_loc_list
;
4344 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4346 static hashval_t
hash (addr_table_entry
*);
4347 static bool equal (addr_table_entry
*, addr_table_entry
*);
4350 /* Table of entries into the .debug_addr section. */
4352 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4354 /* Hash an address_table_entry. */
4357 addr_hasher::hash (addr_table_entry
*a
)
4359 inchash::hash hstate
;
4365 case ate_kind_rtx_dtprel
:
4368 case ate_kind_label
:
4369 return htab_hash_string (a
->addr
.label
);
4373 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4374 return hstate
.end ();
4377 /* Determine equality for two address_table_entries. */
4380 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4382 if (a1
->kind
!= a2
->kind
)
4387 case ate_kind_rtx_dtprel
:
4388 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4389 case ate_kind_label
:
4390 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4396 /* Initialize an addr_table_entry. */
4399 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4405 case ate_kind_rtx_dtprel
:
4406 e
->addr
.rtl
= (rtx
) addr
;
4408 case ate_kind_label
:
4409 e
->addr
.label
= (char *) addr
;
4413 e
->index
= NO_INDEX_ASSIGNED
;
4416 /* Add attr to the address table entry to the table. Defer setting an
4417 index until output time. */
4419 static addr_table_entry
*
4420 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4422 addr_table_entry
*node
;
4423 addr_table_entry finder
;
4425 gcc_assert (dwarf_split_debug_info
);
4426 if (! addr_index_table
)
4427 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4428 init_addr_table_entry (&finder
, kind
, addr
);
4429 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4431 if (*slot
== HTAB_EMPTY_ENTRY
)
4433 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4434 init_addr_table_entry (node
, kind
, addr
);
4444 /* Remove an entry from the addr table by decrementing its refcount.
4445 Strictly, decrementing the refcount would be enough, but the
4446 assertion that the entry is actually in the table has found
4450 remove_addr_table_entry (addr_table_entry
*entry
)
4452 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4453 /* After an index is assigned, the table is frozen. */
4454 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4458 /* Given a location list, remove all addresses it refers to from the
4462 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4464 for (; descr
; descr
= descr
->dw_loc_next
)
4465 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4467 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4468 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4472 /* A helper function for dwarf2out_finish called through
4473 htab_traverse. Assign an addr_table_entry its index. All entries
4474 must be collected into the table when this function is called,
4475 because the indexing code relies on htab_traverse to traverse nodes
4476 in the same order for each run. */
4479 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4481 addr_table_entry
*node
= *h
;
4483 /* Don't index unreferenced nodes. */
4484 if (node
->refcount
== 0)
4487 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4488 node
->index
= *index
;
4494 /* Add an address constant attribute value to a DIE. When using
4495 dwarf_split_debug_info, address attributes in dies destined for the
4496 final executable should be direct references--setting the parameter
4497 force_direct ensures this behavior. */
4500 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4505 attr
.dw_attr
= attr_kind
;
4506 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4507 attr
.dw_attr_val
.v
.val_addr
= addr
;
4508 if (dwarf_split_debug_info
&& !force_direct
)
4509 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4511 attr
.dw_attr_val
.val_entry
= NULL
;
4512 add_dwarf_attr (die
, &attr
);
4515 /* Get the RTX from to an address DIE attribute. */
4518 AT_addr (dw_attr_node
*a
)
4520 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4521 return a
->dw_attr_val
.v
.val_addr
;
4524 /* Add a file attribute value to a DIE. */
4527 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4528 struct dwarf_file_data
*fd
)
4532 attr
.dw_attr
= attr_kind
;
4533 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4534 attr
.dw_attr_val
.val_entry
= NULL
;
4535 attr
.dw_attr_val
.v
.val_file
= fd
;
4536 add_dwarf_attr (die
, &attr
);
4539 /* Get the dwarf_file_data from a file DIE attribute. */
4541 static inline struct dwarf_file_data
*
4542 AT_file (dw_attr_node
*a
)
4544 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4545 return a
->dw_attr_val
.v
.val_file
;
4548 /* Add a vms delta attribute value to a DIE. */
4551 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4552 const char *lbl1
, const char *lbl2
)
4556 attr
.dw_attr
= attr_kind
;
4557 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4558 attr
.dw_attr_val
.val_entry
= NULL
;
4559 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4560 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4561 add_dwarf_attr (die
, &attr
);
4564 /* Add a label identifier attribute value to a DIE. */
4567 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4572 attr
.dw_attr
= attr_kind
;
4573 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4574 attr
.dw_attr_val
.val_entry
= NULL
;
4575 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4576 if (dwarf_split_debug_info
)
4577 attr
.dw_attr_val
.val_entry
4578 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4580 add_dwarf_attr (die
, &attr
);
4583 /* Add a section offset attribute value to a DIE, an offset into the
4584 debug_line section. */
4587 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4592 attr
.dw_attr
= attr_kind
;
4593 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4594 attr
.dw_attr_val
.val_entry
= NULL
;
4595 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4596 add_dwarf_attr (die
, &attr
);
4599 /* Add a section offset attribute value to a DIE, an offset into the
4600 debug_macinfo section. */
4603 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4608 attr
.dw_attr
= attr_kind
;
4609 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4610 attr
.dw_attr_val
.val_entry
= NULL
;
4611 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4612 add_dwarf_attr (die
, &attr
);
4615 /* Add an offset attribute value to a DIE. */
4618 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4619 unsigned HOST_WIDE_INT offset
)
4623 attr
.dw_attr
= attr_kind
;
4624 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4625 attr
.dw_attr_val
.val_entry
= NULL
;
4626 attr
.dw_attr_val
.v
.val_offset
= offset
;
4627 add_dwarf_attr (die
, &attr
);
4630 /* Add a range_list attribute value to a DIE. When using
4631 dwarf_split_debug_info, address attributes in dies destined for the
4632 final executable should be direct references--setting the parameter
4633 force_direct ensures this behavior. */
4635 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4636 #define RELOCATED_OFFSET (NULL)
4639 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4640 long unsigned int offset
, bool force_direct
)
4644 attr
.dw_attr
= attr_kind
;
4645 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4646 /* For the range_list attribute, use val_entry to store whether the
4647 offset should follow split-debug-info or normal semantics. This
4648 value is read in output_range_list_offset. */
4649 if (dwarf_split_debug_info
&& !force_direct
)
4650 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4652 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4653 attr
.dw_attr_val
.v
.val_offset
= offset
;
4654 add_dwarf_attr (die
, &attr
);
4657 /* Return the start label of a delta attribute. */
4659 static inline const char *
4660 AT_vms_delta1 (dw_attr_node
*a
)
4662 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4663 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4666 /* Return the end label of a delta attribute. */
4668 static inline const char *
4669 AT_vms_delta2 (dw_attr_node
*a
)
4671 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4672 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4675 static inline const char *
4676 AT_lbl (dw_attr_node
*a
)
4678 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4679 || AT_class (a
) == dw_val_class_lineptr
4680 || AT_class (a
) == dw_val_class_macptr
4681 || AT_class (a
) == dw_val_class_high_pc
));
4682 return a
->dw_attr_val
.v
.val_lbl_id
;
4685 /* Get the attribute of type attr_kind. */
4687 static dw_attr_node
*
4688 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4692 dw_die_ref spec
= NULL
;
4697 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4698 if (a
->dw_attr
== attr_kind
)
4700 else if (a
->dw_attr
== DW_AT_specification
4701 || a
->dw_attr
== DW_AT_abstract_origin
)
4705 return get_AT (spec
, attr_kind
);
4710 /* Returns the parent of the declaration of DIE. */
4713 get_die_parent (dw_die_ref die
)
4720 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4721 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4724 return die
->die_parent
;
4727 /* Return the "low pc" attribute value, typically associated with a subprogram
4728 DIE. Return null if the "low pc" attribute is either not present, or if it
4729 cannot be represented as an assembler label identifier. */
4731 static inline const char *
4732 get_AT_low_pc (dw_die_ref die
)
4734 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
4736 return a
? AT_lbl (a
) : NULL
;
4739 /* Return the "high pc" attribute value, typically associated with a subprogram
4740 DIE. Return null if the "high pc" attribute is either not present, or if it
4741 cannot be represented as an assembler label identifier. */
4743 static inline const char *
4744 get_AT_hi_pc (dw_die_ref die
)
4746 dw_attr_node
*a
= get_AT (die
, DW_AT_high_pc
);
4748 return a
? AT_lbl (a
) : NULL
;
4751 /* Return the value of the string attribute designated by ATTR_KIND, or
4752 NULL if it is not present. */
4754 static inline const char *
4755 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4757 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4759 return a
? AT_string (a
) : NULL
;
4762 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4763 if it is not present. */
4766 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4768 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4770 return a
? AT_flag (a
) : 0;
4773 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4774 if it is not present. */
4776 static inline unsigned
4777 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4779 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4781 return a
? AT_unsigned (a
) : 0;
4784 static inline dw_die_ref
4785 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4787 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4789 return a
? AT_ref (a
) : NULL
;
4792 static inline struct dwarf_file_data
*
4793 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4795 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4797 return a
? AT_file (a
) : NULL
;
4800 /* Return TRUE if the language is C++. */
4805 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4807 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
4808 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
4811 /* Return TRUE if the language is Java. */
4816 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4818 return lang
== DW_LANG_Java
;
4821 /* Return TRUE if the language is Fortran. */
4826 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4828 return (lang
== DW_LANG_Fortran77
4829 || lang
== DW_LANG_Fortran90
4830 || lang
== DW_LANG_Fortran95
4831 || lang
== DW_LANG_Fortran03
4832 || lang
== DW_LANG_Fortran08
);
4835 /* Return TRUE if the language is Ada. */
4840 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4842 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4845 /* Remove the specified attribute if present. Return TRUE if removal
4849 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4857 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4858 if (a
->dw_attr
== attr_kind
)
4860 if (AT_class (a
) == dw_val_class_str
)
4861 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4862 a
->dw_attr_val
.v
.val_str
->refcount
--;
4864 /* vec::ordered_remove should help reduce the number of abbrevs
4866 die
->die_attr
->ordered_remove (ix
);
4872 /* Remove CHILD from its parent. PREV must have the property that
4873 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4876 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4878 gcc_assert (child
->die_parent
== prev
->die_parent
);
4879 gcc_assert (prev
->die_sib
== child
);
4882 gcc_assert (child
->die_parent
->die_child
== child
);
4886 prev
->die_sib
= child
->die_sib
;
4887 if (child
->die_parent
->die_child
== child
)
4888 child
->die_parent
->die_child
= prev
;
4891 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4892 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4895 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4897 dw_die_ref parent
= old_child
->die_parent
;
4899 gcc_assert (parent
== prev
->die_parent
);
4900 gcc_assert (prev
->die_sib
== old_child
);
4902 new_child
->die_parent
= parent
;
4903 if (prev
== old_child
)
4905 gcc_assert (parent
->die_child
== old_child
);
4906 new_child
->die_sib
= new_child
;
4910 prev
->die_sib
= new_child
;
4911 new_child
->die_sib
= old_child
->die_sib
;
4913 if (old_child
->die_parent
->die_child
== old_child
)
4914 old_child
->die_parent
->die_child
= new_child
;
4917 /* Move all children from OLD_PARENT to NEW_PARENT. */
4920 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4923 new_parent
->die_child
= old_parent
->die_child
;
4924 old_parent
->die_child
= NULL
;
4925 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4928 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4932 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4938 dw_die_ref prev
= c
;
4940 while (c
->die_tag
== tag
)
4942 remove_child_with_prev (c
, prev
);
4943 c
->die_parent
= NULL
;
4944 /* Might have removed every child. */
4945 if (c
== c
->die_sib
)
4949 } while (c
!= die
->die_child
);
4952 /* Add a CHILD_DIE as the last child of DIE. */
4955 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4957 /* FIXME this should probably be an assert. */
4958 if (! die
|| ! child_die
)
4960 gcc_assert (die
!= child_die
);
4962 child_die
->die_parent
= die
;
4965 child_die
->die_sib
= die
->die_child
->die_sib
;
4966 die
->die_child
->die_sib
= child_die
;
4969 child_die
->die_sib
= child_die
;
4970 die
->die_child
= child_die
;
4973 /* Unassociate CHILD from its parent, and make its parent be
4977 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
4979 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4980 if (p
->die_sib
== child
)
4982 remove_child_with_prev (child
, p
);
4985 add_child_die (new_parent
, child
);
4988 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4989 is the specification, to the end of PARENT's list of children.
4990 This is done by removing and re-adding it. */
4993 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4995 /* We want the declaration DIE from inside the class, not the
4996 specification DIE at toplevel. */
4997 if (child
->die_parent
!= parent
)
4999 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5005 gcc_assert (child
->die_parent
== parent
5006 || (child
->die_parent
5007 == get_AT_ref (parent
, DW_AT_specification
)));
5009 reparent_child (child
, parent
);
5012 /* Create and return a new die with a parent of PARENT_DIE. If
5013 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5014 associated tree T must be supplied to determine parenthood
5017 static inline dw_die_ref
5018 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5020 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5022 die
->die_tag
= tag_value
;
5024 if (parent_die
!= NULL
)
5025 add_child_die (parent_die
, die
);
5028 limbo_die_node
*limbo_node
;
5030 /* No DIEs created after early dwarf should end up in limbo,
5031 because the limbo list should not persist past LTO
5033 if (tag_value
!= DW_TAG_compile_unit
5034 /* These are allowed because they're generated while
5035 breaking out COMDAT units late. */
5036 && tag_value
!= DW_TAG_type_unit
5038 /* Allow nested functions to live in limbo because they will
5039 only temporarily live there, as decls_for_scope will fix
5041 && (TREE_CODE (t
) != FUNCTION_DECL
5042 || !decl_function_context (t
))
5043 /* Same as nested functions above but for types. Types that
5044 are local to a function will be fixed in
5046 && (!RECORD_OR_UNION_TYPE_P (t
)
5047 || !TYPE_CONTEXT (t
)
5048 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5049 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5050 especially in the ltrans stage, but once we implement LTO
5051 dwarf streaming, we should remove this exception. */
5054 fprintf (stderr
, "symbol ended up in limbo too late:");
5055 debug_generic_stmt (t
);
5059 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5060 limbo_node
->die
= die
;
5061 limbo_node
->created_for
= t
;
5062 limbo_node
->next
= limbo_die_list
;
5063 limbo_die_list
= limbo_node
;
5069 /* Return the DIE associated with the given type specifier. */
5071 static inline dw_die_ref
5072 lookup_type_die (tree type
)
5074 return TYPE_SYMTAB_DIE (type
);
5077 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5078 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5079 anonymous type instead the one of the naming typedef. */
5081 static inline dw_die_ref
5082 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5085 && TREE_CODE (type
) == RECORD_TYPE
5087 && type_die
->die_tag
== DW_TAG_typedef
5088 && is_naming_typedef_decl (TYPE_NAME (type
)))
5089 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5093 /* Like lookup_type_die, but if type is an anonymous type named by a
5094 typedef[1], return the DIE of the anonymous type instead the one of
5095 the naming typedef. This is because in gen_typedef_die, we did
5096 equate the anonymous struct named by the typedef with the DIE of
5097 the naming typedef. So by default, lookup_type_die on an anonymous
5098 struct yields the DIE of the naming typedef.
5100 [1]: Read the comment of is_naming_typedef_decl to learn about what
5101 a naming typedef is. */
5103 static inline dw_die_ref
5104 lookup_type_die_strip_naming_typedef (tree type
)
5106 dw_die_ref die
= lookup_type_die (type
);
5107 return strip_naming_typedef (type
, die
);
5110 /* Equate a DIE to a given type specifier. */
5113 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5115 TYPE_SYMTAB_DIE (type
) = type_die
;
5118 /* Returns a hash value for X (which really is a die_struct). */
5121 decl_die_hasher::hash (die_node
*x
)
5123 return (hashval_t
) x
->decl_id
;
5126 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5129 decl_die_hasher::equal (die_node
*x
, tree y
)
5131 return (x
->decl_id
== DECL_UID (y
));
5134 /* Return the DIE associated with a given declaration. */
5136 static inline dw_die_ref
5137 lookup_decl_die (tree decl
)
5139 return decl_die_table
->find_with_hash (decl
, DECL_UID (decl
));
5142 /* Returns a hash value for X (which really is a var_loc_list). */
5145 decl_loc_hasher::hash (var_loc_list
*x
)
5147 return (hashval_t
) x
->decl_id
;
5150 /* Return nonzero if decl_id of var_loc_list X is the same as
5154 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5156 return (x
->decl_id
== DECL_UID (y
));
5159 /* Return the var_loc list associated with a given declaration. */
5161 static inline var_loc_list
*
5162 lookup_decl_loc (const_tree decl
)
5164 if (!decl_loc_table
)
5166 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5169 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5172 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5174 return (hashval_t
) x
->decl_id
;
5177 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5181 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5183 return (x
->decl_id
== DECL_UID (y
));
5186 /* Equate a DIE to a particular declaration. */
5189 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5191 unsigned int decl_id
= DECL_UID (decl
);
5193 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5194 decl_die
->decl_id
= decl_id
;
5197 /* Return how many bits covers PIECE EXPR_LIST. */
5199 static HOST_WIDE_INT
5200 decl_piece_bitsize (rtx piece
)
5202 int ret
= (int) GET_MODE (piece
);
5205 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5206 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5207 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5210 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5213 decl_piece_varloc_ptr (rtx piece
)
5215 if ((int) GET_MODE (piece
))
5216 return &XEXP (piece
, 0);
5218 return &XEXP (XEXP (piece
, 0), 1);
5221 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5222 Next is the chain of following piece nodes. */
5224 static rtx_expr_list
*
5225 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5227 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5228 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5230 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5235 /* Return rtx that should be stored into loc field for
5236 LOC_NOTE and BITPOS/BITSIZE. */
5239 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5240 HOST_WIDE_INT bitsize
)
5244 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5246 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5251 /* This function either modifies location piece list *DEST in
5252 place (if SRC and INNER is NULL), or copies location piece list
5253 *SRC to *DEST while modifying it. Location BITPOS is modified
5254 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5255 not copied and if needed some padding around it is added.
5256 When modifying in place, DEST should point to EXPR_LIST where
5257 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5258 to the start of the whole list and INNER points to the EXPR_LIST
5259 where earlier pieces cover PIECE_BITPOS bits. */
5262 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5263 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5264 HOST_WIDE_INT bitsize
, rtx loc_note
)
5267 bool copy
= inner
!= NULL
;
5271 /* First copy all nodes preceding the current bitpos. */
5272 while (src
!= inner
)
5274 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5275 decl_piece_bitsize (*src
), NULL_RTX
);
5276 dest
= &XEXP (*dest
, 1);
5277 src
= &XEXP (*src
, 1);
5280 /* Add padding if needed. */
5281 if (bitpos
!= piece_bitpos
)
5283 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5284 copy
? NULL_RTX
: *dest
);
5285 dest
= &XEXP (*dest
, 1);
5287 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5290 /* A piece with correct bitpos and bitsize already exist,
5291 just update the location for it and return. */
5292 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5295 /* Add the piece that changed. */
5296 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5297 dest
= &XEXP (*dest
, 1);
5298 /* Skip over pieces that overlap it. */
5299 diff
= bitpos
- piece_bitpos
+ bitsize
;
5302 while (diff
> 0 && *src
)
5305 diff
-= decl_piece_bitsize (piece
);
5307 src
= &XEXP (piece
, 1);
5310 *src
= XEXP (piece
, 1);
5311 free_EXPR_LIST_node (piece
);
5314 /* Add padding if needed. */
5315 if (diff
< 0 && *src
)
5319 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5320 dest
= &XEXP (*dest
, 1);
5324 /* Finally copy all nodes following it. */
5327 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5328 decl_piece_bitsize (*src
), NULL_RTX
);
5329 dest
= &XEXP (*dest
, 1);
5330 src
= &XEXP (*src
, 1);
5334 /* Add a variable location node to the linked list for DECL. */
5336 static struct var_loc_node
*
5337 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5339 unsigned int decl_id
;
5341 struct var_loc_node
*loc
= NULL
;
5342 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5344 if (TREE_CODE (decl
) == VAR_DECL
5345 && DECL_HAS_DEBUG_EXPR_P (decl
))
5347 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5348 if (handled_component_p (realdecl
)
5349 || (TREE_CODE (realdecl
) == MEM_REF
5350 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5352 HOST_WIDE_INT maxsize
;
5355 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
,
5357 if (!DECL_P (innerdecl
)
5358 || DECL_IGNORED_P (innerdecl
)
5359 || TREE_STATIC (innerdecl
)
5361 || bitpos
+ bitsize
> 256
5362 || bitsize
!= maxsize
)
5368 decl_id
= DECL_UID (decl
);
5370 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5373 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5374 temp
->decl_id
= decl_id
;
5380 /* For PARM_DECLs try to keep around the original incoming value,
5381 even if that means we'll emit a zero-range .debug_loc entry. */
5383 && temp
->first
== temp
->last
5384 && TREE_CODE (decl
) == PARM_DECL
5385 && NOTE_P (temp
->first
->loc
)
5386 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5387 && DECL_INCOMING_RTL (decl
)
5388 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5389 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5390 == GET_CODE (DECL_INCOMING_RTL (decl
))
5391 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5393 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5394 NOTE_VAR_LOCATION_LOC (loc_note
))
5395 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5396 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5398 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5399 temp
->first
->next
= loc
;
5401 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5403 else if (temp
->last
)
5405 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5406 rtx
*piece_loc
= NULL
, last_loc_note
;
5407 HOST_WIDE_INT piece_bitpos
= 0;
5411 gcc_assert (last
->next
== NULL
);
5413 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5415 piece_loc
= &last
->loc
;
5418 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5419 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5421 piece_bitpos
+= cur_bitsize
;
5422 piece_loc
= &XEXP (*piece_loc
, 1);
5426 /* TEMP->LAST here is either pointer to the last but one or
5427 last element in the chained list, LAST is pointer to the
5429 if (label
&& strcmp (last
->label
, label
) == 0)
5431 /* For SRA optimized variables if there weren't any real
5432 insns since last note, just modify the last node. */
5433 if (piece_loc
!= NULL
)
5435 adjust_piece_list (piece_loc
, NULL
, NULL
,
5436 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5439 /* If the last note doesn't cover any instructions, remove it. */
5440 if (temp
->last
!= last
)
5442 temp
->last
->next
= NULL
;
5445 gcc_assert (strcmp (last
->label
, label
) != 0);
5449 gcc_assert (temp
->first
== temp
->last
5450 || (temp
->first
->next
== temp
->last
5451 && TREE_CODE (decl
) == PARM_DECL
));
5452 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5453 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5457 if (bitsize
== -1 && NOTE_P (last
->loc
))
5458 last_loc_note
= last
->loc
;
5459 else if (piece_loc
!= NULL
5460 && *piece_loc
!= NULL_RTX
5461 && piece_bitpos
== bitpos
5462 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5463 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5465 last_loc_note
= NULL_RTX
;
5466 /* If the current location is the same as the end of the list,
5467 and either both or neither of the locations is uninitialized,
5468 we have nothing to do. */
5469 if (last_loc_note
== NULL_RTX
5470 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5471 NOTE_VAR_LOCATION_LOC (loc_note
)))
5472 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5473 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5474 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5475 == VAR_INIT_STATUS_UNINITIALIZED
)
5476 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5477 == VAR_INIT_STATUS_UNINITIALIZED
))))
5479 /* Add LOC to the end of list and update LAST. If the last
5480 element of the list has been removed above, reuse its
5481 memory for the new node, otherwise allocate a new one. */
5485 memset (loc
, '\0', sizeof (*loc
));
5488 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5489 if (bitsize
== -1 || piece_loc
== NULL
)
5490 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5492 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5493 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5495 /* Ensure TEMP->LAST will point either to the new last but one
5496 element of the chain, or to the last element in it. */
5497 if (last
!= temp
->last
)
5505 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5508 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5513 /* Keep track of the number of spaces used to indent the
5514 output of the debugging routines that print the structure of
5515 the DIE internal representation. */
5516 static int print_indent
;
5518 /* Indent the line the number of spaces given by print_indent. */
5521 print_spaces (FILE *outfile
)
5523 fprintf (outfile
, "%*s", print_indent
, "");
5526 /* Print a type signature in hex. */
5529 print_signature (FILE *outfile
, char *sig
)
5533 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5534 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5538 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
5540 if (discr_value
->pos
)
5541 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
5543 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
5546 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
5548 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5549 RECURSE, output location descriptor operations. */
5552 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
5554 switch (val
->val_class
)
5556 case dw_val_class_addr
:
5557 fprintf (outfile
, "address");
5559 case dw_val_class_offset
:
5560 fprintf (outfile
, "offset");
5562 case dw_val_class_loc
:
5563 fprintf (outfile
, "location descriptor");
5564 if (val
->v
.val_loc
== NULL
)
5565 fprintf (outfile
, " -> <null>\n");
5568 fprintf (outfile
, ":\n");
5570 print_loc_descr (val
->v
.val_loc
, outfile
);
5574 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
5576 case dw_val_class_loc_list
:
5577 fprintf (outfile
, "location list -> label:%s",
5578 val
->v
.val_loc_list
->ll_symbol
);
5580 case dw_val_class_range_list
:
5581 fprintf (outfile
, "range list");
5583 case dw_val_class_const
:
5584 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
5586 case dw_val_class_unsigned_const
:
5587 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
5589 case dw_val_class_const_double
:
5590 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
5591 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5592 val
->v
.val_double
.high
,
5593 val
->v
.val_double
.low
);
5595 case dw_val_class_wide_int
:
5597 int i
= val
->v
.val_wide
->get_len ();
5598 fprintf (outfile
, "constant (");
5600 if (val
->v
.val_wide
->elt (i
- 1) == 0)
5601 fprintf (outfile
, "0x");
5602 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5603 val
->v
.val_wide
->elt (--i
));
5605 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5606 val
->v
.val_wide
->elt (i
));
5607 fprintf (outfile
, ")");
5610 case dw_val_class_vec
:
5611 fprintf (outfile
, "floating-point or vector constant");
5613 case dw_val_class_flag
:
5614 fprintf (outfile
, "%u", val
->v
.val_flag
);
5616 case dw_val_class_die_ref
:
5617 if (val
->v
.val_die_ref
.die
!= NULL
)
5619 dw_die_ref die
= val
->v
.val_die_ref
.die
;
5621 if (die
->comdat_type_p
)
5623 fprintf (outfile
, "die -> signature: ");
5624 print_signature (outfile
,
5625 die
->die_id
.die_type_node
->signature
);
5627 else if (die
->die_id
.die_symbol
)
5628 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
5630 fprintf (outfile
, "die -> %ld", die
->die_offset
);
5631 fprintf (outfile
, " (%p)", (void *) die
);
5634 fprintf (outfile
, "die -> <null>");
5636 case dw_val_class_vms_delta
:
5637 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5638 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
5640 case dw_val_class_lbl_id
:
5641 case dw_val_class_lineptr
:
5642 case dw_val_class_macptr
:
5643 case dw_val_class_high_pc
:
5644 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
5646 case dw_val_class_str
:
5647 if (val
->v
.val_str
->str
!= NULL
)
5648 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
5650 fprintf (outfile
, "<null>");
5652 case dw_val_class_file
:
5653 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
5654 val
->v
.val_file
->emitted_number
);
5656 case dw_val_class_data8
:
5660 for (i
= 0; i
< 8; i
++)
5661 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
5664 case dw_val_class_discr_value
:
5665 print_discr_value (outfile
, &val
->v
.val_discr_value
);
5667 case dw_val_class_discr_list
:
5668 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
5670 node
= node
->dw_discr_next
)
5672 if (node
->dw_discr_range
)
5674 fprintf (outfile
, " .. ");
5675 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5676 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
5679 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5681 if (node
->dw_discr_next
!= NULL
)
5682 fprintf (outfile
, " | ");
5689 /* Likewise, for a DIE attribute. */
5692 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
5694 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
5698 /* Print the list of operands in the LOC location description to OUTFILE. This
5699 routine is a debugging aid only. */
5702 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
5704 dw_loc_descr_ref l
= loc
;
5708 print_spaces (outfile
);
5709 fprintf (outfile
, "<null>\n");
5713 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5715 print_spaces (outfile
);
5716 fprintf (outfile
, "(%p) %s",
5718 dwarf_stack_op_name (l
->dw_loc_opc
));
5719 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
5721 fprintf (outfile
, " ");
5722 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
5724 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
5726 fprintf (outfile
, ", ");
5727 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
5729 fprintf (outfile
, "\n");
5733 /* Print the information associated with a given DIE, and its children.
5734 This routine is a debugging aid only. */
5737 print_die (dw_die_ref die
, FILE *outfile
)
5743 print_spaces (outfile
);
5744 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5745 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5747 print_spaces (outfile
);
5748 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5749 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5750 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5752 if (die
->comdat_type_p
)
5754 print_spaces (outfile
);
5755 fprintf (outfile
, " signature: ");
5756 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5757 fprintf (outfile
, "\n");
5760 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5762 print_spaces (outfile
);
5763 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5765 print_attribute (a
, true, outfile
);
5766 fprintf (outfile
, "\n");
5769 if (die
->die_child
!= NULL
)
5772 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5775 if (print_indent
== 0)
5776 fprintf (outfile
, "\n");
5779 /* Print the list of operations in the LOC location description. */
5782 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
5784 print_loc_descr (loc
, stderr
);
5787 /* Print the information collected for a given DIE. */
5790 debug_dwarf_die (dw_die_ref die
)
5792 print_die (die
, stderr
);
5796 debug (die_struct
&ref
)
5798 print_die (&ref
, stderr
);
5802 debug (die_struct
*ptr
)
5807 fprintf (stderr
, "<nil>\n");
5811 /* Print all DWARF information collected for the compilation unit.
5812 This routine is a debugging aid only. */
5818 print_die (comp_unit_die (), stderr
);
5821 /* Sanity checks on DIEs. */
5824 check_die (dw_die_ref die
)
5828 bool inline_found
= false;
5829 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
5830 int n_decl_line
= 0, n_decl_file
= 0;
5831 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5836 if (a
->dw_attr_val
.v
.val_unsigned
)
5837 inline_found
= true;
5839 case DW_AT_location
:
5848 case DW_AT_artificial
:
5851 case DW_AT_decl_line
:
5854 case DW_AT_decl_file
:
5861 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
5862 || n_decl_line
> 1 || n_decl_file
> 1)
5864 fprintf (stderr
, "Duplicate attributes in DIE:\n");
5865 debug_dwarf_die (die
);
5870 /* A debugging information entry that is a member of an abstract
5871 instance tree [that has DW_AT_inline] should not contain any
5872 attributes which describe aspects of the subroutine which vary
5873 between distinct inlined expansions or distinct out-of-line
5875 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5876 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
5877 && a
->dw_attr
!= DW_AT_high_pc
5878 && a
->dw_attr
!= DW_AT_location
5879 && a
->dw_attr
!= DW_AT_frame_base
5880 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
5884 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5885 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5886 DIE that marks the start of the DIEs for this include file. */
5889 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5891 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5892 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5894 new_unit
->die_sib
= old_unit
;
5898 /* Close an include-file CU and reopen the enclosing one. */
5901 pop_compile_unit (dw_die_ref old_unit
)
5903 dw_die_ref new_unit
= old_unit
->die_sib
;
5905 old_unit
->die_sib
= NULL
;
5909 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5910 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5911 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5913 /* Calculate the checksum of a location expression. */
5916 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5919 inchash::hash hstate
;
5922 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5924 hash_loc_operands (loc
, hstate
);
5925 hash
= hstate
.end();
5929 /* Calculate the checksum of an attribute. */
5932 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
5934 dw_loc_descr_ref loc
;
5937 CHECKSUM (at
->dw_attr
);
5939 /* We don't care that this was compiled with a different compiler
5940 snapshot; if the output is the same, that's what matters. */
5941 if (at
->dw_attr
== DW_AT_producer
)
5944 switch (AT_class (at
))
5946 case dw_val_class_const
:
5947 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5949 case dw_val_class_unsigned_const
:
5950 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5952 case dw_val_class_const_double
:
5953 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5955 case dw_val_class_wide_int
:
5956 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
5957 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
5958 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
5960 case dw_val_class_vec
:
5961 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5962 (at
->dw_attr_val
.v
.val_vec
.length
5963 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5965 case dw_val_class_flag
:
5966 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5968 case dw_val_class_str
:
5969 CHECKSUM_STRING (AT_string (at
));
5972 case dw_val_class_addr
:
5974 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5975 CHECKSUM_STRING (XSTR (r
, 0));
5978 case dw_val_class_offset
:
5979 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5982 case dw_val_class_loc
:
5983 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5984 loc_checksum (loc
, ctx
);
5987 case dw_val_class_die_ref
:
5988 die_checksum (AT_ref (at
), ctx
, mark
);
5991 case dw_val_class_fde_ref
:
5992 case dw_val_class_vms_delta
:
5993 case dw_val_class_lbl_id
:
5994 case dw_val_class_lineptr
:
5995 case dw_val_class_macptr
:
5996 case dw_val_class_high_pc
:
5999 case dw_val_class_file
:
6000 CHECKSUM_STRING (AT_file (at
)->filename
);
6003 case dw_val_class_data8
:
6004 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6012 /* Calculate the checksum of a DIE. */
6015 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6021 /* To avoid infinite recursion. */
6024 CHECKSUM (die
->die_mark
);
6027 die
->die_mark
= ++(*mark
);
6029 CHECKSUM (die
->die_tag
);
6031 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6032 attr_checksum (a
, ctx
, mark
);
6034 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6038 #undef CHECKSUM_BLOCK
6039 #undef CHECKSUM_STRING
6041 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6042 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6043 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6044 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6045 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6046 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6047 #define CHECKSUM_ATTR(FOO) \
6048 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6050 /* Calculate the checksum of a number in signed LEB128 format. */
6053 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6060 byte
= (value
& 0x7f);
6062 more
= !((value
== 0 && (byte
& 0x40) == 0)
6063 || (value
== -1 && (byte
& 0x40) != 0));
6072 /* Calculate the checksum of a number in unsigned LEB128 format. */
6075 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6079 unsigned char byte
= (value
& 0x7f);
6082 /* More bytes to follow. */
6090 /* Checksum the context of the DIE. This adds the names of any
6091 surrounding namespaces or structures to the checksum. */
6094 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
6098 int tag
= die
->die_tag
;
6100 if (tag
!= DW_TAG_namespace
6101 && tag
!= DW_TAG_structure_type
6102 && tag
!= DW_TAG_class_type
)
6105 name
= get_AT_string (die
, DW_AT_name
);
6107 spec
= get_AT_ref (die
, DW_AT_specification
);
6111 if (die
->die_parent
!= NULL
)
6112 checksum_die_context (die
->die_parent
, ctx
);
6114 CHECKSUM_ULEB128 ('C');
6115 CHECKSUM_ULEB128 (tag
);
6117 CHECKSUM_STRING (name
);
6120 /* Calculate the checksum of a location expression. */
6123 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6125 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6126 were emitted as a DW_FORM_sdata instead of a location expression. */
6127 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6129 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6130 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6134 /* Otherwise, just checksum the raw location expression. */
6137 inchash::hash hstate
;
6140 CHECKSUM_ULEB128 (loc
->dtprel
);
6141 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6142 hash_loc_operands (loc
, hstate
);
6143 hash
= hstate
.end ();
6145 loc
= loc
->dw_loc_next
;
6149 /* Calculate the checksum of an attribute. */
6152 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
6153 struct md5_ctx
*ctx
, int *mark
)
6155 dw_loc_descr_ref loc
;
6158 if (AT_class (at
) == dw_val_class_die_ref
)
6160 dw_die_ref target_die
= AT_ref (at
);
6162 /* For pointer and reference types, we checksum only the (qualified)
6163 name of the target type (if there is a name). For friend entries,
6164 we checksum only the (qualified) name of the target type or function.
6165 This allows the checksum to remain the same whether the target type
6166 is complete or not. */
6167 if ((at
->dw_attr
== DW_AT_type
6168 && (tag
== DW_TAG_pointer_type
6169 || tag
== DW_TAG_reference_type
6170 || tag
== DW_TAG_rvalue_reference_type
6171 || tag
== DW_TAG_ptr_to_member_type
))
6172 || (at
->dw_attr
== DW_AT_friend
6173 && tag
== DW_TAG_friend
))
6175 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
6177 if (name_attr
!= NULL
)
6179 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6183 CHECKSUM_ULEB128 ('N');
6184 CHECKSUM_ULEB128 (at
->dw_attr
);
6185 if (decl
->die_parent
!= NULL
)
6186 checksum_die_context (decl
->die_parent
, ctx
);
6187 CHECKSUM_ULEB128 ('E');
6188 CHECKSUM_STRING (AT_string (name_attr
));
6193 /* For all other references to another DIE, we check to see if the
6194 target DIE has already been visited. If it has, we emit a
6195 backward reference; if not, we descend recursively. */
6196 if (target_die
->die_mark
> 0)
6198 CHECKSUM_ULEB128 ('R');
6199 CHECKSUM_ULEB128 (at
->dw_attr
);
6200 CHECKSUM_ULEB128 (target_die
->die_mark
);
6204 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6208 target_die
->die_mark
= ++(*mark
);
6209 CHECKSUM_ULEB128 ('T');
6210 CHECKSUM_ULEB128 (at
->dw_attr
);
6211 if (decl
->die_parent
!= NULL
)
6212 checksum_die_context (decl
->die_parent
, ctx
);
6213 die_checksum_ordered (target_die
, ctx
, mark
);
6218 CHECKSUM_ULEB128 ('A');
6219 CHECKSUM_ULEB128 (at
->dw_attr
);
6221 switch (AT_class (at
))
6223 case dw_val_class_const
:
6224 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6225 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6228 case dw_val_class_unsigned_const
:
6229 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6230 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6233 case dw_val_class_const_double
:
6234 CHECKSUM_ULEB128 (DW_FORM_block
);
6235 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6236 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6239 case dw_val_class_wide_int
:
6240 CHECKSUM_ULEB128 (DW_FORM_block
);
6241 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6242 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6243 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6244 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6245 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6248 case dw_val_class_vec
:
6249 CHECKSUM_ULEB128 (DW_FORM_block
);
6250 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6251 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6252 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6253 (at
->dw_attr_val
.v
.val_vec
.length
6254 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6257 case dw_val_class_flag
:
6258 CHECKSUM_ULEB128 (DW_FORM_flag
);
6259 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6262 case dw_val_class_str
:
6263 CHECKSUM_ULEB128 (DW_FORM_string
);
6264 CHECKSUM_STRING (AT_string (at
));
6267 case dw_val_class_addr
:
6269 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6270 CHECKSUM_ULEB128 (DW_FORM_string
);
6271 CHECKSUM_STRING (XSTR (r
, 0));
6274 case dw_val_class_offset
:
6275 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6276 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6279 case dw_val_class_loc
:
6280 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6281 loc_checksum_ordered (loc
, ctx
);
6284 case dw_val_class_fde_ref
:
6285 case dw_val_class_lbl_id
:
6286 case dw_val_class_lineptr
:
6287 case dw_val_class_macptr
:
6288 case dw_val_class_high_pc
:
6291 case dw_val_class_file
:
6292 CHECKSUM_ULEB128 (DW_FORM_string
);
6293 CHECKSUM_STRING (AT_file (at
)->filename
);
6296 case dw_val_class_data8
:
6297 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6305 struct checksum_attributes
6307 dw_attr_node
*at_name
;
6308 dw_attr_node
*at_type
;
6309 dw_attr_node
*at_friend
;
6310 dw_attr_node
*at_accessibility
;
6311 dw_attr_node
*at_address_class
;
6312 dw_attr_node
*at_allocated
;
6313 dw_attr_node
*at_artificial
;
6314 dw_attr_node
*at_associated
;
6315 dw_attr_node
*at_binary_scale
;
6316 dw_attr_node
*at_bit_offset
;
6317 dw_attr_node
*at_bit_size
;
6318 dw_attr_node
*at_bit_stride
;
6319 dw_attr_node
*at_byte_size
;
6320 dw_attr_node
*at_byte_stride
;
6321 dw_attr_node
*at_const_value
;
6322 dw_attr_node
*at_containing_type
;
6323 dw_attr_node
*at_count
;
6324 dw_attr_node
*at_data_location
;
6325 dw_attr_node
*at_data_member_location
;
6326 dw_attr_node
*at_decimal_scale
;
6327 dw_attr_node
*at_decimal_sign
;
6328 dw_attr_node
*at_default_value
;
6329 dw_attr_node
*at_digit_count
;
6330 dw_attr_node
*at_discr
;
6331 dw_attr_node
*at_discr_list
;
6332 dw_attr_node
*at_discr_value
;
6333 dw_attr_node
*at_encoding
;
6334 dw_attr_node
*at_endianity
;
6335 dw_attr_node
*at_explicit
;
6336 dw_attr_node
*at_is_optional
;
6337 dw_attr_node
*at_location
;
6338 dw_attr_node
*at_lower_bound
;
6339 dw_attr_node
*at_mutable
;
6340 dw_attr_node
*at_ordering
;
6341 dw_attr_node
*at_picture_string
;
6342 dw_attr_node
*at_prototyped
;
6343 dw_attr_node
*at_small
;
6344 dw_attr_node
*at_segment
;
6345 dw_attr_node
*at_string_length
;
6346 dw_attr_node
*at_threads_scaled
;
6347 dw_attr_node
*at_upper_bound
;
6348 dw_attr_node
*at_use_location
;
6349 dw_attr_node
*at_use_UTF8
;
6350 dw_attr_node
*at_variable_parameter
;
6351 dw_attr_node
*at_virtuality
;
6352 dw_attr_node
*at_visibility
;
6353 dw_attr_node
*at_vtable_elem_location
;
6356 /* Collect the attributes that we will want to use for the checksum. */
6359 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6364 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6375 attrs
->at_friend
= a
;
6377 case DW_AT_accessibility
:
6378 attrs
->at_accessibility
= a
;
6380 case DW_AT_address_class
:
6381 attrs
->at_address_class
= a
;
6383 case DW_AT_allocated
:
6384 attrs
->at_allocated
= a
;
6386 case DW_AT_artificial
:
6387 attrs
->at_artificial
= a
;
6389 case DW_AT_associated
:
6390 attrs
->at_associated
= a
;
6392 case DW_AT_binary_scale
:
6393 attrs
->at_binary_scale
= a
;
6395 case DW_AT_bit_offset
:
6396 attrs
->at_bit_offset
= a
;
6398 case DW_AT_bit_size
:
6399 attrs
->at_bit_size
= a
;
6401 case DW_AT_bit_stride
:
6402 attrs
->at_bit_stride
= a
;
6404 case DW_AT_byte_size
:
6405 attrs
->at_byte_size
= a
;
6407 case DW_AT_byte_stride
:
6408 attrs
->at_byte_stride
= a
;
6410 case DW_AT_const_value
:
6411 attrs
->at_const_value
= a
;
6413 case DW_AT_containing_type
:
6414 attrs
->at_containing_type
= a
;
6417 attrs
->at_count
= a
;
6419 case DW_AT_data_location
:
6420 attrs
->at_data_location
= a
;
6422 case DW_AT_data_member_location
:
6423 attrs
->at_data_member_location
= a
;
6425 case DW_AT_decimal_scale
:
6426 attrs
->at_decimal_scale
= a
;
6428 case DW_AT_decimal_sign
:
6429 attrs
->at_decimal_sign
= a
;
6431 case DW_AT_default_value
:
6432 attrs
->at_default_value
= a
;
6434 case DW_AT_digit_count
:
6435 attrs
->at_digit_count
= a
;
6438 attrs
->at_discr
= a
;
6440 case DW_AT_discr_list
:
6441 attrs
->at_discr_list
= a
;
6443 case DW_AT_discr_value
:
6444 attrs
->at_discr_value
= a
;
6446 case DW_AT_encoding
:
6447 attrs
->at_encoding
= a
;
6449 case DW_AT_endianity
:
6450 attrs
->at_endianity
= a
;
6452 case DW_AT_explicit
:
6453 attrs
->at_explicit
= a
;
6455 case DW_AT_is_optional
:
6456 attrs
->at_is_optional
= a
;
6458 case DW_AT_location
:
6459 attrs
->at_location
= a
;
6461 case DW_AT_lower_bound
:
6462 attrs
->at_lower_bound
= a
;
6465 attrs
->at_mutable
= a
;
6467 case DW_AT_ordering
:
6468 attrs
->at_ordering
= a
;
6470 case DW_AT_picture_string
:
6471 attrs
->at_picture_string
= a
;
6473 case DW_AT_prototyped
:
6474 attrs
->at_prototyped
= a
;
6477 attrs
->at_small
= a
;
6480 attrs
->at_segment
= a
;
6482 case DW_AT_string_length
:
6483 attrs
->at_string_length
= a
;
6485 case DW_AT_threads_scaled
:
6486 attrs
->at_threads_scaled
= a
;
6488 case DW_AT_upper_bound
:
6489 attrs
->at_upper_bound
= a
;
6491 case DW_AT_use_location
:
6492 attrs
->at_use_location
= a
;
6494 case DW_AT_use_UTF8
:
6495 attrs
->at_use_UTF8
= a
;
6497 case DW_AT_variable_parameter
:
6498 attrs
->at_variable_parameter
= a
;
6500 case DW_AT_virtuality
:
6501 attrs
->at_virtuality
= a
;
6503 case DW_AT_visibility
:
6504 attrs
->at_visibility
= a
;
6506 case DW_AT_vtable_elem_location
:
6507 attrs
->at_vtable_elem_location
= a
;
6515 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6518 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6522 struct checksum_attributes attrs
;
6524 CHECKSUM_ULEB128 ('D');
6525 CHECKSUM_ULEB128 (die
->die_tag
);
6527 memset (&attrs
, 0, sizeof (attrs
));
6529 decl
= get_AT_ref (die
, DW_AT_specification
);
6531 collect_checksum_attributes (&attrs
, decl
);
6532 collect_checksum_attributes (&attrs
, die
);
6534 CHECKSUM_ATTR (attrs
.at_name
);
6535 CHECKSUM_ATTR (attrs
.at_accessibility
);
6536 CHECKSUM_ATTR (attrs
.at_address_class
);
6537 CHECKSUM_ATTR (attrs
.at_allocated
);
6538 CHECKSUM_ATTR (attrs
.at_artificial
);
6539 CHECKSUM_ATTR (attrs
.at_associated
);
6540 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6541 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6542 CHECKSUM_ATTR (attrs
.at_bit_size
);
6543 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6544 CHECKSUM_ATTR (attrs
.at_byte_size
);
6545 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6546 CHECKSUM_ATTR (attrs
.at_const_value
);
6547 CHECKSUM_ATTR (attrs
.at_containing_type
);
6548 CHECKSUM_ATTR (attrs
.at_count
);
6549 CHECKSUM_ATTR (attrs
.at_data_location
);
6550 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6551 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6552 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6553 CHECKSUM_ATTR (attrs
.at_default_value
);
6554 CHECKSUM_ATTR (attrs
.at_digit_count
);
6555 CHECKSUM_ATTR (attrs
.at_discr
);
6556 CHECKSUM_ATTR (attrs
.at_discr_list
);
6557 CHECKSUM_ATTR (attrs
.at_discr_value
);
6558 CHECKSUM_ATTR (attrs
.at_encoding
);
6559 CHECKSUM_ATTR (attrs
.at_endianity
);
6560 CHECKSUM_ATTR (attrs
.at_explicit
);
6561 CHECKSUM_ATTR (attrs
.at_is_optional
);
6562 CHECKSUM_ATTR (attrs
.at_location
);
6563 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6564 CHECKSUM_ATTR (attrs
.at_mutable
);
6565 CHECKSUM_ATTR (attrs
.at_ordering
);
6566 CHECKSUM_ATTR (attrs
.at_picture_string
);
6567 CHECKSUM_ATTR (attrs
.at_prototyped
);
6568 CHECKSUM_ATTR (attrs
.at_small
);
6569 CHECKSUM_ATTR (attrs
.at_segment
);
6570 CHECKSUM_ATTR (attrs
.at_string_length
);
6571 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6572 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6573 CHECKSUM_ATTR (attrs
.at_use_location
);
6574 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6575 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6576 CHECKSUM_ATTR (attrs
.at_virtuality
);
6577 CHECKSUM_ATTR (attrs
.at_visibility
);
6578 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6579 CHECKSUM_ATTR (attrs
.at_type
);
6580 CHECKSUM_ATTR (attrs
.at_friend
);
6582 /* Checksum the child DIEs. */
6585 dw_attr_node
*name_attr
;
6588 name_attr
= get_AT (c
, DW_AT_name
);
6589 if (is_template_instantiation (c
))
6591 /* Ignore instantiations of member type and function templates. */
6593 else if (name_attr
!= NULL
6594 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6596 /* Use a shallow checksum for named nested types and member
6598 CHECKSUM_ULEB128 ('S');
6599 CHECKSUM_ULEB128 (c
->die_tag
);
6600 CHECKSUM_STRING (AT_string (name_attr
));
6604 /* Use a deep checksum for other children. */
6605 /* Mark this DIE so it gets processed when unmarking. */
6606 if (c
->die_mark
== 0)
6608 die_checksum_ordered (c
, ctx
, mark
);
6610 } while (c
!= die
->die_child
);
6612 CHECKSUM_ULEB128 (0);
6615 /* Add a type name and tag to a hash. */
6617 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6619 CHECKSUM_ULEB128 (tag
);
6620 CHECKSUM_STRING (name
);
6624 #undef CHECKSUM_STRING
6625 #undef CHECKSUM_ATTR
6626 #undef CHECKSUM_LEB128
6627 #undef CHECKSUM_ULEB128
6629 /* Generate the type signature for DIE. This is computed by generating an
6630 MD5 checksum over the DIE's tag, its relevant attributes, and its
6631 children. Attributes that are references to other DIEs are processed
6632 by recursion, using the MARK field to prevent infinite recursion.
6633 If the DIE is nested inside a namespace or another type, we also
6634 need to include that context in the signature. The lower 64 bits
6635 of the resulting MD5 checksum comprise the signature. */
6638 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6642 unsigned char checksum
[16];
6647 name
= get_AT_string (die
, DW_AT_name
);
6648 decl
= get_AT_ref (die
, DW_AT_specification
);
6649 parent
= get_die_parent (die
);
6651 /* First, compute a signature for just the type name (and its surrounding
6652 context, if any. This is stored in the type unit DIE for link-time
6653 ODR (one-definition rule) checking. */
6655 if (is_cxx () && name
!= NULL
)
6657 md5_init_ctx (&ctx
);
6659 /* Checksum the names of surrounding namespaces and structures. */
6661 checksum_die_context (parent
, &ctx
);
6663 /* Checksum the current DIE. */
6664 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6665 md5_finish_ctx (&ctx
, checksum
);
6667 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6670 /* Next, compute the complete type signature. */
6672 md5_init_ctx (&ctx
);
6674 die
->die_mark
= mark
;
6676 /* Checksum the names of surrounding namespaces and structures. */
6678 checksum_die_context (parent
, &ctx
);
6680 /* Checksum the DIE and its children. */
6681 die_checksum_ordered (die
, &ctx
, &mark
);
6682 unmark_all_dies (die
);
6683 md5_finish_ctx (&ctx
, checksum
);
6685 /* Store the signature in the type node and link the type DIE and the
6686 type node together. */
6687 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6688 DWARF_TYPE_SIGNATURE_SIZE
);
6689 die
->comdat_type_p
= true;
6690 die
->die_id
.die_type_node
= type_node
;
6691 type_node
->type_die
= die
;
6693 /* If the DIE is a specification, link its declaration to the type node
6697 decl
->comdat_type_p
= true;
6698 decl
->die_id
.die_type_node
= type_node
;
6702 /* Do the location expressions look same? */
6704 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6706 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6707 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6708 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6711 /* Do the values look the same? */
6713 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6715 dw_loc_descr_ref loc1
, loc2
;
6718 if (v1
->val_class
!= v2
->val_class
)
6721 switch (v1
->val_class
)
6723 case dw_val_class_const
:
6724 return v1
->v
.val_int
== v2
->v
.val_int
;
6725 case dw_val_class_unsigned_const
:
6726 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6727 case dw_val_class_const_double
:
6728 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6729 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6730 case dw_val_class_wide_int
:
6731 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
6732 case dw_val_class_vec
:
6733 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6734 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6736 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6737 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6740 case dw_val_class_flag
:
6741 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6742 case dw_val_class_str
:
6743 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6745 case dw_val_class_addr
:
6746 r1
= v1
->v
.val_addr
;
6747 r2
= v2
->v
.val_addr
;
6748 if (GET_CODE (r1
) != GET_CODE (r2
))
6750 return !rtx_equal_p (r1
, r2
);
6752 case dw_val_class_offset
:
6753 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6755 case dw_val_class_loc
:
6756 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6758 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6759 if (!same_loc_p (loc1
, loc2
, mark
))
6761 return !loc1
&& !loc2
;
6763 case dw_val_class_die_ref
:
6764 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6766 case dw_val_class_fde_ref
:
6767 case dw_val_class_vms_delta
:
6768 case dw_val_class_lbl_id
:
6769 case dw_val_class_lineptr
:
6770 case dw_val_class_macptr
:
6771 case dw_val_class_high_pc
:
6774 case dw_val_class_file
:
6775 return v1
->v
.val_file
== v2
->v
.val_file
;
6777 case dw_val_class_data8
:
6778 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6785 /* Do the attributes look the same? */
6788 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
6790 if (at1
->dw_attr
!= at2
->dw_attr
)
6793 /* We don't care that this was compiled with a different compiler
6794 snapshot; if the output is the same, that's what matters. */
6795 if (at1
->dw_attr
== DW_AT_producer
)
6798 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6801 /* Do the dies look the same? */
6804 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6810 /* To avoid infinite recursion. */
6812 return die1
->die_mark
== die2
->die_mark
;
6813 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6815 if (die1
->die_tag
!= die2
->die_tag
)
6818 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6821 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6822 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6825 c1
= die1
->die_child
;
6826 c2
= die2
->die_child
;
6835 if (!same_die_p (c1
, c2
, mark
))
6839 if (c1
== die1
->die_child
)
6841 if (c2
== die2
->die_child
)
6851 /* Do the dies look the same? Wrapper around same_die_p. */
6854 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6857 int ret
= same_die_p (die1
, die2
, &mark
);
6859 unmark_all_dies (die1
);
6860 unmark_all_dies (die2
);
6865 /* The prefix to attach to symbols on DIEs in the current comdat debug
6867 static const char *comdat_symbol_id
;
6869 /* The index of the current symbol within the current comdat CU. */
6870 static unsigned int comdat_symbol_number
;
6872 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6873 children, and set comdat_symbol_id accordingly. */
6876 compute_section_prefix (dw_die_ref unit_die
)
6878 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6879 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6880 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6883 unsigned char checksum
[16];
6886 /* Compute the checksum of the DIE, then append part of it as hex digits to
6887 the name filename of the unit. */
6889 md5_init_ctx (&ctx
);
6891 die_checksum (unit_die
, &ctx
, &mark
);
6892 unmark_all_dies (unit_die
);
6893 md5_finish_ctx (&ctx
, checksum
);
6895 sprintf (name
, "%s.", base
);
6896 clean_symbol_name (name
);
6898 p
= name
+ strlen (name
);
6899 for (i
= 0; i
< 4; i
++)
6901 sprintf (p
, "%.2x", checksum
[i
]);
6905 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6906 comdat_symbol_number
= 0;
6909 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6912 is_type_die (dw_die_ref die
)
6914 switch (die
->die_tag
)
6916 case DW_TAG_array_type
:
6917 case DW_TAG_class_type
:
6918 case DW_TAG_interface_type
:
6919 case DW_TAG_enumeration_type
:
6920 case DW_TAG_pointer_type
:
6921 case DW_TAG_reference_type
:
6922 case DW_TAG_rvalue_reference_type
:
6923 case DW_TAG_string_type
:
6924 case DW_TAG_structure_type
:
6925 case DW_TAG_subroutine_type
:
6926 case DW_TAG_union_type
:
6927 case DW_TAG_ptr_to_member_type
:
6928 case DW_TAG_set_type
:
6929 case DW_TAG_subrange_type
:
6930 case DW_TAG_base_type
:
6931 case DW_TAG_const_type
:
6932 case DW_TAG_file_type
:
6933 case DW_TAG_packed_type
:
6934 case DW_TAG_volatile_type
:
6935 case DW_TAG_typedef
:
6942 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6943 Basically, we want to choose the bits that are likely to be shared between
6944 compilations (types) and leave out the bits that are specific to individual
6945 compilations (functions). */
6948 is_comdat_die (dw_die_ref c
)
6950 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6951 we do for stabs. The advantage is a greater likelihood of sharing between
6952 objects that don't include headers in the same order (and therefore would
6953 put the base types in a different comdat). jason 8/28/00 */
6955 if (c
->die_tag
== DW_TAG_base_type
)
6958 if (c
->die_tag
== DW_TAG_pointer_type
6959 || c
->die_tag
== DW_TAG_reference_type
6960 || c
->die_tag
== DW_TAG_rvalue_reference_type
6961 || c
->die_tag
== DW_TAG_const_type
6962 || c
->die_tag
== DW_TAG_volatile_type
)
6964 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6966 return t
? is_comdat_die (t
) : 0;
6969 return is_type_die (c
);
6972 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6973 compilation unit. */
6976 is_symbol_die (dw_die_ref c
)
6978 return (is_type_die (c
)
6979 || is_declaration_die (c
)
6980 || c
->die_tag
== DW_TAG_namespace
6981 || c
->die_tag
== DW_TAG_module
);
6984 /* Returns true iff C is a compile-unit DIE. */
6987 is_cu_die (dw_die_ref c
)
6989 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6992 /* Returns true iff C is a unit DIE of some sort. */
6995 is_unit_die (dw_die_ref c
)
6997 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6998 || c
->die_tag
== DW_TAG_partial_unit
6999 || c
->die_tag
== DW_TAG_type_unit
);
7002 /* Returns true iff C is a namespace DIE. */
7005 is_namespace_die (dw_die_ref c
)
7007 return c
&& c
->die_tag
== DW_TAG_namespace
;
7010 /* Returns true iff C is a class or structure DIE. */
7013 is_class_die (dw_die_ref c
)
7015 return c
&& (c
->die_tag
== DW_TAG_class_type
7016 || c
->die_tag
== DW_TAG_structure_type
);
7019 /* Return non-zero if this DIE is a template parameter. */
7022 is_template_parameter (dw_die_ref die
)
7024 switch (die
->die_tag
)
7026 case DW_TAG_template_type_param
:
7027 case DW_TAG_template_value_param
:
7028 case DW_TAG_GNU_template_template_param
:
7029 case DW_TAG_GNU_template_parameter_pack
:
7036 /* Return non-zero if this DIE represents a template instantiation. */
7039 is_template_instantiation (dw_die_ref die
)
7043 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
7045 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
7050 gen_internal_sym (const char *prefix
)
7054 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7055 return xstrdup (buf
);
7058 /* Assign symbols to all worthy DIEs under DIE. */
7061 assign_symbol_names (dw_die_ref die
)
7065 if (is_symbol_die (die
) && !die
->comdat_type_p
)
7067 if (comdat_symbol_id
)
7069 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
7071 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
7072 comdat_symbol_id
, comdat_symbol_number
++);
7073 die
->die_id
.die_symbol
= xstrdup (p
);
7076 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
7079 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
7082 struct cu_hash_table_entry
7085 unsigned min_comdat_num
, max_comdat_num
;
7086 struct cu_hash_table_entry
*next
;
7089 /* Helpers to manipulate hash table of CUs. */
7091 struct cu_hash_table_entry_hasher
: pointer_hash
<cu_hash_table_entry
>
7093 typedef die_struct
*compare_type
;
7094 static inline hashval_t
hash (const cu_hash_table_entry
*);
7095 static inline bool equal (const cu_hash_table_entry
*, const die_struct
*);
7096 static inline void remove (cu_hash_table_entry
*);
7100 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry
*entry
)
7102 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
7106 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry
*entry1
,
7107 const die_struct
*entry2
)
7109 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
7113 cu_hash_table_entry_hasher::remove (cu_hash_table_entry
*entry
)
7115 struct cu_hash_table_entry
*next
;
7125 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
7127 /* Check whether we have already seen this CU and set up SYM_NUM
7130 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
7132 struct cu_hash_table_entry dummy
;
7133 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7135 dummy
.max_comdat_num
= 0;
7137 slot
= htable
->find_slot_with_hash (cu
,
7138 htab_hash_string (cu
->die_id
.die_symbol
),
7142 for (; entry
; last
= entry
, entry
= entry
->next
)
7144 if (same_die_p_wrap (cu
, entry
->cu
))
7150 *sym_num
= entry
->min_comdat_num
;
7154 entry
= XCNEW (struct cu_hash_table_entry
);
7156 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7157 entry
->next
= *slot
;
7163 /* Record SYM_NUM to record of CU in HTABLE. */
7165 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
7166 unsigned int sym_num
)
7168 struct cu_hash_table_entry
**slot
, *entry
;
7170 slot
= htable
->find_slot_with_hash (cu
,
7171 htab_hash_string (cu
->die_id
.die_symbol
),
7175 entry
->max_comdat_num
= sym_num
;
7178 /* Traverse the DIE (which is always comp_unit_die), and set up
7179 additional compilation units for each of the include files we see
7180 bracketed by BINCL/EINCL. */
7183 break_out_includes (dw_die_ref die
)
7186 dw_die_ref unit
= NULL
;
7187 limbo_die_node
*node
, **pnode
;
7191 dw_die_ref prev
= c
;
7193 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7194 || (unit
&& is_comdat_die (c
)))
7196 dw_die_ref next
= c
->die_sib
;
7198 /* This DIE is for a secondary CU; remove it from the main one. */
7199 remove_child_with_prev (c
, prev
);
7201 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7202 unit
= push_new_compile_unit (unit
, c
);
7203 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7204 unit
= pop_compile_unit (unit
);
7206 add_child_die (unit
, c
);
7208 if (c
== die
->die_child
)
7211 } while (c
!= die
->die_child
);
7214 /* We can only use this in debugging, since the frontend doesn't check
7215 to make sure that we leave every include file we enter. */
7219 assign_symbol_names (die
);
7220 cu_hash_type
cu_hash_table (10);
7221 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7227 compute_section_prefix (node
->die
);
7228 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
7229 &comdat_symbol_number
);
7230 assign_symbol_names (node
->die
);
7232 *pnode
= node
->next
;
7235 pnode
= &node
->next
;
7236 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
7237 comdat_symbol_number
);
7242 /* Return non-zero if this DIE is a declaration. */
7245 is_declaration_die (dw_die_ref die
)
7250 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7251 if (a
->dw_attr
== DW_AT_declaration
)
7257 /* Return non-zero if this DIE is nested inside a subprogram. */
7260 is_nested_in_subprogram (dw_die_ref die
)
7262 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7266 return local_scope_p (decl
);
7269 /* Return non-zero if this DIE contains a defining declaration of a
7273 contains_subprogram_definition (dw_die_ref die
)
7277 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7279 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7283 /* Return non-zero if this is a type DIE that should be moved to a
7284 COMDAT .debug_types section. */
7287 should_move_die_to_comdat (dw_die_ref die
)
7289 switch (die
->die_tag
)
7291 case DW_TAG_class_type
:
7292 case DW_TAG_structure_type
:
7293 case DW_TAG_enumeration_type
:
7294 case DW_TAG_union_type
:
7295 /* Don't move declarations, inlined instances, types nested in a
7296 subprogram, or types that contain subprogram definitions. */
7297 if (is_declaration_die (die
)
7298 || get_AT (die
, DW_AT_abstract_origin
)
7299 || is_nested_in_subprogram (die
)
7300 || contains_subprogram_definition (die
))
7303 case DW_TAG_array_type
:
7304 case DW_TAG_interface_type
:
7305 case DW_TAG_pointer_type
:
7306 case DW_TAG_reference_type
:
7307 case DW_TAG_rvalue_reference_type
:
7308 case DW_TAG_string_type
:
7309 case DW_TAG_subroutine_type
:
7310 case DW_TAG_ptr_to_member_type
:
7311 case DW_TAG_set_type
:
7312 case DW_TAG_subrange_type
:
7313 case DW_TAG_base_type
:
7314 case DW_TAG_const_type
:
7315 case DW_TAG_file_type
:
7316 case DW_TAG_packed_type
:
7317 case DW_TAG_volatile_type
:
7318 case DW_TAG_typedef
:
7324 /* Make a clone of DIE. */
7327 clone_die (dw_die_ref die
)
7333 clone
= ggc_cleared_alloc
<die_node
> ();
7334 clone
->die_tag
= die
->die_tag
;
7336 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7337 add_dwarf_attr (clone
, a
);
7342 /* Make a clone of the tree rooted at DIE. */
7345 clone_tree (dw_die_ref die
)
7348 dw_die_ref clone
= clone_die (die
);
7350 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7355 /* Make a clone of DIE as a declaration. */
7358 clone_as_declaration (dw_die_ref die
)
7365 /* If the DIE is already a declaration, just clone it. */
7366 if (is_declaration_die (die
))
7367 return clone_die (die
);
7369 /* If the DIE is a specification, just clone its declaration DIE. */
7370 decl
= get_AT_ref (die
, DW_AT_specification
);
7373 clone
= clone_die (decl
);
7374 if (die
->comdat_type_p
)
7375 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7379 clone
= ggc_cleared_alloc
<die_node
> ();
7380 clone
->die_tag
= die
->die_tag
;
7382 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7384 /* We don't want to copy over all attributes.
7385 For example we don't want DW_AT_byte_size because otherwise we will no
7386 longer have a declaration and GDB will treat it as a definition. */
7390 case DW_AT_abstract_origin
:
7391 case DW_AT_artificial
:
7392 case DW_AT_containing_type
:
7393 case DW_AT_external
:
7396 case DW_AT_virtuality
:
7397 case DW_AT_linkage_name
:
7398 case DW_AT_MIPS_linkage_name
:
7399 add_dwarf_attr (clone
, a
);
7401 case DW_AT_byte_size
:
7407 if (die
->comdat_type_p
)
7408 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7410 add_AT_flag (clone
, DW_AT_declaration
, 1);
7415 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7417 struct decl_table_entry
7423 /* Helpers to manipulate hash table of copied declarations. */
7425 /* Hashtable helpers. */
7427 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7429 typedef die_struct
*compare_type
;
7430 static inline hashval_t
hash (const decl_table_entry
*);
7431 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7435 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7437 return htab_hash_pointer (entry
->orig
);
7441 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7442 const die_struct
*entry2
)
7444 return entry1
->orig
== entry2
;
7447 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7449 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7450 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7451 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7452 to check if the ancestor has already been copied into UNIT. */
7455 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7456 decl_hash_type
*decl_table
)
7458 dw_die_ref parent
= die
->die_parent
;
7459 dw_die_ref new_parent
= unit
;
7461 decl_table_entry
**slot
= NULL
;
7462 struct decl_table_entry
*entry
= NULL
;
7466 /* Check if the entry has already been copied to UNIT. */
7467 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7469 if (*slot
!= HTAB_EMPTY_ENTRY
)
7475 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7476 entry
= XCNEW (struct decl_table_entry
);
7484 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7487 if (!is_unit_die (parent
))
7488 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7491 copy
= clone_as_declaration (die
);
7492 add_child_die (new_parent
, copy
);
7496 /* Record the pointer to the copy. */
7502 /* Copy the declaration context to the new type unit DIE. This includes
7503 any surrounding namespace or type declarations. If the DIE has an
7504 AT_specification attribute, it also includes attributes and children
7505 attached to the specification, and returns a pointer to the original
7506 parent of the declaration DIE. Returns NULL otherwise. */
7509 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7512 dw_die_ref new_decl
;
7513 dw_die_ref orig_parent
= NULL
;
7515 decl
= get_AT_ref (die
, DW_AT_specification
);
7524 /* The original DIE will be changed to a declaration, and must
7525 be moved to be a child of the original declaration DIE. */
7526 orig_parent
= decl
->die_parent
;
7528 /* Copy the type node pointer from the new DIE to the original
7529 declaration DIE so we can forward references later. */
7530 decl
->comdat_type_p
= true;
7531 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7533 remove_AT (die
, DW_AT_specification
);
7535 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7537 if (a
->dw_attr
!= DW_AT_name
7538 && a
->dw_attr
!= DW_AT_declaration
7539 && a
->dw_attr
!= DW_AT_external
)
7540 add_dwarf_attr (die
, a
);
7543 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7546 if (decl
->die_parent
!= NULL
7547 && !is_unit_die (decl
->die_parent
))
7549 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7550 if (new_decl
!= NULL
)
7552 remove_AT (new_decl
, DW_AT_signature
);
7553 add_AT_specification (die
, new_decl
);
7560 /* Generate the skeleton ancestor tree for the given NODE, then clone
7561 the DIE and add the clone into the tree. */
7564 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7566 if (node
->new_die
!= NULL
)
7569 node
->new_die
= clone_as_declaration (node
->old_die
);
7571 if (node
->parent
!= NULL
)
7573 generate_skeleton_ancestor_tree (node
->parent
);
7574 add_child_die (node
->parent
->new_die
, node
->new_die
);
7578 /* Generate a skeleton tree of DIEs containing any declarations that are
7579 found in the original tree. We traverse the tree looking for declaration
7580 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7583 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7585 skeleton_chain_node node
;
7588 dw_die_ref prev
= NULL
;
7589 dw_die_ref next
= NULL
;
7591 node
.parent
= parent
;
7593 first
= c
= parent
->old_die
->die_child
;
7597 if (prev
== NULL
|| prev
->die_sib
== c
)
7600 next
= (c
== first
? NULL
: c
->die_sib
);
7602 node
.new_die
= NULL
;
7603 if (is_declaration_die (c
))
7605 if (is_template_instantiation (c
))
7607 /* Instantiated templates do not need to be cloned into the
7608 type unit. Just move the DIE and its children back to
7609 the skeleton tree (in the main CU). */
7610 remove_child_with_prev (c
, prev
);
7611 add_child_die (parent
->new_die
, c
);
7616 /* Clone the existing DIE, move the original to the skeleton
7617 tree (which is in the main CU), and put the clone, with
7618 all the original's children, where the original came from
7619 (which is about to be moved to the type unit). */
7620 dw_die_ref clone
= clone_die (c
);
7621 move_all_children (c
, clone
);
7623 /* If the original has a DW_AT_object_pointer attribute,
7624 it would now point to a child DIE just moved to the
7625 cloned tree, so we need to remove that attribute from
7627 remove_AT (c
, DW_AT_object_pointer
);
7629 replace_child (c
, clone
, prev
);
7630 generate_skeleton_ancestor_tree (parent
);
7631 add_child_die (parent
->new_die
, c
);
7636 generate_skeleton_bottom_up (&node
);
7637 } while (next
!= NULL
);
7640 /* Wrapper function for generate_skeleton_bottom_up. */
7643 generate_skeleton (dw_die_ref die
)
7645 skeleton_chain_node node
;
7648 node
.new_die
= NULL
;
7651 /* If this type definition is nested inside another type,
7652 and is not an instantiation of a template, always leave
7653 at least a declaration in its place. */
7654 if (die
->die_parent
!= NULL
7655 && is_type_die (die
->die_parent
)
7656 && !is_template_instantiation (die
))
7657 node
.new_die
= clone_as_declaration (die
);
7659 generate_skeleton_bottom_up (&node
);
7660 return node
.new_die
;
7663 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7664 declaration. The original DIE is moved to a new compile unit so that
7665 existing references to it follow it to the new location. If any of the
7666 original DIE's descendants is a declaration, we need to replace the
7667 original DIE with a skeleton tree and move the declarations back into the
7671 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7674 dw_die_ref skeleton
, orig_parent
;
7676 /* Copy the declaration context to the type unit DIE. If the returned
7677 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7679 orig_parent
= copy_declaration_context (unit
, child
);
7681 skeleton
= generate_skeleton (child
);
7682 if (skeleton
== NULL
)
7683 remove_child_with_prev (child
, prev
);
7686 skeleton
->comdat_type_p
= true;
7687 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7689 /* If the original DIE was a specification, we need to put
7690 the skeleton under the parent DIE of the declaration.
7691 This leaves the original declaration in the tree, but
7692 it will be pruned later since there are no longer any
7693 references to it. */
7694 if (orig_parent
!= NULL
)
7696 remove_child_with_prev (child
, prev
);
7697 add_child_die (orig_parent
, skeleton
);
7700 replace_child (child
, skeleton
, prev
);
7707 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
7708 comdat_type_node
*type_node
,
7709 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
7711 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
7712 procedure, put it under TYPE_NODE and return the copy. Continue looking for
7713 DWARF procedure references in the DW_AT_location attribute. */
7716 copy_dwarf_procedure (dw_die_ref die
,
7717 comdat_type_node
*type_node
,
7718 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
7720 /* We do this for COMDAT section, which is DWARFv4 specific, so
7721 DWARF procedure are always DW_TAG_dwarf_procedure DIEs (unlike
7722 DW_TAG_variable in DWARFv3). */
7723 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
7725 /* DWARF procedures are not supposed to have children... */
7726 gcc_assert (die
->die_child
== NULL
);
7728 /* ... and they are supposed to have only one attribute: DW_AT_location. */
7729 gcc_assert (vec_safe_length (die
->die_attr
) == 1
7730 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
7732 /* Do not copy more than once DWARF procedures. */
7734 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
7738 die_copy
= clone_die (die
);
7739 add_child_die (type_node
->root_die
, die_copy
);
7740 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
7744 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
7745 procedures in DIE's attributes. */
7748 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
7749 comdat_type_node
*type_node
,
7750 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
7755 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
7757 dw_loc_descr_ref loc
;
7759 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
7762 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
7764 switch (loc
->dw_loc_opc
)
7768 case DW_OP_call_ref
:
7769 gcc_assert (loc
->dw_loc_oprnd1
.val_class
7770 == dw_val_class_die_ref
);
7771 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
7772 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
7774 copied_dwarf_procs
);
7783 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
7784 rewrite references to point to the copies.
7786 References are looked for in DIE's attributes and recursively in all its
7787 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
7788 mapping from old DWARF procedures to their copy. It is used not to copy
7789 twice the same DWARF procedure under TYPE_NODE. */
7792 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
7793 comdat_type_node
*type_node
,
7794 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
7798 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
7799 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
7801 copied_dwarf_procs
));
7804 /* Traverse the DIE and set up additional .debug_types sections for each
7805 type worthy of being placed in a COMDAT section. */
7808 break_out_comdat_types (dw_die_ref die
)
7812 dw_die_ref prev
= NULL
;
7813 dw_die_ref next
= NULL
;
7814 dw_die_ref unit
= NULL
;
7816 first
= c
= die
->die_child
;
7820 if (prev
== NULL
|| prev
->die_sib
== c
)
7823 next
= (c
== first
? NULL
: c
->die_sib
);
7824 if (should_move_die_to_comdat (c
))
7826 dw_die_ref replacement
;
7827 comdat_type_node
*type_node
;
7829 /* Break out nested types into their own type units. */
7830 break_out_comdat_types (c
);
7832 /* Create a new type unit DIE as the root for the new tree, and
7833 add it to the list of comdat types. */
7834 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7835 add_AT_unsigned (unit
, DW_AT_language
,
7836 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7837 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
7838 type_node
->root_die
= unit
;
7839 type_node
->next
= comdat_type_list
;
7840 comdat_type_list
= type_node
;
7842 /* Generate the type signature. */
7843 generate_type_signature (c
, type_node
);
7845 /* Copy the declaration context, attributes, and children of the
7846 declaration into the new type unit DIE, then remove this DIE
7847 from the main CU (or replace it with a skeleton if necessary). */
7848 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7849 type_node
->skeleton_die
= replacement
;
7851 /* Add the DIE to the new compunit. */
7852 add_child_die (unit
, c
);
7854 /* Types can reference DWARF procedures for type size or data location
7855 expressions. Calls in DWARF expressions cannot target procedures
7856 that are not in the same section. So we must copy DWARF procedures
7857 along with this type and then rewrite references to them. */
7858 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
7859 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
7861 if (replacement
!= NULL
)
7864 else if (c
->die_tag
== DW_TAG_namespace
7865 || c
->die_tag
== DW_TAG_class_type
7866 || c
->die_tag
== DW_TAG_structure_type
7867 || c
->die_tag
== DW_TAG_union_type
)
7869 /* Look for nested types that can be broken out. */
7870 break_out_comdat_types (c
);
7872 } while (next
!= NULL
);
7875 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7876 Enter all the cloned children into the hash table decl_table. */
7879 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
7883 struct decl_table_entry
*entry
;
7884 decl_table_entry
**slot
;
7886 if (die
->die_tag
== DW_TAG_subprogram
)
7887 clone
= clone_as_declaration (die
);
7889 clone
= clone_die (die
);
7891 slot
= decl_table
->find_slot_with_hash (die
,
7892 htab_hash_pointer (die
), INSERT
);
7894 /* Assert that DIE isn't in the hash table yet. If it would be there
7895 before, the ancestors would be necessarily there as well, therefore
7896 clone_tree_partial wouldn't be called. */
7897 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7899 entry
= XCNEW (struct decl_table_entry
);
7901 entry
->copy
= clone
;
7904 if (die
->die_tag
!= DW_TAG_subprogram
)
7905 FOR_EACH_CHILD (die
, c
,
7906 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7911 /* Walk the DIE and its children, looking for references to incomplete
7912 or trivial types that are unmarked (i.e., that are not in the current
7916 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
7922 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7924 if (AT_class (a
) == dw_val_class_die_ref
)
7926 dw_die_ref targ
= AT_ref (a
);
7927 decl_table_entry
**slot
;
7928 struct decl_table_entry
*entry
;
7930 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7933 slot
= decl_table
->find_slot_with_hash (targ
,
7934 htab_hash_pointer (targ
),
7937 if (*slot
!= HTAB_EMPTY_ENTRY
)
7939 /* TARG has already been copied, so we just need to
7940 modify the reference to point to the copy. */
7942 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7946 dw_die_ref parent
= unit
;
7947 dw_die_ref copy
= clone_die (targ
);
7949 /* Record in DECL_TABLE that TARG has been copied.
7950 Need to do this now, before the recursive call,
7951 because DECL_TABLE may be expanded and SLOT
7952 would no longer be a valid pointer. */
7953 entry
= XCNEW (struct decl_table_entry
);
7958 /* If TARG is not a declaration DIE, we need to copy its
7960 if (!is_declaration_die (targ
))
7964 add_child_die (copy
,
7965 clone_tree_partial (c
, decl_table
)));
7968 /* Make sure the cloned tree is marked as part of the
7972 /* If TARG has surrounding context, copy its ancestor tree
7973 into the new type unit. */
7974 if (targ
->die_parent
!= NULL
7975 && !is_unit_die (targ
->die_parent
))
7976 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7979 add_child_die (parent
, copy
);
7980 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7982 /* Make sure the newly-copied DIE is walked. If it was
7983 installed in a previously-added context, it won't
7984 get visited otherwise. */
7987 /* Find the highest point of the newly-added tree,
7988 mark each node along the way, and walk from there. */
7989 parent
->die_mark
= 1;
7990 while (parent
->die_parent
7991 && parent
->die_parent
->die_mark
== 0)
7993 parent
= parent
->die_parent
;
7994 parent
->die_mark
= 1;
7996 copy_decls_walk (unit
, parent
, decl_table
);
8002 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8005 /* Copy declarations for "unworthy" types into the new comdat section.
8006 Incomplete types, modified types, and certain other types aren't broken
8007 out into comdat sections of their own, so they don't have a signature,
8008 and we need to copy the declaration into the same section so that we
8009 don't have an external reference. */
8012 copy_decls_for_unworthy_types (dw_die_ref unit
)
8015 decl_hash_type
decl_table (10);
8016 copy_decls_walk (unit
, unit
, &decl_table
);
8020 /* Traverse the DIE and add a sibling attribute if it may have the
8021 effect of speeding up access to siblings. To save some space,
8022 avoid generating sibling attributes for DIE's without children. */
8025 add_sibling_attributes (dw_die_ref die
)
8029 if (! die
->die_child
)
8032 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8033 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8035 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8038 /* Output all location lists for the DIE and its children. */
8041 output_location_lists (dw_die_ref die
)
8047 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8048 if (AT_class (a
) == dw_val_class_loc_list
)
8049 output_loc_list (AT_loc_list (a
));
8051 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
8054 /* We want to limit the number of external references, because they are
8055 larger than local references: a relocation takes multiple words, and
8056 even a sig8 reference is always eight bytes, whereas a local reference
8057 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8058 So if we encounter multiple external references to the same type DIE, we
8059 make a local typedef stub for it and redirect all references there.
8061 This is the element of the hash table for keeping track of these
8071 /* Hashtable helpers. */
8073 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
8075 static inline hashval_t
hash (const external_ref
*);
8076 static inline bool equal (const external_ref
*, const external_ref
*);
8080 external_ref_hasher::hash (const external_ref
*r
)
8082 dw_die_ref die
= r
->type
;
8085 /* We can't use the address of the DIE for hashing, because
8086 that will make the order of the stub DIEs non-deterministic. */
8087 if (! die
->comdat_type_p
)
8088 /* We have a symbol; use it to compute a hash. */
8089 h
= htab_hash_string (die
->die_id
.die_symbol
);
8092 /* We have a type signature; use a subset of the bits as the hash.
8093 The 8-byte signature is at least as large as hashval_t. */
8094 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
8095 memcpy (&h
, type_node
->signature
, sizeof (h
));
8101 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
8103 return r1
->type
== r2
->type
;
8106 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
8108 /* Return a pointer to the external_ref for references to DIE. */
8110 static struct external_ref
*
8111 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
8113 struct external_ref ref
, *ref_p
;
8114 external_ref
**slot
;
8117 slot
= map
->find_slot (&ref
, INSERT
);
8118 if (*slot
!= HTAB_EMPTY_ENTRY
)
8121 ref_p
= XCNEW (struct external_ref
);
8127 /* Subroutine of optimize_external_refs, below.
8129 If we see a type skeleton, record it as our stub. If we see external
8130 references, remember how many we've seen. */
8133 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
8138 struct external_ref
*ref_p
;
8140 if (is_type_die (die
)
8141 && (c
= get_AT_ref (die
, DW_AT_signature
)))
8143 /* This is a local skeleton; use it for local references. */
8144 ref_p
= lookup_external_ref (map
, c
);
8148 /* Scan the DIE references, and remember any that refer to DIEs from
8149 other CUs (i.e. those which are not marked). */
8150 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8151 if (AT_class (a
) == dw_val_class_die_ref
8152 && (c
= AT_ref (a
))->die_mark
== 0
8155 ref_p
= lookup_external_ref (map
, c
);
8159 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
8162 /* htab_traverse callback function for optimize_external_refs, below. SLOT
8163 points to an external_ref, DATA is the CU we're processing. If we don't
8164 already have a local stub, and we have multiple refs, build a stub. */
8167 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
8169 struct external_ref
*ref_p
= *slot
;
8171 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
8173 /* We have multiple references to this type, so build a small stub.
8174 Both of these forms are a bit dodgy from the perspective of the
8175 DWARF standard, since technically they should have names. */
8176 dw_die_ref cu
= data
;
8177 dw_die_ref type
= ref_p
->type
;
8178 dw_die_ref stub
= NULL
;
8180 if (type
->comdat_type_p
)
8182 /* If we refer to this type via sig8, use AT_signature. */
8183 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
8184 add_AT_die_ref (stub
, DW_AT_signature
, type
);
8188 /* Otherwise, use a typedef with no name. */
8189 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
8190 add_AT_die_ref (stub
, DW_AT_type
, type
);
8199 /* DIE is a unit; look through all the DIE references to see if there are
8200 any external references to types, and if so, create local stubs for
8201 them which will be applied in build_abbrev_table. This is useful because
8202 references to local DIEs are smaller. */
8204 static external_ref_hash_type
*
8205 optimize_external_refs (dw_die_ref die
)
8207 external_ref_hash_type
*map
= new external_ref_hash_type (10);
8208 optimize_external_refs_1 (die
, map
);
8209 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
8213 /* The format of each DIE (and its attribute value pairs) is encoded in an
8214 abbreviation table. This routine builds the abbreviation table and assigns
8215 a unique abbreviation id for each abbreviation entry. The children of each
8216 die are visited recursively. */
8219 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
8221 unsigned long abbrev_id
;
8222 unsigned int n_alloc
;
8227 /* Scan the DIE references, and replace any that refer to
8228 DIEs from other CUs (i.e. those which are not marked) with
8229 the local stubs we built in optimize_external_refs. */
8230 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8231 if (AT_class (a
) == dw_val_class_die_ref
8232 && (c
= AT_ref (a
))->die_mark
== 0)
8234 struct external_ref
*ref_p
;
8235 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8237 ref_p
= lookup_external_ref (extern_map
, c
);
8238 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8239 change_AT_die_ref (a
, ref_p
->stub
);
8241 /* We aren't changing this reference, so mark it external. */
8242 set_AT_ref_external (a
, 1);
8245 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8247 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
8248 dw_attr_node
*die_a
, *abbrev_a
;
8252 if (abbrev
->die_tag
!= die
->die_tag
)
8254 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8257 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8260 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8262 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8263 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8264 || (value_format (abbrev_a
) != value_format (die_a
)))
8274 if (abbrev_id
>= abbrev_die_table_in_use
)
8276 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
8278 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
8279 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
8282 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
8283 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
8284 abbrev_die_table_allocated
= n_alloc
;
8287 ++abbrev_die_table_in_use
;
8288 abbrev_die_table
[abbrev_id
] = die
;
8291 die
->die_abbrev
= abbrev_id
;
8292 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8295 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8298 constant_size (unsigned HOST_WIDE_INT value
)
8305 log
= floor_log2 (value
);
8308 log
= 1 << (floor_log2 (log
) + 1);
8313 /* Return the size of a DIE as it is represented in the
8314 .debug_info section. */
8316 static unsigned long
8317 size_of_die (dw_die_ref die
)
8319 unsigned long size
= 0;
8322 enum dwarf_form form
;
8324 size
+= size_of_uleb128 (die
->die_abbrev
);
8325 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8327 switch (AT_class (a
))
8329 case dw_val_class_addr
:
8330 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8332 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8333 size
+= size_of_uleb128 (AT_index (a
));
8336 size
+= DWARF2_ADDR_SIZE
;
8338 case dw_val_class_offset
:
8339 size
+= DWARF_OFFSET_SIZE
;
8341 case dw_val_class_loc
:
8343 unsigned long lsize
= size_of_locs (AT_loc (a
));
8346 if (dwarf_version
>= 4)
8347 size
+= size_of_uleb128 (lsize
);
8349 size
+= constant_size (lsize
);
8353 case dw_val_class_loc_list
:
8354 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8356 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8357 size
+= size_of_uleb128 (AT_index (a
));
8360 size
+= DWARF_OFFSET_SIZE
;
8362 case dw_val_class_range_list
:
8363 size
+= DWARF_OFFSET_SIZE
;
8365 case dw_val_class_const
:
8366 size
+= size_of_sleb128 (AT_int (a
));
8368 case dw_val_class_unsigned_const
:
8370 int csize
= constant_size (AT_unsigned (a
));
8371 if (dwarf_version
== 3
8372 && a
->dw_attr
== DW_AT_data_member_location
8374 size
+= size_of_uleb128 (AT_unsigned (a
));
8379 case dw_val_class_const_double
:
8380 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
8381 if (HOST_BITS_PER_WIDE_INT
>= 64)
8384 case dw_val_class_wide_int
:
8385 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8386 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
8387 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
8391 case dw_val_class_vec
:
8392 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
8393 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
8394 + a
->dw_attr_val
.v
.val_vec
.length
8395 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
8397 case dw_val_class_flag
:
8398 if (dwarf_version
>= 4)
8399 /* Currently all add_AT_flag calls pass in 1 as last argument,
8400 so DW_FORM_flag_present can be used. If that ever changes,
8401 we'll need to use DW_FORM_flag and have some optimization
8402 in build_abbrev_table that will change those to
8403 DW_FORM_flag_present if it is set to 1 in all DIEs using
8404 the same abbrev entry. */
8405 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8409 case dw_val_class_die_ref
:
8410 if (AT_ref_external (a
))
8412 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8413 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8414 is sized by target address length, whereas in DWARF3
8415 it's always sized as an offset. */
8416 if (use_debug_types
)
8417 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
8418 else if (dwarf_version
== 2)
8419 size
+= DWARF2_ADDR_SIZE
;
8421 size
+= DWARF_OFFSET_SIZE
;
8424 size
+= DWARF_OFFSET_SIZE
;
8426 case dw_val_class_fde_ref
:
8427 size
+= DWARF_OFFSET_SIZE
;
8429 case dw_val_class_lbl_id
:
8430 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8432 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8433 size
+= size_of_uleb128 (AT_index (a
));
8436 size
+= DWARF2_ADDR_SIZE
;
8438 case dw_val_class_lineptr
:
8439 case dw_val_class_macptr
:
8440 size
+= DWARF_OFFSET_SIZE
;
8442 case dw_val_class_str
:
8443 form
= AT_string_form (a
);
8444 if (form
== DW_FORM_strp
)
8445 size
+= DWARF_OFFSET_SIZE
;
8446 else if (form
== DW_FORM_GNU_str_index
)
8447 size
+= size_of_uleb128 (AT_index (a
));
8449 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
8451 case dw_val_class_file
:
8452 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
8454 case dw_val_class_data8
:
8457 case dw_val_class_vms_delta
:
8458 size
+= DWARF_OFFSET_SIZE
;
8460 case dw_val_class_high_pc
:
8461 size
+= DWARF2_ADDR_SIZE
;
8463 case dw_val_class_discr_value
:
8464 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
8466 case dw_val_class_discr_list
:
8468 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
8470 /* This is a block, so we have the block length and then its
8472 size
+= constant_size (block_size
) + block_size
;
8483 /* Size the debugging information associated with a given DIE. Visits the
8484 DIE's children recursively. Updates the global variable next_die_offset, on
8485 each time through. Uses the current value of next_die_offset to update the
8486 die_offset field in each DIE. */
8489 calc_die_sizes (dw_die_ref die
)
8493 gcc_assert (die
->die_offset
== 0
8494 || (unsigned long int) die
->die_offset
== next_die_offset
);
8495 die
->die_offset
= next_die_offset
;
8496 next_die_offset
+= size_of_die (die
);
8498 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
8500 if (die
->die_child
!= NULL
)
8501 /* Count the null byte used to terminate sibling lists. */
8502 next_die_offset
+= 1;
8505 /* Size just the base type children at the start of the CU.
8506 This is needed because build_abbrev needs to size locs
8507 and sizing of type based stack ops needs to know die_offset
8508 values for the base types. */
8511 calc_base_type_die_sizes (void)
8513 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8515 dw_die_ref base_type
;
8516 #if ENABLE_ASSERT_CHECKING
8517 dw_die_ref prev
= comp_unit_die ()->die_child
;
8520 die_offset
+= size_of_die (comp_unit_die ());
8521 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
8523 #if ENABLE_ASSERT_CHECKING
8524 gcc_assert (base_type
->die_offset
== 0
8525 && prev
->die_sib
== base_type
8526 && base_type
->die_child
== NULL
8527 && base_type
->die_abbrev
);
8530 base_type
->die_offset
= die_offset
;
8531 die_offset
+= size_of_die (base_type
);
8535 /* Set the marks for a die and its children. We do this so
8536 that we know whether or not a reference needs to use FORM_ref_addr; only
8537 DIEs in the same CU will be marked. We used to clear out the offset
8538 and use that as the flag, but ran into ordering problems. */
8541 mark_dies (dw_die_ref die
)
8545 gcc_assert (!die
->die_mark
);
8548 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8551 /* Clear the marks for a die and its children. */
8554 unmark_dies (dw_die_ref die
)
8558 if (! use_debug_types
)
8559 gcc_assert (die
->die_mark
);
8562 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8565 /* Clear the marks for a die, its children and referred dies. */
8568 unmark_all_dies (dw_die_ref die
)
8578 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8580 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8581 if (AT_class (a
) == dw_val_class_die_ref
)
8582 unmark_all_dies (AT_ref (a
));
8585 /* Calculate if the entry should appear in the final output file. It may be
8586 from a pruned a type. */
8589 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8591 /* By limiting gnu pubnames to definitions only, gold can generate a
8592 gdb index without entries for declarations, which don't include
8593 enough information to be useful. */
8594 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8597 if (table
== pubname_table
)
8599 /* Enumerator names are part of the pubname table, but the
8600 parent DW_TAG_enumeration_type die may have been pruned.
8601 Don't output them if that is the case. */
8602 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8603 (p
->die
->die_parent
== NULL
8604 || !p
->die
->die_parent
->die_perennial_p
))
8607 /* Everything else in the pubname table is included. */
8611 /* The pubtypes table shouldn't include types that have been
8613 return (p
->die
->die_offset
!= 0
8614 || !flag_eliminate_unused_debug_types
);
8617 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8618 generated for the compilation unit. */
8620 static unsigned long
8621 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8626 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8628 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8629 FOR_EACH_VEC_ELT (*names
, i
, p
)
8630 if (include_pubname_in_output (names
, p
))
8631 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8633 size
+= DWARF_OFFSET_SIZE
;
8637 /* Return the size of the information in the .debug_aranges section. */
8639 static unsigned long
8640 size_of_aranges (void)
8644 size
= DWARF_ARANGES_HEADER_SIZE
;
8646 /* Count the address/length pair for this compilation unit. */
8647 if (text_section_used
)
8648 size
+= 2 * DWARF2_ADDR_SIZE
;
8649 if (cold_text_section_used
)
8650 size
+= 2 * DWARF2_ADDR_SIZE
;
8651 if (have_multiple_function_sections
)
8656 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8658 if (DECL_IGNORED_P (fde
->decl
))
8660 if (!fde
->in_std_section
)
8661 size
+= 2 * DWARF2_ADDR_SIZE
;
8662 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8663 size
+= 2 * DWARF2_ADDR_SIZE
;
8667 /* Count the two zero words used to terminated the address range table. */
8668 size
+= 2 * DWARF2_ADDR_SIZE
;
8672 /* Select the encoding of an attribute value. */
8674 static enum dwarf_form
8675 value_format (dw_attr_node
*a
)
8677 switch (AT_class (a
))
8679 case dw_val_class_addr
:
8680 /* Only very few attributes allow DW_FORM_addr. */
8685 case DW_AT_entry_pc
:
8686 case DW_AT_trampoline
:
8687 return (AT_index (a
) == NOT_INDEXED
8688 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8692 switch (DWARF2_ADDR_SIZE
)
8695 return DW_FORM_data1
;
8697 return DW_FORM_data2
;
8699 return DW_FORM_data4
;
8701 return DW_FORM_data8
;
8705 case dw_val_class_range_list
:
8706 case dw_val_class_loc_list
:
8707 if (dwarf_version
>= 4)
8708 return DW_FORM_sec_offset
;
8710 case dw_val_class_vms_delta
:
8711 case dw_val_class_offset
:
8712 switch (DWARF_OFFSET_SIZE
)
8715 return DW_FORM_data4
;
8717 return DW_FORM_data8
;
8721 case dw_val_class_loc
:
8722 if (dwarf_version
>= 4)
8723 return DW_FORM_exprloc
;
8724 switch (constant_size (size_of_locs (AT_loc (a
))))
8727 return DW_FORM_block1
;
8729 return DW_FORM_block2
;
8731 return DW_FORM_block4
;
8735 case dw_val_class_const
:
8736 return DW_FORM_sdata
;
8737 case dw_val_class_unsigned_const
:
8738 switch (constant_size (AT_unsigned (a
)))
8741 return DW_FORM_data1
;
8743 return DW_FORM_data2
;
8745 /* In DWARF3 DW_AT_data_member_location with
8746 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8747 constant, so we need to use DW_FORM_udata if we need
8748 a large constant. */
8749 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8750 return DW_FORM_udata
;
8751 return DW_FORM_data4
;
8753 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8754 return DW_FORM_udata
;
8755 return DW_FORM_data8
;
8759 case dw_val_class_const_double
:
8760 switch (HOST_BITS_PER_WIDE_INT
)
8763 return DW_FORM_data2
;
8765 return DW_FORM_data4
;
8767 return DW_FORM_data8
;
8770 return DW_FORM_block1
;
8772 case dw_val_class_wide_int
:
8773 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
8776 return DW_FORM_data1
;
8778 return DW_FORM_data2
;
8780 return DW_FORM_data4
;
8782 return DW_FORM_data8
;
8784 return DW_FORM_block1
;
8786 case dw_val_class_vec
:
8787 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8788 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8791 return DW_FORM_block1
;
8793 return DW_FORM_block2
;
8795 return DW_FORM_block4
;
8799 case dw_val_class_flag
:
8800 if (dwarf_version
>= 4)
8802 /* Currently all add_AT_flag calls pass in 1 as last argument,
8803 so DW_FORM_flag_present can be used. If that ever changes,
8804 we'll need to use DW_FORM_flag and have some optimization
8805 in build_abbrev_table that will change those to
8806 DW_FORM_flag_present if it is set to 1 in all DIEs using
8807 the same abbrev entry. */
8808 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8809 return DW_FORM_flag_present
;
8811 return DW_FORM_flag
;
8812 case dw_val_class_die_ref
:
8813 if (AT_ref_external (a
))
8814 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8817 case dw_val_class_fde_ref
:
8818 return DW_FORM_data
;
8819 case dw_val_class_lbl_id
:
8820 return (AT_index (a
) == NOT_INDEXED
8821 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8822 case dw_val_class_lineptr
:
8823 case dw_val_class_macptr
:
8824 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8825 case dw_val_class_str
:
8826 return AT_string_form (a
);
8827 case dw_val_class_file
:
8828 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8831 return DW_FORM_data1
;
8833 return DW_FORM_data2
;
8835 return DW_FORM_data4
;
8840 case dw_val_class_data8
:
8841 return DW_FORM_data8
;
8843 case dw_val_class_high_pc
:
8844 switch (DWARF2_ADDR_SIZE
)
8847 return DW_FORM_data1
;
8849 return DW_FORM_data2
;
8851 return DW_FORM_data4
;
8853 return DW_FORM_data8
;
8858 case dw_val_class_discr_value
:
8859 return (a
->dw_attr_val
.v
.val_discr_value
.pos
8862 case dw_val_class_discr_list
:
8863 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
8866 return DW_FORM_block1
;
8868 return DW_FORM_block2
;
8870 return DW_FORM_block4
;
8880 /* Output the encoding of an attribute value. */
8883 output_value_format (dw_attr_node
*a
)
8885 enum dwarf_form form
= value_format (a
);
8887 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8890 /* Given a die and id, produce the appropriate abbreviations. */
8893 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8896 dw_attr_node
*a_attr
;
8898 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8899 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8900 dwarf_tag_name (abbrev
->die_tag
));
8902 if (abbrev
->die_child
!= NULL
)
8903 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8905 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8907 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8909 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8910 dwarf_attr_name (a_attr
->dw_attr
));
8911 output_value_format (a_attr
);
8914 dw2_asm_output_data (1, 0, NULL
);
8915 dw2_asm_output_data (1, 0, NULL
);
8919 /* Output the .debug_abbrev section which defines the DIE abbreviation
8923 output_abbrev_section (void)
8925 unsigned long abbrev_id
;
8927 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8928 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8930 /* Terminate the table. */
8931 dw2_asm_output_data (1, 0, NULL
);
8934 /* Output a symbol we can use to refer to this DIE from another CU. */
8937 output_die_symbol (dw_die_ref die
)
8939 const char *sym
= die
->die_id
.die_symbol
;
8941 gcc_assert (!die
->comdat_type_p
);
8946 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8947 /* We make these global, not weak; if the target doesn't support
8948 .linkonce, it doesn't support combining the sections, so debugging
8950 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8952 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8955 /* Return a new location list, given the begin and end range, and the
8958 static inline dw_loc_list_ref
8959 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8960 const char *section
)
8962 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
8964 retlist
->begin
= begin
;
8965 retlist
->begin_entry
= NULL
;
8967 retlist
->expr
= expr
;
8968 retlist
->section
= section
;
8973 /* Generate a new internal symbol for this location list node, if it
8974 hasn't got one yet. */
8977 gen_llsym (dw_loc_list_ref list
)
8979 gcc_assert (!list
->ll_symbol
);
8980 list
->ll_symbol
= gen_internal_sym ("LLST");
8983 /* Output the location list given to us. */
8986 output_loc_list (dw_loc_list_ref list_head
)
8988 dw_loc_list_ref curr
= list_head
;
8990 if (list_head
->emitted
)
8992 list_head
->emitted
= true;
8994 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8996 /* Walk the location list, and output each range + expression. */
8997 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
9000 /* Don't output an entry that starts and ends at the same address. */
9001 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
9003 size
= size_of_locs (curr
->expr
);
9004 /* If the expression is too large, drop it on the floor. We could
9005 perhaps put it into DW_TAG_dwarf_procedure and refer to that
9006 in the expression, but >= 64KB expressions for a single value
9007 in a single range are unlikely very useful. */
9010 if (dwarf_split_debug_info
)
9012 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
9013 "Location list start/length entry (%s)",
9014 list_head
->ll_symbol
);
9015 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9016 "Location list range start index (%s)",
9018 /* The length field is 4 bytes. If we ever need to support
9019 an 8-byte length, we can add a new DW_LLE code or fall back
9020 to DW_LLE_GNU_start_end_entry. */
9021 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
9022 "Location list range length (%s)",
9023 list_head
->ll_symbol
);
9025 else if (!have_multiple_function_sections
)
9027 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
9028 "Location list begin address (%s)",
9029 list_head
->ll_symbol
);
9030 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
9031 "Location list end address (%s)",
9032 list_head
->ll_symbol
);
9036 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9037 "Location list begin address (%s)",
9038 list_head
->ll_symbol
);
9039 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9040 "Location list end address (%s)",
9041 list_head
->ll_symbol
);
9044 /* Output the block length for this list of location operations. */
9045 gcc_assert (size
<= 0xffff);
9046 dw2_asm_output_data (2, size
, "%s", "Location expression size");
9048 output_loc_sequence (curr
->expr
, -1);
9051 if (dwarf_split_debug_info
)
9052 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
9053 "Location list terminator (%s)",
9054 list_head
->ll_symbol
);
9057 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9058 "Location list terminator begin (%s)",
9059 list_head
->ll_symbol
);
9060 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9061 "Location list terminator end (%s)",
9062 list_head
->ll_symbol
);
9066 /* Output a range_list offset into the debug_range section. Emit a
9067 relocated reference if val_entry is NULL, otherwise, emit an
9068 indirect reference. */
9071 output_range_list_offset (dw_attr_node
*a
)
9073 const char *name
= dwarf_attr_name (a
->dw_attr
);
9075 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
9077 char *p
= strchr (ranges_section_label
, '\0');
9078 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
9079 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
9080 debug_ranges_section
, "%s", name
);
9084 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
9085 "%s (offset from %s)", name
, ranges_section_label
);
9088 /* Output the offset into the debug_loc section. */
9091 output_loc_list_offset (dw_attr_node
*a
)
9093 char *sym
= AT_loc_list (a
)->ll_symbol
;
9096 if (dwarf_split_debug_info
)
9097 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
9098 "%s", dwarf_attr_name (a
->dw_attr
));
9100 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
9101 "%s", dwarf_attr_name (a
->dw_attr
));
9104 /* Output an attribute's index or value appropriately. */
9107 output_attr_index_or_value (dw_attr_node
*a
)
9109 const char *name
= dwarf_attr_name (a
->dw_attr
);
9111 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9113 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
9116 switch (AT_class (a
))
9118 case dw_val_class_addr
:
9119 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
9121 case dw_val_class_high_pc
:
9122 case dw_val_class_lbl_id
:
9123 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
9125 case dw_val_class_loc_list
:
9126 output_loc_list_offset (a
);
9133 /* Output a type signature. */
9136 output_signature (const char *sig
, const char *name
)
9140 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9141 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
9144 /* Output a discriminant value. */
9147 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
9149 if (discr_value
->pos
)
9150 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
9152 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
9155 /* Output the DIE and its attributes. Called recursively to generate
9156 the definitions of each child DIE. */
9159 output_die (dw_die_ref die
)
9166 /* If someone in another CU might refer to us, set up a symbol for
9167 them to point to. */
9168 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
9169 output_die_symbol (die
);
9171 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
9172 (unsigned long)die
->die_offset
,
9173 dwarf_tag_name (die
->die_tag
));
9175 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9177 const char *name
= dwarf_attr_name (a
->dw_attr
);
9179 switch (AT_class (a
))
9181 case dw_val_class_addr
:
9182 output_attr_index_or_value (a
);
9185 case dw_val_class_offset
:
9186 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
9190 case dw_val_class_range_list
:
9191 output_range_list_offset (a
);
9194 case dw_val_class_loc
:
9195 size
= size_of_locs (AT_loc (a
));
9197 /* Output the block length for this list of location operations. */
9198 if (dwarf_version
>= 4)
9199 dw2_asm_output_data_uleb128 (size
, "%s", name
);
9201 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
9203 output_loc_sequence (AT_loc (a
), -1);
9206 case dw_val_class_const
:
9207 /* ??? It would be slightly more efficient to use a scheme like is
9208 used for unsigned constants below, but gdb 4.x does not sign
9209 extend. Gdb 5.x does sign extend. */
9210 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
9213 case dw_val_class_unsigned_const
:
9215 int csize
= constant_size (AT_unsigned (a
));
9216 if (dwarf_version
== 3
9217 && a
->dw_attr
== DW_AT_data_member_location
9219 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
9221 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
9225 case dw_val_class_const_double
:
9227 unsigned HOST_WIDE_INT first
, second
;
9229 if (HOST_BITS_PER_WIDE_INT
>= 64)
9230 dw2_asm_output_data (1,
9231 HOST_BITS_PER_DOUBLE_INT
9232 / HOST_BITS_PER_CHAR
,
9235 if (WORDS_BIG_ENDIAN
)
9237 first
= a
->dw_attr_val
.v
.val_double
.high
;
9238 second
= a
->dw_attr_val
.v
.val_double
.low
;
9242 first
= a
->dw_attr_val
.v
.val_double
.low
;
9243 second
= a
->dw_attr_val
.v
.val_double
.high
;
9246 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
9248 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
9253 case dw_val_class_wide_int
:
9256 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
9257 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
9258 if (len
* HOST_BITS_PER_WIDE_INT
> 64)
9259 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
) * l
,
9262 if (WORDS_BIG_ENDIAN
)
9263 for (i
= len
- 1; i
>= 0; --i
)
9265 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
9270 for (i
= 0; i
< len
; ++i
)
9272 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
9279 case dw_val_class_vec
:
9281 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
9282 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
9286 dw2_asm_output_data (constant_size (len
* elt_size
),
9287 len
* elt_size
, "%s", name
);
9288 if (elt_size
> sizeof (HOST_WIDE_INT
))
9293 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
9296 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
9297 "fp or vector constant word %u", i
);
9301 case dw_val_class_flag
:
9302 if (dwarf_version
>= 4)
9304 /* Currently all add_AT_flag calls pass in 1 as last argument,
9305 so DW_FORM_flag_present can be used. If that ever changes,
9306 we'll need to use DW_FORM_flag and have some optimization
9307 in build_abbrev_table that will change those to
9308 DW_FORM_flag_present if it is set to 1 in all DIEs using
9309 the same abbrev entry. */
9310 gcc_assert (AT_flag (a
) == 1);
9312 fprintf (asm_out_file
, "\t\t\t%s %s\n",
9313 ASM_COMMENT_START
, name
);
9316 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
9319 case dw_val_class_loc_list
:
9320 output_attr_index_or_value (a
);
9323 case dw_val_class_die_ref
:
9324 if (AT_ref_external (a
))
9326 if (AT_ref (a
)->comdat_type_p
)
9328 comdat_type_node
*type_node
=
9329 AT_ref (a
)->die_id
.die_type_node
;
9331 gcc_assert (type_node
);
9332 output_signature (type_node
->signature
, name
);
9336 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
9340 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9341 length, whereas in DWARF3 it's always sized as an
9343 if (dwarf_version
== 2)
9344 size
= DWARF2_ADDR_SIZE
;
9346 size
= DWARF_OFFSET_SIZE
;
9347 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
9353 gcc_assert (AT_ref (a
)->die_offset
);
9354 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
9359 case dw_val_class_fde_ref
:
9363 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
9364 a
->dw_attr_val
.v
.val_fde_index
* 2);
9365 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
9370 case dw_val_class_vms_delta
:
9371 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
9372 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
9373 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9376 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
9377 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9382 case dw_val_class_lbl_id
:
9383 output_attr_index_or_value (a
);
9386 case dw_val_class_lineptr
:
9387 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9388 debug_line_section
, "%s", name
);
9391 case dw_val_class_macptr
:
9392 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9393 debug_macinfo_section
, "%s", name
);
9396 case dw_val_class_str
:
9397 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
9398 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9399 a
->dw_attr_val
.v
.val_str
->label
,
9401 "%s: \"%s\"", name
, AT_string (a
));
9402 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
9403 dw2_asm_output_data_uleb128 (AT_index (a
),
9404 "%s: \"%s\"", name
, AT_string (a
));
9406 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
9409 case dw_val_class_file
:
9411 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
9413 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
9414 a
->dw_attr_val
.v
.val_file
->filename
);
9418 case dw_val_class_data8
:
9422 for (i
= 0; i
< 8; i
++)
9423 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
9424 i
== 0 ? "%s" : NULL
, name
);
9428 case dw_val_class_high_pc
:
9429 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
9430 get_AT_low_pc (die
), "DW_AT_high_pc");
9433 case dw_val_class_discr_value
:
9434 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
9437 case dw_val_class_discr_list
:
9439 dw_discr_list_ref list
= AT_discr_list (a
);
9440 const int size
= size_of_discr_list (list
);
9442 /* This is a block, so output its length first. */
9443 dw2_asm_output_data (constant_size (size
), size
,
9444 "%s: block size", name
);
9446 for (; list
!= NULL
; list
= list
->dw_discr_next
)
9448 /* One byte for the discriminant value descriptor, and then as
9449 many LEB128 numbers as required. */
9450 if (list
->dw_discr_range
)
9451 dw2_asm_output_data (1, DW_DSC_range
,
9452 "%s: DW_DSC_range", name
);
9454 dw2_asm_output_data (1, DW_DSC_label
,
9455 "%s: DW_DSC_label", name
);
9457 output_discr_value (&list
->dw_discr_lower_bound
, name
);
9458 if (list
->dw_discr_range
)
9459 output_discr_value (&list
->dw_discr_upper_bound
, name
);
9469 FOR_EACH_CHILD (die
, c
, output_die (c
));
9471 /* Add null byte to terminate sibling list. */
9472 if (die
->die_child
!= NULL
)
9473 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9474 (unsigned long) die
->die_offset
);
9477 /* Output the compilation unit that appears at the beginning of the
9478 .debug_info section, and precedes the DIE descriptions. */
9481 output_compilation_unit_header (void)
9483 /* We don't support actual DWARFv5 units yet, we just use some
9484 DWARFv5 draft DIE tags in DWARFv4 format. */
9485 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9487 if (!XCOFF_DEBUGGING_INFO
)
9489 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9490 dw2_asm_output_data (4, 0xffffffff,
9491 "Initial length escape value indicating 64-bit DWARF extension");
9492 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9493 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
9494 "Length of Compilation Unit Info");
9497 dw2_asm_output_data (2, ver
, "DWARF version number");
9498 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
9499 debug_abbrev_section
,
9500 "Offset Into Abbrev. Section");
9501 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9504 /* Output the compilation unit DIE and its children. */
9507 output_comp_unit (dw_die_ref die
, int output_if_empty
)
9509 const char *secname
, *oldsym
;
9512 /* Unless we are outputting main CU, we may throw away empty ones. */
9513 if (!output_if_empty
&& die
->die_child
== NULL
)
9516 /* Even if there are no children of this DIE, we must output the information
9517 about the compilation unit. Otherwise, on an empty translation unit, we
9518 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9519 will then complain when examining the file. First mark all the DIEs in
9520 this CU so we know which get local refs. */
9523 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
9525 build_abbrev_table (die
, extern_map
);
9529 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9530 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
9531 calc_die_sizes (die
);
9533 oldsym
= die
->die_id
.die_symbol
;
9536 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
9538 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
9540 die
->die_id
.die_symbol
= NULL
;
9541 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9545 switch_to_section (debug_info_section
);
9546 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
9547 info_section_emitted
= true;
9550 /* Output debugging information. */
9551 output_compilation_unit_header ();
9554 /* Leave the marks on the main CU, so we can check them in
9559 die
->die_id
.die_symbol
= oldsym
;
9563 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9564 and .debug_pubtypes. This is configured per-target, but can be
9565 overridden by the -gpubnames or -gno-pubnames options. */
9568 want_pubnames (void)
9570 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9572 if (debug_generate_pub_sections
!= -1)
9573 return debug_generate_pub_sections
;
9574 return targetm
.want_debug_pub_sections
;
9577 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9580 add_AT_pubnames (dw_die_ref die
)
9582 if (want_pubnames ())
9583 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
9586 /* Add a string attribute value to a skeleton DIE. */
9589 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9593 struct indirect_string_node
*node
;
9595 if (! skeleton_debug_str_hash
)
9596 skeleton_debug_str_hash
9597 = hash_table
<indirect_string_hasher
>::create_ggc (10);
9599 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
9600 find_string_form (node
);
9601 if (node
->form
== DW_FORM_GNU_str_index
)
9602 node
->form
= DW_FORM_strp
;
9604 attr
.dw_attr
= attr_kind
;
9605 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
9606 attr
.dw_attr_val
.val_entry
= NULL
;
9607 attr
.dw_attr_val
.v
.val_str
= node
;
9608 add_dwarf_attr (die
, &attr
);
9611 /* Helper function to generate top-level dies for skeleton debug_info and
9615 add_top_level_skeleton_die_attrs (dw_die_ref die
)
9617 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
9618 const char *comp_dir
= comp_dir_string ();
9620 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
9621 if (comp_dir
!= NULL
)
9622 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
9623 add_AT_pubnames (die
);
9624 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
9627 /* Output skeleton debug sections that point to the dwo file. */
9630 output_skeleton_debug_sections (dw_die_ref comp_unit
)
9632 /* We don't support actual DWARFv5 units yet, we just use some
9633 DWARFv5 draft DIE tags in DWARFv4 format. */
9634 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9636 /* These attributes will be found in the full debug_info section. */
9637 remove_AT (comp_unit
, DW_AT_producer
);
9638 remove_AT (comp_unit
, DW_AT_language
);
9640 switch_to_section (debug_skeleton_info_section
);
9641 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
9643 /* Produce the skeleton compilation-unit header. This one differs enough from
9644 a normal CU header that it's better not to call output_compilation_unit
9646 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9647 dw2_asm_output_data (4, 0xffffffff,
9648 "Initial length escape value indicating 64-bit DWARF extension");
9650 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9651 DWARF_COMPILE_UNIT_HEADER_SIZE
9652 - DWARF_INITIAL_LENGTH_SIZE
9653 + size_of_die (comp_unit
),
9654 "Length of Compilation Unit Info");
9655 dw2_asm_output_data (2, ver
, "DWARF version number");
9656 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
9657 debug_abbrev_section
,
9658 "Offset Into Abbrev. Section");
9659 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9661 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
9662 output_die (comp_unit
);
9664 /* Build the skeleton debug_abbrev section. */
9665 switch_to_section (debug_skeleton_abbrev_section
);
9666 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
9668 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
9670 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9673 /* Output a comdat type unit DIE and its children. */
9676 output_comdat_type_unit (comdat_type_node
*node
)
9678 const char *secname
;
9681 #if defined (OBJECT_FORMAT_ELF)
9685 /* First mark all the DIEs in this CU so we know which get local refs. */
9686 mark_dies (node
->root_die
);
9688 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
9690 build_abbrev_table (node
->root_die
, extern_map
);
9695 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9696 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9697 calc_die_sizes (node
->root_die
);
9699 #if defined (OBJECT_FORMAT_ELF)
9700 if (!dwarf_split_debug_info
)
9701 secname
= ".debug_types";
9703 secname
= ".debug_types.dwo";
9705 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9706 sprintf (tmp
, "wt.");
9707 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9708 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9709 comdat_key
= get_identifier (tmp
);
9710 targetm
.asm_out
.named_section (secname
,
9711 SECTION_DEBUG
| SECTION_LINKONCE
,
9714 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9715 sprintf (tmp
, ".gnu.linkonce.wt.");
9716 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9717 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9719 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9722 /* Output debugging information. */
9723 output_compilation_unit_header ();
9724 output_signature (node
->signature
, "Type Signature");
9725 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9726 "Offset to Type DIE");
9727 output_die (node
->root_die
);
9729 unmark_dies (node
->root_die
);
9732 /* Return the DWARF2/3 pubname associated with a decl. */
9735 dwarf2_name (tree decl
, int scope
)
9737 if (DECL_NAMELESS (decl
))
9739 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9742 /* Add a new entry to .debug_pubnames if appropriate. */
9745 add_pubname_string (const char *str
, dw_die_ref die
)
9750 e
.name
= xstrdup (str
);
9751 vec_safe_push (pubname_table
, e
);
9755 add_pubname (tree decl
, dw_die_ref die
)
9757 if (!want_pubnames ())
9760 /* Don't add items to the table when we expect that the consumer will have
9761 just read the enclosing die. For example, if the consumer is looking at a
9762 class_member, it will either be inside the class already, or will have just
9763 looked up the class to find the member. Either way, searching the class is
9764 faster than searching the index. */
9765 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9766 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9768 const char *name
= dwarf2_name (decl
, 1);
9771 add_pubname_string (name
, die
);
9775 /* Add an enumerator to the pubnames section. */
9778 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9782 gcc_assert (scope_name
);
9783 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9785 vec_safe_push (pubname_table
, e
);
9788 /* Add a new entry to .debug_pubtypes if appropriate. */
9791 add_pubtype (tree decl
, dw_die_ref die
)
9795 if (!want_pubnames ())
9798 if ((TREE_PUBLIC (decl
)
9799 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9800 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9803 const char *scope_name
= "";
9804 const char *sep
= is_cxx () ? "::" : ".";
9807 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9808 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9810 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9811 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9812 scope_name
= concat (scope_name
, sep
, NULL
);
9818 name
= type_tag (decl
);
9820 name
= lang_hooks
.dwarf_name (decl
, 1);
9822 /* If we don't have a name for the type, there's no point in adding
9824 if (name
!= NULL
&& name
[0] != '\0')
9827 e
.name
= concat (scope_name
, name
, NULL
);
9828 vec_safe_push (pubtype_table
, e
);
9831 /* Although it might be more consistent to add the pubinfo for the
9832 enumerators as their dies are created, they should only be added if the
9833 enum type meets the criteria above. So rather than re-check the parent
9834 enum type whenever an enumerator die is created, just output them all
9835 here. This isn't protected by the name conditional because anonymous
9836 enums don't have names. */
9837 if (die
->die_tag
== DW_TAG_enumeration_type
)
9841 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9846 /* Output a single entry in the pubnames table. */
9849 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9851 dw_die_ref die
= entry
->die
;
9852 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9854 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9856 if (debug_generate_pub_sections
== 2)
9858 /* This logic follows gdb's method for determining the value of the flag
9860 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9861 switch (die
->die_tag
)
9863 case DW_TAG_typedef
:
9864 case DW_TAG_base_type
:
9865 case DW_TAG_subrange_type
:
9866 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9867 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9869 case DW_TAG_enumerator
:
9870 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9871 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9872 if (!is_cxx () && !is_java ())
9873 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9875 case DW_TAG_subprogram
:
9876 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9877 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9879 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9881 case DW_TAG_constant
:
9882 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9883 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9884 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9886 case DW_TAG_variable
:
9887 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9888 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9889 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9891 case DW_TAG_namespace
:
9892 case DW_TAG_imported_declaration
:
9893 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9895 case DW_TAG_class_type
:
9896 case DW_TAG_interface_type
:
9897 case DW_TAG_structure_type
:
9898 case DW_TAG_union_type
:
9899 case DW_TAG_enumeration_type
:
9900 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9901 if (!is_cxx () && !is_java ())
9902 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9905 /* An unusual tag. Leave the flag-byte empty. */
9908 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9912 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9916 /* Output the public names table used to speed up access to externally
9917 visible names; or the public types table used to find type definitions. */
9920 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9923 unsigned long pubnames_length
= size_of_pubnames (names
);
9926 if (!XCOFF_DEBUGGING_INFO
)
9928 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9929 dw2_asm_output_data (4, 0xffffffff,
9930 "Initial length escape value indicating 64-bit DWARF extension");
9931 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9935 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9936 dw2_asm_output_data (2, 2, "DWARF Version");
9938 if (dwarf_split_debug_info
)
9939 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9940 debug_skeleton_info_section
,
9941 "Offset of Compilation Unit Info");
9943 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9945 "Offset of Compilation Unit Info");
9946 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9947 "Compilation Unit Length");
9949 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9951 if (include_pubname_in_output (names
, pub
))
9953 dw_offset die_offset
= pub
->die
->die_offset
;
9955 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9956 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9957 gcc_assert (pub
->die
->die_mark
);
9959 /* If we're putting types in their own .debug_types sections,
9960 the .debug_pubtypes table will still point to the compile
9961 unit (not the type unit), so we want to use the offset of
9962 the skeleton DIE (if there is one). */
9963 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9965 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
9967 if (type_node
!= NULL
)
9968 die_offset
= (type_node
->skeleton_die
!= NULL
9969 ? type_node
->skeleton_die
->die_offset
9970 : comp_unit_die ()->die_offset
);
9973 output_pubname (die_offset
, pub
);
9977 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9980 /* Output public names and types tables if necessary. */
9983 output_pubtables (void)
9985 if (!want_pubnames () || !info_section_emitted
)
9988 switch_to_section (debug_pubnames_section
);
9989 output_pubnames (pubname_table
);
9990 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9991 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9992 simply won't look for the section. */
9993 switch_to_section (debug_pubtypes_section
);
9994 output_pubnames (pubtype_table
);
9998 /* Output the information that goes into the .debug_aranges table.
9999 Namely, define the beginning and ending address range of the
10000 text section generated for this compilation unit. */
10003 output_aranges (void)
10006 unsigned long aranges_length
= size_of_aranges ();
10008 if (!XCOFF_DEBUGGING_INFO
)
10010 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10011 dw2_asm_output_data (4, 0xffffffff,
10012 "Initial length escape value indicating 64-bit DWARF extension");
10013 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
10014 "Length of Address Ranges Info");
10017 /* Version number for aranges is still 2, even up to DWARF5. */
10018 dw2_asm_output_data (2, 2, "DWARF Version");
10019 if (dwarf_split_debug_info
)
10020 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10021 debug_skeleton_info_section
,
10022 "Offset of Compilation Unit Info");
10024 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10025 debug_info_section
,
10026 "Offset of Compilation Unit Info");
10027 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
10028 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
10030 /* We need to align to twice the pointer size here. */
10031 if (DWARF_ARANGES_PAD_SIZE
)
10033 /* Pad using a 2 byte words so that padding is correct for any
10035 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
10036 2 * DWARF2_ADDR_SIZE
);
10037 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
10038 dw2_asm_output_data (2, 0, NULL
);
10041 /* It is necessary not to output these entries if the sections were
10042 not used; if the sections were not used, the length will be 0 and
10043 the address may end up as 0 if the section is discarded by ld
10044 --gc-sections, leaving an invalid (0, 0) entry that can be
10045 confused with the terminator. */
10046 if (text_section_used
)
10048 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
10049 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
10050 text_section_label
, "Length");
10052 if (cold_text_section_used
)
10054 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
10056 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
10057 cold_text_section_label
, "Length");
10060 if (have_multiple_function_sections
)
10065 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
10067 if (DECL_IGNORED_P (fde
->decl
))
10069 if (!fde
->in_std_section
)
10071 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
10073 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
10074 fde
->dw_fde_begin
, "Length");
10076 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
10078 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
10080 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
10081 fde
->dw_fde_second_begin
, "Length");
10086 /* Output the terminator words. */
10087 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10088 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10091 /* Add a new entry to .debug_ranges. Return the offset at which it
10094 static unsigned int
10095 add_ranges_num (int num
)
10097 unsigned int in_use
= ranges_table_in_use
;
10099 if (in_use
== ranges_table_allocated
)
10101 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
10102 ranges_table
= GGC_RESIZEVEC (dw_ranges
, ranges_table
,
10103 ranges_table_allocated
);
10104 memset (ranges_table
+ ranges_table_in_use
, 0,
10105 RANGES_TABLE_INCREMENT
* sizeof (dw_ranges
));
10108 ranges_table
[in_use
].num
= num
;
10109 ranges_table_in_use
= in_use
+ 1;
10111 return in_use
* 2 * DWARF2_ADDR_SIZE
;
10114 /* Add a new entry to .debug_ranges corresponding to a block, or a
10115 range terminator if BLOCK is NULL. */
10117 static unsigned int
10118 add_ranges (const_tree block
)
10120 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
10123 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
10124 When using dwarf_split_debug_info, address attributes in dies destined
10125 for the final executable should be direct references--setting the
10126 parameter force_direct ensures this behavior. */
10129 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
10130 bool *added
, bool force_direct
)
10132 unsigned int in_use
= ranges_by_label_in_use
;
10133 unsigned int offset
;
10135 if (in_use
== ranges_by_label_allocated
)
10137 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
10138 ranges_by_label
= GGC_RESIZEVEC (dw_ranges_by_label
, ranges_by_label
,
10139 ranges_by_label_allocated
);
10140 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
10141 RANGES_TABLE_INCREMENT
* sizeof (dw_ranges_by_label
));
10144 ranges_by_label
[in_use
].begin
= begin
;
10145 ranges_by_label
[in_use
].end
= end
;
10146 ranges_by_label_in_use
= in_use
+ 1;
10148 offset
= add_ranges_num (-(int)in_use
- 1);
10151 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
10157 output_ranges (void)
10160 static const char *const start_fmt
= "Offset %#x";
10161 const char *fmt
= start_fmt
;
10163 for (i
= 0; i
< ranges_table_in_use
; i
++)
10165 int block_num
= ranges_table
[i
].num
;
10169 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
10170 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
10172 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
10173 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
10175 /* If all code is in the text section, then the compilation
10176 unit base address defaults to DW_AT_low_pc, which is the
10177 base of the text section. */
10178 if (!have_multiple_function_sections
)
10180 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
10181 text_section_label
,
10182 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
10183 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
10184 text_section_label
, NULL
);
10187 /* Otherwise, the compilation unit base address is zero,
10188 which allows us to use absolute addresses, and not worry
10189 about whether the target supports cross-section
10193 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
10194 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
10195 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
10201 /* Negative block_num stands for an index into ranges_by_label. */
10202 else if (block_num
< 0)
10204 int lab_idx
= - block_num
- 1;
10206 if (!have_multiple_function_sections
)
10208 gcc_unreachable ();
10210 /* If we ever use add_ranges_by_labels () for a single
10211 function section, all we have to do is to take out
10212 the #if 0 above. */
10213 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
10214 ranges_by_label
[lab_idx
].begin
,
10215 text_section_label
,
10216 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
10217 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
10218 ranges_by_label
[lab_idx
].end
,
10219 text_section_label
, NULL
);
10224 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
10225 ranges_by_label
[lab_idx
].begin
,
10226 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
10227 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
10228 ranges_by_label
[lab_idx
].end
,
10234 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10235 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10241 /* Data structure containing information about input files. */
10244 const char *path
; /* Complete file name. */
10245 const char *fname
; /* File name part. */
10246 int length
; /* Length of entire string. */
10247 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
10248 int dir_idx
; /* Index in directory table. */
10251 /* Data structure containing information about directories with source
10255 const char *path
; /* Path including directory name. */
10256 int length
; /* Path length. */
10257 int prefix
; /* Index of directory entry which is a prefix. */
10258 int count
; /* Number of files in this directory. */
10259 int dir_idx
; /* Index of directory used as base. */
10262 /* Callback function for file_info comparison. We sort by looking at
10263 the directories in the path. */
10266 file_info_cmp (const void *p1
, const void *p2
)
10268 const struct file_info
*const s1
= (const struct file_info
*) p1
;
10269 const struct file_info
*const s2
= (const struct file_info
*) p2
;
10270 const unsigned char *cp1
;
10271 const unsigned char *cp2
;
10273 /* Take care of file names without directories. We need to make sure that
10274 we return consistent values to qsort since some will get confused if
10275 we return the same value when identical operands are passed in opposite
10276 orders. So if neither has a directory, return 0 and otherwise return
10277 1 or -1 depending on which one has the directory. */
10278 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
10279 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
10281 cp1
= (const unsigned char *) s1
->path
;
10282 cp2
= (const unsigned char *) s2
->path
;
10288 /* Reached the end of the first path? If so, handle like above. */
10289 if ((cp1
== (const unsigned char *) s1
->fname
)
10290 || (cp2
== (const unsigned char *) s2
->fname
))
10291 return ((cp2
== (const unsigned char *) s2
->fname
)
10292 - (cp1
== (const unsigned char *) s1
->fname
));
10294 /* Character of current path component the same? */
10295 else if (*cp1
!= *cp2
)
10296 return *cp1
- *cp2
;
10300 struct file_name_acquire_data
10302 struct file_info
*files
;
10307 /* Traversal function for the hash table. */
10310 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
10312 struct dwarf_file_data
*d
= *slot
;
10313 struct file_info
*fi
;
10316 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
10318 if (! d
->emitted_number
)
10321 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
10323 fi
= fnad
->files
+ fnad
->used_files
++;
10325 /* Skip all leading "./". */
10327 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
10330 /* Create a new array entry. */
10332 fi
->length
= strlen (f
);
10335 /* Search for the file name part. */
10336 f
= strrchr (f
, DIR_SEPARATOR
);
10337 #if defined (DIR_SEPARATOR_2)
10339 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
10343 if (f
== NULL
|| f
< g
)
10349 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
10353 /* Output the directory table and the file name table. We try to minimize
10354 the total amount of memory needed. A heuristic is used to avoid large
10355 slowdowns with many input files. */
10358 output_file_names (void)
10360 struct file_name_acquire_data fnad
;
10362 struct file_info
*files
;
10363 struct dir_info
*dirs
;
10371 if (!last_emitted_file
)
10373 dw2_asm_output_data (1, 0, "End directory table");
10374 dw2_asm_output_data (1, 0, "End file name table");
10378 numfiles
= last_emitted_file
->emitted_number
;
10380 /* Allocate the various arrays we need. */
10381 files
= XALLOCAVEC (struct file_info
, numfiles
);
10382 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
10384 fnad
.files
= files
;
10385 fnad
.used_files
= 0;
10386 fnad
.max_files
= numfiles
;
10387 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
10388 gcc_assert (fnad
.used_files
== fnad
.max_files
);
10390 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
10392 /* Find all the different directories used. */
10393 dirs
[0].path
= files
[0].path
;
10394 dirs
[0].length
= files
[0].fname
- files
[0].path
;
10395 dirs
[0].prefix
= -1;
10397 dirs
[0].dir_idx
= 0;
10398 files
[0].dir_idx
= 0;
10401 for (i
= 1; i
< numfiles
; i
++)
10402 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
10403 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
10404 dirs
[ndirs
- 1].length
) == 0)
10406 /* Same directory as last entry. */
10407 files
[i
].dir_idx
= ndirs
- 1;
10408 ++dirs
[ndirs
- 1].count
;
10414 /* This is a new directory. */
10415 dirs
[ndirs
].path
= files
[i
].path
;
10416 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
10417 dirs
[ndirs
].count
= 1;
10418 dirs
[ndirs
].dir_idx
= ndirs
;
10419 files
[i
].dir_idx
= ndirs
;
10421 /* Search for a prefix. */
10422 dirs
[ndirs
].prefix
= -1;
10423 for (j
= 0; j
< ndirs
; j
++)
10424 if (dirs
[j
].length
< dirs
[ndirs
].length
10425 && dirs
[j
].length
> 1
10426 && (dirs
[ndirs
].prefix
== -1
10427 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
10428 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
10429 dirs
[ndirs
].prefix
= j
;
10434 /* Now to the actual work. We have to find a subset of the directories which
10435 allow expressing the file name using references to the directory table
10436 with the least amount of characters. We do not do an exhaustive search
10437 where we would have to check out every combination of every single
10438 possible prefix. Instead we use a heuristic which provides nearly optimal
10439 results in most cases and never is much off. */
10440 saved
= XALLOCAVEC (int, ndirs
);
10441 savehere
= XALLOCAVEC (int, ndirs
);
10443 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
10444 for (i
= 0; i
< ndirs
; i
++)
10449 /* We can always save some space for the current directory. But this
10450 does not mean it will be enough to justify adding the directory. */
10451 savehere
[i
] = dirs
[i
].length
;
10452 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
10454 for (j
= i
+ 1; j
< ndirs
; j
++)
10457 if (saved
[j
] < dirs
[i
].length
)
10459 /* Determine whether the dirs[i] path is a prefix of the
10463 k
= dirs
[j
].prefix
;
10464 while (k
!= -1 && k
!= (int) i
)
10465 k
= dirs
[k
].prefix
;
10469 /* Yes it is. We can possibly save some memory by
10470 writing the filenames in dirs[j] relative to
10472 savehere
[j
] = dirs
[i
].length
;
10473 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
10478 /* Check whether we can save enough to justify adding the dirs[i]
10480 if (total
> dirs
[i
].length
+ 1)
10482 /* It's worthwhile adding. */
10483 for (j
= i
; j
< ndirs
; j
++)
10484 if (savehere
[j
] > 0)
10486 /* Remember how much we saved for this directory so far. */
10487 saved
[j
] = savehere
[j
];
10489 /* Remember the prefix directory. */
10490 dirs
[j
].dir_idx
= i
;
10495 /* Emit the directory name table. */
10496 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
10497 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
10498 dw2_asm_output_nstring (dirs
[i
].path
,
10500 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
10501 "Directory Entry: %#x", i
+ idx_offset
);
10503 dw2_asm_output_data (1, 0, "End directory table");
10505 /* We have to emit them in the order of emitted_number since that's
10506 used in the debug info generation. To do this efficiently we
10507 generate a back-mapping of the indices first. */
10508 backmap
= XALLOCAVEC (int, numfiles
);
10509 for (i
= 0; i
< numfiles
; i
++)
10510 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
10512 /* Now write all the file names. */
10513 for (i
= 0; i
< numfiles
; i
++)
10515 int file_idx
= backmap
[i
];
10516 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
10518 #ifdef VMS_DEBUGGING_INFO
10519 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
10521 /* Setting these fields can lead to debugger miscomparisons,
10522 but VMS Debug requires them to be set correctly. */
10527 int maxfilelen
= strlen (files
[file_idx
].path
)
10528 + dirs
[dir_idx
].length
10529 + MAX_VMS_VERSION_LEN
+ 1;
10530 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
10532 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
10533 snprintf (filebuf
, maxfilelen
, "%s;%d",
10534 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
10536 dw2_asm_output_nstring
10537 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
10539 /* Include directory index. */
10540 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10542 /* Modification time. */
10543 dw2_asm_output_data_uleb128
10544 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
10548 /* File length in bytes. */
10549 dw2_asm_output_data_uleb128
10550 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
10554 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
10555 "File Entry: %#x", (unsigned) i
+ 1);
10557 /* Include directory index. */
10558 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10560 /* Modification time. */
10561 dw2_asm_output_data_uleb128 (0, NULL
);
10563 /* File length in bytes. */
10564 dw2_asm_output_data_uleb128 (0, NULL
);
10565 #endif /* VMS_DEBUGGING_INFO */
10568 dw2_asm_output_data (1, 0, "End file name table");
10572 /* Output one line number table into the .debug_line section. */
10575 output_one_line_info_table (dw_line_info_table
*table
)
10577 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10578 unsigned int current_line
= 1;
10579 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
10580 dw_line_info_entry
*ent
;
10583 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
10585 switch (ent
->opcode
)
10587 case LI_set_address
:
10588 /* ??? Unfortunately, we have little choice here currently, and
10589 must always use the most general form. GCC does not know the
10590 address delta itself, so we can't use DW_LNS_advance_pc. Many
10591 ports do have length attributes which will give an upper bound
10592 on the address range. We could perhaps use length attributes
10593 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10594 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
10596 /* This can handle any delta. This takes
10597 4+DWARF2_ADDR_SIZE bytes. */
10598 dw2_asm_output_data (1, 0, "set address %s", line_label
);
10599 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10600 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10601 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
10605 if (ent
->val
== current_line
)
10607 /* We still need to start a new row, so output a copy insn. */
10608 dw2_asm_output_data (1, DW_LNS_copy
,
10609 "copy line %u", current_line
);
10613 int line_offset
= ent
->val
- current_line
;
10614 int line_delta
= line_offset
- DWARF_LINE_BASE
;
10616 current_line
= ent
->val
;
10617 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
10619 /* This can handle deltas from -10 to 234, using the current
10620 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10621 This takes 1 byte. */
10622 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
10623 "line %u", current_line
);
10627 /* This can handle any delta. This takes at least 4 bytes,
10628 depending on the value being encoded. */
10629 dw2_asm_output_data (1, DW_LNS_advance_line
,
10630 "advance to line %u", current_line
);
10631 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
10632 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
10638 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
10639 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10642 case LI_set_column
:
10643 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
10644 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10647 case LI_negate_stmt
:
10648 current_is_stmt
= !current_is_stmt
;
10649 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10650 "is_stmt %d", current_is_stmt
);
10653 case LI_set_prologue_end
:
10654 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10655 "set prologue end");
10658 case LI_set_epilogue_begin
:
10659 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10660 "set epilogue begin");
10663 case LI_set_discriminator
:
10664 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10665 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10666 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10667 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10672 /* Emit debug info for the address of the end of the table. */
10673 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10674 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10675 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10676 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10678 dw2_asm_output_data (1, 0, "end sequence");
10679 dw2_asm_output_data_uleb128 (1, NULL
);
10680 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10683 /* Output the source line number correspondence information. This
10684 information goes into the .debug_line section. */
10687 output_line_info (bool prologue_only
)
10689 char l1
[20], l2
[20], p1
[20], p2
[20];
10690 /* We don't support DWARFv5 line tables yet. */
10691 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
10692 bool saw_one
= false;
10695 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10696 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10697 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10698 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10700 if (!XCOFF_DEBUGGING_INFO
)
10702 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10703 dw2_asm_output_data (4, 0xffffffff,
10704 "Initial length escape value indicating 64-bit DWARF extension");
10705 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10706 "Length of Source Line Info");
10709 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10711 dw2_asm_output_data (2, ver
, "DWARF Version");
10712 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10713 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10715 /* Define the architecture-dependent minimum instruction length (in bytes).
10716 In this implementation of DWARF, this field is used for information
10717 purposes only. Since GCC generates assembly language, we have no
10718 a priori knowledge of how many instruction bytes are generated for each
10719 source line, and therefore can use only the DW_LNE_set_address and
10720 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10721 this as '1', which is "correct enough" for all architectures,
10722 and don't let the target override. */
10723 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10726 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10727 "Maximum Operations Per Instruction");
10728 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10729 "Default is_stmt_start flag");
10730 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10731 "Line Base Value (Special Opcodes)");
10732 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10733 "Line Range Value (Special Opcodes)");
10734 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10735 "Special Opcode Base");
10737 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10742 case DW_LNS_advance_pc
:
10743 case DW_LNS_advance_line
:
10744 case DW_LNS_set_file
:
10745 case DW_LNS_set_column
:
10746 case DW_LNS_fixed_advance_pc
:
10747 case DW_LNS_set_isa
:
10755 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10759 /* Write out the information about the files we use. */
10760 output_file_names ();
10761 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10764 /* Output the marker for the end of the line number info. */
10765 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10769 if (separate_line_info
)
10771 dw_line_info_table
*table
;
10774 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10777 output_one_line_info_table (table
);
10781 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10783 output_one_line_info_table (cold_text_section_line_info
);
10787 /* ??? Some Darwin linkers crash on a .debug_line section with no
10788 sequences. Further, merely a DW_LNE_end_sequence entry is not
10789 sufficient -- the address column must also be initialized.
10790 Make sure to output at least one set_address/end_sequence pair,
10791 choosing .text since that section is always present. */
10792 if (text_section_line_info
->in_use
|| !saw_one
)
10793 output_one_line_info_table (text_section_line_info
);
10795 /* Output the marker for the end of the line number info. */
10796 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10799 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
10802 need_endianity_attribute_p (bool reverse
)
10804 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
10807 /* Given a pointer to a tree node for some base type, return a pointer to
10808 a DIE that describes the given type. REVERSE is true if the type is
10809 to be interpreted in the reverse storage order wrt the target order.
10811 This routine must only be called for GCC type nodes that correspond to
10812 Dwarf base (fundamental) types. */
10815 base_type_die (tree type
, bool reverse
)
10817 dw_die_ref base_type_result
;
10818 enum dwarf_type encoding
;
10819 bool fpt_used
= false;
10820 struct fixed_point_type_info fpt_info
;
10821 tree type_bias
= NULL_TREE
;
10823 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10826 /* If this is a subtype that should not be emitted as a subrange type,
10827 use the base type. See subrange_type_for_debug_p. */
10828 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10829 type
= TREE_TYPE (type
);
10831 switch (TREE_CODE (type
))
10834 if ((dwarf_version
>= 4 || !dwarf_strict
)
10835 && TYPE_NAME (type
)
10836 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10837 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10838 && DECL_NAME (TYPE_NAME (type
)))
10840 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10841 if (strcmp (name
, "char16_t") == 0
10842 || strcmp (name
, "char32_t") == 0)
10844 encoding
= DW_ATE_UTF
;
10848 if ((dwarf_version
>= 3 || !dwarf_strict
)
10849 && lang_hooks
.types
.get_fixed_point_type_info
)
10851 memset (&fpt_info
, 0, sizeof (fpt_info
));
10852 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
10855 encoding
= ((TYPE_UNSIGNED (type
))
10856 ? DW_ATE_unsigned_fixed
10857 : DW_ATE_signed_fixed
);
10861 if (TYPE_STRING_FLAG (type
))
10863 if (TYPE_UNSIGNED (type
))
10864 encoding
= DW_ATE_unsigned_char
;
10866 encoding
= DW_ATE_signed_char
;
10868 else if (TYPE_UNSIGNED (type
))
10869 encoding
= DW_ATE_unsigned
;
10871 encoding
= DW_ATE_signed
;
10874 && lang_hooks
.types
.get_type_bias
)
10875 type_bias
= lang_hooks
.types
.get_type_bias (type
);
10879 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10881 if (dwarf_version
>= 3 || !dwarf_strict
)
10882 encoding
= DW_ATE_decimal_float
;
10884 encoding
= DW_ATE_lo_user
;
10887 encoding
= DW_ATE_float
;
10890 case FIXED_POINT_TYPE
:
10891 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10892 encoding
= DW_ATE_lo_user
;
10893 else if (TYPE_UNSIGNED (type
))
10894 encoding
= DW_ATE_unsigned_fixed
;
10896 encoding
= DW_ATE_signed_fixed
;
10899 /* Dwarf2 doesn't know anything about complex ints, so use
10900 a user defined type for it. */
10902 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10903 encoding
= DW_ATE_complex_float
;
10905 encoding
= DW_ATE_lo_user
;
10909 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10910 encoding
= DW_ATE_boolean
;
10914 /* No other TREE_CODEs are Dwarf fundamental types. */
10915 gcc_unreachable ();
10918 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10920 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10921 int_size_in_bytes (type
));
10922 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10924 if (need_endianity_attribute_p (reverse
))
10925 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
10926 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
10930 switch (fpt_info
.scale_factor_kind
)
10932 case fixed_point_scale_factor_binary
:
10933 add_AT_int (base_type_result
, DW_AT_binary_scale
,
10934 fpt_info
.scale_factor
.binary
);
10937 case fixed_point_scale_factor_decimal
:
10938 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
10939 fpt_info
.scale_factor
.decimal
);
10942 case fixed_point_scale_factor_arbitrary
:
10943 /* Arbitrary scale factors cannot be described in standard DWARF,
10947 /* Describe the scale factor as a rational constant. */
10948 const dw_die_ref scale_factor
10949 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
10951 add_AT_unsigned (scale_factor
, DW_AT_GNU_numerator
,
10952 fpt_info
.scale_factor
.arbitrary
.numerator
);
10953 add_AT_int (scale_factor
, DW_AT_GNU_denominator
,
10954 fpt_info
.scale_factor
.arbitrary
.denominator
);
10956 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
10961 gcc_unreachable ();
10966 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
10967 dw_scalar_form_constant
10968 | dw_scalar_form_exprloc
10969 | dw_scalar_form_reference
,
10972 add_pubtype (type
, base_type_result
);
10974 return base_type_result
;
10977 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
10978 named 'auto' in its type: return true for it, false otherwise. */
10981 is_cxx_auto (tree type
)
10985 tree name
= TYPE_IDENTIFIER (type
);
10986 if (name
== get_identifier ("auto")
10987 || name
== get_identifier ("decltype(auto)"))
10993 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10994 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10997 is_base_type (tree type
)
10999 switch (TREE_CODE (type
))
11005 case FIXED_POINT_TYPE
:
11008 case POINTER_BOUNDS_TYPE
:
11014 case QUAL_UNION_TYPE
:
11015 case ENUMERAL_TYPE
:
11016 case FUNCTION_TYPE
:
11019 case REFERENCE_TYPE
:
11027 if (is_cxx_auto (type
))
11029 gcc_unreachable ();
11035 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
11036 node, return the size in bits for the type if it is a constant, or else
11037 return the alignment for the type if the type's size is not constant, or
11038 else return BITS_PER_WORD if the type actually turns out to be an
11039 ERROR_MARK node. */
11041 static inline unsigned HOST_WIDE_INT
11042 simple_type_size_in_bits (const_tree type
)
11044 if (TREE_CODE (type
) == ERROR_MARK
)
11045 return BITS_PER_WORD
;
11046 else if (TYPE_SIZE (type
) == NULL_TREE
)
11048 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
11049 return tree_to_uhwi (TYPE_SIZE (type
));
11051 return TYPE_ALIGN (type
);
11054 /* Similarly, but return an offset_int instead of UHWI. */
11056 static inline offset_int
11057 offset_int_type_size_in_bits (const_tree type
)
11059 if (TREE_CODE (type
) == ERROR_MARK
)
11060 return BITS_PER_WORD
;
11061 else if (TYPE_SIZE (type
) == NULL_TREE
)
11063 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
11064 return wi::to_offset (TYPE_SIZE (type
));
11066 return TYPE_ALIGN (type
);
11069 /* Given a pointer to a tree node for a subrange type, return a pointer
11070 to a DIE that describes the given type. */
11073 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
11074 dw_die_ref context_die
)
11076 dw_die_ref subrange_die
;
11077 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
11079 if (context_die
== NULL
)
11080 context_die
= comp_unit_die ();
11082 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
11084 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
11086 /* The size of the subrange type and its base type do not match,
11087 so we need to generate a size attribute for the subrange type. */
11088 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
11092 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
11094 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
11095 if (bias
&& !dwarf_strict
)
11096 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
11097 dw_scalar_form_constant
11098 | dw_scalar_form_exprloc
11099 | dw_scalar_form_reference
,
11102 return subrange_die
;
11105 /* Returns the (const and/or volatile) cv_qualifiers associated with
11106 the decl node. This will normally be augmented with the
11107 cv_qualifiers of the underlying type in add_type_attribute. */
11110 decl_quals (const_tree decl
)
11112 return ((TREE_READONLY (decl
)
11113 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
11114 | (TREE_THIS_VOLATILE (decl
)
11115 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
11118 /* Determine the TYPE whose qualifiers match the largest strict subset
11119 of the given TYPE_QUALS, and return its qualifiers. Ignore all
11120 qualifiers outside QUAL_MASK. */
11123 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
11126 int best_rank
= 0, best_qual
= 0, max_rank
;
11128 type_quals
&= qual_mask
;
11129 max_rank
= popcount_hwi (type_quals
) - 1;
11131 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
11132 t
= TYPE_NEXT_VARIANT (t
))
11134 int q
= TYPE_QUALS (t
) & qual_mask
;
11136 if ((q
& type_quals
) == q
&& q
!= type_quals
11137 && check_base_type (t
, type
))
11139 int rank
= popcount_hwi (q
);
11141 if (rank
> best_rank
)
11152 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
11153 entry that chains the modifiers specified by CV_QUALS in front of the
11154 given type. REVERSE is true if the type is to be interpreted in the
11155 reverse storage order wrt the target order. */
11158 modified_type_die (tree type
, int cv_quals
, bool reverse
,
11159 dw_die_ref context_die
)
11161 enum tree_code code
= TREE_CODE (type
);
11162 dw_die_ref mod_type_die
;
11163 dw_die_ref sub_die
= NULL
;
11164 tree item_type
= NULL
;
11165 tree qualified_type
;
11166 tree name
, low
, high
;
11167 dw_die_ref mod_scope
;
11168 /* Only these cv-qualifiers are currently handled. */
11169 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
11170 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
11172 if (code
== ERROR_MARK
)
11175 if (lang_hooks
.types
.get_debug_type
)
11177 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
11179 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
11180 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
11183 cv_quals
&= cv_qual_mask
;
11185 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
11186 tag modifier (and not an attribute) old consumers won't be able
11188 if (dwarf_version
< 3)
11189 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
11191 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
11192 if (dwarf_version
< 5)
11193 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
11195 /* See if we already have the appropriately qualified variant of
11197 qualified_type
= get_qualified_type (type
, cv_quals
);
11199 if (qualified_type
== sizetype
11200 && TYPE_NAME (qualified_type
)
11201 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
11203 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
11205 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
11206 && TYPE_PRECISION (t
)
11207 == TYPE_PRECISION (qualified_type
)
11208 && TYPE_UNSIGNED (t
)
11209 == TYPE_UNSIGNED (qualified_type
));
11210 qualified_type
= t
;
11213 /* If we do, then we can just use its DIE, if it exists. */
11214 if (qualified_type
)
11216 mod_type_die
= lookup_type_die (qualified_type
);
11218 /* DW_AT_endianity doesn't come from a qualifier on the type. */
11220 && (!need_endianity_attribute_p (reverse
)
11221 || !is_base_type (type
)
11222 || get_AT_unsigned (mod_type_die
, DW_AT_endianity
)))
11223 return mod_type_die
;
11226 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
11228 /* Handle C typedef types. */
11229 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
11230 && !DECL_ARTIFICIAL (name
))
11232 tree dtype
= TREE_TYPE (name
);
11234 if (qualified_type
== dtype
)
11236 /* For a named type, use the typedef. */
11237 gen_type_die (qualified_type
, context_die
);
11238 return lookup_type_die (qualified_type
);
11242 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
11243 dquals
&= cv_qual_mask
;
11244 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
11245 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
11246 /* cv-unqualified version of named type. Just use
11247 the unnamed type to which it refers. */
11248 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
11249 reverse
, context_die
);
11250 /* Else cv-qualified version of named type; fall through. */
11254 mod_scope
= scope_die_for (type
, context_die
);
11258 struct qual_info
{ int q
; enum dwarf_tag t
; };
11259 static const struct qual_info qual_info
[] =
11261 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
},
11262 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
11263 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
11264 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
11269 /* Determine a lesser qualified type that most closely matches
11270 this one. Then generate DW_TAG_* entries for the remaining
11272 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
11274 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
11276 for (i
= 0; i
< sizeof (qual_info
) / sizeof (qual_info
[0]); i
++)
11277 if (qual_info
[i
].q
& cv_quals
& ~sub_quals
)
11279 dw_die_ref d
= new_die (qual_info
[i
].t
, mod_scope
, type
);
11281 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
11285 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
11287 dwarf_tag tag
= DW_TAG_pointer_type
;
11288 if (code
== REFERENCE_TYPE
)
11290 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
11291 tag
= DW_TAG_rvalue_reference_type
;
11293 tag
= DW_TAG_reference_type
;
11295 mod_type_die
= new_die (tag
, mod_scope
, type
);
11297 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
11298 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
11299 item_type
= TREE_TYPE (type
);
11301 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
11302 if (!ADDR_SPACE_GENERIC_P (as
))
11304 int action
= targetm
.addr_space
.debug (as
);
11307 /* Positive values indicate an address_class. */
11308 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
11312 /* Negative values indicate an (inverted) segment base reg. */
11314 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
11315 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
11319 else if (code
== INTEGER_TYPE
11320 && TREE_TYPE (type
) != NULL_TREE
11321 && subrange_type_for_debug_p (type
, &low
, &high
))
11323 tree bias
= NULL_TREE
;
11324 if (lang_hooks
.types
.get_type_bias
)
11325 bias
= lang_hooks
.types
.get_type_bias (type
);
11326 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
11327 item_type
= TREE_TYPE (type
);
11329 else if (is_base_type (type
))
11330 mod_type_die
= base_type_die (type
, reverse
);
11333 gen_type_die (type
, context_die
);
11335 /* We have to get the type_main_variant here (and pass that to the
11336 `lookup_type_die' routine) because the ..._TYPE node we have
11337 might simply be a *copy* of some original type node (where the
11338 copy was created to help us keep track of typedef names) and
11339 that copy might have a different TYPE_UID from the original
11341 if (TREE_CODE (type
) != VECTOR_TYPE
)
11342 return lookup_type_die (type_main_variant (type
));
11344 /* Vectors have the debugging information in the type,
11345 not the main variant. */
11346 return lookup_type_die (type
);
11349 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
11350 don't output a DW_TAG_typedef, since there isn't one in the
11351 user's program; just attach a DW_AT_name to the type.
11352 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
11353 if the base type already has the same name. */
11355 && ((TREE_CODE (name
) != TYPE_DECL
11356 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
11357 || (cv_quals
== TYPE_UNQUALIFIED
)))
11358 || (TREE_CODE (name
) == TYPE_DECL
11359 && TREE_TYPE (name
) == qualified_type
11360 && DECL_NAME (name
))))
11362 if (TREE_CODE (name
) == TYPE_DECL
)
11363 /* Could just call add_name_and_src_coords_attributes here,
11364 but since this is a builtin type it doesn't have any
11365 useful source coordinates anyway. */
11366 name
= DECL_NAME (name
);
11367 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
11369 /* This probably indicates a bug. */
11370 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
11372 name
= TYPE_IDENTIFIER (type
);
11373 add_name_attribute (mod_type_die
,
11374 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
11377 if (qualified_type
)
11378 equate_type_number_to_die (qualified_type
, mod_type_die
);
11381 /* We must do this after the equate_type_number_to_die call, in case
11382 this is a recursive type. This ensures that the modified_type_die
11383 recursion will terminate even if the type is recursive. Recursive
11384 types are possible in Ada. */
11385 sub_die
= modified_type_die (item_type
,
11386 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
11390 if (sub_die
!= NULL
)
11391 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
11393 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
11394 if (TYPE_ARTIFICIAL (type
))
11395 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
11397 return mod_type_die
;
11400 /* Generate DIEs for the generic parameters of T.
11401 T must be either a generic type or a generic function.
11402 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
11405 gen_generic_params_dies (tree t
)
11409 dw_die_ref die
= NULL
;
11412 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
11416 die
= lookup_type_die (t
);
11417 else if (DECL_P (t
))
11418 die
= lookup_decl_die (t
);
11422 parms
= lang_hooks
.get_innermost_generic_parms (t
);
11424 /* T has no generic parameter. It means T is neither a generic type
11425 or function. End of story. */
11428 parms_num
= TREE_VEC_LENGTH (parms
);
11429 args
= lang_hooks
.get_innermost_generic_args (t
);
11430 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
11431 non_default
= int_cst_value (TREE_CHAIN (args
));
11433 non_default
= TREE_VEC_LENGTH (args
);
11434 for (i
= 0; i
< parms_num
; i
++)
11436 tree parm
, arg
, arg_pack_elems
;
11437 dw_die_ref parm_die
;
11439 parm
= TREE_VEC_ELT (parms
, i
);
11440 arg
= TREE_VEC_ELT (args
, i
);
11441 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
11442 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
11444 if (parm
&& TREE_VALUE (parm
) && arg
)
11446 /* If PARM represents a template parameter pack,
11447 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
11448 by DW_TAG_template_*_parameter DIEs for the argument
11449 pack elements of ARG. Note that ARG would then be
11450 an argument pack. */
11451 if (arg_pack_elems
)
11452 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
11456 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
11457 true /* emit name */, die
);
11458 if (i
>= non_default
)
11459 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
11464 /* Create and return a DIE for PARM which should be
11465 the representation of a generic type parameter.
11466 For instance, in the C++ front end, PARM would be a template parameter.
11467 ARG is the argument to PARM.
11468 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
11470 PARENT_DIE is the parent DIE which the new created DIE should be added to,
11471 as a child node. */
11474 generic_parameter_die (tree parm
, tree arg
,
11476 dw_die_ref parent_die
)
11478 dw_die_ref tmpl_die
= NULL
;
11479 const char *name
= NULL
;
11481 if (!parm
|| !DECL_NAME (parm
) || !arg
)
11484 /* We support non-type generic parameters and arguments,
11485 type generic parameters and arguments, as well as
11486 generic generic parameters (a.k.a. template template parameters in C++)
11488 if (TREE_CODE (parm
) == PARM_DECL
)
11489 /* PARM is a nontype generic parameter */
11490 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
11491 else if (TREE_CODE (parm
) == TYPE_DECL
)
11492 /* PARM is a type generic parameter. */
11493 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
11494 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11495 /* PARM is a generic generic parameter.
11496 Its DIE is a GNU extension. It shall have a
11497 DW_AT_name attribute to represent the name of the template template
11498 parameter, and a DW_AT_GNU_template_name attribute to represent the
11499 name of the template template argument. */
11500 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
11503 gcc_unreachable ();
11509 /* If PARM is a generic parameter pack, it means we are
11510 emitting debug info for a template argument pack element.
11511 In other terms, ARG is a template argument pack element.
11512 In that case, we don't emit any DW_AT_name attribute for
11516 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
11518 add_AT_string (tmpl_die
, DW_AT_name
, name
);
11521 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11523 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
11524 TMPL_DIE should have a child DW_AT_type attribute that is set
11525 to the type of the argument to PARM, which is ARG.
11526 If PARM is a type generic parameter, TMPL_DIE should have a
11527 child DW_AT_type that is set to ARG. */
11528 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
11529 add_type_attribute (tmpl_die
, tmpl_type
,
11530 (TREE_THIS_VOLATILE (tmpl_type
)
11531 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
11532 false, parent_die
);
11536 /* So TMPL_DIE is a DIE representing a
11537 a generic generic template parameter, a.k.a template template
11538 parameter in C++ and arg is a template. */
11540 /* The DW_AT_GNU_template_name attribute of the DIE must be set
11541 to the name of the argument. */
11542 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
11544 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
11547 if (TREE_CODE (parm
) == PARM_DECL
)
11548 /* So PARM is a non-type generic parameter.
11549 DWARF3 5.6.8 says we must set a DW_AT_const_value child
11550 attribute of TMPL_DIE which value represents the value
11552 We must be careful here:
11553 The value of ARG might reference some function decls.
11554 We might currently be emitting debug info for a generic
11555 type and types are emitted before function decls, we don't
11556 know if the function decls referenced by ARG will actually be
11557 emitted after cgraph computations.
11558 So must defer the generation of the DW_AT_const_value to
11559 after cgraph is ready. */
11560 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
11566 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
11567 PARM_PACK must be a template parameter pack. The returned DIE
11568 will be child DIE of PARENT_DIE. */
11571 template_parameter_pack_die (tree parm_pack
,
11572 tree parm_pack_args
,
11573 dw_die_ref parent_die
)
11578 gcc_assert (parent_die
&& parm_pack
);
11580 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
11581 add_name_and_src_coords_attributes (die
, parm_pack
);
11582 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
11583 generic_parameter_die (parm_pack
,
11584 TREE_VEC_ELT (parm_pack_args
, j
),
11585 false /* Don't emit DW_AT_name */,
11590 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
11591 an enumerated type. */
11594 type_is_enum (const_tree type
)
11596 return TREE_CODE (type
) == ENUMERAL_TYPE
;
11599 /* Return the DBX register number described by a given RTL node. */
11601 static unsigned int
11602 dbx_reg_number (const_rtx rtl
)
11604 unsigned regno
= REGNO (rtl
);
11606 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
11608 #ifdef LEAF_REG_REMAP
11609 if (crtl
->uses_only_leaf_regs
)
11611 int leaf_reg
= LEAF_REG_REMAP (regno
);
11612 if (leaf_reg
!= -1)
11613 regno
= (unsigned) leaf_reg
;
11617 regno
= DBX_REGISTER_NUMBER (regno
);
11618 gcc_assert (regno
!= INVALID_REGNUM
);
11622 /* Optionally add a DW_OP_piece term to a location description expression.
11623 DW_OP_piece is only added if the location description expression already
11624 doesn't end with DW_OP_piece. */
11627 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
11629 dw_loc_descr_ref loc
;
11631 if (*list_head
!= NULL
)
11633 /* Find the end of the chain. */
11634 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
11637 if (loc
->dw_loc_opc
!= DW_OP_piece
)
11638 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
11642 /* Return a location descriptor that designates a machine register or
11643 zero if there is none. */
11645 static dw_loc_descr_ref
11646 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
11650 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
11653 /* We only use "frame base" when we're sure we're talking about the
11654 post-prologue local stack frame. We do this by *not* running
11655 register elimination until this point, and recognizing the special
11656 argument pointer and soft frame pointer rtx's.
11657 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
11658 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
11659 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
11661 dw_loc_descr_ref result
= NULL
;
11663 if (dwarf_version
>= 4 || !dwarf_strict
)
11665 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
11668 add_loc_descr (&result
,
11669 new_loc_descr (DW_OP_stack_value
, 0, 0));
11674 regs
= targetm
.dwarf_register_span (rtl
);
11676 if (REG_NREGS (rtl
) > 1 || regs
)
11677 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
11680 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
11681 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11683 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
11687 /* Return a location descriptor that designates a machine register for
11688 a given hard register number. */
11690 static dw_loc_descr_ref
11691 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
11693 dw_loc_descr_ref reg_loc_descr
;
11697 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
11699 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
11701 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11702 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11704 return reg_loc_descr
;
11707 /* Given an RTL of a register, return a location descriptor that
11708 designates a value that spans more than one register. */
11710 static dw_loc_descr_ref
11711 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
11712 enum var_init_status initialized
)
11715 dw_loc_descr_ref loc_result
= NULL
;
11717 /* Simple, contiguous registers. */
11718 if (regs
== NULL_RTX
)
11720 unsigned reg
= REGNO (rtl
);
11723 #ifdef LEAF_REG_REMAP
11724 if (crtl
->uses_only_leaf_regs
)
11726 int leaf_reg
= LEAF_REG_REMAP (reg
);
11727 if (leaf_reg
!= -1)
11728 reg
= (unsigned) leaf_reg
;
11732 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
11733 nregs
= REG_NREGS (rtl
);
11735 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
11740 dw_loc_descr_ref t
;
11742 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
11743 VAR_INIT_STATUS_INITIALIZED
);
11744 add_loc_descr (&loc_result
, t
);
11745 add_loc_descr_op_piece (&loc_result
, size
);
11751 /* Now onto stupid register sets in non contiguous locations. */
11753 gcc_assert (GET_CODE (regs
) == PARALLEL
);
11755 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
11758 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
11760 dw_loc_descr_ref t
;
11762 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
11763 VAR_INIT_STATUS_INITIALIZED
);
11764 add_loc_descr (&loc_result
, t
);
11765 add_loc_descr_op_piece (&loc_result
, size
);
11768 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11769 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11773 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
11775 /* Return a location descriptor that designates a constant i,
11776 as a compound operation from constant (i >> shift), constant shift
11779 static dw_loc_descr_ref
11780 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11782 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
11783 add_loc_descr (&ret
, int_loc_descriptor (shift
));
11784 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11788 /* Return a location descriptor that designates a constant. */
11790 static dw_loc_descr_ref
11791 int_loc_descriptor (HOST_WIDE_INT i
)
11793 enum dwarf_location_atom op
;
11795 /* Pick the smallest representation of a constant, rather than just
11796 defaulting to the LEB encoding. */
11799 int clz
= clz_hwi (i
);
11800 int ctz
= ctz_hwi (i
);
11802 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
11803 else if (i
<= 0xff)
11804 op
= DW_OP_const1u
;
11805 else if (i
<= 0xffff)
11806 op
= DW_OP_const2u
;
11807 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11808 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11809 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11810 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11811 while DW_OP_const4u is 5 bytes. */
11812 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
11813 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11814 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11815 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11816 while DW_OP_const4u is 5 bytes. */
11817 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11818 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11819 op
= DW_OP_const4u
;
11820 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11821 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11822 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11823 while DW_OP_constu of constant >= 0x100000000 takes at least
11825 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11826 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11827 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
11828 >= HOST_BITS_PER_WIDE_INT
)
11829 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11830 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11831 while DW_OP_constu takes in this case at least 6 bytes. */
11832 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
11833 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11834 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11835 && size_of_uleb128 (i
) > 6)
11836 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11837 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11844 op
= DW_OP_const1s
;
11845 else if (i
>= -0x8000)
11846 op
= DW_OP_const2s
;
11847 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11849 if (size_of_int_loc_descriptor (i
) < 5)
11851 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11852 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11855 op
= DW_OP_const4s
;
11859 if (size_of_int_loc_descriptor (i
)
11860 < (unsigned long) 1 + size_of_sleb128 (i
))
11862 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11863 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11870 return new_loc_descr (op
, i
, 0);
11873 /* Likewise, for unsigned constants. */
11875 static dw_loc_descr_ref
11876 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
11878 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
11879 const unsigned HOST_WIDE_INT max_uint
11880 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
11882 /* If possible, use the clever signed constants handling. */
11884 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
11886 /* Here, we are left with positive numbers that cannot be represented as
11887 HOST_WIDE_INT, i.e.:
11888 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
11890 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
11891 whereas may be better to output a negative integer: thanks to integer
11892 wrapping, we know that:
11893 x = x - 2 ** DWARF2_ADDR_SIZE
11894 = x - 2 * (max (HOST_WIDE_INT) + 1)
11895 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
11896 small negative integers. Let's try that in cases it will clearly improve
11897 the encoding: there is no gain turning DW_OP_const4u into
11899 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
11900 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
11901 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
11903 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
11905 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
11906 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
11907 const HOST_WIDE_INT second_shift
11908 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
11910 /* So we finally have:
11911 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
11912 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
11913 return int_loc_descriptor (second_shift
);
11916 /* Last chance: fallback to a simple constant operation. */
11917 return new_loc_descr
11918 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11924 /* Generate and return a location description that computes the unsigned
11925 comparison of the two stack top entries (a OP b where b is the top-most
11926 entry and a is the second one). The KIND of comparison can be LT_EXPR,
11927 LE_EXPR, GT_EXPR or GE_EXPR. */
11929 static dw_loc_descr_ref
11930 uint_comparison_loc_list (enum tree_code kind
)
11932 enum dwarf_location_atom op
, flip_op
;
11933 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
11950 gcc_unreachable ();
11953 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11954 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
11956 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
11957 possible to perform unsigned comparisons: we just have to distinguish
11960 1. when a and b have the same sign (as signed integers); then we should
11961 return: a OP(signed) b;
11963 2. when a is a negative signed integer while b is a positive one, then a
11964 is a greater unsigned integer than b; likewise when a and b's roles
11967 So first, compare the sign of the two operands. */
11968 ret
= new_loc_descr (DW_OP_over
, 0, 0);
11969 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11970 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
11971 /* If they have different signs (i.e. they have different sign bits), then
11972 the stack top value has now the sign bit set and thus it's smaller than
11974 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
11975 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
11976 add_loc_descr (&ret
, bra_node
);
11978 /* We are in case 1. At this point, we know both operands have the same
11979 sign, to it's safe to use the built-in signed comparison. */
11980 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11981 add_loc_descr (&ret
, jmp_node
);
11983 /* We are in case 2. Here, we know both operands do not have the same sign,
11984 so we have to flip the signed comparison. */
11985 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
11986 tmp
= new_loc_descr (flip_op
, 0, 0);
11987 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11988 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
11989 add_loc_descr (&ret
, tmp
);
11991 /* This dummy operation is necessary to make the two branches join. */
11992 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
11993 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11994 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
11995 add_loc_descr (&ret
, tmp
);
12000 /* Likewise, but takes the location description lists (might be destructive on
12001 them). Return NULL if either is NULL or if concatenation fails. */
12003 static dw_loc_list_ref
12004 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
12005 enum tree_code kind
)
12007 if (left
== NULL
|| right
== NULL
)
12010 add_loc_list (&left
, right
);
12014 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
12018 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
12019 without actually allocating it. */
12021 static unsigned long
12022 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
12024 return size_of_int_loc_descriptor (i
>> shift
)
12025 + size_of_int_loc_descriptor (shift
)
12029 /* Return size_of_locs (int_loc_descriptor (i)) without
12030 actually allocating it. */
12032 static unsigned long
12033 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
12042 else if (i
<= 0xff)
12044 else if (i
<= 0xffff)
12048 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
12049 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
12050 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12052 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
12053 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
12054 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12056 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
12058 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
12059 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
12060 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
12061 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12063 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
12064 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
12065 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12067 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
12068 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
12070 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12079 else if (i
>= -0x8000)
12081 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
12083 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
12085 s
= size_of_int_loc_descriptor (-i
) + 1;
12093 unsigned long r
= 1 + size_of_sleb128 (i
);
12094 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
12096 s
= size_of_int_loc_descriptor (-i
) + 1;
12105 /* Return loc description representing "address" of integer value.
12106 This can appear only as toplevel expression. */
12108 static dw_loc_descr_ref
12109 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
12112 dw_loc_descr_ref loc_result
= NULL
;
12114 if (!(dwarf_version
>= 4 || !dwarf_strict
))
12117 litsize
= size_of_int_loc_descriptor (i
);
12118 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
12119 is more compact. For DW_OP_stack_value we need:
12120 litsize + 1 (DW_OP_stack_value)
12121 and for DW_OP_implicit_value:
12122 1 (DW_OP_implicit_value) + 1 (length) + size. */
12123 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
12125 loc_result
= int_loc_descriptor (i
);
12126 add_loc_descr (&loc_result
,
12127 new_loc_descr (DW_OP_stack_value
, 0, 0));
12131 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12133 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12134 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
12138 /* Return a location descriptor that designates a base+offset location. */
12140 static dw_loc_descr_ref
12141 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
12142 enum var_init_status initialized
)
12144 unsigned int regno
;
12145 dw_loc_descr_ref result
;
12146 dw_fde_ref fde
= cfun
->fde
;
12148 /* We only use "frame base" when we're sure we're talking about the
12149 post-prologue local stack frame. We do this by *not* running
12150 register elimination until this point, and recognizing the special
12151 argument pointer and soft frame pointer rtx's. */
12152 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
12154 rtx elim
= (ira_use_lra_p
12155 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
12156 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
12160 if (GET_CODE (elim
) == PLUS
)
12162 offset
+= INTVAL (XEXP (elim
, 1));
12163 elim
= XEXP (elim
, 0);
12165 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12166 && (elim
== hard_frame_pointer_rtx
12167 || elim
== stack_pointer_rtx
))
12168 || elim
== (frame_pointer_needed
12169 ? hard_frame_pointer_rtx
12170 : stack_pointer_rtx
));
12172 /* If drap register is used to align stack, use frame
12173 pointer + offset to access stack variables. If stack
12174 is aligned without drap, use stack pointer + offset to
12175 access stack variables. */
12176 if (crtl
->stack_realign_tried
12177 && reg
== frame_pointer_rtx
)
12180 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
12181 ? HARD_FRAME_POINTER_REGNUM
12183 return new_reg_loc_descr (base_reg
, offset
);
12186 gcc_assert (frame_pointer_fb_offset_valid
);
12187 offset
+= frame_pointer_fb_offset
;
12188 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
12192 regno
= REGNO (reg
);
12193 #ifdef LEAF_REG_REMAP
12194 if (crtl
->uses_only_leaf_regs
)
12196 int leaf_reg
= LEAF_REG_REMAP (regno
);
12197 if (leaf_reg
!= -1)
12198 regno
= (unsigned) leaf_reg
;
12201 regno
= DWARF_FRAME_REGNUM (regno
);
12203 if (!optimize
&& fde
12204 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
12206 /* Use cfa+offset to represent the location of arguments passed
12207 on the stack when drap is used to align stack.
12208 Only do this when not optimizing, for optimized code var-tracking
12209 is supposed to track where the arguments live and the register
12210 used as vdrap or drap in some spot might be used for something
12211 else in other part of the routine. */
12212 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
12216 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
12219 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
12221 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12222 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12227 /* Return true if this RTL expression describes a base+offset calculation. */
12230 is_based_loc (const_rtx rtl
)
12232 return (GET_CODE (rtl
) == PLUS
12233 && ((REG_P (XEXP (rtl
, 0))
12234 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
12235 && CONST_INT_P (XEXP (rtl
, 1)))));
12238 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
12241 static dw_loc_descr_ref
12242 tls_mem_loc_descriptor (rtx mem
)
12245 dw_loc_descr_ref loc_result
;
12247 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
12250 base
= get_base_address (MEM_EXPR (mem
));
12252 || TREE_CODE (base
) != VAR_DECL
12253 || !DECL_THREAD_LOCAL_P (base
))
12256 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
12257 if (loc_result
== NULL
)
12260 if (MEM_OFFSET (mem
))
12261 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
12266 /* Output debug info about reason why we failed to expand expression as dwarf
12270 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
12272 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
12274 fprintf (dump_file
, "Failed to expand as dwarf: ");
12276 print_generic_expr (dump_file
, expr
, dump_flags
);
12279 fprintf (dump_file
, "\n");
12280 print_rtl (dump_file
, rtl
);
12282 fprintf (dump_file
, "\nReason: %s\n", reason
);
12286 /* Helper function for const_ok_for_output. */
12289 const_ok_for_output_1 (rtx rtl
)
12291 if (GET_CODE (rtl
) == UNSPEC
)
12293 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
12294 we can't express it in the debug info. */
12295 /* Don't complain about TLS UNSPECs, those are just too hard to
12296 delegitimize. Note this could be a non-decl SYMBOL_REF such as
12297 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
12298 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
12300 && (XVECLEN (rtl
, 0) == 0
12301 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
12302 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
12303 inform (current_function_decl
12304 ? DECL_SOURCE_LOCATION (current_function_decl
)
12305 : UNKNOWN_LOCATION
,
12306 #if NUM_UNSPEC_VALUES > 0
12307 "non-delegitimized UNSPEC %s (%d) found in variable location",
12308 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
12309 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
12312 "non-delegitimized UNSPEC %d found in variable location",
12315 expansion_failed (NULL_TREE
, rtl
,
12316 "UNSPEC hasn't been delegitimized.\n");
12320 if (targetm
.const_not_ok_for_debug_p (rtl
))
12322 expansion_failed (NULL_TREE
, rtl
,
12323 "Expression rejected for debug by the backend.\n");
12327 /* FIXME: Refer to PR60655. It is possible for simplification
12328 of rtl expressions in var tracking to produce such expressions.
12329 We should really identify / validate expressions
12330 enclosed in CONST that can be handled by assemblers on various
12331 targets and only handle legitimate cases here. */
12332 if (GET_CODE (rtl
) != SYMBOL_REF
)
12334 if (GET_CODE (rtl
) == NOT
)
12339 if (CONSTANT_POOL_ADDRESS_P (rtl
))
12342 get_pool_constant_mark (rtl
, &marked
);
12343 /* If all references to this pool constant were optimized away,
12344 it was not output and thus we can't represent it. */
12347 expansion_failed (NULL_TREE
, rtl
,
12348 "Constant was removed from constant pool.\n");
12353 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12356 /* Avoid references to external symbols in debug info, on several targets
12357 the linker might even refuse to link when linking a shared library,
12358 and in many other cases the relocations for .debug_info/.debug_loc are
12359 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
12360 to be defined within the same shared library or executable are fine. */
12361 if (SYMBOL_REF_EXTERNAL_P (rtl
))
12363 tree decl
= SYMBOL_REF_DECL (rtl
);
12365 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
12367 expansion_failed (NULL_TREE
, rtl
,
12368 "Symbol not defined in current TU.\n");
12376 /* Return true if constant RTL can be emitted in DW_OP_addr or
12377 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
12378 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
12381 const_ok_for_output (rtx rtl
)
12383 if (GET_CODE (rtl
) == SYMBOL_REF
)
12384 return const_ok_for_output_1 (rtl
);
12386 if (GET_CODE (rtl
) == CONST
)
12388 subrtx_var_iterator::array_type array
;
12389 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
12390 if (!const_ok_for_output_1 (*iter
))
12398 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
12399 if possible, NULL otherwise. */
12402 base_type_for_mode (machine_mode mode
, bool unsignedp
)
12404 dw_die_ref type_die
;
12405 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
12409 switch (TREE_CODE (type
))
12417 type_die
= lookup_type_die (type
);
12419 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
12421 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
12426 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
12427 type matching MODE, or, if MODE is narrower than or as wide as
12428 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
12431 static dw_loc_descr_ref
12432 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
12434 machine_mode outer_mode
= mode
;
12435 dw_die_ref type_die
;
12436 dw_loc_descr_ref cvt
;
12438 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12440 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
12443 type_die
= base_type_for_mode (outer_mode
, 1);
12444 if (type_die
== NULL
)
12446 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12447 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12448 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12449 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12450 add_loc_descr (&op
, cvt
);
12454 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
12456 static dw_loc_descr_ref
12457 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
12458 dw_loc_descr_ref op1
)
12460 dw_loc_descr_ref ret
= op0
;
12461 add_loc_descr (&ret
, op1
);
12462 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12463 if (STORE_FLAG_VALUE
!= 1)
12465 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
12466 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
12471 /* Return location descriptor for signed comparison OP RTL. */
12473 static dw_loc_descr_ref
12474 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
12475 machine_mode mem_mode
)
12477 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
12478 dw_loc_descr_ref op0
, op1
;
12481 if (op_mode
== VOIDmode
)
12482 op_mode
= GET_MODE (XEXP (rtl
, 1));
12483 if (op_mode
== VOIDmode
)
12487 && (GET_MODE_CLASS (op_mode
) != MODE_INT
12488 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
12491 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
12492 VAR_INIT_STATUS_INITIALIZED
);
12493 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
12494 VAR_INIT_STATUS_INITIALIZED
);
12496 if (op0
== NULL
|| op1
== NULL
)
12499 if (GET_MODE_CLASS (op_mode
) != MODE_INT
12500 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
12501 return compare_loc_descriptor (op
, op0
, op1
);
12503 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
12505 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
12506 dw_loc_descr_ref cvt
;
12508 if (type_die
== NULL
)
12510 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12511 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12512 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12513 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12514 add_loc_descr (&op0
, cvt
);
12515 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12516 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12517 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12518 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12519 add_loc_descr (&op1
, cvt
);
12520 return compare_loc_descriptor (op
, op0
, op1
);
12523 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
12524 /* For eq/ne, if the operands are known to be zero-extended,
12525 there is no need to do the fancy shifting up. */
12526 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
12528 dw_loc_descr_ref last0
, last1
;
12529 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
12531 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
12533 /* deref_size zero extends, and for constants we can check
12534 whether they are zero extended or not. */
12535 if (((last0
->dw_loc_opc
== DW_OP_deref_size
12536 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
12537 || (CONST_INT_P (XEXP (rtl
, 0))
12538 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
12539 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
12540 && ((last1
->dw_loc_opc
== DW_OP_deref_size
12541 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
12542 || (CONST_INT_P (XEXP (rtl
, 1))
12543 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
12544 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
12545 return compare_loc_descriptor (op
, op0
, op1
);
12547 /* EQ/NE comparison against constant in narrower type than
12548 DWARF2_ADDR_SIZE can be performed either as
12549 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
12552 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
12553 DW_OP_{eq,ne}. Pick whatever is shorter. */
12554 if (CONST_INT_P (XEXP (rtl
, 1))
12555 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
12556 && (size_of_int_loc_descriptor (shift
) + 1
12557 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
12558 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
12559 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
12560 & GET_MODE_MASK (op_mode
))))
12562 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
12563 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12564 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
12565 & GET_MODE_MASK (op_mode
));
12566 return compare_loc_descriptor (op
, op0
, op1
);
12569 add_loc_descr (&op0
, int_loc_descriptor (shift
));
12570 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
12571 if (CONST_INT_P (XEXP (rtl
, 1)))
12572 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
12575 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12576 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12578 return compare_loc_descriptor (op
, op0
, op1
);
12581 /* Return location descriptor for unsigned comparison OP RTL. */
12583 static dw_loc_descr_ref
12584 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
12585 machine_mode mem_mode
)
12587 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
12588 dw_loc_descr_ref op0
, op1
;
12590 if (op_mode
== VOIDmode
)
12591 op_mode
= GET_MODE (XEXP (rtl
, 1));
12592 if (op_mode
== VOIDmode
)
12594 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
12597 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
12600 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
12601 VAR_INIT_STATUS_INITIALIZED
);
12602 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
12603 VAR_INIT_STATUS_INITIALIZED
);
12605 if (op0
== NULL
|| op1
== NULL
)
12608 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
12610 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
12611 dw_loc_descr_ref last0
, last1
;
12612 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
12614 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
12616 if (CONST_INT_P (XEXP (rtl
, 0)))
12617 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
12618 /* deref_size zero extends, so no need to mask it again. */
12619 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
12620 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12622 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12623 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12625 if (CONST_INT_P (XEXP (rtl
, 1)))
12626 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
12627 /* deref_size zero extends, so no need to mask it again. */
12628 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
12629 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12631 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12632 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12635 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
12637 HOST_WIDE_INT bias
= 1;
12638 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12639 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12640 if (CONST_INT_P (XEXP (rtl
, 1)))
12641 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
12642 + INTVAL (XEXP (rtl
, 1)));
12644 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
12647 return compare_loc_descriptor (op
, op0
, op1
);
12650 /* Return location descriptor for {U,S}{MIN,MAX}. */
12652 static dw_loc_descr_ref
12653 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
12654 machine_mode mem_mode
)
12656 enum dwarf_location_atom op
;
12657 dw_loc_descr_ref op0
, op1
, ret
;
12658 dw_loc_descr_ref bra_node
, drop_node
;
12661 && (GET_MODE_CLASS (mode
) != MODE_INT
12662 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
12665 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12666 VAR_INIT_STATUS_INITIALIZED
);
12667 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12668 VAR_INIT_STATUS_INITIALIZED
);
12670 if (op0
== NULL
|| op1
== NULL
)
12673 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
12674 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
12675 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
12676 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
12678 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12680 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
12681 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12682 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12683 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12684 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12686 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12688 HOST_WIDE_INT bias
= 1;
12689 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12690 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12691 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12694 else if (GET_MODE_CLASS (mode
) == MODE_INT
12695 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12697 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
12698 add_loc_descr (&op0
, int_loc_descriptor (shift
));
12699 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
12700 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12701 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12703 else if (GET_MODE_CLASS (mode
) == MODE_INT
12704 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12706 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
12707 dw_loc_descr_ref cvt
;
12708 if (type_die
== NULL
)
12710 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12711 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12712 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12713 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12714 add_loc_descr (&op0
, cvt
);
12715 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12716 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12717 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12718 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12719 add_loc_descr (&op1
, cvt
);
12722 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
12727 add_loc_descr (&ret
, op1
);
12728 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12729 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12730 add_loc_descr (&ret
, bra_node
);
12731 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12732 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12733 add_loc_descr (&ret
, drop_node
);
12734 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12735 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12736 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
12737 && GET_MODE_CLASS (mode
) == MODE_INT
12738 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12739 ret
= convert_descriptor_to_mode (mode
, ret
);
12743 /* Helper function for mem_loc_descriptor. Perform OP binary op,
12744 but after converting arguments to type_die, afterwards
12745 convert back to unsigned. */
12747 static dw_loc_descr_ref
12748 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
12749 machine_mode mode
, machine_mode mem_mode
)
12751 dw_loc_descr_ref cvt
, op0
, op1
;
12753 if (type_die
== NULL
)
12755 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12756 VAR_INIT_STATUS_INITIALIZED
);
12757 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12758 VAR_INIT_STATUS_INITIALIZED
);
12759 if (op0
== NULL
|| op1
== NULL
)
12761 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12762 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12763 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12764 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12765 add_loc_descr (&op0
, cvt
);
12766 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12767 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12768 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12769 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12770 add_loc_descr (&op1
, cvt
);
12771 add_loc_descr (&op0
, op1
);
12772 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
12773 return convert_descriptor_to_mode (mode
, op0
);
12776 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
12777 const0 is DW_OP_lit0 or corresponding typed constant,
12778 const1 is DW_OP_lit1 or corresponding typed constant
12779 and constMSB is constant with just the MSB bit set
12781 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12782 L1: const0 DW_OP_swap
12783 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
12784 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12789 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12790 L1: const0 DW_OP_swap
12791 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12792 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12797 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
12798 L1: const1 DW_OP_swap
12799 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12800 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12804 static dw_loc_descr_ref
12805 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
12806 machine_mode mem_mode
)
12808 dw_loc_descr_ref op0
, ret
, tmp
;
12809 HOST_WIDE_INT valv
;
12810 dw_loc_descr_ref l1jump
, l1label
;
12811 dw_loc_descr_ref l2jump
, l2label
;
12812 dw_loc_descr_ref l3jump
, l3label
;
12813 dw_loc_descr_ref l4jump
, l4label
;
12816 if (GET_MODE_CLASS (mode
) != MODE_INT
12817 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12820 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12821 VAR_INIT_STATUS_INITIALIZED
);
12825 if (GET_CODE (rtl
) == CLZ
)
12827 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12828 valv
= GET_MODE_BITSIZE (mode
);
12830 else if (GET_CODE (rtl
) == FFS
)
12832 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12833 valv
= GET_MODE_BITSIZE (mode
);
12834 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12835 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12836 add_loc_descr (&ret
, l1jump
);
12837 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12838 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
12839 VAR_INIT_STATUS_INITIALIZED
);
12842 add_loc_descr (&ret
, tmp
);
12843 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12844 add_loc_descr (&ret
, l4jump
);
12845 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
12846 ? const1_rtx
: const0_rtx
,
12848 VAR_INIT_STATUS_INITIALIZED
);
12849 if (l1label
== NULL
)
12851 add_loc_descr (&ret
, l1label
);
12852 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12853 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
12854 add_loc_descr (&ret
, l2label
);
12855 if (GET_CODE (rtl
) != CLZ
)
12857 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
12858 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
12859 << (GET_MODE_BITSIZE (mode
) - 1));
12861 msb
= immed_wide_int_const
12862 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
12863 GET_MODE_PRECISION (mode
)), mode
);
12864 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
12865 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12866 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
12867 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
12869 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
12870 VAR_INIT_STATUS_INITIALIZED
);
12873 add_loc_descr (&ret
, tmp
);
12874 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12875 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12876 add_loc_descr (&ret
, l3jump
);
12877 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12878 VAR_INIT_STATUS_INITIALIZED
);
12881 add_loc_descr (&ret
, tmp
);
12882 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
12883 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
12884 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12885 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
12886 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12887 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12888 add_loc_descr (&ret
, l2jump
);
12889 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
12890 add_loc_descr (&ret
, l3label
);
12891 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
12892 add_loc_descr (&ret
, l4label
);
12893 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12894 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12895 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12896 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12897 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12898 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
12899 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12900 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
12904 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
12905 const1 is DW_OP_lit1 or corresponding typed constant):
12907 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12908 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12912 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12913 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12916 static dw_loc_descr_ref
12917 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
12918 machine_mode mem_mode
)
12920 dw_loc_descr_ref op0
, ret
, tmp
;
12921 dw_loc_descr_ref l1jump
, l1label
;
12922 dw_loc_descr_ref l2jump
, l2label
;
12924 if (GET_MODE_CLASS (mode
) != MODE_INT
12925 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12928 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12929 VAR_INIT_STATUS_INITIALIZED
);
12933 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12934 VAR_INIT_STATUS_INITIALIZED
);
12937 add_loc_descr (&ret
, tmp
);
12938 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12939 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
12940 add_loc_descr (&ret
, l1label
);
12941 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12942 add_loc_descr (&ret
, l2jump
);
12943 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12944 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12945 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12946 VAR_INIT_STATUS_INITIALIZED
);
12949 add_loc_descr (&ret
, tmp
);
12950 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12951 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
12952 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
12953 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12954 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12955 VAR_INIT_STATUS_INITIALIZED
);
12956 add_loc_descr (&ret
, tmp
);
12957 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12958 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12959 add_loc_descr (&ret
, l1jump
);
12960 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12961 add_loc_descr (&ret
, l2label
);
12962 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12963 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12964 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12965 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12969 /* BSWAP (constS is initial shift count, either 56 or 24):
12971 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
12972 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
12973 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
12974 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
12975 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
12977 static dw_loc_descr_ref
12978 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
12979 machine_mode mem_mode
)
12981 dw_loc_descr_ref op0
, ret
, tmp
;
12982 dw_loc_descr_ref l1jump
, l1label
;
12983 dw_loc_descr_ref l2jump
, l2label
;
12985 if (GET_MODE_CLASS (mode
) != MODE_INT
12986 || BITS_PER_UNIT
!= 8
12987 || (GET_MODE_BITSIZE (mode
) != 32
12988 && GET_MODE_BITSIZE (mode
) != 64))
12991 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12992 VAR_INIT_STATUS_INITIALIZED
);
12997 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12999 VAR_INIT_STATUS_INITIALIZED
);
13002 add_loc_descr (&ret
, tmp
);
13003 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
13004 VAR_INIT_STATUS_INITIALIZED
);
13007 add_loc_descr (&ret
, tmp
);
13008 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
13009 add_loc_descr (&ret
, l1label
);
13010 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
13012 VAR_INIT_STATUS_INITIALIZED
);
13013 add_loc_descr (&ret
, tmp
);
13014 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
13015 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
13016 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
13017 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
13018 VAR_INIT_STATUS_INITIALIZED
);
13021 add_loc_descr (&ret
, tmp
);
13022 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
13023 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
13024 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13025 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
13026 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13027 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
13028 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
13029 VAR_INIT_STATUS_INITIALIZED
);
13030 add_loc_descr (&ret
, tmp
);
13031 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
13032 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
13033 add_loc_descr (&ret
, l2jump
);
13034 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
13035 VAR_INIT_STATUS_INITIALIZED
);
13036 add_loc_descr (&ret
, tmp
);
13037 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
13038 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13039 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
13040 add_loc_descr (&ret
, l1jump
);
13041 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
13042 add_loc_descr (&ret
, l2label
);
13043 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13044 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
13045 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13046 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
13047 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13048 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
13052 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
13053 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
13054 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
13055 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
13057 ROTATERT is similar:
13058 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
13059 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
13060 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
13062 static dw_loc_descr_ref
13063 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
13064 machine_mode mem_mode
)
13066 rtx rtlop1
= XEXP (rtl
, 1);
13067 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
13070 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13073 if (GET_MODE (rtlop1
) != VOIDmode
13074 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
13075 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
13076 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13077 VAR_INIT_STATUS_INITIALIZED
);
13078 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
13079 VAR_INIT_STATUS_INITIALIZED
);
13080 if (op0
== NULL
|| op1
== NULL
)
13082 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
13083 for (i
= 0; i
< 2; i
++)
13085 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
13086 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
13088 VAR_INIT_STATUS_INITIALIZED
);
13089 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
13090 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
13092 : HOST_BITS_PER_WIDE_INT
== 64
13093 ? DW_OP_const8u
: DW_OP_constu
,
13094 GET_MODE_MASK (mode
), 0);
13097 if (mask
[i
] == NULL
)
13099 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
13102 add_loc_descr (&ret
, op1
);
13103 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13104 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13105 if (GET_CODE (rtl
) == ROTATERT
)
13107 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13108 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
13109 GET_MODE_BITSIZE (mode
), 0));
13111 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13112 if (mask
[0] != NULL
)
13113 add_loc_descr (&ret
, mask
[0]);
13114 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
13115 if (mask
[1] != NULL
)
13117 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13118 add_loc_descr (&ret
, mask
[1]);
13119 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13121 if (GET_CODE (rtl
) == ROTATE
)
13123 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13124 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
13125 GET_MODE_BITSIZE (mode
), 0));
13127 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
13128 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
13132 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
13133 for DEBUG_PARAMETER_REF RTL. */
13135 static dw_loc_descr_ref
13136 parameter_ref_descriptor (rtx rtl
)
13138 dw_loc_descr_ref ret
;
13143 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
13144 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
13145 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
13148 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13149 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13150 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13154 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13155 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
13160 /* The following routine converts the RTL for a variable or parameter
13161 (resident in memory) into an equivalent Dwarf representation of a
13162 mechanism for getting the address of that same variable onto the top of a
13163 hypothetical "address evaluation" stack.
13165 When creating memory location descriptors, we are effectively transforming
13166 the RTL for a memory-resident object into its Dwarf postfix expression
13167 equivalent. This routine recursively descends an RTL tree, turning
13168 it into Dwarf postfix code as it goes.
13170 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
13172 MEM_MODE is the mode of the memory reference, needed to handle some
13173 autoincrement addressing modes.
13175 Return 0 if we can't represent the location. */
13178 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
13179 machine_mode mem_mode
,
13180 enum var_init_status initialized
)
13182 dw_loc_descr_ref mem_loc_result
= NULL
;
13183 enum dwarf_location_atom op
;
13184 dw_loc_descr_ref op0
, op1
;
13185 rtx inner
= NULL_RTX
;
13187 if (mode
== VOIDmode
)
13188 mode
= GET_MODE (rtl
);
13190 /* Note that for a dynamically sized array, the location we will generate a
13191 description of here will be the lowest numbered location which is
13192 actually within the array. That's *not* necessarily the same as the
13193 zeroth element of the array. */
13195 rtl
= targetm
.delegitimize_address (rtl
);
13197 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
13200 switch (GET_CODE (rtl
))
13205 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
13208 /* The case of a subreg may arise when we have a local (register)
13209 variable or a formal (register) parameter which doesn't quite fill
13210 up an entire register. For now, just assume that it is
13211 legitimate to make the Dwarf info refer to the whole register which
13212 contains the given subreg. */
13213 if (!subreg_lowpart_p (rtl
))
13215 inner
= SUBREG_REG (rtl
);
13217 if (inner
== NULL_RTX
)
13218 inner
= XEXP (rtl
, 0);
13219 if (GET_MODE_CLASS (mode
) == MODE_INT
13220 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
13221 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13222 #ifdef POINTERS_EXTEND_UNSIGNED
13223 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
13226 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
13228 mem_loc_result
= mem_loc_descriptor (inner
,
13230 mem_mode
, initialized
);
13235 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
13237 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
13238 && (GET_MODE_CLASS (mode
) != MODE_INT
13239 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
13243 dw_die_ref type_die
;
13244 dw_loc_descr_ref cvt
;
13246 mem_loc_result
= mem_loc_descriptor (inner
,
13248 mem_mode
, initialized
);
13249 if (mem_loc_result
== NULL
)
13251 type_die
= base_type_for_mode (mode
,
13252 GET_MODE_CLASS (mode
) == MODE_INT
);
13253 if (type_die
== NULL
)
13255 mem_loc_result
= NULL
;
13258 if (GET_MODE_SIZE (mode
)
13259 != GET_MODE_SIZE (GET_MODE (inner
)))
13260 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13262 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
13263 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13264 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13265 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13266 add_loc_descr (&mem_loc_result
, cvt
);
13267 if (GET_MODE_CLASS (mode
) == MODE_INT
13268 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13270 /* Convert it to untyped afterwards. */
13271 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13272 add_loc_descr (&mem_loc_result
, cvt
);
13278 if (GET_MODE_CLASS (mode
) != MODE_INT
13279 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
13280 && rtl
!= arg_pointer_rtx
13281 && rtl
!= frame_pointer_rtx
13282 #ifdef POINTERS_EXTEND_UNSIGNED
13283 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
13287 dw_die_ref type_die
;
13288 unsigned int dbx_regnum
;
13292 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
13294 type_die
= base_type_for_mode (mode
,
13295 GET_MODE_CLASS (mode
) == MODE_INT
);
13296 if (type_die
== NULL
)
13299 dbx_regnum
= dbx_reg_number (rtl
);
13300 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
13302 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
13304 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
13305 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
13306 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
13309 /* Whenever a register number forms a part of the description of the
13310 method for calculating the (dynamic) address of a memory resident
13311 object, DWARF rules require the register number be referred to as
13312 a "base register". This distinction is not based in any way upon
13313 what category of register the hardware believes the given register
13314 belongs to. This is strictly DWARF terminology we're dealing with
13315 here. Note that in cases where the location of a memory-resident
13316 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13317 OP_CONST (0)) the actual DWARF location descriptor that we generate
13318 may just be OP_BASEREG (basereg). This may look deceptively like
13319 the object in question was allocated to a register (rather than in
13320 memory) so DWARF consumers need to be aware of the subtle
13321 distinction between OP_REG and OP_BASEREG. */
13322 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
13323 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
13324 else if (stack_realign_drap
13326 && crtl
->args
.internal_arg_pointer
== rtl
13327 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
13329 /* If RTL is internal_arg_pointer, which has been optimized
13330 out, use DRAP instead. */
13331 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
13332 VAR_INIT_STATUS_INITIALIZED
);
13338 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13340 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13341 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13344 else if (GET_CODE (rtl
) == ZERO_EXTEND
13345 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13346 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13347 < HOST_BITS_PER_WIDE_INT
13348 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
13349 to expand zero extend as two shifts instead of
13351 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
13353 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
13354 mem_loc_result
= op0
;
13355 add_loc_descr (&mem_loc_result
,
13356 int_loc_descriptor (GET_MODE_MASK (imode
)));
13357 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
13359 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13361 int shift
= DWARF2_ADDR_SIZE
13362 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
13363 shift
*= BITS_PER_UNIT
;
13364 if (GET_CODE (rtl
) == SIGN_EXTEND
)
13368 mem_loc_result
= op0
;
13369 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13370 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13371 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13372 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13374 else if (!dwarf_strict
)
13376 dw_die_ref type_die1
, type_die2
;
13377 dw_loc_descr_ref cvt
;
13379 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
13380 GET_CODE (rtl
) == ZERO_EXTEND
);
13381 if (type_die1
== NULL
)
13383 type_die2
= base_type_for_mode (mode
, 1);
13384 if (type_die2
== NULL
)
13386 mem_loc_result
= op0
;
13387 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13388 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13389 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
13390 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13391 add_loc_descr (&mem_loc_result
, cvt
);
13392 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13393 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13394 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
13395 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13396 add_loc_descr (&mem_loc_result
, cvt
);
13402 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13403 if (new_rtl
!= rtl
)
13405 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
13407 if (mem_loc_result
!= NULL
)
13408 return mem_loc_result
;
13411 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
13412 get_address_mode (rtl
), mode
,
13413 VAR_INIT_STATUS_INITIALIZED
);
13414 if (mem_loc_result
== NULL
)
13415 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
13416 if (mem_loc_result
!= NULL
)
13418 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
13419 || GET_MODE_CLASS (mode
) != MODE_INT
)
13421 dw_die_ref type_die
;
13422 dw_loc_descr_ref deref
;
13427 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
13428 if (type_die
== NULL
)
13430 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
13431 GET_MODE_SIZE (mode
), 0);
13432 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
13433 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
13434 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
13435 add_loc_descr (&mem_loc_result
, deref
);
13437 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
13438 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
13440 add_loc_descr (&mem_loc_result
,
13441 new_loc_descr (DW_OP_deref_size
,
13442 GET_MODE_SIZE (mode
), 0));
13447 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
13450 /* Some ports can transform a symbol ref into a label ref, because
13451 the symbol ref is too far away and has to be dumped into a constant
13455 if ((GET_MODE_CLASS (mode
) != MODE_INT
13456 && GET_MODE_CLASS (mode
) != MODE_PARTIAL_INT
)
13457 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
13458 #ifdef POINTERS_EXTEND_UNSIGNED
13459 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
13463 if (GET_CODE (rtl
) == SYMBOL_REF
13464 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13466 dw_loc_descr_ref temp
;
13468 /* If this is not defined, we have no way to emit the data. */
13469 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
13472 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
13474 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
13475 add_loc_descr (&mem_loc_result
, temp
);
13480 if (!const_ok_for_output (rtl
))
13482 if (GET_CODE (rtl
) == CONST
)
13483 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13489 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13490 vec_safe_push (used_rtx_array
, rtl
);
13496 case DEBUG_IMPLICIT_PTR
:
13497 expansion_failed (NULL_TREE
, rtl
,
13498 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13504 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
13506 if (GET_MODE_CLASS (mode
) != MODE_INT
13507 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
13508 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
13509 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13512 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
13513 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
13515 op0
= one_reg_loc_descriptor (dbx_regnum
,
13516 VAR_INIT_STATUS_INITIALIZED
);
13519 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
13520 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
13522 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
13523 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13524 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
13528 gcc_unreachable ();
13531 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
13532 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13533 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
13536 case DEBUG_PARAMETER_REF
:
13537 mem_loc_result
= parameter_ref_descriptor (rtl
);
13541 /* Extract the PLUS expression nested inside and fall into
13542 PLUS code below. */
13543 rtl
= XEXP (rtl
, 1);
13548 /* Turn these into a PLUS expression and fall into the PLUS code
13550 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
13551 gen_int_mode (GET_CODE (rtl
) == PRE_INC
13552 ? GET_MODE_UNIT_SIZE (mem_mode
)
13553 : -GET_MODE_UNIT_SIZE (mem_mode
),
13556 /* ... fall through ... */
13560 if (is_based_loc (rtl
)
13561 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13562 || XEXP (rtl
, 0) == arg_pointer_rtx
13563 || XEXP (rtl
, 0) == frame_pointer_rtx
)
13564 && GET_MODE_CLASS (mode
) == MODE_INT
)
13565 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
13566 INTVAL (XEXP (rtl
, 1)),
13567 VAR_INIT_STATUS_INITIALIZED
);
13570 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13571 VAR_INIT_STATUS_INITIALIZED
);
13572 if (mem_loc_result
== 0)
13575 if (CONST_INT_P (XEXP (rtl
, 1))
13576 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13577 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
13580 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13581 VAR_INIT_STATUS_INITIALIZED
);
13584 add_loc_descr (&mem_loc_result
, op1
);
13585 add_loc_descr (&mem_loc_result
,
13586 new_loc_descr (DW_OP_plus
, 0, 0));
13591 /* If a pseudo-reg is optimized away, it is possible for it to
13592 be replaced with a MEM containing a multiply or shift. */
13603 && GET_MODE_CLASS (mode
) == MODE_INT
13604 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
13606 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13607 base_type_for_mode (mode
, 0),
13631 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13633 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13634 VAR_INIT_STATUS_INITIALIZED
);
13636 rtx rtlop1
= XEXP (rtl
, 1);
13637 if (GET_MODE (rtlop1
) != VOIDmode
13638 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
13639 < GET_MODE_BITSIZE (mode
))
13640 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
13641 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
13642 VAR_INIT_STATUS_INITIALIZED
);
13645 if (op0
== 0 || op1
== 0)
13648 mem_loc_result
= op0
;
13649 add_loc_descr (&mem_loc_result
, op1
);
13650 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13666 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13667 VAR_INIT_STATUS_INITIALIZED
);
13668 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13669 VAR_INIT_STATUS_INITIALIZED
);
13671 if (op0
== 0 || op1
== 0)
13674 mem_loc_result
= op0
;
13675 add_loc_descr (&mem_loc_result
, op1
);
13676 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13680 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
13682 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
13683 base_type_for_mode (mode
, 0),
13688 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13689 VAR_INIT_STATUS_INITIALIZED
);
13690 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13691 VAR_INIT_STATUS_INITIALIZED
);
13693 if (op0
== 0 || op1
== 0)
13696 mem_loc_result
= op0
;
13697 add_loc_descr (&mem_loc_result
, op1
);
13698 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13699 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13700 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
13701 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13702 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
13706 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
13708 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
13713 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13714 base_type_for_mode (mode
, 1),
13732 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13733 VAR_INIT_STATUS_INITIALIZED
);
13738 mem_loc_result
= op0
;
13739 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13743 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13744 #ifdef POINTERS_EXTEND_UNSIGNED
13746 && mem_mode
!= VOIDmode
13747 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
13751 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13755 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
13756 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
13758 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
13759 machine_mode amode
;
13760 if (type_die
== NULL
)
13762 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
13764 if (INTVAL (rtl
) >= 0
13765 && amode
!= BLKmode
13766 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
13767 /* const DW_OP_GNU_convert <XXX> vs.
13768 DW_OP_GNU_const_type <XXX, 1, const>. */
13769 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
13770 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
13772 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13773 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13774 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13775 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13776 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13777 add_loc_descr (&mem_loc_result
, op0
);
13778 return mem_loc_result
;
13780 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
13782 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13783 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13784 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13785 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
13786 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13789 mem_loc_result
->dw_loc_oprnd2
.val_class
13790 = dw_val_class_const_double
;
13791 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13792 = double_int::from_shwi (INTVAL (rtl
));
13800 dw_die_ref type_die
;
13802 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
13803 CONST_DOUBLE rtx could represent either a large integer
13804 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
13805 the value is always a floating point constant.
13807 When it is an integer, a CONST_DOUBLE is used whenever
13808 the constant requires 2 HWIs to be adequately represented.
13809 We output CONST_DOUBLEs as blocks. */
13810 if (mode
== VOIDmode
13811 || (GET_MODE (rtl
) == VOIDmode
13812 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
13814 type_die
= base_type_for_mode (mode
,
13815 GET_MODE_CLASS (mode
) == MODE_INT
);
13816 if (type_die
== NULL
)
13818 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13819 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13820 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13821 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13822 #if TARGET_SUPPORTS_WIDE_INT == 0
13823 if (!SCALAR_FLOAT_MODE_P (mode
))
13825 mem_loc_result
->dw_loc_oprnd2
.val_class
13826 = dw_val_class_const_double
;
13827 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13828 = rtx_to_double_int (rtl
);
13833 unsigned int length
= GET_MODE_SIZE (mode
);
13834 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13836 insert_float (rtl
, array
);
13837 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13838 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13839 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13840 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13845 case CONST_WIDE_INT
:
13848 dw_die_ref type_die
;
13850 type_die
= base_type_for_mode (mode
,
13851 GET_MODE_CLASS (mode
) == MODE_INT
);
13852 if (type_die
== NULL
)
13854 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13855 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13856 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13857 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13858 mem_loc_result
->dw_loc_oprnd2
.val_class
13859 = dw_val_class_wide_int
;
13860 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13861 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13866 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
13870 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13874 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13878 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13882 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13886 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
13890 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13894 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13898 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13902 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13907 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13912 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
13917 if (CONST_INT_P (XEXP (rtl
, 1))
13918 && CONST_INT_P (XEXP (rtl
, 2))
13919 && ((unsigned) INTVAL (XEXP (rtl
, 1))
13920 + (unsigned) INTVAL (XEXP (rtl
, 2))
13921 <= GET_MODE_BITSIZE (mode
))
13922 && GET_MODE_CLASS (mode
) == MODE_INT
13923 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13924 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
13927 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13928 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13931 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
13935 mem_loc_result
= op0
;
13936 size
= INTVAL (XEXP (rtl
, 1));
13937 shift
= INTVAL (XEXP (rtl
, 2));
13938 if (BITS_BIG_ENDIAN
)
13939 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13941 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
13943 add_loc_descr (&mem_loc_result
,
13944 int_loc_descriptor (DWARF2_ADDR_SIZE
13946 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13948 if (size
!= (int) DWARF2_ADDR_SIZE
)
13950 add_loc_descr (&mem_loc_result
,
13951 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
13952 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13959 dw_loc_descr_ref op2
, bra_node
, drop_node
;
13960 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
13961 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
13962 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
13963 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13964 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13965 VAR_INIT_STATUS_INITIALIZED
);
13966 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
13967 VAR_INIT_STATUS_INITIALIZED
);
13968 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
13971 mem_loc_result
= op1
;
13972 add_loc_descr (&mem_loc_result
, op2
);
13973 add_loc_descr (&mem_loc_result
, op0
);
13974 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13975 add_loc_descr (&mem_loc_result
, bra_node
);
13976 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
13977 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
13978 add_loc_descr (&mem_loc_result
, drop_node
);
13979 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13980 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
13985 case FLOAT_TRUNCATE
:
13987 case UNSIGNED_FLOAT
:
13992 dw_die_ref type_die
;
13993 dw_loc_descr_ref cvt
;
13995 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13996 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13999 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
14000 && (GET_CODE (rtl
) == FLOAT
14001 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
14002 <= DWARF2_ADDR_SIZE
))
14004 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
14005 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
14006 if (type_die
== NULL
)
14008 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
14009 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14010 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14011 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14012 add_loc_descr (&op0
, cvt
);
14014 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
14015 if (type_die
== NULL
)
14017 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
14018 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14019 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14020 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14021 add_loc_descr (&op0
, cvt
);
14022 if (GET_MODE_CLASS (mode
) == MODE_INT
14023 && (GET_CODE (rtl
) == FIX
14024 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
14026 op0
= convert_descriptor_to_mode (mode
, op0
);
14030 mem_loc_result
= op0
;
14037 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
14042 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
14046 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
14051 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
14055 /* In theory, we could implement the above. */
14056 /* DWARF cannot represent the unsigned compare operations
14081 case FRACT_CONVERT
:
14082 case UNSIGNED_FRACT_CONVERT
:
14084 case UNSIGNED_SAT_FRACT
:
14090 case VEC_DUPLICATE
:
14094 case STRICT_LOW_PART
:
14099 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14100 can't express it in the debug info. This can happen e.g. with some
14105 resolve_one_addr (&rtl
);
14111 print_rtl (stderr
, rtl
);
14112 gcc_unreachable ();
14117 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14118 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14120 return mem_loc_result
;
14123 /* Return a descriptor that describes the concatenation of two locations.
14124 This is typically a complex variable. */
14126 static dw_loc_descr_ref
14127 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
14129 dw_loc_descr_ref cc_loc_result
= NULL
;
14130 dw_loc_descr_ref x0_ref
14131 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14132 dw_loc_descr_ref x1_ref
14133 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14135 if (x0_ref
== 0 || x1_ref
== 0)
14138 cc_loc_result
= x0_ref
;
14139 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
14141 add_loc_descr (&cc_loc_result
, x1_ref
);
14142 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
14144 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14145 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14147 return cc_loc_result
;
14150 /* Return a descriptor that describes the concatenation of N
14153 static dw_loc_descr_ref
14154 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
14157 dw_loc_descr_ref cc_loc_result
= NULL
;
14158 unsigned int n
= XVECLEN (concatn
, 0);
14160 for (i
= 0; i
< n
; ++i
)
14162 dw_loc_descr_ref ref
;
14163 rtx x
= XVECEXP (concatn
, 0, i
);
14165 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14169 add_loc_descr (&cc_loc_result
, ref
);
14170 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
14173 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14174 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14176 return cc_loc_result
;
14179 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14180 for DEBUG_IMPLICIT_PTR RTL. */
14182 static dw_loc_descr_ref
14183 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
14185 dw_loc_descr_ref ret
;
14190 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
14191 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
14192 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
14193 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
14194 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
14195 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
14198 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14199 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14200 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14204 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14205 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
14210 /* Output a proper Dwarf location descriptor for a variable or parameter
14211 which is either allocated in a register or in a memory location. For a
14212 register, we just generate an OP_REG and the register number. For a
14213 memory location we provide a Dwarf postfix expression describing how to
14214 generate the (dynamic) address of the object onto the address stack.
14216 MODE is mode of the decl if this loc_descriptor is going to be used in
14217 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14218 allowed, VOIDmode otherwise.
14220 If we don't know how to describe it, return 0. */
14222 static dw_loc_descr_ref
14223 loc_descriptor (rtx rtl
, machine_mode mode
,
14224 enum var_init_status initialized
)
14226 dw_loc_descr_ref loc_result
= NULL
;
14228 switch (GET_CODE (rtl
))
14231 /* The case of a subreg may arise when we have a local (register)
14232 variable or a formal (register) parameter which doesn't quite fill
14233 up an entire register. For now, just assume that it is
14234 legitimate to make the Dwarf info refer to the whole register which
14235 contains the given subreg. */
14236 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
14237 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
14238 GET_MODE (SUBREG_REG (rtl
)), initialized
);
14244 loc_result
= reg_loc_descriptor (rtl
, initialized
);
14248 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
14249 GET_MODE (rtl
), initialized
);
14250 if (loc_result
== NULL
)
14251 loc_result
= tls_mem_loc_descriptor (rtl
);
14252 if (loc_result
== NULL
)
14254 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14255 if (new_rtl
!= rtl
)
14256 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
14261 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
14266 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
14271 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
14273 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
14274 if (GET_CODE (loc
) == EXPR_LIST
)
14275 loc
= XEXP (loc
, 0);
14276 loc_result
= loc_descriptor (loc
, mode
, initialized
);
14280 rtl
= XEXP (rtl
, 1);
14285 rtvec par_elems
= XVEC (rtl
, 0);
14286 int num_elem
= GET_NUM_ELEM (par_elems
);
14290 /* Create the first one, so we have something to add to. */
14291 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
14292 VOIDmode
, initialized
);
14293 if (loc_result
== NULL
)
14295 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
14296 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14297 for (i
= 1; i
< num_elem
; i
++)
14299 dw_loc_descr_ref temp
;
14301 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
14302 VOIDmode
, initialized
);
14305 add_loc_descr (&loc_result
, temp
);
14306 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
14307 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14313 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
14314 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
14319 if (mode
== VOIDmode
)
14320 mode
= GET_MODE (rtl
);
14322 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14324 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14326 /* Note that a CONST_DOUBLE rtx could represent either an integer
14327 or a floating-point constant. A CONST_DOUBLE is used whenever
14328 the constant requires more than one word in order to be
14329 adequately represented. We output CONST_DOUBLEs as blocks. */
14330 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14331 GET_MODE_SIZE (mode
), 0);
14332 #if TARGET_SUPPORTS_WIDE_INT == 0
14333 if (!SCALAR_FLOAT_MODE_P (mode
))
14335 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
14336 loc_result
->dw_loc_oprnd2
.v
.val_double
14337 = rtx_to_double_int (rtl
);
14342 unsigned int length
= GET_MODE_SIZE (mode
);
14343 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
14345 insert_float (rtl
, array
);
14346 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14347 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
14348 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
14349 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14354 case CONST_WIDE_INT
:
14355 if (mode
== VOIDmode
)
14356 mode
= GET_MODE (rtl
);
14358 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14360 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14361 GET_MODE_SIZE (mode
), 0);
14362 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
14363 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
14364 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
14369 if (mode
== VOIDmode
)
14370 mode
= GET_MODE (rtl
);
14372 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14374 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
14375 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14376 unsigned char *array
14377 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
14380 machine_mode imode
= GET_MODE_INNER (mode
);
14382 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14383 switch (GET_MODE_CLASS (mode
))
14385 case MODE_VECTOR_INT
:
14386 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14388 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14389 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
14393 case MODE_VECTOR_FLOAT
:
14394 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14396 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14397 insert_float (elt
, p
);
14402 gcc_unreachable ();
14405 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14406 length
* elt_size
, 0);
14407 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14408 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
14409 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
14410 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14415 if (mode
== VOIDmode
14416 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
14417 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
14418 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
14420 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
14425 if (!const_ok_for_output (rtl
))
14428 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
14429 && (dwarf_version
>= 4 || !dwarf_strict
))
14431 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14432 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14433 vec_safe_push (used_rtx_array
, rtl
);
14437 case DEBUG_IMPLICIT_PTR
:
14438 loc_result
= implicit_ptr_descriptor (rtl
, 0);
14442 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
14443 && CONST_INT_P (XEXP (rtl
, 1)))
14446 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
14452 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
14453 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
14454 && dwarf_version
>= 4)
14455 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
14457 /* Value expression. */
14458 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
14460 add_loc_descr (&loc_result
,
14461 new_loc_descr (DW_OP_stack_value
, 0, 0));
14469 /* We need to figure out what section we should use as the base for the
14470 address ranges where a given location is valid.
14471 1. If this particular DECL has a section associated with it, use that.
14472 2. If this function has a section associated with it, use that.
14473 3. Otherwise, use the text section.
14474 XXX: If you split a variable across multiple sections, we won't notice. */
14476 static const char *
14477 secname_for_decl (const_tree decl
)
14479 const char *secname
;
14481 if (VAR_OR_FUNCTION_DECL_P (decl
)
14482 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
14483 && DECL_SECTION_NAME (decl
))
14484 secname
= DECL_SECTION_NAME (decl
);
14485 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
14486 secname
= DECL_SECTION_NAME (current_function_decl
);
14487 else if (cfun
&& in_cold_section_p
)
14488 secname
= crtl
->subsections
.cold_section_label
;
14490 secname
= text_section_label
;
14495 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14498 decl_by_reference_p (tree decl
)
14500 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
14501 || TREE_CODE (decl
) == VAR_DECL
)
14502 && DECL_BY_REFERENCE (decl
));
14505 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14508 static dw_loc_descr_ref
14509 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
14510 enum var_init_status initialized
)
14512 int have_address
= 0;
14513 dw_loc_descr_ref descr
;
14516 if (want_address
!= 2)
14518 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
14520 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14522 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14523 if (GET_CODE (varloc
) == EXPR_LIST
)
14524 varloc
= XEXP (varloc
, 0);
14525 mode
= GET_MODE (varloc
);
14526 if (MEM_P (varloc
))
14528 rtx addr
= XEXP (varloc
, 0);
14529 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
14530 mode
, initialized
);
14535 rtx x
= avoid_constant_pool_reference (varloc
);
14537 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
14542 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
14549 if (GET_CODE (varloc
) == VAR_LOCATION
)
14550 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
14552 mode
= DECL_MODE (loc
);
14553 descr
= loc_descriptor (varloc
, mode
, initialized
);
14560 if (want_address
== 2 && !have_address
14561 && (dwarf_version
>= 4 || !dwarf_strict
))
14563 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14565 expansion_failed (loc
, NULL_RTX
,
14566 "DWARF address size mismatch");
14569 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14572 /* Show if we can't fill the request for an address. */
14573 if (want_address
&& !have_address
)
14575 expansion_failed (loc
, NULL_RTX
,
14576 "Want address and only have value");
14580 /* If we've got an address and don't want one, dereference. */
14581 if (!want_address
&& have_address
)
14583 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14584 enum dwarf_location_atom op
;
14586 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14588 expansion_failed (loc
, NULL_RTX
,
14589 "DWARF address size mismatch");
14592 else if (size
== DWARF2_ADDR_SIZE
)
14595 op
= DW_OP_deref_size
;
14597 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
14603 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14604 if it is not possible. */
14606 static dw_loc_descr_ref
14607 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
14609 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
14610 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
14611 else if (dwarf_version
>= 3 || !dwarf_strict
)
14612 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
14617 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14618 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14620 static dw_loc_descr_ref
14621 dw_sra_loc_expr (tree decl
, rtx loc
)
14624 unsigned HOST_WIDE_INT padsize
= 0;
14625 dw_loc_descr_ref descr
, *descr_tail
;
14626 unsigned HOST_WIDE_INT decl_size
;
14628 enum var_init_status initialized
;
14630 if (DECL_SIZE (decl
) == NULL
14631 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
14634 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
14636 descr_tail
= &descr
;
14638 for (p
= loc
; p
; p
= XEXP (p
, 1))
14640 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
14641 rtx loc_note
= *decl_piece_varloc_ptr (p
);
14642 dw_loc_descr_ref cur_descr
;
14643 dw_loc_descr_ref
*tail
, last
= NULL
;
14644 unsigned HOST_WIDE_INT opsize
= 0;
14646 if (loc_note
== NULL_RTX
14647 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
14649 padsize
+= bitsize
;
14652 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
14653 varloc
= NOTE_VAR_LOCATION (loc_note
);
14654 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
14655 if (cur_descr
== NULL
)
14657 padsize
+= bitsize
;
14661 /* Check that cur_descr either doesn't use
14662 DW_OP_*piece operations, or their sum is equal
14663 to bitsize. Otherwise we can't embed it. */
14664 for (tail
= &cur_descr
; *tail
!= NULL
;
14665 tail
= &(*tail
)->dw_loc_next
)
14666 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
14668 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
14672 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
14674 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
14678 if (last
!= NULL
&& opsize
!= bitsize
)
14680 padsize
+= bitsize
;
14681 /* Discard the current piece of the descriptor and release any
14682 addr_table entries it uses. */
14683 remove_loc_list_addr_table_entries (cur_descr
);
14687 /* If there is a hole, add DW_OP_*piece after empty DWARF
14688 expression, which means that those bits are optimized out. */
14691 if (padsize
> decl_size
)
14693 remove_loc_list_addr_table_entries (cur_descr
);
14694 goto discard_descr
;
14696 decl_size
-= padsize
;
14697 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
14698 if (*descr_tail
== NULL
)
14700 remove_loc_list_addr_table_entries (cur_descr
);
14701 goto discard_descr
;
14703 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14706 *descr_tail
= cur_descr
;
14708 if (bitsize
> decl_size
)
14709 goto discard_descr
;
14710 decl_size
-= bitsize
;
14713 HOST_WIDE_INT offset
= 0;
14714 if (GET_CODE (varloc
) == VAR_LOCATION
14715 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14717 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14718 if (GET_CODE (varloc
) == EXPR_LIST
)
14719 varloc
= XEXP (varloc
, 0);
14723 if (GET_CODE (varloc
) == CONST
14724 || GET_CODE (varloc
) == SIGN_EXTEND
14725 || GET_CODE (varloc
) == ZERO_EXTEND
)
14726 varloc
= XEXP (varloc
, 0);
14727 else if (GET_CODE (varloc
) == SUBREG
)
14728 varloc
= SUBREG_REG (varloc
);
14733 /* DW_OP_bit_size offset should be zero for register
14734 or implicit location descriptions and empty location
14735 descriptions, but for memory addresses needs big endian
14737 if (MEM_P (varloc
))
14739 unsigned HOST_WIDE_INT memsize
14740 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
14741 if (memsize
!= bitsize
)
14743 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
14744 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
14745 goto discard_descr
;
14746 if (memsize
< bitsize
)
14747 goto discard_descr
;
14748 if (BITS_BIG_ENDIAN
)
14749 offset
= memsize
- bitsize
;
14753 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
14754 if (*descr_tail
== NULL
)
14755 goto discard_descr
;
14756 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14760 /* If there were any non-empty expressions, add padding till the end of
14762 if (descr
!= NULL
&& decl_size
!= 0)
14764 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
14765 if (*descr_tail
== NULL
)
14766 goto discard_descr
;
14771 /* Discard the descriptor and release any addr_table entries it uses. */
14772 remove_loc_list_addr_table_entries (descr
);
14776 /* Return the dwarf representation of the location list LOC_LIST of
14777 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14780 static dw_loc_list_ref
14781 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
14783 const char *endname
, *secname
;
14785 enum var_init_status initialized
;
14786 struct var_loc_node
*node
;
14787 dw_loc_descr_ref descr
;
14788 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
14789 dw_loc_list_ref list
= NULL
;
14790 dw_loc_list_ref
*listp
= &list
;
14792 /* Now that we know what section we are using for a base,
14793 actually construct the list of locations.
14794 The first location information is what is passed to the
14795 function that creates the location list, and the remaining
14796 locations just get added on to that list.
14797 Note that we only know the start address for a location
14798 (IE location changes), so to build the range, we use
14799 the range [current location start, next location start].
14800 This means we have to special case the last node, and generate
14801 a range of [last location start, end of function label]. */
14803 secname
= secname_for_decl (decl
);
14805 for (node
= loc_list
->first
; node
; node
= node
->next
)
14806 if (GET_CODE (node
->loc
) == EXPR_LIST
14807 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
14809 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14811 /* This requires DW_OP_{,bit_}piece, which is not usable
14812 inside DWARF expressions. */
14813 if (want_address
!= 2)
14815 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14821 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14822 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14823 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
14827 bool range_across_switch
= false;
14828 /* If section switch happens in between node->label
14829 and node->next->label (or end of function) and
14830 we can't emit it as a single entry list,
14831 emit two ranges, first one ending at the end
14832 of first partition and second one starting at the
14833 beginning of second partition. */
14834 if (node
== loc_list
->last_before_switch
14835 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
14836 && current_function_decl
)
14838 endname
= cfun
->fde
->dw_fde_end
;
14839 range_across_switch
= true;
14841 /* The variable has a location between NODE->LABEL and
14842 NODE->NEXT->LABEL. */
14843 else if (node
->next
)
14844 endname
= node
->next
->label
;
14845 /* If the variable has a location at the last label
14846 it keeps its location until the end of function. */
14847 else if (!current_function_decl
)
14848 endname
= text_end_label
;
14851 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
14852 current_function_funcdef_no
);
14853 endname
= ggc_strdup (label_id
);
14856 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
14857 if (TREE_CODE (decl
) == PARM_DECL
14858 && node
== loc_list
->first
14859 && NOTE_P (node
->loc
)
14860 && strcmp (node
->label
, endname
) == 0)
14861 (*listp
)->force
= true;
14862 listp
= &(*listp
)->dw_loc_next
;
14864 if (range_across_switch
)
14866 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14867 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14870 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14871 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14872 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
14875 gcc_assert (descr
);
14876 /* The variable has a location between NODE->LABEL and
14877 NODE->NEXT->LABEL. */
14879 endname
= node
->next
->label
;
14881 endname
= cfun
->fde
->dw_fde_second_end
;
14882 *listp
= new_loc_list (descr
,
14883 cfun
->fde
->dw_fde_second_begin
,
14885 listp
= &(*listp
)->dw_loc_next
;
14890 /* Try to avoid the overhead of a location list emitting a location
14891 expression instead, but only if we didn't have more than one
14892 location entry in the first place. If some entries were not
14893 representable, we don't want to pretend a single entry that was
14894 applies to the entire scope in which the variable is
14896 if (list
&& loc_list
->first
->next
)
14902 /* Return if the loc_list has only single element and thus can be represented
14903 as location description. */
14906 single_element_loc_list_p (dw_loc_list_ref list
)
14908 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
14909 return !list
->ll_symbol
;
14912 /* To each location in list LIST add loc descr REF. */
14915 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
14917 dw_loc_descr_ref copy
;
14918 add_loc_descr (&list
->expr
, ref
);
14919 list
= list
->dw_loc_next
;
14922 copy
= ggc_alloc
<dw_loc_descr_node
> ();
14923 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
14924 add_loc_descr (&list
->expr
, copy
);
14925 while (copy
->dw_loc_next
)
14927 dw_loc_descr_ref new_copy
= ggc_alloc
<dw_loc_descr_node
> ();
14928 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
14929 copy
->dw_loc_next
= new_copy
;
14932 list
= list
->dw_loc_next
;
14936 /* Given two lists RET and LIST
14937 produce location list that is result of adding expression in LIST
14938 to expression in RET on each position in program.
14939 Might be destructive on both RET and LIST.
14941 TODO: We handle only simple cases of RET or LIST having at most one
14942 element. General case would inolve sorting the lists in program order
14943 and merging them that will need some additional work.
14944 Adding that will improve quality of debug info especially for SRA-ed
14948 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
14957 if (!list
->dw_loc_next
)
14959 add_loc_descr_to_each (*ret
, list
->expr
);
14962 if (!(*ret
)->dw_loc_next
)
14964 add_loc_descr_to_each (list
, (*ret
)->expr
);
14968 expansion_failed (NULL_TREE
, NULL_RTX
,
14969 "Don't know how to merge two non-trivial"
14970 " location lists.\n");
14975 /* LOC is constant expression. Try a luck, look it up in constant
14976 pool and return its loc_descr of its address. */
14978 static dw_loc_descr_ref
14979 cst_pool_loc_descr (tree loc
)
14981 /* Get an RTL for this, if something has been emitted. */
14982 rtx rtl
= lookup_constant_def (loc
);
14984 if (!rtl
|| !MEM_P (rtl
))
14989 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
14991 /* TODO: We might get more coverage if we was actually delaying expansion
14992 of all expressions till end of compilation when constant pools are fully
14994 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
14996 expansion_failed (loc
, NULL_RTX
,
14997 "CST value in contant pool but not marked.");
15000 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
15001 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
15004 /* Return dw_loc_list representing address of addr_expr LOC
15005 by looking for inner INDIRECT_REF expression and turning
15006 it into simple arithmetics.
15008 See loc_list_from_tree for the meaning of CONTEXT. */
15010 static dw_loc_list_ref
15011 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
15012 const loc_descr_context
*context
)
15015 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
15017 int unsignedp
, reversep
, volatilep
= 0;
15018 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
15020 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
15021 &bitsize
, &bitpos
, &offset
, &mode
,
15022 &unsignedp
, &reversep
, &volatilep
, false);
15024 if (bitpos
% BITS_PER_UNIT
)
15026 expansion_failed (loc
, NULL_RTX
, "bitfield access");
15029 if (!INDIRECT_REF_P (obj
))
15031 expansion_failed (obj
,
15032 NULL_RTX
, "no indirect ref in inner refrence");
15035 if (!offset
&& !bitpos
)
15036 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
15039 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
15040 && (dwarf_version
>= 4 || !dwarf_strict
))
15042 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
15047 /* Variable offset. */
15048 list_ret1
= loc_list_from_tree (offset
, 0, context
);
15049 if (list_ret1
== 0)
15051 add_loc_list (&list_ret
, list_ret1
);
15054 add_loc_descr_to_each (list_ret
,
15055 new_loc_descr (DW_OP_plus
, 0, 0));
15057 bytepos
= bitpos
/ BITS_PER_UNIT
;
15059 add_loc_descr_to_each (list_ret
,
15060 new_loc_descr (DW_OP_plus_uconst
,
15062 else if (bytepos
< 0)
15063 loc_list_plus_const (list_ret
, bytepos
);
15064 add_loc_descr_to_each (list_ret
,
15065 new_loc_descr (DW_OP_stack_value
, 0, 0));
15070 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
15071 all operations from LOC are nops, move to the last one. Insert in NOPS all
15072 operations that are skipped. */
15075 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
15076 hash_set
<dw_loc_descr_ref
> &nops
)
15078 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
15081 loc
= loc
->dw_loc_next
;
15085 /* Helper for loc_descr_without_nops: free the location description operation
15089 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
15095 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
15099 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
15101 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
15104 /* Set of all DW_OP_nop operations we remove. */
15105 hash_set
<dw_loc_descr_ref
> nops
;
15107 /* First, strip all prefix NOP operations in order to keep the head of the
15108 operations list. */
15109 loc_descr_to_next_no_nop (loc
, nops
);
15111 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
15113 /* For control flow operations: strip "prefix" nops in destination
15115 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
15116 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
15117 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
15118 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
15120 /* Do the same for the operations that follow, then move to the next
15122 if (cur
->dw_loc_next
!= NULL
)
15123 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
15124 cur
= cur
->dw_loc_next
;
15127 nops
.traverse
<void *, free_loc_descr
> (NULL
);
15131 struct dwarf_procedure_info
;
15133 /* Helper structure for location descriptions generation. */
15134 struct loc_descr_context
15136 /* The type that is implicitly referenced by DW_OP_push_object_address, or
15137 NULL_TREE if DW_OP_push_object_address in invalid for this location
15138 description. This is used when processing PLACEHOLDER_EXPR nodes. */
15140 /* The ..._DECL node that should be translated as a
15141 DW_OP_push_object_address operation. */
15143 /* Information about the DWARF procedure we are currently generating. NULL if
15144 we are not generating a DWARF procedure. */
15145 struct dwarf_procedure_info
*dpi
;
15148 /* DWARF procedures generation
15150 DWARF expressions (aka. location descriptions) are used to encode variable
15151 things such as sizes or offsets. Such computations can have redundant parts
15152 that can be factorized in order to reduce the size of the output debug
15153 information. This is the whole point of DWARF procedures.
15155 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
15156 already factorized into functions ("size functions") in order to handle very
15157 big and complex types. Such functions are quite simple: they have integral
15158 arguments, they return an integral result and their body contains only a
15159 return statement with arithmetic expressions. This is the only kind of
15160 function we are interested in translating into DWARF procedures, here.
15162 DWARF expressions and DWARF procedure are executed using a stack, so we have
15163 to define some calling convention for them to interact. Let's say that:
15165 - Before calling a DWARF procedure, DWARF expressions must push on the stack
15166 all arguments in reverse order (right-to-left) so that when the DWARF
15167 procedure execution starts, the first argument is the top of the stack.
15169 - Then, when returning, the DWARF procedure must have consumed all arguments
15170 on the stack, must have pushed the result and touched nothing else.
15172 - Each integral argument and the result are integral types can be hold in a
15175 - We call "frame offset" the number of stack slots that are "under DWARF
15176 procedure control": it includes the arguments slots, the temporaries and
15177 the result slot. Thus, it is equal to the number of arguments when the
15178 procedure execution starts and must be equal to one (the result) when it
15181 /* Helper structure used when generating operations for a DWARF procedure. */
15182 struct dwarf_procedure_info
15184 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
15185 currently translated. */
15187 /* The number of arguments FNDECL takes. */
15188 unsigned args_count
;
15191 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
15192 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
15193 equate it to this DIE. */
15196 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
15197 dw_die_ref parent_die
)
15199 const bool dwarf_proc_supported
= dwarf_version
>= 4;
15200 dw_die_ref dwarf_proc_die
;
15202 if ((dwarf_version
< 3 && dwarf_strict
)
15203 || location
== NULL
)
15206 dwarf_proc_die
= new_die (dwarf_proc_supported
15207 ? DW_TAG_dwarf_procedure
15212 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
15213 if (!dwarf_proc_supported
)
15214 add_AT_flag (dwarf_proc_die
, DW_AT_artificial
, 1);
15215 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
15216 return dwarf_proc_die
;
15219 /* Return whether TYPE is a supported type as a DWARF procedure argument
15220 type or return type (we handle only scalar types and pointer types that
15221 aren't wider than the DWARF expression evaluation stack. */
15224 is_handled_procedure_type (tree type
)
15226 return ((INTEGRAL_TYPE_P (type
)
15227 || TREE_CODE (type
) == OFFSET_TYPE
15228 || TREE_CODE (type
) == POINTER_TYPE
)
15229 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
15232 /* Helper for resolve_args_picking. Stop when coming across VISITED nodes. */
15235 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
15236 struct dwarf_procedure_info
*dpi
,
15237 hash_set
<dw_loc_descr_ref
> &visited
)
15239 /* The "frame_offset" identifier is already used to name a macro... */
15240 unsigned frame_offset_
= initial_frame_offset
;
15241 dw_loc_descr_ref l
;
15243 for (l
= loc
; l
!= NULL
;)
15245 /* If we already met this node, there is nothing to compute anymore. */
15246 if (visited
.add (l
))
15248 #if ENABLE_CHECKING
15249 /* Make sure that the stack size is consistent wherever the execution
15250 flow comes from. */
15251 gcc_assert ((unsigned) l
->dw_loc_frame_offset
== frame_offset_
);
15255 #if ENABLE_CHECKING
15256 l
->dw_loc_frame_offset
= frame_offset_
;
15259 /* If needed, relocate the picking offset with respect to the frame
15261 if (l
->dw_loc_opc
== DW_OP_pick
&& l
->frame_offset_rel
)
15263 /* frame_offset_ is the size of the current stack frame, including
15264 incoming arguments. Besides, the arguments are pushed
15265 right-to-left. Thus, in order to access the Nth argument from
15266 this operation node, the picking has to skip temporaries *plus*
15267 one stack slot per argument (0 for the first one, 1 for the second
15270 The targetted argument number (N) is already set as the operand,
15271 and the number of temporaries can be computed with:
15272 frame_offsets_ - dpi->args_count */
15273 l
->dw_loc_oprnd1
.v
.val_unsigned
+= frame_offset_
- dpi
->args_count
;
15275 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
15276 if (l
->dw_loc_oprnd1
.v
.val_unsigned
> 255)
15280 /* Update frame_offset according to the effect the current operation has
15282 switch (l
->dw_loc_opc
)
15289 case DW_OP_plus_uconst
:
15325 case DW_OP_deref_size
:
15327 case DW_OP_form_tls_address
:
15328 case DW_OP_bit_piece
:
15329 case DW_OP_implicit_value
:
15330 case DW_OP_stack_value
:
15334 case DW_OP_const1u
:
15335 case DW_OP_const1s
:
15336 case DW_OP_const2u
:
15337 case DW_OP_const2s
:
15338 case DW_OP_const4u
:
15339 case DW_OP_const4s
:
15340 case DW_OP_const8u
:
15341 case DW_OP_const8s
:
15412 case DW_OP_push_object_address
:
15413 case DW_OP_call_frame_cfa
:
15439 case DW_OP_xderef_size
:
15445 case DW_OP_call_ref
:
15447 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
15448 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
15450 if (stack_usage
== NULL
)
15452 frame_offset
+= *stack_usage
;
15456 case DW_OP_GNU_push_tls_address
:
15457 case DW_OP_GNU_uninit
:
15458 case DW_OP_GNU_encoded_addr
:
15459 case DW_OP_GNU_implicit_pointer
:
15460 case DW_OP_GNU_entry_value
:
15461 case DW_OP_GNU_const_type
:
15462 case DW_OP_GNU_regval_type
:
15463 case DW_OP_GNU_deref_type
:
15464 case DW_OP_GNU_convert
:
15465 case DW_OP_GNU_reinterpret
:
15466 case DW_OP_GNU_parameter_ref
:
15467 /* loc_list_from_tree will probably not output these operations for
15468 size functions, so assume they will not appear here. */
15469 /* Fall through... */
15472 gcc_unreachable ();
15475 /* Now, follow the control flow (except subroutine calls). */
15476 switch (l
->dw_loc_opc
)
15479 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
15482 /* Fall through... */
15485 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
15488 case DW_OP_stack_value
:
15492 l
= l
->dw_loc_next
;
15500 /* Make a DFS over operations reachable through LOC (i.e. follow branch
15501 operations) in order to resolve the operand of DW_OP_pick operations that
15502 target DWARF procedure arguments (DPI). Stop at already visited nodes.
15503 INITIAL_FRAME_OFFSET is the frame offset *before* LOC is executed. Return
15504 if all relocations were successful. */
15507 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
15508 struct dwarf_procedure_info
*dpi
)
15510 hash_set
<dw_loc_descr_ref
> visited
;
15512 return resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
, visited
);
15515 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
15516 Return NULL if it is not possible. */
15519 function_to_dwarf_procedure (tree fndecl
)
15521 struct loc_descr_context ctx
;
15522 struct dwarf_procedure_info dpi
;
15523 dw_die_ref dwarf_proc_die
;
15524 tree tree_body
= DECL_SAVED_TREE (fndecl
);
15525 dw_loc_descr_ref loc_body
, epilogue
;
15530 /* Do not generate multiple DWARF procedures for the same function
15532 dwarf_proc_die
= lookup_decl_die (fndecl
);
15533 if (dwarf_proc_die
!= NULL
)
15534 return dwarf_proc_die
;
15536 /* DWARF procedures are available starting with the DWARFv3 standard, but
15537 it's the DWARFv4 standard that introduces the DW_TAG_dwarf_procedure
15539 if (dwarf_version
< 3 && dwarf_strict
)
15542 /* We handle only functions for which we still have a body, that return a
15543 supported type and that takes arguments with supported types. Note that
15544 there is no point translating functions that return nothing. */
15545 if (tree_body
== NULL_TREE
15546 || DECL_RESULT (fndecl
) == NULL_TREE
15547 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
15550 for (cursor
= DECL_ARGUMENTS (fndecl
);
15551 cursor
!= NULL_TREE
;
15552 cursor
= TREE_CHAIN (cursor
))
15553 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
15556 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
15557 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
15559 tree_body
= TREE_OPERAND (tree_body
, 0);
15560 if (TREE_CODE (tree_body
) != MODIFY_EXPR
15561 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
15563 tree_body
= TREE_OPERAND (tree_body
, 1);
15565 /* Try to translate the body expression itself. Note that this will probably
15566 cause an infinite recursion if its call graph has a cycle. This is very
15567 unlikely for size functions, however, so don't bother with such things at
15569 ctx
.context_type
= NULL_TREE
;
15570 ctx
.base_decl
= NULL_TREE
;
15572 dpi
.fndecl
= fndecl
;
15573 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
15574 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
15578 /* After evaluating all operands in "loc_body", we should still have on the
15579 stack all arguments plus the desired function result (top of the stack).
15580 Generate code in order to keep only the result in our stack frame. */
15582 for (i
= 0; i
< dpi
.args_count
; ++i
)
15584 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
15585 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
15586 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
15587 epilogue
= op_couple
;
15589 add_loc_descr (&loc_body
, epilogue
);
15590 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
15593 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
15594 because they are considered useful. Now there is an epilogue, they are
15595 not anymore, so give it another try. */
15596 loc_descr_without_nops (loc_body
);
15598 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
15599 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
15600 though, given that size functions do not come from source, so they should
15601 not have a dedicated DW_TAG_subprogram DIE. */
15603 = new_dwarf_proc_die (loc_body
, fndecl
,
15604 get_context_die (DECL_CONTEXT (fndecl
)));
15606 /* The called DWARF procedure consumes one stack slot per argument and
15607 returns one stack slot. */
15608 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
15610 return dwarf_proc_die
;
15614 /* Generate Dwarf location list representing LOC.
15615 If WANT_ADDRESS is false, expression computing LOC will be computed
15616 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15617 if WANT_ADDRESS is 2, expression computing address useable in location
15618 will be returned (i.e. DW_OP_reg can be used
15619 to refer to register values).
15621 CONTEXT provides information to customize the location descriptions
15622 generation. Its context_type field specifies what type is implicitly
15623 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
15624 will not be generated.
15626 Its DPI field determines whether we are generating a DWARF expression for a
15627 DWARF procedure, so PARM_DECL references are processed specifically.
15629 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
15630 and dpi fields were null. */
15632 static dw_loc_list_ref
15633 loc_list_from_tree_1 (tree loc
, int want_address
,
15634 const struct loc_descr_context
*context
)
15636 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
15637 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
15638 int have_address
= 0;
15639 enum dwarf_location_atom op
;
15641 /* ??? Most of the time we do not take proper care for sign/zero
15642 extending the values properly. Hopefully this won't be a real
15645 if (context
!= NULL
15646 && context
->base_decl
== loc
15647 && want_address
== 0)
15649 if (dwarf_version
>= 3 || !dwarf_strict
)
15650 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
15656 switch (TREE_CODE (loc
))
15659 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
15662 case PLACEHOLDER_EXPR
:
15663 /* This case involves extracting fields from an object to determine the
15664 position of other fields. It is supposed to appear only as the first
15665 operand of COMPONENT_REF nodes and to reference precisely the type
15666 that the context allows. */
15667 if (context
!= NULL
15668 && TREE_TYPE (loc
) == context
->context_type
15669 && want_address
>= 1)
15671 if (dwarf_version
>= 3 || !dwarf_strict
)
15673 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
15681 expansion_failed (loc
, NULL_RTX
,
15682 "PLACEHOLDER_EXPR for an unexpected type");
15687 const int nargs
= call_expr_nargs (loc
);
15688 tree callee
= get_callee_fndecl (loc
);
15690 dw_die_ref dwarf_proc
;
15692 if (callee
== NULL_TREE
)
15693 goto call_expansion_failed
;
15695 /* We handle only functions that return an integer. */
15696 if (!is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
))))
15697 goto call_expansion_failed
;
15699 dwarf_proc
= function_to_dwarf_procedure (callee
);
15700 if (dwarf_proc
== NULL
)
15701 goto call_expansion_failed
;
15703 /* Evaluate arguments right-to-left so that the first argument will
15704 be the top-most one on the stack. */
15705 for (i
= nargs
- 1; i
>= 0; --i
)
15707 dw_loc_descr_ref loc_descr
15708 = loc_descriptor_from_tree (CALL_EXPR_ARG (loc
, i
), 0,
15711 if (loc_descr
== NULL
)
15712 goto call_expansion_failed
;
15714 add_loc_descr (&ret
, loc_descr
);
15717 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
15718 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15719 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
15720 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15721 add_loc_descr (&ret
, ret1
);
15724 call_expansion_failed
:
15725 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
15726 /* There are no opcodes for these operations. */
15730 case PREINCREMENT_EXPR
:
15731 case PREDECREMENT_EXPR
:
15732 case POSTINCREMENT_EXPR
:
15733 case POSTDECREMENT_EXPR
:
15734 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
15735 /* There are no opcodes for these operations. */
15739 /* If we already want an address, see if there is INDIRECT_REF inside
15740 e.g. for &this->field. */
15743 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
15744 (loc
, want_address
== 2, context
);
15747 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
15748 && (ret
= cst_pool_loc_descr (loc
)))
15751 /* Otherwise, process the argument and look for the address. */
15752 if (!list_ret
&& !ret
)
15753 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
15757 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
15763 if (DECL_THREAD_LOCAL_P (loc
))
15766 enum dwarf_location_atom tls_op
;
15767 enum dtprel_bool dtprel
= dtprel_false
;
15769 if (targetm
.have_tls
)
15771 /* If this is not defined, we have no way to emit the
15773 if (!targetm
.asm_out
.output_dwarf_dtprel
)
15776 /* The way DW_OP_GNU_push_tls_address is specified, we
15777 can only look up addresses of objects in the current
15778 module. We used DW_OP_addr as first op, but that's
15779 wrong, because DW_OP_addr is relocated by the debug
15780 info consumer, while DW_OP_GNU_push_tls_address
15781 operand shouldn't be. */
15782 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
15784 dtprel
= dtprel_true
;
15785 tls_op
= DW_OP_GNU_push_tls_address
;
15789 if (!targetm
.emutls
.debug_form_tls_address
15790 || !(dwarf_version
>= 3 || !dwarf_strict
))
15792 /* We stuffed the control variable into the DECL_VALUE_EXPR
15793 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15794 no longer appear in gimple code. We used the control
15795 variable in specific so that we could pick it up here. */
15796 loc
= DECL_VALUE_EXPR (loc
);
15797 tls_op
= DW_OP_form_tls_address
;
15800 rtl
= rtl_for_decl_location (loc
);
15801 if (rtl
== NULL_RTX
)
15806 rtl
= XEXP (rtl
, 0);
15807 if (! CONSTANT_P (rtl
))
15810 ret
= new_addr_loc_descr (rtl
, dtprel
);
15811 ret1
= new_loc_descr (tls_op
, 0, 0);
15812 add_loc_descr (&ret
, ret1
);
15820 if (context
!= NULL
&& context
->dpi
!= NULL
15821 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
15823 /* We are generating code for a DWARF procedure and we want to access
15824 one of its arguments: find the appropriate argument offset and let
15825 the resolve_args_picking pass compute the offset that complies
15826 with the stack frame size. */
15830 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
15831 cursor
!= NULL_TREE
&& cursor
!= loc
;
15832 cursor
= TREE_CHAIN (cursor
), ++i
)
15834 /* If we are translating a DWARF procedure, all referenced parameters
15835 must belong to the current function. */
15836 gcc_assert (cursor
!= NULL_TREE
);
15838 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
15839 ret
->frame_offset_rel
= 1;
15845 if (DECL_HAS_VALUE_EXPR_P (loc
))
15846 return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc
),
15847 want_address
, context
);
15850 case FUNCTION_DECL
:
15853 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
15855 if (loc_list
&& loc_list
->first
)
15857 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
15858 have_address
= want_address
!= 0;
15861 rtl
= rtl_for_decl_location (loc
);
15862 if (rtl
== NULL_RTX
)
15864 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
15867 else if (CONST_INT_P (rtl
))
15869 HOST_WIDE_INT val
= INTVAL (rtl
);
15870 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15871 val
&= GET_MODE_MASK (DECL_MODE (loc
));
15872 ret
= int_loc_descriptor (val
);
15874 else if (GET_CODE (rtl
) == CONST_STRING
)
15876 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
15879 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
15880 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
15883 machine_mode mode
, mem_mode
;
15885 /* Certain constructs can only be represented at top-level. */
15886 if (want_address
== 2)
15888 ret
= loc_descriptor (rtl
, VOIDmode
,
15889 VAR_INIT_STATUS_INITIALIZED
);
15894 mode
= GET_MODE (rtl
);
15895 mem_mode
= VOIDmode
;
15899 mode
= get_address_mode (rtl
);
15900 rtl
= XEXP (rtl
, 0);
15903 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
15904 VAR_INIT_STATUS_INITIALIZED
);
15907 expansion_failed (loc
, rtl
,
15908 "failed to produce loc descriptor for rtl");
15914 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
15921 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
15925 case TARGET_MEM_REF
:
15927 case DEBUG_EXPR_DECL
:
15930 case COMPOUND_EXPR
:
15931 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
15935 case VIEW_CONVERT_EXPR
:
15938 case NON_LVALUE_EXPR
:
15939 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
15942 case COMPONENT_REF
:
15943 case BIT_FIELD_REF
:
15945 case ARRAY_RANGE_REF
:
15946 case REALPART_EXPR
:
15947 case IMAGPART_EXPR
:
15950 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
15952 int unsignedp
, reversep
, volatilep
= 0;
15954 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
15955 &unsignedp
, &reversep
, &volatilep
, false);
15957 gcc_assert (obj
!= loc
);
15959 list_ret
= loc_list_from_tree_1 (obj
,
15961 && !bitpos
&& !offset
? 2 : 1,
15963 /* TODO: We can extract value of the small expression via shifting even
15964 for nonzero bitpos. */
15967 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
15969 expansion_failed (loc
, NULL_RTX
,
15970 "bitfield access");
15974 if (offset
!= NULL_TREE
)
15976 /* Variable offset. */
15977 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
15978 if (list_ret1
== 0)
15980 add_loc_list (&list_ret
, list_ret1
);
15983 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
15986 bytepos
= bitpos
/ BITS_PER_UNIT
;
15988 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
15989 else if (bytepos
< 0)
15990 loc_list_plus_const (list_ret
, bytepos
);
15997 if ((want_address
|| !tree_fits_shwi_p (loc
))
15998 && (ret
= cst_pool_loc_descr (loc
)))
16000 else if (want_address
== 2
16001 && tree_fits_shwi_p (loc
)
16002 && (ret
= address_of_int_loc_descriptor
16003 (int_size_in_bytes (TREE_TYPE (loc
)),
16004 tree_to_shwi (loc
))))
16006 else if (tree_fits_shwi_p (loc
))
16007 ret
= int_loc_descriptor (tree_to_shwi (loc
));
16008 else if (tree_fits_uhwi_p (loc
))
16009 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
16012 expansion_failed (loc
, NULL_RTX
,
16013 "Integer operand is not host integer");
16022 if ((ret
= cst_pool_loc_descr (loc
)))
16025 /* We can construct small constants here using int_loc_descriptor. */
16026 expansion_failed (loc
, NULL_RTX
,
16027 "constructor or constant not in constant pool");
16030 case TRUTH_AND_EXPR
:
16031 case TRUTH_ANDIF_EXPR
:
16036 case TRUTH_XOR_EXPR
:
16041 case TRUTH_OR_EXPR
:
16042 case TRUTH_ORIF_EXPR
:
16047 case FLOOR_DIV_EXPR
:
16048 case CEIL_DIV_EXPR
:
16049 case ROUND_DIV_EXPR
:
16050 case TRUNC_DIV_EXPR
:
16051 case EXACT_DIV_EXPR
:
16052 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
16061 case FLOOR_MOD_EXPR
:
16062 case CEIL_MOD_EXPR
:
16063 case ROUND_MOD_EXPR
:
16064 case TRUNC_MOD_EXPR
:
16065 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
16070 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16071 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
16072 if (list_ret
== 0 || list_ret1
== 0)
16075 add_loc_list (&list_ret
, list_ret1
);
16078 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
16079 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
16080 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
16081 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
16082 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
16094 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
16097 case POINTER_PLUS_EXPR
:
16100 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
16102 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
16103 smarter to encode their opposite. The DW_OP_plus_uconst operation
16104 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
16105 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
16106 bytes, Y being the size of the operation that pushes the opposite
16107 of the addend. So let's choose the smallest representation. */
16108 const tree tree_addend
= TREE_OPERAND (loc
, 1);
16109 offset_int wi_addend
;
16110 HOST_WIDE_INT shwi_addend
;
16111 dw_loc_descr_ref loc_naddend
;
16113 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16117 /* Try to get the literal to push. It is the opposite of the addend,
16118 so as we rely on wrapping during DWARF evaluation, first decode
16119 the literal as a "DWARF-sized" signed number. */
16120 wi_addend
= wi::to_offset (tree_addend
);
16121 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
16122 shwi_addend
= wi_addend
.to_shwi ();
16123 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
16124 ? int_loc_descriptor (-shwi_addend
)
16127 if (loc_naddend
!= NULL
16128 && ((unsigned) size_of_uleb128 (shwi_addend
)
16129 > size_of_loc_descr (loc_naddend
)))
16131 add_loc_descr_to_each (list_ret
, loc_naddend
);
16132 add_loc_descr_to_each (list_ret
,
16133 new_loc_descr (DW_OP_minus
, 0, 0));
16137 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
16139 loc_naddend
= loc_cur
;
16140 loc_cur
= loc_cur
->dw_loc_next
;
16141 ggc_free (loc_naddend
);
16143 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
16153 goto do_comp_binop
;
16157 goto do_comp_binop
;
16161 goto do_comp_binop
;
16165 goto do_comp_binop
;
16168 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
16170 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
16171 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
16172 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
16188 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16189 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
16190 if (list_ret
== 0 || list_ret1
== 0)
16193 add_loc_list (&list_ret
, list_ret1
);
16196 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
16199 case TRUTH_NOT_EXPR
:
16213 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16217 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
16223 const enum tree_code code
=
16224 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
16226 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
16227 build2 (code
, integer_type_node
,
16228 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
16229 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
16232 /* ... fall through ... */
16236 dw_loc_descr_ref lhs
16237 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
16238 dw_loc_list_ref rhs
16239 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
16240 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
16242 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16243 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
16246 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
16247 add_loc_descr_to_each (list_ret
, bra_node
);
16249 add_loc_list (&list_ret
, rhs
);
16250 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
16251 add_loc_descr_to_each (list_ret
, jump_node
);
16253 add_loc_descr_to_each (list_ret
, lhs
);
16254 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16255 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
16257 /* ??? Need a node to point the skip at. Use a nop. */
16258 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
16259 add_loc_descr_to_each (list_ret
, tmp
);
16260 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16261 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
16265 case FIX_TRUNC_EXPR
:
16269 /* Leave front-end specific codes as simply unknown. This comes
16270 up, for instance, with the C STMT_EXPR. */
16271 if ((unsigned int) TREE_CODE (loc
)
16272 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
16274 expansion_failed (loc
, NULL_RTX
,
16275 "language specific tree node");
16279 /* Otherwise this is a generic code; we should just lists all of
16280 these explicitly. We forgot one. */
16282 gcc_unreachable ();
16284 /* In a release build, we want to degrade gracefully: better to
16285 generate incomplete debugging information than to crash. */
16289 if (!ret
&& !list_ret
)
16292 if (want_address
== 2 && !have_address
16293 && (dwarf_version
>= 4 || !dwarf_strict
))
16295 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
16297 expansion_failed (loc
, NULL_RTX
,
16298 "DWARF address size mismatch");
16302 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16304 add_loc_descr_to_each (list_ret
,
16305 new_loc_descr (DW_OP_stack_value
, 0, 0));
16308 /* Show if we can't fill the request for an address. */
16309 if (want_address
&& !have_address
)
16311 expansion_failed (loc
, NULL_RTX
,
16312 "Want address and only have value");
16316 gcc_assert (!ret
|| !list_ret
);
16318 /* If we've got an address and don't want one, dereference. */
16319 if (!want_address
&& have_address
)
16321 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
16323 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
16325 expansion_failed (loc
, NULL_RTX
,
16326 "DWARF address size mismatch");
16329 else if (size
== DWARF2_ADDR_SIZE
)
16332 op
= DW_OP_deref_size
;
16335 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
16337 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
16340 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
16345 /* Likewise, but strip useless DW_OP_nop operations in the resulting
16348 static dw_loc_list_ref
16349 loc_list_from_tree (tree loc
, int want_address
,
16350 const struct loc_descr_context
*context
)
16352 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
16354 for (dw_loc_list_ref loc_cur
= result
;
16355 loc_cur
!= NULL
; loc_cur
=
16356 loc_cur
->dw_loc_next
)
16357 loc_descr_without_nops (loc_cur
->expr
);
16361 /* Same as above but return only single location expression. */
16362 static dw_loc_descr_ref
16363 loc_descriptor_from_tree (tree loc
, int want_address
,
16364 const struct loc_descr_context
*context
)
16366 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
16369 if (ret
->dw_loc_next
)
16371 expansion_failed (loc
, NULL_RTX
,
16372 "Location list where only loc descriptor needed");
16378 /* Given a value, round it up to the lowest multiple of `boundary'
16379 which is not less than the value itself. */
16381 static inline HOST_WIDE_INT
16382 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
16384 return (((value
+ boundary
- 1) / boundary
) * boundary
);
16387 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
16388 pointer to the declared type for the relevant field variable, or return
16389 `integer_type_node' if the given node turns out to be an
16390 ERROR_MARK node. */
16393 field_type (const_tree decl
)
16397 if (TREE_CODE (decl
) == ERROR_MARK
)
16398 return integer_type_node
;
16400 type
= DECL_BIT_FIELD_TYPE (decl
);
16401 if (type
== NULL_TREE
)
16402 type
= TREE_TYPE (decl
);
16407 /* Given a pointer to a tree node, return the alignment in bits for
16408 it, or else return BITS_PER_WORD if the node actually turns out to
16409 be an ERROR_MARK node. */
16411 static inline unsigned
16412 simple_type_align_in_bits (const_tree type
)
16414 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
16417 static inline unsigned
16418 simple_decl_align_in_bits (const_tree decl
)
16420 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
16423 /* Return the result of rounding T up to ALIGN. */
16425 static inline offset_int
16426 round_up_to_align (const offset_int
&t
, unsigned int align
)
16428 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
16431 /* Compute the size of TYPE in bytes. If possible, return NULL and store the
16432 size as an integer constant in CST_SIZE. Otherwise, if possible, return a
16433 DWARF expression that computes the size. Return NULL and set CST_SIZE to -1
16434 if we fail to return the size in one of these two forms. */
16436 static dw_loc_descr_ref
16437 type_byte_size (const_tree type
, HOST_WIDE_INT
*cst_size
)
16440 struct loc_descr_context ctx
;
16442 /* Return a constant integer in priority, if possible. */
16443 *cst_size
= int_size_in_bytes (type
);
16444 if (*cst_size
!= -1)
16447 ctx
.context_type
= const_cast<tree
> (type
);
16448 ctx
.base_decl
= NULL_TREE
;
16451 type
= TYPE_MAIN_VARIANT (type
);
16452 tree_size
= TYPE_SIZE_UNIT (type
);
16453 return ((tree_size
!= NULL_TREE
)
16454 ? loc_descriptor_from_tree (tree_size
, 0, &ctx
)
16458 /* Helper structure for RECORD_TYPE processing. */
16461 /* Root RECORD_TYPE. It is needed to generate data member location
16462 descriptions in variable-length records (VLR), but also to cope with
16463 variants, which are composed of nested structures multiplexed with
16464 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
16465 function processing a FIELD_DECL, it is required to be non null. */
16467 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
16468 QUAL_UNION_TYPE), this holds an expression that computes the offset for
16469 this variant part as part of the root record (in storage units). For
16470 regular records, it must be NULL_TREE. */
16471 tree variant_part_offset
;
16474 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
16475 addressed byte of the "containing object" for the given FIELD_DECL. If
16476 possible, return a native constant through CST_OFFSET (in which case NULL is
16477 returned); otherwise return a DWARF expression that computes the offset.
16479 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
16480 that offset is, either because the argument turns out to be a pointer to an
16481 ERROR_MARK node, or because the offset expression is too complex for us.
16483 CTX is required: see the comment for VLR_CONTEXT. */
16485 static dw_loc_descr_ref
16486 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
16487 HOST_WIDE_INT
*cst_offset
)
16489 offset_int object_offset_in_bits
;
16490 offset_int object_offset_in_bytes
;
16491 offset_int bitpos_int
;
16492 bool is_byte_offset_cst
, is_bit_offset_cst
;
16494 dw_loc_list_ref loc_result
;
16498 if (TREE_CODE (decl
) == ERROR_MARK
)
16501 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
16503 is_bit_offset_cst
= TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
;
16504 is_byte_offset_cst
= TREE_CODE (DECL_FIELD_OFFSET (decl
)) != INTEGER_CST
;
16506 /* We cannot handle variable bit offsets at the moment, so abort if it's the
16508 if (is_bit_offset_cst
)
16511 #ifdef PCC_BITFIELD_TYPE_MATTERS
16512 /* We used to handle only constant offsets in all cases. Now, we handle
16513 properly dynamic byte offsets only when PCC bitfield type doesn't
16515 if (PCC_BITFIELD_TYPE_MATTERS
&& is_byte_offset_cst
&& is_bit_offset_cst
)
16518 tree field_size_tree
;
16519 offset_int deepest_bitpos
;
16520 offset_int field_size_in_bits
;
16521 unsigned int type_align_in_bits
;
16522 unsigned int decl_align_in_bits
;
16523 offset_int type_size_in_bits
;
16525 bitpos_int
= wi::to_offset (bit_position (decl
));
16526 type
= field_type (decl
);
16527 type_size_in_bits
= offset_int_type_size_in_bits (type
);
16528 type_align_in_bits
= simple_type_align_in_bits (type
);
16530 field_size_tree
= DECL_SIZE (decl
);
16532 /* The size could be unspecified if there was an error, or for
16533 a flexible array member. */
16534 if (!field_size_tree
)
16535 field_size_tree
= bitsize_zero_node
;
16537 /* If the size of the field is not constant, use the type size. */
16538 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
16539 field_size_in_bits
= wi::to_offset (field_size_tree
);
16541 field_size_in_bits
= type_size_in_bits
;
16543 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
16545 /* The GCC front-end doesn't make any attempt to keep track of the
16546 starting bit offset (relative to the start of the containing
16547 structure type) of the hypothetical "containing object" for a
16548 bit-field. Thus, when computing the byte offset value for the
16549 start of the "containing object" of a bit-field, we must deduce
16550 this information on our own. This can be rather tricky to do in
16551 some cases. For example, handling the following structure type
16552 definition when compiling for an i386/i486 target (which only
16553 aligns long long's to 32-bit boundaries) can be very tricky:
16555 struct S { int field1; long long field2:31; };
16557 Fortunately, there is a simple rule-of-thumb which can be used
16558 in such cases. When compiling for an i386/i486, GCC will
16559 allocate 8 bytes for the structure shown above. It decides to
16560 do this based upon one simple rule for bit-field allocation.
16561 GCC allocates each "containing object" for each bit-field at
16562 the first (i.e. lowest addressed) legitimate alignment boundary
16563 (based upon the required minimum alignment for the declared
16564 type of the field) which it can possibly use, subject to the
16565 condition that there is still enough available space remaining
16566 in the containing object (when allocated at the selected point)
16567 to fully accommodate all of the bits of the bit-field itself.
16569 This simple rule makes it obvious why GCC allocates 8 bytes for
16570 each object of the structure type shown above. When looking
16571 for a place to allocate the "containing object" for `field2',
16572 the compiler simply tries to allocate a 64-bit "containing
16573 object" at each successive 32-bit boundary (starting at zero)
16574 until it finds a place to allocate that 64- bit field such that
16575 at least 31 contiguous (and previously unallocated) bits remain
16576 within that selected 64 bit field. (As it turns out, for the
16577 example above, the compiler finds it is OK to allocate the
16578 "containing object" 64-bit field at bit-offset zero within the
16581 Here we attempt to work backwards from the limited set of facts
16582 we're given, and we try to deduce from those facts, where GCC
16583 must have believed that the containing object started (within
16584 the structure type). The value we deduce is then used (by the
16585 callers of this routine) to generate DW_AT_location and
16586 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16587 the case of DW_AT_location, regular fields as well). */
16589 /* Figure out the bit-distance from the start of the structure to
16590 the "deepest" bit of the bit-field. */
16591 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
16593 /* This is the tricky part. Use some fancy footwork to deduce
16594 where the lowest addressed bit of the containing object must
16596 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
16598 /* Round up to type_align by default. This works best for
16600 object_offset_in_bits
16601 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
16603 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
16605 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
16607 /* Round up to decl_align instead. */
16608 object_offset_in_bits
16609 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
16612 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16614 tree_result
= byte_position (decl
);
16615 if (ctx
->variant_part_offset
!= NULL_TREE
)
16616 tree_result
= fold (build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
16617 ctx
->variant_part_offset
, tree_result
));
16619 /* If the byte offset is a constant, it's simplier to handle a native
16620 constant rather than a DWARF expression. */
16621 if (TREE_CODE (tree_result
) == INTEGER_CST
)
16623 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
16626 struct loc_descr_context loc_ctx
= {
16627 ctx
->struct_type
, /* context_type */
16628 NULL_TREE
, /* base_decl */
16631 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
16633 /* We want a DWARF expression: abort if we only have a location list with
16634 multiple elements. */
16635 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
16638 return loc_result
->expr
;
16641 /* The following routines define various Dwarf attributes and any data
16642 associated with them. */
16644 /* Add a location description attribute value to a DIE.
16646 This emits location attributes suitable for whole variables and
16647 whole parameters. Note that the location attributes for struct fields are
16648 generated by the routine `data_member_location_attribute' below. */
16651 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
16652 dw_loc_list_ref descr
)
16656 if (single_element_loc_list_p (descr
))
16657 add_AT_loc (die
, attr_kind
, descr
->expr
);
16659 add_AT_loc_list (die
, attr_kind
, descr
);
16662 /* Add DW_AT_accessibility attribute to DIE if needed. */
16665 add_accessibility_attribute (dw_die_ref die
, tree decl
)
16667 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16668 children, otherwise the default is DW_ACCESS_public. In DWARF2
16669 the default has always been DW_ACCESS_public. */
16670 if (TREE_PROTECTED (decl
))
16671 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
16672 else if (TREE_PRIVATE (decl
))
16674 if (dwarf_version
== 2
16675 || die
->die_parent
== NULL
16676 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
16677 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
16679 else if (dwarf_version
> 2
16681 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
16682 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
16685 /* Attach the specialized form of location attribute used for data members of
16686 struct and union types. In the special case of a FIELD_DECL node which
16687 represents a bit-field, the "offset" part of this special location
16688 descriptor must indicate the distance in bytes from the lowest-addressed
16689 byte of the containing struct or union type to the lowest-addressed byte of
16690 the "containing object" for the bit-field. (See the `field_byte_offset'
16693 For any given bit-field, the "containing object" is a hypothetical object
16694 (of some integral or enum type) within which the given bit-field lives. The
16695 type of this hypothetical "containing object" is always the same as the
16696 declared type of the individual bit-field itself (for GCC anyway... the
16697 DWARF spec doesn't actually mandate this). Note that it is the size (in
16698 bytes) of the hypothetical "containing object" which will be given in the
16699 DW_AT_byte_size attribute for this bit-field. (See the
16700 `byte_size_attribute' function below.) It is also used when calculating the
16701 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16704 CTX is required: see the comment for VLR_CONTEXT. */
16707 add_data_member_location_attribute (dw_die_ref die
,
16709 struct vlr_context
*ctx
)
16711 HOST_WIDE_INT offset
;
16712 dw_loc_descr_ref loc_descr
= 0;
16714 if (TREE_CODE (decl
) == TREE_BINFO
)
16716 /* We're working on the TAG_inheritance for a base class. */
16717 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
16719 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16720 aren't at a fixed offset from all (sub)objects of the same
16721 type. We need to extract the appropriate offset from our
16722 vtable. The following dwarf expression means
16724 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16726 This is specific to the V3 ABI, of course. */
16728 dw_loc_descr_ref tmp
;
16730 /* Make a copy of the object address. */
16731 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
16732 add_loc_descr (&loc_descr
, tmp
);
16734 /* Extract the vtable address. */
16735 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
16736 add_loc_descr (&loc_descr
, tmp
);
16738 /* Calculate the address of the offset. */
16739 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
16740 gcc_assert (offset
< 0);
16742 tmp
= int_loc_descriptor (-offset
);
16743 add_loc_descr (&loc_descr
, tmp
);
16744 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
16745 add_loc_descr (&loc_descr
, tmp
);
16747 /* Extract the offset. */
16748 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
16749 add_loc_descr (&loc_descr
, tmp
);
16751 /* Add it to the object address. */
16752 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
16753 add_loc_descr (&loc_descr
, tmp
);
16756 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
16760 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
16762 /* If loc_descr is available then we know the field offset is dynamic.
16763 However, GDB does not handle dynamic field offsets very well at the
16765 if (loc_descr
!= NULL
&& gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
)
16771 /* Data member location evalutation starts with the base address on the
16772 stack. Compute the field offset and add it to this base address. */
16773 else if (loc_descr
!= NULL
)
16774 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
16779 if (dwarf_version
> 2)
16781 /* Don't need to output a location expression, just the constant. */
16783 add_AT_int (die
, DW_AT_data_member_location
, offset
);
16785 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
16790 enum dwarf_location_atom op
;
16792 /* The DWARF2 standard says that we should assume that the structure
16793 address is already on the stack, so we can specify a structure
16794 field address by using DW_OP_plus_uconst. */
16795 op
= DW_OP_plus_uconst
;
16796 loc_descr
= new_loc_descr (op
, offset
, 0);
16800 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
16803 /* Writes integer values to dw_vec_const array. */
16806 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
16810 *dest
++ = val
& 0xff;
16816 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16818 static HOST_WIDE_INT
16819 extract_int (const unsigned char *src
, unsigned int size
)
16821 HOST_WIDE_INT val
= 0;
16827 val
|= *--src
& 0xff;
16833 /* Writes wide_int values to dw_vec_const array. */
16836 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
16840 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
16842 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
16846 /* We'd have to extend this code to support odd sizes. */
16847 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
16849 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
16851 if (WORDS_BIG_ENDIAN
)
16852 for (i
= n
- 1; i
>= 0; i
--)
16854 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
16855 dest
+= sizeof (HOST_WIDE_INT
);
16858 for (i
= 0; i
< n
; i
++)
16860 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
16861 dest
+= sizeof (HOST_WIDE_INT
);
16865 /* Writes floating point values to dw_vec_const array. */
16868 insert_float (const_rtx rtl
, unsigned char *array
)
16873 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), GET_MODE (rtl
));
16875 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16876 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
16878 insert_int (val
[i
], 4, array
);
16883 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16884 does not have a "location" either in memory or in a register. These
16885 things can arise in GNU C when a constant is passed as an actual parameter
16886 to an inlined function. They can also arise in C++ where declared
16887 constants do not necessarily get memory "homes". */
16890 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
16892 switch (GET_CODE (rtl
))
16896 HOST_WIDE_INT val
= INTVAL (rtl
);
16899 add_AT_int (die
, DW_AT_const_value
, val
);
16901 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
16905 case CONST_WIDE_INT
:
16907 wide_int w1
= std::make_pair (rtl
, MAX_MODE_INT
);
16908 unsigned int prec
= MIN (wi::min_precision (w1
, UNSIGNED
),
16909 (unsigned int)CONST_WIDE_INT_NUNITS (rtl
) * HOST_BITS_PER_WIDE_INT
);
16910 wide_int w
= wi::zext (w1
, prec
);
16911 add_AT_wide (die
, DW_AT_const_value
, w
);
16916 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16917 floating-point constant. A CONST_DOUBLE is used whenever the
16918 constant requires more than one word in order to be adequately
16921 machine_mode mode
= GET_MODE (rtl
);
16923 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
16924 add_AT_double (die
, DW_AT_const_value
,
16925 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
16928 unsigned int length
= GET_MODE_SIZE (mode
);
16929 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
16931 insert_float (rtl
, array
);
16932 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
16939 machine_mode mode
= GET_MODE (rtl
);
16940 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
16941 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
16942 unsigned char *array
16943 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
16946 machine_mode imode
= GET_MODE_INNER (mode
);
16948 switch (GET_MODE_CLASS (mode
))
16950 case MODE_VECTOR_INT
:
16951 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16953 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16954 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
16958 case MODE_VECTOR_FLOAT
:
16959 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
16961 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
16962 insert_float (elt
, p
);
16967 gcc_unreachable ();
16970 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
16975 if (dwarf_version
>= 4 || !dwarf_strict
)
16977 dw_loc_descr_ref loc_result
;
16978 resolve_one_addr (&rtl
);
16980 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
16981 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16982 add_AT_loc (die
, DW_AT_location
, loc_result
);
16983 vec_safe_push (used_rtx_array
, rtl
);
16989 if (CONSTANT_P (XEXP (rtl
, 0)))
16990 return add_const_value_attribute (die
, XEXP (rtl
, 0));
16993 if (!const_ok_for_output (rtl
))
16996 if (dwarf_version
>= 4 || !dwarf_strict
)
17001 /* In cases where an inlined instance of an inline function is passed
17002 the address of an `auto' variable (which is local to the caller) we
17003 can get a situation where the DECL_RTL of the artificial local
17004 variable (for the inlining) which acts as a stand-in for the
17005 corresponding formal parameter (of the inline function) will look
17006 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
17007 exactly a compile-time constant expression, but it isn't the address
17008 of the (artificial) local variable either. Rather, it represents the
17009 *value* which the artificial local variable always has during its
17010 lifetime. We currently have no way to represent such quasi-constant
17011 values in Dwarf, so for now we just punt and generate nothing. */
17019 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
17020 && MEM_READONLY_P (rtl
)
17021 && GET_MODE (rtl
) == BLKmode
)
17023 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
17029 /* No other kinds of rtx should be possible here. */
17030 gcc_unreachable ();
17035 /* Determine whether the evaluation of EXPR references any variables
17036 or functions which aren't otherwise used (and therefore may not be
17039 reference_to_unused (tree
* tp
, int * walk_subtrees
,
17040 void * data ATTRIBUTE_UNUSED
)
17042 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
17043 *walk_subtrees
= 0;
17045 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
17046 && ! TREE_ASM_WRITTEN (*tp
))
17048 /* ??? The C++ FE emits debug information for using decls, so
17049 putting gcc_unreachable here falls over. See PR31899. For now
17050 be conservative. */
17051 else if (!symtab
->global_info_ready
17052 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
17054 else if (TREE_CODE (*tp
) == VAR_DECL
)
17056 varpool_node
*node
= varpool_node::get (*tp
);
17057 if (!node
|| !node
->definition
)
17060 else if (TREE_CODE (*tp
) == FUNCTION_DECL
17061 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
17063 /* The call graph machinery must have finished analyzing,
17064 optimizing and gimplifying the CU by now.
17065 So if *TP has no call graph node associated
17066 to it, it means *TP will not be emitted. */
17067 if (!cgraph_node::get (*tp
))
17070 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
17076 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
17077 for use in a later add_const_value_attribute call. */
17080 rtl_for_decl_init (tree init
, tree type
)
17082 rtx rtl
= NULL_RTX
;
17086 /* If a variable is initialized with a string constant without embedded
17087 zeros, build CONST_STRING. */
17088 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
17090 tree enttype
= TREE_TYPE (type
);
17091 tree domain
= TYPE_DOMAIN (type
);
17092 machine_mode mode
= TYPE_MODE (enttype
);
17094 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
17096 && integer_zerop (TYPE_MIN_VALUE (domain
))
17097 && compare_tree_int (TYPE_MAX_VALUE (domain
),
17098 TREE_STRING_LENGTH (init
) - 1) == 0
17099 && ((size_t) TREE_STRING_LENGTH (init
)
17100 == strlen (TREE_STRING_POINTER (init
)) + 1))
17102 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
17103 ggc_strdup (TREE_STRING_POINTER (init
)));
17104 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
17105 MEM_READONLY_P (rtl
) = 1;
17108 /* Other aggregates, and complex values, could be represented using
17110 else if (AGGREGATE_TYPE_P (type
)
17111 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
17112 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
17113 || TREE_CODE (type
) == COMPLEX_TYPE
)
17115 /* Vectors only work if their mode is supported by the target.
17116 FIXME: generic vectors ought to work too. */
17117 else if (TREE_CODE (type
) == VECTOR_TYPE
17118 && !VECTOR_MODE_P (TYPE_MODE (type
)))
17120 /* If the initializer is something that we know will expand into an
17121 immediate RTL constant, expand it now. We must be careful not to
17122 reference variables which won't be output. */
17123 else if (initializer_constant_valid_p (init
, type
)
17124 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
17126 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
17128 if (TREE_CODE (type
) == VECTOR_TYPE
)
17129 switch (TREE_CODE (init
))
17134 if (TREE_CONSTANT (init
))
17136 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
17137 bool constant_p
= true;
17139 unsigned HOST_WIDE_INT ix
;
17141 /* Even when ctor is constant, it might contain non-*_CST
17142 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
17143 belong into VECTOR_CST nodes. */
17144 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
17145 if (!CONSTANT_CLASS_P (value
))
17147 constant_p
= false;
17153 init
= build_vector_from_ctor (type
, elts
);
17163 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
17165 /* If expand_expr returns a MEM, it wasn't immediate. */
17166 gcc_assert (!rtl
|| !MEM_P (rtl
));
17172 /* Generate RTL for the variable DECL to represent its location. */
17175 rtl_for_decl_location (tree decl
)
17179 /* Here we have to decide where we are going to say the parameter "lives"
17180 (as far as the debugger is concerned). We only have a couple of
17181 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
17183 DECL_RTL normally indicates where the parameter lives during most of the
17184 activation of the function. If optimization is enabled however, this
17185 could be either NULL or else a pseudo-reg. Both of those cases indicate
17186 that the parameter doesn't really live anywhere (as far as the code
17187 generation parts of GCC are concerned) during most of the function's
17188 activation. That will happen (for example) if the parameter is never
17189 referenced within the function.
17191 We could just generate a location descriptor here for all non-NULL
17192 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
17193 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
17194 where DECL_RTL is NULL or is a pseudo-reg.
17196 Note however that we can only get away with using DECL_INCOMING_RTL as
17197 a backup substitute for DECL_RTL in certain limited cases. In cases
17198 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
17199 we can be sure that the parameter was passed using the same type as it is
17200 declared to have within the function, and that its DECL_INCOMING_RTL
17201 points us to a place where a value of that type is passed.
17203 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
17204 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
17205 because in these cases DECL_INCOMING_RTL points us to a value of some
17206 type which is *different* from the type of the parameter itself. Thus,
17207 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
17208 such cases, the debugger would end up (for example) trying to fetch a
17209 `float' from a place which actually contains the first part of a
17210 `double'. That would lead to really incorrect and confusing
17211 output at debug-time.
17213 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
17214 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
17215 are a couple of exceptions however. On little-endian machines we can
17216 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
17217 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
17218 an integral type that is smaller than TREE_TYPE (decl). These cases arise
17219 when (on a little-endian machine) a non-prototyped function has a
17220 parameter declared to be of type `short' or `char'. In such cases,
17221 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
17222 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
17223 passed `int' value. If the debugger then uses that address to fetch
17224 a `short' or a `char' (on a little-endian machine) the result will be
17225 the correct data, so we allow for such exceptional cases below.
17227 Note that our goal here is to describe the place where the given formal
17228 parameter lives during most of the function's activation (i.e. between the
17229 end of the prologue and the start of the epilogue). We'll do that as best
17230 as we can. Note however that if the given formal parameter is modified
17231 sometime during the execution of the function, then a stack backtrace (at
17232 debug-time) will show the function as having been called with the *new*
17233 value rather than the value which was originally passed in. This happens
17234 rarely enough that it is not a major problem, but it *is* a problem, and
17235 I'd like to fix it.
17237 A future version of dwarf2out.c may generate two additional attributes for
17238 any given DW_TAG_formal_parameter DIE which will describe the "passed
17239 type" and the "passed location" for the given formal parameter in addition
17240 to the attributes we now generate to indicate the "declared type" and the
17241 "active location" for each parameter. This additional set of attributes
17242 could be used by debuggers for stack backtraces. Separately, note that
17243 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
17244 This happens (for example) for inlined-instances of inline function formal
17245 parameters which are never referenced. This really shouldn't be
17246 happening. All PARM_DECL nodes should get valid non-NULL
17247 DECL_INCOMING_RTL values. FIXME. */
17249 /* Use DECL_RTL as the "location" unless we find something better. */
17250 rtl
= DECL_RTL_IF_SET (decl
);
17252 /* When generating abstract instances, ignore everything except
17253 constants, symbols living in memory, and symbols living in
17254 fixed registers. */
17255 if (! reload_completed
)
17258 && (CONSTANT_P (rtl
)
17260 && CONSTANT_P (XEXP (rtl
, 0)))
17262 && TREE_CODE (decl
) == VAR_DECL
17263 && TREE_STATIC (decl
))))
17265 rtl
= targetm
.delegitimize_address (rtl
);
17270 else if (TREE_CODE (decl
) == PARM_DECL
)
17272 if (rtl
== NULL_RTX
17273 || is_pseudo_reg (rtl
)
17275 && is_pseudo_reg (XEXP (rtl
, 0))
17276 && DECL_INCOMING_RTL (decl
)
17277 && MEM_P (DECL_INCOMING_RTL (decl
))
17278 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
17280 tree declared_type
= TREE_TYPE (decl
);
17281 tree passed_type
= DECL_ARG_TYPE (decl
);
17282 machine_mode dmode
= TYPE_MODE (declared_type
);
17283 machine_mode pmode
= TYPE_MODE (passed_type
);
17285 /* This decl represents a formal parameter which was optimized out.
17286 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
17287 all cases where (rtl == NULL_RTX) just below. */
17288 if (dmode
== pmode
)
17289 rtl
= DECL_INCOMING_RTL (decl
);
17290 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
17291 && SCALAR_INT_MODE_P (dmode
)
17292 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
17293 && DECL_INCOMING_RTL (decl
))
17295 rtx inc
= DECL_INCOMING_RTL (decl
);
17298 else if (MEM_P (inc
))
17300 if (BYTES_BIG_ENDIAN
)
17301 rtl
= adjust_address_nv (inc
, dmode
,
17302 GET_MODE_SIZE (pmode
)
17303 - GET_MODE_SIZE (dmode
));
17310 /* If the parm was passed in registers, but lives on the stack, then
17311 make a big endian correction if the mode of the type of the
17312 parameter is not the same as the mode of the rtl. */
17313 /* ??? This is the same series of checks that are made in dbxout.c before
17314 we reach the big endian correction code there. It isn't clear if all
17315 of these checks are necessary here, but keeping them all is the safe
17317 else if (MEM_P (rtl
)
17318 && XEXP (rtl
, 0) != const0_rtx
17319 && ! CONSTANT_P (XEXP (rtl
, 0))
17320 /* Not passed in memory. */
17321 && !MEM_P (DECL_INCOMING_RTL (decl
))
17322 /* Not passed by invisible reference. */
17323 && (!REG_P (XEXP (rtl
, 0))
17324 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
17325 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
17326 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
17327 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
17330 /* Big endian correction check. */
17331 && BYTES_BIG_ENDIAN
17332 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
17333 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
17336 machine_mode addr_mode
= get_address_mode (rtl
);
17337 int offset
= (UNITS_PER_WORD
17338 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
17340 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
17341 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
17344 else if (TREE_CODE (decl
) == VAR_DECL
17347 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
17348 && BYTES_BIG_ENDIAN
)
17350 machine_mode addr_mode
= get_address_mode (rtl
);
17351 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
17352 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
17354 /* If a variable is declared "register" yet is smaller than
17355 a register, then if we store the variable to memory, it
17356 looks like we're storing a register-sized value, when in
17357 fact we are not. We need to adjust the offset of the
17358 storage location to reflect the actual value's bytes,
17359 else gdb will not be able to display it. */
17361 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
17362 plus_constant (addr_mode
, XEXP (rtl
, 0),
17366 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
17367 and will have been substituted directly into all expressions that use it.
17368 C does not have such a concept, but C++ and other languages do. */
17369 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
17370 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
17373 rtl
= targetm
.delegitimize_address (rtl
);
17375 /* If we don't look past the constant pool, we risk emitting a
17376 reference to a constant pool entry that isn't referenced from
17377 code, and thus is not emitted. */
17379 rtl
= avoid_constant_pool_reference (rtl
);
17381 /* Try harder to get a rtl. If this symbol ends up not being emitted
17382 in the current CU, resolve_addr will remove the expression referencing
17384 if (rtl
== NULL_RTX
17385 && TREE_CODE (decl
) == VAR_DECL
17386 && !DECL_EXTERNAL (decl
)
17387 && TREE_STATIC (decl
)
17388 && DECL_NAME (decl
)
17389 && !DECL_HARD_REGISTER (decl
)
17390 && DECL_MODE (decl
) != VOIDmode
)
17392 rtl
= make_decl_rtl_for_debug (decl
);
17394 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
17395 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
17402 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
17403 returned. If so, the decl for the COMMON block is returned, and the
17404 value is the offset into the common block for the symbol. */
17407 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
17409 tree val_expr
, cvar
;
17411 HOST_WIDE_INT bitsize
, bitpos
;
17413 int unsignedp
, reversep
, volatilep
= 0;
17415 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
17416 it does not have a value (the offset into the common area), or if it
17417 is thread local (as opposed to global) then it isn't common, and shouldn't
17418 be handled as such. */
17419 if (TREE_CODE (decl
) != VAR_DECL
17420 || !TREE_STATIC (decl
)
17421 || !DECL_HAS_VALUE_EXPR_P (decl
)
17425 val_expr
= DECL_VALUE_EXPR (decl
);
17426 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
17429 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
17430 &unsignedp
, &reversep
, &volatilep
, true);
17432 if (cvar
== NULL_TREE
17433 || TREE_CODE (cvar
) != VAR_DECL
17434 || DECL_ARTIFICIAL (cvar
)
17435 || !TREE_PUBLIC (cvar
))
17439 if (offset
!= NULL
)
17441 if (!tree_fits_shwi_p (offset
))
17443 *value
= tree_to_shwi (offset
);
17446 *value
+= bitpos
/ BITS_PER_UNIT
;
17451 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
17452 data attribute for a variable or a parameter. We generate the
17453 DW_AT_const_value attribute only in those cases where the given variable
17454 or parameter does not have a true "location" either in memory or in a
17455 register. This can happen (for example) when a constant is passed as an
17456 actual argument in a call to an inline function. (It's possible that
17457 these things can crop up in other ways also.) Note that one type of
17458 constant value which can be passed into an inlined function is a constant
17459 pointer. This can happen for example if an actual argument in an inlined
17460 function call evaluates to a compile-time constant address.
17462 CACHE_P is true if it is worth caching the location list for DECL,
17463 so that future calls can reuse it rather than regenerate it from scratch.
17464 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
17465 since we will need to refer to them each time the function is inlined. */
17468 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
17471 dw_loc_list_ref list
;
17472 var_loc_list
*loc_list
;
17473 cached_dw_loc_list
*cache
;
17478 if (TREE_CODE (decl
) == ERROR_MARK
)
17481 if (get_AT (die
, DW_AT_location
)
17482 || get_AT (die
, DW_AT_const_value
))
17485 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
17486 || TREE_CODE (decl
) == RESULT_DECL
);
17488 /* Try to get some constant RTL for this decl, and use that as the value of
17491 rtl
= rtl_for_decl_location (decl
);
17492 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
17493 && add_const_value_attribute (die
, rtl
))
17496 /* See if we have single element location list that is equivalent to
17497 a constant value. That way we are better to use add_const_value_attribute
17498 rather than expanding constant value equivalent. */
17499 loc_list
= lookup_decl_loc (decl
);
17502 && loc_list
->first
->next
== NULL
17503 && NOTE_P (loc_list
->first
->loc
)
17504 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
17505 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
17507 struct var_loc_node
*node
;
17509 node
= loc_list
->first
;
17510 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
17511 if (GET_CODE (rtl
) == EXPR_LIST
)
17512 rtl
= XEXP (rtl
, 0);
17513 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
17514 && add_const_value_attribute (die
, rtl
))
17517 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
17518 list several times. See if we've already cached the contents. */
17520 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
17524 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
17526 list
= cache
->loc_list
;
17530 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
17532 /* It is usually worth caching this result if the decl is from
17533 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
17534 if (cache_p
&& list
&& list
->dw_loc_next
)
17536 cached_dw_loc_list
**slot
17537 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
17540 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
17541 cache
->decl_id
= DECL_UID (decl
);
17542 cache
->loc_list
= list
;
17548 add_AT_location_description (die
, DW_AT_location
, list
);
17551 /* None of that worked, so it must not really have a location;
17552 try adding a constant value attribute from the DECL_INITIAL. */
17553 return tree_add_const_value_attribute_for_decl (die
, decl
);
17556 /* Helper function for tree_add_const_value_attribute. Natively encode
17557 initializer INIT into an array. Return true if successful. */
17560 native_encode_initializer (tree init
, unsigned char *array
, int size
)
17564 if (init
== NULL_TREE
)
17568 switch (TREE_CODE (init
))
17571 type
= TREE_TYPE (init
);
17572 if (TREE_CODE (type
) == ARRAY_TYPE
)
17574 tree enttype
= TREE_TYPE (type
);
17575 machine_mode mode
= TYPE_MODE (enttype
);
17577 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
17579 if (int_size_in_bytes (type
) != size
)
17581 if (size
> TREE_STRING_LENGTH (init
))
17583 memcpy (array
, TREE_STRING_POINTER (init
),
17584 TREE_STRING_LENGTH (init
));
17585 memset (array
+ TREE_STRING_LENGTH (init
),
17586 '\0', size
- TREE_STRING_LENGTH (init
));
17589 memcpy (array
, TREE_STRING_POINTER (init
), size
);
17594 type
= TREE_TYPE (init
);
17595 if (int_size_in_bytes (type
) != size
)
17597 if (TREE_CODE (type
) == ARRAY_TYPE
)
17599 HOST_WIDE_INT min_index
;
17600 unsigned HOST_WIDE_INT cnt
;
17601 int curpos
= 0, fieldsize
;
17602 constructor_elt
*ce
;
17604 if (TYPE_DOMAIN (type
) == NULL_TREE
17605 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
17608 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
17609 if (fieldsize
<= 0)
17612 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
17613 memset (array
, '\0', size
);
17614 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
17616 tree val
= ce
->value
;
17617 tree index
= ce
->index
;
17619 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
17620 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
17623 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
17628 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
17631 curpos
= pos
+ fieldsize
;
17632 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
17634 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
17635 - tree_to_shwi (TREE_OPERAND (index
, 0));
17636 while (count
-- > 0)
17639 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
17640 curpos
+= fieldsize
;
17643 gcc_assert (curpos
<= size
);
17647 else if (TREE_CODE (type
) == RECORD_TYPE
17648 || TREE_CODE (type
) == UNION_TYPE
)
17650 tree field
= NULL_TREE
;
17651 unsigned HOST_WIDE_INT cnt
;
17652 constructor_elt
*ce
;
17654 if (int_size_in_bytes (type
) != size
)
17657 if (TREE_CODE (type
) == RECORD_TYPE
)
17658 field
= TYPE_FIELDS (type
);
17660 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
17662 tree val
= ce
->value
;
17663 int pos
, fieldsize
;
17665 if (ce
->index
!= 0)
17671 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
17674 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
17675 && TYPE_DOMAIN (TREE_TYPE (field
))
17676 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
17678 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
17679 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
17681 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
17682 pos
= int_byte_position (field
);
17683 gcc_assert (pos
+ fieldsize
<= size
);
17685 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
17691 case VIEW_CONVERT_EXPR
:
17692 case NON_LVALUE_EXPR
:
17693 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
17695 return native_encode_expr (init
, array
, size
) == size
;
17699 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17700 attribute is the const value T. */
17703 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
17706 tree type
= TREE_TYPE (t
);
17709 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
17713 gcc_assert (!DECL_P (init
));
17715 rtl
= rtl_for_decl_init (init
, type
);
17717 return add_const_value_attribute (die
, rtl
);
17718 /* If the host and target are sane, try harder. */
17719 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
17720 && initializer_constant_valid_p (init
, type
))
17722 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
17723 if (size
> 0 && (int) size
== size
)
17725 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
17727 if (native_encode_initializer (init
, array
, size
))
17729 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
17738 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17739 attribute is the const value of T, where T is an integral constant
17740 variable with static storage duration
17741 (so it can't be a PARM_DECL or a RESULT_DECL). */
17744 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
17748 || (TREE_CODE (decl
) != VAR_DECL
17749 && TREE_CODE (decl
) != CONST_DECL
)
17750 || (TREE_CODE (decl
) == VAR_DECL
17751 && !TREE_STATIC (decl
)))
17754 if (TREE_READONLY (decl
)
17755 && ! TREE_THIS_VOLATILE (decl
)
17756 && DECL_INITIAL (decl
))
17761 /* Don't add DW_AT_const_value if abstract origin already has one. */
17762 if (get_AT (var_die
, DW_AT_const_value
))
17765 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
17768 /* Convert the CFI instructions for the current function into a
17769 location list. This is used for DW_AT_frame_base when we targeting
17770 a dwarf2 consumer that does not support the dwarf3
17771 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17774 static dw_loc_list_ref
17775 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
17779 dw_loc_list_ref list
, *list_tail
;
17781 dw_cfa_location last_cfa
, next_cfa
;
17782 const char *start_label
, *last_label
, *section
;
17783 dw_cfa_location remember
;
17786 gcc_assert (fde
!= NULL
);
17788 section
= secname_for_decl (current_function_decl
);
17792 memset (&next_cfa
, 0, sizeof (next_cfa
));
17793 next_cfa
.reg
= INVALID_REGNUM
;
17794 remember
= next_cfa
;
17796 start_label
= fde
->dw_fde_begin
;
17798 /* ??? Bald assumption that the CIE opcode list does not contain
17799 advance opcodes. */
17800 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
17801 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
17803 last_cfa
= next_cfa
;
17804 last_label
= start_label
;
17806 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
17808 /* If the first partition contained no CFI adjustments, the
17809 CIE opcodes apply to the whole first partition. */
17810 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17811 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
17812 list_tail
=&(*list_tail
)->dw_loc_next
;
17813 start_label
= last_label
= fde
->dw_fde_second_begin
;
17816 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
17818 switch (cfi
->dw_cfi_opc
)
17820 case DW_CFA_set_loc
:
17821 case DW_CFA_advance_loc1
:
17822 case DW_CFA_advance_loc2
:
17823 case DW_CFA_advance_loc4
:
17824 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17826 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17827 start_label
, last_label
, section
);
17829 list_tail
= &(*list_tail
)->dw_loc_next
;
17830 last_cfa
= next_cfa
;
17831 start_label
= last_label
;
17833 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
17836 case DW_CFA_advance_loc
:
17837 /* The encoding is complex enough that we should never emit this. */
17838 gcc_unreachable ();
17841 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
17844 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
17846 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17848 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17849 start_label
, last_label
, section
);
17851 list_tail
= &(*list_tail
)->dw_loc_next
;
17852 last_cfa
= next_cfa
;
17853 start_label
= last_label
;
17855 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17856 start_label
, fde
->dw_fde_end
, section
);
17857 list_tail
= &(*list_tail
)->dw_loc_next
;
17858 start_label
= last_label
= fde
->dw_fde_second_begin
;
17862 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17864 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17865 start_label
, last_label
, section
);
17866 list_tail
= &(*list_tail
)->dw_loc_next
;
17867 start_label
= last_label
;
17870 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
17872 fde
->dw_fde_second_begin
17873 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
17876 if (list
&& list
->dw_loc_next
)
17882 /* Compute a displacement from the "steady-state frame pointer" to the
17883 frame base (often the same as the CFA), and store it in
17884 frame_pointer_fb_offset. OFFSET is added to the displacement
17885 before the latter is negated. */
17888 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
17892 #ifdef FRAME_POINTER_CFA_OFFSET
17893 reg
= frame_pointer_rtx
;
17894 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
17896 reg
= arg_pointer_rtx
;
17897 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
17900 elim
= (ira_use_lra_p
17901 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
17902 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
17903 if (GET_CODE (elim
) == PLUS
)
17905 offset
+= INTVAL (XEXP (elim
, 1));
17906 elim
= XEXP (elim
, 0);
17909 frame_pointer_fb_offset
= -offset
;
17911 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
17912 in which to eliminate. This is because it's stack pointer isn't
17913 directly accessible as a register within the ISA. To work around
17914 this, assume that while we cannot provide a proper value for
17915 frame_pointer_fb_offset, we won't need one either. */
17916 frame_pointer_fb_offset_valid
17917 = ((SUPPORTS_STACK_ALIGNMENT
17918 && (elim
== hard_frame_pointer_rtx
17919 || elim
== stack_pointer_rtx
))
17920 || elim
== (frame_pointer_needed
17921 ? hard_frame_pointer_rtx
17922 : stack_pointer_rtx
));
17925 /* Generate a DW_AT_name attribute given some string value to be included as
17926 the value of the attribute. */
17929 add_name_attribute (dw_die_ref die
, const char *name_string
)
17931 if (name_string
!= NULL
&& *name_string
!= 0)
17933 if (demangle_name_func
)
17934 name_string
= (*demangle_name_func
) (name_string
);
17936 add_AT_string (die
, DW_AT_name
, name_string
);
17940 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
17941 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
17942 of TYPE accordingly.
17944 ??? This is a temporary measure until after we're able to generate
17945 regular DWARF for the complex Ada type system. */
17948 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
17949 dw_die_ref context_die
)
17952 dw_die_ref dtype_die
;
17954 if (!lang_hooks
.types
.descriptive_type
)
17957 dtype
= lang_hooks
.types
.descriptive_type (type
);
17961 dtype_die
= lookup_type_die (dtype
);
17964 gen_type_die (dtype
, context_die
);
17965 dtype_die
= lookup_type_die (dtype
);
17966 gcc_assert (dtype_die
);
17969 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
17972 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
17974 static const char *
17975 comp_dir_string (void)
17979 static const char *cached_wd
= NULL
;
17981 if (cached_wd
!= NULL
)
17984 wd
= get_src_pwd ();
17988 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
17992 wdlen
= strlen (wd
);
17993 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
17995 wd1
[wdlen
] = DIR_SEPARATOR
;
17996 wd1
[wdlen
+ 1] = 0;
18000 cached_wd
= remap_debug_filename (wd
);
18004 /* Generate a DW_AT_comp_dir attribute for DIE. */
18007 add_comp_dir_attribute (dw_die_ref die
)
18009 const char * wd
= comp_dir_string ();
18011 add_AT_string (die
, DW_AT_comp_dir
, wd
);
18014 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
18015 pointer computation, ...), output a representation for that bound according
18016 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
18017 loc_list_from_tree for the meaning of CONTEXT. */
18020 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
18021 int forms
, const struct loc_descr_context
*context
)
18023 dw_die_ref context_die
, decl_die
;
18024 dw_loc_list_ref list
;
18026 bool strip_conversions
= true;
18028 while (strip_conversions
)
18029 switch (TREE_CODE (value
))
18036 case VIEW_CONVERT_EXPR
:
18037 value
= TREE_OPERAND (value
, 0);
18041 strip_conversions
= false;
18045 /* If possible and permitted, output the attribute as a constant. */
18046 if ((forms
& dw_scalar_form_constant
) != 0
18047 && TREE_CODE (value
) == INTEGER_CST
)
18049 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
18051 /* If HOST_WIDE_INT is big enough then represent the bound as
18052 a constant value. We need to choose a form based on
18053 whether the type is signed or unsigned. We cannot just
18054 call add_AT_unsigned if the value itself is positive
18055 (add_AT_unsigned might add the unsigned value encoded as
18056 DW_FORM_data[1248]). Some DWARF consumers will lookup the
18057 bounds type and then sign extend any unsigned values found
18058 for signed types. This is needed only for
18059 DW_AT_{lower,upper}_bound, since for most other attributes,
18060 consumers will treat DW_FORM_data[1248] as unsigned values,
18061 regardless of the underlying type. */
18062 if (prec
<= HOST_BITS_PER_WIDE_INT
18063 || tree_fits_uhwi_p (value
))
18065 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
18066 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
18068 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
18071 /* Otherwise represent the bound as an unsigned value with
18072 the precision of its type. The precision and signedness
18073 of the type will be necessary to re-interpret it
18075 add_AT_wide (die
, attr
, value
);
18079 /* Otherwise, if it's possible and permitted too, output a reference to
18081 if ((forms
& dw_scalar_form_reference
) != 0)
18083 tree decl
= NULL_TREE
;
18085 /* Some type attributes reference an outer type. For instance, the upper
18086 bound of an array may reference an embedding record (this happens in
18088 if (TREE_CODE (value
) == COMPONENT_REF
18089 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
18090 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
18091 decl
= TREE_OPERAND (value
, 1);
18093 else if (TREE_CODE (value
) == VAR_DECL
18094 || TREE_CODE (value
) == PARM_DECL
18095 || TREE_CODE (value
) == RESULT_DECL
)
18098 if (decl
!= NULL_TREE
)
18100 dw_die_ref decl_die
= lookup_decl_die (decl
);
18102 /* ??? Can this happen, or should the variable have been bound
18103 first? Probably it can, since I imagine that we try to create
18104 the types of parameters in the order in which they exist in
18105 the list, and won't have created a forward reference to a
18106 later parameter. */
18107 if (decl_die
!= NULL
)
18109 add_AT_die_ref (die
, attr
, decl_die
);
18115 /* Last chance: try to create a stack operation procedure to evaluate the
18116 value. Do nothing if even that is not possible or permitted. */
18117 if ((forms
& dw_scalar_form_exprloc
) == 0)
18120 list
= loc_list_from_tree (value
, 2, context
);
18121 if (list
== NULL
|| single_element_loc_list_p (list
))
18123 /* If this attribute is not a reference nor constant, it is
18124 a DWARF expression rather than location description. For that
18125 loc_list_from_tree (value, 0, &context) is needed. */
18126 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
18127 if (list2
&& single_element_loc_list_p (list2
))
18129 add_AT_loc (die
, attr
, list2
->expr
);
18134 /* If that failed to give a single element location list, fall back to
18135 outputting this as a reference... still if permitted. */
18136 if (list
== NULL
|| (forms
& dw_scalar_form_reference
) == 0)
18139 if (current_function_decl
== 0)
18140 context_die
= comp_unit_die ();
18142 context_die
= lookup_decl_die (current_function_decl
);
18144 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
18145 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18146 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
18148 add_AT_location_description (decl_die
, DW_AT_location
, list
);
18149 add_AT_die_ref (die
, attr
, decl_die
);
18152 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
18156 lower_bound_default (void)
18158 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
18164 case DW_LANG_C_plus_plus
:
18165 case DW_LANG_C_plus_plus_11
:
18166 case DW_LANG_C_plus_plus_14
:
18168 case DW_LANG_ObjC_plus_plus
:
18171 case DW_LANG_Fortran77
:
18172 case DW_LANG_Fortran90
:
18173 case DW_LANG_Fortran95
:
18174 case DW_LANG_Fortran03
:
18175 case DW_LANG_Fortran08
:
18179 case DW_LANG_Python
:
18180 return dwarf_version
>= 4 ? 0 : -1;
18181 case DW_LANG_Ada95
:
18182 case DW_LANG_Ada83
:
18183 case DW_LANG_Cobol74
:
18184 case DW_LANG_Cobol85
:
18185 case DW_LANG_Pascal83
:
18186 case DW_LANG_Modula2
:
18188 return dwarf_version
>= 4 ? 1 : -1;
18194 /* Given a tree node describing an array bound (either lower or upper) output
18195 a representation for that bound. */
18198 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
18199 tree bound
, const struct loc_descr_context
*context
)
18204 switch (TREE_CODE (bound
))
18206 /* Strip all conversions. */
18208 case VIEW_CONVERT_EXPR
:
18209 bound
= TREE_OPERAND (bound
, 0);
18212 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
18213 are even omitted when they are the default. */
18215 /* If the value for this bound is the default one, we can even omit the
18217 if (bound_attr
== DW_AT_lower_bound
18218 && tree_fits_shwi_p (bound
)
18219 && (dflt
= lower_bound_default ()) != -1
18220 && tree_to_shwi (bound
) == dflt
)
18226 /* Because of the complex interaction there can be with other GNAT
18227 encodings, GDB isn't ready yet to handle proper DWARF description
18228 for self-referencial subrange bounds: let GNAT encodings do the
18229 magic in such a case. */
18230 if (gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
18231 && contains_placeholder_p (bound
))
18234 add_scalar_info (subrange_die
, bound_attr
, bound
,
18235 dw_scalar_form_constant
18236 | dw_scalar_form_exprloc
18237 | dw_scalar_form_reference
,
18243 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
18244 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
18245 Note that the block of subscript information for an array type also
18246 includes information about the element type of the given array type.
18248 This function reuses previously set type and bound information if
18252 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
18254 unsigned dimension_number
;
18256 dw_die_ref child
= type_die
->die_child
;
18258 for (dimension_number
= 0;
18259 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
18260 type
= TREE_TYPE (type
), dimension_number
++)
18262 tree domain
= TYPE_DOMAIN (type
);
18264 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
18267 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
18268 and (in GNU C only) variable bounds. Handle all three forms
18271 /* Find and reuse a previously generated DW_TAG_subrange_type if
18274 For multi-dimensional arrays, as we iterate through the
18275 various dimensions in the enclosing for loop above, we also
18276 iterate through the DIE children and pick at each
18277 DW_TAG_subrange_type previously generated (if available).
18278 Each child DW_TAG_subrange_type DIE describes the range of
18279 the current dimension. At this point we should have as many
18280 DW_TAG_subrange_type's as we have dimensions in the
18282 dw_die_ref subrange_die
= NULL
;
18286 child
= child
->die_sib
;
18287 if (child
->die_tag
== DW_TAG_subrange_type
)
18288 subrange_die
= child
;
18289 if (child
== type_die
->die_child
)
18291 /* If we wrapped around, stop looking next time. */
18295 if (child
->die_tag
== DW_TAG_subrange_type
)
18299 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
18303 /* We have an array type with specified bounds. */
18304 lower
= TYPE_MIN_VALUE (domain
);
18305 upper
= TYPE_MAX_VALUE (domain
);
18307 /* Define the index type. */
18308 if (TREE_TYPE (domain
)
18309 && !get_AT (subrange_die
, DW_AT_type
))
18311 /* ??? This is probably an Ada unnamed subrange type. Ignore the
18312 TREE_TYPE field. We can't emit debug info for this
18313 because it is an unnamed integral type. */
18314 if (TREE_CODE (domain
) == INTEGER_TYPE
18315 && TYPE_NAME (domain
) == NULL_TREE
18316 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
18317 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
18320 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
18321 TYPE_UNQUALIFIED
, false, type_die
);
18324 /* ??? If upper is NULL, the array has unspecified length,
18325 but it does have a lower bound. This happens with Fortran
18327 Since the debugger is definitely going to need to know N
18328 to produce useful results, go ahead and output the lower
18329 bound solo, and hope the debugger can cope. */
18331 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
18332 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
18333 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
18334 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
18337 /* Otherwise we have an array type with an unspecified length. The
18338 DWARF-2 spec does not say how to handle this; let's just leave out the
18343 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
18346 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
18348 dw_die_ref decl_die
;
18349 HOST_WIDE_INT size
;
18350 dw_loc_descr_ref size_expr
= NULL
;
18352 switch (TREE_CODE (tree_node
))
18357 case ENUMERAL_TYPE
:
18360 case QUAL_UNION_TYPE
:
18361 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
18362 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
18364 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
18367 size_expr
= type_byte_size (tree_node
, &size
);
18370 /* For a data member of a struct or union, the DW_AT_byte_size is
18371 generally given as the number of bytes normally allocated for an
18372 object of the *declared* type of the member itself. This is true
18373 even for bit-fields. */
18374 size
= int_size_in_bytes (field_type (tree_node
));
18377 gcc_unreachable ();
18380 /* Support for dynamically-sized objects was introduced by DWARFv3.
18381 At the moment, GDB does not handle variable byte sizes very well,
18383 if ((dwarf_version
>= 3 || !dwarf_strict
)
18384 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
18385 && size_expr
!= NULL
)
18386 add_AT_loc (die
, DW_AT_byte_size
, size_expr
);
18388 /* Note that `size' might be -1 when we get to this point. If it is, that
18389 indicates that the byte size of the entity in question is variable and
18390 that we could not generate a DWARF expression that computes it. */
18392 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
18395 /* For a FIELD_DECL node which represents a bit-field, output an attribute
18396 which specifies the distance in bits from the highest order bit of the
18397 "containing object" for the bit-field to the highest order bit of the
18400 For any given bit-field, the "containing object" is a hypothetical object
18401 (of some integral or enum type) within which the given bit-field lives. The
18402 type of this hypothetical "containing object" is always the same as the
18403 declared type of the individual bit-field itself. The determination of the
18404 exact location of the "containing object" for a bit-field is rather
18405 complicated. It's handled by the `field_byte_offset' function (above).
18407 CTX is required: see the comment for VLR_CONTEXT.
18409 Note that it is the size (in bytes) of the hypothetical "containing object"
18410 which will be given in the DW_AT_byte_size attribute for this bit-field.
18411 (See `byte_size_attribute' above). */
18414 add_bit_offset_attribute (dw_die_ref die
, tree decl
, struct vlr_context
*ctx
)
18416 HOST_WIDE_INT object_offset_in_bytes
;
18417 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
18418 HOST_WIDE_INT bitpos_int
;
18419 HOST_WIDE_INT highest_order_object_bit_offset
;
18420 HOST_WIDE_INT highest_order_field_bit_offset
;
18421 HOST_WIDE_INT bit_offset
;
18423 field_byte_offset (decl
, ctx
, &object_offset_in_bytes
);
18425 /* Must be a field and a bit field. */
18426 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
18428 /* We can't yet handle bit-fields whose offsets are variable, so if we
18429 encounter such things, just return without generating any attribute
18430 whatsoever. Likewise for variable or too large size. */
18431 if (! tree_fits_shwi_p (bit_position (decl
))
18432 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
18435 bitpos_int
= int_bit_position (decl
);
18437 /* Note that the bit offset is always the distance (in bits) from the
18438 highest-order bit of the "containing object" to the highest-order bit of
18439 the bit-field itself. Since the "high-order end" of any object or field
18440 is different on big-endian and little-endian machines, the computation
18441 below must take account of these differences. */
18442 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
18443 highest_order_field_bit_offset
= bitpos_int
;
18445 if (! BYTES_BIG_ENDIAN
)
18447 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
18448 highest_order_object_bit_offset
+=
18449 simple_type_size_in_bits (original_type
);
18453 = (! BYTES_BIG_ENDIAN
18454 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
18455 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
18457 if (bit_offset
< 0)
18458 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
18460 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
18463 /* For a FIELD_DECL node which represents a bit field, output an attribute
18464 which specifies the length in bits of the given field. */
18467 add_bit_size_attribute (dw_die_ref die
, tree decl
)
18469 /* Must be a field and a bit field. */
18470 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
18471 && DECL_BIT_FIELD_TYPE (decl
));
18473 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
18474 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
18477 /* If the compiled language is ANSI C, then add a 'prototyped'
18478 attribute, if arg types are given for the parameters of a function. */
18481 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
18483 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
18490 if (prototype_p (func_type
))
18491 add_AT_flag (die
, DW_AT_prototyped
, 1);
18498 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
18499 by looking in either the type declaration or object declaration
18502 static inline dw_die_ref
18503 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
18505 dw_die_ref origin_die
= NULL
;
18507 if (TREE_CODE (origin
) != FUNCTION_DECL
)
18509 /* We may have gotten separated from the block for the inlined
18510 function, if we're in an exception handler or some such; make
18511 sure that the abstract function has been written out.
18513 Doing this for nested functions is wrong, however; functions are
18514 distinct units, and our context might not even be inline. */
18518 fn
= TYPE_STUB_DECL (fn
);
18520 fn
= decl_function_context (fn
);
18522 dwarf2out_abstract_function (fn
);
18525 if (DECL_P (origin
))
18526 origin_die
= lookup_decl_die (origin
);
18527 else if (TYPE_P (origin
))
18528 origin_die
= lookup_type_die (origin
);
18530 /* XXX: Functions that are never lowered don't always have correct block
18531 trees (in the case of java, they simply have no block tree, in some other
18532 languages). For these functions, there is nothing we can really do to
18533 output correct debug info for inlined functions in all cases. Rather
18534 than die, we'll just produce deficient debug info now, in that we will
18535 have variables without a proper abstract origin. In the future, when all
18536 functions are lowered, we should re-add a gcc_assert (origin_die)
18540 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
18544 /* We do not currently support the pure_virtual attribute. */
18547 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
18549 if (DECL_VINDEX (func_decl
))
18551 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18553 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
18554 add_AT_loc (die
, DW_AT_vtable_elem_location
,
18555 new_loc_descr (DW_OP_constu
,
18556 tree_to_shwi (DECL_VINDEX (func_decl
)),
18559 /* GNU extension: Record what type this method came from originally. */
18560 if (debug_info_level
> DINFO_LEVEL_TERSE
18561 && DECL_CONTEXT (func_decl
))
18562 add_AT_die_ref (die
, DW_AT_containing_type
,
18563 lookup_type_die (DECL_CONTEXT (func_decl
)));
18567 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
18568 given decl. This used to be a vendor extension until after DWARF 4
18569 standardized it. */
18572 add_linkage_attr (dw_die_ref die
, tree decl
)
18574 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
18576 /* Mimic what assemble_name_raw does with a leading '*'. */
18577 if (name
[0] == '*')
18580 if (dwarf_version
>= 4)
18581 add_AT_string (die
, DW_AT_linkage_name
, name
);
18583 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
18586 /* Add source coordinate attributes for the given decl. */
18589 add_src_coords_attributes (dw_die_ref die
, tree decl
)
18591 expanded_location s
;
18593 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
18595 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18596 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
18597 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
18600 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
18603 add_linkage_name_raw (dw_die_ref die
, tree decl
)
18605 /* Defer until we have an assembler name set. */
18606 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
18608 limbo_die_node
*asm_name
;
18610 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
18611 asm_name
->die
= die
;
18612 asm_name
->created_for
= decl
;
18613 asm_name
->next
= deferred_asm_name
;
18614 deferred_asm_name
= asm_name
;
18616 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
18617 add_linkage_attr (die
, decl
);
18620 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
18623 add_linkage_name (dw_die_ref die
, tree decl
)
18625 if (debug_info_level
> DINFO_LEVEL_NONE
18626 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
18627 && TREE_PUBLIC (decl
)
18628 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
18629 && die
->die_tag
!= DW_TAG_member
)
18630 add_linkage_name_raw (die
, decl
);
18633 /* Add a DW_AT_name attribute and source coordinate attribute for the
18634 given decl, but only if it actually has a name. */
18637 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
18641 decl_name
= DECL_NAME (decl
);
18642 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
18644 const char *name
= dwarf2_name (decl
, 0);
18646 add_name_attribute (die
, name
);
18647 if (! DECL_ARTIFICIAL (decl
))
18648 add_src_coords_attributes (die
, decl
);
18650 add_linkage_name (die
, decl
);
18653 #ifdef VMS_DEBUGGING_INFO
18654 /* Get the function's name, as described by its RTL. This may be different
18655 from the DECL_NAME name used in the source file. */
18656 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
18658 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
18659 XEXP (DECL_RTL (decl
), 0), false);
18660 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
18662 #endif /* VMS_DEBUGGING_INFO */
18665 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
18668 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
18672 attr
.dw_attr
= DW_AT_discr_value
;
18673 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
18674 attr
.dw_attr_val
.val_entry
= NULL
;
18675 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
18677 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
18679 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
18680 add_dwarf_attr (die
, &attr
);
18683 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
18686 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
18690 attr
.dw_attr
= DW_AT_discr_list
;
18691 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
18692 attr
.dw_attr_val
.val_entry
= NULL
;
18693 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
18694 add_dwarf_attr (die
, &attr
);
18697 static inline dw_discr_list_ref
18698 AT_discr_list (dw_attr_node
*attr
)
18700 return attr
->dw_attr_val
.v
.val_discr_list
;
18703 #ifdef VMS_DEBUGGING_INFO
18704 /* Output the debug main pointer die for VMS */
18707 dwarf2out_vms_debug_main_pointer (void)
18709 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18712 /* Allocate the VMS debug main subprogram die. */
18713 die
= ggc_cleared_alloc
<die_node
> ();
18714 die
->die_tag
= DW_TAG_subprogram
;
18715 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
18716 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
18717 current_function_funcdef_no
);
18718 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18720 /* Make it the first child of comp_unit_die (). */
18721 die
->die_parent
= comp_unit_die ();
18722 if (comp_unit_die ()->die_child
)
18724 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
18725 comp_unit_die ()->die_child
->die_sib
= die
;
18729 die
->die_sib
= die
;
18730 comp_unit_die ()->die_child
= die
;
18733 #endif /* VMS_DEBUGGING_INFO */
18735 /* Push a new declaration scope. */
18738 push_decl_scope (tree scope
)
18740 vec_safe_push (decl_scope_table
, scope
);
18743 /* Pop a declaration scope. */
18746 pop_decl_scope (void)
18748 decl_scope_table
->pop ();
18751 /* walk_tree helper function for uses_local_type, below. */
18754 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
18757 *walk_subtrees
= 0;
18760 tree name
= TYPE_NAME (*tp
);
18761 if (name
&& DECL_P (name
) && decl_function_context (name
))
18767 /* If TYPE involves a function-local type (including a local typedef to a
18768 non-local type), returns that type; otherwise returns NULL_TREE. */
18771 uses_local_type (tree type
)
18773 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
18777 /* Return the DIE for the scope that immediately contains this type.
18778 Non-named types that do not involve a function-local type get global
18779 scope. Named types nested in namespaces or other types get their
18780 containing scope. All other types (i.e. function-local named types) get
18781 the current active scope. */
18784 scope_die_for (tree t
, dw_die_ref context_die
)
18786 dw_die_ref scope_die
= NULL
;
18787 tree containing_scope
;
18789 /* Non-types always go in the current scope. */
18790 gcc_assert (TYPE_P (t
));
18792 /* Use the scope of the typedef, rather than the scope of the type
18794 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
18795 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
18797 containing_scope
= TYPE_CONTEXT (t
);
18799 /* Use the containing namespace if there is one. */
18800 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
18802 if (context_die
== lookup_decl_die (containing_scope
))
18804 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
18805 context_die
= get_context_die (containing_scope
);
18807 containing_scope
= NULL_TREE
;
18810 /* Ignore function type "scopes" from the C frontend. They mean that
18811 a tagged type is local to a parmlist of a function declarator, but
18812 that isn't useful to DWARF. */
18813 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
18814 containing_scope
= NULL_TREE
;
18816 if (SCOPE_FILE_SCOPE_P (containing_scope
))
18818 /* If T uses a local type keep it local as well, to avoid references
18819 to function-local DIEs from outside the function. */
18820 if (current_function_decl
&& uses_local_type (t
))
18821 scope_die
= context_die
;
18823 scope_die
= comp_unit_die ();
18825 else if (TYPE_P (containing_scope
))
18827 /* For types, we can just look up the appropriate DIE. */
18828 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18829 scope_die
= get_context_die (containing_scope
);
18832 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
18833 if (scope_die
== NULL
)
18834 scope_die
= comp_unit_die ();
18838 scope_die
= context_die
;
18843 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
18846 local_scope_p (dw_die_ref context_die
)
18848 for (; context_die
; context_die
= context_die
->die_parent
)
18849 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
18850 || context_die
->die_tag
== DW_TAG_subprogram
)
18856 /* Returns nonzero if CONTEXT_DIE is a class. */
18859 class_scope_p (dw_die_ref context_die
)
18861 return (context_die
18862 && (context_die
->die_tag
== DW_TAG_structure_type
18863 || context_die
->die_tag
== DW_TAG_class_type
18864 || context_die
->die_tag
== DW_TAG_interface_type
18865 || context_die
->die_tag
== DW_TAG_union_type
));
18868 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
18869 whether or not to treat a DIE in this context as a declaration. */
18872 class_or_namespace_scope_p (dw_die_ref context_die
)
18874 return (class_scope_p (context_die
)
18875 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
18878 /* Many forms of DIEs require a "type description" attribute. This
18879 routine locates the proper "type descriptor" die for the type given
18880 by 'type' plus any additional qualifiers given by 'cv_quals', and
18881 adds a DW_AT_type attribute below the given die. */
18884 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
18885 bool reverse
, dw_die_ref context_die
)
18887 enum tree_code code
= TREE_CODE (type
);
18888 dw_die_ref type_die
= NULL
;
18890 /* ??? If this type is an unnamed subrange type of an integral, floating-point
18891 or fixed-point type, use the inner type. This is because we have no
18892 support for unnamed types in base_type_die. This can happen if this is
18893 an Ada subrange type. Correct solution is emit a subrange type die. */
18894 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
18895 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
18896 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
18898 if (code
== ERROR_MARK
18899 /* Handle a special case. For functions whose return type is void, we
18900 generate *no* type attribute. (Note that no object may have type
18901 `void', so this only applies to function return types). */
18902 || code
== VOID_TYPE
)
18905 type_die
= modified_type_die (type
,
18906 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
18910 if (type_die
!= NULL
)
18911 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
18914 /* Given an object die, add the calling convention attribute for the
18915 function call type. */
18917 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
18919 enum dwarf_calling_convention value
= DW_CC_normal
;
18921 value
= ((enum dwarf_calling_convention
)
18922 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
18925 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
18927 /* DWARF 2 doesn't provide a way to identify a program's source-level
18928 entry point. DW_AT_calling_convention attributes are only meant
18929 to describe functions' calling conventions. However, lacking a
18930 better way to signal the Fortran main program, we used this for
18931 a long time, following existing custom. Now, DWARF 4 has
18932 DW_AT_main_subprogram, which we add below, but some tools still
18933 rely on the old way, which we thus keep. */
18934 value
= DW_CC_program
;
18936 if (dwarf_version
>= 4 || !dwarf_strict
)
18937 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
18940 /* Only add the attribute if the backend requests it, and
18941 is not DW_CC_normal. */
18942 if (value
&& (value
!= DW_CC_normal
))
18943 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
18946 /* Given a tree pointer to a struct, class, union, or enum type node, return
18947 a pointer to the (string) tag name for the given type, or zero if the type
18948 was declared without a tag. */
18950 static const char *
18951 type_tag (const_tree type
)
18953 const char *name
= 0;
18955 if (TYPE_NAME (type
) != 0)
18959 /* Find the IDENTIFIER_NODE for the type name. */
18960 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
18961 && !TYPE_NAMELESS (type
))
18962 t
= TYPE_NAME (type
);
18964 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18965 a TYPE_DECL node, regardless of whether or not a `typedef' was
18967 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
18968 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
18970 /* We want to be extra verbose. Don't call dwarf_name if
18971 DECL_NAME isn't set. The default hook for decl_printable_name
18972 doesn't like that, and in this context it's correct to return
18973 0, instead of "<anonymous>" or the like. */
18974 if (DECL_NAME (TYPE_NAME (type
))
18975 && !DECL_NAMELESS (TYPE_NAME (type
)))
18976 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
18979 /* Now get the name as a string, or invent one. */
18980 if (!name
&& t
!= 0)
18981 name
= IDENTIFIER_POINTER (t
);
18984 return (name
== 0 || *name
== '\0') ? 0 : name
;
18987 /* Return the type associated with a data member, make a special check
18988 for bit field types. */
18991 member_declared_type (const_tree member
)
18993 return (DECL_BIT_FIELD_TYPE (member
)
18994 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
18997 /* Get the decl's label, as described by its RTL. This may be different
18998 from the DECL_NAME name used in the source file. */
19001 static const char *
19002 decl_start_label (tree decl
)
19005 const char *fnname
;
19007 x
= DECL_RTL (decl
);
19008 gcc_assert (MEM_P (x
));
19011 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
19013 fnname
= XSTR (x
, 0);
19018 /* For variable-length arrays that have been previously generated, but
19019 may be incomplete due to missing subscript info, fill the subscript
19020 info. Return TRUE if this is one of those cases. */
19022 fill_variable_array_bounds (tree type
)
19024 if (TREE_ASM_WRITTEN (type
)
19025 && TREE_CODE (type
) == ARRAY_TYPE
19026 && variably_modified_type_p (type
, NULL
))
19028 dw_die_ref array_die
= lookup_type_die (type
);
19031 add_subscript_info (array_die
, type
, !is_ada ());
19037 /* These routines generate the internal representation of the DIE's for
19038 the compilation unit. Debugging information is collected by walking
19039 the declaration trees passed in from dwarf2out_decl(). */
19042 gen_array_type_die (tree type
, dw_die_ref context_die
)
19044 dw_die_ref array_die
;
19046 /* GNU compilers represent multidimensional array types as sequences of one
19047 dimensional array types whose element types are themselves array types.
19048 We sometimes squish that down to a single array_type DIE with multiple
19049 subscripts in the Dwarf debugging info. The draft Dwarf specification
19050 say that we are allowed to do this kind of compression in C, because
19051 there is no difference between an array of arrays and a multidimensional
19052 array. We don't do this for Ada to remain as close as possible to the
19053 actual representation, which is especially important against the language
19054 flexibilty wrt arrays of variable size. */
19056 bool collapse_nested_arrays
= !is_ada ();
19058 if (fill_variable_array_bounds (type
))
19061 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
19064 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
19065 DW_TAG_string_type doesn't have DW_AT_type attribute). */
19066 if (TYPE_STRING_FLAG (type
)
19067 && TREE_CODE (type
) == ARRAY_TYPE
19069 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
19071 HOST_WIDE_INT size
;
19073 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
19074 add_name_attribute (array_die
, type_tag (type
));
19075 equate_type_number_to_die (type
, array_die
);
19076 size
= int_size_in_bytes (type
);
19078 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
19079 else if (TYPE_DOMAIN (type
) != NULL_TREE
19080 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
19081 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
19083 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
19084 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2, NULL
);
19086 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
19087 if (loc
&& size
> 0)
19089 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
19090 if (size
!= DWARF2_ADDR_SIZE
)
19091 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
19097 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
19098 add_name_attribute (array_die
, type_tag (type
));
19099 equate_type_number_to_die (type
, array_die
);
19101 if (TREE_CODE (type
) == VECTOR_TYPE
)
19102 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
19104 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
19106 && TREE_CODE (type
) == ARRAY_TYPE
19107 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
19108 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
19109 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
19112 /* We default the array ordering. SDB will probably do
19113 the right things even if DW_AT_ordering is not present. It's not even
19114 an issue until we start to get into multidimensional arrays anyway. If
19115 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
19116 then we'll have to put the DW_AT_ordering attribute back in. (But if
19117 and when we find out that we need to put these in, we will only do so
19118 for multidimensional arrays. */
19119 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
19122 if (TREE_CODE (type
) == VECTOR_TYPE
)
19124 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
19125 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
19126 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
19127 add_bound_info (subrange_die
, DW_AT_upper_bound
,
19128 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
19131 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
19133 /* Add representation of the type of the elements of this array type and
19134 emit the corresponding DIE if we haven't done it already. */
19135 element_type
= TREE_TYPE (type
);
19136 if (collapse_nested_arrays
)
19137 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
19139 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
19141 element_type
= TREE_TYPE (element_type
);
19144 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
19145 TREE_CODE (type
) == ARRAY_TYPE
19146 && TYPE_REVERSE_STORAGE_ORDER (type
),
19149 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
19150 if (TYPE_ARTIFICIAL (type
))
19151 add_AT_flag (array_die
, DW_AT_artificial
, 1);
19153 if (get_AT (array_die
, DW_AT_name
))
19154 add_pubtype (type
, array_die
);
19157 /* This routine generates DIE for array with hidden descriptor, details
19158 are filled into *info by a langhook. */
19161 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
19162 dw_die_ref context_die
)
19164 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
19165 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
19166 const struct loc_descr_context context
= { type
, info
->base_decl
, NULL
};
19169 add_name_attribute (array_die
, type_tag (type
));
19170 equate_type_number_to_die (type
, array_die
);
19172 if (info
->ndimensions
> 1)
19173 switch (info
->ordering
)
19175 case array_descr_ordering_row_major
:
19176 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
19178 case array_descr_ordering_column_major
:
19179 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
19185 if (dwarf_version
>= 3 || !dwarf_strict
)
19187 if (info
->data_location
)
19188 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
19189 dw_scalar_form_exprloc
, &context
);
19190 if (info
->associated
)
19191 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
19192 dw_scalar_form_constant
19193 | dw_scalar_form_exprloc
19194 | dw_scalar_form_reference
, &context
);
19195 if (info
->allocated
)
19196 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
19197 dw_scalar_form_constant
19198 | dw_scalar_form_exprloc
19199 | dw_scalar_form_reference
, &context
);
19202 const enum dwarf_attribute attr
19203 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
19205 = (info
->stride_in_bits
)
19206 ? dw_scalar_form_constant
19207 : (dw_scalar_form_constant
19208 | dw_scalar_form_exprloc
19209 | dw_scalar_form_reference
);
19211 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
19215 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
19217 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
19219 dw_die_ref subrange_die
19220 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
19222 if (info
->dimen
[dim
].bounds_type
)
19223 add_type_attribute (subrange_die
,
19224 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
19225 false, context_die
);
19226 if (info
->dimen
[dim
].lower_bound
)
19227 add_bound_info (subrange_die
, DW_AT_lower_bound
,
19228 info
->dimen
[dim
].lower_bound
, &context
);
19229 if (info
->dimen
[dim
].upper_bound
)
19230 add_bound_info (subrange_die
, DW_AT_upper_bound
,
19231 info
->dimen
[dim
].upper_bound
, &context
);
19232 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
19233 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
19234 info
->dimen
[dim
].stride
,
19235 dw_scalar_form_constant
19236 | dw_scalar_form_exprloc
19237 | dw_scalar_form_reference
,
19241 gen_type_die (info
->element_type
, context_die
);
19242 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
19243 TREE_CODE (type
) == ARRAY_TYPE
19244 && TYPE_REVERSE_STORAGE_ORDER (type
),
19247 if (get_AT (array_die
, DW_AT_name
))
19248 add_pubtype (type
, array_die
);
19253 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
19255 tree origin
= decl_ultimate_origin (decl
);
19256 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
19258 if (origin
!= NULL
)
19259 add_abstract_origin_attribute (decl_die
, origin
);
19262 add_name_and_src_coords_attributes (decl_die
, decl
);
19263 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
19264 TYPE_UNQUALIFIED
, false, context_die
);
19267 if (DECL_ABSTRACT_P (decl
))
19268 equate_decl_number_to_die (decl
, decl_die
);
19270 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
19274 /* Walk through the list of incomplete types again, trying once more to
19275 emit full debugging info for them. */
19278 retry_incomplete_types (void)
19282 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
19283 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
19284 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
19287 /* Determine what tag to use for a record type. */
19289 static enum dwarf_tag
19290 record_type_tag (tree type
)
19292 if (! lang_hooks
.types
.classify_record
)
19293 return DW_TAG_structure_type
;
19295 switch (lang_hooks
.types
.classify_record (type
))
19297 case RECORD_IS_STRUCT
:
19298 return DW_TAG_structure_type
;
19300 case RECORD_IS_CLASS
:
19301 return DW_TAG_class_type
;
19303 case RECORD_IS_INTERFACE
:
19304 if (dwarf_version
>= 3 || !dwarf_strict
)
19305 return DW_TAG_interface_type
;
19306 return DW_TAG_structure_type
;
19309 gcc_unreachable ();
19313 /* Generate a DIE to represent an enumeration type. Note that these DIEs
19314 include all of the information about the enumeration values also. Each
19315 enumerated type name/value is listed as a child of the enumerated type
19319 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
19321 dw_die_ref type_die
= lookup_type_die (type
);
19323 if (type_die
== NULL
)
19325 type_die
= new_die (DW_TAG_enumeration_type
,
19326 scope_die_for (type
, context_die
), type
);
19327 equate_type_number_to_die (type
, type_die
);
19328 add_name_attribute (type_die
, type_tag (type
));
19329 if (dwarf_version
>= 4 || !dwarf_strict
)
19331 if (ENUM_IS_SCOPED (type
))
19332 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
19333 if (ENUM_IS_OPAQUE (type
))
19334 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19337 else if (! TYPE_SIZE (type
))
19340 remove_AT (type_die
, DW_AT_declaration
);
19342 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
19343 given enum type is incomplete, do not generate the DW_AT_byte_size
19344 attribute or the DW_AT_element_list attribute. */
19345 if (TYPE_SIZE (type
))
19349 TREE_ASM_WRITTEN (type
) = 1;
19350 add_byte_size_attribute (type_die
, type
);
19351 if (dwarf_version
>= 3 || !dwarf_strict
)
19353 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
19354 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
19357 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19359 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19360 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19363 /* If the first reference to this type was as the return type of an
19364 inline function, then it may not have a parent. Fix this now. */
19365 if (type_die
->die_parent
== NULL
)
19366 add_child_die (scope_die_for (type
, context_die
), type_die
);
19368 for (link
= TYPE_VALUES (type
);
19369 link
!= NULL
; link
= TREE_CHAIN (link
))
19371 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
19372 tree value
= TREE_VALUE (link
);
19374 add_name_attribute (enum_die
,
19375 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
19377 if (TREE_CODE (value
) == CONST_DECL
)
19378 value
= DECL_INITIAL (value
);
19380 if (simple_type_size_in_bits (TREE_TYPE (value
))
19381 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
19383 /* For constant forms created by add_AT_unsigned DWARF
19384 consumers (GDB, elfutils, etc.) always zero extend
19385 the value. Only when the actual value is negative
19386 do we need to use add_AT_int to generate a constant
19387 form that can represent negative values. */
19388 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
19389 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
19390 add_AT_unsigned (enum_die
, DW_AT_const_value
,
19391 (unsigned HOST_WIDE_INT
) val
);
19393 add_AT_int (enum_die
, DW_AT_const_value
, val
);
19396 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
19397 that here. TODO: This should be re-worked to use correct
19398 signed/unsigned double tags for all cases. */
19399 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
19402 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19403 if (TYPE_ARTIFICIAL (type
))
19404 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19407 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19409 add_pubtype (type
, type_die
);
19414 /* Generate a DIE to represent either a real live formal parameter decl or to
19415 represent just the type of some formal parameter position in some function
19418 Note that this routine is a bit unusual because its argument may be a
19419 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
19420 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
19421 node. If it's the former then this function is being called to output a
19422 DIE to represent a formal parameter object (or some inlining thereof). If
19423 it's the latter, then this function is only being called to output a
19424 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
19425 argument type of some subprogram type.
19426 If EMIT_NAME_P is true, name and source coordinate attributes
19430 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
19431 dw_die_ref context_die
)
19433 tree node_or_origin
= node
? node
: origin
;
19434 tree ultimate_origin
;
19435 dw_die_ref parm_die
= NULL
;
19437 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
19439 parm_die
= lookup_decl_die (node
);
19441 /* If the contexts differ, we may not be talking about the same
19443 if (parm_die
&& parm_die
->die_parent
!= context_die
)
19445 if (!DECL_ABSTRACT_P (node
))
19447 /* This can happen when creating an inlined instance, in
19448 which case we need to create a new DIE that will get
19449 annotated with DW_AT_abstract_origin. */
19454 /* FIXME: Reuse DIE even with a differing context.
19456 This can happen when calling
19457 dwarf2out_abstract_function to build debug info for
19458 the abstract instance of a function for which we have
19459 already generated a DIE in
19460 dwarf2out_early_global_decl.
19462 Once we remove dwarf2out_abstract_function, we should
19463 have a call to gcc_unreachable here. */
19467 if (parm_die
&& parm_die
->die_parent
== NULL
)
19469 /* Check that parm_die already has the right attributes that
19470 we would have added below. If any attributes are
19471 missing, fall through to add them. */
19472 if (! DECL_ABSTRACT_P (node_or_origin
)
19473 && !get_AT (parm_die
, DW_AT_location
)
19474 && !get_AT (parm_die
, DW_AT_const_value
))
19475 /* We are missing location info, and are about to add it. */
19479 add_child_die (context_die
, parm_die
);
19485 /* If we have a previously generated DIE, use it, unless this is an
19486 concrete instance (origin != NULL), in which case we need a new
19487 DIE with a corresponding DW_AT_abstract_origin. */
19489 if (parm_die
&& origin
== NULL
)
19490 reusing_die
= true;
19493 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
19494 reusing_die
= false;
19497 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
19499 case tcc_declaration
:
19500 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
19501 if (node
|| ultimate_origin
)
19502 origin
= ultimate_origin
;
19507 if (origin
!= NULL
)
19508 add_abstract_origin_attribute (parm_die
, origin
);
19509 else if (emit_name_p
)
19510 add_name_and_src_coords_attributes (parm_die
, node
);
19512 || (! DECL_ABSTRACT_P (node_or_origin
)
19513 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
19514 decl_function_context
19515 (node_or_origin
))))
19517 tree type
= TREE_TYPE (node_or_origin
);
19518 if (decl_by_reference_p (node_or_origin
))
19519 add_type_attribute (parm_die
, TREE_TYPE (type
),
19521 false, context_die
);
19523 add_type_attribute (parm_die
, type
,
19524 decl_quals (node_or_origin
),
19525 false, context_die
);
19527 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
19528 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
19530 if (node
&& node
!= origin
)
19531 equate_decl_number_to_die (node
, parm_die
);
19532 if (! DECL_ABSTRACT_P (node_or_origin
))
19533 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
19539 /* We were called with some kind of a ..._TYPE node. */
19540 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
19545 gcc_unreachable ();
19551 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
19552 children DW_TAG_formal_parameter DIEs representing the arguments of the
19555 PARM_PACK must be a function parameter pack.
19556 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
19557 must point to the subsequent arguments of the function PACK_ARG belongs to.
19558 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
19559 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
19560 following the last one for which a DIE was generated. */
19563 gen_formal_parameter_pack_die (tree parm_pack
,
19565 dw_die_ref subr_die
,
19569 dw_die_ref parm_pack_die
;
19571 gcc_assert (parm_pack
19572 && lang_hooks
.function_parameter_pack_p (parm_pack
)
19575 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
19576 add_src_coords_attributes (parm_pack_die
, parm_pack
);
19578 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
19580 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
19583 gen_formal_parameter_die (arg
, NULL
,
19584 false /* Don't emit name attribute. */,
19589 return parm_pack_die
;
19592 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
19593 at the end of an (ANSI prototyped) formal parameters list. */
19596 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
19598 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
19601 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
19602 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
19603 parameters as specified in some function type specification (except for
19604 those which appear as part of a function *definition*). */
19607 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
19610 tree formal_type
= NULL
;
19611 tree first_parm_type
;
19614 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
19616 arg
= DECL_ARGUMENTS (function_or_method_type
);
19617 function_or_method_type
= TREE_TYPE (function_or_method_type
);
19622 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
19624 /* Make our first pass over the list of formal parameter types and output a
19625 DW_TAG_formal_parameter DIE for each one. */
19626 for (link
= first_parm_type
; link
; )
19628 dw_die_ref parm_die
;
19630 formal_type
= TREE_VALUE (link
);
19631 if (formal_type
== void_type_node
)
19634 /* Output a (nameless) DIE to represent the formal parameter itself. */
19635 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
19637 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
19638 true /* Emit name attribute. */,
19640 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
19641 && link
== first_parm_type
)
19643 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
19644 if (dwarf_version
>= 3 || !dwarf_strict
)
19645 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
19647 else if (arg
&& DECL_ARTIFICIAL (arg
))
19648 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
19651 link
= TREE_CHAIN (link
);
19653 arg
= DECL_CHAIN (arg
);
19656 /* If this function type has an ellipsis, add a
19657 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
19658 if (formal_type
!= void_type_node
)
19659 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
19661 /* Make our second (and final) pass over the list of formal parameter types
19662 and output DIEs to represent those types (as necessary). */
19663 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
19664 link
&& TREE_VALUE (link
);
19665 link
= TREE_CHAIN (link
))
19666 gen_type_die (TREE_VALUE (link
), context_die
);
19669 /* We want to generate the DIE for TYPE so that we can generate the
19670 die for MEMBER, which has been defined; we will need to refer back
19671 to the member declaration nested within TYPE. If we're trying to
19672 generate minimal debug info for TYPE, processing TYPE won't do the
19673 trick; we need to attach the member declaration by hand. */
19676 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
19678 gen_type_die (type
, context_die
);
19680 /* If we're trying to avoid duplicate debug info, we may not have
19681 emitted the member decl for this function. Emit it now. */
19682 if (TYPE_STUB_DECL (type
)
19683 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
19684 && ! lookup_decl_die (member
))
19686 dw_die_ref type_die
;
19687 gcc_assert (!decl_ultimate_origin (member
));
19689 push_decl_scope (type
);
19690 type_die
= lookup_type_die_strip_naming_typedef (type
);
19691 if (TREE_CODE (member
) == FUNCTION_DECL
)
19692 gen_subprogram_die (member
, type_die
);
19693 else if (TREE_CODE (member
) == FIELD_DECL
)
19695 /* Ignore the nameless fields that are used to skip bits but handle
19696 C++ anonymous unions and structs. */
19697 if (DECL_NAME (member
) != NULL_TREE
19698 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
19699 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
19701 struct vlr_context vlr_ctx
= {
19702 DECL_CONTEXT (member
), /* struct_type */
19703 NULL_TREE
/* variant_part_offset */
19705 gen_type_die (member_declared_type (member
), type_die
);
19706 gen_field_die (member
, &vlr_ctx
, type_die
);
19710 gen_variable_die (member
, NULL_TREE
, type_die
);
19716 /* Forward declare these functions, because they are mutually recursive
19717 with their set_block_* pairing functions. */
19718 static void set_decl_origin_self (tree
);
19719 static void set_decl_abstract_flags (tree
, vec
<tree
> &);
19721 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
19722 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
19723 that it points to the node itself, thus indicating that the node is its
19724 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
19725 the given node is NULL, recursively descend the decl/block tree which
19726 it is the root of, and for each other ..._DECL or BLOCK node contained
19727 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
19728 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
19729 values to point to themselves. */
19732 set_block_origin_self (tree stmt
)
19734 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
19736 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
19741 for (local_decl
= BLOCK_VARS (stmt
);
19742 local_decl
!= NULL_TREE
;
19743 local_decl
= DECL_CHAIN (local_decl
))
19744 /* Do not recurse on nested functions since the inlining status
19745 of parent and child can be different as per the DWARF spec. */
19746 if (TREE_CODE (local_decl
) != FUNCTION_DECL
19747 && !DECL_EXTERNAL (local_decl
))
19748 set_decl_origin_self (local_decl
);
19754 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
19755 subblock
!= NULL_TREE
;
19756 subblock
= BLOCK_CHAIN (subblock
))
19757 set_block_origin_self (subblock
); /* Recurse. */
19762 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
19763 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
19764 node to so that it points to the node itself, thus indicating that the
19765 node represents its own (abstract) origin. Additionally, if the
19766 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
19767 the decl/block tree of which the given node is the root of, and for
19768 each other ..._DECL or BLOCK node contained therein whose
19769 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
19770 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
19771 point to themselves. */
19774 set_decl_origin_self (tree decl
)
19776 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
19778 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
19779 if (TREE_CODE (decl
) == FUNCTION_DECL
)
19783 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
19784 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
19785 if (DECL_INITIAL (decl
) != NULL_TREE
19786 && DECL_INITIAL (decl
) != error_mark_node
)
19787 set_block_origin_self (DECL_INITIAL (decl
));
19792 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
19793 and if it wasn't 1 before, push it to abstract_vec vector.
19794 For all local decls and all local sub-blocks (recursively) do it
19798 set_block_abstract_flags (tree stmt
, vec
<tree
> &abstract_vec
)
19804 if (!BLOCK_ABSTRACT (stmt
))
19806 abstract_vec
.safe_push (stmt
);
19807 BLOCK_ABSTRACT (stmt
) = 1;
19810 for (local_decl
= BLOCK_VARS (stmt
);
19811 local_decl
!= NULL_TREE
;
19812 local_decl
= DECL_CHAIN (local_decl
))
19813 if (! DECL_EXTERNAL (local_decl
))
19814 set_decl_abstract_flags (local_decl
, abstract_vec
);
19816 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19818 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
19819 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
19820 || TREE_CODE (local_decl
) == PARM_DECL
)
19821 set_decl_abstract_flags (local_decl
, abstract_vec
);
19824 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
19825 subblock
!= NULL_TREE
;
19826 subblock
= BLOCK_CHAIN (subblock
))
19827 set_block_abstract_flags (subblock
, abstract_vec
);
19830 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
19831 to 1 and if it wasn't 1 before, push to abstract_vec vector.
19832 In the case where the decl is a FUNCTION_DECL also set the abstract
19833 flags for all of the parameters, local vars, local
19834 blocks and sub-blocks (recursively). */
19837 set_decl_abstract_flags (tree decl
, vec
<tree
> &abstract_vec
)
19839 if (!DECL_ABSTRACT_P (decl
))
19841 abstract_vec
.safe_push (decl
);
19842 DECL_ABSTRACT_P (decl
) = 1;
19845 if (TREE_CODE (decl
) == FUNCTION_DECL
)
19849 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
19850 if (!DECL_ABSTRACT_P (arg
))
19852 abstract_vec
.safe_push (arg
);
19853 DECL_ABSTRACT_P (arg
) = 1;
19855 if (DECL_INITIAL (decl
) != NULL_TREE
19856 && DECL_INITIAL (decl
) != error_mark_node
)
19857 set_block_abstract_flags (DECL_INITIAL (decl
), abstract_vec
);
19861 /* Generate the DWARF2 info for the "abstract" instance of a function which we
19862 may later generate inlined and/or out-of-line instances of.
19864 FIXME: In the early-dwarf world, this function, and most of the
19865 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
19866 the abstract instance. All we would need to do is annotate
19867 the early DIE with the appropriate DW_AT_inline in late
19868 dwarf (perhaps in gen_inlined_subroutine_die).
19870 However, we can't do this yet, because LTO streaming of DIEs
19871 has not been implemented yet. */
19874 dwarf2out_abstract_function (tree decl
)
19876 dw_die_ref old_die
;
19879 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
19880 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
19881 int old_call_site_count
, old_tail_call_site_count
;
19882 struct call_arg_loc_node
*old_call_arg_locations
;
19884 /* Make sure we have the actual abstract inline, not a clone. */
19885 decl
= DECL_ORIGIN (decl
);
19887 old_die
= lookup_decl_die (decl
);
19888 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
19889 /* We've already generated the abstract instance. */
19892 /* We can be called while recursively when seeing block defining inlined subroutine
19893 DIE. Be sure to not clobber the outer location table nor use it or we would
19894 get locations in abstract instantces. */
19895 old_decl_loc_table
= decl_loc_table
;
19896 decl_loc_table
= NULL
;
19897 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
19898 cached_dw_loc_list_table
= NULL
;
19899 old_call_arg_locations
= call_arg_locations
;
19900 call_arg_locations
= NULL
;
19901 old_call_site_count
= call_site_count
;
19902 call_site_count
= -1;
19903 old_tail_call_site_count
= tail_call_site_count
;
19904 tail_call_site_count
= -1;
19906 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
19907 we don't get confused by DECL_ABSTRACT_P. */
19908 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19910 context
= decl_class_context (decl
);
19912 gen_type_die_for_member
19913 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
19916 /* Pretend we've just finished compiling this function. */
19917 save_fn
= current_function_decl
;
19918 current_function_decl
= decl
;
19920 auto_vec
<tree
, 64> abstract_vec
;
19921 set_decl_abstract_flags (decl
, abstract_vec
);
19922 dwarf2out_decl (decl
);
19925 FOR_EACH_VEC_ELT (abstract_vec
, i
, t
)
19926 if (TREE_CODE (t
) == BLOCK
)
19927 BLOCK_ABSTRACT (t
) = 0;
19929 DECL_ABSTRACT_P (t
) = 0;
19931 current_function_decl
= save_fn
;
19932 decl_loc_table
= old_decl_loc_table
;
19933 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
19934 call_arg_locations
= old_call_arg_locations
;
19935 call_site_count
= old_call_site_count
;
19936 tail_call_site_count
= old_tail_call_site_count
;
19939 /* Helper function of premark_used_types() which gets called through
19942 Marks the DIE of a given type in *SLOT as perennial, so it never gets
19943 marked as unused by prune_unused_types. */
19946 premark_used_types_helper (tree
const &type
, void *)
19950 die
= lookup_type_die (type
);
19952 die
->die_perennial_p
= 1;
19956 /* Helper function of premark_types_used_by_global_vars which gets called
19957 through htab_traverse.
19959 Marks the DIE of a given type in *SLOT as perennial, so it never gets
19960 marked as unused by prune_unused_types. The DIE of the type is marked
19961 only if the global variable using the type will actually be emitted. */
19964 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
19967 struct types_used_by_vars_entry
*entry
;
19970 entry
= (struct types_used_by_vars_entry
*) *slot
;
19971 gcc_assert (entry
->type
!= NULL
19972 && entry
->var_decl
!= NULL
);
19973 die
= lookup_type_die (entry
->type
);
19976 /* Ask cgraph if the global variable really is to be emitted.
19977 If yes, then we'll keep the DIE of ENTRY->TYPE. */
19978 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
19979 if (node
&& node
->definition
)
19981 die
->die_perennial_p
= 1;
19982 /* Keep the parent DIEs as well. */
19983 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
19984 die
->die_perennial_p
= 1;
19990 /* Mark all members of used_types_hash as perennial. */
19993 premark_used_types (struct function
*fun
)
19995 if (fun
&& fun
->used_types_hash
)
19996 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
19999 /* Mark all members of types_used_by_vars_entry as perennial. */
20002 premark_types_used_by_global_vars (void)
20004 if (types_used_by_vars_hash
)
20005 types_used_by_vars_hash
20006 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
20009 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
20010 for CA_LOC call arg loc node. */
20013 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
20014 struct call_arg_loc_node
*ca_loc
)
20016 dw_die_ref stmt_die
= NULL
, die
;
20017 tree block
= ca_loc
->block
;
20020 && block
!= DECL_INITIAL (decl
)
20021 && TREE_CODE (block
) == BLOCK
)
20023 stmt_die
= BLOCK_DIE (block
);
20026 block
= BLOCK_SUPERCONTEXT (block
);
20028 if (stmt_die
== NULL
)
20029 stmt_die
= subr_die
;
20030 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
20031 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
20032 if (ca_loc
->tail_call_p
)
20033 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
20034 if (ca_loc
->symbol_ref
)
20036 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
20038 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
20040 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
20045 /* Generate a DIE to represent a declared function (either file-scope or
20049 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
20051 tree origin
= decl_ultimate_origin (decl
);
20052 dw_die_ref subr_die
;
20053 dw_die_ref old_die
= lookup_decl_die (decl
);
20055 /* This function gets called multiple times for different stages of
20056 the debug process. For example, for func() in this code:
20060 void func() { ... }
20063 ...we get called 4 times. Twice in early debug and twice in
20069 1. Once while generating func() within the namespace. This is
20070 the declaration. The declaration bit below is set, as the
20071 context is the namespace.
20073 A new DIE will be generated with DW_AT_declaration set.
20075 2. Once for func() itself. This is the specification. The
20076 declaration bit below is clear as the context is the CU.
20078 We will use the cached DIE from (1) to create a new DIE with
20079 DW_AT_specification pointing to the declaration in (1).
20081 Late debug via rest_of_handle_final()
20082 -------------------------------------
20084 3. Once generating func() within the namespace. This is also the
20085 declaration, as in (1), but this time we will early exit below
20086 as we have a cached DIE and a declaration needs no additional
20087 annotations (no locations), as the source declaration line
20090 4. Once for func() itself. As in (2), this is the specification,
20091 but this time we will re-use the cached DIE, and just annotate
20092 it with the location information that should now be available.
20094 For something without namespaces, but with abstract instances, we
20095 are also called a multiple times:
20100 Base (); // constructor declaration (1)
20103 Base::Base () { } // constructor specification (2)
20108 1. Once for the Base() constructor by virtue of it being a
20109 member of the Base class. This is done via
20110 rest_of_type_compilation.
20112 This is a declaration, so a new DIE will be created with
20115 2. Once for the Base() constructor definition, but this time
20116 while generating the abstract instance of the base
20117 constructor (__base_ctor) which is being generated via early
20118 debug of reachable functions.
20120 Even though we have a cached version of the declaration (1),
20121 we will create a DW_AT_specification of the declaration DIE
20124 3. Once for the __base_ctor itself, but this time, we generate
20125 an DW_AT_abstract_origin version of the DW_AT_specification in
20128 Late debug via rest_of_handle_final
20129 -----------------------------------
20131 4. One final time for the __base_ctor (which will have a cached
20132 DIE with DW_AT_abstract_origin created in (3). This time,
20133 we will just annotate the location information now
20136 int declaration
= (current_function_decl
!= decl
20137 || class_or_namespace_scope_p (context_die
));
20139 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
20141 /* Now that the C++ front end lazily declares artificial member fns, we
20142 might need to retrofit the declaration into its class. */
20143 if (!declaration
&& !origin
&& !old_die
20144 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
20145 && !class_or_namespace_scope_p (context_die
)
20146 && debug_info_level
> DINFO_LEVEL_TERSE
)
20147 old_die
= force_decl_die (decl
);
20149 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
20150 if (origin
!= NULL
)
20152 gcc_assert (!declaration
|| local_scope_p (context_die
));
20154 /* Fixup die_parent for the abstract instance of a nested
20155 inline function. */
20156 if (old_die
&& old_die
->die_parent
== NULL
)
20157 add_child_die (context_die
, old_die
);
20159 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
20161 /* If we have a DW_AT_abstract_origin we have a working
20163 subr_die
= old_die
;
20167 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
20168 add_abstract_origin_attribute (subr_die
, origin
);
20169 /* This is where the actual code for a cloned function is.
20170 Let's emit linkage name attribute for it. This helps
20171 debuggers to e.g, set breakpoints into
20172 constructors/destructors when the user asks "break
20174 add_linkage_name (subr_die
, decl
);
20177 /* A cached copy, possibly from early dwarf generation. Reuse as
20178 much as possible. */
20181 /* A declaration that has been previously dumped needs no
20182 additional information. */
20186 if (!get_AT_flag (old_die
, DW_AT_declaration
)
20187 /* We can have a normal definition following an inline one in the
20188 case of redefinition of GNU C extern inlines.
20189 It seems reasonable to use AT_specification in this case. */
20190 && !get_AT (old_die
, DW_AT_inline
))
20192 /* Detect and ignore this case, where we are trying to output
20193 something we have already output. */
20194 if (get_AT (old_die
, DW_AT_low_pc
)
20195 || get_AT (old_die
, DW_AT_ranges
))
20198 /* If we have no location information, this must be a
20199 partially generated DIE from early dwarf generation.
20200 Fall through and generate it. */
20203 /* If the definition comes from the same place as the declaration,
20204 maybe use the old DIE. We always want the DIE for this function
20205 that has the *_pc attributes to be under comp_unit_die so the
20206 debugger can find it. We also need to do this for abstract
20207 instances of inlines, since the spec requires the out-of-line copy
20208 to have the same parent. For local class methods, this doesn't
20209 apply; we just use the old DIE. */
20210 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
20211 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
20212 if ((is_cu_die (old_die
->die_parent
)
20213 /* This condition fixes the inconsistency/ICE with the
20214 following Fortran test (or some derivative thereof) while
20215 building libgfortran:
20219 logical function funky (FLAG)
20224 || (old_die
->die_parent
20225 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
20226 || context_die
== NULL
)
20227 && (DECL_ARTIFICIAL (decl
)
20228 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
20229 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
20230 == (unsigned) s
.line
))))
20232 subr_die
= old_die
;
20234 /* Clear out the declaration attribute, but leave the
20235 parameters so they can be augmented with location
20236 information later. Unless this was a declaration, in
20237 which case, wipe out the nameless parameters and recreate
20238 them further down. */
20239 if (remove_AT (subr_die
, DW_AT_declaration
))
20242 remove_AT (subr_die
, DW_AT_object_pointer
);
20243 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
20246 /* Make a specification pointing to the previously built
20250 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
20251 add_AT_specification (subr_die
, old_die
);
20252 add_pubname (decl
, subr_die
);
20253 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
20254 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
20255 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
20256 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
20258 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
20259 emit the real type on the definition die. */
20260 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
20262 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
20263 if (die
== auto_die
|| die
== decltype_auto_die
)
20264 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
20265 TYPE_UNQUALIFIED
, false, context_die
);
20269 /* Create a fresh DIE for anything else. */
20272 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
20274 if (TREE_PUBLIC (decl
))
20275 add_AT_flag (subr_die
, DW_AT_external
, 1);
20277 add_name_and_src_coords_attributes (subr_die
, decl
);
20278 add_pubname (decl
, subr_die
);
20279 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20281 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
20282 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
20283 TYPE_UNQUALIFIED
, false, context_die
);
20286 add_pure_or_virtual_attribute (subr_die
, decl
);
20287 if (DECL_ARTIFICIAL (decl
))
20288 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
20290 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
20291 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
20293 add_accessibility_attribute (subr_die
, decl
);
20296 /* Unless we have an existing non-declaration DIE, equate the new
20298 if (!old_die
|| is_declaration_die (old_die
))
20299 equate_decl_number_to_die (decl
, subr_die
);
20303 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
20305 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
20307 /* If this is an explicit function declaration then generate
20308 a DW_AT_explicit attribute. */
20309 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
20310 && (dwarf_version
>= 3 || !dwarf_strict
))
20311 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
20313 /* If this is a C++11 deleted special function member then generate
20314 a DW_AT_GNU_deleted attribute. */
20315 if (lang_hooks
.decls
.function_decl_deleted_p (decl
)
20316 && (! dwarf_strict
))
20317 add_AT_flag (subr_die
, DW_AT_GNU_deleted
, 1);
20320 /* Tag abstract instances with DW_AT_inline. */
20321 else if (DECL_ABSTRACT_P (decl
))
20323 if (DECL_DECLARED_INLINE_P (decl
))
20325 if (cgraph_function_possibly_inlined_p (decl
))
20326 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
20328 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
20332 if (cgraph_function_possibly_inlined_p (decl
))
20333 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
20335 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
20338 if (DECL_DECLARED_INLINE_P (decl
)
20339 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
20340 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
20342 /* For non DECL_EXTERNALs, if range information is available, fill
20343 the DIE with it. */
20344 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
20346 HOST_WIDE_INT cfa_fb_offset
;
20348 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
20350 if (!flag_reorder_blocks_and_partition
)
20352 dw_fde_ref fde
= fun
->fde
;
20353 if (fde
->dw_fde_begin
)
20355 /* We have already generated the labels. */
20356 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
20357 fde
->dw_fde_end
, false);
20361 /* Create start/end labels and add the range. */
20362 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
20363 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
20364 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
20365 current_function_funcdef_no
);
20366 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
20367 current_function_funcdef_no
);
20368 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
20372 #if VMS_DEBUGGING_INFO
20373 /* HP OpenVMS Industry Standard 64: DWARF Extensions
20374 Section 2.3 Prologue and Epilogue Attributes:
20375 When a breakpoint is set on entry to a function, it is generally
20376 desirable for execution to be suspended, not on the very first
20377 instruction of the function, but rather at a point after the
20378 function's frame has been set up, after any language defined local
20379 declaration processing has been completed, and before execution of
20380 the first statement of the function begins. Debuggers generally
20381 cannot properly determine where this point is. Similarly for a
20382 breakpoint set on exit from a function. The prologue and epilogue
20383 attributes allow a compiler to communicate the location(s) to use. */
20386 if (fde
->dw_fde_vms_end_prologue
)
20387 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
20388 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
20390 if (fde
->dw_fde_vms_begin_epilogue
)
20391 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
20392 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
20399 /* Generate pubnames entries for the split function code ranges. */
20400 dw_fde_ref fde
= fun
->fde
;
20402 if (fde
->dw_fde_second_begin
)
20404 if (dwarf_version
>= 3 || !dwarf_strict
)
20406 /* We should use ranges for non-contiguous code section
20407 addresses. Use the actual code range for the initial
20408 section, since the HOT/COLD labels might precede an
20409 alignment offset. */
20410 bool range_list_added
= false;
20411 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
20412 fde
->dw_fde_end
, &range_list_added
,
20414 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
20415 fde
->dw_fde_second_end
,
20416 &range_list_added
, false);
20417 if (range_list_added
)
20422 /* There is no real support in DW2 for this .. so we make
20423 a work-around. First, emit the pub name for the segment
20424 containing the function label. Then make and emit a
20425 simplified subprogram DIE for the second segment with the
20426 name pre-fixed by __hot/cold_sect_of_. We use the same
20427 linkage name for the second die so that gdb will find both
20428 sections when given "b foo". */
20429 const char *name
= NULL
;
20430 tree decl_name
= DECL_NAME (decl
);
20431 dw_die_ref seg_die
;
20433 /* Do the 'primary' section. */
20434 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
20435 fde
->dw_fde_end
, false);
20437 /* Build a minimal DIE for the secondary section. */
20438 seg_die
= new_die (DW_TAG_subprogram
,
20439 subr_die
->die_parent
, decl
);
20441 if (TREE_PUBLIC (decl
))
20442 add_AT_flag (seg_die
, DW_AT_external
, 1);
20444 if (decl_name
!= NULL
20445 && IDENTIFIER_POINTER (decl_name
) != NULL
)
20447 name
= dwarf2_name (decl
, 1);
20448 if (! DECL_ARTIFICIAL (decl
))
20449 add_src_coords_attributes (seg_die
, decl
);
20451 add_linkage_name (seg_die
, decl
);
20453 gcc_assert (name
!= NULL
);
20454 add_pure_or_virtual_attribute (seg_die
, decl
);
20455 if (DECL_ARTIFICIAL (decl
))
20456 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
20458 name
= concat ("__second_sect_of_", name
, NULL
);
20459 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
20460 fde
->dw_fde_second_end
, false);
20461 add_name_attribute (seg_die
, name
);
20462 if (want_pubnames ())
20463 add_pubname_string (name
, seg_die
);
20467 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
20471 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
20473 /* We define the "frame base" as the function's CFA. This is more
20474 convenient for several reasons: (1) It's stable across the prologue
20475 and epilogue, which makes it better than just a frame pointer,
20476 (2) With dwarf3, there exists a one-byte encoding that allows us
20477 to reference the .debug_frame data by proxy, but failing that,
20478 (3) We can at least reuse the code inspection and interpretation
20479 code that determines the CFA position at various points in the
20481 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
20483 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
20484 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
20488 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
20489 if (list
->dw_loc_next
)
20490 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
20492 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
20495 /* Compute a displacement from the "steady-state frame pointer" to
20496 the CFA. The former is what all stack slots and argument slots
20497 will reference in the rtl; the latter is what we've told the
20498 debugger about. We'll need to adjust all frame_base references
20499 by this displacement. */
20500 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
20502 if (fun
->static_chain_decl
)
20504 /* DWARF requires here a location expression that computes the
20505 address of the enclosing subprogram's frame base. The machinery
20506 in tree-nested.c is supposed to store this specific address in the
20507 last field of the FRAME record. */
20508 const tree frame_type
20509 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
20510 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
20513 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
20514 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
20515 fb_expr
, fb_decl
, NULL_TREE
);
20517 add_AT_location_description (subr_die
, DW_AT_static_link
,
20518 loc_list_from_tree (fb_expr
, 0, NULL
));
20522 /* Generate child dies for template paramaters. */
20523 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
20524 gen_generic_params_dies (decl
);
20526 /* Now output descriptions of the arguments for this function. This gets
20527 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
20528 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
20529 `...' at the end of the formal parameter list. In order to find out if
20530 there was a trailing ellipsis or not, we must instead look at the type
20531 associated with the FUNCTION_DECL. This will be a node of type
20532 FUNCTION_TYPE. If the chain of type nodes hanging off of this
20533 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
20534 an ellipsis at the end. */
20536 /* In the case where we are describing a mere function declaration, all we
20537 need to do here (and all we *can* do here) is to describe the *types* of
20538 its formal parameters. */
20539 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20541 else if (declaration
)
20542 gen_formal_types_die (decl
, subr_die
);
20545 /* Generate DIEs to represent all known formal parameters. */
20546 tree parm
= DECL_ARGUMENTS (decl
);
20547 tree generic_decl
= early_dwarf
20548 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
20549 tree generic_decl_parm
= generic_decl
20550 ? DECL_ARGUMENTS (generic_decl
)
20553 /* Now we want to walk the list of parameters of the function and
20554 emit their relevant DIEs.
20556 We consider the case of DECL being an instance of a generic function
20557 as well as it being a normal function.
20559 If DECL is an instance of a generic function we walk the
20560 parameters of the generic function declaration _and_ the parameters of
20561 DECL itself. This is useful because we want to emit specific DIEs for
20562 function parameter packs and those are declared as part of the
20563 generic function declaration. In that particular case,
20564 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
20565 That DIE has children DIEs representing the set of arguments
20566 of the pack. Note that the set of pack arguments can be empty.
20567 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
20570 Otherwise, we just consider the parameters of DECL. */
20571 while (generic_decl_parm
|| parm
)
20573 if (generic_decl_parm
20574 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
20575 gen_formal_parameter_pack_die (generic_decl_parm
,
20578 else if (parm
&& !POINTER_BOUNDS_P (parm
))
20580 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
20582 if (parm
== DECL_ARGUMENTS (decl
)
20583 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
20585 && (dwarf_version
>= 3 || !dwarf_strict
))
20586 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
20588 parm
= DECL_CHAIN (parm
);
20591 parm
= DECL_CHAIN (parm
);
20593 if (generic_decl_parm
)
20594 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
20597 /* Decide whether we need an unspecified_parameters DIE at the end.
20598 There are 2 more cases to do this for: 1) the ansi ... declaration -
20599 this is detectable when the end of the arg list is not a
20600 void_type_node 2) an unprototyped function declaration (not a
20601 definition). This just means that we have no info about the
20602 parameters at all. */
20603 if (prototype_p (TREE_TYPE (decl
)))
20605 /* This is the prototyped case, check for.... */
20606 if (stdarg_p (TREE_TYPE (decl
)))
20607 gen_unspecified_parameters_die (decl
, subr_die
);
20609 else if (DECL_INITIAL (decl
) == NULL_TREE
)
20610 gen_unspecified_parameters_die (decl
, subr_die
);
20613 if (subr_die
!= old_die
)
20614 /* Add the calling convention attribute if requested. */
20615 add_calling_convention_attribute (subr_die
, decl
);
20617 /* Output Dwarf info for all of the stuff within the body of the function
20618 (if it has one - it may be just a declaration).
20620 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
20621 a function. This BLOCK actually represents the outermost binding contour
20622 for the function, i.e. the contour in which the function's formal
20623 parameters and labels get declared. Curiously, it appears that the front
20624 end doesn't actually put the PARM_DECL nodes for the current function onto
20625 the BLOCK_VARS list for this outer scope, but are strung off of the
20626 DECL_ARGUMENTS list for the function instead.
20628 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
20629 the LABEL_DECL nodes for the function however, and we output DWARF info
20630 for those in decls_for_scope. Just within the `outer_scope' there will be
20631 a BLOCK node representing the function's outermost pair of curly braces,
20632 and any blocks used for the base and member initializers of a C++
20633 constructor function. */
20634 tree outer_scope
= DECL_INITIAL (decl
);
20635 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
20637 int call_site_note_count
= 0;
20638 int tail_call_site_note_count
= 0;
20640 /* Emit a DW_TAG_variable DIE for a named return value. */
20641 if (DECL_NAME (DECL_RESULT (decl
)))
20642 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
20644 /* The first time through decls_for_scope we will generate the
20645 DIEs for the locals. The second time, we fill in the
20647 decls_for_scope (outer_scope
, subr_die
);
20649 if (call_arg_locations
&& !dwarf_strict
)
20651 struct call_arg_loc_node
*ca_loc
;
20652 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
20654 dw_die_ref die
= NULL
;
20655 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
20658 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
20659 ? NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
)
20661 arg
; arg
= next_arg
)
20663 dw_loc_descr_ref reg
, val
;
20664 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
20665 dw_die_ref cdie
, tdie
= NULL
;
20667 next_arg
= XEXP (arg
, 1);
20668 if (REG_P (XEXP (XEXP (arg
, 0), 0))
20670 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
20671 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
20672 && REGNO (XEXP (XEXP (arg
, 0), 0))
20673 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
20674 next_arg
= XEXP (next_arg
, 1);
20675 if (mode
== VOIDmode
)
20677 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
20678 if (mode
== VOIDmode
)
20679 mode
= GET_MODE (XEXP (arg
, 0));
20681 if (mode
== VOIDmode
|| mode
== BLKmode
)
20683 /* Get dynamic information about call target only if we
20684 have no static information: we cannot generate both
20685 DW_AT_abstract_origin and DW_AT_GNU_call_site_target
20687 if (ca_loc
->symbol_ref
== NULL_RTX
)
20689 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
20691 tloc
= XEXP (XEXP (arg
, 0), 1);
20694 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
20695 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
20697 tlocc
= XEXP (XEXP (arg
, 0), 1);
20702 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
20703 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
20704 VAR_INIT_STATUS_INITIALIZED
);
20705 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
20707 rtx mem
= XEXP (XEXP (arg
, 0), 0);
20708 reg
= mem_loc_descriptor (XEXP (mem
, 0),
20709 get_address_mode (mem
),
20711 VAR_INIT_STATUS_INITIALIZED
);
20713 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
20714 == DEBUG_PARAMETER_REF
)
20717 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
20718 tdie
= lookup_decl_die (tdecl
);
20725 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
20726 != DEBUG_PARAMETER_REF
)
20728 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
20730 VAR_INIT_STATUS_INITIALIZED
);
20734 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
20735 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
20738 add_AT_loc (cdie
, DW_AT_location
, reg
);
20739 else if (tdie
!= NULL
)
20740 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
20741 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
20742 if (next_arg
!= XEXP (arg
, 1))
20744 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
20745 if (mode
== VOIDmode
)
20746 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
20747 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
20750 VAR_INIT_STATUS_INITIALIZED
);
20752 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
20756 && (ca_loc
->symbol_ref
|| tloc
))
20757 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
20758 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
20760 dw_loc_descr_ref tval
= NULL
;
20762 if (tloc
!= NULL_RTX
)
20763 tval
= mem_loc_descriptor (tloc
,
20764 GET_MODE (tloc
) == VOIDmode
20765 ? Pmode
: GET_MODE (tloc
),
20767 VAR_INIT_STATUS_INITIALIZED
);
20769 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
20770 else if (tlocc
!= NULL_RTX
)
20772 tval
= mem_loc_descriptor (tlocc
,
20773 GET_MODE (tlocc
) == VOIDmode
20774 ? Pmode
: GET_MODE (tlocc
),
20776 VAR_INIT_STATUS_INITIALIZED
);
20778 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
20784 call_site_note_count
++;
20785 if (ca_loc
->tail_call_p
)
20786 tail_call_site_note_count
++;
20790 call_arg_locations
= NULL
;
20791 call_arg_loc_last
= NULL
;
20792 if (tail_call_site_count
>= 0
20793 && tail_call_site_count
== tail_call_site_note_count
20796 if (call_site_count
>= 0
20797 && call_site_count
== call_site_note_count
)
20798 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
20800 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
20802 call_site_count
= -1;
20803 tail_call_site_count
= -1;
20807 /* Returns a hash value for X (which really is a die_struct). */
20810 block_die_hasher::hash (die_struct
*d
)
20812 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
20815 /* Return nonzero if decl_id and die_parent of die_struct X is the same
20816 as decl_id and die_parent of die_struct Y. */
20819 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
20821 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
20824 /* Return TRUE if DECL, which may have been previously generated as
20825 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
20826 true if decl (or its origin) is either an extern declaration or a
20827 class/namespace scoped declaration.
20829 The declare_in_namespace support causes us to get two DIEs for one
20830 variable, both of which are declarations. We want to avoid
20831 considering one to be a specification, so we must test for
20832 DECLARATION and DW_AT_declaration. */
20834 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
20836 return (old_die
&& TREE_STATIC (decl
) && !declaration
20837 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
20840 /* Return true if DECL is a local static. */
20843 local_function_static (tree decl
)
20845 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
20846 return TREE_STATIC (decl
)
20847 && DECL_CONTEXT (decl
)
20848 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
20851 /* Generate a DIE to represent a declared data object.
20852 Either DECL or ORIGIN must be non-null. */
20855 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
20857 HOST_WIDE_INT off
= 0;
20859 tree decl_or_origin
= decl
? decl
: origin
;
20860 tree ultimate_origin
;
20861 dw_die_ref var_die
;
20862 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
20863 dw_die_ref origin_die
= NULL
;
20864 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
20865 || class_or_namespace_scope_p (context_die
));
20866 bool specialization_p
= false;
20868 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20869 if (decl
|| ultimate_origin
)
20870 origin
= ultimate_origin
;
20871 com_decl
= fortran_common (decl_or_origin
, &off
);
20873 /* Symbol in common gets emitted as a child of the common block, in the form
20874 of a data member. */
20877 dw_die_ref com_die
;
20878 dw_loc_list_ref loc
;
20879 die_node com_die_arg
;
20881 var_die
= lookup_decl_die (decl_or_origin
);
20884 if (get_AT (var_die
, DW_AT_location
) == NULL
)
20886 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
20891 /* Optimize the common case. */
20892 if (single_element_loc_list_p (loc
)
20893 && loc
->expr
->dw_loc_opc
== DW_OP_addr
20894 && loc
->expr
->dw_loc_next
== NULL
20895 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
20898 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
20899 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
20900 = plus_constant (GET_MODE (x
), x
, off
);
20903 loc_list_plus_const (loc
, off
);
20905 add_AT_location_description (var_die
, DW_AT_location
, loc
);
20906 remove_AT (var_die
, DW_AT_declaration
);
20912 if (common_block_die_table
== NULL
)
20913 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
20915 com_die_arg
.decl_id
= DECL_UID (com_decl
);
20916 com_die_arg
.die_parent
= context_die
;
20917 com_die
= common_block_die_table
->find (&com_die_arg
);
20918 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
20919 if (com_die
== NULL
)
20922 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
20925 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
20926 add_name_and_src_coords_attributes (com_die
, com_decl
);
20929 add_AT_location_description (com_die
, DW_AT_location
, loc
);
20930 /* Avoid sharing the same loc descriptor between
20931 DW_TAG_common_block and DW_TAG_variable. */
20932 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
20934 else if (DECL_EXTERNAL (decl
))
20935 add_AT_flag (com_die
, DW_AT_declaration
, 1);
20936 if (want_pubnames ())
20937 add_pubname_string (cnam
, com_die
); /* ??? needed? */
20938 com_die
->decl_id
= DECL_UID (com_decl
);
20939 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
20942 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
20944 add_AT_location_description (com_die
, DW_AT_location
, loc
);
20945 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
20946 remove_AT (com_die
, DW_AT_declaration
);
20948 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
20949 add_name_and_src_coords_attributes (var_die
, decl
);
20950 add_type_attribute (var_die
, TREE_TYPE (decl
), decl_quals (decl
), false,
20952 add_AT_flag (var_die
, DW_AT_external
, 1);
20957 /* Optimize the common case. */
20958 if (single_element_loc_list_p (loc
)
20959 && loc
->expr
->dw_loc_opc
== DW_OP_addr
20960 && loc
->expr
->dw_loc_next
== NULL
20961 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
20963 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
20964 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
20965 = plus_constant (GET_MODE (x
), x
, off
);
20968 loc_list_plus_const (loc
, off
);
20970 add_AT_location_description (var_die
, DW_AT_location
, loc
);
20972 else if (DECL_EXTERNAL (decl
))
20973 add_AT_flag (var_die
, DW_AT_declaration
, 1);
20974 equate_decl_number_to_die (decl
, var_die
);
20982 /* A declaration that has been previously dumped, needs no
20983 further annotations, since it doesn't need location on
20984 the second pass. */
20987 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
20988 && !get_AT (old_die
, DW_AT_specification
))
20990 /* Fall-thru so we can make a new variable die along with a
20991 DW_AT_specification. */
20993 else if (origin
&& old_die
->die_parent
!= context_die
)
20995 /* If we will be creating an inlined instance, we need a
20996 new DIE that will get annotated with
20997 DW_AT_abstract_origin. Clear things so we can get a
20999 gcc_assert (!DECL_ABSTRACT_P (decl
));
21004 /* If a DIE was dumped early, it still needs location info.
21005 Skip to where we fill the location bits. */
21007 goto gen_variable_die_location
;
21011 /* For static data members, the declaration in the class is supposed
21012 to have DW_TAG_member tag; the specification should still be
21013 DW_TAG_variable referencing the DW_TAG_member DIE. */
21014 if (declaration
&& class_scope_p (context_die
))
21015 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
21017 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
21019 if (origin
!= NULL
)
21020 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
21022 /* Loop unrolling can create multiple blocks that refer to the same
21023 static variable, so we must test for the DW_AT_declaration flag.
21025 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
21026 copy decls and set the DECL_ABSTRACT_P flag on them instead of
21029 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
21030 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
21032 /* This is a definition of a C++ class level static. */
21033 add_AT_specification (var_die
, old_die
);
21034 specialization_p
= true;
21035 if (DECL_NAME (decl
))
21037 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
21038 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
21040 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
21041 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
21043 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
21044 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
21046 if (old_die
->die_tag
== DW_TAG_member
)
21047 add_linkage_name (var_die
, decl
);
21051 add_name_and_src_coords_attributes (var_die
, decl
);
21053 if ((origin
== NULL
&& !specialization_p
)
21055 && !DECL_ABSTRACT_P (decl_or_origin
)
21056 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
21057 decl_function_context
21058 (decl_or_origin
))))
21060 tree type
= TREE_TYPE (decl_or_origin
);
21062 if (decl_by_reference_p (decl_or_origin
))
21063 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
21066 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
21070 if (origin
== NULL
&& !specialization_p
)
21072 if (TREE_PUBLIC (decl
))
21073 add_AT_flag (var_die
, DW_AT_external
, 1);
21075 if (DECL_ARTIFICIAL (decl
))
21076 add_AT_flag (var_die
, DW_AT_artificial
, 1);
21078 add_accessibility_attribute (var_die
, decl
);
21082 add_AT_flag (var_die
, DW_AT_declaration
, 1);
21084 if (decl
&& (DECL_ABSTRACT_P (decl
)
21085 || !old_die
|| is_declaration_die (old_die
)))
21086 equate_decl_number_to_die (decl
, var_die
);
21088 gen_variable_die_location
:
21090 && (! DECL_ABSTRACT_P (decl_or_origin
)
21091 /* Local static vars are shared between all clones/inlines,
21092 so emit DW_AT_location on the abstract DIE if DECL_RTL is
21094 || (TREE_CODE (decl_or_origin
) == VAR_DECL
21095 && TREE_STATIC (decl_or_origin
)
21096 && DECL_RTL_SET_P (decl_or_origin
)))
21097 /* When abstract origin already has DW_AT_location attribute, no need
21098 to add it again. */
21099 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
21102 add_pubname (decl_or_origin
, var_die
);
21104 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
21108 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
21111 /* Generate a DIE to represent a named constant. */
21114 gen_const_die (tree decl
, dw_die_ref context_die
)
21116 dw_die_ref const_die
;
21117 tree type
= TREE_TYPE (decl
);
21119 const_die
= lookup_decl_die (decl
);
21123 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
21124 equate_decl_number_to_die (decl
, const_die
);
21125 add_name_and_src_coords_attributes (const_die
, decl
);
21126 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
21127 if (TREE_PUBLIC (decl
))
21128 add_AT_flag (const_die
, DW_AT_external
, 1);
21129 if (DECL_ARTIFICIAL (decl
))
21130 add_AT_flag (const_die
, DW_AT_artificial
, 1);
21131 tree_add_const_value_attribute_for_decl (const_die
, decl
);
21134 /* Generate a DIE to represent a label identifier. */
21137 gen_label_die (tree decl
, dw_die_ref context_die
)
21139 tree origin
= decl_ultimate_origin (decl
);
21140 dw_die_ref lbl_die
= lookup_decl_die (decl
);
21142 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21146 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
21147 equate_decl_number_to_die (decl
, lbl_die
);
21149 if (origin
!= NULL
)
21150 add_abstract_origin_attribute (lbl_die
, origin
);
21152 add_name_and_src_coords_attributes (lbl_die
, decl
);
21155 if (DECL_ABSTRACT_P (decl
))
21156 equate_decl_number_to_die (decl
, lbl_die
);
21159 insn
= DECL_RTL_IF_SET (decl
);
21161 /* Deleted labels are programmer specified labels which have been
21162 eliminated because of various optimizations. We still emit them
21163 here so that it is possible to put breakpoints on them. */
21167 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
21169 /* When optimization is enabled (via -O) some parts of the compiler
21170 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
21171 represent source-level labels which were explicitly declared by
21172 the user. This really shouldn't be happening though, so catch
21173 it if it ever does happen. */
21174 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
21176 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
21177 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
21181 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
21182 && CODE_LABEL_NUMBER (insn
) != -1)
21184 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
21185 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
21190 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
21191 attributes to the DIE for a block STMT, to describe where the inlined
21192 function was called from. This is similar to add_src_coords_attributes. */
21195 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
21197 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
21199 if (dwarf_version
>= 3 || !dwarf_strict
)
21201 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
21202 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
21207 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
21208 Add low_pc and high_pc attributes to the DIE for a block STMT. */
21211 add_high_low_attributes (tree stmt
, dw_die_ref die
)
21213 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21215 if (BLOCK_FRAGMENT_CHAIN (stmt
)
21216 && (dwarf_version
>= 3 || !dwarf_strict
))
21218 tree chain
, superblock
= NULL_TREE
;
21220 dw_attr_node
*attr
= NULL
;
21222 if (inlined_function_outer_scope_p (stmt
))
21224 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
21225 BLOCK_NUMBER (stmt
));
21226 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
21229 /* Optimize duplicate .debug_ranges lists or even tails of
21230 lists. If this BLOCK has same ranges as its supercontext,
21231 lookup DW_AT_ranges attribute in the supercontext (and
21232 recursively so), verify that the ranges_table contains the
21233 right values and use it instead of adding a new .debug_range. */
21234 for (chain
= stmt
, pdie
= die
;
21235 BLOCK_SAME_RANGE (chain
);
21236 chain
= BLOCK_SUPERCONTEXT (chain
))
21238 dw_attr_node
*new_attr
;
21240 pdie
= pdie
->die_parent
;
21243 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
21245 new_attr
= get_AT (pdie
, DW_AT_ranges
);
21246 if (new_attr
== NULL
21247 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
21250 superblock
= BLOCK_SUPERCONTEXT (chain
);
21253 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
21254 / 2 / DWARF2_ADDR_SIZE
].num
21255 == BLOCK_NUMBER (superblock
))
21256 && BLOCK_FRAGMENT_CHAIN (superblock
))
21258 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
21259 / 2 / DWARF2_ADDR_SIZE
;
21260 unsigned long supercnt
= 0, thiscnt
= 0;
21261 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
21262 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
21265 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
21266 == BLOCK_NUMBER (chain
));
21268 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
21269 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
21270 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
21272 gcc_assert (supercnt
>= thiscnt
);
21273 add_AT_range_list (die
, DW_AT_ranges
,
21274 ((off
+ supercnt
- thiscnt
)
21275 * 2 * DWARF2_ADDR_SIZE
),
21280 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
21282 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
21285 add_ranges (chain
);
21286 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
21293 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
21294 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
21295 BLOCK_NUMBER (stmt
));
21296 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
21297 BLOCK_NUMBER (stmt
));
21298 add_AT_low_high_pc (die
, label
, label_high
, false);
21302 /* Generate a DIE for a lexical block. */
21305 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
21307 dw_die_ref old_die
= BLOCK_DIE (stmt
);
21308 dw_die_ref stmt_die
= NULL
;
21311 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
21312 BLOCK_DIE (stmt
) = stmt_die
;
21315 if (BLOCK_ABSTRACT (stmt
))
21319 /* This must have been generated early and it won't even
21320 need location information since it's a DW_AT_inline
21323 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
21324 if (c
->die_tag
== DW_TAG_inlined_subroutine
21325 || c
->die_tag
== DW_TAG_subprogram
)
21327 gcc_assert (get_AT (c
, DW_AT_inline
));
21333 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
21335 /* If this is an inlined instance, create a new lexical die for
21336 anything below to attach DW_AT_abstract_origin to. */
21339 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
21340 BLOCK_DIE (stmt
) = stmt_die
;
21346 stmt_die
= old_die
;
21348 /* A non abstract block whose blocks have already been reordered
21349 should have the instruction range for this block. If so, set the
21350 high/low attributes. */
21351 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
21353 gcc_assert (stmt_die
);
21354 add_high_low_attributes (stmt
, stmt_die
);
21357 decls_for_scope (stmt
, stmt_die
);
21360 /* Generate a DIE for an inlined subprogram. */
21363 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
21367 /* The instance of function that is effectively being inlined shall not
21369 gcc_assert (! BLOCK_ABSTRACT (stmt
));
21371 decl
= block_ultimate_origin (stmt
);
21373 /* Make sure any inlined functions are known to be inlineable. */
21374 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
21375 || cgraph_function_possibly_inlined_p (decl
));
21377 /* Emit info for the abstract instance first, if we haven't yet. We
21378 must emit this even if the block is abstract, otherwise when we
21379 emit the block below (or elsewhere), we may end up trying to emit
21380 a die whose origin die hasn't been emitted, and crashing. */
21381 dwarf2out_abstract_function (decl
);
21383 if (! BLOCK_ABSTRACT (stmt
))
21385 dw_die_ref subr_die
21386 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
21388 if (call_arg_locations
)
21389 BLOCK_DIE (stmt
) = subr_die
;
21390 add_abstract_origin_attribute (subr_die
, decl
);
21391 if (TREE_ASM_WRITTEN (stmt
))
21392 add_high_low_attributes (stmt
, subr_die
);
21393 add_call_src_coords_attributes (stmt
, subr_die
);
21395 decls_for_scope (stmt
, subr_die
);
21399 /* Generate a DIE for a field in a record, or structure. CTX is required: see
21400 the comment for VLR_CONTEXT. */
21403 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
21405 dw_die_ref decl_die
;
21407 if (TREE_TYPE (decl
) == error_mark_node
)
21410 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
21411 add_name_and_src_coords_attributes (decl_die
, decl
);
21412 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
21413 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
21416 if (DECL_BIT_FIELD_TYPE (decl
))
21418 add_byte_size_attribute (decl_die
, decl
);
21419 add_bit_size_attribute (decl_die
, decl
);
21420 add_bit_offset_attribute (decl_die
, decl
, ctx
);
21423 /* If we have a variant part offset, then we are supposed to process a member
21424 of a QUAL_UNION_TYPE, which is how we represent variant parts in
21426 gcc_assert (ctx
->variant_part_offset
== NULL_TREE
21427 || TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != QUAL_UNION_TYPE
);
21428 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
21429 add_data_member_location_attribute (decl_die
, decl
, ctx
);
21431 if (DECL_ARTIFICIAL (decl
))
21432 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
21434 add_accessibility_attribute (decl_die
, decl
);
21436 /* Equate decl number to die, so that we can look up this decl later on. */
21437 equate_decl_number_to_die (decl
, decl_die
);
21441 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21442 Use modified_type_die instead.
21443 We keep this code here just in case these types of DIEs may be needed to
21444 represent certain things in other languages (e.g. Pascal) someday. */
21447 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
21450 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
21452 equate_type_number_to_die (type
, ptr_die
);
21453 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
21455 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
21458 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21459 Use modified_type_die instead.
21460 We keep this code here just in case these types of DIEs may be needed to
21461 represent certain things in other languages (e.g. Pascal) someday. */
21464 gen_reference_type_die (tree type
, dw_die_ref context_die
)
21466 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
21468 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
21469 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
21471 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
21473 equate_type_number_to_die (type
, ref_die
);
21474 add_type_attribute (ref_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
21476 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
21480 /* Generate a DIE for a pointer to a member type. */
21483 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
21486 = new_die (DW_TAG_ptr_to_member_type
,
21487 scope_die_for (type
, context_die
), type
);
21489 equate_type_number_to_die (type
, ptr_die
);
21490 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
21491 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
21492 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
21496 static char *producer_string
;
21498 /* Return a heap allocated producer string including command line options
21499 if -grecord-gcc-switches. */
21502 gen_producer_string (void)
21505 auto_vec
<const char *> switches
;
21506 const char *language_string
= lang_hooks
.name
;
21507 char *producer
, *tail
;
21509 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
21510 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
21512 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
21513 switch (save_decoded_options
[j
].opt_index
)
21520 case OPT_auxbase_strip
:
21529 case OPT_SPECIAL_unknown
:
21530 case OPT_SPECIAL_ignore
:
21531 case OPT_SPECIAL_program_name
:
21532 case OPT_SPECIAL_input_file
:
21533 case OPT_grecord_gcc_switches
:
21534 case OPT_gno_record_gcc_switches
:
21535 case OPT__output_pch_
:
21536 case OPT_fdiagnostics_show_location_
:
21537 case OPT_fdiagnostics_show_option
:
21538 case OPT_fdiagnostics_show_caret
:
21539 case OPT_fdiagnostics_color_
:
21540 case OPT_fverbose_asm
:
21542 case OPT__sysroot_
:
21544 case OPT_nostdinc__
:
21545 case OPT_fpreprocessed
:
21546 case OPT_fltrans_output_list_
:
21547 case OPT_fresolution_
:
21548 case OPT_fdebug_prefix_map_
:
21549 /* Ignore these. */
21552 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
21553 & CL_NO_DWARF_RECORD
)
21555 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
21557 switch (save_decoded_options
[j
].canonical_option
[0][1])
21564 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
21571 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
21572 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
21576 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
21578 sprintf (tail
, "%s %s", language_string
, version_string
);
21581 FOR_EACH_VEC_ELT (switches
, j
, p
)
21585 memcpy (tail
+ 1, p
, len
);
21593 /* Given a C and/or C++ language/version string return the "highest".
21594 C++ is assumed to be "higher" than C in this case. Used for merging
21595 LTO translation unit languages. */
21596 static const char *
21597 highest_c_language (const char *lang1
, const char *lang2
)
21599 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
21600 return "GNU C++14";
21601 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
21602 return "GNU C++11";
21603 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
21604 return "GNU C++98";
21606 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
21608 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
21610 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
21613 gcc_unreachable ();
21617 /* Generate the DIE for the compilation unit. */
21620 gen_compile_unit_die (const char *filename
)
21623 const char *language_string
= lang_hooks
.name
;
21626 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
21630 add_name_attribute (die
, filename
);
21631 /* Don't add cwd for <built-in>. */
21632 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
21633 add_comp_dir_attribute (die
);
21636 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
21638 /* If our producer is LTO try to figure out a common language to use
21639 from the global list of translation units. */
21640 if (strcmp (language_string
, "GNU GIMPLE") == 0)
21644 const char *common_lang
= NULL
;
21646 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
21648 if (!TRANSLATION_UNIT_LANGUAGE (t
))
21651 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
21652 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
21654 else if (strncmp (common_lang
, "GNU C", 5) == 0
21655 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
21656 /* Mixing C and C++ is ok, use C++ in that case. */
21657 common_lang
= highest_c_language (common_lang
,
21658 TRANSLATION_UNIT_LANGUAGE (t
));
21661 /* Fall back to C. */
21662 common_lang
= NULL
;
21668 language_string
= common_lang
;
21671 language
= DW_LANG_C
;
21672 if (strncmp (language_string
, "GNU C", 5) == 0
21673 && ISDIGIT (language_string
[5]))
21675 language
= DW_LANG_C89
;
21676 if (dwarf_version
>= 3 || !dwarf_strict
)
21678 if (strcmp (language_string
, "GNU C89") != 0)
21679 language
= DW_LANG_C99
;
21681 if (dwarf_version
>= 5 /* || !dwarf_strict */)
21682 if (strcmp (language_string
, "GNU C11") == 0)
21683 language
= DW_LANG_C11
;
21686 else if (strncmp (language_string
, "GNU C++", 7) == 0)
21688 language
= DW_LANG_C_plus_plus
;
21689 if (dwarf_version
>= 5 /* || !dwarf_strict */)
21691 if (strcmp (language_string
, "GNU C++11") == 0)
21692 language
= DW_LANG_C_plus_plus_11
;
21693 else if (strcmp (language_string
, "GNU C++14") == 0)
21694 language
= DW_LANG_C_plus_plus_14
;
21697 else if (strcmp (language_string
, "GNU F77") == 0)
21698 language
= DW_LANG_Fortran77
;
21699 else if (strcmp (language_string
, "GNU Pascal") == 0)
21700 language
= DW_LANG_Pascal83
;
21701 else if (dwarf_version
>= 3 || !dwarf_strict
)
21703 if (strcmp (language_string
, "GNU Ada") == 0)
21704 language
= DW_LANG_Ada95
;
21705 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
21707 language
= DW_LANG_Fortran95
;
21708 if (dwarf_version
>= 5 /* || !dwarf_strict */)
21710 if (strcmp (language_string
, "GNU Fortran2003") == 0)
21711 language
= DW_LANG_Fortran03
;
21712 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
21713 language
= DW_LANG_Fortran08
;
21716 else if (strcmp (language_string
, "GNU Java") == 0)
21717 language
= DW_LANG_Java
;
21718 else if (strcmp (language_string
, "GNU Objective-C") == 0)
21719 language
= DW_LANG_ObjC
;
21720 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
21721 language
= DW_LANG_ObjC_plus_plus
;
21722 else if (dwarf_version
>= 5 || !dwarf_strict
)
21724 if (strcmp (language_string
, "GNU Go") == 0)
21725 language
= DW_LANG_Go
;
21728 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
21729 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
21730 language
= DW_LANG_Fortran90
;
21732 add_AT_unsigned (die
, DW_AT_language
, language
);
21736 case DW_LANG_Fortran77
:
21737 case DW_LANG_Fortran90
:
21738 case DW_LANG_Fortran95
:
21739 case DW_LANG_Fortran03
:
21740 case DW_LANG_Fortran08
:
21741 /* Fortran has case insensitive identifiers and the front-end
21742 lowercases everything. */
21743 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
21746 /* The default DW_ID_case_sensitive doesn't need to be specified. */
21752 /* Generate the DIE for a base class. */
21755 gen_inheritance_die (tree binfo
, tree access
, tree type
,
21756 dw_die_ref context_die
)
21758 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
21759 struct vlr_context ctx
= { type
, NULL
};
21761 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
21763 add_data_member_location_attribute (die
, binfo
, &ctx
);
21765 if (BINFO_VIRTUAL_P (binfo
))
21766 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
21768 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
21769 children, otherwise the default is DW_ACCESS_public. In DWARF2
21770 the default has always been DW_ACCESS_private. */
21771 if (access
== access_public_node
)
21773 if (dwarf_version
== 2
21774 || context_die
->die_tag
== DW_TAG_class_type
)
21775 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
21777 else if (access
== access_protected_node
)
21778 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
21779 else if (dwarf_version
> 2
21780 && context_die
->die_tag
!= DW_TAG_class_type
)
21781 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
21784 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
21787 is_variant_part (tree decl
)
21789 return (TREE_CODE (decl
) == FIELD_DECL
21790 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
21793 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
21794 return the FIELD_DECL. Return NULL_TREE otherwise. */
21797 analyze_discr_in_predicate (tree operand
, tree struct_type
)
21799 bool continue_stripping
= true;
21800 while (continue_stripping
)
21801 switch (TREE_CODE (operand
))
21804 operand
= TREE_OPERAND (operand
, 0);
21807 continue_stripping
= false;
21811 /* Match field access to members of struct_type only. */
21812 if (TREE_CODE (operand
) == COMPONENT_REF
21813 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
21814 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
21815 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
21816 return TREE_OPERAND (operand
, 1);
21821 /* Check that SRC is a constant integer that can be represented as a native
21822 integer constant (either signed or unsigned). If so, store it into DEST and
21823 return true. Return false otherwise. */
21826 get_discr_value (tree src
, dw_discr_value
*dest
)
21828 bool is_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
21830 if (TREE_CODE (src
) != INTEGER_CST
21831 || !(is_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
21834 dest
->pos
= is_unsigned
;
21836 dest
->v
.uval
= tree_to_uhwi (src
);
21838 dest
->v
.sval
= tree_to_shwi (src
);
21843 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
21844 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
21845 store NULL_TREE in DISCR_DECL. Otherwise:
21847 - store the discriminant field in STRUCT_TYPE that controls the variant
21848 part to *DISCR_DECL
21850 - put in *DISCR_LISTS_P an array where for each variant, the item
21851 represents the corresponding matching list of discriminant values.
21853 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
21856 Note that when the array is allocated (i.e. when the analysis is
21857 successful), it is up to the caller to free the array. */
21860 analyze_variants_discr (tree variant_part_decl
,
21863 dw_discr_list_ref
**discr_lists_p
,
21864 unsigned *discr_lists_length
)
21866 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
21868 dw_discr_list_ref
*discr_lists
;
21871 /* Compute how many variants there are in this variant part. */
21872 *discr_lists_length
= 0;
21873 for (variant
= TYPE_FIELDS (variant_part_type
);
21874 variant
!= NULL_TREE
;
21875 variant
= DECL_CHAIN (variant
))
21876 ++*discr_lists_length
;
21878 *discr_decl
= NULL_TREE
;
21880 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
21881 sizeof (**discr_lists_p
));
21882 discr_lists
= *discr_lists_p
;
21884 /* And then analyze all variants to extract discriminant information for all
21885 of them. This analysis is conservative: as soon as we detect something we
21886 do not support, abort everything and pretend we found nothing. */
21887 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
21888 variant
!= NULL_TREE
;
21889 variant
= DECL_CHAIN (variant
), ++i
)
21891 tree match_expr
= DECL_QUALIFIER (variant
);
21893 /* Now, try to analyze the predicate and deduce a discriminant for
21895 if (match_expr
== boolean_true_node
)
21896 /* Typically happens for the default variant: it matches all cases that
21897 previous variants rejected. Don't output any matching value for
21901 /* The following loop tries to iterate over each discriminant
21902 possibility: single values or ranges. */
21903 while (match_expr
!= NULL_TREE
)
21905 tree next_round_match_expr
;
21906 tree candidate_discr
= NULL_TREE
;
21907 dw_discr_list_ref new_node
= NULL
;
21909 /* Possibilities are matched one after the other by nested
21910 TRUTH_ORIF_EXPR expressions. Process the current possibility and
21911 continue with the rest at next iteration. */
21912 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
21914 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
21915 match_expr
= TREE_OPERAND (match_expr
, 1);
21918 next_round_match_expr
= NULL_TREE
;
21920 if (match_expr
== boolean_false_node
)
21921 /* This sub-expression matches nothing: just wait for the next
21925 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
21927 /* We are matching: <discr_field> == <integer_cst>
21928 This sub-expression matches a single value. */
21929 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
21932 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
21935 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
21936 if (!get_discr_value (integer_cst
,
21937 &new_node
->dw_discr_lower_bound
))
21939 new_node
->dw_discr_range
= false;
21942 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
21944 /* We are matching:
21945 <discr_field> > <integer_cst>
21946 && <discr_field> < <integer_cst>.
21947 This sub-expression matches the range of values between the
21948 two matched integer constants. Note that comparisons can be
21949 inclusive or exclusive. */
21950 tree candidate_discr_1
, candidate_discr_2
;
21951 tree lower_cst
, upper_cst
;
21952 bool lower_cst_included
, upper_cst_included
;
21953 tree lower_op
= TREE_OPERAND (match_expr
, 0);
21954 tree upper_op
= TREE_OPERAND (match_expr
, 1);
21956 /* When the comparison is exclusive, the integer constant is not
21957 the discriminant range bound we are looking for: we will have
21958 to increment or decrement it. */
21959 if (TREE_CODE (lower_op
) == GE_EXPR
)
21960 lower_cst_included
= true;
21961 else if (TREE_CODE (lower_op
) == GT_EXPR
)
21962 lower_cst_included
= false;
21966 if (TREE_CODE (upper_op
) == LE_EXPR
)
21967 upper_cst_included
= true;
21968 else if (TREE_CODE (upper_op
) == LT_EXPR
)
21969 upper_cst_included
= false;
21973 /* Extract the discriminant from the first operand and check it
21974 is consistant with the same analysis in the second
21977 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
21980 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
21982 if (candidate_discr_1
== candidate_discr_2
)
21983 candidate_discr
= candidate_discr_1
;
21987 /* Extract bounds from both. */
21988 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
21989 lower_cst
= TREE_OPERAND (lower_op
, 1);
21990 upper_cst
= TREE_OPERAND (upper_op
, 1);
21992 if (!lower_cst_included
)
21994 = fold (build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
),
21996 build_int_cst (TREE_TYPE (lower_cst
), 1)));
21997 if (!upper_cst_included
)
21999 = fold (build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
),
22001 build_int_cst (TREE_TYPE (upper_cst
), 1)));
22003 if (!get_discr_value (lower_cst
,
22004 &new_node
->dw_discr_lower_bound
)
22005 || !get_discr_value (upper_cst
,
22006 &new_node
->dw_discr_upper_bound
))
22009 new_node
->dw_discr_range
= true;
22013 /* Unsupported sub-expression: we cannot determine the set of
22014 matching discriminant values. Abort everything. */
22017 /* If the discriminant info is not consistant with what we saw so
22018 far, consider the analysis failed and abort everything. */
22019 if (candidate_discr
== NULL_TREE
22020 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
22023 *discr_decl
= candidate_discr
;
22025 if (new_node
!= NULL
)
22027 new_node
->dw_discr_next
= discr_lists
[i
];
22028 discr_lists
[i
] = new_node
;
22030 match_expr
= next_round_match_expr
;
22034 /* If we reach this point, we could match everything we were interested
22039 /* Clean all data structure and return no result. */
22040 free (*discr_lists_p
);
22041 *discr_lists_p
= NULL
;
22042 *discr_decl
= NULL_TREE
;
22045 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
22046 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
22049 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
22050 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
22051 this type, which are record types, represent the available variants and each
22052 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
22053 values are inferred from these attributes.
22055 In trees, the offsets for the fields inside these sub-records are relative
22056 to the variant part itself, whereas the corresponding DIEs should have
22057 offset attributes that are relative to the embedding record base address.
22058 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
22059 must be an expression that computes the offset of the variant part to
22060 describe in DWARF. */
22063 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
22064 dw_die_ref context_die
)
22066 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
22067 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
22068 struct loc_descr_context ctx
= {
22069 vlr_ctx
->struct_type
, /* context_type */
22070 NULL_TREE
, /* base_decl */
22074 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
22075 NULL_TREE if there is no such field. */
22076 tree discr_decl
= NULL_TREE
;
22077 dw_discr_list_ref
*discr_lists
;
22078 unsigned discr_lists_length
= 0;
22081 dw_die_ref dwarf_proc_die
= NULL
;
22082 dw_die_ref variant_part_die
22083 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
22085 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
22087 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
22088 &discr_decl
, &discr_lists
, &discr_lists_length
);
22090 if (discr_decl
!= NULL_TREE
)
22092 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
22095 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
22097 /* We have no DIE for the discriminant, so just discard all
22098 discrimimant information in the output. */
22099 discr_decl
= NULL_TREE
;
22102 /* If the offset for this variant part is more complex than a constant,
22103 create a DWARF procedure for it so that we will not have to generate DWARF
22104 expressions for it for each member. */
22105 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
22106 && (dwarf_version
>= 3 || !dwarf_strict
))
22108 const tree dwarf_proc_fndecl
22109 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
22110 build_function_type (TREE_TYPE (variant_part_offset
),
22112 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
22113 const dw_loc_descr_ref dwarf_proc_body
22114 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
22116 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
22117 dwarf_proc_fndecl
, context_die
);
22118 if (dwarf_proc_die
!= NULL
)
22119 variant_part_offset
= dwarf_proc_call
;
22122 /* Output DIEs for all variants. */
22124 for (tree variant
= TYPE_FIELDS (variant_part_type
);
22125 variant
!= NULL_TREE
;
22126 variant
= DECL_CHAIN (variant
), ++i
)
22128 tree variant_type
= TREE_TYPE (variant
);
22129 dw_die_ref variant_die
;
22131 /* All variants (i.e. members of a variant part) are supposed to be
22132 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
22133 under these records. */
22134 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
22136 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
22137 equate_decl_number_to_die (variant
, variant_die
);
22139 /* Output discriminant values this variant matches, if any. */
22140 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
22141 /* In the case we have discriminant information at all, this is
22142 probably the default variant: as the standard says, don't
22143 output any discriminant value/list attribute. */
22145 else if (discr_lists
[i
]->dw_discr_next
== NULL
22146 && !discr_lists
[i
]->dw_discr_range
)
22147 /* If there is only one accepted value, don't bother outputting a
22149 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
22151 add_discr_list (variant_die
, discr_lists
[i
]);
22153 for (tree member
= TYPE_FIELDS (variant_type
);
22154 member
!= NULL_TREE
;
22155 member
= DECL_CHAIN (member
))
22157 struct vlr_context vlr_sub_ctx
= {
22158 vlr_ctx
->struct_type
, /* struct_type */
22159 NULL
/* variant_part_offset */
22161 if (is_variant_part (member
))
22163 /* All offsets for fields inside variant parts are relative to
22164 the top-level embedding RECORD_TYPE's base address. On the
22165 other hand, offsets in GCC's types are relative to the
22166 nested-most variant part. So we have to sum offsets each time
22169 vlr_sub_ctx
.variant_part_offset
22170 = fold (build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
22171 variant_part_offset
, byte_position (member
)));
22172 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
22176 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
22177 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
22182 free (discr_lists
);
22185 /* Generate a DIE for a class member. */
22188 gen_member_die (tree type
, dw_die_ref context_die
)
22191 tree binfo
= TYPE_BINFO (type
);
22194 /* If this is not an incomplete type, output descriptions of each of its
22195 members. Note that as we output the DIEs necessary to represent the
22196 members of this record or union type, we will also be trying to output
22197 DIEs to represent the *types* of those members. However the `type'
22198 function (above) will specifically avoid generating type DIEs for member
22199 types *within* the list of member DIEs for this (containing) type except
22200 for those types (of members) which are explicitly marked as also being
22201 members of this (containing) type themselves. The g++ front- end can
22202 force any given type to be treated as a member of some other (containing)
22203 type by setting the TYPE_CONTEXT of the given (member) type to point to
22204 the TREE node representing the appropriate (containing) type. */
22206 /* First output info about the base classes. */
22209 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
22213 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
22214 gen_inheritance_die (base
,
22215 (accesses
? (*accesses
)[i
] : access_public_node
),
22220 /* Now output info about the data members and type members. */
22221 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
22223 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
22225 /* If we thought we were generating minimal debug info for TYPE
22226 and then changed our minds, some of the member declarations
22227 may have already been defined. Don't define them again, but
22228 do put them in the right order. */
22230 child
= lookup_decl_die (member
);
22232 splice_child_die (context_die
, child
);
22234 /* Do not generate standard DWARF for variant parts if we are generating
22235 the corresponding GNAT encodings: DIEs generated for both would
22236 conflict in our mappings. */
22237 else if (is_variant_part (member
)
22238 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
)
22240 vlr_ctx
.variant_part_offset
= byte_position (member
);
22241 gen_variant_part (member
, &vlr_ctx
, context_die
);
22245 vlr_ctx
.variant_part_offset
= NULL_TREE
;
22246 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
22250 /* We do not keep type methods in type variants. */
22251 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
22252 /* Now output info about the function members (if any). */
22253 if (TYPE_METHODS (type
) != error_mark_node
)
22254 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
22256 /* Don't include clones in the member list. */
22257 if (DECL_ABSTRACT_ORIGIN (member
))
22259 /* Nor constructors for anonymous classes. */
22260 if (DECL_ARTIFICIAL (member
)
22261 && dwarf2_name (member
, 0) == NULL
)
22264 child
= lookup_decl_die (member
);
22266 splice_child_die (context_die
, child
);
22268 gen_decl_die (member
, NULL
, NULL
, context_die
);
22272 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
22273 is set, we pretend that the type was never defined, so we only get the
22274 member DIEs needed by later specification DIEs. */
22277 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
22278 enum debug_info_usage usage
)
22280 if (TREE_ASM_WRITTEN (type
))
22282 /* Fill in the bound of variable-length fields in late dwarf if
22283 still incomplete. */
22284 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
22285 for (tree member
= TYPE_FIELDS (type
);
22287 member
= DECL_CHAIN (member
))
22288 fill_variable_array_bounds (TREE_TYPE (member
));
22292 dw_die_ref type_die
= lookup_type_die (type
);
22293 dw_die_ref scope_die
= 0;
22295 int complete
= (TYPE_SIZE (type
)
22296 && (! TYPE_STUB_DECL (type
)
22297 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
22298 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
22299 complete
= complete
&& should_emit_struct_debug (type
, usage
);
22301 if (type_die
&& ! complete
)
22304 if (TYPE_CONTEXT (type
) != NULL_TREE
22305 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
22306 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
22309 scope_die
= scope_die_for (type
, context_die
);
22311 /* Generate child dies for template paramaters. */
22312 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
22313 schedule_generic_params_dies_gen (type
);
22315 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
22316 /* First occurrence of type or toplevel definition of nested class. */
22318 dw_die_ref old_die
= type_die
;
22320 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
22321 ? record_type_tag (type
) : DW_TAG_union_type
,
22323 equate_type_number_to_die (type
, type_die
);
22325 add_AT_specification (type_die
, old_die
);
22327 add_name_attribute (type_die
, type_tag (type
));
22330 remove_AT (type_die
, DW_AT_declaration
);
22332 /* If this type has been completed, then give it a byte_size attribute and
22333 then give a list of members. */
22334 if (complete
&& !ns_decl
)
22336 /* Prevent infinite recursion in cases where the type of some member of
22337 this type is expressed in terms of this type itself. */
22338 TREE_ASM_WRITTEN (type
) = 1;
22339 add_byte_size_attribute (type_die
, type
);
22340 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
22342 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
22343 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
22346 /* If the first reference to this type was as the return type of an
22347 inline function, then it may not have a parent. Fix this now. */
22348 if (type_die
->die_parent
== NULL
)
22349 add_child_die (scope_die
, type_die
);
22351 push_decl_scope (type
);
22352 gen_member_die (type
, type_die
);
22355 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
22356 if (TYPE_ARTIFICIAL (type
))
22357 add_AT_flag (type_die
, DW_AT_artificial
, 1);
22359 /* GNU extension: Record what type our vtable lives in. */
22360 if (TYPE_VFIELD (type
))
22362 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
22364 gen_type_die (vtype
, context_die
);
22365 add_AT_die_ref (type_die
, DW_AT_containing_type
,
22366 lookup_type_die (vtype
));
22371 add_AT_flag (type_die
, DW_AT_declaration
, 1);
22373 /* We don't need to do this for function-local types. */
22374 if (TYPE_STUB_DECL (type
)
22375 && ! decl_function_context (TYPE_STUB_DECL (type
)))
22376 vec_safe_push (incomplete_types
, type
);
22379 if (get_AT (type_die
, DW_AT_name
))
22380 add_pubtype (type
, type_die
);
22383 /* Generate a DIE for a subroutine _type_. */
22386 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
22388 tree return_type
= TREE_TYPE (type
);
22389 dw_die_ref subr_die
22390 = new_die (DW_TAG_subroutine_type
,
22391 scope_die_for (type
, context_die
), type
);
22393 equate_type_number_to_die (type
, subr_die
);
22394 add_prototyped_attribute (subr_die
, type
);
22395 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
22397 gen_formal_types_die (type
, subr_die
);
22399 if (get_AT (subr_die
, DW_AT_name
))
22400 add_pubtype (type
, subr_die
);
22403 /* Generate a DIE for a type definition. */
22406 gen_typedef_die (tree decl
, dw_die_ref context_die
)
22408 dw_die_ref type_die
;
22411 if (TREE_ASM_WRITTEN (decl
))
22413 if (DECL_ORIGINAL_TYPE (decl
))
22414 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
22418 TREE_ASM_WRITTEN (decl
) = 1;
22419 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
22420 origin
= decl_ultimate_origin (decl
);
22421 if (origin
!= NULL
)
22422 add_abstract_origin_attribute (type_die
, origin
);
22427 add_name_and_src_coords_attributes (type_die
, decl
);
22428 if (DECL_ORIGINAL_TYPE (decl
))
22430 type
= DECL_ORIGINAL_TYPE (decl
);
22432 if (type
== error_mark_node
)
22435 gcc_assert (type
!= TREE_TYPE (decl
));
22436 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
22440 type
= TREE_TYPE (decl
);
22442 if (type
== error_mark_node
)
22445 if (is_naming_typedef_decl (TYPE_NAME (type
)))
22447 /* Here, we are in the case of decl being a typedef naming
22448 an anonymous type, e.g:
22449 typedef struct {...} foo;
22450 In that case TREE_TYPE (decl) is not a typedef variant
22451 type and TYPE_NAME of the anonymous type is set to the
22452 TYPE_DECL of the typedef. This construct is emitted by
22455 TYPE is the anonymous struct named by the typedef
22456 DECL. As we need the DW_AT_type attribute of the
22457 DW_TAG_typedef to point to the DIE of TYPE, let's
22458 generate that DIE right away. add_type_attribute
22459 called below will then pick (via lookup_type_die) that
22460 anonymous struct DIE. */
22461 if (!TREE_ASM_WRITTEN (type
))
22462 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
22464 /* This is a GNU Extension. We are adding a
22465 DW_AT_linkage_name attribute to the DIE of the
22466 anonymous struct TYPE. The value of that attribute
22467 is the name of the typedef decl naming the anonymous
22468 struct. This greatly eases the work of consumers of
22469 this debug info. */
22470 add_linkage_name_raw (lookup_type_die (type
), decl
);
22474 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
22477 if (is_naming_typedef_decl (decl
))
22478 /* We want that all subsequent calls to lookup_type_die with
22479 TYPE in argument yield the DW_TAG_typedef we have just
22481 equate_type_number_to_die (type
, type_die
);
22483 add_accessibility_attribute (type_die
, decl
);
22486 if (DECL_ABSTRACT_P (decl
))
22487 equate_decl_number_to_die (decl
, type_die
);
22489 if (get_AT (type_die
, DW_AT_name
))
22490 add_pubtype (decl
, type_die
);
22493 /* Generate a DIE for a struct, class, enum or union type. */
22496 gen_tagged_type_die (tree type
,
22497 dw_die_ref context_die
,
22498 enum debug_info_usage usage
)
22502 if (type
== NULL_TREE
22503 || !is_tagged_type (type
))
22506 if (TREE_ASM_WRITTEN (type
))
22508 /* If this is a nested type whose containing class hasn't been written
22509 out yet, writing it out will cover this one, too. This does not apply
22510 to instantiations of member class templates; they need to be added to
22511 the containing class as they are generated. FIXME: This hurts the
22512 idea of combining type decls from multiple TUs, since we can't predict
22513 what set of template instantiations we'll get. */
22514 else if (TYPE_CONTEXT (type
)
22515 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
22516 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
22518 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
22520 if (TREE_ASM_WRITTEN (type
))
22523 /* If that failed, attach ourselves to the stub. */
22524 push_decl_scope (TYPE_CONTEXT (type
));
22525 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
22528 else if (TYPE_CONTEXT (type
) != NULL_TREE
22529 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
22531 /* If this type is local to a function that hasn't been written
22532 out yet, use a NULL context for now; it will be fixed up in
22533 decls_for_scope. */
22534 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
22535 /* A declaration DIE doesn't count; nested types need to go in the
22537 if (context_die
&& is_declaration_die (context_die
))
22538 context_die
= NULL
;
22543 context_die
= declare_in_namespace (type
, context_die
);
22547 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
22549 /* This might have been written out by the call to
22550 declare_in_namespace. */
22551 if (!TREE_ASM_WRITTEN (type
))
22552 gen_enumeration_type_die (type
, context_die
);
22555 gen_struct_or_union_type_die (type
, context_die
, usage
);
22560 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
22561 it up if it is ever completed. gen_*_type_die will set it for us
22562 when appropriate. */
22565 /* Generate a type description DIE. */
22568 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
22569 enum debug_info_usage usage
)
22571 struct array_descr_info info
;
22573 if (type
== NULL_TREE
|| type
== error_mark_node
)
22576 if (flag_checking
&& type
)
22577 verify_type (type
);
22579 if (TYPE_NAME (type
) != NULL_TREE
22580 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
22581 && is_redundant_typedef (TYPE_NAME (type
))
22582 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
22583 /* The DECL of this type is a typedef we don't want to emit debug
22584 info for but we want debug info for its underlying typedef.
22585 This can happen for e.g, the injected-class-name of a C++
22587 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
22589 /* If TYPE is a typedef type variant, let's generate debug info
22590 for the parent typedef which TYPE is a type of. */
22591 if (typedef_variant_p (type
))
22593 if (TREE_ASM_WRITTEN (type
))
22596 /* Prevent broken recursion; we can't hand off to the same type. */
22597 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
22599 /* Give typedefs the right scope. */
22600 context_die
= scope_die_for (type
, context_die
);
22602 TREE_ASM_WRITTEN (type
) = 1;
22604 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
22608 /* If type is an anonymous tagged type named by a typedef, let's
22609 generate debug info for the typedef. */
22610 if (is_naming_typedef_decl (TYPE_NAME (type
)))
22612 /* Use the DIE of the containing namespace as the parent DIE of
22613 the type description DIE we want to generate. */
22614 if (DECL_CONTEXT (TYPE_NAME (type
))
22615 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
22616 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
22618 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
22622 /* We are going to output a DIE to represent the unqualified version
22623 of this type (i.e. without any const or volatile qualifiers) so
22624 get the main variant (i.e. the unqualified version) of this type
22625 now. (Vectors and arrays are special because the debugging info is in the
22626 cloned type itself). */
22627 if (TREE_CODE (type
) != VECTOR_TYPE
22628 && TREE_CODE (type
) != ARRAY_TYPE
)
22629 type
= type_main_variant (type
);
22631 /* If this is an array type with hidden descriptor, handle it first. */
22632 if (!TREE_ASM_WRITTEN (type
)
22633 && lang_hooks
.types
.get_array_descr_info
)
22635 memset (&info
, 0, sizeof (info
));
22636 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
22638 /* Fortran sometimes emits array types with no dimension. */
22639 gcc_assert (info
.ndimensions
>= 0
22640 && (info
.ndimensions
22641 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
22642 gen_descr_array_type_die (type
, &info
, context_die
);
22643 TREE_ASM_WRITTEN (type
) = 1;
22648 if (TREE_ASM_WRITTEN (type
))
22650 /* Variable-length types may be incomplete even if
22651 TREE_ASM_WRITTEN. For such types, fall through to
22652 gen_array_type_die() and possibly fill in
22653 DW_AT_{upper,lower}_bound attributes. */
22654 if ((TREE_CODE (type
) != ARRAY_TYPE
22655 && TREE_CODE (type
) != RECORD_TYPE
22656 && TREE_CODE (type
) != UNION_TYPE
22657 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
22658 || !variably_modified_type_p (type
, NULL
))
22662 switch (TREE_CODE (type
))
22668 case REFERENCE_TYPE
:
22669 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
22670 ensures that the gen_type_die recursion will terminate even if the
22671 type is recursive. Recursive types are possible in Ada. */
22672 /* ??? We could perhaps do this for all types before the switch
22674 TREE_ASM_WRITTEN (type
) = 1;
22676 /* For these types, all that is required is that we output a DIE (or a
22677 set of DIEs) to represent the "basis" type. */
22678 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
22679 DINFO_USAGE_IND_USE
);
22683 /* This code is used for C++ pointer-to-data-member types.
22684 Output a description of the relevant class type. */
22685 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
22686 DINFO_USAGE_IND_USE
);
22688 /* Output a description of the type of the object pointed to. */
22689 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
22690 DINFO_USAGE_IND_USE
);
22692 /* Now output a DIE to represent this pointer-to-data-member type
22694 gen_ptr_to_mbr_type_die (type
, context_die
);
22697 case FUNCTION_TYPE
:
22698 /* Force out return type (in case it wasn't forced out already). */
22699 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
22700 DINFO_USAGE_DIR_USE
);
22701 gen_subroutine_type_die (type
, context_die
);
22705 /* Force out return type (in case it wasn't forced out already). */
22706 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
22707 DINFO_USAGE_DIR_USE
);
22708 gen_subroutine_type_die (type
, context_die
);
22713 gen_array_type_die (type
, context_die
);
22716 case ENUMERAL_TYPE
:
22719 case QUAL_UNION_TYPE
:
22720 gen_tagged_type_die (type
, context_die
, usage
);
22726 case FIXED_POINT_TYPE
:
22729 case POINTER_BOUNDS_TYPE
:
22730 /* No DIEs needed for fundamental types. */
22735 /* Just use DW_TAG_unspecified_type. */
22737 dw_die_ref type_die
= lookup_type_die (type
);
22738 if (type_die
== NULL
)
22740 tree name
= TYPE_IDENTIFIER (type
);
22741 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
22743 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
22744 equate_type_number_to_die (type
, type_die
);
22750 if (is_cxx_auto (type
))
22752 tree name
= TYPE_IDENTIFIER (type
);
22753 dw_die_ref
*die
= (name
== get_identifier ("auto")
22754 ? &auto_die
: &decltype_auto_die
);
22757 *die
= new_die (DW_TAG_unspecified_type
,
22758 comp_unit_die (), NULL_TREE
);
22759 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
22761 equate_type_number_to_die (type
, *die
);
22764 gcc_unreachable ();
22767 TREE_ASM_WRITTEN (type
) = 1;
22771 gen_type_die (tree type
, dw_die_ref context_die
)
22773 if (type
!= error_mark_node
)
22775 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
22778 dw_die_ref die
= lookup_type_die (type
);
22785 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
22786 things which are local to the given block. */
22789 gen_block_die (tree stmt
, dw_die_ref context_die
)
22791 int must_output_die
= 0;
22794 /* Ignore blocks that are NULL. */
22795 if (stmt
== NULL_TREE
)
22798 inlined_func
= inlined_function_outer_scope_p (stmt
);
22800 /* If the block is one fragment of a non-contiguous block, do not
22801 process the variables, since they will have been done by the
22802 origin block. Do process subblocks. */
22803 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
22807 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
22808 gen_block_die (sub
, context_die
);
22813 /* Determine if we need to output any Dwarf DIEs at all to represent this
22816 /* The outer scopes for inlinings *must* always be represented. We
22817 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
22818 must_output_die
= 1;
22821 /* Determine if this block directly contains any "significant"
22822 local declarations which we will need to output DIEs for. */
22823 if (debug_info_level
> DINFO_LEVEL_TERSE
)
22824 /* We are not in terse mode so *any* local declaration counts
22825 as being a "significant" one. */
22826 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
22827 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
22828 && (TREE_USED (stmt
)
22829 || TREE_ASM_WRITTEN (stmt
)
22830 || BLOCK_ABSTRACT (stmt
)));
22831 else if ((TREE_USED (stmt
)
22832 || TREE_ASM_WRITTEN (stmt
)
22833 || BLOCK_ABSTRACT (stmt
))
22834 && !dwarf2out_ignore_block (stmt
))
22835 must_output_die
= 1;
22838 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
22839 DIE for any block which contains no significant local declarations at
22840 all. Rather, in such cases we just call `decls_for_scope' so that any
22841 needed Dwarf info for any sub-blocks will get properly generated. Note
22842 that in terse mode, our definition of what constitutes a "significant"
22843 local declaration gets restricted to include only inlined function
22844 instances and local (nested) function definitions. */
22845 if (must_output_die
)
22849 /* If STMT block is abstract, that means we have been called
22850 indirectly from dwarf2out_abstract_function.
22851 That function rightfully marks the descendent blocks (of
22852 the abstract function it is dealing with) as being abstract,
22853 precisely to prevent us from emitting any
22854 DW_TAG_inlined_subroutine DIE as a descendent
22855 of an abstract function instance. So in that case, we should
22856 not call gen_inlined_subroutine_die.
22858 Later though, when cgraph asks dwarf2out to emit info
22859 for the concrete instance of the function decl into which
22860 the concrete instance of STMT got inlined, the later will lead
22861 to the generation of a DW_TAG_inlined_subroutine DIE. */
22862 if (! BLOCK_ABSTRACT (stmt
))
22863 gen_inlined_subroutine_die (stmt
, context_die
);
22866 gen_lexical_block_die (stmt
, context_die
);
22869 decls_for_scope (stmt
, context_die
);
22872 /* Process variable DECL (or variable with origin ORIGIN) within
22873 block STMT and add it to CONTEXT_DIE. */
22875 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
22878 tree decl_or_origin
= decl
? decl
: origin
;
22880 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
22881 die
= lookup_decl_die (decl_or_origin
);
22882 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
22883 && TYPE_DECL_IS_STUB (decl_or_origin
))
22884 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
22888 if (die
!= NULL
&& die
->die_parent
== NULL
)
22889 add_child_die (context_die
, die
);
22890 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
22893 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
22894 stmt
, context_die
);
22897 gen_decl_die (decl
, origin
, NULL
, context_die
);
22900 /* Generate all of the decls declared within a given scope and (recursively)
22901 all of its sub-blocks. */
22904 decls_for_scope (tree stmt
, dw_die_ref context_die
)
22910 /* Ignore NULL blocks. */
22911 if (stmt
== NULL_TREE
)
22914 /* Output the DIEs to represent all of the data objects and typedefs
22915 declared directly within this block but not within any nested
22916 sub-blocks. Also, nested function and tag DIEs have been
22917 generated with a parent of NULL; fix that up now. We don't
22918 have to do this if we're at -g1. */
22919 if (debug_info_level
> DINFO_LEVEL_TERSE
)
22921 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
22922 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
22923 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
22924 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
22928 /* Even if we're at -g1, we need to process the subblocks in order to get
22929 inlined call information. */
22931 /* Output the DIEs to represent all sub-blocks (and the items declared
22932 therein) of this block. */
22933 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
22935 subblocks
= BLOCK_CHAIN (subblocks
))
22936 gen_block_die (subblocks
, context_die
);
22939 /* Is this a typedef we can avoid emitting? */
22942 is_redundant_typedef (const_tree decl
)
22944 if (TYPE_DECL_IS_STUB (decl
))
22947 if (DECL_ARTIFICIAL (decl
)
22948 && DECL_CONTEXT (decl
)
22949 && is_tagged_type (DECL_CONTEXT (decl
))
22950 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
22951 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
22952 /* Also ignore the artificial member typedef for the class name. */
22958 /* Return TRUE if TYPE is a typedef that names a type for linkage
22959 purposes. This kind of typedefs is produced by the C++ FE for
22962 typedef struct {...} foo;
22964 In that case, there is no typedef variant type produced for foo.
22965 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
22969 is_naming_typedef_decl (const_tree decl
)
22971 if (decl
== NULL_TREE
22972 || TREE_CODE (decl
) != TYPE_DECL
22973 || !is_tagged_type (TREE_TYPE (decl
))
22974 || DECL_IS_BUILTIN (decl
)
22975 || is_redundant_typedef (decl
)
22976 /* It looks like Ada produces TYPE_DECLs that are very similar
22977 to C++ naming typedefs but that have different
22978 semantics. Let's be specific to c++ for now. */
22982 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
22983 && TYPE_NAME (TREE_TYPE (decl
)) == decl
22984 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
22985 != TYPE_NAME (TREE_TYPE (decl
))));
22988 /* Looks up the DIE for a context. */
22990 static inline dw_die_ref
22991 lookup_context_die (tree context
)
22995 /* Find die that represents this context. */
22996 if (TYPE_P (context
))
22998 context
= TYPE_MAIN_VARIANT (context
);
22999 dw_die_ref ctx
= lookup_type_die (context
);
23002 return strip_naming_typedef (context
, ctx
);
23005 return lookup_decl_die (context
);
23007 return comp_unit_die ();
23010 /* Returns the DIE for a context. */
23012 static inline dw_die_ref
23013 get_context_die (tree context
)
23017 /* Find die that represents this context. */
23018 if (TYPE_P (context
))
23020 context
= TYPE_MAIN_VARIANT (context
);
23021 return strip_naming_typedef (context
, force_type_die (context
));
23024 return force_decl_die (context
);
23026 return comp_unit_die ();
23029 /* Returns the DIE for decl. A DIE will always be returned. */
23032 force_decl_die (tree decl
)
23034 dw_die_ref decl_die
;
23035 unsigned saved_external_flag
;
23036 tree save_fn
= NULL_TREE
;
23037 decl_die
= lookup_decl_die (decl
);
23040 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
23042 decl_die
= lookup_decl_die (decl
);
23046 switch (TREE_CODE (decl
))
23048 case FUNCTION_DECL
:
23049 /* Clear current_function_decl, so that gen_subprogram_die thinks
23050 that this is a declaration. At this point, we just want to force
23051 declaration die. */
23052 save_fn
= current_function_decl
;
23053 current_function_decl
= NULL_TREE
;
23054 gen_subprogram_die (decl
, context_die
);
23055 current_function_decl
= save_fn
;
23059 /* Set external flag to force declaration die. Restore it after
23060 gen_decl_die() call. */
23061 saved_external_flag
= DECL_EXTERNAL (decl
);
23062 DECL_EXTERNAL (decl
) = 1;
23063 gen_decl_die (decl
, NULL
, NULL
, context_die
);
23064 DECL_EXTERNAL (decl
) = saved_external_flag
;
23067 case NAMESPACE_DECL
:
23068 if (dwarf_version
>= 3 || !dwarf_strict
)
23069 dwarf2out_decl (decl
);
23071 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
23072 decl_die
= comp_unit_die ();
23075 case TRANSLATION_UNIT_DECL
:
23076 decl_die
= comp_unit_die ();
23080 gcc_unreachable ();
23083 /* We should be able to find the DIE now. */
23085 decl_die
= lookup_decl_die (decl
);
23086 gcc_assert (decl_die
);
23092 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
23093 always returned. */
23096 force_type_die (tree type
)
23098 dw_die_ref type_die
;
23100 type_die
= lookup_type_die (type
);
23103 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
23105 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
23106 false, context_die
);
23107 gcc_assert (type_die
);
23112 /* Force out any required namespaces to be able to output DECL,
23113 and return the new context_die for it, if it's changed. */
23116 setup_namespace_context (tree thing
, dw_die_ref context_die
)
23118 tree context
= (DECL_P (thing
)
23119 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
23120 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
23121 /* Force out the namespace. */
23122 context_die
= force_decl_die (context
);
23124 return context_die
;
23127 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
23128 type) within its namespace, if appropriate.
23130 For compatibility with older debuggers, namespace DIEs only contain
23131 declarations; all definitions are emitted at CU scope, with
23132 DW_AT_specification pointing to the declaration (like with class
23136 declare_in_namespace (tree thing
, dw_die_ref context_die
)
23138 dw_die_ref ns_context
;
23140 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23141 return context_die
;
23143 /* External declarations in the local scope only need to be emitted
23144 once, not once in the namespace and once in the scope.
23146 This avoids declaring the `extern' below in the
23147 namespace DIE as well as in the innermost scope:
23160 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
23161 return context_die
;
23163 /* If this decl is from an inlined function, then don't try to emit it in its
23164 namespace, as we will get confused. It would have already been emitted
23165 when the abstract instance of the inline function was emitted anyways. */
23166 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
23167 return context_die
;
23169 ns_context
= setup_namespace_context (thing
, context_die
);
23171 if (ns_context
!= context_die
)
23175 if (DECL_P (thing
))
23176 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
23178 gen_type_die (thing
, ns_context
);
23180 return context_die
;
23183 /* Generate a DIE for a namespace or namespace alias. */
23186 gen_namespace_die (tree decl
, dw_die_ref context_die
)
23188 dw_die_ref namespace_die
;
23190 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
23191 they are an alias of. */
23192 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
23194 /* Output a real namespace or module. */
23195 context_die
= setup_namespace_context (decl
, comp_unit_die ());
23196 namespace_die
= new_die (is_fortran ()
23197 ? DW_TAG_module
: DW_TAG_namespace
,
23198 context_die
, decl
);
23199 /* For Fortran modules defined in different CU don't add src coords. */
23200 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
23202 const char *name
= dwarf2_name (decl
, 0);
23204 add_name_attribute (namespace_die
, name
);
23207 add_name_and_src_coords_attributes (namespace_die
, decl
);
23208 if (DECL_EXTERNAL (decl
))
23209 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
23210 equate_decl_number_to_die (decl
, namespace_die
);
23214 /* Output a namespace alias. */
23216 /* Force out the namespace we are an alias of, if necessary. */
23217 dw_die_ref origin_die
23218 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
23220 if (DECL_FILE_SCOPE_P (decl
)
23221 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
23222 context_die
= setup_namespace_context (decl
, comp_unit_die ());
23223 /* Now create the namespace alias DIE. */
23224 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
23225 add_name_and_src_coords_attributes (namespace_die
, decl
);
23226 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
23227 equate_decl_number_to_die (decl
, namespace_die
);
23229 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
23230 if (want_pubnames ())
23231 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
23234 /* Generate Dwarf debug information for a decl described by DECL.
23235 The return value is currently only meaningful for PARM_DECLs,
23236 for all other decls it returns NULL.
23238 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
23239 It can be NULL otherwise. */
23242 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
23243 dw_die_ref context_die
)
23245 tree decl_or_origin
= decl
? decl
: origin
;
23246 tree class_origin
= NULL
, ultimate_origin
;
23248 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
23251 /* Ignore pointer bounds decls. */
23252 if (DECL_P (decl_or_origin
)
23253 && TREE_TYPE (decl_or_origin
)
23254 && POINTER_BOUNDS_P (decl_or_origin
))
23257 switch (TREE_CODE (decl_or_origin
))
23263 if (!is_fortran () && !is_ada ())
23265 /* The individual enumerators of an enum type get output when we output
23266 the Dwarf representation of the relevant enum type itself. */
23270 /* Emit its type. */
23271 gen_type_die (TREE_TYPE (decl
), context_die
);
23273 /* And its containing namespace. */
23274 context_die
= declare_in_namespace (decl
, context_die
);
23276 gen_const_die (decl
, context_die
);
23279 case FUNCTION_DECL
:
23280 /* Don't output any DIEs to represent mere function declarations,
23281 unless they are class members or explicit block externs. */
23282 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
23283 && DECL_FILE_SCOPE_P (decl_or_origin
)
23284 && (current_function_decl
== NULL_TREE
23285 || DECL_ARTIFICIAL (decl_or_origin
)))
23290 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
23291 on local redeclarations of global functions. That seems broken. */
23292 if (current_function_decl
!= decl
)
23293 /* This is only a declaration. */;
23296 /* If we're emitting a clone, emit info for the abstract instance. */
23297 if (origin
|| DECL_ORIGIN (decl
) != decl
)
23298 dwarf2out_abstract_function (origin
23299 ? DECL_ORIGIN (origin
)
23300 : DECL_ABSTRACT_ORIGIN (decl
));
23302 /* If we're emitting an out-of-line copy of an inline function,
23303 emit info for the abstract instance and set up to refer to it. */
23304 else if (cgraph_function_possibly_inlined_p (decl
)
23305 && ! DECL_ABSTRACT_P (decl
)
23306 && ! class_or_namespace_scope_p (context_die
)
23307 /* dwarf2out_abstract_function won't emit a die if this is just
23308 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
23309 that case, because that works only if we have a die. */
23310 && DECL_INITIAL (decl
) != NULL_TREE
)
23312 dwarf2out_abstract_function (decl
);
23313 set_decl_origin_self (decl
);
23316 /* Otherwise we're emitting the primary DIE for this decl. */
23317 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
23319 /* Before we describe the FUNCTION_DECL itself, make sure that we
23320 have its containing type. */
23322 origin
= decl_class_context (decl
);
23323 if (origin
!= NULL_TREE
)
23324 gen_type_die (origin
, context_die
);
23326 /* And its return type. */
23327 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
23329 /* And its virtual context. */
23330 if (DECL_VINDEX (decl
) != NULL_TREE
)
23331 gen_type_die (DECL_CONTEXT (decl
), context_die
);
23333 /* Make sure we have a member DIE for decl. */
23334 if (origin
!= NULL_TREE
)
23335 gen_type_die_for_member (origin
, decl
, context_die
);
23337 /* And its containing namespace. */
23338 context_die
= declare_in_namespace (decl
, context_die
);
23341 /* Now output a DIE to represent the function itself. */
23343 gen_subprogram_die (decl
, context_die
);
23347 /* If we are in terse mode, don't generate any DIEs to represent any
23348 actual typedefs. */
23349 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23352 /* In the special case of a TYPE_DECL node representing the declaration
23353 of some type tag, if the given TYPE_DECL is marked as having been
23354 instantiated from some other (original) TYPE_DECL node (e.g. one which
23355 was generated within the original definition of an inline function) we
23356 used to generate a special (abbreviated) DW_TAG_structure_type,
23357 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
23358 should be actually referencing those DIEs, as variable DIEs with that
23359 type would be emitted already in the abstract origin, so it was always
23360 removed during unused type prunning. Don't add anything in this
23362 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
23365 if (is_redundant_typedef (decl
))
23366 gen_type_die (TREE_TYPE (decl
), context_die
);
23368 /* Output a DIE to represent the typedef itself. */
23369 gen_typedef_die (decl
, context_die
);
23373 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23374 gen_label_die (decl
, context_die
);
23379 /* If we are in terse mode, don't generate any DIEs to represent any
23380 variable declarations or definitions. */
23381 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23384 /* Output any DIEs that are needed to specify the type of this data
23386 if (decl_by_reference_p (decl_or_origin
))
23387 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
23389 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
23391 /* And its containing type. */
23392 class_origin
= decl_class_context (decl_or_origin
);
23393 if (class_origin
!= NULL_TREE
)
23394 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
23396 /* And its containing namespace. */
23397 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
23399 /* Now output the DIE to represent the data object itself. This gets
23400 complicated because of the possibility that the VAR_DECL really
23401 represents an inlined instance of a formal parameter for an inline
23403 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
23404 if (ultimate_origin
!= NULL_TREE
23405 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
23406 gen_formal_parameter_die (decl
, origin
,
23407 true /* Emit name attribute. */,
23410 gen_variable_die (decl
, origin
, context_die
);
23414 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
23415 /* Ignore the nameless fields that are used to skip bits but handle C++
23416 anonymous unions and structs. */
23417 if (DECL_NAME (decl
) != NULL_TREE
23418 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
23419 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
23421 gen_type_die (member_declared_type (decl
), context_die
);
23422 gen_field_die (decl
, ctx
, context_die
);
23427 if (DECL_BY_REFERENCE (decl_or_origin
))
23428 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
23430 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
23431 return gen_formal_parameter_die (decl
, origin
,
23432 true /* Emit name attribute. */,
23435 case NAMESPACE_DECL
:
23436 if (dwarf_version
>= 3 || !dwarf_strict
)
23437 gen_namespace_die (decl
, context_die
);
23440 case IMPORTED_DECL
:
23441 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
23442 DECL_CONTEXT (decl
), context_die
);
23445 case NAMELIST_DECL
:
23446 gen_namelist_decl (DECL_NAME (decl
), context_die
,
23447 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
23451 /* Probably some frontend-internal decl. Assume we don't care. */
23452 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
23459 /* Output initial debug information for global DECL. Called at the
23460 end of the parsing process.
23462 This is the initial debug generation process. As such, the DIEs
23463 generated may be incomplete. A later debug generation pass
23464 (dwarf2out_late_global_decl) will augment the information generated
23465 in this pass (e.g., with complete location info). */
23468 dwarf2out_early_global_decl (tree decl
)
23472 /* gen_decl_die() will set DECL_ABSTRACT because
23473 cgraph_function_possibly_inlined_p() returns true. This is in
23474 turn will cause DW_AT_inline attributes to be set.
23476 This happens because at early dwarf generation, there is no
23477 cgraph information, causing cgraph_function_possibly_inlined_p()
23478 to return true. Trick cgraph_function_possibly_inlined_p()
23479 while we generate dwarf early. */
23480 bool save
= symtab
->global_info_ready
;
23481 symtab
->global_info_ready
= true;
23483 /* We don't handle TYPE_DECLs. If required, they'll be reached via
23484 other DECLs and they can point to template types or other things
23485 that dwarf2out can't handle when done via dwarf2out_decl. */
23486 if (TREE_CODE (decl
) != TYPE_DECL
23487 && TREE_CODE (decl
) != PARM_DECL
)
23489 tree save_fndecl
= current_function_decl
;
23490 if (TREE_CODE (decl
) == FUNCTION_DECL
)
23492 /* No cfun means the symbol has no body, so there's nothing
23494 if (!DECL_STRUCT_FUNCTION (decl
))
23495 goto early_decl_exit
;
23497 current_function_decl
= decl
;
23499 dwarf2out_decl (decl
);
23500 if (TREE_CODE (decl
) == FUNCTION_DECL
)
23501 current_function_decl
= save_fndecl
;
23504 symtab
->global_info_ready
= save
;
23507 /* Output debug information for global decl DECL. Called from
23508 toplev.c after compilation proper has finished. */
23511 dwarf2out_late_global_decl (tree decl
)
23513 /* We have to generate early debug late for LTO. */
23515 dwarf2out_early_global_decl (decl
);
23517 /* Fill-in any location information we were unable to determine
23518 on the first pass. */
23519 if (TREE_CODE (decl
) == VAR_DECL
23520 && !POINTER_BOUNDS_P (decl
))
23522 dw_die_ref die
= lookup_decl_die (decl
);
23524 add_location_or_const_value_attribute (die
, decl
, false);
23528 /* Output debug information for type decl DECL. Called from toplev.c
23529 and from language front ends (to record built-in types). */
23531 dwarf2out_type_decl (tree decl
, int local
)
23536 dwarf2out_decl (decl
);
23540 /* Output debug information for imported module or decl DECL.
23541 NAME is non-NULL name in the lexical block if the decl has been renamed.
23542 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
23543 that DECL belongs to.
23544 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
23546 dwarf2out_imported_module_or_decl_1 (tree decl
,
23548 tree lexical_block
,
23549 dw_die_ref lexical_block_die
)
23551 expanded_location xloc
;
23552 dw_die_ref imported_die
= NULL
;
23553 dw_die_ref at_import_die
;
23555 if (TREE_CODE (decl
) == IMPORTED_DECL
)
23557 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
23558 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
23562 xloc
= expand_location (input_location
);
23564 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
23566 at_import_die
= force_type_die (TREE_TYPE (decl
));
23567 /* For namespace N { typedef void T; } using N::T; base_type_die
23568 returns NULL, but DW_TAG_imported_declaration requires
23569 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
23570 if (!at_import_die
)
23572 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
23573 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
23574 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
23575 gcc_assert (at_import_die
);
23580 at_import_die
= lookup_decl_die (decl
);
23581 if (!at_import_die
)
23583 /* If we're trying to avoid duplicate debug info, we may not have
23584 emitted the member decl for this field. Emit it now. */
23585 if (TREE_CODE (decl
) == FIELD_DECL
)
23587 tree type
= DECL_CONTEXT (decl
);
23589 if (TYPE_CONTEXT (type
)
23590 && TYPE_P (TYPE_CONTEXT (type
))
23591 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
23592 DINFO_USAGE_DIR_USE
))
23594 gen_type_die_for_member (type
, decl
,
23595 get_context_die (TYPE_CONTEXT (type
)));
23597 if (TREE_CODE (decl
) == NAMELIST_DECL
)
23598 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
23599 get_context_die (DECL_CONTEXT (decl
)),
23602 at_import_die
= force_decl_die (decl
);
23606 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
23608 if (dwarf_version
>= 3 || !dwarf_strict
)
23609 imported_die
= new_die (DW_TAG_imported_module
,
23616 imported_die
= new_die (DW_TAG_imported_declaration
,
23620 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
23621 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
23623 add_AT_string (imported_die
, DW_AT_name
,
23624 IDENTIFIER_POINTER (name
));
23625 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
23628 /* Output debug information for imported module or decl DECL.
23629 NAME is non-NULL name in context if the decl has been renamed.
23630 CHILD is true if decl is one of the renamed decls as part of
23631 importing whole module. */
23634 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
23637 /* dw_die_ref at_import_die; */
23638 dw_die_ref scope_die
;
23640 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23647 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
23648 We need decl DIE for reference and scope die. First, get DIE for the decl
23651 /* Get the scope die for decl context. Use comp_unit_die for global module
23652 or decl. If die is not found for non globals, force new die. */
23654 && TYPE_P (context
)
23655 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
23658 if (!(dwarf_version
>= 3 || !dwarf_strict
))
23661 scope_die
= get_context_die (context
);
23665 gcc_assert (scope_die
->die_child
);
23666 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
23667 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
23668 scope_die
= scope_die
->die_child
;
23671 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
23672 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
23675 /* Output debug information for namelists. */
23678 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
23680 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
23684 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23687 gcc_assert (scope_die
!= NULL
);
23688 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
23689 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
23691 /* If there are no item_decls, we have a nondefining namelist, e.g.
23692 with USE association; hence, set DW_AT_declaration. */
23693 if (item_decls
== NULL_TREE
)
23695 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
23699 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
23701 nml_item_ref_die
= lookup_decl_die (value
);
23702 if (!nml_item_ref_die
)
23703 nml_item_ref_die
= force_decl_die (value
);
23705 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
23706 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
23712 /* Write the debugging output for DECL and return the DIE. */
23715 dwarf2out_decl (tree decl
)
23717 dw_die_ref context_die
= comp_unit_die ();
23719 switch (TREE_CODE (decl
))
23724 case FUNCTION_DECL
:
23725 /* What we would really like to do here is to filter out all mere
23726 file-scope declarations of file-scope functions which are never
23727 referenced later within this translation unit (and keep all of ones
23728 that *are* referenced later on) but we aren't clairvoyant, so we have
23729 no idea which functions will be referenced in the future (i.e. later
23730 on within the current translation unit). So here we just ignore all
23731 file-scope function declarations which are not also definitions. If
23732 and when the debugger needs to know something about these functions,
23733 it will have to hunt around and find the DWARF information associated
23734 with the definition of the function.
23736 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
23737 nodes represent definitions and which ones represent mere
23738 declarations. We have to check DECL_INITIAL instead. That's because
23739 the C front-end supports some weird semantics for "extern inline"
23740 function definitions. These can get inlined within the current
23741 translation unit (and thus, we need to generate Dwarf info for their
23742 abstract instances so that the Dwarf info for the concrete inlined
23743 instances can have something to refer to) but the compiler never
23744 generates any out-of-lines instances of such things (despite the fact
23745 that they *are* definitions).
23747 The important point is that the C front-end marks these "extern
23748 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
23749 them anyway. Note that the C++ front-end also plays some similar games
23750 for inline function definitions appearing within include files which
23751 also contain `#pragma interface' pragmas.
23753 If we are called from dwarf2out_abstract_function output a DIE
23754 anyway. We can end up here this way with early inlining and LTO
23755 where the inlined function is output in a different LTRANS unit
23757 if (DECL_INITIAL (decl
) == NULL_TREE
23758 && ! DECL_ABSTRACT_P (decl
))
23761 /* If we're a nested function, initially use a parent of NULL; if we're
23762 a plain function, this will be fixed up in decls_for_scope. If
23763 we're a method, it will be ignored, since we already have a DIE. */
23764 if (decl_function_context (decl
)
23765 /* But if we're in terse mode, we don't care about scope. */
23766 && debug_info_level
> DINFO_LEVEL_TERSE
)
23767 context_die
= NULL
;
23771 /* For local statics lookup proper context die. */
23772 if (local_function_static (decl
))
23773 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
23775 /* If we are in terse mode, don't generate any DIEs to represent any
23776 variable declarations or definitions. */
23777 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23782 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23784 if (!is_fortran () && !is_ada ())
23786 if (TREE_STATIC (decl
) && decl_function_context (decl
))
23787 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
23790 case NAMESPACE_DECL
:
23791 case IMPORTED_DECL
:
23792 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23794 if (lookup_decl_die (decl
) != NULL
)
23799 /* Don't emit stubs for types unless they are needed by other DIEs. */
23800 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
23803 /* Don't bother trying to generate any DIEs to represent any of the
23804 normal built-in types for the language we are compiling. */
23805 if (DECL_IS_BUILTIN (decl
))
23808 /* If we are in terse mode, don't generate any DIEs for types. */
23809 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23812 /* If we're a function-scope tag, initially use a parent of NULL;
23813 this will be fixed up in decls_for_scope. */
23814 if (decl_function_context (decl
))
23815 context_die
= NULL
;
23819 case NAMELIST_DECL
:
23826 gen_decl_die (decl
, NULL
, NULL
, context_die
);
23830 dw_die_ref die
= lookup_decl_die (decl
);
23836 /* Write the debugging output for DECL. */
23839 dwarf2out_function_decl (tree decl
)
23841 dwarf2out_decl (decl
);
23842 call_arg_locations
= NULL
;
23843 call_arg_loc_last
= NULL
;
23844 call_site_count
= -1;
23845 tail_call_site_count
= -1;
23846 decl_loc_table
->empty ();
23847 cached_dw_loc_list_table
->empty ();
23850 /* Output a marker (i.e. a label) for the beginning of the generated code for
23851 a lexical block. */
23854 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
23855 unsigned int blocknum
)
23857 switch_to_section (current_function_section ());
23858 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
23861 /* Output a marker (i.e. a label) for the end of the generated code for a
23865 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
23867 switch_to_section (current_function_section ());
23868 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
23871 /* Returns nonzero if it is appropriate not to emit any debugging
23872 information for BLOCK, because it doesn't contain any instructions.
23874 Don't allow this for blocks with nested functions or local classes
23875 as we would end up with orphans, and in the presence of scheduling
23876 we may end up calling them anyway. */
23879 dwarf2out_ignore_block (const_tree block
)
23884 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
23885 if (TREE_CODE (decl
) == FUNCTION_DECL
23886 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
23888 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
23890 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
23891 if (TREE_CODE (decl
) == FUNCTION_DECL
23892 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
23899 /* Hash table routines for file_hash. */
23902 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
23904 return filename_cmp (p1
->filename
, p2
) == 0;
23908 dwarf_file_hasher::hash (dwarf_file_data
*p
)
23910 return htab_hash_string (p
->filename
);
23913 /* Lookup FILE_NAME (in the list of filenames that we know about here in
23914 dwarf2out.c) and return its "index". The index of each (known) filename is
23915 just a unique number which is associated with only that one filename. We
23916 need such numbers for the sake of generating labels (in the .debug_sfnames
23917 section) and references to those files numbers (in the .debug_srcinfo
23918 and .debug_macinfo sections). If the filename given as an argument is not
23919 found in our current list, add it to the list and assign it the next
23920 available unique index number. */
23922 static struct dwarf_file_data
*
23923 lookup_filename (const char *file_name
)
23925 struct dwarf_file_data
* created
;
23930 dwarf_file_data
**slot
23931 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
23936 created
= ggc_alloc
<dwarf_file_data
> ();
23937 created
->filename
= file_name
;
23938 created
->emitted_number
= 0;
23943 /* If the assembler will construct the file table, then translate the compiler
23944 internal file table number into the assembler file table number, and emit
23945 a .file directive if we haven't already emitted one yet. The file table
23946 numbers are different because we prune debug info for unused variables and
23947 types, which may include filenames. */
23950 maybe_emit_file (struct dwarf_file_data
* fd
)
23952 if (! fd
->emitted_number
)
23954 if (last_emitted_file
)
23955 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
23957 fd
->emitted_number
= 1;
23958 last_emitted_file
= fd
;
23960 if (DWARF2_ASM_LINE_DEBUG_INFO
)
23962 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
23963 output_quoted_string (asm_out_file
,
23964 remap_debug_filename (fd
->filename
));
23965 fputc ('\n', asm_out_file
);
23969 return fd
->emitted_number
;
23972 /* Schedule generation of a DW_AT_const_value attribute to DIE.
23973 That generation should happen after function debug info has been
23974 generated. The value of the attribute is the constant value of ARG. */
23977 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
23979 die_arg_entry entry
;
23984 gcc_assert (early_dwarf
);
23986 if (!tmpl_value_parm_die_table
)
23987 vec_alloc (tmpl_value_parm_die_table
, 32);
23991 vec_safe_push (tmpl_value_parm_die_table
, entry
);
23994 /* Return TRUE if T is an instance of generic type, FALSE
23998 generic_type_p (tree t
)
24000 if (t
== NULL_TREE
|| !TYPE_P (t
))
24002 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
24005 /* Schedule the generation of the generic parameter dies for the
24006 instance of generic type T. The proper generation itself is later
24007 done by gen_scheduled_generic_parms_dies. */
24010 schedule_generic_params_dies_gen (tree t
)
24012 if (!generic_type_p (t
))
24015 gcc_assert (early_dwarf
);
24017 if (!generic_type_instances
)
24018 vec_alloc (generic_type_instances
, 256);
24020 vec_safe_push (generic_type_instances
, t
);
24023 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
24024 by append_entry_to_tmpl_value_parm_die_table. This function must
24025 be called after function DIEs have been generated. */
24028 gen_remaining_tmpl_value_param_die_attribute (void)
24030 if (tmpl_value_parm_die_table
)
24035 /* We do this in two phases - first get the cases we can
24036 handle during early-finish, preserving those we cannot
24037 (containing symbolic constants where we don't yet know
24038 whether we are going to output the referenced symbols).
24039 For those we try again at late-finish. */
24041 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
24043 if (!tree_add_const_value_attribute (e
->die
, e
->arg
))
24044 (*tmpl_value_parm_die_table
)[j
++] = *e
;
24046 tmpl_value_parm_die_table
->truncate (j
);
24050 /* Generate generic parameters DIEs for instances of generic types
24051 that have been previously scheduled by
24052 schedule_generic_params_dies_gen. This function must be called
24053 after all the types of the CU have been laid out. */
24056 gen_scheduled_generic_parms_dies (void)
24061 if (!generic_type_instances
)
24064 /* We end up "recursing" into schedule_generic_params_dies_gen, so
24065 pretend this generation is part of "early dwarf" as well. */
24068 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
24069 if (COMPLETE_TYPE_P (t
))
24070 gen_generic_params_dies (t
);
24072 generic_type_instances
= NULL
;
24076 /* Replace DW_AT_name for the decl with name. */
24079 dwarf2out_set_name (tree decl
, tree name
)
24082 dw_attr_node
*attr
;
24085 die
= TYPE_SYMTAB_DIE (decl
);
24089 dname
= dwarf2_name (name
, 0);
24093 attr
= get_AT (die
, DW_AT_name
);
24096 struct indirect_string_node
*node
;
24098 node
= find_AT_string (dname
);
24099 /* replace the string. */
24100 attr
->dw_attr_val
.v
.val_str
= node
;
24104 add_name_attribute (die
, dname
);
24107 /* True if before or during processing of the first function being emitted. */
24108 static bool in_first_function_p
= true;
24109 /* True if loc_note during dwarf2out_var_location call might still be
24110 before first real instruction at address equal to .Ltext0. */
24111 static bool maybe_at_text_label_p
= true;
24112 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
24113 static unsigned int first_loclabel_num_not_at_text_label
;
24115 /* Called by the final INSN scan whenever we see a var location. We
24116 use it to drop labels in the right places, and throw the location in
24117 our lookup table. */
24120 dwarf2out_var_location (rtx_insn
*loc_note
)
24122 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
24123 struct var_loc_node
*newloc
;
24124 rtx_insn
*next_real
, *next_note
;
24125 rtx_insn
*call_insn
= NULL
;
24126 static const char *last_label
;
24127 static const char *last_postcall_label
;
24128 static bool last_in_cold_section_p
;
24129 static rtx_insn
*expected_next_loc_note
;
24133 if (!NOTE_P (loc_note
))
24135 if (CALL_P (loc_note
))
24138 if (SIBLING_CALL_P (loc_note
))
24139 tail_call_site_count
++;
24140 if (optimize
== 0 && !flag_var_tracking
)
24142 /* When the var-tracking pass is not running, there is no note
24143 for indirect calls whose target is compile-time known. In this
24144 case, process such calls specifically so that we generate call
24145 sites for them anyway. */
24146 rtx x
= PATTERN (loc_note
);
24147 if (GET_CODE (x
) == PARALLEL
)
24148 x
= XVECEXP (x
, 0, 0);
24149 if (GET_CODE (x
) == SET
)
24151 if (GET_CODE (x
) == CALL
)
24154 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
24155 || !SYMBOL_REF_DECL (XEXP (x
, 0))
24156 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
24159 call_insn
= loc_note
;
24163 next_real
= next_real_insn (call_insn
);
24165 cached_next_real_insn
= NULL
;
24173 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
24174 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
24177 /* Optimize processing a large consecutive sequence of location
24178 notes so we don't spend too much time in next_real_insn. If the
24179 next insn is another location note, remember the next_real_insn
24180 calculation for next time. */
24181 next_real
= cached_next_real_insn
;
24184 if (expected_next_loc_note
!= loc_note
)
24188 next_note
= NEXT_INSN (loc_note
);
24190 || next_note
->deleted ()
24191 || ! NOTE_P (next_note
)
24192 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
24193 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
24197 next_real
= next_real_insn (loc_note
);
24201 expected_next_loc_note
= next_note
;
24202 cached_next_real_insn
= next_real
;
24205 cached_next_real_insn
= NULL
;
24207 /* If there are no instructions which would be affected by this note,
24208 don't do anything. */
24210 && next_real
== NULL_RTX
24211 && !NOTE_DURING_CALL_P (loc_note
))
24216 if (next_real
== NULL_RTX
)
24217 next_real
= get_last_insn ();
24219 /* If there were any real insns between note we processed last time
24220 and this note (or if it is the first note), clear
24221 last_{,postcall_}label so that they are not reused this time. */
24222 if (last_var_location_insn
== NULL_RTX
24223 || last_var_location_insn
!= next_real
24224 || last_in_cold_section_p
!= in_cold_section_p
)
24227 last_postcall_label
= NULL
;
24232 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
24233 newloc
= add_var_loc_to_decl (decl
, loc_note
,
24234 NOTE_DURING_CALL_P (loc_note
)
24235 ? last_postcall_label
: last_label
);
24236 if (newloc
== NULL
)
24245 /* If there were no real insns between note we processed last time
24246 and this note, use the label we emitted last time. Otherwise
24247 create a new label and emit it. */
24248 if (last_label
== NULL
)
24250 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
24251 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
24253 last_label
= ggc_strdup (loclabel
);
24254 /* See if loclabel might be equal to .Ltext0. If yes,
24255 bump first_loclabel_num_not_at_text_label. */
24256 if (!have_multiple_function_sections
24257 && in_first_function_p
24258 && maybe_at_text_label_p
)
24260 static rtx_insn
*last_start
;
24262 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
24263 if (insn
== last_start
)
24265 else if (!NONDEBUG_INSN_P (insn
))
24269 rtx body
= PATTERN (insn
);
24270 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
24272 /* Inline asm could occupy zero bytes. */
24273 else if (GET_CODE (body
) == ASM_INPUT
24274 || asm_noperands (body
) >= 0)
24276 #ifdef HAVE_attr_length
24277 else if (get_attr_min_length (insn
) == 0)
24282 /* Assume insn has non-zero length. */
24283 maybe_at_text_label_p
= false;
24287 if (maybe_at_text_label_p
)
24289 last_start
= loc_note
;
24290 first_loclabel_num_not_at_text_label
= loclabel_num
;
24295 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
24296 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
24300 struct call_arg_loc_node
*ca_loc
24301 = ggc_cleared_alloc
<call_arg_loc_node
> ();
24303 = loc_note
!= NULL_RTX
? prev_real_insn (loc_note
) : call_insn
;
24305 ca_loc
->call_arg_loc_note
= loc_note
;
24306 ca_loc
->next
= NULL
;
24307 ca_loc
->label
= last_label
;
24310 || (NONJUMP_INSN_P (prev
)
24311 && GET_CODE (PATTERN (prev
)) == SEQUENCE
24312 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
24313 if (!CALL_P (prev
))
24314 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
24315 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
24317 /* Look for a SYMBOL_REF in the "prev" instruction. */
24318 rtx x
= get_call_rtx_from (PATTERN (prev
));
24321 /* Try to get the call symbol, if any. */
24322 if (MEM_P (XEXP (x
, 0)))
24324 /* First, look for a memory access to a symbol_ref. */
24325 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
24326 && SYMBOL_REF_DECL (XEXP (x
, 0))
24327 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
24328 ca_loc
->symbol_ref
= XEXP (x
, 0);
24329 /* Otherwise, look at a compile-time known user-level function
24333 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
24334 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
24337 ca_loc
->block
= insn_scope (prev
);
24338 if (call_arg_locations
)
24339 call_arg_loc_last
->next
= ca_loc
;
24341 call_arg_locations
= ca_loc
;
24342 call_arg_loc_last
= ca_loc
;
24344 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
24345 newloc
->label
= last_label
;
24348 if (!last_postcall_label
)
24350 sprintf (loclabel
, "%s-1", last_label
);
24351 last_postcall_label
= ggc_strdup (loclabel
);
24353 newloc
->label
= last_postcall_label
;
24356 last_var_location_insn
= next_real
;
24357 last_in_cold_section_p
= in_cold_section_p
;
24360 /* Called from finalize_size_functions for size functions so that their body
24361 can be encoded in the debug info to describe the layout of variable-length
24365 dwarf2out_size_function (tree decl
)
24367 function_to_dwarf_procedure (decl
);
24370 /* Note in one location list that text section has changed. */
24373 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
24375 var_loc_list
*list
= *slot
;
24377 list
->last_before_switch
24378 = list
->last
->next
? list
->last
->next
: list
->last
;
24382 /* Note in all location lists that text section has changed. */
24385 var_location_switch_text_section (void)
24387 if (decl_loc_table
== NULL
)
24390 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
24393 /* Create a new line number table. */
24395 static dw_line_info_table
*
24396 new_line_info_table (void)
24398 dw_line_info_table
*table
;
24400 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
24401 table
->file_num
= 1;
24402 table
->line_num
= 1;
24403 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
24408 /* Lookup the "current" table into which we emit line info, so
24409 that we don't have to do it for every source line. */
24412 set_cur_line_info_table (section
*sec
)
24414 dw_line_info_table
*table
;
24416 if (sec
== text_section
)
24417 table
= text_section_line_info
;
24418 else if (sec
== cold_text_section
)
24420 table
= cold_text_section_line_info
;
24423 cold_text_section_line_info
= table
= new_line_info_table ();
24424 table
->end_label
= cold_end_label
;
24429 const char *end_label
;
24431 if (flag_reorder_blocks_and_partition
)
24433 if (in_cold_section_p
)
24434 end_label
= crtl
->subsections
.cold_section_end_label
;
24436 end_label
= crtl
->subsections
.hot_section_end_label
;
24440 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
24441 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
24442 current_function_funcdef_no
);
24443 end_label
= ggc_strdup (label
);
24446 table
= new_line_info_table ();
24447 table
->end_label
= end_label
;
24449 vec_safe_push (separate_line_info
, table
);
24452 if (DWARF2_ASM_LINE_DEBUG_INFO
)
24453 table
->is_stmt
= (cur_line_info_table
24454 ? cur_line_info_table
->is_stmt
24455 : DWARF_LINE_DEFAULT_IS_STMT_START
);
24456 cur_line_info_table
= table
;
24460 /* We need to reset the locations at the beginning of each
24461 function. We can't do this in the end_function hook, because the
24462 declarations that use the locations won't have been output when
24463 that hook is called. Also compute have_multiple_function_sections here. */
24466 dwarf2out_begin_function (tree fun
)
24468 section
*sec
= function_section (fun
);
24470 if (sec
!= text_section
)
24471 have_multiple_function_sections
= true;
24473 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
24475 gcc_assert (current_function_decl
== fun
);
24476 cold_text_section
= unlikely_text_section ();
24477 switch_to_section (cold_text_section
);
24478 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
24479 switch_to_section (sec
);
24482 dwarf2out_note_section_used ();
24483 call_site_count
= 0;
24484 tail_call_site_count
= 0;
24486 set_cur_line_info_table (sec
);
24489 /* Helper function of dwarf2out_end_function, called only after emitting
24490 the very first function into assembly. Check if some .debug_loc range
24491 might end with a .LVL* label that could be equal to .Ltext0.
24492 In that case we must force using absolute addresses in .debug_loc ranges,
24493 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
24494 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
24496 Set have_multiple_function_sections to true in that case and
24497 terminate htab traversal. */
24500 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
24502 var_loc_list
*entry
= *slot
;
24503 struct var_loc_node
*node
;
24505 node
= entry
->first
;
24506 if (node
&& node
->next
&& node
->next
->label
)
24509 const char *label
= node
->next
->label
;
24510 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
24512 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
24514 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
24515 if (strcmp (label
, loclabel
) == 0)
24517 have_multiple_function_sections
= true;
24525 /* Hook called after emitting a function into assembly.
24526 This does something only for the very first function emitted. */
24529 dwarf2out_end_function (unsigned int)
24531 if (in_first_function_p
24532 && !have_multiple_function_sections
24533 && first_loclabel_num_not_at_text_label
24535 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
24536 in_first_function_p
= false;
24537 maybe_at_text_label_p
= false;
24540 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
24541 front-ends register a translation unit even before dwarf2out_init is
24543 static tree main_translation_unit
= NULL_TREE
;
24545 /* Hook called by front-ends after they built their main translation unit.
24546 Associate comp_unit_die to UNIT. */
24549 dwarf2out_register_main_translation_unit (tree unit
)
24551 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
24552 && main_translation_unit
== NULL_TREE
);
24553 main_translation_unit
= unit
;
24554 /* If dwarf2out_init has not been called yet, it will perform the association
24555 itself looking at main_translation_unit. */
24556 if (decl_die_table
!= NULL
)
24557 equate_decl_number_to_die (unit
, comp_unit_die ());
24560 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
24563 push_dw_line_info_entry (dw_line_info_table
*table
,
24564 enum dw_line_info_opcode opcode
, unsigned int val
)
24566 dw_line_info_entry e
;
24569 vec_safe_push (table
->entries
, e
);
24572 /* Output a label to mark the beginning of a source code line entry
24573 and record information relating to this source line, in
24574 'line_info_table' for later output of the .debug_line section. */
24575 /* ??? The discriminator parameter ought to be unsigned. */
24578 dwarf2out_source_line (unsigned int line
, const char *filename
,
24579 int discriminator
, bool is_stmt
)
24581 unsigned int file_num
;
24582 dw_line_info_table
*table
;
24584 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
24587 /* The discriminator column was added in dwarf4. Simplify the below
24588 by simply removing it if we're not supposed to output it. */
24589 if (dwarf_version
< 4 && dwarf_strict
)
24592 table
= cur_line_info_table
;
24593 file_num
= maybe_emit_file (lookup_filename (filename
));
24595 /* ??? TODO: Elide duplicate line number entries. Traditionally,
24596 the debugger has used the second (possibly duplicate) line number
24597 at the beginning of the function to mark the end of the prologue.
24598 We could eliminate any other duplicates within the function. For
24599 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
24600 that second line number entry. */
24601 /* Recall that this end-of-prologue indication is *not* the same thing
24602 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
24603 to which the hook corresponds, follows the last insn that was
24604 emitted by gen_prologue. What we need is to precede the first insn
24605 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
24606 insn that corresponds to something the user wrote. These may be
24607 very different locations once scheduling is enabled. */
24609 if (0 && file_num
== table
->file_num
24610 && line
== table
->line_num
24611 && discriminator
== table
->discrim_num
24612 && is_stmt
== table
->is_stmt
)
24615 switch_to_section (current_function_section ());
24617 /* If requested, emit something human-readable. */
24618 if (flag_debug_asm
)
24619 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
24621 if (DWARF2_ASM_LINE_DEBUG_INFO
)
24623 /* Emit the .loc directive understood by GNU as. */
24624 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
24625 file_num, line, is_stmt, discriminator */
24626 fputs ("\t.loc ", asm_out_file
);
24627 fprint_ul (asm_out_file
, file_num
);
24628 putc (' ', asm_out_file
);
24629 fprint_ul (asm_out_file
, line
);
24630 putc (' ', asm_out_file
);
24631 putc ('0', asm_out_file
);
24633 if (is_stmt
!= table
->is_stmt
)
24635 fputs (" is_stmt ", asm_out_file
);
24636 putc (is_stmt
? '1' : '0', asm_out_file
);
24638 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
24640 gcc_assert (discriminator
> 0);
24641 fputs (" discriminator ", asm_out_file
);
24642 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
24644 putc ('\n', asm_out_file
);
24648 unsigned int label_num
= ++line_info_label_num
;
24650 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
24652 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
24653 if (file_num
!= table
->file_num
)
24654 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
24655 if (discriminator
!= table
->discrim_num
)
24656 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
24657 if (is_stmt
!= table
->is_stmt
)
24658 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
24659 push_dw_line_info_entry (table
, LI_set_line
, line
);
24662 table
->file_num
= file_num
;
24663 table
->line_num
= line
;
24664 table
->discrim_num
= discriminator
;
24665 table
->is_stmt
= is_stmt
;
24666 table
->in_use
= true;
24669 /* Record the beginning of a new source file. */
24672 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
24674 if (flag_eliminate_dwarf2_dups
)
24676 /* Record the beginning of the file for break_out_includes. */
24677 dw_die_ref bincl_die
;
24679 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
24680 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
24683 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
24686 e
.code
= DW_MACINFO_start_file
;
24688 e
.info
= ggc_strdup (filename
);
24689 vec_safe_push (macinfo_table
, e
);
24693 /* Record the end of a source file. */
24696 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
24698 if (flag_eliminate_dwarf2_dups
)
24699 /* Record the end of the file for break_out_includes. */
24700 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
24702 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
24705 e
.code
= DW_MACINFO_end_file
;
24708 vec_safe_push (macinfo_table
, e
);
24712 /* Called from debug_define in toplev.c. The `buffer' parameter contains
24713 the tail part of the directive line, i.e. the part which is past the
24714 initial whitespace, #, whitespace, directive-name, whitespace part. */
24717 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
24718 const char *buffer ATTRIBUTE_UNUSED
)
24720 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
24723 /* Insert a dummy first entry to be able to optimize the whole
24724 predefined macro block using DW_MACRO_GNU_transparent_include. */
24725 if (macinfo_table
->is_empty () && lineno
<= 1)
24730 vec_safe_push (macinfo_table
, e
);
24732 e
.code
= DW_MACINFO_define
;
24734 e
.info
= ggc_strdup (buffer
);
24735 vec_safe_push (macinfo_table
, e
);
24739 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
24740 the tail part of the directive line, i.e. the part which is past the
24741 initial whitespace, #, whitespace, directive-name, whitespace part. */
24744 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
24745 const char *buffer ATTRIBUTE_UNUSED
)
24747 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
24750 /* Insert a dummy first entry to be able to optimize the whole
24751 predefined macro block using DW_MACRO_GNU_transparent_include. */
24752 if (macinfo_table
->is_empty () && lineno
<= 1)
24757 vec_safe_push (macinfo_table
, e
);
24759 e
.code
= DW_MACINFO_undef
;
24761 e
.info
= ggc_strdup (buffer
);
24762 vec_safe_push (macinfo_table
, e
);
24766 /* Helpers to manipulate hash table of CUs. */
24768 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
24770 static inline hashval_t
hash (const macinfo_entry
*);
24771 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
24775 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
24777 return htab_hash_string (entry
->info
);
24781 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
24782 const macinfo_entry
*entry2
)
24784 return !strcmp (entry1
->info
, entry2
->info
);
24787 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
24789 /* Output a single .debug_macinfo entry. */
24792 output_macinfo_op (macinfo_entry
*ref
)
24796 struct indirect_string_node
*node
;
24797 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
24798 struct dwarf_file_data
*fd
;
24802 case DW_MACINFO_start_file
:
24803 fd
= lookup_filename (ref
->info
);
24804 file_num
= maybe_emit_file (fd
);
24805 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
24806 dw2_asm_output_data_uleb128 (ref
->lineno
,
24807 "Included from line number %lu",
24808 (unsigned long) ref
->lineno
);
24809 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
24811 case DW_MACINFO_end_file
:
24812 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
24814 case DW_MACINFO_define
:
24815 case DW_MACINFO_undef
:
24816 len
= strlen (ref
->info
) + 1;
24818 && len
> DWARF_OFFSET_SIZE
24819 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
24820 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
24822 ref
->code
= ref
->code
== DW_MACINFO_define
24823 ? DW_MACRO_GNU_define_indirect
24824 : DW_MACRO_GNU_undef_indirect
;
24825 output_macinfo_op (ref
);
24828 dw2_asm_output_data (1, ref
->code
,
24829 ref
->code
== DW_MACINFO_define
24830 ? "Define macro" : "Undefine macro");
24831 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
24832 (unsigned long) ref
->lineno
);
24833 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
24835 case DW_MACRO_GNU_define_indirect
:
24836 case DW_MACRO_GNU_undef_indirect
:
24837 node
= find_AT_string (ref
->info
);
24839 && ((node
->form
== DW_FORM_strp
)
24840 || (node
->form
== DW_FORM_GNU_str_index
)));
24841 dw2_asm_output_data (1, ref
->code
,
24842 ref
->code
== DW_MACRO_GNU_define_indirect
24843 ? "Define macro indirect"
24844 : "Undefine macro indirect");
24845 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
24846 (unsigned long) ref
->lineno
);
24847 if (node
->form
== DW_FORM_strp
)
24848 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
24849 debug_str_section
, "The macro: \"%s\"",
24852 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
24855 case DW_MACRO_GNU_transparent_include
:
24856 dw2_asm_output_data (1, ref
->code
, "Transparent include");
24857 ASM_GENERATE_INTERNAL_LABEL (label
,
24858 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
24859 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
24862 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
24863 ASM_COMMENT_START
, (unsigned long) ref
->code
);
24868 /* Attempt to make a sequence of define/undef macinfo ops shareable with
24869 other compilation unit .debug_macinfo sections. IDX is the first
24870 index of a define/undef, return the number of ops that should be
24871 emitted in a comdat .debug_macinfo section and emit
24872 a DW_MACRO_GNU_transparent_include entry referencing it.
24873 If the define/undef entry should be emitted normally, return 0. */
24876 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
24877 macinfo_hash_type
**macinfo_htab
)
24879 macinfo_entry
*first
, *second
, *cur
, *inc
;
24880 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
24881 unsigned char checksum
[16];
24882 struct md5_ctx ctx
;
24883 char *grp_name
, *tail
;
24885 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
24886 macinfo_entry
**slot
;
24888 first
= &(*macinfo_table
)[idx
];
24889 second
= &(*macinfo_table
)[idx
+ 1];
24891 /* Optimize only if there are at least two consecutive define/undef ops,
24892 and either all of them are before first DW_MACINFO_start_file
24893 with lineno {0,1} (i.e. predefined macro block), or all of them are
24894 in some included header file. */
24895 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
24897 if (vec_safe_is_empty (files
))
24899 if (first
->lineno
> 1 || second
->lineno
> 1)
24902 else if (first
->lineno
== 0)
24905 /* Find the last define/undef entry that can be grouped together
24906 with first and at the same time compute md5 checksum of their
24907 codes, linenumbers and strings. */
24908 md5_init_ctx (&ctx
);
24909 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
24910 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
24912 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
24916 unsigned char code
= cur
->code
;
24917 md5_process_bytes (&code
, 1, &ctx
);
24918 checksum_uleb128 (cur
->lineno
, &ctx
);
24919 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
24921 md5_finish_ctx (&ctx
, checksum
);
24924 /* From the containing include filename (if any) pick up just
24925 usable characters from its basename. */
24926 if (vec_safe_is_empty (files
))
24929 base
= lbasename (files
->last ().info
);
24930 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
24931 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
24932 encoded_filename_len
++;
24933 /* Count . at the end. */
24934 if (encoded_filename_len
)
24935 encoded_filename_len
++;
24937 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
24938 linebuf_len
= strlen (linebuf
);
24940 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
24941 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
24943 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
24944 tail
= grp_name
+ 4;
24945 if (encoded_filename_len
)
24947 for (i
= 0; base
[i
]; i
++)
24948 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
24952 memcpy (tail
, linebuf
, linebuf_len
);
24953 tail
+= linebuf_len
;
24955 for (i
= 0; i
< 16; i
++)
24956 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
24958 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
24959 in the empty vector entry before the first define/undef. */
24960 inc
= &(*macinfo_table
)[idx
- 1];
24961 inc
->code
= DW_MACRO_GNU_transparent_include
;
24963 inc
->info
= ggc_strdup (grp_name
);
24964 if (!*macinfo_htab
)
24965 *macinfo_htab
= new macinfo_hash_type (10);
24966 /* Avoid emitting duplicates. */
24967 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
24972 /* If such an entry has been used before, just emit
24973 a DW_MACRO_GNU_transparent_include op. */
24975 output_macinfo_op (inc
);
24976 /* And clear all macinfo_entry in the range to avoid emitting them
24977 in the second pass. */
24978 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
24987 inc
->lineno
= (*macinfo_htab
)->elements ();
24988 output_macinfo_op (inc
);
24993 /* Save any strings needed by the macinfo table in the debug str
24994 table. All strings must be collected into the table by the time
24995 index_string is called. */
24998 save_macinfo_strings (void)
25002 macinfo_entry
*ref
;
25004 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
25008 /* Match the logic in output_macinfo_op to decide on
25009 indirect strings. */
25010 case DW_MACINFO_define
:
25011 case DW_MACINFO_undef
:
25012 len
= strlen (ref
->info
) + 1;
25014 && len
> DWARF_OFFSET_SIZE
25015 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
25016 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
25017 set_indirect_string (find_AT_string (ref
->info
));
25019 case DW_MACRO_GNU_define_indirect
:
25020 case DW_MACRO_GNU_undef_indirect
:
25021 set_indirect_string (find_AT_string (ref
->info
));
25029 /* Output macinfo section(s). */
25032 output_macinfo (void)
25035 unsigned long length
= vec_safe_length (macinfo_table
);
25036 macinfo_entry
*ref
;
25037 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
25038 macinfo_hash_type
*macinfo_htab
= NULL
;
25043 /* output_macinfo* uses these interchangeably. */
25044 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
25045 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
25046 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
25047 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
25049 /* For .debug_macro emit the section header. */
25052 dw2_asm_output_data (2, 4, "DWARF macro version number");
25053 if (DWARF_OFFSET_SIZE
== 8)
25054 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
25056 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
25057 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
25058 (!dwarf_split_debug_info
? debug_line_section_label
25059 : debug_skeleton_line_section_label
),
25060 debug_line_section
, NULL
);
25063 /* In the first loop, it emits the primary .debug_macinfo section
25064 and after each emitted op the macinfo_entry is cleared.
25065 If a longer range of define/undef ops can be optimized using
25066 DW_MACRO_GNU_transparent_include, the
25067 DW_MACRO_GNU_transparent_include op is emitted and kept in
25068 the vector before the first define/undef in the range and the
25069 whole range of define/undef ops is not emitted and kept. */
25070 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
25074 case DW_MACINFO_start_file
:
25075 vec_safe_push (files
, *ref
);
25077 case DW_MACINFO_end_file
:
25078 if (!vec_safe_is_empty (files
))
25081 case DW_MACINFO_define
:
25082 case DW_MACINFO_undef
:
25084 && HAVE_COMDAT_GROUP
25085 && vec_safe_length (files
) != 1
25088 && (*macinfo_table
)[i
- 1].code
== 0)
25090 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
25099 /* A dummy entry may be inserted at the beginning to be able
25100 to optimize the whole block of predefined macros. */
25106 output_macinfo_op (ref
);
25114 delete macinfo_htab
;
25115 macinfo_htab
= NULL
;
25117 /* If any DW_MACRO_GNU_transparent_include were used, on those
25118 DW_MACRO_GNU_transparent_include entries terminate the
25119 current chain and switch to a new comdat .debug_macinfo
25120 section and emit the define/undef entries within it. */
25121 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
25126 case DW_MACRO_GNU_transparent_include
:
25128 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
25129 tree comdat_key
= get_identifier (ref
->info
);
25130 /* Terminate the previous .debug_macinfo section. */
25131 dw2_asm_output_data (1, 0, "End compilation unit");
25132 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
25134 | SECTION_LINKONCE
,
25136 ASM_GENERATE_INTERNAL_LABEL (label
,
25137 DEBUG_MACRO_SECTION_LABEL
,
25139 ASM_OUTPUT_LABEL (asm_out_file
, label
);
25142 dw2_asm_output_data (2, 4, "DWARF macro version number");
25143 if (DWARF_OFFSET_SIZE
== 8)
25144 dw2_asm_output_data (1, 1, "Flags: 64-bit");
25146 dw2_asm_output_data (1, 0, "Flags: 32-bit");
25149 case DW_MACINFO_define
:
25150 case DW_MACINFO_undef
:
25151 output_macinfo_op (ref
);
25156 gcc_unreachable ();
25160 /* Set up for Dwarf output at the start of compilation. */
25163 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
25165 /* This option is currently broken, see (PR53118 and PR46102). */
25166 if (flag_eliminate_dwarf2_dups
25167 && strstr (lang_hooks
.name
, "C++"))
25169 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
25170 flag_eliminate_dwarf2_dups
= 0;
25173 /* Allocate the file_table. */
25174 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
25176 #ifndef DWARF2_LINENO_DEBUGGING_INFO
25177 /* Allocate the decl_die_table. */
25178 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
25180 /* Allocate the decl_loc_table. */
25181 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
25183 /* Allocate the cached_dw_loc_list_table. */
25184 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
25186 /* Allocate the initial hunk of the decl_scope_table. */
25187 vec_alloc (decl_scope_table
, 256);
25189 /* Allocate the initial hunk of the abbrev_die_table. */
25190 abbrev_die_table
= ggc_cleared_vec_alloc
<dw_die_ref
>
25191 (ABBREV_DIE_TABLE_INCREMENT
);
25192 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
25193 /* Zero-th entry is allocated, but unused. */
25194 abbrev_die_table_in_use
= 1;
25196 /* Allocate the dwarf_proc_stack_usage_map. */
25197 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
25199 /* Allocate the pubtypes and pubnames vectors. */
25200 vec_alloc (pubname_table
, 32);
25201 vec_alloc (pubtype_table
, 32);
25203 vec_alloc (incomplete_types
, 64);
25205 vec_alloc (used_rtx_array
, 32);
25207 if (!dwarf_split_debug_info
)
25209 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
25210 SECTION_DEBUG
, NULL
);
25211 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
25212 SECTION_DEBUG
, NULL
);
25213 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
25214 SECTION_DEBUG
, NULL
);
25218 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
25219 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
25220 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
25221 SECTION_DEBUG
| SECTION_EXCLUDE
,
25223 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
25224 SECTION_DEBUG
, NULL
);
25225 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
25226 SECTION_DEBUG
, NULL
);
25227 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
25228 SECTION_DEBUG
, NULL
);
25229 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
25230 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
25232 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
25233 the main .o, but the skeleton_line goes into the split off dwo. */
25234 debug_skeleton_line_section
25235 = get_section (DEBUG_DWO_LINE_SECTION
,
25236 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
25237 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
25238 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
25239 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
25240 SECTION_DEBUG
| SECTION_EXCLUDE
,
25242 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
25243 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
25244 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
25245 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
25246 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
25247 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
25249 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
25250 SECTION_DEBUG
, NULL
);
25251 debug_macinfo_section
= get_section (dwarf_strict
25252 ? DEBUG_MACINFO_SECTION
25253 : DEBUG_MACRO_SECTION
,
25254 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
25255 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
25256 SECTION_DEBUG
, NULL
);
25257 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
25258 SECTION_DEBUG
, NULL
);
25259 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
25260 SECTION_DEBUG
, NULL
);
25261 debug_str_section
= get_section (DEBUG_STR_SECTION
,
25262 DEBUG_STR_SECTION_FLAGS
, NULL
);
25263 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
25264 SECTION_DEBUG
, NULL
);
25265 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
25266 SECTION_DEBUG
, NULL
);
25268 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
25269 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
25270 DEBUG_ABBREV_SECTION_LABEL
, 0);
25271 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
25272 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
25273 COLD_TEXT_SECTION_LABEL
, 0);
25274 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
25276 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
25277 DEBUG_INFO_SECTION_LABEL
, 0);
25278 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
25279 DEBUG_LINE_SECTION_LABEL
, 0);
25280 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
25281 DEBUG_RANGES_SECTION_LABEL
, 0);
25282 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
25283 DEBUG_ADDR_SECTION_LABEL
, 0);
25284 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
25286 ? DEBUG_MACINFO_SECTION_LABEL
25287 : DEBUG_MACRO_SECTION_LABEL
, 0);
25288 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
25290 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
25291 vec_alloc (macinfo_table
, 64);
25293 switch_to_section (text_section
);
25294 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
25297 /* Make sure the line number table for .text always exists. */
25298 text_section_line_info
= new_line_info_table ();
25299 text_section_line_info
->end_label
= text_end_label
;
25301 #ifdef DWARF2_LINENO_DEBUGGING_INFO
25302 cur_line_info_table
= text_section_line_info
;
25305 /* If front-ends already registered a main translation unit but we were not
25306 ready to perform the association, do this now. */
25307 if (main_translation_unit
!= NULL_TREE
)
25308 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
25311 /* Called before compile () starts outputtting functions, variables
25312 and toplevel asms into assembly. */
25315 dwarf2out_assembly_start (void)
25317 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
25318 && dwarf2out_do_cfi_asm ()
25319 && (!(flag_unwind_tables
|| flag_exceptions
)
25320 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
25321 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
25324 /* A helper function for dwarf2out_finish called through
25325 htab_traverse. Assign a string its index. All strings must be
25326 collected into the table by the time index_string is called,
25327 because the indexing code relies on htab_traverse to traverse nodes
25328 in the same order for each run. */
25331 index_string (indirect_string_node
**h
, unsigned int *index
)
25333 indirect_string_node
*node
= *h
;
25335 find_string_form (node
);
25336 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
25338 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
25339 node
->index
= *index
;
25345 /* A helper function for output_indirect_strings called through
25346 htab_traverse. Output the offset to a string and update the
25350 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
25352 indirect_string_node
*node
= *h
;
25354 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
25356 /* Assert that this node has been assigned an index. */
25357 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
25358 && node
->index
!= NOT_INDEXED
);
25359 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
25360 "indexed string 0x%x: %s", node
->index
, node
->str
);
25361 *offset
+= strlen (node
->str
) + 1;
25366 /* A helper function for dwarf2out_finish called through
25367 htab_traverse. Output the indexed string. */
25370 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
25372 struct indirect_string_node
*node
= *h
;
25374 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
25376 /* Assert that the strings are output in the same order as their
25377 indexes were assigned. */
25378 gcc_assert (*cur_idx
== node
->index
);
25379 assemble_string (node
->str
, strlen (node
->str
) + 1);
25385 /* A helper function for dwarf2out_finish called through
25386 htab_traverse. Emit one queued .debug_str string. */
25389 output_indirect_string (indirect_string_node
**h
, void *)
25391 struct indirect_string_node
*node
= *h
;
25393 node
->form
= find_string_form (node
);
25394 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
25396 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
25397 assemble_string (node
->str
, strlen (node
->str
) + 1);
25403 /* Output the indexed string table. */
25406 output_indirect_strings (void)
25408 switch_to_section (debug_str_section
);
25409 if (!dwarf_split_debug_info
)
25410 debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
25413 unsigned int offset
= 0;
25414 unsigned int cur_idx
= 0;
25416 skeleton_debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
25418 switch_to_section (debug_str_offsets_section
);
25419 debug_str_hash
->traverse_noresize
25420 <unsigned int *, output_index_string_offset
> (&offset
);
25421 switch_to_section (debug_str_dwo_section
);
25422 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
25427 /* Callback for htab_traverse to assign an index to an entry in the
25428 table, and to write that entry to the .debug_addr section. */
25431 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
25433 addr_table_entry
*entry
= *slot
;
25435 if (entry
->refcount
== 0)
25437 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
25438 || entry
->index
== NOT_INDEXED
);
25442 gcc_assert (entry
->index
== *cur_index
);
25445 switch (entry
->kind
)
25448 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
25449 "0x%x", entry
->index
);
25451 case ate_kind_rtx_dtprel
:
25452 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
25453 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
25456 fputc ('\n', asm_out_file
);
25458 case ate_kind_label
:
25459 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
25460 "0x%x", entry
->index
);
25463 gcc_unreachable ();
25468 /* Produce the .debug_addr section. */
25471 output_addr_table (void)
25473 unsigned int index
= 0;
25474 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
25477 switch_to_section (debug_addr_section
);
25479 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
25482 #if ENABLE_ASSERT_CHECKING
25483 /* Verify that all marks are clear. */
25486 verify_marks_clear (dw_die_ref die
)
25490 gcc_assert (! die
->die_mark
);
25491 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
25493 #endif /* ENABLE_ASSERT_CHECKING */
25495 /* Clear the marks for a die and its children.
25496 Be cool if the mark isn't set. */
25499 prune_unmark_dies (dw_die_ref die
)
25505 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
25508 /* Given LOC that is referenced by a DIE we're marking as used, find all
25509 referenced DWARF procedures it references and mark them as used. */
25512 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
25514 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
25515 switch (loc
->dw_loc_opc
)
25519 case DW_OP_call_ref
:
25520 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
25527 /* Given DIE that we're marking as used, find any other dies
25528 it references as attributes and mark them as used. */
25531 prune_unused_types_walk_attribs (dw_die_ref die
)
25536 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25538 switch (AT_class (a
))
25540 /* Make sure DWARF procedures referenced by location descriptions will
25542 case dw_val_class_loc
:
25543 prune_unused_types_walk_loc_descr (AT_loc (a
));
25545 case dw_val_class_loc_list
:
25546 for (dw_loc_list_ref list
= AT_loc_list (a
);
25548 list
= list
->dw_loc_next
)
25549 prune_unused_types_walk_loc_descr (list
->expr
);
25552 case dw_val_class_die_ref
:
25553 /* A reference to another DIE.
25554 Make sure that it will get emitted.
25555 If it was broken out into a comdat group, don't follow it. */
25556 if (! AT_ref (a
)->comdat_type_p
25557 || a
->dw_attr
== DW_AT_specification
)
25558 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
25561 case dw_val_class_str
:
25562 /* Set the string's refcount to 0 so that prune_unused_types_mark
25563 accounts properly for it. */
25564 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
25573 /* Mark the generic parameters and arguments children DIEs of DIE. */
25576 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
25580 if (die
== NULL
|| die
->die_child
== NULL
)
25582 c
= die
->die_child
;
25585 if (is_template_parameter (c
))
25586 prune_unused_types_mark (c
, 1);
25588 } while (c
&& c
!= die
->die_child
);
25591 /* Mark DIE as being used. If DOKIDS is true, then walk down
25592 to DIE's children. */
25595 prune_unused_types_mark (dw_die_ref die
, int dokids
)
25599 if (die
->die_mark
== 0)
25601 /* We haven't done this node yet. Mark it as used. */
25603 /* If this is the DIE of a generic type instantiation,
25604 mark the children DIEs that describe its generic parms and
25606 prune_unused_types_mark_generic_parms_dies (die
);
25608 /* We also have to mark its parents as used.
25609 (But we don't want to mark our parent's kids due to this,
25610 unless it is a class.) */
25611 if (die
->die_parent
)
25612 prune_unused_types_mark (die
->die_parent
,
25613 class_scope_p (die
->die_parent
));
25615 /* Mark any referenced nodes. */
25616 prune_unused_types_walk_attribs (die
);
25618 /* If this node is a specification,
25619 also mark the definition, if it exists. */
25620 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
25621 prune_unused_types_mark (die
->die_definition
, 1);
25624 if (dokids
&& die
->die_mark
!= 2)
25626 /* We need to walk the children, but haven't done so yet.
25627 Remember that we've walked the kids. */
25630 /* If this is an array type, we need to make sure our
25631 kids get marked, even if they're types. If we're
25632 breaking out types into comdat sections, do this
25633 for all type definitions. */
25634 if (die
->die_tag
== DW_TAG_array_type
25635 || (use_debug_types
25636 && is_type_die (die
) && ! is_declaration_die (die
)))
25637 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
25639 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
25643 /* For local classes, look if any static member functions were emitted
25644 and if so, mark them. */
25647 prune_unused_types_walk_local_classes (dw_die_ref die
)
25651 if (die
->die_mark
== 2)
25654 switch (die
->die_tag
)
25656 case DW_TAG_structure_type
:
25657 case DW_TAG_union_type
:
25658 case DW_TAG_class_type
:
25661 case DW_TAG_subprogram
:
25662 if (!get_AT_flag (die
, DW_AT_declaration
)
25663 || die
->die_definition
!= NULL
)
25664 prune_unused_types_mark (die
, 1);
25671 /* Mark children. */
25672 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
25675 /* Walk the tree DIE and mark types that we actually use. */
25678 prune_unused_types_walk (dw_die_ref die
)
25682 /* Don't do anything if this node is already marked and
25683 children have been marked as well. */
25684 if (die
->die_mark
== 2)
25687 switch (die
->die_tag
)
25689 case DW_TAG_structure_type
:
25690 case DW_TAG_union_type
:
25691 case DW_TAG_class_type
:
25692 if (die
->die_perennial_p
)
25695 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
25696 if (c
->die_tag
== DW_TAG_subprogram
)
25699 /* Finding used static member functions inside of classes
25700 is needed just for local classes, because for other classes
25701 static member function DIEs with DW_AT_specification
25702 are emitted outside of the DW_TAG_*_type. If we ever change
25703 it, we'd need to call this even for non-local classes. */
25705 prune_unused_types_walk_local_classes (die
);
25707 /* It's a type node --- don't mark it. */
25710 case DW_TAG_const_type
:
25711 case DW_TAG_packed_type
:
25712 case DW_TAG_pointer_type
:
25713 case DW_TAG_reference_type
:
25714 case DW_TAG_rvalue_reference_type
:
25715 case DW_TAG_volatile_type
:
25716 case DW_TAG_typedef
:
25717 case DW_TAG_array_type
:
25718 case DW_TAG_interface_type
:
25719 case DW_TAG_friend
:
25720 case DW_TAG_enumeration_type
:
25721 case DW_TAG_subroutine_type
:
25722 case DW_TAG_string_type
:
25723 case DW_TAG_set_type
:
25724 case DW_TAG_subrange_type
:
25725 case DW_TAG_ptr_to_member_type
:
25726 case DW_TAG_file_type
:
25727 /* Type nodes are useful only when other DIEs reference them --- don't
25731 case DW_TAG_dwarf_procedure
:
25732 /* Likewise for DWARF procedures. */
25734 if (die
->die_perennial_p
)
25740 /* Mark everything else. */
25744 if (die
->die_mark
== 0)
25748 /* Now, mark any dies referenced from here. */
25749 prune_unused_types_walk_attribs (die
);
25754 /* Mark children. */
25755 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
25758 /* Increment the string counts on strings referred to from DIE's
25762 prune_unused_types_update_strings (dw_die_ref die
)
25767 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25768 if (AT_class (a
) == dw_val_class_str
)
25770 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
25772 /* Avoid unnecessarily putting strings that are used less than
25773 twice in the hash table. */
25775 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
25777 indirect_string_node
**slot
25778 = debug_str_hash
->find_slot_with_hash (s
->str
,
25779 htab_hash_string (s
->str
),
25781 gcc_assert (*slot
== NULL
);
25787 /* Remove from the tree DIE any dies that aren't marked. */
25790 prune_unused_types_prune (dw_die_ref die
)
25794 gcc_assert (die
->die_mark
);
25795 prune_unused_types_update_strings (die
);
25797 if (! die
->die_child
)
25800 c
= die
->die_child
;
25802 dw_die_ref prev
= c
;
25803 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
25804 if (c
== die
->die_child
)
25806 /* No marked children between 'prev' and the end of the list. */
25808 /* No marked children at all. */
25809 die
->die_child
= NULL
;
25812 prev
->die_sib
= c
->die_sib
;
25813 die
->die_child
= prev
;
25818 if (c
!= prev
->die_sib
)
25820 prune_unused_types_prune (c
);
25821 } while (c
!= die
->die_child
);
25824 /* Remove dies representing declarations that we never use. */
25827 prune_unused_types (void)
25830 limbo_die_node
*node
;
25831 comdat_type_node
*ctnode
;
25832 pubname_entry
*pub
;
25833 dw_die_ref base_type
;
25835 #if ENABLE_ASSERT_CHECKING
25836 /* All the marks should already be clear. */
25837 verify_marks_clear (comp_unit_die ());
25838 for (node
= limbo_die_list
; node
; node
= node
->next
)
25839 verify_marks_clear (node
->die
);
25840 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
25841 verify_marks_clear (ctnode
->root_die
);
25842 #endif /* ENABLE_ASSERT_CHECKING */
25844 /* Mark types that are used in global variables. */
25845 premark_types_used_by_global_vars ();
25847 /* Set the mark on nodes that are actually used. */
25848 prune_unused_types_walk (comp_unit_die ());
25849 for (node
= limbo_die_list
; node
; node
= node
->next
)
25850 prune_unused_types_walk (node
->die
);
25851 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
25853 prune_unused_types_walk (ctnode
->root_die
);
25854 prune_unused_types_mark (ctnode
->type_die
, 1);
25857 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
25858 are unusual in that they are pubnames that are the children of pubtypes.
25859 They should only be marked via their parent DW_TAG_enumeration_type die,
25860 not as roots in themselves. */
25861 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
25862 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
25863 prune_unused_types_mark (pub
->die
, 1);
25864 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
25865 prune_unused_types_mark (base_type
, 1);
25867 if (debug_str_hash
)
25868 debug_str_hash
->empty ();
25869 if (skeleton_debug_str_hash
)
25870 skeleton_debug_str_hash
->empty ();
25871 prune_unused_types_prune (comp_unit_die ());
25872 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
25875 if (!node
->die
->die_mark
)
25876 *pnode
= node
->next
;
25879 prune_unused_types_prune (node
->die
);
25880 pnode
= &node
->next
;
25883 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
25884 prune_unused_types_prune (ctnode
->root_die
);
25886 /* Leave the marks clear. */
25887 prune_unmark_dies (comp_unit_die ());
25888 for (node
= limbo_die_list
; node
; node
= node
->next
)
25889 prune_unmark_dies (node
->die
);
25890 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
25891 prune_unmark_dies (ctnode
->root_die
);
25894 /* Set the parameter to true if there are any relative pathnames in
25897 file_table_relative_p (dwarf_file_data
**slot
, bool *p
)
25899 struct dwarf_file_data
*d
= *slot
;
25900 if (!IS_ABSOLUTE_PATH (d
->filename
))
25908 /* Helpers to manipulate hash table of comdat type units. */
25910 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
25912 static inline hashval_t
hash (const comdat_type_node
*);
25913 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
25917 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
25920 memcpy (&h
, type_node
->signature
, sizeof (h
));
25925 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
25926 const comdat_type_node
*type_node_2
)
25928 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
25929 DWARF_TYPE_SIGNATURE_SIZE
));
25932 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
25933 to the location it would have been added, should we know its
25934 DECL_ASSEMBLER_NAME when we added other attributes. This will
25935 probably improve compactness of debug info, removing equivalent
25936 abbrevs, and hide any differences caused by deferring the
25937 computation of the assembler name, triggered by e.g. PCH. */
25940 move_linkage_attr (dw_die_ref die
)
25942 unsigned ix
= vec_safe_length (die
->die_attr
);
25943 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
25945 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
25946 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
25950 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
25952 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
25956 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
25958 die
->die_attr
->pop ();
25959 die
->die_attr
->quick_insert (ix
, linkage
);
25963 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
25964 referenced from typed stack ops and count how often they are used. */
25967 mark_base_types (dw_loc_descr_ref loc
)
25969 dw_die_ref base_type
= NULL
;
25971 for (; loc
; loc
= loc
->dw_loc_next
)
25973 switch (loc
->dw_loc_opc
)
25975 case DW_OP_GNU_regval_type
:
25976 case DW_OP_GNU_deref_type
:
25977 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
25979 case DW_OP_GNU_convert
:
25980 case DW_OP_GNU_reinterpret
:
25981 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
25984 case DW_OP_GNU_const_type
:
25985 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
25987 case DW_OP_GNU_entry_value
:
25988 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
25993 gcc_assert (base_type
->die_parent
== comp_unit_die ());
25994 if (base_type
->die_mark
)
25995 base_type
->die_mark
++;
25998 base_types
.safe_push (base_type
);
25999 base_type
->die_mark
= 1;
26004 /* Comparison function for sorting marked base types. */
26007 base_type_cmp (const void *x
, const void *y
)
26009 dw_die_ref dx
= *(const dw_die_ref
*) x
;
26010 dw_die_ref dy
= *(const dw_die_ref
*) y
;
26011 unsigned int byte_size1
, byte_size2
;
26012 unsigned int encoding1
, encoding2
;
26013 if (dx
->die_mark
> dy
->die_mark
)
26015 if (dx
->die_mark
< dy
->die_mark
)
26017 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
26018 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
26019 if (byte_size1
< byte_size2
)
26021 if (byte_size1
> byte_size2
)
26023 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
26024 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
26025 if (encoding1
< encoding2
)
26027 if (encoding1
> encoding2
)
26032 /* Move base types marked by mark_base_types as early as possible
26033 in the CU, sorted by decreasing usage count both to make the
26034 uleb128 references as small as possible and to make sure they
26035 will have die_offset already computed by calc_die_sizes when
26036 sizes of typed stack loc ops is computed. */
26039 move_marked_base_types (void)
26042 dw_die_ref base_type
, die
, c
;
26044 if (base_types
.is_empty ())
26047 /* Sort by decreasing usage count, they will be added again in that
26049 base_types
.qsort (base_type_cmp
);
26050 die
= comp_unit_die ();
26051 c
= die
->die_child
;
26054 dw_die_ref prev
= c
;
26056 while (c
->die_mark
)
26058 remove_child_with_prev (c
, prev
);
26059 /* As base types got marked, there must be at least
26060 one node other than DW_TAG_base_type. */
26061 gcc_assert (c
!= c
->die_sib
);
26065 while (c
!= die
->die_child
);
26066 gcc_assert (die
->die_child
);
26067 c
= die
->die_child
;
26068 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
26070 base_type
->die_mark
= 0;
26071 base_type
->die_sib
= c
->die_sib
;
26072 c
->die_sib
= base_type
;
26077 /* Helper function for resolve_addr, attempt to resolve
26078 one CONST_STRING, return true if successful. Similarly verify that
26079 SYMBOL_REFs refer to variables emitted in the current CU. */
26082 resolve_one_addr (rtx
*addr
)
26086 if (GET_CODE (rtl
) == CONST_STRING
)
26088 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
26089 tree t
= build_string (len
, XSTR (rtl
, 0));
26090 tree tlen
= size_int (len
- 1);
26092 = build_array_type (char_type_node
, build_index_type (tlen
));
26093 rtl
= lookup_constant_def (t
);
26094 if (!rtl
|| !MEM_P (rtl
))
26096 rtl
= XEXP (rtl
, 0);
26097 if (GET_CODE (rtl
) == SYMBOL_REF
26098 && SYMBOL_REF_DECL (rtl
)
26099 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
26101 vec_safe_push (used_rtx_array
, rtl
);
26106 if (GET_CODE (rtl
) == SYMBOL_REF
26107 && SYMBOL_REF_DECL (rtl
))
26109 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
26111 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
26114 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
26118 if (GET_CODE (rtl
) == CONST
)
26120 subrtx_ptr_iterator::array_type array
;
26121 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
26122 if (!resolve_one_addr (*iter
))
26129 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
26130 if possible, and create DW_TAG_dwarf_procedure that can be referenced
26131 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
26134 string_cst_pool_decl (tree t
)
26136 rtx rtl
= output_constant_def (t
, 1);
26137 unsigned char *array
;
26138 dw_loc_descr_ref l
;
26143 if (!rtl
|| !MEM_P (rtl
))
26145 rtl
= XEXP (rtl
, 0);
26146 if (GET_CODE (rtl
) != SYMBOL_REF
26147 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
26150 decl
= SYMBOL_REF_DECL (rtl
);
26151 if (!lookup_decl_die (decl
))
26153 len
= TREE_STRING_LENGTH (t
);
26154 vec_safe_push (used_rtx_array
, rtl
);
26155 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
26156 array
= ggc_vec_alloc
<unsigned char> (len
);
26157 memcpy (array
, TREE_STRING_POINTER (t
), len
);
26158 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
26159 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
26160 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
26161 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
26162 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
26163 add_AT_loc (ref
, DW_AT_location
, l
);
26164 equate_decl_number_to_die (decl
, ref
);
26169 /* Helper function of resolve_addr_in_expr. LOC is
26170 a DW_OP_addr followed by DW_OP_stack_value, either at the start
26171 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
26172 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
26173 with DW_OP_GNU_implicit_pointer if possible
26174 and return true, if unsuccessful, return false. */
26177 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
26179 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
26180 HOST_WIDE_INT offset
= 0;
26181 dw_die_ref ref
= NULL
;
26184 if (GET_CODE (rtl
) == CONST
26185 && GET_CODE (XEXP (rtl
, 0)) == PLUS
26186 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
26188 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
26189 rtl
= XEXP (XEXP (rtl
, 0), 0);
26191 if (GET_CODE (rtl
) == CONST_STRING
)
26193 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
26194 tree t
= build_string (len
, XSTR (rtl
, 0));
26195 tree tlen
= size_int (len
- 1);
26198 = build_array_type (char_type_node
, build_index_type (tlen
));
26199 rtl
= string_cst_pool_decl (t
);
26203 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
26205 decl
= SYMBOL_REF_DECL (rtl
);
26206 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
26208 ref
= lookup_decl_die (decl
);
26209 if (ref
&& (get_AT (ref
, DW_AT_location
)
26210 || get_AT (ref
, DW_AT_const_value
)))
26212 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
26213 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
26214 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
26215 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
26216 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
26217 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
26218 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
26226 /* Helper function for resolve_addr, handle one location
26227 expression, return false if at least one CONST_STRING or SYMBOL_REF in
26228 the location list couldn't be resolved. */
26231 resolve_addr_in_expr (dw_loc_descr_ref loc
)
26233 dw_loc_descr_ref keep
= NULL
;
26234 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
26235 switch (loc
->dw_loc_opc
)
26238 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
26241 || prev
->dw_loc_opc
== DW_OP_piece
26242 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
26243 && loc
->dw_loc_next
26244 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
26246 && optimize_one_addr_into_implicit_ptr (loc
))
26251 case DW_OP_GNU_addr_index
:
26252 case DW_OP_GNU_const_index
:
26253 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
26254 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
26256 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
26257 if (!resolve_one_addr (&rtl
))
26259 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
26260 loc
->dw_loc_oprnd1
.val_entry
=
26261 add_addr_table_entry (rtl
, ate_kind_rtx
);
26264 case DW_OP_const4u
:
26265 case DW_OP_const8u
:
26267 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
26270 case DW_OP_plus_uconst
:
26271 if (size_of_loc_descr (loc
)
26272 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
26274 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
26276 dw_loc_descr_ref repl
26277 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
26278 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
26279 add_loc_descr (&repl
, loc
->dw_loc_next
);
26283 case DW_OP_implicit_value
:
26284 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
26285 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
26288 case DW_OP_GNU_implicit_pointer
:
26289 case DW_OP_GNU_parameter_ref
:
26290 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
26293 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
26296 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
26297 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
26298 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
26301 case DW_OP_GNU_const_type
:
26302 case DW_OP_GNU_regval_type
:
26303 case DW_OP_GNU_deref_type
:
26304 case DW_OP_GNU_convert
:
26305 case DW_OP_GNU_reinterpret
:
26306 while (loc
->dw_loc_next
26307 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
26309 dw_die_ref base1
, base2
;
26310 unsigned enc1
, enc2
, size1
, size2
;
26311 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
26312 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
26313 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
26314 else if (loc
->dw_loc_oprnd1
.val_class
26315 == dw_val_class_unsigned_const
)
26318 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
26319 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
26320 == dw_val_class_unsigned_const
)
26322 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
26323 gcc_assert (base1
->die_tag
== DW_TAG_base_type
26324 && base2
->die_tag
== DW_TAG_base_type
);
26325 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
26326 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
26327 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
26328 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
26330 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
26331 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
26335 /* Optimize away next DW_OP_GNU_convert after
26336 adjusting LOC's base type die reference. */
26337 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
26338 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
26339 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
26341 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
26342 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
26345 /* Don't change integer DW_OP_GNU_convert after e.g. floating
26346 point typed stack entry. */
26347 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
26348 keep
= loc
->dw_loc_next
;
26358 /* Helper function of resolve_addr. DIE had DW_AT_location of
26359 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
26360 and DW_OP_addr couldn't be resolved. resolve_addr has already
26361 removed the DW_AT_location attribute. This function attempts to
26362 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
26363 to it or DW_AT_const_value attribute, if possible. */
26366 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
26368 if (TREE_CODE (decl
) != VAR_DECL
26369 || lookup_decl_die (decl
) != die
26370 || DECL_EXTERNAL (decl
)
26371 || !TREE_STATIC (decl
)
26372 || DECL_INITIAL (decl
) == NULL_TREE
26373 || DECL_P (DECL_INITIAL (decl
))
26374 || get_AT (die
, DW_AT_const_value
))
26377 tree init
= DECL_INITIAL (decl
);
26378 HOST_WIDE_INT offset
= 0;
26379 /* For variables that have been optimized away and thus
26380 don't have a memory location, see if we can emit
26381 DW_AT_const_value instead. */
26382 if (tree_add_const_value_attribute (die
, init
))
26386 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
26387 and ADDR_EXPR refers to a decl that has DW_AT_location or
26388 DW_AT_const_value (but isn't addressable, otherwise
26389 resolving the original DW_OP_addr wouldn't fail), see if
26390 we can add DW_OP_GNU_implicit_pointer. */
26392 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
26393 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
26395 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
26396 init
= TREE_OPERAND (init
, 0);
26399 if (TREE_CODE (init
) != ADDR_EXPR
)
26401 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
26402 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
26403 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
26404 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
26405 && TREE_OPERAND (init
, 0) != decl
))
26408 dw_loc_descr_ref l
;
26410 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
26412 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
26415 decl
= SYMBOL_REF_DECL (rtl
);
26418 decl
= TREE_OPERAND (init
, 0);
26419 ref
= lookup_decl_die (decl
);
26421 || (!get_AT (ref
, DW_AT_location
)
26422 && !get_AT (ref
, DW_AT_const_value
)))
26424 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
26425 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
26426 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
26427 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
26428 add_AT_loc (die
, DW_AT_location
, l
);
26432 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
26433 an address in .rodata section if the string literal is emitted there,
26434 or remove the containing location list or replace DW_AT_const_value
26435 with DW_AT_location and empty location expression, if it isn't found
26436 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
26437 to something that has been emitted in the current CU. */
26440 resolve_addr (dw_die_ref die
)
26444 dw_loc_list_ref
*curr
, *start
, loc
;
26447 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
26448 switch (AT_class (a
))
26450 case dw_val_class_loc_list
:
26451 start
= curr
= AT_loc_list_ptr (a
);
26454 /* The same list can be referenced more than once. See if we have
26455 already recorded the result from a previous pass. */
26457 *curr
= loc
->dw_loc_next
;
26458 else if (!loc
->resolved_addr
)
26460 /* As things stand, we do not expect or allow one die to
26461 reference a suffix of another die's location list chain.
26462 References must be identical or completely separate.
26463 There is therefore no need to cache the result of this
26464 pass on any list other than the first; doing so
26465 would lead to unnecessary writes. */
26468 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
26469 if (!resolve_addr_in_expr ((*curr
)->expr
))
26471 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
26472 dw_loc_descr_ref l
= (*curr
)->expr
;
26474 if (next
&& (*curr
)->ll_symbol
)
26476 gcc_assert (!next
->ll_symbol
);
26477 next
->ll_symbol
= (*curr
)->ll_symbol
;
26479 if (dwarf_split_debug_info
)
26480 remove_loc_list_addr_table_entries (l
);
26485 mark_base_types ((*curr
)->expr
);
26486 curr
= &(*curr
)->dw_loc_next
;
26490 loc
->resolved_addr
= 1;
26494 loc
->dw_loc_next
= *start
;
26499 remove_AT (die
, a
->dw_attr
);
26503 case dw_val_class_loc
:
26505 dw_loc_descr_ref l
= AT_loc (a
);
26506 /* For -gdwarf-2 don't attempt to optimize
26507 DW_AT_data_member_location containing
26508 DW_OP_plus_uconst - older consumers might
26509 rely on it being that op instead of a more complex,
26510 but shorter, location description. */
26511 if ((dwarf_version
> 2
26512 || a
->dw_attr
!= DW_AT_data_member_location
26514 || l
->dw_loc_opc
!= DW_OP_plus_uconst
26515 || l
->dw_loc_next
!= NULL
)
26516 && !resolve_addr_in_expr (l
))
26518 if (dwarf_split_debug_info
)
26519 remove_loc_list_addr_table_entries (l
);
26521 && l
->dw_loc_next
== NULL
26522 && l
->dw_loc_opc
== DW_OP_addr
26523 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
26524 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
26525 && a
->dw_attr
== DW_AT_location
)
26527 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
26528 remove_AT (die
, a
->dw_attr
);
26530 optimize_location_into_implicit_ptr (die
, decl
);
26533 remove_AT (die
, a
->dw_attr
);
26537 mark_base_types (l
);
26540 case dw_val_class_addr
:
26541 if (a
->dw_attr
== DW_AT_const_value
26542 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
26544 if (AT_index (a
) != NOT_INDEXED
)
26545 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
26546 remove_AT (die
, a
->dw_attr
);
26549 if (die
->die_tag
== DW_TAG_GNU_call_site
26550 && a
->dw_attr
== DW_AT_abstract_origin
)
26552 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
26553 dw_die_ref tdie
= lookup_decl_die (tdecl
);
26556 && DECL_EXTERNAL (tdecl
)
26557 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
26558 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
26560 /* Creating a full DIE for tdecl is overly expensive and
26561 at this point even wrong when in the LTO phase
26562 as it can end up generating new type DIEs we didn't
26563 output and thus optimize_external_refs will crash. */
26564 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
26565 add_AT_flag (tdie
, DW_AT_external
, 1);
26566 add_AT_flag (tdie
, DW_AT_declaration
, 1);
26567 add_linkage_attr (tdie
, tdecl
);
26568 add_name_and_src_coords_attributes (tdie
, tdecl
);
26569 equate_decl_number_to_die (tdecl
, tdie
);
26573 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
26574 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
26575 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
26579 if (AT_index (a
) != NOT_INDEXED
)
26580 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
26581 remove_AT (die
, a
->dw_attr
);
26590 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
26593 /* Helper routines for optimize_location_lists.
26594 This pass tries to share identical local lists in .debug_loc
26597 /* Iteratively hash operands of LOC opcode into HSTATE. */
26600 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
26602 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
26603 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
26605 switch (loc
->dw_loc_opc
)
26607 case DW_OP_const4u
:
26608 case DW_OP_const8u
:
26612 case DW_OP_const1u
:
26613 case DW_OP_const1s
:
26614 case DW_OP_const2u
:
26615 case DW_OP_const2s
:
26616 case DW_OP_const4s
:
26617 case DW_OP_const8s
:
26621 case DW_OP_plus_uconst
:
26657 case DW_OP_deref_size
:
26658 case DW_OP_xderef_size
:
26659 hstate
.add_object (val1
->v
.val_int
);
26666 gcc_assert (val1
->val_class
== dw_val_class_loc
);
26667 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
26668 hstate
.add_object (offset
);
26671 case DW_OP_implicit_value
:
26672 hstate
.add_object (val1
->v
.val_unsigned
);
26673 switch (val2
->val_class
)
26675 case dw_val_class_const
:
26676 hstate
.add_object (val2
->v
.val_int
);
26678 case dw_val_class_vec
:
26680 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
26681 unsigned int len
= val2
->v
.val_vec
.length
;
26683 hstate
.add_int (elt_size
);
26684 hstate
.add_int (len
);
26685 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
26688 case dw_val_class_const_double
:
26689 hstate
.add_object (val2
->v
.val_double
.low
);
26690 hstate
.add_object (val2
->v
.val_double
.high
);
26692 case dw_val_class_wide_int
:
26693 hstate
.add (val2
->v
.val_wide
->get_val (),
26694 get_full_len (*val2
->v
.val_wide
)
26695 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
26697 case dw_val_class_addr
:
26698 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
26701 gcc_unreachable ();
26705 case DW_OP_bit_piece
:
26706 hstate
.add_object (val1
->v
.val_int
);
26707 hstate
.add_object (val2
->v
.val_int
);
26713 unsigned char dtprel
= 0xd1;
26714 hstate
.add_object (dtprel
);
26716 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
26718 case DW_OP_GNU_addr_index
:
26719 case DW_OP_GNU_const_index
:
26723 unsigned char dtprel
= 0xd1;
26724 hstate
.add_object (dtprel
);
26726 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
26729 case DW_OP_GNU_implicit_pointer
:
26730 hstate
.add_int (val2
->v
.val_int
);
26732 case DW_OP_GNU_entry_value
:
26733 hstate
.add_object (val1
->v
.val_loc
);
26735 case DW_OP_GNU_regval_type
:
26736 case DW_OP_GNU_deref_type
:
26738 unsigned int byte_size
26739 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
26740 unsigned int encoding
26741 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
26742 hstate
.add_object (val1
->v
.val_int
);
26743 hstate
.add_object (byte_size
);
26744 hstate
.add_object (encoding
);
26747 case DW_OP_GNU_convert
:
26748 case DW_OP_GNU_reinterpret
:
26749 if (val1
->val_class
== dw_val_class_unsigned_const
)
26751 hstate
.add_object (val1
->v
.val_unsigned
);
26755 case DW_OP_GNU_const_type
:
26757 unsigned int byte_size
26758 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
26759 unsigned int encoding
26760 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
26761 hstate
.add_object (byte_size
);
26762 hstate
.add_object (encoding
);
26763 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
26765 hstate
.add_object (val2
->val_class
);
26766 switch (val2
->val_class
)
26768 case dw_val_class_const
:
26769 hstate
.add_object (val2
->v
.val_int
);
26771 case dw_val_class_vec
:
26773 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
26774 unsigned int len
= val2
->v
.val_vec
.length
;
26776 hstate
.add_object (elt_size
);
26777 hstate
.add_object (len
);
26778 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
26781 case dw_val_class_const_double
:
26782 hstate
.add_object (val2
->v
.val_double
.low
);
26783 hstate
.add_object (val2
->v
.val_double
.high
);
26785 case dw_val_class_wide_int
:
26786 hstate
.add (val2
->v
.val_wide
->get_val (),
26787 get_full_len (*val2
->v
.val_wide
)
26788 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
26791 gcc_unreachable ();
26797 /* Other codes have no operands. */
26802 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
26805 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
26807 dw_loc_descr_ref l
;
26808 bool sizes_computed
= false;
26809 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
26810 size_of_locs (loc
);
26812 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
26814 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
26815 hstate
.add_object (opc
);
26816 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
26818 size_of_locs (loc
);
26819 sizes_computed
= true;
26821 hash_loc_operands (l
, hstate
);
26825 /* Compute hash of the whole location list LIST_HEAD. */
26828 hash_loc_list (dw_loc_list_ref list_head
)
26830 dw_loc_list_ref curr
= list_head
;
26831 inchash::hash hstate
;
26833 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
26835 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
26836 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
26838 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
26839 hash_locs (curr
->expr
, hstate
);
26841 list_head
->hash
= hstate
.end ();
26844 /* Return true if X and Y opcodes have the same operands. */
26847 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
26849 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
26850 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
26851 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
26852 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
26854 switch (x
->dw_loc_opc
)
26856 case DW_OP_const4u
:
26857 case DW_OP_const8u
:
26861 case DW_OP_const1u
:
26862 case DW_OP_const1s
:
26863 case DW_OP_const2u
:
26864 case DW_OP_const2s
:
26865 case DW_OP_const4s
:
26866 case DW_OP_const8s
:
26870 case DW_OP_plus_uconst
:
26906 case DW_OP_deref_size
:
26907 case DW_OP_xderef_size
:
26908 return valx1
->v
.val_int
== valy1
->v
.val_int
;
26911 /* If splitting debug info, the use of DW_OP_GNU_addr_index
26912 can cause irrelevant differences in dw_loc_addr. */
26913 gcc_assert (valx1
->val_class
== dw_val_class_loc
26914 && valy1
->val_class
== dw_val_class_loc
26915 && (dwarf_split_debug_info
26916 || x
->dw_loc_addr
== y
->dw_loc_addr
));
26917 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
26918 case DW_OP_implicit_value
:
26919 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
26920 || valx2
->val_class
!= valy2
->val_class
)
26922 switch (valx2
->val_class
)
26924 case dw_val_class_const
:
26925 return valx2
->v
.val_int
== valy2
->v
.val_int
;
26926 case dw_val_class_vec
:
26927 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
26928 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
26929 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
26930 valx2
->v
.val_vec
.elt_size
26931 * valx2
->v
.val_vec
.length
) == 0;
26932 case dw_val_class_const_double
:
26933 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
26934 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
26935 case dw_val_class_wide_int
:
26936 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
26937 case dw_val_class_addr
:
26938 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
26940 gcc_unreachable ();
26943 case DW_OP_bit_piece
:
26944 return valx1
->v
.val_int
== valy1
->v
.val_int
26945 && valx2
->v
.val_int
== valy2
->v
.val_int
;
26948 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
26949 case DW_OP_GNU_addr_index
:
26950 case DW_OP_GNU_const_index
:
26952 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
26953 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
26954 return rtx_equal_p (ax1
, ay1
);
26956 case DW_OP_GNU_implicit_pointer
:
26957 return valx1
->val_class
== dw_val_class_die_ref
26958 && valx1
->val_class
== valy1
->val_class
26959 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
26960 && valx2
->v
.val_int
== valy2
->v
.val_int
;
26961 case DW_OP_GNU_entry_value
:
26962 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
26963 case DW_OP_GNU_const_type
:
26964 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
26965 || valx2
->val_class
!= valy2
->val_class
)
26967 switch (valx2
->val_class
)
26969 case dw_val_class_const
:
26970 return valx2
->v
.val_int
== valy2
->v
.val_int
;
26971 case dw_val_class_vec
:
26972 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
26973 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
26974 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
26975 valx2
->v
.val_vec
.elt_size
26976 * valx2
->v
.val_vec
.length
) == 0;
26977 case dw_val_class_const_double
:
26978 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
26979 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
26980 case dw_val_class_wide_int
:
26981 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
26983 gcc_unreachable ();
26985 case DW_OP_GNU_regval_type
:
26986 case DW_OP_GNU_deref_type
:
26987 return valx1
->v
.val_int
== valy1
->v
.val_int
26988 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
26989 case DW_OP_GNU_convert
:
26990 case DW_OP_GNU_reinterpret
:
26991 if (valx1
->val_class
!= valy1
->val_class
)
26993 if (valx1
->val_class
== dw_val_class_unsigned_const
)
26994 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
26995 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
26996 case DW_OP_GNU_parameter_ref
:
26997 return valx1
->val_class
== dw_val_class_die_ref
26998 && valx1
->val_class
== valy1
->val_class
26999 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
27001 /* Other codes have no operands. */
27006 /* Return true if DWARF location expressions X and Y are the same. */
27009 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
27011 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
27012 if (x
->dw_loc_opc
!= y
->dw_loc_opc
27013 || x
->dtprel
!= y
->dtprel
27014 || !compare_loc_operands (x
, y
))
27016 return x
== NULL
&& y
== NULL
;
27019 /* Hashtable helpers. */
27021 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
27023 static inline hashval_t
hash (const dw_loc_list_struct
*);
27024 static inline bool equal (const dw_loc_list_struct
*,
27025 const dw_loc_list_struct
*);
27028 /* Return precomputed hash of location list X. */
27031 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
27036 /* Return true if location lists A and B are the same. */
27039 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
27040 const dw_loc_list_struct
*b
)
27044 if (a
->hash
!= b
->hash
)
27046 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
27047 if (strcmp (a
->begin
, b
->begin
) != 0
27048 || strcmp (a
->end
, b
->end
) != 0
27049 || (a
->section
== NULL
) != (b
->section
== NULL
)
27050 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
27051 || !compare_locs (a
->expr
, b
->expr
))
27053 return a
== NULL
&& b
== NULL
;
27056 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
27059 /* Recursively optimize location lists referenced from DIE
27060 children and share them whenever possible. */
27063 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
27068 dw_loc_list_struct
**slot
;
27070 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27071 if (AT_class (a
) == dw_val_class_loc_list
)
27073 dw_loc_list_ref list
= AT_loc_list (a
);
27074 /* TODO: perform some optimizations here, before hashing
27075 it and storing into the hash table. */
27076 hash_loc_list (list
);
27077 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
27081 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
27084 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
27088 /* Recursively assign each location list a unique index into the debug_addr
27092 index_location_lists (dw_die_ref die
)
27098 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27099 if (AT_class (a
) == dw_val_class_loc_list
)
27101 dw_loc_list_ref list
= AT_loc_list (a
);
27102 dw_loc_list_ref curr
;
27103 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
27105 /* Don't index an entry that has already been indexed
27106 or won't be output. */
27107 if (curr
->begin_entry
!= NULL
27108 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
27112 = add_addr_table_entry (xstrdup (curr
->begin
),
27117 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
27120 /* Optimize location lists referenced from DIE
27121 children and share them whenever possible. */
27124 optimize_location_lists (dw_die_ref die
)
27126 loc_list_hash_type
htab (500);
27127 optimize_location_lists_1 (die
, &htab
);
27130 /* Traverse the limbo die list, and add parent/child links. The only
27131 dies without parents that should be here are concrete instances of
27132 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
27133 For concrete instances, we can get the parent die from the abstract
27137 flush_limbo_die_list (void)
27139 limbo_die_node
*node
, *next_node
;
27141 for (node
= limbo_die_list
; node
; node
= next_node
)
27143 dw_die_ref die
= node
->die
;
27144 next_node
= node
->next
;
27146 if (die
->die_parent
== NULL
)
27148 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
27150 if (origin
&& origin
->die_parent
)
27151 add_child_die (origin
->die_parent
, die
);
27152 else if (is_cu_die (die
))
27154 else if (seen_error ())
27155 /* It's OK to be confused by errors in the input. */
27156 add_child_die (comp_unit_die (), die
);
27159 /* In certain situations, the lexical block containing a
27160 nested function can be optimized away, which results
27161 in the nested function die being orphaned. Likewise
27162 with the return type of that nested function. Force
27163 this to be a child of the containing function.
27165 It may happen that even the containing function got fully
27166 inlined and optimized out. In that case we are lost and
27167 assign the empty child. This should not be big issue as
27168 the function is likely unreachable too. */
27169 gcc_assert (node
->created_for
);
27171 if (DECL_P (node
->created_for
))
27172 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
27173 else if (TYPE_P (node
->created_for
))
27174 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
27176 origin
= comp_unit_die ();
27178 add_child_die (origin
, die
);
27183 limbo_die_list
= NULL
;
27186 /* Output stuff that dwarf requires at the end of every file,
27187 and generate the DWARF-2 debugging info. */
27190 dwarf2out_finish (const char *filename
)
27192 comdat_type_node
*ctnode
;
27193 dw_die_ref main_comp_unit_die
;
27195 /* Flush out any latecomers to the limbo party. */
27196 flush_limbo_die_list ();
27198 /* We shouldn't have any symbols with delayed asm names for
27199 DIEs generated after early finish. */
27200 gcc_assert (deferred_asm_name
== NULL
);
27202 /* PCH might result in DW_AT_producer string being restored from the
27203 header compilation, so always fill it with empty string initially
27204 and overwrite only here. */
27205 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
27206 producer_string
= gen_producer_string ();
27207 producer
->dw_attr_val
.v
.val_str
->refcount
--;
27208 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
27210 gen_remaining_tmpl_value_param_die_attribute ();
27212 /* Add the name for the main input file now. We delayed this from
27213 dwarf2out_init to avoid complications with PCH.
27214 For LTO produced units use a fixed artificial name to avoid
27215 leaking tempfile names into the dwarf. */
27217 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
27219 add_name_attribute (comp_unit_die (), "<artificial>");
27220 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
27221 add_comp_dir_attribute (comp_unit_die ());
27222 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
27225 file_table
->traverse
<bool *, file_table_relative_p
> (&p
);
27227 add_comp_dir_attribute (comp_unit_die ());
27230 #if ENABLE_ASSERT_CHECKING
27232 dw_die_ref die
= comp_unit_die (), c
;
27233 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
27236 resolve_addr (comp_unit_die ());
27237 move_marked_base_types ();
27239 /* Walk through the list of incomplete types again, trying once more to
27240 emit full debugging info for them. */
27241 retry_incomplete_types ();
27243 if (flag_eliminate_unused_debug_types
)
27244 prune_unused_types ();
27246 /* Generate separate COMDAT sections for type DIEs. */
27247 if (use_debug_types
)
27249 break_out_comdat_types (comp_unit_die ());
27251 /* Each new type_unit DIE was added to the limbo die list when created.
27252 Since these have all been added to comdat_type_list, clear the
27254 limbo_die_list
= NULL
;
27256 /* For each new comdat type unit, copy declarations for incomplete
27257 types to make the new unit self-contained (i.e., no direct
27258 references to the main compile unit). */
27259 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
27260 copy_decls_for_unworthy_types (ctnode
->root_die
);
27261 copy_decls_for_unworthy_types (comp_unit_die ());
27263 /* In the process of copying declarations from one unit to another,
27264 we may have left some declarations behind that are no longer
27265 referenced. Prune them. */
27266 prune_unused_types ();
27269 /* Generate separate CUs for each of the include files we've seen.
27270 They will go into limbo_die_list. */
27271 if (flag_eliminate_dwarf2_dups
)
27272 break_out_includes (comp_unit_die ());
27274 /* Traverse the DIE's and add sibling attributes to those DIE's that
27276 add_sibling_attributes (comp_unit_die ());
27277 limbo_die_node
*node
;
27278 for (node
= limbo_die_list
; node
; node
= node
->next
)
27279 add_sibling_attributes (node
->die
);
27280 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
27281 add_sibling_attributes (ctnode
->root_die
);
27283 /* When splitting DWARF info, we put some attributes in the
27284 skeleton compile_unit DIE that remains in the .o, while
27285 most attributes go in the DWO compile_unit_die. */
27286 if (dwarf_split_debug_info
)
27287 main_comp_unit_die
= gen_compile_unit_die (NULL
);
27289 main_comp_unit_die
= comp_unit_die ();
27291 /* Output a terminator label for the .text section. */
27292 switch_to_section (text_section
);
27293 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
27294 if (cold_text_section
)
27296 switch_to_section (cold_text_section
);
27297 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
27300 /* We can only use the low/high_pc attributes if all of the code was
27302 if (!have_multiple_function_sections
27303 || (dwarf_version
< 3 && dwarf_strict
))
27305 /* Don't add if the CU has no associated code. */
27306 if (text_section_used
)
27307 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
27308 text_end_label
, true);
27314 bool range_list_added
= false;
27316 if (text_section_used
)
27317 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
27318 text_end_label
, &range_list_added
, true);
27319 if (cold_text_section_used
)
27320 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
27321 cold_end_label
, &range_list_added
, true);
27323 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
27325 if (DECL_IGNORED_P (fde
->decl
))
27327 if (!fde
->in_std_section
)
27328 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
27329 fde
->dw_fde_end
, &range_list_added
,
27331 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
27332 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
27333 fde
->dw_fde_second_end
, &range_list_added
,
27337 if (range_list_added
)
27339 /* We need to give .debug_loc and .debug_ranges an appropriate
27340 "base address". Use zero so that these addresses become
27341 absolute. Historically, we've emitted the unexpected
27342 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
27343 Emit both to give time for other tools to adapt. */
27344 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
27345 if (! dwarf_strict
&& dwarf_version
< 4)
27346 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
27352 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
27353 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
27354 debug_line_section_label
);
27357 add_AT_macptr (comp_unit_die (),
27358 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
27359 macinfo_section_label
);
27361 if (dwarf_split_debug_info
)
27363 /* optimize_location_lists calculates the size of the lists,
27364 so index them first, and assign indices to the entries.
27365 Although optimize_location_lists will remove entries from
27366 the table, it only does so for duplicates, and therefore
27367 only reduces ref_counts to 1. */
27368 index_location_lists (comp_unit_die ());
27370 if (addr_index_table
!= NULL
)
27372 unsigned int index
= 0;
27374 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
27379 if (have_location_lists
)
27380 optimize_location_lists (comp_unit_die ());
27382 save_macinfo_strings ();
27384 if (dwarf_split_debug_info
)
27386 unsigned int index
= 0;
27388 /* Add attributes common to skeleton compile_units and
27389 type_units. Because these attributes include strings, it
27390 must be done before freezing the string table. Top-level
27391 skeleton die attrs are added when the skeleton type unit is
27392 created, so ensure it is created by this point. */
27393 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
27394 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
27397 /* Output all of the compilation units. We put the main one last so that
27398 the offsets are available to output_pubnames. */
27399 for (node
= limbo_die_list
; node
; node
= node
->next
)
27400 output_comp_unit (node
->die
, 0);
27402 hash_table
<comdat_type_hasher
> comdat_type_table (100);
27403 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
27405 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
27407 /* Don't output duplicate types. */
27408 if (*slot
!= HTAB_EMPTY_ENTRY
)
27411 /* Add a pointer to the line table for the main compilation unit
27412 so that the debugger can make sense of DW_AT_decl_file
27414 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
27415 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
27416 (!dwarf_split_debug_info
27417 ? debug_line_section_label
27418 : debug_skeleton_line_section_label
));
27420 output_comdat_type_unit (ctnode
);
27424 /* The AT_pubnames attribute needs to go in all skeleton dies, including
27425 both the main_cu and all skeleton TUs. Making this call unconditional
27426 would end up either adding a second copy of the AT_pubnames attribute, or
27427 requiring a special case in add_top_level_skeleton_die_attrs. */
27428 if (!dwarf_split_debug_info
)
27429 add_AT_pubnames (comp_unit_die ());
27431 if (dwarf_split_debug_info
)
27434 unsigned char checksum
[16];
27435 struct md5_ctx ctx
;
27437 /* Compute a checksum of the comp_unit to use as the dwo_id. */
27438 md5_init_ctx (&ctx
);
27440 die_checksum (comp_unit_die (), &ctx
, &mark
);
27441 unmark_all_dies (comp_unit_die ());
27442 md5_finish_ctx (&ctx
, checksum
);
27444 /* Use the first 8 bytes of the checksum as the dwo_id,
27445 and add it to both comp-unit DIEs. */
27446 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
27447 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
27449 /* Add the base offset of the ranges table to the skeleton
27451 if (ranges_table_in_use
)
27452 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
27453 ranges_section_label
);
27455 switch_to_section (debug_addr_section
);
27456 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
27457 output_addr_table ();
27460 /* Output the main compilation unit if non-empty or if .debug_macinfo
27461 or .debug_macro will be emitted. */
27462 output_comp_unit (comp_unit_die (), have_macinfo
);
27464 if (dwarf_split_debug_info
&& info_section_emitted
)
27465 output_skeleton_debug_sections (main_comp_unit_die
);
27467 /* Output the abbreviation table. */
27468 if (abbrev_die_table_in_use
!= 1)
27470 switch_to_section (debug_abbrev_section
);
27471 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
27472 output_abbrev_section ();
27475 /* Output location list section if necessary. */
27476 if (have_location_lists
)
27478 /* Output the location lists info. */
27479 switch_to_section (debug_loc_section
);
27480 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
27481 output_location_lists (comp_unit_die ());
27484 output_pubtables ();
27486 /* Output the address range information if a CU (.debug_info section)
27487 was emitted. We output an empty table even if we had no functions
27488 to put in it. This because the consumer has no way to tell the
27489 difference between an empty table that we omitted and failure to
27490 generate a table that would have contained data. */
27491 if (info_section_emitted
)
27493 switch_to_section (debug_aranges_section
);
27497 /* Output ranges section if necessary. */
27498 if (ranges_table_in_use
)
27500 switch_to_section (debug_ranges_section
);
27501 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
27505 /* Have to end the macro section. */
27508 switch_to_section (debug_macinfo_section
);
27509 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
27511 dw2_asm_output_data (1, 0, "End compilation unit");
27514 /* Output the source line correspondence table. We must do this
27515 even if there is no line information. Otherwise, on an empty
27516 translation unit, we will generate a present, but empty,
27517 .debug_info section. IRIX 6.5 `nm' will then complain when
27518 examining the file. This is done late so that any filenames
27519 used by the debug_info section are marked as 'used'. */
27520 switch_to_section (debug_line_section
);
27521 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
27522 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
27523 output_line_info (false);
27525 if (dwarf_split_debug_info
&& info_section_emitted
)
27527 switch_to_section (debug_skeleton_line_section
);
27528 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
27529 output_line_info (true);
27532 /* If we emitted any indirect strings, output the string table too. */
27533 if (debug_str_hash
|| skeleton_debug_str_hash
)
27534 output_indirect_strings ();
27537 /* Perform any cleanups needed after the early debug generation pass
27541 dwarf2out_early_finish (void)
27543 limbo_die_node
*node
;
27545 /* Add DW_AT_linkage_name for all deferred DIEs. */
27546 for (node
= deferred_asm_name
; node
; node
= node
->next
)
27548 tree decl
= node
->created_for
;
27549 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
27550 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
27551 ended up in deferred_asm_name before we knew it was
27552 constant and never written to disk. */
27553 && DECL_ASSEMBLER_NAME (decl
))
27555 add_linkage_attr (node
->die
, decl
);
27556 move_linkage_attr (node
->die
);
27559 deferred_asm_name
= NULL
;
27561 /* The point here is to flush out the limbo list so that it is empty
27562 and we don't need to stream it for LTO. */
27563 flush_limbo_die_list ();
27565 gen_scheduled_generic_parms_dies ();
27566 gen_remaining_tmpl_value_param_die_attribute ();
27569 /* Reset all state within dwarf2out.c so that we can rerun the compiler
27570 within the same process. For use by toplev::finalize. */
27573 dwarf2out_c_finalize (void)
27575 last_var_location_insn
= NULL
;
27576 cached_next_real_insn
= NULL
;
27577 used_rtx_array
= NULL
;
27578 incomplete_types
= NULL
;
27579 decl_scope_table
= NULL
;
27580 debug_info_section
= NULL
;
27581 debug_skeleton_info_section
= NULL
;
27582 debug_abbrev_section
= NULL
;
27583 debug_skeleton_abbrev_section
= NULL
;
27584 debug_aranges_section
= NULL
;
27585 debug_addr_section
= NULL
;
27586 debug_macinfo_section
= NULL
;
27587 debug_line_section
= NULL
;
27588 debug_skeleton_line_section
= NULL
;
27589 debug_loc_section
= NULL
;
27590 debug_pubnames_section
= NULL
;
27591 debug_pubtypes_section
= NULL
;
27592 debug_str_section
= NULL
;
27593 debug_str_dwo_section
= NULL
;
27594 debug_str_offsets_section
= NULL
;
27595 debug_ranges_section
= NULL
;
27596 debug_frame_section
= NULL
;
27598 debug_str_hash
= NULL
;
27599 skeleton_debug_str_hash
= NULL
;
27600 dw2_string_counter
= 0;
27601 have_multiple_function_sections
= false;
27602 text_section_used
= false;
27603 cold_text_section_used
= false;
27604 cold_text_section
= NULL
;
27605 current_unit_personality
= NULL
;
27607 next_die_offset
= 0;
27608 single_comp_unit_die
= NULL
;
27609 comdat_type_list
= NULL
;
27610 limbo_die_list
= NULL
;
27612 decl_die_table
= NULL
;
27613 common_block_die_table
= NULL
;
27614 decl_loc_table
= NULL
;
27615 call_arg_locations
= NULL
;
27616 call_arg_loc_last
= NULL
;
27617 call_site_count
= -1;
27618 tail_call_site_count
= -1;
27619 cached_dw_loc_list_table
= NULL
;
27620 abbrev_die_table
= NULL
;
27621 abbrev_die_table_allocated
= 0;
27622 abbrev_die_table_in_use
= 0;
27623 delete dwarf_proc_stack_usage_map
;
27624 dwarf_proc_stack_usage_map
= NULL
;
27625 line_info_label_num
= 0;
27626 cur_line_info_table
= NULL
;
27627 text_section_line_info
= NULL
;
27628 cold_text_section_line_info
= NULL
;
27629 separate_line_info
= NULL
;
27630 info_section_emitted
= false;
27631 pubname_table
= NULL
;
27632 pubtype_table
= NULL
;
27633 macinfo_table
= NULL
;
27634 ranges_table
= NULL
;
27635 ranges_table_allocated
= 0;
27636 ranges_table_in_use
= 0;
27637 ranges_by_label
= 0;
27638 ranges_by_label_allocated
= 0;
27639 ranges_by_label_in_use
= 0;
27640 have_location_lists
= false;
27643 last_emitted_file
= NULL
;
27645 tmpl_value_parm_die_table
= NULL
;
27646 generic_type_instances
= NULL
;
27647 frame_pointer_fb_offset
= 0;
27648 frame_pointer_fb_offset_valid
= false;
27649 base_types
.release ();
27650 XDELETEVEC (producer_string
);
27651 producer_string
= NULL
;
27654 #include "gt-dwarf2out.h"