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 /* Pointer to vector of DW_TAG_string_type DIEs that need finalization
3130 once all arguments are parsed. */
3131 static vec<dw_die_ref> *string_types;
3133 /* Flags to represent a set of attribute classes for attributes that represent
3134 a scalar value (bounds, pointers, ...). */
3137 dw_scalar_form_constant = 0x01,
3138 dw_scalar_form_exprloc = 0x02,
3139 dw_scalar_form_reference = 0x04
3142 /* Forward declarations for functions defined in this file. */
3144 static int is_pseudo_reg (const_rtx);
3145 static tree type_main_variant (tree);
3146 static int is_tagged_type (const_tree);
3147 static const char *dwarf_tag_name (unsigned);
3148 static const char *dwarf_attr_name (unsigned);
3149 static const char *dwarf_form_name (unsigned);
3150 static tree decl_ultimate_origin (const_tree);
3151 static tree decl_class_context (tree);
3152 static void add_dwarf_attr (dw_die_ref, dw_attr_node *);
3153 static inline enum dw_val_class AT_class (dw_attr_node *);
3154 static inline unsigned int AT_index (dw_attr_node *);
3155 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3156 static inline unsigned AT_flag (dw_attr_node *);
3157 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3158 static inline HOST_WIDE_INT AT_int (dw_attr_node *);
3159 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3160 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_node *);
3161 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
3162 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3163 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3164 unsigned int, unsigned char *);
3165 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
3166 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3167 static inline const char *AT_string (dw_attr_node *);
3168 static enum dwarf_form AT_string_form (dw_attr_node *);
3169 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3170 static void add_AT_specification (dw_die_ref, dw_die_ref);
3171 static inline dw_die_ref AT_ref (dw_attr_node *);
3172 static inline int AT_ref_external (dw_attr_node *);
3173 static inline void set_AT_ref_external (dw_attr_node *, int);
3174 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3175 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3176 static inline dw_loc_descr_ref AT_loc (dw_attr_node *);
3177 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3179 static inline dw_loc_list_ref AT_loc_list (dw_attr_node *);
3180 static addr_table_entry *add_addr_table_entry (void *, enum ate_kind);
3181 static void remove_addr_table_entry (addr_table_entry *);
3182 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx, bool);
3183 static inline rtx AT_addr (dw_attr_node *);
3184 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3185 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
3186 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
3187 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3188 unsigned HOST_WIDE_INT);
3189 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3190 unsigned long, bool);
3191 static inline const char *AT_lbl (dw_attr_node *);
3192 static dw_attr_node *get_AT (dw_die_ref, enum dwarf_attribute);
3193 static const char *get_AT_low_pc (dw_die_ref);
3194 static const char *get_AT_hi_pc (dw_die_ref);
3195 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3196 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3197 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3198 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3199 static bool is_cxx (void);
3200 static bool is_fortran (void);
3201 static bool is_ada (void);
3202 static bool remove_AT (dw_die_ref, enum dwarf_attribute);
3203 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3204 static void add_child_die (dw_die_ref, dw_die_ref);
3205 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3206 static dw_die_ref lookup_type_die (tree);
3207 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
3208 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
3209 static void equate_type_number_to_die (tree, dw_die_ref);
3210 static dw_die_ref lookup_decl_die (tree);
3211 static var_loc_list *lookup_decl_loc (const_tree);
3212 static void equate_decl_number_to_die (tree, dw_die_ref);
3213 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
3214 static void print_spaces (FILE *);
3215 static void print_die (dw_die_ref, FILE *);
3216 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3217 static dw_die_ref pop_compile_unit (dw_die_ref);
3218 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3219 static void attr_checksum (dw_attr_node *, struct md5_ctx *, int *);
3220 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3221 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
3222 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
3223 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
3224 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_node *,
3225 struct md5_ctx *, int *);
3226 struct checksum_attributes;
3227 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
3228 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
3229 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
3230 static void generate_type_signature (dw_die_ref, comdat_type_node *);
3231 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3232 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
3233 static int same_attr_p (dw_attr_node *, dw_attr_node *, int *);
3234 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3235 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3236 static void compute_section_prefix (dw_die_ref);
3237 static int is_type_die (dw_die_ref);
3238 static int is_comdat_die (dw_die_ref);
3239 static int is_symbol_die (dw_die_ref);
3240 static inline bool is_template_instantiation (dw_die_ref);
3241 static void assign_symbol_names (dw_die_ref);
3242 static void break_out_includes (dw_die_ref);
3243 static int is_declaration_die (dw_die_ref);
3244 static int should_move_die_to_comdat (dw_die_ref);
3245 static dw_die_ref clone_as_declaration (dw_die_ref);
3246 static dw_die_ref clone_die (dw_die_ref);
3247 static dw_die_ref clone_tree (dw_die_ref);
3248 static dw_die_ref copy_declaration_context (dw_die_ref, dw_die_ref);
3249 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
3250 static void generate_skeleton_bottom_up (skeleton_chain_node *);
3251 static dw_die_ref generate_skeleton (dw_die_ref);
3252 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
3255 static void break_out_comdat_types (dw_die_ref);
3256 static void copy_decls_for_unworthy_types (dw_die_ref);
3258 static void add_sibling_attributes (dw_die_ref);
3259 static void output_location_lists (dw_die_ref);
3260 static int constant_size (unsigned HOST_WIDE_INT);
3261 static unsigned long size_of_die (dw_die_ref);
3262 static void calc_die_sizes (dw_die_ref);
3263 static void calc_base_type_die_sizes (void);
3264 static void mark_dies (dw_die_ref);
3265 static void unmark_dies (dw_die_ref);
3266 static void unmark_all_dies (dw_die_ref);
3267 static unsigned long size_of_pubnames (vec<pubname_entry, va_gc> *);
3268 static unsigned long size_of_aranges (void);
3269 static enum dwarf_form value_format (dw_attr_node *);
3270 static void output_value_format (dw_attr_node *);
3271 static void output_abbrev_section (void);
3272 static void output_die_abbrevs (unsigned long, dw_die_ref);
3273 static void output_die_symbol (dw_die_ref);
3274 static void output_die (dw_die_ref);
3275 static void output_compilation_unit_header (void);
3276 static void output_comp_unit (dw_die_ref, int);
3277 static void output_comdat_type_unit (comdat_type_node *);
3278 static const char *dwarf2_name (tree, int);
3279 static void add_pubname (tree, dw_die_ref);
3280 static void add_enumerator_pubname (const char *, dw_die_ref);
3281 static void add_pubname_string (const char *, dw_die_ref);
3282 static void add_pubtype (tree, dw_die_ref);
3283 static void output_pubnames (vec<pubname_entry, va_gc> *);
3284 static void output_aranges (void);
3285 static unsigned int add_ranges_num (int);
3286 static unsigned int add_ranges (const_tree);
3287 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
3289 static void output_ranges (void);
3290 static dw_line_info_table *new_line_info_table (void);
3291 static void output_line_info (bool);
3292 static void output_file_names (void);
3293 static dw_die_ref base_type_die (tree, bool);
3294 static int is_base_type (tree);
3295 static dw_die_ref subrange_type_die (tree, tree, tree, tree, dw_die_ref);
3296 static int decl_quals (const_tree);
3297 static dw_die_ref modified_type_die (tree, int, bool, dw_die_ref);
3298 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
3299 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
3300 static int type_is_enum (const_tree);
3301 static unsigned int dbx_reg_number (const_rtx);
3302 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3303 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
3304 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
3305 enum var_init_status);
3306 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
3307 enum var_init_status);
3308 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
3309 enum var_init_status);
3310 static int is_based_loc (const_rtx);
3311 static bool resolve_one_addr (rtx *);
3312 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
3313 enum var_init_status);
3314 static dw_loc_descr_ref loc_descriptor (rtx, machine_mode mode,
3315 enum var_init_status);
3316 struct loc_descr_context;
3317 static void add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref);
3318 static void add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list);
3319 static dw_loc_list_ref loc_list_from_tree (tree, int,
3320 const struct loc_descr_context *);
3321 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int,
3322 const struct loc_descr_context *);
3323 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3324 static tree field_type (const_tree);
3325 static unsigned int simple_type_align_in_bits (const_tree);
3326 static unsigned int simple_decl_align_in_bits (const_tree);
3327 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
3329 static dw_loc_descr_ref field_byte_offset (const_tree, struct vlr_context *,
3331 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3333 static void add_data_member_location_attribute (dw_die_ref, tree,
3334 struct vlr_context *);
3335 static bool add_const_value_attribute (dw_die_ref, rtx);
3336 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3337 static void insert_wide_int (const wide_int &, unsigned char *, int);
3338 static void insert_float (const_rtx, unsigned char *);
3339 static rtx rtl_for_decl_location (tree);
3340 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool);
3341 static bool tree_add_const_value_attribute (dw_die_ref, tree);
3342 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
3343 static void add_name_attribute (dw_die_ref, const char *);
3344 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
3345 static void add_comp_dir_attribute (dw_die_ref);
3346 static void add_scalar_info (dw_die_ref, enum dwarf_attribute, tree, int,
3347 const struct loc_descr_context *);
3348 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree,
3349 const struct loc_descr_context *);
3350 static void add_subscript_info (dw_die_ref, tree, bool);
3351 static void add_byte_size_attribute (dw_die_ref, tree);
3352 static inline void add_bit_offset_attribute (dw_die_ref, tree,
3353 struct vlr_context *);
3354 static void add_bit_size_attribute (dw_die_ref, tree);
3355 static void add_prototyped_attribute (dw_die_ref, tree);
3356 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
3357 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3358 static void add_src_coords_attributes (dw_die_ref, tree);
3359 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3360 static void add_discr_value (dw_die_ref, dw_discr_value *);
3361 static void add_discr_list (dw_die_ref, dw_discr_list_ref);
3362 static inline dw_discr_list_ref AT_discr_list (dw_attr_node *);
3363 static void push_decl_scope (tree);
3364 static void pop_decl_scope (void);
3365 static dw_die_ref scope_die_for (tree, dw_die_ref);
3366 static inline int local_scope_p (dw_die_ref);
3367 static inline int class_scope_p (dw_die_ref);
3368 static inline int class_or_namespace_scope_p (dw_die_ref);
3369 static void add_type_attribute (dw_die_ref, tree, int, bool, dw_die_ref);
3370 static void add_calling_convention_attribute (dw_die_ref, tree);
3371 static const char *type_tag (const_tree);
3372 static tree member_declared_type (const_tree);
3374 static const char *decl_start_label (tree);
3376 static void gen_array_type_die (tree, dw_die_ref);
3377 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
3379 static void gen_entry_point_die (tree, dw_die_ref);
3381 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
3382 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
3383 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
3384 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3385 static void gen_formal_types_die (tree, dw_die_ref);
3386 static void gen_subprogram_die (tree, dw_die_ref);
3387 static void gen_variable_die (tree, tree, dw_die_ref);
3388 static void gen_const_die (tree, dw_die_ref);
3389 static void gen_label_die (tree, dw_die_ref);
3390 static void gen_lexical_block_die (tree, dw_die_ref);
3391 static void gen_inlined_subroutine_die (tree, dw_die_ref);
3392 static void gen_field_die (tree, struct vlr_context *, dw_die_ref);
3393 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3394 static dw_die_ref gen_compile_unit_die (const char *);
3395 static void gen_inheritance_die (tree, tree, tree, dw_die_ref);
3396 static void gen_member_die (tree, dw_die_ref);
3397 static void gen_struct_or_union_type_die (tree, dw_die_ref,
3398 enum debug_info_usage);
3399 static void gen_subroutine_type_die (tree, dw_die_ref);
3400 static void gen_typedef_die (tree, dw_die_ref);
3401 static void gen_type_die (tree, dw_die_ref);
3402 static void gen_block_die (tree, dw_die_ref);
3403 static void decls_for_scope (tree, dw_die_ref);
3404 static bool is_naming_typedef_decl (const_tree);
3405 static inline dw_die_ref get_context_die (tree);
3406 static void gen_namespace_die (tree, dw_die_ref);
3407 static dw_die_ref gen_namelist_decl (tree, dw_die_ref, tree);
3408 static dw_die_ref gen_decl_die (tree, tree, struct vlr_context *, dw_die_ref);
3409 static dw_die_ref force_decl_die (tree);
3410 static dw_die_ref force_type_die (tree);
3411 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
3412 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
3413 static struct dwarf_file_data * lookup_filename (const char *);
3414 static void retry_incomplete_types (void);
3415 static void gen_type_die_for_member (tree, tree, dw_die_ref);
3416 static void gen_generic_params_dies (tree);
3417 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
3418 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
3419 static void splice_child_die (dw_die_ref, dw_die_ref);
3420 static int file_info_cmp (const void *, const void *);
3421 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3422 const char *, const char *);
3423 static void output_loc_list (dw_loc_list_ref);
3424 static char *gen_internal_sym (const char *);
3425 static bool want_pubnames (void);
3427 static void prune_unmark_dies (dw_die_ref);
3428 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
3429 static void prune_unused_types_mark (dw_die_ref, int);
3430 static void prune_unused_types_walk (dw_die_ref);
3431 static void prune_unused_types_walk_attribs (dw_die_ref);
3432 static void prune_unused_types_prune (dw_die_ref);
3433 static void prune_unused_types (void);
3434 static int maybe_emit_file (struct dwarf_file_data *fd);
3435 static inline const char *AT_vms_delta1 (dw_attr_node *);
3436 static inline const char *AT_vms_delta2 (dw_attr_node *);
3437 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
3438 const char *, const char *);
3439 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
3440 static void gen_remaining_tmpl_value_param_die_attribute (void);
3441 static bool generic_type_p (tree);
3442 static void schedule_generic_params_dies_gen (tree t);
3443 static void gen_scheduled_generic_parms_dies (void);
3445 static const char *comp_dir_string (void);
3447 static void hash_loc_operands (dw_loc_descr_ref, inchash::hash &);
3449 /* enum for tracking thread-local variables whose address is really an offset
3450 relative to the TLS pointer, which will need link-time relocation, but will
3451 not need relocation by the DWARF consumer. */
3459 /* Return the operator to use for an address of a variable. For dtprel_true, we
3460 use DW_OP_const*. For regular variables, which need both link-time
3461 relocation and consumer-level relocation (e.g., to account for shared objects
3462 loaded at a random address), we use DW_OP_addr*. */
3464 static inline enum dwarf_location_atom
3465 dw_addr_op (enum dtprel_bool dtprel)
3467 if (dtprel == dtprel_true)
3468 return (dwarf_split_debug_info ? DW_OP_GNU_const_index
3469 : (DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u));
3471 return dwarf_split_debug_info ? DW_OP_GNU_addr_index : DW_OP_addr;
3474 /* Return a pointer to a newly allocated address location description. If
3475 dwarf_split_debug_info is true, then record the address with the appropriate
3477 static inline dw_loc_descr_ref
3478 new_addr_loc_descr (rtx addr, enum dtprel_bool dtprel)
3480 dw_loc_descr_ref ref = new_loc_descr (dw_addr_op (dtprel), 0, 0);
3482 ref->dw_loc_oprnd1.val_class = dw_val_class_addr;
3483 ref->dw_loc_oprnd1.v.val_addr = addr;
3484 ref->dtprel = dtprel;
3485 if (dwarf_split_debug_info)
3486 ref->dw_loc_oprnd1.val_entry
3487 = add_addr_table_entry (addr,
3488 dtprel ? ate_kind_rtx_dtprel : ate_kind_rtx);
3490 ref->dw_loc_oprnd1.val_entry = NULL;
3495 /* Section names used to hold DWARF debugging information. */
3497 #ifndef DEBUG_INFO_SECTION
3498 #define DEBUG_INFO_SECTION ".debug_info"
3500 #ifndef DEBUG_DWO_INFO_SECTION
3501 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3503 #ifndef DEBUG_ABBREV_SECTION
3504 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3506 #ifndef DEBUG_DWO_ABBREV_SECTION
3507 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3509 #ifndef DEBUG_ARANGES_SECTION
3510 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3512 #ifndef DEBUG_ADDR_SECTION
3513 #define DEBUG_ADDR_SECTION ".debug_addr"
3515 #ifndef DEBUG_NORM_MACINFO_SECTION
3516 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3518 #ifndef DEBUG_DWO_MACINFO_SECTION
3519 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3521 #ifndef DEBUG_MACINFO_SECTION
3522 #define DEBUG_MACINFO_SECTION \
3523 (!dwarf_split_debug_info \
3524 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3526 #ifndef DEBUG_NORM_MACRO_SECTION
3527 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3529 #ifndef DEBUG_DWO_MACRO_SECTION
3530 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3532 #ifndef DEBUG_MACRO_SECTION
3533 #define DEBUG_MACRO_SECTION \
3534 (!dwarf_split_debug_info \
3535 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3537 #ifndef DEBUG_LINE_SECTION
3538 #define DEBUG_LINE_SECTION ".debug_line"
3540 #ifndef DEBUG_DWO_LINE_SECTION
3541 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3543 #ifndef DEBUG_LOC_SECTION
3544 #define DEBUG_LOC_SECTION ".debug_loc"
3546 #ifndef DEBUG_DWO_LOC_SECTION
3547 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3549 #ifndef DEBUG_PUBNAMES_SECTION
3550 #define DEBUG_PUBNAMES_SECTION \
3551 ((debug_generate_pub_sections == 2) \
3552 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3554 #ifndef DEBUG_PUBTYPES_SECTION
3555 #define DEBUG_PUBTYPES_SECTION \
3556 ((debug_generate_pub_sections == 2) \
3557 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3559 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3560 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3561 #ifndef DEBUG_STR_OFFSETS_SECTION
3562 #define DEBUG_STR_OFFSETS_SECTION \
3563 (!dwarf_split_debug_info \
3564 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3566 #ifndef DEBUG_STR_DWO_SECTION
3567 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3569 #ifndef DEBUG_STR_SECTION
3570 #define DEBUG_STR_SECTION ".debug_str"
3572 #ifndef DEBUG_RANGES_SECTION
3573 #define DEBUG_RANGES_SECTION ".debug_ranges"
3576 /* Standard ELF section names for compiled code and data. */
3577 #ifndef TEXT_SECTION_NAME
3578 #define TEXT_SECTION_NAME ".text"
3581 /* Section flags for .debug_macinfo/.debug_macro section. */
3582 #define DEBUG_MACRO_SECTION_FLAGS \
3583 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3585 /* Section flags for .debug_str section. */
3586 #define DEBUG_STR_SECTION_FLAGS \
3587 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3588 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3591 /* Section flags for .debug_str.dwo section. */
3592 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3594 /* Labels we insert at beginning sections we can reference instead of
3595 the section names themselves. */
3597 #ifndef TEXT_SECTION_LABEL
3598 #define TEXT_SECTION_LABEL "Ltext"
3600 #ifndef COLD_TEXT_SECTION_LABEL
3601 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3603 #ifndef DEBUG_LINE_SECTION_LABEL
3604 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3606 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3607 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3609 #ifndef DEBUG_INFO_SECTION_LABEL
3610 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3612 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3613 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3615 #ifndef DEBUG_ABBREV_SECTION_LABEL
3616 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3618 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3619 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3621 #ifndef DEBUG_ADDR_SECTION_LABEL
3622 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3624 #ifndef DEBUG_LOC_SECTION_LABEL
3625 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3627 #ifndef DEBUG_RANGES_SECTION_LABEL
3628 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3630 #ifndef DEBUG_MACINFO_SECTION_LABEL
3631 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3633 #ifndef DEBUG_MACRO_SECTION_LABEL
3634 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3636 #define SKELETON_COMP_DIE_ABBREV 1
3637 #define SKELETON_TYPE_DIE_ABBREV 2
3639 /* Definitions of defaults for formats and names of various special
3640 (artificial) labels which may be generated within this file (when the -g
3641 options is used and DWARF2_DEBUGGING_INFO is in effect.
3642 If necessary, these may be overridden from within the tm.h file, but
3643 typically, overriding these defaults is unnecessary. */
3645 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3646 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3647 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3648 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3649 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3650 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3651 static char debug_skeleton_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3652 static char debug_skeleton_abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3653 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3654 static char debug_addr_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3655 static char debug_skeleton_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3656 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3657 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3658 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3660 #ifndef TEXT_END_LABEL
3661 #define TEXT_END_LABEL "Letext"
3663 #ifndef COLD_END_LABEL
3664 #define COLD_END_LABEL "Letext_cold"
3666 #ifndef BLOCK_BEGIN_LABEL
3667 #define BLOCK_BEGIN_LABEL "LBB"
3669 #ifndef BLOCK_END_LABEL
3670 #define BLOCK_END_LABEL "LBE"
3672 #ifndef LINE_CODE_LABEL
3673 #define LINE_CODE_LABEL "LM"
3677 /* Return the root of the DIE's built for the current compilation unit. */
3679 comp_unit_die (void)
3681 if (!single_comp_unit_die)
3682 single_comp_unit_die = gen_compile_unit_die (NULL);
3683 return single_comp_unit_die;
3686 /* We allow a language front-end to designate a function that is to be
3687 called to "demangle" any name before it is put into a DIE. */
3689 static const char *(*demangle_name_func) (const char *);
3692 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3694 demangle_name_func = func;
3697 /* Test if rtl node points to a pseudo register. */
3700 is_pseudo_reg (const_rtx rtl)
3702 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3703 || (GET_CODE (rtl) == SUBREG
3704 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3707 /* Return a reference to a type, with its const and volatile qualifiers
3711 type_main_variant (tree type)
3713 type = TYPE_MAIN_VARIANT (type);
3715 /* ??? There really should be only one main variant among any group of
3716 variants of a given type (and all of the MAIN_VARIANT values for all
3717 members of the group should point to that one type) but sometimes the C
3718 front-end messes this up for array types, so we work around that bug
3720 if (TREE_CODE (type) == ARRAY_TYPE)
3721 while (type != TYPE_MAIN_VARIANT (type))
3722 type = TYPE_MAIN_VARIANT (type);
3727 /* Return nonzero if the given type node represents a tagged type. */
3730 is_tagged_type (const_tree type)
3732 enum tree_code code = TREE_CODE (type);
3734 return (code == RECORD_TYPE || code == UNION_TYPE
3735 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3738 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3741 get_ref_die_offset_label (char *label, dw_die_ref ref)
3743 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
3746 /* Return die_offset of a DIE reference to a base type. */
3748 static unsigned long int
3749 get_base_type_offset (dw_die_ref ref)
3751 if (ref->die_offset)
3752 return ref->die_offset;
3753 if (comp_unit_die ()->die_abbrev)
3755 calc_base_type_die_sizes ();
3756 gcc_assert (ref->die_offset);
3758 return ref->die_offset;
3761 /* Return die_offset of a DIE reference other than base type. */
3763 static unsigned long int
3764 get_ref_die_offset (dw_die_ref ref)
3766 gcc_assert (ref->die_offset);
3767 return ref->die_offset;
3770 /* Convert a DIE tag into its string name. */
3773 dwarf_tag_name (unsigned int tag)
3775 const char *name = get_DW_TAG_name (tag);
3780 return "DW_TAG_<unknown>";
3783 /* Convert a DWARF attribute code into its string name. */
3786 dwarf_attr_name (unsigned int attr)
3792 #if VMS_DEBUGGING_INFO
3793 case DW_AT_HP_prologue:
3794 return "DW_AT_HP_prologue";
3796 case DW_AT_MIPS_loop_unroll_factor:
3797 return "DW_AT_MIPS_loop_unroll_factor";
3800 #if VMS_DEBUGGING_INFO
3801 case DW_AT_HP_epilogue:
3802 return "DW_AT_HP_epilogue";
3804 case DW_AT_MIPS_stride:
3805 return "DW_AT_MIPS_stride";
3809 name = get_DW_AT_name (attr);
3814 return "DW_AT_<unknown>";
3817 /* Convert a DWARF value form code into its string name. */
3820 dwarf_form_name (unsigned int form)
3822 const char *name = get_DW_FORM_name (form);
3827 return "DW_FORM_<unknown>";
3830 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3831 instance of an inlined instance of a decl which is local to an inline
3832 function, so we have to trace all of the way back through the origin chain
3833 to find out what sort of node actually served as the original seed for the
3837 decl_ultimate_origin (const_tree decl)
3839 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
3842 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3843 we're trying to output the abstract instance of this function. */
3844 if (DECL_ABSTRACT_P (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3847 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3848 most distant ancestor, this should never happen. */
3849 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
3851 return DECL_ABSTRACT_ORIGIN (decl);
3854 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3855 of a virtual function may refer to a base class, so we check the 'this'
3859 decl_class_context (tree decl)
3861 tree context = NULL_TREE;
3863 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3864 context = DECL_CONTEXT (decl);
3866 context = TYPE_MAIN_VARIANT
3867 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3869 if (context && !TYPE_P (context))
3870 context = NULL_TREE;
3875 /* Add an attribute/value pair to a DIE. */
3878 add_dwarf_attr (dw_die_ref die, dw_attr_node *attr)
3880 /* Maybe this should be an assert? */
3884 vec_safe_reserve (die->die_attr, 1);
3885 vec_safe_push (die->die_attr, *attr);
3888 static inline enum dw_val_class
3889 AT_class (dw_attr_node *a)
3891 return a->dw_attr_val.val_class;
3894 /* Return the index for any attribute that will be referenced with a
3895 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3896 are stored in dw_attr_val.v.val_str for reference counting
3899 static inline unsigned int
3900 AT_index (dw_attr_node *a)
3902 if (AT_class (a) == dw_val_class_str)
3903 return a->dw_attr_val.v.val_str->index;
3904 else if (a->dw_attr_val.val_entry != NULL)
3905 return a->dw_attr_val.val_entry->index;
3909 /* Add a flag value attribute to a DIE. */
3912 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
3916 attr.dw_attr = attr_kind;
3917 attr.dw_attr_val.val_class = dw_val_class_flag;
3918 attr.dw_attr_val.val_entry = NULL;
3919 attr.dw_attr_val.v.val_flag = flag;
3920 add_dwarf_attr (die, &attr);
3923 static inline unsigned
3924 AT_flag (dw_attr_node *a)
3926 gcc_assert (a && AT_class (a) == dw_val_class_flag);
3927 return a->dw_attr_val.v.val_flag;
3930 /* Add a signed integer attribute value to a DIE. */
3933 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
3937 attr.dw_attr = attr_kind;
3938 attr.dw_attr_val.val_class = dw_val_class_const;
3939 attr.dw_attr_val.val_entry = NULL;
3940 attr.dw_attr_val.v.val_int = int_val;
3941 add_dwarf_attr (die, &attr);
3944 static inline HOST_WIDE_INT
3945 AT_int (dw_attr_node *a)
3947 gcc_assert (a && AT_class (a) == dw_val_class_const);
3948 return a->dw_attr_val.v.val_int;
3951 /* Add an unsigned integer attribute value to a DIE. */
3954 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
3955 unsigned HOST_WIDE_INT unsigned_val)
3959 attr.dw_attr = attr_kind;
3960 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
3961 attr.dw_attr_val.val_entry = NULL;
3962 attr.dw_attr_val.v.val_unsigned = unsigned_val;
3963 add_dwarf_attr (die, &attr);
3966 static inline unsigned HOST_WIDE_INT
3967 AT_unsigned (dw_attr_node *a)
3969 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
3970 return a->dw_attr_val.v.val_unsigned;
3973 /* Add an unsigned wide integer attribute value to a DIE. */
3976 add_AT_wide (dw_die_ref die, enum dwarf_attribute attr_kind,
3981 attr.dw_attr = attr_kind;
3982 attr.dw_attr_val.val_class = dw_val_class_wide_int;
3983 attr.dw_attr_val.val_entry = NULL;
3984 attr.dw_attr_val.v.val_wide = ggc_alloc<wide_int> ();
3985 *attr.dw_attr_val.v.val_wide = w;
3986 add_dwarf_attr (die, &attr);
3989 /* Add an unsigned double integer attribute value to a DIE. */
3992 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
3993 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
3997 attr.dw_attr = attr_kind;
3998 attr.dw_attr_val.val_class = dw_val_class_const_double;
3999 attr.dw_attr_val.val_entry = NULL;
4000 attr.dw_attr_val.v.val_double.high = high;
4001 attr.dw_attr_val.v.val_double.low = low;
4002 add_dwarf_attr (die, &attr);
4005 /* Add a floating point attribute value to a DIE and return it. */
4008 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4009 unsigned int length, unsigned int elt_size, unsigned char *array)
4013 attr.dw_attr = attr_kind;
4014 attr.dw_attr_val.val_class = dw_val_class_vec;
4015 attr.dw_attr_val.val_entry = NULL;
4016 attr.dw_attr_val.v.val_vec.length = length;
4017 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
4018 attr.dw_attr_val.v.val_vec.array = array;
4019 add_dwarf_attr (die, &attr);
4022 /* Add an 8-byte data attribute value to a DIE. */
4025 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
4026 unsigned char data8[8])
4030 attr.dw_attr = attr_kind;
4031 attr.dw_attr_val.val_class = dw_val_class_data8;
4032 attr.dw_attr_val.val_entry = NULL;
4033 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
4034 add_dwarf_attr (die, &attr);
4037 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4038 dwarf_split_debug_info, address attributes in dies destined for the
4039 final executable have force_direct set to avoid using indexed
4043 add_AT_low_high_pc (dw_die_ref die, const char *lbl_low, const char *lbl_high,
4049 lbl_id = xstrdup (lbl_low);
4050 attr.dw_attr = DW_AT_low_pc;
4051 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4052 attr.dw_attr_val.v.val_lbl_id = lbl_id;
4053 if (dwarf_split_debug_info && !force_direct)
4054 attr.dw_attr_val.val_entry
4055 = add_addr_table_entry (lbl_id, ate_kind_label);
4057 attr.dw_attr_val.val_entry = NULL;
4058 add_dwarf_attr (die, &attr);
4060 attr.dw_attr = DW_AT_high_pc;
4061 if (dwarf_version < 4)
4062 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4064 attr.dw_attr_val.val_class = dw_val_class_high_pc;
4065 lbl_id = xstrdup (lbl_high);
4066 attr.dw_attr_val.v.val_lbl_id = lbl_id;
4067 if (attr.dw_attr_val.val_class == dw_val_class_lbl_id
4068 && dwarf_split_debug_info && !force_direct)
4069 attr.dw_attr_val.val_entry
4070 = add_addr_table_entry (lbl_id, ate_kind_label);
4072 attr.dw_attr_val.val_entry = NULL;
4073 add_dwarf_attr (die, &attr);
4076 /* Hash and equality functions for debug_str_hash. */
4079 indirect_string_hasher::hash (indirect_string_node *x)
4081 return htab_hash_string (x->str);
4085 indirect_string_hasher::equal (indirect_string_node *x1, const char *x2)
4087 return strcmp (x1->str, x2) == 0;
4090 /* Add STR to the given string hash table. */
4092 static struct indirect_string_node *
4093 find_AT_string_in_table (const char *str,
4094 hash_table<indirect_string_hasher> *table)
4096 struct indirect_string_node *node;
4098 indirect_string_node **slot
4099 = table->find_slot_with_hash (str, htab_hash_string (str), INSERT);
4102 node = ggc_cleared_alloc<indirect_string_node> ();
4103 node->str = ggc_strdup (str);
4113 /* Add STR to the indirect string hash table. */
4115 static struct indirect_string_node *
4116 find_AT_string (const char *str)
4118 if (! debug_str_hash)
4119 debug_str_hash = hash_table<indirect_string_hasher>::create_ggc (10);
4121 return find_AT_string_in_table (str, debug_str_hash);
4124 /* Add a string attribute value to a DIE. */
4127 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4130 struct indirect_string_node *node;
4132 node = find_AT_string (str);
4134 attr.dw_attr = attr_kind;
4135 attr.dw_attr_val.val_class = dw_val_class_str;
4136 attr.dw_attr_val.val_entry = NULL;
4137 attr.dw_attr_val.v.val_str = node;
4138 add_dwarf_attr (die, &attr);
4141 static inline const char *
4142 AT_string (dw_attr_node *a)
4144 gcc_assert (a && AT_class (a) == dw_val_class_str);
4145 return a->dw_attr_val.v.val_str->str;
4148 /* Call this function directly to bypass AT_string_form's logic to put
4149 the string inline in the die. */
4152 set_indirect_string (struct indirect_string_node *node)
4155 /* Already indirect is a no op. */
4156 if (node->form == DW_FORM_strp || node->form == DW_FORM_GNU_str_index)
4158 gcc_assert (node->label);
4161 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4162 ++dw2_string_counter;
4163 node->label = xstrdup (label);
4165 if (!dwarf_split_debug_info)
4167 node->form = DW_FORM_strp;
4168 node->index = NOT_INDEXED;
4172 node->form = DW_FORM_GNU_str_index;
4173 node->index = NO_INDEX_ASSIGNED;
4177 /* Find out whether a string should be output inline in DIE
4178 or out-of-line in .debug_str section. */
4180 static enum dwarf_form
4181 find_string_form (struct indirect_string_node *node)
4188 len = strlen (node->str) + 1;
4190 /* If the string is shorter or equal to the size of the reference, it is
4191 always better to put it inline. */
4192 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4193 return node->form = DW_FORM_string;
4195 /* If we cannot expect the linker to merge strings in .debug_str
4196 section, only put it into .debug_str if it is worth even in this
4198 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4199 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
4200 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
4201 return node->form = DW_FORM_string;
4203 set_indirect_string (node);
4208 /* Find out whether the string referenced from the attribute should be
4209 output inline in DIE or out-of-line in .debug_str section. */
4211 static enum dwarf_form
4212 AT_string_form (dw_attr_node *a)
4214 gcc_assert (a && AT_class (a) == dw_val_class_str);
4215 return find_string_form (a->dw_attr_val.v.val_str);
4218 /* Add a DIE reference attribute value to a DIE. */
4221 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4224 gcc_checking_assert (targ_die != NULL);
4226 /* With LTO we can end up trying to reference something we didn't create
4227 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4228 if (targ_die == NULL)
4231 attr.dw_attr = attr_kind;
4232 attr.dw_attr_val.val_class = dw_val_class_die_ref;
4233 attr.dw_attr_val.val_entry = NULL;
4234 attr.dw_attr_val.v.val_die_ref.die = targ_die;
4235 attr.dw_attr_val.v.val_die_ref.external = 0;
4236 add_dwarf_attr (die, &attr);
4239 /* Change DIE reference REF to point to NEW_DIE instead. */
4242 change_AT_die_ref (dw_attr_node *ref, dw_die_ref new_die)
4244 gcc_assert (ref->dw_attr_val.val_class == dw_val_class_die_ref);
4245 ref->dw_attr_val.v.val_die_ref.die = new_die;
4246 ref->dw_attr_val.v.val_die_ref.external = 0;
4249 /* Add an AT_specification attribute to a DIE, and also make the back
4250 pointer from the specification to the definition. */
4253 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4255 add_AT_die_ref (die, DW_AT_specification, targ_die);
4256 gcc_assert (!targ_die->die_definition);
4257 targ_die->die_definition = die;
4260 static inline dw_die_ref
4261 AT_ref (dw_attr_node *a)
4263 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4264 return a->dw_attr_val.v.val_die_ref.die;
4268 AT_ref_external (dw_attr_node *a)
4270 if (a && AT_class (a) == dw_val_class_die_ref)
4271 return a->dw_attr_val.v.val_die_ref.external;
4277 set_AT_ref_external (dw_attr_node *a, int i)
4279 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4280 a->dw_attr_val.v.val_die_ref.external = i;
4283 /* Add an FDE reference attribute value to a DIE. */
4286 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4290 attr.dw_attr = attr_kind;
4291 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
4292 attr.dw_attr_val.val_entry = NULL;
4293 attr.dw_attr_val.v.val_fde_index = targ_fde;
4294 add_dwarf_attr (die, &attr);
4297 /* Add a location description attribute value to a DIE. */
4300 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4304 attr.dw_attr = attr_kind;
4305 attr.dw_attr_val.val_class = dw_val_class_loc;
4306 attr.dw_attr_val.val_entry = NULL;
4307 attr.dw_attr_val.v.val_loc = loc;
4308 add_dwarf_attr (die, &attr);
4311 static inline dw_loc_descr_ref
4312 AT_loc (dw_attr_node *a)
4314 gcc_assert (a && AT_class (a) == dw_val_class_loc);
4315 return a->dw_attr_val.v.val_loc;
4319 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4323 if (XCOFF_DEBUGGING_INFO && !HAVE_XCOFF_DWARF_EXTRAS)
4326 attr.dw_attr = attr_kind;
4327 attr.dw_attr_val.val_class = dw_val_class_loc_list;
4328 attr.dw_attr_val.val_entry = NULL;
4329 attr.dw_attr_val.v.val_loc_list = loc_list;
4330 add_dwarf_attr (die, &attr);
4331 have_location_lists = true;
4334 static inline dw_loc_list_ref
4335 AT_loc_list (dw_attr_node *a)
4337 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4338 return a->dw_attr_val.v.val_loc_list;
4341 static inline dw_loc_list_ref *
4342 AT_loc_list_ptr (dw_attr_node *a)
4344 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4345 return &a->dw_attr_val.v.val_loc_list;
4348 struct addr_hasher : ggc_ptr_hash<addr_table_entry>
4350 static hashval_t hash (addr_table_entry *);
4351 static bool equal (addr_table_entry *, addr_table_entry *);
4354 /* Table of entries into the .debug_addr section. */
4356 static GTY (()) hash_table<addr_hasher> *addr_index_table;
4358 /* Hash an address_table_entry. */
4361 addr_hasher::hash (addr_table_entry *a)
4363 inchash::hash hstate;
4369 case ate_kind_rtx_dtprel:
4372 case ate_kind_label:
4373 return htab_hash_string (a->addr.label);
4377 inchash::add_rtx (a->addr.rtl, hstate);
4378 return hstate.end ();
4381 /* Determine equality for two address_table_entries. */
4384 addr_hasher::equal (addr_table_entry *a1, addr_table_entry *a2)
4386 if (a1->kind != a2->kind)
4391 case ate_kind_rtx_dtprel:
4392 return rtx_equal_p (a1->addr.rtl, a2->addr.rtl);
4393 case ate_kind_label:
4394 return strcmp (a1->addr.label, a2->addr.label) == 0;
4400 /* Initialize an addr_table_entry. */
4403 init_addr_table_entry (addr_table_entry *e, enum ate_kind kind, void *addr)
4409 case ate_kind_rtx_dtprel:
4410 e->addr.rtl = (rtx) addr;
4412 case ate_kind_label:
4413 e->addr.label = (char *) addr;
4417 e->index = NO_INDEX_ASSIGNED;
4420 /* Add attr to the address table entry to the table. Defer setting an
4421 index until output time. */
4423 static addr_table_entry *
4424 add_addr_table_entry (void *addr, enum ate_kind kind)
4426 addr_table_entry *node;
4427 addr_table_entry finder;
4429 gcc_assert (dwarf_split_debug_info);
4430 if (! addr_index_table)
4431 addr_index_table = hash_table<addr_hasher>::create_ggc (10);
4432 init_addr_table_entry (&finder, kind, addr);
4433 addr_table_entry **slot = addr_index_table->find_slot (&finder, INSERT);
4435 if (*slot == HTAB_EMPTY_ENTRY)
4437 node = ggc_cleared_alloc<addr_table_entry> ();
4438 init_addr_table_entry (node, kind, addr);
4448 /* Remove an entry from the addr table by decrementing its refcount.
4449 Strictly, decrementing the refcount would be enough, but the
4450 assertion that the entry is actually in the table has found
4454 remove_addr_table_entry (addr_table_entry *entry)
4456 gcc_assert (dwarf_split_debug_info && addr_index_table);
4457 /* After an index is assigned, the table is frozen. */
4458 gcc_assert (entry->refcount > 0 && entry->index == NO_INDEX_ASSIGNED);
4462 /* Given a location list, remove all addresses it refers to from the
4466 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr)
4468 for (; descr; descr = descr->dw_loc_next)
4469 if (descr->dw_loc_oprnd1.val_entry != NULL)
4471 gcc_assert (descr->dw_loc_oprnd1.val_entry->index == NO_INDEX_ASSIGNED);
4472 remove_addr_table_entry (descr->dw_loc_oprnd1.val_entry);
4476 /* A helper function for dwarf2out_finish called through
4477 htab_traverse. Assign an addr_table_entry its index. All entries
4478 must be collected into the table when this function is called,
4479 because the indexing code relies on htab_traverse to traverse nodes
4480 in the same order for each run. */
4483 index_addr_table_entry (addr_table_entry **h, unsigned int *index)
4485 addr_table_entry *node = *h;
4487 /* Don't index unreferenced nodes. */
4488 if (node->refcount == 0)
4491 gcc_assert (node->index == NO_INDEX_ASSIGNED);
4492 node->index = *index;
4498 /* Add an address constant attribute value to a DIE. When using
4499 dwarf_split_debug_info, address attributes in dies destined for the
4500 final executable should be direct references--setting the parameter
4501 force_direct ensures this behavior. */
4504 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr,
4509 attr.dw_attr = attr_kind;
4510 attr.dw_attr_val.val_class = dw_val_class_addr;
4511 attr.dw_attr_val.v.val_addr = addr;
4512 if (dwarf_split_debug_info && !force_direct)
4513 attr.dw_attr_val.val_entry = add_addr_table_entry (addr, ate_kind_rtx);
4515 attr.dw_attr_val.val_entry = NULL;
4516 add_dwarf_attr (die, &attr);
4519 /* Get the RTX from to an address DIE attribute. */
4522 AT_addr (dw_attr_node *a)
4524 gcc_assert (a && AT_class (a) == dw_val_class_addr);
4525 return a->dw_attr_val.v.val_addr;
4528 /* Add a file attribute value to a DIE. */
4531 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
4532 struct dwarf_file_data *fd)
4536 attr.dw_attr = attr_kind;
4537 attr.dw_attr_val.val_class = dw_val_class_file;
4538 attr.dw_attr_val.val_entry = NULL;
4539 attr.dw_attr_val.v.val_file = fd;
4540 add_dwarf_attr (die, &attr);
4543 /* Get the dwarf_file_data from a file DIE attribute. */
4545 static inline struct dwarf_file_data *
4546 AT_file (dw_attr_node *a)
4548 gcc_assert (a && AT_class (a) == dw_val_class_file);
4549 return a->dw_attr_val.v.val_file;
4552 /* Add a vms delta attribute value to a DIE. */
4555 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
4556 const char *lbl1, const char *lbl2)
4560 attr.dw_attr = attr_kind;
4561 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
4562 attr.dw_attr_val.val_entry = NULL;
4563 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
4564 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
4565 add_dwarf_attr (die, &attr);
4568 /* Add a label identifier attribute value to a DIE. */
4571 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind,
4576 attr.dw_attr = attr_kind;
4577 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4578 attr.dw_attr_val.val_entry = NULL;
4579 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4580 if (dwarf_split_debug_info)
4581 attr.dw_attr_val.val_entry
4582 = add_addr_table_entry (attr.dw_attr_val.v.val_lbl_id,
4584 add_dwarf_attr (die, &attr);
4587 /* Add a section offset attribute value to a DIE, an offset into the
4588 debug_line section. */
4591 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4596 attr.dw_attr = attr_kind;
4597 attr.dw_attr_val.val_class = dw_val_class_lineptr;
4598 attr.dw_attr_val.val_entry = NULL;
4599 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4600 add_dwarf_attr (die, &attr);
4603 /* Add a section offset attribute value to a DIE, an offset into the
4604 debug_macinfo section. */
4607 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4612 attr.dw_attr = attr_kind;
4613 attr.dw_attr_val.val_class = dw_val_class_macptr;
4614 attr.dw_attr_val.val_entry = NULL;
4615 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4616 add_dwarf_attr (die, &attr);
4619 /* Add an offset attribute value to a DIE. */
4622 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
4623 unsigned HOST_WIDE_INT offset)
4627 attr.dw_attr = attr_kind;
4628 attr.dw_attr_val.val_class = dw_val_class_offset;
4629 attr.dw_attr_val.val_entry = NULL;
4630 attr.dw_attr_val.v.val_offset = offset;
4631 add_dwarf_attr (die, &attr);
4634 /* Add a range_list attribute value to a DIE. When using
4635 dwarf_split_debug_info, address attributes in dies destined for the
4636 final executable should be direct references--setting the parameter
4637 force_direct ensures this behavior. */
4639 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4640 #define RELOCATED_OFFSET (NULL)
4643 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
4644 long unsigned int offset, bool force_direct)
4648 attr.dw_attr = attr_kind;
4649 attr.dw_attr_val.val_class = dw_val_class_range_list;
4650 /* For the range_list attribute, use val_entry to store whether the
4651 offset should follow split-debug-info or normal semantics. This
4652 value is read in output_range_list_offset. */
4653 if (dwarf_split_debug_info && !force_direct)
4654 attr.dw_attr_val.val_entry = UNRELOCATED_OFFSET;
4656 attr.dw_attr_val.val_entry = RELOCATED_OFFSET;
4657 attr.dw_attr_val.v.val_offset = offset;
4658 add_dwarf_attr (die, &attr);
4661 /* Return the start label of a delta attribute. */
4663 static inline const char *
4664 AT_vms_delta1 (dw_attr_node *a)
4666 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4667 return a->dw_attr_val.v.val_vms_delta.lbl1;
4670 /* Return the end label of a delta attribute. */
4672 static inline const char *
4673 AT_vms_delta2 (dw_attr_node *a)
4675 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4676 return a->dw_attr_val.v.val_vms_delta.lbl2;
4679 static inline const char *
4680 AT_lbl (dw_attr_node *a)
4682 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
4683 || AT_class (a) == dw_val_class_lineptr
4684 || AT_class (a) == dw_val_class_macptr
4685 || AT_class (a) == dw_val_class_high_pc));
4686 return a->dw_attr_val.v.val_lbl_id;
4689 /* Get the attribute of type attr_kind. */
4691 static dw_attr_node *
4692 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4696 dw_die_ref spec = NULL;
4701 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
4702 if (a->dw_attr == attr_kind)
4704 else if (a->dw_attr == DW_AT_specification
4705 || a->dw_attr == DW_AT_abstract_origin)
4709 return get_AT (spec, attr_kind);
4714 /* Returns the parent of the declaration of DIE. */
4717 get_die_parent (dw_die_ref die)
4724 if ((t = get_AT_ref (die, DW_AT_abstract_origin))
4725 || (t = get_AT_ref (die, DW_AT_specification)))
4728 return die->die_parent;
4731 /* Return the "low pc" attribute value, typically associated with a subprogram
4732 DIE. Return null if the "low pc" attribute is either not present, or if it
4733 cannot be represented as an assembler label identifier. */
4735 static inline const char *
4736 get_AT_low_pc (dw_die_ref die)
4738 dw_attr_node *a = get_AT (die, DW_AT_low_pc);
4740 return a ? AT_lbl (a) : NULL;
4743 /* Return the "high pc" attribute value, typically associated with a subprogram
4744 DIE. Return null if the "high pc" attribute is either not present, or if it
4745 cannot be represented as an assembler label identifier. */
4747 static inline const char *
4748 get_AT_hi_pc (dw_die_ref die)
4750 dw_attr_node *a = get_AT (die, DW_AT_high_pc);
4752 return a ? AT_lbl (a) : NULL;
4755 /* Return the value of the string attribute designated by ATTR_KIND, or
4756 NULL if it is not present. */
4758 static inline const char *
4759 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
4761 dw_attr_node *a = get_AT (die, attr_kind);
4763 return a ? AT_string (a) : NULL;
4766 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4767 if it is not present. */
4770 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
4772 dw_attr_node *a = get_AT (die, attr_kind);
4774 return a ? AT_flag (a) : 0;
4777 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4778 if it is not present. */
4780 static inline unsigned
4781 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
4783 dw_attr_node *a = get_AT (die, attr_kind);
4785 return a ? AT_unsigned (a) : 0;
4788 static inline dw_die_ref
4789 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
4791 dw_attr_node *a = get_AT (die, attr_kind);
4793 return a ? AT_ref (a) : NULL;
4796 static inline struct dwarf_file_data *
4797 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
4799 dw_attr_node *a = get_AT (die, attr_kind);
4801 return a ? AT_file (a) : NULL;
4804 /* Return TRUE if the language is C++. */
4809 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4811 return (lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus
4812 || lang == DW_LANG_C_plus_plus_11 || lang == DW_LANG_C_plus_plus_14);
4815 /* Return TRUE if the language is Java. */
4820 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4822 return lang == DW_LANG_Java;
4825 /* Return TRUE if the language is Fortran. */
4830 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4832 return (lang == DW_LANG_Fortran77
4833 || lang == DW_LANG_Fortran90
4834 || lang == DW_LANG_Fortran95
4835 || lang == DW_LANG_Fortran03
4836 || lang == DW_LANG_Fortran08);
4839 /* Return TRUE if the language is Ada. */
4844 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4846 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
4849 /* Remove the specified attribute if present. Return TRUE if removal
4853 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4861 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
4862 if (a->dw_attr == attr_kind)
4864 if (AT_class (a) == dw_val_class_str)
4865 if (a->dw_attr_val.v.val_str->refcount)
4866 a->dw_attr_val.v.val_str->refcount--;
4868 /* vec::ordered_remove should help reduce the number of abbrevs
4870 die->die_attr->ordered_remove (ix);
4876 /* Remove CHILD from its parent. PREV must have the property that
4877 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4880 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
4882 gcc_assert (child->die_parent == prev->die_parent);
4883 gcc_assert (prev->die_sib == child);
4886 gcc_assert (child->die_parent->die_child == child);
4890 prev->die_sib = child->die_sib;
4891 if (child->die_parent->die_child == child)
4892 child->die_parent->die_child = prev;
4895 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4896 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4899 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
4901 dw_die_ref parent = old_child->die_parent;
4903 gcc_assert (parent == prev->die_parent);
4904 gcc_assert (prev->die_sib == old_child);
4906 new_child->die_parent = parent;
4907 if (prev == old_child)
4909 gcc_assert (parent->die_child == old_child);
4910 new_child->die_sib = new_child;
4914 prev->die_sib = new_child;
4915 new_child->die_sib = old_child->die_sib;
4917 if (old_child->die_parent->die_child == old_child)
4918 old_child->die_parent->die_child = new_child;
4921 /* Move all children from OLD_PARENT to NEW_PARENT. */
4924 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
4927 new_parent->die_child = old_parent->die_child;
4928 old_parent->die_child = NULL;
4929 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
4932 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4936 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
4942 dw_die_ref prev = c;
4944 while (c->die_tag == tag)
4946 remove_child_with_prev (c, prev);
4947 c->die_parent = NULL;
4948 /* Might have removed every child. */
4949 if (c == c->die_sib)
4953 } while (c != die->die_child);
4956 /* Add a CHILD_DIE as the last child of DIE. */
4959 add_child_die (dw_die_ref die, dw_die_ref child_die)
4961 /* FIXME this should probably be an assert. */
4962 if (! die || ! child_die)
4964 gcc_assert (die != child_die);
4966 child_die->die_parent = die;
4969 child_die->die_sib = die->die_child->die_sib;
4970 die->die_child->die_sib = child_die;
4973 child_die->die_sib = child_die;
4974 die->die_child = child_die;
4977 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
4980 add_child_die_after (dw_die_ref die, dw_die_ref child_die,
4981 dw_die_ref after_die)
4987 && die != child_die);
4989 child_die->die_parent = die;
4990 child_die->die_sib = after_die->die_sib;
4991 after_die->die_sib = child_die;
4992 if (die->die_child == after_die)
4993 die->die_child = child_die;
4996 /* Unassociate CHILD from its parent, and make its parent be
5000 reparent_child (dw_die_ref child, dw_die_ref new_parent)
5002 for (dw_die_ref p = child->die_parent->die_child; ; p = p->die_sib)
5003 if (p->die_sib == child)
5005 remove_child_with_prev (child, p);
5008 add_child_die (new_parent, child);
5011 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5012 is the specification, to the end of PARENT's list of children.
5013 This is done by removing and re-adding it. */
5016 splice_child_die (dw_die_ref parent, dw_die_ref child)
5018 /* We want the declaration DIE from inside the class, not the
5019 specification DIE at toplevel. */
5020 if (child->die_parent != parent)
5022 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5028 gcc_assert (child->die_parent == parent
5029 || (child->die_parent
5030 == get_AT_ref (parent, DW_AT_specification)));
5032 reparent_child (child, parent);
5035 /* Create and return a new die with a parent of PARENT_DIE. If
5036 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5037 associated tree T must be supplied to determine parenthood
5040 static inline dw_die_ref
5041 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5043 dw_die_ref die = ggc_cleared_alloc<die_node> ();
5045 die->die_tag = tag_value;
5047 if (parent_die != NULL)
5048 add_child_die (parent_die, die);
5051 limbo_die_node *limbo_node;
5053 /* No DIEs created after early dwarf should end up in limbo,
5054 because the limbo list should not persist past LTO
5056 if (tag_value != DW_TAG_compile_unit
5057 /* These are allowed because they're generated while
5058 breaking out COMDAT units late. */
5059 && tag_value != DW_TAG_type_unit
5061 /* Allow nested functions to live in limbo because they will
5062 only temporarily live there, as decls_for_scope will fix
5064 && (TREE_CODE (t) != FUNCTION_DECL
5065 || !decl_function_context (t))
5066 /* Same as nested functions above but for types. Types that
5067 are local to a function will be fixed in
5069 && (!RECORD_OR_UNION_TYPE_P (t)
5070 || !TYPE_CONTEXT (t)
5071 || TREE_CODE (TYPE_CONTEXT (t)) != FUNCTION_DECL)
5072 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5073 especially in the ltrans stage, but once we implement LTO
5074 dwarf streaming, we should remove this exception. */
5077 fprintf (stderr, "symbol ended up in limbo too late:");
5078 debug_generic_stmt (t);
5082 limbo_node = ggc_cleared_alloc<limbo_die_node> ();
5083 limbo_node->die = die;
5084 limbo_node->created_for = t;
5085 limbo_node->next = limbo_die_list;
5086 limbo_die_list = limbo_node;
5092 /* Return the DIE associated with the given type specifier. */
5094 static inline dw_die_ref
5095 lookup_type_die (tree type)
5097 return TYPE_SYMTAB_DIE (type);
5100 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5101 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5102 anonymous type instead the one of the naming typedef. */
5104 static inline dw_die_ref
5105 strip_naming_typedef (tree type, dw_die_ref type_die)
5108 && TREE_CODE (type) == RECORD_TYPE
5110 && type_die->die_tag == DW_TAG_typedef
5111 && is_naming_typedef_decl (TYPE_NAME (type)))
5112 type_die = get_AT_ref (type_die, DW_AT_type);
5116 /* Like lookup_type_die, but if type is an anonymous type named by a
5117 typedef[1], return the DIE of the anonymous type instead the one of
5118 the naming typedef. This is because in gen_typedef_die, we did
5119 equate the anonymous struct named by the typedef with the DIE of
5120 the naming typedef. So by default, lookup_type_die on an anonymous
5121 struct yields the DIE of the naming typedef.
5123 [1]: Read the comment of is_naming_typedef_decl to learn about what
5124 a naming typedef is. */
5126 static inline dw_die_ref
5127 lookup_type_die_strip_naming_typedef (tree type)
5129 dw_die_ref die = lookup_type_die (type);
5130 return strip_naming_typedef (type, die);
5133 /* Equate a DIE to a given type specifier. */
5136 equate_type_number_to_die (tree type, dw_die_ref type_die)
5138 TYPE_SYMTAB_DIE (type) = type_die;
5141 /* Returns a hash value for X (which really is a die_struct). */
5144 decl_die_hasher::hash (die_node *x)
5146 return (hashval_t) x->decl_id;
5149 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5152 decl_die_hasher::equal (die_node *x, tree y)
5154 return (x->decl_id == DECL_UID (y));
5157 /* Return the DIE associated with a given declaration. */
5159 static inline dw_die_ref
5160 lookup_decl_die (tree decl)
5162 return decl_die_table->find_with_hash (decl, DECL_UID (decl));
5165 /* Returns a hash value for X (which really is a var_loc_list). */
5168 decl_loc_hasher::hash (var_loc_list *x)
5170 return (hashval_t) x->decl_id;
5173 /* Return nonzero if decl_id of var_loc_list X is the same as
5177 decl_loc_hasher::equal (var_loc_list *x, const_tree y)
5179 return (x->decl_id == DECL_UID (y));
5182 /* Return the var_loc list associated with a given declaration. */
5184 static inline var_loc_list *
5185 lookup_decl_loc (const_tree decl)
5187 if (!decl_loc_table)
5189 return decl_loc_table->find_with_hash (decl, DECL_UID (decl));
5192 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5195 dw_loc_list_hasher::hash (cached_dw_loc_list *x)
5197 return (hashval_t) x->decl_id;
5200 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5204 dw_loc_list_hasher::equal (cached_dw_loc_list *x, const_tree y)
5206 return (x->decl_id == DECL_UID (y));
5209 /* Equate a DIE to a particular declaration. */
5212 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5214 unsigned int decl_id = DECL_UID (decl);
5216 *decl_die_table->find_slot_with_hash (decl, decl_id, INSERT) = decl_die;
5217 decl_die->decl_id = decl_id;
5220 /* Return how many bits covers PIECE EXPR_LIST. */
5222 static HOST_WIDE_INT
5223 decl_piece_bitsize (rtx piece)
5225 int ret = (int) GET_MODE (piece);
5228 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
5229 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
5230 return INTVAL (XEXP (XEXP (piece, 0), 0));
5233 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5236 decl_piece_varloc_ptr (rtx piece)
5238 if ((int) GET_MODE (piece))
5239 return &XEXP (piece, 0);
5241 return &XEXP (XEXP (piece, 0), 1);
5244 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5245 Next is the chain of following piece nodes. */
5247 static rtx_expr_list *
5248 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
5250 if (bitsize > 0 && bitsize <= (int) MAX_MACHINE_MODE)
5251 return alloc_EXPR_LIST (bitsize, loc_note, next);
5253 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
5258 /* Return rtx that should be stored into loc field for
5259 LOC_NOTE and BITPOS/BITSIZE. */
5262 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
5263 HOST_WIDE_INT bitsize)
5267 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
5269 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
5274 /* This function either modifies location piece list *DEST in
5275 place (if SRC and INNER is NULL), or copies location piece list
5276 *SRC to *DEST while modifying it. Location BITPOS is modified
5277 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5278 not copied and if needed some padding around it is added.
5279 When modifying in place, DEST should point to EXPR_LIST where
5280 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5281 to the start of the whole list and INNER points to the EXPR_LIST
5282 where earlier pieces cover PIECE_BITPOS bits. */
5285 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
5286 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
5287 HOST_WIDE_INT bitsize, rtx loc_note)
5290 bool copy = inner != NULL;
5294 /* First copy all nodes preceding the current bitpos. */
5295 while (src != inner)
5297 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5298 decl_piece_bitsize (*src), NULL_RTX);
5299 dest = &XEXP (*dest, 1);
5300 src = &XEXP (*src, 1);
5303 /* Add padding if needed. */
5304 if (bitpos != piece_bitpos)
5306 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
5307 copy ? NULL_RTX : *dest);
5308 dest = &XEXP (*dest, 1);
5310 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
5313 /* A piece with correct bitpos and bitsize already exist,
5314 just update the location for it and return. */
5315 *decl_piece_varloc_ptr (*dest) = loc_note;
5318 /* Add the piece that changed. */
5319 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
5320 dest = &XEXP (*dest, 1);
5321 /* Skip over pieces that overlap it. */
5322 diff = bitpos - piece_bitpos + bitsize;
5325 while (diff > 0 && *src)
5328 diff -= decl_piece_bitsize (piece);
5330 src = &XEXP (piece, 1);
5333 *src = XEXP (piece, 1);
5334 free_EXPR_LIST_node (piece);
5337 /* Add padding if needed. */
5338 if (diff < 0 && *src)
5342 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
5343 dest = &XEXP (*dest, 1);
5347 /* Finally copy all nodes following it. */
5350 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5351 decl_piece_bitsize (*src), NULL_RTX);
5352 dest = &XEXP (*dest, 1);
5353 src = &XEXP (*src, 1);
5357 /* Add a variable location node to the linked list for DECL. */
5359 static struct var_loc_node *
5360 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
5362 unsigned int decl_id;
5364 struct var_loc_node *loc = NULL;
5365 HOST_WIDE_INT bitsize = -1, bitpos = -1;
5367 if (TREE_CODE (decl) == VAR_DECL
5368 && DECL_HAS_DEBUG_EXPR_P (decl))
5370 tree realdecl = DECL_DEBUG_EXPR (decl);
5371 if (handled_component_p (realdecl)
5372 || (TREE_CODE (realdecl) == MEM_REF
5373 && TREE_CODE (TREE_OPERAND (realdecl, 0)) == ADDR_EXPR))
5375 HOST_WIDE_INT maxsize;
5378 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize,
5380 if (!DECL_P (innerdecl)
5381 || DECL_IGNORED_P (innerdecl)
5382 || TREE_STATIC (innerdecl)
5384 || bitpos + bitsize > 256
5385 || bitsize != maxsize)
5391 decl_id = DECL_UID (decl);
5393 = decl_loc_table->find_slot_with_hash (decl, decl_id, INSERT);
5396 temp = ggc_cleared_alloc<var_loc_list> ();
5397 temp->decl_id = decl_id;
5403 /* For PARM_DECLs try to keep around the original incoming value,
5404 even if that means we'll emit a zero-range .debug_loc entry. */
5406 && temp->first == temp->last
5407 && TREE_CODE (decl) == PARM_DECL
5408 && NOTE_P (temp->first->loc)
5409 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
5410 && DECL_INCOMING_RTL (decl)
5411 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
5412 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
5413 == GET_CODE (DECL_INCOMING_RTL (decl))
5414 && prev_real_insn (temp->first->loc) == NULL_RTX
5416 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
5417 NOTE_VAR_LOCATION_LOC (loc_note))
5418 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
5419 != NOTE_VAR_LOCATION_STATUS (loc_note))))
5421 loc = ggc_cleared_alloc<var_loc_node> ();
5422 temp->first->next = loc;
5424 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5426 else if (temp->last)
5428 struct var_loc_node *last = temp->last, *unused = NULL;
5429 rtx *piece_loc = NULL, last_loc_note;
5430 HOST_WIDE_INT piece_bitpos = 0;
5434 gcc_assert (last->next == NULL);
5436 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
5438 piece_loc = &last->loc;
5441 HOST_WIDE_INT cur_bitsize = decl_piece_bitsize (*piece_loc);
5442 if (piece_bitpos + cur_bitsize > bitpos)
5444 piece_bitpos += cur_bitsize;
5445 piece_loc = &XEXP (*piece_loc, 1);
5449 /* TEMP->LAST here is either pointer to the last but one or
5450 last element in the chained list, LAST is pointer to the
5452 if (label && strcmp (last->label, label) == 0)
5454 /* For SRA optimized variables if there weren't any real
5455 insns since last note, just modify the last node. */
5456 if (piece_loc != NULL)
5458 adjust_piece_list (piece_loc, NULL, NULL,
5459 bitpos, piece_bitpos, bitsize, loc_note);
5462 /* If the last note doesn't cover any instructions, remove it. */
5463 if (temp->last != last)
5465 temp->last->next = NULL;
5468 gcc_assert (strcmp (last->label, label) != 0);
5472 gcc_assert (temp->first == temp->last
5473 || (temp->first->next == temp->last
5474 && TREE_CODE (decl) == PARM_DECL));
5475 memset (temp->last, '\0', sizeof (*temp->last));
5476 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
5480 if (bitsize == -1 && NOTE_P (last->loc))
5481 last_loc_note = last->loc;
5482 else if (piece_loc != NULL
5483 && *piece_loc != NULL_RTX
5484 && piece_bitpos == bitpos
5485 && decl_piece_bitsize (*piece_loc) == bitsize)
5486 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
5488 last_loc_note = NULL_RTX;
5489 /* If the current location is the same as the end of the list,
5490 and either both or neither of the locations is uninitialized,
5491 we have nothing to do. */
5492 if (last_loc_note == NULL_RTX
5493 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
5494 NOTE_VAR_LOCATION_LOC (loc_note)))
5495 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5496 != NOTE_VAR_LOCATION_STATUS (loc_note))
5497 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5498 == VAR_INIT_STATUS_UNINITIALIZED)
5499 || (NOTE_VAR_LOCATION_STATUS (loc_note)
5500 == VAR_INIT_STATUS_UNINITIALIZED))))
5502 /* Add LOC to the end of list and update LAST. If the last
5503 element of the list has been removed above, reuse its
5504 memory for the new node, otherwise allocate a new one. */
5508 memset (loc, '\0', sizeof (*loc));
5511 loc = ggc_cleared_alloc<var_loc_node> ();
5512 if (bitsize == -1 || piece_loc == NULL)
5513 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5515 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
5516 bitpos, piece_bitpos, bitsize, loc_note);
5518 /* Ensure TEMP->LAST will point either to the new last but one
5519 element of the chain, or to the last element in it. */
5520 if (last != temp->last)
5528 loc = ggc_cleared_alloc<var_loc_node> ();
5531 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5536 /* Keep track of the number of spaces used to indent the
5537 output of the debugging routines that print the structure of
5538 the DIE internal representation. */
5539 static int print_indent;
5541 /* Indent the line the number of spaces given by print_indent. */
5544 print_spaces (FILE *outfile)
5546 fprintf (outfile, "%*s", print_indent, "");
5549 /* Print a type signature in hex. */
5552 print_signature (FILE *outfile, char *sig)
5556 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
5557 fprintf (outfile, "%02x", sig[i] & 0xff);
5561 print_discr_value (FILE *outfile, dw_discr_value *discr_value)
5563 if (discr_value->pos)
5564 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, discr_value->v.sval);
5566 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, discr_value->v.uval);
5569 static void print_loc_descr (dw_loc_descr_ref, FILE *);
5571 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5572 RECURSE, output location descriptor operations. */
5575 print_dw_val (dw_val_node *val, bool recurse, FILE *outfile)
5577 switch (val->val_class)
5579 case dw_val_class_addr:
5580 fprintf (outfile, "address");
5582 case dw_val_class_offset:
5583 fprintf (outfile, "offset");
5585 case dw_val_class_loc:
5586 fprintf (outfile, "location descriptor");
5587 if (val->v.val_loc == NULL)
5588 fprintf (outfile, " -> <null>\n");
5591 fprintf (outfile, ":\n");
5593 print_loc_descr (val->v.val_loc, outfile);
5597 fprintf (outfile, " (%p)\n", (void *) val->v.val_loc);
5599 case dw_val_class_loc_list:
5600 fprintf (outfile, "location list -> label:%s",
5601 val->v.val_loc_list->ll_symbol);
5603 case dw_val_class_range_list:
5604 fprintf (outfile, "range list");
5606 case dw_val_class_const:
5607 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, val->v.val_int);
5609 case dw_val_class_unsigned_const:
5610 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, val->v.val_unsigned);
5612 case dw_val_class_const_double:
5613 fprintf (outfile, "constant (" HOST_WIDE_INT_PRINT_DEC","\
5614 HOST_WIDE_INT_PRINT_UNSIGNED")",
5615 val->v.val_double.high,
5616 val->v.val_double.low);
5618 case dw_val_class_wide_int:
5620 int i = val->v.val_wide->get_len ();
5621 fprintf (outfile, "constant (");
5623 if (val->v.val_wide->elt (i - 1) == 0)
5624 fprintf (outfile, "0x");
5625 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX,
5626 val->v.val_wide->elt (--i));
5628 fprintf (outfile, HOST_WIDE_INT_PRINT_PADDED_HEX,
5629 val->v.val_wide->elt (i));
5630 fprintf (outfile, ")");
5633 case dw_val_class_vec:
5634 fprintf (outfile, "floating-point or vector constant");
5636 case dw_val_class_flag:
5637 fprintf (outfile, "%u", val->v.val_flag);
5639 case dw_val_class_die_ref:
5640 if (val->v.val_die_ref.die != NULL)
5642 dw_die_ref die = val->v.val_die_ref.die;
5644 if (die->comdat_type_p)
5646 fprintf (outfile, "die -> signature: ");
5647 print_signature (outfile,
5648 die->die_id.die_type_node->signature);
5650 else if (die->die_id.die_symbol)
5651 fprintf (outfile, "die -> label: %s", die->die_id.die_symbol);
5653 fprintf (outfile, "die -> %ld", die->die_offset);
5654 fprintf (outfile, " (%p)", (void *) die);
5657 fprintf (outfile, "die -> <null>");
5659 case dw_val_class_vms_delta:
5660 fprintf (outfile, "delta: @slotcount(%s-%s)",
5661 val->v.val_vms_delta.lbl2, val->v.val_vms_delta.lbl1);
5663 case dw_val_class_lbl_id:
5664 case dw_val_class_lineptr:
5665 case dw_val_class_macptr:
5666 case dw_val_class_high_pc:
5667 fprintf (outfile, "label: %s", val->v.val_lbl_id);
5669 case dw_val_class_str:
5670 if (val->v.val_str->str != NULL)
5671 fprintf (outfile, "\"%s\"", val->v.val_str->str);
5673 fprintf (outfile, "<null>");
5675 case dw_val_class_file:
5676 fprintf (outfile, "\"%s\" (%d)", val->v.val_file->filename,
5677 val->v.val_file->emitted_number);
5679 case dw_val_class_data8:
5683 for (i = 0; i < 8; i++)
5684 fprintf (outfile, "%02x", val->v.val_data8[i]);
5687 case dw_val_class_discr_value:
5688 print_discr_value (outfile, &val->v.val_discr_value);
5690 case dw_val_class_discr_list:
5691 for (dw_discr_list_ref node = val->v.val_discr_list;
5693 node = node->dw_discr_next)
5695 if (node->dw_discr_range)
5697 fprintf (outfile, " .. ");
5698 print_discr_value (outfile, &node->dw_discr_lower_bound);
5699 print_discr_value (outfile, &node->dw_discr_upper_bound);
5702 print_discr_value (outfile, &node->dw_discr_lower_bound);
5704 if (node->dw_discr_next != NULL)
5705 fprintf (outfile, " | ");
5712 /* Likewise, for a DIE attribute. */
5715 print_attribute (dw_attr_node *a, bool recurse, FILE *outfile)
5717 print_dw_val (&a->dw_attr_val, recurse, outfile);
5721 /* Print the list of operands in the LOC location description to OUTFILE. This
5722 routine is a debugging aid only. */
5725 print_loc_descr (dw_loc_descr_ref loc, FILE *outfile)
5727 dw_loc_descr_ref l = loc;
5731 print_spaces (outfile);
5732 fprintf (outfile, "<null>\n");
5736 for (l = loc; l != NULL; l = l->dw_loc_next)
5738 print_spaces (outfile);
5739 fprintf (outfile, "(%p) %s",
5741 dwarf_stack_op_name (l->dw_loc_opc));
5742 if (l->dw_loc_oprnd1.val_class != dw_val_class_none)
5744 fprintf (outfile, " ");
5745 print_dw_val (&l->dw_loc_oprnd1, false, outfile);
5747 if (l->dw_loc_oprnd2.val_class != dw_val_class_none)
5749 fprintf (outfile, ", ");
5750 print_dw_val (&l->dw_loc_oprnd2, false, outfile);
5752 fprintf (outfile, "\n");
5756 /* Print the information associated with a given DIE, and its children.
5757 This routine is a debugging aid only. */
5760 print_die (dw_die_ref die, FILE *outfile)
5766 print_spaces (outfile);
5767 fprintf (outfile, "DIE %4ld: %s (%p)\n",
5768 die->die_offset, dwarf_tag_name (die->die_tag),
5770 print_spaces (outfile);
5771 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5772 fprintf (outfile, " offset: %ld", die->die_offset);
5773 fprintf (outfile, " mark: %d\n", die->die_mark);
5775 if (die->comdat_type_p)
5777 print_spaces (outfile);
5778 fprintf (outfile, " signature: ");
5779 print_signature (outfile, die->die_id.die_type_node->signature);
5780 fprintf (outfile, "\n");
5783 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5785 print_spaces (outfile);
5786 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5788 print_attribute (a, true, outfile);
5789 fprintf (outfile, "\n");
5792 if (die->die_child != NULL)
5795 FOR_EACH_CHILD (die, c, print_die (c, outfile));
5798 if (print_indent == 0)
5799 fprintf (outfile, "\n");
5802 /* Print the list of operations in the LOC location description. */
5805 debug_dwarf_loc_descr (dw_loc_descr_ref loc)
5807 print_loc_descr (loc, stderr);
5810 /* Print the information collected for a given DIE. */
5813 debug_dwarf_die (dw_die_ref die)
5815 print_die (die, stderr);
5819 debug (die_struct &ref)
5821 print_die (&ref, stderr);
5825 debug (die_struct *ptr)
5830 fprintf (stderr, "<nil>\n");
5834 /* Print all DWARF information collected for the compilation unit.
5835 This routine is a debugging aid only. */
5841 print_die (comp_unit_die (), stderr);
5844 /* Sanity checks on DIEs. */
5847 check_die (dw_die_ref die)
5851 bool inline_found = false;
5852 int n_location = 0, n_low_pc = 0, n_high_pc = 0, n_artificial = 0;
5853 int n_decl_line = 0, n_decl_file = 0;
5854 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5859 if (a->dw_attr_val.v.val_unsigned)
5860 inline_found = true;
5862 case DW_AT_location:
5871 case DW_AT_artificial:
5874 case DW_AT_decl_line:
5877 case DW_AT_decl_file:
5884 if (n_location > 1 || n_low_pc > 1 || n_high_pc > 1 || n_artificial > 1
5885 || n_decl_line > 1 || n_decl_file > 1)
5887 fprintf (stderr, "Duplicate attributes in DIE:\n");
5888 debug_dwarf_die (die);
5893 /* A debugging information entry that is a member of an abstract
5894 instance tree [that has DW_AT_inline] should not contain any
5895 attributes which describe aspects of the subroutine which vary
5896 between distinct inlined expansions or distinct out-of-line
5898 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5899 gcc_assert (a->dw_attr != DW_AT_low_pc
5900 && a->dw_attr != DW_AT_high_pc
5901 && a->dw_attr != DW_AT_location
5902 && a->dw_attr != DW_AT_frame_base
5903 && a->dw_attr != DW_AT_GNU_all_call_sites);
5907 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5908 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5909 DIE that marks the start of the DIEs for this include file. */
5912 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5914 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5915 dw_die_ref new_unit = gen_compile_unit_die (filename);
5917 new_unit->die_sib = old_unit;
5921 /* Close an include-file CU and reopen the enclosing one. */
5924 pop_compile_unit (dw_die_ref old_unit)
5926 dw_die_ref new_unit = old_unit->die_sib;
5928 old_unit->die_sib = NULL;
5932 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5933 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5934 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5936 /* Calculate the checksum of a location expression. */
5939 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5942 inchash::hash hstate;
5945 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
5947 hash_loc_operands (loc, hstate);
5948 hash = hstate.end();
5952 /* Calculate the checksum of an attribute. */
5955 attr_checksum (dw_attr_node *at, struct md5_ctx *ctx, int *mark)
5957 dw_loc_descr_ref loc;
5960 CHECKSUM (at->dw_attr);
5962 /* We don't care that this was compiled with a different compiler
5963 snapshot; if the output is the same, that's what matters. */
5964 if (at->dw_attr == DW_AT_producer)
5967 switch (AT_class (at))
5969 case dw_val_class_const:
5970 CHECKSUM (at->dw_attr_val.v.val_int);
5972 case dw_val_class_unsigned_const:
5973 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5975 case dw_val_class_const_double:
5976 CHECKSUM (at->dw_attr_val.v.val_double);
5978 case dw_val_class_wide_int:
5979 CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
5980 get_full_len (*at->dw_attr_val.v.val_wide)
5981 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
5983 case dw_val_class_vec:
5984 CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
5985 (at->dw_attr_val.v.val_vec.length
5986 * at->dw_attr_val.v.val_vec.elt_size));
5988 case dw_val_class_flag:
5989 CHECKSUM (at->dw_attr_val.v.val_flag);
5991 case dw_val_class_str:
5992 CHECKSUM_STRING (AT_string (at));
5995 case dw_val_class_addr:
5997 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5998 CHECKSUM_STRING (XSTR (r, 0));
6001 case dw_val_class_offset:
6002 CHECKSUM (at->dw_attr_val.v.val_offset);
6005 case dw_val_class_loc:
6006 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6007 loc_checksum (loc, ctx);
6010 case dw_val_class_die_ref:
6011 die_checksum (AT_ref (at), ctx, mark);
6014 case dw_val_class_fde_ref:
6015 case dw_val_class_vms_delta:
6016 case dw_val_class_lbl_id:
6017 case dw_val_class_lineptr:
6018 case dw_val_class_macptr:
6019 case dw_val_class_high_pc:
6022 case dw_val_class_file:
6023 CHECKSUM_STRING (AT_file (at)->filename);
6026 case dw_val_class_data8:
6027 CHECKSUM (at->dw_attr_val.v.val_data8);
6035 /* Calculate the checksum of a DIE. */
6038 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6044 /* To avoid infinite recursion. */
6047 CHECKSUM (die->die_mark);
6050 die->die_mark = ++(*mark);
6052 CHECKSUM (die->die_tag);
6054 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
6055 attr_checksum (a, ctx, mark);
6057 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6061 #undef CHECKSUM_BLOCK
6062 #undef CHECKSUM_STRING
6064 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6065 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6066 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6067 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6068 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6069 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6070 #define CHECKSUM_ATTR(FOO) \
6071 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6073 /* Calculate the checksum of a number in signed LEB128 format. */
6076 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
6083 byte = (value & 0x7f);
6085 more = !((value == 0 && (byte & 0x40) == 0)
6086 || (value == -1 && (byte & 0x40) != 0));
6095 /* Calculate the checksum of a number in unsigned LEB128 format. */
6098 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
6102 unsigned char byte = (value & 0x7f);
6105 /* More bytes to follow. */
6113 /* Checksum the context of the DIE. This adds the names of any
6114 surrounding namespaces or structures to the checksum. */
6117 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
6121 int tag = die->die_tag;
6123 if (tag != DW_TAG_namespace
6124 && tag != DW_TAG_structure_type
6125 && tag != DW_TAG_class_type)
6128 name = get_AT_string (die, DW_AT_name);
6130 spec = get_AT_ref (die, DW_AT_specification);
6134 if (die->die_parent != NULL)
6135 checksum_die_context (die->die_parent, ctx);
6137 CHECKSUM_ULEB128 ('C');
6138 CHECKSUM_ULEB128 (tag);
6140 CHECKSUM_STRING (name);
6143 /* Calculate the checksum of a location expression. */
6146 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6148 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6149 were emitted as a DW_FORM_sdata instead of a location expression. */
6150 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
6152 CHECKSUM_ULEB128 (DW_FORM_sdata);
6153 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
6157 /* Otherwise, just checksum the raw location expression. */
6160 inchash::hash hstate;
6163 CHECKSUM_ULEB128 (loc->dtprel);
6164 CHECKSUM_ULEB128 (loc->dw_loc_opc);
6165 hash_loc_operands (loc, hstate);
6166 hash = hstate.end ();
6168 loc = loc->dw_loc_next;
6172 /* Calculate the checksum of an attribute. */
6175 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_node *at,
6176 struct md5_ctx *ctx, int *mark)
6178 dw_loc_descr_ref loc;
6181 if (AT_class (at) == dw_val_class_die_ref)
6183 dw_die_ref target_die = AT_ref (at);
6185 /* For pointer and reference types, we checksum only the (qualified)
6186 name of the target type (if there is a name). For friend entries,
6187 we checksum only the (qualified) name of the target type or function.
6188 This allows the checksum to remain the same whether the target type
6189 is complete or not. */
6190 if ((at->dw_attr == DW_AT_type
6191 && (tag == DW_TAG_pointer_type
6192 || tag == DW_TAG_reference_type
6193 || tag == DW_TAG_rvalue_reference_type
6194 || tag == DW_TAG_ptr_to_member_type))
6195 || (at->dw_attr == DW_AT_friend
6196 && tag == DW_TAG_friend))
6198 dw_attr_node *name_attr = get_AT (target_die, DW_AT_name);
6200 if (name_attr != NULL)
6202 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
6206 CHECKSUM_ULEB128 ('N');
6207 CHECKSUM_ULEB128 (at->dw_attr);
6208 if (decl->die_parent != NULL)
6209 checksum_die_context (decl->die_parent, ctx);
6210 CHECKSUM_ULEB128 ('E');
6211 CHECKSUM_STRING (AT_string (name_attr));
6216 /* For all other references to another DIE, we check to see if the
6217 target DIE has already been visited. If it has, we emit a
6218 backward reference; if not, we descend recursively. */
6219 if (target_die->die_mark > 0)
6221 CHECKSUM_ULEB128 ('R');
6222 CHECKSUM_ULEB128 (at->dw_attr);
6223 CHECKSUM_ULEB128 (target_die->die_mark);
6227 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
6231 target_die->die_mark = ++(*mark);
6232 CHECKSUM_ULEB128 ('T');
6233 CHECKSUM_ULEB128 (at->dw_attr);
6234 if (decl->die_parent != NULL)
6235 checksum_die_context (decl->die_parent, ctx);
6236 die_checksum_ordered (target_die, ctx, mark);
6241 CHECKSUM_ULEB128 ('A');
6242 CHECKSUM_ULEB128 (at->dw_attr);
6244 switch (AT_class (at))
6246 case dw_val_class_const:
6247 CHECKSUM_ULEB128 (DW_FORM_sdata);
6248 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
6251 case dw_val_class_unsigned_const:
6252 CHECKSUM_ULEB128 (DW_FORM_sdata);
6253 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
6256 case dw_val_class_const_double:
6257 CHECKSUM_ULEB128 (DW_FORM_block);
6258 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
6259 CHECKSUM (at->dw_attr_val.v.val_double);
6262 case dw_val_class_wide_int:
6263 CHECKSUM_ULEB128 (DW_FORM_block);
6264 CHECKSUM_ULEB128 (get_full_len (*at->dw_attr_val.v.val_wide)
6265 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
6266 CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
6267 get_full_len (*at->dw_attr_val.v.val_wide)
6268 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
6271 case dw_val_class_vec:
6272 CHECKSUM_ULEB128 (DW_FORM_block);
6273 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_vec.length
6274 * at->dw_attr_val.v.val_vec.elt_size);
6275 CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
6276 (at->dw_attr_val.v.val_vec.length
6277 * at->dw_attr_val.v.val_vec.elt_size));
6280 case dw_val_class_flag:
6281 CHECKSUM_ULEB128 (DW_FORM_flag);
6282 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
6285 case dw_val_class_str:
6286 CHECKSUM_ULEB128 (DW_FORM_string);
6287 CHECKSUM_STRING (AT_string (at));
6290 case dw_val_class_addr:
6292 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6293 CHECKSUM_ULEB128 (DW_FORM_string);
6294 CHECKSUM_STRING (XSTR (r, 0));
6297 case dw_val_class_offset:
6298 CHECKSUM_ULEB128 (DW_FORM_sdata);
6299 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
6302 case dw_val_class_loc:
6303 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6304 loc_checksum_ordered (loc, ctx);
6307 case dw_val_class_fde_ref:
6308 case dw_val_class_lbl_id:
6309 case dw_val_class_lineptr:
6310 case dw_val_class_macptr:
6311 case dw_val_class_high_pc:
6314 case dw_val_class_file:
6315 CHECKSUM_ULEB128 (DW_FORM_string);
6316 CHECKSUM_STRING (AT_file (at)->filename);
6319 case dw_val_class_data8:
6320 CHECKSUM (at->dw_attr_val.v.val_data8);
6328 struct checksum_attributes
6330 dw_attr_node *at_name;
6331 dw_attr_node *at_type;
6332 dw_attr_node *at_friend;
6333 dw_attr_node *at_accessibility;
6334 dw_attr_node *at_address_class;
6335 dw_attr_node *at_allocated;
6336 dw_attr_node *at_artificial;
6337 dw_attr_node *at_associated;
6338 dw_attr_node *at_binary_scale;
6339 dw_attr_node *at_bit_offset;
6340 dw_attr_node *at_bit_size;
6341 dw_attr_node *at_bit_stride;
6342 dw_attr_node *at_byte_size;
6343 dw_attr_node *at_byte_stride;
6344 dw_attr_node *at_const_value;
6345 dw_attr_node *at_containing_type;
6346 dw_attr_node *at_count;
6347 dw_attr_node *at_data_location;
6348 dw_attr_node *at_data_member_location;
6349 dw_attr_node *at_decimal_scale;
6350 dw_attr_node *at_decimal_sign;
6351 dw_attr_node *at_default_value;
6352 dw_attr_node *at_digit_count;
6353 dw_attr_node *at_discr;
6354 dw_attr_node *at_discr_list;
6355 dw_attr_node *at_discr_value;
6356 dw_attr_node *at_encoding;
6357 dw_attr_node *at_endianity;
6358 dw_attr_node *at_explicit;
6359 dw_attr_node *at_is_optional;
6360 dw_attr_node *at_location;
6361 dw_attr_node *at_lower_bound;
6362 dw_attr_node *at_mutable;
6363 dw_attr_node *at_ordering;
6364 dw_attr_node *at_picture_string;
6365 dw_attr_node *at_prototyped;
6366 dw_attr_node *at_small;
6367 dw_attr_node *at_segment;
6368 dw_attr_node *at_string_length;
6369 dw_attr_node *at_threads_scaled;
6370 dw_attr_node *at_upper_bound;
6371 dw_attr_node *at_use_location;
6372 dw_attr_node *at_use_UTF8;
6373 dw_attr_node *at_variable_parameter;
6374 dw_attr_node *at_virtuality;
6375 dw_attr_node *at_visibility;
6376 dw_attr_node *at_vtable_elem_location;
6379 /* Collect the attributes that we will want to use for the checksum. */
6382 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
6387 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
6398 attrs->at_friend = a;
6400 case DW_AT_accessibility:
6401 attrs->at_accessibility = a;
6403 case DW_AT_address_class:
6404 attrs->at_address_class = a;
6406 case DW_AT_allocated:
6407 attrs->at_allocated = a;
6409 case DW_AT_artificial:
6410 attrs->at_artificial = a;
6412 case DW_AT_associated:
6413 attrs->at_associated = a;
6415 case DW_AT_binary_scale:
6416 attrs->at_binary_scale = a;
6418 case DW_AT_bit_offset:
6419 attrs->at_bit_offset = a;
6421 case DW_AT_bit_size:
6422 attrs->at_bit_size = a;
6424 case DW_AT_bit_stride:
6425 attrs->at_bit_stride = a;
6427 case DW_AT_byte_size:
6428 attrs->at_byte_size = a;
6430 case DW_AT_byte_stride:
6431 attrs->at_byte_stride = a;
6433 case DW_AT_const_value:
6434 attrs->at_const_value = a;
6436 case DW_AT_containing_type:
6437 attrs->at_containing_type = a;
6440 attrs->at_count = a;
6442 case DW_AT_data_location:
6443 attrs->at_data_location = a;
6445 case DW_AT_data_member_location:
6446 attrs->at_data_member_location = a;
6448 case DW_AT_decimal_scale:
6449 attrs->at_decimal_scale = a;
6451 case DW_AT_decimal_sign:
6452 attrs->at_decimal_sign = a;
6454 case DW_AT_default_value:
6455 attrs->at_default_value = a;
6457 case DW_AT_digit_count:
6458 attrs->at_digit_count = a;
6461 attrs->at_discr = a;
6463 case DW_AT_discr_list:
6464 attrs->at_discr_list = a;
6466 case DW_AT_discr_value:
6467 attrs->at_discr_value = a;
6469 case DW_AT_encoding:
6470 attrs->at_encoding = a;
6472 case DW_AT_endianity:
6473 attrs->at_endianity = a;
6475 case DW_AT_explicit:
6476 attrs->at_explicit = a;
6478 case DW_AT_is_optional:
6479 attrs->at_is_optional = a;
6481 case DW_AT_location:
6482 attrs->at_location = a;
6484 case DW_AT_lower_bound:
6485 attrs->at_lower_bound = a;
6488 attrs->at_mutable = a;
6490 case DW_AT_ordering:
6491 attrs->at_ordering = a;
6493 case DW_AT_picture_string:
6494 attrs->at_picture_string = a;
6496 case DW_AT_prototyped:
6497 attrs->at_prototyped = a;
6500 attrs->at_small = a;
6503 attrs->at_segment = a;
6505 case DW_AT_string_length:
6506 attrs->at_string_length = a;
6508 case DW_AT_threads_scaled:
6509 attrs->at_threads_scaled = a;
6511 case DW_AT_upper_bound:
6512 attrs->at_upper_bound = a;
6514 case DW_AT_use_location:
6515 attrs->at_use_location = a;
6517 case DW_AT_use_UTF8:
6518 attrs->at_use_UTF8 = a;
6520 case DW_AT_variable_parameter:
6521 attrs->at_variable_parameter = a;
6523 case DW_AT_virtuality:
6524 attrs->at_virtuality = a;
6526 case DW_AT_visibility:
6527 attrs->at_visibility = a;
6529 case DW_AT_vtable_elem_location:
6530 attrs->at_vtable_elem_location = a;
6538 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6541 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6545 struct checksum_attributes attrs;
6547 CHECKSUM_ULEB128 ('D');
6548 CHECKSUM_ULEB128 (die->die_tag);
6550 memset (&attrs, 0, sizeof (attrs));
6552 decl = get_AT_ref (die, DW_AT_specification);
6554 collect_checksum_attributes (&attrs, decl);
6555 collect_checksum_attributes (&attrs, die);
6557 CHECKSUM_ATTR (attrs.at_name);
6558 CHECKSUM_ATTR (attrs.at_accessibility);
6559 CHECKSUM_ATTR (attrs.at_address_class);
6560 CHECKSUM_ATTR (attrs.at_allocated);
6561 CHECKSUM_ATTR (attrs.at_artificial);
6562 CHECKSUM_ATTR (attrs.at_associated);
6563 CHECKSUM_ATTR (attrs.at_binary_scale);
6564 CHECKSUM_ATTR (attrs.at_bit_offset);
6565 CHECKSUM_ATTR (attrs.at_bit_size);
6566 CHECKSUM_ATTR (attrs.at_bit_stride);
6567 CHECKSUM_ATTR (attrs.at_byte_size);
6568 CHECKSUM_ATTR (attrs.at_byte_stride);
6569 CHECKSUM_ATTR (attrs.at_const_value);
6570 CHECKSUM_ATTR (attrs.at_containing_type);
6571 CHECKSUM_ATTR (attrs.at_count);
6572 CHECKSUM_ATTR (attrs.at_data_location);
6573 CHECKSUM_ATTR (attrs.at_data_member_location);
6574 CHECKSUM_ATTR (attrs.at_decimal_scale);
6575 CHECKSUM_ATTR (attrs.at_decimal_sign);
6576 CHECKSUM_ATTR (attrs.at_default_value);
6577 CHECKSUM_ATTR (attrs.at_digit_count);
6578 CHECKSUM_ATTR (attrs.at_discr);
6579 CHECKSUM_ATTR (attrs.at_discr_list);
6580 CHECKSUM_ATTR (attrs.at_discr_value);
6581 CHECKSUM_ATTR (attrs.at_encoding);
6582 CHECKSUM_ATTR (attrs.at_endianity);
6583 CHECKSUM_ATTR (attrs.at_explicit);
6584 CHECKSUM_ATTR (attrs.at_is_optional);
6585 CHECKSUM_ATTR (attrs.at_location);
6586 CHECKSUM_ATTR (attrs.at_lower_bound);
6587 CHECKSUM_ATTR (attrs.at_mutable);
6588 CHECKSUM_ATTR (attrs.at_ordering);
6589 CHECKSUM_ATTR (attrs.at_picture_string);
6590 CHECKSUM_ATTR (attrs.at_prototyped);
6591 CHECKSUM_ATTR (attrs.at_small);
6592 CHECKSUM_ATTR (attrs.at_segment);
6593 CHECKSUM_ATTR (attrs.at_string_length);
6594 CHECKSUM_ATTR (attrs.at_threads_scaled);
6595 CHECKSUM_ATTR (attrs.at_upper_bound);
6596 CHECKSUM_ATTR (attrs.at_use_location);
6597 CHECKSUM_ATTR (attrs.at_use_UTF8);
6598 CHECKSUM_ATTR (attrs.at_variable_parameter);
6599 CHECKSUM_ATTR (attrs.at_virtuality);
6600 CHECKSUM_ATTR (attrs.at_visibility);
6601 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
6602 CHECKSUM_ATTR (attrs.at_type);
6603 CHECKSUM_ATTR (attrs.at_friend);
6605 /* Checksum the child DIEs. */
6608 dw_attr_node *name_attr;
6611 name_attr = get_AT (c, DW_AT_name);
6612 if (is_template_instantiation (c))
6614 /* Ignore instantiations of member type and function templates. */
6616 else if (name_attr != NULL
6617 && (is_type_die (c) || c->die_tag == DW_TAG_subprogram))
6619 /* Use a shallow checksum for named nested types and member
6621 CHECKSUM_ULEB128 ('S');
6622 CHECKSUM_ULEB128 (c->die_tag);
6623 CHECKSUM_STRING (AT_string (name_attr));
6627 /* Use a deep checksum for other children. */
6628 /* Mark this DIE so it gets processed when unmarking. */
6629 if (c->die_mark == 0)
6631 die_checksum_ordered (c, ctx, mark);
6633 } while (c != die->die_child);
6635 CHECKSUM_ULEB128 (0);
6638 /* Add a type name and tag to a hash. */
6640 die_odr_checksum (int tag, const char *name, md5_ctx *ctx)
6642 CHECKSUM_ULEB128 (tag);
6643 CHECKSUM_STRING (name);
6647 #undef CHECKSUM_STRING
6648 #undef CHECKSUM_ATTR
6649 #undef CHECKSUM_LEB128
6650 #undef CHECKSUM_ULEB128
6652 /* Generate the type signature for DIE. This is computed by generating an
6653 MD5 checksum over the DIE's tag, its relevant attributes, and its
6654 children. Attributes that are references to other DIEs are processed
6655 by recursion, using the MARK field to prevent infinite recursion.
6656 If the DIE is nested inside a namespace or another type, we also
6657 need to include that context in the signature. The lower 64 bits
6658 of the resulting MD5 checksum comprise the signature. */
6661 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
6665 unsigned char checksum[16];
6670 name = get_AT_string (die, DW_AT_name);
6671 decl = get_AT_ref (die, DW_AT_specification);
6672 parent = get_die_parent (die);
6674 /* First, compute a signature for just the type name (and its surrounding
6675 context, if any. This is stored in the type unit DIE for link-time
6676 ODR (one-definition rule) checking. */
6678 if (is_cxx () && name != NULL)
6680 md5_init_ctx (&ctx);
6682 /* Checksum the names of surrounding namespaces and structures. */
6684 checksum_die_context (parent, &ctx);
6686 /* Checksum the current DIE. */
6687 die_odr_checksum (die->die_tag, name, &ctx);
6688 md5_finish_ctx (&ctx, checksum);
6690 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
6693 /* Next, compute the complete type signature. */
6695 md5_init_ctx (&ctx);
6697 die->die_mark = mark;
6699 /* Checksum the names of surrounding namespaces and structures. */
6701 checksum_die_context (parent, &ctx);
6703 /* Checksum the DIE and its children. */
6704 die_checksum_ordered (die, &ctx, &mark);
6705 unmark_all_dies (die);
6706 md5_finish_ctx (&ctx, checksum);
6708 /* Store the signature in the type node and link the type DIE and the
6709 type node together. */
6710 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
6711 DWARF_TYPE_SIGNATURE_SIZE);
6712 die->comdat_type_p = true;
6713 die->die_id.die_type_node = type_node;
6714 type_node->type_die = die;
6716 /* If the DIE is a specification, link its declaration to the type node
6720 decl->comdat_type_p = true;
6721 decl->die_id.die_type_node = type_node;
6725 /* Do the location expressions look same? */
6727 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6729 return loc1->dw_loc_opc == loc2->dw_loc_opc
6730 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6731 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6734 /* Do the values look the same? */
6736 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6738 dw_loc_descr_ref loc1, loc2;
6741 if (v1->val_class != v2->val_class)
6744 switch (v1->val_class)
6746 case dw_val_class_const:
6747 return v1->v.val_int == v2->v.val_int;
6748 case dw_val_class_unsigned_const:
6749 return v1->v.val_unsigned == v2->v.val_unsigned;
6750 case dw_val_class_const_double:
6751 return v1->v.val_double.high == v2->v.val_double.high
6752 && v1->v.val_double.low == v2->v.val_double.low;
6753 case dw_val_class_wide_int:
6754 return *v1->v.val_wide == *v2->v.val_wide;
6755 case dw_val_class_vec:
6756 if (v1->v.val_vec.length != v2->v.val_vec.length
6757 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6759 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6760 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6763 case dw_val_class_flag:
6764 return v1->v.val_flag == v2->v.val_flag;
6765 case dw_val_class_str:
6766 return !strcmp (v1->v.val_str->str, v2->v.val_str->str);
6768 case dw_val_class_addr:
6769 r1 = v1->v.val_addr;
6770 r2 = v2->v.val_addr;
6771 if (GET_CODE (r1) != GET_CODE (r2))
6773 return !rtx_equal_p (r1, r2);
6775 case dw_val_class_offset:
6776 return v1->v.val_offset == v2->v.val_offset;
6778 case dw_val_class_loc:
6779 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6781 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6782 if (!same_loc_p (loc1, loc2, mark))
6784 return !loc1 && !loc2;
6786 case dw_val_class_die_ref:
6787 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6789 case dw_val_class_fde_ref:
6790 case dw_val_class_vms_delta:
6791 case dw_val_class_lbl_id:
6792 case dw_val_class_lineptr:
6793 case dw_val_class_macptr:
6794 case dw_val_class_high_pc:
6797 case dw_val_class_file:
6798 return v1->v.val_file == v2->v.val_file;
6800 case dw_val_class_data8:
6801 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
6808 /* Do the attributes look the same? */
6811 same_attr_p (dw_attr_node *at1, dw_attr_node *at2, int *mark)
6813 if (at1->dw_attr != at2->dw_attr)
6816 /* We don't care that this was compiled with a different compiler
6817 snapshot; if the output is the same, that's what matters. */
6818 if (at1->dw_attr == DW_AT_producer)
6821 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6824 /* Do the dies look the same? */
6827 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6833 /* To avoid infinite recursion. */
6835 return die1->die_mark == die2->die_mark;
6836 die1->die_mark = die2->die_mark = ++(*mark);
6838 if (die1->die_tag != die2->die_tag)
6841 if (vec_safe_length (die1->die_attr) != vec_safe_length (die2->die_attr))
6844 FOR_EACH_VEC_SAFE_ELT (die1->die_attr, ix, a1)
6845 if (!same_attr_p (a1, &(*die2->die_attr)[ix], mark))
6848 c1 = die1->die_child;
6849 c2 = die2->die_child;
6858 if (!same_die_p (c1, c2, mark))
6862 if (c1 == die1->die_child)
6864 if (c2 == die2->die_child)
6874 /* Do the dies look the same? Wrapper around same_die_p. */
6877 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6880 int ret = same_die_p (die1, die2, &mark);
6882 unmark_all_dies (die1);
6883 unmark_all_dies (die2);
6888 /* The prefix to attach to symbols on DIEs in the current comdat debug
6890 static const char *comdat_symbol_id;
6892 /* The index of the current symbol within the current comdat CU. */
6893 static unsigned int comdat_symbol_number;
6895 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6896 children, and set comdat_symbol_id accordingly. */
6899 compute_section_prefix (dw_die_ref unit_die)
6901 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6902 const char *base = die_name ? lbasename (die_name) : "anonymous";
6903 char *name = XALLOCAVEC (char, strlen (base) + 64);
6906 unsigned char checksum[16];
6909 /* Compute the checksum of the DIE, then append part of it as hex digits to
6910 the name filename of the unit. */
6912 md5_init_ctx (&ctx);
6914 die_checksum (unit_die, &ctx, &mark);
6915 unmark_all_dies (unit_die);
6916 md5_finish_ctx (&ctx, checksum);
6918 sprintf (name, "%s.", base);
6919 clean_symbol_name (name);
6921 p = name + strlen (name);
6922 for (i = 0; i < 4; i++)
6924 sprintf (p, "%.2x", checksum[i]);
6928 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
6929 comdat_symbol_number = 0;
6932 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6935 is_type_die (dw_die_ref die)
6937 switch (die->die_tag)
6939 case DW_TAG_array_type:
6940 case DW_TAG_class_type:
6941 case DW_TAG_interface_type:
6942 case DW_TAG_enumeration_type:
6943 case DW_TAG_pointer_type:
6944 case DW_TAG_reference_type:
6945 case DW_TAG_rvalue_reference_type:
6946 case DW_TAG_string_type:
6947 case DW_TAG_structure_type:
6948 case DW_TAG_subroutine_type:
6949 case DW_TAG_union_type:
6950 case DW_TAG_ptr_to_member_type:
6951 case DW_TAG_set_type:
6952 case DW_TAG_subrange_type:
6953 case DW_TAG_base_type:
6954 case DW_TAG_const_type:
6955 case DW_TAG_file_type:
6956 case DW_TAG_packed_type:
6957 case DW_TAG_volatile_type:
6958 case DW_TAG_typedef:
6965 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6966 Basically, we want to choose the bits that are likely to be shared between
6967 compilations (types) and leave out the bits that are specific to individual
6968 compilations (functions). */
6971 is_comdat_die (dw_die_ref c)
6973 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6974 we do for stabs. The advantage is a greater likelihood of sharing between
6975 objects that don't include headers in the same order (and therefore would
6976 put the base types in a different comdat). jason 8/28/00 */
6978 if (c->die_tag == DW_TAG_base_type)
6981 if (c->die_tag == DW_TAG_pointer_type
6982 || c->die_tag == DW_TAG_reference_type
6983 || c->die_tag == DW_TAG_rvalue_reference_type
6984 || c->die_tag == DW_TAG_const_type
6985 || c->die_tag == DW_TAG_volatile_type)
6987 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6989 return t ? is_comdat_die (t) : 0;
6992 return is_type_die (c);
6995 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6996 compilation unit. */
6999 is_symbol_die (dw_die_ref c)
7001 return (is_type_die (c)
7002 || is_declaration_die (c)
7003 || c->die_tag == DW_TAG_namespace
7004 || c->die_tag == DW_TAG_module);
7007 /* Returns true iff C is a compile-unit DIE. */
7010 is_cu_die (dw_die_ref c)
7012 return c && c->die_tag == DW_TAG_compile_unit;
7015 /* Returns true iff C is a unit DIE of some sort. */
7018 is_unit_die (dw_die_ref c)
7020 return c && (c->die_tag == DW_TAG_compile_unit
7021 || c->die_tag == DW_TAG_partial_unit
7022 || c->die_tag == DW_TAG_type_unit);
7025 /* Returns true iff C is a namespace DIE. */
7028 is_namespace_die (dw_die_ref c)
7030 return c && c->die_tag == DW_TAG_namespace;
7033 /* Returns true iff C is a class or structure DIE. */
7036 is_class_die (dw_die_ref c)
7038 return c && (c->die_tag == DW_TAG_class_type
7039 || c->die_tag == DW_TAG_structure_type);
7042 /* Return non-zero if this DIE is a template parameter. */
7045 is_template_parameter (dw_die_ref die)
7047 switch (die->die_tag)
7049 case DW_TAG_template_type_param:
7050 case DW_TAG_template_value_param:
7051 case DW_TAG_GNU_template_template_param:
7052 case DW_TAG_GNU_template_parameter_pack:
7059 /* Return non-zero if this DIE represents a template instantiation. */
7062 is_template_instantiation (dw_die_ref die)
7066 if (!is_type_die (die) && die->die_tag != DW_TAG_subprogram)
7068 FOR_EACH_CHILD (die, c, if (is_template_parameter (c)) return true);
7073 gen_internal_sym (const char *prefix)
7077 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
7078 return xstrdup (buf);
7081 /* Assign symbols to all worthy DIEs under DIE. */
7084 assign_symbol_names (dw_die_ref die)
7088 if (is_symbol_die (die) && !die->comdat_type_p)
7090 if (comdat_symbol_id)
7092 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
7094 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
7095 comdat_symbol_id, comdat_symbol_number++);
7096 die->die_id.die_symbol = xstrdup (p);
7099 die->die_id.die_symbol = gen_internal_sym ("LDIE");
7102 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
7105 struct cu_hash_table_entry
7108 unsigned min_comdat_num, max_comdat_num;
7109 struct cu_hash_table_entry *next;
7112 /* Helpers to manipulate hash table of CUs. */
7114 struct cu_hash_table_entry_hasher : pointer_hash <cu_hash_table_entry>
7116 typedef die_struct *compare_type;
7117 static inline hashval_t hash (const cu_hash_table_entry *);
7118 static inline bool equal (const cu_hash_table_entry *, const die_struct *);
7119 static inline void remove (cu_hash_table_entry *);
7123 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry *entry)
7125 return htab_hash_string (entry->cu->die_id.die_symbol);
7129 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry *entry1,
7130 const die_struct *entry2)
7132 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
7136 cu_hash_table_entry_hasher::remove (cu_hash_table_entry *entry)
7138 struct cu_hash_table_entry *next;
7148 typedef hash_table<cu_hash_table_entry_hasher> cu_hash_type;
7150 /* Check whether we have already seen this CU and set up SYM_NUM
7153 check_duplicate_cu (dw_die_ref cu, cu_hash_type *htable, unsigned int *sym_num)
7155 struct cu_hash_table_entry dummy;
7156 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7158 dummy.max_comdat_num = 0;
7160 slot = htable->find_slot_with_hash (cu,
7161 htab_hash_string (cu->die_id.die_symbol),
7165 for (; entry; last = entry, entry = entry->next)
7167 if (same_die_p_wrap (cu, entry->cu))
7173 *sym_num = entry->min_comdat_num;
7177 entry = XCNEW (struct cu_hash_table_entry);
7179 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7180 entry->next = *slot;
7186 /* Record SYM_NUM to record of CU in HTABLE. */
7188 record_comdat_symbol_number (dw_die_ref cu, cu_hash_type *htable,
7189 unsigned int sym_num)
7191 struct cu_hash_table_entry **slot, *entry;
7193 slot = htable->find_slot_with_hash (cu,
7194 htab_hash_string (cu->die_id.die_symbol),
7198 entry->max_comdat_num = sym_num;
7201 /* Traverse the DIE (which is always comp_unit_die), and set up
7202 additional compilation units for each of the include files we see
7203 bracketed by BINCL/EINCL. */
7206 break_out_includes (dw_die_ref die)
7209 dw_die_ref unit = NULL;
7210 limbo_die_node *node, **pnode;
7214 dw_die_ref prev = c;
7216 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7217 || (unit && is_comdat_die (c)))
7219 dw_die_ref next = c->die_sib;
7221 /* This DIE is for a secondary CU; remove it from the main one. */
7222 remove_child_with_prev (c, prev);
7224 if (c->die_tag == DW_TAG_GNU_BINCL)
7225 unit = push_new_compile_unit (unit, c);
7226 else if (c->die_tag == DW_TAG_GNU_EINCL)
7227 unit = pop_compile_unit (unit);
7229 add_child_die (unit, c);
7231 if (c == die->die_child)
7234 } while (c != die->die_child);
7237 /* We can only use this in debugging, since the frontend doesn't check
7238 to make sure that we leave every include file we enter. */
7242 assign_symbol_names (die);
7243 cu_hash_type cu_hash_table (10);
7244 for (node = limbo_die_list, pnode = &limbo_die_list;
7250 compute_section_prefix (node->die);
7251 is_dupl = check_duplicate_cu (node->die, &cu_hash_table,
7252 &comdat_symbol_number);
7253 assign_symbol_names (node->die);
7255 *pnode = node->next;
7258 pnode = &node->next;
7259 record_comdat_symbol_number (node->die, &cu_hash_table,
7260 comdat_symbol_number);
7265 /* Return non-zero if this DIE is a declaration. */
7268 is_declaration_die (dw_die_ref die)
7273 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7274 if (a->dw_attr == DW_AT_declaration)
7280 /* Return non-zero if this DIE is nested inside a subprogram. */
7283 is_nested_in_subprogram (dw_die_ref die)
7285 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
7289 return local_scope_p (decl);
7292 /* Return non-zero if this DIE contains a defining declaration of a
7296 contains_subprogram_definition (dw_die_ref die)
7300 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
7302 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition (c)) return 1);
7306 /* Return non-zero if this is a type DIE that should be moved to a
7307 COMDAT .debug_types section. */
7310 should_move_die_to_comdat (dw_die_ref die)
7312 switch (die->die_tag)
7314 case DW_TAG_class_type:
7315 case DW_TAG_structure_type:
7316 case DW_TAG_enumeration_type:
7317 case DW_TAG_union_type:
7318 /* Don't move declarations, inlined instances, types nested in a
7319 subprogram, or types that contain subprogram definitions. */
7320 if (is_declaration_die (die)
7321 || get_AT (die, DW_AT_abstract_origin)
7322 || is_nested_in_subprogram (die)
7323 || contains_subprogram_definition (die))
7326 case DW_TAG_array_type:
7327 case DW_TAG_interface_type:
7328 case DW_TAG_pointer_type:
7329 case DW_TAG_reference_type:
7330 case DW_TAG_rvalue_reference_type:
7331 case DW_TAG_string_type:
7332 case DW_TAG_subroutine_type:
7333 case DW_TAG_ptr_to_member_type:
7334 case DW_TAG_set_type:
7335 case DW_TAG_subrange_type:
7336 case DW_TAG_base_type:
7337 case DW_TAG_const_type:
7338 case DW_TAG_file_type:
7339 case DW_TAG_packed_type:
7340 case DW_TAG_volatile_type:
7341 case DW_TAG_typedef:
7347 /* Make a clone of DIE. */
7350 clone_die (dw_die_ref die)
7356 clone = ggc_cleared_alloc<die_node> ();
7357 clone->die_tag = die->die_tag;
7359 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7360 add_dwarf_attr (clone, a);
7365 /* Make a clone of the tree rooted at DIE. */
7368 clone_tree (dw_die_ref die)
7371 dw_die_ref clone = clone_die (die);
7373 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree (c)));
7378 /* Make a clone of DIE as a declaration. */
7381 clone_as_declaration (dw_die_ref die)
7388 /* If the DIE is already a declaration, just clone it. */
7389 if (is_declaration_die (die))
7390 return clone_die (die);
7392 /* If the DIE is a specification, just clone its declaration DIE. */
7393 decl = get_AT_ref (die, DW_AT_specification);
7396 clone = clone_die (decl);
7397 if (die->comdat_type_p)
7398 add_AT_die_ref (clone, DW_AT_signature, die);
7402 clone = ggc_cleared_alloc<die_node> ();
7403 clone->die_tag = die->die_tag;
7405 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7407 /* We don't want to copy over all attributes.
7408 For example we don't want DW_AT_byte_size because otherwise we will no
7409 longer have a declaration and GDB will treat it as a definition. */
7413 case DW_AT_abstract_origin:
7414 case DW_AT_artificial:
7415 case DW_AT_containing_type:
7416 case DW_AT_external:
7419 case DW_AT_virtuality:
7420 case DW_AT_linkage_name:
7421 case DW_AT_MIPS_linkage_name:
7422 add_dwarf_attr (clone, a);
7424 case DW_AT_byte_size:
7430 if (die->comdat_type_p)
7431 add_AT_die_ref (clone, DW_AT_signature, die);
7433 add_AT_flag (clone, DW_AT_declaration, 1);
7438 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7440 struct decl_table_entry
7446 /* Helpers to manipulate hash table of copied declarations. */
7448 /* Hashtable helpers. */
7450 struct decl_table_entry_hasher : free_ptr_hash <decl_table_entry>
7452 typedef die_struct *compare_type;
7453 static inline hashval_t hash (const decl_table_entry *);
7454 static inline bool equal (const decl_table_entry *, const die_struct *);
7458 decl_table_entry_hasher::hash (const decl_table_entry *entry)
7460 return htab_hash_pointer (entry->orig);
7464 decl_table_entry_hasher::equal (const decl_table_entry *entry1,
7465 const die_struct *entry2)
7467 return entry1->orig == entry2;
7470 typedef hash_table<decl_table_entry_hasher> decl_hash_type;
7472 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7473 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7474 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7475 to check if the ancestor has already been copied into UNIT. */
7478 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die,
7479 decl_hash_type *decl_table)
7481 dw_die_ref parent = die->die_parent;
7482 dw_die_ref new_parent = unit;
7484 decl_table_entry **slot = NULL;
7485 struct decl_table_entry *entry = NULL;
7489 /* Check if the entry has already been copied to UNIT. */
7490 slot = decl_table->find_slot_with_hash (die, htab_hash_pointer (die),
7492 if (*slot != HTAB_EMPTY_ENTRY)
7498 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7499 entry = XCNEW (struct decl_table_entry);
7507 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
7510 if (!is_unit_die (parent))
7511 new_parent = copy_ancestor_tree (unit, parent, decl_table);
7514 copy = clone_as_declaration (die);
7515 add_child_die (new_parent, copy);
7519 /* Record the pointer to the copy. */
7525 /* Copy the declaration context to the new type unit DIE. This includes
7526 any surrounding namespace or type declarations. If the DIE has an
7527 AT_specification attribute, it also includes attributes and children
7528 attached to the specification, and returns a pointer to the original
7529 parent of the declaration DIE. Returns NULL otherwise. */
7532 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
7535 dw_die_ref new_decl;
7536 dw_die_ref orig_parent = NULL;
7538 decl = get_AT_ref (die, DW_AT_specification);
7547 /* The original DIE will be changed to a declaration, and must
7548 be moved to be a child of the original declaration DIE. */
7549 orig_parent = decl->die_parent;
7551 /* Copy the type node pointer from the new DIE to the original
7552 declaration DIE so we can forward references later. */
7553 decl->comdat_type_p = true;
7554 decl->die_id.die_type_node = die->die_id.die_type_node;
7556 remove_AT (die, DW_AT_specification);
7558 FOR_EACH_VEC_SAFE_ELT (decl->die_attr, ix, a)
7560 if (a->dw_attr != DW_AT_name
7561 && a->dw_attr != DW_AT_declaration
7562 && a->dw_attr != DW_AT_external)
7563 add_dwarf_attr (die, a);
7566 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree (c)));
7569 if (decl->die_parent != NULL
7570 && !is_unit_die (decl->die_parent))
7572 new_decl = copy_ancestor_tree (unit, decl, NULL);
7573 if (new_decl != NULL)
7575 remove_AT (new_decl, DW_AT_signature);
7576 add_AT_specification (die, new_decl);
7583 /* Generate the skeleton ancestor tree for the given NODE, then clone
7584 the DIE and add the clone into the tree. */
7587 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
7589 if (node->new_die != NULL)
7592 node->new_die = clone_as_declaration (node->old_die);
7594 if (node->parent != NULL)
7596 generate_skeleton_ancestor_tree (node->parent);
7597 add_child_die (node->parent->new_die, node->new_die);
7601 /* Generate a skeleton tree of DIEs containing any declarations that are
7602 found in the original tree. We traverse the tree looking for declaration
7603 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7606 generate_skeleton_bottom_up (skeleton_chain_node *parent)
7608 skeleton_chain_node node;
7611 dw_die_ref prev = NULL;
7612 dw_die_ref next = NULL;
7614 node.parent = parent;
7616 first = c = parent->old_die->die_child;
7620 if (prev == NULL || prev->die_sib == c)
7623 next = (c == first ? NULL : c->die_sib);
7625 node.new_die = NULL;
7626 if (is_declaration_die (c))
7628 if (is_template_instantiation (c))
7630 /* Instantiated templates do not need to be cloned into the
7631 type unit. Just move the DIE and its children back to
7632 the skeleton tree (in the main CU). */
7633 remove_child_with_prev (c, prev);
7634 add_child_die (parent->new_die, c);
7639 /* Clone the existing DIE, move the original to the skeleton
7640 tree (which is in the main CU), and put the clone, with
7641 all the original's children, where the original came from
7642 (which is about to be moved to the type unit). */
7643 dw_die_ref clone = clone_die (c);
7644 move_all_children (c, clone);
7646 /* If the original has a DW_AT_object_pointer attribute,
7647 it would now point to a child DIE just moved to the
7648 cloned tree, so we need to remove that attribute from
7650 remove_AT (c, DW_AT_object_pointer);
7652 replace_child (c, clone, prev);
7653 generate_skeleton_ancestor_tree (parent);
7654 add_child_die (parent->new_die, c);
7659 generate_skeleton_bottom_up (&node);
7660 } while (next != NULL);
7663 /* Wrapper function for generate_skeleton_bottom_up. */
7666 generate_skeleton (dw_die_ref die)
7668 skeleton_chain_node node;
7671 node.new_die = NULL;
7674 /* If this type definition is nested inside another type,
7675 and is not an instantiation of a template, always leave
7676 at least a declaration in its place. */
7677 if (die->die_parent != NULL
7678 && is_type_die (die->die_parent)
7679 && !is_template_instantiation (die))
7680 node.new_die = clone_as_declaration (die);
7682 generate_skeleton_bottom_up (&node);
7683 return node.new_die;
7686 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7687 declaration. The original DIE is moved to a new compile unit so that
7688 existing references to it follow it to the new location. If any of the
7689 original DIE's descendants is a declaration, we need to replace the
7690 original DIE with a skeleton tree and move the declarations back into the
7694 remove_child_or_replace_with_skeleton (dw_die_ref unit, dw_die_ref child,
7697 dw_die_ref skeleton, orig_parent;
7699 /* Copy the declaration context to the type unit DIE. If the returned
7700 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7702 orig_parent = copy_declaration_context (unit, child);
7704 skeleton = generate_skeleton (child);
7705 if (skeleton == NULL)
7706 remove_child_with_prev (child, prev);
7709 skeleton->comdat_type_p = true;
7710 skeleton->die_id.die_type_node = child->die_id.die_type_node;
7712 /* If the original DIE was a specification, we need to put
7713 the skeleton under the parent DIE of the declaration.
7714 This leaves the original declaration in the tree, but
7715 it will be pruned later since there are no longer any
7716 references to it. */
7717 if (orig_parent != NULL)
7719 remove_child_with_prev (child, prev);
7720 add_child_die (orig_parent, skeleton);
7723 replace_child (child, skeleton, prev);
7730 copy_dwarf_procs_ref_in_attrs (dw_die_ref die,
7731 comdat_type_node *type_node,
7732 hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs);
7734 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
7735 procedure, put it under TYPE_NODE and return the copy. Continue looking for
7736 DWARF procedure references in the DW_AT_location attribute. */
7739 copy_dwarf_procedure (dw_die_ref die,
7740 comdat_type_node *type_node,
7741 hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs)
7743 /* We do this for COMDAT section, which is DWARFv4 specific, so
7744 DWARF procedure are always DW_TAG_dwarf_procedure DIEs (unlike
7745 DW_TAG_variable in DWARFv3). */
7746 gcc_assert (die->die_tag == DW_TAG_dwarf_procedure);
7748 /* DWARF procedures are not supposed to have children... */
7749 gcc_assert (die->die_child == NULL);
7751 /* ... and they are supposed to have only one attribute: DW_AT_location. */
7752 gcc_assert (vec_safe_length (die->die_attr) == 1
7753 && ((*die->die_attr)[0].dw_attr == DW_AT_location));
7755 /* Do not copy more than once DWARF procedures. */
7757 dw_die_ref &die_copy = copied_dwarf_procs.get_or_insert (die, &existed);
7761 die_copy = clone_die (die);
7762 add_child_die (type_node->root_die, die_copy);
7763 copy_dwarf_procs_ref_in_attrs (die_copy, type_node, copied_dwarf_procs);
7767 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
7768 procedures in DIE's attributes. */
7771 copy_dwarf_procs_ref_in_attrs (dw_die_ref die,
7772 comdat_type_node *type_node,
7773 hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs)
7778 FOR_EACH_VEC_SAFE_ELT (die->die_attr, i, a)
7780 dw_loc_descr_ref loc;
7782 if (a->dw_attr_val.val_class != dw_val_class_loc)
7785 for (loc = a->dw_attr_val.v.val_loc; loc != NULL; loc = loc->dw_loc_next)
7787 switch (loc->dw_loc_opc)
7791 case DW_OP_call_ref:
7792 gcc_assert (loc->dw_loc_oprnd1.val_class
7793 == dw_val_class_die_ref);
7794 loc->dw_loc_oprnd1.v.val_die_ref.die
7795 = copy_dwarf_procedure (loc->dw_loc_oprnd1.v.val_die_ref.die,
7797 copied_dwarf_procs);
7806 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
7807 rewrite references to point to the copies.
7809 References are looked for in DIE's attributes and recursively in all its
7810 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
7811 mapping from old DWARF procedures to their copy. It is used not to copy
7812 twice the same DWARF procedure under TYPE_NODE. */
7815 copy_dwarf_procs_ref_in_dies (dw_die_ref die,
7816 comdat_type_node *type_node,
7817 hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs)
7821 copy_dwarf_procs_ref_in_attrs (die, type_node, copied_dwarf_procs);
7822 FOR_EACH_CHILD (die, c, copy_dwarf_procs_ref_in_dies (c,
7824 copied_dwarf_procs));
7827 /* Traverse the DIE and set up additional .debug_types sections for each
7828 type worthy of being placed in a COMDAT section. */
7831 break_out_comdat_types (dw_die_ref die)
7835 dw_die_ref prev = NULL;
7836 dw_die_ref next = NULL;
7837 dw_die_ref unit = NULL;
7839 first = c = die->die_child;
7843 if (prev == NULL || prev->die_sib == c)
7846 next = (c == first ? NULL : c->die_sib);
7847 if (should_move_die_to_comdat (c))
7849 dw_die_ref replacement;
7850 comdat_type_node *type_node;
7852 /* Break out nested types into their own type units. */
7853 break_out_comdat_types (c);
7855 /* Create a new type unit DIE as the root for the new tree, and
7856 add it to the list of comdat types. */
7857 unit = new_die (DW_TAG_type_unit, NULL, NULL);
7858 add_AT_unsigned (unit, DW_AT_language,
7859 get_AT_unsigned (comp_unit_die (), DW_AT_language));
7860 type_node = ggc_cleared_alloc<comdat_type_node> ();
7861 type_node->root_die = unit;
7862 type_node->next = comdat_type_list;
7863 comdat_type_list = type_node;
7865 /* Generate the type signature. */
7866 generate_type_signature (c, type_node);
7868 /* Copy the declaration context, attributes, and children of the
7869 declaration into the new type unit DIE, then remove this DIE
7870 from the main CU (or replace it with a skeleton if necessary). */
7871 replacement = remove_child_or_replace_with_skeleton (unit, c, prev);
7872 type_node->skeleton_die = replacement;
7874 /* Add the DIE to the new compunit. */
7875 add_child_die (unit, c);
7877 /* Types can reference DWARF procedures for type size or data location
7878 expressions. Calls in DWARF expressions cannot target procedures
7879 that are not in the same section. So we must copy DWARF procedures
7880 along with this type and then rewrite references to them. */
7881 hash_map<dw_die_ref, dw_die_ref> copied_dwarf_procs;
7882 copy_dwarf_procs_ref_in_dies (c, type_node, copied_dwarf_procs);
7884 if (replacement != NULL)
7887 else if (c->die_tag == DW_TAG_namespace
7888 || c->die_tag == DW_TAG_class_type
7889 || c->die_tag == DW_TAG_structure_type
7890 || c->die_tag == DW_TAG_union_type)
7892 /* Look for nested types that can be broken out. */
7893 break_out_comdat_types (c);
7895 } while (next != NULL);
7898 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7899 Enter all the cloned children into the hash table decl_table. */
7902 clone_tree_partial (dw_die_ref die, decl_hash_type *decl_table)
7906 struct decl_table_entry *entry;
7907 decl_table_entry **slot;
7909 if (die->die_tag == DW_TAG_subprogram)
7910 clone = clone_as_declaration (die);
7912 clone = clone_die (die);
7914 slot = decl_table->find_slot_with_hash (die,
7915 htab_hash_pointer (die), INSERT);
7917 /* Assert that DIE isn't in the hash table yet. If it would be there
7918 before, the ancestors would be necessarily there as well, therefore
7919 clone_tree_partial wouldn't be called. */
7920 gcc_assert (*slot == HTAB_EMPTY_ENTRY);
7922 entry = XCNEW (struct decl_table_entry);
7924 entry->copy = clone;
7927 if (die->die_tag != DW_TAG_subprogram)
7928 FOR_EACH_CHILD (die, c,
7929 add_child_die (clone, clone_tree_partial (c, decl_table)));
7934 /* Walk the DIE and its children, looking for references to incomplete
7935 or trivial types that are unmarked (i.e., that are not in the current
7939 copy_decls_walk (dw_die_ref unit, dw_die_ref die, decl_hash_type *decl_table)
7945 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7947 if (AT_class (a) == dw_val_class_die_ref)
7949 dw_die_ref targ = AT_ref (a);
7950 decl_table_entry **slot;
7951 struct decl_table_entry *entry;
7953 if (targ->die_mark != 0 || targ->comdat_type_p)
7956 slot = decl_table->find_slot_with_hash (targ,
7957 htab_hash_pointer (targ),
7960 if (*slot != HTAB_EMPTY_ENTRY)
7962 /* TARG has already been copied, so we just need to
7963 modify the reference to point to the copy. */
7965 a->dw_attr_val.v.val_die_ref.die = entry->copy;
7969 dw_die_ref parent = unit;
7970 dw_die_ref copy = clone_die (targ);
7972 /* Record in DECL_TABLE that TARG has been copied.
7973 Need to do this now, before the recursive call,
7974 because DECL_TABLE may be expanded and SLOT
7975 would no longer be a valid pointer. */
7976 entry = XCNEW (struct decl_table_entry);
7981 /* If TARG is not a declaration DIE, we need to copy its
7983 if (!is_declaration_die (targ))
7987 add_child_die (copy,
7988 clone_tree_partial (c, decl_table)));
7991 /* Make sure the cloned tree is marked as part of the
7995 /* If TARG has surrounding context, copy its ancestor tree
7996 into the new type unit. */
7997 if (targ->die_parent != NULL
7998 && !is_unit_die (targ->die_parent))
7999 parent = copy_ancestor_tree (unit, targ->die_parent,
8002 add_child_die (parent, copy);
8003 a->dw_attr_val.v.val_die_ref.die = copy;
8005 /* Make sure the newly-copied DIE is walked. If it was
8006 installed in a previously-added context, it won't
8007 get visited otherwise. */
8010 /* Find the highest point of the newly-added tree,
8011 mark each node along the way, and walk from there. */
8012 parent->die_mark = 1;
8013 while (parent->die_parent
8014 && parent->die_parent->die_mark == 0)
8016 parent = parent->die_parent;
8017 parent->die_mark = 1;
8019 copy_decls_walk (unit, parent, decl_table);
8025 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
8028 /* Copy declarations for "unworthy" types into the new comdat section.
8029 Incomplete types, modified types, and certain other types aren't broken
8030 out into comdat sections of their own, so they don't have a signature,
8031 and we need to copy the declaration into the same section so that we
8032 don't have an external reference. */
8035 copy_decls_for_unworthy_types (dw_die_ref unit)
8038 decl_hash_type decl_table (10);
8039 copy_decls_walk (unit, unit, &decl_table);
8043 /* Traverse the DIE and add a sibling attribute if it may have the
8044 effect of speeding up access to siblings. To save some space,
8045 avoid generating sibling attributes for DIE's without children. */
8048 add_sibling_attributes (dw_die_ref die)
8052 if (! die->die_child)
8055 if (die->die_parent && die != die->die_parent->die_child)
8056 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
8058 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
8061 /* Output all location lists for the DIE and its children. */
8064 output_location_lists (dw_die_ref die)
8070 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8071 if (AT_class (a) == dw_val_class_loc_list)
8072 output_loc_list (AT_loc_list (a));
8074 FOR_EACH_CHILD (die, c, output_location_lists (c));
8077 /* We want to limit the number of external references, because they are
8078 larger than local references: a relocation takes multiple words, and
8079 even a sig8 reference is always eight bytes, whereas a local reference
8080 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8081 So if we encounter multiple external references to the same type DIE, we
8082 make a local typedef stub for it and redirect all references there.
8084 This is the element of the hash table for keeping track of these
8094 /* Hashtable helpers. */
8096 struct external_ref_hasher : free_ptr_hash <external_ref>
8098 static inline hashval_t hash (const external_ref *);
8099 static inline bool equal (const external_ref *, const external_ref *);
8103 external_ref_hasher::hash (const external_ref *r)
8105 dw_die_ref die = r->type;
8108 /* We can't use the address of the DIE for hashing, because
8109 that will make the order of the stub DIEs non-deterministic. */
8110 if (! die->comdat_type_p)
8111 /* We have a symbol; use it to compute a hash. */
8112 h = htab_hash_string (die->die_id.die_symbol);
8115 /* We have a type signature; use a subset of the bits as the hash.
8116 The 8-byte signature is at least as large as hashval_t. */
8117 comdat_type_node *type_node = die->die_id.die_type_node;
8118 memcpy (&h, type_node->signature, sizeof (h));
8124 external_ref_hasher::equal (const external_ref *r1, const external_ref *r2)
8126 return r1->type == r2->type;
8129 typedef hash_table<external_ref_hasher> external_ref_hash_type;
8131 /* Return a pointer to the external_ref for references to DIE. */
8133 static struct external_ref *
8134 lookup_external_ref (external_ref_hash_type *map, dw_die_ref die)
8136 struct external_ref ref, *ref_p;
8137 external_ref **slot;
8140 slot = map->find_slot (&ref, INSERT);
8141 if (*slot != HTAB_EMPTY_ENTRY)
8144 ref_p = XCNEW (struct external_ref);
8150 /* Subroutine of optimize_external_refs, below.
8152 If we see a type skeleton, record it as our stub. If we see external
8153 references, remember how many we've seen. */
8156 optimize_external_refs_1 (dw_die_ref die, external_ref_hash_type *map)
8161 struct external_ref *ref_p;
8163 if (is_type_die (die)
8164 && (c = get_AT_ref (die, DW_AT_signature)))
8166 /* This is a local skeleton; use it for local references. */
8167 ref_p = lookup_external_ref (map, c);
8171 /* Scan the DIE references, and remember any that refer to DIEs from
8172 other CUs (i.e. those which are not marked). */
8173 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8174 if (AT_class (a) == dw_val_class_die_ref
8175 && (c = AT_ref (a))->die_mark == 0
8178 ref_p = lookup_external_ref (map, c);
8182 FOR_EACH_CHILD (die, c, optimize_external_refs_1 (c, map));
8185 /* htab_traverse callback function for optimize_external_refs, below. SLOT
8186 points to an external_ref, DATA is the CU we're processing. If we don't
8187 already have a local stub, and we have multiple refs, build a stub. */
8190 dwarf2_build_local_stub (external_ref **slot, dw_die_ref data)
8192 struct external_ref *ref_p = *slot;
8194 if (ref_p->stub == NULL && ref_p->n_refs > 1 && !dwarf_strict)
8196 /* We have multiple references to this type, so build a small stub.
8197 Both of these forms are a bit dodgy from the perspective of the
8198 DWARF standard, since technically they should have names. */
8199 dw_die_ref cu = data;
8200 dw_die_ref type = ref_p->type;
8201 dw_die_ref stub = NULL;
8203 if (type->comdat_type_p)
8205 /* If we refer to this type via sig8, use AT_signature. */
8206 stub = new_die (type->die_tag, cu, NULL_TREE);
8207 add_AT_die_ref (stub, DW_AT_signature, type);
8211 /* Otherwise, use a typedef with no name. */
8212 stub = new_die (DW_TAG_typedef, cu, NULL_TREE);
8213 add_AT_die_ref (stub, DW_AT_type, type);
8222 /* DIE is a unit; look through all the DIE references to see if there are
8223 any external references to types, and if so, create local stubs for
8224 them which will be applied in build_abbrev_table. This is useful because
8225 references to local DIEs are smaller. */
8227 static external_ref_hash_type *
8228 optimize_external_refs (dw_die_ref die)
8230 external_ref_hash_type *map = new external_ref_hash_type (10);
8231 optimize_external_refs_1 (die, map);
8232 map->traverse <dw_die_ref, dwarf2_build_local_stub> (die);
8236 /* The format of each DIE (and its attribute value pairs) is encoded in an
8237 abbreviation table. This routine builds the abbreviation table and assigns
8238 a unique abbreviation id for each abbreviation entry. The children of each
8239 die are visited recursively. */
8242 build_abbrev_table (dw_die_ref die, external_ref_hash_type *extern_map)
8244 unsigned long abbrev_id;
8245 unsigned int n_alloc;
8250 /* Scan the DIE references, and replace any that refer to
8251 DIEs from other CUs (i.e. those which are not marked) with
8252 the local stubs we built in optimize_external_refs. */
8253 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8254 if (AT_class (a) == dw_val_class_die_ref
8255 && (c = AT_ref (a))->die_mark == 0)
8257 struct external_ref *ref_p;
8258 gcc_assert (AT_ref (a)->comdat_type_p || AT_ref (a)->die_id.die_symbol);
8260 ref_p = lookup_external_ref (extern_map, c);
8261 if (ref_p->stub && ref_p->stub != die)
8262 change_AT_die_ref (a, ref_p->stub);
8264 /* We aren't changing this reference, so mark it external. */
8265 set_AT_ref_external (a, 1);
8268 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8270 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8271 dw_attr_node *die_a, *abbrev_a;
8275 if (abbrev->die_tag != die->die_tag)
8277 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
8280 if (vec_safe_length (abbrev->die_attr) != vec_safe_length (die->die_attr))
8283 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, die_a)
8285 abbrev_a = &(*abbrev->die_attr)[ix];
8286 if ((abbrev_a->dw_attr != die_a->dw_attr)
8287 || (value_format (abbrev_a) != value_format (die_a)))
8297 if (abbrev_id >= abbrev_die_table_in_use)
8299 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
8301 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
8302 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
8305 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
8306 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
8307 abbrev_die_table_allocated = n_alloc;
8310 ++abbrev_die_table_in_use;
8311 abbrev_die_table[abbrev_id] = die;
8314 die->die_abbrev = abbrev_id;
8315 FOR_EACH_CHILD (die, c, build_abbrev_table (c, extern_map));
8318 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8321 constant_size (unsigned HOST_WIDE_INT value)
8328 log = floor_log2 (value);
8331 log = 1 << (floor_log2 (log) + 1);
8336 /* Return the size of a DIE as it is represented in the
8337 .debug_info section. */
8339 static unsigned long
8340 size_of_die (dw_die_ref die)
8342 unsigned long size = 0;
8345 enum dwarf_form form;
8347 size += size_of_uleb128 (die->die_abbrev);
8348 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8350 switch (AT_class (a))
8352 case dw_val_class_addr:
8353 if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
8355 gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
8356 size += size_of_uleb128 (AT_index (a));
8359 size += DWARF2_ADDR_SIZE;
8361 case dw_val_class_offset:
8362 size += DWARF_OFFSET_SIZE;
8364 case dw_val_class_loc:
8366 unsigned long lsize = size_of_locs (AT_loc (a));
8369 if (dwarf_version >= 4)
8370 size += size_of_uleb128 (lsize);
8372 size += constant_size (lsize);
8376 case dw_val_class_loc_list:
8377 if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
8379 gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
8380 size += size_of_uleb128 (AT_index (a));
8383 size += DWARF_OFFSET_SIZE;
8385 case dw_val_class_range_list:
8386 size += DWARF_OFFSET_SIZE;
8388 case dw_val_class_const:
8389 size += size_of_sleb128 (AT_int (a));
8391 case dw_val_class_unsigned_const:
8393 int csize = constant_size (AT_unsigned (a));
8394 if (dwarf_version == 3
8395 && a->dw_attr == DW_AT_data_member_location
8397 size += size_of_uleb128 (AT_unsigned (a));
8402 case dw_val_class_const_double:
8403 size += HOST_BITS_PER_DOUBLE_INT / HOST_BITS_PER_CHAR;
8404 if (HOST_BITS_PER_WIDE_INT >= 64)
8407 case dw_val_class_wide_int:
8408 size += (get_full_len (*a->dw_attr_val.v.val_wide)
8409 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
8410 if (get_full_len (*a->dw_attr_val.v.val_wide) * HOST_BITS_PER_WIDE_INT
8414 case dw_val_class_vec:
8415 size += constant_size (a->dw_attr_val.v.val_vec.length
8416 * a->dw_attr_val.v.val_vec.elt_size)
8417 + a->dw_attr_val.v.val_vec.length
8418 * a->dw_attr_val.v.val_vec.elt_size; /* block */
8420 case dw_val_class_flag:
8421 if (dwarf_version >= 4)
8422 /* Currently all add_AT_flag calls pass in 1 as last argument,
8423 so DW_FORM_flag_present can be used. If that ever changes,
8424 we'll need to use DW_FORM_flag and have some optimization
8425 in build_abbrev_table that will change those to
8426 DW_FORM_flag_present if it is set to 1 in all DIEs using
8427 the same abbrev entry. */
8428 gcc_assert (a->dw_attr_val.v.val_flag == 1);
8432 case dw_val_class_die_ref:
8433 if (AT_ref_external (a))
8435 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8436 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8437 is sized by target address length, whereas in DWARF3
8438 it's always sized as an offset. */
8439 if (use_debug_types)
8440 size += DWARF_TYPE_SIGNATURE_SIZE;
8441 else if (dwarf_version == 2)
8442 size += DWARF2_ADDR_SIZE;
8444 size += DWARF_OFFSET_SIZE;
8447 size += DWARF_OFFSET_SIZE;
8449 case dw_val_class_fde_ref:
8450 size += DWARF_OFFSET_SIZE;
8452 case dw_val_class_lbl_id:
8453 if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
8455 gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
8456 size += size_of_uleb128 (AT_index (a));
8459 size += DWARF2_ADDR_SIZE;
8461 case dw_val_class_lineptr:
8462 case dw_val_class_macptr:
8463 size += DWARF_OFFSET_SIZE;
8465 case dw_val_class_str:
8466 form = AT_string_form (a);
8467 if (form == DW_FORM_strp)
8468 size += DWARF_OFFSET_SIZE;
8469 else if (form == DW_FORM_GNU_str_index)
8470 size += size_of_uleb128 (AT_index (a));
8472 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
8474 case dw_val_class_file:
8475 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
8477 case dw_val_class_data8:
8480 case dw_val_class_vms_delta:
8481 size += DWARF_OFFSET_SIZE;
8483 case dw_val_class_high_pc:
8484 size += DWARF2_ADDR_SIZE;
8486 case dw_val_class_discr_value:
8487 size += size_of_discr_value (&a->dw_attr_val.v.val_discr_value);
8489 case dw_val_class_discr_list:
8491 unsigned block_size = size_of_discr_list (AT_discr_list (a));
8493 /* This is a block, so we have the block length and then its
8495 size += constant_size (block_size) + block_size;
8506 /* Size the debugging information associated with a given DIE. Visits the
8507 DIE's children recursively. Updates the global variable next_die_offset, on
8508 each time through. Uses the current value of next_die_offset to update the
8509 die_offset field in each DIE. */
8512 calc_die_sizes (dw_die_ref die)
8516 gcc_assert (die->die_offset == 0
8517 || (unsigned long int) die->die_offset == next_die_offset);
8518 die->die_offset = next_die_offset;
8519 next_die_offset += size_of_die (die);
8521 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
8523 if (die->die_child != NULL)
8524 /* Count the null byte used to terminate sibling lists. */
8525 next_die_offset += 1;
8528 /* Size just the base type children at the start of the CU.
8529 This is needed because build_abbrev needs to size locs
8530 and sizing of type based stack ops needs to know die_offset
8531 values for the base types. */
8534 calc_base_type_die_sizes (void)
8536 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8538 dw_die_ref base_type;
8539 #if ENABLE_ASSERT_CHECKING
8540 dw_die_ref prev = comp_unit_die ()->die_child;
8543 die_offset += size_of_die (comp_unit_die ());
8544 for (i = 0; base_types.iterate (i, &base_type); i++)
8546 #if ENABLE_ASSERT_CHECKING
8547 gcc_assert (base_type->die_offset == 0
8548 && prev->die_sib == base_type
8549 && base_type->die_child == NULL
8550 && base_type->die_abbrev);
8553 base_type->die_offset = die_offset;
8554 die_offset += size_of_die (base_type);
8558 /* Set the marks for a die and its children. We do this so
8559 that we know whether or not a reference needs to use FORM_ref_addr; only
8560 DIEs in the same CU will be marked. We used to clear out the offset
8561 and use that as the flag, but ran into ordering problems. */
8564 mark_dies (dw_die_ref die)
8568 gcc_assert (!die->die_mark);
8571 FOR_EACH_CHILD (die, c, mark_dies (c));
8574 /* Clear the marks for a die and its children. */
8577 unmark_dies (dw_die_ref die)
8581 if (! use_debug_types)
8582 gcc_assert (die->die_mark);
8585 FOR_EACH_CHILD (die, c, unmark_dies (c));
8588 /* Clear the marks for a die, its children and referred dies. */
8591 unmark_all_dies (dw_die_ref die)
8601 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8603 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8604 if (AT_class (a) == dw_val_class_die_ref)
8605 unmark_all_dies (AT_ref (a));
8608 /* Calculate if the entry should appear in the final output file. It may be
8609 from a pruned a type. */
8612 include_pubname_in_output (vec<pubname_entry, va_gc> *table, pubname_entry *p)
8614 /* By limiting gnu pubnames to definitions only, gold can generate a
8615 gdb index without entries for declarations, which don't include
8616 enough information to be useful. */
8617 if (debug_generate_pub_sections == 2 && is_declaration_die (p->die))
8620 if (table == pubname_table)
8622 /* Enumerator names are part of the pubname table, but the
8623 parent DW_TAG_enumeration_type die may have been pruned.
8624 Don't output them if that is the case. */
8625 if (p->die->die_tag == DW_TAG_enumerator &&
8626 (p->die->die_parent == NULL
8627 || !p->die->die_parent->die_perennial_p))
8630 /* Everything else in the pubname table is included. */
8634 /* The pubtypes table shouldn't include types that have been
8636 return (p->die->die_offset != 0
8637 || !flag_eliminate_unused_debug_types);
8640 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8641 generated for the compilation unit. */
8643 static unsigned long
8644 size_of_pubnames (vec<pubname_entry, va_gc> *names)
8649 int space_for_flags = (debug_generate_pub_sections == 2) ? 1 : 0;
8651 size = DWARF_PUBNAMES_HEADER_SIZE;
8652 FOR_EACH_VEC_ELT (*names, i, p)
8653 if (include_pubname_in_output (names, p))
8654 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1 + space_for_flags;
8656 size += DWARF_OFFSET_SIZE;
8660 /* Return the size of the information in the .debug_aranges section. */
8662 static unsigned long
8663 size_of_aranges (void)
8667 size = DWARF_ARANGES_HEADER_SIZE;
8669 /* Count the address/length pair for this compilation unit. */
8670 if (text_section_used)
8671 size += 2 * DWARF2_ADDR_SIZE;
8672 if (cold_text_section_used)
8673 size += 2 * DWARF2_ADDR_SIZE;
8674 if (have_multiple_function_sections)
8679 FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
8681 if (DECL_IGNORED_P (fde->decl))
8683 if (!fde->in_std_section)
8684 size += 2 * DWARF2_ADDR_SIZE;
8685 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
8686 size += 2 * DWARF2_ADDR_SIZE;
8690 /* Count the two zero words used to terminated the address range table. */
8691 size += 2 * DWARF2_ADDR_SIZE;
8695 /* Select the encoding of an attribute value. */
8697 static enum dwarf_form
8698 value_format (dw_attr_node *a)
8700 switch (AT_class (a))
8702 case dw_val_class_addr:
8703 /* Only very few attributes allow DW_FORM_addr. */
8708 case DW_AT_entry_pc:
8709 case DW_AT_trampoline:
8710 return (AT_index (a) == NOT_INDEXED
8711 ? DW_FORM_addr : DW_FORM_GNU_addr_index);
8715 switch (DWARF2_ADDR_SIZE)
8718 return DW_FORM_data1;
8720 return DW_FORM_data2;
8722 return DW_FORM_data4;
8724 return DW_FORM_data8;
8728 case dw_val_class_range_list:
8729 case dw_val_class_loc_list:
8730 if (dwarf_version >= 4)
8731 return DW_FORM_sec_offset;
8733 case dw_val_class_vms_delta:
8734 case dw_val_class_offset:
8735 switch (DWARF_OFFSET_SIZE)
8738 return DW_FORM_data4;
8740 return DW_FORM_data8;
8744 case dw_val_class_loc:
8745 if (dwarf_version >= 4)
8746 return DW_FORM_exprloc;
8747 switch (constant_size (size_of_locs (AT_loc (a))))
8750 return DW_FORM_block1;
8752 return DW_FORM_block2;
8754 return DW_FORM_block4;
8758 case dw_val_class_const:
8759 return DW_FORM_sdata;
8760 case dw_val_class_unsigned_const:
8761 switch (constant_size (AT_unsigned (a)))
8764 return DW_FORM_data1;
8766 return DW_FORM_data2;
8768 /* In DWARF3 DW_AT_data_member_location with
8769 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8770 constant, so we need to use DW_FORM_udata if we need
8771 a large constant. */
8772 if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
8773 return DW_FORM_udata;
8774 return DW_FORM_data4;
8776 if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
8777 return DW_FORM_udata;
8778 return DW_FORM_data8;
8782 case dw_val_class_const_double:
8783 switch (HOST_BITS_PER_WIDE_INT)
8786 return DW_FORM_data2;
8788 return DW_FORM_data4;
8790 return DW_FORM_data8;
8793 return DW_FORM_block1;
8795 case dw_val_class_wide_int:
8796 switch (get_full_len (*a->dw_attr_val.v.val_wide) * HOST_BITS_PER_WIDE_INT)
8799 return DW_FORM_data1;
8801 return DW_FORM_data2;
8803 return DW_FORM_data4;
8805 return DW_FORM_data8;
8807 return DW_FORM_block1;
8809 case dw_val_class_vec:
8810 switch (constant_size (a->dw_attr_val.v.val_vec.length
8811 * a->dw_attr_val.v.val_vec.elt_size))
8814 return DW_FORM_block1;
8816 return DW_FORM_block2;
8818 return DW_FORM_block4;
8822 case dw_val_class_flag:
8823 if (dwarf_version >= 4)
8825 /* Currently all add_AT_flag calls pass in 1 as last argument,
8826 so DW_FORM_flag_present can be used. If that ever changes,
8827 we'll need to use DW_FORM_flag and have some optimization
8828 in build_abbrev_table that will change those to
8829 DW_FORM_flag_present if it is set to 1 in all DIEs using
8830 the same abbrev entry. */
8831 gcc_assert (a->dw_attr_val.v.val_flag == 1);
8832 return DW_FORM_flag_present;
8834 return DW_FORM_flag;
8835 case dw_val_class_die_ref:
8836 if (AT_ref_external (a))
8837 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
8840 case dw_val_class_fde_ref:
8841 return DW_FORM_data;
8842 case dw_val_class_lbl_id:
8843 return (AT_index (a) == NOT_INDEXED
8844 ? DW_FORM_addr : DW_FORM_GNU_addr_index);
8845 case dw_val_class_lineptr:
8846 case dw_val_class_macptr:
8847 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
8848 case dw_val_class_str:
8849 return AT_string_form (a);
8850 case dw_val_class_file:
8851 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8854 return DW_FORM_data1;
8856 return DW_FORM_data2;
8858 return DW_FORM_data4;
8863 case dw_val_class_data8:
8864 return DW_FORM_data8;
8866 case dw_val_class_high_pc:
8867 switch (DWARF2_ADDR_SIZE)
8870 return DW_FORM_data1;
8872 return DW_FORM_data2;
8874 return DW_FORM_data4;
8876 return DW_FORM_data8;
8881 case dw_val_class_discr_value:
8882 return (a->dw_attr_val.v.val_discr_value.pos
8885 case dw_val_class_discr_list:
8886 switch (constant_size (size_of_discr_list (AT_discr_list (a))))
8889 return DW_FORM_block1;
8891 return DW_FORM_block2;
8893 return DW_FORM_block4;
8903 /* Output the encoding of an attribute value. */
8906 output_value_format (dw_attr_node *a)
8908 enum dwarf_form form = value_format (a);
8910 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8913 /* Given a die and id, produce the appropriate abbreviations. */
8916 output_die_abbrevs (unsigned long abbrev_id, dw_die_ref abbrev)
8919 dw_attr_node *a_attr;
8921 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8922 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8923 dwarf_tag_name (abbrev->die_tag));
8925 if (abbrev->die_child != NULL)
8926 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8928 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8930 for (ix = 0; vec_safe_iterate (abbrev->die_attr, ix, &a_attr); ix++)
8932 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8933 dwarf_attr_name (a_attr->dw_attr));
8934 output_value_format (a_attr);
8937 dw2_asm_output_data (1, 0, NULL);
8938 dw2_asm_output_data (1, 0, NULL);
8942 /* Output the .debug_abbrev section which defines the DIE abbreviation
8946 output_abbrev_section (void)
8948 unsigned long abbrev_id;
8950 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8951 output_die_abbrevs (abbrev_id, abbrev_die_table[abbrev_id]);
8953 /* Terminate the table. */
8954 dw2_asm_output_data (1, 0, NULL);
8957 /* Output a symbol we can use to refer to this DIE from another CU. */
8960 output_die_symbol (dw_die_ref die)
8962 const char *sym = die->die_id.die_symbol;
8964 gcc_assert (!die->comdat_type_p);
8969 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8970 /* We make these global, not weak; if the target doesn't support
8971 .linkonce, it doesn't support combining the sections, so debugging
8973 targetm.asm_out.globalize_label (asm_out_file, sym);
8975 ASM_OUTPUT_LABEL (asm_out_file, sym);
8978 /* Return a new location list, given the begin and end range, and the
8981 static inline dw_loc_list_ref
8982 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8983 const char *section)
8985 dw_loc_list_ref retlist = ggc_cleared_alloc<dw_loc_list_node> ();
8987 retlist->begin = begin;
8988 retlist->begin_entry = NULL;
8990 retlist->expr = expr;
8991 retlist->section = section;
8996 /* Generate a new internal symbol for this location list node, if it
8997 hasn't got one yet. */
9000 gen_llsym (dw_loc_list_ref list)
9002 gcc_assert (!list->ll_symbol);
9003 list->ll_symbol = gen_internal_sym ("LLST");
9006 /* Output the location list given to us. */
9009 output_loc_list (dw_loc_list_ref list_head)
9011 dw_loc_list_ref curr = list_head;
9013 if (list_head->emitted)
9015 list_head->emitted = true;
9017 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
9019 /* Walk the location list, and output each range + expression. */
9020 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
9023 /* Don't output an entry that starts and ends at the same address. */
9024 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
9026 size = size_of_locs (curr->expr);
9027 /* If the expression is too large, drop it on the floor. We could
9028 perhaps put it into DW_TAG_dwarf_procedure and refer to that
9029 in the expression, but >= 64KB expressions for a single value
9030 in a single range are unlikely very useful. */
9033 if (dwarf_split_debug_info)
9035 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry,
9036 "Location list start/length entry (%s)",
9037 list_head->ll_symbol);
9038 dw2_asm_output_data_uleb128 (curr->begin_entry->index,
9039 "Location list range start index (%s)",
9041 /* The length field is 4 bytes. If we ever need to support
9042 an 8-byte length, we can add a new DW_LLE code or fall back
9043 to DW_LLE_GNU_start_end_entry. */
9044 dw2_asm_output_delta (4, curr->end, curr->begin,
9045 "Location list range length (%s)",
9046 list_head->ll_symbol);
9048 else if (!have_multiple_function_sections)
9050 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
9051 "Location list begin address (%s)",
9052 list_head->ll_symbol);
9053 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
9054 "Location list end address (%s)",
9055 list_head->ll_symbol);
9059 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
9060 "Location list begin address (%s)",
9061 list_head->ll_symbol);
9062 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
9063 "Location list end address (%s)",
9064 list_head->ll_symbol);
9067 /* Output the block length for this list of location operations. */
9068 gcc_assert (size <= 0xffff);
9069 dw2_asm_output_data (2, size, "%s", "Location expression size");
9071 output_loc_sequence (curr->expr, -1);
9074 if (dwarf_split_debug_info)
9075 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry,
9076 "Location list terminator (%s)",
9077 list_head->ll_symbol);
9080 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
9081 "Location list terminator begin (%s)",
9082 list_head->ll_symbol);
9083 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
9084 "Location list terminator end (%s)",
9085 list_head->ll_symbol);
9089 /* Output a range_list offset into the debug_range section. Emit a
9090 relocated reference if val_entry is NULL, otherwise, emit an
9091 indirect reference. */
9094 output_range_list_offset (dw_attr_node *a)
9096 const char *name = dwarf_attr_name (a->dw_attr);
9098 if (a->dw_attr_val.val_entry == RELOCATED_OFFSET)
9100 char *p = strchr (ranges_section_label, '\0');
9101 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX, a->dw_attr_val.v.val_offset);
9102 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
9103 debug_ranges_section, "%s", name);
9107 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
9108 "%s (offset from %s)", name, ranges_section_label);
9111 /* Output the offset into the debug_loc section. */
9114 output_loc_list_offset (dw_attr_node *a)
9116 char *sym = AT_loc_list (a)->ll_symbol;
9119 if (dwarf_split_debug_info)
9120 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label,
9121 "%s", dwarf_attr_name (a->dw_attr));
9123 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
9124 "%s", dwarf_attr_name (a->dw_attr));
9127 /* Output an attribute's index or value appropriately. */
9130 output_attr_index_or_value (dw_attr_node *a)
9132 const char *name = dwarf_attr_name (a->dw_attr);
9134 if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
9136 dw2_asm_output_data_uleb128 (AT_index (a), "%s", name);
9139 switch (AT_class (a))
9141 case dw_val_class_addr:
9142 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
9144 case dw_val_class_high_pc:
9145 case dw_val_class_lbl_id:
9146 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
9148 case dw_val_class_loc_list:
9149 output_loc_list_offset (a);
9156 /* Output a type signature. */
9159 output_signature (const char *sig, const char *name)
9163 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
9164 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
9167 /* Output a discriminant value. */
9170 output_discr_value (dw_discr_value *discr_value, const char *name)
9172 if (discr_value->pos)
9173 dw2_asm_output_data_uleb128 (discr_value->v.uval, "%s", name);
9175 dw2_asm_output_data_sleb128 (discr_value->v.sval, "%s", name);
9178 /* Output the DIE and its attributes. Called recursively to generate
9179 the definitions of each child DIE. */
9182 output_die (dw_die_ref die)
9189 /* If someone in another CU might refer to us, set up a symbol for
9190 them to point to. */
9191 if (! die->comdat_type_p && die->die_id.die_symbol)
9192 output_die_symbol (die);
9194 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
9195 (unsigned long)die->die_offset,
9196 dwarf_tag_name (die->die_tag));
9198 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9200 const char *name = dwarf_attr_name (a->dw_attr);
9202 switch (AT_class (a))
9204 case dw_val_class_addr:
9205 output_attr_index_or_value (a);
9208 case dw_val_class_offset:
9209 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
9213 case dw_val_class_range_list:
9214 output_range_list_offset (a);
9217 case dw_val_class_loc:
9218 size = size_of_locs (AT_loc (a));
9220 /* Output the block length for this list of location operations. */
9221 if (dwarf_version >= 4)
9222 dw2_asm_output_data_uleb128 (size, "%s", name);
9224 dw2_asm_output_data (constant_size (size), size, "%s", name);
9226 output_loc_sequence (AT_loc (a), -1);
9229 case dw_val_class_const:
9230 /* ??? It would be slightly more efficient to use a scheme like is
9231 used for unsigned constants below, but gdb 4.x does not sign
9232 extend. Gdb 5.x does sign extend. */
9233 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
9236 case dw_val_class_unsigned_const:
9238 int csize = constant_size (AT_unsigned (a));
9239 if (dwarf_version == 3
9240 && a->dw_attr == DW_AT_data_member_location
9242 dw2_asm_output_data_uleb128 (AT_unsigned (a), "%s", name);
9244 dw2_asm_output_data (csize, AT_unsigned (a), "%s", name);
9248 case dw_val_class_const_double:
9250 unsigned HOST_WIDE_INT first, second;
9252 if (HOST_BITS_PER_WIDE_INT >= 64)
9253 dw2_asm_output_data (1,
9254 HOST_BITS_PER_DOUBLE_INT
9255 / HOST_BITS_PER_CHAR,
9258 if (WORDS_BIG_ENDIAN)
9260 first = a->dw_attr_val.v.val_double.high;
9261 second = a->dw_attr_val.v.val_double.low;
9265 first = a->dw_attr_val.v.val_double.low;
9266 second = a->dw_attr_val.v.val_double.high;
9269 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
9271 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
9276 case dw_val_class_wide_int:
9279 int len = get_full_len (*a->dw_attr_val.v.val_wide);
9280 int l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
9281 if (len * HOST_BITS_PER_WIDE_INT > 64)
9282 dw2_asm_output_data (1, get_full_len (*a->dw_attr_val.v.val_wide) * l,
9285 if (WORDS_BIG_ENDIAN)
9286 for (i = len - 1; i >= 0; --i)
9288 dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
9293 for (i = 0; i < len; ++i)
9295 dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
9302 case dw_val_class_vec:
9304 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
9305 unsigned int len = a->dw_attr_val.v.val_vec.length;
9309 dw2_asm_output_data (constant_size (len * elt_size),
9310 len * elt_size, "%s", name);
9311 if (elt_size > sizeof (HOST_WIDE_INT))
9316 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
9319 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
9320 "fp or vector constant word %u", i);
9324 case dw_val_class_flag:
9325 if (dwarf_version >= 4)
9327 /* Currently all add_AT_flag calls pass in 1 as last argument,
9328 so DW_FORM_flag_present can be used. If that ever changes,
9329 we'll need to use DW_FORM_flag and have some optimization
9330 in build_abbrev_table that will change those to
9331 DW_FORM_flag_present if it is set to 1 in all DIEs using
9332 the same abbrev entry. */
9333 gcc_assert (AT_flag (a) == 1);
9335 fprintf (asm_out_file, "\t\t\t%s %s\n",
9336 ASM_COMMENT_START, name);
9339 dw2_asm_output_data (1, AT_flag (a), "%s", name);
9342 case dw_val_class_loc_list:
9343 output_attr_index_or_value (a);
9346 case dw_val_class_die_ref:
9347 if (AT_ref_external (a))
9349 if (AT_ref (a)->comdat_type_p)
9351 comdat_type_node *type_node =
9352 AT_ref (a)->die_id.die_type_node;
9354 gcc_assert (type_node);
9355 output_signature (type_node->signature, name);
9359 const char *sym = AT_ref (a)->die_id.die_symbol;
9363 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9364 length, whereas in DWARF3 it's always sized as an
9366 if (dwarf_version == 2)
9367 size = DWARF2_ADDR_SIZE;
9369 size = DWARF_OFFSET_SIZE;
9370 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
9376 gcc_assert (AT_ref (a)->die_offset);
9377 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
9382 case dw_val_class_fde_ref:
9386 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
9387 a->dw_attr_val.v.val_fde_index * 2);
9388 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
9393 case dw_val_class_vms_delta:
9394 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
9395 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
9396 AT_vms_delta2 (a), AT_vms_delta1 (a),
9399 dw2_asm_output_delta (DWARF_OFFSET_SIZE,
9400 AT_vms_delta2 (a), AT_vms_delta1 (a),
9405 case dw_val_class_lbl_id:
9406 output_attr_index_or_value (a);
9409 case dw_val_class_lineptr:
9410 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9411 debug_line_section, "%s", name);
9414 case dw_val_class_macptr:
9415 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9416 debug_macinfo_section, "%s", name);
9419 case dw_val_class_str:
9420 if (a->dw_attr_val.v.val_str->form == DW_FORM_strp)
9421 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
9422 a->dw_attr_val.v.val_str->label,
9424 "%s: \"%s\"", name, AT_string (a));
9425 else if (a->dw_attr_val.v.val_str->form == DW_FORM_GNU_str_index)
9426 dw2_asm_output_data_uleb128 (AT_index (a),
9427 "%s: \"%s\"", name, AT_string (a));
9429 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
9432 case dw_val_class_file:
9434 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
9436 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
9437 a->dw_attr_val.v.val_file->filename);
9441 case dw_val_class_data8:
9445 for (i = 0; i < 8; i++)
9446 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
9447 i == 0 ? "%s" : NULL, name);
9451 case dw_val_class_high_pc:
9452 dw2_asm_output_delta (DWARF2_ADDR_SIZE, AT_lbl (a),
9453 get_AT_low_pc (die), "DW_AT_high_pc");
9456 case dw_val_class_discr_value:
9457 output_discr_value (&a->dw_attr_val.v.val_discr_value, name);
9460 case dw_val_class_discr_list:
9462 dw_discr_list_ref list = AT_discr_list (a);
9463 const int size = size_of_discr_list (list);
9465 /* This is a block, so output its length first. */
9466 dw2_asm_output_data (constant_size (size), size,
9467 "%s: block size", name);
9469 for (; list != NULL; list = list->dw_discr_next)
9471 /* One byte for the discriminant value descriptor, and then as
9472 many LEB128 numbers as required. */
9473 if (list->dw_discr_range)
9474 dw2_asm_output_data (1, DW_DSC_range,
9475 "%s: DW_DSC_range", name);
9477 dw2_asm_output_data (1, DW_DSC_label,
9478 "%s: DW_DSC_label", name);
9480 output_discr_value (&list->dw_discr_lower_bound, name);
9481 if (list->dw_discr_range)
9482 output_discr_value (&list->dw_discr_upper_bound, name);
9492 FOR_EACH_CHILD (die, c, output_die (c));
9494 /* Add null byte to terminate sibling list. */
9495 if (die->die_child != NULL)
9496 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9497 (unsigned long) die->die_offset);
9500 /* Output the compilation unit that appears at the beginning of the
9501 .debug_info section, and precedes the DIE descriptions. */
9504 output_compilation_unit_header (void)
9506 /* We don't support actual DWARFv5 units yet, we just use some
9507 DWARFv5 draft DIE tags in DWARFv4 format. */
9508 int ver = dwarf_version < 5 ? dwarf_version : 4;
9510 if (!XCOFF_DEBUGGING_INFO)
9512 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9513 dw2_asm_output_data (4, 0xffffffff,
9514 "Initial length escape value indicating 64-bit DWARF extension");
9515 dw2_asm_output_data (DWARF_OFFSET_SIZE,
9516 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
9517 "Length of Compilation Unit Info");
9520 dw2_asm_output_data (2, ver, "DWARF version number");
9521 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
9522 debug_abbrev_section,
9523 "Offset Into Abbrev. Section");
9524 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
9527 /* Output the compilation unit DIE and its children. */
9530 output_comp_unit (dw_die_ref die, int output_if_empty)
9532 const char *secname, *oldsym;
9535 /* Unless we are outputting main CU, we may throw away empty ones. */
9536 if (!output_if_empty && die->die_child == NULL)
9539 /* Even if there are no children of this DIE, we must output the information
9540 about the compilation unit. Otherwise, on an empty translation unit, we
9541 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9542 will then complain when examining the file. First mark all the DIEs in
9543 this CU so we know which get local refs. */
9546 external_ref_hash_type *extern_map = optimize_external_refs (die);
9548 build_abbrev_table (die, extern_map);
9552 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9553 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9554 calc_die_sizes (die);
9556 oldsym = die->die_id.die_symbol;
9559 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
9561 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
9563 die->die_id.die_symbol = NULL;
9564 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9568 switch_to_section (debug_info_section);
9569 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9570 info_section_emitted = true;
9573 /* Output debugging information. */
9574 output_compilation_unit_header ();
9577 /* Leave the marks on the main CU, so we can check them in
9582 die->die_id.die_symbol = oldsym;
9586 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9587 and .debug_pubtypes. This is configured per-target, but can be
9588 overridden by the -gpubnames or -gno-pubnames options. */
9591 want_pubnames (void)
9593 if (debug_info_level <= DINFO_LEVEL_TERSE)
9595 if (debug_generate_pub_sections != -1)
9596 return debug_generate_pub_sections;
9597 return targetm.want_debug_pub_sections;
9600 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9603 add_AT_pubnames (dw_die_ref die)
9605 if (want_pubnames ())
9606 add_AT_flag (die, DW_AT_GNU_pubnames, 1);
9609 /* Add a string attribute value to a skeleton DIE. */
9612 add_skeleton_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind,
9616 struct indirect_string_node *node;
9618 if (! skeleton_debug_str_hash)
9619 skeleton_debug_str_hash
9620 = hash_table<indirect_string_hasher>::create_ggc (10);
9622 node = find_AT_string_in_table (str, skeleton_debug_str_hash);
9623 find_string_form (node);
9624 if (node->form == DW_FORM_GNU_str_index)
9625 node->form = DW_FORM_strp;
9627 attr.dw_attr = attr_kind;
9628 attr.dw_attr_val.val_class = dw_val_class_str;
9629 attr.dw_attr_val.val_entry = NULL;
9630 attr.dw_attr_val.v.val_str = node;
9631 add_dwarf_attr (die, &attr);
9634 /* Helper function to generate top-level dies for skeleton debug_info and
9638 add_top_level_skeleton_die_attrs (dw_die_ref die)
9640 const char *dwo_file_name = concat (aux_base_name, ".dwo", NULL);
9641 const char *comp_dir = comp_dir_string ();
9643 add_skeleton_AT_string (die, DW_AT_GNU_dwo_name, dwo_file_name);
9644 if (comp_dir != NULL)
9645 add_skeleton_AT_string (die, DW_AT_comp_dir, comp_dir);
9646 add_AT_pubnames (die);
9647 add_AT_lineptr (die, DW_AT_GNU_addr_base, debug_addr_section_label);
9650 /* Output skeleton debug sections that point to the dwo file. */
9653 output_skeleton_debug_sections (dw_die_ref comp_unit)
9655 /* We don't support actual DWARFv5 units yet, we just use some
9656 DWARFv5 draft DIE tags in DWARFv4 format. */
9657 int ver = dwarf_version < 5 ? dwarf_version : 4;
9659 /* These attributes will be found in the full debug_info section. */
9660 remove_AT (comp_unit, DW_AT_producer);
9661 remove_AT (comp_unit, DW_AT_language);
9663 switch_to_section (debug_skeleton_info_section);
9664 ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_info_section_label);
9666 /* Produce the skeleton compilation-unit header. This one differs enough from
9667 a normal CU header that it's better not to call output_compilation_unit
9669 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9670 dw2_asm_output_data (4, 0xffffffff,
9671 "Initial length escape value indicating 64-bit DWARF extension");
9673 dw2_asm_output_data (DWARF_OFFSET_SIZE,
9674 DWARF_COMPILE_UNIT_HEADER_SIZE
9675 - DWARF_INITIAL_LENGTH_SIZE
9676 + size_of_die (comp_unit),
9677 "Length of Compilation Unit Info");
9678 dw2_asm_output_data (2, ver, "DWARF version number");
9679 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_abbrev_section_label,
9680 debug_abbrev_section,
9681 "Offset Into Abbrev. Section");
9682 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
9684 comp_unit->die_abbrev = SKELETON_COMP_DIE_ABBREV;
9685 output_die (comp_unit);
9687 /* Build the skeleton debug_abbrev section. */
9688 switch_to_section (debug_skeleton_abbrev_section);
9689 ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_abbrev_section_label);
9691 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV, comp_unit);
9693 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9696 /* Output a comdat type unit DIE and its children. */
9699 output_comdat_type_unit (comdat_type_node *node)
9701 const char *secname;
9704 #if defined (OBJECT_FORMAT_ELF)
9708 /* First mark all the DIEs in this CU so we know which get local refs. */
9709 mark_dies (node->root_die);
9711 external_ref_hash_type *extern_map = optimize_external_refs (node->root_die);
9713 build_abbrev_table (node->root_die, extern_map);
9718 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9719 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
9720 calc_die_sizes (node->root_die);
9722 #if defined (OBJECT_FORMAT_ELF)
9723 if (!dwarf_split_debug_info)
9724 secname = ".debug_types";
9726 secname = ".debug_types.dwo";
9728 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
9729 sprintf (tmp, "wt.");
9730 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
9731 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
9732 comdat_key = get_identifier (tmp);
9733 targetm.asm_out.named_section (secname,
9734 SECTION_DEBUG | SECTION_LINKONCE,
9737 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
9738 sprintf (tmp, ".gnu.linkonce.wt.");
9739 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
9740 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
9742 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9745 /* Output debugging information. */
9746 output_compilation_unit_header ();
9747 output_signature (node->signature, "Type Signature");
9748 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
9749 "Offset to Type DIE");
9750 output_die (node->root_die);
9752 unmark_dies (node->root_die);
9755 /* Return the DWARF2/3 pubname associated with a decl. */
9758 dwarf2_name (tree decl, int scope)
9760 if (DECL_NAMELESS (decl))
9762 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
9765 /* Add a new entry to .debug_pubnames if appropriate. */
9768 add_pubname_string (const char *str, dw_die_ref die)
9773 e.name = xstrdup (str);
9774 vec_safe_push (pubname_table, e);
9778 add_pubname (tree decl, dw_die_ref die)
9780 if (!want_pubnames ())
9783 /* Don't add items to the table when we expect that the consumer will have
9784 just read the enclosing die. For example, if the consumer is looking at a
9785 class_member, it will either be inside the class already, or will have just
9786 looked up the class to find the member. Either way, searching the class is
9787 faster than searching the index. */
9788 if ((TREE_PUBLIC (decl) && !class_scope_p (die->die_parent))
9789 || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
9791 const char *name = dwarf2_name (decl, 1);
9794 add_pubname_string (name, die);
9798 /* Add an enumerator to the pubnames section. */
9801 add_enumerator_pubname (const char *scope_name, dw_die_ref die)
9805 gcc_assert (scope_name);
9806 e.name = concat (scope_name, get_AT_string (die, DW_AT_name), NULL);
9808 vec_safe_push (pubname_table, e);
9811 /* Add a new entry to .debug_pubtypes if appropriate. */
9814 add_pubtype (tree decl, dw_die_ref die)
9818 if (!want_pubnames ())
9821 if ((TREE_PUBLIC (decl)
9822 || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
9823 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
9826 const char *scope_name = "";
9827 const char *sep = is_cxx () ? "::" : ".";
9830 scope = TYPE_P (decl) ? TYPE_CONTEXT (decl) : NULL;
9831 if (scope && TREE_CODE (scope) == NAMESPACE_DECL)
9833 scope_name = lang_hooks.dwarf_name (scope, 1);
9834 if (scope_name != NULL && scope_name[0] != '\0')
9835 scope_name = concat (scope_name, sep, NULL);
9841 name = type_tag (decl);
9843 name = lang_hooks.dwarf_name (decl, 1);
9845 /* If we don't have a name for the type, there's no point in adding
9847 if (name != NULL && name[0] != '\0')
9850 e.name = concat (scope_name, name, NULL);
9851 vec_safe_push (pubtype_table, e);
9854 /* Although it might be more consistent to add the pubinfo for the
9855 enumerators as their dies are created, they should only be added if the
9856 enum type meets the criteria above. So rather than re-check the parent
9857 enum type whenever an enumerator die is created, just output them all
9858 here. This isn't protected by the name conditional because anonymous
9859 enums don't have names. */
9860 if (die->die_tag == DW_TAG_enumeration_type)
9864 FOR_EACH_CHILD (die, c, add_enumerator_pubname (scope_name, c));
9869 /* Output a single entry in the pubnames table. */
9872 output_pubname (dw_offset die_offset, pubname_entry *entry)
9874 dw_die_ref die = entry->die;
9875 int is_static = get_AT_flag (die, DW_AT_external) ? 0 : 1;
9877 dw2_asm_output_data (DWARF_OFFSET_SIZE, die_offset, "DIE offset");
9879 if (debug_generate_pub_sections == 2)
9881 /* This logic follows gdb's method for determining the value of the flag
9883 uint32_t flags = GDB_INDEX_SYMBOL_KIND_NONE;
9884 switch (die->die_tag)
9886 case DW_TAG_typedef:
9887 case DW_TAG_base_type:
9888 case DW_TAG_subrange_type:
9889 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
9890 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
9892 case DW_TAG_enumerator:
9893 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
9894 GDB_INDEX_SYMBOL_KIND_VARIABLE);
9895 if (!is_cxx () && !is_java ())
9896 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
9898 case DW_TAG_subprogram:
9899 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
9900 GDB_INDEX_SYMBOL_KIND_FUNCTION);
9902 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
9904 case DW_TAG_constant:
9905 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
9906 GDB_INDEX_SYMBOL_KIND_VARIABLE);
9907 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
9909 case DW_TAG_variable:
9910 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
9911 GDB_INDEX_SYMBOL_KIND_VARIABLE);
9912 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
9914 case DW_TAG_namespace:
9915 case DW_TAG_imported_declaration:
9916 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
9918 case DW_TAG_class_type:
9919 case DW_TAG_interface_type:
9920 case DW_TAG_structure_type:
9921 case DW_TAG_union_type:
9922 case DW_TAG_enumeration_type:
9923 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
9924 if (!is_cxx () && !is_java ())
9925 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
9928 /* An unusual tag. Leave the flag-byte empty. */
9931 dw2_asm_output_data (1, flags >> GDB_INDEX_CU_BITSIZE,
9935 dw2_asm_output_nstring (entry->name, -1, "external name");
9939 /* Output the public names table used to speed up access to externally
9940 visible names; or the public types table used to find type definitions. */
9943 output_pubnames (vec<pubname_entry, va_gc> *names)
9946 unsigned long pubnames_length = size_of_pubnames (names);
9949 if (!XCOFF_DEBUGGING_INFO)
9951 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9952 dw2_asm_output_data (4, 0xffffffff,
9953 "Initial length escape value indicating 64-bit DWARF extension");
9954 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9958 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9959 dw2_asm_output_data (2, 2, "DWARF Version");
9961 if (dwarf_split_debug_info)
9962 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label,
9963 debug_skeleton_info_section,
9964 "Offset of Compilation Unit Info");
9966 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9968 "Offset of Compilation Unit Info");
9969 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
9970 "Compilation Unit Length");
9972 FOR_EACH_VEC_ELT (*names, i, pub)
9974 if (include_pubname_in_output (names, pub))
9976 dw_offset die_offset = pub->die->die_offset;
9978 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9979 if (names == pubname_table && pub->die->die_tag != DW_TAG_enumerator)
9980 gcc_assert (pub->die->die_mark);
9982 /* If we're putting types in their own .debug_types sections,
9983 the .debug_pubtypes table will still point to the compile
9984 unit (not the type unit), so we want to use the offset of
9985 the skeleton DIE (if there is one). */
9986 if (pub->die->comdat_type_p && names == pubtype_table)
9988 comdat_type_node *type_node = pub->die->die_id.die_type_node;
9990 if (type_node != NULL)
9991 die_offset = (type_node->skeleton_die != NULL
9992 ? type_node->skeleton_die->die_offset
9993 : comp_unit_die ()->die_offset);
9996 output_pubname (die_offset, pub);
10000 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
10003 /* Output public names and types tables if necessary. */
10006 output_pubtables (void)
10008 if (!want_pubnames () || !info_section_emitted)
10011 switch_to_section (debug_pubnames_section);
10012 output_pubnames (pubname_table);
10013 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
10014 It shouldn't hurt to emit it always, since pure DWARF2 consumers
10015 simply won't look for the section. */
10016 switch_to_section (debug_pubtypes_section);
10017 output_pubnames (pubtype_table);
10021 /* Output the information that goes into the .debug_aranges table.
10022 Namely, define the beginning and ending address range of the
10023 text section generated for this compilation unit. */
10026 output_aranges (void)
10029 unsigned long aranges_length = size_of_aranges ();
10031 if (!XCOFF_DEBUGGING_INFO)
10033 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
10034 dw2_asm_output_data (4, 0xffffffff,
10035 "Initial length escape value indicating 64-bit DWARF extension");
10036 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
10037 "Length of Address Ranges Info");
10040 /* Version number for aranges is still 2, even up to DWARF5. */
10041 dw2_asm_output_data (2, 2, "DWARF Version");
10042 if (dwarf_split_debug_info)
10043 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label,
10044 debug_skeleton_info_section,
10045 "Offset of Compilation Unit Info");
10047 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
10048 debug_info_section,
10049 "Offset of Compilation Unit Info");
10050 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
10051 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
10053 /* We need to align to twice the pointer size here. */
10054 if (DWARF_ARANGES_PAD_SIZE)
10056 /* Pad using a 2 byte words so that padding is correct for any
10058 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
10059 2 * DWARF2_ADDR_SIZE);
10060 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
10061 dw2_asm_output_data (2, 0, NULL);
10064 /* It is necessary not to output these entries if the sections were
10065 not used; if the sections were not used, the length will be 0 and
10066 the address may end up as 0 if the section is discarded by ld
10067 --gc-sections, leaving an invalid (0, 0) entry that can be
10068 confused with the terminator. */
10069 if (text_section_used)
10071 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
10072 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
10073 text_section_label, "Length");
10075 if (cold_text_section_used)
10077 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
10079 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
10080 cold_text_section_label, "Length");
10083 if (have_multiple_function_sections)
10088 FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
10090 if (DECL_IGNORED_P (fde->decl))
10092 if (!fde->in_std_section)
10094 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
10096 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
10097 fde->dw_fde_begin, "Length");
10099 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
10101 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
10103 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
10104 fde->dw_fde_second_begin, "Length");
10109 /* Output the terminator words. */
10110 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
10111 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
10114 /* Add a new entry to .debug_ranges. Return the offset at which it
10117 static unsigned int
10118 add_ranges_num (int num)
10120 unsigned int in_use = ranges_table_in_use;
10122 if (in_use == ranges_table_allocated)
10124 ranges_table_allocated += RANGES_TABLE_INCREMENT;
10125 ranges_table = GGC_RESIZEVEC (dw_ranges, ranges_table,
10126 ranges_table_allocated);
10127 memset (ranges_table + ranges_table_in_use, 0,
10128 RANGES_TABLE_INCREMENT * sizeof (dw_ranges));
10131 ranges_table[in_use].num = num;
10132 ranges_table_in_use = in_use + 1;
10134 return in_use * 2 * DWARF2_ADDR_SIZE;
10137 /* Add a new entry to .debug_ranges corresponding to a block, or a
10138 range terminator if BLOCK is NULL. */
10140 static unsigned int
10141 add_ranges (const_tree block)
10143 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
10146 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
10147 When using dwarf_split_debug_info, address attributes in dies destined
10148 for the final executable should be direct references--setting the
10149 parameter force_direct ensures this behavior. */
10152 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
10153 bool *added, bool force_direct)
10155 unsigned int in_use = ranges_by_label_in_use;
10156 unsigned int offset;
10158 if (in_use == ranges_by_label_allocated)
10160 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
10161 ranges_by_label = GGC_RESIZEVEC (dw_ranges_by_label, ranges_by_label,
10162 ranges_by_label_allocated);
10163 memset (ranges_by_label + ranges_by_label_in_use, 0,
10164 RANGES_TABLE_INCREMENT * sizeof (dw_ranges_by_label));
10167 ranges_by_label[in_use].begin = begin;
10168 ranges_by_label[in_use].end = end;
10169 ranges_by_label_in_use = in_use + 1;
10171 offset = add_ranges_num (-(int)in_use - 1);
10174 add_AT_range_list (die, DW_AT_ranges, offset, force_direct);
10180 output_ranges (void)
10183 static const char *const start_fmt = "Offset %#x";
10184 const char *fmt = start_fmt;
10186 for (i = 0; i < ranges_table_in_use; i++)
10188 int block_num = ranges_table[i].num;
10192 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
10193 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
10195 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
10196 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
10198 /* If all code is in the text section, then the compilation
10199 unit base address defaults to DW_AT_low_pc, which is the
10200 base of the text section. */
10201 if (!have_multiple_function_sections)
10203 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
10204 text_section_label,
10205 fmt, i * 2 * DWARF2_ADDR_SIZE);
10206 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
10207 text_section_label, NULL);
10210 /* Otherwise, the compilation unit base address is zero,
10211 which allows us to use absolute addresses, and not worry
10212 about whether the target supports cross-section
10216 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
10217 fmt, i * 2 * DWARF2_ADDR_SIZE);
10218 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
10224 /* Negative block_num stands for an index into ranges_by_label. */
10225 else if (block_num < 0)
10227 int lab_idx = - block_num - 1;
10229 if (!have_multiple_function_sections)
10231 gcc_unreachable ();
10233 /* If we ever use add_ranges_by_labels () for a single
10234 function section, all we have to do is to take out
10235 the #if 0 above. */
10236 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
10237 ranges_by_label[lab_idx].begin,
10238 text_section_label,
10239 fmt, i * 2 * DWARF2_ADDR_SIZE);
10240 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
10241 ranges_by_label[lab_idx].end,
10242 text_section_label, NULL);
10247 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
10248 ranges_by_label[lab_idx].begin,
10249 fmt, i * 2 * DWARF2_ADDR_SIZE);
10250 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
10251 ranges_by_label[lab_idx].end,
10257 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
10258 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
10264 /* Data structure containing information about input files. */
10267 const char *path; /* Complete file name. */
10268 const char *fname; /* File name part. */
10269 int length; /* Length of entire string. */
10270 struct dwarf_file_data * file_idx; /* Index in input file table. */
10271 int dir_idx; /* Index in directory table. */
10274 /* Data structure containing information about directories with source
10278 const char *path; /* Path including directory name. */
10279 int length; /* Path length. */
10280 int prefix; /* Index of directory entry which is a prefix. */
10281 int count; /* Number of files in this directory. */
10282 int dir_idx; /* Index of directory used as base. */
10285 /* Callback function for file_info comparison. We sort by looking at
10286 the directories in the path. */
10289 file_info_cmp (const void *p1, const void *p2)
10291 const struct file_info *const s1 = (const struct file_info *) p1;
10292 const struct file_info *const s2 = (const struct file_info *) p2;
10293 const unsigned char *cp1;
10294 const unsigned char *cp2;
10296 /* Take care of file names without directories. We need to make sure that
10297 we return consistent values to qsort since some will get confused if
10298 we return the same value when identical operands are passed in opposite
10299 orders. So if neither has a directory, return 0 and otherwise return
10300 1 or -1 depending on which one has the directory. */
10301 if ((s1->path == s1->fname || s2->path == s2->fname))
10302 return (s2->path == s2->fname) - (s1->path == s1->fname);
10304 cp1 = (const unsigned char *) s1->path;
10305 cp2 = (const unsigned char *) s2->path;
10311 /* Reached the end of the first path? If so, handle like above. */
10312 if ((cp1 == (const unsigned char *) s1->fname)
10313 || (cp2 == (const unsigned char *) s2->fname))
10314 return ((cp2 == (const unsigned char *) s2->fname)
10315 - (cp1 == (const unsigned char *) s1->fname));
10317 /* Character of current path component the same? */
10318 else if (*cp1 != *cp2)
10319 return *cp1 - *cp2;
10323 struct file_name_acquire_data
10325 struct file_info *files;
10330 /* Traversal function for the hash table. */
10333 file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad)
10335 struct dwarf_file_data *d = *slot;
10336 struct file_info *fi;
10339 gcc_assert (fnad->max_files >= d->emitted_number);
10341 if (! d->emitted_number)
10344 gcc_assert (fnad->max_files != fnad->used_files);
10346 fi = fnad->files + fnad->used_files++;
10348 /* Skip all leading "./". */
10350 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
10353 /* Create a new array entry. */
10355 fi->length = strlen (f);
10358 /* Search for the file name part. */
10359 f = strrchr (f, DIR_SEPARATOR);
10360 #if defined (DIR_SEPARATOR_2)
10362 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
10366 if (f == NULL || f < g)
10372 fi->fname = f == NULL ? fi->path : f + 1;
10376 /* Output the directory table and the file name table. We try to minimize
10377 the total amount of memory needed. A heuristic is used to avoid large
10378 slowdowns with many input files. */
10381 output_file_names (void)
10383 struct file_name_acquire_data fnad;
10385 struct file_info *files;
10386 struct dir_info *dirs;
10394 if (!last_emitted_file)
10396 dw2_asm_output_data (1, 0, "End directory table");
10397 dw2_asm_output_data (1, 0, "End file name table");
10401 numfiles = last_emitted_file->emitted_number;
10403 /* Allocate the various arrays we need. */
10404 files = XALLOCAVEC (struct file_info, numfiles);
10405 dirs = XALLOCAVEC (struct dir_info, numfiles);
10407 fnad.files = files;
10408 fnad.used_files = 0;
10409 fnad.max_files = numfiles;
10410 file_table->traverse<file_name_acquire_data *, file_name_acquire> (&fnad);
10411 gcc_assert (fnad.used_files == fnad.max_files);
10413 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
10415 /* Find all the different directories used. */
10416 dirs[0].path = files[0].path;
10417 dirs[0].length = files[0].fname - files[0].path;
10418 dirs[0].prefix = -1;
10420 dirs[0].dir_idx = 0;
10421 files[0].dir_idx = 0;
10424 for (i = 1; i < numfiles; i++)
10425 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
10426 && memcmp (dirs[ndirs - 1].path, files[i].path,
10427 dirs[ndirs - 1].length) == 0)
10429 /* Same directory as last entry. */
10430 files[i].dir_idx = ndirs - 1;
10431 ++dirs[ndirs - 1].count;
10437 /* This is a new directory. */
10438 dirs[ndirs].path = files[i].path;
10439 dirs[ndirs].length = files[i].fname - files[i].path;
10440 dirs[ndirs].count = 1;
10441 dirs[ndirs].dir_idx = ndirs;
10442 files[i].dir_idx = ndirs;
10444 /* Search for a prefix. */
10445 dirs[ndirs].prefix = -1;
10446 for (j = 0; j < ndirs; j++)
10447 if (dirs[j].length < dirs[ndirs].length
10448 && dirs[j].length > 1
10449 && (dirs[ndirs].prefix == -1
10450 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
10451 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
10452 dirs[ndirs].prefix = j;
10457 /* Now to the actual work. We have to find a subset of the directories which
10458 allow expressing the file name using references to the directory table
10459 with the least amount of characters. We do not do an exhaustive search
10460 where we would have to check out every combination of every single
10461 possible prefix. Instead we use a heuristic which provides nearly optimal
10462 results in most cases and never is much off. */
10463 saved = XALLOCAVEC (int, ndirs);
10464 savehere = XALLOCAVEC (int, ndirs);
10466 memset (saved, '\0', ndirs * sizeof (saved[0]));
10467 for (i = 0; i < ndirs; i++)
10472 /* We can always save some space for the current directory. But this
10473 does not mean it will be enough to justify adding the directory. */
10474 savehere[i] = dirs[i].length;
10475 total = (savehere[i] - saved[i]) * dirs[i].count;
10477 for (j = i + 1; j < ndirs; j++)
10480 if (saved[j] < dirs[i].length)
10482 /* Determine whether the dirs[i] path is a prefix of the
10486 k = dirs[j].prefix;
10487 while (k != -1 && k != (int) i)
10488 k = dirs[k].prefix;
10492 /* Yes it is. We can possibly save some memory by
10493 writing the filenames in dirs[j] relative to
10495 savehere[j] = dirs[i].length;
10496 total += (savehere[j] - saved[j]) * dirs[j].count;
10501 /* Check whether we can save enough to justify adding the dirs[i]
10503 if (total > dirs[i].length + 1)
10505 /* It's worthwhile adding. */
10506 for (j = i; j < ndirs; j++)
10507 if (savehere[j] > 0)
10509 /* Remember how much we saved for this directory so far. */
10510 saved[j] = savehere[j];
10512 /* Remember the prefix directory. */
10513 dirs[j].dir_idx = i;
10518 /* Emit the directory name table. */
10519 idx_offset = dirs[0].length > 0 ? 1 : 0;
10520 for (i = 1 - idx_offset; i < ndirs; i++)
10521 dw2_asm_output_nstring (dirs[i].path,
10523 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
10524 "Directory Entry: %#x", i + idx_offset);
10526 dw2_asm_output_data (1, 0, "End directory table");
10528 /* We have to emit them in the order of emitted_number since that's
10529 used in the debug info generation. To do this efficiently we
10530 generate a back-mapping of the indices first. */
10531 backmap = XALLOCAVEC (int, numfiles);
10532 for (i = 0; i < numfiles; i++)
10533 backmap[files[i].file_idx->emitted_number - 1] = i;
10535 /* Now write all the file names. */
10536 for (i = 0; i < numfiles; i++)
10538 int file_idx = backmap[i];
10539 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
10541 #ifdef VMS_DEBUGGING_INFO
10542 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
10544 /* Setting these fields can lead to debugger miscomparisons,
10545 but VMS Debug requires them to be set correctly. */
10550 int maxfilelen = strlen (files[file_idx].path)
10551 + dirs[dir_idx].length
10552 + MAX_VMS_VERSION_LEN + 1;
10553 char *filebuf = XALLOCAVEC (char, maxfilelen);
10555 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
10556 snprintf (filebuf, maxfilelen, "%s;%d",
10557 files[file_idx].path + dirs[dir_idx].length, ver);
10559 dw2_asm_output_nstring
10560 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
10562 /* Include directory index. */
10563 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
10565 /* Modification time. */
10566 dw2_asm_output_data_uleb128
10567 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
10571 /* File length in bytes. */
10572 dw2_asm_output_data_uleb128
10573 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
10577 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
10578 "File Entry: %#x", (unsigned) i + 1);
10580 /* Include directory index. */
10581 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
10583 /* Modification time. */
10584 dw2_asm_output_data_uleb128 (0, NULL);
10586 /* File length in bytes. */
10587 dw2_asm_output_data_uleb128 (0, NULL);
10588 #endif /* VMS_DEBUGGING_INFO */
10591 dw2_asm_output_data (1, 0, "End file name table");
10595 /* Output one line number table into the .debug_line section. */
10598 output_one_line_info_table (dw_line_info_table *table)
10600 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
10601 unsigned int current_line = 1;
10602 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
10603 dw_line_info_entry *ent;
10606 FOR_EACH_VEC_SAFE_ELT (table->entries, i, ent)
10608 switch (ent->opcode)
10610 case LI_set_address:
10611 /* ??? Unfortunately, we have little choice here currently, and
10612 must always use the most general form. GCC does not know the
10613 address delta itself, so we can't use DW_LNS_advance_pc. Many
10614 ports do have length attributes which will give an upper bound
10615 on the address range. We could perhaps use length attributes
10616 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10617 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
10619 /* This can handle any delta. This takes
10620 4+DWARF2_ADDR_SIZE bytes. */
10621 dw2_asm_output_data (1, 0, "set address %s", line_label);
10622 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10623 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10624 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10628 if (ent->val == current_line)
10630 /* We still need to start a new row, so output a copy insn. */
10631 dw2_asm_output_data (1, DW_LNS_copy,
10632 "copy line %u", current_line);
10636 int line_offset = ent->val - current_line;
10637 int line_delta = line_offset - DWARF_LINE_BASE;
10639 current_line = ent->val;
10640 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
10642 /* This can handle deltas from -10 to 234, using the current
10643 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10644 This takes 1 byte. */
10645 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
10646 "line %u", current_line);
10650 /* This can handle any delta. This takes at least 4 bytes,
10651 depending on the value being encoded. */
10652 dw2_asm_output_data (1, DW_LNS_advance_line,
10653 "advance to line %u", current_line);
10654 dw2_asm_output_data_sleb128 (line_offset, NULL);
10655 dw2_asm_output_data (1, DW_LNS_copy, NULL);
10661 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
10662 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
10665 case LI_set_column:
10666 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
10667 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
10670 case LI_negate_stmt:
10671 current_is_stmt = !current_is_stmt;
10672 dw2_asm_output_data (1, DW_LNS_negate_stmt,
10673 "is_stmt %d", current_is_stmt);
10676 case LI_set_prologue_end:
10677 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
10678 "set prologue end");
10681 case LI_set_epilogue_begin:
10682 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
10683 "set epilogue begin");
10686 case LI_set_discriminator:
10687 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
10688 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
10689 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
10690 dw2_asm_output_data_uleb128 (ent->val, NULL);
10695 /* Emit debug info for the address of the end of the table. */
10696 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
10697 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10698 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10699 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
10701 dw2_asm_output_data (1, 0, "end sequence");
10702 dw2_asm_output_data_uleb128 (1, NULL);
10703 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
10706 /* Output the source line number correspondence information. This
10707 information goes into the .debug_line section. */
10710 output_line_info (bool prologue_only)
10712 char l1[20], l2[20], p1[20], p2[20];
10713 /* We don't support DWARFv5 line tables yet. */
10714 int ver = dwarf_version < 5 ? dwarf_version : 4;
10715 bool saw_one = false;
10718 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
10719 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
10720 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
10721 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
10723 if (!XCOFF_DEBUGGING_INFO)
10725 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
10726 dw2_asm_output_data (4, 0xffffffff,
10727 "Initial length escape value indicating 64-bit DWARF extension");
10728 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
10729 "Length of Source Line Info");
10732 ASM_OUTPUT_LABEL (asm_out_file, l1);
10734 dw2_asm_output_data (2, ver, "DWARF Version");
10735 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
10736 ASM_OUTPUT_LABEL (asm_out_file, p1);
10738 /* Define the architecture-dependent minimum instruction length (in bytes).
10739 In this implementation of DWARF, this field is used for information
10740 purposes only. Since GCC generates assembly language, we have no
10741 a priori knowledge of how many instruction bytes are generated for each
10742 source line, and therefore can use only the DW_LNE_set_address and
10743 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10744 this as '1', which is "correct enough" for all architectures,
10745 and don't let the target override. */
10746 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10749 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
10750 "Maximum Operations Per Instruction");
10751 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
10752 "Default is_stmt_start flag");
10753 dw2_asm_output_data (1, DWARF_LINE_BASE,
10754 "Line Base Value (Special Opcodes)");
10755 dw2_asm_output_data (1, DWARF_LINE_RANGE,
10756 "Line Range Value (Special Opcodes)");
10757 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
10758 "Special Opcode Base");
10760 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
10765 case DW_LNS_advance_pc:
10766 case DW_LNS_advance_line:
10767 case DW_LNS_set_file:
10768 case DW_LNS_set_column:
10769 case DW_LNS_fixed_advance_pc:
10770 case DW_LNS_set_isa:
10778 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
10782 /* Write out the information about the files we use. */
10783 output_file_names ();
10784 ASM_OUTPUT_LABEL (asm_out_file, p2);
10787 /* Output the marker for the end of the line number info. */
10788 ASM_OUTPUT_LABEL (asm_out_file, l2);
10792 if (separate_line_info)
10794 dw_line_info_table *table;
10797 FOR_EACH_VEC_ELT (*separate_line_info, i, table)
10800 output_one_line_info_table (table);
10804 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
10806 output_one_line_info_table (cold_text_section_line_info);
10810 /* ??? Some Darwin linkers crash on a .debug_line section with no
10811 sequences. Further, merely a DW_LNE_end_sequence entry is not
10812 sufficient -- the address column must also be initialized.
10813 Make sure to output at least one set_address/end_sequence pair,
10814 choosing .text since that section is always present. */
10815 if (text_section_line_info->in_use || !saw_one)
10816 output_one_line_info_table (text_section_line_info);
10818 /* Output the marker for the end of the line number info. */
10819 ASM_OUTPUT_LABEL (asm_out_file, l2);
10822 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
10825 need_endianity_attribute_p (bool reverse)
10827 return reverse && (dwarf_version >= 3 || !dwarf_strict);
10830 /* Given a pointer to a tree node for some base type, return a pointer to
10831 a DIE that describes the given type. REVERSE is true if the type is
10832 to be interpreted in the reverse storage order wrt the target order.
10834 This routine must only be called for GCC type nodes that correspond to
10835 Dwarf base (fundamental) types. */
10838 base_type_die (tree type, bool reverse)
10840 dw_die_ref base_type_result;
10841 enum dwarf_type encoding;
10842 bool fpt_used = false;
10843 struct fixed_point_type_info fpt_info;
10844 tree type_bias = NULL_TREE;
10846 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
10849 /* If this is a subtype that should not be emitted as a subrange type,
10850 use the base type. See subrange_type_for_debug_p. */
10851 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
10852 type = TREE_TYPE (type);
10854 switch (TREE_CODE (type))
10857 if ((dwarf_version >= 4 || !dwarf_strict)
10858 && TYPE_NAME (type)
10859 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10860 && DECL_IS_BUILTIN (TYPE_NAME (type))
10861 && DECL_NAME (TYPE_NAME (type)))
10863 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
10864 if (strcmp (name, "char16_t") == 0
10865 || strcmp (name, "char32_t") == 0)
10867 encoding = DW_ATE_UTF;
10871 if ((dwarf_version >= 3 || !dwarf_strict)
10872 && lang_hooks.types.get_fixed_point_type_info)
10874 memset (&fpt_info, 0, sizeof (fpt_info));
10875 if (lang_hooks.types.get_fixed_point_type_info (type, &fpt_info))
10878 encoding = ((TYPE_UNSIGNED (type))
10879 ? DW_ATE_unsigned_fixed
10880 : DW_ATE_signed_fixed);
10884 if (TYPE_STRING_FLAG (type))
10886 if (TYPE_UNSIGNED (type))
10887 encoding = DW_ATE_unsigned_char;
10889 encoding = DW_ATE_signed_char;
10891 else if (TYPE_UNSIGNED (type))
10892 encoding = DW_ATE_unsigned;
10894 encoding = DW_ATE_signed;
10897 && lang_hooks.types.get_type_bias)
10898 type_bias = lang_hooks.types.get_type_bias (type);
10902 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
10904 if (dwarf_version >= 3 || !dwarf_strict)
10905 encoding = DW_ATE_decimal_float;
10907 encoding = DW_ATE_lo_user;
10910 encoding = DW_ATE_float;
10913 case FIXED_POINT_TYPE:
10914 if (!(dwarf_version >= 3 || !dwarf_strict))
10915 encoding = DW_ATE_lo_user;
10916 else if (TYPE_UNSIGNED (type))
10917 encoding = DW_ATE_unsigned_fixed;
10919 encoding = DW_ATE_signed_fixed;
10922 /* Dwarf2 doesn't know anything about complex ints, so use
10923 a user defined type for it. */
10925 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
10926 encoding = DW_ATE_complex_float;
10928 encoding = DW_ATE_lo_user;
10932 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10933 encoding = DW_ATE_boolean;
10937 /* No other TREE_CODEs are Dwarf fundamental types. */
10938 gcc_unreachable ();
10941 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
10943 add_AT_unsigned (base_type_result, DW_AT_byte_size,
10944 int_size_in_bytes (type));
10945 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
10947 if (need_endianity_attribute_p (reverse))
10948 add_AT_unsigned (base_type_result, DW_AT_endianity,
10949 BYTES_BIG_ENDIAN ? DW_END_little : DW_END_big);
10953 switch (fpt_info.scale_factor_kind)
10955 case fixed_point_scale_factor_binary:
10956 add_AT_int (base_type_result, DW_AT_binary_scale,
10957 fpt_info.scale_factor.binary);
10960 case fixed_point_scale_factor_decimal:
10961 add_AT_int (base_type_result, DW_AT_decimal_scale,
10962 fpt_info.scale_factor.decimal);
10965 case fixed_point_scale_factor_arbitrary:
10966 /* Arbitrary scale factors cannot be described in standard DWARF,
10970 /* Describe the scale factor as a rational constant. */
10971 const dw_die_ref scale_factor
10972 = new_die (DW_TAG_constant, comp_unit_die (), type);
10974 add_AT_unsigned (scale_factor, DW_AT_GNU_numerator,
10975 fpt_info.scale_factor.arbitrary.numerator);
10976 add_AT_int (scale_factor, DW_AT_GNU_denominator,
10977 fpt_info.scale_factor.arbitrary.denominator);
10979 add_AT_die_ref (base_type_result, DW_AT_small, scale_factor);
10984 gcc_unreachable ();
10989 add_scalar_info (base_type_result, DW_AT_GNU_bias, type_bias,
10990 dw_scalar_form_constant
10991 | dw_scalar_form_exprloc
10992 | dw_scalar_form_reference,
10995 add_pubtype (type, base_type_result);
10997 return base_type_result;
11000 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
11001 named 'auto' in its type: return true for it, false otherwise. */
11004 is_cxx_auto (tree type)
11008 tree name = TYPE_IDENTIFIER (type);
11009 if (name == get_identifier ("auto")
11010 || name == get_identifier ("decltype(auto)"))
11016 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
11017 given input type is a Dwarf "fundamental" type. Otherwise return null. */
11020 is_base_type (tree type)
11022 switch (TREE_CODE (type))
11028 case FIXED_POINT_TYPE:
11031 case POINTER_BOUNDS_TYPE:
11037 case QUAL_UNION_TYPE:
11038 case ENUMERAL_TYPE:
11039 case FUNCTION_TYPE:
11042 case REFERENCE_TYPE:
11050 if (is_cxx_auto (type))
11052 gcc_unreachable ();
11058 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
11059 node, return the size in bits for the type if it is a constant, or else
11060 return the alignment for the type if the type's size is not constant, or
11061 else return BITS_PER_WORD if the type actually turns out to be an
11062 ERROR_MARK node. */
11064 static inline unsigned HOST_WIDE_INT
11065 simple_type_size_in_bits (const_tree type)
11067 if (TREE_CODE (type) == ERROR_MARK)
11068 return BITS_PER_WORD;
11069 else if (TYPE_SIZE (type) == NULL_TREE)
11071 else if (tree_fits_uhwi_p (TYPE_SIZE (type)))
11072 return tree_to_uhwi (TYPE_SIZE (type));
11074 return TYPE_ALIGN (type);
11077 /* Similarly, but return an offset_int instead of UHWI. */
11079 static inline offset_int
11080 offset_int_type_size_in_bits (const_tree type)
11082 if (TREE_CODE (type) == ERROR_MARK)
11083 return BITS_PER_WORD;
11084 else if (TYPE_SIZE (type) == NULL_TREE)
11086 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
11087 return wi::to_offset (TYPE_SIZE (type));
11089 return TYPE_ALIGN (type);
11092 /* Given a pointer to a tree node for a subrange type, return a pointer
11093 to a DIE that describes the given type. */
11096 subrange_type_die (tree type, tree low, tree high, tree bias,
11097 dw_die_ref context_die)
11099 dw_die_ref subrange_die;
11100 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
11102 if (context_die == NULL)
11103 context_die = comp_unit_die ();
11105 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
11107 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
11109 /* The size of the subrange type and its base type do not match,
11110 so we need to generate a size attribute for the subrange type. */
11111 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
11115 add_bound_info (subrange_die, DW_AT_lower_bound, low, NULL);
11117 add_bound_info (subrange_die, DW_AT_upper_bound, high, NULL);
11118 if (bias && !dwarf_strict)
11119 add_scalar_info (subrange_die, DW_AT_GNU_bias, bias,
11120 dw_scalar_form_constant
11121 | dw_scalar_form_exprloc
11122 | dw_scalar_form_reference,
11125 return subrange_die;
11128 /* Returns the (const and/or volatile) cv_qualifiers associated with
11129 the decl node. This will normally be augmented with the
11130 cv_qualifiers of the underlying type in add_type_attribute. */
11133 decl_quals (const_tree decl)
11135 return ((TREE_READONLY (decl)
11136 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED)
11137 | (TREE_THIS_VOLATILE (decl)
11138 ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED));
11141 /* Determine the TYPE whose qualifiers match the largest strict subset
11142 of the given TYPE_QUALS, and return its qualifiers. Ignore all
11143 qualifiers outside QUAL_MASK. */
11146 get_nearest_type_subqualifiers (tree type, int type_quals, int qual_mask)
11149 int best_rank = 0, best_qual = 0, max_rank;
11151 type_quals &= qual_mask;
11152 max_rank = popcount_hwi (type_quals) - 1;
11154 for (t = TYPE_MAIN_VARIANT (type); t && best_rank < max_rank;
11155 t = TYPE_NEXT_VARIANT (t))
11157 int q = TYPE_QUALS (t) & qual_mask;
11159 if ((q & type_quals) == q && q != type_quals
11160 && check_base_type (t, type))
11162 int rank = popcount_hwi (q);
11164 if (rank > best_rank)
11175 struct dwarf_qual_info_t { int q; enum dwarf_tag t; };
11176 static const dwarf_qual_info_t dwarf_qual_info[] =
11178 { TYPE_QUAL_CONST, DW_TAG_const_type },
11179 { TYPE_QUAL_VOLATILE, DW_TAG_volatile_type },
11180 { TYPE_QUAL_RESTRICT, DW_TAG_restrict_type },
11181 { TYPE_QUAL_ATOMIC, DW_TAG_atomic_type }
11183 static const unsigned int dwarf_qual_info_size
11184 = sizeof (dwarf_qual_info) / sizeof (dwarf_qual_info[0]);
11186 /* If DIE is a qualified DIE of some base DIE with the same parent,
11187 return the base DIE, otherwise return NULL. Set MASK to the
11188 qualifiers added compared to the returned DIE. */
11191 qualified_die_p (dw_die_ref die, int *mask, unsigned int depth)
11194 for (i = 0; i < dwarf_qual_info_size; i++)
11195 if (die->die_tag == dwarf_qual_info[i].t)
11197 if (i == dwarf_qual_info_size)
11199 if (vec_safe_length (die->die_attr) != 1)
11201 dw_die_ref type = get_AT_ref (die, DW_AT_type);
11202 if (type == NULL || type->die_parent != die->die_parent)
11204 *mask |= dwarf_qual_info[i].q;
11207 dw_die_ref ret = qualified_die_p (type, mask, depth - 1);
11214 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
11215 entry that chains the modifiers specified by CV_QUALS in front of the
11216 given type. REVERSE is true if the type is to be interpreted in the
11217 reverse storage order wrt the target order. */
11220 modified_type_die (tree type, int cv_quals, bool reverse,
11221 dw_die_ref context_die)
11223 enum tree_code code = TREE_CODE (type);
11224 dw_die_ref mod_type_die;
11225 dw_die_ref sub_die = NULL;
11226 tree item_type = NULL;
11227 tree qualified_type;
11228 tree name, low, high;
11229 dw_die_ref mod_scope;
11230 /* Only these cv-qualifiers are currently handled. */
11231 const int cv_qual_mask = (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE
11232 | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC);
11234 if (code == ERROR_MARK)
11237 if (lang_hooks.types.get_debug_type)
11239 tree debug_type = lang_hooks.types.get_debug_type (type);
11241 if (debug_type != NULL_TREE && debug_type != type)
11242 return modified_type_die (debug_type, cv_quals, reverse, context_die);
11245 cv_quals &= cv_qual_mask;
11247 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
11248 tag modifier (and not an attribute) old consumers won't be able
11250 if (dwarf_version < 3)
11251 cv_quals &= ~TYPE_QUAL_RESTRICT;
11253 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
11254 if (dwarf_version < 5)
11255 cv_quals &= ~TYPE_QUAL_ATOMIC;
11257 /* See if we already have the appropriately qualified variant of
11259 qualified_type = get_qualified_type (type, cv_quals);
11261 if (qualified_type == sizetype
11262 && TYPE_NAME (qualified_type)
11263 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
11265 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
11267 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
11268 && TYPE_PRECISION (t)
11269 == TYPE_PRECISION (qualified_type)
11270 && TYPE_UNSIGNED (t)
11271 == TYPE_UNSIGNED (qualified_type));
11272 qualified_type = t;
11275 /* If we do, then we can just use its DIE, if it exists. */
11276 if (qualified_type)
11278 mod_type_die = lookup_type_die (qualified_type);
11280 /* DW_AT_endianity doesn't come from a qualifier on the type. */
11282 && (!need_endianity_attribute_p (reverse)
11283 || !is_base_type (type)
11284 || get_AT_unsigned (mod_type_die, DW_AT_endianity)))
11285 return mod_type_die;
11288 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
11290 /* Handle C typedef types. */
11291 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
11292 && !DECL_ARTIFICIAL (name))
11294 tree dtype = TREE_TYPE (name);
11296 if (qualified_type == dtype)
11298 /* For a named type, use the typedef. */
11299 gen_type_die (qualified_type, context_die);
11300 return lookup_type_die (qualified_type);
11304 int dquals = TYPE_QUALS_NO_ADDR_SPACE (dtype);
11305 dquals &= cv_qual_mask;
11306 if ((dquals & ~cv_quals) != TYPE_UNQUALIFIED
11307 || (cv_quals == dquals && DECL_ORIGINAL_TYPE (name) != type))
11308 /* cv-unqualified version of named type. Just use
11309 the unnamed type to which it refers. */
11310 return modified_type_die (DECL_ORIGINAL_TYPE (name), cv_quals,
11311 reverse, context_die);
11312 /* Else cv-qualified version of named type; fall through. */
11316 mod_scope = scope_die_for (type, context_die);
11320 int sub_quals = 0, first_quals = 0;
11322 dw_die_ref first = NULL, last = NULL;
11324 /* Determine a lesser qualified type that most closely matches
11325 this one. Then generate DW_TAG_* entries for the remaining
11327 sub_quals = get_nearest_type_subqualifiers (type, cv_quals,
11329 if (sub_quals && use_debug_types)
11331 bool needed = false;
11332 /* If emitting type units, make sure the order of qualifiers
11333 is canonical. Thus, start from unqualified type if
11334 an earlier qualifier is missing in sub_quals, but some later
11335 one is present there. */
11336 for (i = 0; i < dwarf_qual_info_size; i++)
11337 if (dwarf_qual_info[i].q & cv_quals & ~sub_quals)
11339 else if (needed && (dwarf_qual_info[i].q & cv_quals))
11345 mod_type_die = modified_type_die (type, sub_quals, reverse, context_die);
11346 if (mod_scope && mod_type_die && mod_type_die->die_parent == mod_scope)
11348 /* As not all intermediate qualified DIEs have corresponding
11349 tree types, ensure that qualified DIEs in the same scope
11350 as their DW_AT_type are emitted after their DW_AT_type,
11351 only with other qualified DIEs for the same type possibly
11352 in between them. Determine the range of such qualified
11353 DIEs now (first being the base type, last being corresponding
11354 last qualified DIE for it). */
11355 unsigned int count = 0;
11356 first = qualified_die_p (mod_type_die, &first_quals,
11357 dwarf_qual_info_size);
11359 first = mod_type_die;
11360 gcc_assert ((first_quals & ~sub_quals) == 0);
11361 for (count = 0, last = first;
11362 count < (1U << dwarf_qual_info_size);
11363 count++, last = last->die_sib)
11366 if (last == mod_scope->die_child)
11368 if (qualified_die_p (last->die_sib, &quals, dwarf_qual_info_size)
11374 for (i = 0; i < dwarf_qual_info_size; i++)
11375 if (dwarf_qual_info[i].q & cv_quals & ~sub_quals)
11378 if (first && first != last)
11380 for (d = first->die_sib; ; d = d->die_sib)
11383 qualified_die_p (d, &quals, dwarf_qual_info_size);
11384 if (quals == (first_quals | dwarf_qual_info[i].q))
11400 d = ggc_cleared_alloc<die_node> ();
11401 d->die_tag = dwarf_qual_info[i].t;
11402 add_child_die_after (mod_scope, d, last);
11406 d = new_die (dwarf_qual_info[i].t, mod_scope, type);
11408 add_AT_die_ref (d, DW_AT_type, mod_type_die);
11410 first_quals |= dwarf_qual_info[i].q;
11413 else if (code == POINTER_TYPE || code == REFERENCE_TYPE)
11415 dwarf_tag tag = DW_TAG_pointer_type;
11416 if (code == REFERENCE_TYPE)
11418 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
11419 tag = DW_TAG_rvalue_reference_type;
11421 tag = DW_TAG_reference_type;
11423 mod_type_die = new_die (tag, mod_scope, type);
11425 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
11426 simple_type_size_in_bits (type) / BITS_PER_UNIT);
11427 item_type = TREE_TYPE (type);
11429 addr_space_t as = TYPE_ADDR_SPACE (item_type);
11430 if (!ADDR_SPACE_GENERIC_P (as))
11432 int action = targetm.addr_space.debug (as);
11435 /* Positive values indicate an address_class. */
11436 add_AT_unsigned (mod_type_die, DW_AT_address_class, action);
11440 /* Negative values indicate an (inverted) segment base reg. */
11442 = one_reg_loc_descriptor (~action, VAR_INIT_STATUS_INITIALIZED);
11443 add_AT_loc (mod_type_die, DW_AT_segment, d);
11447 else if (code == INTEGER_TYPE
11448 && TREE_TYPE (type) != NULL_TREE
11449 && subrange_type_for_debug_p (type, &low, &high))
11451 tree bias = NULL_TREE;
11452 if (lang_hooks.types.get_type_bias)
11453 bias = lang_hooks.types.get_type_bias (type);
11454 mod_type_die = subrange_type_die (type, low, high, bias, context_die);
11455 item_type = TREE_TYPE (type);
11457 else if (is_base_type (type))
11458 mod_type_die = base_type_die (type, reverse);
11461 gen_type_die (type, context_die);
11463 /* We have to get the type_main_variant here (and pass that to the
11464 `lookup_type_die' routine) because the ..._TYPE node we have
11465 might simply be a *copy* of some original type node (where the
11466 copy was created to help us keep track of typedef names) and
11467 that copy might have a different TYPE_UID from the original
11469 if (TREE_CODE (type) != VECTOR_TYPE
11470 && TREE_CODE (type) != ARRAY_TYPE)
11471 return lookup_type_die (type_main_variant (type));
11473 /* Vectors have the debugging information in the type,
11474 not the main variant. */
11475 return lookup_type_die (type);
11478 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
11479 don't output a DW_TAG_typedef, since there isn't one in the
11480 user's program; just attach a DW_AT_name to the type.
11481 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
11482 if the base type already has the same name. */
11484 && ((TREE_CODE (name) != TYPE_DECL
11485 && (qualified_type == TYPE_MAIN_VARIANT (type)
11486 || (cv_quals == TYPE_UNQUALIFIED)))
11487 || (TREE_CODE (name) == TYPE_DECL
11488 && TREE_TYPE (name) == qualified_type
11489 && DECL_NAME (name))))
11491 if (TREE_CODE (name) == TYPE_DECL)
11492 /* Could just call add_name_and_src_coords_attributes here,
11493 but since this is a builtin type it doesn't have any
11494 useful source coordinates anyway. */
11495 name = DECL_NAME (name);
11496 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
11498 /* This probably indicates a bug. */
11499 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
11501 name = TYPE_IDENTIFIER (type);
11502 add_name_attribute (mod_type_die,
11503 name ? IDENTIFIER_POINTER (name) : "__unknown__");
11506 if (qualified_type)
11507 equate_type_number_to_die (qualified_type, mod_type_die);
11510 /* We must do this after the equate_type_number_to_die call, in case
11511 this is a recursive type. This ensures that the modified_type_die
11512 recursion will terminate even if the type is recursive. Recursive
11513 types are possible in Ada. */
11514 sub_die = modified_type_die (item_type,
11515 TYPE_QUALS_NO_ADDR_SPACE (item_type),
11519 if (sub_die != NULL)
11520 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
11522 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
11523 if (TYPE_ARTIFICIAL (type))
11524 add_AT_flag (mod_type_die, DW_AT_artificial, 1);
11526 return mod_type_die;
11529 /* Generate DIEs for the generic parameters of T.
11530 T must be either a generic type or a generic function.
11531 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
11534 gen_generic_params_dies (tree t)
11538 dw_die_ref die = NULL;
11541 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
11545 die = lookup_type_die (t);
11546 else if (DECL_P (t))
11547 die = lookup_decl_die (t);
11551 parms = lang_hooks.get_innermost_generic_parms (t);
11553 /* T has no generic parameter. It means T is neither a generic type
11554 or function. End of story. */
11557 parms_num = TREE_VEC_LENGTH (parms);
11558 args = lang_hooks.get_innermost_generic_args (t);
11559 if (TREE_CHAIN (args) && TREE_CODE (TREE_CHAIN (args)) == INTEGER_CST)
11560 non_default = int_cst_value (TREE_CHAIN (args));
11562 non_default = TREE_VEC_LENGTH (args);
11563 for (i = 0; i < parms_num; i++)
11565 tree parm, arg, arg_pack_elems;
11566 dw_die_ref parm_die;
11568 parm = TREE_VEC_ELT (parms, i);
11569 arg = TREE_VEC_ELT (args, i);
11570 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
11571 gcc_assert (parm && TREE_VALUE (parm) && arg);
11573 if (parm && TREE_VALUE (parm) && arg)
11575 /* If PARM represents a template parameter pack,
11576 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
11577 by DW_TAG_template_*_parameter DIEs for the argument
11578 pack elements of ARG. Note that ARG would then be
11579 an argument pack. */
11580 if (arg_pack_elems)
11581 parm_die = template_parameter_pack_die (TREE_VALUE (parm),
11585 parm_die = generic_parameter_die (TREE_VALUE (parm), arg,
11586 true /* emit name */, die);
11587 if (i >= non_default)
11588 add_AT_flag (parm_die, DW_AT_default_value, 1);
11593 /* Create and return a DIE for PARM which should be
11594 the representation of a generic type parameter.
11595 For instance, in the C++ front end, PARM would be a template parameter.
11596 ARG is the argument to PARM.
11597 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
11599 PARENT_DIE is the parent DIE which the new created DIE should be added to,
11600 as a child node. */
11603 generic_parameter_die (tree parm, tree arg,
11605 dw_die_ref parent_die)
11607 dw_die_ref tmpl_die = NULL;
11608 const char *name = NULL;
11610 if (!parm || !DECL_NAME (parm) || !arg)
11613 /* We support non-type generic parameters and arguments,
11614 type generic parameters and arguments, as well as
11615 generic generic parameters (a.k.a. template template parameters in C++)
11617 if (TREE_CODE (parm) == PARM_DECL)
11618 /* PARM is a nontype generic parameter */
11619 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
11620 else if (TREE_CODE (parm) == TYPE_DECL)
11621 /* PARM is a type generic parameter. */
11622 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
11623 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
11624 /* PARM is a generic generic parameter.
11625 Its DIE is a GNU extension. It shall have a
11626 DW_AT_name attribute to represent the name of the template template
11627 parameter, and a DW_AT_GNU_template_name attribute to represent the
11628 name of the template template argument. */
11629 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
11632 gcc_unreachable ();
11638 /* If PARM is a generic parameter pack, it means we are
11639 emitting debug info for a template argument pack element.
11640 In other terms, ARG is a template argument pack element.
11641 In that case, we don't emit any DW_AT_name attribute for
11645 name = IDENTIFIER_POINTER (DECL_NAME (parm));
11647 add_AT_string (tmpl_die, DW_AT_name, name);
11650 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
11652 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
11653 TMPL_DIE should have a child DW_AT_type attribute that is set
11654 to the type of the argument to PARM, which is ARG.
11655 If PARM is a type generic parameter, TMPL_DIE should have a
11656 child DW_AT_type that is set to ARG. */
11657 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
11658 add_type_attribute (tmpl_die, tmpl_type,
11659 (TREE_THIS_VOLATILE (tmpl_type)
11660 ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED),
11661 false, parent_die);
11665 /* So TMPL_DIE is a DIE representing a
11666 a generic generic template parameter, a.k.a template template
11667 parameter in C++ and arg is a template. */
11669 /* The DW_AT_GNU_template_name attribute of the DIE must be set
11670 to the name of the argument. */
11671 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
11673 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
11676 if (TREE_CODE (parm) == PARM_DECL)
11677 /* So PARM is a non-type generic parameter.
11678 DWARF3 5.6.8 says we must set a DW_AT_const_value child
11679 attribute of TMPL_DIE which value represents the value
11681 We must be careful here:
11682 The value of ARG might reference some function decls.
11683 We might currently be emitting debug info for a generic
11684 type and types are emitted before function decls, we don't
11685 know if the function decls referenced by ARG will actually be
11686 emitted after cgraph computations.
11687 So must defer the generation of the DW_AT_const_value to
11688 after cgraph is ready. */
11689 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
11695 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
11696 PARM_PACK must be a template parameter pack. The returned DIE
11697 will be child DIE of PARENT_DIE. */
11700 template_parameter_pack_die (tree parm_pack,
11701 tree parm_pack_args,
11702 dw_die_ref parent_die)
11707 gcc_assert (parent_die && parm_pack);
11709 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
11710 add_name_and_src_coords_attributes (die, parm_pack);
11711 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
11712 generic_parameter_die (parm_pack,
11713 TREE_VEC_ELT (parm_pack_args, j),
11714 false /* Don't emit DW_AT_name */,
11719 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
11720 an enumerated type. */
11723 type_is_enum (const_tree type)
11725 return TREE_CODE (type) == ENUMERAL_TYPE;
11728 /* Return the DBX register number described by a given RTL node. */
11730 static unsigned int
11731 dbx_reg_number (const_rtx rtl)
11733 unsigned regno = REGNO (rtl);
11735 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
11737 #ifdef LEAF_REG_REMAP
11738 if (crtl->uses_only_leaf_regs)
11740 int leaf_reg = LEAF_REG_REMAP (regno);
11741 if (leaf_reg != -1)
11742 regno = (unsigned) leaf_reg;
11746 regno = DBX_REGISTER_NUMBER (regno);
11747 gcc_assert (regno != INVALID_REGNUM);
11751 /* Optionally add a DW_OP_piece term to a location description expression.
11752 DW_OP_piece is only added if the location description expression already
11753 doesn't end with DW_OP_piece. */
11756 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
11758 dw_loc_descr_ref loc;
11760 if (*list_head != NULL)
11762 /* Find the end of the chain. */
11763 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
11766 if (loc->dw_loc_opc != DW_OP_piece)
11767 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
11771 /* Return a location descriptor that designates a machine register or
11772 zero if there is none. */
11774 static dw_loc_descr_ref
11775 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
11779 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
11782 /* We only use "frame base" when we're sure we're talking about the
11783 post-prologue local stack frame. We do this by *not* running
11784 register elimination until this point, and recognizing the special
11785 argument pointer and soft frame pointer rtx's.
11786 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
11787 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
11788 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
11790 dw_loc_descr_ref result = NULL;
11792 if (dwarf_version >= 4 || !dwarf_strict)
11794 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
11797 add_loc_descr (&result,
11798 new_loc_descr (DW_OP_stack_value, 0, 0));
11803 regs = targetm.dwarf_register_span (rtl);
11805 if (REG_NREGS (rtl) > 1 || regs)
11806 return multiple_reg_loc_descriptor (rtl, regs, initialized);
11809 unsigned int dbx_regnum = dbx_reg_number (rtl);
11810 if (dbx_regnum == IGNORED_DWARF_REGNUM)
11812 return one_reg_loc_descriptor (dbx_regnum, initialized);
11816 /* Return a location descriptor that designates a machine register for
11817 a given hard register number. */
11819 static dw_loc_descr_ref
11820 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
11822 dw_loc_descr_ref reg_loc_descr;
11826 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
11828 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
11830 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
11831 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11833 return reg_loc_descr;
11836 /* Given an RTL of a register, return a location descriptor that
11837 designates a value that spans more than one register. */
11839 static dw_loc_descr_ref
11840 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
11841 enum var_init_status initialized)
11844 dw_loc_descr_ref loc_result = NULL;
11846 /* Simple, contiguous registers. */
11847 if (regs == NULL_RTX)
11849 unsigned reg = REGNO (rtl);
11852 #ifdef LEAF_REG_REMAP
11853 if (crtl->uses_only_leaf_regs)
11855 int leaf_reg = LEAF_REG_REMAP (reg);
11856 if (leaf_reg != -1)
11857 reg = (unsigned) leaf_reg;
11861 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
11862 nregs = REG_NREGS (rtl);
11864 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
11869 dw_loc_descr_ref t;
11871 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
11872 VAR_INIT_STATUS_INITIALIZED);
11873 add_loc_descr (&loc_result, t);
11874 add_loc_descr_op_piece (&loc_result, size);
11880 /* Now onto stupid register sets in non contiguous locations. */
11882 gcc_assert (GET_CODE (regs) == PARALLEL);
11884 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
11887 for (i = 0; i < XVECLEN (regs, 0); ++i)
11889 dw_loc_descr_ref t;
11891 t = one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs, 0, i)),
11892 VAR_INIT_STATUS_INITIALIZED);
11893 add_loc_descr (&loc_result, t);
11894 add_loc_descr_op_piece (&loc_result, size);
11897 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
11898 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11902 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT);
11904 /* Return a location descriptor that designates a constant i,
11905 as a compound operation from constant (i >> shift), constant shift
11908 static dw_loc_descr_ref
11909 int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
11911 dw_loc_descr_ref ret = int_loc_descriptor (i >> shift);
11912 add_loc_descr (&ret, int_loc_descriptor (shift));
11913 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11917 /* Return a location descriptor that designates a constant. */
11919 static dw_loc_descr_ref
11920 int_loc_descriptor (HOST_WIDE_INT i)
11922 enum dwarf_location_atom op;
11924 /* Pick the smallest representation of a constant, rather than just
11925 defaulting to the LEB encoding. */
11928 int clz = clz_hwi (i);
11929 int ctz = ctz_hwi (i);
11931 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
11932 else if (i <= 0xff)
11933 op = DW_OP_const1u;
11934 else if (i <= 0xffff)
11935 op = DW_OP_const2u;
11936 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
11937 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
11938 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11939 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11940 while DW_OP_const4u is 5 bytes. */
11941 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 5);
11942 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
11943 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
11944 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11945 while DW_OP_const4u is 5 bytes. */
11946 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
11947 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
11948 op = DW_OP_const4u;
11949 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
11950 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
11951 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11952 while DW_OP_constu of constant >= 0x100000000 takes at least
11954 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
11955 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
11956 && clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
11957 >= HOST_BITS_PER_WIDE_INT)
11958 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11959 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11960 while DW_OP_constu takes in this case at least 6 bytes. */
11961 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
11962 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
11963 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
11964 && size_of_uleb128 (i) > 6)
11965 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11966 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 32);
11973 op = DW_OP_const1s;
11974 else if (i >= -0x8000)
11975 op = DW_OP_const2s;
11976 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
11978 if (size_of_int_loc_descriptor (i) < 5)
11980 dw_loc_descr_ref ret = int_loc_descriptor (-i);
11981 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11984 op = DW_OP_const4s;
11988 if (size_of_int_loc_descriptor (i)
11989 < (unsigned long) 1 + size_of_sleb128 (i))
11991 dw_loc_descr_ref ret = int_loc_descriptor (-i);
11992 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11999 return new_loc_descr (op, i, 0);
12002 /* Likewise, for unsigned constants. */
12004 static dw_loc_descr_ref
12005 uint_loc_descriptor (unsigned HOST_WIDE_INT i)
12007 const unsigned HOST_WIDE_INT max_int = INTTYPE_MAXIMUM (HOST_WIDE_INT);
12008 const unsigned HOST_WIDE_INT max_uint
12009 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT);
12011 /* If possible, use the clever signed constants handling. */
12013 return int_loc_descriptor ((HOST_WIDE_INT) i);
12015 /* Here, we are left with positive numbers that cannot be represented as
12016 HOST_WIDE_INT, i.e.:
12017 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
12019 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
12020 whereas may be better to output a negative integer: thanks to integer
12021 wrapping, we know that:
12022 x = x - 2 ** DWARF2_ADDR_SIZE
12023 = x - 2 * (max (HOST_WIDE_INT) + 1)
12024 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
12025 small negative integers. Let's try that in cases it will clearly improve
12026 the encoding: there is no gain turning DW_OP_const4u into
12028 if (DWARF2_ADDR_SIZE * 8 == HOST_BITS_PER_WIDE_INT
12029 && ((DWARF2_ADDR_SIZE == 4 && i > max_uint - 0x8000)
12030 || (DWARF2_ADDR_SIZE == 8 && i > max_uint - 0x80000000)))
12032 const unsigned HOST_WIDE_INT first_shift = i - max_int - 1;
12034 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
12035 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
12036 const HOST_WIDE_INT second_shift
12037 = (HOST_WIDE_INT) first_shift - (HOST_WIDE_INT) max_int - 1;
12039 /* So we finally have:
12040 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
12041 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
12042 return int_loc_descriptor (second_shift);
12045 /* Last chance: fallback to a simple constant operation. */
12046 return new_loc_descr
12047 ((HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
12053 /* Generate and return a location description that computes the unsigned
12054 comparison of the two stack top entries (a OP b where b is the top-most
12055 entry and a is the second one). The KIND of comparison can be LT_EXPR,
12056 LE_EXPR, GT_EXPR or GE_EXPR. */
12058 static dw_loc_descr_ref
12059 uint_comparison_loc_list (enum tree_code kind)
12061 enum dwarf_location_atom op, flip_op;
12062 dw_loc_descr_ref ret, bra_node, jmp_node, tmp;
12079 gcc_unreachable ();
12082 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12083 jmp_node = new_loc_descr (DW_OP_skip, 0, 0);
12085 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
12086 possible to perform unsigned comparisons: we just have to distinguish
12089 1. when a and b have the same sign (as signed integers); then we should
12090 return: a OP(signed) b;
12092 2. when a is a negative signed integer while b is a positive one, then a
12093 is a greater unsigned integer than b; likewise when a and b's roles
12096 So first, compare the sign of the two operands. */
12097 ret = new_loc_descr (DW_OP_over, 0, 0);
12098 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
12099 add_loc_descr (&ret, new_loc_descr (DW_OP_xor, 0, 0));
12100 /* If they have different signs (i.e. they have different sign bits), then
12101 the stack top value has now the sign bit set and thus it's smaller than
12103 add_loc_descr (&ret, new_loc_descr (DW_OP_lit0, 0, 0));
12104 add_loc_descr (&ret, new_loc_descr (DW_OP_lt, 0, 0));
12105 add_loc_descr (&ret, bra_node);
12107 /* We are in case 1. At this point, we know both operands have the same
12108 sign, to it's safe to use the built-in signed comparison. */
12109 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
12110 add_loc_descr (&ret, jmp_node);
12112 /* We are in case 2. Here, we know both operands do not have the same sign,
12113 so we have to flip the signed comparison. */
12114 flip_op = (kind == LT_EXPR || kind == LE_EXPR) ? DW_OP_gt : DW_OP_lt;
12115 tmp = new_loc_descr (flip_op, 0, 0);
12116 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12117 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
12118 add_loc_descr (&ret, tmp);
12120 /* This dummy operation is necessary to make the two branches join. */
12121 tmp = new_loc_descr (DW_OP_nop, 0, 0);
12122 jmp_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12123 jmp_node->dw_loc_oprnd1.v.val_loc = tmp;
12124 add_loc_descr (&ret, tmp);
12129 /* Likewise, but takes the location description lists (might be destructive on
12130 them). Return NULL if either is NULL or if concatenation fails. */
12132 static dw_loc_list_ref
12133 loc_list_from_uint_comparison (dw_loc_list_ref left, dw_loc_list_ref right,
12134 enum tree_code kind)
12136 if (left == NULL || right == NULL)
12139 add_loc_list (&left, right);
12143 add_loc_descr_to_each (left, uint_comparison_loc_list (kind));
12147 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
12148 without actually allocating it. */
12150 static unsigned long
12151 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
12153 return size_of_int_loc_descriptor (i >> shift)
12154 + size_of_int_loc_descriptor (shift)
12158 /* Return size_of_locs (int_loc_descriptor (i)) without
12159 actually allocating it. */
12161 static unsigned long
12162 size_of_int_loc_descriptor (HOST_WIDE_INT i)
12171 else if (i <= 0xff)
12173 else if (i <= 0xffff)
12177 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
12178 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
12179 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
12181 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
12182 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
12183 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
12185 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
12187 s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
12188 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
12189 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
12190 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
12192 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
12193 && clz + 16 + (s > 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT)
12194 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
12196 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
12197 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
12199 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
12208 else if (i >= -0x8000)
12210 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
12212 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
12214 s = size_of_int_loc_descriptor (-i) + 1;
12222 unsigned long r = 1 + size_of_sleb128 (i);
12223 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
12225 s = size_of_int_loc_descriptor (-i) + 1;
12234 /* Return loc description representing "address" of integer value.
12235 This can appear only as toplevel expression. */
12237 static dw_loc_descr_ref
12238 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
12241 dw_loc_descr_ref loc_result = NULL;
12243 if (!(dwarf_version >= 4 || !dwarf_strict))
12246 litsize = size_of_int_loc_descriptor (i);
12247 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
12248 is more compact. For DW_OP_stack_value we need:
12249 litsize + 1 (DW_OP_stack_value)
12250 and for DW_OP_implicit_value:
12251 1 (DW_OP_implicit_value) + 1 (length) + size. */
12252 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
12254 loc_result = int_loc_descriptor (i);
12255 add_loc_descr (&loc_result,
12256 new_loc_descr (DW_OP_stack_value, 0, 0));
12260 loc_result = new_loc_descr (DW_OP_implicit_value,
12262 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
12263 loc_result->dw_loc_oprnd2.v.val_int = i;
12267 /* Return a location descriptor that designates a base+offset location. */
12269 static dw_loc_descr_ref
12270 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
12271 enum var_init_status initialized)
12273 unsigned int regno;
12274 dw_loc_descr_ref result;
12275 dw_fde_ref fde = cfun->fde;
12277 /* We only use "frame base" when we're sure we're talking about the
12278 post-prologue local stack frame. We do this by *not* running
12279 register elimination until this point, and recognizing the special
12280 argument pointer and soft frame pointer rtx's. */
12281 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
12283 rtx elim = (ira_use_lra_p
12284 ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
12285 : eliminate_regs (reg, VOIDmode, NULL_RTX));
12289 if (GET_CODE (elim) == PLUS)
12291 offset += INTVAL (XEXP (elim, 1));
12292 elim = XEXP (elim, 0);
12294 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12295 && (elim == hard_frame_pointer_rtx
12296 || elim == stack_pointer_rtx))
12297 || elim == (frame_pointer_needed
12298 ? hard_frame_pointer_rtx
12299 : stack_pointer_rtx));
12301 /* If drap register is used to align stack, use frame
12302 pointer + offset to access stack variables. If stack
12303 is aligned without drap, use stack pointer + offset to
12304 access stack variables. */
12305 if (crtl->stack_realign_tried
12306 && reg == frame_pointer_rtx)
12309 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
12310 ? HARD_FRAME_POINTER_REGNUM
12312 return new_reg_loc_descr (base_reg, offset);
12315 gcc_assert (frame_pointer_fb_offset_valid);
12316 offset += frame_pointer_fb_offset;
12317 return new_loc_descr (DW_OP_fbreg, offset, 0);
12321 regno = REGNO (reg);
12322 #ifdef LEAF_REG_REMAP
12323 if (crtl->uses_only_leaf_regs)
12325 int leaf_reg = LEAF_REG_REMAP (regno);
12326 if (leaf_reg != -1)
12327 regno = (unsigned) leaf_reg;
12330 regno = DWARF_FRAME_REGNUM (regno);
12332 if (!optimize && fde
12333 && (fde->drap_reg == regno || fde->vdrap_reg == regno))
12335 /* Use cfa+offset to represent the location of arguments passed
12336 on the stack when drap is used to align stack.
12337 Only do this when not optimizing, for optimized code var-tracking
12338 is supposed to track where the arguments live and the register
12339 used as vdrap or drap in some spot might be used for something
12340 else in other part of the routine. */
12341 return new_loc_descr (DW_OP_fbreg, offset, 0);
12345 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
12348 result = new_loc_descr (DW_OP_bregx, regno, offset);
12350 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
12351 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12356 /* Return true if this RTL expression describes a base+offset calculation. */
12359 is_based_loc (const_rtx rtl)
12361 return (GET_CODE (rtl) == PLUS
12362 && ((REG_P (XEXP (rtl, 0))
12363 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
12364 && CONST_INT_P (XEXP (rtl, 1)))));
12367 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
12370 static dw_loc_descr_ref
12371 tls_mem_loc_descriptor (rtx mem)
12374 dw_loc_descr_ref loc_result;
12376 if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
12379 base = get_base_address (MEM_EXPR (mem));
12381 || TREE_CODE (base) != VAR_DECL
12382 || !DECL_THREAD_LOCAL_P (base))
12385 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1, NULL);
12386 if (loc_result == NULL)
12389 if (MEM_OFFSET (mem))
12390 loc_descr_plus_const (&loc_result, MEM_OFFSET (mem));
12395 /* Output debug info about reason why we failed to expand expression as dwarf
12399 expansion_failed (tree expr, rtx rtl, char const *reason)
12401 if (dump_file && (dump_flags & TDF_DETAILS))
12403 fprintf (dump_file, "Failed to expand as dwarf: ");
12405 print_generic_expr (dump_file, expr, dump_flags);
12408 fprintf (dump_file, "\n");
12409 print_rtl (dump_file, rtl);
12411 fprintf (dump_file, "\nReason: %s\n", reason);
12415 /* Helper function for const_ok_for_output. */
12418 const_ok_for_output_1 (rtx rtl)
12420 if (GET_CODE (rtl) == UNSPEC)
12422 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
12423 we can't express it in the debug info. */
12424 /* Don't complain about TLS UNSPECs, those are just too hard to
12425 delegitimize. Note this could be a non-decl SYMBOL_REF such as
12426 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
12427 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
12429 && (XVECLEN (rtl, 0) == 0
12430 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
12431 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl, 0, 0)) == TLS_MODEL_NONE))
12432 inform (current_function_decl
12433 ? DECL_SOURCE_LOCATION (current_function_decl)
12434 : UNKNOWN_LOCATION,
12435 #if NUM_UNSPEC_VALUES > 0
12436 "non-delegitimized UNSPEC %s (%d) found in variable location",
12437 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
12438 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
12441 "non-delegitimized UNSPEC %d found in variable location",
12444 expansion_failed (NULL_TREE, rtl,
12445 "UNSPEC hasn't been delegitimized.\n");
12449 if (targetm.const_not_ok_for_debug_p (rtl))
12451 expansion_failed (NULL_TREE, rtl,
12452 "Expression rejected for debug by the backend.\n");
12456 /* FIXME: Refer to PR60655. It is possible for simplification
12457 of rtl expressions in var tracking to produce such expressions.
12458 We should really identify / validate expressions
12459 enclosed in CONST that can be handled by assemblers on various
12460 targets and only handle legitimate cases here. */
12461 if (GET_CODE (rtl) != SYMBOL_REF)
12463 if (GET_CODE (rtl) == NOT)
12468 if (CONSTANT_POOL_ADDRESS_P (rtl))
12471 get_pool_constant_mark (rtl, &marked);
12472 /* If all references to this pool constant were optimized away,
12473 it was not output and thus we can't represent it. */
12476 expansion_failed (NULL_TREE, rtl,
12477 "Constant was removed from constant pool.\n");
12482 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
12485 /* Avoid references to external symbols in debug info, on several targets
12486 the linker might even refuse to link when linking a shared library,
12487 and in many other cases the relocations for .debug_info/.debug_loc are
12488 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
12489 to be defined within the same shared library or executable are fine. */
12490 if (SYMBOL_REF_EXTERNAL_P (rtl))
12492 tree decl = SYMBOL_REF_DECL (rtl);
12494 if (decl == NULL || !targetm.binds_local_p (decl))
12496 expansion_failed (NULL_TREE, rtl,
12497 "Symbol not defined in current TU.\n");
12505 /* Return true if constant RTL can be emitted in DW_OP_addr or
12506 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
12507 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
12510 const_ok_for_output (rtx rtl)
12512 if (GET_CODE (rtl) == SYMBOL_REF)
12513 return const_ok_for_output_1 (rtl);
12515 if (GET_CODE (rtl) == CONST)
12517 subrtx_var_iterator::array_type array;
12518 FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
12519 if (!const_ok_for_output_1 (*iter))
12527 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
12528 if possible, NULL otherwise. */
12531 base_type_for_mode (machine_mode mode, bool unsignedp)
12533 dw_die_ref type_die;
12534 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
12538 switch (TREE_CODE (type))
12546 type_die = lookup_type_die (type);
12548 type_die = modified_type_die (type, TYPE_UNQUALIFIED, false,
12550 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
12555 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
12556 type matching MODE, or, if MODE is narrower than or as wide as
12557 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
12560 static dw_loc_descr_ref
12561 convert_descriptor_to_mode (machine_mode mode, dw_loc_descr_ref op)
12563 machine_mode outer_mode = mode;
12564 dw_die_ref type_die;
12565 dw_loc_descr_ref cvt;
12567 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
12569 add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
12572 type_die = base_type_for_mode (outer_mode, 1);
12573 if (type_die == NULL)
12575 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12576 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12577 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12578 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12579 add_loc_descr (&op, cvt);
12583 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
12585 static dw_loc_descr_ref
12586 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
12587 dw_loc_descr_ref op1)
12589 dw_loc_descr_ref ret = op0;
12590 add_loc_descr (&ret, op1);
12591 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
12592 if (STORE_FLAG_VALUE != 1)
12594 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
12595 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
12600 /* Return location descriptor for signed comparison OP RTL. */
12602 static dw_loc_descr_ref
12603 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
12604 machine_mode mem_mode)
12606 machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
12607 dw_loc_descr_ref op0, op1;
12610 if (op_mode == VOIDmode)
12611 op_mode = GET_MODE (XEXP (rtl, 1));
12612 if (op_mode == VOIDmode)
12616 && (GET_MODE_CLASS (op_mode) != MODE_INT
12617 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
12620 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
12621 VAR_INIT_STATUS_INITIALIZED);
12622 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
12623 VAR_INIT_STATUS_INITIALIZED);
12625 if (op0 == NULL || op1 == NULL)
12628 if (GET_MODE_CLASS (op_mode) != MODE_INT
12629 || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
12630 return compare_loc_descriptor (op, op0, op1);
12632 if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
12634 dw_die_ref type_die = base_type_for_mode (op_mode, 0);
12635 dw_loc_descr_ref cvt;
12637 if (type_die == NULL)
12639 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12640 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12641 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12642 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12643 add_loc_descr (&op0, cvt);
12644 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12645 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12646 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12647 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12648 add_loc_descr (&op1, cvt);
12649 return compare_loc_descriptor (op, op0, op1);
12652 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
12653 /* For eq/ne, if the operands are known to be zero-extended,
12654 there is no need to do the fancy shifting up. */
12655 if (op == DW_OP_eq || op == DW_OP_ne)
12657 dw_loc_descr_ref last0, last1;
12658 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
12660 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
12662 /* deref_size zero extends, and for constants we can check
12663 whether they are zero extended or not. */
12664 if (((last0->dw_loc_opc == DW_OP_deref_size
12665 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
12666 || (CONST_INT_P (XEXP (rtl, 0))
12667 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
12668 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
12669 && ((last1->dw_loc_opc == DW_OP_deref_size
12670 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
12671 || (CONST_INT_P (XEXP (rtl, 1))
12672 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
12673 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
12674 return compare_loc_descriptor (op, op0, op1);
12676 /* EQ/NE comparison against constant in narrower type than
12677 DWARF2_ADDR_SIZE can be performed either as
12678 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
12681 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
12682 DW_OP_{eq,ne}. Pick whatever is shorter. */
12683 if (CONST_INT_P (XEXP (rtl, 1))
12684 && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
12685 && (size_of_int_loc_descriptor (shift) + 1
12686 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift)
12687 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
12688 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
12689 & GET_MODE_MASK (op_mode))))
12691 add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
12692 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
12693 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
12694 & GET_MODE_MASK (op_mode));
12695 return compare_loc_descriptor (op, op0, op1);
12698 add_loc_descr (&op0, int_loc_descriptor (shift));
12699 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
12700 if (CONST_INT_P (XEXP (rtl, 1)))
12701 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
12704 add_loc_descr (&op1, int_loc_descriptor (shift));
12705 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
12707 return compare_loc_descriptor (op, op0, op1);
12710 /* Return location descriptor for unsigned comparison OP RTL. */
12712 static dw_loc_descr_ref
12713 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
12714 machine_mode mem_mode)
12716 machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
12717 dw_loc_descr_ref op0, op1;
12719 if (op_mode == VOIDmode)
12720 op_mode = GET_MODE (XEXP (rtl, 1));
12721 if (op_mode == VOIDmode)
12723 if (GET_MODE_CLASS (op_mode) != MODE_INT)
12726 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
12729 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
12730 VAR_INIT_STATUS_INITIALIZED);
12731 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
12732 VAR_INIT_STATUS_INITIALIZED);
12734 if (op0 == NULL || op1 == NULL)
12737 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
12739 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
12740 dw_loc_descr_ref last0, last1;
12741 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
12743 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
12745 if (CONST_INT_P (XEXP (rtl, 0)))
12746 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
12747 /* deref_size zero extends, so no need to mask it again. */
12748 else if (last0->dw_loc_opc != DW_OP_deref_size
12749 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
12751 add_loc_descr (&op0, int_loc_descriptor (mask));
12752 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
12754 if (CONST_INT_P (XEXP (rtl, 1)))
12755 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
12756 /* deref_size zero extends, so no need to mask it again. */
12757 else if (last1->dw_loc_opc != DW_OP_deref_size
12758 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
12760 add_loc_descr (&op1, int_loc_descriptor (mask));
12761 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
12764 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
12766 HOST_WIDE_INT bias = 1;
12767 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
12768 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
12769 if (CONST_INT_P (XEXP (rtl, 1)))
12770 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
12771 + INTVAL (XEXP (rtl, 1)));
12773 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
12776 return compare_loc_descriptor (op, op0, op1);
12779 /* Return location descriptor for {U,S}{MIN,MAX}. */
12781 static dw_loc_descr_ref
12782 minmax_loc_descriptor (rtx rtl, machine_mode mode,
12783 machine_mode mem_mode)
12785 enum dwarf_location_atom op;
12786 dw_loc_descr_ref op0, op1, ret;
12787 dw_loc_descr_ref bra_node, drop_node;
12790 && (GET_MODE_CLASS (mode) != MODE_INT
12791 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
12794 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12795 VAR_INIT_STATUS_INITIALIZED);
12796 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12797 VAR_INIT_STATUS_INITIALIZED);
12799 if (op0 == NULL || op1 == NULL)
12802 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
12803 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
12804 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
12805 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
12807 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
12809 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
12810 add_loc_descr (&op0, int_loc_descriptor (mask));
12811 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
12812 add_loc_descr (&op1, int_loc_descriptor (mask));
12813 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
12815 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
12817 HOST_WIDE_INT bias = 1;
12818 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
12819 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
12820 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
12823 else if (GET_MODE_CLASS (mode) == MODE_INT
12824 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
12826 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
12827 add_loc_descr (&op0, int_loc_descriptor (shift));
12828 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
12829 add_loc_descr (&op1, int_loc_descriptor (shift));
12830 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
12832 else if (GET_MODE_CLASS (mode) == MODE_INT
12833 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
12835 dw_die_ref type_die = base_type_for_mode (mode, 0);
12836 dw_loc_descr_ref cvt;
12837 if (type_die == NULL)
12839 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12840 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12841 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12842 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12843 add_loc_descr (&op0, cvt);
12844 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12845 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12846 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12847 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12848 add_loc_descr (&op1, cvt);
12851 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
12856 add_loc_descr (&ret, op1);
12857 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
12858 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12859 add_loc_descr (&ret, bra_node);
12860 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12861 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
12862 add_loc_descr (&ret, drop_node);
12863 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12864 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
12865 if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
12866 && GET_MODE_CLASS (mode) == MODE_INT
12867 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
12868 ret = convert_descriptor_to_mode (mode, ret);
12872 /* Helper function for mem_loc_descriptor. Perform OP binary op,
12873 but after converting arguments to type_die, afterwards
12874 convert back to unsigned. */
12876 static dw_loc_descr_ref
12877 typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
12878 machine_mode mode, machine_mode mem_mode)
12880 dw_loc_descr_ref cvt, op0, op1;
12882 if (type_die == NULL)
12884 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12885 VAR_INIT_STATUS_INITIALIZED);
12886 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12887 VAR_INIT_STATUS_INITIALIZED);
12888 if (op0 == NULL || op1 == NULL)
12890 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12891 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12892 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12893 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12894 add_loc_descr (&op0, cvt);
12895 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12896 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12897 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12898 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12899 add_loc_descr (&op1, cvt);
12900 add_loc_descr (&op0, op1);
12901 add_loc_descr (&op0, new_loc_descr (op, 0, 0));
12902 return convert_descriptor_to_mode (mode, op0);
12905 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
12906 const0 is DW_OP_lit0 or corresponding typed constant,
12907 const1 is DW_OP_lit1 or corresponding typed constant
12908 and constMSB is constant with just the MSB bit set
12910 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12911 L1: const0 DW_OP_swap
12912 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
12913 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12918 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12919 L1: const0 DW_OP_swap
12920 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12921 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12926 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
12927 L1: const1 DW_OP_swap
12928 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12929 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12933 static dw_loc_descr_ref
12934 clz_loc_descriptor (rtx rtl, machine_mode mode,
12935 machine_mode mem_mode)
12937 dw_loc_descr_ref op0, ret, tmp;
12938 HOST_WIDE_INT valv;
12939 dw_loc_descr_ref l1jump, l1label;
12940 dw_loc_descr_ref l2jump, l2label;
12941 dw_loc_descr_ref l3jump, l3label;
12942 dw_loc_descr_ref l4jump, l4label;
12945 if (GET_MODE_CLASS (mode) != MODE_INT
12946 || GET_MODE (XEXP (rtl, 0)) != mode)
12949 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12950 VAR_INIT_STATUS_INITIALIZED);
12954 if (GET_CODE (rtl) == CLZ)
12956 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
12957 valv = GET_MODE_BITSIZE (mode);
12959 else if (GET_CODE (rtl) == FFS)
12961 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
12962 valv = GET_MODE_BITSIZE (mode);
12963 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
12964 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
12965 add_loc_descr (&ret, l1jump);
12966 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
12967 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
12968 VAR_INIT_STATUS_INITIALIZED);
12971 add_loc_descr (&ret, tmp);
12972 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
12973 add_loc_descr (&ret, l4jump);
12974 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
12975 ? const1_rtx : const0_rtx,
12977 VAR_INIT_STATUS_INITIALIZED);
12978 if (l1label == NULL)
12980 add_loc_descr (&ret, l1label);
12981 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12982 l2label = new_loc_descr (DW_OP_dup, 0, 0);
12983 add_loc_descr (&ret, l2label);
12984 if (GET_CODE (rtl) != CLZ)
12986 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
12987 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
12988 << (GET_MODE_BITSIZE (mode) - 1));
12990 msb = immed_wide_int_const
12991 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode) - 1,
12992 GET_MODE_PRECISION (mode)), mode);
12993 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
12994 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
12995 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
12996 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
12998 tmp = mem_loc_descriptor (msb, mode, mem_mode,
12999 VAR_INIT_STATUS_INITIALIZED);
13002 add_loc_descr (&ret, tmp);
13003 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
13004 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
13005 add_loc_descr (&ret, l3jump);
13006 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
13007 VAR_INIT_STATUS_INITIALIZED);
13010 add_loc_descr (&ret, tmp);
13011 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
13012 ? DW_OP_shl : DW_OP_shr, 0, 0));
13013 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
13014 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
13015 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
13016 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
13017 add_loc_descr (&ret, l2jump);
13018 l3label = new_loc_descr (DW_OP_drop, 0, 0);
13019 add_loc_descr (&ret, l3label);
13020 l4label = new_loc_descr (DW_OP_nop, 0, 0);
13021 add_loc_descr (&ret, l4label);
13022 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
13023 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
13024 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
13025 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
13026 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
13027 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
13028 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
13029 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
13033 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
13034 const1 is DW_OP_lit1 or corresponding typed constant):
13036 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
13037 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
13041 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
13042 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
13045 static dw_loc_descr_ref
13046 popcount_loc_descriptor (rtx rtl, machine_mode mode,
13047 machine_mode mem_mode)
13049 dw_loc_descr_ref op0, ret, tmp;
13050 dw_loc_descr_ref l1jump, l1label;
13051 dw_loc_descr_ref l2jump, l2label;
13053 if (GET_MODE_CLASS (mode) != MODE_INT
13054 || GET_MODE (XEXP (rtl, 0)) != mode)
13057 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13058 VAR_INIT_STATUS_INITIALIZED);
13062 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
13063 VAR_INIT_STATUS_INITIALIZED);
13066 add_loc_descr (&ret, tmp);
13067 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
13068 l1label = new_loc_descr (DW_OP_dup, 0, 0);
13069 add_loc_descr (&ret, l1label);
13070 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
13071 add_loc_descr (&ret, l2jump);
13072 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
13073 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
13074 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
13075 VAR_INIT_STATUS_INITIALIZED);
13078 add_loc_descr (&ret, tmp);
13079 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
13080 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
13081 ? DW_OP_plus : DW_OP_xor, 0, 0));
13082 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
13083 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
13084 VAR_INIT_STATUS_INITIALIZED);
13085 add_loc_descr (&ret, tmp);
13086 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
13087 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
13088 add_loc_descr (&ret, l1jump);
13089 l2label = new_loc_descr (DW_OP_drop, 0, 0);
13090 add_loc_descr (&ret, l2label);
13091 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
13092 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
13093 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
13094 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
13098 /* BSWAP (constS is initial shift count, either 56 or 24):
13100 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
13101 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
13102 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
13103 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
13104 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
13106 static dw_loc_descr_ref
13107 bswap_loc_descriptor (rtx rtl, machine_mode mode,
13108 machine_mode mem_mode)
13110 dw_loc_descr_ref op0, ret, tmp;
13111 dw_loc_descr_ref l1jump, l1label;
13112 dw_loc_descr_ref l2jump, l2label;
13114 if (GET_MODE_CLASS (mode) != MODE_INT
13115 || BITS_PER_UNIT != 8
13116 || (GET_MODE_BITSIZE (mode) != 32
13117 && GET_MODE_BITSIZE (mode) != 64))
13120 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13121 VAR_INIT_STATUS_INITIALIZED);
13126 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
13128 VAR_INIT_STATUS_INITIALIZED);
13131 add_loc_descr (&ret, tmp);
13132 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
13133 VAR_INIT_STATUS_INITIALIZED);
13136 add_loc_descr (&ret, tmp);
13137 l1label = new_loc_descr (DW_OP_pick, 2, 0);
13138 add_loc_descr (&ret, l1label);
13139 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
13141 VAR_INIT_STATUS_INITIALIZED);
13142 add_loc_descr (&ret, tmp);
13143 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
13144 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
13145 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
13146 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
13147 VAR_INIT_STATUS_INITIALIZED);
13150 add_loc_descr (&ret, tmp);
13151 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
13152 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
13153 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
13154 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
13155 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
13156 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
13157 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
13158 VAR_INIT_STATUS_INITIALIZED);
13159 add_loc_descr (&ret, tmp);
13160 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
13161 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
13162 add_loc_descr (&ret, l2jump);
13163 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
13164 VAR_INIT_STATUS_INITIALIZED);
13165 add_loc_descr (&ret, tmp);
13166 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
13167 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
13168 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
13169 add_loc_descr (&ret, l1jump);
13170 l2label = new_loc_descr (DW_OP_drop, 0, 0);
13171 add_loc_descr (&ret, l2label);
13172 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
13173 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
13174 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
13175 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
13176 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
13177 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
13181 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
13182 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
13183 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
13184 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
13186 ROTATERT is similar:
13187 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
13188 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
13189 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
13191 static dw_loc_descr_ref
13192 rotate_loc_descriptor (rtx rtl, machine_mode mode,
13193 machine_mode mem_mode)
13195 rtx rtlop1 = XEXP (rtl, 1);
13196 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
13199 if (GET_MODE_CLASS (mode) != MODE_INT)
13202 if (GET_MODE (rtlop1) != VOIDmode
13203 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
13204 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
13205 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13206 VAR_INIT_STATUS_INITIALIZED);
13207 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
13208 VAR_INIT_STATUS_INITIALIZED);
13209 if (op0 == NULL || op1 == NULL)
13211 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
13212 for (i = 0; i < 2; i++)
13214 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
13215 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
13217 VAR_INIT_STATUS_INITIALIZED);
13218 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
13219 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
13221 : HOST_BITS_PER_WIDE_INT == 64
13222 ? DW_OP_const8u : DW_OP_constu,
13223 GET_MODE_MASK (mode), 0);
13226 if (mask[i] == NULL)
13228 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
13231 add_loc_descr (&ret, op1);
13232 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
13233 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
13234 if (GET_CODE (rtl) == ROTATERT)
13236 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
13237 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
13238 GET_MODE_BITSIZE (mode), 0));
13240 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
13241 if (mask[0] != NULL)
13242 add_loc_descr (&ret, mask[0]);
13243 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
13244 if (mask[1] != NULL)
13246 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
13247 add_loc_descr (&ret, mask[1]);
13248 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
13250 if (GET_CODE (rtl) == ROTATE)
13252 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
13253 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
13254 GET_MODE_BITSIZE (mode), 0));
13256 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
13257 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
13261 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
13262 for DEBUG_PARAMETER_REF RTL. */
13264 static dw_loc_descr_ref
13265 parameter_ref_descriptor (rtx rtl)
13267 dw_loc_descr_ref ret;
13272 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
13273 ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
13274 ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
13277 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13278 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
13279 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
13283 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
13284 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
13289 /* The following routine converts the RTL for a variable or parameter
13290 (resident in memory) into an equivalent Dwarf representation of a
13291 mechanism for getting the address of that same variable onto the top of a
13292 hypothetical "address evaluation" stack.
13294 When creating memory location descriptors, we are effectively transforming
13295 the RTL for a memory-resident object into its Dwarf postfix expression
13296 equivalent. This routine recursively descends an RTL tree, turning
13297 it into Dwarf postfix code as it goes.
13299 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
13301 MEM_MODE is the mode of the memory reference, needed to handle some
13302 autoincrement addressing modes.
13304 Return 0 if we can't represent the location. */
13307 mem_loc_descriptor (rtx rtl, machine_mode mode,
13308 machine_mode mem_mode,
13309 enum var_init_status initialized)
13311 dw_loc_descr_ref mem_loc_result = NULL;
13312 enum dwarf_location_atom op;
13313 dw_loc_descr_ref op0, op1;
13314 rtx inner = NULL_RTX;
13316 if (mode == VOIDmode)
13317 mode = GET_MODE (rtl);
13319 /* Note that for a dynamically sized array, the location we will generate a
13320 description of here will be the lowest numbered location which is
13321 actually within the array. That's *not* necessarily the same as the
13322 zeroth element of the array. */
13324 rtl = targetm.delegitimize_address (rtl);
13326 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
13329 switch (GET_CODE (rtl))
13334 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
13337 /* The case of a subreg may arise when we have a local (register)
13338 variable or a formal (register) parameter which doesn't quite fill
13339 up an entire register. For now, just assume that it is
13340 legitimate to make the Dwarf info refer to the whole register which
13341 contains the given subreg. */
13342 if (!subreg_lowpart_p (rtl))
13344 inner = SUBREG_REG (rtl);
13347 if (inner == NULL_RTX)
13348 inner = XEXP (rtl, 0);
13349 if (GET_MODE_CLASS (mode) == MODE_INT
13350 && GET_MODE_CLASS (GET_MODE (inner)) == MODE_INT
13351 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
13352 #ifdef POINTERS_EXTEND_UNSIGNED
13353 || (mode == Pmode && mem_mode != VOIDmode)
13356 && GET_MODE_SIZE (GET_MODE (inner)) <= DWARF2_ADDR_SIZE)
13358 mem_loc_result = mem_loc_descriptor (inner,
13360 mem_mode, initialized);
13365 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (inner)))
13367 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (inner))
13368 && (GET_MODE_CLASS (mode) != MODE_INT
13369 || GET_MODE_CLASS (GET_MODE (inner)) != MODE_INT))
13373 dw_die_ref type_die;
13374 dw_loc_descr_ref cvt;
13376 mem_loc_result = mem_loc_descriptor (inner,
13378 mem_mode, initialized);
13379 if (mem_loc_result == NULL)
13381 type_die = base_type_for_mode (mode,
13382 GET_MODE_CLASS (mode) == MODE_INT);
13383 if (type_die == NULL)
13385 mem_loc_result = NULL;
13388 if (GET_MODE_SIZE (mode)
13389 != GET_MODE_SIZE (GET_MODE (inner)))
13390 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13392 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 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_die;
13395 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13396 add_loc_descr (&mem_loc_result, cvt);
13397 if (GET_MODE_CLASS (mode) == MODE_INT
13398 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
13400 /* Convert it to untyped afterwards. */
13401 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13402 add_loc_descr (&mem_loc_result, cvt);
13408 if (GET_MODE_CLASS (mode) != MODE_INT
13409 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
13410 && rtl != arg_pointer_rtx
13411 && rtl != frame_pointer_rtx
13412 #ifdef POINTERS_EXTEND_UNSIGNED
13413 && (mode != Pmode || mem_mode == VOIDmode)
13417 dw_die_ref type_die;
13418 unsigned int dbx_regnum;
13422 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
13424 type_die = base_type_for_mode (mode,
13425 GET_MODE_CLASS (mode) == MODE_INT);
13426 if (type_die == NULL)
13429 dbx_regnum = dbx_reg_number (rtl);
13430 if (dbx_regnum == IGNORED_DWARF_REGNUM)
13432 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
13434 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
13435 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
13436 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
13439 /* Whenever a register number forms a part of the description of the
13440 method for calculating the (dynamic) address of a memory resident
13441 object, DWARF rules require the register number be referred to as
13442 a "base register". This distinction is not based in any way upon
13443 what category of register the hardware believes the given register
13444 belongs to. This is strictly DWARF terminology we're dealing with
13445 here. Note that in cases where the location of a memory-resident
13446 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13447 OP_CONST (0)) the actual DWARF location descriptor that we generate
13448 may just be OP_BASEREG (basereg). This may look deceptively like
13449 the object in question was allocated to a register (rather than in
13450 memory) so DWARF consumers need to be aware of the subtle
13451 distinction between OP_REG and OP_BASEREG. */
13452 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13453 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13454 else if (stack_realign_drap
13456 && crtl->args.internal_arg_pointer == rtl
13457 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13459 /* If RTL is internal_arg_pointer, which has been optimized
13460 out, use DRAP instead. */
13461 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13462 VAR_INIT_STATUS_INITIALIZED);
13468 if (GET_MODE_CLASS (mode) != MODE_INT)
13470 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
13471 mem_mode, VAR_INIT_STATUS_INITIALIZED);
13474 else if (GET_CODE (rtl) == ZERO_EXTEND
13475 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
13476 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
13477 < HOST_BITS_PER_WIDE_INT
13478 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
13479 to expand zero extend as two shifts instead of
13481 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
13483 machine_mode imode = GET_MODE (XEXP (rtl, 0));
13484 mem_loc_result = op0;
13485 add_loc_descr (&mem_loc_result,
13486 int_loc_descriptor (GET_MODE_MASK (imode)));
13487 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
13489 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
13491 int shift = DWARF2_ADDR_SIZE
13492 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13493 shift *= BITS_PER_UNIT;
13494 if (GET_CODE (rtl) == SIGN_EXTEND)
13498 mem_loc_result = op0;
13499 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13500 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13501 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13502 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13504 else if (!dwarf_strict)
13506 dw_die_ref type_die1, type_die2;
13507 dw_loc_descr_ref cvt;
13509 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
13510 GET_CODE (rtl) == ZERO_EXTEND);
13511 if (type_die1 == NULL)
13513 type_die2 = base_type_for_mode (mode, 1);
13514 if (type_die2 == NULL)
13516 mem_loc_result = op0;
13517 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13518 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13519 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
13520 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13521 add_loc_descr (&mem_loc_result, cvt);
13522 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13523 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13524 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
13525 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13526 add_loc_descr (&mem_loc_result, cvt);
13532 rtx new_rtl = avoid_constant_pool_reference (rtl);
13533 if (new_rtl != rtl)
13535 mem_loc_result = mem_loc_descriptor (new_rtl, mode, mem_mode,
13537 if (mem_loc_result != NULL)
13538 return mem_loc_result;
13541 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
13542 get_address_mode (rtl), mode,
13543 VAR_INIT_STATUS_INITIALIZED);
13544 if (mem_loc_result == NULL)
13545 mem_loc_result = tls_mem_loc_descriptor (rtl);
13546 if (mem_loc_result != NULL)
13548 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
13549 || GET_MODE_CLASS (mode) != MODE_INT)
13551 dw_die_ref type_die;
13552 dw_loc_descr_ref deref;
13557 = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
13558 if (type_die == NULL)
13560 deref = new_loc_descr (DW_OP_GNU_deref_type,
13561 GET_MODE_SIZE (mode), 0);
13562 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
13563 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
13564 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
13565 add_loc_descr (&mem_loc_result, deref);
13567 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
13568 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13570 add_loc_descr (&mem_loc_result,
13571 new_loc_descr (DW_OP_deref_size,
13572 GET_MODE_SIZE (mode), 0));
13577 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
13580 /* Some ports can transform a symbol ref into a label ref, because
13581 the symbol ref is too far away and has to be dumped into a constant
13585 if ((GET_MODE_CLASS (mode) != MODE_INT
13586 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
13587 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
13588 #ifdef POINTERS_EXTEND_UNSIGNED
13589 && (mode != Pmode || mem_mode == VOIDmode)
13593 if (GET_CODE (rtl) == SYMBOL_REF
13594 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13596 dw_loc_descr_ref temp;
13598 /* If this is not defined, we have no way to emit the data. */
13599 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13602 temp = new_addr_loc_descr (rtl, dtprel_true);
13604 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
13605 add_loc_descr (&mem_loc_result, temp);
13610 if (!const_ok_for_output (rtl))
13612 if (GET_CODE (rtl) == CONST)
13613 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13619 mem_loc_result = new_addr_loc_descr (rtl, dtprel_false);
13620 vec_safe_push (used_rtx_array, rtl);
13626 case DEBUG_IMPLICIT_PTR:
13627 expansion_failed (NULL_TREE, rtl,
13628 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13634 if (REG_P (ENTRY_VALUE_EXP (rtl)))
13636 if (GET_MODE_CLASS (mode) != MODE_INT
13637 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
13638 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
13639 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
13642 unsigned int dbx_regnum = dbx_reg_number (ENTRY_VALUE_EXP (rtl));
13643 if (dbx_regnum == IGNORED_DWARF_REGNUM)
13645 op0 = one_reg_loc_descriptor (dbx_regnum,
13646 VAR_INIT_STATUS_INITIALIZED);
13649 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
13650 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
13652 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
13653 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
13654 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
13658 gcc_unreachable ();
13661 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
13662 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
13663 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
13666 case DEBUG_PARAMETER_REF:
13667 mem_loc_result = parameter_ref_descriptor (rtl);
13671 /* Extract the PLUS expression nested inside and fall into
13672 PLUS code below. */
13673 rtl = XEXP (rtl, 1);
13678 /* Turn these into a PLUS expression and fall into the PLUS code
13680 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
13681 gen_int_mode (GET_CODE (rtl) == PRE_INC
13682 ? GET_MODE_UNIT_SIZE (mem_mode)
13683 : -GET_MODE_UNIT_SIZE (mem_mode),
13690 if (is_based_loc (rtl)
13691 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
13692 || XEXP (rtl, 0) == arg_pointer_rtx
13693 || XEXP (rtl, 0) == frame_pointer_rtx)
13694 && GET_MODE_CLASS (mode) == MODE_INT)
13695 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
13696 INTVAL (XEXP (rtl, 1)),
13697 VAR_INIT_STATUS_INITIALIZED);
13700 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13701 VAR_INIT_STATUS_INITIALIZED);
13702 if (mem_loc_result == 0)
13705 if (CONST_INT_P (XEXP (rtl, 1))
13706 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
13707 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13710 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
13711 VAR_INIT_STATUS_INITIALIZED);
13714 add_loc_descr (&mem_loc_result, op1);
13715 add_loc_descr (&mem_loc_result,
13716 new_loc_descr (DW_OP_plus, 0, 0));
13721 /* If a pseudo-reg is optimized away, it is possible for it to
13722 be replaced with a MEM containing a multiply or shift. */
13733 && GET_MODE_CLASS (mode) == MODE_INT
13734 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
13736 mem_loc_result = typed_binop (DW_OP_div, rtl,
13737 base_type_for_mode (mode, 0),
13761 if (GET_MODE_CLASS (mode) != MODE_INT)
13763 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13764 VAR_INIT_STATUS_INITIALIZED);
13766 rtx rtlop1 = XEXP (rtl, 1);
13767 if (GET_MODE (rtlop1) != VOIDmode
13768 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
13769 < GET_MODE_BITSIZE (mode))
13770 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
13771 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
13772 VAR_INIT_STATUS_INITIALIZED);
13775 if (op0 == 0 || op1 == 0)
13778 mem_loc_result = op0;
13779 add_loc_descr (&mem_loc_result, op1);
13780 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13796 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13797 VAR_INIT_STATUS_INITIALIZED);
13798 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
13799 VAR_INIT_STATUS_INITIALIZED);
13801 if (op0 == 0 || op1 == 0)
13804 mem_loc_result = op0;
13805 add_loc_descr (&mem_loc_result, op1);
13806 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13810 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
13812 mem_loc_result = typed_binop (DW_OP_mod, rtl,
13813 base_type_for_mode (mode, 0),
13818 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13819 VAR_INIT_STATUS_INITIALIZED);
13820 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
13821 VAR_INIT_STATUS_INITIALIZED);
13823 if (op0 == 0 || op1 == 0)
13826 mem_loc_result = op0;
13827 add_loc_descr (&mem_loc_result, op1);
13828 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13829 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13830 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
13831 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13832 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
13836 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
13838 if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
13843 mem_loc_result = typed_binop (DW_OP_div, rtl,
13844 base_type_for_mode (mode, 1),
13862 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13863 VAR_INIT_STATUS_INITIALIZED);
13868 mem_loc_result = op0;
13869 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13873 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
13874 #ifdef POINTERS_EXTEND_UNSIGNED
13876 && mem_mode != VOIDmode
13877 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
13881 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
13885 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
13886 || GET_MODE_BITSIZE (mode) == HOST_BITS_PER_DOUBLE_INT))
13888 dw_die_ref type_die = base_type_for_mode (mode, 1);
13889 machine_mode amode;
13890 if (type_die == NULL)
13892 amode = mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT,
13894 if (INTVAL (rtl) >= 0
13895 && amode != BLKmode
13896 && trunc_int_for_mode (INTVAL (rtl), amode) == INTVAL (rtl)
13897 /* const DW_OP_GNU_convert <XXX> vs.
13898 DW_OP_GNU_const_type <XXX, 1, const>. */
13899 && size_of_int_loc_descriptor (INTVAL (rtl)) + 1 + 1
13900 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode))
13902 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
13903 op0 = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13904 op0->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13905 op0->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13906 op0->dw_loc_oprnd1.v.val_die_ref.external = 0;
13907 add_loc_descr (&mem_loc_result, op0);
13908 return mem_loc_result;
13910 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
13912 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13913 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13914 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
13915 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
13916 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13919 mem_loc_result->dw_loc_oprnd2.val_class
13920 = dw_val_class_const_double;
13921 mem_loc_result->dw_loc_oprnd2.v.val_double
13922 = double_int::from_shwi (INTVAL (rtl));
13930 dw_die_ref type_die;
13932 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
13933 CONST_DOUBLE rtx could represent either a large integer
13934 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
13935 the value is always a floating point constant.
13937 When it is an integer, a CONST_DOUBLE is used whenever
13938 the constant requires 2 HWIs to be adequately represented.
13939 We output CONST_DOUBLEs as blocks. */
13940 if (mode == VOIDmode
13941 || (GET_MODE (rtl) == VOIDmode
13942 && GET_MODE_BITSIZE (mode) != HOST_BITS_PER_DOUBLE_INT))
13944 type_die = base_type_for_mode (mode,
13945 GET_MODE_CLASS (mode) == MODE_INT);
13946 if (type_die == NULL)
13948 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
13949 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13950 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13951 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
13952 #if TARGET_SUPPORTS_WIDE_INT == 0
13953 if (!SCALAR_FLOAT_MODE_P (mode))
13955 mem_loc_result->dw_loc_oprnd2.val_class
13956 = dw_val_class_const_double;
13957 mem_loc_result->dw_loc_oprnd2.v.val_double
13958 = rtx_to_double_int (rtl);
13963 unsigned int length = GET_MODE_SIZE (mode);
13964 unsigned char *array = ggc_vec_alloc<unsigned char> (length);
13966 insert_float (rtl, array);
13967 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
13968 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
13969 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
13970 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
13975 case CONST_WIDE_INT:
13978 dw_die_ref type_die;
13980 type_die = base_type_for_mode (mode,
13981 GET_MODE_CLASS (mode) == MODE_INT);
13982 if (type_die == NULL)
13984 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
13985 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13986 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13987 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
13988 mem_loc_result->dw_loc_oprnd2.val_class
13989 = dw_val_class_wide_int;
13990 mem_loc_result->dw_loc_oprnd2.v.val_wide = ggc_alloc<wide_int> ();
13991 *mem_loc_result->dw_loc_oprnd2.v.val_wide = std::make_pair (rtl, mode);
13996 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
14000 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
14004 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
14008 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
14012 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
14016 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
14020 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
14024 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
14028 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
14032 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
14037 if (GET_MODE_CLASS (mode) != MODE_INT)
14042 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
14047 if (CONST_INT_P (XEXP (rtl, 1))
14048 && CONST_INT_P (XEXP (rtl, 2))
14049 && ((unsigned) INTVAL (XEXP (rtl, 1))
14050 + (unsigned) INTVAL (XEXP (rtl, 2))
14051 <= GET_MODE_BITSIZE (mode))
14052 && GET_MODE_CLASS (mode) == MODE_INT
14053 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
14054 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14057 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
14058 mem_mode, VAR_INIT_STATUS_INITIALIZED);
14061 if (GET_CODE (rtl) == SIGN_EXTRACT)
14065 mem_loc_result = op0;
14066 size = INTVAL (XEXP (rtl, 1));
14067 shift = INTVAL (XEXP (rtl, 2));
14068 if (BITS_BIG_ENDIAN)
14069 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14071 if (shift + size != (int) DWARF2_ADDR_SIZE)
14073 add_loc_descr (&mem_loc_result,
14074 int_loc_descriptor (DWARF2_ADDR_SIZE
14076 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14078 if (size != (int) DWARF2_ADDR_SIZE)
14080 add_loc_descr (&mem_loc_result,
14081 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14082 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14089 dw_loc_descr_ref op2, bra_node, drop_node;
14090 op0 = mem_loc_descriptor (XEXP (rtl, 0),
14091 GET_MODE (XEXP (rtl, 0)) == VOIDmode
14092 ? word_mode : GET_MODE (XEXP (rtl, 0)),
14093 mem_mode, VAR_INIT_STATUS_INITIALIZED);
14094 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14095 VAR_INIT_STATUS_INITIALIZED);
14096 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
14097 VAR_INIT_STATUS_INITIALIZED);
14098 if (op0 == NULL || op1 == NULL || op2 == NULL)
14101 mem_loc_result = op1;
14102 add_loc_descr (&mem_loc_result, op2);
14103 add_loc_descr (&mem_loc_result, op0);
14104 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14105 add_loc_descr (&mem_loc_result, bra_node);
14106 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14107 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14108 add_loc_descr (&mem_loc_result, drop_node);
14109 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14110 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14115 case FLOAT_TRUNCATE:
14117 case UNSIGNED_FLOAT:
14122 dw_die_ref type_die;
14123 dw_loc_descr_ref cvt;
14125 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
14126 mem_mode, VAR_INIT_STATUS_INITIALIZED);
14129 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
14130 && (GET_CODE (rtl) == FLOAT
14131 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
14132 <= DWARF2_ADDR_SIZE))
14134 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
14135 GET_CODE (rtl) == UNSIGNED_FLOAT);
14136 if (type_die == NULL)
14138 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14139 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14140 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14141 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14142 add_loc_descr (&op0, cvt);
14144 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
14145 if (type_die == NULL)
14147 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14148 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14149 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14150 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14151 add_loc_descr (&op0, cvt);
14152 if (GET_MODE_CLASS (mode) == MODE_INT
14153 && (GET_CODE (rtl) == FIX
14154 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
14156 op0 = convert_descriptor_to_mode (mode, op0);
14160 mem_loc_result = op0;
14167 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
14172 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
14176 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
14181 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
14185 /* In theory, we could implement the above. */
14186 /* DWARF cannot represent the unsigned compare operations
14211 case FRACT_CONVERT:
14212 case UNSIGNED_FRACT_CONVERT:
14214 case UNSIGNED_SAT_FRACT:
14220 case VEC_DUPLICATE:
14224 case STRICT_LOW_PART:
14229 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14230 can't express it in the debug info. This can happen e.g. with some
14235 resolve_one_addr (&rtl);
14241 print_rtl (stderr, rtl);
14242 gcc_unreachable ();
14247 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14248 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14250 return mem_loc_result;
14253 /* Return a descriptor that describes the concatenation of two locations.
14254 This is typically a complex variable. */
14256 static dw_loc_descr_ref
14257 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14259 dw_loc_descr_ref cc_loc_result = NULL;
14260 dw_loc_descr_ref x0_ref
14261 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14262 dw_loc_descr_ref x1_ref
14263 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14265 if (x0_ref == 0 || x1_ref == 0)
14268 cc_loc_result = x0_ref;
14269 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14271 add_loc_descr (&cc_loc_result, x1_ref);
14272 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14274 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14275 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14277 return cc_loc_result;
14280 /* Return a descriptor that describes the concatenation of N
14283 static dw_loc_descr_ref
14284 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14287 dw_loc_descr_ref cc_loc_result = NULL;
14288 unsigned int n = XVECLEN (concatn, 0);
14290 for (i = 0; i < n; ++i)
14292 dw_loc_descr_ref ref;
14293 rtx x = XVECEXP (concatn, 0, i);
14295 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14299 add_loc_descr (&cc_loc_result, ref);
14300 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14303 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14304 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14306 return cc_loc_result;
14309 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14310 for DEBUG_IMPLICIT_PTR RTL. */
14312 static dw_loc_descr_ref
14313 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
14315 dw_loc_descr_ref ret;
14320 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
14321 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
14322 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
14323 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
14324 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
14325 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
14328 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14329 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14330 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14334 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14335 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
14340 /* Output a proper Dwarf location descriptor for a variable or parameter
14341 which is either allocated in a register or in a memory location. For a
14342 register, we just generate an OP_REG and the register number. For a
14343 memory location we provide a Dwarf postfix expression describing how to
14344 generate the (dynamic) address of the object onto the address stack.
14346 MODE is mode of the decl if this loc_descriptor is going to be used in
14347 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14348 allowed, VOIDmode otherwise.
14350 If we don't know how to describe it, return 0. */
14352 static dw_loc_descr_ref
14353 loc_descriptor (rtx rtl, machine_mode mode,
14354 enum var_init_status initialized)
14356 dw_loc_descr_ref loc_result = NULL;
14358 switch (GET_CODE (rtl))
14361 /* The case of a subreg may arise when we have a local (register)
14362 variable or a formal (register) parameter which doesn't quite fill
14363 up an entire register. For now, just assume that it is
14364 legitimate to make the Dwarf info refer to the whole register which
14365 contains the given subreg. */
14366 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
14367 loc_result = loc_descriptor (SUBREG_REG (rtl),
14368 GET_MODE (SUBREG_REG (rtl)), initialized);
14374 loc_result = reg_loc_descriptor (rtl, initialized);
14378 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
14379 GET_MODE (rtl), initialized);
14380 if (loc_result == NULL)
14381 loc_result = tls_mem_loc_descriptor (rtl);
14382 if (loc_result == NULL)
14384 rtx new_rtl = avoid_constant_pool_reference (rtl);
14385 if (new_rtl != rtl)
14386 loc_result = loc_descriptor (new_rtl, mode, initialized);
14391 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14396 loc_result = concatn_loc_descriptor (rtl, initialized);
14401 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14403 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14404 if (GET_CODE (loc) == EXPR_LIST)
14405 loc = XEXP (loc, 0);
14406 loc_result = loc_descriptor (loc, mode, initialized);
14410 rtl = XEXP (rtl, 1);
14415 rtvec par_elems = XVEC (rtl, 0);
14416 int num_elem = GET_NUM_ELEM (par_elems);
14420 /* Create the first one, so we have something to add to. */
14421 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14422 VOIDmode, initialized);
14423 if (loc_result == NULL)
14425 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14426 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14427 for (i = 1; i < num_elem; i++)
14429 dw_loc_descr_ref temp;
14431 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14432 VOIDmode, initialized);
14435 add_loc_descr (&loc_result, temp);
14436 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14437 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14443 if (mode != VOIDmode && mode != BLKmode)
14444 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14449 if (mode == VOIDmode)
14450 mode = GET_MODE (rtl);
14452 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14454 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14456 /* Note that a CONST_DOUBLE rtx could represent either an integer
14457 or a floating-point constant. A CONST_DOUBLE is used whenever
14458 the constant requires more than one word in order to be
14459 adequately represented. We output CONST_DOUBLEs as blocks. */
14460 loc_result = new_loc_descr (DW_OP_implicit_value,
14461 GET_MODE_SIZE (mode), 0);
14462 #if TARGET_SUPPORTS_WIDE_INT == 0
14463 if (!SCALAR_FLOAT_MODE_P (mode))
14465 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14466 loc_result->dw_loc_oprnd2.v.val_double
14467 = rtx_to_double_int (rtl);
14472 unsigned int length = GET_MODE_SIZE (mode);
14473 unsigned char *array = ggc_vec_alloc<unsigned char> (length);
14475 insert_float (rtl, array);
14476 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14477 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14478 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14479 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14484 case CONST_WIDE_INT:
14485 if (mode == VOIDmode)
14486 mode = GET_MODE (rtl);
14488 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14490 loc_result = new_loc_descr (DW_OP_implicit_value,
14491 GET_MODE_SIZE (mode), 0);
14492 loc_result->dw_loc_oprnd2.val_class = dw_val_class_wide_int;
14493 loc_result->dw_loc_oprnd2.v.val_wide = ggc_alloc<wide_int> ();
14494 *loc_result->dw_loc_oprnd2.v.val_wide = std::make_pair (rtl, mode);
14499 if (mode == VOIDmode)
14500 mode = GET_MODE (rtl);
14502 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14504 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14505 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14506 unsigned char *array
14507 = ggc_vec_alloc<unsigned char> (length * elt_size);
14510 machine_mode imode = GET_MODE_INNER (mode);
14512 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14513 switch (GET_MODE_CLASS (mode))
14515 case MODE_VECTOR_INT:
14516 for (i = 0, p = array; i < length; i++, p += elt_size)
14518 rtx elt = CONST_VECTOR_ELT (rtl, i);
14519 insert_wide_int (std::make_pair (elt, imode), p, elt_size);
14523 case MODE_VECTOR_FLOAT:
14524 for (i = 0, p = array; i < length; i++, p += elt_size)
14526 rtx elt = CONST_VECTOR_ELT (rtl, i);
14527 insert_float (elt, p);
14532 gcc_unreachable ();
14535 loc_result = new_loc_descr (DW_OP_implicit_value,
14536 length * elt_size, 0);
14537 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14538 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14539 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14540 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14545 if (mode == VOIDmode
14546 || CONST_SCALAR_INT_P (XEXP (rtl, 0))
14547 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl, 0))
14548 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14550 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14555 if (!const_ok_for_output (rtl))
14558 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14559 && (dwarf_version >= 4 || !dwarf_strict))
14561 loc_result = new_addr_loc_descr (rtl, dtprel_false);
14562 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14563 vec_safe_push (used_rtx_array, rtl);
14567 case DEBUG_IMPLICIT_PTR:
14568 loc_result = implicit_ptr_descriptor (rtl, 0);
14572 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
14573 && CONST_INT_P (XEXP (rtl, 1)))
14576 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
14582 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14583 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14584 && dwarf_version >= 4)
14585 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
14587 /* Value expression. */
14588 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
14590 add_loc_descr (&loc_result,
14591 new_loc_descr (DW_OP_stack_value, 0, 0));
14599 /* We need to figure out what section we should use as the base for the
14600 address ranges where a given location is valid.
14601 1. If this particular DECL has a section associated with it, use that.
14602 2. If this function has a section associated with it, use that.
14603 3. Otherwise, use the text section.
14604 XXX: If you split a variable across multiple sections, we won't notice. */
14606 static const char *
14607 secname_for_decl (const_tree decl)
14609 const char *secname;
14611 if (VAR_OR_FUNCTION_DECL_P (decl)
14612 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl) || TREE_STATIC (decl))
14613 && DECL_SECTION_NAME (decl))
14614 secname = DECL_SECTION_NAME (decl);
14615 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14616 secname = DECL_SECTION_NAME (current_function_decl);
14617 else if (cfun && in_cold_section_p)
14618 secname = crtl->subsections.cold_section_label;
14620 secname = text_section_label;
14625 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14628 decl_by_reference_p (tree decl)
14630 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14631 || TREE_CODE (decl) == VAR_DECL)
14632 && DECL_BY_REFERENCE (decl));
14635 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14638 static dw_loc_descr_ref
14639 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14640 enum var_init_status initialized)
14642 int have_address = 0;
14643 dw_loc_descr_ref descr;
14646 if (want_address != 2)
14648 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14650 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14652 varloc = PAT_VAR_LOCATION_LOC (varloc);
14653 if (GET_CODE (varloc) == EXPR_LIST)
14654 varloc = XEXP (varloc, 0);
14655 mode = GET_MODE (varloc);
14656 if (MEM_P (varloc))
14658 rtx addr = XEXP (varloc, 0);
14659 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
14660 mode, initialized);
14665 rtx x = avoid_constant_pool_reference (varloc);
14667 descr = mem_loc_descriptor (x, mode, VOIDmode,
14672 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
14679 if (GET_CODE (varloc) == VAR_LOCATION)
14680 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
14682 mode = DECL_MODE (loc);
14683 descr = loc_descriptor (varloc, mode, initialized);
14690 if (want_address == 2 && !have_address
14691 && (dwarf_version >= 4 || !dwarf_strict))
14693 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14695 expansion_failed (loc, NULL_RTX,
14696 "DWARF address size mismatch");
14699 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14702 /* Show if we can't fill the request for an address. */
14703 if (want_address && !have_address)
14705 expansion_failed (loc, NULL_RTX,
14706 "Want address and only have value");
14710 /* If we've got an address and don't want one, dereference. */
14711 if (!want_address && have_address)
14713 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14714 enum dwarf_location_atom op;
14716 if (size > DWARF2_ADDR_SIZE || size == -1)
14718 expansion_failed (loc, NULL_RTX,
14719 "DWARF address size mismatch");
14722 else if (size == DWARF2_ADDR_SIZE)
14725 op = DW_OP_deref_size;
14727 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14733 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14734 if it is not possible. */
14736 static dw_loc_descr_ref
14737 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14739 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14740 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14741 else if (dwarf_version >= 3 || !dwarf_strict)
14742 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14747 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14748 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14750 static dw_loc_descr_ref
14751 dw_sra_loc_expr (tree decl, rtx loc)
14754 unsigned HOST_WIDE_INT padsize = 0;
14755 dw_loc_descr_ref descr, *descr_tail;
14756 unsigned HOST_WIDE_INT decl_size;
14758 enum var_init_status initialized;
14760 if (DECL_SIZE (decl) == NULL
14761 || !tree_fits_uhwi_p (DECL_SIZE (decl)))
14764 decl_size = tree_to_uhwi (DECL_SIZE (decl));
14766 descr_tail = &descr;
14768 for (p = loc; p; p = XEXP (p, 1))
14770 unsigned HOST_WIDE_INT bitsize = decl_piece_bitsize (p);
14771 rtx loc_note = *decl_piece_varloc_ptr (p);
14772 dw_loc_descr_ref cur_descr;
14773 dw_loc_descr_ref *tail, last = NULL;
14774 unsigned HOST_WIDE_INT opsize = 0;
14776 if (loc_note == NULL_RTX
14777 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14779 padsize += bitsize;
14782 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14783 varloc = NOTE_VAR_LOCATION (loc_note);
14784 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14785 if (cur_descr == NULL)
14787 padsize += bitsize;
14791 /* Check that cur_descr either doesn't use
14792 DW_OP_*piece operations, or their sum is equal
14793 to bitsize. Otherwise we can't embed it. */
14794 for (tail = &cur_descr; *tail != NULL;
14795 tail = &(*tail)->dw_loc_next)
14796 if ((*tail)->dw_loc_opc == DW_OP_piece)
14798 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14802 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14804 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14808 if (last != NULL && opsize != bitsize)
14810 padsize += bitsize;
14811 /* Discard the current piece of the descriptor and release any
14812 addr_table entries it uses. */
14813 remove_loc_list_addr_table_entries (cur_descr);
14817 /* If there is a hole, add DW_OP_*piece after empty DWARF
14818 expression, which means that those bits are optimized out. */
14821 if (padsize > decl_size)
14823 remove_loc_list_addr_table_entries (cur_descr);
14824 goto discard_descr;
14826 decl_size -= padsize;
14827 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
14828 if (*descr_tail == NULL)
14830 remove_loc_list_addr_table_entries (cur_descr);
14831 goto discard_descr;
14833 descr_tail = &(*descr_tail)->dw_loc_next;
14836 *descr_tail = cur_descr;
14838 if (bitsize > decl_size)
14839 goto discard_descr;
14840 decl_size -= bitsize;
14843 HOST_WIDE_INT offset = 0;
14844 if (GET_CODE (varloc) == VAR_LOCATION
14845 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14847 varloc = PAT_VAR_LOCATION_LOC (varloc);
14848 if (GET_CODE (varloc) == EXPR_LIST)
14849 varloc = XEXP (varloc, 0);
14853 if (GET_CODE (varloc) == CONST
14854 || GET_CODE (varloc) == SIGN_EXTEND
14855 || GET_CODE (varloc) == ZERO_EXTEND)
14856 varloc = XEXP (varloc, 0);
14857 else if (GET_CODE (varloc) == SUBREG)
14858 varloc = SUBREG_REG (varloc);
14863 /* DW_OP_bit_size offset should be zero for register
14864 or implicit location descriptions and empty location
14865 descriptions, but for memory addresses needs big endian
14867 if (MEM_P (varloc))
14869 unsigned HOST_WIDE_INT memsize
14870 = MEM_SIZE (varloc) * BITS_PER_UNIT;
14871 if (memsize != bitsize)
14873 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
14874 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
14875 goto discard_descr;
14876 if (memsize < bitsize)
14877 goto discard_descr;
14878 if (BITS_BIG_ENDIAN)
14879 offset = memsize - bitsize;
14883 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
14884 if (*descr_tail == NULL)
14885 goto discard_descr;
14886 descr_tail = &(*descr_tail)->dw_loc_next;
14890 /* If there were any non-empty expressions, add padding till the end of
14892 if (descr != NULL && decl_size != 0)
14894 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
14895 if (*descr_tail == NULL)
14896 goto discard_descr;
14901 /* Discard the descriptor and release any addr_table entries it uses. */
14902 remove_loc_list_addr_table_entries (descr);
14906 /* Return the dwarf representation of the location list LOC_LIST of
14907 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14910 static dw_loc_list_ref
14911 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
14913 const char *endname, *secname;
14915 enum var_init_status initialized;
14916 struct var_loc_node *node;
14917 dw_loc_descr_ref descr;
14918 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
14919 dw_loc_list_ref list = NULL;
14920 dw_loc_list_ref *listp = &list;
14922 /* Now that we know what section we are using for a base,
14923 actually construct the list of locations.
14924 The first location information is what is passed to the
14925 function that creates the location list, and the remaining
14926 locations just get added on to that list.
14927 Note that we only know the start address for a location
14928 (IE location changes), so to build the range, we use
14929 the range [current location start, next location start].
14930 This means we have to special case the last node, and generate
14931 a range of [last location start, end of function label]. */
14933 secname = secname_for_decl (decl);
14935 for (node = loc_list->first; node; node = node->next)
14936 if (GET_CODE (node->loc) == EXPR_LIST
14937 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
14939 if (GET_CODE (node->loc) == EXPR_LIST)
14941 /* This requires DW_OP_{,bit_}piece, which is not usable
14942 inside DWARF expressions. */
14943 if (want_address != 2)
14945 descr = dw_sra_loc_expr (decl, node->loc);
14951 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
14952 varloc = NOTE_VAR_LOCATION (node->loc);
14953 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
14957 bool range_across_switch = false;
14958 /* If section switch happens in between node->label
14959 and node->next->label (or end of function) and
14960 we can't emit it as a single entry list,
14961 emit two ranges, first one ending at the end
14962 of first partition and second one starting at the
14963 beginning of second partition. */
14964 if (node == loc_list->last_before_switch
14965 && (node != loc_list->first || loc_list->first->next)
14966 && current_function_decl)
14968 endname = cfun->fde->dw_fde_end;
14969 range_across_switch = true;
14971 /* The variable has a location between NODE->LABEL and
14972 NODE->NEXT->LABEL. */
14973 else if (node->next)
14974 endname = node->next->label;
14975 /* If the variable has a location at the last label
14976 it keeps its location until the end of function. */
14977 else if (!current_function_decl)
14978 endname = text_end_label;
14981 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
14982 current_function_funcdef_no);
14983 endname = ggc_strdup (label_id);
14986 *listp = new_loc_list (descr, node->label, endname, secname);
14987 if (TREE_CODE (decl) == PARM_DECL
14988 && node == loc_list->first
14989 && NOTE_P (node->loc)
14990 && strcmp (node->label, endname) == 0)
14991 (*listp)->force = true;
14992 listp = &(*listp)->dw_loc_next;
14994 if (range_across_switch)
14996 if (GET_CODE (node->loc) == EXPR_LIST)
14997 descr = dw_sra_loc_expr (decl, node->loc);
15000 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15001 varloc = NOTE_VAR_LOCATION (node->loc);
15002 descr = dw_loc_list_1 (decl, varloc, want_address,
15005 gcc_assert (descr);
15006 /* The variable has a location between NODE->LABEL and
15007 NODE->NEXT->LABEL. */
15009 endname = node->next->label;
15011 endname = cfun->fde->dw_fde_second_end;
15012 *listp = new_loc_list (descr,
15013 cfun->fde->dw_fde_second_begin,
15015 listp = &(*listp)->dw_loc_next;
15020 /* Try to avoid the overhead of a location list emitting a location
15021 expression instead, but only if we didn't have more than one
15022 location entry in the first place. If some entries were not
15023 representable, we don't want to pretend a single entry that was
15024 applies to the entire scope in which the variable is
15026 if (list && loc_list->first->next)
15032 /* Return if the loc_list has only single element and thus can be represented
15033 as location description. */
15036 single_element_loc_list_p (dw_loc_list_ref list)
15038 gcc_assert (!list->dw_loc_next || list->ll_symbol);
15039 return !list->ll_symbol;
15042 /* To each location in list LIST add loc descr REF. */
15045 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
15047 dw_loc_descr_ref copy;
15048 add_loc_descr (&list->expr, ref);
15049 list = list->dw_loc_next;
15052 copy = ggc_alloc<dw_loc_descr_node> ();
15053 memcpy (copy, ref, sizeof (dw_loc_descr_node));
15054 add_loc_descr (&list->expr, copy);
15055 while (copy->dw_loc_next)
15057 dw_loc_descr_ref new_copy = ggc_alloc<dw_loc_descr_node> ();
15058 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
15059 copy->dw_loc_next = new_copy;
15062 list = list->dw_loc_next;
15066 /* Given two lists RET and LIST
15067 produce location list that is result of adding expression in LIST
15068 to expression in RET on each position in program.
15069 Might be destructive on both RET and LIST.
15071 TODO: We handle only simple cases of RET or LIST having at most one
15072 element. General case would inolve sorting the lists in program order
15073 and merging them that will need some additional work.
15074 Adding that will improve quality of debug info especially for SRA-ed
15078 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
15087 if (!list->dw_loc_next)
15089 add_loc_descr_to_each (*ret, list->expr);
15092 if (!(*ret)->dw_loc_next)
15094 add_loc_descr_to_each (list, (*ret)->expr);
15098 expansion_failed (NULL_TREE, NULL_RTX,
15099 "Don't know how to merge two non-trivial"
15100 " location lists.\n");
15105 /* LOC is constant expression. Try a luck, look it up in constant
15106 pool and return its loc_descr of its address. */
15108 static dw_loc_descr_ref
15109 cst_pool_loc_descr (tree loc)
15111 /* Get an RTL for this, if something has been emitted. */
15112 rtx rtl = lookup_constant_def (loc);
15114 if (!rtl || !MEM_P (rtl))
15119 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
15121 /* TODO: We might get more coverage if we was actually delaying expansion
15122 of all expressions till end of compilation when constant pools are fully
15124 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
15126 expansion_failed (loc, NULL_RTX,
15127 "CST value in contant pool but not marked.");
15130 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
15131 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
15134 /* Return dw_loc_list representing address of addr_expr LOC
15135 by looking for inner INDIRECT_REF expression and turning
15136 it into simple arithmetics.
15138 See loc_list_from_tree for the meaning of CONTEXT. */
15140 static dw_loc_list_ref
15141 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev,
15142 const loc_descr_context *context)
15145 HOST_WIDE_INT bitsize, bitpos, bytepos;
15147 int unsignedp, reversep, volatilep = 0;
15148 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15150 obj = get_inner_reference (TREE_OPERAND (loc, 0),
15151 &bitsize, &bitpos, &offset, &mode,
15152 &unsignedp, &reversep, &volatilep, false);
15154 if (bitpos % BITS_PER_UNIT)
15156 expansion_failed (loc, NULL_RTX, "bitfield access");
15159 if (!INDIRECT_REF_P (obj))
15161 expansion_failed (obj,
15162 NULL_RTX, "no indirect ref in inner refrence");
15165 if (!offset && !bitpos)
15166 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1,
15169 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
15170 && (dwarf_version >= 4 || !dwarf_strict))
15172 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0, context);
15177 /* Variable offset. */
15178 list_ret1 = loc_list_from_tree (offset, 0, context);
15179 if (list_ret1 == 0)
15181 add_loc_list (&list_ret, list_ret1);
15184 add_loc_descr_to_each (list_ret,
15185 new_loc_descr (DW_OP_plus, 0, 0));
15187 bytepos = bitpos / BITS_PER_UNIT;
15189 add_loc_descr_to_each (list_ret,
15190 new_loc_descr (DW_OP_plus_uconst,
15192 else if (bytepos < 0)
15193 loc_list_plus_const (list_ret, bytepos);
15194 add_loc_descr_to_each (list_ret,
15195 new_loc_descr (DW_OP_stack_value, 0, 0));
15200 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
15201 all operations from LOC are nops, move to the last one. Insert in NOPS all
15202 operations that are skipped. */
15205 loc_descr_to_next_no_nop (dw_loc_descr_ref &loc,
15206 hash_set<dw_loc_descr_ref> &nops)
15208 while (loc->dw_loc_next != NULL && loc->dw_loc_opc == DW_OP_nop)
15211 loc = loc->dw_loc_next;
15215 /* Helper for loc_descr_without_nops: free the location description operation
15219 free_loc_descr (const dw_loc_descr_ref &loc, void *data ATTRIBUTE_UNUSED)
15225 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
15229 loc_descr_without_nops (dw_loc_descr_ref &loc)
15231 if (loc->dw_loc_opc == DW_OP_nop && loc->dw_loc_next == NULL)
15234 /* Set of all DW_OP_nop operations we remove. */
15235 hash_set<dw_loc_descr_ref> nops;
15237 /* First, strip all prefix NOP operations in order to keep the head of the
15238 operations list. */
15239 loc_descr_to_next_no_nop (loc, nops);
15241 for (dw_loc_descr_ref cur = loc; cur != NULL;)
15243 /* For control flow operations: strip "prefix" nops in destination
15245 if (cur->dw_loc_oprnd1.val_class == dw_val_class_loc)
15246 loc_descr_to_next_no_nop (cur->dw_loc_oprnd1.v.val_loc, nops);
15247 if (cur->dw_loc_oprnd2.val_class == dw_val_class_loc)
15248 loc_descr_to_next_no_nop (cur->dw_loc_oprnd2.v.val_loc, nops);
15250 /* Do the same for the operations that follow, then move to the next
15252 if (cur->dw_loc_next != NULL)
15253 loc_descr_to_next_no_nop (cur->dw_loc_next, nops);
15254 cur = cur->dw_loc_next;
15257 nops.traverse<void *, free_loc_descr> (NULL);
15261 struct dwarf_procedure_info;
15263 /* Helper structure for location descriptions generation. */
15264 struct loc_descr_context
15266 /* The type that is implicitly referenced by DW_OP_push_object_address, or
15267 NULL_TREE if DW_OP_push_object_address in invalid for this location
15268 description. This is used when processing PLACEHOLDER_EXPR nodes. */
15270 /* The ..._DECL node that should be translated as a
15271 DW_OP_push_object_address operation. */
15273 /* Information about the DWARF procedure we are currently generating. NULL if
15274 we are not generating a DWARF procedure. */
15275 struct dwarf_procedure_info *dpi;
15278 /* DWARF procedures generation
15280 DWARF expressions (aka. location descriptions) are used to encode variable
15281 things such as sizes or offsets. Such computations can have redundant parts
15282 that can be factorized in order to reduce the size of the output debug
15283 information. This is the whole point of DWARF procedures.
15285 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
15286 already factorized into functions ("size functions") in order to handle very
15287 big and complex types. Such functions are quite simple: they have integral
15288 arguments, they return an integral result and their body contains only a
15289 return statement with arithmetic expressions. This is the only kind of
15290 function we are interested in translating into DWARF procedures, here.
15292 DWARF expressions and DWARF procedure are executed using a stack, so we have
15293 to define some calling convention for them to interact. Let's say that:
15295 - Before calling a DWARF procedure, DWARF expressions must push on the stack
15296 all arguments in reverse order (right-to-left) so that when the DWARF
15297 procedure execution starts, the first argument is the top of the stack.
15299 - Then, when returning, the DWARF procedure must have consumed all arguments
15300 on the stack, must have pushed the result and touched nothing else.
15302 - Each integral argument and the result are integral types can be hold in a
15305 - We call "frame offset" the number of stack slots that are "under DWARF
15306 procedure control": it includes the arguments slots, the temporaries and
15307 the result slot. Thus, it is equal to the number of arguments when the
15308 procedure execution starts and must be equal to one (the result) when it
15311 /* Helper structure used when generating operations for a DWARF procedure. */
15312 struct dwarf_procedure_info
15314 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
15315 currently translated. */
15317 /* The number of arguments FNDECL takes. */
15318 unsigned args_count;
15321 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
15322 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
15323 equate it to this DIE. */
15326 new_dwarf_proc_die (dw_loc_descr_ref location, tree fndecl,
15327 dw_die_ref parent_die)
15329 const bool dwarf_proc_supported = dwarf_version >= 4;
15330 dw_die_ref dwarf_proc_die;
15332 if ((dwarf_version < 3 && dwarf_strict)
15333 || location == NULL)
15336 dwarf_proc_die = new_die (dwarf_proc_supported
15337 ? DW_TAG_dwarf_procedure
15342 equate_decl_number_to_die (fndecl, dwarf_proc_die);
15343 if (!dwarf_proc_supported)
15344 add_AT_flag (dwarf_proc_die, DW_AT_artificial, 1);
15345 add_AT_loc (dwarf_proc_die, DW_AT_location, location);
15346 return dwarf_proc_die;
15349 /* Return whether TYPE is a supported type as a DWARF procedure argument
15350 type or return type (we handle only scalar types and pointer types that
15351 aren't wider than the DWARF expression evaluation stack. */
15354 is_handled_procedure_type (tree type)
15356 return ((INTEGRAL_TYPE_P (type)
15357 || TREE_CODE (type) == OFFSET_TYPE
15358 || TREE_CODE (type) == POINTER_TYPE)
15359 && int_size_in_bytes (type) <= DWARF2_ADDR_SIZE);
15362 /* Helper for resolve_args_picking. Stop when coming across VISITED nodes. */
15365 resolve_args_picking_1 (dw_loc_descr_ref loc, unsigned initial_frame_offset,
15366 struct dwarf_procedure_info *dpi,
15367 hash_set<dw_loc_descr_ref> &visited)
15369 /* The "frame_offset" identifier is already used to name a macro... */
15370 unsigned frame_offset_ = initial_frame_offset;
15371 dw_loc_descr_ref l;
15373 for (l = loc; l != NULL;)
15375 /* If we already met this node, there is nothing to compute anymore. */
15376 if (visited.add (l))
15379 /* Make sure that the stack size is consistent wherever the execution
15380 flow comes from. */
15381 gcc_assert ((unsigned) l->dw_loc_frame_offset == frame_offset_);
15386 l->dw_loc_frame_offset = frame_offset_;
15389 /* If needed, relocate the picking offset with respect to the frame
15391 if (l->dw_loc_opc == DW_OP_pick && l->frame_offset_rel)
15393 /* frame_offset_ is the size of the current stack frame, including
15394 incoming arguments. Besides, the arguments are pushed
15395 right-to-left. Thus, in order to access the Nth argument from
15396 this operation node, the picking has to skip temporaries *plus*
15397 one stack slot per argument (0 for the first one, 1 for the second
15400 The targetted argument number (N) is already set as the operand,
15401 and the number of temporaries can be computed with:
15402 frame_offsets_ - dpi->args_count */
15403 l->dw_loc_oprnd1.v.val_unsigned += frame_offset_ - dpi->args_count;
15405 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
15406 if (l->dw_loc_oprnd1.v.val_unsigned > 255)
15410 /* Update frame_offset according to the effect the current operation has
15412 switch (l->dw_loc_opc)
15419 case DW_OP_plus_uconst:
15455 case DW_OP_deref_size:
15457 case DW_OP_form_tls_address:
15458 case DW_OP_bit_piece:
15459 case DW_OP_implicit_value:
15460 case DW_OP_stack_value:
15464 case DW_OP_const1u:
15465 case DW_OP_const1s:
15466 case DW_OP_const2u:
15467 case DW_OP_const2s:
15468 case DW_OP_const4u:
15469 case DW_OP_const4s:
15470 case DW_OP_const8u:
15471 case DW_OP_const8s:
15542 case DW_OP_push_object_address:
15543 case DW_OP_call_frame_cfa:
15569 case DW_OP_xderef_size:
15575 case DW_OP_call_ref:
15577 dw_die_ref dwarf_proc = l->dw_loc_oprnd1.v.val_die_ref.die;
15578 int *stack_usage = dwarf_proc_stack_usage_map->get (dwarf_proc);
15580 if (stack_usage == NULL)
15582 frame_offset_ += *stack_usage;
15586 case DW_OP_GNU_push_tls_address:
15587 case DW_OP_GNU_uninit:
15588 case DW_OP_GNU_encoded_addr:
15589 case DW_OP_GNU_implicit_pointer:
15590 case DW_OP_GNU_entry_value:
15591 case DW_OP_GNU_const_type:
15592 case DW_OP_GNU_regval_type:
15593 case DW_OP_GNU_deref_type:
15594 case DW_OP_GNU_convert:
15595 case DW_OP_GNU_reinterpret:
15596 case DW_OP_GNU_parameter_ref:
15597 /* loc_list_from_tree will probably not output these operations for
15598 size functions, so assume they will not appear here. */
15599 /* Fall through... */
15602 gcc_unreachable ();
15605 /* Now, follow the control flow (except subroutine calls). */
15606 switch (l->dw_loc_opc)
15609 if (!resolve_args_picking_1 (l->dw_loc_next, frame_offset_, dpi,
15612 /* Fall through. */
15615 l = l->dw_loc_oprnd1.v.val_loc;
15618 case DW_OP_stack_value:
15622 l = l->dw_loc_next;
15630 /* Make a DFS over operations reachable through LOC (i.e. follow branch
15631 operations) in order to resolve the operand of DW_OP_pick operations that
15632 target DWARF procedure arguments (DPI). Stop at already visited nodes.
15633 INITIAL_FRAME_OFFSET is the frame offset *before* LOC is executed. Return
15634 if all relocations were successful. */
15637 resolve_args_picking (dw_loc_descr_ref loc, unsigned initial_frame_offset,
15638 struct dwarf_procedure_info *dpi)
15640 hash_set<dw_loc_descr_ref> visited;
15642 return resolve_args_picking_1 (loc, initial_frame_offset, dpi, visited);
15645 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
15646 Return NULL if it is not possible. */
15649 function_to_dwarf_procedure (tree fndecl)
15651 struct loc_descr_context ctx;
15652 struct dwarf_procedure_info dpi;
15653 dw_die_ref dwarf_proc_die;
15654 tree tree_body = DECL_SAVED_TREE (fndecl);
15655 dw_loc_descr_ref loc_body, epilogue;
15660 /* Do not generate multiple DWARF procedures for the same function
15662 dwarf_proc_die = lookup_decl_die (fndecl);
15663 if (dwarf_proc_die != NULL)
15664 return dwarf_proc_die;
15666 /* DWARF procedures are available starting with the DWARFv3 standard, but
15667 it's the DWARFv4 standard that introduces the DW_TAG_dwarf_procedure
15669 if (dwarf_version < 3 && dwarf_strict)
15672 /* We handle only functions for which we still have a body, that return a
15673 supported type and that takes arguments with supported types. Note that
15674 there is no point translating functions that return nothing. */
15675 if (tree_body == NULL_TREE
15676 || DECL_RESULT (fndecl) == NULL_TREE
15677 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl))))
15680 for (cursor = DECL_ARGUMENTS (fndecl);
15681 cursor != NULL_TREE;
15682 cursor = TREE_CHAIN (cursor))
15683 if (!is_handled_procedure_type (TREE_TYPE (cursor)))
15686 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
15687 if (TREE_CODE (tree_body) != RETURN_EXPR)
15689 tree_body = TREE_OPERAND (tree_body, 0);
15690 if (TREE_CODE (tree_body) != MODIFY_EXPR
15691 || TREE_OPERAND (tree_body, 0) != DECL_RESULT (fndecl))
15693 tree_body = TREE_OPERAND (tree_body, 1);
15695 /* Try to translate the body expression itself. Note that this will probably
15696 cause an infinite recursion if its call graph has a cycle. This is very
15697 unlikely for size functions, however, so don't bother with such things at
15699 ctx.context_type = NULL_TREE;
15700 ctx.base_decl = NULL_TREE;
15702 dpi.fndecl = fndecl;
15703 dpi.args_count = list_length (DECL_ARGUMENTS (fndecl));
15704 loc_body = loc_descriptor_from_tree (tree_body, 0, &ctx);
15708 /* After evaluating all operands in "loc_body", we should still have on the
15709 stack all arguments plus the desired function result (top of the stack).
15710 Generate code in order to keep only the result in our stack frame. */
15712 for (i = 0; i < dpi.args_count; ++i)
15714 dw_loc_descr_ref op_couple = new_loc_descr (DW_OP_swap, 0, 0);
15715 op_couple->dw_loc_next = new_loc_descr (DW_OP_drop, 0, 0);
15716 op_couple->dw_loc_next->dw_loc_next = epilogue;
15717 epilogue = op_couple;
15719 add_loc_descr (&loc_body, epilogue);
15720 if (!resolve_args_picking (loc_body, dpi.args_count, &dpi))
15723 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
15724 because they are considered useful. Now there is an epilogue, they are
15725 not anymore, so give it another try. */
15726 loc_descr_without_nops (loc_body);
15728 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
15729 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
15730 though, given that size functions do not come from source, so they should
15731 not have a dedicated DW_TAG_subprogram DIE. */
15733 = new_dwarf_proc_die (loc_body, fndecl,
15734 get_context_die (DECL_CONTEXT (fndecl)));
15736 /* The called DWARF procedure consumes one stack slot per argument and
15737 returns one stack slot. */
15738 dwarf_proc_stack_usage_map->put (dwarf_proc_die, 1 - dpi.args_count);
15740 return dwarf_proc_die;
15744 /* Generate Dwarf location list representing LOC.
15745 If WANT_ADDRESS is false, expression computing LOC will be computed
15746 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15747 if WANT_ADDRESS is 2, expression computing address useable in location
15748 will be returned (i.e. DW_OP_reg can be used
15749 to refer to register values).
15751 CONTEXT provides information to customize the location descriptions
15752 generation. Its context_type field specifies what type is implicitly
15753 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
15754 will not be generated.
15756 Its DPI field determines whether we are generating a DWARF expression for a
15757 DWARF procedure, so PARM_DECL references are processed specifically.
15759 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
15760 and dpi fields were null. */
15762 static dw_loc_list_ref
15763 loc_list_from_tree_1 (tree loc, int want_address,
15764 const struct loc_descr_context *context)
15766 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15767 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15768 int have_address = 0;
15769 enum dwarf_location_atom op;
15771 /* ??? Most of the time we do not take proper care for sign/zero
15772 extending the values properly. Hopefully this won't be a real
15775 if (context != NULL
15776 && context->base_decl == loc
15777 && want_address == 0)
15779 if (dwarf_version >= 3 || !dwarf_strict)
15780 return new_loc_list (new_loc_descr (DW_OP_push_object_address, 0, 0),
15786 switch (TREE_CODE (loc))
15789 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15792 case PLACEHOLDER_EXPR:
15793 /* This case involves extracting fields from an object to determine the
15794 position of other fields. It is supposed to appear only as the first
15795 operand of COMPONENT_REF nodes and to reference precisely the type
15796 that the context allows. */
15797 if (context != NULL
15798 && TREE_TYPE (loc) == context->context_type
15799 && want_address >= 1)
15801 if (dwarf_version >= 3 || !dwarf_strict)
15803 ret = new_loc_descr (DW_OP_push_object_address, 0, 0);
15811 expansion_failed (loc, NULL_RTX,
15812 "PLACEHOLDER_EXPR for an unexpected type");
15817 const int nargs = call_expr_nargs (loc);
15818 tree callee = get_callee_fndecl (loc);
15820 dw_die_ref dwarf_proc;
15822 if (callee == NULL_TREE)
15823 goto call_expansion_failed;
15825 /* We handle only functions that return an integer. */
15826 if (!is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee))))
15827 goto call_expansion_failed;
15829 dwarf_proc = function_to_dwarf_procedure (callee);
15830 if (dwarf_proc == NULL)
15831 goto call_expansion_failed;
15833 /* Evaluate arguments right-to-left so that the first argument will
15834 be the top-most one on the stack. */
15835 for (i = nargs - 1; i >= 0; --i)
15837 dw_loc_descr_ref loc_descr
15838 = loc_descriptor_from_tree (CALL_EXPR_ARG (loc, i), 0,
15841 if (loc_descr == NULL)
15842 goto call_expansion_failed;
15844 add_loc_descr (&ret, loc_descr);
15847 ret1 = new_loc_descr (DW_OP_call4, 0, 0);
15848 ret1->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15849 ret1->dw_loc_oprnd1.v.val_die_ref.die = dwarf_proc;
15850 ret1->dw_loc_oprnd1.v.val_die_ref.external = 0;
15851 add_loc_descr (&ret, ret1);
15854 call_expansion_failed:
15855 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15856 /* There are no opcodes for these operations. */
15860 case PREINCREMENT_EXPR:
15861 case PREDECREMENT_EXPR:
15862 case POSTINCREMENT_EXPR:
15863 case POSTDECREMENT_EXPR:
15864 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15865 /* There are no opcodes for these operations. */
15869 /* If we already want an address, see if there is INDIRECT_REF inside
15870 e.g. for &this->field. */
15873 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15874 (loc, want_address == 2, context);
15877 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15878 && (ret = cst_pool_loc_descr (loc)))
15881 /* Otherwise, process the argument and look for the address. */
15882 if (!list_ret && !ret)
15883 list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 1, context);
15887 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15893 if (DECL_THREAD_LOCAL_P (loc))
15896 enum dwarf_location_atom tls_op;
15897 enum dtprel_bool dtprel = dtprel_false;
15899 if (targetm.have_tls)
15901 /* If this is not defined, we have no way to emit the
15903 if (!targetm.asm_out.output_dwarf_dtprel)
15906 /* The way DW_OP_GNU_push_tls_address is specified, we
15907 can only look up addresses of objects in the current
15908 module. We used DW_OP_addr as first op, but that's
15909 wrong, because DW_OP_addr is relocated by the debug
15910 info consumer, while DW_OP_GNU_push_tls_address
15911 operand shouldn't be. */
15912 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15914 dtprel = dtprel_true;
15915 tls_op = DW_OP_GNU_push_tls_address;
15919 if (!targetm.emutls.debug_form_tls_address
15920 || !(dwarf_version >= 3 || !dwarf_strict))
15922 /* We stuffed the control variable into the DECL_VALUE_EXPR
15923 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15924 no longer appear in gimple code. We used the control
15925 variable in specific so that we could pick it up here. */
15926 loc = DECL_VALUE_EXPR (loc);
15927 tls_op = DW_OP_form_tls_address;
15930 rtl = rtl_for_decl_location (loc);
15931 if (rtl == NULL_RTX)
15936 rtl = XEXP (rtl, 0);
15937 if (! CONSTANT_P (rtl))
15940 ret = new_addr_loc_descr (rtl, dtprel);
15941 ret1 = new_loc_descr (tls_op, 0, 0);
15942 add_loc_descr (&ret, ret1);
15950 if (context != NULL && context->dpi != NULL
15951 && DECL_CONTEXT (loc) == context->dpi->fndecl)
15953 /* We are generating code for a DWARF procedure and we want to access
15954 one of its arguments: find the appropriate argument offset and let
15955 the resolve_args_picking pass compute the offset that complies
15956 with the stack frame size. */
15960 for (cursor = DECL_ARGUMENTS (context->dpi->fndecl);
15961 cursor != NULL_TREE && cursor != loc;
15962 cursor = TREE_CHAIN (cursor), ++i)
15964 /* If we are translating a DWARF procedure, all referenced parameters
15965 must belong to the current function. */
15966 gcc_assert (cursor != NULL_TREE);
15968 ret = new_loc_descr (DW_OP_pick, i, 0);
15969 ret->frame_offset_rel = 1;
15975 if (DECL_HAS_VALUE_EXPR_P (loc))
15976 return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc),
15977 want_address, context);
15980 case FUNCTION_DECL:
15983 var_loc_list *loc_list = lookup_decl_loc (loc);
15985 if (loc_list && loc_list->first)
15987 list_ret = dw_loc_list (loc_list, loc, want_address);
15988 have_address = want_address != 0;
15991 rtl = rtl_for_decl_location (loc);
15992 if (rtl == NULL_RTX)
15994 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15997 else if (CONST_INT_P (rtl))
15999 HOST_WIDE_INT val = INTVAL (rtl);
16000 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16001 val &= GET_MODE_MASK (DECL_MODE (loc));
16002 ret = int_loc_descriptor (val);
16004 else if (GET_CODE (rtl) == CONST_STRING)
16006 expansion_failed (loc, NULL_RTX, "CONST_STRING");
16009 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
16010 ret = new_addr_loc_descr (rtl, dtprel_false);
16013 machine_mode mode, mem_mode;
16015 /* Certain constructs can only be represented at top-level. */
16016 if (want_address == 2)
16018 ret = loc_descriptor (rtl, VOIDmode,
16019 VAR_INIT_STATUS_INITIALIZED);
16024 mode = GET_MODE (rtl);
16025 mem_mode = VOIDmode;
16029 mode = get_address_mode (rtl);
16030 rtl = XEXP (rtl, 0);
16033 ret = mem_loc_descriptor (rtl, mode, mem_mode,
16034 VAR_INIT_STATUS_INITIALIZED);
16037 expansion_failed (loc, rtl,
16038 "failed to produce loc descriptor for rtl");
16044 if (!integer_zerop (TREE_OPERAND (loc, 1)))
16051 list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
16055 case TARGET_MEM_REF:
16057 case DEBUG_EXPR_DECL:
16060 case COMPOUND_EXPR:
16061 return loc_list_from_tree_1 (TREE_OPERAND (loc, 1), want_address,
16065 case VIEW_CONVERT_EXPR:
16068 case NON_LVALUE_EXPR:
16069 return loc_list_from_tree_1 (TREE_OPERAND (loc, 0), want_address,
16072 case COMPONENT_REF:
16073 case BIT_FIELD_REF:
16075 case ARRAY_RANGE_REF:
16076 case REALPART_EXPR:
16077 case IMAGPART_EXPR:
16080 HOST_WIDE_INT bitsize, bitpos, bytepos;
16082 int unsignedp, reversep, volatilep = 0;
16084 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
16085 &unsignedp, &reversep, &volatilep, false);
16087 gcc_assert (obj != loc);
16089 list_ret = loc_list_from_tree_1 (obj,
16091 && !bitpos && !offset ? 2 : 1,
16093 /* TODO: We can extract value of the small expression via shifting even
16094 for nonzero bitpos. */
16097 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
16099 expansion_failed (loc, NULL_RTX,
16100 "bitfield access");
16104 if (offset != NULL_TREE)
16106 /* Variable offset. */
16107 list_ret1 = loc_list_from_tree_1 (offset, 0, context);
16108 if (list_ret1 == 0)
16110 add_loc_list (&list_ret, list_ret1);
16113 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
16116 bytepos = bitpos / BITS_PER_UNIT;
16118 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
16119 else if (bytepos < 0)
16120 loc_list_plus_const (list_ret, bytepos);
16127 if ((want_address || !tree_fits_shwi_p (loc))
16128 && (ret = cst_pool_loc_descr (loc)))
16130 else if (want_address == 2
16131 && tree_fits_shwi_p (loc)
16132 && (ret = address_of_int_loc_descriptor
16133 (int_size_in_bytes (TREE_TYPE (loc)),
16134 tree_to_shwi (loc))))
16136 else if (tree_fits_shwi_p (loc))
16137 ret = int_loc_descriptor (tree_to_shwi (loc));
16138 else if (tree_fits_uhwi_p (loc))
16139 ret = uint_loc_descriptor (tree_to_uhwi (loc));
16142 expansion_failed (loc, NULL_RTX,
16143 "Integer operand is not host integer");
16152 if ((ret = cst_pool_loc_descr (loc)))
16155 /* We can construct small constants here using int_loc_descriptor. */
16156 expansion_failed (loc, NULL_RTX,
16157 "constructor or constant not in constant pool");
16160 case TRUTH_AND_EXPR:
16161 case TRUTH_ANDIF_EXPR:
16166 case TRUTH_XOR_EXPR:
16171 case TRUTH_OR_EXPR:
16172 case TRUTH_ORIF_EXPR:
16177 case FLOOR_DIV_EXPR:
16178 case CEIL_DIV_EXPR:
16179 case ROUND_DIV_EXPR:
16180 case TRUNC_DIV_EXPR:
16181 case EXACT_DIV_EXPR:
16182 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16191 case FLOOR_MOD_EXPR:
16192 case CEIL_MOD_EXPR:
16193 case ROUND_MOD_EXPR:
16194 case TRUNC_MOD_EXPR:
16195 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16200 list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
16201 list_ret1 = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context);
16202 if (list_ret == 0 || list_ret1 == 0)
16205 add_loc_list (&list_ret, list_ret1);
16208 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
16209 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
16210 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
16211 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
16212 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
16224 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
16227 case POINTER_PLUS_EXPR:
16230 if (tree_fits_shwi_p (TREE_OPERAND (loc, 1)))
16232 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
16233 smarter to encode their opposite. The DW_OP_plus_uconst operation
16234 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
16235 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
16236 bytes, Y being the size of the operation that pushes the opposite
16237 of the addend. So let's choose the smallest representation. */
16238 const tree tree_addend = TREE_OPERAND (loc, 1);
16239 offset_int wi_addend;
16240 HOST_WIDE_INT shwi_addend;
16241 dw_loc_descr_ref loc_naddend;
16243 list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
16247 /* Try to get the literal to push. It is the opposite of the addend,
16248 so as we rely on wrapping during DWARF evaluation, first decode
16249 the literal as a "DWARF-sized" signed number. */
16250 wi_addend = wi::to_offset (tree_addend);
16251 wi_addend = wi::sext (wi_addend, DWARF2_ADDR_SIZE * 8);
16252 shwi_addend = wi_addend.to_shwi ();
16253 loc_naddend = (shwi_addend != INTTYPE_MINIMUM (HOST_WIDE_INT))
16254 ? int_loc_descriptor (-shwi_addend)
16257 if (loc_naddend != NULL
16258 && ((unsigned) size_of_uleb128 (shwi_addend)
16259 > size_of_loc_descr (loc_naddend)))
16261 add_loc_descr_to_each (list_ret, loc_naddend);
16262 add_loc_descr_to_each (list_ret,
16263 new_loc_descr (DW_OP_minus, 0, 0));
16267 for (dw_loc_descr_ref loc_cur = loc_naddend; loc_cur != NULL; )
16269 loc_naddend = loc_cur;
16270 loc_cur = loc_cur->dw_loc_next;
16271 ggc_free (loc_naddend);
16273 loc_list_plus_const (list_ret, wi_addend.to_shwi ());
16283 goto do_comp_binop;
16287 goto do_comp_binop;
16291 goto do_comp_binop;
16295 goto do_comp_binop;
16298 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16300 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
16301 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
16302 list_ret = loc_list_from_uint_comparison (list_ret, list_ret1,
16318 list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
16319 list_ret1 = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context);
16320 if (list_ret == 0 || list_ret1 == 0)
16323 add_loc_list (&list_ret, list_ret1);
16326 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
16329 case TRUTH_NOT_EXPR:
16343 list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
16347 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
16353 const enum tree_code code =
16354 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
16356 loc = build3 (COND_EXPR, TREE_TYPE (loc),
16357 build2 (code, integer_type_node,
16358 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
16359 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
16366 dw_loc_descr_ref lhs
16367 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0, context);
16368 dw_loc_list_ref rhs
16369 = loc_list_from_tree_1 (TREE_OPERAND (loc, 2), 0, context);
16370 dw_loc_descr_ref bra_node, jump_node, tmp;
16372 list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
16373 if (list_ret == 0 || lhs == 0 || rhs == 0)
16376 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
16377 add_loc_descr_to_each (list_ret, bra_node);
16379 add_loc_list (&list_ret, rhs);
16380 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
16381 add_loc_descr_to_each (list_ret, jump_node);
16383 add_loc_descr_to_each (list_ret, lhs);
16384 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
16385 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
16387 /* ??? Need a node to point the skip at. Use a nop. */
16388 tmp = new_loc_descr (DW_OP_nop, 0, 0);
16389 add_loc_descr_to_each (list_ret, tmp);
16390 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
16391 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
16395 case FIX_TRUNC_EXPR:
16399 /* Leave front-end specific codes as simply unknown. This comes
16400 up, for instance, with the C STMT_EXPR. */
16401 if ((unsigned int) TREE_CODE (loc)
16402 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
16404 expansion_failed (loc, NULL_RTX,
16405 "language specific tree node");
16409 /* Otherwise this is a generic code; we should just lists all of
16410 these explicitly. We forgot one. */
16412 gcc_unreachable ();
16414 /* In a release build, we want to degrade gracefully: better to
16415 generate incomplete debugging information than to crash. */
16419 if (!ret && !list_ret)
16422 if (want_address == 2 && !have_address
16423 && (dwarf_version >= 4 || !dwarf_strict))
16425 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
16427 expansion_failed (loc, NULL_RTX,
16428 "DWARF address size mismatch");
16432 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
16434 add_loc_descr_to_each (list_ret,
16435 new_loc_descr (DW_OP_stack_value, 0, 0));
16438 /* Show if we can't fill the request for an address. */
16439 if (want_address && !have_address)
16441 expansion_failed (loc, NULL_RTX,
16442 "Want address and only have value");
16446 gcc_assert (!ret || !list_ret);
16448 /* If we've got an address and don't want one, dereference. */
16449 if (!want_address && have_address)
16451 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
16453 if (size > DWARF2_ADDR_SIZE || size == -1)
16455 expansion_failed (loc, NULL_RTX,
16456 "DWARF address size mismatch");
16459 else if (size == DWARF2_ADDR_SIZE)
16462 op = DW_OP_deref_size;
16465 add_loc_descr (&ret, new_loc_descr (op, size, 0));
16467 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
16470 list_ret = new_loc_list (ret, NULL, NULL, NULL);
16475 /* Likewise, but strip useless DW_OP_nop operations in the resulting
16478 static dw_loc_list_ref
16479 loc_list_from_tree (tree loc, int want_address,
16480 const struct loc_descr_context *context)
16482 dw_loc_list_ref result = loc_list_from_tree_1 (loc, want_address, context);
16484 for (dw_loc_list_ref loc_cur = result;
16485 loc_cur != NULL; loc_cur =
16486 loc_cur->dw_loc_next)
16487 loc_descr_without_nops (loc_cur->expr);
16491 /* Same as above but return only single location expression. */
16492 static dw_loc_descr_ref
16493 loc_descriptor_from_tree (tree loc, int want_address,
16494 const struct loc_descr_context *context)
16496 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address, context);
16499 if (ret->dw_loc_next)
16501 expansion_failed (loc, NULL_RTX,
16502 "Location list where only loc descriptor needed");
16508 /* Given a value, round it up to the lowest multiple of `boundary'
16509 which is not less than the value itself. */
16511 static inline HOST_WIDE_INT
16512 ceiling (HOST_WIDE_INT value, unsigned int boundary)
16514 return (((value + boundary - 1) / boundary) * boundary);
16517 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
16518 pointer to the declared type for the relevant field variable, or return
16519 `integer_type_node' if the given node turns out to be an
16520 ERROR_MARK node. */
16523 field_type (const_tree decl)
16527 if (TREE_CODE (decl) == ERROR_MARK)
16528 return integer_type_node;
16530 type = DECL_BIT_FIELD_TYPE (decl);
16531 if (type == NULL_TREE)
16532 type = TREE_TYPE (decl);
16537 /* Given a pointer to a tree node, return the alignment in bits for
16538 it, or else return BITS_PER_WORD if the node actually turns out to
16539 be an ERROR_MARK node. */
16541 static inline unsigned
16542 simple_type_align_in_bits (const_tree type)
16544 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
16547 static inline unsigned
16548 simple_decl_align_in_bits (const_tree decl)
16550 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
16553 /* Return the result of rounding T up to ALIGN. */
16555 static inline offset_int
16556 round_up_to_align (const offset_int &t, unsigned int align)
16558 return wi::udiv_trunc (t + align - 1, align) * align;
16561 /* Compute the size of TYPE in bytes. If possible, return NULL and store the
16562 size as an integer constant in CST_SIZE. Otherwise, if possible, return a
16563 DWARF expression that computes the size. Return NULL and set CST_SIZE to -1
16564 if we fail to return the size in one of these two forms. */
16566 static dw_loc_descr_ref
16567 type_byte_size (const_tree type, HOST_WIDE_INT *cst_size)
16570 struct loc_descr_context ctx;
16572 /* Return a constant integer in priority, if possible. */
16573 *cst_size = int_size_in_bytes (type);
16574 if (*cst_size != -1)
16577 ctx.context_type = const_cast<tree> (type);
16578 ctx.base_decl = NULL_TREE;
16581 type = TYPE_MAIN_VARIANT (type);
16582 tree_size = TYPE_SIZE_UNIT (type);
16583 return ((tree_size != NULL_TREE)
16584 ? loc_descriptor_from_tree (tree_size, 0, &ctx)
16588 /* Helper structure for RECORD_TYPE processing. */
16591 /* Root RECORD_TYPE. It is needed to generate data member location
16592 descriptions in variable-length records (VLR), but also to cope with
16593 variants, which are composed of nested structures multiplexed with
16594 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
16595 function processing a FIELD_DECL, it is required to be non null. */
16597 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
16598 QUAL_UNION_TYPE), this holds an expression that computes the offset for
16599 this variant part as part of the root record (in storage units). For
16600 regular records, it must be NULL_TREE. */
16601 tree variant_part_offset;
16604 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
16605 addressed byte of the "containing object" for the given FIELD_DECL. If
16606 possible, return a native constant through CST_OFFSET (in which case NULL is
16607 returned); otherwise return a DWARF expression that computes the offset.
16609 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
16610 that offset is, either because the argument turns out to be a pointer to an
16611 ERROR_MARK node, or because the offset expression is too complex for us.
16613 CTX is required: see the comment for VLR_CONTEXT. */
16615 static dw_loc_descr_ref
16616 field_byte_offset (const_tree decl, struct vlr_context *ctx,
16617 HOST_WIDE_INT *cst_offset)
16620 dw_loc_list_ref loc_result;
16624 if (TREE_CODE (decl) == ERROR_MARK)
16627 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
16629 /* We cannot handle variable bit offsets at the moment, so abort if it's the
16631 if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl)) != INTEGER_CST)
16634 #ifdef PCC_BITFIELD_TYPE_MATTERS
16635 /* We used to handle only constant offsets in all cases. Now, we handle
16636 properly dynamic byte offsets only when PCC bitfield type doesn't
16638 if (PCC_BITFIELD_TYPE_MATTERS
16639 && TREE_CODE (DECL_FIELD_OFFSET (decl)) == INTEGER_CST)
16641 offset_int object_offset_in_bits;
16642 offset_int object_offset_in_bytes;
16643 offset_int bitpos_int;
16645 tree field_size_tree;
16646 offset_int deepest_bitpos;
16647 offset_int field_size_in_bits;
16648 unsigned int type_align_in_bits;
16649 unsigned int decl_align_in_bits;
16650 offset_int type_size_in_bits;
16652 bitpos_int = wi::to_offset (bit_position (decl));
16653 type = field_type (decl);
16654 type_size_in_bits = offset_int_type_size_in_bits (type);
16655 type_align_in_bits = simple_type_align_in_bits (type);
16657 field_size_tree = DECL_SIZE (decl);
16659 /* The size could be unspecified if there was an error, or for
16660 a flexible array member. */
16661 if (!field_size_tree)
16662 field_size_tree = bitsize_zero_node;
16664 /* If the size of the field is not constant, use the type size. */
16665 if (TREE_CODE (field_size_tree) == INTEGER_CST)
16666 field_size_in_bits = wi::to_offset (field_size_tree);
16668 field_size_in_bits = type_size_in_bits;
16670 decl_align_in_bits = simple_decl_align_in_bits (decl);
16672 /* The GCC front-end doesn't make any attempt to keep track of the
16673 starting bit offset (relative to the start of the containing
16674 structure type) of the hypothetical "containing object" for a
16675 bit-field. Thus, when computing the byte offset value for the
16676 start of the "containing object" of a bit-field, we must deduce
16677 this information on our own. This can be rather tricky to do in
16678 some cases. For example, handling the following structure type
16679 definition when compiling for an i386/i486 target (which only
16680 aligns long long's to 32-bit boundaries) can be very tricky:
16682 struct S { int field1; long long field2:31; };
16684 Fortunately, there is a simple rule-of-thumb which can be used
16685 in such cases. When compiling for an i386/i486, GCC will
16686 allocate 8 bytes for the structure shown above. It decides to
16687 do this based upon one simple rule for bit-field allocation.
16688 GCC allocates each "containing object" for each bit-field at
16689 the first (i.e. lowest addressed) legitimate alignment boundary
16690 (based upon the required minimum alignment for the declared
16691 type of the field) which it can possibly use, subject to the
16692 condition that there is still enough available space remaining
16693 in the containing object (when allocated at the selected point)
16694 to fully accommodate all of the bits of the bit-field itself.
16696 This simple rule makes it obvious why GCC allocates 8 bytes for
16697 each object of the structure type shown above. When looking
16698 for a place to allocate the "containing object" for `field2',
16699 the compiler simply tries to allocate a 64-bit "containing
16700 object" at each successive 32-bit boundary (starting at zero)
16701 until it finds a place to allocate that 64- bit field such that
16702 at least 31 contiguous (and previously unallocated) bits remain
16703 within that selected 64 bit field. (As it turns out, for the
16704 example above, the compiler finds it is OK to allocate the
16705 "containing object" 64-bit field at bit-offset zero within the
16708 Here we attempt to work backwards from the limited set of facts
16709 we're given, and we try to deduce from those facts, where GCC
16710 must have believed that the containing object started (within
16711 the structure type). The value we deduce is then used (by the
16712 callers of this routine) to generate DW_AT_location and
16713 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16714 the case of DW_AT_location, regular fields as well). */
16716 /* Figure out the bit-distance from the start of the structure to
16717 the "deepest" bit of the bit-field. */
16718 deepest_bitpos = bitpos_int + field_size_in_bits;
16720 /* This is the tricky part. Use some fancy footwork to deduce
16721 where the lowest addressed bit of the containing object must
16723 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
16725 /* Round up to type_align by default. This works best for
16727 object_offset_in_bits
16728 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
16730 if (wi::gtu_p (object_offset_in_bits, bitpos_int))
16732 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
16734 /* Round up to decl_align instead. */
16735 object_offset_in_bits
16736 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
16739 object_offset_in_bytes
16740 = wi::lrshift (object_offset_in_bits, LOG2_BITS_PER_UNIT);
16741 if (ctx->variant_part_offset == NULL_TREE)
16743 *cst_offset = object_offset_in_bytes.to_shwi ();
16746 tree_result = wide_int_to_tree (sizetype, object_offset_in_bytes);
16749 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16750 tree_result = byte_position (decl);
16752 if (ctx->variant_part_offset != NULL_TREE)
16753 tree_result = fold_build2 (PLUS_EXPR, TREE_TYPE (tree_result),
16754 ctx->variant_part_offset, tree_result);
16756 /* If the byte offset is a constant, it's simplier to handle a native
16757 constant rather than a DWARF expression. */
16758 if (TREE_CODE (tree_result) == INTEGER_CST)
16760 *cst_offset = wi::to_offset (tree_result).to_shwi ();
16763 struct loc_descr_context loc_ctx = {
16764 ctx->struct_type, /* context_type */
16765 NULL_TREE, /* base_decl */
16768 loc_result = loc_list_from_tree (tree_result, 0, &loc_ctx);
16770 /* We want a DWARF expression: abort if we only have a location list with
16771 multiple elements. */
16772 if (!loc_result || !single_element_loc_list_p (loc_result))
16775 return loc_result->expr;
16778 /* The following routines define various Dwarf attributes and any data
16779 associated with them. */
16781 /* Add a location description attribute value to a DIE.
16783 This emits location attributes suitable for whole variables and
16784 whole parameters. Note that the location attributes for struct fields are
16785 generated by the routine `data_member_location_attribute' below. */
16788 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
16789 dw_loc_list_ref descr)
16793 if (single_element_loc_list_p (descr))
16794 add_AT_loc (die, attr_kind, descr->expr);
16796 add_AT_loc_list (die, attr_kind, descr);
16799 /* Add DW_AT_accessibility attribute to DIE if needed. */
16802 add_accessibility_attribute (dw_die_ref die, tree decl)
16804 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16805 children, otherwise the default is DW_ACCESS_public. In DWARF2
16806 the default has always been DW_ACCESS_public. */
16807 if (TREE_PROTECTED (decl))
16808 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16809 else if (TREE_PRIVATE (decl))
16811 if (dwarf_version == 2
16812 || die->die_parent == NULL
16813 || die->die_parent->die_tag != DW_TAG_class_type)
16814 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
16816 else if (dwarf_version > 2
16818 && die->die_parent->die_tag == DW_TAG_class_type)
16819 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16822 /* Attach the specialized form of location attribute used for data members of
16823 struct and union types. In the special case of a FIELD_DECL node which
16824 represents a bit-field, the "offset" part of this special location
16825 descriptor must indicate the distance in bytes from the lowest-addressed
16826 byte of the containing struct or union type to the lowest-addressed byte of
16827 the "containing object" for the bit-field. (See the `field_byte_offset'
16830 For any given bit-field, the "containing object" is a hypothetical object
16831 (of some integral or enum type) within which the given bit-field lives. The
16832 type of this hypothetical "containing object" is always the same as the
16833 declared type of the individual bit-field itself (for GCC anyway... the
16834 DWARF spec doesn't actually mandate this). Note that it is the size (in
16835 bytes) of the hypothetical "containing object" which will be given in the
16836 DW_AT_byte_size attribute for this bit-field. (See the
16837 `byte_size_attribute' function below.) It is also used when calculating the
16838 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16841 CTX is required: see the comment for VLR_CONTEXT. */
16844 add_data_member_location_attribute (dw_die_ref die,
16846 struct vlr_context *ctx)
16848 HOST_WIDE_INT offset;
16849 dw_loc_descr_ref loc_descr = 0;
16851 if (TREE_CODE (decl) == TREE_BINFO)
16853 /* We're working on the TAG_inheritance for a base class. */
16854 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
16856 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16857 aren't at a fixed offset from all (sub)objects of the same
16858 type. We need to extract the appropriate offset from our
16859 vtable. The following dwarf expression means
16861 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16863 This is specific to the V3 ABI, of course. */
16865 dw_loc_descr_ref tmp;
16867 /* Make a copy of the object address. */
16868 tmp = new_loc_descr (DW_OP_dup, 0, 0);
16869 add_loc_descr (&loc_descr, tmp);
16871 /* Extract the vtable address. */
16872 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16873 add_loc_descr (&loc_descr, tmp);
16875 /* Calculate the address of the offset. */
16876 offset = tree_to_shwi (BINFO_VPTR_FIELD (decl));
16877 gcc_assert (offset < 0);
16879 tmp = int_loc_descriptor (-offset);
16880 add_loc_descr (&loc_descr, tmp);
16881 tmp = new_loc_descr (DW_OP_minus, 0, 0);
16882 add_loc_descr (&loc_descr, tmp);
16884 /* Extract the offset. */
16885 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16886 add_loc_descr (&loc_descr, tmp);
16888 /* Add it to the object address. */
16889 tmp = new_loc_descr (DW_OP_plus, 0, 0);
16890 add_loc_descr (&loc_descr, tmp);
16893 offset = tree_to_shwi (BINFO_OFFSET (decl));
16897 loc_descr = field_byte_offset (decl, ctx, &offset);
16899 /* If loc_descr is available then we know the field offset is dynamic.
16900 However, GDB does not handle dynamic field offsets very well at the
16902 if (loc_descr != NULL && gnat_encodings != DWARF_GNAT_ENCODINGS_MINIMAL)
16908 /* Data member location evalutation starts with the base address on the
16909 stack. Compute the field offset and add it to this base address. */
16910 else if (loc_descr != NULL)
16911 add_loc_descr (&loc_descr, new_loc_descr (DW_OP_plus, 0, 0));
16916 if (dwarf_version > 2)
16918 /* Don't need to output a location expression, just the constant. */
16920 add_AT_int (die, DW_AT_data_member_location, offset);
16922 add_AT_unsigned (die, DW_AT_data_member_location, offset);
16927 enum dwarf_location_atom op;
16929 /* The DWARF2 standard says that we should assume that the structure
16930 address is already on the stack, so we can specify a structure
16931 field address by using DW_OP_plus_uconst. */
16932 op = DW_OP_plus_uconst;
16933 loc_descr = new_loc_descr (op, offset, 0);
16937 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
16940 /* Writes integer values to dw_vec_const array. */
16943 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
16947 *dest++ = val & 0xff;
16953 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16955 static HOST_WIDE_INT
16956 extract_int (const unsigned char *src, unsigned int size)
16958 HOST_WIDE_INT val = 0;
16964 val |= *--src & 0xff;
16970 /* Writes wide_int values to dw_vec_const array. */
16973 insert_wide_int (const wide_int &val, unsigned char *dest, int elt_size)
16977 if (elt_size <= HOST_BITS_PER_WIDE_INT/BITS_PER_UNIT)
16979 insert_int ((HOST_WIDE_INT) val.elt (0), elt_size, dest);
16983 /* We'd have to extend this code to support odd sizes. */
16984 gcc_assert (elt_size % (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT) == 0);
16986 int n = elt_size / (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
16988 if (WORDS_BIG_ENDIAN)
16989 for (i = n - 1; i >= 0; i--)
16991 insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
16992 dest += sizeof (HOST_WIDE_INT);
16995 for (i = 0; i < n; i++)
16997 insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
16998 dest += sizeof (HOST_WIDE_INT);
17002 /* Writes floating point values to dw_vec_const array. */
17005 insert_float (const_rtx rtl, unsigned char *array)
17010 real_to_target (val, CONST_DOUBLE_REAL_VALUE (rtl), GET_MODE (rtl));
17012 /* real_to_target puts 32-bit pieces in each long. Pack them. */
17013 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
17015 insert_int (val[i], 4, array);
17020 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
17021 does not have a "location" either in memory or in a register. These
17022 things can arise in GNU C when a constant is passed as an actual parameter
17023 to an inlined function. They can also arise in C++ where declared
17024 constants do not necessarily get memory "homes". */
17027 add_const_value_attribute (dw_die_ref die, rtx rtl)
17029 switch (GET_CODE (rtl))
17033 HOST_WIDE_INT val = INTVAL (rtl);
17036 add_AT_int (die, DW_AT_const_value, val);
17038 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
17042 case CONST_WIDE_INT:
17044 wide_int w1 = std::make_pair (rtl, MAX_MODE_INT);
17045 unsigned int prec = MIN (wi::min_precision (w1, UNSIGNED),
17046 (unsigned int)CONST_WIDE_INT_NUNITS (rtl) * HOST_BITS_PER_WIDE_INT);
17047 wide_int w = wi::zext (w1, prec);
17048 add_AT_wide (die, DW_AT_const_value, w);
17053 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
17054 floating-point constant. A CONST_DOUBLE is used whenever the
17055 constant requires more than one word in order to be adequately
17058 machine_mode mode = GET_MODE (rtl);
17060 if (TARGET_SUPPORTS_WIDE_INT == 0 && !SCALAR_FLOAT_MODE_P (mode))
17061 add_AT_double (die, DW_AT_const_value,
17062 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
17065 unsigned int length = GET_MODE_SIZE (mode);
17066 unsigned char *array = ggc_vec_alloc<unsigned char> (length);
17068 insert_float (rtl, array);
17069 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
17076 machine_mode mode = GET_MODE (rtl);
17077 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
17078 unsigned int length = CONST_VECTOR_NUNITS (rtl);
17079 unsigned char *array
17080 = ggc_vec_alloc<unsigned char> (length * elt_size);
17083 machine_mode imode = GET_MODE_INNER (mode);
17085 switch (GET_MODE_CLASS (mode))
17087 case MODE_VECTOR_INT:
17088 for (i = 0, p = array; i < length; i++, p += elt_size)
17090 rtx elt = CONST_VECTOR_ELT (rtl, i);
17091 insert_wide_int (std::make_pair (elt, imode), p, elt_size);
17095 case MODE_VECTOR_FLOAT:
17096 for (i = 0, p = array; i < length; i++, p += elt_size)
17098 rtx elt = CONST_VECTOR_ELT (rtl, i);
17099 insert_float (elt, p);
17104 gcc_unreachable ();
17107 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
17112 if (dwarf_version >= 4 || !dwarf_strict)
17114 dw_loc_descr_ref loc_result;
17115 resolve_one_addr (&rtl);
17117 loc_result = new_addr_loc_descr (rtl, dtprel_false);
17118 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
17119 add_AT_loc (die, DW_AT_location, loc_result);
17120 vec_safe_push (used_rtx_array, rtl);
17126 if (CONSTANT_P (XEXP (rtl, 0)))
17127 return add_const_value_attribute (die, XEXP (rtl, 0));
17130 if (!const_ok_for_output (rtl))
17133 if (dwarf_version >= 4 || !dwarf_strict)
17138 /* In cases where an inlined instance of an inline function is passed
17139 the address of an `auto' variable (which is local to the caller) we
17140 can get a situation where the DECL_RTL of the artificial local
17141 variable (for the inlining) which acts as a stand-in for the
17142 corresponding formal parameter (of the inline function) will look
17143 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
17144 exactly a compile-time constant expression, but it isn't the address
17145 of the (artificial) local variable either. Rather, it represents the
17146 *value* which the artificial local variable always has during its
17147 lifetime. We currently have no way to represent such quasi-constant
17148 values in Dwarf, so for now we just punt and generate nothing. */
17156 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
17157 && MEM_READONLY_P (rtl)
17158 && GET_MODE (rtl) == BLKmode)
17160 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
17166 /* No other kinds of rtx should be possible here. */
17167 gcc_unreachable ();
17172 /* Determine whether the evaluation of EXPR references any variables
17173 or functions which aren't otherwise used (and therefore may not be
17176 reference_to_unused (tree * tp, int * walk_subtrees,
17177 void * data ATTRIBUTE_UNUSED)
17179 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
17180 *walk_subtrees = 0;
17182 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
17183 && ! TREE_ASM_WRITTEN (*tp))
17185 /* ??? The C++ FE emits debug information for using decls, so
17186 putting gcc_unreachable here falls over. See PR31899. For now
17187 be conservative. */
17188 else if (!symtab->global_info_ready
17189 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
17191 else if (TREE_CODE (*tp) == VAR_DECL)
17193 varpool_node *node = varpool_node::get (*tp);
17194 if (!node || !node->definition)
17197 else if (TREE_CODE (*tp) == FUNCTION_DECL
17198 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
17200 /* The call graph machinery must have finished analyzing,
17201 optimizing and gimplifying the CU by now.
17202 So if *TP has no call graph node associated
17203 to it, it means *TP will not be emitted. */
17204 if (!cgraph_node::get (*tp))
17207 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
17213 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
17214 for use in a later add_const_value_attribute call. */
17217 rtl_for_decl_init (tree init, tree type)
17219 rtx rtl = NULL_RTX;
17223 /* If a variable is initialized with a string constant without embedded
17224 zeros, build CONST_STRING. */
17225 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
17227 tree enttype = TREE_TYPE (type);
17228 tree domain = TYPE_DOMAIN (type);
17229 machine_mode mode = TYPE_MODE (enttype);
17231 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
17233 && integer_zerop (TYPE_MIN_VALUE (domain))
17234 && compare_tree_int (TYPE_MAX_VALUE (domain),
17235 TREE_STRING_LENGTH (init) - 1) == 0
17236 && ((size_t) TREE_STRING_LENGTH (init)
17237 == strlen (TREE_STRING_POINTER (init)) + 1))
17239 rtl = gen_rtx_CONST_STRING (VOIDmode,
17240 ggc_strdup (TREE_STRING_POINTER (init)));
17241 rtl = gen_rtx_MEM (BLKmode, rtl);
17242 MEM_READONLY_P (rtl) = 1;
17245 /* Other aggregates, and complex values, could be represented using
17247 else if (AGGREGATE_TYPE_P (type)
17248 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
17249 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
17250 || TREE_CODE (type) == COMPLEX_TYPE)
17252 /* Vectors only work if their mode is supported by the target.
17253 FIXME: generic vectors ought to work too. */
17254 else if (TREE_CODE (type) == VECTOR_TYPE
17255 && !VECTOR_MODE_P (TYPE_MODE (type)))
17257 /* If the initializer is something that we know will expand into an
17258 immediate RTL constant, expand it now. We must be careful not to
17259 reference variables which won't be output. */
17260 else if (initializer_constant_valid_p (init, type)
17261 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
17263 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
17265 if (TREE_CODE (type) == VECTOR_TYPE)
17266 switch (TREE_CODE (init))
17271 if (TREE_CONSTANT (init))
17273 vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (init);
17274 bool constant_p = true;
17276 unsigned HOST_WIDE_INT ix;
17278 /* Even when ctor is constant, it might contain non-*_CST
17279 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
17280 belong into VECTOR_CST nodes. */
17281 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
17282 if (!CONSTANT_CLASS_P (value))
17284 constant_p = false;
17290 init = build_vector_from_ctor (type, elts);
17300 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
17302 /* If expand_expr returns a MEM, it wasn't immediate. */
17303 gcc_assert (!rtl || !MEM_P (rtl));
17309 /* Generate RTL for the variable DECL to represent its location. */
17312 rtl_for_decl_location (tree decl)
17316 /* Here we have to decide where we are going to say the parameter "lives"
17317 (as far as the debugger is concerned). We only have a couple of
17318 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
17320 DECL_RTL normally indicates where the parameter lives during most of the
17321 activation of the function. If optimization is enabled however, this
17322 could be either NULL or else a pseudo-reg. Both of those cases indicate
17323 that the parameter doesn't really live anywhere (as far as the code
17324 generation parts of GCC are concerned) during most of the function's
17325 activation. That will happen (for example) if the parameter is never
17326 referenced within the function.
17328 We could just generate a location descriptor here for all non-NULL
17329 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
17330 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
17331 where DECL_RTL is NULL or is a pseudo-reg.
17333 Note however that we can only get away with using DECL_INCOMING_RTL as
17334 a backup substitute for DECL_RTL in certain limited cases. In cases
17335 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
17336 we can be sure that the parameter was passed using the same type as it is
17337 declared to have within the function, and that its DECL_INCOMING_RTL
17338 points us to a place where a value of that type is passed.
17340 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
17341 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
17342 because in these cases DECL_INCOMING_RTL points us to a value of some
17343 type which is *different* from the type of the parameter itself. Thus,
17344 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
17345 such cases, the debugger would end up (for example) trying to fetch a
17346 `float' from a place which actually contains the first part of a
17347 `double'. That would lead to really incorrect and confusing
17348 output at debug-time.
17350 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
17351 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
17352 are a couple of exceptions however. On little-endian machines we can
17353 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
17354 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
17355 an integral type that is smaller than TREE_TYPE (decl). These cases arise
17356 when (on a little-endian machine) a non-prototyped function has a
17357 parameter declared to be of type `short' or `char'. In such cases,
17358 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
17359 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
17360 passed `int' value. If the debugger then uses that address to fetch
17361 a `short' or a `char' (on a little-endian machine) the result will be
17362 the correct data, so we allow for such exceptional cases below.
17364 Note that our goal here is to describe the place where the given formal
17365 parameter lives during most of the function's activation (i.e. between the
17366 end of the prologue and the start of the epilogue). We'll do that as best
17367 as we can. Note however that if the given formal parameter is modified
17368 sometime during the execution of the function, then a stack backtrace (at
17369 debug-time) will show the function as having been called with the *new*
17370 value rather than the value which was originally passed in. This happens
17371 rarely enough that it is not a major problem, but it *is* a problem, and
17372 I'd like to fix it.
17374 A future version of dwarf2out.c may generate two additional attributes for
17375 any given DW_TAG_formal_parameter DIE which will describe the "passed
17376 type" and the "passed location" for the given formal parameter in addition
17377 to the attributes we now generate to indicate the "declared type" and the
17378 "active location" for each parameter. This additional set of attributes
17379 could be used by debuggers for stack backtraces. Separately, note that
17380 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
17381 This happens (for example) for inlined-instances of inline function formal
17382 parameters which are never referenced. This really shouldn't be
17383 happening. All PARM_DECL nodes should get valid non-NULL
17384 DECL_INCOMING_RTL values. FIXME. */
17386 /* Use DECL_RTL as the "location" unless we find something better. */
17387 rtl = DECL_RTL_IF_SET (decl);
17389 /* When generating abstract instances, ignore everything except
17390 constants, symbols living in memory, and symbols living in
17391 fixed registers. */
17392 if (! reload_completed)
17395 && (CONSTANT_P (rtl)
17397 && CONSTANT_P (XEXP (rtl, 0)))
17399 && TREE_CODE (decl) == VAR_DECL
17400 && TREE_STATIC (decl))))
17402 rtl = targetm.delegitimize_address (rtl);
17407 else if (TREE_CODE (decl) == PARM_DECL)
17409 if (rtl == NULL_RTX
17410 || is_pseudo_reg (rtl)
17412 && is_pseudo_reg (XEXP (rtl, 0))
17413 && DECL_INCOMING_RTL (decl)
17414 && MEM_P (DECL_INCOMING_RTL (decl))
17415 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
17417 tree declared_type = TREE_TYPE (decl);
17418 tree passed_type = DECL_ARG_TYPE (decl);
17419 machine_mode dmode = TYPE_MODE (declared_type);
17420 machine_mode pmode = TYPE_MODE (passed_type);
17422 /* This decl represents a formal parameter which was optimized out.
17423 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
17424 all cases where (rtl == NULL_RTX) just below. */
17425 if (dmode == pmode)
17426 rtl = DECL_INCOMING_RTL (decl);
17427 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
17428 && SCALAR_INT_MODE_P (dmode)
17429 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
17430 && DECL_INCOMING_RTL (decl))
17432 rtx inc = DECL_INCOMING_RTL (decl);
17435 else if (MEM_P (inc))
17437 if (BYTES_BIG_ENDIAN)
17438 rtl = adjust_address_nv (inc, dmode,
17439 GET_MODE_SIZE (pmode)
17440 - GET_MODE_SIZE (dmode));
17447 /* If the parm was passed in registers, but lives on the stack, then
17448 make a big endian correction if the mode of the type of the
17449 parameter is not the same as the mode of the rtl. */
17450 /* ??? This is the same series of checks that are made in dbxout.c before
17451 we reach the big endian correction code there. It isn't clear if all
17452 of these checks are necessary here, but keeping them all is the safe
17454 else if (MEM_P (rtl)
17455 && XEXP (rtl, 0) != const0_rtx
17456 && ! CONSTANT_P (XEXP (rtl, 0))
17457 /* Not passed in memory. */
17458 && !MEM_P (DECL_INCOMING_RTL (decl))
17459 /* Not passed by invisible reference. */
17460 && (!REG_P (XEXP (rtl, 0))
17461 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
17462 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
17463 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
17464 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
17467 /* Big endian correction check. */
17468 && BYTES_BIG_ENDIAN
17469 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
17470 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
17473 machine_mode addr_mode = get_address_mode (rtl);
17474 int offset = (UNITS_PER_WORD
17475 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
17477 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
17478 plus_constant (addr_mode, XEXP (rtl, 0), offset));
17481 else if (TREE_CODE (decl) == VAR_DECL
17484 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
17485 && BYTES_BIG_ENDIAN)
17487 machine_mode addr_mode = get_address_mode (rtl);
17488 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
17489 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
17491 /* If a variable is declared "register" yet is smaller than
17492 a register, then if we store the variable to memory, it
17493 looks like we're storing a register-sized value, when in
17494 fact we are not. We need to adjust the offset of the
17495 storage location to reflect the actual value's bytes,
17496 else gdb will not be able to display it. */
17498 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
17499 plus_constant (addr_mode, XEXP (rtl, 0),
17503 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
17504 and will have been substituted directly into all expressions that use it.
17505 C does not have such a concept, but C++ and other languages do. */
17506 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
17507 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
17510 rtl = targetm.delegitimize_address (rtl);
17512 /* If we don't look past the constant pool, we risk emitting a
17513 reference to a constant pool entry that isn't referenced from
17514 code, and thus is not emitted. */
17516 rtl = avoid_constant_pool_reference (rtl);
17518 /* Try harder to get a rtl. If this symbol ends up not being emitted
17519 in the current CU, resolve_addr will remove the expression referencing
17521 if (rtl == NULL_RTX
17522 && TREE_CODE (decl) == VAR_DECL
17523 && !DECL_EXTERNAL (decl)
17524 && TREE_STATIC (decl)
17525 && DECL_NAME (decl)
17526 && !DECL_HARD_REGISTER (decl)
17527 && DECL_MODE (decl) != VOIDmode)
17529 rtl = make_decl_rtl_for_debug (decl);
17531 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
17532 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
17539 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
17540 returned. If so, the decl for the COMMON block is returned, and the
17541 value is the offset into the common block for the symbol. */
17544 fortran_common (tree decl, HOST_WIDE_INT *value)
17546 tree val_expr, cvar;
17548 HOST_WIDE_INT bitsize, bitpos;
17550 int unsignedp, reversep, volatilep = 0;
17552 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
17553 it does not have a value (the offset into the common area), or if it
17554 is thread local (as opposed to global) then it isn't common, and shouldn't
17555 be handled as such. */
17556 if (TREE_CODE (decl) != VAR_DECL
17557 || !TREE_STATIC (decl)
17558 || !DECL_HAS_VALUE_EXPR_P (decl)
17562 val_expr = DECL_VALUE_EXPR (decl);
17563 if (TREE_CODE (val_expr) != COMPONENT_REF)
17566 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset, &mode,
17567 &unsignedp, &reversep, &volatilep, true);
17569 if (cvar == NULL_TREE
17570 || TREE_CODE (cvar) != VAR_DECL
17571 || DECL_ARTIFICIAL (cvar)
17572 || !TREE_PUBLIC (cvar))
17576 if (offset != NULL)
17578 if (!tree_fits_shwi_p (offset))
17580 *value = tree_to_shwi (offset);
17583 *value += bitpos / BITS_PER_UNIT;
17588 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
17589 data attribute for a variable or a parameter. We generate the
17590 DW_AT_const_value attribute only in those cases where the given variable
17591 or parameter does not have a true "location" either in memory or in a
17592 register. This can happen (for example) when a constant is passed as an
17593 actual argument in a call to an inline function. (It's possible that
17594 these things can crop up in other ways also.) Note that one type of
17595 constant value which can be passed into an inlined function is a constant
17596 pointer. This can happen for example if an actual argument in an inlined
17597 function call evaluates to a compile-time constant address.
17599 CACHE_P is true if it is worth caching the location list for DECL,
17600 so that future calls can reuse it rather than regenerate it from scratch.
17601 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
17602 since we will need to refer to them each time the function is inlined. */
17605 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p)
17608 dw_loc_list_ref list;
17609 var_loc_list *loc_list;
17610 cached_dw_loc_list *cache;
17615 if (TREE_CODE (decl) == ERROR_MARK)
17618 if (get_AT (die, DW_AT_location)
17619 || get_AT (die, DW_AT_const_value))
17622 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
17623 || TREE_CODE (decl) == RESULT_DECL);
17625 /* Try to get some constant RTL for this decl, and use that as the value of
17628 rtl = rtl_for_decl_location (decl);
17629 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
17630 && add_const_value_attribute (die, rtl))
17633 /* See if we have single element location list that is equivalent to
17634 a constant value. That way we are better to use add_const_value_attribute
17635 rather than expanding constant value equivalent. */
17636 loc_list = lookup_decl_loc (decl);
17639 && loc_list->first->next == NULL
17640 && NOTE_P (loc_list->first->loc)
17641 && NOTE_VAR_LOCATION (loc_list->first->loc)
17642 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
17644 struct var_loc_node *node;
17646 node = loc_list->first;
17647 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
17648 if (GET_CODE (rtl) == EXPR_LIST)
17649 rtl = XEXP (rtl, 0);
17650 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
17651 && add_const_value_attribute (die, rtl))
17654 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
17655 list several times. See if we've already cached the contents. */
17657 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
17661 cache = cached_dw_loc_list_table->find_with_hash (decl, DECL_UID (decl));
17663 list = cache->loc_list;
17667 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2,
17669 /* It is usually worth caching this result if the decl is from
17670 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
17671 if (cache_p && list && list->dw_loc_next)
17673 cached_dw_loc_list **slot
17674 = cached_dw_loc_list_table->find_slot_with_hash (decl,
17677 cache = ggc_cleared_alloc<cached_dw_loc_list> ();
17678 cache->decl_id = DECL_UID (decl);
17679 cache->loc_list = list;
17685 add_AT_location_description (die, DW_AT_location, list);
17688 /* None of that worked, so it must not really have a location;
17689 try adding a constant value attribute from the DECL_INITIAL. */
17690 return tree_add_const_value_attribute_for_decl (die, decl);
17693 /* Helper function for tree_add_const_value_attribute. Natively encode
17694 initializer INIT into an array. Return true if successful. */
17697 native_encode_initializer (tree init, unsigned char *array, int size)
17701 if (init == NULL_TREE)
17705 switch (TREE_CODE (init))
17708 type = TREE_TYPE (init);
17709 if (TREE_CODE (type) == ARRAY_TYPE)
17711 tree enttype = TREE_TYPE (type);
17712 machine_mode mode = TYPE_MODE (enttype);
17714 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
17716 if (int_size_in_bytes (type) != size)
17718 if (size > TREE_STRING_LENGTH (init))
17720 memcpy (array, TREE_STRING_POINTER (init),
17721 TREE_STRING_LENGTH (init));
17722 memset (array + TREE_STRING_LENGTH (init),
17723 '\0', size - TREE_STRING_LENGTH (init));
17726 memcpy (array, TREE_STRING_POINTER (init), size);
17731 type = TREE_TYPE (init);
17732 if (int_size_in_bytes (type) != size)
17734 if (TREE_CODE (type) == ARRAY_TYPE)
17736 HOST_WIDE_INT min_index;
17737 unsigned HOST_WIDE_INT cnt;
17738 int curpos = 0, fieldsize;
17739 constructor_elt *ce;
17741 if (TYPE_DOMAIN (type) == NULL_TREE
17742 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type))))
17745 fieldsize = int_size_in_bytes (TREE_TYPE (type));
17746 if (fieldsize <= 0)
17749 min_index = tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type)));
17750 memset (array, '\0', size);
17751 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init), cnt, ce)
17753 tree val = ce->value;
17754 tree index = ce->index;
17756 if (index && TREE_CODE (index) == RANGE_EXPR)
17757 pos = (tree_to_shwi (TREE_OPERAND (index, 0)) - min_index)
17760 pos = (tree_to_shwi (index) - min_index) * fieldsize;
17765 if (!native_encode_initializer (val, array + pos, fieldsize))
17768 curpos = pos + fieldsize;
17769 if (index && TREE_CODE (index) == RANGE_EXPR)
17771 int count = tree_to_shwi (TREE_OPERAND (index, 1))
17772 - tree_to_shwi (TREE_OPERAND (index, 0));
17773 while (count-- > 0)
17776 memcpy (array + curpos, array + pos, fieldsize);
17777 curpos += fieldsize;
17780 gcc_assert (curpos <= size);
17784 else if (TREE_CODE (type) == RECORD_TYPE
17785 || TREE_CODE (type) == UNION_TYPE)
17787 tree field = NULL_TREE;
17788 unsigned HOST_WIDE_INT cnt;
17789 constructor_elt *ce;
17791 if (int_size_in_bytes (type) != size)
17794 if (TREE_CODE (type) == RECORD_TYPE)
17795 field = TYPE_FIELDS (type);
17797 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init), cnt, ce)
17799 tree val = ce->value;
17800 int pos, fieldsize;
17802 if (ce->index != 0)
17808 if (field == NULL_TREE || DECL_BIT_FIELD (field))
17811 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
17812 && TYPE_DOMAIN (TREE_TYPE (field))
17813 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
17815 else if (DECL_SIZE_UNIT (field) == NULL_TREE
17816 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field)))
17818 fieldsize = tree_to_shwi (DECL_SIZE_UNIT (field));
17819 pos = int_byte_position (field);
17820 gcc_assert (pos + fieldsize <= size);
17821 if (val && fieldsize != 0
17822 && !native_encode_initializer (val, array + pos, fieldsize))
17828 case VIEW_CONVERT_EXPR:
17829 case NON_LVALUE_EXPR:
17830 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
17832 return native_encode_expr (init, array, size) == size;
17836 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17837 attribute is the const value T. */
17840 tree_add_const_value_attribute (dw_die_ref die, tree t)
17843 tree type = TREE_TYPE (t);
17846 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
17850 gcc_assert (!DECL_P (init));
17852 rtl = rtl_for_decl_init (init, type);
17854 return add_const_value_attribute (die, rtl);
17855 /* If the host and target are sane, try harder. */
17856 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
17857 && initializer_constant_valid_p (init, type))
17859 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
17860 if (size > 0 && (int) size == size)
17862 unsigned char *array = ggc_cleared_vec_alloc<unsigned char> (size);
17864 if (native_encode_initializer (init, array, size))
17866 add_AT_vec (die, DW_AT_const_value, size, 1, array);
17875 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17876 attribute is the const value of T, where T is an integral constant
17877 variable with static storage duration
17878 (so it can't be a PARM_DECL or a RESULT_DECL). */
17881 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
17885 || (TREE_CODE (decl) != VAR_DECL
17886 && TREE_CODE (decl) != CONST_DECL)
17887 || (TREE_CODE (decl) == VAR_DECL
17888 && !TREE_STATIC (decl)))
17891 if (TREE_READONLY (decl)
17892 && ! TREE_THIS_VOLATILE (decl)
17893 && DECL_INITIAL (decl))
17898 /* Don't add DW_AT_const_value if abstract origin already has one. */
17899 if (get_AT (var_die, DW_AT_const_value))
17902 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
17905 /* Convert the CFI instructions for the current function into a
17906 location list. This is used for DW_AT_frame_base when we targeting
17907 a dwarf2 consumer that does not support the dwarf3
17908 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17911 static dw_loc_list_ref
17912 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
17916 dw_loc_list_ref list, *list_tail;
17918 dw_cfa_location last_cfa, next_cfa;
17919 const char *start_label, *last_label, *section;
17920 dw_cfa_location remember;
17923 gcc_assert (fde != NULL);
17925 section = secname_for_decl (current_function_decl);
17929 memset (&next_cfa, 0, sizeof (next_cfa));
17930 next_cfa.reg = INVALID_REGNUM;
17931 remember = next_cfa;
17933 start_label = fde->dw_fde_begin;
17935 /* ??? Bald assumption that the CIE opcode list does not contain
17936 advance opcodes. */
17937 FOR_EACH_VEC_ELT (*cie_cfi_vec, ix, cfi)
17938 lookup_cfa_1 (cfi, &next_cfa, &remember);
17940 last_cfa = next_cfa;
17941 last_label = start_label;
17943 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
17945 /* If the first partition contained no CFI adjustments, the
17946 CIE opcodes apply to the whole first partition. */
17947 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17948 fde->dw_fde_begin, fde->dw_fde_end, section);
17949 list_tail =&(*list_tail)->dw_loc_next;
17950 start_label = last_label = fde->dw_fde_second_begin;
17953 FOR_EACH_VEC_SAFE_ELT (fde->dw_fde_cfi, ix, cfi)
17955 switch (cfi->dw_cfi_opc)
17957 case DW_CFA_set_loc:
17958 case DW_CFA_advance_loc1:
17959 case DW_CFA_advance_loc2:
17960 case DW_CFA_advance_loc4:
17961 if (!cfa_equal_p (&last_cfa, &next_cfa))
17963 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17964 start_label, last_label, section);
17966 list_tail = &(*list_tail)->dw_loc_next;
17967 last_cfa = next_cfa;
17968 start_label = last_label;
17970 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
17973 case DW_CFA_advance_loc:
17974 /* The encoding is complex enough that we should never emit this. */
17975 gcc_unreachable ();
17978 lookup_cfa_1 (cfi, &next_cfa, &remember);
17981 if (ix + 1 == fde->dw_fde_switch_cfi_index)
17983 if (!cfa_equal_p (&last_cfa, &next_cfa))
17985 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17986 start_label, last_label, section);
17988 list_tail = &(*list_tail)->dw_loc_next;
17989 last_cfa = next_cfa;
17990 start_label = last_label;
17992 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17993 start_label, fde->dw_fde_end, section);
17994 list_tail = &(*list_tail)->dw_loc_next;
17995 start_label = last_label = fde->dw_fde_second_begin;
17999 if (!cfa_equal_p (&last_cfa, &next_cfa))
18001 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18002 start_label, last_label, section);
18003 list_tail = &(*list_tail)->dw_loc_next;
18004 start_label = last_label;
18007 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
18009 fde->dw_fde_second_begin
18010 ? fde->dw_fde_second_end : fde->dw_fde_end,
18013 if (list && list->dw_loc_next)
18019 /* Compute a displacement from the "steady-state frame pointer" to the
18020 frame base (often the same as the CFA), and store it in
18021 frame_pointer_fb_offset. OFFSET is added to the displacement
18022 before the latter is negated. */
18025 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
18029 #ifdef FRAME_POINTER_CFA_OFFSET
18030 reg = frame_pointer_rtx;
18031 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
18033 reg = arg_pointer_rtx;
18034 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
18037 elim = (ira_use_lra_p
18038 ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
18039 : eliminate_regs (reg, VOIDmode, NULL_RTX));
18040 if (GET_CODE (elim) == PLUS)
18042 offset += INTVAL (XEXP (elim, 1));
18043 elim = XEXP (elim, 0);
18046 frame_pointer_fb_offset = -offset;
18048 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
18049 in which to eliminate. This is because it's stack pointer isn't
18050 directly accessible as a register within the ISA. To work around
18051 this, assume that while we cannot provide a proper value for
18052 frame_pointer_fb_offset, we won't need one either. */
18053 frame_pointer_fb_offset_valid
18054 = ((SUPPORTS_STACK_ALIGNMENT
18055 && (elim == hard_frame_pointer_rtx
18056 || elim == stack_pointer_rtx))
18057 || elim == (frame_pointer_needed
18058 ? hard_frame_pointer_rtx
18059 : stack_pointer_rtx));
18062 /* Generate a DW_AT_name attribute given some string value to be included as
18063 the value of the attribute. */
18066 add_name_attribute (dw_die_ref die, const char *name_string)
18068 if (name_string != NULL && *name_string != 0)
18070 if (demangle_name_func)
18071 name_string = (*demangle_name_func) (name_string);
18073 add_AT_string (die, DW_AT_name, name_string);
18077 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
18078 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
18079 of TYPE accordingly.
18081 ??? This is a temporary measure until after we're able to generate
18082 regular DWARF for the complex Ada type system. */
18085 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
18086 dw_die_ref context_die)
18089 dw_die_ref dtype_die;
18091 if (!lang_hooks.types.descriptive_type)
18094 dtype = lang_hooks.types.descriptive_type (type);
18098 dtype_die = lookup_type_die (dtype);
18101 gen_type_die (dtype, context_die);
18102 dtype_die = lookup_type_die (dtype);
18103 gcc_assert (dtype_die);
18106 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
18109 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
18111 static const char *
18112 comp_dir_string (void)
18116 static const char *cached_wd = NULL;
18118 if (cached_wd != NULL)
18121 wd = get_src_pwd ();
18125 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
18129 wdlen = strlen (wd);
18130 wd1 = ggc_vec_alloc<char> (wdlen + 2);
18132 wd1 [wdlen] = DIR_SEPARATOR;
18133 wd1 [wdlen + 1] = 0;
18137 cached_wd = remap_debug_filename (wd);
18141 /* Generate a DW_AT_comp_dir attribute for DIE. */
18144 add_comp_dir_attribute (dw_die_ref die)
18146 const char * wd = comp_dir_string ();
18148 add_AT_string (die, DW_AT_comp_dir, wd);
18151 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
18152 pointer computation, ...), output a representation for that bound according
18153 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
18154 loc_list_from_tree for the meaning of CONTEXT. */
18157 add_scalar_info (dw_die_ref die, enum dwarf_attribute attr, tree value,
18158 int forms, const struct loc_descr_context *context)
18160 dw_die_ref context_die, decl_die;
18161 dw_loc_list_ref list;
18163 bool strip_conversions = true;
18165 while (strip_conversions)
18166 switch (TREE_CODE (value))
18173 case VIEW_CONVERT_EXPR:
18174 value = TREE_OPERAND (value, 0);
18178 strip_conversions = false;
18182 /* If possible and permitted, output the attribute as a constant. */
18183 if ((forms & dw_scalar_form_constant) != 0
18184 && TREE_CODE (value) == INTEGER_CST)
18186 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (value));
18188 /* If HOST_WIDE_INT is big enough then represent the bound as
18189 a constant value. We need to choose a form based on
18190 whether the type is signed or unsigned. We cannot just
18191 call add_AT_unsigned if the value itself is positive
18192 (add_AT_unsigned might add the unsigned value encoded as
18193 DW_FORM_data[1248]). Some DWARF consumers will lookup the
18194 bounds type and then sign extend any unsigned values found
18195 for signed types. This is needed only for
18196 DW_AT_{lower,upper}_bound, since for most other attributes,
18197 consumers will treat DW_FORM_data[1248] as unsigned values,
18198 regardless of the underlying type. */
18199 if (prec <= HOST_BITS_PER_WIDE_INT
18200 || tree_fits_uhwi_p (value))
18202 if (TYPE_UNSIGNED (TREE_TYPE (value)))
18203 add_AT_unsigned (die, attr, TREE_INT_CST_LOW (value));
18205 add_AT_int (die, attr, TREE_INT_CST_LOW (value));
18208 /* Otherwise represent the bound as an unsigned value with
18209 the precision of its type. The precision and signedness
18210 of the type will be necessary to re-interpret it
18212 add_AT_wide (die, attr, value);
18216 /* Otherwise, if it's possible and permitted too, output a reference to
18218 if ((forms & dw_scalar_form_reference) != 0)
18220 tree decl = NULL_TREE;
18222 /* Some type attributes reference an outer type. For instance, the upper
18223 bound of an array may reference an embedding record (this happens in
18225 if (TREE_CODE (value) == COMPONENT_REF
18226 && TREE_CODE (TREE_OPERAND (value, 0)) == PLACEHOLDER_EXPR
18227 && TREE_CODE (TREE_OPERAND (value, 1)) == FIELD_DECL)
18228 decl = TREE_OPERAND (value, 1);
18230 else if (TREE_CODE (value) == VAR_DECL
18231 || TREE_CODE (value) == PARM_DECL
18232 || TREE_CODE (value) == RESULT_DECL)
18235 if (decl != NULL_TREE)
18237 dw_die_ref decl_die = lookup_decl_die (decl);
18239 /* ??? Can this happen, or should the variable have been bound
18240 first? Probably it can, since I imagine that we try to create
18241 the types of parameters in the order in which they exist in
18242 the list, and won't have created a forward reference to a
18243 later parameter. */
18244 if (decl_die != NULL)
18246 add_AT_die_ref (die, attr, decl_die);
18252 /* Last chance: try to create a stack operation procedure to evaluate the
18253 value. Do nothing if even that is not possible or permitted. */
18254 if ((forms & dw_scalar_form_exprloc) == 0)
18257 list = loc_list_from_tree (value, 2, context);
18258 if (list == NULL || single_element_loc_list_p (list))
18260 /* If this attribute is not a reference nor constant, it is
18261 a DWARF expression rather than location description. For that
18262 loc_list_from_tree (value, 0, &context) is needed. */
18263 dw_loc_list_ref list2 = loc_list_from_tree (value, 0, context);
18264 if (list2 && single_element_loc_list_p (list2))
18266 add_AT_loc (die, attr, list2->expr);
18271 /* If that failed to give a single element location list, fall back to
18272 outputting this as a reference... still if permitted. */
18273 if (list == NULL || (forms & dw_scalar_form_reference) == 0)
18276 if (current_function_decl == 0)
18277 context_die = comp_unit_die ();
18279 context_die = lookup_decl_die (current_function_decl);
18281 decl_die = new_die (DW_TAG_variable, context_die, value);
18282 add_AT_flag (decl_die, DW_AT_artificial, 1);
18283 add_type_attribute (decl_die, TREE_TYPE (value), TYPE_QUAL_CONST, false,
18285 add_AT_location_description (decl_die, DW_AT_location, list);
18286 add_AT_die_ref (die, attr, decl_die);
18289 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
18293 lower_bound_default (void)
18295 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
18301 case DW_LANG_C_plus_plus:
18302 case DW_LANG_C_plus_plus_11:
18303 case DW_LANG_C_plus_plus_14:
18305 case DW_LANG_ObjC_plus_plus:
18308 case DW_LANG_Fortran77:
18309 case DW_LANG_Fortran90:
18310 case DW_LANG_Fortran95:
18311 case DW_LANG_Fortran03:
18312 case DW_LANG_Fortran08:
18316 case DW_LANG_Python:
18317 return dwarf_version >= 4 ? 0 : -1;
18318 case DW_LANG_Ada95:
18319 case DW_LANG_Ada83:
18320 case DW_LANG_Cobol74:
18321 case DW_LANG_Cobol85:
18322 case DW_LANG_Pascal83:
18323 case DW_LANG_Modula2:
18325 return dwarf_version >= 4 ? 1 : -1;
18331 /* Given a tree node describing an array bound (either lower or upper) output
18332 a representation for that bound. */
18335 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr,
18336 tree bound, const struct loc_descr_context *context)
18341 switch (TREE_CODE (bound))
18343 /* Strip all conversions. */
18345 case VIEW_CONVERT_EXPR:
18346 bound = TREE_OPERAND (bound, 0);
18349 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
18350 are even omitted when they are the default. */
18352 /* If the value for this bound is the default one, we can even omit the
18354 if (bound_attr == DW_AT_lower_bound
18355 && tree_fits_shwi_p (bound)
18356 && (dflt = lower_bound_default ()) != -1
18357 && tree_to_shwi (bound) == dflt)
18363 /* Because of the complex interaction there can be with other GNAT
18364 encodings, GDB isn't ready yet to handle proper DWARF description
18365 for self-referencial subrange bounds: let GNAT encodings do the
18366 magic in such a case. */
18367 if (gnat_encodings != DWARF_GNAT_ENCODINGS_MINIMAL
18368 && contains_placeholder_p (bound))
18371 add_scalar_info (subrange_die, bound_attr, bound,
18372 dw_scalar_form_constant
18373 | dw_scalar_form_exprloc
18374 | dw_scalar_form_reference,
18380 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
18381 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
18382 Note that the block of subscript information for an array type also
18383 includes information about the element type of the given array type.
18385 This function reuses previously set type and bound information if
18389 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
18391 unsigned dimension_number;
18393 dw_die_ref child = type_die->die_child;
18395 for (dimension_number = 0;
18396 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
18397 type = TREE_TYPE (type), dimension_number++)
18399 tree domain = TYPE_DOMAIN (type);
18401 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
18404 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
18405 and (in GNU C only) variable bounds. Handle all three forms
18408 /* Find and reuse a previously generated DW_TAG_subrange_type if
18411 For multi-dimensional arrays, as we iterate through the
18412 various dimensions in the enclosing for loop above, we also
18413 iterate through the DIE children and pick at each
18414 DW_TAG_subrange_type previously generated (if available).
18415 Each child DW_TAG_subrange_type DIE describes the range of
18416 the current dimension. At this point we should have as many
18417 DW_TAG_subrange_type's as we have dimensions in the
18419 dw_die_ref subrange_die = NULL;
18423 child = child->die_sib;
18424 if (child->die_tag == DW_TAG_subrange_type)
18425 subrange_die = child;
18426 if (child == type_die->die_child)
18428 /* If we wrapped around, stop looking next time. */
18432 if (child->die_tag == DW_TAG_subrange_type)
18436 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
18440 /* We have an array type with specified bounds. */
18441 lower = TYPE_MIN_VALUE (domain);
18442 upper = TYPE_MAX_VALUE (domain);
18444 /* Define the index type. */
18445 if (TREE_TYPE (domain)
18446 && !get_AT (subrange_die, DW_AT_type))
18448 /* ??? This is probably an Ada unnamed subrange type. Ignore the
18449 TREE_TYPE field. We can't emit debug info for this
18450 because it is an unnamed integral type. */
18451 if (TREE_CODE (domain) == INTEGER_TYPE
18452 && TYPE_NAME (domain) == NULL_TREE
18453 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
18454 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
18457 add_type_attribute (subrange_die, TREE_TYPE (domain),
18458 TYPE_UNQUALIFIED, false, type_die);
18461 /* ??? If upper is NULL, the array has unspecified length,
18462 but it does have a lower bound. This happens with Fortran
18464 Since the debugger is definitely going to need to know N
18465 to produce useful results, go ahead and output the lower
18466 bound solo, and hope the debugger can cope. */
18468 if (!get_AT (subrange_die, DW_AT_lower_bound))
18469 add_bound_info (subrange_die, DW_AT_lower_bound, lower, NULL);
18470 if (upper && !get_AT (subrange_die, DW_AT_upper_bound))
18471 add_bound_info (subrange_die, DW_AT_upper_bound, upper, NULL);
18474 /* Otherwise we have an array type with an unspecified length. The
18475 DWARF-2 spec does not say how to handle this; let's just leave out the
18480 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
18483 add_byte_size_attribute (dw_die_ref die, tree tree_node)
18485 dw_die_ref decl_die;
18486 HOST_WIDE_INT size;
18487 dw_loc_descr_ref size_expr = NULL;
18489 switch (TREE_CODE (tree_node))
18494 case ENUMERAL_TYPE:
18497 case QUAL_UNION_TYPE:
18498 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node)) == VAR_DECL
18499 && (decl_die = lookup_decl_die (TYPE_SIZE_UNIT (tree_node))))
18501 add_AT_die_ref (die, DW_AT_byte_size, decl_die);
18504 size_expr = type_byte_size (tree_node, &size);
18507 /* For a data member of a struct or union, the DW_AT_byte_size is
18508 generally given as the number of bytes normally allocated for an
18509 object of the *declared* type of the member itself. This is true
18510 even for bit-fields. */
18511 size = int_size_in_bytes (field_type (tree_node));
18514 gcc_unreachable ();
18517 /* Support for dynamically-sized objects was introduced by DWARFv3.
18518 At the moment, GDB does not handle variable byte sizes very well,
18520 if ((dwarf_version >= 3 || !dwarf_strict)
18521 && gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL
18522 && size_expr != NULL)
18523 add_AT_loc (die, DW_AT_byte_size, size_expr);
18525 /* Note that `size' might be -1 when we get to this point. If it is, that
18526 indicates that the byte size of the entity in question is variable and
18527 that we could not generate a DWARF expression that computes it. */
18529 add_AT_unsigned (die, DW_AT_byte_size, size);
18532 /* For a FIELD_DECL node which represents a bit-field, output an attribute
18533 which specifies the distance in bits from the highest order bit of the
18534 "containing object" for the bit-field to the highest order bit of the
18537 For any given bit-field, the "containing object" is a hypothetical object
18538 (of some integral or enum type) within which the given bit-field lives. The
18539 type of this hypothetical "containing object" is always the same as the
18540 declared type of the individual bit-field itself. The determination of the
18541 exact location of the "containing object" for a bit-field is rather
18542 complicated. It's handled by the `field_byte_offset' function (above).
18544 CTX is required: see the comment for VLR_CONTEXT.
18546 Note that it is the size (in bytes) of the hypothetical "containing object"
18547 which will be given in the DW_AT_byte_size attribute for this bit-field.
18548 (See `byte_size_attribute' above). */
18551 add_bit_offset_attribute (dw_die_ref die, tree decl, struct vlr_context *ctx)
18553 HOST_WIDE_INT object_offset_in_bytes;
18554 tree original_type = DECL_BIT_FIELD_TYPE (decl);
18555 HOST_WIDE_INT bitpos_int;
18556 HOST_WIDE_INT highest_order_object_bit_offset;
18557 HOST_WIDE_INT highest_order_field_bit_offset;
18558 HOST_WIDE_INT bit_offset;
18560 field_byte_offset (decl, ctx, &object_offset_in_bytes);
18562 /* Must be a field and a bit field. */
18563 gcc_assert (original_type && TREE_CODE (decl) == FIELD_DECL);
18565 /* We can't yet handle bit-fields whose offsets are variable, so if we
18566 encounter such things, just return without generating any attribute
18567 whatsoever. Likewise for variable or too large size. */
18568 if (! tree_fits_shwi_p (bit_position (decl))
18569 || ! tree_fits_uhwi_p (DECL_SIZE (decl)))
18572 bitpos_int = int_bit_position (decl);
18574 /* Note that the bit offset is always the distance (in bits) from the
18575 highest-order bit of the "containing object" to the highest-order bit of
18576 the bit-field itself. Since the "high-order end" of any object or field
18577 is different on big-endian and little-endian machines, the computation
18578 below must take account of these differences. */
18579 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
18580 highest_order_field_bit_offset = bitpos_int;
18582 if (! BYTES_BIG_ENDIAN)
18584 highest_order_field_bit_offset += tree_to_shwi (DECL_SIZE (decl));
18585 highest_order_object_bit_offset +=
18586 simple_type_size_in_bits (original_type);
18590 = (! BYTES_BIG_ENDIAN
18591 ? highest_order_object_bit_offset - highest_order_field_bit_offset
18592 : highest_order_field_bit_offset - highest_order_object_bit_offset);
18594 if (bit_offset < 0)
18595 add_AT_int (die, DW_AT_bit_offset, bit_offset);
18597 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
18600 /* For a FIELD_DECL node which represents a bit field, output an attribute
18601 which specifies the length in bits of the given field. */
18604 add_bit_size_attribute (dw_die_ref die, tree decl)
18606 /* Must be a field and a bit field. */
18607 gcc_assert (TREE_CODE (decl) == FIELD_DECL
18608 && DECL_BIT_FIELD_TYPE (decl));
18610 if (tree_fits_uhwi_p (DECL_SIZE (decl)))
18611 add_AT_unsigned (die, DW_AT_bit_size, tree_to_uhwi (DECL_SIZE (decl)));
18614 /* If the compiled language is ANSI C, then add a 'prototyped'
18615 attribute, if arg types are given for the parameters of a function. */
18618 add_prototyped_attribute (dw_die_ref die, tree func_type)
18620 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
18627 if (prototype_p (func_type))
18628 add_AT_flag (die, DW_AT_prototyped, 1);
18635 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
18636 by looking in either the type declaration or object declaration
18639 static inline dw_die_ref
18640 add_abstract_origin_attribute (dw_die_ref die, tree origin)
18642 dw_die_ref origin_die = NULL;
18644 if (TREE_CODE (origin) != FUNCTION_DECL)
18646 /* We may have gotten separated from the block for the inlined
18647 function, if we're in an exception handler or some such; make
18648 sure that the abstract function has been written out.
18650 Doing this for nested functions is wrong, however; functions are
18651 distinct units, and our context might not even be inline. */
18655 fn = TYPE_STUB_DECL (fn);
18657 fn = decl_function_context (fn);
18659 dwarf2out_abstract_function (fn);
18662 if (DECL_P (origin))
18663 origin_die = lookup_decl_die (origin);
18664 else if (TYPE_P (origin))
18665 origin_die = lookup_type_die (origin);
18667 /* XXX: Functions that are never lowered don't always have correct block
18668 trees (in the case of java, they simply have no block tree, in some other
18669 languages). For these functions, there is nothing we can really do to
18670 output correct debug info for inlined functions in all cases. Rather
18671 than die, we'll just produce deficient debug info now, in that we will
18672 have variables without a proper abstract origin. In the future, when all
18673 functions are lowered, we should re-add a gcc_assert (origin_die)
18677 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
18681 /* We do not currently support the pure_virtual attribute. */
18684 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
18686 if (DECL_VINDEX (func_decl))
18688 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
18690 if (tree_fits_shwi_p (DECL_VINDEX (func_decl)))
18691 add_AT_loc (die, DW_AT_vtable_elem_location,
18692 new_loc_descr (DW_OP_constu,
18693 tree_to_shwi (DECL_VINDEX (func_decl)),
18696 /* GNU extension: Record what type this method came from originally. */
18697 if (debug_info_level > DINFO_LEVEL_TERSE
18698 && DECL_CONTEXT (func_decl))
18699 add_AT_die_ref (die, DW_AT_containing_type,
18700 lookup_type_die (DECL_CONTEXT (func_decl)));
18704 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
18705 given decl. This used to be a vendor extension until after DWARF 4
18706 standardized it. */
18709 add_linkage_attr (dw_die_ref die, tree decl)
18711 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
18713 /* Mimic what assemble_name_raw does with a leading '*'. */
18714 if (name[0] == '*')
18717 if (dwarf_version >= 4)
18718 add_AT_string (die, DW_AT_linkage_name, name);
18720 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
18723 /* Add source coordinate attributes for the given decl. */
18726 add_src_coords_attributes (dw_die_ref die, tree decl)
18728 expanded_location s;
18730 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl)) == UNKNOWN_LOCATION)
18732 s = expand_location (DECL_SOURCE_LOCATION (decl));
18733 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
18734 add_AT_unsigned (die, DW_AT_decl_line, s.line);
18737 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
18740 add_linkage_name_raw (dw_die_ref die, tree decl)
18742 /* Defer until we have an assembler name set. */
18743 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
18745 limbo_die_node *asm_name;
18747 asm_name = ggc_cleared_alloc<limbo_die_node> ();
18748 asm_name->die = die;
18749 asm_name->created_for = decl;
18750 asm_name->next = deferred_asm_name;
18751 deferred_asm_name = asm_name;
18753 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
18754 add_linkage_attr (die, decl);
18757 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
18760 add_linkage_name (dw_die_ref die, tree decl)
18762 if (debug_info_level > DINFO_LEVEL_NONE
18763 && (TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
18764 && TREE_PUBLIC (decl)
18765 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
18766 && die->die_tag != DW_TAG_member)
18767 add_linkage_name_raw (die, decl);
18770 /* Add a DW_AT_name attribute and source coordinate attribute for the
18771 given decl, but only if it actually has a name. */
18774 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
18778 decl_name = DECL_NAME (decl);
18779 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
18781 const char *name = dwarf2_name (decl, 0);
18783 add_name_attribute (die, name);
18784 if (! DECL_ARTIFICIAL (decl))
18785 add_src_coords_attributes (die, decl);
18787 add_linkage_name (die, decl);
18790 #ifdef VMS_DEBUGGING_INFO
18791 /* Get the function's name, as described by its RTL. This may be different
18792 from the DECL_NAME name used in the source file. */
18793 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
18795 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
18796 XEXP (DECL_RTL (decl), 0), false);
18797 vec_safe_push (used_rtx_array, XEXP (DECL_RTL (decl), 0));
18799 #endif /* VMS_DEBUGGING_INFO */
18802 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
18805 add_discr_value (dw_die_ref die, dw_discr_value *value)
18809 attr.dw_attr = DW_AT_discr_value;
18810 attr.dw_attr_val.val_class = dw_val_class_discr_value;
18811 attr.dw_attr_val.val_entry = NULL;
18812 attr.dw_attr_val.v.val_discr_value.pos = value->pos;
18814 attr.dw_attr_val.v.val_discr_value.v.uval = value->v.uval;
18816 attr.dw_attr_val.v.val_discr_value.v.sval = value->v.sval;
18817 add_dwarf_attr (die, &attr);
18820 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
18823 add_discr_list (dw_die_ref die, dw_discr_list_ref discr_list)
18827 attr.dw_attr = DW_AT_discr_list;
18828 attr.dw_attr_val.val_class = dw_val_class_discr_list;
18829 attr.dw_attr_val.val_entry = NULL;
18830 attr.dw_attr_val.v.val_discr_list = discr_list;
18831 add_dwarf_attr (die, &attr);
18834 static inline dw_discr_list_ref
18835 AT_discr_list (dw_attr_node *attr)
18837 return attr->dw_attr_val.v.val_discr_list;
18840 #ifdef VMS_DEBUGGING_INFO
18841 /* Output the debug main pointer die for VMS */
18844 dwarf2out_vms_debug_main_pointer (void)
18846 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18849 /* Allocate the VMS debug main subprogram die. */
18850 die = ggc_cleared_alloc<die_node> ();
18851 die->die_tag = DW_TAG_subprogram;
18852 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
18853 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
18854 current_function_funcdef_no);
18855 add_AT_lbl_id (die, DW_AT_entry_pc, label);
18857 /* Make it the first child of comp_unit_die (). */
18858 die->die_parent = comp_unit_die ();
18859 if (comp_unit_die ()->die_child)
18861 die->die_sib = comp_unit_die ()->die_child->die_sib;
18862 comp_unit_die ()->die_child->die_sib = die;
18866 die->die_sib = die;
18867 comp_unit_die ()->die_child = die;
18870 #endif /* VMS_DEBUGGING_INFO */
18872 /* Push a new declaration scope. */
18875 push_decl_scope (tree scope)
18877 vec_safe_push (decl_scope_table, scope);
18880 /* Pop a declaration scope. */
18883 pop_decl_scope (void)
18885 decl_scope_table->pop ();
18888 /* walk_tree helper function for uses_local_type, below. */
18891 uses_local_type_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
18894 *walk_subtrees = 0;
18897 tree name = TYPE_NAME (*tp);
18898 if (name && DECL_P (name) && decl_function_context (name))
18904 /* If TYPE involves a function-local type (including a local typedef to a
18905 non-local type), returns that type; otherwise returns NULL_TREE. */
18908 uses_local_type (tree type)
18910 tree used = walk_tree_without_duplicates (&type, uses_local_type_r, NULL);
18914 /* Return the DIE for the scope that immediately contains this type.
18915 Non-named types that do not involve a function-local type get global
18916 scope. Named types nested in namespaces or other types get their
18917 containing scope. All other types (i.e. function-local named types) get
18918 the current active scope. */
18921 scope_die_for (tree t, dw_die_ref context_die)
18923 dw_die_ref scope_die = NULL;
18924 tree containing_scope;
18926 /* Non-types always go in the current scope. */
18927 gcc_assert (TYPE_P (t));
18929 /* Use the scope of the typedef, rather than the scope of the type
18931 if (TYPE_NAME (t) && DECL_P (TYPE_NAME (t)))
18932 containing_scope = DECL_CONTEXT (TYPE_NAME (t));
18934 containing_scope = TYPE_CONTEXT (t);
18936 /* Use the containing namespace if there is one. */
18937 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
18939 if (context_die == lookup_decl_die (containing_scope))
18941 else if (debug_info_level > DINFO_LEVEL_TERSE)
18942 context_die = get_context_die (containing_scope);
18944 containing_scope = NULL_TREE;
18947 /* Ignore function type "scopes" from the C frontend. They mean that
18948 a tagged type is local to a parmlist of a function declarator, but
18949 that isn't useful to DWARF. */
18950 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
18951 containing_scope = NULL_TREE;
18953 if (SCOPE_FILE_SCOPE_P (containing_scope))
18955 /* If T uses a local type keep it local as well, to avoid references
18956 to function-local DIEs from outside the function. */
18957 if (current_function_decl && uses_local_type (t))
18958 scope_die = context_die;
18960 scope_die = comp_unit_die ();
18962 else if (TYPE_P (containing_scope))
18964 /* For types, we can just look up the appropriate DIE. */
18965 if (debug_info_level > DINFO_LEVEL_TERSE)
18966 scope_die = get_context_die (containing_scope);
18969 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
18970 if (scope_die == NULL)
18971 scope_die = comp_unit_die ();
18975 scope_die = context_die;
18980 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
18983 local_scope_p (dw_die_ref context_die)
18985 for (; context_die; context_die = context_die->die_parent)
18986 if (context_die->die_tag == DW_TAG_inlined_subroutine
18987 || context_die->die_tag == DW_TAG_subprogram)
18993 /* Returns nonzero if CONTEXT_DIE is a class. */
18996 class_scope_p (dw_die_ref context_die)
18998 return (context_die
18999 && (context_die->die_tag == DW_TAG_structure_type
19000 || context_die->die_tag == DW_TAG_class_type
19001 || context_die->die_tag == DW_TAG_interface_type
19002 || context_die->die_tag == DW_TAG_union_type));
19005 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
19006 whether or not to treat a DIE in this context as a declaration. */
19009 class_or_namespace_scope_p (dw_die_ref context_die)
19011 return (class_scope_p (context_die)
19012 || (context_die && context_die->die_tag == DW_TAG_namespace));
19015 /* Many forms of DIEs require a "type description" attribute. This
19016 routine locates the proper "type descriptor" die for the type given
19017 by 'type' plus any additional qualifiers given by 'cv_quals', and
19018 adds a DW_AT_type attribute below the given die. */
19021 add_type_attribute (dw_die_ref object_die, tree type, int cv_quals,
19022 bool reverse, dw_die_ref context_die)
19024 enum tree_code code = TREE_CODE (type);
19025 dw_die_ref type_die = NULL;
19027 /* ??? If this type is an unnamed subrange type of an integral, floating-point
19028 or fixed-point type, use the inner type. This is because we have no
19029 support for unnamed types in base_type_die. This can happen if this is
19030 an Ada subrange type. Correct solution is emit a subrange type die. */
19031 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
19032 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
19033 type = TREE_TYPE (type), code = TREE_CODE (type);
19035 if (code == ERROR_MARK
19036 /* Handle a special case. For functions whose return type is void, we
19037 generate *no* type attribute. (Note that no object may have type
19038 `void', so this only applies to function return types). */
19039 || code == VOID_TYPE)
19042 type_die = modified_type_die (type,
19043 cv_quals | TYPE_QUALS_NO_ADDR_SPACE (type),
19047 if (type_die != NULL)
19048 add_AT_die_ref (object_die, DW_AT_type, type_die);
19051 /* Given an object die, add the calling convention attribute for the
19052 function call type. */
19054 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
19056 enum dwarf_calling_convention value = DW_CC_normal;
19058 value = ((enum dwarf_calling_convention)
19059 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
19062 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
19064 /* DWARF 2 doesn't provide a way to identify a program's source-level
19065 entry point. DW_AT_calling_convention attributes are only meant
19066 to describe functions' calling conventions. However, lacking a
19067 better way to signal the Fortran main program, we used this for
19068 a long time, following existing custom. Now, DWARF 4 has
19069 DW_AT_main_subprogram, which we add below, but some tools still
19070 rely on the old way, which we thus keep. */
19071 value = DW_CC_program;
19073 if (dwarf_version >= 4 || !dwarf_strict)
19074 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
19077 /* Only add the attribute if the backend requests it, and
19078 is not DW_CC_normal. */
19079 if (value && (value != DW_CC_normal))
19080 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
19083 /* Given a tree pointer to a struct, class, union, or enum type node, return
19084 a pointer to the (string) tag name for the given type, or zero if the type
19085 was declared without a tag. */
19087 static const char *
19088 type_tag (const_tree type)
19090 const char *name = 0;
19092 if (TYPE_NAME (type) != 0)
19096 /* Find the IDENTIFIER_NODE for the type name. */
19097 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
19098 && !TYPE_NAMELESS (type))
19099 t = TYPE_NAME (type);
19101 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
19102 a TYPE_DECL node, regardless of whether or not a `typedef' was
19104 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
19105 && ! DECL_IGNORED_P (TYPE_NAME (type)))
19107 /* We want to be extra verbose. Don't call dwarf_name if
19108 DECL_NAME isn't set. The default hook for decl_printable_name
19109 doesn't like that, and in this context it's correct to return
19110 0, instead of "<anonymous>" or the like. */
19111 if (DECL_NAME (TYPE_NAME (type))
19112 && !DECL_NAMELESS (TYPE_NAME (type)))
19113 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
19116 /* Now get the name as a string, or invent one. */
19117 if (!name && t != 0)
19118 name = IDENTIFIER_POINTER (t);
19121 return (name == 0 || *name == '\0') ? 0 : name;
19124 /* Return the type associated with a data member, make a special check
19125 for bit field types. */
19128 member_declared_type (const_tree member)
19130 return (DECL_BIT_FIELD_TYPE (member)
19131 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
19134 /* Get the decl's label, as described by its RTL. This may be different
19135 from the DECL_NAME name used in the source file. */
19138 static const char *
19139 decl_start_label (tree decl)
19142 const char *fnname;
19144 x = DECL_RTL (decl);
19145 gcc_assert (MEM_P (x));
19148 gcc_assert (GET_CODE (x) == SYMBOL_REF);
19150 fnname = XSTR (x, 0);
19155 /* For variable-length arrays that have been previously generated, but
19156 may be incomplete due to missing subscript info, fill the subscript
19157 info. Return TRUE if this is one of those cases. */
19159 fill_variable_array_bounds (tree type)
19161 if (TREE_ASM_WRITTEN (type)
19162 && TREE_CODE (type) == ARRAY_TYPE
19163 && variably_modified_type_p (type, NULL))
19165 dw_die_ref array_die = lookup_type_die (type);
19168 add_subscript_info (array_die, type, !is_ada ());
19174 /* These routines generate the internal representation of the DIE's for
19175 the compilation unit. Debugging information is collected by walking
19176 the declaration trees passed in from dwarf2out_decl(). */
19179 gen_array_type_die (tree type, dw_die_ref context_die)
19181 dw_die_ref array_die;
19183 /* GNU compilers represent multidimensional array types as sequences of one
19184 dimensional array types whose element types are themselves array types.
19185 We sometimes squish that down to a single array_type DIE with multiple
19186 subscripts in the Dwarf debugging info. The draft Dwarf specification
19187 say that we are allowed to do this kind of compression in C, because
19188 there is no difference between an array of arrays and a multidimensional
19189 array. We don't do this for Ada to remain as close as possible to the
19190 actual representation, which is especially important against the language
19191 flexibilty wrt arrays of variable size. */
19193 bool collapse_nested_arrays = !is_ada ();
19195 if (fill_variable_array_bounds (type))
19198 dw_die_ref scope_die = scope_die_for (type, context_die);
19201 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
19202 DW_TAG_string_type doesn't have DW_AT_type attribute). */
19203 if (TYPE_STRING_FLAG (type)
19204 && TREE_CODE (type) == ARRAY_TYPE
19206 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
19208 HOST_WIDE_INT size;
19210 array_die = new_die (DW_TAG_string_type, scope_die, type);
19211 add_name_attribute (array_die, type_tag (type));
19212 equate_type_number_to_die (type, array_die);
19213 size = int_size_in_bytes (type);
19215 add_AT_unsigned (array_die, DW_AT_byte_size, size);
19216 else if (TYPE_DOMAIN (type) != NULL_TREE
19217 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE)
19219 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
19220 tree rszdecl = szdecl;
19221 HOST_WIDE_INT rsize = 0;
19223 size = int_size_in_bytes (TREE_TYPE (szdecl));
19224 if (!DECL_P (szdecl))
19226 if (TREE_CODE (szdecl) == INDIRECT_REF
19227 && DECL_P (TREE_OPERAND (szdecl, 0)))
19229 rszdecl = TREE_OPERAND (szdecl, 0);
19230 rsize = int_size_in_bytes (TREE_TYPE (rszdecl));
19239 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2, NULL);
19242 && current_function_decl
19243 && DECL_CONTEXT (rszdecl) == current_function_decl)
19245 dw_die_ref ref = lookup_decl_die (rszdecl);
19246 dw_loc_descr_ref l = NULL;
19249 l = new_loc_descr (DW_OP_call4, 0, 0);
19250 l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
19251 l->dw_loc_oprnd1.v.val_die_ref.die = ref;
19252 l->dw_loc_oprnd1.v.val_die_ref.external = 0;
19254 else if (TREE_CODE (rszdecl) == PARM_DECL
19257 l = new_loc_descr (DW_OP_call4, 0, 0);
19258 l->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
19259 l->dw_loc_oprnd1.v.val_decl_ref = rszdecl;
19260 string_types->safe_push (array_die);
19262 if (l && rszdecl != szdecl)
19264 if (rsize == DWARF2_ADDR_SIZE)
19265 add_loc_descr (&l, new_loc_descr (DW_OP_deref,
19268 add_loc_descr (&l, new_loc_descr (DW_OP_deref_size,
19272 loc = new_loc_list (l, NULL, NULL, NULL);
19276 add_AT_location_description (array_die, DW_AT_string_length,
19278 if (size != DWARF2_ADDR_SIZE)
19279 add_AT_unsigned (array_die, DW_AT_byte_size, size);
19286 array_die = new_die (DW_TAG_array_type, scope_die, type);
19287 add_name_attribute (array_die, type_tag (type));
19288 equate_type_number_to_die (type, array_die);
19290 if (TREE_CODE (type) == VECTOR_TYPE)
19291 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
19293 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
19295 && TREE_CODE (type) == ARRAY_TYPE
19296 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
19297 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
19298 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
19301 /* We default the array ordering. SDB will probably do
19302 the right things even if DW_AT_ordering is not present. It's not even
19303 an issue until we start to get into multidimensional arrays anyway. If
19304 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
19305 then we'll have to put the DW_AT_ordering attribute back in. (But if
19306 and when we find out that we need to put these in, we will only do so
19307 for multidimensional arrays. */
19308 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
19311 if (TREE_CODE (type) == VECTOR_TYPE)
19313 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
19314 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
19315 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node, NULL);
19316 add_bound_info (subrange_die, DW_AT_upper_bound,
19317 size_int (TYPE_VECTOR_SUBPARTS (type) - 1), NULL);
19320 add_subscript_info (array_die, type, collapse_nested_arrays);
19322 /* Add representation of the type of the elements of this array type and
19323 emit the corresponding DIE if we haven't done it already. */
19324 element_type = TREE_TYPE (type);
19325 if (collapse_nested_arrays)
19326 while (TREE_CODE (element_type) == ARRAY_TYPE)
19328 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
19330 element_type = TREE_TYPE (element_type);
19333 add_type_attribute (array_die, element_type, TYPE_UNQUALIFIED,
19334 TREE_CODE (type) == ARRAY_TYPE
19335 && TYPE_REVERSE_STORAGE_ORDER (type),
19338 add_gnat_descriptive_type_attribute (array_die, type, context_die);
19339 if (TYPE_ARTIFICIAL (type))
19340 add_AT_flag (array_die, DW_AT_artificial, 1);
19342 if (get_AT (array_die, DW_AT_name))
19343 add_pubtype (type, array_die);
19346 /* After all arguments are created, adjust any DW_TAG_string_type
19347 DIEs DW_AT_string_length attributes. */
19350 adjust_string_types (void)
19352 dw_die_ref array_die;
19354 FOR_EACH_VEC_ELT (*string_types, i, array_die)
19356 dw_attr_node *a = get_AT (array_die, DW_AT_string_length);
19359 dw_loc_descr_ref loc = AT_loc (a);
19360 gcc_assert (loc->dw_loc_opc == DW_OP_call4
19361 && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref);
19362 dw_die_ref ref = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
19365 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
19366 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
19367 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
19371 remove_AT (array_die, DW_AT_string_length);
19372 remove_AT (array_die, DW_AT_byte_size);
19377 /* This routine generates DIE for array with hidden descriptor, details
19378 are filled into *info by a langhook. */
19381 gen_descr_array_type_die (tree type, struct array_descr_info *info,
19382 dw_die_ref context_die)
19384 const dw_die_ref scope_die = scope_die_for (type, context_die);
19385 const dw_die_ref array_die = new_die (DW_TAG_array_type, scope_die, type);
19386 const struct loc_descr_context context = { type, info->base_decl, NULL };
19389 add_name_attribute (array_die, type_tag (type));
19390 equate_type_number_to_die (type, array_die);
19392 if (info->ndimensions > 1)
19393 switch (info->ordering)
19395 case array_descr_ordering_row_major:
19396 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
19398 case array_descr_ordering_column_major:
19399 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
19405 if (dwarf_version >= 3 || !dwarf_strict)
19407 if (info->data_location)
19408 add_scalar_info (array_die, DW_AT_data_location, info->data_location,
19409 dw_scalar_form_exprloc, &context);
19410 if (info->associated)
19411 add_scalar_info (array_die, DW_AT_associated, info->associated,
19412 dw_scalar_form_constant
19413 | dw_scalar_form_exprloc
19414 | dw_scalar_form_reference, &context);
19415 if (info->allocated)
19416 add_scalar_info (array_die, DW_AT_allocated, info->allocated,
19417 dw_scalar_form_constant
19418 | dw_scalar_form_exprloc
19419 | dw_scalar_form_reference, &context);
19422 const enum dwarf_attribute attr
19423 = (info->stride_in_bits) ? DW_AT_bit_stride : DW_AT_byte_stride;
19425 = (info->stride_in_bits)
19426 ? dw_scalar_form_constant
19427 : (dw_scalar_form_constant
19428 | dw_scalar_form_exprloc
19429 | dw_scalar_form_reference);
19431 add_scalar_info (array_die, attr, info->stride, forms, &context);
19435 add_gnat_descriptive_type_attribute (array_die, type, context_die);
19437 for (dim = 0; dim < info->ndimensions; dim++)
19439 dw_die_ref subrange_die
19440 = new_die (DW_TAG_subrange_type, array_die, NULL);
19442 if (info->dimen[dim].bounds_type)
19443 add_type_attribute (subrange_die,
19444 info->dimen[dim].bounds_type, TYPE_UNQUALIFIED,
19445 false, context_die);
19446 if (info->dimen[dim].lower_bound)
19447 add_bound_info (subrange_die, DW_AT_lower_bound,
19448 info->dimen[dim].lower_bound, &context);
19449 if (info->dimen[dim].upper_bound)
19450 add_bound_info (subrange_die, DW_AT_upper_bound,
19451 info->dimen[dim].upper_bound, &context);
19452 if ((dwarf_version >= 3 || !dwarf_strict) && info->dimen[dim].stride)
19453 add_scalar_info (subrange_die, DW_AT_byte_stride,
19454 info->dimen[dim].stride,
19455 dw_scalar_form_constant
19456 | dw_scalar_form_exprloc
19457 | dw_scalar_form_reference,
19461 gen_type_die (info->element_type, context_die);
19462 add_type_attribute (array_die, info->element_type, TYPE_UNQUALIFIED,
19463 TREE_CODE (type) == ARRAY_TYPE
19464 && TYPE_REVERSE_STORAGE_ORDER (type),
19467 if (get_AT (array_die, DW_AT_name))
19468 add_pubtype (type, array_die);
19473 gen_entry_point_die (tree decl, dw_die_ref context_die)
19475 tree origin = decl_ultimate_origin (decl);
19476 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
19478 if (origin != NULL)
19479 add_abstract_origin_attribute (decl_die, origin);
19482 add_name_and_src_coords_attributes (decl_die, decl);
19483 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
19484 TYPE_UNQUALIFIED, false, context_die);
19487 if (DECL_ABSTRACT_P (decl))
19488 equate_decl_number_to_die (decl, decl_die);
19490 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
19494 /* Walk through the list of incomplete types again, trying once more to
19495 emit full debugging info for them. */
19498 retry_incomplete_types (void)
19503 for (i = vec_safe_length (incomplete_types) - 1; i >= 0; i--)
19504 if (should_emit_struct_debug ((*incomplete_types)[i], DINFO_USAGE_DIR_USE))
19505 gen_type_die ((*incomplete_types)[i], comp_unit_die ());
19506 vec_safe_truncate (incomplete_types, 0);
19509 /* Determine what tag to use for a record type. */
19511 static enum dwarf_tag
19512 record_type_tag (tree type)
19514 if (! lang_hooks.types.classify_record)
19515 return DW_TAG_structure_type;
19517 switch (lang_hooks.types.classify_record (type))
19519 case RECORD_IS_STRUCT:
19520 return DW_TAG_structure_type;
19522 case RECORD_IS_CLASS:
19523 return DW_TAG_class_type;
19525 case RECORD_IS_INTERFACE:
19526 if (dwarf_version >= 3 || !dwarf_strict)
19527 return DW_TAG_interface_type;
19528 return DW_TAG_structure_type;
19531 gcc_unreachable ();
19535 /* Generate a DIE to represent an enumeration type. Note that these DIEs
19536 include all of the information about the enumeration values also. Each
19537 enumerated type name/value is listed as a child of the enumerated type
19541 gen_enumeration_type_die (tree type, dw_die_ref context_die)
19543 dw_die_ref type_die = lookup_type_die (type);
19545 if (type_die == NULL)
19547 type_die = new_die (DW_TAG_enumeration_type,
19548 scope_die_for (type, context_die), type);
19549 equate_type_number_to_die (type, type_die);
19550 add_name_attribute (type_die, type_tag (type));
19551 if (dwarf_version >= 4 || !dwarf_strict)
19553 if (ENUM_IS_SCOPED (type))
19554 add_AT_flag (type_die, DW_AT_enum_class, 1);
19555 if (ENUM_IS_OPAQUE (type))
19556 add_AT_flag (type_die, DW_AT_declaration, 1);
19559 else if (! TYPE_SIZE (type))
19562 remove_AT (type_die, DW_AT_declaration);
19564 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
19565 given enum type is incomplete, do not generate the DW_AT_byte_size
19566 attribute or the DW_AT_element_list attribute. */
19567 if (TYPE_SIZE (type))
19571 TREE_ASM_WRITTEN (type) = 1;
19572 add_byte_size_attribute (type_die, type);
19573 if (dwarf_version >= 3 || !dwarf_strict)
19575 tree underlying = lang_hooks.types.enum_underlying_base_type (type);
19576 add_type_attribute (type_die, underlying, TYPE_UNQUALIFIED, false,
19579 if (TYPE_STUB_DECL (type) != NULL_TREE)
19581 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
19582 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
19585 /* If the first reference to this type was as the return type of an
19586 inline function, then it may not have a parent. Fix this now. */
19587 if (type_die->die_parent == NULL)
19588 add_child_die (scope_die_for (type, context_die), type_die);
19590 for (link = TYPE_VALUES (type);
19591 link != NULL; link = TREE_CHAIN (link))
19593 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
19594 tree value = TREE_VALUE (link);
19596 add_name_attribute (enum_die,
19597 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
19599 if (TREE_CODE (value) == CONST_DECL)
19600 value = DECL_INITIAL (value);
19602 if (simple_type_size_in_bits (TREE_TYPE (value))
19603 <= HOST_BITS_PER_WIDE_INT || tree_fits_shwi_p (value))
19605 /* For constant forms created by add_AT_unsigned DWARF
19606 consumers (GDB, elfutils, etc.) always zero extend
19607 the value. Only when the actual value is negative
19608 do we need to use add_AT_int to generate a constant
19609 form that can represent negative values. */
19610 HOST_WIDE_INT val = TREE_INT_CST_LOW (value);
19611 if (TYPE_UNSIGNED (TREE_TYPE (value)) || val >= 0)
19612 add_AT_unsigned (enum_die, DW_AT_const_value,
19613 (unsigned HOST_WIDE_INT) val);
19615 add_AT_int (enum_die, DW_AT_const_value, val);
19618 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
19619 that here. TODO: This should be re-worked to use correct
19620 signed/unsigned double tags for all cases. */
19621 add_AT_wide (enum_die, DW_AT_const_value, value);
19624 add_gnat_descriptive_type_attribute (type_die, type, context_die);
19625 if (TYPE_ARTIFICIAL (type))
19626 add_AT_flag (type_die, DW_AT_artificial, 1);
19629 add_AT_flag (type_die, DW_AT_declaration, 1);
19631 add_pubtype (type, type_die);
19636 /* Generate a DIE to represent either a real live formal parameter decl or to
19637 represent just the type of some formal parameter position in some function
19640 Note that this routine is a bit unusual because its argument may be a
19641 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
19642 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
19643 node. If it's the former then this function is being called to output a
19644 DIE to represent a formal parameter object (or some inlining thereof). If
19645 it's the latter, then this function is only being called to output a
19646 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
19647 argument type of some subprogram type.
19648 If EMIT_NAME_P is true, name and source coordinate attributes
19652 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
19653 dw_die_ref context_die)
19655 tree node_or_origin = node ? node : origin;
19656 tree ultimate_origin;
19657 dw_die_ref parm_die = NULL;
19659 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin)) == tcc_declaration)
19661 parm_die = lookup_decl_die (node);
19663 /* If the contexts differ, we may not be talking about the same
19665 if (parm_die && parm_die->die_parent != context_die)
19667 if (!DECL_ABSTRACT_P (node))
19669 /* This can happen when creating an inlined instance, in
19670 which case we need to create a new DIE that will get
19671 annotated with DW_AT_abstract_origin. */
19676 /* FIXME: Reuse DIE even with a differing context.
19678 This can happen when calling
19679 dwarf2out_abstract_function to build debug info for
19680 the abstract instance of a function for which we have
19681 already generated a DIE in
19682 dwarf2out_early_global_decl.
19684 Once we remove dwarf2out_abstract_function, we should
19685 have a call to gcc_unreachable here. */
19689 if (parm_die && parm_die->die_parent == NULL)
19691 /* Check that parm_die already has the right attributes that
19692 we would have added below. If any attributes are
19693 missing, fall through to add them. */
19694 if (! DECL_ABSTRACT_P (node_or_origin)
19695 && !get_AT (parm_die, DW_AT_location)
19696 && !get_AT (parm_die, DW_AT_const_value))
19697 /* We are missing location info, and are about to add it. */
19701 add_child_die (context_die, parm_die);
19707 /* If we have a previously generated DIE, use it, unless this is an
19708 concrete instance (origin != NULL), in which case we need a new
19709 DIE with a corresponding DW_AT_abstract_origin. */
19711 if (parm_die && origin == NULL)
19712 reusing_die = true;
19715 parm_die = new_die (DW_TAG_formal_parameter, context_die, node);
19716 reusing_die = false;
19719 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
19721 case tcc_declaration:
19722 ultimate_origin = decl_ultimate_origin (node_or_origin);
19723 if (node || ultimate_origin)
19724 origin = ultimate_origin;
19729 if (origin != NULL)
19730 add_abstract_origin_attribute (parm_die, origin);
19731 else if (emit_name_p)
19732 add_name_and_src_coords_attributes (parm_die, node);
19734 || (! DECL_ABSTRACT_P (node_or_origin)
19735 && variably_modified_type_p (TREE_TYPE (node_or_origin),
19736 decl_function_context
19737 (node_or_origin))))
19739 tree type = TREE_TYPE (node_or_origin);
19740 if (decl_by_reference_p (node_or_origin))
19741 add_type_attribute (parm_die, TREE_TYPE (type),
19743 false, context_die);
19745 add_type_attribute (parm_die, type,
19746 decl_quals (node_or_origin),
19747 false, context_die);
19749 if (origin == NULL && DECL_ARTIFICIAL (node))
19750 add_AT_flag (parm_die, DW_AT_artificial, 1);
19752 if (node && node != origin)
19753 equate_decl_number_to_die (node, parm_die);
19754 if (! DECL_ABSTRACT_P (node_or_origin))
19755 add_location_or_const_value_attribute (parm_die, node_or_origin,
19761 /* We were called with some kind of a ..._TYPE node. */
19762 add_type_attribute (parm_die, node_or_origin, TYPE_UNQUALIFIED, false,
19767 gcc_unreachable ();
19773 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
19774 children DW_TAG_formal_parameter DIEs representing the arguments of the
19777 PARM_PACK must be a function parameter pack.
19778 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
19779 must point to the subsequent arguments of the function PACK_ARG belongs to.
19780 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
19781 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
19782 following the last one for which a DIE was generated. */
19785 gen_formal_parameter_pack_die (tree parm_pack,
19787 dw_die_ref subr_die,
19791 dw_die_ref parm_pack_die;
19793 gcc_assert (parm_pack
19794 && lang_hooks.function_parameter_pack_p (parm_pack)
19797 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
19798 add_src_coords_attributes (parm_pack_die, parm_pack);
19800 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
19802 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
19805 gen_formal_parameter_die (arg, NULL,
19806 false /* Don't emit name attribute. */,
19811 return parm_pack_die;
19814 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
19815 at the end of an (ANSI prototyped) formal parameters list. */
19818 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
19820 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
19823 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
19824 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
19825 parameters as specified in some function type specification (except for
19826 those which appear as part of a function *definition*). */
19829 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
19832 tree formal_type = NULL;
19833 tree first_parm_type;
19836 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
19838 arg = DECL_ARGUMENTS (function_or_method_type);
19839 function_or_method_type = TREE_TYPE (function_or_method_type);
19844 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
19846 /* Make our first pass over the list of formal parameter types and output a
19847 DW_TAG_formal_parameter DIE for each one. */
19848 for (link = first_parm_type; link; )
19850 dw_die_ref parm_die;
19852 formal_type = TREE_VALUE (link);
19853 if (formal_type == void_type_node)
19856 /* Output a (nameless) DIE to represent the formal parameter itself. */
19857 if (!POINTER_BOUNDS_TYPE_P (formal_type))
19859 parm_die = gen_formal_parameter_die (formal_type, NULL,
19860 true /* Emit name attribute. */,
19862 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
19863 && link == first_parm_type)
19865 add_AT_flag (parm_die, DW_AT_artificial, 1);
19866 if (dwarf_version >= 3 || !dwarf_strict)
19867 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
19869 else if (arg && DECL_ARTIFICIAL (arg))
19870 add_AT_flag (parm_die, DW_AT_artificial, 1);
19873 link = TREE_CHAIN (link);
19875 arg = DECL_CHAIN (arg);
19878 /* If this function type has an ellipsis, add a
19879 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
19880 if (formal_type != void_type_node)
19881 gen_unspecified_parameters_die (function_or_method_type, context_die);
19883 /* Make our second (and final) pass over the list of formal parameter types
19884 and output DIEs to represent those types (as necessary). */
19885 for (link = TYPE_ARG_TYPES (function_or_method_type);
19886 link && TREE_VALUE (link);
19887 link = TREE_CHAIN (link))
19888 gen_type_die (TREE_VALUE (link), context_die);
19891 /* We want to generate the DIE for TYPE so that we can generate the
19892 die for MEMBER, which has been defined; we will need to refer back
19893 to the member declaration nested within TYPE. If we're trying to
19894 generate minimal debug info for TYPE, processing TYPE won't do the
19895 trick; we need to attach the member declaration by hand. */
19898 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
19900 gen_type_die (type, context_die);
19902 /* If we're trying to avoid duplicate debug info, we may not have
19903 emitted the member decl for this function. Emit it now. */
19904 if (TYPE_STUB_DECL (type)
19905 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
19906 && ! lookup_decl_die (member))
19908 dw_die_ref type_die;
19909 gcc_assert (!decl_ultimate_origin (member));
19911 push_decl_scope (type);
19912 type_die = lookup_type_die_strip_naming_typedef (type);
19913 if (TREE_CODE (member) == FUNCTION_DECL)
19914 gen_subprogram_die (member, type_die);
19915 else if (TREE_CODE (member) == FIELD_DECL)
19917 /* Ignore the nameless fields that are used to skip bits but handle
19918 C++ anonymous unions and structs. */
19919 if (DECL_NAME (member) != NULL_TREE
19920 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
19921 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
19923 struct vlr_context vlr_ctx = {
19924 DECL_CONTEXT (member), /* struct_type */
19925 NULL_TREE /* variant_part_offset */
19927 gen_type_die (member_declared_type (member), type_die);
19928 gen_field_die (member, &vlr_ctx, type_die);
19932 gen_variable_die (member, NULL_TREE, type_die);
19938 /* Forward declare these functions, because they are mutually recursive
19939 with their set_block_* pairing functions. */
19940 static void set_decl_origin_self (tree);
19941 static void set_decl_abstract_flags (tree, vec<tree> &);
19943 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
19944 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
19945 that it points to the node itself, thus indicating that the node is its
19946 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
19947 the given node is NULL, recursively descend the decl/block tree which
19948 it is the root of, and for each other ..._DECL or BLOCK node contained
19949 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
19950 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
19951 values to point to themselves. */
19954 set_block_origin_self (tree stmt)
19956 if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
19958 BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
19963 for (local_decl = BLOCK_VARS (stmt);
19964 local_decl != NULL_TREE;
19965 local_decl = DECL_CHAIN (local_decl))
19966 /* Do not recurse on nested functions since the inlining status
19967 of parent and child can be different as per the DWARF spec. */
19968 if (TREE_CODE (local_decl) != FUNCTION_DECL
19969 && !DECL_EXTERNAL (local_decl))
19970 set_decl_origin_self (local_decl);
19976 for (subblock = BLOCK_SUBBLOCKS (stmt);
19977 subblock != NULL_TREE;
19978 subblock = BLOCK_CHAIN (subblock))
19979 set_block_origin_self (subblock); /* Recurse. */
19984 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
19985 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
19986 node to so that it points to the node itself, thus indicating that the
19987 node represents its own (abstract) origin. Additionally, if the
19988 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
19989 the decl/block tree of which the given node is the root of, and for
19990 each other ..._DECL or BLOCK node contained therein whose
19991 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
19992 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
19993 point to themselves. */
19996 set_decl_origin_self (tree decl)
19998 if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
20000 DECL_ABSTRACT_ORIGIN (decl) = decl;
20001 if (TREE_CODE (decl) == FUNCTION_DECL)
20005 for (arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
20006 DECL_ABSTRACT_ORIGIN (arg) = arg;
20007 if (DECL_INITIAL (decl) != NULL_TREE
20008 && DECL_INITIAL (decl) != error_mark_node)
20009 set_block_origin_self (DECL_INITIAL (decl));
20014 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
20015 and if it wasn't 1 before, push it to abstract_vec vector.
20016 For all local decls and all local sub-blocks (recursively) do it
20020 set_block_abstract_flags (tree stmt, vec<tree> &abstract_vec)
20026 if (!BLOCK_ABSTRACT (stmt))
20028 abstract_vec.safe_push (stmt);
20029 BLOCK_ABSTRACT (stmt) = 1;
20032 for (local_decl = BLOCK_VARS (stmt);
20033 local_decl != NULL_TREE;
20034 local_decl = DECL_CHAIN (local_decl))
20035 if (! DECL_EXTERNAL (local_decl))
20036 set_decl_abstract_flags (local_decl, abstract_vec);
20038 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
20040 local_decl = BLOCK_NONLOCALIZED_VAR (stmt, i);
20041 if ((TREE_CODE (local_decl) == VAR_DECL && !TREE_STATIC (local_decl))
20042 || TREE_CODE (local_decl) == PARM_DECL)
20043 set_decl_abstract_flags (local_decl, abstract_vec);
20046 for (subblock = BLOCK_SUBBLOCKS (stmt);
20047 subblock != NULL_TREE;
20048 subblock = BLOCK_CHAIN (subblock))
20049 set_block_abstract_flags (subblock, abstract_vec);
20052 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
20053 to 1 and if it wasn't 1 before, push to abstract_vec vector.
20054 In the case where the decl is a FUNCTION_DECL also set the abstract
20055 flags for all of the parameters, local vars, local
20056 blocks and sub-blocks (recursively). */
20059 set_decl_abstract_flags (tree decl, vec<tree> &abstract_vec)
20061 if (!DECL_ABSTRACT_P (decl))
20063 abstract_vec.safe_push (decl);
20064 DECL_ABSTRACT_P (decl) = 1;
20067 if (TREE_CODE (decl) == FUNCTION_DECL)
20071 for (arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
20072 if (!DECL_ABSTRACT_P (arg))
20074 abstract_vec.safe_push (arg);
20075 DECL_ABSTRACT_P (arg) = 1;
20077 if (DECL_INITIAL (decl) != NULL_TREE
20078 && DECL_INITIAL (decl) != error_mark_node)
20079 set_block_abstract_flags (DECL_INITIAL (decl), abstract_vec);
20083 /* Generate the DWARF2 info for the "abstract" instance of a function which we
20084 may later generate inlined and/or out-of-line instances of.
20086 FIXME: In the early-dwarf world, this function, and most of the
20087 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
20088 the abstract instance. All we would need to do is annotate
20089 the early DIE with the appropriate DW_AT_inline in late
20090 dwarf (perhaps in gen_inlined_subroutine_die).
20092 However, we can't do this yet, because LTO streaming of DIEs
20093 has not been implemented yet. */
20096 dwarf2out_abstract_function (tree decl)
20098 dw_die_ref old_die;
20101 hash_table<decl_loc_hasher> *old_decl_loc_table;
20102 hash_table<dw_loc_list_hasher> *old_cached_dw_loc_list_table;
20103 int old_call_site_count, old_tail_call_site_count;
20104 struct call_arg_loc_node *old_call_arg_locations;
20106 /* Make sure we have the actual abstract inline, not a clone. */
20107 decl = DECL_ORIGIN (decl);
20109 old_die = lookup_decl_die (decl);
20110 if (old_die && get_AT (old_die, DW_AT_inline))
20111 /* We've already generated the abstract instance. */
20114 /* We can be called while recursively when seeing block defining inlined subroutine
20115 DIE. Be sure to not clobber the outer location table nor use it or we would
20116 get locations in abstract instantces. */
20117 old_decl_loc_table = decl_loc_table;
20118 decl_loc_table = NULL;
20119 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
20120 cached_dw_loc_list_table = NULL;
20121 old_call_arg_locations = call_arg_locations;
20122 call_arg_locations = NULL;
20123 old_call_site_count = call_site_count;
20124 call_site_count = -1;
20125 old_tail_call_site_count = tail_call_site_count;
20126 tail_call_site_count = -1;
20128 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
20129 we don't get confused by DECL_ABSTRACT_P. */
20130 if (debug_info_level > DINFO_LEVEL_TERSE)
20132 context = decl_class_context (decl);
20134 gen_type_die_for_member
20135 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
20138 /* Pretend we've just finished compiling this function. */
20139 save_fn = current_function_decl;
20140 current_function_decl = decl;
20142 auto_vec<tree, 64> abstract_vec;
20143 set_decl_abstract_flags (decl, abstract_vec);
20144 dwarf2out_decl (decl);
20147 FOR_EACH_VEC_ELT (abstract_vec, i, t)
20148 if (TREE_CODE (t) == BLOCK)
20149 BLOCK_ABSTRACT (t) = 0;
20151 DECL_ABSTRACT_P (t) = 0;
20153 current_function_decl = save_fn;
20154 decl_loc_table = old_decl_loc_table;
20155 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
20156 call_arg_locations = old_call_arg_locations;
20157 call_site_count = old_call_site_count;
20158 tail_call_site_count = old_tail_call_site_count;
20161 /* Helper function of premark_used_types() which gets called through
20164 Marks the DIE of a given type in *SLOT as perennial, so it never gets
20165 marked as unused by prune_unused_types. */
20168 premark_used_types_helper (tree const &type, void *)
20172 die = lookup_type_die (type);
20174 die->die_perennial_p = 1;
20178 /* Helper function of premark_types_used_by_global_vars which gets called
20179 through htab_traverse.
20181 Marks the DIE of a given type in *SLOT as perennial, so it never gets
20182 marked as unused by prune_unused_types. The DIE of the type is marked
20183 only if the global variable using the type will actually be emitted. */
20186 premark_types_used_by_global_vars_helper (types_used_by_vars_entry **slot,
20189 struct types_used_by_vars_entry *entry;
20192 entry = (struct types_used_by_vars_entry *) *slot;
20193 gcc_assert (entry->type != NULL
20194 && entry->var_decl != NULL);
20195 die = lookup_type_die (entry->type);
20198 /* Ask cgraph if the global variable really is to be emitted.
20199 If yes, then we'll keep the DIE of ENTRY->TYPE. */
20200 varpool_node *node = varpool_node::get (entry->var_decl);
20201 if (node && node->definition)
20203 die->die_perennial_p = 1;
20204 /* Keep the parent DIEs as well. */
20205 while ((die = die->die_parent) && die->die_perennial_p == 0)
20206 die->die_perennial_p = 1;
20212 /* Mark all members of used_types_hash as perennial. */
20215 premark_used_types (struct function *fun)
20217 if (fun && fun->used_types_hash)
20218 fun->used_types_hash->traverse<void *, premark_used_types_helper> (NULL);
20221 /* Mark all members of types_used_by_vars_entry as perennial. */
20224 premark_types_used_by_global_vars (void)
20226 if (types_used_by_vars_hash)
20227 types_used_by_vars_hash
20228 ->traverse<void *, premark_types_used_by_global_vars_helper> (NULL);
20231 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
20232 for CA_LOC call arg loc node. */
20235 gen_call_site_die (tree decl, dw_die_ref subr_die,
20236 struct call_arg_loc_node *ca_loc)
20238 dw_die_ref stmt_die = NULL, die;
20239 tree block = ca_loc->block;
20242 && block != DECL_INITIAL (decl)
20243 && TREE_CODE (block) == BLOCK)
20245 stmt_die = BLOCK_DIE (block);
20248 block = BLOCK_SUPERCONTEXT (block);
20250 if (stmt_die == NULL)
20251 stmt_die = subr_die;
20252 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
20253 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
20254 if (ca_loc->tail_call_p)
20255 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
20256 if (ca_loc->symbol_ref)
20258 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
20260 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
20262 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref, false);
20267 /* Generate a DIE to represent a declared function (either file-scope or
20271 gen_subprogram_die (tree decl, dw_die_ref context_die)
20273 tree origin = decl_ultimate_origin (decl);
20274 dw_die_ref subr_die;
20275 dw_die_ref old_die = lookup_decl_die (decl);
20277 /* This function gets called multiple times for different stages of
20278 the debug process. For example, for func() in this code:
20282 void func() { ... }
20285 ...we get called 4 times. Twice in early debug and twice in
20291 1. Once while generating func() within the namespace. This is
20292 the declaration. The declaration bit below is set, as the
20293 context is the namespace.
20295 A new DIE will be generated with DW_AT_declaration set.
20297 2. Once for func() itself. This is the specification. The
20298 declaration bit below is clear as the context is the CU.
20300 We will use the cached DIE from (1) to create a new DIE with
20301 DW_AT_specification pointing to the declaration in (1).
20303 Late debug via rest_of_handle_final()
20304 -------------------------------------
20306 3. Once generating func() within the namespace. This is also the
20307 declaration, as in (1), but this time we will early exit below
20308 as we have a cached DIE and a declaration needs no additional
20309 annotations (no locations), as the source declaration line
20312 4. Once for func() itself. As in (2), this is the specification,
20313 but this time we will re-use the cached DIE, and just annotate
20314 it with the location information that should now be available.
20316 For something without namespaces, but with abstract instances, we
20317 are also called a multiple times:
20322 Base (); // constructor declaration (1)
20325 Base::Base () { } // constructor specification (2)
20330 1. Once for the Base() constructor by virtue of it being a
20331 member of the Base class. This is done via
20332 rest_of_type_compilation.
20334 This is a declaration, so a new DIE will be created with
20337 2. Once for the Base() constructor definition, but this time
20338 while generating the abstract instance of the base
20339 constructor (__base_ctor) which is being generated via early
20340 debug of reachable functions.
20342 Even though we have a cached version of the declaration (1),
20343 we will create a DW_AT_specification of the declaration DIE
20346 3. Once for the __base_ctor itself, but this time, we generate
20347 an DW_AT_abstract_origin version of the DW_AT_specification in
20350 Late debug via rest_of_handle_final
20351 -----------------------------------
20353 4. One final time for the __base_ctor (which will have a cached
20354 DIE with DW_AT_abstract_origin created in (3). This time,
20355 we will just annotate the location information now
20358 int declaration = (current_function_decl != decl
20359 || class_or_namespace_scope_p (context_die));
20361 premark_used_types (DECL_STRUCT_FUNCTION (decl));
20363 /* Now that the C++ front end lazily declares artificial member fns, we
20364 might need to retrofit the declaration into its class. */
20365 if (!declaration && !origin && !old_die
20366 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
20367 && !class_or_namespace_scope_p (context_die)
20368 && debug_info_level > DINFO_LEVEL_TERSE)
20369 old_die = force_decl_die (decl);
20371 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
20372 if (origin != NULL)
20374 gcc_assert (!declaration || local_scope_p (context_die));
20376 /* Fixup die_parent for the abstract instance of a nested
20377 inline function. */
20378 if (old_die && old_die->die_parent == NULL)
20379 add_child_die (context_die, old_die);
20381 if (old_die && get_AT_ref (old_die, DW_AT_abstract_origin))
20383 /* If we have a DW_AT_abstract_origin we have a working
20385 subr_die = old_die;
20389 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
20390 add_abstract_origin_attribute (subr_die, origin);
20391 /* This is where the actual code for a cloned function is.
20392 Let's emit linkage name attribute for it. This helps
20393 debuggers to e.g, set breakpoints into
20394 constructors/destructors when the user asks "break
20396 add_linkage_name (subr_die, decl);
20399 /* A cached copy, possibly from early dwarf generation. Reuse as
20400 much as possible. */
20403 /* A declaration that has been previously dumped needs no
20404 additional information. */
20408 if (!get_AT_flag (old_die, DW_AT_declaration)
20409 /* We can have a normal definition following an inline one in the
20410 case of redefinition of GNU C extern inlines.
20411 It seems reasonable to use AT_specification in this case. */
20412 && !get_AT (old_die, DW_AT_inline))
20414 /* Detect and ignore this case, where we are trying to output
20415 something we have already output. */
20416 if (get_AT (old_die, DW_AT_low_pc)
20417 || get_AT (old_die, DW_AT_ranges))
20420 /* If we have no location information, this must be a
20421 partially generated DIE from early dwarf generation.
20422 Fall through and generate it. */
20425 /* If the definition comes from the same place as the declaration,
20426 maybe use the old DIE. We always want the DIE for this function
20427 that has the *_pc attributes to be under comp_unit_die so the
20428 debugger can find it. We also need to do this for abstract
20429 instances of inlines, since the spec requires the out-of-line copy
20430 to have the same parent. For local class methods, this doesn't
20431 apply; we just use the old DIE. */
20432 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
20433 struct dwarf_file_data * file_index = lookup_filename (s.file);
20434 if ((is_cu_die (old_die->die_parent)
20435 /* This condition fixes the inconsistency/ICE with the
20436 following Fortran test (or some derivative thereof) while
20437 building libgfortran:
20441 logical function funky (FLAG)
20446 || (old_die->die_parent
20447 && old_die->die_parent->die_tag == DW_TAG_module)
20448 || context_die == NULL)
20449 && (DECL_ARTIFICIAL (decl)
20450 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
20451 && (get_AT_unsigned (old_die, DW_AT_decl_line)
20452 == (unsigned) s.line))))
20454 subr_die = old_die;
20456 /* Clear out the declaration attribute, but leave the
20457 parameters so they can be augmented with location
20458 information later. Unless this was a declaration, in
20459 which case, wipe out the nameless parameters and recreate
20460 them further down. */
20461 if (remove_AT (subr_die, DW_AT_declaration))
20464 remove_AT (subr_die, DW_AT_object_pointer);
20465 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
20468 /* Make a specification pointing to the previously built
20472 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
20473 add_AT_specification (subr_die, old_die);
20474 add_pubname (decl, subr_die);
20475 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
20476 add_AT_file (subr_die, DW_AT_decl_file, file_index);
20477 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
20478 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
20480 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
20481 emit the real type on the definition die. */
20482 if (is_cxx() && debug_info_level > DINFO_LEVEL_TERSE)
20484 dw_die_ref die = get_AT_ref (old_die, DW_AT_type);
20485 if (die == auto_die || die == decltype_auto_die)
20486 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
20487 TYPE_UNQUALIFIED, false, context_die);
20491 /* Create a fresh DIE for anything else. */
20494 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
20496 if (TREE_PUBLIC (decl))
20497 add_AT_flag (subr_die, DW_AT_external, 1);
20499 add_name_and_src_coords_attributes (subr_die, decl);
20500 add_pubname (decl, subr_die);
20501 if (debug_info_level > DINFO_LEVEL_TERSE)
20503 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
20504 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
20505 TYPE_UNQUALIFIED, false, context_die);
20508 add_pure_or_virtual_attribute (subr_die, decl);
20509 if (DECL_ARTIFICIAL (decl))
20510 add_AT_flag (subr_die, DW_AT_artificial, 1);
20512 if (TREE_THIS_VOLATILE (decl) && (dwarf_version >= 5 || !dwarf_strict))
20513 add_AT_flag (subr_die, DW_AT_noreturn, 1);
20515 add_accessibility_attribute (subr_die, decl);
20518 /* Unless we have an existing non-declaration DIE, equate the new
20520 if (!old_die || is_declaration_die (old_die))
20521 equate_decl_number_to_die (decl, subr_die);
20525 if (!old_die || !get_AT (old_die, DW_AT_inline))
20527 add_AT_flag (subr_die, DW_AT_declaration, 1);
20529 /* If this is an explicit function declaration then generate
20530 a DW_AT_explicit attribute. */
20531 if (lang_hooks.decls.function_decl_explicit_p (decl)
20532 && (dwarf_version >= 3 || !dwarf_strict))
20533 add_AT_flag (subr_die, DW_AT_explicit, 1);
20535 /* If this is a C++11 deleted special function member then generate
20536 a DW_AT_GNU_deleted attribute. */
20537 if (lang_hooks.decls.function_decl_deleted_p (decl)
20538 && (! dwarf_strict))
20539 add_AT_flag (subr_die, DW_AT_GNU_deleted, 1);
20542 /* Tag abstract instances with DW_AT_inline. */
20543 else if (DECL_ABSTRACT_P (decl))
20545 if (DECL_DECLARED_INLINE_P (decl))
20547 if (cgraph_function_possibly_inlined_p (decl))
20548 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
20550 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
20554 if (cgraph_function_possibly_inlined_p (decl))
20555 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
20557 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
20560 if (DECL_DECLARED_INLINE_P (decl)
20561 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
20562 add_AT_flag (subr_die, DW_AT_artificial, 1);
20564 /* For non DECL_EXTERNALs, if range information is available, fill
20565 the DIE with it. */
20566 else if (!DECL_EXTERNAL (decl) && !early_dwarf)
20568 HOST_WIDE_INT cfa_fb_offset;
20570 struct function *fun = DECL_STRUCT_FUNCTION (decl);
20572 if (!flag_reorder_blocks_and_partition)
20574 dw_fde_ref fde = fun->fde;
20575 if (fde->dw_fde_begin)
20577 /* We have already generated the labels. */
20578 add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
20579 fde->dw_fde_end, false);
20583 /* Create start/end labels and add the range. */
20584 char label_id_low[MAX_ARTIFICIAL_LABEL_BYTES];
20585 char label_id_high[MAX_ARTIFICIAL_LABEL_BYTES];
20586 ASM_GENERATE_INTERNAL_LABEL (label_id_low, FUNC_BEGIN_LABEL,
20587 current_function_funcdef_no);
20588 ASM_GENERATE_INTERNAL_LABEL (label_id_high, FUNC_END_LABEL,
20589 current_function_funcdef_no);
20590 add_AT_low_high_pc (subr_die, label_id_low, label_id_high,
20594 #if VMS_DEBUGGING_INFO
20595 /* HP OpenVMS Industry Standard 64: DWARF Extensions
20596 Section 2.3 Prologue and Epilogue Attributes:
20597 When a breakpoint is set on entry to a function, it is generally
20598 desirable for execution to be suspended, not on the very first
20599 instruction of the function, but rather at a point after the
20600 function's frame has been set up, after any language defined local
20601 declaration processing has been completed, and before execution of
20602 the first statement of the function begins. Debuggers generally
20603 cannot properly determine where this point is. Similarly for a
20604 breakpoint set on exit from a function. The prologue and epilogue
20605 attributes allow a compiler to communicate the location(s) to use. */
20608 if (fde->dw_fde_vms_end_prologue)
20609 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
20610 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
20612 if (fde->dw_fde_vms_begin_epilogue)
20613 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
20614 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
20621 /* Generate pubnames entries for the split function code ranges. */
20622 dw_fde_ref fde = fun->fde;
20624 if (fde->dw_fde_second_begin)
20626 if (dwarf_version >= 3 || !dwarf_strict)
20628 /* We should use ranges for non-contiguous code section
20629 addresses. Use the actual code range for the initial
20630 section, since the HOT/COLD labels might precede an
20631 alignment offset. */
20632 bool range_list_added = false;
20633 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
20634 fde->dw_fde_end, &range_list_added,
20636 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
20637 fde->dw_fde_second_end,
20638 &range_list_added, false);
20639 if (range_list_added)
20644 /* There is no real support in DW2 for this .. so we make
20645 a work-around. First, emit the pub name for the segment
20646 containing the function label. Then make and emit a
20647 simplified subprogram DIE for the second segment with the
20648 name pre-fixed by __hot/cold_sect_of_. We use the same
20649 linkage name for the second die so that gdb will find both
20650 sections when given "b foo". */
20651 const char *name = NULL;
20652 tree decl_name = DECL_NAME (decl);
20653 dw_die_ref seg_die;
20655 /* Do the 'primary' section. */
20656 add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
20657 fde->dw_fde_end, false);
20659 /* Build a minimal DIE for the secondary section. */
20660 seg_die = new_die (DW_TAG_subprogram,
20661 subr_die->die_parent, decl);
20663 if (TREE_PUBLIC (decl))
20664 add_AT_flag (seg_die, DW_AT_external, 1);
20666 if (decl_name != NULL
20667 && IDENTIFIER_POINTER (decl_name) != NULL)
20669 name = dwarf2_name (decl, 1);
20670 if (! DECL_ARTIFICIAL (decl))
20671 add_src_coords_attributes (seg_die, decl);
20673 add_linkage_name (seg_die, decl);
20675 gcc_assert (name != NULL);
20676 add_pure_or_virtual_attribute (seg_die, decl);
20677 if (DECL_ARTIFICIAL (decl))
20678 add_AT_flag (seg_die, DW_AT_artificial, 1);
20680 name = concat ("__second_sect_of_", name, NULL);
20681 add_AT_low_high_pc (seg_die, fde->dw_fde_second_begin,
20682 fde->dw_fde_second_end, false);
20683 add_name_attribute (seg_die, name);
20684 if (want_pubnames ())
20685 add_pubname_string (name, seg_die);
20689 add_AT_low_high_pc (subr_die, fde->dw_fde_begin, fde->dw_fde_end,
20693 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
20695 /* We define the "frame base" as the function's CFA. This is more
20696 convenient for several reasons: (1) It's stable across the prologue
20697 and epilogue, which makes it better than just a frame pointer,
20698 (2) With dwarf3, there exists a one-byte encoding that allows us
20699 to reference the .debug_frame data by proxy, but failing that,
20700 (3) We can at least reuse the code inspection and interpretation
20701 code that determines the CFA position at various points in the
20703 if (dwarf_version >= 3 && targetm.debug_unwind_info () == UI_DWARF2)
20705 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
20706 add_AT_loc (subr_die, DW_AT_frame_base, op);
20710 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
20711 if (list->dw_loc_next)
20712 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
20714 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
20717 /* Compute a displacement from the "steady-state frame pointer" to
20718 the CFA. The former is what all stack slots and argument slots
20719 will reference in the rtl; the latter is what we've told the
20720 debugger about. We'll need to adjust all frame_base references
20721 by this displacement. */
20722 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
20724 if (fun->static_chain_decl)
20726 /* DWARF requires here a location expression that computes the
20727 address of the enclosing subprogram's frame base. The machinery
20728 in tree-nested.c is supposed to store this specific address in the
20729 last field of the FRAME record. */
20730 const tree frame_type
20731 = TREE_TYPE (TREE_TYPE (fun->static_chain_decl));
20732 const tree fb_decl = tree_last (TYPE_FIELDS (frame_type));
20735 = build1 (INDIRECT_REF, frame_type, fun->static_chain_decl);
20736 fb_expr = build3 (COMPONENT_REF, TREE_TYPE (fb_decl),
20737 fb_expr, fb_decl, NULL_TREE);
20739 add_AT_location_description (subr_die, DW_AT_static_link,
20740 loc_list_from_tree (fb_expr, 0, NULL));
20744 /* Generate child dies for template paramaters. */
20745 if (early_dwarf && debug_info_level > DINFO_LEVEL_TERSE)
20746 gen_generic_params_dies (decl);
20748 /* Now output descriptions of the arguments for this function. This gets
20749 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
20750 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
20751 `...' at the end of the formal parameter list. In order to find out if
20752 there was a trailing ellipsis or not, we must instead look at the type
20753 associated with the FUNCTION_DECL. This will be a node of type
20754 FUNCTION_TYPE. If the chain of type nodes hanging off of this
20755 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
20756 an ellipsis at the end. */
20758 /* In the case where we are describing a mere function declaration, all we
20759 need to do here (and all we *can* do here) is to describe the *types* of
20760 its formal parameters. */
20761 if (debug_info_level <= DINFO_LEVEL_TERSE)
20763 else if (declaration)
20764 gen_formal_types_die (decl, subr_die);
20767 /* Generate DIEs to represent all known formal parameters. */
20768 tree parm = DECL_ARGUMENTS (decl);
20769 tree generic_decl = early_dwarf
20770 ? lang_hooks.decls.get_generic_function_decl (decl) : NULL;
20771 tree generic_decl_parm = generic_decl
20772 ? DECL_ARGUMENTS (generic_decl)
20774 auto_vec<dw_die_ref> string_types_vec;
20775 if (string_types == NULL)
20776 string_types = &string_types_vec;
20778 /* Now we want to walk the list of parameters of the function and
20779 emit their relevant DIEs.
20781 We consider the case of DECL being an instance of a generic function
20782 as well as it being a normal function.
20784 If DECL is an instance of a generic function we walk the
20785 parameters of the generic function declaration _and_ the parameters of
20786 DECL itself. This is useful because we want to emit specific DIEs for
20787 function parameter packs and those are declared as part of the
20788 generic function declaration. In that particular case,
20789 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
20790 That DIE has children DIEs representing the set of arguments
20791 of the pack. Note that the set of pack arguments can be empty.
20792 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
20795 Otherwise, we just consider the parameters of DECL. */
20796 while (generic_decl_parm || parm)
20798 if (generic_decl_parm
20799 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
20800 gen_formal_parameter_pack_die (generic_decl_parm,
20803 else if (parm && !POINTER_BOUNDS_P (parm))
20805 dw_die_ref parm_die = gen_decl_die (parm, NULL, NULL, subr_die);
20807 if (parm == DECL_ARGUMENTS (decl)
20808 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
20810 && (dwarf_version >= 3 || !dwarf_strict))
20811 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
20813 parm = DECL_CHAIN (parm);
20816 parm = DECL_CHAIN (parm);
20818 if (generic_decl_parm)
20819 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
20822 /* Decide whether we need an unspecified_parameters DIE at the end.
20823 There are 2 more cases to do this for: 1) the ansi ... declaration -
20824 this is detectable when the end of the arg list is not a
20825 void_type_node 2) an unprototyped function declaration (not a
20826 definition). This just means that we have no info about the
20827 parameters at all. */
20830 if (prototype_p (TREE_TYPE (decl)))
20832 /* This is the prototyped case, check for.... */
20833 if (stdarg_p (TREE_TYPE (decl)))
20834 gen_unspecified_parameters_die (decl, subr_die);
20836 else if (DECL_INITIAL (decl) == NULL_TREE)
20837 gen_unspecified_parameters_die (decl, subr_die);
20840 /* Adjust DW_TAG_string_type DIEs if needed, now that all arguments
20842 if (string_types == &string_types_vec)
20844 adjust_string_types ();
20845 string_types = NULL;
20849 if (subr_die != old_die)
20850 /* Add the calling convention attribute if requested. */
20851 add_calling_convention_attribute (subr_die, decl);
20853 /* Output Dwarf info for all of the stuff within the body of the function
20854 (if it has one - it may be just a declaration).
20856 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
20857 a function. This BLOCK actually represents the outermost binding contour
20858 for the function, i.e. the contour in which the function's formal
20859 parameters and labels get declared. Curiously, it appears that the front
20860 end doesn't actually put the PARM_DECL nodes for the current function onto
20861 the BLOCK_VARS list for this outer scope, but are strung off of the
20862 DECL_ARGUMENTS list for the function instead.
20864 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
20865 the LABEL_DECL nodes for the function however, and we output DWARF info
20866 for those in decls_for_scope. Just within the `outer_scope' there will be
20867 a BLOCK node representing the function's outermost pair of curly braces,
20868 and any blocks used for the base and member initializers of a C++
20869 constructor function. */
20870 tree outer_scope = DECL_INITIAL (decl);
20871 if (! declaration && outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
20873 int call_site_note_count = 0;
20874 int tail_call_site_note_count = 0;
20876 /* Emit a DW_TAG_variable DIE for a named return value. */
20877 if (DECL_NAME (DECL_RESULT (decl)))
20878 gen_decl_die (DECL_RESULT (decl), NULL, NULL, subr_die);
20880 /* The first time through decls_for_scope we will generate the
20881 DIEs for the locals. The second time, we fill in the
20883 decls_for_scope (outer_scope, subr_die);
20885 if (call_arg_locations && !dwarf_strict)
20887 struct call_arg_loc_node *ca_loc;
20888 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
20890 dw_die_ref die = NULL;
20891 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
20894 for (arg = (ca_loc->call_arg_loc_note != NULL_RTX
20895 ? NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note)
20897 arg; arg = next_arg)
20899 dw_loc_descr_ref reg, val;
20900 machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
20901 dw_die_ref cdie, tdie = NULL;
20903 next_arg = XEXP (arg, 1);
20904 if (REG_P (XEXP (XEXP (arg, 0), 0))
20906 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
20907 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
20908 && REGNO (XEXP (XEXP (arg, 0), 0))
20909 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
20910 next_arg = XEXP (next_arg, 1);
20911 if (mode == VOIDmode)
20913 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
20914 if (mode == VOIDmode)
20915 mode = GET_MODE (XEXP (arg, 0));
20917 if (mode == VOIDmode || mode == BLKmode)
20919 /* Get dynamic information about call target only if we
20920 have no static information: we cannot generate both
20921 DW_AT_abstract_origin and DW_AT_GNU_call_site_target
20923 if (ca_loc->symbol_ref == NULL_RTX)
20925 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
20927 tloc = XEXP (XEXP (arg, 0), 1);
20930 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
20931 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
20933 tlocc = XEXP (XEXP (arg, 0), 1);
20938 if (REG_P (XEXP (XEXP (arg, 0), 0)))
20939 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
20940 VAR_INIT_STATUS_INITIALIZED);
20941 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
20943 rtx mem = XEXP (XEXP (arg, 0), 0);
20944 reg = mem_loc_descriptor (XEXP (mem, 0),
20945 get_address_mode (mem),
20947 VAR_INIT_STATUS_INITIALIZED);
20949 else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
20950 == DEBUG_PARAMETER_REF)
20953 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
20954 tdie = lookup_decl_die (tdecl);
20961 && GET_CODE (XEXP (XEXP (arg, 0), 0))
20962 != DEBUG_PARAMETER_REF)
20964 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
20966 VAR_INIT_STATUS_INITIALIZED);
20970 die = gen_call_site_die (decl, subr_die, ca_loc);
20971 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
20974 add_AT_loc (cdie, DW_AT_location, reg);
20975 else if (tdie != NULL)
20976 add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
20977 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
20978 if (next_arg != XEXP (arg, 1))
20980 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
20981 if (mode == VOIDmode)
20982 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
20983 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
20986 VAR_INIT_STATUS_INITIALIZED);
20988 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
20992 && (ca_loc->symbol_ref || tloc))
20993 die = gen_call_site_die (decl, subr_die, ca_loc);
20994 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
20996 dw_loc_descr_ref tval = NULL;
20998 if (tloc != NULL_RTX)
20999 tval = mem_loc_descriptor (tloc,
21000 GET_MODE (tloc) == VOIDmode
21001 ? Pmode : GET_MODE (tloc),
21003 VAR_INIT_STATUS_INITIALIZED);
21005 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
21006 else if (tlocc != NULL_RTX)
21008 tval = mem_loc_descriptor (tlocc,
21009 GET_MODE (tlocc) == VOIDmode
21010 ? Pmode : GET_MODE (tlocc),
21012 VAR_INIT_STATUS_INITIALIZED);
21014 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
21020 call_site_note_count++;
21021 if (ca_loc->tail_call_p)
21022 tail_call_site_note_count++;
21026 call_arg_locations = NULL;
21027 call_arg_loc_last = NULL;
21028 if (tail_call_site_count >= 0
21029 && tail_call_site_count == tail_call_site_note_count
21032 if (call_site_count >= 0
21033 && call_site_count == call_site_note_count)
21034 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
21036 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
21038 call_site_count = -1;
21039 tail_call_site_count = -1;
21043 /* Returns a hash value for X (which really is a die_struct). */
21046 block_die_hasher::hash (die_struct *d)
21048 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
21051 /* Return nonzero if decl_id and die_parent of die_struct X is the same
21052 as decl_id and die_parent of die_struct Y. */
21055 block_die_hasher::equal (die_struct *x, die_struct *y)
21057 return x->decl_id == y->decl_id && x->die_parent == y->die_parent;
21060 /* Return TRUE if DECL, which may have been previously generated as
21061 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
21062 true if decl (or its origin) is either an extern declaration or a
21063 class/namespace scoped declaration.
21065 The declare_in_namespace support causes us to get two DIEs for one
21066 variable, both of which are declarations. We want to avoid
21067 considering one to be a specification, so we must test for
21068 DECLARATION and DW_AT_declaration. */
21070 decl_will_get_specification_p (dw_die_ref old_die, tree decl, bool declaration)
21072 return (old_die && TREE_STATIC (decl) && !declaration
21073 && get_AT_flag (old_die, DW_AT_declaration) == 1);
21076 /* Return true if DECL is a local static. */
21079 local_function_static (tree decl)
21081 gcc_assert (TREE_CODE (decl) == VAR_DECL);
21082 return TREE_STATIC (decl)
21083 && DECL_CONTEXT (decl)
21084 && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL;
21087 /* Generate a DIE to represent a declared data object.
21088 Either DECL or ORIGIN must be non-null. */
21091 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
21093 HOST_WIDE_INT off = 0;
21095 tree decl_or_origin = decl ? decl : origin;
21096 tree ultimate_origin;
21097 dw_die_ref var_die;
21098 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
21099 dw_die_ref origin_die = NULL;
21100 bool declaration = (DECL_EXTERNAL (decl_or_origin)
21101 || class_or_namespace_scope_p (context_die));
21102 bool specialization_p = false;
21104 ultimate_origin = decl_ultimate_origin (decl_or_origin);
21105 if (decl || ultimate_origin)
21106 origin = ultimate_origin;
21107 com_decl = fortran_common (decl_or_origin, &off);
21109 /* Symbol in common gets emitted as a child of the common block, in the form
21110 of a data member. */
21113 dw_die_ref com_die;
21114 dw_loc_list_ref loc;
21115 die_node com_die_arg;
21117 var_die = lookup_decl_die (decl_or_origin);
21120 if (get_AT (var_die, DW_AT_location) == NULL)
21122 loc = loc_list_from_tree (com_decl, off ? 1 : 2, NULL);
21127 /* Optimize the common case. */
21128 if (single_element_loc_list_p (loc)
21129 && loc->expr->dw_loc_opc == DW_OP_addr
21130 && loc->expr->dw_loc_next == NULL
21131 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
21134 rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
21135 loc->expr->dw_loc_oprnd1.v.val_addr
21136 = plus_constant (GET_MODE (x), x , off);
21139 loc_list_plus_const (loc, off);
21141 add_AT_location_description (var_die, DW_AT_location, loc);
21142 remove_AT (var_die, DW_AT_declaration);
21148 if (common_block_die_table == NULL)
21149 common_block_die_table = hash_table<block_die_hasher>::create_ggc (10);
21151 com_die_arg.decl_id = DECL_UID (com_decl);
21152 com_die_arg.die_parent = context_die;
21153 com_die = common_block_die_table->find (&com_die_arg);
21154 loc = loc_list_from_tree (com_decl, 2, NULL);
21155 if (com_die == NULL)
21158 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
21161 com_die = new_die (DW_TAG_common_block, context_die, decl);
21162 add_name_and_src_coords_attributes (com_die, com_decl);
21165 add_AT_location_description (com_die, DW_AT_location, loc);
21166 /* Avoid sharing the same loc descriptor between
21167 DW_TAG_common_block and DW_TAG_variable. */
21168 loc = loc_list_from_tree (com_decl, 2, NULL);
21170 else if (DECL_EXTERNAL (decl_or_origin))
21171 add_AT_flag (com_die, DW_AT_declaration, 1);
21172 if (want_pubnames ())
21173 add_pubname_string (cnam, com_die); /* ??? needed? */
21174 com_die->decl_id = DECL_UID (com_decl);
21175 slot = common_block_die_table->find_slot (com_die, INSERT);
21178 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
21180 add_AT_location_description (com_die, DW_AT_location, loc);
21181 loc = loc_list_from_tree (com_decl, 2, NULL);
21182 remove_AT (com_die, DW_AT_declaration);
21184 var_die = new_die (DW_TAG_variable, com_die, decl);
21185 add_name_and_src_coords_attributes (var_die, decl_or_origin);
21186 add_type_attribute (var_die, TREE_TYPE (decl_or_origin),
21187 decl_quals (decl_or_origin), false,
21189 add_AT_flag (var_die, DW_AT_external, 1);
21194 /* Optimize the common case. */
21195 if (single_element_loc_list_p (loc)
21196 && loc->expr->dw_loc_opc == DW_OP_addr
21197 && loc->expr->dw_loc_next == NULL
21198 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
21200 rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
21201 loc->expr->dw_loc_oprnd1.v.val_addr
21202 = plus_constant (GET_MODE (x), x, off);
21205 loc_list_plus_const (loc, off);
21207 add_AT_location_description (var_die, DW_AT_location, loc);
21209 else if (DECL_EXTERNAL (decl_or_origin))
21210 add_AT_flag (var_die, DW_AT_declaration, 1);
21212 equate_decl_number_to_die (decl, var_die);
21220 /* A declaration that has been previously dumped, needs no
21221 further annotations, since it doesn't need location on
21222 the second pass. */
21225 else if (decl_will_get_specification_p (old_die, decl, declaration)
21226 && !get_AT (old_die, DW_AT_specification))
21228 /* Fall-thru so we can make a new variable die along with a
21229 DW_AT_specification. */
21231 else if (origin && old_die->die_parent != context_die)
21233 /* If we will be creating an inlined instance, we need a
21234 new DIE that will get annotated with
21235 DW_AT_abstract_origin. Clear things so we can get a
21237 gcc_assert (!DECL_ABSTRACT_P (decl));
21242 /* If a DIE was dumped early, it still needs location info.
21243 Skip to where we fill the location bits. */
21245 goto gen_variable_die_location;
21249 /* For static data members, the declaration in the class is supposed
21250 to have DW_TAG_member tag; the specification should still be
21251 DW_TAG_variable referencing the DW_TAG_member DIE. */
21252 if (declaration && class_scope_p (context_die))
21253 var_die = new_die (DW_TAG_member, context_die, decl);
21255 var_die = new_die (DW_TAG_variable, context_die, decl);
21257 if (origin != NULL)
21258 origin_die = add_abstract_origin_attribute (var_die, origin);
21260 /* Loop unrolling can create multiple blocks that refer to the same
21261 static variable, so we must test for the DW_AT_declaration flag.
21263 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
21264 copy decls and set the DECL_ABSTRACT_P flag on them instead of
21267 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
21268 else if (decl_will_get_specification_p (old_die, decl, declaration))
21270 /* This is a definition of a C++ class level static. */
21271 add_AT_specification (var_die, old_die);
21272 specialization_p = true;
21273 if (DECL_NAME (decl))
21275 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
21276 struct dwarf_file_data * file_index = lookup_filename (s.file);
21278 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
21279 add_AT_file (var_die, DW_AT_decl_file, file_index);
21281 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
21282 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
21284 if (old_die->die_tag == DW_TAG_member)
21285 add_linkage_name (var_die, decl);
21289 add_name_and_src_coords_attributes (var_die, decl);
21291 if ((origin == NULL && !specialization_p)
21293 && !DECL_ABSTRACT_P (decl_or_origin)
21294 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
21295 decl_function_context
21296 (decl_or_origin))))
21298 tree type = TREE_TYPE (decl_or_origin);
21300 if (decl_by_reference_p (decl_or_origin))
21301 add_type_attribute (var_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
21304 add_type_attribute (var_die, type, decl_quals (decl_or_origin), false,
21308 if (origin == NULL && !specialization_p)
21310 if (TREE_PUBLIC (decl))
21311 add_AT_flag (var_die, DW_AT_external, 1);
21313 if (DECL_ARTIFICIAL (decl))
21314 add_AT_flag (var_die, DW_AT_artificial, 1);
21316 add_accessibility_attribute (var_die, decl);
21320 add_AT_flag (var_die, DW_AT_declaration, 1);
21322 if (decl && (DECL_ABSTRACT_P (decl)
21323 || !old_die || is_declaration_die (old_die)))
21324 equate_decl_number_to_die (decl, var_die);
21326 gen_variable_die_location:
21328 && (! DECL_ABSTRACT_P (decl_or_origin)
21329 /* Local static vars are shared between all clones/inlines,
21330 so emit DW_AT_location on the abstract DIE if DECL_RTL is
21332 || (TREE_CODE (decl_or_origin) == VAR_DECL
21333 && TREE_STATIC (decl_or_origin)
21334 && DECL_RTL_SET_P (decl_or_origin)))
21335 /* When abstract origin already has DW_AT_location attribute, no need
21336 to add it again. */
21337 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
21340 add_pubname (decl_or_origin, var_die);
21342 add_location_or_const_value_attribute (var_die, decl_or_origin,
21346 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
21349 /* Generate a DIE to represent a named constant. */
21352 gen_const_die (tree decl, dw_die_ref context_die)
21354 dw_die_ref const_die;
21355 tree type = TREE_TYPE (decl);
21357 const_die = lookup_decl_die (decl);
21361 const_die = new_die (DW_TAG_constant, context_die, decl);
21362 equate_decl_number_to_die (decl, const_die);
21363 add_name_and_src_coords_attributes (const_die, decl);
21364 add_type_attribute (const_die, type, TYPE_QUAL_CONST, false, context_die);
21365 if (TREE_PUBLIC (decl))
21366 add_AT_flag (const_die, DW_AT_external, 1);
21367 if (DECL_ARTIFICIAL (decl))
21368 add_AT_flag (const_die, DW_AT_artificial, 1);
21369 tree_add_const_value_attribute_for_decl (const_die, decl);
21372 /* Generate a DIE to represent a label identifier. */
21375 gen_label_die (tree decl, dw_die_ref context_die)
21377 tree origin = decl_ultimate_origin (decl);
21378 dw_die_ref lbl_die = lookup_decl_die (decl);
21380 char label[MAX_ARTIFICIAL_LABEL_BYTES];
21384 lbl_die = new_die (DW_TAG_label, context_die, decl);
21385 equate_decl_number_to_die (decl, lbl_die);
21387 if (origin != NULL)
21388 add_abstract_origin_attribute (lbl_die, origin);
21390 add_name_and_src_coords_attributes (lbl_die, decl);
21393 if (DECL_ABSTRACT_P (decl))
21394 equate_decl_number_to_die (decl, lbl_die);
21397 insn = DECL_RTL_IF_SET (decl);
21399 /* Deleted labels are programmer specified labels which have been
21400 eliminated because of various optimizations. We still emit them
21401 here so that it is possible to put breakpoints on them. */
21405 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
21407 /* When optimization is enabled (via -O) some parts of the compiler
21408 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
21409 represent source-level labels which were explicitly declared by
21410 the user. This really shouldn't be happening though, so catch
21411 it if it ever does happen. */
21412 gcc_assert (!as_a<rtx_insn *> (insn)->deleted ());
21414 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
21415 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
21419 && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL
21420 && CODE_LABEL_NUMBER (insn) != -1)
21422 ASM_GENERATE_INTERNAL_LABEL (label, "LDL", CODE_LABEL_NUMBER (insn));
21423 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
21428 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
21429 attributes to the DIE for a block STMT, to describe where the inlined
21430 function was called from. This is similar to add_src_coords_attributes. */
21433 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
21435 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
21437 if (dwarf_version >= 3 || !dwarf_strict)
21439 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
21440 add_AT_unsigned (die, DW_AT_call_line, s.line);
21445 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
21446 Add low_pc and high_pc attributes to the DIE for a block STMT. */
21449 add_high_low_attributes (tree stmt, dw_die_ref die)
21451 char label[MAX_ARTIFICIAL_LABEL_BYTES];
21453 if (BLOCK_FRAGMENT_CHAIN (stmt)
21454 && (dwarf_version >= 3 || !dwarf_strict))
21456 tree chain, superblock = NULL_TREE;
21458 dw_attr_node *attr = NULL;
21460 if (inlined_function_outer_scope_p (stmt))
21462 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
21463 BLOCK_NUMBER (stmt));
21464 add_AT_lbl_id (die, DW_AT_entry_pc, label);
21467 /* Optimize duplicate .debug_ranges lists or even tails of
21468 lists. If this BLOCK has same ranges as its supercontext,
21469 lookup DW_AT_ranges attribute in the supercontext (and
21470 recursively so), verify that the ranges_table contains the
21471 right values and use it instead of adding a new .debug_range. */
21472 for (chain = stmt, pdie = die;
21473 BLOCK_SAME_RANGE (chain);
21474 chain = BLOCK_SUPERCONTEXT (chain))
21476 dw_attr_node *new_attr;
21478 pdie = pdie->die_parent;
21481 if (BLOCK_SUPERCONTEXT (chain) == NULL_TREE)
21483 new_attr = get_AT (pdie, DW_AT_ranges);
21484 if (new_attr == NULL
21485 || new_attr->dw_attr_val.val_class != dw_val_class_range_list)
21488 superblock = BLOCK_SUPERCONTEXT (chain);
21491 && (ranges_table[attr->dw_attr_val.v.val_offset
21492 / 2 / DWARF2_ADDR_SIZE].num
21493 == BLOCK_NUMBER (superblock))
21494 && BLOCK_FRAGMENT_CHAIN (superblock))
21496 unsigned long off = attr->dw_attr_val.v.val_offset
21497 / 2 / DWARF2_ADDR_SIZE;
21498 unsigned long supercnt = 0, thiscnt = 0;
21499 for (chain = BLOCK_FRAGMENT_CHAIN (superblock);
21500 chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
21503 gcc_checking_assert (ranges_table[off + supercnt].num
21504 == BLOCK_NUMBER (chain));
21506 gcc_checking_assert (ranges_table[off + supercnt + 1].num == 0);
21507 for (chain = BLOCK_FRAGMENT_CHAIN (stmt);
21508 chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
21510 gcc_assert (supercnt >= thiscnt);
21511 add_AT_range_list (die, DW_AT_ranges,
21512 ((off + supercnt - thiscnt)
21513 * 2 * DWARF2_ADDR_SIZE),
21518 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt), false);
21520 chain = BLOCK_FRAGMENT_CHAIN (stmt);
21523 add_ranges (chain);
21524 chain = BLOCK_FRAGMENT_CHAIN (chain);
21531 char label_high[MAX_ARTIFICIAL_LABEL_BYTES];
21532 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
21533 BLOCK_NUMBER (stmt));
21534 ASM_GENERATE_INTERNAL_LABEL (label_high, BLOCK_END_LABEL,
21535 BLOCK_NUMBER (stmt));
21536 add_AT_low_high_pc (die, label, label_high, false);
21540 /* Generate a DIE for a lexical block. */
21543 gen_lexical_block_die (tree stmt, dw_die_ref context_die)
21545 dw_die_ref old_die = BLOCK_DIE (stmt);
21546 dw_die_ref stmt_die = NULL;
21549 stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
21550 BLOCK_DIE (stmt) = stmt_die;
21553 if (BLOCK_ABSTRACT (stmt))
21557 /* This must have been generated early and it won't even
21558 need location information since it's a DW_AT_inline
21561 for (dw_die_ref c = context_die; c; c = c->die_parent)
21562 if (c->die_tag == DW_TAG_inlined_subroutine
21563 || c->die_tag == DW_TAG_subprogram)
21565 gcc_assert (get_AT (c, DW_AT_inline));
21571 else if (BLOCK_ABSTRACT_ORIGIN (stmt))
21573 /* If this is an inlined instance, create a new lexical die for
21574 anything below to attach DW_AT_abstract_origin to. */
21577 stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
21578 BLOCK_DIE (stmt) = stmt_die;
21584 stmt_die = old_die;
21586 /* A non abstract block whose blocks have already been reordered
21587 should have the instruction range for this block. If so, set the
21588 high/low attributes. */
21589 if (!early_dwarf && !BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
21591 gcc_assert (stmt_die);
21592 add_high_low_attributes (stmt, stmt_die);
21595 decls_for_scope (stmt, stmt_die);
21598 /* Generate a DIE for an inlined subprogram. */
21601 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die)
21605 /* The instance of function that is effectively being inlined shall not
21607 gcc_assert (! BLOCK_ABSTRACT (stmt));
21609 decl = block_ultimate_origin (stmt);
21611 /* Make sure any inlined functions are known to be inlineable. */
21612 gcc_checking_assert (DECL_ABSTRACT_P (decl)
21613 || cgraph_function_possibly_inlined_p (decl));
21615 /* Emit info for the abstract instance first, if we haven't yet. We
21616 must emit this even if the block is abstract, otherwise when we
21617 emit the block below (or elsewhere), we may end up trying to emit
21618 a die whose origin die hasn't been emitted, and crashing. */
21619 dwarf2out_abstract_function (decl);
21621 if (! BLOCK_ABSTRACT (stmt))
21623 dw_die_ref subr_die
21624 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
21626 if (call_arg_locations)
21627 BLOCK_DIE (stmt) = subr_die;
21628 add_abstract_origin_attribute (subr_die, decl);
21629 if (TREE_ASM_WRITTEN (stmt))
21630 add_high_low_attributes (stmt, subr_die);
21631 add_call_src_coords_attributes (stmt, subr_die);
21633 decls_for_scope (stmt, subr_die);
21637 /* Generate a DIE for a field in a record, or structure. CTX is required: see
21638 the comment for VLR_CONTEXT. */
21641 gen_field_die (tree decl, struct vlr_context *ctx, dw_die_ref context_die)
21643 dw_die_ref decl_die;
21645 if (TREE_TYPE (decl) == error_mark_node)
21648 decl_die = new_die (DW_TAG_member, context_die, decl);
21649 add_name_and_src_coords_attributes (decl_die, decl);
21650 add_type_attribute (decl_die, member_declared_type (decl), decl_quals (decl),
21651 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl)),
21654 if (DECL_BIT_FIELD_TYPE (decl))
21656 add_byte_size_attribute (decl_die, decl);
21657 add_bit_size_attribute (decl_die, decl);
21658 add_bit_offset_attribute (decl_die, decl, ctx);
21661 /* If we have a variant part offset, then we are supposed to process a member
21662 of a QUAL_UNION_TYPE, which is how we represent variant parts in
21664 gcc_assert (ctx->variant_part_offset == NULL_TREE
21665 || TREE_CODE (DECL_FIELD_CONTEXT (decl)) != QUAL_UNION_TYPE);
21666 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
21667 add_data_member_location_attribute (decl_die, decl, ctx);
21669 if (DECL_ARTIFICIAL (decl))
21670 add_AT_flag (decl_die, DW_AT_artificial, 1);
21672 add_accessibility_attribute (decl_die, decl);
21674 /* Equate decl number to die, so that we can look up this decl later on. */
21675 equate_decl_number_to_die (decl, decl_die);
21679 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21680 Use modified_type_die instead.
21681 We keep this code here just in case these types of DIEs may be needed to
21682 represent certain things in other languages (e.g. Pascal) someday. */
21685 gen_pointer_type_die (tree type, dw_die_ref context_die)
21688 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
21690 equate_type_number_to_die (type, ptr_die);
21691 add_type_attribute (ptr_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
21693 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
21696 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21697 Use modified_type_die instead.
21698 We keep this code here just in case these types of DIEs may be needed to
21699 represent certain things in other languages (e.g. Pascal) someday. */
21702 gen_reference_type_die (tree type, dw_die_ref context_die)
21704 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
21706 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
21707 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
21709 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
21711 equate_type_number_to_die (type, ref_die);
21712 add_type_attribute (ref_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
21714 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
21718 /* Generate a DIE for a pointer to a member type. */
21721 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
21724 = new_die (DW_TAG_ptr_to_member_type,
21725 scope_die_for (type, context_die), type);
21727 equate_type_number_to_die (type, ptr_die);
21728 add_AT_die_ref (ptr_die, DW_AT_containing_type,
21729 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
21730 add_type_attribute (ptr_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
21734 static char *producer_string;
21736 /* Return a heap allocated producer string including command line options
21737 if -grecord-gcc-switches. */
21740 gen_producer_string (void)
21743 auto_vec<const char *> switches;
21744 const char *language_string = lang_hooks.name;
21745 char *producer, *tail;
21747 size_t len = dwarf_record_gcc_switches ? 0 : 3;
21748 size_t plen = strlen (language_string) + 1 + strlen (version_string);
21750 for (j = 1; dwarf_record_gcc_switches && j < save_decoded_options_count; j++)
21751 switch (save_decoded_options[j].opt_index)
21758 case OPT_auxbase_strip:
21767 case OPT_SPECIAL_unknown:
21768 case OPT_SPECIAL_ignore:
21769 case OPT_SPECIAL_program_name:
21770 case OPT_SPECIAL_input_file:
21771 case OPT_grecord_gcc_switches:
21772 case OPT_gno_record_gcc_switches:
21773 case OPT__output_pch_:
21774 case OPT_fdiagnostics_show_location_:
21775 case OPT_fdiagnostics_show_option:
21776 case OPT_fdiagnostics_show_caret:
21777 case OPT_fdiagnostics_color_:
21778 case OPT_fverbose_asm:
21780 case OPT__sysroot_:
21782 case OPT_nostdinc__:
21783 case OPT_fpreprocessed:
21784 case OPT_fltrans_output_list_:
21785 case OPT_fresolution_:
21786 case OPT_fdebug_prefix_map_:
21787 /* Ignore these. */
21790 if (cl_options[save_decoded_options[j].opt_index].flags
21791 & CL_NO_DWARF_RECORD)
21793 gcc_checking_assert (save_decoded_options[j].canonical_option[0][0]
21795 switch (save_decoded_options[j].canonical_option[0][1])
21802 if (strncmp (save_decoded_options[j].canonical_option[0] + 2,
21809 switches.safe_push (save_decoded_options[j].orig_option_with_args_text);
21810 len += strlen (save_decoded_options[j].orig_option_with_args_text) + 1;
21814 producer = XNEWVEC (char, plen + 1 + len + 1);
21816 sprintf (tail, "%s %s", language_string, version_string);
21819 FOR_EACH_VEC_ELT (switches, j, p)
21823 memcpy (tail + 1, p, len);
21831 /* Given a C and/or C++ language/version string return the "highest".
21832 C++ is assumed to be "higher" than C in this case. Used for merging
21833 LTO translation unit languages. */
21834 static const char *
21835 highest_c_language (const char *lang1, const char *lang2)
21837 if (strcmp ("GNU C++14", lang1) == 0 || strcmp ("GNU C++14", lang2) == 0)
21838 return "GNU C++14";
21839 if (strcmp ("GNU C++11", lang1) == 0 || strcmp ("GNU C++11", lang2) == 0)
21840 return "GNU C++11";
21841 if (strcmp ("GNU C++98", lang1) == 0 || strcmp ("GNU C++98", lang2) == 0)
21842 return "GNU C++98";
21844 if (strcmp ("GNU C11", lang1) == 0 || strcmp ("GNU C11", lang2) == 0)
21846 if (strcmp ("GNU C99", lang1) == 0 || strcmp ("GNU C99", lang2) == 0)
21848 if (strcmp ("GNU C89", lang1) == 0 || strcmp ("GNU C89", lang2) == 0)
21851 gcc_unreachable ();
21855 /* Generate the DIE for the compilation unit. */
21858 gen_compile_unit_die (const char *filename)
21861 const char *language_string = lang_hooks.name;
21864 die = new_die (DW_TAG_compile_unit, NULL, NULL);
21868 add_name_attribute (die, filename);
21869 /* Don't add cwd for <built-in>. */
21870 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
21871 add_comp_dir_attribute (die);
21874 add_AT_string (die, DW_AT_producer, producer_string ? producer_string : "");
21876 /* If our producer is LTO try to figure out a common language to use
21877 from the global list of translation units. */
21878 if (strcmp (language_string, "GNU GIMPLE") == 0)
21882 const char *common_lang = NULL;
21884 FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, t)
21886 if (!TRANSLATION_UNIT_LANGUAGE (t))
21889 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
21890 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
21892 else if (strncmp (common_lang, "GNU C", 5) == 0
21893 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
21894 /* Mixing C and C++ is ok, use C++ in that case. */
21895 common_lang = highest_c_language (common_lang,
21896 TRANSLATION_UNIT_LANGUAGE (t));
21899 /* Fall back to C. */
21900 common_lang = NULL;
21906 language_string = common_lang;
21909 language = DW_LANG_C;
21910 if (strncmp (language_string, "GNU C", 5) == 0
21911 && ISDIGIT (language_string[5]))
21913 language = DW_LANG_C89;
21914 if (dwarf_version >= 3 || !dwarf_strict)
21916 if (strcmp (language_string, "GNU C89") != 0)
21917 language = DW_LANG_C99;
21919 if (dwarf_version >= 5 /* || !dwarf_strict */)
21920 if (strcmp (language_string, "GNU C11") == 0)
21921 language = DW_LANG_C11;
21924 else if (strncmp (language_string, "GNU C++", 7) == 0)
21926 language = DW_LANG_C_plus_plus;
21927 if (dwarf_version >= 5 /* || !dwarf_strict */)
21929 if (strcmp (language_string, "GNU C++11") == 0)
21930 language = DW_LANG_C_plus_plus_11;
21931 else if (strcmp (language_string, "GNU C++14") == 0)
21932 language = DW_LANG_C_plus_plus_14;
21935 else if (strcmp (language_string, "GNU F77") == 0)
21936 language = DW_LANG_Fortran77;
21937 else if (strcmp (language_string, "GNU Pascal") == 0)
21938 language = DW_LANG_Pascal83;
21939 else if (dwarf_version >= 3 || !dwarf_strict)
21941 if (strcmp (language_string, "GNU Ada") == 0)
21942 language = DW_LANG_Ada95;
21943 else if (strncmp (language_string, "GNU Fortran", 11) == 0)
21945 language = DW_LANG_Fortran95;
21946 if (dwarf_version >= 5 /* || !dwarf_strict */)
21948 if (strcmp (language_string, "GNU Fortran2003") == 0)
21949 language = DW_LANG_Fortran03;
21950 else if (strcmp (language_string, "GNU Fortran2008") == 0)
21951 language = DW_LANG_Fortran08;
21954 else if (strcmp (language_string, "GNU Java") == 0)
21955 language = DW_LANG_Java;
21956 else if (strcmp (language_string, "GNU Objective-C") == 0)
21957 language = DW_LANG_ObjC;
21958 else if (strcmp (language_string, "GNU Objective-C++") == 0)
21959 language = DW_LANG_ObjC_plus_plus;
21960 else if (dwarf_version >= 5 || !dwarf_strict)
21962 if (strcmp (language_string, "GNU Go") == 0)
21963 language = DW_LANG_Go;
21966 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
21967 else if (strncmp (language_string, "GNU Fortran", 11) == 0)
21968 language = DW_LANG_Fortran90;
21970 add_AT_unsigned (die, DW_AT_language, language);
21974 case DW_LANG_Fortran77:
21975 case DW_LANG_Fortran90:
21976 case DW_LANG_Fortran95:
21977 case DW_LANG_Fortran03:
21978 case DW_LANG_Fortran08:
21979 /* Fortran has case insensitive identifiers and the front-end
21980 lowercases everything. */
21981 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
21984 /* The default DW_ID_case_sensitive doesn't need to be specified. */
21990 /* Generate the DIE for a base class. */
21993 gen_inheritance_die (tree binfo, tree access, tree type,
21994 dw_die_ref context_die)
21996 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
21997 struct vlr_context ctx = { type, NULL };
21999 add_type_attribute (die, BINFO_TYPE (binfo), TYPE_UNQUALIFIED, false,
22001 add_data_member_location_attribute (die, binfo, &ctx);
22003 if (BINFO_VIRTUAL_P (binfo))
22004 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
22006 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
22007 children, otherwise the default is DW_ACCESS_public. In DWARF2
22008 the default has always been DW_ACCESS_private. */
22009 if (access == access_public_node)
22011 if (dwarf_version == 2
22012 || context_die->die_tag == DW_TAG_class_type)
22013 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
22015 else if (access == access_protected_node)
22016 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
22017 else if (dwarf_version > 2
22018 && context_die->die_tag != DW_TAG_class_type)
22019 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
22022 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
22025 is_variant_part (tree decl)
22027 return (TREE_CODE (decl) == FIELD_DECL
22028 && TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
22031 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
22032 return the FIELD_DECL. Return NULL_TREE otherwise. */
22035 analyze_discr_in_predicate (tree operand, tree struct_type)
22037 bool continue_stripping = true;
22038 while (continue_stripping)
22039 switch (TREE_CODE (operand))
22042 operand = TREE_OPERAND (operand, 0);
22045 continue_stripping = false;
22049 /* Match field access to members of struct_type only. */
22050 if (TREE_CODE (operand) == COMPONENT_REF
22051 && TREE_CODE (TREE_OPERAND (operand, 0)) == PLACEHOLDER_EXPR
22052 && TREE_TYPE (TREE_OPERAND (operand, 0)) == struct_type
22053 && TREE_CODE (TREE_OPERAND (operand, 1)) == FIELD_DECL)
22054 return TREE_OPERAND (operand, 1);
22059 /* Check that SRC is a constant integer that can be represented as a native
22060 integer constant (either signed or unsigned). If so, store it into DEST and
22061 return true. Return false otherwise. */
22064 get_discr_value (tree src, dw_discr_value *dest)
22066 bool is_unsigned = TYPE_UNSIGNED (TREE_TYPE (src));
22068 if (TREE_CODE (src) != INTEGER_CST
22069 || !(is_unsigned ? tree_fits_uhwi_p (src) : tree_fits_shwi_p (src)))
22072 dest->pos = is_unsigned;
22074 dest->v.uval = tree_to_uhwi (src);
22076 dest->v.sval = tree_to_shwi (src);
22081 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
22082 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
22083 store NULL_TREE in DISCR_DECL. Otherwise:
22085 - store the discriminant field in STRUCT_TYPE that controls the variant
22086 part to *DISCR_DECL
22088 - put in *DISCR_LISTS_P an array where for each variant, the item
22089 represents the corresponding matching list of discriminant values.
22091 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
22094 Note that when the array is allocated (i.e. when the analysis is
22095 successful), it is up to the caller to free the array. */
22098 analyze_variants_discr (tree variant_part_decl,
22101 dw_discr_list_ref **discr_lists_p,
22102 unsigned *discr_lists_length)
22104 tree variant_part_type = TREE_TYPE (variant_part_decl);
22106 dw_discr_list_ref *discr_lists;
22109 /* Compute how many variants there are in this variant part. */
22110 *discr_lists_length = 0;
22111 for (variant = TYPE_FIELDS (variant_part_type);
22112 variant != NULL_TREE;
22113 variant = DECL_CHAIN (variant))
22114 ++*discr_lists_length;
22116 *discr_decl = NULL_TREE;
22118 = (dw_discr_list_ref *) xcalloc (*discr_lists_length,
22119 sizeof (**discr_lists_p));
22120 discr_lists = *discr_lists_p;
22122 /* And then analyze all variants to extract discriminant information for all
22123 of them. This analysis is conservative: as soon as we detect something we
22124 do not support, abort everything and pretend we found nothing. */
22125 for (variant = TYPE_FIELDS (variant_part_type), i = 0;
22126 variant != NULL_TREE;
22127 variant = DECL_CHAIN (variant), ++i)
22129 tree match_expr = DECL_QUALIFIER (variant);
22131 /* Now, try to analyze the predicate and deduce a discriminant for
22133 if (match_expr == boolean_true_node)
22134 /* Typically happens for the default variant: it matches all cases that
22135 previous variants rejected. Don't output any matching value for
22139 /* The following loop tries to iterate over each discriminant
22140 possibility: single values or ranges. */
22141 while (match_expr != NULL_TREE)
22143 tree next_round_match_expr;
22144 tree candidate_discr = NULL_TREE;
22145 dw_discr_list_ref new_node = NULL;
22147 /* Possibilities are matched one after the other by nested
22148 TRUTH_ORIF_EXPR expressions. Process the current possibility and
22149 continue with the rest at next iteration. */
22150 if (TREE_CODE (match_expr) == TRUTH_ORIF_EXPR)
22152 next_round_match_expr = TREE_OPERAND (match_expr, 0);
22153 match_expr = TREE_OPERAND (match_expr, 1);
22156 next_round_match_expr = NULL_TREE;
22158 if (match_expr == boolean_false_node)
22159 /* This sub-expression matches nothing: just wait for the next
22163 else if (TREE_CODE (match_expr) == EQ_EXPR)
22165 /* We are matching: <discr_field> == <integer_cst>
22166 This sub-expression matches a single value. */
22167 tree integer_cst = TREE_OPERAND (match_expr, 1);
22170 = analyze_discr_in_predicate (TREE_OPERAND (match_expr, 0),
22173 new_node = ggc_cleared_alloc<dw_discr_list_node> ();
22174 if (!get_discr_value (integer_cst,
22175 &new_node->dw_discr_lower_bound))
22177 new_node->dw_discr_range = false;
22180 else if (TREE_CODE (match_expr) == TRUTH_ANDIF_EXPR)
22182 /* We are matching:
22183 <discr_field> > <integer_cst>
22184 && <discr_field> < <integer_cst>.
22185 This sub-expression matches the range of values between the
22186 two matched integer constants. Note that comparisons can be
22187 inclusive or exclusive. */
22188 tree candidate_discr_1, candidate_discr_2;
22189 tree lower_cst, upper_cst;
22190 bool lower_cst_included, upper_cst_included;
22191 tree lower_op = TREE_OPERAND (match_expr, 0);
22192 tree upper_op = TREE_OPERAND (match_expr, 1);
22194 /* When the comparison is exclusive, the integer constant is not
22195 the discriminant range bound we are looking for: we will have
22196 to increment or decrement it. */
22197 if (TREE_CODE (lower_op) == GE_EXPR)
22198 lower_cst_included = true;
22199 else if (TREE_CODE (lower_op) == GT_EXPR)
22200 lower_cst_included = false;
22204 if (TREE_CODE (upper_op) == LE_EXPR)
22205 upper_cst_included = true;
22206 else if (TREE_CODE (upper_op) == LT_EXPR)
22207 upper_cst_included = false;
22211 /* Extract the discriminant from the first operand and check it
22212 is consistant with the same analysis in the second
22215 = analyze_discr_in_predicate (TREE_OPERAND (lower_op, 0),
22218 = analyze_discr_in_predicate (TREE_OPERAND (upper_op, 0),
22220 if (candidate_discr_1 == candidate_discr_2)
22221 candidate_discr = candidate_discr_1;
22225 /* Extract bounds from both. */
22226 new_node = ggc_cleared_alloc<dw_discr_list_node> ();
22227 lower_cst = TREE_OPERAND (lower_op, 1);
22228 upper_cst = TREE_OPERAND (upper_op, 1);
22230 if (!lower_cst_included)
22232 = fold_build2 (PLUS_EXPR, TREE_TYPE (lower_cst), lower_cst,
22233 build_int_cst (TREE_TYPE (lower_cst), 1));
22234 if (!upper_cst_included)
22236 = fold_build2 (MINUS_EXPR, TREE_TYPE (upper_cst), upper_cst,
22237 build_int_cst (TREE_TYPE (upper_cst), 1));
22239 if (!get_discr_value (lower_cst,
22240 &new_node->dw_discr_lower_bound)
22241 || !get_discr_value (upper_cst,
22242 &new_node->dw_discr_upper_bound))
22245 new_node->dw_discr_range = true;
22249 /* Unsupported sub-expression: we cannot determine the set of
22250 matching discriminant values. Abort everything. */
22253 /* If the discriminant info is not consistant with what we saw so
22254 far, consider the analysis failed and abort everything. */
22255 if (candidate_discr == NULL_TREE
22256 || (*discr_decl != NULL_TREE && candidate_discr != *discr_decl))
22259 *discr_decl = candidate_discr;
22261 if (new_node != NULL)
22263 new_node->dw_discr_next = discr_lists[i];
22264 discr_lists[i] = new_node;
22266 match_expr = next_round_match_expr;
22270 /* If we reach this point, we could match everything we were interested
22275 /* Clean all data structure and return no result. */
22276 free (*discr_lists_p);
22277 *discr_lists_p = NULL;
22278 *discr_decl = NULL_TREE;
22281 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
22282 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
22285 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
22286 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
22287 this type, which are record types, represent the available variants and each
22288 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
22289 values are inferred from these attributes.
22291 In trees, the offsets for the fields inside these sub-records are relative
22292 to the variant part itself, whereas the corresponding DIEs should have
22293 offset attributes that are relative to the embedding record base address.
22294 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
22295 must be an expression that computes the offset of the variant part to
22296 describe in DWARF. */
22299 gen_variant_part (tree variant_part_decl, struct vlr_context *vlr_ctx,
22300 dw_die_ref context_die)
22302 const tree variant_part_type = TREE_TYPE (variant_part_decl);
22303 tree variant_part_offset = vlr_ctx->variant_part_offset;
22304 struct loc_descr_context ctx = {
22305 vlr_ctx->struct_type, /* context_type */
22306 NULL_TREE, /* base_decl */
22310 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
22311 NULL_TREE if there is no such field. */
22312 tree discr_decl = NULL_TREE;
22313 dw_discr_list_ref *discr_lists;
22314 unsigned discr_lists_length = 0;
22317 dw_die_ref dwarf_proc_die = NULL;
22318 dw_die_ref variant_part_die
22319 = new_die (DW_TAG_variant_part, context_die, variant_part_type);
22321 equate_decl_number_to_die (variant_part_decl, variant_part_die);
22323 analyze_variants_discr (variant_part_decl, vlr_ctx->struct_type,
22324 &discr_decl, &discr_lists, &discr_lists_length);
22326 if (discr_decl != NULL_TREE)
22328 dw_die_ref discr_die = lookup_decl_die (discr_decl);
22331 add_AT_die_ref (variant_part_die, DW_AT_discr, discr_die);
22333 /* We have no DIE for the discriminant, so just discard all
22334 discrimimant information in the output. */
22335 discr_decl = NULL_TREE;
22338 /* If the offset for this variant part is more complex than a constant,
22339 create a DWARF procedure for it so that we will not have to generate DWARF
22340 expressions for it for each member. */
22341 if (TREE_CODE (variant_part_offset) != INTEGER_CST
22342 && (dwarf_version >= 3 || !dwarf_strict))
22344 const tree dwarf_proc_fndecl
22345 = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, NULL_TREE,
22346 build_function_type (TREE_TYPE (variant_part_offset),
22348 const tree dwarf_proc_call = build_call_expr (dwarf_proc_fndecl, 0);
22349 const dw_loc_descr_ref dwarf_proc_body
22350 = loc_descriptor_from_tree (variant_part_offset, 0, &ctx);
22352 dwarf_proc_die = new_dwarf_proc_die (dwarf_proc_body,
22353 dwarf_proc_fndecl, context_die);
22354 if (dwarf_proc_die != NULL)
22355 variant_part_offset = dwarf_proc_call;
22358 /* Output DIEs for all variants. */
22360 for (tree variant = TYPE_FIELDS (variant_part_type);
22361 variant != NULL_TREE;
22362 variant = DECL_CHAIN (variant), ++i)
22364 tree variant_type = TREE_TYPE (variant);
22365 dw_die_ref variant_die;
22367 /* All variants (i.e. members of a variant part) are supposed to be
22368 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
22369 under these records. */
22370 gcc_assert (TREE_CODE (variant_type) == RECORD_TYPE);
22372 variant_die = new_die (DW_TAG_variant, variant_part_die, variant_type);
22373 equate_decl_number_to_die (variant, variant_die);
22375 /* Output discriminant values this variant matches, if any. */
22376 if (discr_decl == NULL || discr_lists[i] == NULL)
22377 /* In the case we have discriminant information at all, this is
22378 probably the default variant: as the standard says, don't
22379 output any discriminant value/list attribute. */
22381 else if (discr_lists[i]->dw_discr_next == NULL
22382 && !discr_lists[i]->dw_discr_range)
22383 /* If there is only one accepted value, don't bother outputting a
22385 add_discr_value (variant_die, &discr_lists[i]->dw_discr_lower_bound);
22387 add_discr_list (variant_die, discr_lists[i]);
22389 for (tree member = TYPE_FIELDS (variant_type);
22390 member != NULL_TREE;
22391 member = DECL_CHAIN (member))
22393 struct vlr_context vlr_sub_ctx = {
22394 vlr_ctx->struct_type, /* struct_type */
22395 NULL /* variant_part_offset */
22397 if (is_variant_part (member))
22399 /* All offsets for fields inside variant parts are relative to
22400 the top-level embedding RECORD_TYPE's base address. On the
22401 other hand, offsets in GCC's types are relative to the
22402 nested-most variant part. So we have to sum offsets each time
22405 vlr_sub_ctx.variant_part_offset
22406 = fold_build2 (PLUS_EXPR, TREE_TYPE (variant_part_offset),
22407 variant_part_offset, byte_position (member));
22408 gen_variant_part (member, &vlr_sub_ctx, variant_die);
22412 vlr_sub_ctx.variant_part_offset = variant_part_offset;
22413 gen_decl_die (member, NULL, &vlr_sub_ctx, variant_die);
22418 free (discr_lists);
22421 /* Generate a DIE for a class member. */
22424 gen_member_die (tree type, dw_die_ref context_die)
22427 tree binfo = TYPE_BINFO (type);
22430 /* If this is not an incomplete type, output descriptions of each of its
22431 members. Note that as we output the DIEs necessary to represent the
22432 members of this record or union type, we will also be trying to output
22433 DIEs to represent the *types* of those members. However the `type'
22434 function (above) will specifically avoid generating type DIEs for member
22435 types *within* the list of member DIEs for this (containing) type except
22436 for those types (of members) which are explicitly marked as also being
22437 members of this (containing) type themselves. The g++ front- end can
22438 force any given type to be treated as a member of some other (containing)
22439 type by setting the TYPE_CONTEXT of the given (member) type to point to
22440 the TREE node representing the appropriate (containing) type. */
22442 /* First output info about the base classes. */
22445 vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
22449 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
22450 gen_inheritance_die (base,
22451 (accesses ? (*accesses)[i] : access_public_node),
22456 /* Now output info about the data members and type members. */
22457 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
22459 struct vlr_context vlr_ctx = { type, NULL_TREE };
22461 /* If we thought we were generating minimal debug info for TYPE
22462 and then changed our minds, some of the member declarations
22463 may have already been defined. Don't define them again, but
22464 do put them in the right order. */
22466 child = lookup_decl_die (member);
22468 splice_child_die (context_die, child);
22470 /* Do not generate standard DWARF for variant parts if we are generating
22471 the corresponding GNAT encodings: DIEs generated for both would
22472 conflict in our mappings. */
22473 else if (is_variant_part (member)
22474 && gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
22476 vlr_ctx.variant_part_offset = byte_position (member);
22477 gen_variant_part (member, &vlr_ctx, context_die);
22481 vlr_ctx.variant_part_offset = NULL_TREE;
22482 gen_decl_die (member, NULL, &vlr_ctx, context_die);
22486 /* We do not keep type methods in type variants. */
22487 gcc_assert (TYPE_MAIN_VARIANT (type) == type);
22488 /* Now output info about the function members (if any). */
22489 if (TYPE_METHODS (type) != error_mark_node)
22490 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
22492 /* Don't include clones in the member list. */
22493 if (DECL_ABSTRACT_ORIGIN (member))
22495 /* Nor constructors for anonymous classes. */
22496 if (DECL_ARTIFICIAL (member)
22497 && dwarf2_name (member, 0) == NULL)
22500 child = lookup_decl_die (member);
22502 splice_child_die (context_die, child);
22504 gen_decl_die (member, NULL, NULL, context_die);
22508 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
22509 is set, we pretend that the type was never defined, so we only get the
22510 member DIEs needed by later specification DIEs. */
22513 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
22514 enum debug_info_usage usage)
22516 if (TREE_ASM_WRITTEN (type))
22518 /* Fill in the bound of variable-length fields in late dwarf if
22519 still incomplete. */
22520 if (!early_dwarf && variably_modified_type_p (type, NULL))
22521 for (tree member = TYPE_FIELDS (type);
22523 member = DECL_CHAIN (member))
22524 fill_variable_array_bounds (TREE_TYPE (member));
22528 dw_die_ref type_die = lookup_type_die (type);
22529 dw_die_ref scope_die = 0;
22531 int complete = (TYPE_SIZE (type)
22532 && (! TYPE_STUB_DECL (type)
22533 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
22534 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
22535 complete = complete && should_emit_struct_debug (type, usage);
22537 if (type_die && ! complete)
22540 if (TYPE_CONTEXT (type) != NULL_TREE
22541 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
22542 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
22545 scope_die = scope_die_for (type, context_die);
22547 /* Generate child dies for template paramaters. */
22548 if (!type_die && debug_info_level > DINFO_LEVEL_TERSE)
22549 schedule_generic_params_dies_gen (type);
22551 if (! type_die || (nested && is_cu_die (scope_die)))
22552 /* First occurrence of type or toplevel definition of nested class. */
22554 dw_die_ref old_die = type_die;
22556 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
22557 ? record_type_tag (type) : DW_TAG_union_type,
22559 equate_type_number_to_die (type, type_die);
22561 add_AT_specification (type_die, old_die);
22563 add_name_attribute (type_die, type_tag (type));
22566 remove_AT (type_die, DW_AT_declaration);
22568 /* If this type has been completed, then give it a byte_size attribute and
22569 then give a list of members. */
22570 if (complete && !ns_decl)
22572 /* Prevent infinite recursion in cases where the type of some member of
22573 this type is expressed in terms of this type itself. */
22574 TREE_ASM_WRITTEN (type) = 1;
22575 add_byte_size_attribute (type_die, type);
22576 if (TYPE_STUB_DECL (type) != NULL_TREE)
22578 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
22579 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
22582 /* If the first reference to this type was as the return type of an
22583 inline function, then it may not have a parent. Fix this now. */
22584 if (type_die->die_parent == NULL)
22585 add_child_die (scope_die, type_die);
22587 push_decl_scope (type);
22588 gen_member_die (type, type_die);
22591 add_gnat_descriptive_type_attribute (type_die, type, context_die);
22592 if (TYPE_ARTIFICIAL (type))
22593 add_AT_flag (type_die, DW_AT_artificial, 1);
22595 /* GNU extension: Record what type our vtable lives in. */
22596 if (TYPE_VFIELD (type))
22598 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
22600 gen_type_die (vtype, context_die);
22601 add_AT_die_ref (type_die, DW_AT_containing_type,
22602 lookup_type_die (vtype));
22607 add_AT_flag (type_die, DW_AT_declaration, 1);
22609 /* We don't need to do this for function-local types. */
22610 if (TYPE_STUB_DECL (type)
22611 && ! decl_function_context (TYPE_STUB_DECL (type)))
22612 vec_safe_push (incomplete_types, type);
22615 if (get_AT (type_die, DW_AT_name))
22616 add_pubtype (type, type_die);
22619 /* Generate a DIE for a subroutine _type_. */
22622 gen_subroutine_type_die (tree type, dw_die_ref context_die)
22624 tree return_type = TREE_TYPE (type);
22625 dw_die_ref subr_die
22626 = new_die (DW_TAG_subroutine_type,
22627 scope_die_for (type, context_die), type);
22629 equate_type_number_to_die (type, subr_die);
22630 add_prototyped_attribute (subr_die, type);
22631 add_type_attribute (subr_die, return_type, TYPE_UNQUALIFIED, false,
22633 gen_formal_types_die (type, subr_die);
22635 if (get_AT (subr_die, DW_AT_name))
22636 add_pubtype (type, subr_die);
22639 /* Generate a DIE for a type definition. */
22642 gen_typedef_die (tree decl, dw_die_ref context_die)
22644 dw_die_ref type_die;
22647 if (TREE_ASM_WRITTEN (decl))
22649 if (DECL_ORIGINAL_TYPE (decl))
22650 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl));
22654 TREE_ASM_WRITTEN (decl) = 1;
22655 type_die = new_die (DW_TAG_typedef, context_die, decl);
22656 origin = decl_ultimate_origin (decl);
22657 if (origin != NULL)
22658 add_abstract_origin_attribute (type_die, origin);
22663 add_name_and_src_coords_attributes (type_die, decl);
22664 if (DECL_ORIGINAL_TYPE (decl))
22666 type = DECL_ORIGINAL_TYPE (decl);
22668 if (type == error_mark_node)
22671 gcc_assert (type != TREE_TYPE (decl));
22672 equate_type_number_to_die (TREE_TYPE (decl), type_die);
22676 type = TREE_TYPE (decl);
22678 if (type == error_mark_node)
22681 if (is_naming_typedef_decl (TYPE_NAME (type)))
22683 /* Here, we are in the case of decl being a typedef naming
22684 an anonymous type, e.g:
22685 typedef struct {...} foo;
22686 In that case TREE_TYPE (decl) is not a typedef variant
22687 type and TYPE_NAME of the anonymous type is set to the
22688 TYPE_DECL of the typedef. This construct is emitted by
22691 TYPE is the anonymous struct named by the typedef
22692 DECL. As we need the DW_AT_type attribute of the
22693 DW_TAG_typedef to point to the DIE of TYPE, let's
22694 generate that DIE right away. add_type_attribute
22695 called below will then pick (via lookup_type_die) that
22696 anonymous struct DIE. */
22697 if (!TREE_ASM_WRITTEN (type))
22698 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
22700 /* This is a GNU Extension. We are adding a
22701 DW_AT_linkage_name attribute to the DIE of the
22702 anonymous struct TYPE. The value of that attribute
22703 is the name of the typedef decl naming the anonymous
22704 struct. This greatly eases the work of consumers of
22705 this debug info. */
22706 add_linkage_name_raw (lookup_type_die (type), decl);
22710 add_type_attribute (type_die, type, decl_quals (decl), false,
22713 if (is_naming_typedef_decl (decl))
22714 /* We want that all subsequent calls to lookup_type_die with
22715 TYPE in argument yield the DW_TAG_typedef we have just
22717 equate_type_number_to_die (type, type_die);
22719 add_accessibility_attribute (type_die, decl);
22722 if (DECL_ABSTRACT_P (decl))
22723 equate_decl_number_to_die (decl, type_die);
22725 if (get_AT (type_die, DW_AT_name))
22726 add_pubtype (decl, type_die);
22729 /* Generate a DIE for a struct, class, enum or union type. */
22732 gen_tagged_type_die (tree type,
22733 dw_die_ref context_die,
22734 enum debug_info_usage usage)
22738 if (type == NULL_TREE
22739 || !is_tagged_type (type))
22742 if (TREE_ASM_WRITTEN (type))
22744 /* If this is a nested type whose containing class hasn't been written
22745 out yet, writing it out will cover this one, too. This does not apply
22746 to instantiations of member class templates; they need to be added to
22747 the containing class as they are generated. FIXME: This hurts the
22748 idea of combining type decls from multiple TUs, since we can't predict
22749 what set of template instantiations we'll get. */
22750 else if (TYPE_CONTEXT (type)
22751 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
22752 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
22754 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
22756 if (TREE_ASM_WRITTEN (type))
22759 /* If that failed, attach ourselves to the stub. */
22760 push_decl_scope (TYPE_CONTEXT (type));
22761 context_die = lookup_type_die (TYPE_CONTEXT (type));
22764 else if (TYPE_CONTEXT (type) != NULL_TREE
22765 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
22767 /* If this type is local to a function that hasn't been written
22768 out yet, use a NULL context for now; it will be fixed up in
22769 decls_for_scope. */
22770 context_die = lookup_decl_die (TYPE_CONTEXT (type));
22771 /* A declaration DIE doesn't count; nested types need to go in the
22773 if (context_die && is_declaration_die (context_die))
22774 context_die = NULL;
22779 context_die = declare_in_namespace (type, context_die);
22783 if (TREE_CODE (type) == ENUMERAL_TYPE)
22785 /* This might have been written out by the call to
22786 declare_in_namespace. */
22787 if (!TREE_ASM_WRITTEN (type))
22788 gen_enumeration_type_die (type, context_die);
22791 gen_struct_or_union_type_die (type, context_die, usage);
22796 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
22797 it up if it is ever completed. gen_*_type_die will set it for us
22798 when appropriate. */
22801 /* Generate a type description DIE. */
22804 gen_type_die_with_usage (tree type, dw_die_ref context_die,
22805 enum debug_info_usage usage)
22807 struct array_descr_info info;
22809 if (type == NULL_TREE || type == error_mark_node)
22812 if (flag_checking && type)
22813 verify_type (type);
22815 if (TYPE_NAME (type) != NULL_TREE
22816 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
22817 && is_redundant_typedef (TYPE_NAME (type))
22818 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
22819 /* The DECL of this type is a typedef we don't want to emit debug
22820 info for but we want debug info for its underlying typedef.
22821 This can happen for e.g, the injected-class-name of a C++
22823 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
22825 /* If TYPE is a typedef type variant, let's generate debug info
22826 for the parent typedef which TYPE is a type of. */
22827 if (typedef_variant_p (type))
22829 if (TREE_ASM_WRITTEN (type))
22832 /* Prevent broken recursion; we can't hand off to the same type. */
22833 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
22835 /* Give typedefs the right scope. */
22836 context_die = scope_die_for (type, context_die);
22838 TREE_ASM_WRITTEN (type) = 1;
22840 gen_decl_die (TYPE_NAME (type), NULL, NULL, context_die);
22844 /* If type is an anonymous tagged type named by a typedef, let's
22845 generate debug info for the typedef. */
22846 if (is_naming_typedef_decl (TYPE_NAME (type)))
22848 /* Use the DIE of the containing namespace as the parent DIE of
22849 the type description DIE we want to generate. */
22850 if (DECL_CONTEXT (TYPE_NAME (type))
22851 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
22852 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
22854 gen_decl_die (TYPE_NAME (type), NULL, NULL, context_die);
22858 /* We are going to output a DIE to represent the unqualified version
22859 of this type (i.e. without any const or volatile qualifiers) so
22860 get the main variant (i.e. the unqualified version) of this type
22861 now. (Vectors and arrays are special because the debugging info is in the
22862 cloned type itself). */
22863 if (TREE_CODE (type) != VECTOR_TYPE
22864 && TREE_CODE (type) != ARRAY_TYPE)
22865 type = type_main_variant (type);
22867 /* If this is an array type with hidden descriptor, handle it first. */
22868 if (!TREE_ASM_WRITTEN (type)
22869 && lang_hooks.types.get_array_descr_info)
22871 memset (&info, 0, sizeof (info));
22872 if (lang_hooks.types.get_array_descr_info (type, &info))
22874 /* Fortran sometimes emits array types with no dimension. */
22875 gcc_assert (info.ndimensions >= 0
22876 && (info.ndimensions
22877 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN));
22878 gen_descr_array_type_die (type, &info, context_die);
22879 TREE_ASM_WRITTEN (type) = 1;
22884 if (TREE_ASM_WRITTEN (type))
22886 /* Variable-length types may be incomplete even if
22887 TREE_ASM_WRITTEN. For such types, fall through to
22888 gen_array_type_die() and possibly fill in
22889 DW_AT_{upper,lower}_bound attributes. */
22890 if ((TREE_CODE (type) != ARRAY_TYPE
22891 && TREE_CODE (type) != RECORD_TYPE
22892 && TREE_CODE (type) != UNION_TYPE
22893 && TREE_CODE (type) != QUAL_UNION_TYPE)
22894 || !variably_modified_type_p (type, NULL))
22898 switch (TREE_CODE (type))
22904 case REFERENCE_TYPE:
22905 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
22906 ensures that the gen_type_die recursion will terminate even if the
22907 type is recursive. Recursive types are possible in Ada. */
22908 /* ??? We could perhaps do this for all types before the switch
22910 TREE_ASM_WRITTEN (type) = 1;
22912 /* For these types, all that is required is that we output a DIE (or a
22913 set of DIEs) to represent the "basis" type. */
22914 gen_type_die_with_usage (TREE_TYPE (type), context_die,
22915 DINFO_USAGE_IND_USE);
22919 /* This code is used for C++ pointer-to-data-member types.
22920 Output a description of the relevant class type. */
22921 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
22922 DINFO_USAGE_IND_USE);
22924 /* Output a description of the type of the object pointed to. */
22925 gen_type_die_with_usage (TREE_TYPE (type), context_die,
22926 DINFO_USAGE_IND_USE);
22928 /* Now output a DIE to represent this pointer-to-data-member type
22930 gen_ptr_to_mbr_type_die (type, context_die);
22933 case FUNCTION_TYPE:
22934 /* Force out return type (in case it wasn't forced out already). */
22935 gen_type_die_with_usage (TREE_TYPE (type), context_die,
22936 DINFO_USAGE_DIR_USE);
22937 gen_subroutine_type_die (type, context_die);
22941 /* Force out return type (in case it wasn't forced out already). */
22942 gen_type_die_with_usage (TREE_TYPE (type), context_die,
22943 DINFO_USAGE_DIR_USE);
22944 gen_subroutine_type_die (type, context_die);
22949 gen_array_type_die (type, context_die);
22952 case ENUMERAL_TYPE:
22955 case QUAL_UNION_TYPE:
22956 gen_tagged_type_die (type, context_die, usage);
22962 case FIXED_POINT_TYPE:
22965 case POINTER_BOUNDS_TYPE:
22966 /* No DIEs needed for fundamental types. */
22971 /* Just use DW_TAG_unspecified_type. */
22973 dw_die_ref type_die = lookup_type_die (type);
22974 if (type_die == NULL)
22976 tree name = TYPE_IDENTIFIER (type);
22977 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (),
22979 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
22980 equate_type_number_to_die (type, type_die);
22986 if (is_cxx_auto (type))
22988 tree name = TYPE_IDENTIFIER (type);
22989 dw_die_ref *die = (name == get_identifier ("auto")
22990 ? &auto_die : &decltype_auto_die);
22993 *die = new_die (DW_TAG_unspecified_type,
22994 comp_unit_die (), NULL_TREE);
22995 add_name_attribute (*die, IDENTIFIER_POINTER (name));
22997 equate_type_number_to_die (type, *die);
23000 gcc_unreachable ();
23003 TREE_ASM_WRITTEN (type) = 1;
23007 gen_type_die (tree type, dw_die_ref context_die)
23009 if (type != error_mark_node)
23011 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
23014 dw_die_ref die = lookup_type_die (type);
23021 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
23022 things which are local to the given block. */
23025 gen_block_die (tree stmt, dw_die_ref context_die)
23027 int must_output_die = 0;
23030 /* Ignore blocks that are NULL. */
23031 if (stmt == NULL_TREE)
23034 inlined_func = inlined_function_outer_scope_p (stmt);
23036 /* If the block is one fragment of a non-contiguous block, do not
23037 process the variables, since they will have been done by the
23038 origin block. Do process subblocks. */
23039 if (BLOCK_FRAGMENT_ORIGIN (stmt))
23043 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
23044 gen_block_die (sub, context_die);
23049 /* Determine if we need to output any Dwarf DIEs at all to represent this
23052 /* The outer scopes for inlinings *must* always be represented. We
23053 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
23054 must_output_die = 1;
23057 /* Determine if this block directly contains any "significant"
23058 local declarations which we will need to output DIEs for. */
23059 if (debug_info_level > DINFO_LEVEL_TERSE)
23060 /* We are not in terse mode so *any* local declaration counts
23061 as being a "significant" one. */
23062 must_output_die = ((BLOCK_VARS (stmt) != NULL
23063 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
23064 && (TREE_USED (stmt)
23065 || TREE_ASM_WRITTEN (stmt)
23066 || BLOCK_ABSTRACT (stmt)));
23067 else if ((TREE_USED (stmt)
23068 || TREE_ASM_WRITTEN (stmt)
23069 || BLOCK_ABSTRACT (stmt))
23070 && !dwarf2out_ignore_block (stmt))
23071 must_output_die = 1;
23074 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
23075 DIE for any block which contains no significant local declarations at
23076 all. Rather, in such cases we just call `decls_for_scope' so that any
23077 needed Dwarf info for any sub-blocks will get properly generated. Note
23078 that in terse mode, our definition of what constitutes a "significant"
23079 local declaration gets restricted to include only inlined function
23080 instances and local (nested) function definitions. */
23081 if (must_output_die)
23085 /* If STMT block is abstract, that means we have been called
23086 indirectly from dwarf2out_abstract_function.
23087 That function rightfully marks the descendent blocks (of
23088 the abstract function it is dealing with) as being abstract,
23089 precisely to prevent us from emitting any
23090 DW_TAG_inlined_subroutine DIE as a descendent
23091 of an abstract function instance. So in that case, we should
23092 not call gen_inlined_subroutine_die.
23094 Later though, when cgraph asks dwarf2out to emit info
23095 for the concrete instance of the function decl into which
23096 the concrete instance of STMT got inlined, the later will lead
23097 to the generation of a DW_TAG_inlined_subroutine DIE. */
23098 if (! BLOCK_ABSTRACT (stmt))
23099 gen_inlined_subroutine_die (stmt, context_die);
23102 gen_lexical_block_die (stmt, context_die);
23105 decls_for_scope (stmt, context_die);
23108 /* Process variable DECL (or variable with origin ORIGIN) within
23109 block STMT and add it to CONTEXT_DIE. */
23111 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
23114 tree decl_or_origin = decl ? decl : origin;
23116 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
23117 die = lookup_decl_die (decl_or_origin);
23118 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
23119 && TYPE_DECL_IS_STUB (decl_or_origin))
23120 die = lookup_type_die (TREE_TYPE (decl_or_origin));
23124 if (die != NULL && die->die_parent == NULL)
23125 add_child_die (context_die, die);
23126 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
23129 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
23130 stmt, context_die);
23133 gen_decl_die (decl, origin, NULL, context_die);
23136 /* Generate all of the decls declared within a given scope and (recursively)
23137 all of its sub-blocks. */
23140 decls_for_scope (tree stmt, dw_die_ref context_die)
23146 /* Ignore NULL blocks. */
23147 if (stmt == NULL_TREE)
23150 /* Output the DIEs to represent all of the data objects and typedefs
23151 declared directly within this block but not within any nested
23152 sub-blocks. Also, nested function and tag DIEs have been
23153 generated with a parent of NULL; fix that up now. We don't
23154 have to do this if we're at -g1. */
23155 if (debug_info_level > DINFO_LEVEL_TERSE)
23157 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
23158 process_scope_var (stmt, decl, NULL_TREE, context_die);
23159 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
23160 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
23164 /* Even if we're at -g1, we need to process the subblocks in order to get
23165 inlined call information. */
23167 /* Output the DIEs to represent all sub-blocks (and the items declared
23168 therein) of this block. */
23169 for (subblocks = BLOCK_SUBBLOCKS (stmt);
23171 subblocks = BLOCK_CHAIN (subblocks))
23172 gen_block_die (subblocks, context_die);
23175 /* Is this a typedef we can avoid emitting? */
23178 is_redundant_typedef (const_tree decl)
23180 if (TYPE_DECL_IS_STUB (decl))
23183 if (DECL_ARTIFICIAL (decl)
23184 && DECL_CONTEXT (decl)
23185 && is_tagged_type (DECL_CONTEXT (decl))
23186 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
23187 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
23188 /* Also ignore the artificial member typedef for the class name. */
23194 /* Return TRUE if TYPE is a typedef that names a type for linkage
23195 purposes. This kind of typedefs is produced by the C++ FE for
23198 typedef struct {...} foo;
23200 In that case, there is no typedef variant type produced for foo.
23201 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
23205 is_naming_typedef_decl (const_tree decl)
23207 if (decl == NULL_TREE
23208 || TREE_CODE (decl) != TYPE_DECL
23209 || DECL_NAMELESS (decl)
23210 || !is_tagged_type (TREE_TYPE (decl))
23211 || DECL_IS_BUILTIN (decl)
23212 || is_redundant_typedef (decl)
23213 /* It looks like Ada produces TYPE_DECLs that are very similar
23214 to C++ naming typedefs but that have different
23215 semantics. Let's be specific to c++ for now. */
23219 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
23220 && TYPE_NAME (TREE_TYPE (decl)) == decl
23221 && (TYPE_STUB_DECL (TREE_TYPE (decl))
23222 != TYPE_NAME (TREE_TYPE (decl))));
23225 /* Looks up the DIE for a context. */
23227 static inline dw_die_ref
23228 lookup_context_die (tree context)
23232 /* Find die that represents this context. */
23233 if (TYPE_P (context))
23235 context = TYPE_MAIN_VARIANT (context);
23236 dw_die_ref ctx = lookup_type_die (context);
23239 return strip_naming_typedef (context, ctx);
23242 return lookup_decl_die (context);
23244 return comp_unit_die ();
23247 /* Returns the DIE for a context. */
23249 static inline dw_die_ref
23250 get_context_die (tree context)
23254 /* Find die that represents this context. */
23255 if (TYPE_P (context))
23257 context = TYPE_MAIN_VARIANT (context);
23258 return strip_naming_typedef (context, force_type_die (context));
23261 return force_decl_die (context);
23263 return comp_unit_die ();
23266 /* Returns the DIE for decl. A DIE will always be returned. */
23269 force_decl_die (tree decl)
23271 dw_die_ref decl_die;
23272 unsigned saved_external_flag;
23273 tree save_fn = NULL_TREE;
23274 decl_die = lookup_decl_die (decl);
23277 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
23279 decl_die = lookup_decl_die (decl);
23283 switch (TREE_CODE (decl))
23285 case FUNCTION_DECL:
23286 /* Clear current_function_decl, so that gen_subprogram_die thinks
23287 that this is a declaration. At this point, we just want to force
23288 declaration die. */
23289 save_fn = current_function_decl;
23290 current_function_decl = NULL_TREE;
23291 gen_subprogram_die (decl, context_die);
23292 current_function_decl = save_fn;
23296 /* Set external flag to force declaration die. Restore it after
23297 gen_decl_die() call. */
23298 saved_external_flag = DECL_EXTERNAL (decl);
23299 DECL_EXTERNAL (decl) = 1;
23300 gen_decl_die (decl, NULL, NULL, context_die);
23301 DECL_EXTERNAL (decl) = saved_external_flag;
23304 case NAMESPACE_DECL:
23305 if (dwarf_version >= 3 || !dwarf_strict)
23306 dwarf2out_decl (decl);
23308 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
23309 decl_die = comp_unit_die ();
23312 case TRANSLATION_UNIT_DECL:
23313 decl_die = comp_unit_die ();
23317 gcc_unreachable ();
23320 /* We should be able to find the DIE now. */
23322 decl_die = lookup_decl_die (decl);
23323 gcc_assert (decl_die);
23329 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
23330 always returned. */
23333 force_type_die (tree type)
23335 dw_die_ref type_die;
23337 type_die = lookup_type_die (type);
23340 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
23342 type_die = modified_type_die (type, TYPE_QUALS_NO_ADDR_SPACE (type),
23343 false, context_die);
23344 gcc_assert (type_die);
23349 /* Force out any required namespaces to be able to output DECL,
23350 and return the new context_die for it, if it's changed. */
23353 setup_namespace_context (tree thing, dw_die_ref context_die)
23355 tree context = (DECL_P (thing)
23356 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
23357 if (context && TREE_CODE (context) == NAMESPACE_DECL)
23358 /* Force out the namespace. */
23359 context_die = force_decl_die (context);
23361 return context_die;
23364 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
23365 type) within its namespace, if appropriate.
23367 For compatibility with older debuggers, namespace DIEs only contain
23368 declarations; all definitions are emitted at CU scope, with
23369 DW_AT_specification pointing to the declaration (like with class
23373 declare_in_namespace (tree thing, dw_die_ref context_die)
23375 dw_die_ref ns_context;
23377 if (debug_info_level <= DINFO_LEVEL_TERSE)
23378 return context_die;
23380 /* External declarations in the local scope only need to be emitted
23381 once, not once in the namespace and once in the scope.
23383 This avoids declaring the `extern' below in the
23384 namespace DIE as well as in the innermost scope:
23397 if (DECL_P (thing) && DECL_EXTERNAL (thing) && local_scope_p (context_die))
23398 return context_die;
23400 /* If this decl is from an inlined function, then don't try to emit it in its
23401 namespace, as we will get confused. It would have already been emitted
23402 when the abstract instance of the inline function was emitted anyways. */
23403 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
23404 return context_die;
23406 ns_context = setup_namespace_context (thing, context_die);
23408 if (ns_context != context_die)
23412 if (DECL_P (thing))
23413 gen_decl_die (thing, NULL, NULL, ns_context);
23415 gen_type_die (thing, ns_context);
23417 return context_die;
23420 /* Generate a DIE for a namespace or namespace alias. */
23423 gen_namespace_die (tree decl, dw_die_ref context_die)
23425 dw_die_ref namespace_die;
23427 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
23428 they are an alias of. */
23429 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
23431 /* Output a real namespace or module. */
23432 context_die = setup_namespace_context (decl, comp_unit_die ());
23433 namespace_die = new_die (is_fortran ()
23434 ? DW_TAG_module : DW_TAG_namespace,
23435 context_die, decl);
23436 /* For Fortran modules defined in different CU don't add src coords. */
23437 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
23439 const char *name = dwarf2_name (decl, 0);
23441 add_name_attribute (namespace_die, name);
23444 add_name_and_src_coords_attributes (namespace_die, decl);
23445 if (DECL_EXTERNAL (decl))
23446 add_AT_flag (namespace_die, DW_AT_declaration, 1);
23447 equate_decl_number_to_die (decl, namespace_die);
23451 /* Output a namespace alias. */
23453 /* Force out the namespace we are an alias of, if necessary. */
23454 dw_die_ref origin_die
23455 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
23457 if (DECL_FILE_SCOPE_P (decl)
23458 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
23459 context_die = setup_namespace_context (decl, comp_unit_die ());
23460 /* Now create the namespace alias DIE. */
23461 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
23462 add_name_and_src_coords_attributes (namespace_die, decl);
23463 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
23464 equate_decl_number_to_die (decl, namespace_die);
23466 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
23467 if (want_pubnames ())
23468 add_pubname_string (lang_hooks.dwarf_name (decl, 1), namespace_die);
23471 /* Generate Dwarf debug information for a decl described by DECL.
23472 The return value is currently only meaningful for PARM_DECLs,
23473 for all other decls it returns NULL.
23475 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
23476 It can be NULL otherwise. */
23479 gen_decl_die (tree decl, tree origin, struct vlr_context *ctx,
23480 dw_die_ref context_die)
23482 tree decl_or_origin = decl ? decl : origin;
23483 tree class_origin = NULL, ultimate_origin;
23485 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
23488 /* Ignore pointer bounds decls. */
23489 if (DECL_P (decl_or_origin)
23490 && TREE_TYPE (decl_or_origin)
23491 && POINTER_BOUNDS_P (decl_or_origin))
23494 switch (TREE_CODE (decl_or_origin))
23500 if (!is_fortran () && !is_ada ())
23502 /* The individual enumerators of an enum type get output when we output
23503 the Dwarf representation of the relevant enum type itself. */
23507 /* Emit its type. */
23508 gen_type_die (TREE_TYPE (decl), context_die);
23510 /* And its containing namespace. */
23511 context_die = declare_in_namespace (decl, context_die);
23513 gen_const_die (decl, context_die);
23516 case FUNCTION_DECL:
23517 /* Don't output any DIEs to represent mere function declarations,
23518 unless they are class members or explicit block externs. */
23519 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
23520 && DECL_FILE_SCOPE_P (decl_or_origin)
23521 && (current_function_decl == NULL_TREE
23522 || DECL_ARTIFICIAL (decl_or_origin)))
23527 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
23528 on local redeclarations of global functions. That seems broken. */
23529 if (current_function_decl != decl)
23530 /* This is only a declaration. */;
23533 /* If we're emitting a clone, emit info for the abstract instance. */
23534 if (origin || DECL_ORIGIN (decl) != decl)
23535 dwarf2out_abstract_function (origin
23536 ? DECL_ORIGIN (origin)
23537 : DECL_ABSTRACT_ORIGIN (decl));
23539 /* If we're emitting an out-of-line copy of an inline function,
23540 emit info for the abstract instance and set up to refer to it. */
23541 else if (cgraph_function_possibly_inlined_p (decl)
23542 && ! DECL_ABSTRACT_P (decl)
23543 && ! class_or_namespace_scope_p (context_die)
23544 /* dwarf2out_abstract_function won't emit a die if this is just
23545 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
23546 that case, because that works only if we have a die. */
23547 && DECL_INITIAL (decl) != NULL_TREE)
23549 dwarf2out_abstract_function (decl);
23550 set_decl_origin_self (decl);
23553 /* Otherwise we're emitting the primary DIE for this decl. */
23554 else if (debug_info_level > DINFO_LEVEL_TERSE)
23556 /* Before we describe the FUNCTION_DECL itself, make sure that we
23557 have its containing type. */
23559 origin = decl_class_context (decl);
23560 if (origin != NULL_TREE)
23561 gen_type_die (origin, context_die);
23563 /* And its return type. */
23564 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
23566 /* And its virtual context. */
23567 if (DECL_VINDEX (decl) != NULL_TREE)
23568 gen_type_die (DECL_CONTEXT (decl), context_die);
23570 /* Make sure we have a member DIE for decl. */
23571 if (origin != NULL_TREE)
23572 gen_type_die_for_member (origin, decl, context_die);
23574 /* And its containing namespace. */
23575 context_die = declare_in_namespace (decl, context_die);
23578 /* Now output a DIE to represent the function itself. */
23580 gen_subprogram_die (decl, context_die);
23584 /* If we are in terse mode, don't generate any DIEs to represent any
23585 actual typedefs. */
23586 if (debug_info_level <= DINFO_LEVEL_TERSE)
23589 /* In the special case of a TYPE_DECL node representing the declaration
23590 of some type tag, if the given TYPE_DECL is marked as having been
23591 instantiated from some other (original) TYPE_DECL node (e.g. one which
23592 was generated within the original definition of an inline function) we
23593 used to generate a special (abbreviated) DW_TAG_structure_type,
23594 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
23595 should be actually referencing those DIEs, as variable DIEs with that
23596 type would be emitted already in the abstract origin, so it was always
23597 removed during unused type prunning. Don't add anything in this
23599 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
23602 if (is_redundant_typedef (decl))
23603 gen_type_die (TREE_TYPE (decl), context_die);
23605 /* Output a DIE to represent the typedef itself. */
23606 gen_typedef_die (decl, context_die);
23610 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23611 gen_label_die (decl, context_die);
23616 /* If we are in terse mode, don't generate any DIEs to represent any
23617 variable declarations or definitions. */
23618 if (debug_info_level <= DINFO_LEVEL_TERSE)
23621 /* Output any DIEs that are needed to specify the type of this data
23623 if (decl_by_reference_p (decl_or_origin))
23624 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
23626 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
23628 /* And its containing type. */
23629 class_origin = decl_class_context (decl_or_origin);
23630 if (class_origin != NULL_TREE)
23631 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
23633 /* And its containing namespace. */
23634 context_die = declare_in_namespace (decl_or_origin, context_die);
23636 /* Now output the DIE to represent the data object itself. This gets
23637 complicated because of the possibility that the VAR_DECL really
23638 represents an inlined instance of a formal parameter for an inline
23640 ultimate_origin = decl_ultimate_origin (decl_or_origin);
23641 if (ultimate_origin != NULL_TREE
23642 && TREE_CODE (ultimate_origin) == PARM_DECL)
23643 gen_formal_parameter_die (decl, origin,
23644 true /* Emit name attribute. */,
23647 gen_variable_die (decl, origin, context_die);
23651 gcc_assert (ctx != NULL && ctx->struct_type != NULL);
23652 /* Ignore the nameless fields that are used to skip bits but handle C++
23653 anonymous unions and structs. */
23654 if (DECL_NAME (decl) != NULL_TREE
23655 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
23656 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
23658 gen_type_die (member_declared_type (decl), context_die);
23659 gen_field_die (decl, ctx, context_die);
23664 if (DECL_BY_REFERENCE (decl_or_origin))
23665 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
23667 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
23668 return gen_formal_parameter_die (decl, origin,
23669 true /* Emit name attribute. */,
23672 case NAMESPACE_DECL:
23673 if (dwarf_version >= 3 || !dwarf_strict)
23674 gen_namespace_die (decl, context_die);
23677 case IMPORTED_DECL:
23678 dwarf2out_imported_module_or_decl_1 (decl, DECL_NAME (decl),
23679 DECL_CONTEXT (decl), context_die);
23682 case NAMELIST_DECL:
23683 gen_namelist_decl (DECL_NAME (decl), context_die,
23684 NAMELIST_DECL_ASSOCIATED_DECL (decl));
23688 /* Probably some frontend-internal decl. Assume we don't care. */
23689 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
23696 /* Output initial debug information for global DECL. Called at the
23697 end of the parsing process.
23699 This is the initial debug generation process. As such, the DIEs
23700 generated may be incomplete. A later debug generation pass
23701 (dwarf2out_late_global_decl) will augment the information generated
23702 in this pass (e.g., with complete location info). */
23705 dwarf2out_early_global_decl (tree decl)
23709 /* gen_decl_die() will set DECL_ABSTRACT because
23710 cgraph_function_possibly_inlined_p() returns true. This is in
23711 turn will cause DW_AT_inline attributes to be set.
23713 This happens because at early dwarf generation, there is no
23714 cgraph information, causing cgraph_function_possibly_inlined_p()
23715 to return true. Trick cgraph_function_possibly_inlined_p()
23716 while we generate dwarf early. */
23717 bool save = symtab->global_info_ready;
23718 symtab->global_info_ready = true;
23720 /* We don't handle TYPE_DECLs. If required, they'll be reached via
23721 other DECLs and they can point to template types or other things
23722 that dwarf2out can't handle when done via dwarf2out_decl. */
23723 if (TREE_CODE (decl) != TYPE_DECL
23724 && TREE_CODE (decl) != PARM_DECL)
23726 tree save_fndecl = current_function_decl;
23727 if (TREE_CODE (decl) == FUNCTION_DECL)
23729 /* No cfun means the symbol has no body, so there's nothing
23731 if (!DECL_STRUCT_FUNCTION (decl))
23732 goto early_decl_exit;
23734 current_function_decl = decl;
23736 dwarf2out_decl (decl);
23737 if (TREE_CODE (decl) == FUNCTION_DECL)
23738 current_function_decl = save_fndecl;
23741 symtab->global_info_ready = save;
23744 /* Output debug information for global decl DECL. Called from
23745 toplev.c after compilation proper has finished. */
23748 dwarf2out_late_global_decl (tree decl)
23750 /* We have to generate early debug late for LTO. */
23752 dwarf2out_early_global_decl (decl);
23754 /* Fill-in any location information we were unable to determine
23755 on the first pass. */
23756 if (TREE_CODE (decl) == VAR_DECL
23757 && !POINTER_BOUNDS_P (decl))
23759 dw_die_ref die = lookup_decl_die (decl);
23762 /* We get called via the symtab code invoking late_global_decl
23763 for symbols that are optimized out. Do not add locations
23765 varpool_node *node = varpool_node::get (decl);
23766 if (! node || ! node->definition)
23767 tree_add_const_value_attribute_for_decl (die, decl);
23769 add_location_or_const_value_attribute (die, decl, false);
23774 /* Output debug information for type decl DECL. Called from toplev.c
23775 and from language front ends (to record built-in types). */
23777 dwarf2out_type_decl (tree decl, int local)
23782 dwarf2out_decl (decl);
23786 /* Output debug information for imported module or decl DECL.
23787 NAME is non-NULL name in the lexical block if the decl has been renamed.
23788 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
23789 that DECL belongs to.
23790 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
23792 dwarf2out_imported_module_or_decl_1 (tree decl,
23794 tree lexical_block,
23795 dw_die_ref lexical_block_die)
23797 expanded_location xloc;
23798 dw_die_ref imported_die = NULL;
23799 dw_die_ref at_import_die;
23801 if (TREE_CODE (decl) == IMPORTED_DECL)
23803 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
23804 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
23808 xloc = expand_location (input_location);
23810 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
23812 at_import_die = force_type_die (TREE_TYPE (decl));
23813 /* For namespace N { typedef void T; } using N::T; base_type_die
23814 returns NULL, but DW_TAG_imported_declaration requires
23815 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
23816 if (!at_import_die)
23818 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
23819 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
23820 at_import_die = lookup_type_die (TREE_TYPE (decl));
23821 gcc_assert (at_import_die);
23826 at_import_die = lookup_decl_die (decl);
23827 if (!at_import_die)
23829 /* If we're trying to avoid duplicate debug info, we may not have
23830 emitted the member decl for this field. Emit it now. */
23831 if (TREE_CODE (decl) == FIELD_DECL)
23833 tree type = DECL_CONTEXT (decl);
23835 if (TYPE_CONTEXT (type)
23836 && TYPE_P (TYPE_CONTEXT (type))
23837 && !should_emit_struct_debug (TYPE_CONTEXT (type),
23838 DINFO_USAGE_DIR_USE))
23840 gen_type_die_for_member (type, decl,
23841 get_context_die (TYPE_CONTEXT (type)));
23843 if (TREE_CODE (decl) == NAMELIST_DECL)
23844 at_import_die = gen_namelist_decl (DECL_NAME (decl),
23845 get_context_die (DECL_CONTEXT (decl)),
23848 at_import_die = force_decl_die (decl);
23852 if (TREE_CODE (decl) == NAMESPACE_DECL)
23854 if (dwarf_version >= 3 || !dwarf_strict)
23855 imported_die = new_die (DW_TAG_imported_module,
23862 imported_die = new_die (DW_TAG_imported_declaration,
23866 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
23867 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
23869 add_AT_string (imported_die, DW_AT_name,
23870 IDENTIFIER_POINTER (name));
23871 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
23874 /* Output debug information for imported module or decl DECL.
23875 NAME is non-NULL name in context if the decl has been renamed.
23876 CHILD is true if decl is one of the renamed decls as part of
23877 importing whole module. */
23880 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
23883 /* dw_die_ref at_import_die; */
23884 dw_die_ref scope_die;
23886 if (debug_info_level <= DINFO_LEVEL_TERSE)
23893 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
23894 We need decl DIE for reference and scope die. First, get DIE for the decl
23897 /* Get the scope die for decl context. Use comp_unit_die for global module
23898 or decl. If die is not found for non globals, force new die. */
23900 && TYPE_P (context)
23901 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
23904 if (!(dwarf_version >= 3 || !dwarf_strict))
23907 scope_die = get_context_die (context);
23911 gcc_assert (scope_die->die_child);
23912 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
23913 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
23914 scope_die = scope_die->die_child;
23917 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
23918 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
23921 /* Output debug information for namelists. */
23924 gen_namelist_decl (tree name, dw_die_ref scope_die, tree item_decls)
23926 dw_die_ref nml_die, nml_item_die, nml_item_ref_die;
23930 if (debug_info_level <= DINFO_LEVEL_TERSE)
23933 gcc_assert (scope_die != NULL);
23934 nml_die = new_die (DW_TAG_namelist, scope_die, NULL);
23935 add_AT_string (nml_die, DW_AT_name, IDENTIFIER_POINTER (name));
23937 /* If there are no item_decls, we have a nondefining namelist, e.g.
23938 with USE association; hence, set DW_AT_declaration. */
23939 if (item_decls == NULL_TREE)
23941 add_AT_flag (nml_die, DW_AT_declaration, 1);
23945 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls), i, value)
23947 nml_item_ref_die = lookup_decl_die (value);
23948 if (!nml_item_ref_die)
23949 nml_item_ref_die = force_decl_die (value);
23951 nml_item_die = new_die (DW_TAG_namelist_item, nml_die, NULL);
23952 add_AT_die_ref (nml_item_die, DW_AT_namelist_items, nml_item_ref_die);
23958 /* Write the debugging output for DECL and return the DIE. */
23961 dwarf2out_decl (tree decl)
23963 dw_die_ref context_die = comp_unit_die ();
23965 switch (TREE_CODE (decl))
23970 case FUNCTION_DECL:
23971 /* What we would really like to do here is to filter out all mere
23972 file-scope declarations of file-scope functions which are never
23973 referenced later within this translation unit (and keep all of ones
23974 that *are* referenced later on) but we aren't clairvoyant, so we have
23975 no idea which functions will be referenced in the future (i.e. later
23976 on within the current translation unit). So here we just ignore all
23977 file-scope function declarations which are not also definitions. If
23978 and when the debugger needs to know something about these functions,
23979 it will have to hunt around and find the DWARF information associated
23980 with the definition of the function.
23982 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
23983 nodes represent definitions and which ones represent mere
23984 declarations. We have to check DECL_INITIAL instead. That's because
23985 the C front-end supports some weird semantics for "extern inline"
23986 function definitions. These can get inlined within the current
23987 translation unit (and thus, we need to generate Dwarf info for their
23988 abstract instances so that the Dwarf info for the concrete inlined
23989 instances can have something to refer to) but the compiler never
23990 generates any out-of-lines instances of such things (despite the fact
23991 that they *are* definitions).
23993 The important point is that the C front-end marks these "extern
23994 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
23995 them anyway. Note that the C++ front-end also plays some similar games
23996 for inline function definitions appearing within include files which
23997 also contain `#pragma interface' pragmas.
23999 If we are called from dwarf2out_abstract_function output a DIE
24000 anyway. We can end up here this way with early inlining and LTO
24001 where the inlined function is output in a different LTRANS unit
24003 if (DECL_INITIAL (decl) == NULL_TREE
24004 && ! DECL_ABSTRACT_P (decl))
24007 /* If we're a nested function, initially use a parent of NULL; if we're
24008 a plain function, this will be fixed up in decls_for_scope. If
24009 we're a method, it will be ignored, since we already have a DIE. */
24010 if (decl_function_context (decl)
24011 /* But if we're in terse mode, we don't care about scope. */
24012 && debug_info_level > DINFO_LEVEL_TERSE)
24013 context_die = NULL;
24017 /* For local statics lookup proper context die. */
24018 if (local_function_static (decl))
24019 context_die = lookup_decl_die (DECL_CONTEXT (decl));
24021 /* If we are in terse mode, don't generate any DIEs to represent any
24022 variable declarations or definitions. */
24023 if (debug_info_level <= DINFO_LEVEL_TERSE)
24028 if (debug_info_level <= DINFO_LEVEL_TERSE)
24030 if (!is_fortran () && !is_ada ())
24032 if (TREE_STATIC (decl) && decl_function_context (decl))
24033 context_die = lookup_decl_die (DECL_CONTEXT (decl));
24036 case NAMESPACE_DECL:
24037 case IMPORTED_DECL:
24038 if (debug_info_level <= DINFO_LEVEL_TERSE)
24040 if (lookup_decl_die (decl) != NULL)
24045 /* Don't emit stubs for types unless they are needed by other DIEs. */
24046 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
24049 /* Don't bother trying to generate any DIEs to represent any of the
24050 normal built-in types for the language we are compiling. */
24051 if (DECL_IS_BUILTIN (decl))
24054 /* If we are in terse mode, don't generate any DIEs for types. */
24055 if (debug_info_level <= DINFO_LEVEL_TERSE)
24058 /* If we're a function-scope tag, initially use a parent of NULL;
24059 this will be fixed up in decls_for_scope. */
24060 if (decl_function_context (decl))
24061 context_die = NULL;
24065 case NAMELIST_DECL:
24072 gen_decl_die (decl, NULL, NULL, context_die);
24076 dw_die_ref die = lookup_decl_die (decl);
24082 /* Write the debugging output for DECL. */
24085 dwarf2out_function_decl (tree decl)
24087 dwarf2out_decl (decl);
24088 call_arg_locations = NULL;
24089 call_arg_loc_last = NULL;
24090 call_site_count = -1;
24091 tail_call_site_count = -1;
24092 decl_loc_table->empty ();
24093 cached_dw_loc_list_table->empty ();
24096 /* Output a marker (i.e. a label) for the beginning of the generated code for
24097 a lexical block. */
24100 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
24101 unsigned int blocknum)
24103 switch_to_section (current_function_section ());
24104 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
24107 /* Output a marker (i.e. a label) for the end of the generated code for a
24111 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
24113 switch_to_section (current_function_section ());
24114 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
24117 /* Returns nonzero if it is appropriate not to emit any debugging
24118 information for BLOCK, because it doesn't contain any instructions.
24120 Don't allow this for blocks with nested functions or local classes
24121 as we would end up with orphans, and in the presence of scheduling
24122 we may end up calling them anyway. */
24125 dwarf2out_ignore_block (const_tree block)
24130 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
24131 if (TREE_CODE (decl) == FUNCTION_DECL
24132 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
24134 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
24136 decl = BLOCK_NONLOCALIZED_VAR (block, i);
24137 if (TREE_CODE (decl) == FUNCTION_DECL
24138 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
24145 /* Hash table routines for file_hash. */
24148 dwarf_file_hasher::equal (dwarf_file_data *p1, const char *p2)
24150 return filename_cmp (p1->filename, p2) == 0;
24154 dwarf_file_hasher::hash (dwarf_file_data *p)
24156 return htab_hash_string (p->filename);
24159 /* Lookup FILE_NAME (in the list of filenames that we know about here in
24160 dwarf2out.c) and return its "index". The index of each (known) filename is
24161 just a unique number which is associated with only that one filename. We
24162 need such numbers for the sake of generating labels (in the .debug_sfnames
24163 section) and references to those files numbers (in the .debug_srcinfo
24164 and .debug_macinfo sections). If the filename given as an argument is not
24165 found in our current list, add it to the list and assign it the next
24166 available unique index number. */
24168 static struct dwarf_file_data *
24169 lookup_filename (const char *file_name)
24171 struct dwarf_file_data * created;
24176 dwarf_file_data **slot
24177 = file_table->find_slot_with_hash (file_name, htab_hash_string (file_name),
24182 created = ggc_alloc<dwarf_file_data> ();
24183 created->filename = file_name;
24184 created->emitted_number = 0;
24189 /* If the assembler will construct the file table, then translate the compiler
24190 internal file table number into the assembler file table number, and emit
24191 a .file directive if we haven't already emitted one yet. The file table
24192 numbers are different because we prune debug info for unused variables and
24193 types, which may include filenames. */
24196 maybe_emit_file (struct dwarf_file_data * fd)
24198 if (! fd->emitted_number)
24200 if (last_emitted_file)
24201 fd->emitted_number = last_emitted_file->emitted_number + 1;
24203 fd->emitted_number = 1;
24204 last_emitted_file = fd;
24206 if (DWARF2_ASM_LINE_DEBUG_INFO)
24208 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
24209 output_quoted_string (asm_out_file,
24210 remap_debug_filename (fd->filename));
24211 fputc ('\n', asm_out_file);
24215 return fd->emitted_number;
24218 /* Schedule generation of a DW_AT_const_value attribute to DIE.
24219 That generation should happen after function debug info has been
24220 generated. The value of the attribute is the constant value of ARG. */
24223 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
24225 die_arg_entry entry;
24230 gcc_assert (early_dwarf);
24232 if (!tmpl_value_parm_die_table)
24233 vec_alloc (tmpl_value_parm_die_table, 32);
24237 vec_safe_push (tmpl_value_parm_die_table, entry);
24240 /* Return TRUE if T is an instance of generic type, FALSE
24244 generic_type_p (tree t)
24246 if (t == NULL_TREE || !TYPE_P (t))
24248 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
24251 /* Schedule the generation of the generic parameter dies for the
24252 instance of generic type T. The proper generation itself is later
24253 done by gen_scheduled_generic_parms_dies. */
24256 schedule_generic_params_dies_gen (tree t)
24258 if (!generic_type_p (t))
24261 gcc_assert (early_dwarf);
24263 if (!generic_type_instances)
24264 vec_alloc (generic_type_instances, 256);
24266 vec_safe_push (generic_type_instances, t);
24269 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
24270 by append_entry_to_tmpl_value_parm_die_table. This function must
24271 be called after function DIEs have been generated. */
24274 gen_remaining_tmpl_value_param_die_attribute (void)
24276 if (tmpl_value_parm_die_table)
24281 /* We do this in two phases - first get the cases we can
24282 handle during early-finish, preserving those we cannot
24283 (containing symbolic constants where we don't yet know
24284 whether we are going to output the referenced symbols).
24285 For those we try again at late-finish. */
24287 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table, i, e)
24289 if (!tree_add_const_value_attribute (e->die, e->arg))
24290 (*tmpl_value_parm_die_table)[j++] = *e;
24292 tmpl_value_parm_die_table->truncate (j);
24296 /* Generate generic parameters DIEs for instances of generic types
24297 that have been previously scheduled by
24298 schedule_generic_params_dies_gen. This function must be called
24299 after all the types of the CU have been laid out. */
24302 gen_scheduled_generic_parms_dies (void)
24307 if (!generic_type_instances)
24310 /* We end up "recursing" into schedule_generic_params_dies_gen, so
24311 pretend this generation is part of "early dwarf" as well. */
24314 FOR_EACH_VEC_ELT (*generic_type_instances, i, t)
24315 if (COMPLETE_TYPE_P (t))
24316 gen_generic_params_dies (t);
24318 generic_type_instances = NULL;
24322 /* Replace DW_AT_name for the decl with name. */
24325 dwarf2out_set_name (tree decl, tree name)
24328 dw_attr_node *attr;
24331 die = TYPE_SYMTAB_DIE (decl);
24335 dname = dwarf2_name (name, 0);
24339 attr = get_AT (die, DW_AT_name);
24342 struct indirect_string_node *node;
24344 node = find_AT_string (dname);
24345 /* replace the string. */
24346 attr->dw_attr_val.v.val_str = node;
24350 add_name_attribute (die, dname);
24353 /* True if before or during processing of the first function being emitted. */
24354 static bool in_first_function_p = true;
24355 /* True if loc_note during dwarf2out_var_location call might still be
24356 before first real instruction at address equal to .Ltext0. */
24357 static bool maybe_at_text_label_p = true;
24358 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
24359 static unsigned int first_loclabel_num_not_at_text_label;
24361 /* Called by the final INSN scan whenever we see a var location. We
24362 use it to drop labels in the right places, and throw the location in
24363 our lookup table. */
24366 dwarf2out_var_location (rtx_insn *loc_note)
24368 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
24369 struct var_loc_node *newloc;
24370 rtx_insn *next_real, *next_note;
24371 rtx_insn *call_insn = NULL;
24372 static const char *last_label;
24373 static const char *last_postcall_label;
24374 static bool last_in_cold_section_p;
24375 static rtx_insn *expected_next_loc_note;
24379 if (!NOTE_P (loc_note))
24381 if (CALL_P (loc_note))
24384 if (SIBLING_CALL_P (loc_note))
24385 tail_call_site_count++;
24386 if (optimize == 0 && !flag_var_tracking)
24388 /* When the var-tracking pass is not running, there is no note
24389 for indirect calls whose target is compile-time known. In this
24390 case, process such calls specifically so that we generate call
24391 sites for them anyway. */
24392 rtx x = PATTERN (loc_note);
24393 if (GET_CODE (x) == PARALLEL)
24394 x = XVECEXP (x, 0, 0);
24395 if (GET_CODE (x) == SET)
24397 if (GET_CODE (x) == CALL)
24400 || GET_CODE (XEXP (x, 0)) != SYMBOL_REF
24401 || !SYMBOL_REF_DECL (XEXP (x, 0))
24402 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x, 0)))
24405 call_insn = loc_note;
24409 next_real = next_real_insn (call_insn);
24411 cached_next_real_insn = NULL;
24419 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
24420 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
24423 /* Optimize processing a large consecutive sequence of location
24424 notes so we don't spend too much time in next_real_insn. If the
24425 next insn is another location note, remember the next_real_insn
24426 calculation for next time. */
24427 next_real = cached_next_real_insn;
24430 if (expected_next_loc_note != loc_note)
24434 next_note = NEXT_INSN (loc_note);
24436 || next_note->deleted ()
24437 || ! NOTE_P (next_note)
24438 || (NOTE_KIND (next_note) != NOTE_INSN_VAR_LOCATION
24439 && NOTE_KIND (next_note) != NOTE_INSN_CALL_ARG_LOCATION))
24443 next_real = next_real_insn (loc_note);
24447 expected_next_loc_note = next_note;
24448 cached_next_real_insn = next_real;
24451 cached_next_real_insn = NULL;
24453 /* If there are no instructions which would be affected by this note,
24454 don't do anything. */
24456 && next_real == NULL_RTX
24457 && !NOTE_DURING_CALL_P (loc_note))
24462 if (next_real == NULL_RTX)
24463 next_real = get_last_insn ();
24465 /* If there were any real insns between note we processed last time
24466 and this note (or if it is the first note), clear
24467 last_{,postcall_}label so that they are not reused this time. */
24468 if (last_var_location_insn == NULL_RTX
24469 || last_var_location_insn != next_real
24470 || last_in_cold_section_p != in_cold_section_p)
24473 last_postcall_label = NULL;
24478 decl = NOTE_VAR_LOCATION_DECL (loc_note);
24479 newloc = add_var_loc_to_decl (decl, loc_note,
24480 NOTE_DURING_CALL_P (loc_note)
24481 ? last_postcall_label : last_label);
24482 if (newloc == NULL)
24491 /* If there were no real insns between note we processed last time
24492 and this note, use the label we emitted last time. Otherwise
24493 create a new label and emit it. */
24494 if (last_label == NULL)
24496 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
24497 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
24499 last_label = ggc_strdup (loclabel);
24500 /* See if loclabel might be equal to .Ltext0. If yes,
24501 bump first_loclabel_num_not_at_text_label. */
24502 if (!have_multiple_function_sections
24503 && in_first_function_p
24504 && maybe_at_text_label_p)
24506 static rtx_insn *last_start;
24508 for (insn = loc_note; insn; insn = previous_insn (insn))
24509 if (insn == last_start)
24511 else if (!NONDEBUG_INSN_P (insn))
24515 rtx body = PATTERN (insn);
24516 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
24518 /* Inline asm could occupy zero bytes. */
24519 else if (GET_CODE (body) == ASM_INPUT
24520 || asm_noperands (body) >= 0)
24522 #ifdef HAVE_attr_length
24523 else if (get_attr_min_length (insn) == 0)
24528 /* Assume insn has non-zero length. */
24529 maybe_at_text_label_p = false;
24533 if (maybe_at_text_label_p)
24535 last_start = loc_note;
24536 first_loclabel_num_not_at_text_label = loclabel_num;
24541 gcc_assert ((loc_note == NULL_RTX && call_insn != NULL_RTX)
24542 || (loc_note != NULL_RTX && call_insn == NULL_RTX));
24546 struct call_arg_loc_node *ca_loc
24547 = ggc_cleared_alloc<call_arg_loc_node> ();
24549 = loc_note != NULL_RTX ? prev_real_insn (loc_note) : call_insn;
24551 ca_loc->call_arg_loc_note = loc_note;
24552 ca_loc->next = NULL;
24553 ca_loc->label = last_label;
24556 || (NONJUMP_INSN_P (prev)
24557 && GET_CODE (PATTERN (prev)) == SEQUENCE
24558 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
24559 if (!CALL_P (prev))
24560 prev = as_a <rtx_sequence *> (PATTERN (prev))->insn (0);
24561 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
24563 /* Look for a SYMBOL_REF in the "prev" instruction. */
24564 rtx x = get_call_rtx_from (PATTERN (prev));
24567 /* Try to get the call symbol, if any. */
24568 if (MEM_P (XEXP (x, 0)))
24570 /* First, look for a memory access to a symbol_ref. */
24571 if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
24572 && SYMBOL_REF_DECL (XEXP (x, 0))
24573 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x, 0))) == FUNCTION_DECL)
24574 ca_loc->symbol_ref = XEXP (x, 0);
24575 /* Otherwise, look at a compile-time known user-level function
24579 && TREE_CODE (MEM_EXPR (x)) == FUNCTION_DECL)
24580 ca_loc->symbol_ref = XEXP (DECL_RTL (MEM_EXPR (x)), 0);
24583 ca_loc->block = insn_scope (prev);
24584 if (call_arg_locations)
24585 call_arg_loc_last->next = ca_loc;
24587 call_arg_locations = ca_loc;
24588 call_arg_loc_last = ca_loc;
24590 else if (loc_note != NULL_RTX && !NOTE_DURING_CALL_P (loc_note))
24591 newloc->label = last_label;
24594 if (!last_postcall_label)
24596 sprintf (loclabel, "%s-1", last_label);
24597 last_postcall_label = ggc_strdup (loclabel);
24599 newloc->label = last_postcall_label;
24602 last_var_location_insn = next_real;
24603 last_in_cold_section_p = in_cold_section_p;
24606 /* Called from finalize_size_functions for size functions so that their body
24607 can be encoded in the debug info to describe the layout of variable-length
24611 dwarf2out_size_function (tree decl)
24613 function_to_dwarf_procedure (decl);
24616 /* Note in one location list that text section has changed. */
24619 var_location_switch_text_section_1 (var_loc_list **slot, void *)
24621 var_loc_list *list = *slot;
24623 list->last_before_switch
24624 = list->last->next ? list->last->next : list->last;
24628 /* Note in all location lists that text section has changed. */
24631 var_location_switch_text_section (void)
24633 if (decl_loc_table == NULL)
24636 decl_loc_table->traverse<void *, var_location_switch_text_section_1> (NULL);
24639 /* Create a new line number table. */
24641 static dw_line_info_table *
24642 new_line_info_table (void)
24644 dw_line_info_table *table;
24646 table = ggc_cleared_alloc<dw_line_info_table> ();
24647 table->file_num = 1;
24648 table->line_num = 1;
24649 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
24654 /* Lookup the "current" table into which we emit line info, so
24655 that we don't have to do it for every source line. */
24658 set_cur_line_info_table (section *sec)
24660 dw_line_info_table *table;
24662 if (sec == text_section)
24663 table = text_section_line_info;
24664 else if (sec == cold_text_section)
24666 table = cold_text_section_line_info;
24669 cold_text_section_line_info = table = new_line_info_table ();
24670 table->end_label = cold_end_label;
24675 const char *end_label;
24677 if (flag_reorder_blocks_and_partition)
24679 if (in_cold_section_p)
24680 end_label = crtl->subsections.cold_section_end_label;
24682 end_label = crtl->subsections.hot_section_end_label;
24686 char label[MAX_ARTIFICIAL_LABEL_BYTES];
24687 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
24688 current_function_funcdef_no);
24689 end_label = ggc_strdup (label);
24692 table = new_line_info_table ();
24693 table->end_label = end_label;
24695 vec_safe_push (separate_line_info, table);
24698 if (DWARF2_ASM_LINE_DEBUG_INFO)
24699 table->is_stmt = (cur_line_info_table
24700 ? cur_line_info_table->is_stmt
24701 : DWARF_LINE_DEFAULT_IS_STMT_START);
24702 cur_line_info_table = table;
24706 /* We need to reset the locations at the beginning of each
24707 function. We can't do this in the end_function hook, because the
24708 declarations that use the locations won't have been output when
24709 that hook is called. Also compute have_multiple_function_sections here. */
24712 dwarf2out_begin_function (tree fun)
24714 section *sec = function_section (fun);
24716 if (sec != text_section)
24717 have_multiple_function_sections = true;
24719 if (flag_reorder_blocks_and_partition && !cold_text_section)
24721 gcc_assert (current_function_decl == fun);
24722 cold_text_section = unlikely_text_section ();
24723 switch_to_section (cold_text_section);
24724 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
24725 switch_to_section (sec);
24728 dwarf2out_note_section_used ();
24729 call_site_count = 0;
24730 tail_call_site_count = 0;
24732 set_cur_line_info_table (sec);
24735 /* Helper function of dwarf2out_end_function, called only after emitting
24736 the very first function into assembly. Check if some .debug_loc range
24737 might end with a .LVL* label that could be equal to .Ltext0.
24738 In that case we must force using absolute addresses in .debug_loc ranges,
24739 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
24740 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
24742 Set have_multiple_function_sections to true in that case and
24743 terminate htab traversal. */
24746 find_empty_loc_ranges_at_text_label (var_loc_list **slot, int)
24748 var_loc_list *entry = *slot;
24749 struct var_loc_node *node;
24751 node = entry->first;
24752 if (node && node->next && node->next->label)
24755 const char *label = node->next->label;
24756 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
24758 for (i = 0; i < first_loclabel_num_not_at_text_label; i++)
24760 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", i);
24761 if (strcmp (label, loclabel) == 0)
24763 have_multiple_function_sections = true;
24771 /* Hook called after emitting a function into assembly.
24772 This does something only for the very first function emitted. */
24775 dwarf2out_end_function (unsigned int)
24777 if (in_first_function_p
24778 && !have_multiple_function_sections
24779 && first_loclabel_num_not_at_text_label
24781 decl_loc_table->traverse<int, find_empty_loc_ranges_at_text_label> (0);
24782 in_first_function_p = false;
24783 maybe_at_text_label_p = false;
24786 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
24787 front-ends register a translation unit even before dwarf2out_init is
24789 static tree main_translation_unit = NULL_TREE;
24791 /* Hook called by front-ends after they built their main translation unit.
24792 Associate comp_unit_die to UNIT. */
24795 dwarf2out_register_main_translation_unit (tree unit)
24797 gcc_assert (TREE_CODE (unit) == TRANSLATION_UNIT_DECL
24798 && main_translation_unit == NULL_TREE);
24799 main_translation_unit = unit;
24800 /* If dwarf2out_init has not been called yet, it will perform the association
24801 itself looking at main_translation_unit. */
24802 if (decl_die_table != NULL)
24803 equate_decl_number_to_die (unit, comp_unit_die ());
24806 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
24809 push_dw_line_info_entry (dw_line_info_table *table,
24810 enum dw_line_info_opcode opcode, unsigned int val)
24812 dw_line_info_entry e;
24815 vec_safe_push (table->entries, e);
24818 /* Output a label to mark the beginning of a source code line entry
24819 and record information relating to this source line, in
24820 'line_info_table' for later output of the .debug_line section. */
24821 /* ??? The discriminator parameter ought to be unsigned. */
24824 dwarf2out_source_line (unsigned int line, const char *filename,
24825 int discriminator, bool is_stmt)
24827 unsigned int file_num;
24828 dw_line_info_table *table;
24830 if (debug_info_level < DINFO_LEVEL_TERSE || line == 0)
24833 /* The discriminator column was added in dwarf4. Simplify the below
24834 by simply removing it if we're not supposed to output it. */
24835 if (dwarf_version < 4 && dwarf_strict)
24838 table = cur_line_info_table;
24839 file_num = maybe_emit_file (lookup_filename (filename));
24841 /* ??? TODO: Elide duplicate line number entries. Traditionally,
24842 the debugger has used the second (possibly duplicate) line number
24843 at the beginning of the function to mark the end of the prologue.
24844 We could eliminate any other duplicates within the function. For
24845 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
24846 that second line number entry. */
24847 /* Recall that this end-of-prologue indication is *not* the same thing
24848 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
24849 to which the hook corresponds, follows the last insn that was
24850 emitted by gen_prologue. What we need is to precede the first insn
24851 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
24852 insn that corresponds to something the user wrote. These may be
24853 very different locations once scheduling is enabled. */
24855 if (0 && file_num == table->file_num
24856 && line == table->line_num
24857 && discriminator == table->discrim_num
24858 && is_stmt == table->is_stmt)
24861 switch_to_section (current_function_section ());
24863 /* If requested, emit something human-readable. */
24864 if (flag_debug_asm)
24865 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
24867 if (DWARF2_ASM_LINE_DEBUG_INFO)
24869 /* Emit the .loc directive understood by GNU as. */
24870 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
24871 file_num, line, is_stmt, discriminator */
24872 fputs ("\t.loc ", asm_out_file);
24873 fprint_ul (asm_out_file, file_num);
24874 putc (' ', asm_out_file);
24875 fprint_ul (asm_out_file, line);
24876 putc (' ', asm_out_file);
24877 putc ('0', asm_out_file);
24879 if (is_stmt != table->is_stmt)
24881 fputs (" is_stmt ", asm_out_file);
24882 putc (is_stmt ? '1' : '0', asm_out_file);
24884 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
24886 gcc_assert (discriminator > 0);
24887 fputs (" discriminator ", asm_out_file);
24888 fprint_ul (asm_out_file, (unsigned long) discriminator);
24890 putc ('\n', asm_out_file);
24894 unsigned int label_num = ++line_info_label_num;
24896 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
24898 push_dw_line_info_entry (table, LI_set_address, label_num);
24899 if (file_num != table->file_num)
24900 push_dw_line_info_entry (table, LI_set_file, file_num);
24901 if (discriminator != table->discrim_num)
24902 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
24903 if (is_stmt != table->is_stmt)
24904 push_dw_line_info_entry (table, LI_negate_stmt, 0);
24905 push_dw_line_info_entry (table, LI_set_line, line);
24908 table->file_num = file_num;
24909 table->line_num = line;
24910 table->discrim_num = discriminator;
24911 table->is_stmt = is_stmt;
24912 table->in_use = true;
24915 /* Record the beginning of a new source file. */
24918 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
24920 if (flag_eliminate_dwarf2_dups)
24922 /* Record the beginning of the file for break_out_includes. */
24923 dw_die_ref bincl_die;
24925 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
24926 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
24929 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
24932 e.code = DW_MACINFO_start_file;
24934 e.info = ggc_strdup (filename);
24935 vec_safe_push (macinfo_table, e);
24939 /* Record the end of a source file. */
24942 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
24944 if (flag_eliminate_dwarf2_dups)
24945 /* Record the end of the file for break_out_includes. */
24946 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
24948 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
24951 e.code = DW_MACINFO_end_file;
24954 vec_safe_push (macinfo_table, e);
24958 /* Called from debug_define in toplev.c. The `buffer' parameter contains
24959 the tail part of the directive line, i.e. the part which is past the
24960 initial whitespace, #, whitespace, directive-name, whitespace part. */
24963 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
24964 const char *buffer ATTRIBUTE_UNUSED)
24966 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
24969 /* Insert a dummy first entry to be able to optimize the whole
24970 predefined macro block using DW_MACRO_GNU_transparent_include. */
24971 if (macinfo_table->is_empty () && lineno <= 1)
24976 vec_safe_push (macinfo_table, e);
24978 e.code = DW_MACINFO_define;
24980 e.info = ggc_strdup (buffer);
24981 vec_safe_push (macinfo_table, e);
24985 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
24986 the tail part of the directive line, i.e. the part which is past the
24987 initial whitespace, #, whitespace, directive-name, whitespace part. */
24990 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
24991 const char *buffer ATTRIBUTE_UNUSED)
24993 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
24996 /* Insert a dummy first entry to be able to optimize the whole
24997 predefined macro block using DW_MACRO_GNU_transparent_include. */
24998 if (macinfo_table->is_empty () && lineno <= 1)
25003 vec_safe_push (macinfo_table, e);
25005 e.code = DW_MACINFO_undef;
25007 e.info = ggc_strdup (buffer);
25008 vec_safe_push (macinfo_table, e);
25012 /* Helpers to manipulate hash table of CUs. */
25014 struct macinfo_entry_hasher : nofree_ptr_hash <macinfo_entry>
25016 static inline hashval_t hash (const macinfo_entry *);
25017 static inline bool equal (const macinfo_entry *, const macinfo_entry *);
25021 macinfo_entry_hasher::hash (const macinfo_entry *entry)
25023 return htab_hash_string (entry->info);
25027 macinfo_entry_hasher::equal (const macinfo_entry *entry1,
25028 const macinfo_entry *entry2)
25030 return !strcmp (entry1->info, entry2->info);
25033 typedef hash_table<macinfo_entry_hasher> macinfo_hash_type;
25035 /* Output a single .debug_macinfo entry. */
25038 output_macinfo_op (macinfo_entry *ref)
25042 struct indirect_string_node *node;
25043 char label[MAX_ARTIFICIAL_LABEL_BYTES];
25044 struct dwarf_file_data *fd;
25048 case DW_MACINFO_start_file:
25049 fd = lookup_filename (ref->info);
25050 file_num = maybe_emit_file (fd);
25051 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
25052 dw2_asm_output_data_uleb128 (ref->lineno,
25053 "Included from line number %lu",
25054 (unsigned long) ref->lineno);
25055 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
25057 case DW_MACINFO_end_file:
25058 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
25060 case DW_MACINFO_define:
25061 case DW_MACINFO_undef:
25062 len = strlen (ref->info) + 1;
25064 && len > DWARF_OFFSET_SIZE
25065 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
25066 && (debug_str_section->common.flags & SECTION_MERGE) != 0)
25068 ref->code = ref->code == DW_MACINFO_define
25069 ? DW_MACRO_GNU_define_indirect
25070 : DW_MACRO_GNU_undef_indirect;
25071 output_macinfo_op (ref);
25074 dw2_asm_output_data (1, ref->code,
25075 ref->code == DW_MACINFO_define
25076 ? "Define macro" : "Undefine macro");
25077 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
25078 (unsigned long) ref->lineno);
25079 dw2_asm_output_nstring (ref->info, -1, "The macro");
25081 case DW_MACRO_GNU_define_indirect:
25082 case DW_MACRO_GNU_undef_indirect:
25083 node = find_AT_string (ref->info);
25085 && ((node->form == DW_FORM_strp)
25086 || (node->form == DW_FORM_GNU_str_index)));
25087 dw2_asm_output_data (1, ref->code,
25088 ref->code == DW_MACRO_GNU_define_indirect
25089 ? "Define macro indirect"
25090 : "Undefine macro indirect");
25091 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
25092 (unsigned long) ref->lineno);
25093 if (node->form == DW_FORM_strp)
25094 dw2_asm_output_offset (DWARF_OFFSET_SIZE, node->label,
25095 debug_str_section, "The macro: \"%s\"",
25098 dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
25101 case DW_MACRO_GNU_transparent_include:
25102 dw2_asm_output_data (1, ref->code, "Transparent include");
25103 ASM_GENERATE_INTERNAL_LABEL (label,
25104 DEBUG_MACRO_SECTION_LABEL, ref->lineno);
25105 dw2_asm_output_offset (DWARF_OFFSET_SIZE, label, NULL, NULL);
25108 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
25109 ASM_COMMENT_START, (unsigned long) ref->code);
25114 /* Attempt to make a sequence of define/undef macinfo ops shareable with
25115 other compilation unit .debug_macinfo sections. IDX is the first
25116 index of a define/undef, return the number of ops that should be
25117 emitted in a comdat .debug_macinfo section and emit
25118 a DW_MACRO_GNU_transparent_include entry referencing it.
25119 If the define/undef entry should be emitted normally, return 0. */
25122 optimize_macinfo_range (unsigned int idx, vec<macinfo_entry, va_gc> *files,
25123 macinfo_hash_type **macinfo_htab)
25125 macinfo_entry *first, *second, *cur, *inc;
25126 char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1];
25127 unsigned char checksum[16];
25128 struct md5_ctx ctx;
25129 char *grp_name, *tail;
25131 unsigned int i, count, encoded_filename_len, linebuf_len;
25132 macinfo_entry **slot;
25134 first = &(*macinfo_table)[idx];
25135 second = &(*macinfo_table)[idx + 1];
25137 /* Optimize only if there are at least two consecutive define/undef ops,
25138 and either all of them are before first DW_MACINFO_start_file
25139 with lineno {0,1} (i.e. predefined macro block), or all of them are
25140 in some included header file. */
25141 if (second->code != DW_MACINFO_define && second->code != DW_MACINFO_undef)
25143 if (vec_safe_is_empty (files))
25145 if (first->lineno > 1 || second->lineno > 1)
25148 else if (first->lineno == 0)
25151 /* Find the last define/undef entry that can be grouped together
25152 with first and at the same time compute md5 checksum of their
25153 codes, linenumbers and strings. */
25154 md5_init_ctx (&ctx);
25155 for (i = idx; macinfo_table->iterate (i, &cur); i++)
25156 if (cur->code != DW_MACINFO_define && cur->code != DW_MACINFO_undef)
25158 else if (vec_safe_is_empty (files) && cur->lineno > 1)
25162 unsigned char code = cur->code;
25163 md5_process_bytes (&code, 1, &ctx);
25164 checksum_uleb128 (cur->lineno, &ctx);
25165 md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx);
25167 md5_finish_ctx (&ctx, checksum);
25170 /* From the containing include filename (if any) pick up just
25171 usable characters from its basename. */
25172 if (vec_safe_is_empty (files))
25175 base = lbasename (files->last ().info);
25176 for (encoded_filename_len = 0, i = 0; base[i]; i++)
25177 if (ISIDNUM (base[i]) || base[i] == '.')
25178 encoded_filename_len++;
25179 /* Count . at the end. */
25180 if (encoded_filename_len)
25181 encoded_filename_len++;
25183 sprintf (linebuf, HOST_WIDE_INT_PRINT_UNSIGNED, first->lineno);
25184 linebuf_len = strlen (linebuf);
25186 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
25187 grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
25189 memcpy (grp_name, DWARF_OFFSET_SIZE == 4 ? "wm4." : "wm8.", 4);
25190 tail = grp_name + 4;
25191 if (encoded_filename_len)
25193 for (i = 0; base[i]; i++)
25194 if (ISIDNUM (base[i]) || base[i] == '.')
25198 memcpy (tail, linebuf, linebuf_len);
25199 tail += linebuf_len;
25201 for (i = 0; i < 16; i++)
25202 sprintf (tail + i * 2, "%02x", checksum[i] & 0xff);
25204 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
25205 in the empty vector entry before the first define/undef. */
25206 inc = &(*macinfo_table)[idx - 1];
25207 inc->code = DW_MACRO_GNU_transparent_include;
25209 inc->info = ggc_strdup (grp_name);
25210 if (!*macinfo_htab)
25211 *macinfo_htab = new macinfo_hash_type (10);
25212 /* Avoid emitting duplicates. */
25213 slot = (*macinfo_htab)->find_slot (inc, INSERT);
25218 /* If such an entry has been used before, just emit
25219 a DW_MACRO_GNU_transparent_include op. */
25221 output_macinfo_op (inc);
25222 /* And clear all macinfo_entry in the range to avoid emitting them
25223 in the second pass. */
25224 for (i = idx; macinfo_table->iterate (i, &cur) && i < idx + count; i++)
25233 inc->lineno = (*macinfo_htab)->elements ();
25234 output_macinfo_op (inc);
25239 /* Save any strings needed by the macinfo table in the debug str
25240 table. All strings must be collected into the table by the time
25241 index_string is called. */
25244 save_macinfo_strings (void)
25248 macinfo_entry *ref;
25250 for (i = 0; macinfo_table && macinfo_table->iterate (i, &ref); i++)
25254 /* Match the logic in output_macinfo_op to decide on
25255 indirect strings. */
25256 case DW_MACINFO_define:
25257 case DW_MACINFO_undef:
25258 len = strlen (ref->info) + 1;
25260 && len > DWARF_OFFSET_SIZE
25261 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
25262 && (debug_str_section->common.flags & SECTION_MERGE) != 0)
25263 set_indirect_string (find_AT_string (ref->info));
25265 case DW_MACRO_GNU_define_indirect:
25266 case DW_MACRO_GNU_undef_indirect:
25267 set_indirect_string (find_AT_string (ref->info));
25275 /* Output macinfo section(s). */
25278 output_macinfo (void)
25281 unsigned long length = vec_safe_length (macinfo_table);
25282 macinfo_entry *ref;
25283 vec<macinfo_entry, va_gc> *files = NULL;
25284 macinfo_hash_type *macinfo_htab = NULL;
25289 /* output_macinfo* uses these interchangeably. */
25290 gcc_assert ((int) DW_MACINFO_define == (int) DW_MACRO_GNU_define
25291 && (int) DW_MACINFO_undef == (int) DW_MACRO_GNU_undef
25292 && (int) DW_MACINFO_start_file == (int) DW_MACRO_GNU_start_file
25293 && (int) DW_MACINFO_end_file == (int) DW_MACRO_GNU_end_file);
25295 /* For .debug_macro emit the section header. */
25298 dw2_asm_output_data (2, 4, "DWARF macro version number");
25299 if (DWARF_OFFSET_SIZE == 8)
25300 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
25302 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
25303 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
25304 (!dwarf_split_debug_info ? debug_line_section_label
25305 : debug_skeleton_line_section_label),
25306 debug_line_section, NULL);
25309 /* In the first loop, it emits the primary .debug_macinfo section
25310 and after each emitted op the macinfo_entry is cleared.
25311 If a longer range of define/undef ops can be optimized using
25312 DW_MACRO_GNU_transparent_include, the
25313 DW_MACRO_GNU_transparent_include op is emitted and kept in
25314 the vector before the first define/undef in the range and the
25315 whole range of define/undef ops is not emitted and kept. */
25316 for (i = 0; macinfo_table->iterate (i, &ref); i++)
25320 case DW_MACINFO_start_file:
25321 vec_safe_push (files, *ref);
25323 case DW_MACINFO_end_file:
25324 if (!vec_safe_is_empty (files))
25327 case DW_MACINFO_define:
25328 case DW_MACINFO_undef:
25330 && HAVE_COMDAT_GROUP
25331 && vec_safe_length (files) != 1
25334 && (*macinfo_table)[i - 1].code == 0)
25336 unsigned count = optimize_macinfo_range (i, files, &macinfo_htab);
25345 /* A dummy entry may be inserted at the beginning to be able
25346 to optimize the whole block of predefined macros. */
25352 output_macinfo_op (ref);
25360 delete macinfo_htab;
25361 macinfo_htab = NULL;
25363 /* If any DW_MACRO_GNU_transparent_include were used, on those
25364 DW_MACRO_GNU_transparent_include entries terminate the
25365 current chain and switch to a new comdat .debug_macinfo
25366 section and emit the define/undef entries within it. */
25367 for (i = 0; macinfo_table->iterate (i, &ref); i++)
25372 case DW_MACRO_GNU_transparent_include:
25374 char label[MAX_ARTIFICIAL_LABEL_BYTES];
25375 tree comdat_key = get_identifier (ref->info);
25376 /* Terminate the previous .debug_macinfo section. */
25377 dw2_asm_output_data (1, 0, "End compilation unit");
25378 targetm.asm_out.named_section (DEBUG_MACRO_SECTION,
25380 | SECTION_LINKONCE,
25382 ASM_GENERATE_INTERNAL_LABEL (label,
25383 DEBUG_MACRO_SECTION_LABEL,
25385 ASM_OUTPUT_LABEL (asm_out_file, label);
25388 dw2_asm_output_data (2, 4, "DWARF macro version number");
25389 if (DWARF_OFFSET_SIZE == 8)
25390 dw2_asm_output_data (1, 1, "Flags: 64-bit");
25392 dw2_asm_output_data (1, 0, "Flags: 32-bit");
25395 case DW_MACINFO_define:
25396 case DW_MACINFO_undef:
25397 output_macinfo_op (ref);
25402 gcc_unreachable ();
25406 /* Set up for Dwarf output at the start of compilation. */
25409 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
25411 /* This option is currently broken, see (PR53118 and PR46102). */
25412 if (flag_eliminate_dwarf2_dups
25413 && strstr (lang_hooks.name, "C++"))
25415 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
25416 flag_eliminate_dwarf2_dups = 0;
25419 /* Allocate the file_table. */
25420 file_table = hash_table<dwarf_file_hasher>::create_ggc (50);
25422 #ifndef DWARF2_LINENO_DEBUGGING_INFO
25423 /* Allocate the decl_die_table. */
25424 decl_die_table = hash_table<decl_die_hasher>::create_ggc (10);
25426 /* Allocate the decl_loc_table. */
25427 decl_loc_table = hash_table<decl_loc_hasher>::create_ggc (10);
25429 /* Allocate the cached_dw_loc_list_table. */
25430 cached_dw_loc_list_table = hash_table<dw_loc_list_hasher>::create_ggc (10);
25432 /* Allocate the initial hunk of the decl_scope_table. */
25433 vec_alloc (decl_scope_table, 256);
25435 /* Allocate the initial hunk of the abbrev_die_table. */
25436 abbrev_die_table = ggc_cleared_vec_alloc<dw_die_ref>
25437 (ABBREV_DIE_TABLE_INCREMENT);
25438 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
25439 /* Zero-th entry is allocated, but unused. */
25440 abbrev_die_table_in_use = 1;
25442 /* Allocate the dwarf_proc_stack_usage_map. */
25443 dwarf_proc_stack_usage_map = new hash_map<dw_die_ref, int>;
25445 /* Allocate the pubtypes and pubnames vectors. */
25446 vec_alloc (pubname_table, 32);
25447 vec_alloc (pubtype_table, 32);
25449 vec_alloc (incomplete_types, 64);
25451 vec_alloc (used_rtx_array, 32);
25453 if (!dwarf_split_debug_info)
25455 debug_info_section = get_section (DEBUG_INFO_SECTION,
25456 SECTION_DEBUG, NULL);
25457 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
25458 SECTION_DEBUG, NULL);
25459 debug_loc_section = get_section (DEBUG_LOC_SECTION,
25460 SECTION_DEBUG, NULL);
25464 debug_info_section = get_section (DEBUG_DWO_INFO_SECTION,
25465 SECTION_DEBUG | SECTION_EXCLUDE, NULL);
25466 debug_abbrev_section = get_section (DEBUG_DWO_ABBREV_SECTION,
25467 SECTION_DEBUG | SECTION_EXCLUDE,
25469 debug_addr_section = get_section (DEBUG_ADDR_SECTION,
25470 SECTION_DEBUG, NULL);
25471 debug_skeleton_info_section = get_section (DEBUG_INFO_SECTION,
25472 SECTION_DEBUG, NULL);
25473 debug_skeleton_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
25474 SECTION_DEBUG, NULL);
25475 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
25476 DEBUG_SKELETON_ABBREV_SECTION_LABEL, 0);
25478 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
25479 the main .o, but the skeleton_line goes into the split off dwo. */
25480 debug_skeleton_line_section
25481 = get_section (DEBUG_DWO_LINE_SECTION,
25482 SECTION_DEBUG | SECTION_EXCLUDE, NULL);
25483 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
25484 DEBUG_SKELETON_LINE_SECTION_LABEL, 0);
25485 debug_str_offsets_section = get_section (DEBUG_STR_OFFSETS_SECTION,
25486 SECTION_DEBUG | SECTION_EXCLUDE,
25488 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
25489 DEBUG_SKELETON_INFO_SECTION_LABEL, 0);
25490 debug_loc_section = get_section (DEBUG_DWO_LOC_SECTION,
25491 SECTION_DEBUG | SECTION_EXCLUDE, NULL);
25492 debug_str_dwo_section = get_section (DEBUG_STR_DWO_SECTION,
25493 DEBUG_STR_DWO_SECTION_FLAGS, NULL);
25495 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
25496 SECTION_DEBUG, NULL);
25497 debug_macinfo_section = get_section (dwarf_strict
25498 ? DEBUG_MACINFO_SECTION
25499 : DEBUG_MACRO_SECTION,
25500 DEBUG_MACRO_SECTION_FLAGS, NULL);
25501 debug_line_section = get_section (DEBUG_LINE_SECTION,
25502 SECTION_DEBUG, NULL);
25503 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
25504 SECTION_DEBUG, NULL);
25505 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
25506 SECTION_DEBUG, NULL);
25507 debug_str_section = get_section (DEBUG_STR_SECTION,
25508 DEBUG_STR_SECTION_FLAGS, NULL);
25509 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
25510 SECTION_DEBUG, NULL);
25511 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
25512 SECTION_DEBUG, NULL);
25514 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
25515 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
25516 DEBUG_ABBREV_SECTION_LABEL, 0);
25517 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
25518 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
25519 COLD_TEXT_SECTION_LABEL, 0);
25520 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
25522 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
25523 DEBUG_INFO_SECTION_LABEL, 0);
25524 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
25525 DEBUG_LINE_SECTION_LABEL, 0);
25526 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
25527 DEBUG_RANGES_SECTION_LABEL, 0);
25528 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label,
25529 DEBUG_ADDR_SECTION_LABEL, 0);
25530 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
25532 ? DEBUG_MACINFO_SECTION_LABEL
25533 : DEBUG_MACRO_SECTION_LABEL, 0);
25534 ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0);
25536 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
25537 vec_alloc (macinfo_table, 64);
25539 switch_to_section (text_section);
25540 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
25543 /* Make sure the line number table for .text always exists. */
25544 text_section_line_info = new_line_info_table ();
25545 text_section_line_info->end_label = text_end_label;
25547 #ifdef DWARF2_LINENO_DEBUGGING_INFO
25548 cur_line_info_table = text_section_line_info;
25551 /* If front-ends already registered a main translation unit but we were not
25552 ready to perform the association, do this now. */
25553 if (main_translation_unit != NULL_TREE)
25554 equate_decl_number_to_die (main_translation_unit, comp_unit_die ());
25557 /* Called before compile () starts outputtting functions, variables
25558 and toplevel asms into assembly. */
25561 dwarf2out_assembly_start (void)
25563 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
25564 && dwarf2out_do_cfi_asm ()
25565 && (!(flag_unwind_tables || flag_exceptions)
25566 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
25567 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
25570 /* A helper function for dwarf2out_finish called through
25571 htab_traverse. Assign a string its index. All strings must be
25572 collected into the table by the time index_string is called,
25573 because the indexing code relies on htab_traverse to traverse nodes
25574 in the same order for each run. */
25577 index_string (indirect_string_node **h, unsigned int *index)
25579 indirect_string_node *node = *h;
25581 find_string_form (node);
25582 if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
25584 gcc_assert (node->index == NO_INDEX_ASSIGNED);
25585 node->index = *index;
25591 /* A helper function for output_indirect_strings called through
25592 htab_traverse. Output the offset to a string and update the
25596 output_index_string_offset (indirect_string_node **h, unsigned int *offset)
25598 indirect_string_node *node = *h;
25600 if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
25602 /* Assert that this node has been assigned an index. */
25603 gcc_assert (node->index != NO_INDEX_ASSIGNED
25604 && node->index != NOT_INDEXED);
25605 dw2_asm_output_data (DWARF_OFFSET_SIZE, *offset,
25606 "indexed string 0x%x: %s", node->index, node->str);
25607 *offset += strlen (node->str) + 1;
25612 /* A helper function for dwarf2out_finish called through
25613 htab_traverse. Output the indexed string. */
25616 output_index_string (indirect_string_node **h, unsigned int *cur_idx)
25618 struct indirect_string_node *node = *h;
25620 if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
25622 /* Assert that the strings are output in the same order as their
25623 indexes were assigned. */
25624 gcc_assert (*cur_idx == node->index);
25625 assemble_string (node->str, strlen (node->str) + 1);
25631 /* A helper function for dwarf2out_finish called through
25632 htab_traverse. Emit one queued .debug_str string. */
25635 output_indirect_string (indirect_string_node **h, void *)
25637 struct indirect_string_node *node = *h;
25639 node->form = find_string_form (node);
25640 if (node->form == DW_FORM_strp && node->refcount > 0)
25642 ASM_OUTPUT_LABEL (asm_out_file, node->label);
25643 assemble_string (node->str, strlen (node->str) + 1);
25649 /* Output the indexed string table. */
25652 output_indirect_strings (void)
25654 switch_to_section (debug_str_section);
25655 if (!dwarf_split_debug_info)
25656 debug_str_hash->traverse<void *, output_indirect_string> (NULL);
25659 unsigned int offset = 0;
25660 unsigned int cur_idx = 0;
25662 skeleton_debug_str_hash->traverse<void *, output_indirect_string> (NULL);
25664 switch_to_section (debug_str_offsets_section);
25665 debug_str_hash->traverse_noresize
25666 <unsigned int *, output_index_string_offset> (&offset);
25667 switch_to_section (debug_str_dwo_section);
25668 debug_str_hash->traverse_noresize<unsigned int *, output_index_string>
25673 /* Callback for htab_traverse to assign an index to an entry in the
25674 table, and to write that entry to the .debug_addr section. */
25677 output_addr_table_entry (addr_table_entry **slot, unsigned int *cur_index)
25679 addr_table_entry *entry = *slot;
25681 if (entry->refcount == 0)
25683 gcc_assert (entry->index == NO_INDEX_ASSIGNED
25684 || entry->index == NOT_INDEXED);
25688 gcc_assert (entry->index == *cur_index);
25691 switch (entry->kind)
25694 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, entry->addr.rtl,
25695 "0x%x", entry->index);
25697 case ate_kind_rtx_dtprel:
25698 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
25699 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
25702 fputc ('\n', asm_out_file);
25704 case ate_kind_label:
25705 dw2_asm_output_addr (DWARF2_ADDR_SIZE, entry->addr.label,
25706 "0x%x", entry->index);
25709 gcc_unreachable ();
25714 /* Produce the .debug_addr section. */
25717 output_addr_table (void)
25719 unsigned int index = 0;
25720 if (addr_index_table == NULL || addr_index_table->size () == 0)
25723 switch_to_section (debug_addr_section);
25725 ->traverse_noresize<unsigned int *, output_addr_table_entry> (&index);
25728 #if ENABLE_ASSERT_CHECKING
25729 /* Verify that all marks are clear. */
25732 verify_marks_clear (dw_die_ref die)
25736 gcc_assert (! die->die_mark);
25737 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
25739 #endif /* ENABLE_ASSERT_CHECKING */
25741 /* Clear the marks for a die and its children.
25742 Be cool if the mark isn't set. */
25745 prune_unmark_dies (dw_die_ref die)
25751 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
25754 /* Given LOC that is referenced by a DIE we're marking as used, find all
25755 referenced DWARF procedures it references and mark them as used. */
25758 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc)
25760 for (; loc != NULL; loc = loc->dw_loc_next)
25761 switch (loc->dw_loc_opc)
25763 case DW_OP_GNU_implicit_pointer:
25764 case DW_OP_GNU_convert:
25765 case DW_OP_GNU_reinterpret:
25766 if (loc->dw_loc_oprnd1.val_class == dw_val_class_die_ref)
25767 prune_unused_types_mark (loc->dw_loc_oprnd1.v.val_die_ref.die, 1);
25771 case DW_OP_call_ref:
25772 case DW_OP_GNU_const_type:
25773 case DW_OP_GNU_parameter_ref:
25774 gcc_assert (loc->dw_loc_oprnd1.val_class == dw_val_class_die_ref);
25775 prune_unused_types_mark (loc->dw_loc_oprnd1.v.val_die_ref.die, 1);
25777 case DW_OP_GNU_regval_type:
25778 case DW_OP_GNU_deref_type:
25779 gcc_assert (loc->dw_loc_oprnd2.val_class == dw_val_class_die_ref);
25780 prune_unused_types_mark (loc->dw_loc_oprnd2.v.val_die_ref.die, 1);
25782 case DW_OP_GNU_entry_value:
25783 gcc_assert (loc->dw_loc_oprnd1.val_class == dw_val_class_loc);
25784 prune_unused_types_walk_loc_descr (loc->dw_loc_oprnd1.v.val_loc);
25791 /* Given DIE that we're marking as used, find any other dies
25792 it references as attributes and mark them as used. */
25795 prune_unused_types_walk_attribs (dw_die_ref die)
25800 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
25802 switch (AT_class (a))
25804 /* Make sure DWARF procedures referenced by location descriptions will
25806 case dw_val_class_loc:
25807 prune_unused_types_walk_loc_descr (AT_loc (a));
25809 case dw_val_class_loc_list:
25810 for (dw_loc_list_ref list = AT_loc_list (a);
25812 list = list->dw_loc_next)
25813 prune_unused_types_walk_loc_descr (list->expr);
25816 case dw_val_class_die_ref:
25817 /* A reference to another DIE.
25818 Make sure that it will get emitted.
25819 If it was broken out into a comdat group, don't follow it. */
25820 if (! AT_ref (a)->comdat_type_p
25821 || a->dw_attr == DW_AT_specification)
25822 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
25825 case dw_val_class_str:
25826 /* Set the string's refcount to 0 so that prune_unused_types_mark
25827 accounts properly for it. */
25828 a->dw_attr_val.v.val_str->refcount = 0;
25837 /* Mark the generic parameters and arguments children DIEs of DIE. */
25840 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
25844 if (die == NULL || die->die_child == NULL)
25846 c = die->die_child;
25849 if (is_template_parameter (c))
25850 prune_unused_types_mark (c, 1);
25852 } while (c && c != die->die_child);
25855 /* Mark DIE as being used. If DOKIDS is true, then walk down
25856 to DIE's children. */
25859 prune_unused_types_mark (dw_die_ref die, int dokids)
25863 if (die->die_mark == 0)
25865 /* We haven't done this node yet. Mark it as used. */
25867 /* If this is the DIE of a generic type instantiation,
25868 mark the children DIEs that describe its generic parms and
25870 prune_unused_types_mark_generic_parms_dies (die);
25872 /* We also have to mark its parents as used.
25873 (But we don't want to mark our parent's kids due to this,
25874 unless it is a class.) */
25875 if (die->die_parent)
25876 prune_unused_types_mark (die->die_parent,
25877 class_scope_p (die->die_parent));
25879 /* Mark any referenced nodes. */
25880 prune_unused_types_walk_attribs (die);
25882 /* If this node is a specification,
25883 also mark the definition, if it exists. */
25884 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
25885 prune_unused_types_mark (die->die_definition, 1);
25888 if (dokids && die->die_mark != 2)
25890 /* We need to walk the children, but haven't done so yet.
25891 Remember that we've walked the kids. */
25894 /* If this is an array type, we need to make sure our
25895 kids get marked, even if they're types. If we're
25896 breaking out types into comdat sections, do this
25897 for all type definitions. */
25898 if (die->die_tag == DW_TAG_array_type
25899 || (use_debug_types
25900 && is_type_die (die) && ! is_declaration_die (die)))
25901 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
25903 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
25907 /* For local classes, look if any static member functions were emitted
25908 and if so, mark them. */
25911 prune_unused_types_walk_local_classes (dw_die_ref die)
25915 if (die->die_mark == 2)
25918 switch (die->die_tag)
25920 case DW_TAG_structure_type:
25921 case DW_TAG_union_type:
25922 case DW_TAG_class_type:
25925 case DW_TAG_subprogram:
25926 if (!get_AT_flag (die, DW_AT_declaration)
25927 || die->die_definition != NULL)
25928 prune_unused_types_mark (die, 1);
25935 /* Mark children. */
25936 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
25939 /* Walk the tree DIE and mark types that we actually use. */
25942 prune_unused_types_walk (dw_die_ref die)
25946 /* Don't do anything if this node is already marked and
25947 children have been marked as well. */
25948 if (die->die_mark == 2)
25951 switch (die->die_tag)
25953 case DW_TAG_structure_type:
25954 case DW_TAG_union_type:
25955 case DW_TAG_class_type:
25956 if (die->die_perennial_p)
25959 for (c = die->die_parent; c; c = c->die_parent)
25960 if (c->die_tag == DW_TAG_subprogram)
25963 /* Finding used static member functions inside of classes
25964 is needed just for local classes, because for other classes
25965 static member function DIEs with DW_AT_specification
25966 are emitted outside of the DW_TAG_*_type. If we ever change
25967 it, we'd need to call this even for non-local classes. */
25969 prune_unused_types_walk_local_classes (die);
25971 /* It's a type node --- don't mark it. */
25974 case DW_TAG_const_type:
25975 case DW_TAG_packed_type:
25976 case DW_TAG_pointer_type:
25977 case DW_TAG_reference_type:
25978 case DW_TAG_rvalue_reference_type:
25979 case DW_TAG_volatile_type:
25980 case DW_TAG_typedef:
25981 case DW_TAG_array_type:
25982 case DW_TAG_interface_type:
25983 case DW_TAG_friend:
25984 case DW_TAG_enumeration_type:
25985 case DW_TAG_subroutine_type:
25986 case DW_TAG_string_type:
25987 case DW_TAG_set_type:
25988 case DW_TAG_subrange_type:
25989 case DW_TAG_ptr_to_member_type:
25990 case DW_TAG_file_type:
25991 /* Type nodes are useful only when other DIEs reference them --- don't
25995 case DW_TAG_dwarf_procedure:
25996 /* Likewise for DWARF procedures. */
25998 if (die->die_perennial_p)
26004 /* Mark everything else. */
26008 if (die->die_mark == 0)
26012 /* Now, mark any dies referenced from here. */
26013 prune_unused_types_walk_attribs (die);
26018 /* Mark children. */
26019 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
26022 /* Increment the string counts on strings referred to from DIE's
26026 prune_unused_types_update_strings (dw_die_ref die)
26031 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
26032 if (AT_class (a) == dw_val_class_str)
26034 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
26036 /* Avoid unnecessarily putting strings that are used less than
26037 twice in the hash table. */
26039 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
26041 indirect_string_node **slot
26042 = debug_str_hash->find_slot_with_hash (s->str,
26043 htab_hash_string (s->str),
26045 gcc_assert (*slot == NULL);
26051 /* Remove from the tree DIE any dies that aren't marked. */
26054 prune_unused_types_prune (dw_die_ref die)
26058 gcc_assert (die->die_mark);
26059 prune_unused_types_update_strings (die);
26061 if (! die->die_child)
26064 c = die->die_child;
26066 dw_die_ref prev = c;
26067 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
26068 if (c == die->die_child)
26070 /* No marked children between 'prev' and the end of the list. */
26072 /* No marked children at all. */
26073 die->die_child = NULL;
26076 prev->die_sib = c->die_sib;
26077 die->die_child = prev;
26082 if (c != prev->die_sib)
26084 prune_unused_types_prune (c);
26085 } while (c != die->die_child);
26088 /* Remove dies representing declarations that we never use. */
26091 prune_unused_types (void)
26094 limbo_die_node *node;
26095 comdat_type_node *ctnode;
26096 pubname_entry *pub;
26097 dw_die_ref base_type;
26099 #if ENABLE_ASSERT_CHECKING
26100 /* All the marks should already be clear. */
26101 verify_marks_clear (comp_unit_die ());
26102 for (node = limbo_die_list; node; node = node->next)
26103 verify_marks_clear (node->die);
26104 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
26105 verify_marks_clear (ctnode->root_die);
26106 #endif /* ENABLE_ASSERT_CHECKING */
26108 /* Mark types that are used in global variables. */
26109 premark_types_used_by_global_vars ();
26111 /* Set the mark on nodes that are actually used. */
26112 prune_unused_types_walk (comp_unit_die ());
26113 for (node = limbo_die_list; node; node = node->next)
26114 prune_unused_types_walk (node->die);
26115 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
26117 prune_unused_types_walk (ctnode->root_die);
26118 prune_unused_types_mark (ctnode->type_die, 1);
26121 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
26122 are unusual in that they are pubnames that are the children of pubtypes.
26123 They should only be marked via their parent DW_TAG_enumeration_type die,
26124 not as roots in themselves. */
26125 FOR_EACH_VEC_ELT (*pubname_table, i, pub)
26126 if (pub->die->die_tag != DW_TAG_enumerator)
26127 prune_unused_types_mark (pub->die, 1);
26128 for (i = 0; base_types.iterate (i, &base_type); i++)
26129 prune_unused_types_mark (base_type, 1);
26131 if (debug_str_hash)
26132 debug_str_hash->empty ();
26133 if (skeleton_debug_str_hash)
26134 skeleton_debug_str_hash->empty ();
26135 prune_unused_types_prune (comp_unit_die ());
26136 for (limbo_die_node **pnode = &limbo_die_list; *pnode; )
26139 if (!node->die->die_mark)
26140 *pnode = node->next;
26143 prune_unused_types_prune (node->die);
26144 pnode = &node->next;
26147 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
26148 prune_unused_types_prune (ctnode->root_die);
26150 /* Leave the marks clear. */
26151 prune_unmark_dies (comp_unit_die ());
26152 for (node = limbo_die_list; node; node = node->next)
26153 prune_unmark_dies (node->die);
26154 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
26155 prune_unmark_dies (ctnode->root_die);
26158 /* Set the parameter to true if there are any relative pathnames in
26161 file_table_relative_p (dwarf_file_data **slot, bool *p)
26163 struct dwarf_file_data *d = *slot;
26164 if (!IS_ABSOLUTE_PATH (d->filename))
26172 /* Helpers to manipulate hash table of comdat type units. */
26174 struct comdat_type_hasher : nofree_ptr_hash <comdat_type_node>
26176 static inline hashval_t hash (const comdat_type_node *);
26177 static inline bool equal (const comdat_type_node *, const comdat_type_node *);
26181 comdat_type_hasher::hash (const comdat_type_node *type_node)
26184 memcpy (&h, type_node->signature, sizeof (h));
26189 comdat_type_hasher::equal (const comdat_type_node *type_node_1,
26190 const comdat_type_node *type_node_2)
26192 return (! memcmp (type_node_1->signature, type_node_2->signature,
26193 DWARF_TYPE_SIGNATURE_SIZE));
26196 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
26197 to the location it would have been added, should we know its
26198 DECL_ASSEMBLER_NAME when we added other attributes. This will
26199 probably improve compactness of debug info, removing equivalent
26200 abbrevs, and hide any differences caused by deferring the
26201 computation of the assembler name, triggered by e.g. PCH. */
26204 move_linkage_attr (dw_die_ref die)
26206 unsigned ix = vec_safe_length (die->die_attr);
26207 dw_attr_node linkage = (*die->die_attr)[ix - 1];
26209 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
26210 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
26214 dw_attr_node *prev = &(*die->die_attr)[ix - 1];
26216 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
26220 if (ix != vec_safe_length (die->die_attr) - 1)
26222 die->die_attr->pop ();
26223 die->die_attr->quick_insert (ix, linkage);
26227 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
26228 referenced from typed stack ops and count how often they are used. */
26231 mark_base_types (dw_loc_descr_ref loc)
26233 dw_die_ref base_type = NULL;
26235 for (; loc; loc = loc->dw_loc_next)
26237 switch (loc->dw_loc_opc)
26239 case DW_OP_GNU_regval_type:
26240 case DW_OP_GNU_deref_type:
26241 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
26243 case DW_OP_GNU_convert:
26244 case DW_OP_GNU_reinterpret:
26245 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
26248 case DW_OP_GNU_const_type:
26249 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
26251 case DW_OP_GNU_entry_value:
26252 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
26257 gcc_assert (base_type->die_parent == comp_unit_die ());
26258 if (base_type->die_mark)
26259 base_type->die_mark++;
26262 base_types.safe_push (base_type);
26263 base_type->die_mark = 1;
26268 /* Comparison function for sorting marked base types. */
26271 base_type_cmp (const void *x, const void *y)
26273 dw_die_ref dx = *(const dw_die_ref *) x;
26274 dw_die_ref dy = *(const dw_die_ref *) y;
26275 unsigned int byte_size1, byte_size2;
26276 unsigned int encoding1, encoding2;
26277 if (dx->die_mark > dy->die_mark)
26279 if (dx->die_mark < dy->die_mark)
26281 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
26282 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
26283 if (byte_size1 < byte_size2)
26285 if (byte_size1 > byte_size2)
26287 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
26288 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
26289 if (encoding1 < encoding2)
26291 if (encoding1 > encoding2)
26296 /* Move base types marked by mark_base_types as early as possible
26297 in the CU, sorted by decreasing usage count both to make the
26298 uleb128 references as small as possible and to make sure they
26299 will have die_offset already computed by calc_die_sizes when
26300 sizes of typed stack loc ops is computed. */
26303 move_marked_base_types (void)
26306 dw_die_ref base_type, die, c;
26308 if (base_types.is_empty ())
26311 /* Sort by decreasing usage count, they will be added again in that
26313 base_types.qsort (base_type_cmp);
26314 die = comp_unit_die ();
26315 c = die->die_child;
26318 dw_die_ref prev = c;
26320 while (c->die_mark)
26322 remove_child_with_prev (c, prev);
26323 /* As base types got marked, there must be at least
26324 one node other than DW_TAG_base_type. */
26325 gcc_assert (c != c->die_sib);
26329 while (c != die->die_child);
26330 gcc_assert (die->die_child);
26331 c = die->die_child;
26332 for (i = 0; base_types.iterate (i, &base_type); i++)
26334 base_type->die_mark = 0;
26335 base_type->die_sib = c->die_sib;
26336 c->die_sib = base_type;
26341 /* Helper function for resolve_addr, attempt to resolve
26342 one CONST_STRING, return true if successful. Similarly verify that
26343 SYMBOL_REFs refer to variables emitted in the current CU. */
26346 resolve_one_addr (rtx *addr)
26350 if (GET_CODE (rtl) == CONST_STRING)
26352 size_t len = strlen (XSTR (rtl, 0)) + 1;
26353 tree t = build_string (len, XSTR (rtl, 0));
26354 tree tlen = size_int (len - 1);
26356 = build_array_type (char_type_node, build_index_type (tlen));
26357 rtl = lookup_constant_def (t);
26358 if (!rtl || !MEM_P (rtl))
26360 rtl = XEXP (rtl, 0);
26361 if (GET_CODE (rtl) == SYMBOL_REF
26362 && SYMBOL_REF_DECL (rtl)
26363 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
26365 vec_safe_push (used_rtx_array, rtl);
26370 if (GET_CODE (rtl) == SYMBOL_REF
26371 && SYMBOL_REF_DECL (rtl))
26373 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
26375 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
26378 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
26382 if (GET_CODE (rtl) == CONST)
26384 subrtx_ptr_iterator::array_type array;
26385 FOR_EACH_SUBRTX_PTR (iter, array, &XEXP (rtl, 0), ALL)
26386 if (!resolve_one_addr (*iter))
26393 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
26394 if possible, and create DW_TAG_dwarf_procedure that can be referenced
26395 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
26398 string_cst_pool_decl (tree t)
26400 rtx rtl = output_constant_def (t, 1);
26401 unsigned char *array;
26402 dw_loc_descr_ref l;
26407 if (!rtl || !MEM_P (rtl))
26409 rtl = XEXP (rtl, 0);
26410 if (GET_CODE (rtl) != SYMBOL_REF
26411 || SYMBOL_REF_DECL (rtl) == NULL_TREE)
26414 decl = SYMBOL_REF_DECL (rtl);
26415 if (!lookup_decl_die (decl))
26417 len = TREE_STRING_LENGTH (t);
26418 vec_safe_push (used_rtx_array, rtl);
26419 ref = new_die (DW_TAG_dwarf_procedure, comp_unit_die (), decl);
26420 array = ggc_vec_alloc<unsigned char> (len);
26421 memcpy (array, TREE_STRING_POINTER (t), len);
26422 l = new_loc_descr (DW_OP_implicit_value, len, 0);
26423 l->dw_loc_oprnd2.val_class = dw_val_class_vec;
26424 l->dw_loc_oprnd2.v.val_vec.length = len;
26425 l->dw_loc_oprnd2.v.val_vec.elt_size = 1;
26426 l->dw_loc_oprnd2.v.val_vec.array = array;
26427 add_AT_loc (ref, DW_AT_location, l);
26428 equate_decl_number_to_die (decl, ref);
26433 /* Helper function of resolve_addr_in_expr. LOC is
26434 a DW_OP_addr followed by DW_OP_stack_value, either at the start
26435 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
26436 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
26437 with DW_OP_GNU_implicit_pointer if possible
26438 and return true, if unsuccessful, return false. */
26441 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc)
26443 rtx rtl = loc->dw_loc_oprnd1.v.val_addr;
26444 HOST_WIDE_INT offset = 0;
26445 dw_die_ref ref = NULL;
26448 if (GET_CODE (rtl) == CONST
26449 && GET_CODE (XEXP (rtl, 0)) == PLUS
26450 && CONST_INT_P (XEXP (XEXP (rtl, 0), 1)))
26452 offset = INTVAL (XEXP (XEXP (rtl, 0), 1));
26453 rtl = XEXP (XEXP (rtl, 0), 0);
26455 if (GET_CODE (rtl) == CONST_STRING)
26457 size_t len = strlen (XSTR (rtl, 0)) + 1;
26458 tree t = build_string (len, XSTR (rtl, 0));
26459 tree tlen = size_int (len - 1);
26462 = build_array_type (char_type_node, build_index_type (tlen));
26463 rtl = string_cst_pool_decl (t);
26467 if (GET_CODE (rtl) == SYMBOL_REF && SYMBOL_REF_DECL (rtl))
26469 decl = SYMBOL_REF_DECL (rtl);
26470 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
26472 ref = lookup_decl_die (decl);
26473 if (ref && (get_AT (ref, DW_AT_location)
26474 || get_AT (ref, DW_AT_const_value)))
26476 loc->dw_loc_opc = DW_OP_GNU_implicit_pointer;
26477 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
26478 loc->dw_loc_oprnd1.val_entry = NULL;
26479 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
26480 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
26481 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
26482 loc->dw_loc_oprnd2.v.val_int = offset;
26490 /* Helper function for resolve_addr, handle one location
26491 expression, return false if at least one CONST_STRING or SYMBOL_REF in
26492 the location list couldn't be resolved. */
26495 resolve_addr_in_expr (dw_loc_descr_ref loc)
26497 dw_loc_descr_ref keep = NULL;
26498 for (dw_loc_descr_ref prev = NULL; loc; prev = loc, loc = loc->dw_loc_next)
26499 switch (loc->dw_loc_opc)
26502 if (!resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
26505 || prev->dw_loc_opc == DW_OP_piece
26506 || prev->dw_loc_opc == DW_OP_bit_piece)
26507 && loc->dw_loc_next
26508 && loc->dw_loc_next->dw_loc_opc == DW_OP_stack_value
26510 && optimize_one_addr_into_implicit_ptr (loc))
26515 case DW_OP_GNU_addr_index:
26516 case DW_OP_GNU_const_index:
26517 if (loc->dw_loc_opc == DW_OP_GNU_addr_index
26518 || (loc->dw_loc_opc == DW_OP_GNU_const_index && loc->dtprel))
26520 rtx rtl = loc->dw_loc_oprnd1.val_entry->addr.rtl;
26521 if (!resolve_one_addr (&rtl))
26523 remove_addr_table_entry (loc->dw_loc_oprnd1.val_entry);
26524 loc->dw_loc_oprnd1.val_entry =
26525 add_addr_table_entry (rtl, ate_kind_rtx);
26528 case DW_OP_const4u:
26529 case DW_OP_const8u:
26531 && !resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
26534 case DW_OP_plus_uconst:
26535 if (size_of_loc_descr (loc)
26536 > size_of_int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned)
26538 && loc->dw_loc_oprnd1.v.val_unsigned > 0)
26540 dw_loc_descr_ref repl
26541 = int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned);
26542 add_loc_descr (&repl, new_loc_descr (DW_OP_plus, 0, 0));
26543 add_loc_descr (&repl, loc->dw_loc_next);
26547 case DW_OP_implicit_value:
26548 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
26549 && !resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr))
26552 case DW_OP_GNU_implicit_pointer:
26553 case DW_OP_GNU_parameter_ref:
26554 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
26557 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
26560 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
26561 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
26562 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
26565 case DW_OP_GNU_const_type:
26566 case DW_OP_GNU_regval_type:
26567 case DW_OP_GNU_deref_type:
26568 case DW_OP_GNU_convert:
26569 case DW_OP_GNU_reinterpret:
26570 while (loc->dw_loc_next
26571 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
26573 dw_die_ref base1, base2;
26574 unsigned enc1, enc2, size1, size2;
26575 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
26576 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
26577 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
26578 else if (loc->dw_loc_oprnd1.val_class
26579 == dw_val_class_unsigned_const)
26582 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
26583 if (loc->dw_loc_next->dw_loc_oprnd1.val_class
26584 == dw_val_class_unsigned_const)
26586 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
26587 gcc_assert (base1->die_tag == DW_TAG_base_type
26588 && base2->die_tag == DW_TAG_base_type);
26589 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
26590 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
26591 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
26592 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
26594 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
26595 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
26599 /* Optimize away next DW_OP_GNU_convert after
26600 adjusting LOC's base type die reference. */
26601 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
26602 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
26603 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
26605 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
26606 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
26609 /* Don't change integer DW_OP_GNU_convert after e.g. floating
26610 point typed stack entry. */
26611 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
26612 keep = loc->dw_loc_next;
26622 /* Helper function of resolve_addr. DIE had DW_AT_location of
26623 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
26624 and DW_OP_addr couldn't be resolved. resolve_addr has already
26625 removed the DW_AT_location attribute. This function attempts to
26626 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
26627 to it or DW_AT_const_value attribute, if possible. */
26630 optimize_location_into_implicit_ptr (dw_die_ref die, tree decl)
26632 if (TREE_CODE (decl) != VAR_DECL
26633 || lookup_decl_die (decl) != die
26634 || DECL_EXTERNAL (decl)
26635 || !TREE_STATIC (decl)
26636 || DECL_INITIAL (decl) == NULL_TREE
26637 || DECL_P (DECL_INITIAL (decl))
26638 || get_AT (die, DW_AT_const_value))
26641 tree init = DECL_INITIAL (decl);
26642 HOST_WIDE_INT offset = 0;
26643 /* For variables that have been optimized away and thus
26644 don't have a memory location, see if we can emit
26645 DW_AT_const_value instead. */
26646 if (tree_add_const_value_attribute (die, init))
26650 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
26651 and ADDR_EXPR refers to a decl that has DW_AT_location or
26652 DW_AT_const_value (but isn't addressable, otherwise
26653 resolving the original DW_OP_addr wouldn't fail), see if
26654 we can add DW_OP_GNU_implicit_pointer. */
26656 if (TREE_CODE (init) == POINTER_PLUS_EXPR
26657 && tree_fits_shwi_p (TREE_OPERAND (init, 1)))
26659 offset = tree_to_shwi (TREE_OPERAND (init, 1));
26660 init = TREE_OPERAND (init, 0);
26663 if (TREE_CODE (init) != ADDR_EXPR)
26665 if ((TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST
26666 && !TREE_ASM_WRITTEN (TREE_OPERAND (init, 0)))
26667 || (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL
26668 && !DECL_EXTERNAL (TREE_OPERAND (init, 0))
26669 && TREE_OPERAND (init, 0) != decl))
26672 dw_loc_descr_ref l;
26674 if (TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST)
26676 rtx rtl = string_cst_pool_decl (TREE_OPERAND (init, 0));
26679 decl = SYMBOL_REF_DECL (rtl);
26682 decl = TREE_OPERAND (init, 0);
26683 ref = lookup_decl_die (decl);
26685 || (!get_AT (ref, DW_AT_location)
26686 && !get_AT (ref, DW_AT_const_value)))
26688 l = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
26689 l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
26690 l->dw_loc_oprnd1.v.val_die_ref.die = ref;
26691 l->dw_loc_oprnd1.v.val_die_ref.external = 0;
26692 add_AT_loc (die, DW_AT_location, l);
26696 /* Return NULL if l is a DWARF expression, or first op that is not
26697 valid DWARF expression. */
26699 static dw_loc_descr_ref
26700 non_dwarf_expression (dw_loc_descr_ref l)
26704 if (l->dw_loc_opc >= DW_OP_reg0 && l->dw_loc_opc <= DW_OP_reg31)
26706 switch (l->dw_loc_opc)
26709 case DW_OP_implicit_value:
26710 case DW_OP_stack_value:
26711 case DW_OP_GNU_implicit_pointer:
26712 case DW_OP_GNU_parameter_ref:
26714 case DW_OP_bit_piece:
26719 l = l->dw_loc_next;
26724 /* Return adjusted copy of EXPR:
26725 If it is empty DWARF expression, return it.
26726 If it is valid non-empty DWARF expression,
26727 return copy of EXPR with copy of DEREF appended to it.
26728 If it is DWARF expression followed by DW_OP_reg{N,x}, return
26729 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended
26731 If it is DWARF expression followed by DW_OP_stack_value, return
26732 copy of the DWARF expression without anything appended.
26733 Otherwise, return NULL. */
26735 static dw_loc_descr_ref
26736 copy_deref_exprloc (dw_loc_descr_ref expr, dw_loc_descr_ref deref)
26742 dw_loc_descr_ref l = non_dwarf_expression (expr);
26743 if (l && l->dw_loc_next)
26748 if (l->dw_loc_opc >= DW_OP_reg0 && l->dw_loc_opc <= DW_OP_reg31)
26749 deref = new_loc_descr ((enum dwarf_location_atom)
26750 (DW_OP_breg0 + (l->dw_loc_opc - DW_OP_reg0)),
26753 switch (l->dw_loc_opc)
26756 deref = new_loc_descr (DW_OP_bregx,
26757 l->dw_loc_oprnd1.v.val_unsigned, 0);
26759 case DW_OP_stack_value:
26767 deref = new_loc_descr (deref->dw_loc_opc,
26768 deref->dw_loc_oprnd1.v.val_int, 0);
26770 dw_loc_descr_ref ret = NULL, *p = &ret;
26773 *p = new_loc_descr (expr->dw_loc_opc, 0, 0);
26774 (*p)->dw_loc_oprnd1 = expr->dw_loc_oprnd1;
26775 (*p)->dw_loc_oprnd2 = expr->dw_loc_oprnd2;
26776 p = &(*p)->dw_loc_next;
26777 expr = expr->dw_loc_next;
26783 /* For DW_AT_string_length attribute with DW_OP_call4 reference to a variable
26784 or argument, adjust it if needed and return:
26785 -1 if the DW_AT_string_length attribute and DW_AT_byte_size attribute
26786 if present should be removed
26787 0 keep the attribute as is if the referenced var or argument has
26788 only DWARF expression that covers all ranges
26789 1 if the attribute has been successfully adjusted. */
26792 optimize_string_length (dw_attr_node *a)
26794 dw_loc_descr_ref l = AT_loc (a), lv;
26795 dw_die_ref die = l->dw_loc_oprnd1.v.val_die_ref.die;
26796 dw_attr_node *av = get_AT (die, DW_AT_location);
26798 bool non_dwarf_expr = false;
26802 switch (AT_class (av))
26804 case dw_val_class_loc_list:
26805 for (d = AT_loc_list (av); d != NULL; d = d->dw_loc_next)
26806 if (d->expr && non_dwarf_expression (d->expr))
26807 non_dwarf_expr = true;
26809 case dw_val_class_loc:
26813 if (non_dwarf_expression (lv))
26814 non_dwarf_expr = true;
26820 /* If it is safe to keep DW_OP_call4 in, keep it. */
26821 if (!non_dwarf_expr
26822 && (l->dw_loc_next == NULL || AT_class (av) == dw_val_class_loc))
26825 /* If not dereferencing the DW_OP_call4 afterwards, we can just
26826 copy over the DW_AT_location attribute from die to a. */
26827 if (l->dw_loc_next == NULL)
26829 a->dw_attr_val = av->dw_attr_val;
26833 dw_loc_list_ref list, *p;
26834 switch (AT_class (av))
26836 case dw_val_class_loc_list:
26839 for (d = AT_loc_list (av); d != NULL; d = d->dw_loc_next)
26841 lv = copy_deref_exprloc (d->expr, l->dw_loc_next);
26844 *p = new_loc_list (lv, d->begin, d->end, d->section);
26845 p = &(*p)->dw_loc_next;
26850 a->dw_attr_val.val_class = dw_val_class_loc_list;
26852 *AT_loc_list_ptr (a) = list;
26854 case dw_val_class_loc:
26855 lv = copy_deref_exprloc (AT_loc (av), l->dw_loc_next);
26858 a->dw_attr_val.v.val_loc = lv;
26861 gcc_unreachable ();
26865 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
26866 an address in .rodata section if the string literal is emitted there,
26867 or remove the containing location list or replace DW_AT_const_value
26868 with DW_AT_location and empty location expression, if it isn't found
26869 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
26870 to something that has been emitted in the current CU. */
26873 resolve_addr (dw_die_ref die)
26877 dw_loc_list_ref *curr, *start, loc;
26879 bool remove_AT_byte_size = false;
26881 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
26882 switch (AT_class (a))
26884 case dw_val_class_loc_list:
26885 start = curr = AT_loc_list_ptr (a);
26888 /* The same list can be referenced more than once. See if we have
26889 already recorded the result from a previous pass. */
26891 *curr = loc->dw_loc_next;
26892 else if (!loc->resolved_addr)
26894 /* As things stand, we do not expect or allow one die to
26895 reference a suffix of another die's location list chain.
26896 References must be identical or completely separate.
26897 There is therefore no need to cache the result of this
26898 pass on any list other than the first; doing so
26899 would lead to unnecessary writes. */
26902 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
26903 if (!resolve_addr_in_expr ((*curr)->expr))
26905 dw_loc_list_ref next = (*curr)->dw_loc_next;
26906 dw_loc_descr_ref l = (*curr)->expr;
26908 if (next && (*curr)->ll_symbol)
26910 gcc_assert (!next->ll_symbol);
26911 next->ll_symbol = (*curr)->ll_symbol;
26913 if (dwarf_split_debug_info)
26914 remove_loc_list_addr_table_entries (l);
26919 mark_base_types ((*curr)->expr);
26920 curr = &(*curr)->dw_loc_next;
26924 loc->resolved_addr = 1;
26928 loc->dw_loc_next = *start;
26933 remove_AT (die, a->dw_attr);
26937 case dw_val_class_loc:
26939 dw_loc_descr_ref l = AT_loc (a);
26940 /* Using DW_OP_call4 or DW_OP_call4 DW_OP_deref in
26941 DW_AT_string_length is only a rough approximation; unfortunately
26942 DW_AT_string_length can't be a reference to a DIE. DW_OP_call4
26943 needs a DWARF expression, while DW_AT_location of the referenced
26944 variable or argument might be any location description. */
26945 if (a->dw_attr == DW_AT_string_length
26947 && l->dw_loc_opc == DW_OP_call4
26948 && l->dw_loc_oprnd1.val_class == dw_val_class_die_ref
26949 && (l->dw_loc_next == NULL
26950 || (l->dw_loc_next->dw_loc_next == NULL
26951 && (l->dw_loc_next->dw_loc_opc == DW_OP_deref
26952 || l->dw_loc_next->dw_loc_opc != DW_OP_deref_size))))
26954 switch (optimize_string_length (a))
26957 remove_AT (die, a->dw_attr);
26959 /* For DWARF4 and earlier, if we drop DW_AT_string_length,
26960 we need to drop also DW_AT_byte_size. */
26961 remove_AT_byte_size = true;
26966 /* Even if we keep the optimized DW_AT_string_length,
26967 it might have changed AT_class, so process it again. */
26972 /* For -gdwarf-2 don't attempt to optimize
26973 DW_AT_data_member_location containing
26974 DW_OP_plus_uconst - older consumers might
26975 rely on it being that op instead of a more complex,
26976 but shorter, location description. */
26977 if ((dwarf_version > 2
26978 || a->dw_attr != DW_AT_data_member_location
26980 || l->dw_loc_opc != DW_OP_plus_uconst
26981 || l->dw_loc_next != NULL)
26982 && !resolve_addr_in_expr (l))
26984 if (dwarf_split_debug_info)
26985 remove_loc_list_addr_table_entries (l);
26987 && l->dw_loc_next == NULL
26988 && l->dw_loc_opc == DW_OP_addr
26989 && GET_CODE (l->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF
26990 && SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr)
26991 && a->dw_attr == DW_AT_location)
26993 tree decl = SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr);
26994 remove_AT (die, a->dw_attr);
26996 optimize_location_into_implicit_ptr (die, decl);
26999 remove_AT (die, a->dw_attr);
27003 mark_base_types (l);
27006 case dw_val_class_addr:
27007 if (a->dw_attr == DW_AT_const_value
27008 && !resolve_one_addr (&a->dw_attr_val.v.val_addr))
27010 if (AT_index (a) != NOT_INDEXED)
27011 remove_addr_table_entry (a->dw_attr_val.val_entry);
27012 remove_AT (die, a->dw_attr);
27015 if (die->die_tag == DW_TAG_GNU_call_site
27016 && a->dw_attr == DW_AT_abstract_origin)
27018 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
27019 dw_die_ref tdie = lookup_decl_die (tdecl);
27022 && DECL_EXTERNAL (tdecl)
27023 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE
27024 && (cdie = lookup_context_die (DECL_CONTEXT (tdecl))))
27026 /* Creating a full DIE for tdecl is overly expensive and
27027 at this point even wrong when in the LTO phase
27028 as it can end up generating new type DIEs we didn't
27029 output and thus optimize_external_refs will crash. */
27030 tdie = new_die (DW_TAG_subprogram, cdie, NULL_TREE);
27031 add_AT_flag (tdie, DW_AT_external, 1);
27032 add_AT_flag (tdie, DW_AT_declaration, 1);
27033 add_linkage_attr (tdie, tdecl);
27034 add_name_and_src_coords_attributes (tdie, tdecl);
27035 equate_decl_number_to_die (tdecl, tdie);
27039 a->dw_attr_val.val_class = dw_val_class_die_ref;
27040 a->dw_attr_val.v.val_die_ref.die = tdie;
27041 a->dw_attr_val.v.val_die_ref.external = 0;
27045 if (AT_index (a) != NOT_INDEXED)
27046 remove_addr_table_entry (a->dw_attr_val.val_entry);
27047 remove_AT (die, a->dw_attr);
27056 if (remove_AT_byte_size)
27057 remove_AT (die, DW_AT_byte_size);
27059 FOR_EACH_CHILD (die, c, resolve_addr (c));
27062 /* Helper routines for optimize_location_lists.
27063 This pass tries to share identical local lists in .debug_loc
27066 /* Iteratively hash operands of LOC opcode into HSTATE. */
27069 hash_loc_operands (dw_loc_descr_ref loc, inchash::hash &hstate)
27071 dw_val_ref val1 = &loc->dw_loc_oprnd1;
27072 dw_val_ref val2 = &loc->dw_loc_oprnd2;
27074 switch (loc->dw_loc_opc)
27076 case DW_OP_const4u:
27077 case DW_OP_const8u:
27081 case DW_OP_const1u:
27082 case DW_OP_const1s:
27083 case DW_OP_const2u:
27084 case DW_OP_const2s:
27085 case DW_OP_const4s:
27086 case DW_OP_const8s:
27090 case DW_OP_plus_uconst:
27126 case DW_OP_deref_size:
27127 case DW_OP_xderef_size:
27128 hstate.add_object (val1->v.val_int);
27135 gcc_assert (val1->val_class == dw_val_class_loc);
27136 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
27137 hstate.add_object (offset);
27140 case DW_OP_implicit_value:
27141 hstate.add_object (val1->v.val_unsigned);
27142 switch (val2->val_class)
27144 case dw_val_class_const:
27145 hstate.add_object (val2->v.val_int);
27147 case dw_val_class_vec:
27149 unsigned int elt_size = val2->v.val_vec.elt_size;
27150 unsigned int len = val2->v.val_vec.length;
27152 hstate.add_int (elt_size);
27153 hstate.add_int (len);
27154 hstate.add (val2->v.val_vec.array, len * elt_size);
27157 case dw_val_class_const_double:
27158 hstate.add_object (val2->v.val_double.low);
27159 hstate.add_object (val2->v.val_double.high);
27161 case dw_val_class_wide_int:
27162 hstate.add (val2->v.val_wide->get_val (),
27163 get_full_len (*val2->v.val_wide)
27164 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
27166 case dw_val_class_addr:
27167 inchash::add_rtx (val2->v.val_addr, hstate);
27170 gcc_unreachable ();
27174 case DW_OP_bit_piece:
27175 hstate.add_object (val1->v.val_int);
27176 hstate.add_object (val2->v.val_int);
27182 unsigned char dtprel = 0xd1;
27183 hstate.add_object (dtprel);
27185 inchash::add_rtx (val1->v.val_addr, hstate);
27187 case DW_OP_GNU_addr_index:
27188 case DW_OP_GNU_const_index:
27192 unsigned char dtprel = 0xd1;
27193 hstate.add_object (dtprel);
27195 inchash::add_rtx (val1->val_entry->addr.rtl, hstate);
27198 case DW_OP_GNU_implicit_pointer:
27199 hstate.add_int (val2->v.val_int);
27201 case DW_OP_GNU_entry_value:
27202 hstate.add_object (val1->v.val_loc);
27204 case DW_OP_GNU_regval_type:
27205 case DW_OP_GNU_deref_type:
27207 unsigned int byte_size
27208 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
27209 unsigned int encoding
27210 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
27211 hstate.add_object (val1->v.val_int);
27212 hstate.add_object (byte_size);
27213 hstate.add_object (encoding);
27216 case DW_OP_GNU_convert:
27217 case DW_OP_GNU_reinterpret:
27218 if (val1->val_class == dw_val_class_unsigned_const)
27220 hstate.add_object (val1->v.val_unsigned);
27224 case DW_OP_GNU_const_type:
27226 unsigned int byte_size
27227 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
27228 unsigned int encoding
27229 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
27230 hstate.add_object (byte_size);
27231 hstate.add_object (encoding);
27232 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
27234 hstate.add_object (val2->val_class);
27235 switch (val2->val_class)
27237 case dw_val_class_const:
27238 hstate.add_object (val2->v.val_int);
27240 case dw_val_class_vec:
27242 unsigned int elt_size = val2->v.val_vec.elt_size;
27243 unsigned int len = val2->v.val_vec.length;
27245 hstate.add_object (elt_size);
27246 hstate.add_object (len);
27247 hstate.add (val2->v.val_vec.array, len * elt_size);
27250 case dw_val_class_const_double:
27251 hstate.add_object (val2->v.val_double.low);
27252 hstate.add_object (val2->v.val_double.high);
27254 case dw_val_class_wide_int:
27255 hstate.add (val2->v.val_wide->get_val (),
27256 get_full_len (*val2->v.val_wide)
27257 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
27260 gcc_unreachable ();
27266 /* Other codes have no operands. */
27271 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
27274 hash_locs (dw_loc_descr_ref loc, inchash::hash &hstate)
27276 dw_loc_descr_ref l;
27277 bool sizes_computed = false;
27278 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
27279 size_of_locs (loc);
27281 for (l = loc; l != NULL; l = l->dw_loc_next)
27283 enum dwarf_location_atom opc = l->dw_loc_opc;
27284 hstate.add_object (opc);
27285 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
27287 size_of_locs (loc);
27288 sizes_computed = true;
27290 hash_loc_operands (l, hstate);
27294 /* Compute hash of the whole location list LIST_HEAD. */
27297 hash_loc_list (dw_loc_list_ref list_head)
27299 dw_loc_list_ref curr = list_head;
27300 inchash::hash hstate;
27302 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
27304 hstate.add (curr->begin, strlen (curr->begin) + 1);
27305 hstate.add (curr->end, strlen (curr->end) + 1);
27307 hstate.add (curr->section, strlen (curr->section) + 1);
27308 hash_locs (curr->expr, hstate);
27310 list_head->hash = hstate.end ();
27313 /* Return true if X and Y opcodes have the same operands. */
27316 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
27318 dw_val_ref valx1 = &x->dw_loc_oprnd1;
27319 dw_val_ref valx2 = &x->dw_loc_oprnd2;
27320 dw_val_ref valy1 = &y->dw_loc_oprnd1;
27321 dw_val_ref valy2 = &y->dw_loc_oprnd2;
27323 switch (x->dw_loc_opc)
27325 case DW_OP_const4u:
27326 case DW_OP_const8u:
27330 case DW_OP_const1u:
27331 case DW_OP_const1s:
27332 case DW_OP_const2u:
27333 case DW_OP_const2s:
27334 case DW_OP_const4s:
27335 case DW_OP_const8s:
27339 case DW_OP_plus_uconst:
27375 case DW_OP_deref_size:
27376 case DW_OP_xderef_size:
27377 return valx1->v.val_int == valy1->v.val_int;
27380 /* If splitting debug info, the use of DW_OP_GNU_addr_index
27381 can cause irrelevant differences in dw_loc_addr. */
27382 gcc_assert (valx1->val_class == dw_val_class_loc
27383 && valy1->val_class == dw_val_class_loc
27384 && (dwarf_split_debug_info
27385 || x->dw_loc_addr == y->dw_loc_addr));
27386 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
27387 case DW_OP_implicit_value:
27388 if (valx1->v.val_unsigned != valy1->v.val_unsigned
27389 || valx2->val_class != valy2->val_class)
27391 switch (valx2->val_class)
27393 case dw_val_class_const:
27394 return valx2->v.val_int == valy2->v.val_int;
27395 case dw_val_class_vec:
27396 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
27397 && valx2->v.val_vec.length == valy2->v.val_vec.length
27398 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
27399 valx2->v.val_vec.elt_size
27400 * valx2->v.val_vec.length) == 0;
27401 case dw_val_class_const_double:
27402 return valx2->v.val_double.low == valy2->v.val_double.low
27403 && valx2->v.val_double.high == valy2->v.val_double.high;
27404 case dw_val_class_wide_int:
27405 return *valx2->v.val_wide == *valy2->v.val_wide;
27406 case dw_val_class_addr:
27407 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
27409 gcc_unreachable ();
27412 case DW_OP_bit_piece:
27413 return valx1->v.val_int == valy1->v.val_int
27414 && valx2->v.val_int == valy2->v.val_int;
27417 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
27418 case DW_OP_GNU_addr_index:
27419 case DW_OP_GNU_const_index:
27421 rtx ax1 = valx1->val_entry->addr.rtl;
27422 rtx ay1 = valy1->val_entry->addr.rtl;
27423 return rtx_equal_p (ax1, ay1);
27425 case DW_OP_GNU_implicit_pointer:
27426 return valx1->val_class == dw_val_class_die_ref
27427 && valx1->val_class == valy1->val_class
27428 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
27429 && valx2->v.val_int == valy2->v.val_int;
27430 case DW_OP_GNU_entry_value:
27431 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
27432 case DW_OP_GNU_const_type:
27433 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
27434 || valx2->val_class != valy2->val_class)
27436 switch (valx2->val_class)
27438 case dw_val_class_const:
27439 return valx2->v.val_int == valy2->v.val_int;
27440 case dw_val_class_vec:
27441 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
27442 && valx2->v.val_vec.length == valy2->v.val_vec.length
27443 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
27444 valx2->v.val_vec.elt_size
27445 * valx2->v.val_vec.length) == 0;
27446 case dw_val_class_const_double:
27447 return valx2->v.val_double.low == valy2->v.val_double.low
27448 && valx2->v.val_double.high == valy2->v.val_double.high;
27449 case dw_val_class_wide_int:
27450 return *valx2->v.val_wide == *valy2->v.val_wide;
27452 gcc_unreachable ();
27454 case DW_OP_GNU_regval_type:
27455 case DW_OP_GNU_deref_type:
27456 return valx1->v.val_int == valy1->v.val_int
27457 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
27458 case DW_OP_GNU_convert:
27459 case DW_OP_GNU_reinterpret:
27460 if (valx1->val_class != valy1->val_class)
27462 if (valx1->val_class == dw_val_class_unsigned_const)
27463 return valx1->v.val_unsigned == valy1->v.val_unsigned;
27464 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
27465 case DW_OP_GNU_parameter_ref:
27466 return valx1->val_class == dw_val_class_die_ref
27467 && valx1->val_class == valy1->val_class
27468 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
27470 /* Other codes have no operands. */
27475 /* Return true if DWARF location expressions X and Y are the same. */
27478 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
27480 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
27481 if (x->dw_loc_opc != y->dw_loc_opc
27482 || x->dtprel != y->dtprel
27483 || !compare_loc_operands (x, y))
27485 return x == NULL && y == NULL;
27488 /* Hashtable helpers. */
27490 struct loc_list_hasher : nofree_ptr_hash <dw_loc_list_struct>
27492 static inline hashval_t hash (const dw_loc_list_struct *);
27493 static inline bool equal (const dw_loc_list_struct *,
27494 const dw_loc_list_struct *);
27497 /* Return precomputed hash of location list X. */
27500 loc_list_hasher::hash (const dw_loc_list_struct *x)
27505 /* Return true if location lists A and B are the same. */
27508 loc_list_hasher::equal (const dw_loc_list_struct *a,
27509 const dw_loc_list_struct *b)
27513 if (a->hash != b->hash)
27515 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
27516 if (strcmp (a->begin, b->begin) != 0
27517 || strcmp (a->end, b->end) != 0
27518 || (a->section == NULL) != (b->section == NULL)
27519 || (a->section && strcmp (a->section, b->section) != 0)
27520 || !compare_locs (a->expr, b->expr))
27522 return a == NULL && b == NULL;
27525 typedef hash_table<loc_list_hasher> loc_list_hash_type;
27528 /* Recursively optimize location lists referenced from DIE
27529 children and share them whenever possible. */
27532 optimize_location_lists_1 (dw_die_ref die, loc_list_hash_type *htab)
27537 dw_loc_list_struct **slot;
27539 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
27540 if (AT_class (a) == dw_val_class_loc_list)
27542 dw_loc_list_ref list = AT_loc_list (a);
27543 /* TODO: perform some optimizations here, before hashing
27544 it and storing into the hash table. */
27545 hash_loc_list (list);
27546 slot = htab->find_slot_with_hash (list, list->hash, INSERT);
27550 a->dw_attr_val.v.val_loc_list = *slot;
27553 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
27557 /* Recursively assign each location list a unique index into the debug_addr
27561 index_location_lists (dw_die_ref die)
27567 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
27568 if (AT_class (a) == dw_val_class_loc_list)
27570 dw_loc_list_ref list = AT_loc_list (a);
27571 dw_loc_list_ref curr;
27572 for (curr = list; curr != NULL; curr = curr->dw_loc_next)
27574 /* Don't index an entry that has already been indexed
27575 or won't be output. */
27576 if (curr->begin_entry != NULL
27577 || (strcmp (curr->begin, curr->end) == 0 && !curr->force))
27581 = add_addr_table_entry (xstrdup (curr->begin),
27586 FOR_EACH_CHILD (die, c, index_location_lists (c));
27589 /* Optimize location lists referenced from DIE
27590 children and share them whenever possible. */
27593 optimize_location_lists (dw_die_ref die)
27595 loc_list_hash_type htab (500);
27596 optimize_location_lists_1 (die, &htab);
27599 /* Traverse the limbo die list, and add parent/child links. The only
27600 dies without parents that should be here are concrete instances of
27601 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
27602 For concrete instances, we can get the parent die from the abstract
27606 flush_limbo_die_list (void)
27608 limbo_die_node *node;
27610 /* get_context_die calls force_decl_die, which can put new DIEs on the
27611 limbo list in LTO mode when nested functions are put in a different
27612 partition than that of their parent function. */
27613 while ((node = limbo_die_list))
27615 dw_die_ref die = node->die;
27616 limbo_die_list = node->next;
27618 if (die->die_parent == NULL)
27620 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
27622 if (origin && origin->die_parent)
27623 add_child_die (origin->die_parent, die);
27624 else if (is_cu_die (die))
27626 else if (seen_error ())
27627 /* It's OK to be confused by errors in the input. */
27628 add_child_die (comp_unit_die (), die);
27631 /* In certain situations, the lexical block containing a
27632 nested function can be optimized away, which results
27633 in the nested function die being orphaned. Likewise
27634 with the return type of that nested function. Force
27635 this to be a child of the containing function.
27637 It may happen that even the containing function got fully
27638 inlined and optimized out. In that case we are lost and
27639 assign the empty child. This should not be big issue as
27640 the function is likely unreachable too. */
27641 gcc_assert (node->created_for);
27643 if (DECL_P (node->created_for))
27644 origin = get_context_die (DECL_CONTEXT (node->created_for));
27645 else if (TYPE_P (node->created_for))
27646 origin = scope_die_for (node->created_for, comp_unit_die ());
27648 origin = comp_unit_die ();
27650 add_child_die (origin, die);
27656 /* Output stuff that dwarf requires at the end of every file,
27657 and generate the DWARF-2 debugging info. */
27660 dwarf2out_finish (const char *filename)
27662 comdat_type_node *ctnode;
27663 dw_die_ref main_comp_unit_die;
27665 /* Flush out any latecomers to the limbo party. */
27666 flush_limbo_die_list ();
27668 /* We shouldn't have any symbols with delayed asm names for
27669 DIEs generated after early finish. */
27670 gcc_assert (deferred_asm_name == NULL);
27672 /* PCH might result in DW_AT_producer string being restored from the
27673 header compilation, so always fill it with empty string initially
27674 and overwrite only here. */
27675 dw_attr_node *producer = get_AT (comp_unit_die (), DW_AT_producer);
27676 producer_string = gen_producer_string ();
27677 producer->dw_attr_val.v.val_str->refcount--;
27678 producer->dw_attr_val.v.val_str = find_AT_string (producer_string);
27680 gen_remaining_tmpl_value_param_die_attribute ();
27682 /* Add the name for the main input file now. We delayed this from
27683 dwarf2out_init to avoid complications with PCH.
27684 For LTO produced units use a fixed artificial name to avoid
27685 leaking tempfile names into the dwarf. */
27687 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
27689 add_name_attribute (comp_unit_die (), "<artificial>");
27690 if (!IS_ABSOLUTE_PATH (filename) || targetm.force_at_comp_dir)
27691 add_comp_dir_attribute (comp_unit_die ());
27692 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
27695 file_table->traverse<bool *, file_table_relative_p> (&p);
27697 add_comp_dir_attribute (comp_unit_die ());
27700 #if ENABLE_ASSERT_CHECKING
27702 dw_die_ref die = comp_unit_die (), c;
27703 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
27706 resolve_addr (comp_unit_die ());
27707 move_marked_base_types ();
27709 if (flag_eliminate_unused_debug_types)
27710 prune_unused_types ();
27712 /* Generate separate COMDAT sections for type DIEs. */
27713 if (use_debug_types)
27715 break_out_comdat_types (comp_unit_die ());
27717 /* Each new type_unit DIE was added to the limbo die list when created.
27718 Since these have all been added to comdat_type_list, clear the
27720 limbo_die_list = NULL;
27722 /* For each new comdat type unit, copy declarations for incomplete
27723 types to make the new unit self-contained (i.e., no direct
27724 references to the main compile unit). */
27725 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
27726 copy_decls_for_unworthy_types (ctnode->root_die);
27727 copy_decls_for_unworthy_types (comp_unit_die ());
27729 /* In the process of copying declarations from one unit to another,
27730 we may have left some declarations behind that are no longer
27731 referenced. Prune them. */
27732 prune_unused_types ();
27735 /* Generate separate CUs for each of the include files we've seen.
27736 They will go into limbo_die_list. */
27737 if (flag_eliminate_dwarf2_dups)
27738 break_out_includes (comp_unit_die ());
27740 /* Traverse the DIE's and add sibling attributes to those DIE's that
27742 add_sibling_attributes (comp_unit_die ());
27743 limbo_die_node *node;
27744 for (node = limbo_die_list; node; node = node->next)
27745 add_sibling_attributes (node->die);
27746 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
27747 add_sibling_attributes (ctnode->root_die);
27749 /* When splitting DWARF info, we put some attributes in the
27750 skeleton compile_unit DIE that remains in the .o, while
27751 most attributes go in the DWO compile_unit_die. */
27752 if (dwarf_split_debug_info)
27753 main_comp_unit_die = gen_compile_unit_die (NULL);
27755 main_comp_unit_die = comp_unit_die ();
27757 /* Output a terminator label for the .text section. */
27758 switch_to_section (text_section);
27759 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
27760 if (cold_text_section)
27762 switch_to_section (cold_text_section);
27763 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
27766 /* We can only use the low/high_pc attributes if all of the code was
27768 if (!have_multiple_function_sections
27769 || (dwarf_version < 3 && dwarf_strict))
27771 /* Don't add if the CU has no associated code. */
27772 if (text_section_used)
27773 add_AT_low_high_pc (main_comp_unit_die, text_section_label,
27774 text_end_label, true);
27780 bool range_list_added = false;
27782 if (text_section_used)
27783 add_ranges_by_labels (main_comp_unit_die, text_section_label,
27784 text_end_label, &range_list_added, true);
27785 if (cold_text_section_used)
27786 add_ranges_by_labels (main_comp_unit_die, cold_text_section_label,
27787 cold_end_label, &range_list_added, true);
27789 FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
27791 if (DECL_IGNORED_P (fde->decl))
27793 if (!fde->in_std_section)
27794 add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_begin,
27795 fde->dw_fde_end, &range_list_added,
27797 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
27798 add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_second_begin,
27799 fde->dw_fde_second_end, &range_list_added,
27803 if (range_list_added)
27805 /* We need to give .debug_loc and .debug_ranges an appropriate
27806 "base address". Use zero so that these addresses become
27807 absolute. Historically, we've emitted the unexpected
27808 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
27809 Emit both to give time for other tools to adapt. */
27810 add_AT_addr (main_comp_unit_die, DW_AT_low_pc, const0_rtx, true);
27811 if (! dwarf_strict && dwarf_version < 4)
27812 add_AT_addr (main_comp_unit_die, DW_AT_entry_pc, const0_rtx, true);
27818 if (debug_info_level >= DINFO_LEVEL_TERSE)
27819 add_AT_lineptr (main_comp_unit_die, DW_AT_stmt_list,
27820 debug_line_section_label);
27823 add_AT_macptr (comp_unit_die (),
27824 dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros,
27825 macinfo_section_label);
27827 if (dwarf_split_debug_info)
27829 /* optimize_location_lists calculates the size of the lists,
27830 so index them first, and assign indices to the entries.
27831 Although optimize_location_lists will remove entries from
27832 the table, it only does so for duplicates, and therefore
27833 only reduces ref_counts to 1. */
27834 index_location_lists (comp_unit_die ());
27836 if (addr_index_table != NULL)
27838 unsigned int index = 0;
27840 ->traverse_noresize<unsigned int *, index_addr_table_entry>
27845 if (have_location_lists)
27846 optimize_location_lists (comp_unit_die ());
27848 save_macinfo_strings ();
27850 if (dwarf_split_debug_info)
27852 unsigned int index = 0;
27854 /* Add attributes common to skeleton compile_units and
27855 type_units. Because these attributes include strings, it
27856 must be done before freezing the string table. Top-level
27857 skeleton die attrs are added when the skeleton type unit is
27858 created, so ensure it is created by this point. */
27859 add_top_level_skeleton_die_attrs (main_comp_unit_die);
27860 debug_str_hash->traverse_noresize<unsigned int *, index_string> (&index);
27863 /* Output all of the compilation units. We put the main one last so that
27864 the offsets are available to output_pubnames. */
27865 for (node = limbo_die_list; node; node = node->next)
27866 output_comp_unit (node->die, 0);
27868 hash_table<comdat_type_hasher> comdat_type_table (100);
27869 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
27871 comdat_type_node **slot = comdat_type_table.find_slot (ctnode, INSERT);
27873 /* Don't output duplicate types. */
27874 if (*slot != HTAB_EMPTY_ENTRY)
27877 /* Add a pointer to the line table for the main compilation unit
27878 so that the debugger can make sense of DW_AT_decl_file
27880 if (debug_info_level >= DINFO_LEVEL_TERSE)
27881 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
27882 (!dwarf_split_debug_info
27883 ? debug_line_section_label
27884 : debug_skeleton_line_section_label));
27886 output_comdat_type_unit (ctnode);
27890 /* The AT_pubnames attribute needs to go in all skeleton dies, including
27891 both the main_cu and all skeleton TUs. Making this call unconditional
27892 would end up either adding a second copy of the AT_pubnames attribute, or
27893 requiring a special case in add_top_level_skeleton_die_attrs. */
27894 if (!dwarf_split_debug_info)
27895 add_AT_pubnames (comp_unit_die ());
27897 if (dwarf_split_debug_info)
27900 unsigned char checksum[16];
27901 struct md5_ctx ctx;
27903 /* Compute a checksum of the comp_unit to use as the dwo_id. */
27904 md5_init_ctx (&ctx);
27906 die_checksum (comp_unit_die (), &ctx, &mark);
27907 unmark_all_dies (comp_unit_die ());
27908 md5_finish_ctx (&ctx, checksum);
27910 /* Use the first 8 bytes of the checksum as the dwo_id,
27911 and add it to both comp-unit DIEs. */
27912 add_AT_data8 (main_comp_unit_die, DW_AT_GNU_dwo_id, checksum);
27913 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id, checksum);
27915 /* Add the base offset of the ranges table to the skeleton
27917 if (ranges_table_in_use)
27918 add_AT_lineptr (main_comp_unit_die, DW_AT_GNU_ranges_base,
27919 ranges_section_label);
27921 switch_to_section (debug_addr_section);
27922 ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label);
27923 output_addr_table ();
27926 /* Output the main compilation unit if non-empty or if .debug_macinfo
27927 or .debug_macro will be emitted. */
27928 output_comp_unit (comp_unit_die (), have_macinfo);
27930 if (dwarf_split_debug_info && info_section_emitted)
27931 output_skeleton_debug_sections (main_comp_unit_die);
27933 /* Output the abbreviation table. */
27934 if (abbrev_die_table_in_use != 1)
27936 switch_to_section (debug_abbrev_section);
27937 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
27938 output_abbrev_section ();
27941 /* Output location list section if necessary. */
27942 if (have_location_lists)
27944 /* Output the location lists info. */
27945 switch_to_section (debug_loc_section);
27946 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
27947 output_location_lists (comp_unit_die ());
27950 output_pubtables ();
27952 /* Output the address range information if a CU (.debug_info section)
27953 was emitted. We output an empty table even if we had no functions
27954 to put in it. This because the consumer has no way to tell the
27955 difference between an empty table that we omitted and failure to
27956 generate a table that would have contained data. */
27957 if (info_section_emitted)
27959 switch_to_section (debug_aranges_section);
27963 /* Output ranges section if necessary. */
27964 if (ranges_table_in_use)
27966 switch_to_section (debug_ranges_section);
27967 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
27971 /* Have to end the macro section. */
27974 switch_to_section (debug_macinfo_section);
27975 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
27977 dw2_asm_output_data (1, 0, "End compilation unit");
27980 /* Output the source line correspondence table. We must do this
27981 even if there is no line information. Otherwise, on an empty
27982 translation unit, we will generate a present, but empty,
27983 .debug_info section. IRIX 6.5 `nm' will then complain when
27984 examining the file. This is done late so that any filenames
27985 used by the debug_info section are marked as 'used'. */
27986 switch_to_section (debug_line_section);
27987 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
27988 if (! DWARF2_ASM_LINE_DEBUG_INFO)
27989 output_line_info (false);
27991 if (dwarf_split_debug_info && info_section_emitted)
27993 switch_to_section (debug_skeleton_line_section);
27994 ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_line_section_label);
27995 output_line_info (true);
27998 /* If we emitted any indirect strings, output the string table too. */
27999 if (debug_str_hash || skeleton_debug_str_hash)
28000 output_indirect_strings ();
28003 /* Perform any cleanups needed after the early debug generation pass
28007 dwarf2out_early_finish (void)
28009 /* Walk through the list of incomplete types again, trying once more to
28010 emit full debugging info for them. */
28011 retry_incomplete_types ();
28013 /* The point here is to flush out the limbo list so that it is empty
28014 and we don't need to stream it for LTO. */
28015 flush_limbo_die_list ();
28017 gen_scheduled_generic_parms_dies ();
28018 gen_remaining_tmpl_value_param_die_attribute ();
28020 /* Add DW_AT_linkage_name for all deferred DIEs. */
28021 for (limbo_die_node *node = deferred_asm_name; node; node = node->next)
28023 tree decl = node->created_for;
28024 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
28025 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
28026 ended up in deferred_asm_name before we knew it was
28027 constant and never written to disk. */
28028 && DECL_ASSEMBLER_NAME (decl))
28030 add_linkage_attr (node->die, decl);
28031 move_linkage_attr (node->die);
28034 deferred_asm_name = NULL;
28037 /* Reset all state within dwarf2out.c so that we can rerun the compiler
28038 within the same process. For use by toplev::finalize. */
28041 dwarf2out_c_finalize (void)
28043 last_var_location_insn = NULL;
28044 cached_next_real_insn = NULL;
28045 used_rtx_array = NULL;
28046 incomplete_types = NULL;
28047 decl_scope_table = NULL;
28048 debug_info_section = NULL;
28049 debug_skeleton_info_section = NULL;
28050 debug_abbrev_section = NULL;
28051 debug_skeleton_abbrev_section = NULL;
28052 debug_aranges_section = NULL;
28053 debug_addr_section = NULL;
28054 debug_macinfo_section = NULL;
28055 debug_line_section = NULL;
28056 debug_skeleton_line_section = NULL;
28057 debug_loc_section = NULL;
28058 debug_pubnames_section = NULL;
28059 debug_pubtypes_section = NULL;
28060 debug_str_section = NULL;
28061 debug_str_dwo_section = NULL;
28062 debug_str_offsets_section = NULL;
28063 debug_ranges_section = NULL;
28064 debug_frame_section = NULL;
28066 debug_str_hash = NULL;
28067 skeleton_debug_str_hash = NULL;
28068 dw2_string_counter = 0;
28069 have_multiple_function_sections = false;
28070 text_section_used = false;
28071 cold_text_section_used = false;
28072 cold_text_section = NULL;
28073 current_unit_personality = NULL;
28075 next_die_offset = 0;
28076 single_comp_unit_die = NULL;
28077 comdat_type_list = NULL;
28078 limbo_die_list = NULL;
28080 decl_die_table = NULL;
28081 common_block_die_table = NULL;
28082 decl_loc_table = NULL;
28083 call_arg_locations = NULL;
28084 call_arg_loc_last = NULL;
28085 call_site_count = -1;
28086 tail_call_site_count = -1;
28087 cached_dw_loc_list_table = NULL;
28088 abbrev_die_table = NULL;
28089 abbrev_die_table_allocated = 0;
28090 abbrev_die_table_in_use = 0;
28091 delete dwarf_proc_stack_usage_map;
28092 dwarf_proc_stack_usage_map = NULL;
28093 line_info_label_num = 0;
28094 cur_line_info_table = NULL;
28095 text_section_line_info = NULL;
28096 cold_text_section_line_info = NULL;
28097 separate_line_info = NULL;
28098 info_section_emitted = false;
28099 pubname_table = NULL;
28100 pubtype_table = NULL;
28101 macinfo_table = NULL;
28102 ranges_table = NULL;
28103 ranges_table_allocated = 0;
28104 ranges_table_in_use = 0;
28105 ranges_by_label = 0;
28106 ranges_by_label_allocated = 0;
28107 ranges_by_label_in_use = 0;
28108 have_location_lists = false;
28111 last_emitted_file = NULL;
28113 tmpl_value_parm_die_table = NULL;
28114 generic_type_instances = NULL;
28115 frame_pointer_fb_offset = 0;
28116 frame_pointer_fb_offset_valid = false;
28117 base_types.release ();
28118 XDELETEVEC (producer_string);
28119 producer_string = NULL;
28122 #include "gt-dwarf2out.h"